ghidra.program.model.lang.Register Java Examples
The following examples show how to use
ghidra.program.model.lang.Register.
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: ReferenceDBManager.java From ghidra with Apache License 2.0 | 6 votes |
@Override public Reference addRegisterReference(Address fromAddr, int opIndex, Register register, RefType type, SourceType sourceType) { if (!fromAddr.isMemoryAddress()) { throw new IllegalArgumentException("From address must be memory address"); } removeAllFrom(fromAddr, opIndex); try { return addRef(fromAddr, register.getAddress(), type, sourceType, opIndex, false, false, 0); } catch (IOException e) { program.dbError(e); } return null; }
Example #2
Source File: RegisterPlugin.java From ghidra with Apache License 2.0 | 6 votes |
void setRegisterValues(ProgramLocationActionContext context, Register register, AddressSetView addrSet, boolean selectRegister) { SetRegisterValueDialog dialog = new SetRegisterValueDialog(context.getProgram(), registers, register, addrSet, true); tool.showDialog(dialog, (Component) null); BigInteger value = dialog.getRegisterValue(); Register selectedRegister = dialog.getSelectRegister(); if (value != null && selectedRegister != null) { applyRegisterValues(context.getProgram(), selectedRegister, value, addrSet); if (selectRegister) { registerMgrProvider.selectRegister(selectedRegister); } } }
Example #3
Source File: RegisterPlugin.java From ghidra with Apache License 2.0 | 6 votes |
protected Register getRegister(ProgramLocationActionContext context) { Program program = context.getProgram(); ProgramLocation location = context.getLocation(); if (location instanceof OperandFieldLocation) { OperandFieldLocation opLoc = (OperandFieldLocation) location; CodeUnit cu = program.getListing().getCodeUnitAt(opLoc.getAddress()); if (cu instanceof Instruction) { Instruction inst = (Instruction) cu; Object[] opObjs = inst.getOpObjects(opLoc.getOperandIndex()); for (Object object : opObjs) { if (object instanceof Register) { return (Register) object; } } } } return null; }
Example #4
Source File: VariableImpl.java From ghidra with Apache License 2.0 | 6 votes |
private static void checkUsage(VariableStorage storage, Address storageAddr, Integer stackOffset, Register register) { boolean invalidUsage = false; if (storage != null) { invalidUsage = storageAddr != null || stackOffset != null || register != null; } else if (register != null) { invalidUsage = storageAddr != null || stackOffset != null; } else if (stackOffset != null) { invalidUsage = storageAddr != null; } if (invalidUsage) { throw new IllegalArgumentException("only one storage location may be specified"); } }
Example #5
Source File: ProgramDiff3Test.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testFunctionRegParamDiff2() throws Exception { // different named registers as param_1 int transactionID1 = p1.startTransaction("Test Transaction"); Function function1 = p1.getFunctionManager().getFunctionAt(addr(p1, 0x1002cf5)); function1.removeParameter(0); Register dr0Reg = p1.getRegister("DR0"); Variable var1 = new ParameterImpl("example", new DWordDataType(), dr0Reg, p1); function1.removeParameter(0); function1.insertParameter(0, var1, SourceType.USER_DEFINED); p1.endTransaction(transactionID1, true); int transactionID2 = p2.startTransaction("Test Transaction"); Function function2 = p2.getFunctionManager().getFunctionAt(addr(p2, 0x1002cf5)); function2.removeParameter(0); dr0Reg = p2.getRegister("DR0"); Variable var2 = new ParameterImpl("variable", new DWordDataType(), dr0Reg, p2); function2.removeParameter(0); function2.insertParameter(0, var2, SourceType.USER_DEFINED); p2.endTransaction(transactionID2, true); AddressSet expectedDiffs = new AddressSet(addr(0x1002cf5), addr(0x1002cf5)); checkDiff(expectedDiffs, ProgramDiffFilter.FUNCTION_DIFFS); }
Example #6
Source File: VarnodeLocationCellEditor.java From ghidra with Apache License 2.0 | 6 votes |
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { VarnodeTableModel tableModel = (VarnodeTableModel) table.getModel(); currentVarnode = tableModel.getRowObject(row); type = currentVarnode.getType(); editorComponent = null; switch (type) { case Register: editorComponent = createRegisterCombo(currentVarnode); break; case Stack: editorComponent = createStackOffsetEditor(currentVarnode); break; case Memory: editorComponent = createAddressEditor(currentVarnode); break; } return editorComponent; }
Example #7
Source File: ProgramMerge1Test.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testFunctionRegParamDiff9() throws Exception { // added register param in program2 int transactionID2 = p2.startTransaction("Test Transaction"); Function function2 = p2.getFunctionManager().getFunctionAt(addr(p2, 0x10048a3)); Register dr0Reg = p1.getRegister("DR0"); Variable var2 = new ParameterImpl("variable", new DWordDataType(), dr0Reg, p2); function2.addParameter(var2, SourceType.USER_DEFINED); p2.endTransaction(transactionID2, true); programMerge = new ProgramMergeManager(p1, p2, TaskMonitorAdapter.DUMMY_MONITOR); AddressSet diffAs = new AddressSet(); diffAs.addRange(addr(0x10048a3), addr(0x10048a3)); programMerge.setDiffFilter(new ProgramDiffFilter(ProgramDiffFilter.FUNCTION_DIFFS)); programMerge.setMergeFilter( new ProgramMergeFilter(ProgramMergeFilter.FUNCTIONS, ProgramMergeFilter.REPLACE)); assertEquals(diffAs, programMerge.getFilteredDifferences()); programMerge.merge(diffAs, TaskMonitorAdapter.DUMMY_MONITOR); assertEquals(new AddressSet(), programMerge.getFilteredDifferences()); }
Example #8
Source File: RegisterFieldFactory.java From ghidra with Apache License 2.0 | 6 votes |
@Override public ListingField getField(ProxyObj<?> proxy, int varWidth) { Object obj = proxy.getObject(); if (!enabled || !(obj instanceof Function)) { return null; } int x = startX + varWidth; Function function = (Function) obj; List<Register> setRegisters = getSetRegisters(function); if (setRegisters.isEmpty()) { return null; } String[] registerStrings = getRegisterStrings(function, setRegisters); return getTextField(registerStrings, proxy, x); }
Example #9
Source File: RegisterValueStore.java From ghidra with Apache License 2.0 | 6 votes |
/** * Preserve register values and handle register name/size change. * @param translator * @param monitor * @return true if translated successfully, false if register not mapped * value storage should be discarded. * @throws CancelledException */ public boolean setLanguage(LanguageTranslator translator, TaskMonitor monitor) throws CancelledException { Register newReg = translator.getNewRegister(baseRegister); if (newReg == null) { return false; } flushWriteCache(); // TODO: What should we do if new register is not a base-register ? - The code below will not work! if (newReg.isProcessorContext() || !newReg.isBaseRegister() || !newReg.getName().equals(baseRegister.getName()) || newReg.getBitLength() != baseRegister.getBitLength()) { rangeMap.setLanguage(translator, baseRegister, monitor); baseRegister = newReg.getBaseRegister(); } return true; }
Example #10
Source File: EditRegisterReferencePanel.java From ghidra with Apache License 2.0 | 6 votes |
@Override public void initialize(CodeUnit fromCu, Reference editReference) { isValidState = false; if (!(fromCu instanceof Instruction)) { throw new IllegalArgumentException("Valid instruction required"); } Register toReg = fromCu.getProgram().getRegister(editReference.getToAddress()); if (toReg == null) { throw new IllegalArgumentException("Valid register reference required"); } this.fromCodeUnit = fromCu; this.editRef = editReference; populateRegisterList(getAllowedRegisters((Instruction) fromCu, toReg), toReg); RefType rt = editRef.getReferenceType(); populateRefTypes(rt); refTypes.setSelectedItem(rt); isValidState = true; }
Example #11
Source File: VarnodeTableModel.java From ghidra with Apache License 2.0 | 6 votes |
@Override public void setValue(VarnodeInfo varnode, Object aValue) { if (aValue == null) { return; } if (aValue instanceof Address) { storageModel.setVarnode(varnode, (Address) aValue, varnode.getSize()); } else if (aValue instanceof Register) { storageModel.setVarnode(varnode, (Register) aValue); } else if (aValue instanceof String) { storageModel.setVarnode(varnode, (String) aValue); } else { throw new AssertException("Unexpected edit value"); } }
Example #12
Source File: ResolveX86orX64LinuxSyscallsScript.java From ghidra with Apache License 2.0 | 6 votes |
/** * Uses the symbolic propogator to attempt to determine the constant value in * the syscall register at each system call instruction * * @param funcsToCalls map from functions containing syscalls to address in each function of * the system call * @param program containing the functions * @return map from addresses of system calls to system call numbers * @throws CancelledException if the user cancels */ private Map<Address, Long> resolveConstants(Map<Function, Set<Address>> funcsToCalls, Program program, TaskMonitor tMonitor) throws CancelledException { Map<Address, Long> addressesToSyscalls = new HashMap<>(); Register syscallReg = program.getLanguage().getRegister(syscallRegister); for (Function func : funcsToCalls.keySet()) { Address start = func.getEntryPoint(); ContextEvaluator eval = new ConstantPropagationContextEvaluator(true); SymbolicPropogator symEval = new SymbolicPropogator(program); symEval.flowConstants(start, func.getBody(), eval, true, tMonitor); for (Address callSite : funcsToCalls.get(func)) { Value val = symEval.getRegisterValue(callSite, syscallReg); if (val == null) { createBookmark(callSite, "System Call", "Couldn't resolve value of " + syscallReg); printf("Couldn't resolve value of " + syscallReg + " at " + callSite + "\n"); continue; } addressesToSyscalls.put(callSite, val.getValue()); } } return addressesToSyscalls; }
Example #13
Source File: PefAnalyzer.java From ghidra with Apache License 2.0 | 6 votes |
/** * Creates a address set consisting of the function bodies of each * function entry point specified in the function address set. */ private AddressSet getInstructionSet(Program program, AddressSetView functionSet, Listing listing, Symbol tocSymbol, TaskMonitor monitor) { AddressSet instructionSet = new AddressSet(); FunctionIterator functions = listing.getFunctions(functionSet, true); Register r2 = program.getRegister("r2"); BigInteger val = BigInteger.valueOf(tocSymbol.getAddress().getOffset()); RegisterValue regVal = new RegisterValue(r2, val); while (functions.hasNext()) { if (monitor.isCancelled()) { break; } Function function = functions.next(); try { program.getProgramContext().setRegisterValue(function.getEntryPoint(), function.getEntryPoint(), regVal); } catch (ContextChangeException e) { // should never happen when changing r2 register } instructionSet.add(function.getBody()); } return instructionSet; }
Example #14
Source File: VectorRegisterPspecTest.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testPspecParsing_PPC_6432() throws Exception { ProgramBuilder pBuilder = new ProgramBuilder("test", ProgramBuilder._PPC_6432); testProgram = pBuilder.getProgram(); Register[] vectorRegs = testProgram.getLanguage().getSortedVectorRegisters(); String[] powerPcVectorRegisterNames = getPowerPCVectorRegisterNames(); assertEquals(powerPcVectorRegisterNames.length, vectorRegs.length); for (int i = 0; i < vectorRegs.length; i++) { assertTrue(vectorRegs[i].isVectorRegister()); assertEquals(powerPcVectorRegisterNames[i], vectorRegs[i].getName()); assertEquals(VSX_BIT_SIZE, vectorRegs[i].getBitLength()); int[] lanes = vectorRegs[i].getLaneSizes(); assertEquals(3, lanes.length); //lane sizes should be 1, 2, 4 int size = 1; for (int lane : lanes) { assertEquals(size, lane); size *= 2; } assertFalse(vectorRegs[i].isValidLaneSize(5)); } }
Example #15
Source File: ReferencesPlugin.java From ghidra with Apache License 2.0 | 6 votes |
boolean addReference(CodeUnit fromCodeUnit, int opIndex, Register reg, RefType refType) { if (!confirmPossibleReferenceRemoval(fromCodeUnit, opIndex, null)) { return false; } Program p = fromCodeUnit.getProgram(); Address fromAddr = fromCodeUnit.getMinAddress(); Function f = p.getFunctionManager().getFunctionContaining(fromAddr); if (f == null) { return false; } AddRegisterRefCmd cmd = new AddRegisterRefCmd(fromAddr, opIndex, reg, refType, SourceType.USER_DEFINED); return tool.execute(cmd, p); }
Example #16
Source File: VariableStorageConflictsTest.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testVariableOverlapNoDifference() throws Exception { AddressSpace space = program.getAddressFactory().getDefaultAddressSpace(); Listing listing = program.getListing(); Function func1 = listing.getFunctionAt(space.getAddress(0x100415aL)); Register axReg = program.getRegister("AX"); func1.insertParameter(0, new ParameterImpl(null, WordDataType.dataType, axReg, program), SourceType.DEFAULT); FunctionVariableStorageConflicts vsc = new FunctionVariableStorageConflicts(func1, func1, false, TaskMonitorAdapter.DUMMY_MONITOR); assertTrue("No conflict expected", !vsc.hasOverlapConflict()); }
Example #17
Source File: ListingHighlightProvider.java From ghidra with Apache License 2.0 | 5 votes |
private List<String> gatherRegisterNames(List<String> names, Register register) { // get the parents Register parent = register.getParentRegister(); while (parent != null) { names.add(parent.getName()); parent = parent.getParentRegister(); } // now the register and its children accumulateSubRegisters(names, register); return names; }
Example #18
Source File: ProgramDiff3Test.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testFunctionRegParamDiff1() throws Exception { // program1 has reg param and program2 doesn't. int transactionID1 = p1.startTransaction("Test Transaction"); Function function1 = p1.getFunctionManager().getFunctionAt(addr(p1, 0x10048a3)); Register dr0Reg = p1.getRegister("DR0"); Variable var1 = new ParameterImpl("variable", new DWordDataType(), dr0Reg, p1); function1.insertParameter(0, var1, SourceType.USER_DEFINED); p1.endTransaction(transactionID1, true); AddressSet expectedDiffs = new AddressSet(addr(0x10048a3), addr(0x10048a3)); checkDiff(expectedDiffs, ProgramDiffFilter.FUNCTION_DIFFS); }
Example #19
Source File: SymbolDB.java From ghidra with Apache License 2.0 | 5 votes |
private void checkEditOK() throws InvalidInputException { if (getSymbolType() == SymbolType.LABEL) { for (Register reg : symbolMgr.getProgram().getRegisters(getAddress())) { if (reg.getName().equals(getName())) { throw new InvalidInputException("Register symbol may not be renamed"); } } } }
Example #20
Source File: ListingDiff.java From ghidra with Apache License 2.0 | 5 votes |
/** * Determine if the first and second instructions objects for a particular operand differ. * The opObjects are checked using the currently specified ignore flags for determining * instruction operand differences. * @param opObjects1 the operand objects that compose an operand for the first instruction * @param opObjects2 the operand objects that compose an operand for the second instruction * @return true if the opObjects differ based on the current diff ignore flags. */ private boolean opObjectsDiffer(Object[] opObjects1, Object[] opObjects2) { if (opObjects1.length != opObjects2.length) { return true; } for (int i = 0; i < opObjects1.length; i++) { Object obj1 = opObjects1[i]; Object obj2 = opObjects2[i]; if (obj1.equals(obj2)) { continue; } if (obj1 instanceof Scalar && obj2 instanceof Scalar) { if (ignoreConstants) { continue; } } else if (obj1 instanceof Address && obj2 instanceof Address) { if (ignoreConstants) { continue; } } else if (obj1 instanceof Register && obj2 instanceof Register) { Register reg1 = (Register) obj1; Register reg2 = (Register) obj2; int len1 = reg1.getBitLength(); int len2 = reg2.getBitLength(); if (len1 != len2) { return true; } if (!ignoreRegisters && !reg1.equals(reg2)) { return true; } continue; } return true; } return false; }
Example #21
Source File: EditRegisterReferencePanel.java From ghidra with Apache License 2.0 | 5 votes |
private void populateRegisterList(Collection<Register> registers, Register selectedRegister) { regList.clearModel(); for (Register reg : registers) { regList.addItem(reg); } if (selectedRegister != null) { regList.setSelectedItem(selectedRegister); } }
Example #22
Source File: ProgramMerge1Test.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testFunctionRegParamDiff10() throws Exception { // same reg param in program 1 and 2 int transactionID1 = p1.startTransaction("Test Transaction"); Function function1 = p1.getFunctionManager().getFunctionAt(addr(p1, 0x1002cf5)); function1.removeParameter(0); Register dr0Reg = p1.getRegister("DR0"); Variable var1 = new ParameterImpl("variable", new DWordDataType(), dr0Reg, p1); function1.removeParameter(0); function1.insertParameter(0, var1, SourceType.USER_DEFINED); p1.endTransaction(transactionID1, true); int transactionID2 = p2.startTransaction("Test Transaction"); Function function2 = p2.getFunctionManager().getFunctionAt(addr(p2, 0x1002cf5)); function2.removeParameter(0); dr0Reg = p2.getRegister("DR0"); Variable var2 = new ParameterImpl("variable", new DWordDataType(), dr0Reg, p2); function2.removeParameter(0); function2.insertParameter(0, var2, SourceType.USER_DEFINED); p2.endTransaction(transactionID2, true); programMerge = new ProgramMergeManager(p1, p2, TaskMonitorAdapter.DUMMY_MONITOR); AddressSet diffAs = new AddressSet(); diffAs.addRange(addr(0x1002cf5), addr(0x1002cf5)); programMerge.setDiffFilter(new ProgramDiffFilter(ProgramDiffFilter.FUNCTION_DIFFS)); programMerge.setMergeFilter( new ProgramMergeFilter(ProgramMergeFilter.FUNCTIONS, ProgramMergeFilter.REPLACE)); assertEquals(new AddressSet(), programMerge.getFilteredDifferences()); programMerge.merge(diffAs, TaskMonitorAdapter.DUMMY_MONITOR); assertEquals(new AddressSet(), programMerge.getFilteredDifferences()); }
Example #23
Source File: SetRegisterValueDialog.java From ghidra with Apache License 2.0 | 5 votes |
private Register doGetSelectedRegister() { RegisterWrapper wrapper = (RegisterWrapper) registerComboBox.getSelectedItem(); if (wrapper != null) { return wrapper.register; } return null; }
Example #24
Source File: RegisterTree.java From ghidra with Apache License 2.0 | 5 votes |
void setFiltered(boolean b) { isFiltered = b; if (program != null) { Register[] registers = isFiltered ? program.getProgramContext().getRegistersWithValues() : getNonHiddenRegisters(program); root.setRegisters(registers); } }
Example #25
Source File: RegisterFieldFactoryTest.java From ghidra with Apache License 2.0 | 5 votes |
private List<Register> getNonContextRegisters(ProgramContext pc) { Register[] regs = pc.getRegisters(); List<Register> nonContextRegs = new ArrayList<Register>(); for (int i = 0; i < regs.length; i++) { if (!regs[i].isProcessorContext()) { nonContextRegs.add(regs[i]); } } return nonContextRegs; }
Example #26
Source File: OldFunctionDataDB.java From ghidra with Apache License 2.0 | 5 votes |
private Parameter getRegisterParameter(Record record, int ordinal) { String name = record.getString(OldRegisterVariableDBAdapter.REG_VAR_NAME_COL); long dataTypeId = record.getLongValue(OldRegisterVariableDBAdapter.REG_VAR_DATA_TYPE_ID_COL); String regName = record.getString(OldRegisterVariableDBAdapter.REG_VAR_REGNAME_COL); DataType dataType = functionManager.getDataType(dataTypeId); try { VariableStorage storage = VariableStorage.BAD_STORAGE; Register register = functionManager.getProgram().getProgramContext().getRegister(regName); if (register == null) { Msg.error(this, "Invalid parameter, register not found: " + regName); } else { storage = new VariableStorage(program, register.getAddress(), dataType.getLength()); } return new OldFunctionParameter(name, ordinal, dataType, storage, program, SourceType.USER_DEFINED); } catch (InvalidInputException e) { Msg.error(this, "Invalid parameter '" + name + "' in function at " + entryPoint.toString()); try { return new OldFunctionParameter(name, ordinal, dataType, VariableStorage.BAD_STORAGE, program, SourceType.USER_DEFINED); } catch (InvalidInputException e1) { // should not occur throw new RuntimeException(e1); } } }
Example #27
Source File: VariableDB.java From ghidra with Apache License 2.0 | 5 votes |
@Override public Register getRegister() { VariableStorage variableStorage = getVariableStorage(); if (variableStorage != null) { return variableStorage.getRegister(); } return null; }
Example #28
Source File: VariableDB.java From ghidra with Apache License 2.0 | 5 votes |
@Override public List<Register> getRegisters() { VariableStorage variableStorage = getVariableStorage(); if (variableStorage != null) { return variableStorage.getRegisters(); } return null; }
Example #29
Source File: DatabaseRangeMapAdapter.java From ghidra with Apache License 2.0 | 5 votes |
public DatabaseRangeMapAdapter(Register register, DBHandle dbHandle, AddressMap addrMap, Lock lock, ErrorHandler errorHandler) { this.dbh = dbHandle; this.errorHandler = errorHandler; mapName = NAME_PREFIX + register.getName(); rangeMap = new AddressRangeMapDB(dbHandle, addrMap, lock, mapName, errorHandler, BinaryField.class, false); addressMap = addrMap; }
Example #30
Source File: AbstractStoredProgramContext.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void setValue(Register register, Address start, Address end, BigInteger value) throws ContextChangeException { if (start.getAddressSpace() != end.getAddressSpace()) { throw new AssertException("start and end address must be in the same address space"); } if (value == null) { remove(start, end, register); return; } setRegisterValue(start, end, new RegisterValue(register, value)); }