mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Read INI1
This commit is contained in:
parent
8b8aa3277f
commit
f04fc33b07
5 changed files with 71 additions and 2 deletions
|
@ -49,6 +49,8 @@ namespace LibHac
|
|||
return DecompressBlz(compressed);
|
||||
}
|
||||
|
||||
public Stream OpenRawFile() => StreamSource.CreateStream();
|
||||
|
||||
private static byte[] DecompressBlz(byte[] compressed)
|
||||
{
|
||||
int additionalSize = BitConverter.ToInt32(compressed, compressed.Length - 4);
|
||||
|
@ -161,4 +163,45 @@ namespace LibHac
|
|||
Attribute = reader.ReadInt32();
|
||||
}
|
||||
}
|
||||
|
||||
public class Ini1
|
||||
{
|
||||
public Kip[] Kips { get; }
|
||||
|
||||
public string Magic { get; }
|
||||
public int Size { get; }
|
||||
public int KipCount { get; }
|
||||
|
||||
private SharedStreamSource StreamSource { get; }
|
||||
|
||||
public Ini1(Stream stream)
|
||||
{
|
||||
StreamSource = new SharedStreamSource(stream);
|
||||
Stream initStream = StreamSource.CreateStream();
|
||||
|
||||
var reader = new BinaryReader(initStream);
|
||||
|
||||
Magic = reader.ReadAscii(4);
|
||||
if (Magic != "INI1")
|
||||
{
|
||||
throw new InvalidDataException("Invalid INI1 file!");
|
||||
}
|
||||
|
||||
Size = reader.ReadInt32();
|
||||
KipCount = reader.ReadInt32();
|
||||
|
||||
Kips = new Kip[KipCount];
|
||||
int offset = 0x10;
|
||||
|
||||
for (int i = 0; i < KipCount; i++)
|
||||
{
|
||||
// How to get the KIP's size the lazy way
|
||||
var kip = new Kip(StreamSource.CreateStream(offset));
|
||||
|
||||
Kips[i] = new Kip(StreamSource.CreateStream(offset, kip.Size));
|
||||
|
||||
offset += kip.Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,7 +147,7 @@ namespace hactoolnet
|
|||
sb.AppendLine(" -r, --raw Keep raw data, don\'t unpack.");
|
||||
sb.AppendLine(" -y, --verify Verify hashes.");
|
||||
sb.AppendLine(" -k, --keyset Load keys from an external file.");
|
||||
sb.AppendLine(" -t, --intype=type Specify input file type [nca, xci, romfs, pk11, pk21, switchfs, save, keygen]");
|
||||
sb.AppendLine(" -t, --intype=type Specify input file type [nca, xci, romfs, pk11, pk21, ini1, kip1, switchfs, save, keygen]");
|
||||
sb.AppendLine(" --titlekeys <file> Load title keys from an external file.");
|
||||
sb.AppendLine("NCA options:");
|
||||
sb.AppendLine(" --section0 <file> Specify Section 0 file path.");
|
||||
|
@ -183,6 +183,8 @@ namespace hactoolnet
|
|||
sb.AppendLine(" --outdir <dir> Specify Package1 directory path.");
|
||||
sb.AppendLine("Package2 options:");
|
||||
sb.AppendLine(" --outdir <dir> Specify Package2 directory path.");
|
||||
sb.AppendLine("INI1 options:");
|
||||
sb.AppendLine(" --outdir <dir> Specify INI1 directory path.");
|
||||
sb.AppendLine("Switch FS options:");
|
||||
sb.AppendLine(" --sdseed <seed> Set console unique seed for SD card NAX0 encryption.");
|
||||
sb.AppendLine(" --listapps List application info.");
|
||||
|
|
|
@ -49,7 +49,8 @@ namespace hactoolnet
|
|||
Keygen,
|
||||
Pk11,
|
||||
Pk21,
|
||||
Kip1
|
||||
Kip1,
|
||||
Ini1
|
||||
}
|
||||
|
||||
internal class Context
|
||||
|
|
|
@ -12,5 +12,25 @@ namespace hactoolnet
|
|||
var kip = new Kip(file);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ProcessIni1(Context ctx)
|
||||
{
|
||||
using (var file = new FileStream(ctx.Options.InFile, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
var ini1 = new Ini1(file);
|
||||
|
||||
string outDir = ctx.Options.OutDir;
|
||||
|
||||
if (outDir != null)
|
||||
{
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
foreach (Kip kip in ini1.Kips)
|
||||
{
|
||||
kip.OpenRawFile().WriteAllBytes(Path.Combine(outDir, $"{kip.Header.Name}.kip1"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,9 @@ namespace hactoolnet
|
|||
case FileType.Kip1:
|
||||
ProcessKip.ProcessKip1(ctx);
|
||||
break;
|
||||
case FileType.Ini1:
|
||||
ProcessKip.ProcessIni1(ctx);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue