diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/managers/CommentsSarifMgr.java b/Ghidra/Features/Sarif/src/main/java/sarif/managers/CommentsSarifMgr.java index 5d69f48f82..b1979beae9 100644 --- a/Ghidra/Features/Sarif/src/main/java/sarif/managers/CommentsSarifMgr.java +++ b/Ghidra/Features/Sarif/src/main/java/sarif/managers/CommentsSarifMgr.java @@ -87,20 +87,14 @@ public class CommentsSarifMgr extends SarifMgr { // 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 public boolean read(Map result, SarifProgramOptions options, TaskMonitor monitor) throws AddressFormatException, CancelledException { - processComment(result, result); + processComment(result); return true; } - private void processComment(Map result, Map result2) throws AddressFormatException { + private void processComment(Map result) throws AddressFormatException { try { Address addr = getLocation(result); String typeStr = (String) result.get("kind"); diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/managers/MemoryMapSarifMgr.java b/Ghidra/Features/Sarif/src/main/java/sarif/managers/MemoryMapSarifMgr.java index 1bb529a561..495fac3006 100644 --- a/Ghidra/Features/Sarif/src/main/java/sarif/managers/MemoryMapSarifMgr.java +++ b/Ghidra/Features/Sarif/src/main/java/sarif/managers/MemoryMapSarifMgr.java @@ -75,7 +75,7 @@ public class MemoryMapSarifMgr extends SarifMgr { public boolean read(Map result, SarifProgramOptions options, TaskMonitor monitor) throws CancelledException { try { - processMemoryBlock(result, result, programMgr.getDirectory(), program, monitor); + processMemoryBlock(result, programMgr.getDirectory(), program, monitor); return true; } catch (FileNotFoundException | AddressOverflowException e) { log.appendException(e); @@ -83,8 +83,8 @@ public class MemoryMapSarifMgr extends SarifMgr { return false; } - private void processMemoryBlock(Map result, Map result2, String directory, - Program program, TaskMonitor monitor) throws FileNotFoundException, AddressOverflowException { + private void processMemoryBlock(Map result, String directory, Program program, TaskMonitor monitor) + throws FileNotFoundException, AddressOverflowException { String name = (String) result.get("name"); AddressSet set = getLocations(result, null); diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/managers/ProgramTreeSarifMgr.java b/Ghidra/Features/Sarif/src/main/java/sarif/managers/ProgramTreeSarifMgr.java index 2c54df5fc7..9d67ee98d9 100644 --- a/Ghidra/Features/Sarif/src/main/java/sarif/managers/ProgramTreeSarifMgr.java +++ b/Ghidra/Features/Sarif/src/main/java/sarif/managers/ProgramTreeSarifMgr.java @@ -26,10 +26,11 @@ import generic.stl.Pair; import ghidra.app.util.importer.MessageLog; import ghidra.program.model.address.Address; 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.listing.DuplicateGroupException; import ghidra.program.model.listing.Group; -import ghidra.program.model.listing.Listing; import ghidra.program.model.listing.Program; import ghidra.program.model.listing.ProgramFragment; import ghidra.program.model.listing.ProgramModule; @@ -69,29 +70,18 @@ public class ProgramTreeSarifMgr extends SarifMgr { //////////////////////////// // 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 public boolean read(Map result, SarifProgramOptions options, TaskMonitor m) throws CancelledException { this.monitor = m; - // remove the default tree that is created when a program is instantiated - listing.removeTree(Listing.DEFAULT_TREE_NAME); - - processTree(result, result); + processTree(result); return true; } @SuppressWarnings("unchecked") - private void processTree(Map result, Map result2) { + private void processTree(Map result) throws CancelledException { treeName = (String) result.get("name"); fragmentNameList = new ArrayList<>(); @@ -125,6 +115,19 @@ public class ProgramTreeSarifMgr extends SarifMgr { 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> modules = (List>) result.get("modules"); for (Map m : modules) { monitor.checkCancelled(); @@ -135,8 +138,8 @@ public class ProgramTreeSarifMgr extends SarifMgr { monitor.checkCancelled(); processFragment(root, f); } - removeEmptyFragments(root); - } catch (Exception e) { + + } catch (NotFoundException | DuplicateNameException e) { log.appendException(e); } } diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/managers/RegisterValuesSarifMgr.java b/Ghidra/Features/Sarif/src/main/java/sarif/managers/RegisterValuesSarifMgr.java index dff936175e..9f1d561833 100644 --- a/Ghidra/Features/Sarif/src/main/java/sarif/managers/RegisterValuesSarifMgr.java +++ b/Ghidra/Features/Sarif/src/main/java/sarif/managers/RegisterValuesSarifMgr.java @@ -62,13 +62,10 @@ public class RegisterValuesSarifMgr extends SarifMgr { // SARIF READ CURRENT DTD // //////////////////////////// - /** - * Process the entry point section of the SARIF file. - */ @Override public boolean read(Map result, SarifProgramOptions options, TaskMonitor monitor) throws CancelledException { - processRegisterValues(result, result); + processRegisterValues(result); return true; } @@ -93,7 +90,7 @@ public class RegisterValuesSarifMgr extends SarifMgr { return regs; } - private void processRegisterValues(Map result, Map result2) { + private void processRegisterValues(Map result) { try { AddressSet set = getLocations(result, null); Address addr = set.getMinAddress(); diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/managers/SarifMgr.java b/Ghidra/Features/Sarif/src/main/java/sarif/managers/SarifMgr.java index 6b39fb332e..fa2747b13e 100644 --- a/Ghidra/Features/Sarif/src/main/java/sarif/managers/SarifMgr.java +++ b/Ghidra/Features/Sarif/src/main/java/sarif/managers/SarifMgr.java @@ -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 result, SarifProgramOptions options, TaskMonitor monitor) throws AddressFormatException, CancelledException;