本文整理汇总了Python中bitstring.BitArray.tofile方法的典型用法代码示例。如果您正苦于以下问题:Python BitArray.tofile方法的具体用法?Python BitArray.tofile怎么用?Python BitArray.tofile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitstring.BitArray
的用法示例。
在下文中一共展示了BitArray.tofile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import tofile [as 别名]
index = fb.find('0xa1dcab8c47a9cf118ee400c00c205365',bytealigned=True)
print "[*] found file properties GUID"
print "[*] File properties GUID: %s" % fb[index[0]:(index[0]+128)]
# index of minumum packet size in File Proprties header
i_min_data_pkt_size = index[0] + 736
print "[*] Original Minimum Data Packet Size: %s" % fb[i_min_data_pkt_size:i_min_data_pkt_size+32].hex
print "[*] Original Maximum Data Packet Size: %s" % fb[i_min_data_pkt_size+32:i_min_data_pkt_size+64].hex
# Accroding to ASF standarad the minimum data size and the maximum data size should be equal
print "[*] Changing Miniumum and Maximum Data packet size to 0"
# changing the data packets in bit array
fb[i_min_data_pkt_size:i_min_data_pkt_size+8] = 0x00
fb[i_min_data_pkt_size+8:i_min_data_pkt_size+16] = 0x00
fb[i_min_data_pkt_size+16:i_min_data_pkt_size+24] = 0x00
fb[i_min_data_pkt_size+24:i_min_data_pkt_size+32] = 0x00
fb[i_min_data_pkt_size+32:i_min_data_pkt_size+40] = 0x00
fb[i_min_data_pkt_size+40:i_min_data_pkt_size+48] = 0x00
fb[i_min_data_pkt_size+48:i_min_data_pkt_size+56] = 0x00
fb[i_min_data_pkt_size+56:i_min_data_pkt_size+64] = 0x00
print "[*] POC File Created poc.asf"
of = open('poc.asf','w+b')
fb.tofile(of)
of.close()
f.close()
示例2: countChars
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import tofile [as 别名]
print 'Analyzing file'
charWeights = countChars(sourceFile)
print '\n'
#Create symbol table based on file analasys
symbolTable = PrefixTree(charWeights).getEncodeTable()
#Initialize output bits with count of chars
outputBits = BitArray(int=len(charWeights), length=8)
#Add char weights to binary output
for char in charWeights.keys():
outputBits.append(BitArray(int=ord(char), length=32))
outputBits.append(BitArray(int=charWeights[char], length=32))
#Add code words
print 'Encoding file'
line = 0
sourceFile = open(sys.argv[1], 'r')
for s_line in sourceFile:
line += 1
update_progress(line, lineCount)
for s_char in s_line:
outputBits.append(BitArray('0b{}'.format(symbolTable[s_char])))
print '\n'
#Write compressed binary to file
outFile = open('{}.hc'.format(sys.argv[1]), 'wb')
outputBits.tofile(outFile)
print 'Done.'
示例3: SaveBinStrData
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import tofile [as 别名]
def SaveBinStrData(binStr, fileName):
binData = BitArray(bin = binStr)
try:
binData.tofile(open(fileName, 'wb'))
except:
GlobalMsg.warn('unable to open file [' + fileName + ']')
示例4: int
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import tofile [as 别名]
modValue = 1000000
#read each line, split to remove extra chars.
for line in file.readlines():
data = line.split()
for line in data:
#hash with the md5 hashfunction.
hash = hashlib.md5(line.lower().encode('utf-8')).digest()
#extract parts of the hash and convert to integer inside array index span
h1 = int(hash[0:3].encode("hex"),16)%modValue
h2 = int(hash[4:7].encode("hex"),16)%modValue
h3 = int(hash[8:11].encode("hex"),16)%modValue
h4 = int(hash[12:15].encode("hex"),16)%modValue
#set the bits in the array. use the set function for speed.
hashTable.set(True,h1)
hashTable.set(True,h2)
hashTable.set(True,h3)
hashTable.set(True,h4)
file.close()
#open file as binary file and write to it.
with open('data', 'wb') as outfile:
hashTable.tofile(outfile)
#print execution time. ~20 seconds on my system
end = time.time()
print(end-start)