Skip to content

Instantly share code, notes, and snippets.

@rgov
Created April 13, 2019 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgov/f1fb93a34a6ec30fe88cf6602776b620 to your computer and use it in GitHub Desktop.
Save rgov/f1fb93a34a6ec30fe88cf6602776b620 to your computer and use it in GitHub Desktop.
Ghidra - Dump array of structures
# 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