public Ini1(IStorage storage) { Storage = storage; var reader = new BinaryReader(Storage.AsStream()); Magic = reader.ReadAscii(4); if (Magic != "INI1") { throw new InvalidDataException("Invalid INI1 file!"); } Size = reader.ReadInt32(); KipCount = reader.ReadInt32(); Kips = new KipReader[KipCount]; int offset = 0x10; for (int i = 0; i < KipCount; i++) { Kips[i] = new KipReader(); Kips[i].Initialize(Storage.Slice(offset)).ThrowIfFailure(); offset += Kips[i].GetFileSize(); } }
public KipExecutable(IStorage inStorage) { KipReader reader = new KipReader(); reader.Initialize(inStorage).ThrowIfFailure(); TextOffset = reader.Segments[0].MemoryOffset; RoOffset = reader.Segments[1].MemoryOffset; DataOffset = reader.Segments[2].MemoryOffset; BssOffset = reader.Segments[3].MemoryOffset; BssSize = reader.Segments[3].Size; StackSize = reader.StackSize; UsesSecureMemory = reader.UsesSecureMemory; Is64BitAddressSpace = reader.Is64BitAddressSpace; Is64Bit = reader.Is64Bit; ProgramId = reader.ProgramId; Priority = reader.Priority; IdealCoreId = reader.IdealCoreId; Version = reader.Version; Name = reader.Name.ToString(); Capabilities = new int[32]; for (int index = 0; index < Capabilities.Length; index++) { Capabilities[index] = (int)reader.Capabilities[index]; } Text = DecompressSection(reader, KipReader.SegmentType.Text); Ro = DecompressSection(reader, KipReader.SegmentType.Ro); Data = DecompressSection(reader, KipReader.SegmentType.Data); }
private static uint DecompressSection(KipReader reader, KipReader.SegmentType segmentType, uint offset, byte[] program) { reader.GetSegmentSize(segmentType, out int uncompressedSize).ThrowIfFailure(); var span = program.AsSpan().Slice((int)offset, uncompressedSize); reader.ReadSegment(segmentType, span).ThrowIfFailure(); return((uint)uncompressedSize); }
private static byte[] DecompressSection(KipReader reader, KipReader.SegmentType segmentType) { reader.GetSegmentSize(segmentType, out int uncompressedSize).ThrowIfFailure(); byte[] result = new byte[uncompressedSize]; reader.ReadSegment(segmentType, result).ThrowIfFailure(); return(result); }
public static void ProcessKip1(Context ctx) { using (var file = new LocalStorage(ctx.Options.InFile, FileAccess.Read)) { var kip = new KipReader(); kip.Initialize(file).ThrowIfFailure(); if (!string.IsNullOrWhiteSpace(ctx.Options.UncompressedOut)) { var uncompressed = new byte[kip.GetUncompressedSize()]; kip.ReadUncompressedKip(uncompressed).ThrowIfFailure(); File.WriteAllBytes(ctx.Options.UncompressedOut, uncompressed); } } }
public static void ExtractIni1(IStorage iniStorage, string outDir) { var ini1 = new InitialProcessBinaryReader(); ini1.Initialize(iniStorage).ThrowIfFailure(); Directory.CreateDirectory(outDir); var kipReader = new KipReader(); for (int i = 0; i < ini1.ProcessCount; i++) { ini1.OpenKipStorage(out IStorage kipStorage, i).ThrowIfFailure(); kipReader.Initialize(kipStorage).ThrowIfFailure(); kipStorage.WriteAllBytes(System.IO.Path.Combine(outDir, $"{kipReader.Name.ToString()}.kip1")); } }