diff --git a/ghidra_scripts/ReferenceMain.py b/ghidra_scripts/ReferenceMain.py new file mode 100644 index 0000000..674c435 --- /dev/null +++ b/ghidra_scripts/ReferenceMain.py @@ -0,0 +1,32 @@ +# Takes all references to address and points them to same address in main memory +#@author markisha64 +#@category Reference +#@keybinding +#@menupath Tools.References.Reference Main +#@toolbar + +from ghidra.program.flatapi import FlatProgramAPI + +api = FlatProgramAPI(currentProgram) +addFact = api.getAddressFactory() + +refs = currentProgram.referenceManager.getReferencesTo(currentAddress) + +for ref in refs: + data = api.getDataAt(ref.getFromAddress()) + instruction = api.getInstructionAt(ref.getFromAddress()) + + address = addFact.getAddress(ref.getToAddress().toString("ram:")) + refType = ref.getReferenceType() + + if data: + newRef = api.createMemoryReference(data, address, refType) + api.setReferencePrimary(newRef) + + if instruction: + operand = ref.getOperandIndex() + newRef = api.createMemoryReference(instruction, operand, address, refType) + api.setReferencePrimary(newRef) + + api.removeReference(ref) +