@@ -162,24 +162,24 @@ def chunk_into_words(code, bytes_per_word, byteorder):
162162 return words
163163
164164
165- def print_code_line (i , asm ):
166- lineformat = '{0} {1}'
165+ def print_code_line (byte_offset , i , asm ):
166+ lineformat = '{0:04x } {1} {2 }'
167167 hex = ubinascii .hexlify (i .to_bytes (4 , 'little' ))
168- print (lineformat .format (hex .decode ('utf-8' ), asm ))
168+ print (lineformat .format (byte_offset , hex .decode ('utf-8' ), asm ))
169169
170170
171- def decode_instruction_and_print (i , verbose = False ):
171+ def decode_instruction_and_print (byte_offset , i , verbose = False ):
172172 try :
173173 ins , name = decode_instruction (i )
174174 except Exception as e :
175- print_code_line (i , e )
175+ print_code_line (byte_offset , i , e )
176176 return
177177
178- print_code_line (i , name )
178+ print_code_line (byte_offset , i , name )
179179
180180 if verbose :
181181 for field , val , extra in get_instruction_fields (ins ):
182- print (" {:10} = {:3}{}" .format (field , val , extra ))
182+ print (" {:10} = {:3}{}" .format (field , val , extra ))
183183
184184
185185def disassemble_manually (byte_sequence_string , verbose = False ):
@@ -190,10 +190,10 @@ def disassemble_manually(byte_sequence_string, verbose=False):
190190 for i in range (0 , len (sequence ), chars_per_instruction )
191191 ]
192192
193- for instruction in list :
193+ for idx , instruction in enumerate ( list ) :
194194 byte_sequence = ubinascii .unhexlify (instruction .replace (' ' ,'' ))
195195 i = int .from_bytes (byte_sequence , 'little' )
196- decode_instruction_and_print (i , verbose )
196+ decode_instruction_and_print (idx << 2 , i , verbose )
197197
198198
199199def disassemble_file (filename , verbose = False ):
@@ -203,8 +203,8 @@ def disassemble_file(filename, verbose=False):
203203 code = data [12 :] # text_offset (where code starts) is always 12 for ULP binaries
204204 words = chunk_into_words (code , bytes_per_word = 4 , byteorder = 'little' )
205205
206- for i in words :
207- decode_instruction_and_print (i , verbose )
206+ for idx , i in enumerate ( words ) :
207+ decode_instruction_and_print (idx << 2 , i , verbose )
208208
209209
210210def print_help ():
0 commit comments