mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-25 13:42:06 +00:00
Fix segment offset extraction
This commit is contained in:
parent
0595537962
commit
1556928554
@ -31,7 +31,7 @@ public class SegmentedAddress extends GenericAddress {
|
||||
*/
|
||||
SegmentedAddress(long flat, SegmentedAddressSpace addrSpace) {
|
||||
super(adjustOffset(flat, addrSpace), addrSpace);
|
||||
segment = addrSpace.getSegmentFromFlat(flat);
|
||||
segment = addrSpace.getDefaultSegmentFromFlat(flat);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,12 +56,12 @@ public class SegmentedAddress extends GenericAddress {
|
||||
SegmentedAddress(SegmentedAddressSpace addrSpace, long flat)
|
||||
throws AddressOutOfBoundsException {
|
||||
super(addrSpace, adjustOffset(flat, addrSpace));
|
||||
segment = addrSpace.getSegmentFromFlat(flat);
|
||||
segment = addrSpace.getDefaultSegmentFromFlat(flat);
|
||||
}
|
||||
|
||||
private static long adjustOffset(long flat, SegmentedAddressSpace addrSpace) {
|
||||
int seg = addrSpace.getSegmentFromFlat(flat);
|
||||
long offset = addrSpace.getOffsetFromFlat(flat);
|
||||
int seg = addrSpace.getDefaultSegmentFromFlat(flat);
|
||||
long offset = addrSpace.getDefaultOffsetFromFlat(flat);
|
||||
return addrSpace.getFlatOffset(seg, offset);
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ public class SegmentedAddress extends GenericAddress {
|
||||
* @return the offset value
|
||||
*/
|
||||
public int getSegmentOffset() {
|
||||
return (int) ((SegmentedAddressSpace) addrSpace).getOffsetFromFlat(offset);
|
||||
return (int) ((SegmentedAddressSpace) addrSpace).getOffsetFromFlat(offset, segment);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,11 +52,11 @@ public class SegmentedAddressSpace extends GenericAddressSpace {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a flat address offset, extract the 16-bit segment portion
|
||||
* Given a flat address offset, extract the default 16-bit segment portion
|
||||
* @param flat is the flat offset
|
||||
* @return the segment value
|
||||
*/
|
||||
protected int getSegmentFromFlat(long flat) {
|
||||
protected int getDefaultSegmentFromFlat(long flat) {
|
||||
if (flat > 0xFFFFFL) {
|
||||
return 0xFFFF;
|
||||
}
|
||||
@ -64,17 +64,29 @@ public class SegmentedAddressSpace extends GenericAddressSpace {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a flat address offset, extract the offset portion
|
||||
* Given a flat address offset, extract the offset portion assuming the
|
||||
* default segment.
|
||||
* @param flat is the flat offset
|
||||
* @return the offset value
|
||||
*/
|
||||
protected long getOffsetFromFlat(long flat) {
|
||||
protected long getDefaultOffsetFromFlat(long flat) {
|
||||
if (flat > 0xFFFFFL) {
|
||||
return flat - 0xFFFF0;
|
||||
}
|
||||
return flat & 0xFFFFL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a flat address offset, extract a segment offset assuming a
|
||||
* specific segment value.
|
||||
* @param flat is the flat offset
|
||||
* @param segment is the specific segment value
|
||||
* @return the segment offset
|
||||
*/
|
||||
protected long getOffsetFromFlat(long flat, int segment) {
|
||||
return flat - (segment << 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a flat address offset and a preferred segment, try
|
||||
* to create an address that maps to the offset and is in the segment. For
|
||||
|
Loading…
Reference in New Issue
Block a user