Created
December 12, 2022 12:06
-
-
Save vngkv123/1a53cc10a192b49b30f5797201793ee0 to your computer and use it in GitHub Desktop.
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
import sys | |
import time | |
import os | |
import traceback | |
import json | |
import idc | |
import idaapi | |
logfilename = idaapi.get_input_file_path() + '.timeida-'+str(int(time.time()*1000))+'.txt' | |
idbfilename = idaapi.get_input_file_path() + '.timeida-'+str(int(time.time()*1000))+'.i64' | |
def log(s): | |
global logfilename | |
with open(logfilename, 'a') as f: | |
f.write(s) | |
f.write('\n') | |
def timeida_on_load(): | |
global idbfilename | |
global analysis_start | |
try: | |
analysis_end = time.time() | |
if os.path.exists(idbfilename): | |
os.unlink(idbfilename) | |
#log('time: {}'.format(analysis_end - analysis_start)) | |
if True: | |
# DBFL_KILL - delete unpacked database | |
# DBFL_COMP - collect garbage | |
idaapi.save_database(idbfilename, idaapi.DBFL_KILL) | |
save_end = time.time() | |
#if os.path.exists(idbfilename): | |
# os.unlink(idbfilename) | |
#log('saved: {}'.format(save_end - analysis_end)) | |
log(json.dumps({"analysis": analysis_end - analysis_start, "save": save_end - analysis_end})) | |
os._exit(os.EX_OK) | |
except Exception: | |
log(traceback.format_exc()) | |
def timeida_wait_for_analysis(): | |
if idaapi.auto_is_ok(): | |
timeida_on_load() | |
return -1 | |
return 100 | |
def timeida_main(): | |
global analysis_start | |
global idbfilename | |
global logfilename | |
try: | |
sync = False | |
for i in idc.ARGV[1:]: | |
if i == '-s': | |
sync = True | |
elif i.startswith('-l'): | |
logfilename = i[2:] | |
elif i.startswith('-i'): | |
idbfilename = i[2:] | |
else: | |
log('unrecognised argument {}'.format(repr(i))) | |
os._exit(1) | |
analysis_start = time.time() | |
if sync: | |
idaapi.auto_wait() | |
timeida_on_load() | |
else: | |
idaapi.register_timer(100, timeida_wait_for_analysis) | |
except Exception: | |
log(traceback.format_exc()) | |
timeida_main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment