PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/linux/sleuthkit/fs/sigParseImageReview.py

https://bitbucket.org/jmstagg/snippets
Python | 43 lines | 36 code | 6 blank | 1 comment | 5 complexity | 8623bab530614346aacbcfe238110898 MD5 | raw file
  1. #!/usr/bin/python
  2. import sys, os, subprocess, re
  3. def runCommand(cmd):
  4. print "running: %s" % cmd
  5. proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
  6. return [proc.stdout.read(), proc.stderr.read()]
  7. def main(argv):
  8. if len(argv) < 3:
  9. sys.stderr.write("\nUsage: %s <hdax.dd> <file sig list of offsets> <output filename> \n" % (argv[0],))
  10. return 1
  11. if not os.path.exists(argv[1]) or not os.path.exists(argv[2]):
  12. sys.stderr.write("\nERROR: an input file was not found!\n")
  13. return 1
  14. dd = runCommand('which dd')[0].strip()
  15. identify = runCommand('which file')[0].strip()
  16. display = runCommand('which display')[0].strip()
  17. grep = runCommand('which grep')[0].strip()
  18. ddImage = argv[1]
  19. outputFile = open(argv[3], "w")
  20. inputFile = open(argv[2], "r")
  21. inputFile.readline()
  22. for line in inputFile:
  23. address = runCommand('echo "%s" | cut -f2 -d\' \'' % line)[0].strip()
  24. print "attempting number: %s" % address
  25. ddCmd = "%s if=%s count=4000 skip=%s" % (dd, ddImage, address)
  26. retval = runCommand("%s | %s - | %s \"image\"" % (ddCmd, identify, grep))[0]
  27. if retval != "":
  28. runCommand("%s | %s" % (ddCmd, display))
  29. saveMsg = os.sys.stdin.readline()
  30. if saveMsg != "":
  31. outputFile.write("%s : %s"%(address, saveMsg))
  32. inputFile.close()
  33. outputFile.close()
  34. if __name__ == "__main__":
  35. sys.exit(main(sys.argv))