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


Python ConstBitStream.find方法代码示例

本文整理汇总了Python中bitstring.ConstBitStream.find方法的典型用法代码示例。如果您正苦于以下问题:Python ConstBitStream.find方法的具体用法?Python ConstBitStream.find怎么用?Python ConstBitStream.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bitstring.ConstBitStream的用法示例。


在下文中一共展示了ConstBitStream.find方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: extractXMP

# 需要导入模块: from bitstring import ConstBitStream [as 别名]
# 或者: from bitstring.ConstBitStream import find [as 别名]
 def extractXMP(self, filename):
     xmpStr = ""        
     # Can initialise from files, bytes, etc.
     try:
         s = ConstBitStream(filename = filename)
         # Search for ":xmpmeta" string in file
         keepSearching = True
         while keepSearching:
             keepSearching = False
             colonXmpmetaInHexStr = '0x3a786d706d657461'
             foundSt = s.find(colonXmpmetaInHexStr, bytealigned=True)
             if foundSt:
                 byteStart = (int(foundSt[0])//8)
                 # The start of data can be "<xmp:xmpmeta" or "<x:xmpmeta"
                 s.bytepos = byteStart - 4
                 prevals = s.peeklist("4*uint:8")
                 prestr = ''.join(chr(i) for i in prevals)
     #            print (prestr, prestr[2:])
                 if prestr == "<xmp":
                     byteStart = byteStart - 4
                     prefix = "0x3c2f786d70"  # "<\xmp" in hex
                 elif prestr[2:] == "<x":
                     byteStart = byteStart - 2
                     prefix = "0x3c2f78"  # "<\x" in hex
                 else:
     #                print ("Cont")
                     keepSearching = True
                     continue
     #            print("Found start code at byte offset %d." % byteStart)
                 foundEnd = s.find(prefix + colonXmpmetaInHexStr, bytealigned=True)
                 if foundEnd:
                     byteEnd = (int(foundEnd[0])//8)
                     s.bytepos = byteStart
     #                print("Found end code at byte offset %d." % byteEnd)
                     xmpBytes = s.readlist(str(byteEnd-byteStart+len(prefix)//2+9) +"*uint:8")
                     xmpStr = ''.join(chr(i) for i in xmpBytes)
                     #if "Rating" in xmpStr:
     #                print (xmpStr)
     except:
         xmpStr = ""
     return xmpStr
开发者ID:,项目名称:,代码行数:43,代码来源:

示例2: ff

# 需要导入模块: from bitstring import ConstBitStream [as 别名]
# 或者: from bitstring.ConstBitStream import find [as 别名]
def ff(file, mode='unknown'):
    '''Read header from data file.'''
    infile = open(file, 'r')

    oldheader = infile.read(8)

    # Finds "Dartmouth"
    s = ConstBitStream(filename=file)
    found = s.find('0x446172746d6f757468', bytealigned=True)
    if found:
        print("Found start code at byte offset %d." % found[0])
        # s0f0, length, bitdepth, height, width = s.readlist('hex: 16, uint: 16,
        # uint: 8, 2 * uint: 16')
        # print("Width %d, Height %d" % (width, height))
    else:
        print("No way!!")

    if oldheader[0:6] == "999999" and mode == 'unknown':
        if oldheader[6:8] == "01":
            mode = 'head'
        elif oldheader[6:8] == "04":
            mode = 'tail'
        else:
            print "ff(): Mode not defined in input or old header"
            return(1)
    elif oldheader[0:6] != "999999" and mode != 'tail':
        print "ff(): No valid GGSE header signature."
        return(1)

    if mode == 'head':
        header = infile.read(8184)
    elif mode == 'tail':
        infile.seek(-8192, os.SEEK_END)
        header = infile.read(8192)
    else:
        print "ff(): Unknown mode."
        return(1)

    infile.close()

    try:
        fhead = fs(header)
    except confp.ParsingError or confp.MissingSectionHeaderError:
        print "ff(): error parsing file: No header in " + mode + " of file?"
        fhead = 1

    return fhead
开发者ID:Dartspacephysiker,项目名称:Core-FFT,代码行数:49,代码来源:ggseHeader.py

示例3: ConstBitStream

# 需要导入模块: from bitstring import ConstBitStream [as 别名]
# 或者: from bitstring.ConstBitStream import find [as 别名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from bitstring import ConstBitStream
import sys

c = ConstBitStream(filename=sys.argv[1])
#Most log entry ends with 0A, this helps us to seek to the beginning of an entry
start = c.find('0x0A', bytealigned=True)[0]
#Seek 8 byte into the stream to skip EOL from previus log entry
start += 8

c.pos = start

while True:
  #Read and print the binary log header
  header = c.readlist('8*uintle:32')
  print header
  #Get the size in bits of the log message
  msgSize = (header[0] * 8 - 256)
  #Move pointer after message
  c.pos += msgSize
  #Check if EOL is present after message, if true, move pointer 8 byte
  if c.peek(8).hex == '0a':
    c.pos += 8
开发者ID:intenso,项目名称:plogclient,代码行数:27,代码来源:plogprinter.py

示例4: ConstBitStream

# 需要导入模块: from bitstring import ConstBitStream [as 别名]
# 或者: from bitstring.ConstBitStream import find [as 别名]
__author__ = 'loki'
from bitstring import ConstBitStream, ReadError
import os
from filetimes import filetime_to_dt, dt_to_filetime, utc
s = ConstBitStream(filename='test3.avi')
statinfo = os.stat('test3.avi')
print statinfo.st_size
print ("Current bytepos %X" % s.bytepos)
# Search to Start of Frame 0 code on byte boundary
foundMoviOffset = s.find('0x6D6F7669', bytealigned=True)
if foundMoviOffset:
    moviOffset = foundMoviOffset[0] / 8
    print("Found movi signature at byte offset %X" % moviOffset)
else:
    print "Signature movi not found"
print ("Current bytepos %X" % s.bytepos)
foundIdx1Offset = s.find('0x69647831', bytealigned=True)
if foundIdx1Offset:
    idx1Offset = foundIdx1Offset[0] / 8
    print("Found idx1 signature at byte offset %X" % idx1Offset)
else:
    print "Signature idx1 not found"
print ("Current bytepos %X" % s.bytepos)
found01dcOffset = s.findall('0x30316463', bytealigned=True)
for i in found01dcOffset:
    i = (i /8) + 8
    print("%X" % i)
    s.bytepos = i
    print s.bytepos
    timeStamp = s.read(64).bin
    print timeStamp
开发者ID:threedognight,项目名称:video-edit,代码行数:33,代码来源:video.py

示例5: __init__

# 需要导入模块: from bitstring import ConstBitStream [as 别名]
# 或者: from bitstring.ConstBitStream import find [as 别名]
class FileReader:
    """ Some basic functionality for reading data from Binary files. """

    def __init__(self, filename):
        self.filename = filename
        if isinstance(filename, str):
            self.file = open(filename, 'rb')
            self.bits = ConstBitStream(open(filename, 'rb'))

    def __enter__(self):
        return self

    def __exit__(self, type, value, traceback):
        self.file.close()

    def skip_bytes(self,count=1):
        self.bits.read('pad:{0}'.format(count*8))

    def peek_int(self):
        return self.bits.peek(32).uintle

    def forward_to_first_non_zero_byte(self, start, end):
        self.bits.pos = start
        while self.bits.pos < end and self.bits.read(8).intle == 0:
            pass
        self.bits.pos -= 8

    def read_strings_from_block(self, start, end, stopAtEmptyString=False):
        self.bits.pos = start
        r = []
        while self.bits.pos < end:
            s = self.read_string()
            if s == "" and stopAtEmptyString:
                return r
            r.append(s)
        return tuple(r)

    def read_int(self):
        """ Read a single little endian 4 byte integer """
        return self.bits.read(32).intle

    def findall(self,bs):
        return self.bits.findall(bs,bytealigned=True)

    def read_bytes(self, count):
        return self.bits.read(count*8)

    def read_byte(self, skip = 0):
        i = self.bits.read(8).uint
        if skip > 0:
            self.skip_bytes(skip)

        return i

    def read_string_safe(self):
        return self.bits.read('bytes:{0}'.format(self.read_byte(skip=3))).decode("utf-8", 'replace')

    def find(self, bs, start, end):
        return self.bits.find(bs,start, end, True )

    def find_first(self, bs):
        return self.bits.find(bs)

    def extract_compressed_payloads(self):
        files = []
        occ = self.findall('0x789C')

        i = 0
        readSize = 2**12

        for pos in occ:
            self.bits.pos = pos

            #read the start of the stream into a buffer.
            if (self.bits.length - self.pos) < 8*2**12:
                readSize = int((self.bits.length - self.pos) / 8)

            buf = self.bits.read('bytes:{0}'.format(readSize))
            zo = zlib.decompressobj()

            #start the decompression
            try:
                stream = zo.decompress(buf)
            except zlib.error: # right magic number but not a zlib stream.
                continue

            while zo.unused_data == b'' and readSize >= 2**12:
                if (self.bits.length - self.pos) < 8*2**12:
                    readSize = int((self.bits.length - self.pos) / 8)

                block = self.bits.read('bytes:{0}'.format(readSize))
                if len(block)> 0:
                    try:
                        stream += zo.decompress(block)
                    except zlib.error:
                        pass
                else:
                    break # we've reached EOF

            with open(self.filename + '_' + str(i) + '.decompressed', 'wb') as fh:
#.........这里部分代码省略.........
开发者ID:rivarolle,项目名称:civ5-saveparser,代码行数:103,代码来源:FileReader.py


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