-
-
Notifications
You must be signed in to change notification settings - Fork 297
Expand file tree
/
Copy pathArm64InstructionSet.cs
More file actions
61 lines (49 loc) · 2.06 KB
/
Arm64InstructionSet.cs
File metadata and controls
61 lines (49 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cpp2IL.Core.Api;
using Cpp2IL.Core.Graphs;
using Cpp2IL.Core.Il2CppApiFunctions;
using Cpp2IL.Core.ISIL;
using Cpp2IL.Core.Model.Contexts;
using Cpp2IL.Core.Utils;
using LibCpp2IL;
namespace Cpp2IL.Core.InstructionSets;
public class Arm64InstructionSet : Cpp2IlInstructionSet
{
public override ReadOnlyMemory<byte> GetRawBytesForMethod(MethodAnalysisContext context, bool isAttributeGenerator)
{
//Avoid use of capstone where possible
if (true || context is not ConcreteGenericMethodAnalysisContext)
{
//Managed method or attr gen => grab raw byte range between a and b
var startOfNextFunction = (int)MiscUtils.GetAddressOfNextFunctionStart(context.UnderlyingPointer) - 1;
var ptrAsInt = (int)context.UnderlyingPointer;
var count = startOfNextFunction - ptrAsInt;
if (startOfNextFunction > 0)
return LibCpp2IlMain.Binary!.GetRawBinaryContent().Slice(ptrAsInt, count);
}
var instructions = Arm64Utils.GetArm64MethodBodyAtVirtualAddress(context.UnderlyingPointer);
return instructions.SelectMany(i => i.Bytes).ToArray();
}
public override List<InstructionSetIndependentInstruction> GetIsilFromMethod(MethodAnalysisContext context)
{
return [];
}
public override BaseKeyFunctionAddresses CreateKeyFunctionAddressesInstance() => new Arm64KeyFunctionAddresses();
public override string PrintAssembly(MethodAnalysisContext context)
{
var sb = new StringBuilder();
var instructions = Arm64Utils.GetArm64MethodBodyAtVirtualAddress(context.UnderlyingPointer);
var first = true;
foreach (var instruction in instructions)
{
if (!first)
sb.AppendLine();
first = false;
sb.Append("0x").Append(instruction.Address.ToString("X")).Append(" ").Append(instruction.Mnemonic).Append(" ").Append(instruction.Operand);
}
return sb.ToString();
}
}