Skip to content

Instantly share code, notes, and snippets.

@mrowrpurr
Created April 13, 2024 14:23
Show Gist options
  • Save mrowrpurr/4e5a3a69921ee0e76e7483e7e10120b7 to your computer and use it in GitHub Desktop.
Save mrowrpurr/4e5a3a69921ee0e76e7483e7e10120b7 to your computer and use it in GitHub Desktop.
def rename_fn(name, offset):
print("Offset " + hex(offset) + ", Name " + name)
func = currentProgram.getFunctionManager().getFunctionAt(getAddress(offset))
if func:
func.setName(name, ghidra.program.model.symbol.SourceType.DEFAULT)
else:
print("Creating function...")
cmd = ghidra.app.cmd.function.CreateFunctionCmd(getAddress(offset))
if cmd.applyTo(currentProgram):
print("Created function.")
func = currentProgram.getFunctionManager().getFunctionAt(getAddress(offset))
if func:
func.setName(name, ghidra.program.model.symbol.SourceType.DEFAULT)
else:
print("FAILED to find the function we just created")
else:
print("FAILED to create function at " + hex(offset))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment