From eeb46c58200191859c75c44a4eb795e839603521 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Tue, 22 Oct 2019 16:24:23 +0200 Subject: [PATCH] Fix x86 edge case bugs --- Il2CppInspector/Il2CppBinaryX86.cs | 35 ++++++++++++++++-------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Il2CppInspector/Il2CppBinaryX86.cs b/Il2CppInspector/Il2CppBinaryX86.cs index 0aae27c..d08a9ac 100644 --- a/Il2CppInspector/Il2CppBinaryX86.cs +++ b/Il2CppInspector/Il2CppBinaryX86.cs @@ -12,6 +12,7 @@ namespace Il2CppInspector { public Il2CppBinaryX86(IFileFormatReader stream) : base(stream) { } public Il2CppBinaryX86(IFileFormatReader stream, uint codeRegistration, uint metadataRegistration) : base(stream, codeRegistration, metadataRegistration) { } + protected override (ulong, ulong) ConsiderCode(uint loc, ulong globalOffset) { ulong metadata, code; long funcPtr; @@ -20,7 +21,7 @@ namespace Il2CppInspector // Variant 1 // Assembly bytes to search for at start of each function - var bytes = new byte[] { 0x6A, 0x00, 0x6A, 0x00, 0x68 }; + var bytes = new byte[] {0x6A, 0x00, 0x6A, 0x00, 0x68}; Image.Position = loc; var buff = Image.ReadBytes(5); if (bytes.SequenceEqual(buff)) { @@ -32,15 +33,16 @@ namespace Il2CppInspector return (0, 0); // Jump to Il2CppCodegenRegistration - Image.Position = Image.MapVATR((ulong) funcPtr) + 6; + Image.Position = Image.MapVATR((ulong) funcPtr + 6); metadata = Image.ReadUInt32(); - Image.Position = Image.MapVATR((ulong) funcPtr) + 11; + Image.Position = Image.MapVATR((ulong) funcPtr + 11); code = Image.ReadUInt32(); return (code, metadata); } // Variant 2 - bytes = new byte[] { 0x55, 0x89, 0xE5, 0x53, 0x83, 0xE4, 0xF0, 0x83, 0xEC, 0x20, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x5B }; + bytes = new byte[] + {0x55, 0x89, 0xE5, 0x53, 0x83, 0xE4, 0xF0, 0x83, 0xEC, 0x20, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x5B}; Image.Position = loc; buff = Image.ReadBytes(16); if (!bytes.SequenceEqual(buff)) @@ -61,19 +63,20 @@ namespace Il2CppInspector if (opcode == 0x838B) { Image.Position = Image.MapVATR(metadata); metadata = Image.ReadUInt32(); + + // Repeat the same logic for extracting the Code pointer + Image.Position = funcPtr + 0x2A; + opcode = Image.ReadUInt16(); + code = Image.ReadUInt32() + globalOffset; + + if (opcode == 0x838B) { + Image.Position = Image.MapVATR(code); + code = Image.ReadUInt32(); + + return (code, metadata); + } } - - // Repeat the same logic for extracting the Code pointer - Image.Position = funcPtr + 0x2A; - opcode = Image.ReadUInt16(); - code = Image.ReadUInt32() + globalOffset; - - if (opcode == 0x838B) { - Image.Position = Image.MapVATR(code); - code = Image.ReadUInt32(); - } - - return (code, metadata); + return (0, 0); } } }