@@ -66,7 +66,7 @@ def __init__(self, ea, n=16):
66
66
struct2 = StructCast (address , n )
67
67
this_pattern = [x .type for x in struct2 .entries [p1 :p2 + 1 ]]
68
68
if this_pattern == pattern_to_match :
69
- entry_element_count = ( address - ea ) / self .element_size
69
+ entry_element_count = int (( address - ea ) / self .element_size )
70
70
break
71
71
72
72
if entry_element_count is not None and entry_element_count > 0 :
@@ -120,7 +120,7 @@ def get_entry_pair(self, structure):
120
120
class Struct (object ):
121
121
122
122
def __init__ (self , ** kwargs ):
123
- for (k , v ) in kwargs .iteritems ():
123
+ for (k , v ) in kwargs .items ():
124
124
setattr (self , k , v )
125
125
126
126
@@ -159,8 +159,8 @@ def valid_function_name(self, name):
159
159
def search (self ):
160
160
patterns = []
161
161
162
- print "Searching for data structure arrays from %s to %s" % \
163
- (hex (self .start ), hex (self .stop ))
162
+ print ( "Searching for data structure arrays from %s to %s" % \
163
+ (hex (self .start ), hex (self .stop )))
164
164
165
165
ea = self .start
166
166
while ea < self .stop :
@@ -186,14 +186,14 @@ def search(self):
186
186
else :
187
187
j += 1
188
188
189
- print "Found an array of %d structures at 0x%X - 0x%X. Each " \
189
+ print ( "Found an array of %d structures at 0x%X - 0x%X. Each " \
190
190
"entry has %d elements of %d bytes each." % \
191
191
(patterns [i ].num_entries , patterns [i ].start , patterns [i ].stop ,
192
- patterns [i ].num_elements , patterns [i ].element_size )
192
+ patterns [i ].num_elements , patterns [i ].element_size ))
193
193
194
- print "Array element #%d is the address pointer, and element #%d " \
194
+ print ( "Array element #%d is the address pointer, and element #%d " \
195
195
"is the address pointer name.\n " % \
196
- (patterns [i ].function_element , patterns [i ].name_element )
196
+ (patterns [i ].function_element , patterns [i ].name_element ))
197
197
198
198
i += 1
199
199
@@ -213,29 +213,29 @@ def parse_function_tables(self):
213
213
ea + (pattern .function_element * pattern .element_size ))
214
214
215
215
new_function_name = ida_shims .get_strlit_contents (
216
- string_address )
216
+ string_address ). decode ( "utf8" )
217
217
current_function_name = ida_shims .get_name (function_address )
218
218
219
219
if not self .valid_function_name (new_function_name ):
220
- print "ERROR: '%s' is not a valid function name. This is " \
220
+ print ( "ERROR: '%s' is not a valid function name. This is " \
221
221
"likely not a function table, or I have parsed it " \
222
- "incorrectly!" % new_function_name
223
- print " Ignoring all entries in the structures " \
222
+ "incorrectly!" % new_function_name )
223
+ print ( " Ignoring all entries in the structures " \
224
224
"between 0x%X and 0x%X.\n " % (pattern .start ,
225
- pattern .stop )
225
+ pattern .stop ))
226
226
name2func = {}
227
227
break
228
228
elif current_function_name .startswith ("sub_" ):
229
229
name2func [new_function_name ] = function_address
230
230
231
231
ea += (pattern .num_elements * pattern .element_size )
232
232
233
- for (name , address ) in name2func .iteritems ():
234
- print "0x%.8X => %s" % (address , name )
233
+ for (name , address ) in name2func .items ():
234
+ print ( "0x%.8X => %s" % (address , name ) )
235
235
ida_shims .set_name (address , name )
236
236
count += 1
237
237
238
- print "Renamed %d functions!" % count
238
+ print ( "Renamed %d functions!" % count )
239
239
240
240
241
241
class FunctionNameology (object ):
@@ -254,16 +254,16 @@ def rename_functions(self, debug=True, dry_run=False):
254
254
'''
255
255
count = 0
256
256
257
- for (function_address , function_name ) in self .func2str_mappings ().iteritems ():
257
+ for (function_address , function_name ) in self .func2str_mappings ().items ():
258
258
if ida_shims .get_name (function_address ).startswith ("sub_" ):
259
259
if dry_run or ida_shims .set_name (function_address , function_name ):
260
260
if debug :
261
- print "0x%.8X => %s" % (function_address ,
262
- function_name )
261
+ print ( "0x%.8X => %s" % (function_address ,
262
+ function_name ))
263
263
count += 1
264
264
265
265
if debug :
266
- print "Renamed %d functions based on unique string xrefs!" % count
266
+ print ( "Renamed %d functions based on unique string xrefs!" % count )
267
267
268
268
return count
269
269
@@ -280,12 +280,12 @@ def func2str_mappings(self):
280
280
if self .is_valid_function_name (str (string )):
281
281
function_address = self .str2func (string .ea )
282
282
if function_address is not None :
283
- if not function_map . has_key ( function_address ) :
283
+ if function_address not in function_map :
284
284
function_map [function_address ] = []
285
285
function_map [function_address ].append (str (string ))
286
286
287
287
# Each function must have only one candidate string
288
- for function_address in function_map .keys ():
288
+ for function_address in list ( function_map .keys () ):
289
289
if len (function_map [function_address ]) == 1 :
290
290
function_map [function_address ] = function_map [function_address ][0 ]
291
291
else :
@@ -363,23 +363,23 @@ def stringify(self):
363
363
if ea == idc .BADADDR :
364
364
ea = ida_shims .get_first_seg ()
365
365
366
- print "Looking for possible strings starting at: 0x%X..." % ea ,
366
+ print ( "Looking for possible strings starting at: 0x%X..." % ea , end = ' ' )
367
367
368
368
for s in idautils .Strings ():
369
369
if s .ea > ea :
370
370
if not ida_shims .is_strlit (ida_shims .get_full_flags (s .ea )) \
371
371
and ida_shims .create_strlit (s .ea , 0 ):
372
372
n += 1
373
373
374
- print "created %d new ASCII strings" % n
374
+ print ( "created %d new ASCII strings" % n )
375
375
376
376
# Converts remaining data into DWORDS.
377
377
def datify (self ):
378
378
ea = self .get_start_ea (self .DATA )
379
379
if ea == idc .BADADDR :
380
380
ea = ida_shims .get_first_seg ()
381
381
382
- print "Converting remaining data to DWORDs..." ,
382
+ print ( "Converting remaining data to DWORDs..." , end = ' ' )
383
383
384
384
while ea != idc .BADADDR :
385
385
flags = ida_shims .get_full_flags (ea )
@@ -391,14 +391,14 @@ def datify(self):
391
391
392
392
ea = ida_shims .next_addr (ea )
393
393
394
- print "done."
394
+ print ( "done." )
395
395
396
396
self ._fix_data_offsets ()
397
397
398
398
def pointify (self ):
399
399
counter = 0
400
400
401
- print "Renaming pointers..." ,
401
+ print ( "Renaming pointers..." , end = ' ' )
402
402
403
403
for (name_ea , name ) in idautils .Names ():
404
404
for xref in idautils .XrefsTo (name_ea ):
@@ -415,13 +415,13 @@ def pointify(self):
415
415
#else:
416
416
# print "Failed to create name '%s'!" % new_name
417
417
418
- print "renamed %d pointers" % counter
418
+ print ( "renamed %d pointers" % counter )
419
419
420
420
def _fix_data_offsets (self ):
421
421
ea = 0
422
422
count = 0
423
423
424
- print "Fixing unresolved offset xrefs..." ,
424
+ print ( "Fixing unresolved offset xrefs..." , end = ' ' )
425
425
426
426
while ea != idaapi .BADADDR :
427
427
(ea , n ) = idaapi .find_notype (ea , idaapi .SEARCH_DOWN )
@@ -435,7 +435,7 @@ def _fix_data_offsets(self):
435
435
(idaapi .dr_O | idaapi .XREF_USER ))
436
436
count += 1
437
437
438
- print "created %d new data xrefs" % count
438
+ print ( "created %d new data xrefs" % count )
439
439
440
440
# Creates functions and code blocks
441
441
def codeify (self , ea = idc .BADADDR ):
@@ -447,8 +447,8 @@ def codeify(self, ea=idc.BADADDR):
447
447
if ea == idc .BADADDR :
448
448
ea = ida_shims .get_first_seg ()
449
449
450
- print "\n Looking for undefined code starting at: %s:0x%X" % \
451
- (ida_shims .get_segm_name (ea ), ea )
450
+ print ( "\n Looking for undefined code starting at: %s:0x%X" % \
451
+ (ida_shims .get_segm_name (ea ), ea ))
452
452
453
453
while ea != idc .BADADDR :
454
454
try :
@@ -466,8 +466,8 @@ def codeify(self, ea=idc.BADADDR):
466
466
467
467
ea = ida_shims .next_addr (ea )
468
468
469
- print "Created %d new functions and %d new code blocks\n " % \
470
- (func_count , code_count )
469
+ print ( "Created %d new functions and %d new code blocks\n " % \
470
+ (func_count , code_count ))
471
471
472
472
473
473
try :
0 commit comments