@@ -73,28 +73,29 @@ def _get_modules_memory_boundaries(self, vmlinux):
7373
7474 return modules_addr_min , modules_addr_max
7575
76- def _get_module_state_live_bytes (
76+ def _get_module_state_values_bytes (
7777 self ,
7878 context : interfaces .context .ContextInterface ,
7979 vmlinux_module_name : str ,
80- ) -> bytes :
81- """Retrieve the MODULE_STATE_LIVE value bytes by introspecting its enum type
80+ ) -> List [ bytes ] :
81+ """Retrieve the module state values bytes by introspecting its enum type
8282
8383 Args:
8484 context: The context to retrieve required elements (layers, symbol tables) from
8585 vmlinux_module_name: The name of the kernel module on which to operate
8686
8787 Returns:
88- The MODULE_STATE_LIVE value bytes
88+ A list with the module state values bytes
8989 """
9090 vmlinux = context .modules [vmlinux_module_name ]
9191 module_state_type_template = vmlinux .get_type ("module" ).vol .members ["state" ][1 ]
92- module_state_live_val = module_state_type_template .choices ["MODULE_STATE_LIVE" ]
9392 data_format = module_state_type_template .base_type .vol .data_format
94- module_state_live_bytes = objects .convert_value_to_data (
95- module_state_live_val , int , data_format
96- )
97- return module_state_live_bytes
93+ values = module_state_type_template .choices .values ()
94+ values_bytes = [
95+ objects .convert_value_to_data (value , int , data_format )
96+ for value in sorted (values )
97+ ]
98+ return values_bytes
9899
99100 def get_hidden_modules_vol2 (
100101 self ,
@@ -174,11 +175,12 @@ def get_hidden_modules_vol2(
174175 scan_buf = b"" .join (scan_list )
175176 del scan_list
176177
177- module_state_live_bytes = self ._get_module_state_live_bytes (
178+ module_state_values_bytes = self ._get_module_state_values_bytes (
178179 context , vmlinux_module_name
179180 )
181+ values_bytes_pattern = b"|" .join (module_state_values_bytes )
180182 # f'strings cannot be combined with bytes literals
181- for cur_addr in re .finditer (b"(?=(%s))" % ( module_state_live_bytes ) , scan_buf ):
183+ for cur_addr in re .finditer (b"(?=(%s))" % values_bytes_pattern , scan_buf ):
182184 module_addr = modules_addr_min + cur_addr .start ()
183185
184186 if module_addr in known_module_addresses :
@@ -235,7 +237,7 @@ def get_hidden_modules_fast(
235237
236238 module_addr_min , module_addr_max = modules_memory_boundaries
237239
238- module_state_live_bytes = self ._get_module_state_live_bytes (
240+ module_state_values_bytes = self ._get_module_state_values_bytes (
239241 context , vmlinux_module_name
240242 )
241243
@@ -248,9 +250,9 @@ def get_hidden_modules_fast(
248250 try :
249251 # This is just a pre-filter. Module readability and consistency are verified in module.is_valid()
250252 module_state_bytes = vmlinux_layer .read (
251- module_addr , len (module_state_live_bytes )
253+ module_addr , len (module_state_values_bytes [ 0 ] )
252254 )
253- if module_state_bytes != module_state_live_bytes :
255+ if module_state_bytes not in module_state_values_bytes :
254256 continue
255257 except (
256258 exceptions .PagedInvalidAddressException ,
0 commit comments