Skip to content

Commit 17635fa

Browse files
committed
Lib: attempt to continue if elf file symbols are broken
1 parent ea01f90 commit 17635fa

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

LibCpp2IL/Elf/ElfFile.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,19 @@ public ElfFile(MemoryStream input) : base(input)
115115
LibLogger.VerboseNewline("\tProcessing Symbols...");
116116
start = DateTime.Now;
117117

118-
ProcessSymbols();
118+
try
119+
{
120+
ProcessSymbols();
119121

120-
LibLogger.VerboseNewline($"\tOK ({(DateTime.Now - start).TotalMilliseconds} ms)");
122+
LibLogger.VerboseNewline($"\tOK ({(DateTime.Now - start).TotalMilliseconds} ms)");
123+
}
124+
catch (Exception e)
125+
{
126+
LibLogger.ErrorNewline($"\tCaught {e.GetType().Name} processing symbols! Attempting to continue without symbol information (no exports, for example)...");
127+
#if DEBUG
128+
LibLogger.ErrorNewline(e.ToString());
129+
#endif
130+
}
121131

122132
LibLogger.Verbose("\tProcessing Initializers...");
123133
start = DateTime.Now;
@@ -397,7 +407,12 @@ private void ProcessSymbols()
397407
{
398408
if (GetDynamicEntryOfType(ElfDynamicType.DT_SYMTAB) is { } dynamicSymTab)
399409
{
400-
var end = _dynamicSection.Where(x => x.Value > dynamicSymTab.Value).OrderBy(x => x.Value).First().Value;
410+
var endSection = _dynamicSection.Where(x => x.Value > dynamicSymTab.Value).OrderBy(x => x.Value).FirstOrDefault();
411+
ulong end;
412+
if(endSection != null)
413+
end = endSection.Value;
414+
else
415+
end = GetProgramHeaderOfType(ElfProgramEntryType.PT_DYNAMIC) is {} dynamicSegment ? dynamicSegment.VirtualAddress + dynamicSegment.RawSize : (ulong)RawLength;
401416
var dynSymSize = is32Bit ? 18ul : 24ul;
402417

403418
var address = (ulong)MapVirtualAddressToRaw(dynamicSymTab.Value);

0 commit comments

Comments
 (0)