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
27 Signature-du-Terroir module to access /proc/modules pseudo file.
29 copyright 2009, R.J.J.H. van Son
31 This program is free software: you can redistribute it and/or modify
32 it under the terms of the GNU General Public License as published by
33 the Free Software Foundation, either version 3 of the License, or
34 (at your option) any later version.
36 This program is distributed in the hope that it will be useful,
37 but WITHOUT ANY WARRANTY; without even the implied warranty of
38 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 GNU General Public License for more details.
41 You should have received a copy of the GNU General Public License
42 along with this program. If not, see <http://www.gnu.org/licenses/>.
48 min_address
= 10**100;
52 with
open('/proc/modules') as m
:
54 module_value
= re
.split(r
'\s+', l
.rstrip('\s\n'));
55 (module
, size
, loadnum
, dependencies
, state
, offset
) = module_value
[0:6];
56 modulelist
.append(module
);
58 loadnum
= int(loadnum
);
59 offset
= int(offset
, 16);
60 module_entry
= {'size':size
, 'loadnum':loadnum
, 'dependencies':dependencies
, 'state':state
, 'offset':offset
};
61 moduledict
[module
] = module_entry
;
62 if min_address
> offset
: min_address
= offset
;
63 if max_address
< offset
+size
: max_address
= offset
+ size
;
64 if max_load
< offset
: max_load
= offset
;
67 kallsyms_modulelist
= [];
68 with
open('/proc/kallsyms') as m
:
70 module_value
= re
.split(r
'\s+', l
.rstrip('\s\n'));
71 module
= module_value
[-1];
72 if module
.startswith('['):
73 modulename
= module
.lstrip('[').rstrip(']');
74 if not modulename
in kallsyms_modulelist
:
75 kallsyms_modulelist
.append(modulename
);
76 kallsyms_modulelist
.sort();
78 memory_range
= max_address
- min_address
80 def sorted_sizes_table():
84 s
+= m
+"\t"+str(moduledict
[m
]['size'])+"\n";
87 def sorted_offset_table():
91 s
+= m
+"\t"+str(moduledict
[m
]['offset'])+"\n";
94 def sorted_loadnum_table():
98 s
+= m
+"\t"+str(moduledict
[m
]['loadnum'])+"\n";
101 def sorted_dependencies_table():
105 s
+= m
+"\t"+str(moduledict
[m
]['dependencies'])+"\n";
108 def sorted_state_table ():
112 s
+= m
+"\t"+str(moduledict
[m
]['state'])+"\n";
115 def dump_module_binary (name
):
116 module_binary
= open('/proc/kcore');
118 if __name__
== "__main__":
120 print(kallsyms_modulelist
);