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