Skip to content

Instantly share code, notes, and snippets.

@Varriount
Created September 30, 2023 00:18
Show Gist options
  • Save Varriount/c3abdb99274c44c063f355c93748665a to your computer and use it in GitHub Desktop.
Save Varriount/c3abdb99274c44c063f355c93748665a to your computer and use it in GitHub Desktop.
Small Python snippet to find small functions in Ghidra (to mark as inline)
TARGET_FUNCTION_PREFIXES = [
'FUN_', # Default prefix for functions found by Ghidra
'f_p__', # CUSTOM_AUTO_FUNC_PREFIX
'f_p__TS__', # CUSTOM_AUTO_THREAD_FUNC_PREFIX
]
from pprint import pprint
cp = currentProgram
listing = cp.getListing()
functions = [f for f in listing.getFunctions(True)]
def address_count(function):
return function.getBody().getNumAddresses()
def unit_count(function):
units = listing.getCodeUnits(function.getBody(), True)
result = 0
for _ in units:
result += 1
return result
candidates = [
f for f in functions
if f.getName().startswith(tuple(TARGET_FUNCTION_PREFIXES))
if not f.isInline()
if not f.isThunk()
]
c = [f for f in candidates if unit_count(f) <= 7];pprint(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment