3 # Signature-du-Terroir module to handle /proc/modules
8 modulelist: List of module names
9 moduledict: Dictionary of [module-name] = {'size', 'loadnum', 'dependencies', 'state', 'offset'}
10 moduledict['video']['offset'] -> offset adress in kernel of the 'video' module
11 min_address: Lowest offset address
12 max_load: Highest offset address
13 max_address: max_load + size-of-last-module
14 sum_sizes: sum of all module sizes
15 memory_range: max_address - min_address
16 kallsyms_modulelist: List of module names constructed from the exported kernel symbols in /proc/kallsyms
19 sorted_sizes_table(): Alphabetically sorted table of modules+sizes as a string
20 sorted_offset_table(): Alphabetically sorted table of modules+offset as a string
21 sorted_loadnum_table(): Alphabetically sorted table of modules+loadnum as a string
22 sorted_dependencies_table(): Alphabetically sorted table of modules+dependencies as a string
23 sorted_state_table(): Alphabetically sorted table of modules+state as a string
29 min_address
= 10**100;
33 with
open('/proc/modules') as m
:
35 module_value
= re
.split(r
'\s+', l
.rstrip('\s\n'));
36 (module
, size
, loadnum
, dependencies
, state
, offset
) = module_value
[0:6];
37 modulelist
.append(module
);
39 loadnum
= int(loadnum
);
40 offset
= int(offset
, 16);
41 module_entry
= {'size':size
, 'loadnum':loadnum
, 'dependencies':dependencies
, 'state':state
, 'offset':offset
};
42 moduledict
[module
] = module_entry
;
43 if min_address
> offset
: min_address
= offset
;
44 if max_address
< offset
+size
: max_address
= offset
+ size
;
45 if max_load
< offset
: max_load
= offset
;
48 kallsyms_modulelist
= [];
49 with
open('/proc/kallsyms') as m
:
51 module_value
= re
.split(r
'\s+', l
.rstrip('\s\n'));
52 module
= module_value
[-1];
53 if module
.startswith('['):
54 modulename
= module
.lstrip('[').rstrip(']');
55 if not modulename
in kallsyms_modulelist
:
56 kallsyms_modulelist
.append(modulename
);
57 kallsyms_modulelist
.sort();
59 memory_range
= max_address
- min_address
61 def sorted_sizes_table():
65 s
+= m
+"\t"+str(moduledict
[m
]['size'])+"\n";
68 def sorted_offset_table():
72 s
+= m
+"\t"+str(moduledict
[m
]['offset'])+"\n";
75 def sorted_loadnum_table():
79 s
+= m
+"\t"+str(moduledict
[m
]['loadnum'])+"\n";
82 def sorted_dependencies_table():
86 s
+= m
+"\t"+str(moduledict
[m
]['dependencies'])+"\n";
89 def sorted_state_table ():
93 s
+= m
+"\t"+str(moduledict
[m
]['state'])+"\n";
96 def dump_module_binary (name
):
97 module_binary
= open('/proc/kcore');
99 if __name__
== "__main__":
101 print(kallsyms_modulelist
);