mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-25 17:00:36 -09:00
GP-476: Fixed parsing error, processed memory-changed event.
This commit is contained in:
@@ -89,6 +89,13 @@ public interface GdbEventsListenerAdapter extends GdbEventsListener {
|
||||
default void breakpointDeleted(GdbBreakpointInfo info, GdbCause cause) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The target memory was changed by the user.
|
||||
*
|
||||
* <p>
|
||||
* This occurs when the user executes a {@code set} command. It does not (necessarily) occur
|
||||
* from the target's execution.
|
||||
*/
|
||||
@Override
|
||||
default void memoryChanged(GdbInferior inferior, long addr, int len, GdbCause cause) {
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public abstract class AbstractGdbThreadGroupEvent extends AbstractGdbEventWithFi
|
||||
/**
|
||||
* Construct a new event by parsing the tail for information
|
||||
*
|
||||
* <p>
|
||||
* The thread group ID must be specified by GDB in the "id" field.
|
||||
*
|
||||
* @param tail the text following the event type in the GDB/MI event record
|
||||
|
||||
@@ -29,6 +29,7 @@ public class GdbMemoryChangedEvent extends AbstractGdbEventWithFields {
|
||||
/**
|
||||
* Construct a new event by parsing the tail for information
|
||||
*
|
||||
* <p>
|
||||
* The thread group, start address, and length must be specified by GDB.
|
||||
*
|
||||
* @param tail the text following the event type in the GDB/MI event record
|
||||
@@ -38,7 +39,7 @@ public class GdbMemoryChangedEvent extends AbstractGdbEventWithFields {
|
||||
super(tail);
|
||||
this.iid = GdbParsingUtils.parseInferiorId(getInfo().getString("thread-group"));
|
||||
this.addr = GdbParsingUtils.parsePrefixedHex(getInfo().getString("addr"));
|
||||
this.len = Integer.parseInt(getInfo().getString("len"));
|
||||
this.len = (int) GdbParsingUtils.parsePrefixedHex(getInfo().getString("len"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -111,6 +111,7 @@ public enum GdbParsingUtils {
|
||||
/**
|
||||
* Parse a hex string to a long
|
||||
*
|
||||
* <P>
|
||||
* The string must have the {@code 0x} prefix
|
||||
*
|
||||
* @param hex the string
|
||||
@@ -126,6 +127,7 @@ public enum GdbParsingUtils {
|
||||
/**
|
||||
* Parse a hex string to a big integer
|
||||
*
|
||||
* <P>
|
||||
* The string must have the {@code 0x} prefix
|
||||
*
|
||||
* @param hex the string
|
||||
@@ -141,6 +143,7 @@ public enum GdbParsingUtils {
|
||||
/**
|
||||
* Parse an octal string to a long
|
||||
*
|
||||
* <P>
|
||||
* The string must have the {@code 0} prefix
|
||||
*
|
||||
* @param oct the string
|
||||
@@ -156,6 +159,7 @@ public enum GdbParsingUtils {
|
||||
/**
|
||||
* Parse an inferior id
|
||||
*
|
||||
* <P>
|
||||
* The id must have the {@code i} prefix
|
||||
*
|
||||
* @param id the string
|
||||
|
||||
@@ -211,6 +211,12 @@ public class GdbModelTargetInferiorContainer
|
||||
inferior.modules.libraryUnloaded(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memoryChanged(GdbInferior inf, long addr, int len, GdbCause cause) {
|
||||
GdbModelTargetInferior inferior = getTargetInferior(inf);
|
||||
inferior.memory.memoryChanged(addr, len);
|
||||
}
|
||||
|
||||
private void updateUsingInferiors(Map<Integer, GdbInferior> byIID) {
|
||||
List<GdbModelTargetInferior> inferiors;
|
||||
synchronized (this) {
|
||||
|
||||
@@ -81,10 +81,8 @@ public class GdbModelTargetProcessMemory
|
||||
return region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<byte[]> readMemory(Address address, int length) {
|
||||
protected CompletableFuture<byte[]> doReadMemory(Address address, long offset, int length) {
|
||||
ByteBuffer buf = ByteBuffer.allocate(length);
|
||||
long offset = address.getOffset();
|
||||
AddressRange range;
|
||||
try {
|
||||
range = new AddressRangeImpl(address, length);
|
||||
@@ -118,6 +116,11 @@ public class GdbModelTargetProcessMemory
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<byte[]> readMemory(Address address, int length) {
|
||||
return doReadMemory(address, address.getOffset(), length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> writeMemory(Address address, byte[] data) {
|
||||
return inferior.writeMemory(address.getOffset(), ByteBuffer.wrap(data)).thenAccept(__ -> {
|
||||
@@ -138,4 +141,12 @@ public class GdbModelTargetProcessMemory
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public void memoryChanged(long offset, int len) {
|
||||
Address address = impl.getAddressFactory().getDefaultAddressSpace().getAddress(offset);
|
||||
doReadMemory(address, offset, len).exceptionally(ex -> {
|
||||
Msg.error(this, "Failed to update memory contents on memory-changed event", ex);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user