PageRenderTime 381ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 1ms

/linux/sleuthkit/fs/sigParseImageDump.py

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