Java Code Examples for ghidra.program.model.lang.Register#getBaseRegister()
The following examples show how to use
ghidra.program.model.lang.Register#getBaseRegister() .
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: 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 2
Source File: ResultsState.java From ghidra with Apache License 2.0 | 6 votes |
private boolean addRegister(Register reg, List<Register> regList) { // Ignore duplicate / reconcile related register for (int i = 0; i < regList.size(); i++) { Register existingReg = regList.get(i); Register parentReg = reg.getParentRegister(); if (existingReg == reg || existingReg == parentReg || existingReg == reg.getBaseRegister()) { return false; } if (parentReg != null && existingReg.getParentRegister() == parentReg) { regList.set(i, parentReg); return true; } } regList.add(reg); return true; }
Example 3
Source File: RegisterValueStore.java From ghidra with Apache License 2.0 | 5 votes |
/** * Constructs a new RegisterValueStore. * @param rangeMap the rangeMapAdapter that handles the low level storage of byte arrays */ public RegisterValueStore(Register register, RangeMapAdapter rangeMap, boolean enableRangeWriteCache) { this.baseRegister = register.getBaseRegister(); this.rangeMap = rangeMap; rangeWriteCacheEnabled = enableRangeWriteCache; }
Example 4
Source File: RegisterValueStore.java From ghidra with Apache License 2.0 | 5 votes |
/** * Clears the address range of any set bits using the mask from the given register value. * existing values in the range that have values that are not part of the input mask are * not changed. If register is null, just clear all the values in range * @param start the start of the range to clear the register value bits. * @param end the end of the range(inclusive) to clear the register value bits. * @param register the register whos mask to use. If null, clear all values in the given range. */ public void clearValue(Address start, Address end, Register register) { flushWriteCache(); // if the mask is all on, then just clear any values that are stored in this range if (register == null || register.isBaseRegister()) { rangeMap.clearRange(start, end); return; } // Otherwise, mask off bits according to the mask passed in. List<AddressRange> list = new ArrayList<AddressRange>(); AddressRangeIterator rangeIt = rangeMap.getAddressRangeIterator(start, end); while (rangeIt.hasNext()) { list.add(rangeIt.next()); } Iterator<AddressRange> it = list.iterator(); while (it.hasNext()) { AddressRange indexRange = it.next(); Address rangeStart = indexRange.getMinAddress(); Address rangeEnd = indexRange.getMaxAddress(); byte[] mask = register.getBaseMask(); RegisterValue currentBaseValue = new RegisterValue(register.getBaseRegister(), rangeMap.getValue(rangeStart)); RegisterValue newBaseValue = currentBaseValue.clearBitValues(mask); if (!newBaseValue.hasAnyValue()) { rangeMap.clearRange(rangeStart, rangeEnd); } else { rangeMap.set(rangeStart, rangeEnd, newBaseValue.toBytes()); } start = rangeEnd.next(); } }
Example 5
Source File: RegisterTree.java From ghidra with Apache License 2.0 | 5 votes |
public void setRegisters(Register[] registers) { if (registers == lastRegisters) { return; } removeAll(); // remove all current children before repopulating lastRegisters = registers; HashMap<String, RegisterTreeGroupNode> groups = new HashMap<String, RegisterTreeGroupNode>(); List<GTreeNode> nodes = new ArrayList<GTreeNode>(); for (Register register : registers) { if (register.getBaseRegister() != register && !register.getParentRegister().isHidden()) { continue; } String groupName = register.getGroup(); if (groupName != null) { RegisterTreeGroupNode group = groups.get(groupName); if (group == null) { group = new RegisterTreeGroupNode(groupName); groups.put(groupName, group); nodes.add(group); } group.addRegister(register); } else { nodes.add(new RegisterTreeNode(register)); } } Collections.sort(nodes); setChildren(nodes); }
Example 6
Source File: ResultsState.java From ghidra with Apache License 2.0 | 5 votes |
private boolean containsRegister(Register reg, List<Register> regList) { for (Register existingReg : regList) { Register parentReg = reg.getParentRegister(); if (existingReg == reg || existingReg == parentReg || existingReg == reg.getBaseRegister()) { return true; } if (parentReg != null && existingReg.getParentRegister() == parentReg) { return false; } } return false; }
Example 7
Source File: EmulatorTestRunner.java From ghidra with Apache License 2.0 | 5 votes |
public RegisterValue getRegisterValue(Register reg) { Register baseReg = reg.getBaseRegister(); byte[] bytes = emuHelper.readMemory(baseReg.getAddress(), baseReg.getMinimumByteSize()); if (!reg.isBigEndian()) { flipBytes(bytes); } byte[] maskValue = new byte[2 * bytes.length]; Arrays.fill(maskValue, (byte) 0xff); System.arraycopy(bytes, 0, maskValue, bytes.length, bytes.length); RegisterValue baseValue = new RegisterValue(baseReg, maskValue); return baseValue.getRegisterValue(reg); }
Example 8
Source File: DatabaseRangeMapAdapter.java From ghidra with Apache License 2.0 | 4 votes |
/** * @see ghidra.program.util.RangeMapAdapter#setLanguage(ghidra.program.util.LanguageTranslator, ghidra.program.model.lang.Register, ghidra.util.task.TaskMonitor) */ @Override public void setLanguage(LanguageTranslator translator, Register mapReg, TaskMonitor monitor) throws CancelledException { Register newReg = translator.getNewRegister(mapReg); if (newReg == null) { // register not translated - clear map rangeMap.dispose(); rangeMap = null; return; } Register newBaseReg = newReg.getBaseRegister(); AddressRangeMapDB tempMap = null; if (!newReg.isBaseRegister() || translator.isValueTranslationRequired(mapReg)) { // Create temporary map String tempName = "TEMP_MAP"; int retry = 0; while (AddressRangeMapDB.exists(dbh, tempName)) { tempName = "TEMP_MAP" + (++retry); } tempMap = new AddressRangeMapDB(dbh, addressMap, new Lock("Test"), tempName, errorHandler, BinaryField.class, false); // Translate range map data into tempMap monitor.initialize(rangeMap.getRecordCount()); monitor.setMessage("Converting " + mapReg.getName() + " values..."); int cnt = 0; AddressRangeIterator rangeIter = rangeMap.getAddressRanges(); while (rangeIter.hasNext()) { if (monitor.isCancelled()) { tempMap.dispose(); throw new CancelledException(); } AddressRange range = rangeIter.next(); BinaryField value = (BinaryField) rangeMap.getValue(range.getMinAddress()); byte[] oldBytes = value.getBinaryData(); RegisterValue regValue = new RegisterValue(mapReg, oldBytes); regValue = translator.getNewRegisterValue(regValue); if (regValue != null && regValue.hasAnyValue()) { byte[] newBytes = regValue.toBytes(); tempMap.paintRange(range.getMinAddress(), range.getMaxAddress(), new BinaryField(newBytes)); } monitor.setProgress(++cnt); } } String newMapName = NAME_PREFIX + newBaseReg.getName(); if (tempMap == null) { if (mapName.equals(newMapName)) { // Nothing to change return; } } else { rangeMap.dispose(); rangeMap = tempMap; } if (rangeMap != null) { try { rangeMap.setName(newMapName); } catch (DuplicateNameException e) { throw new AssertException("Unexpected DuplicateNameException"); } } mapName = newMapName; }