11import binaryninja as bn
22
3- from binaryninja import Symbol , SymbolType , redirect_output_to_log
3+ from binaryninja import Symbol , SymbolType
44
55from .binaryninja_types import *
66from .types import *
77
88NAME = 'Golang Loader Helper'
99GoFixLogger = bn .Logger (0 , NAME )
1010
11-
12- log_debug = GoFixLogger .log_debug
11+ log_debug = GoFixLogger .log_debug
1312log_info = GoFixLogger .log_info
1413log_warn = GoFixLogger .log_warn
1514log_error = GoFixLogger .log_error
@@ -58,7 +57,7 @@ def init_gopclntab(self):
5857 else :
5958 log_error ("Failed to find section .gopclntab" )
6059 return
61-
60+
6261 self .gopclntab = GoPclnTab (start_addr ,
6362 end_addr ,
6463 self .bv [start_addr :end_addr ]
@@ -92,7 +91,7 @@ def init_gopclntab(self):
9291 self .gopclntab .funcnametab = self .gopclntab .range (3 , 4 ) # This contains the names of the functions
9392 self .gopclntab .cutab = self .gopclntab .range (4 , 5 )
9493 self .gopclntab .filetab = self .gopclntab .range (5 , 6 )
95- self .gopclntab .pctab = self .gopclntab .range (6 , 7 )
94+ self .gopclntab .pctab = self .gopclntab .range (6 , 7 )
9695 self .gopclntab .funcdata = self .gopclntab .data (7 ) # This is where the functions info are
9796 self .gopclntab .functab = self .gopclntab .data (7 )
9897 self .gopclntab .functabsize = (self .gopclntab .nfunctab * 2 + 1 ) * functabFieldSize
@@ -111,7 +110,7 @@ def init_gopclntab(self):
111110 self .gopclntab .nfunctab = self .gopclntab .uintptr (8 )
112111 self .gopclntab .funcdata = self .gopclntab .raw
113112 self .gopclntab .funcnametab = self .gopclntab .raw
114- self .gopclntab .functab = self .gopclntab .data_after_offset (8 + self .gopclntab .ptrsize )
113+ self .gopclntab .functab = self .gopclntab .data_after_offset (8 + self .gopclntab .ptrsize )
115114 self .gopclntab .functabsize = (self .gopclntab .nfunctab * 2 + 1 ) * functabFieldSize
116115 self .gopclntab .functab = self .gopclntab .functab [:self .gopclntab .functabsize ]
117116 else :
@@ -154,15 +153,15 @@ def get_function_around(self, addr):
154153 if not bb :
155154 return None
156155 return bb .function
157-
156+
158157 @property
159158 def ptr_size (self ):
160159 return self .gopclntab .ptrsize
161-
160+
162161 def quick_go_version (self ) -> GoVersion :
163162 gopclntab = self .get_section_by_name (".gopclntab" )
164163 start_addr = gopclntab .start
165- return GoVersion .from_magic (self .bv [start_addr :start_addr + 6 ])
164+ return GoVersion .from_magic (self .bv [start_addr :start_addr + 6 ])
166165
167166 def read_varint (self , start_addr : int ) -> (int , int ):
168167 shift = 0
@@ -217,7 +216,7 @@ def rename_functions(self):
217216 renamed += 1
218217 else :
219218 log_warn (f"not using function name { name } for function at { hex (function_addr )} " )
220-
219+
221220 log_info (f"Created { created } functions" )
222221 log_info (f"Renamed { renamed - created } functions" )
223222 log_info (f"Total { renamed } functions" )
@@ -237,8 +236,7 @@ class TypeParser(GoHelper):
237236 'runtime.makechan' ,
238237 'runtime.makemap' ,
239238 'runtime.mapiterinit' ,
240- 'runtime.makeslice'
241- ]
239+ 'runtime.makeslice' ]
242240
243241 MAX_TYPE_LENGHT = 40
244242
@@ -257,7 +255,7 @@ def create_types(self):
257255
258256 for go_type in self .TYPES :
259257 name , type_str = go_type
260- new_type = self .bv .parse_type_string (type_str )
258+ new_type = self .bv .parse_type_string (type_str )
261259 if len (new_type ) == 0 :
262260 log_warn (f"Unable to parse type string { name } " )
263261 continue
@@ -268,7 +266,7 @@ def create_types(self):
268266 log_info ("Searching for functions accessing type objects" )
269267 log_info (f"Will search for { len (self .TYPED )} functions" )
270268 created = 0
271-
269+
272270 for typed_function in self .TYPED :
273271 functions = self .bv .get_functions_by_name (typed_function )
274272 if not functions :
@@ -294,7 +292,7 @@ def create_types(self):
294292 # funny enough `not <void var>` will return `True`
295293 if go_data_type is None :
296294 continue
297-
295+
298296 go_data_type .type = golang_type
299297 # TODO figure out why sometime the type info are not there
300298 # the next portion of code might fail
@@ -346,4 +344,3 @@ def parse_go_file(bv):
346344 fr .join ()
347345 tp = TypeParser (bv )
348346 return tp .start ()
349-
0 commit comments