From fc1363ea9997524e57cad7afaa88d2fced474040 Mon Sep 17 00:00:00 2001 From: Dayton Pidhirney Date: Thu, 12 Dec 2019 21:49:36 -0700 Subject: [PATCH] Quick update for Python 3 --- trace.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/trace.py b/trace.py index 40cd1a9..5c14198 100755 --- a/trace.py +++ b/trace.py @@ -1,7 +1,6 @@ -#!/usr/bin/python +#!/usr/bin/env python3 import lldb -import commands import optparse import shlex import threading @@ -98,16 +97,16 @@ def instrument_calls_syscalls_and_jmps(self): start_address = symbol.GetStartAddress().GetLoadAddress(self.target) end_address = symbol.GetEndAddress().GetLoadAddress(self.target) instruction_list = symbol.GetInstructions(self.target) - previous_breakpoint_address = 0L + previous_breakpoint_address = 0 for i in instruction_list: address = i.GetAddress().GetLoadAddress(self.target) #print >>self.result, '0x%x' % address #print >>self.result, '{}, {}, {}'.format(i.GetMnemonic(self.target), i.GetOperands(self.target), i.GetComment(self.target)) if address in self.call_breakpoints or address in self.jmp_breakpoints: continue - if previous_breakpoint_address != 0L: + if previous_breakpoint_address != 0: self.subsequent_instruction[previous_breakpoint_address] = address - previous_breakpoint_address = 0L + previous_breakpoint_address = 0 mnemonic = i.GetMnemonic(self.target) if mnemonic != None and mnemonic.startswith('call'): log_v('Putting call breakpoint at 0x%lx' % address) @@ -119,7 +118,7 @@ def instrument_calls_syscalls_and_jmps(self): try: jmp_destination = int(i.GetOperands(self.target), 16) except: - jmp_destination = 0L; + jmp_destination = 0; if jmp_destination < start_address or jmp_destination >= end_address: log_v('Putting jmp breakpoint at 0x%lx' % address) @@ -133,18 +132,18 @@ def instrument_calls_syscalls_and_jmps(self): self.syscall_breakpoints[address] = breakpoint def clear_calls_instrumentation(self): - for breakpoint in self.call_breakpoints.itervalues(): + for breakpoint in self.call_breakpoints.values(): self.target.BreakpointDelete(breakpoint.GetID()) self.call_breakpoints = {} self.subsequent_instruction = {} def clear_syscall_instrumentation(self): - for breakpoint in self.syscall_breakpoints.itervalues(): + for breakpoint in self.syscall_breakpoints.values(): self.target.BreakpointDelete(breakpoint.GetID()) self.syscall_breakpoints = {} def clear_jmps_instrumentation(self): - for breakpoint in self.jmp_breakpoints.itervalues(): + for breakpoint in self.jmp_breakpoints.values(): self.target.BreakpointDelete(breakpoint.GetID()) self.jmp_breakpoints = {} @@ -224,8 +223,6 @@ def get_prog_name(self): return "trace" def exit(self, status=0, msg=None): - if msg != None: - print >>self.result, msg self.exited = True def parse_options(command, result): @@ -416,7 +413,7 @@ def trace(debugger, command, result, internal_dict): depth = depth + 1 log_v('Entered new frame at: 0x%lx' % frame.GetPC()) elif instrumented_frame.is_stopped_on_syscall(frame): - rax = -1L; + rax = -1; register_sets = frame.GetRegisters() for register_set in register_sets: if register_set.GetName() == "General Purpose Registers": @@ -460,4 +457,4 @@ def trace(debugger, command, result, internal_dict): # And the initialization code to add your commands def __lldb_init_module(debugger, internal_dict): debugger.HandleCommand('command script add -f trace.trace trace') - print 'The "trace" python command has been installed and is ready for use.' + print('The "trace" python command has been installed and is ready for use.')