Skip to content

Instantly share code, notes, and snippets.

@ret5et
Last active July 19, 2017 10:40
Show Gist options
  • Save ret5et/cffe128540909398ba7a to your computer and use it in GitHub Desktop.
Save ret5et/cffe128540909398ba7a to your computer and use it in GitHub Desktop.
Dump all string in function
#BUGS: not work with unicode strings
from idaapi import *
from idautils import *
import idc
KEY="Shift-D"
def func_dump_str():
fu = get_func(here())
f_end = fu.endEA
f_start = fu.startEA
f_name = GetFunctionName(f_start)
item = idc.NextHead(f_start-1, f_end)
non_ascii = 0
print "~~~ %s strings:" % f_name
while item != BADADDR:
_next = idc.NextHead(item, f_end)
for dref in DataRefsFrom(_next):
_str = GetString(dref)
if _str is not None:
try:
_str.decode('ascii')
except UnicodeDecodeError:
non_ascii += 1
continue
print "0x%x - %s " % (_next, repr(_str))
item = _next
print "NonASCII symbols: %d" % non_ascii
def main ():
hotkey_ctx = idaapi.add_hotkey(KEY, func_dump_str)
if hotkey_ctx is None:
print("DumpStrings - Failed to register hotkey!")
del hotkey_ctx
else:
print("DumpStrings - Hotkey (%s)registered!" % KEY)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment