Skip to content

Commit 1be7b0a

Browse files
ds5678SamboyCoding
authored andcommitted
Remove try catch in key function addresses classes for X86 and Arm64
1 parent d38e4c5 commit 1be7b0a

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

Cpp2IL.Core/Il2CppApiFunctions/NewArm64KeyFunctionAddresses.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using Disarm;
55
using Cpp2IL.Core.Logging;
66
using Cpp2IL.Core.Utils;
7-
using Iced.Intel;
87
using LibCpp2IL;
98
using LibCpp2IL.Reflection;
109

@@ -105,23 +104,16 @@ protected override ulong FindFunctionThisIsAThunkOf(ulong thunkPtr, bool priorit
105104
{
106105
var instructions = NewArm64Utils.GetArm64MethodBodyAtVirtualAddress(thunkPtr, true);
107106

108-
try
109-
{
110-
var target = prioritiseCall ? Arm64Mnemonic.BL : Arm64Mnemonic.B;
111-
var matchingCall = instructions.FirstOrDefault(i => i.Mnemonic == target);
112-
113-
if (matchingCall.Mnemonic == Arm64Mnemonic.INVALID)
114-
{
115-
target = target == Arm64Mnemonic.BL ? Arm64Mnemonic.B : Arm64Mnemonic.BL;
116-
matchingCall = instructions.First(i => i.Mnemonic == target);
117-
}
107+
var target = prioritiseCall ? Arm64Mnemonic.BL : Arm64Mnemonic.B;
108+
var matchingCall = instructions.FirstOrDefault(i => i.Mnemonic == target);
118109

119-
return matchingCall.BranchTarget;
120-
}
121-
catch (Exception)
110+
if (matchingCall.Mnemonic == Arm64Mnemonic.INVALID)
122111
{
123-
return 0;
112+
target = target == Arm64Mnemonic.BL ? Arm64Mnemonic.B : Arm64Mnemonic.BL;
113+
matchingCall = instructions.FirstOrDefault(i => i.Mnemonic == target);
124114
}
115+
116+
return matchingCall.Mnemonic != Arm64Mnemonic.INVALID ? matchingCall.BranchTarget : 0;
125117
}
126118

127119
protected override int GetCallerCount(ulong toWhere)

Cpp2IL.Core/Il2CppApiFunctions/X86KeyFunctionAddresses.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using Cpp2IL.Core.Logging;
@@ -112,23 +112,16 @@ protected override ulong FindFunctionThisIsAThunkOf(ulong thunkPtr, bool priorit
112112
{
113113
var instructions = X86Utils.GetMethodBodyAtVirtAddressNew(thunkPtr, true);
114114

115-
try
116-
{
117-
var target = prioritiseCall ? Mnemonic.Call : Mnemonic.Jmp;
118-
var matchingCall = instructions.FirstOrDefault(i => i.Mnemonic == target);
119-
120-
if (matchingCall.Mnemonic == Mnemonic.INVALID)
121-
{
122-
target = target == Mnemonic.Call ? Mnemonic.Jmp : Mnemonic.Call;
123-
matchingCall = instructions.First(i => i.Mnemonic == target);
124-
}
115+
var target = prioritiseCall ? Mnemonic.Call : Mnemonic.Jmp;
116+
var matchingCall = instructions.FirstOrDefault(i => i.Mnemonic == target);
125117

126-
return matchingCall.NearBranchTarget;
127-
}
128-
catch (Exception)
118+
if (matchingCall.Mnemonic == Mnemonic.INVALID)
129119
{
130-
return 0;
120+
target = target == Mnemonic.Call ? Mnemonic.Jmp : Mnemonic.Call;
121+
matchingCall = instructions.FirstOrDefault(i => i.Mnemonic == target);
131122
}
123+
124+
return matchingCall.Mnemonic != Mnemonic.INVALID ? matchingCall.NearBranchTarget : 0;
132125
}
133126

134127
protected override int GetCallerCount(ulong toWhere)

0 commit comments

Comments
 (0)