Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. import ghidra.app.script.GhidraScript;
  2. import ghidra.program.model.util.*;
  3. import ghidra.program.model.reloc.*;
  4. import ghidra.program.model.data.*;
  5. import ghidra.program.model.block.*;
  6. import ghidra.program.model.symbol.*;
  7. import ghidra.program.model.scalar.*;
  8. import ghidra.program.model.mem.*;
  9. import ghidra.program.model.listing.*;
  10. import ghidra.program.model.lang.*;
  11. import ghidra.program.model.pcode.*;
  12. import ghidra.program.model.address.*;
  13.  
  14. public class ReferencesCleanup extends GhidraScript {
  15.  
  16.     public void run() throws Exception {
  17.         SymbolTable st = state.getCurrentProgram().getSymbolTable();
  18.         java.util.List<Symbol> sym = st.getGlobalSymbols("start");
  19.         Address start = sym.get(0).getAddress();
  20.         println(String.format("Starting at %s", start.toString()));
  21.  
  22.         ReferenceManager refMgr = currentProgram.getReferenceManager();
  23.         ReferenceIterator iter = refMgr.getReferenceIterator(start);
  24.         while (iter.hasNext()) {
  25.             Reference ref = iter.next();
  26.             Address from = ref.getFromAddress();
  27.             Address to = ref.getToAddress();
  28.             RefType refType = ref.getReferenceType();
  29.             SourceType sourceType = ref.getSource();
  30.             int index = ref.getOperandIndex();
  31.             if (to.toString().startsWith("0")) {
  32.                 println(String.format("Ref from %s to %s: %d", from.toString(), to.toString(), index));
  33.                 refMgr.delete(ref);
  34.                 refMgr.addMemoryReference(from, to.add(0x10000), refType, sourceType, index);
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement