Skip to content

Commit

Permalink
Merge pull request #71 from markisha64/referenceMain
Browse files Browse the repository at this point in the history
feat: Reference Main script
  • Loading branch information
lab313ru authored Jul 29, 2023
2 parents c2ccaff + 012d3c3 commit be58c8a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ghidra_scripts/ReferenceMain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Takes all references to address and points them to same address in main memory
#@author markisha64 <[email protected]>
#@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)

0 comments on commit be58c8a

Please sign in to comment.