.
Bitland.Net Security Notes            Comments? email jwilkins-at-bitland*net
More information on the author at Jonathan Wilkins's home page
RSS feed available at http://www.bitland.net/index.rss               Add to Google
Archives: 2007, 2006, 2005, 2004, 2003, 2002, 2001, 2000


Find encrypted or compressed files  |  (2005/10/04 17:45)

I'm going to start stashing random python scripts I write here since some of them will probably be useful for other people. Last weekend Jesse and I were going through the PSP firmware and wanted to find all of the files that weren't packed so we each whipped up a quick python script. I think it's probably more useful as the inverse script so that's what's here. If you want uncompressed, change line 18 to <
# Find encrypted or compressed files
# This isn't perfect, but typically compressed or encrypted files 
# can't be further compressed.  Properly encryped files look like
# random data and fully compressed files can't be made smaller.
import bz2, os
from os.path import join, getsize

for root, dirs, files in os.walk('.'):
	for name in files:
		inf = file(join(root, name), 'rb')
		s=inf.read()
		inf.close()
		insize = len(s)
		if insize > 0:
			c = bz2.compress(s, 9)
			csize = len(c)
			cratio = csize * 1.0 / insize
			if cratio > .98:
				print "%s: %d/%d (%.2f)" % (join(root, name), insize, csize, cratio)



+digg  |  +del.icio.us   |    [Python ]   |   Permanent link

RSS feed available at http://www.bitland.net/index.rss