Skip to content

Commit

Permalink
improve logger and add timer to vxhunter_analysis.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
dark-lbp committed Mar 25, 2020
1 parent 0241b6e commit 6747ab4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
44 changes: 42 additions & 2 deletions firmware_tools/ghidra/vxhunter_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class VxAnalyzer(object):
def __init__(self, logger=None):
self._vx_version = None
self.report = []
self.timer_log = []
self.timer = Timer()

if logger is None:
self.logger = get_logger(self.__name__)
Expand All @@ -28,7 +30,6 @@ def analyze_bss(self):
])
for call_addr in parms_data:
call_parms = parms_data[call_addr]
# print(call_parms)
bss_start_address = call_parms['parms']['parm_1']['parm_value']
self.report.append("bss_start_address: {}".format(hex(bss_start_address)))
bss_length = call_parms['parms']['parm_2']['parm_value']
Expand All @@ -50,7 +51,6 @@ def analyze_bss(self):

else:
self.logger.error("Can't find bzero function in firmware")

self.report.append('{}\r\n'.format("-" * 60))

def analyze_login_accouts(self):
Expand Down Expand Up @@ -374,14 +374,54 @@ def print_report(self):
for line in self.report:
print(line)

# Print timer
print('{:-^60} timer'.format(__name__))
for line in self.timer_log:
print(line)
print('{}\r\n'.format("-" * 60))

def start_analyzer(self):
self.timer.reset()
self.analyze_bss()
timer_log = "analyze bss takes {:.3} seconds".format(self.timer.get_timer())
self.logger.info(timer_log)
self.timer_log.append(timer_log)

self.timer.reset()
self.analyze_login_accouts()
timer_log = "analyze loginUserAdd function takes {:.3} seconds".format(self.timer.get_timer())
self.logger.info(timer_log)
self.timer_log.append(timer_log)

self.timer.reset()
self.analyze_service()
timer_log = "analyze services takes {:.3} seconds".format(self.timer.get_timer())
self.logger.info(timer_log)
self.timer_log.append(timer_log)

self.timer.reset()
self.analyze_symbols()
timer_log = "analyze symbols takes {:.3} seconds".format(self.timer.get_timer())
self.logger.info(timer_log)
self.timer_log.append(timer_log)

self.timer.reset()
self.analyze_netpool()
timer_log = "analyze netpool takes {:.3} seconds".format(self.timer.get_timer())
self.logger.info(timer_log)
self.timer_log.append(timer_log)

self.timer.reset()
self.analyze_function_xref_by_symbol_get()
timer_log = "analyze symFindByName function call takes {:.3} seconds".format(self.timer.get_timer())
self.logger.info(timer_log)
self.timer_log.append(timer_log)

self.timer.reset()
self.analyze_active_task()
timer_log = "analyze active task takes {:.3} seconds".format(self.timer.get_timer())
self.logger.info(timer_log)
self.timer_log.append(timer_log)


if __name__ == '__main__':
Expand Down
7 changes: 1 addition & 6 deletions firmware_tools/ghidra/vxhunter_utility/function_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ def __init__(self, var_node, logger=logger):
"""
self.var_node = var_node
if logger is None:
self.logger = logging.getLogger('FlowNode_logger')
self.logger.setLevel(logging.INFO)
consolehandler = logging.StreamHandler()
console_format = logging.Formatter('[%(levelname)-8s][%(module)s.%(funcName)s] %(message)s')
consolehandler.setFormatter(console_format)
self.logger.addHandler(consolehandler)
self.logger = get_logger(self.__name__)
else:
self.logger = logger

Expand Down

0 comments on commit 6747ab4

Please sign in to comment.