Skip to content

Commit 8048372

Browse files
committed
split module functions to keep current API
1 parent 6372b6f commit 8048372

File tree

1 file changed

+46
-31
lines changed
  • volatility3/framework/symbols/linux/extensions

1 file changed

+46
-31
lines changed

volatility3/framework/symbols/linux/extensions/__init__.py

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -104,64 +104,79 @@ def get_sections(self):
104104
for attr in arr:
105105
yield attr
106106

107-
def get_symbols(self):
108-
"""Get module symbols
109-
110-
Yields:
111-
A tuple for each symbol containing the symbol name and its corresponding value
112-
"""
113-
if symbols.symbol_table_is_64bit(self._context, self.get_symbol_table_name()):
114-
prefix = "Elf64_"
115-
else:
116-
prefix = "Elf32_"
107+
def get_elf_table_name(self):
117108
elf_table_name = intermed.IntermediateSymbolTable.create(
118109
self._context,
119-
"module",
110+
"config_name_elf_symbol_table",
120111
"linux",
121112
"elf",
122113
native_types=None,
123114
class_types=elf.class_types,
124115
)
116+
return elf_table_name
117+
118+
def get_symbols(self):
119+
"""Get symbols of the module
120+
121+
Yields:
122+
A symbol object
123+
"""
125124

125+
if not hasattr(self, "_elf_table_name"):
126+
self._elf_table_name = self.get_elf_table_name()
127+
if symbols.symbol_table_is_64bit(self._context, self.get_symbol_table_name()):
128+
prefix = "Elf64_"
129+
else:
130+
prefix = "Elf32_"
126131
syms = self._context.object(
127132
self.get_symbol_table_name() + constants.BANG + "array",
128133
layer_name=self.vol.layer_name,
129134
offset=self.section_symtab,
130135
subtype=self._context.symbol_space.get_type(
131-
elf_table_name + constants.BANG + prefix + "Sym"
136+
self._elf_table_name + constants.BANG + prefix + "Sym"
132137
),
133138
count=self.num_symtab + 1,
134139
)
135140
if self.section_strtab:
136141
for sym in syms:
137-
sym_arr = self._context.object(
138-
self.get_symbol_table_name() + constants.BANG + "array",
139-
layer_name=self.vol.native_layer_name,
140-
offset=self.section_strtab + sym.st_name,
141-
)
142-
try:
143-
sym_name = utility.array_to_string(
144-
sym_arr, 512
145-
) # 512 is the value of KSYM_NAME_LEN kernel constant
146-
except exceptions.InvalidAddressException:
147-
continue
148-
if sym_name != "":
149-
# Normalize sym.st_value offset, which is an address pointing to the symbol value
150-
mask = self._context.layers[self.vol.layer_name].address_mask
151-
sym_address = sym.st_value & mask
152-
yield (sym_name, sym_address)
142+
yield sym
143+
144+
def get_symbols_names_and_addresses(self):
145+
"""Get names and addresses for each symbol of the module
146+
147+
Yields:
148+
A tuple for each symbol containing the symbol name and its corresponding value
149+
"""
150+
151+
for sym in self.get_symbols():
152+
sym_arr = self._context.object(
153+
self.get_symbol_table_name() + constants.BANG + "array",
154+
layer_name=self.vol.native_layer_name,
155+
offset=self.section_strtab + sym.st_name,
156+
)
157+
try:
158+
sym_name = utility.array_to_string(
159+
sym_arr, 512
160+
) # 512 is the value of KSYM_NAME_LEN kernel constant
161+
except exceptions.InvalidAddressException:
162+
continue
163+
if sym_name != "":
164+
# Normalize sym.st_value offset, which is an address pointing to the symbol value
165+
mask = self._context.layers[self.vol.layer_name].address_mask
166+
sym_address = sym.st_value & mask
167+
yield (sym_name, sym_address)
153168

154169
def get_symbol(self, wanted_sym_name):
155170
"""Get symbol value for a given symbol name"""
156-
for sym_name, sym_address in self.get_symbols():
171+
for sym_name, sym_address in self.get_symbols_names_and_addresses():
157172
if wanted_sym_name == sym_name:
158173
return sym_address
159174

160175
return None
161176

162-
def get_symbol_from_address(self, wanted_sym_address):
177+
def get_symbol_by_address(self, wanted_sym_address):
163178
"""Get symbol name for a given symbol address"""
164-
for sym_name, sym_address in self.get_symbols():
179+
for sym_name, sym_address in self.get_symbols_names_and_addresses():
165180
if wanted_sym_address == sym_address:
166181
return sym_name
167182

0 commit comments

Comments
 (0)