Created
April 13, 2019 17:34
-
-
Save rgov/f1fb93a34a6ec30fe88cf6602776b620 to your computer and use it in GitHub Desktop.
Ghidra - Dump array of structures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Quickly written script to enumerate an array of structures and dump them | |
# as a Python object for further processing. | |
# | |
# This is NOT a good example of Ghidra scripting; I basically figured out | |
# the API by brute force. Hopefully there is a more elegant way to do this. | |
#@author Ryan Govostes | |
#@category Data | |
#@keybinding | |
#@menupath | |
#@toolbar | |
out = [] | |
label = '_thumb_opcodes' | |
array = currentProgram.symbolTable.getLabelOrFunctionSymbols(label, None)[0].object | |
for i in xrange(array.numComponents): | |
el = array.getComponent(i) | |
elout = [] | |
for j in xrange(el.numComponents): | |
m = el.getComponent(j) | |
if isinstance(m.dataType, ghidra.program.database.data.PointerDB): | |
dt = str(m.dataType) | |
value = m.value.offset | |
if isinstance(m.dataType.dataType, ghidra.program.model.data.CharDataType): | |
if m.value.offset == 0: | |
value = None | |
else: | |
start = m.value | |
end = find(start, 0x00) | |
value = '' | |
for k in xrange(0, end.offset - start.offset): | |
b = getDataAt(m.value).getByte(k) | |
value += chr(b) | |
else: | |
dt = m.dataType.CDeclaration | |
value = m.value.value | |
elout.append((dt, value)) | |
out.append(tuple(elout)) | |
print(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment