def testFindAll(self):
     a = Bits('0b0010011')
     b = list(a.findall([1]))
     self.assertEqual(b, [2, 5, 6])
Exemple #2
0
 def testFindAll(self):
     a = Bits('0b0010011')
     b = list(a.findall([1]))
     self.assertEqual(b, [2, 5, 6])
Exemple #3
0
	print "Usage: hexsearch pattern files"
	print "	pattern can be hex (0x00ff) or binary (0b1100)"	
	exit(1)

pattern = argv[1].replace(' ', '') # findall handles spaces just fine but removing them makes calculating the length easier
patternLen = (len(pattern) - 2) / 2 # remove the 0x prefix and each byte is 2 characters

print 'Searching for pattern ' + pattern + ' of length ' + str(patternLen) + ' bytes'

for fileglob in argv[2:]:
	for file in glob(fileglob):
		if not os.access(file, os.R_OK):
			print "Can't read the file path '" + file + "'. Skipping."
			continue

		if os.path.isdir(file):
			print "'' is a directory. Skipping."
			continue
		
		f = open(file, "rb")
		s = Bits(f)
		results = list(s.findall(pattern, bytealigned=True)) # note the byte alignment

		if results:
			print 'Found match in ' + file
			for index in results:
				hexDump(s, index, patternLen)

print 'Done!'

Exemple #4
0
# -*- coding: utf-8 -*-

from bitstring import BitArray, BitStream, Bits
#Use bitstring to readin file.
with open("G:\SmartMeter\\high_freq_raw\\house_3\\current_1\\1303091049", "rb") as f:
    p = Bits(f)
a=p[0:8]
_Timestamplist = list(p.findall('0x74696d65', bytealigned=True))

for i in range(len(_Timestamplist)):
    #print(p[_Timestamplis[i]:p[_Timestamplis[i]+32.tobytes(),p[_Timestamplis[i]+32:_Timestamplis[i]+64].intle, p[_Timestamplis[i]+64:_Timestamplis[i]+96].intle)
    print(p[_Timestamplist[i]:_Timestamplist[i]+32].tobytes(),p[_Timestamplist[i]+32:_Timestamplist[i]+64].intle,p[_Timestamplist[i]+64:_Timestamplist[i]+96].intle,p[_Timestamplist[i]+96:_Timestamplist[i]+128].floatle)
    
#print(p[0:32].tobytes(),p[32:64].intle, p[64:96].intle,p[96:128].floatle,p[128:160].floatle,p[160:192].floatle)
#print(p[0:32])