Java Code Examples for ghidra.program.model.mem.Memory#setLong()

The following examples show how to use ghidra.program.model.mem.Memory#setLong() . 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: eBPF_ElfRelocationHandler.java    From eBPF-for-Ghidra with MIT License 4 votes vote down vote up
@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());
	}

}
 
Example 2
Source File: RelocationFixupHandler.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public boolean process64BitRelocation(Program program, Relocation relocation,
		Address oldImageBase, Address newImageBase) throws MemoryAccessException,
		CodeUnitInsertionException {

	long diff = newImageBase.subtract(oldImageBase);

	Address address = relocation.getAddress();
	Memory memory = program.getMemory();
	long value = memory.getLong(address);
	long newValue = value + diff;

	InstructionStasher instructionStasher = new InstructionStasher(program, address);

	memory.setLong(address, newValue);

	instructionStasher.restore();

	return true;
}