proc_PID.py testing for pid
[signduterre.git] / proc_modules.py
blob6b3898c45825686ad8ed9341b4fb340ab1ba6cbb
1 # proc_modules
2 #
3 # Signature-du-Terroir module to handle /proc/modules
5 # Help text
6 help_text = """
7 Values:
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
18 Functions:
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
24 """
26 import re;
27 modulelist = [];
28 moduledict = {};
29 min_address = 10**100;
30 max_address = -1;
31 max_load = -1;
32 sum_sizes = 0;
33 with open('/proc/modules') as m:
34 for l in 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);
38 size = int(size);
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;
46 sum_sizes += size;
48 kallsyms_modulelist = [];
49 with open('/proc/kallsyms') as m:
50 for l in 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():
62 modulelist.sort();
63 s="";
64 for m in modulelist:
65 s += m+"\t"+str(moduledict[m]['size'])+"\n";
66 return s;
68 def sorted_offset_table():
69 modulelist.sort();
70 s="";
71 for m in modulelist:
72 s += m+"\t"+str(moduledict[m]['offset'])+"\n";
73 return s;
75 def sorted_loadnum_table():
76 modulelist.sort();
77 s="";
78 for m in modulelist:
79 s += m+"\t"+str(moduledict[m]['loadnum'])+"\n";
80 return s;
82 def sorted_dependencies_table():
83 modulelist.sort();
84 s="";
85 for m in modulelist:
86 s += m+"\t"+str(moduledict[m]['dependencies'])+"\n";
87 return s;
89 def sorted_state_table ():
90 modulelist.sort();
91 s="";
92 for m in modulelist:
93 s += m+"\t"+str(moduledict[m]['state'])+"\n";
94 return s;
96 def dump_module_binary (name):
97 module_binary = open('/proc/kcore');
99 if __name__ == "__main__":
100 print(help_text);
101 print(kallsyms_modulelist);