Skip to content

Instantly share code, notes, and snippets.

@camas
Created November 26, 2020 01:27
Show Gist options
  • Save camas/c0aff6e6eb77dae3f1eeab7b35aee7c2 to your computer and use it in GitHub Desktop.
Save camas/c0aff6e6eb77dae3f1eeab7b35aee7c2 to your computer and use it in GitHub Desktop.
Ghidra script that creates signatures for memory searching
# Creates a search signature for the highlighted instructions
# Highlighted area should be continuous
#@author Camas
area_min = currentSelection.getMinAddress()
area_max = currentSelection.getMaxAddress()
current = area_min
output = []
while True:
unit = currentProgram.getListing().getCodeUnitAt(current)
unit_bytes = unit.getBytes()
should_add = True
for r in unit.getReferencesFrom():
a = r.getFromAddress()
b = r.getToAddress()
diff = abs(a.subtract(b))
if diff > 200:
should_add = False
break
if should_add:
for b in unit_bytes:
if b < 0:
b += 0x100
output.append("{:02x}".format(b))
else:
for _ in range(len(unit_bytes)):
output.append("??")
current = current.add(len(unit_bytes))
if current >= area_max:
break
print(" ".join(output))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment