From 682eb3109960907ff45188f7e96f54056da6e58d Mon Sep 17 00:00:00 2001 From: Rob Date: Wed, 16 Sep 2009 12:16:50 +0200 Subject: [PATCH] Refactoring proc_PID --- proc_PID.py | 35 +++++++++++++++++------------------ signduterre.py | 2 +- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/proc_PID.py b/proc_PID.py index c6a316f..be8f0fa 100644 --- a/proc_PID.py +++ b/proc_PID.py @@ -88,8 +88,11 @@ def get_filesystem(path): df_output = process.stdout.read(); return df_output.split()[0]; -def get_debugfs_command (): - return "/sbin/debugfs -f - "+file_system+" -R "; +def get_debugfs_command (file_system, inode): + if os.getuid() != 0: + print("ERROR: must be root to read disk blocks\n", file=sys.stderr); + exit(1); + return "/sbin/debugfs -f - "+file_system+" -R 'cat <"+str(inode)+">'"; def reset (): global file_system; @@ -201,8 +204,7 @@ def inode (command, path): # Get file contents on inode number return_value = b''; inode = map_list[path]['inode']; - cat = "'cat <"+str(inode)+">'"; - debugfs = subprocess.Popen(get_debugfs_command()+cat, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, shell=True, universal_newlines=False); + debugfs = subprocess.Popen(get_debugfs_command(file_system, inode), stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, shell=True, universal_newlines=False); # read out the file contents for l in debugfs.stdout: if type(l).__name__ == 'str': @@ -218,8 +220,7 @@ def maps (command): return_value = b''; for file in path_list: inode = map_list[file]['inode']; - cat = "'cat <"+str(inode)+">'"; - debugfs = subprocess.Popen(get_debugfs_command()+cat, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, shell=True, universal_newlines=False); + debugfs = subprocess.Popen(get_debugfs_command(file_system, inode), stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, shell=True, universal_newlines=False); # read out the file contents for l in debugfs.stdout: if type(l).__name__ == 'str': @@ -229,9 +230,9 @@ def maps (command): return return_value; # Methods that return the SHA512sum -def fileSHA (command, prefix=b''): +def fileSHA (command, prefix=''): getinfo (command); - filehash = hashlib.sha512(prefix); + filehash = hashlib.sha512(bytes(prefix, encoding='ascii')); with open(mapsfile, 'rb') as file: for l in file: if type(l).__name__ == 'str': @@ -239,9 +240,9 @@ def fileSHA (command, prefix=b''): filehash.update(l); return str(filehash.hexdigest()); -def exeSHA (command, prefix=b''): +def exeSHA (command, prefix=''): getinfo(command); - exehash = hashlib.sha512(prefix); + exehash = hashlib.sha512(bytes(prefix, encoding='ascii')); with open(exe, 'rb') as file: for l in file: if type(l).__name__ == 'str': @@ -249,15 +250,14 @@ def exeSHA (command, prefix=b''): exehash.update(l); return str(exehash.hexdigest()); -def inodeSHA (command, path='', prefix=b''): +def inodeSHA (command, path='', prefix=''): getinfo(command); if len(path) == 0: path = mapsfile; # Get file contents on inode number - mapshash = hashlib.sha512(prefix); + mapshash = hashlib.sha512(bytes(prefix, encoding='ascii')); inode = map_list[path]['inode']; - cat = "'cat <"+str(inode)+">'"; - debugfs = subprocess.Popen(get_debugfs_command()+cat, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, shell=True, universal_newlines=False); + debugfs = subprocess.Popen(get_debugfs_command(file_system, inode), stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, shell=True, universal_newlines=False); # read out the file contents for l in debugfs.stdout: if type(l).__name__ == 'str': @@ -266,15 +266,14 @@ def inodeSHA (command, path='', prefix=b''): return str(mapshash.hexdigest()); -def mapsSHA (command, prefix=b''): +def mapsSHA (command, prefix=''): getinfo(command); # Get file contents on inode number - mapshash = hashlib.sha512(prefix); + mapshash = hashlib.sha512(bytes(prefix, encoding='ascii')); for path in path_list: inode = map_list[path]['inode']; - cat = "'cat <"+str(inode)+">'"; - debugfs = subprocess.Popen(get_debugfs_command()+cat, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, shell=True, universal_newlines=False); + debugfs = subprocess.Popen(get_debugfs_command(file_system, inode), stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, shell=True, universal_newlines=False); # read out the file contents for l in debugfs.stdout: if type(l).__name__ == 'str': diff --git a/signduterre.py b/signduterre.py index 3611b2e..4beaf65 100755 --- a/signduterre.py +++ b/signduterre.py @@ -1434,7 +1434,7 @@ for my_passphrase in passphrase_list: # Compile and execute code in a limited namespace user_code = compile(statement_string+"\nsdt_export_result = sdt_exec_code()\n", '', 'exec'); userdict = {'sdt_export_result' : None}; - userdict['mainprefix'] = bytes(prefix, encoding='ascii'); + userdict['mainprefix'] = prefix; argvlist = []; argvlist.append(os.getpid()); for value in execute_args.split(): -- 2.11.4.GIT