-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZ_fixDeviceCapabilityTblRefs.py
More file actions
46 lines (35 loc) · 1.19 KB
/
Z_fixDeviceCapabilityTblRefs.py
File metadata and controls
46 lines (35 loc) · 1.19 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
# A helper script to create missing memory references in the _DeviceCapabilityTbl
# @author Nyan Cat
# @category A_Red
# @keybinding
# @menupath
# @toolbar
# pyright: reportMissingImports=false
# pyright: reportUndefinedVariable=false
import binascii
import array
from ghidra.program.model.symbol import SourceType
from ghidra.program.model.symbol import RefType
def makeByteArr(length):
return array.array('b', b'\x00' * length)
def readMem(address, length, littleEndian=True):
memVal = makeByteArr(length)
mem.getBytes(address, memVal)
if littleEndian:
memVal = memVal[::-1]
return binascii.hexlify(memVal)
# https://github.com/HackOvert/GhidraSnippets
def getAddress(offset):
return currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(offset)
mem = currentProgram.getMemory()
tblBegin = 0x4ba0b0
tblEnd = 0x4be480
cur = tblBegin
while cur < tblEnd:
for i in range(5, 10):
target = cur + i * 8
fromAddr = getAddress(target)
toAddr = getAddress(readMem(fromAddr, 8))
refMgr = currentProgram.getReferenceManager()
refMgr.addMemoryReference(fromAddr, toAddr, RefType.DATA, SourceType.ANALYSIS, 0)
cur += 0x50