leveldown-security / SVD-Loader-Ghidra

GNU General Public License v3.0
468 stars 95 forks source link

Catch exception when there is memory overlap #6

Open kost-div opened 4 years ago

kost-div commented 4 years ago

Currently, when there is memory overlap in memory ranges, it fails with following exception:

Loading SVD file...
        Done!
Generating memory regions...
Traceback (most recent call last):
  File "/opt/ghidra-scripts/SVD-Loader-Ghidra/SVD-Loader.py", line 113, in <module>
    t = currentProgram.memory.createUninitializedBlock(r.name, addr, length, False)
  File "/opt/ghidra-scripts/SVD-Loader-Ghidra/SVD-Loader.py", line 113, in <module>
    t = currentProgram.memory.createUninitializedBlock(r.name, addr, length, False)
        at ghidra.program.database.mem.MemoryMapDB.checkRange(MemoryMapDB.java:1864)
        at ghidra.program.database.mem.MemoryMapDB.createUninitializedBlock(MemoryMapDB.java:611)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
ghidra.program.model.mem.MemoryConflictException: ghidra.program.model.mem.MemoryConflictException: Part of range (40023000, 400233ff) already exists in memory.
SVD-Loader.py> Finished!

So, clearly general exception block do not catch specific exception for memory overlap.

Fix catch correct exception and displays the following:

  Loading SVD file...
    Done!
Generating memory regions...
    Failed to generate due to conflict in memory block for: CRC
('\t', ghidra.program.model.mem.MemoryConflictException: Part of range (40023000, 400233ff) already exists in memory.)

Hope it helps and thanks for the SVD loader!