Java Code Examples for ghidra.program.model.listing.Instruction#getReferencesFrom()
The following examples show how to use
ghidra.program.model.listing.Instruction#getReferencesFrom() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConstantPropagationContextEvaluator.java From ghidra with Apache License 2.0 | 6 votes |
/** * Add instructions to destination set for unknown computed branches. */ @Override public boolean evaluateDestination(VarnodeContext context, Instruction instruction) { FlowType flowType = instruction.getFlowType(); if (!flowType.isJump()) { return false; } /** * For jump targets, that have no computed reference, add the jump location to a set * to evaluate as a potential switch statement. */ Reference[] refs = instruction.getReferencesFrom(); if (refs.length <= 0 || (refs.length == 1 && refs[0].getReferenceType().isData())) { destSet.addRange(instruction.getMinAddress(), instruction.getMinAddress()); } return false; }
Example 2
Source File: BasicBlockModel.java From ghidra with Apache License 2.0 | 5 votes |
@Override protected boolean hasEndOfBlockFlow(Instruction instr) { FlowType flowType = instr.getFlowType(); if (flowType.isJump() || flowType.isTerminal()) { return true; } for (Reference ref : instr.getReferencesFrom()) { RefType refType = ref.getReferenceType(); if (refType.isJump() || refType.isTerminal()) { return true; } } return false; }
Example 3
Source File: InstructionStasher.java From ghidra with Apache License 2.0 | 5 votes |
private void clearAndSave() { Instruction instruction = program.getListing().getInstructionContaining(address); if (instruction == null) { return; } minAddress = instruction.getMinAddress(); prototype = instruction.getPrototype(); referencesFrom = instruction.getReferencesFrom(); program.getListing().clearCodeUnits(minAddress, instruction.getMaxAddress(), false); }
Example 4
Source File: MultiInstructionMemReference.java From ghidra with Apache License 2.0 | 5 votes |
/** Make the reference on the instruction at the correct location. * * @param instruction to receive reference * @param space reference created in this space * @param scalar used as offset into address space */ private void makeReference(Instruction instruction, int opIndex, Address addr) { if (targetInDelaySlot && instruction.getPrototype().hasDelaySlots()) { instruction = instruction.getNext(); if (instruction == null) { return; } } if (opIndex == -1) { for (int i = 0; i < instruction.getNumOperands(); i++) { int opType = instruction.getOperandType(i); // markup the program counter for any flow if ((opType & OperandType.DYNAMIC) != 0) { opIndex = i; break; } } } if (opIndex == -1) { opIndex = instruction.getNumOperands() - 1; } // check if it already has the reference Reference[] referencesFrom = instruction.getReferencesFrom(); boolean hasRef = Arrays.stream(referencesFrom).anyMatch(p -> p.getToAddress().equals(addr)); if (hasRef) { return; } if (opIndex == -1) { instruction.addMnemonicReference(addr, RefType.DATA, SourceType.ANALYSIS); } else { instruction.addOperandReference(opIndex, addr, RefType.DATA, SourceType.ANALYSIS); } }
Example 5
Source File: FindUnrecoveredSwitchesScript.java From ghidra with Apache License 2.0 | 4 votes |
@Override public void run() throws Exception { InstructionIterator iIter = currentProgram.getListing().getInstructions(true); AddressSet set = new AddressSet(); while (iIter.hasNext()) { Instruction instruction = iIter.next(); FlowType flow = instruction.getFlowType(); if (flow.isJump() && flow.isComputed()) { Reference[] refs = instruction.getReferencesFrom(); boolean hasFlowRef = false; for (Reference ref : refs) { RefType refType = ref.getReferenceType(); if (refType.isFlow() && !refType.isFallthrough()) { hasFlowRef = true; break; } } if (!hasFlowRef) { set.addRange(instruction.getMinAddress(), instruction.getMaxAddress()); } } } Address[] addresses = new Address[set.getNumAddressRanges()]; int i = 0; for (AddressRange range : set) { addresses[i++] = range.getMinAddress(); } if (SystemUtilities.isInHeadlessMode()) { Msg.error( this, "POSSIBLE BAD SWITCHES: The number of possible bad switches is: " + set.getNumAddressRanges()); } else { this.show(addresses); } }