Skip to content

Instantly share code, notes, and snippets.

@a1ext
Last active September 21, 2018 15:57
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 a1ext/8396d9e151c7fcee100babe9602215f6 to your computer and use it in GitHub Desktop.
Save a1ext/8396d9e151c7fcee100babe9602215f6 to your computer and use it in GitHub Desktop.
# if string reference is not found within 5 instructions - report unresolved
# returns an operand value or None if nothing is found
def find_function_arg(addr, max_insns=5):
for _ in xrange(max_insns):
addr = idc.PrevHead(addr)
if addr == idaapi.BADADDR:
break
if GetMnem(addr) == "mov" and GetOpnd(addr, 0) == 'eax':
return GetOperandValue(addr, 1)
return None
### MAIN ###
decrypt_func_addr = LocByName("decrypt_string")
print "[*] Applying decrypted strings to the database in malware"
for x in XrefsTo(decrypt_func_addr, 0):
ref = find_function_arg(x.frm)
if str(ref) in __result__:
# IDA7 accepts strings in “utf8” encoding so we state it explicitly
MakeComm(x.frm, __result__[str(ref)].encode('utf8'))
else:
print 'No key %s found' % hex(ref)
print "[*] Script finished, check strings in comments"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment