@@ -240,25 +240,27 @@ def create_file_objects(self, event, ghidraProgram=None):
240240 )
241241
242242 def get_function_infos (self , func ):
243+ # Initialize all potential conditional values to None
244+ ext_lib = fh_hex = fx_hex = fn_sig = fn_code = calling_convention = None
245+
243246 # Basic Info
244247 entry_point = func .getEntryPoint ()
245248
246249 # Handle External/Thunk logic
247- ext_lib = None
248250 if func .isThunk ():
249251 thunked = func .getThunkedFunction (True )
250252 if thunked and thunked .getExternalLocation ():
251253 ext_lib = thunked .getExternalLocation ().getLibraryName ()
252254 elif func .getExternalLocation ():
253255 ext_lib = func .getExternalLocation ().getLibraryName ()
254256
257+ instruction_count = len (
258+ list (self .ghidraProgram .getListing ().getInstructions (func .getBody (), True ))
259+ )
260+
255261 # FID Hashes
256262 hash_function = self .FIDservice .hashFunction (func )
257- fh_hex = None
258- fx_hex = None
259-
260263 if hash_function :
261- # Handle potential property vs method access in pyghidra/ghidra versions
262264 fh = hash_function .getFullHash ()
263265 fx = hash_function .getSpecificHash ()
264266 fh_hex = Long .toHexString (fh )
@@ -270,6 +272,23 @@ def get_function_infos(self, func):
270272 [format (f & 0xFFFFFFFF , "08x" ) for f in signature .features ]
271273 )
272274
275+ # Decompilation logic
276+ decomp_results = self .decompiler .decompileFunction (func , 30 , self .monitor )
277+ try :
278+ decomp_func = decomp_results .getDecompiledFunction ()
279+ fn_sig = decomp_func .getSignature ()
280+ fn_code = decomp_func .getC ()
281+ except :
282+ print ("There was an error in decompilation!" )
283+
284+ calling_convention = (
285+ str (func .getCallingConventionName ())
286+ if func .getCallingConventionName ()
287+ else None
288+ )
289+ lang_id = self .ghidraProgram .getLanguageID ().toString ()
290+ comp_id = self .ghidraProgram .getCompilerSpec ().getCompilerSpecID ().toString ()
291+ print (lang_id , comp_id )
273292 return {
274293 "function-name" : func .getName (),
275294 "entrypoint-address" : entry_point .getOffset (),
@@ -280,10 +299,14 @@ def get_function_infos(self, func):
280299 "function-scope" : "import" if func .isExternal () else "internal" ,
281300 "decompiler-minor-version" : self .decompiler .getMinorVersion (),
282301 "decompiler-major-version" : self .decompiler .getMajorVersion (),
283- "instruction-count" : func . getBody (). getNumAddresses () ,
302+ "instruction-count" : instruction_count ,
284303 "fid-fh-hash" : fh_hex ,
285304 "fid-fx-hash" : fx_hex ,
286305 "bsim-vector" : vector_csv ,
306+ "decompiled-function" : fn_code ,
307+ "function-signature" : fn_sig ,
308+ "return-type" : func .getReturnType ().getName (),
309+ "calling-convention" : calling_convention ,
287310 }
288311
289312 def _create_object_from_function (self , func ):
@@ -335,6 +358,23 @@ def _create_object_from_function(self, func):
335358
336359 ghidra_function .add_attribute ("bsim-vector" , value = info ["bsim-vector" ])
337360
361+ if info ["decompiled-function" ]:
362+ ghidra_function .add_attribute (
363+ "decompiled-function" , value = info ["decompiled-function" ]
364+ )
365+
366+ if info ["function-signature" ]:
367+ ghidra_function .add_attribute (
368+ "function-signature" , value = info ["function-signature" ]
369+ )
370+
371+ if info ["calling-convention" ]:
372+ ghidra_function .add_attribute (
373+ "calling-convention" , value = info ["calling-convention" ]
374+ )
375+
376+ ghidra_function .add_attribute ("return-type" , value = info ["return-type" ])
377+
338378 logger .info (
339379 f"Created MISP object for { info ['function-name' ]} at { hex (info ['entrypoint-address' ])} "
340380 )
0 commit comments