Java Code Examples for ghidra.program.model.mem.Memory#getByte()
The following examples show how to use
ghidra.program.model.mem.Memory#getByte() .
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: ClipboardPluginTest.java From ghidra with Apache License 2.0 | 6 votes |
private void assertByteViewerBytes(String clipboardContents, Address address) throws MemoryAccessException, AddressOutOfBoundsException { Memory memory = program.getMemory(); //b090db777880db774893db77 // expecting a bytes string of the format: b0 90 db 77 78 80 db 77 48 93 db 77 String[] bytes = null; if (clipboardContents.contains(" ")) { bytes = clipboardContents.split("\\s"); } else { bytes = new String[clipboardContents.length() >> 1]; for (int i = 0; i < bytes.length; i++) { int stringOffset = i * 2; bytes[i] = clipboardContents.substring(stringOffset, stringOffset + 2); } } for (int i = 0; i < bytes.length; i++) { byte bite = memory.getByte(address.add(i)); if (!bytes[i].equals(Integer.toHexString(bite & 0xFF))) { Msg.debug(this, "not equal at index: " + i); } assertEquals("Bytes not pasted as expected", bytes[i], Integer.toHexString(bite & 0xFF)); } }
Example 2
Source File: XorMemoryScript.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void run() throws Exception { // default to the current memory block Memory memory = currentProgram.getMemory(); MemoryBlock block = memory.getBlock(currentAddress); AddressSetView set = new AddressSet(block.getStart(),block.getEnd()); if (currentSelection != null && !currentSelection.isEmpty()) { set = currentSelection; } byte[] xorValues = askBytes("XorValue", "Values to xor with selected memory:"); int valueLength = xorValues.length; int xorIndex = 0; AddressIterator aIter = set.getAddresses(true); while (aIter.hasNext() && !monitor.isCancelled()) { Address addr = aIter.next(); monitor.setMessage(addr.toString()); byte xorValue = xorValues[xorIndex]; byte b = memory.getByte(addr); b = (byte) (b ^ xorValue); memory.setByte(addr, b); xorIndex += 1; xorIndex = xorIndex % valueLength; } }
Example 3
Source File: eBPF_ElfRelocationHandler.java From eBPF-for-Ghidra with MIT License | 4 votes |
@Override public void relocate(ElfRelocationContext elfRelocationContext, ElfRelocation relocation, Address relocationAddress) throws MemoryAccessException, NotFoundException { ElfHeader elf = elfRelocationContext.getElfHeader(); if (elf.e_machine() != ElfConstants.EM_BPF) { return; } Program program = elfRelocationContext.getProgram(); Memory memory = program.getMemory(); int type = relocation.getType(); int symbolIndex = relocation.getSymbolIndex(); long value; boolean appliedSymbol = true; if (type == 1) { try { int SymbolIndex= relocation.getSymbolIndex(); ElfSymbol Symbol = elfRelocationContext.getSymbol(SymbolIndex); String map = Symbol.getNameAsString(); SymbolTable table = program.getSymbolTable(); Address mapAddr = table.getSymbol(map).getAddress(); String sec_name = elfRelocationContext.relocationTable.getSectionToBeRelocated().getNameAsString(); if (sec_name.toString().contains("debug")) { return; } value = mapAddr.getAddressableWordOffset(); Byte dst = memory.getByte(relocationAddress.add(0x1)); memory.setLong(relocationAddress.add(0x4), value); memory.setByte(relocationAddress.add(0x1), (byte) (dst + 0x10)); } catch(NullPointerException e) {} } if (appliedSymbol && symbolIndex == 0) { markAsWarning(program, relocationAddress, Long.toString(type), "applied relocation with symbol-index of 0", elfRelocationContext.getLog()); } }