|
@@ -103,6 +103,7 @@ namespace BepInEx.IL2CPP
|
|
|
|
|
|
uint totalBytes = 0;
|
|
uint totalBytes = 0;
|
|
var origInstructions = new InstructionList();
|
|
var origInstructions = new InstructionList();
|
|
|
|
+ var readOverflowArea = false;
|
|
while (codeReader.CanReadByte)
|
|
while (codeReader.CanReadByte)
|
|
{
|
|
{
|
|
decoder.Decode(out var instr);
|
|
decoder.Decode(out var instr);
|
|
@@ -115,26 +116,37 @@ namespace BepInEx.IL2CPP
|
|
if (totalBytes >= minimumTrampolineLength)
|
|
if (totalBytes >= minimumTrampolineLength)
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
+ if (readOverflowArea)
|
|
|
|
+ {
|
|
|
|
+ if (instr.Mnemonic != Mnemonic.Int && instr.Mnemonic != Mnemonic.Nop)
|
|
|
|
+ throw new Exception("Function is too short to hook");
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
switch (instr.FlowControl)
|
|
switch (instr.FlowControl)
|
|
{
|
|
{
|
|
case FlowControl.Next:
|
|
case FlowControl.Next:
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
+ // Interrupts are usually used for aligning
|
|
case FlowControl.Interrupt:// eg. int n
|
|
case FlowControl.Interrupt:// eg. int n
|
|
break;
|
|
break;
|
|
|
|
|
|
// Handled by BlockEncoder in most cases
|
|
// Handled by BlockEncoder in most cases
|
|
case FlowControl.UnconditionalBranch:
|
|
case FlowControl.UnconditionalBranch:
|
|
- case FlowControl.IndirectBranch:// eg. jmp reg/mem
|
|
|
|
- case FlowControl.ConditionalBranch:// eg. je, jno, etc
|
|
|
|
|
|
+ case FlowControl.IndirectBranch: // eg. jmp reg/mem
|
|
|
|
+ case FlowControl.ConditionalBranch: // eg. je, jno, etc
|
|
|
|
+ break;
|
|
|
|
+ case FlowControl.Return: // eg. ret
|
|
|
|
+ // There is a possibility of an overflow area, attempt to allocate trampoline onto it
|
|
|
|
+ readOverflowArea = true;
|
|
break;
|
|
break;
|
|
- case FlowControl.Return:// eg. ret
|
|
|
|
case FlowControl.Call:// eg. call method
|
|
case FlowControl.Call:// eg. call method
|
|
case FlowControl.IndirectCall:// eg. call reg/mem
|
|
case FlowControl.IndirectCall:// eg. call reg/mem
|
|
case FlowControl.XbeginXabortXend:
|
|
case FlowControl.XbeginXabortXend:
|
|
case FlowControl.Exception:// eg. ud0
|
|
case FlowControl.Exception:// eg. ud0
|
|
default:
|
|
default:
|
|
- throw new Exception("Not supported by this simple example - " + instr.FlowControl);
|
|
|
|
|
|
+ throw new Exception("Not supported yet - " + instr.FlowControl);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (totalBytes < minimumTrampolineLength)
|
|
if (totalBytes < minimumTrampolineLength)
|