1010import idaapi
1111import idc
1212
13+ from heapq import heappush , heappop
1314from bap .utils .run import BapIda
1415
1516
1617class FunctionFinder (BapIda ):
1718 def __init__ (self ):
18- super (FunctionFinder , self ).__init__ ()
19+ super (FunctionFinder , self ).__init__ (symbols = False )
1920 self .action = 'looking for function starts'
2021 self .syms = self .tmpfile ('syms' , mode = 'r' )
2122 self .args += [
2223 '--print-symbol-format' , 'addr' ,
2324 '--dump' , 'symbols:{0}' .format (self .syms .name )
2425 ]
2526
27+ # we can be a little bit more promiscuous since IDA will ignore
28+ # function starts that occur in the middle of a function
29+ if 'byteweight' in self .plugins and not \
30+ '--no-byteweight' in self .args :
31+ self .args += [
32+ '--byteweight-threshold' , '0.5' ,
33+ '--byteweight-length' , '4' ,
34+ ]
35+
2636
2737class BAP_Functions (idaapi .plugin_t ):
28- """Plugin to get functions from BAP and mark them in IDA. """
38+ """Uses BAP to find missed functions """
2939
3040 flags = idaapi .PLUGIN_FIX
3141 comment = "BAP Functions Plugin"
@@ -40,15 +50,13 @@ def mark_functions(self):
4050 analysis .run ()
4151
4252 def add_starts (self , bap ):
43- idaapi . refresh_idaview_anyway ()
53+ syms = []
4454 for line in bap .syms :
45- line = line .strip ()
46- if len (line ) == 0 :
47- continue
48- addr = int (line , 16 )
49- end_addr = idaapi .BADADDR
50- idaapi .add_func (addr , end_addr )
55+ heappush (syms , int (line , 16 ))
56+ for i in range (len (syms )):
57+ idaapi .add_func (heappop (syms ), idaapi .BADADDR )
5158 idc .Refresh ()
59+ idaapi .refresh_idaview_anyway ()
5260
5361 def init (self ):
5462 """Initialize Plugin."""
0 commit comments