1   
 2   
 3   
 4   
 5   
 6   
 7   
 8   
 9   
10   
11   
12   
13   
14   
15   
16   
17   
18   
19   
20   
21   
22   
23  """ 
24  @author:       Andrew Case 
25  @license:      GNU General Public License 2.0 
26  @contact:      atcuno@gmail.com 
27  @organization: 
28  """ 
29   
30  from rekall import testlib 
31  from rekall.plugins.linux import common 
32   
33   
34 -class Lsof(common.LinProcessFilter): 
 35      """Lists open files.""" 
36   
37      __name = "lsof" 
38   
39      table_header = [ 
40          dict(name="divider", type="Divider"), 
41          dict(name="proc", hidden=True), 
42          dict(name="file_struct", hidden=True), 
43          dict(name="name", width=30), 
44          dict(name="pid", width=6, align="r"), 
45          dict(name="user", width=8), 
46          dict(name="fd", width=4), 
47          dict(name="size", width=12), 
48          dict(name="offset", width=12), 
49          dict(name="node", width=8), 
50          dict(name="path"), 
51      ] 
52   
54          """List all the files open by a task.""" 
55           
56           
57          for i, file_ptr in enumerate(task.files.fds): 
58              file_struct = file_ptr.deref() 
59              if file_struct: 
60                  yield file_struct, i 
 61   
66   
68          for task in self.filter_processes(): 
69              yield dict(divider=task) 
70              for file_struct, fd in self.get_open_files(task): 
71                  yield dict(proc=task, 
72                             name=task.comm, 
73                             pid=task.pid, 
74                             user=task.uid, 
75                             fd=fd, 
76                             file_struct=file_struct, 
77                             size=file_struct.m("f_path.dentry.d_inode.i_size"), 
78                             offset=file_struct.m("f_pos"), 
79                             node=file_struct.m("f_path.dentry.d_inode.i_ino"), 
80                             path=task.get_path(file_struct)) 
  81   
82   
83 -class TestLsof(testlib.SimpleTestCase): 
 84      @classmethod 
87   
88      PARAMETERS = dict( 
89          commandline="lsof --proc_regex %(proc_name)s", 
90          proc_name="bash" 
91          ) 
 92