mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
Merge remote-tracking branch 'origin/GP-4079_d-millar_SARIF_ProgramTrees--SQUASHED'
This commit is contained in:
commit
9a34a446df
5 changed files with 37 additions and 33 deletions
|
@ -87,20 +87,14 @@ public class CommentsSarifMgr extends SarifMgr {
|
||||||
// SARIF READ CURRENT DTD //
|
// SARIF READ CURRENT DTD //
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|
||||||
/**
|
|
||||||
* Process the entry point section of the SARIF file.
|
|
||||||
*
|
|
||||||
* @param result sarif reader
|
|
||||||
* @param monitor monitor that can be canceled
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean read(Map<String, Object> result, SarifProgramOptions options, TaskMonitor monitor)
|
public boolean read(Map<String, Object> result, SarifProgramOptions options, TaskMonitor monitor)
|
||||||
throws AddressFormatException, CancelledException {
|
throws AddressFormatException, CancelledException {
|
||||||
processComment(result, result);
|
processComment(result);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processComment(Map<String, Object> result, Map<String, Object> result2) throws AddressFormatException {
|
private void processComment(Map<String, Object> result) throws AddressFormatException {
|
||||||
try {
|
try {
|
||||||
Address addr = getLocation(result);
|
Address addr = getLocation(result);
|
||||||
String typeStr = (String) result.get("kind");
|
String typeStr = (String) result.get("kind");
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class MemoryMapSarifMgr extends SarifMgr {
|
||||||
public boolean read(Map<String, Object> result, SarifProgramOptions options, TaskMonitor monitor)
|
public boolean read(Map<String, Object> result, SarifProgramOptions options, TaskMonitor monitor)
|
||||||
throws CancelledException {
|
throws CancelledException {
|
||||||
try {
|
try {
|
||||||
processMemoryBlock(result, result, programMgr.getDirectory(), program, monitor);
|
processMemoryBlock(result, programMgr.getDirectory(), program, monitor);
|
||||||
return true;
|
return true;
|
||||||
} catch (FileNotFoundException | AddressOverflowException e) {
|
} catch (FileNotFoundException | AddressOverflowException e) {
|
||||||
log.appendException(e);
|
log.appendException(e);
|
||||||
|
@ -83,8 +83,8 @@ public class MemoryMapSarifMgr extends SarifMgr {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processMemoryBlock(Map<String, Object> result, Map<String, Object> result2, String directory,
|
private void processMemoryBlock(Map<String, Object> result, String directory, Program program, TaskMonitor monitor)
|
||||||
Program program, TaskMonitor monitor) throws FileNotFoundException, AddressOverflowException {
|
throws FileNotFoundException, AddressOverflowException {
|
||||||
|
|
||||||
String name = (String) result.get("name");
|
String name = (String) result.get("name");
|
||||||
AddressSet set = getLocations(result, null);
|
AddressSet set = getLocations(result, null);
|
||||||
|
|
|
@ -26,10 +26,11 @@ import generic.stl.Pair;
|
||||||
import ghidra.app.util.importer.MessageLog;
|
import ghidra.app.util.importer.MessageLog;
|
||||||
import ghidra.program.model.address.Address;
|
import ghidra.program.model.address.Address;
|
||||||
import ghidra.program.model.address.AddressFormatException;
|
import ghidra.program.model.address.AddressFormatException;
|
||||||
|
import ghidra.program.model.address.AddressRange;
|
||||||
|
import ghidra.program.model.address.AddressRangeIterator;
|
||||||
import ghidra.program.model.address.AddressSetView;
|
import ghidra.program.model.address.AddressSetView;
|
||||||
import ghidra.program.model.listing.DuplicateGroupException;
|
import ghidra.program.model.listing.DuplicateGroupException;
|
||||||
import ghidra.program.model.listing.Group;
|
import ghidra.program.model.listing.Group;
|
||||||
import ghidra.program.model.listing.Listing;
|
|
||||||
import ghidra.program.model.listing.Program;
|
import ghidra.program.model.listing.Program;
|
||||||
import ghidra.program.model.listing.ProgramFragment;
|
import ghidra.program.model.listing.ProgramFragment;
|
||||||
import ghidra.program.model.listing.ProgramModule;
|
import ghidra.program.model.listing.ProgramModule;
|
||||||
|
@ -69,29 +70,18 @@ public class ProgramTreeSarifMgr extends SarifMgr {
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
// SARIF READ CURRENT DTD //
|
// SARIF READ CURRENT DTD //
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|
||||||
/**
|
|
||||||
* Read the Program tree section from an SARIF file.
|
|
||||||
*
|
|
||||||
* @param result parser for the SARIF
|
|
||||||
* @param m monitor that can be canceled
|
|
||||||
* @param addToProgram true if we are adding trees to an existing program
|
|
||||||
* @throws CancelledException if cancelled
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean read(Map<String, Object> result, SarifProgramOptions options, TaskMonitor m)
|
public boolean read(Map<String, Object> result, SarifProgramOptions options, TaskMonitor m)
|
||||||
throws CancelledException {
|
throws CancelledException {
|
||||||
this.monitor = m;
|
this.monitor = m;
|
||||||
|
|
||||||
// remove the default tree that is created when a program is instantiated
|
processTree(result);
|
||||||
listing.removeTree(Listing.DEFAULT_TREE_NAME);
|
|
||||||
|
|
||||||
processTree(result, result);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void processTree(Map<String, Object> result, Map<String, Object> result2) {
|
private void processTree(Map<String, Object> result) throws CancelledException {
|
||||||
treeName = (String) result.get("name");
|
treeName = (String) result.get("name");
|
||||||
fragmentNameList = new ArrayList<>();
|
fragmentNameList = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -125,6 +115,19 @@ public class ProgramTreeSarifMgr extends SarifMgr {
|
||||||
treeName = root.getTreeName();
|
treeName = root.getTreeName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Group[] orig = root.getChildren();
|
||||||
|
ProgramFragment depot = root.createFragment("depot");
|
||||||
|
for (Group g : orig) {
|
||||||
|
if (g instanceof ProgramFragment frag) {
|
||||||
|
AddressRangeIterator iter = frag.getAddressRanges(true);
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
AddressRange next = iter.next();
|
||||||
|
depot.move(next.getMinAddress(), next.getMaxAddress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
removeEmptyFragments(root);
|
||||||
|
|
||||||
List<Map<String, Object>> modules = (List<Map<String, Object>>) result.get("modules");
|
List<Map<String, Object>> modules = (List<Map<String, Object>>) result.get("modules");
|
||||||
for (Map<String, Object> m : modules) {
|
for (Map<String, Object> m : modules) {
|
||||||
monitor.checkCancelled();
|
monitor.checkCancelled();
|
||||||
|
@ -135,8 +138,8 @@ public class ProgramTreeSarifMgr extends SarifMgr {
|
||||||
monitor.checkCancelled();
|
monitor.checkCancelled();
|
||||||
processFragment(root, f);
|
processFragment(root, f);
|
||||||
}
|
}
|
||||||
removeEmptyFragments(root);
|
|
||||||
} catch (Exception e) {
|
} catch (NotFoundException | DuplicateNameException e) {
|
||||||
log.appendException(e);
|
log.appendException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,13 +62,10 @@ public class RegisterValuesSarifMgr extends SarifMgr {
|
||||||
// SARIF READ CURRENT DTD //
|
// SARIF READ CURRENT DTD //
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|
||||||
/**
|
|
||||||
* Process the entry point section of the SARIF file.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean read(Map<String, Object> result, SarifProgramOptions options, TaskMonitor monitor)
|
public boolean read(Map<String, Object> result, SarifProgramOptions options, TaskMonitor monitor)
|
||||||
throws CancelledException {
|
throws CancelledException {
|
||||||
processRegisterValues(result, result);
|
processRegisterValues(result);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +90,7 @@ public class RegisterValuesSarifMgr extends SarifMgr {
|
||||||
return regs;
|
return regs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processRegisterValues(Map<String, Object> result, Map<String, Object> result2) {
|
private void processRegisterValues(Map<String, Object> result) {
|
||||||
try {
|
try {
|
||||||
AddressSet set = getLocations(result, null);
|
AddressSet set = getLocations(result, null);
|
||||||
Address addr = set.getMinAddress();
|
Address addr = set.getMinAddress();
|
||||||
|
|
|
@ -194,6 +194,16 @@ public abstract class SarifMgr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read results from an SARIF file.
|
||||||
|
*
|
||||||
|
* @param result parsed SARIF results
|
||||||
|
* @param options for import/export
|
||||||
|
* @param monitor monitor that can be canceled
|
||||||
|
* @throws AddressFormatException for bad locations
|
||||||
|
* @throws CancelledException if cancelled
|
||||||
|
*/
|
||||||
|
|
||||||
public abstract boolean read(Map<String, Object> result, SarifProgramOptions options, TaskMonitor monitor)
|
public abstract boolean read(Map<String, Object> result, SarifProgramOptions options, TaskMonitor monitor)
|
||||||
throws AddressFormatException, CancelledException;
|
throws AddressFormatException, CancelledException;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue