@@ -17,16 +17,16 @@ abstract class AnELF
17
17
const string SymtabSectionName = ".symtab" ;
18
18
const string RodataSectionName = ".rodata" ;
19
19
20
- ISymbolTable dynamicSymbolsSection ;
21
- ISection rodataSection ;
20
+ ISymbolTable ? dynamicSymbolsSection ;
21
+ ISection ? rodataSection ;
22
22
ISymbolTable ? symbolsSection ;
23
23
string filePath ;
24
24
IELF elf ;
25
25
Stream elfStream ;
26
26
27
- protected ISymbolTable DynSymSection => dynamicSymbolsSection ;
27
+ protected ISymbolTable ? DynSymSection => dynamicSymbolsSection ;
28
28
protected ISymbolTable ? SymSection => symbolsSection ;
29
- protected ISection RodataSection => rodataSection ;
29
+ protected ISection ? RodataSection => rodataSection ;
30
30
public IELF AnyELF => elf ;
31
31
protected Stream ELFStream => elfStream ;
32
32
@@ -36,7 +36,7 @@ abstract class AnELF
36
36
public abstract bool Is64Bit { get ; }
37
37
public abstract string Bitness { get ; }
38
38
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 )
40
40
{
41
41
this . filePath = filePath ;
42
42
this . elf = elf ;
@@ -61,14 +61,14 @@ protected AnELF (Stream stream, string filePath, IELF elf, ISymbolTable dynsymSe
61
61
return symbol ;
62
62
}
63
63
64
- protected static ISymbolEntry ? GetSymbol ( ISymbolTable symtab , string symbolName )
64
+ protected static ISymbolEntry ? GetSymbol ( ISymbolTable ? symtab , string symbolName )
65
65
{
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 ( ) ;
67
67
}
68
68
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
70
70
{
71
- return symtab . Entries . Where ( entry => entry . Value . Equals ( symbolValue ) ) . FirstOrDefault ( ) ;
71
+ return symtab ? . Entries . Where ( entry => entry . Value . Equals ( symbolValue ) ) . FirstOrDefault ( ) ;
72
72
}
73
73
74
74
public bool HasSymbol ( string symbolName )
@@ -85,19 +85,22 @@ public byte[] GetData (string symbolName, out ISymbolEntry? symbolEntry)
85
85
{
86
86
Log . Debug ( $ "Looking for symbol: { symbolName } ") ;
87
87
symbolEntry = GetSymbol ( symbolName ) ;
88
- if ( symbolEntry == null )
88
+ if ( symbolEntry == null ) {
89
89
return EmptyArray ;
90
+ }
90
91
91
92
if ( Is64Bit ) {
92
93
var symbol64 = symbolEntry as SymbolEntry < ulong > ;
93
- if ( symbol64 == null )
94
+ if ( symbol64 == null ) {
94
95
throw new InvalidOperationException ( $ "Symbol '{ symbolName } ' is not a valid 64-bit symbol") ;
96
+ }
95
97
return GetData ( symbol64 ) ;
96
98
}
97
99
98
100
var symbol32 = symbolEntry as SymbolEntry < uint > ;
99
- if ( symbol32 == null )
101
+ if ( symbol32 == null ) {
100
102
throw new InvalidOperationException ( $ "Symbol '{ symbolName } ' is not a valid 32-bit symbol") ;
103
+ }
101
104
102
105
return GetData ( symbol32 ) ;
103
106
}
@@ -168,8 +171,9 @@ protected byte[] GetData (ISection section, ulong size, ulong offset)
168
171
return EmptyArray ;
169
172
}
170
173
171
- if ( size == 0 )
174
+ if ( size == 0 ) {
172
175
size = ( ulong ) data . Length - offset ;
176
+ }
173
177
174
178
var ret = new byte [ size ] ;
175
179
checked {
@@ -280,20 +284,8 @@ public static bool TryLoad (Stream stream, string filePath, out AnELF? anElf)
280
284
return false ;
281
285
}
282
286
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 ) ;
297
289
ISymbolTable ? sym = GetSymbolTable ( elf , SymtabSectionName ) ;
298
290
299
291
if ( is64 ) {
0 commit comments