@@ -77,7 +77,7 @@ def __init__(self, _config, _buffer_output):
7777 self ._is_64b = False
7878
7979 def _print_thread_id (self , thread_id ):
80- print ("{}{:15s }/* TID {:d} */{}" .format (
80+ print ("{}{:16s }/* TID {:d} */{}" .format (
8181 Fore .WHITE ,
8282 self ._color_manager .get_current_color (),
8383 thread_id ,
@@ -279,8 +279,8 @@ def _calculate_backtrace_lengths(self, backtrace):
279279
280280 if b_t_len > max_len :
281281 max_len = b_t_len
282- if len (b_t [ "symbol" ][ "name" ] ) > max_name :
283- max_name = len (b_t [ "symbol" ][ "name" ] )
282+ if len (symbol_name ) > max_name :
283+ max_name = len (symbol_name )
284284
285285 return max_len , max_name , size
286286
@@ -488,6 +488,24 @@ def _parse_args():
488488
489489 return args
490490
491+ def _finish (args , device , pid , scripts ):
492+ print ('Stopping application (name={}, pid={})...' .format (
493+ args .target ,
494+ pid
495+ ), end = "" )
496+ try :
497+ if args .append :
498+ scripts ["append" ].unload ()
499+ scripts ["script" ].unload ()
500+ if args .prepend :
501+ scripts ["prepend" ].unload ()
502+
503+ device .kill (pid )
504+ except frida .InvalidOperationError :
505+ pass
506+ finally :
507+ print ("stopped." )
508+
491509def main ():
492510 """
493511 Main function to process command arguments and to inject Frida.
@@ -516,16 +534,19 @@ def main():
516534 pid = device .get_process (args .target ).pid
517535
518536 session = device .attach (pid )
537+ scripts = {}
519538
520539 if args .prepend :
521540 prepend = session .create_script (args .prepend .read (), runtime = "v8" )
522541 prepend .on ("message" , _custom_script_on_message )
523542 prepend .load ()
524543 args .prepend .close ()
544+ scripts ["prepend" ] = prepend
525545
526546 script = session .create_script (jscode , runtime = "v8" )
527547 script .on ("message" , formatter .on_message )
528548 script .load ()
549+ scripts ["script" ] = script
529550
530551 script .post ({
531552 "type" : "config" ,
@@ -547,6 +568,7 @@ def main():
547568 append .on ("message" , _custom_script_on_message )
548569 append .load ()
549570 args .append .close ()
571+ scripts ["append" ] = append
550572
551573 if args .inject_method == "spawn" :
552574 device .resume (pid )
@@ -564,18 +586,7 @@ def main():
564586 json .dump (formatter .get_output (), args .output , indent = 4 )
565587 args .output .close ()
566588
567- if args .append :
568- append .unload ()
569- script .unload ()
570- if args .prepend :
571- prepend .unload ()
572-
573- print ('Stopping application (name={}, pid={})...' .format (
574- args .target ,
575- pid
576- ), end = "" )
577- device .kill (pid )
578- print ("stopped." )
589+ _finish (args , device , pid , scripts )
579590
580591if __name__ == '__main__' :
581592 main ()
0 commit comments