当前位置: 首页>>代码示例>>Python>>正文


Python BitArray.tofile方法代码示例

本文整理汇总了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()
开发者ID:AlexxNica,项目名称:exploit-database,代码行数:33,代码来源:31429.py

示例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.'
开发者ID:iddogino,项目名称:algorithms,代码行数:32,代码来源:encode.py

示例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 + ']')
开发者ID:sultan86,项目名称:biolzma,代码行数:8,代码来源:DataIO.py

示例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)

开发者ID:tobyndax,项目名称:Kata,代码行数:31,代码来源:bloom.py


注:本文中的bitstring.BitArray.tofile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。