@@ -164,6 +164,7 @@ def chunk_into_words(code, bytes_per_word, byteorder):
164
164
165
165
166
166
def print_ulp_header (h ):
167
+ print ('header' )
167
168
print ('ULP magic : %s (0x%08x)' % (h .magic .to_bytes (4 , 'little' ), h .magic ))
168
169
print ('.text offset : %s (0x%02x)' % (h .text_offset , h .text_offset ))
169
170
print ('.text size : %s (0x%02x)' % (h .text_size , h .text_size ))
@@ -193,6 +194,25 @@ def decode_instruction_and_print(byte_offset, i, verbose=False):
193
194
print (" {:10} = {:3}{}" .format (field , val , extra ))
194
195
195
196
197
+ def print_text_section (code , verbose = False ):
198
+ print ('.text' )
199
+
200
+ words = chunk_into_words (code , bytes_per_word = 4 , byteorder = 'little' )
201
+
202
+ for idx , i in enumerate (words ):
203
+ decode_instruction_and_print (idx << 2 ,i , verbose )
204
+
205
+
206
+ def print_data_section (data_offset , code ):
207
+ print ('.data' )
208
+
209
+ words = chunk_into_words (code , bytes_per_word = 4 , byteorder = 'little' )
210
+
211
+ for idx , i in enumerate (words ):
212
+ asm = "<empty>" if i == 0 else "<non-empty>"
213
+ print_code_line (data_offset + (idx << 2 ), i , asm )
214
+
215
+
196
216
def disassemble_manually (byte_sequence_string , verbose = False ):
197
217
sequence = byte_sequence_string .strip ().replace (' ' ,'' )
198
218
chars_per_instruction = 8
@@ -227,11 +247,15 @@ def disassemble_file(filename, verbose=False):
227
247
if verbose :
228
248
print_ulp_header (h )
229
249
230
- code = data [h .text_offset :]
231
- words = chunk_into_words (code , bytes_per_word = 4 , byteorder = 'little' )
250
+ code = data [h .text_offset :( h . text_offset + h . text_size ) ]
251
+ print_text_section (code , verbose )
232
252
233
- for idx , i in enumerate (words ):
234
- decode_instruction_and_print (idx << 2 , i , verbose )
253
+ if verbose :
254
+ print ('----------------------------------------' )
255
+
256
+ data_offset = h .text_offset + h .text_size
257
+ code = data [data_offset :(data_offset + h .data_size )]
258
+ print_data_section (data_offset - h .text_offset , code )
235
259
236
260
237
261
def print_help ():
0 commit comments