|
@@ -80,6 +80,7 @@ namespace BepInEx.IL2CPP
|
|
|
return trampolinePtr;
|
|
|
}
|
|
|
|
|
|
+ private static ManualLogSource logger = Logger.CreateLogSource("detourgen");
|
|
|
|
|
|
|
|
|
|
|
@@ -103,7 +104,30 @@ namespace BepInEx.IL2CPP
|
|
|
while (codeReader.CanReadByte)
|
|
|
{
|
|
|
decoder.Decode(out var instr);
|
|
|
+
|
|
|
+ if (instr.IsIPRelativeMemoryOperand)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ logger.LogInfo($"Got ptr with relative memory operand: {instr}");
|
|
|
+ var addr = instr.IPRelativeMemoryAddress;
|
|
|
+ logger.LogInfo($"Address: {addr:X}");
|
|
|
+ instr.MemoryBase = Register.None;
|
|
|
+ var op = AssemblerRegisters.__byte_ptr[addr].ToMemoryOperand(64);
|
|
|
+ instr.Op0Kind = OpKind.Memory;
|
|
|
+ instr.MemoryBase = op.Base;
|
|
|
+ instr.MemoryIndex = op.Index;
|
|
|
+ instr.MemoryIndexScale = op.Scale;
|
|
|
+ instr.MemoryDisplSize = op.DisplSize;
|
|
|
+ instr.MemoryDisplacement = (uint)op.Displacement;
|
|
|
+ instr.IsBroadcast = op.IsBroadcast;
|
|
|
+ instr.SegmentPrefix = op.SegmentPrefix;
|
|
|
+ logger.LogInfo($"After edit: {instr}");
|
|
|
+ }
|
|
|
+
|
|
|
origInstructions.Add(instr);
|
|
|
+
|
|
|
totalBytes += (uint)instr.Length;
|
|
|
if (instr.Code == Code.INVALID)
|
|
|
throw new Exception("Found garbage");
|