@@ -17,16 +17,16 @@ abstract class AnELF
1717 const string SymtabSectionName = ".symtab" ;
1818 const string RodataSectionName = ".rodata" ;
1919
20- ISymbolTable dynamicSymbolsSection ;
21- ISection rodataSection ;
20+ ISymbolTable ? dynamicSymbolsSection ;
21+ ISection ? rodataSection ;
2222 ISymbolTable ? symbolsSection ;
2323 string filePath ;
2424 IELF elf ;
2525 Stream elfStream ;
2626
27- protected ISymbolTable DynSymSection => dynamicSymbolsSection ;
27+ protected ISymbolTable ? DynSymSection => dynamicSymbolsSection ;
2828 protected ISymbolTable ? SymSection => symbolsSection ;
29- protected ISection RodataSection => rodataSection ;
29+ protected ISection ? RodataSection => rodataSection ;
3030 public IELF AnyELF => elf ;
3131 protected Stream ELFStream => elfStream ;
3232
@@ -36,7 +36,7 @@ abstract class AnELF
3636 public abstract bool Is64Bit { get ; }
3737 public abstract string Bitness { get ; }
3838
39- protected AnELF ( Stream stream , string filePath , IELF elf , ISymbolTable dynsymSection , ISection rodataSection , ISymbolTable ? symSection )
39+ protected AnELF ( Stream stream , string filePath , IELF elf , ISymbolTable ? dynsymSection , ISection ? rodataSection , ISymbolTable ? symSection )
4040 {
4141 this . filePath = filePath ;
4242 this . elf = elf ;
@@ -61,14 +61,14 @@ protected AnELF (Stream stream, string filePath, IELF elf, ISymbolTable dynsymSe
6161 return symbol ;
6262 }
6363
64- protected static ISymbolEntry ? GetSymbol ( ISymbolTable symtab , string symbolName )
64+ protected static ISymbolEntry ? GetSymbol ( ISymbolTable ? symtab , string symbolName )
6565 {
66- return symtab . Entries . Where ( entry => String . Compare ( entry . Name , symbolName , StringComparison . Ordinal ) == 0 ) . FirstOrDefault ( ) ;
66+ return symtab ? . Entries . Where ( entry => String . Compare ( entry . Name , symbolName , StringComparison . Ordinal ) == 0 ) . FirstOrDefault ( ) ;
6767 }
6868
69- protected static SymbolEntry < T > ? GetSymbol < T > ( SymbolTable < T > symtab , T symbolValue ) where T : struct
69+ protected static SymbolEntry < T > ? GetSymbol < T > ( SymbolTable < T > ? symtab , T symbolValue ) where T : struct
7070 {
71- return symtab . Entries . Where ( entry => entry . Value . Equals ( symbolValue ) ) . FirstOrDefault ( ) ;
71+ return symtab ? . Entries . Where ( entry => entry . Value . Equals ( symbolValue ) ) . FirstOrDefault ( ) ;
7272 }
7373
7474 public bool HasSymbol ( string symbolName )
@@ -85,19 +85,22 @@ public byte[] GetData (string symbolName, out ISymbolEntry? symbolEntry)
8585 {
8686 Log . Debug ( $ "Looking for symbol: { symbolName } ") ;
8787 symbolEntry = GetSymbol ( symbolName ) ;
88- if ( symbolEntry == null )
88+ if ( symbolEntry == null ) {
8989 return EmptyArray ;
90+ }
9091
9192 if ( Is64Bit ) {
9293 var symbol64 = symbolEntry as SymbolEntry < ulong > ;
93- if ( symbol64 == null )
94+ if ( symbol64 == null ) {
9495 throw new InvalidOperationException ( $ "Symbol '{ symbolName } ' is not a valid 64-bit symbol") ;
96+ }
9597 return GetData ( symbol64 ) ;
9698 }
9799
98100 var symbol32 = symbolEntry as SymbolEntry < uint > ;
99- if ( symbol32 == null )
101+ if ( symbol32 == null ) {
100102 throw new InvalidOperationException ( $ "Symbol '{ symbolName } ' is not a valid 32-bit symbol") ;
103+ }
101104
102105 return GetData ( symbol32 ) ;
103106 }
@@ -168,8 +171,9 @@ protected byte[] GetData (ISection section, ulong size, ulong offset)
168171 return EmptyArray ;
169172 }
170173
171- if ( size == 0 )
174+ if ( size == 0 ) {
172175 size = ( ulong ) data . Length - offset ;
176+ }
173177
174178 var ret = new byte [ size ] ;
175179 checked {
@@ -280,20 +284,8 @@ public static bool TryLoad (Stream stream, string filePath, out AnELF? anElf)
280284 return false ;
281285 }
282286
283- ISymbolTable ? symtab = GetSymbolTable ( elf , DynsymSectionName ) ;
284- if ( symtab == null ) {
285- Log . Warning ( $ "{ filePath } does not contain dynamic symbol section '{ DynsymSectionName } '") ;
286- return false ;
287- }
288- ISymbolTable dynsym = symtab ;
289-
290- ISection ? sec = GetSection ( elf , RodataSectionName ) ;
291- if ( sec == null ) {
292- Log . Warning ( $ "{ filePath } does not contain read-only data section ('{ RodataSectionName } ')") ;
293- return false ;
294- }
295- ISection rodata = sec ;
296-
287+ ISymbolTable ? dynsym = GetSymbolTable ( elf , DynsymSectionName ) ;
288+ ISection ? rodata = GetSection ( elf , RodataSectionName ) ;
297289 ISymbolTable ? sym = GetSymbolTable ( elf , SymtabSectionName ) ;
298290
299291 if ( is64 ) {
0 commit comments