-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBNRelocationHandlerCore.cs
More file actions
113 lines (104 loc) · 2.57 KB
/
Copy pathBNRelocationHandlerCore.cs
File metadata and controls
113 lines (104 loc) · 2.57 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Runtime.InteropServices;
namespace BinaryNinja
{
public partial class RelocationHandler
{
private sealed class CoreRelocationHandler : RelocationHandler
{
internal CoreRelocationHandler(IntPtr handle, bool owner)
: base(handle, owner)
{
}
public override bool GetRelocationInfo(
BinaryView view,
Architecture architecture,
RelocationInfo[] result
)
{
return this.GetRelocationInfoCore(view, architecture, result);
}
public override bool ApplyRelocation(
BinaryView view,
Architecture architecture,
Relocation relocation,
IntPtr destination,
ulong length
)
{
RelocationHandler.ValidateRelocationArguments(
view, architecture, relocation
);
return NativeMethods.BNRelocationHandlerApplyRelocation(
this.handle,
view.DangerousGetHandle(),
architecture.DangerousGetHandle(),
relocation.DangerousGetHandle(),
destination,
length
);
}
public override ulong GetOperandForExternalRelocation(
IntPtr data,
ulong address,
ulong length,
LowLevelILFunction lowLevelIl,
Relocation relocation
)
{
if (null == lowLevelIl)
{
throw new ArgumentNullException(nameof(lowLevelIl));
}
if (null == relocation)
{
throw new ArgumentNullException(nameof(relocation));
}
return NativeMethods.BNRelocationHandlerGetOperandForExternalRelocation(
this.handle,
data,
address,
length,
lowLevelIl.DangerousGetHandle(),
relocation.DangerousGetHandle()
);
}
}
private bool GetRelocationInfoCore(
BinaryView view,
Architecture architecture,
RelocationInfo[] result
)
{
RelocationHandler.ValidateRelocationInfoArguments(
view, architecture, result
);
BNRelocationInfo[] nativeResult =
RelocationHandler.CreateNativeRelocationInfo(result);
using (ScopedAllocator allocator = new ScopedAllocator())
{
IntPtr nativePointer = allocator.AllocStructArray(nativeResult);
bool success = NativeMethods.BNRelocationHandlerGetRelocationInfo(
this.handle,
view.DangerousGetHandle(),
architecture.DangerousGetHandle(),
nativePointer,
(ulong)nativeResult.Length
);
if (!success)
{
return false;
}
int nativeSize = Marshal.SizeOf<BNRelocationInfo>();
for (int i = 0; i < result.Length; i++)
{
BNRelocationInfo native = Marshal.PtrToStructure<BNRelocationInfo>(
IntPtr.Add(nativePointer, i * nativeSize)
);
result[i] = RelocationInfo.FromNative(native);
}
return true;
}
}
}
}