Make EH table optional in R2RDump
authorSimon Nattress <nattress@gmail.com>
Wed, 19 Sep 2018 17:24:02 +0000 (10:24 -0700)
committerSimon Nattress <nattress@gmail.com>
Fri, 21 Sep 2018 04:14:11 +0000 (21:14 -0700)
Ready-to-run binaries don't always have an EH table. Fix r2rdump so it doesn't crash if the table isn't present.

src/tools/r2rdump/R2RReader.cs

index c7da578..fb5d30b 100644 (file)
@@ -189,8 +189,11 @@ namespace R2RDump
 
                     ParseDebugInfo();
 
-                    R2RSection exceptionInfoSection = R2RHeader.Sections[R2RSection.SectionType.READYTORUN_SECTION_EXCEPTION_INFO];
-                    EHLookupTable = new EHLookupTable(Image, GetOffset(exceptionInfoSection.RelativeVirtualAddress), exceptionInfoSection.Size);
+                    if (R2RHeader.Sections.ContainsKey(R2RSection.SectionType.READYTORUN_SECTION_EXCEPTION_INFO))
+                    {
+                        R2RSection exceptionInfoSection = R2RHeader.Sections[R2RSection.SectionType.READYTORUN_SECTION_EXCEPTION_INFO];
+                        EHLookupTable = new EHLookupTable(Image, GetOffset(exceptionInfoSection.RelativeVirtualAddress), exceptionInfoSection.Size);
+                    }
 
                     R2RMethods = new List<R2RMethod>();
                     if (R2RHeader.Sections.ContainsKey(R2RSection.SectionType.READYTORUN_SECTION_RUNTIME_FUNCTIONS))
@@ -391,7 +394,7 @@ namespace R2RDump
                     EHInfo ehInfo = null;
 
                     EHInfoLocation ehInfoLocation;
-                    if (EHLookupTable.RuntimeFunctionToEHInfoMap.TryGetValue(startRva, out ehInfoLocation))
+                    if (EHLookupTable != null && EHLookupTable.RuntimeFunctionToEHInfoMap.TryGetValue(startRva, out ehInfoLocation))
                     {
                         ehInfo = new EHInfo(this, ehInfoLocation.EHInfoRVA, startRva, GetOffset(ehInfoLocation.EHInfoRVA), ehInfoLocation.ClauseCount);
                     }