* Initial commit of new UI c# component * Initial commit of new UI frontend component * target WinExe to hide console window in release mode, move ui exe into resources * force single file publishing and add initial gh workflow for publishing ui * fix workflow errors * update dependencies and remove cxxdemangler, as it was outdated * fix c# single file output due to invalid output path * smaller tweaks, hack around loops in cpp type layouting * process other queued exports even if one fails and show error message * add basic support for processing LC_DYLD_CHAINED_FIXUPS * ELF loading should not use the file offset for loading the dynamic section * fix symbol table loading in some modified elfs * add "start export" button on format selection screen, clear all toasts after selecting an export format * embed ui executable directly into c# assembly * only build tauri component in c# release builds * add il2cpp file (binary, metadata) export to advanced tab * fix and enable binary ninja fake string segment support * add support for metadata * unify logic for getting element type index * fix new ui not allowing script exports other than ida * new ui: clear out loaded binary if no IL2CPP images could be loaded * fix toAddr calls in ghidra script target * remove dependency on a section being named .text in loaded pe files * tweak symbol reading a bit and remove sht relocation reading * add initial support for required forward references in il2cpp types, also fix issues with type names clashing with il2cpp api types * reduce clang errors for header file, fix better array size struct, emit required forward definitions in header * expose forward definitions in AppModel, fix issue with method-only used types not being emitted * remove debug log line * fix spelling mistakes in gui outputs * fix il2cpp_array_size_t not being an actual type for later method definitions * change the default port for new ui dev to 5000 * show current version and hash in new ui footer * seperate redux ui impl into FrontendCore project * make inspector version a server api, split up output subtypes and tweak some option names * add redux CLI based on redux GUI output formats * replace all Console.WriteLine calls in core inspector with AnsiConsole calls * add workflow for new cli and add back old gui workflow * disable aot publish and enable single file for redux cli
221 lines
5.6 KiB
C#
221 lines
5.6 KiB
C#
/*
|
|
Copyright 2017-2021 Katy Coe - http://www.djkaty.com - https://github.com/djkaty
|
|
|
|
All rights reserved.
|
|
*/
|
|
|
|
using System;
|
|
using NoisyCowStudios.Bin2Object;
|
|
using VersionedSerialization.Attributes;
|
|
|
|
namespace Il2CppInspector
|
|
{
|
|
#pragma warning disable CS0649
|
|
// Structures and enums: https://opensource.apple.com/source/cctools/cctools-870/include/mach-o/loader.h
|
|
|
|
public enum MachO : uint
|
|
{
|
|
MH_MAGIC = 0xfeedface,
|
|
MH_CIGAM = 0xcefaedfe,
|
|
MH_MAGIC_64 = 0xfeedfacf,
|
|
MH_CIGAM_64 = 0xcffaedfe,
|
|
|
|
MH_MIN_FILETYPE = 0x1,
|
|
MH_MAX_FILETYPE = 0xB,
|
|
|
|
LC_SEGMENT = 0x1,
|
|
LC_SYMTAB = 0x2,
|
|
LC_DYSYMTAB = 0xb,
|
|
LC_SEGMENT_64 = 0x19,
|
|
LC_ENCRYPTION_INFO = 0x21,
|
|
LC_DYLD_INFO = 0x22,
|
|
LC_DYLD_INFO_ONLY = 0x80000022,
|
|
LC_FUNCTION_STARTS = 0x26,
|
|
LC_ENCRYPTION_INFO_64 = 0x2C,
|
|
LC_DYLD_CHAINED_FIXUPS = 0x80000034,
|
|
|
|
CPU_TYPE_X86 = 7,
|
|
CPU_TYPE_X86_64 = 0x01000000 + CPU_TYPE_X86,
|
|
CPU_TYPE_ARM = 12,
|
|
CPU_TYPE_ARM64 = 0x01000000 + CPU_TYPE_ARM,
|
|
}
|
|
|
|
[Flags]
|
|
public enum MachO_NType : byte
|
|
{
|
|
// n_type masks
|
|
N_STAB = 0xe0,
|
|
N_PEXT = 0x10,
|
|
N_TYPE = 0x0e,
|
|
N_EXT = 0x01,
|
|
|
|
// n_stab bits
|
|
N_UNDF = 0x00,
|
|
N_ABS = 0x02,
|
|
N_SECT = 0x0e,
|
|
N_PBUD = 0x0c,
|
|
N_INDR = 0x0a,
|
|
|
|
// n_type bits when N_STAB has some bits set
|
|
N_GSYM = 0x20,
|
|
N_FNAME = 0x22,
|
|
N_FUN = 0x24,
|
|
N_STSYM = 0x26,
|
|
N_BNSYM = 0x2E,
|
|
N_ENSYM = 0x4E,
|
|
N_SO = 0x64,
|
|
N_OSO = 0x66,
|
|
}
|
|
|
|
public class MachOHeader<TWord> where TWord : struct
|
|
{
|
|
public uint Magic;
|
|
public uint CPUType;
|
|
public uint CPUSubType;
|
|
public uint FileType;
|
|
public uint NumCommands;
|
|
public uint SizeOfCommands;
|
|
public TWord Flags;
|
|
}
|
|
|
|
public class MachOLoadCommand
|
|
{
|
|
public uint Command;
|
|
public uint Size;
|
|
}
|
|
|
|
public class MachOSegmentCommand<TWord> where TWord : struct
|
|
{
|
|
// MachOLoadCommand
|
|
[String(FixedSize = 16)]
|
|
public string Name;
|
|
public TWord VirtualAddress;
|
|
public TWord VirtualSize;
|
|
public TWord ImageOffset;
|
|
public TWord ImageSize;
|
|
public uint VMMaxProt;
|
|
public uint VMInitProt;
|
|
public uint NumSections;
|
|
public uint Flags;
|
|
}
|
|
|
|
public class MachOSection<TWord> where TWord : struct
|
|
{
|
|
[String(FixedSize = 16)]
|
|
public string Name;
|
|
[String(FixedSize = 16)]
|
|
public string SegmentName;
|
|
public TWord Address;
|
|
public TWord Size;
|
|
public uint ImageOffset;
|
|
public uint Align;
|
|
public uint ImageRelocOffset;
|
|
public int NumRelocEntries;
|
|
public uint Flags;
|
|
public uint Reserved1;
|
|
public TWord Reserved2;
|
|
}
|
|
|
|
public class MachOLinkEditDataCommand
|
|
{
|
|
// MachOLoadCommand
|
|
public uint Offset;
|
|
public uint Size;
|
|
}
|
|
|
|
public class MachODyldInfoCommand
|
|
{
|
|
public uint RebaseOffset;
|
|
public uint RebaseSize;
|
|
public uint BindOffset;
|
|
public uint BindSize;
|
|
public uint WeakBindOffset;
|
|
public uint WeakBindSize;
|
|
public uint LazyBindOffset;
|
|
public uint LazyBindSize;
|
|
public uint ExportOffset;
|
|
public uint ExportSize;
|
|
}
|
|
|
|
public class MachOSymtabCommand
|
|
{
|
|
public uint SymOffset;
|
|
public uint NumSyms;
|
|
public uint StrOffset;
|
|
public uint StrSize;
|
|
}
|
|
|
|
public class MachOEncryptionInfo
|
|
{
|
|
// MachOLoadCommand
|
|
public uint CryptOffset;
|
|
public uint CryptSize;
|
|
public uint CryptID;
|
|
}
|
|
|
|
public class MachO_nlist<TWord> where TWord : struct
|
|
{
|
|
public MachO_NType n_type => (MachO_NType) f_n_type;
|
|
public uint n_strx;
|
|
public byte f_n_type;
|
|
public byte n_sect;
|
|
public ushort n_desc;
|
|
public TWord n_value;
|
|
}
|
|
|
|
public class MachO_relocation_info
|
|
{
|
|
public int r_address;
|
|
public uint r_data;
|
|
|
|
public uint r_symbolnum => r_data & 0x00ffffff;
|
|
public bool r_pcrel => ((r_data >> 24) & 1) == 1;
|
|
public uint r_length => (r_data >> 25) & 3;
|
|
public bool r_extern => ((r_data >> 27) & 1) == 1;
|
|
public uint r_type => r_data >> 28;
|
|
}
|
|
|
|
[VersionedStruct]
|
|
public partial struct MachODyldChainedFixupsHeader
|
|
{
|
|
public uint FixupsVersion;
|
|
public uint StartsOffset;
|
|
public uint ImportsOffset;
|
|
public uint SymbolsOffset;
|
|
public uint ImportsCount;
|
|
public uint ImportsFormat;
|
|
public uint SymbolsFormat;
|
|
}
|
|
|
|
[VersionedStruct]
|
|
public partial struct MachODyldChainedStartsInSegment
|
|
{
|
|
public const ushort DYLD_CHAINED_PTR_START_NONE = 0xffff;
|
|
|
|
public uint StructSize;
|
|
public ushort PageSize;
|
|
public ushort PointerFormat;
|
|
public ulong SegmentOffset;
|
|
public uint MaxValidPointer;
|
|
public ushort PageCount;
|
|
}
|
|
|
|
public enum MachODyldChainedPtr
|
|
{
|
|
DYLD_CHAINED_PTR_64 = 2,
|
|
DYLD_CHAINED_PTR_64_OFFSET = 6,
|
|
}
|
|
|
|
[VersionedStruct]
|
|
public partial struct MachODyldChainedPtr64Rebase
|
|
{
|
|
private ulong _value;
|
|
|
|
public ulong Target => _value & 0xfffffffff;
|
|
public ulong High8 => (_value >> 36) & 0xff;
|
|
public ulong Reserved => (_value >> (36 + 8)) & 0x7f;
|
|
public ulong Next => (_value >> (36 + 8 + 7)) & 0xfff;
|
|
public bool Bind => ((_value >> (36 + 8 + 7 + 12)) & 0x1) == 0x1;
|
|
}
|
|
}
|