mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-25 17:00:36 -09:00
Merge remote-tracking branch 'origin/GP-21_emteere'
This commit is contained in:
@@ -364,30 +364,26 @@ public class NamespaceManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
set2.addRange(addr(0x20), addr(0x50));
|
||||
set2.addRange(addr(0x1000), addr(0x3000));
|
||||
|
||||
try {
|
||||
namespaceManager.overlapsNamespace(set2);
|
||||
if (namespaceManager.overlapsNamespace(set2) == null) {
|
||||
Assert.fail("Should overlap!");
|
||||
}
|
||||
catch (OverlappingNamespaceException e) {
|
||||
}
|
||||
|
||||
set2 = new AddressSet();
|
||||
set2.addRange(addr(0xff), addr(0x101));
|
||||
set2.addRange(addr(0x1000), addr(0x3000));
|
||||
|
||||
try {
|
||||
namespaceManager.overlapsNamespace(set2);
|
||||
if (namespaceManager.overlapsNamespace(set2) == null) {
|
||||
Assert.fail("Should overlap!");
|
||||
}
|
||||
catch (OverlappingNamespaceException e) {
|
||||
}
|
||||
|
||||
|
||||
set2 = new AddressSet();
|
||||
set.addRange(addr(0x200), addr(0x210));
|
||||
set.addRange(addr(0x55), addr(0xff));
|
||||
set2.addRange(addr(0x1000), addr(0x3000));
|
||||
namespaceManager.overlapsNamespace(set2);
|
||||
|
||||
if (namespaceManager.overlapsNamespace(set2) != null) {
|
||||
Assert.fail("Should not overlap!");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -352,11 +352,9 @@ public class FunctionManagerDB implements ManagerDB, FunctionManager {
|
||||
throw new IllegalArgumentException(
|
||||
"Function entryPoint may not be created on defined data");
|
||||
}
|
||||
try {
|
||||
namespaceMgr.overlapsNamespace(body);
|
||||
}
|
||||
catch (OverlappingNamespaceException e) {
|
||||
throw new OverlappingFunctionException(entryPoint, e);
|
||||
|
||||
if (namespaceMgr.overlapsNamespace(body) != null) {
|
||||
throw new OverlappingFunctionException(entryPoint);
|
||||
}
|
||||
|
||||
if (name == null || name.length() == 0 ||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +24,10 @@ public class OverlappingFunctionException extends Exception {
|
||||
super("Unable to create function at " + entryPoint + " due to overlap with range [" +
|
||||
e.getStart() + "," + e.getEnd() + "]");
|
||||
}
|
||||
|
||||
public OverlappingFunctionException(Address entryPoint) {
|
||||
super("Unable to create function at " + entryPoint + " due to overlap with another namespace");
|
||||
}
|
||||
|
||||
public OverlappingFunctionException(String msg) {
|
||||
super(msg);
|
||||
|
||||
@@ -124,8 +124,7 @@ public class NamespaceManager implements ManagerDB {
|
||||
* @param namespace the namespace whose body is to be modified.
|
||||
* @param set the address set for the new body.
|
||||
*/
|
||||
public void setBody(Namespace namespace, AddressSetView set)
|
||||
throws OverlappingNamespaceException {
|
||||
public void setBody(Namespace namespace, AddressSetView set) throws OverlappingNamespaceException {
|
||||
if (set.getNumAddresses() > Integer.MAX_VALUE) {
|
||||
throw new IllegalArgumentException(
|
||||
"Namespace body size must be less than 0x7fffffff byte addresses");
|
||||
@@ -133,12 +132,10 @@ public class NamespaceManager implements ManagerDB {
|
||||
lock.acquire();
|
||||
try {
|
||||
AddressSetView oldBody = removeBody(namespace);
|
||||
try {
|
||||
overlapsNamespace(set);
|
||||
}
|
||||
catch (OverlappingNamespaceException e) {
|
||||
AddressRange range = overlapsNamespace(set);
|
||||
if (range != null) {
|
||||
doSetBody(namespace, oldBody);
|
||||
throw e;
|
||||
throw new OverlappingNamespaceException(range.getMinAddress(), range.getMaxAddress());
|
||||
}
|
||||
doSetBody(namespace, set);
|
||||
}
|
||||
@@ -200,19 +197,20 @@ public class NamespaceManager implements ManagerDB {
|
||||
|
||||
/**
|
||||
* Checks if an existing namespace's address set intersects with
|
||||
* the given set. If so, then it throws an OverlappingNamespaceException.
|
||||
* @throws OverlappingNamespaceException if the address set to test overlaps a namespace body.
|
||||
* the given set. If so, return the first overlapping range.
|
||||
* @returns null if no overlaps, or an address range of the first overlap
|
||||
*/
|
||||
public void overlapsNamespace(AddressSetView set) throws OverlappingNamespaceException {
|
||||
AddressRangeIterator iter =
|
||||
namespaceMap.getAddressRanges(set.getMinAddress(), set.getMaxAddress());
|
||||
while (iter.hasNext()) {
|
||||
AddressRange range = iter.next();
|
||||
if (set.intersects(range.getMinAddress(), range.getMaxAddress())) {
|
||||
throw new OverlappingNamespaceException(range.getMinAddress(),
|
||||
range.getMaxAddress());
|
||||
public AddressRange overlapsNamespace(AddressSetView set) {
|
||||
AddressRangeIterator addressRanges = set.getAddressRanges();
|
||||
for (AddressRange addressRange : addressRanges) {
|
||||
AddressRangeIterator namesSpaceRanges = namespaceMap.getAddressRanges(
|
||||
addressRange.getMinAddress(), addressRange.getMaxAddress());
|
||||
AddressRange existingRange = namesSpaceRanges.next();
|
||||
if (existingRange != null) {
|
||||
return existingRange;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user