mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GP-5331: Gdb address signedness.
This commit is contained in:
parent
c8937df382
commit
7c983f7bb5
4 changed files with 38 additions and 26 deletions
|
@ -495,10 +495,11 @@ def put_bytes(start, end, pages, is_mi, from_tty):
|
|||
|
||||
|
||||
def eval_address(address):
|
||||
max_addr = util.compute_max_addr()
|
||||
if isinstance(address, int):
|
||||
return address
|
||||
return address & max_addr
|
||||
try:
|
||||
return int(gdb.parse_and_eval(address))
|
||||
return int(gdb.parse_and_eval(address)) & max_addr
|
||||
except gdb.error as e:
|
||||
raise gdb.GdbError("Cannot convert '{}' to address".format(address))
|
||||
|
||||
|
|
|
@ -110,12 +110,12 @@ class ModuleInfoReader(object):
|
|||
n = mat['name']
|
||||
return None if mat is None else mat['name']
|
||||
|
||||
def section_from_line(self, line):
|
||||
def section_from_line(self, line, max_addr):
|
||||
mat = self.section_pattern.fullmatch(line)
|
||||
if mat is None:
|
||||
return None
|
||||
start = try_hexint(mat['vmaS'], 'section start')
|
||||
end = try_hexint(mat['vmaE'], 'section end')
|
||||
start = try_hexint(mat['vmaS'], 'section start') & max_addr
|
||||
end = try_hexint(mat['vmaE'], 'section end') & max_addr
|
||||
offset = try_hexint(mat['offset'], 'section offset')
|
||||
name = mat['name']
|
||||
attrs = [a for a in mat['attrs'].split(' ') if a != '']
|
||||
|
@ -133,6 +133,7 @@ class ModuleInfoReader(object):
|
|||
modules = {}
|
||||
index = Index(REGION_INFO_READER.get_regions())
|
||||
out = gdb.execute(self.cmd, to_string=True)
|
||||
max_addr = compute_max_addr()
|
||||
name = None
|
||||
sections = None
|
||||
for line in out.split('\n'):
|
||||
|
@ -146,7 +147,7 @@ class ModuleInfoReader(object):
|
|||
if name is None:
|
||||
# Don't waste time parsing if no module
|
||||
continue
|
||||
s = self.section_from_line(line)
|
||||
s = self.section_from_line(line, max_addr)
|
||||
if s is not None:
|
||||
if s.name in sections:
|
||||
s = s.better(sections[s.name])
|
||||
|
@ -213,12 +214,12 @@ class RegionInfoReader(object):
|
|||
cmd = REGIONS_CMD
|
||||
region_pattern = REGION_PATTERN
|
||||
|
||||
def region_from_line(self, line):
|
||||
def region_from_line(self, line, max_addr):
|
||||
mat = self.region_pattern.fullmatch(line)
|
||||
if mat is None:
|
||||
return None
|
||||
start = try_hexint(mat['start'], 'region start')
|
||||
end = try_hexint(mat['end'], 'region end')
|
||||
start = try_hexint(mat['start'], 'region start') & max_addr
|
||||
end = try_hexint(mat['end'], 'region end') & max_addr
|
||||
offset = try_hexint(mat['offset'], 'region offset')
|
||||
perms = self.get_region_perms(mat)
|
||||
objfile = mat['objfile']
|
||||
|
@ -228,10 +229,11 @@ class RegionInfoReader(object):
|
|||
regions = []
|
||||
try:
|
||||
out = gdb.execute(self.cmd, to_string=True)
|
||||
max_addr = compute_max_addr()
|
||||
except:
|
||||
return regions
|
||||
for line in out.split('\n'):
|
||||
r = self.region_from_line(line)
|
||||
r = self.region_from_line(line, max_addr)
|
||||
if r is None:
|
||||
continue
|
||||
regions.append(r)
|
||||
|
@ -239,14 +241,14 @@ class RegionInfoReader(object):
|
|||
|
||||
def full_mem(self):
|
||||
# TODO: This may not work for Harvard architectures
|
||||
sizeptr = int(gdb.parse_and_eval('sizeof(void*)')) * 8
|
||||
return Region(0, 1 << sizeptr, 0, None, 'full memory')
|
||||
max_addr = compute_max_addr()
|
||||
return Region(0, max_addr+1, 0, None, 'full memory')
|
||||
|
||||
def have_changed(self, regions):
|
||||
if len(regions) == 1 and regions[0].objfile == 'full memory':
|
||||
return False, None
|
||||
new_regions = self.get_regions()
|
||||
if new_regions == regions:
|
||||
if new_regions == regions and len(new_regions) > 0:
|
||||
return False, None
|
||||
return True, new_regions
|
||||
|
||||
|
@ -396,3 +398,7 @@ def selected_frame():
|
|||
except Exception as e:
|
||||
print("No selected frame")
|
||||
return None
|
||||
|
||||
|
||||
def compute_max_addr():
|
||||
return (1 << (int(gdb.parse_and_eval("sizeof(void*)")) * 8)) - 1
|
||||
|
|
|
@ -63,6 +63,9 @@ public abstract class AbstractMapProposal<T, P, E extends MapEntry<T, P>>
|
|||
}
|
||||
|
||||
protected double computeLengthScore() {
|
||||
if (fromRange == null) {
|
||||
return 0;
|
||||
}
|
||||
long fLen = fromRange.getLength();
|
||||
long tLen = toRange.getLength();
|
||||
for (int bitsmatched = 64; bitsmatched > 0; bitsmatched--) {
|
||||
|
|
|
@ -653,8 +653,8 @@ public class DBTraceMemorySpace
|
|||
int pos = buf.position();
|
||||
try (LockHold hold = LockHold.lock(lock.writeLock())) {
|
||||
|
||||
ByteBuffer oldBytes = ByteBuffer.allocate(buf.remaining());
|
||||
getBytes(snap, start, oldBytes);
|
||||
ByteBuffer oldBuf = ByteBuffer.allocate(buf.remaining());
|
||||
getBytes(snap, start, oldBuf);
|
||||
|
||||
OutSnap lastSnap = new OutSnap(snap);
|
||||
Set<TraceAddressSnapRange> changed = new HashSet<>();
|
||||
|
@ -665,16 +665,18 @@ public class DBTraceMemorySpace
|
|||
|
||||
// Read back the written bytes and fire event
|
||||
byte[] bytes = new byte[result];
|
||||
byte[] oldBytes = new byte[result];
|
||||
buf.get(pos, bytes);
|
||||
oldBuf.get(0, oldBytes);
|
||||
ImmutableTraceAddressSnapRange tasr = new ImmutableTraceAddressSnapRange(start,
|
||||
start.add(result - 1), snap, lastSnap.snap);
|
||||
trace.setChanged(new TraceChangeRecord<>(TraceEvents.BYTES_CHANGED, this, tasr,
|
||||
oldBytes.array(), bytes));
|
||||
oldBytes, bytes));
|
||||
|
||||
// Fixup affected code units
|
||||
DBTraceCodeSpace codeSpace = trace.getCodeManager().get(this, false);
|
||||
if (codeSpace != null) {
|
||||
codeSpace.bytesChanged(changed, snap, start, oldBytes.array(), bytes);
|
||||
codeSpace.bytesChanged(changed, snap, start, oldBytes, bytes);
|
||||
}
|
||||
// Clear program view caches
|
||||
trace.updateViewsBytesChanged(tasr.getRange());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue