Java Code Examples for ghidra.program.model.address.Address#isStackAddress()
The following examples show how to use
ghidra.program.model.address.Address#isStackAddress() .
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: VariableUtilities.java From ghidra with Apache License 2.0 | 6 votes |
private static Varnode shrinkVarnode(Varnode varnode, int sizeReduction, VariableStorage curStorage, int newSize, DataType dataType, boolean alignStack, Function function) throws InvalidInputException { Address addr = varnode.getAddress(); if (addr.isStackAddress()) { return resizeStackVarnode(varnode, varnode.getSize() - sizeReduction, curStorage, newSize, dataType, alignStack, function); } boolean isRegister = function.getProgram().getRegister(varnode) != null; boolean bigEndian = function.getProgram().getMemory().isBigEndian(); boolean complexDt = (dataType instanceof Composite) || (dataType instanceof Array); if (bigEndian && (isRegister || !complexDt)) { return new Varnode(varnode.getAddress().add(sizeReduction), varnode.getSize() - sizeReduction); } return new Varnode(varnode.getAddress(), varnode.getSize() - sizeReduction); }
Example 2
Source File: OperandFieldMouseHandler.java From ghidra with Apache License 2.0 | 6 votes |
private boolean goToRegisterVariable(Navigatable navigatable, CodeUnit codeUnit, OperandFieldLocation loc, GoToService goToService) { Address refAddr = loc.getRefAddress(); Address cuAddr = codeUnit.getMinAddress(); if (refAddr == null || refAddr.isStackAddress()) { return false; } Program p = codeUnit.getProgram(); Register reg = p.getRegister(refAddr, 1); if (reg == null) { return false; } Variable variable = p.getFunctionManager().getReferencedVariable(cuAddr, refAddr, reg.getMinimumByteSize(), !isWrite((Instruction) codeUnit, loc.getOperandIndex(), reg)); if (variable == null) { return false; } ProgramLocation pl = new VariableNameFieldLocation(navigatable.getProgram(), variable, 0); goToService.goTo(navigatable, pl, navigatable.getProgram()); return true; }
Example 3
Source File: VariableImpl.java From ghidra with Apache License 2.0 | 6 votes |
private VariableStorage computeStorage(Address storageAddr) throws InvalidInputException { if (storageAddr == null) { return VariableStorage.UNASSIGNED_STORAGE; } if (!storageAddr.isMemoryAddress() && !storageAddr.isRegisterAddress() && !storageAddr.isStackAddress() && !storageAddr.isHashAddress()) { throw new InvalidInputException("Invalid storage address specified: space=" + storageAddr.getAddressSpace().getName()); } int dtLength = dataType.getLength(); if (!storageAddr.isStackAddress()) { return new VariableStorage(program, storageAddr, dtLength); } long stackOffset = storageAddr.getOffset(); if (stackOffset < 0 && -stackOffset < dtLength) { // do not allow stack element to span the 0-offset // i.e., maintain separation of locals and params throw new InvalidInputException( "Data type does not fit within stack frame constraints (stack offset=" + stackOffset + ", size=" + dtLength); } return new VariableStorage(program, new Varnode(storageAddr, dtLength)); }
Example 4
Source File: VariableImpl.java From ghidra with Apache License 2.0 | 6 votes |
private Varnode shrinkVarnode(Varnode varnode, int sizeReduction, VariableStorage curStorage, int newSize, DataType type) throws InvalidInputException { Address addr = varnode.getAddress(); if (addr.isStackAddress()) { return resizeStackVarnode(varnode, varnode.getSize() - sizeReduction, curStorage, newSize, type); } boolean isRegister = program.getRegister(varnode) != null; boolean bigEndian = program.getMemory().isBigEndian(); boolean complexDt = (type instanceof Composite) || (type instanceof Array); if (bigEndian && (isRegister || !complexDt)) { return new Varnode(varnode.getAddress().add(sizeReduction), varnode.getSize() - sizeReduction); } return new Varnode(varnode.getAddress(), varnode.getSize() - sizeReduction); }
Example 5
Source File: EditReferencesModel.java From ghidra with Apache License 2.0 | 6 votes |
static RefType[] getAllowedRefTypes(Program program, Reference ref) { Address toAddr = ref.getToAddress(); if (toAddr.isStackAddress()) { return RefTypeFactory.getStackRefTypes(); } if (toAddr.isRegisterAddress()) { return RefTypeFactory.getDataRefTypes(); } if (toAddr.isMemoryAddress()) { if (program.getAddressFactory().getDefaultAddressSpace() == toAddr.getAddressSpace() || isComputedFlow(program, ref)) { return RefTypeFactory.getMemoryRefTypes(); } return RefTypeFactory.getDataRefTypes(); } if (toAddr.isExternalAddress()) { return RefTypeFactory.getExternalRefTypes(); } throw new IllegalArgumentException("Unsupported reference"); }
Example 6
Source File: VarnodeInfo.java From ghidra with Apache License 2.0 | 6 votes |
public void setVarnode(Address address, Integer size) { this.address = address; this.size = size; register = getRegister(program, address, size); if (address == null) { return; } if (address.isRegisterAddress() || register != null) { type = VarnodeType.Register; } else if (address.isStackAddress()) { type = VarnodeType.Stack; } else if (address.isMemoryAddress()) { type = VarnodeType.Memory; } else { throw new IllegalArgumentException("Illegal varnode address type"); } }
Example 7
Source File: VarnodeLocationTableCellRenderer.java From ghidra with Apache License 2.0 | 6 votes |
@Override public Component getTableCellRendererComponent(GTableCellRenderingData data) { JLabel label = (JLabel) super.getTableCellRendererComponent(data); Object value = data.getValue(); if (value instanceof Address) { Address address = (Address) value; if (address.isStackAddress()) { label.setText(NumericUtilities.toSignedHexString(address.getOffset())); } } return label; }
Example 8
Source File: AbstractDecompilerAction.java From ghidra with Apache License 2.0 | 5 votes |
/** * Find the HighSymbol the decompiler associates with a specific address. * @param addr is the specific address * @param highFunction is the decompiler results in which to search for the symbol * @return the matching symbol or null if no symbol exists */ private static HighSymbol findHighSymbol(Address addr, HighFunction highFunction) { HighSymbol highSymbol = null; if (addr.isStackAddress()) { LocalSymbolMap lsym = highFunction.getLocalSymbolMap(); highSymbol = lsym.findLocal(addr, null); } else { GlobalSymbolMap gsym = highFunction.getGlobalSymbolMap(); highSymbol = gsym.getSymbol(addr); } return highSymbol; }
Example 9
Source File: GoToHelper.java From ghidra with Apache License 2.0 | 5 votes |
public ProgramLocation getLocation(Program program, Address currentAddress, Address gotoAddress) { ProgramLocation loc = getProgramLocationForAddress(gotoAddress, program); if (loc != null) { return loc; } if (gotoAddress.isStackAddress() || gotoAddress.isRegisterAddress()) { // Convert stack/register address into variable address Function func = program.getFunctionManager().getFunctionContaining(currentAddress); if (func != null) { for (Variable v : func.getAllVariables()) { VariableStorage storage = v.getVariableStorage(); if (storage.contains(gotoAddress)) { return new VariableNameFieldLocation(program, v, 0); } } } } SymbolTable symTable = program.getSymbolTable(); ReferenceManager refMgr = program.getReferenceManager(); Reference ref = refMgr.getReference(currentAddress, gotoAddress, 0); Symbol symbol = symTable.getSymbol(ref); if (symbol != null) { return symbol.getProgramLocation(); } return null; }
Example 10
Source File: EditReferenceDialog.java From ghidra with Apache License 2.0 | 5 votes |
private void configureEditReference(CodeUnit cu, Reference ref) { setTitle("Edit Reference"); setHelpLocation(EDIT_HELP); applyButton.setText("Update"); memRefChoice.setEnabled(false); extRefChoice.setEnabled(false); stackRefChoice.setEnabled(false); regRefChoice.setEnabled(false); Address toAddress = ref.getToAddress(); if (toAddress.isRegisterAddress() || cu.getProgram().getRegister(toAddress) != null) { regRefPanel.initialize(cu, ref); regRefChoice.setSelected(true); regRefChoice.setEnabled(true); if (toAddress.isMemoryAddress()) { memRefPanel.initialize(cu, ref); memRefChoice.setEnabled(true); } } else if (toAddress.isStackAddress()) { stackRefPanel.initialize(cu, ref); stackRefChoice.setSelected(true); stackRefChoice.setEnabled(true); } else if (toAddress.isMemoryAddress()) { memRefPanel.initialize(cu, ref); memRefChoice.setSelected(true); memRefChoice.setEnabled(true); } else if (toAddress.isExternalAddress()) { extRefPanel.initialize(cu, ref); extRefChoice.setSelected(true); extRefChoice.setEnabled(true); } else { throw new AssertException("Unknown address type"); } }
Example 11
Source File: SymbolRenderer.java From ghidra with Apache License 2.0 | 5 votes |
private String getAddressString(Address address) { if (address.isStackAddress()) { return getStackAddressString(address); } else if (address.isRegisterAddress()) { return getRegisterAddressString(address); } else if (address.isExternalAddress() || address == Address.NO_ADDRESS) { return ""; } return address.toString(); }
Example 12
Source File: ASTGraphTask.java From ghidra with Apache License 2.0 | 5 votes |
private String translateVarnode(Varnode node, boolean useVarName) { if (node == null) { return "null"; } Program p = hfunction.getFunction().getProgram(); Address addr = node.getAddress(); if (node.isConstant()) { return "#" + NumericUtilities.toHexString(addr.getOffset(), node.getSize()); } else if (node.isUnique()) { return "u_" + Long.toHexString(addr.getOffset()); } else if (addr.isRegisterAddress()) { Register r = p.getRegister(addr, node.getSize()); if (r == null) { r = p.getRegister(addr); } if (r != null) { return r.getName(); } } else if (addr.isStackAddress()) { if (useVarName) { HighVariable var = node.getHigh(); if (var != null) { return var.getName(); } } return "Stack[" + NumericUtilities.toSignedHexString(addr.getOffset()) + "]"; } else if (addr.isMemoryAddress()) { return addr.toString(true); } return node.toString(); }
Example 13
Source File: VariableImpl.java From ghidra with Apache License 2.0 | 5 votes |
private Varnode expandVarnode(Varnode varnode, int sizeIncrease, VariableStorage curStorage, int newSize, DataType type) throws InvalidInputException { Address addr = varnode.getAddress(); if (addr.isStackAddress()) { return resizeStackVarnode(varnode, varnode.getSize() + sizeIncrease, curStorage, newSize, type); } int size = varnode.getSize() + sizeIncrease; boolean bigEndian = program.getMemory().isBigEndian(); Register reg = program.getRegister(varnode); Address vnAddr = varnode.getAddress(); if (reg != null) { // Register expansion Register newReg = reg; while ((newReg.getMinimumByteSize() < size)) { newReg = newReg.getParentRegister(); if (newReg == null) { throw new InvalidInputException("Current storage can't be expanded to " + newSize + " bytes: " + curStorage.toString()); } } if (bigEndian) { vnAddr = vnAddr.add(newReg.getMinimumByteSize() - size); return new Varnode(vnAddr, size); } } boolean complexDt = (type instanceof Composite) || (type instanceof Array); if (bigEndian && !complexDt) { return new Varnode(vnAddr.subtract(sizeIncrease), size); } return new Varnode(vnAddr, size); }
Example 14
Source File: VariableUtilities.java From ghidra with Apache License 2.0 | 5 votes |
private static Varnode expandVarnode(Varnode varnode, int sizeIncrease, VariableStorage curStorage, int newSize, DataType dataType, boolean alignStack, Function function) throws InvalidInputException { Address addr = varnode.getAddress(); if (addr.isStackAddress()) { return resizeStackVarnode(varnode, varnode.getSize() + sizeIncrease, curStorage, newSize, dataType, alignStack, function); } int size = varnode.getSize() + sizeIncrease; boolean bigEndian = function.getProgram().getMemory().isBigEndian(); Register reg = function.getProgram().getRegister(varnode); Address vnAddr = varnode.getAddress(); if (reg != null) { // Register expansion Register newReg = reg; while ((newReg.getMinimumByteSize() < size)) { newReg = newReg.getParentRegister(); if (newReg == null) { throw new InvalidInputException("Storage can't be expanded to " + newSize + " bytes: " + curStorage.toString()); } } vnAddr = newReg.getAddress(); if (bigEndian) { vnAddr = vnAddr.add(newReg.getMinimumByteSize() - size); return new Varnode(vnAddr, size); } } boolean complexDt = (dataType instanceof Composite) || (dataType instanceof Array); if (bigEndian && !complexDt) { return new Varnode(vnAddr.subtract(sizeIncrease), size); } return new Varnode(vnAddr, size); }
Example 15
Source File: LocalSymbolMap.java From ghidra with Apache License 2.0 | 5 votes |
public MappedVarKey(Address addr, Address pcad) { this.addr = addr; if (!addr.isStackAddress()) { // first use not supported for stack pcaddr = pcad; } }
Example 16
Source File: BigRefListV0.java From ghidra with Apache License 2.0 | 5 votes |
private ReferenceDB getRef(Record rec) { long symbolID = -1; long addr = rec.getLongValue(ADDRESS_COL); RefListFlagsV0 flags = new RefListFlagsV0(rec.getByteValue(FLAGS_COL)); RefType refType = RefTypeFactory.get(rec.getByteValue(TYPE_COL)); byte opIndex = rec.getByteValue(OPINDEX_COL); SourceType source = flags.getSource(); long offsetOrShift = 0; if (flags.hasSymbolID()) { symbolID = rec.getLongValue(SYMBOL_ID_COL); } Address from = isFrom ? address : addrMap.decodeAddress(addr); Address to = isFrom ? addrMap.decodeAddress(addr) : address; if (flags.isOffsetRef() || flags.isShiftRef()) { offsetOrShift = rec.getLongValue(OFFSET_COL); if (flags.isShiftRef()) { return new ShiftedReferenceDB(program, from, to, refType, opIndex, source, flags.isPrimary(), symbolID, (int) offsetOrShift); } return new OffsetReferenceDB(program, from, to, refType, opIndex, source, flags.isPrimary(), symbolID, offsetOrShift); } else if (to.isExternalAddress()) { return new ExternalReferenceDB(program, from, to, refType, opIndex, source); } else if (from.equals(Address.EXT_FROM_ADDRESS)) { return new EntryPointReferenceDB(from, to, refType, opIndex, source, flags.isPrimary(), symbolID); } else if (to.isStackAddress()) { return new StackReferenceDB(program, from, to, refType, opIndex, source, flags.isPrimary(), symbolID); } return new MemReferenceDB(program, from, to, refType, opIndex, source, flags.isPrimary(), symbolID); }
Example 17
Source File: AddressBasedLocation.java From ghidra with Apache License 2.0 | 4 votes |
private static String buildStringRepresentation(Program program, Address address, Reference reference, ShowBlockName showBlockName) { if (address == null) { return "<NULL>"; } if (address.getAddressSpace().getType() == AddressSpace.TYPE_NONE) { return ""; // NO_ADDRESS or EXT_FROM_ADDRESS not rendered } if (address.isExternalAddress()) { return getExternalAddressRepresentation(program, address); } if (address.isVariableAddress()) { return getVariableAddressRepresentation(); } if (address.isStackAddress()) { return getStackAddressRepresentation(address); } if (address.isConstantAddress()) { return getConstantAddressRepresentation(address); } if (address.isRegisterAddress()) { return getRegisterAddressRepresentation(program, address); } // Handle all other spaces (e.g., memory, other, overlays, hash, etc.) String addrStr; if (reference != null && reference.isOffsetReference()) { OffsetReference offsetRef = (OffsetReference) reference; long offset = offsetRef.getOffset(); boolean neg = (offset < 0); Address baseAddr = offsetRef.getBaseAddress(); addrStr = baseAddr.toString() + (neg ? "-" : "+") + "0x" + Long.toHexString(neg ? -offset : offset); } else if (reference != null && reference.isShiftedReference()) { // TODO: unsure of rendering which has never really been addressed // TODO: shifted references have never addressed concerns related to // addressable unit size ShiftedReference shiftedRef = (ShiftedReference) reference; StringBuilder buf = new StringBuilder(); buf.append(address.toString()); buf.append("(0x"); buf.append(Long.toHexString(shiftedRef.getValue())); buf.append("<<"); buf.append(Long.toString(shiftedRef.getShift())); buf.append(")"); addrStr = buf.toString(); } else { addrStr = address.toString(); } if (showBlockName != ShowBlockName.NEVER) { Memory mem = program.getMemory(); MemoryBlock toBlock = mem.getBlock(address); if (toBlock != null && showBlockName == ShowBlockName.NON_LOCAL && reference != null && toBlock.equals(mem.getBlock(reference.getFromAddress()))) { toBlock = null; } if (toBlock != null) { addrStr = toBlock.getName() + "::" + addrStr; } } return addrStr; }
Example 18
Source File: EditReferenceDialog.java From ghidra with Apache License 2.0 | 4 votes |
private void setAddOpIndex(int opIndex, int subIndex) { CodeUnit cu = instrPanel.getCurrentCodeUnit(); Program p = cu.getProgram(); boolean inFunction = (p.getFunctionManager().getFunctionContaining(cu.getMinAddress()) != null); Reference[] refs = p.getReferenceManager().getReferencesFrom(cu.getMinAddress(), opIndex); Address existingRefAddr = refs.length != 0 ? refs[0].getToAddress() : null; if (!memRefPanel.initialize(cu, opIndex, subIndex)) { throw new AssertException("Memory reference must always be permitted"); } memRefChoice.setEnabled(true); extRefChoice.setEnabled(extRefPanel.initialize(cu, opIndex, subIndex)); stackRefChoice.setEnabled(inFunction && stackRefPanel.initialize(cu, opIndex, subIndex)); regRefChoice.setEnabled(inFunction && regRefPanel.initialize(cu, opIndex, subIndex)); memRefChoice.setSelected(true); if (existingRefAddr != null) { if (existingRefAddr.isStackAddress()) { if (stackRefChoice.isEnabled()) { stackRefChoice.setSelected(true); } } else if (existingRefAddr.isRegisterAddress()) { if (regRefChoice.isEnabled()) { regRefChoice.setSelected(true); } } else if (existingRefAddr.isExternalAddress()) { if (extRefChoice.isEnabled()) { extRefChoice.setSelected(true); } } } else { if (stackRefChoice.isEnabled() && stackRefPanel.isValidStackRef()) { stackRefChoice.setSelected(true); } else if (regRefChoice.isEnabled()) { regRefChoice.setSelected(true); } } }
Example 19
Source File: RefListV0.java From ghidra with Apache License 2.0 | 4 votes |
private int decode(byte[] data, int offset, Reference[] result) { long symbolID = -1; long addr = getLong(data, offset); offset += 8; RefListFlagsV0 flags = new RefListFlagsV0(data[offset++]); RefType refType = RefTypeFactory.get(data[offset++]); byte opIndex = data[offset++]; SourceType source = flags.getSource(); long offsetOrShift = 0; if (flags.hasSymbolID()) { symbolID = getLong(data, offset); offset += 8; } Address from = isFrom ? address : addrMap.decodeAddress(addr); Address to = isFrom ? addrMap.decodeAddress(addr) : address; if (flags.isOffsetRef() || flags.isShiftRef()) { offsetOrShift = getLong(data, offset); offset += 8; if (flags.isShiftRef()) { result[0] = new ShiftedReferenceDB(program, from, to, refType, opIndex, source, flags.isPrimary(), symbolID, (int) offsetOrShift); } else { result[0] = new OffsetReferenceDB(program, from, to, refType, opIndex, source, flags.isPrimary(), symbolID, offsetOrShift); } } else if (to.isExternalAddress()) { result[0] = new ExternalReferenceDB(program, from, to, refType, opIndex, source); } else if (from.equals(Address.EXT_FROM_ADDRESS)) { result[0] = new EntryPointReferenceDB(from, to, refType, opIndex, source, flags.isPrimary(), symbolID); } else if (to.isStackAddress()) { result[0] = new StackReferenceDB(program, from, to, refType, opIndex, source, flags.isPrimary(), symbolID); } else { result[0] = new MemReferenceDB(program, from, to, refType, opIndex, source, flags.isPrimary(), symbolID); } return offset; }