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


Python Reader.readformat方法代码示例

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


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

示例1: handle_packet

# 需要导入模块: from reader import Reader [as 别名]
# 或者: from reader.Reader import readformat [as 别名]
def handle_packet(linktype, time, data, sessions):
    r = Reader(data)

    if linktype == 101: # LINKTYPE_RAW, no header!
        pass
    elif linktype == 113: # LINKTYE_LINUX_SLL
        pktype = r.readformat('!H')
        reallinktype = r.readformat('!H')
        linkaddrlen = r.readformat('!H')
        linkaddr = r.readformat('8s')
        prototype = r.readformat('!H')
        assert reallinktype == 1 # ARPHRD_ETHER
        assert linkaddrlen <= 8
        assert prototype == 0x800 # EtherType IPv4

        # 0 means 'sent to us'
        # 4 means 'sent by us'
        # we get two copies of each packet, one *before* NAT, and one *after*
        # while picking 0 or 4 always will have either our local ip as the real client or the nat,
        # depending on whether the packet is incoming or outgoing
        # we only key our session on server ip, not local ip
        if pktype != 0:
            return
    else:
        raise RuntimeError('unknown linktype')

    srcip, dstip = handle_ip_header(r)
    srcport, dstport = handle_udp_header(r)

    srcip = ipaddress.ip_address(srcip)
    dstip = ipaddress.ip_address(dstip)

    if srcip.is_private:
        svrip, svrport = dstip, dstport
    else:
        svrip, svrport = srcip, srcport

    key = "{}:{}".format(svrip, svrport & ~1)

    try:
        session = sessions[key]
    except KeyError:
        if svrport == 5002:
            session = GLSSession(key)
        else:
            session = Session(len(sessions), key, time)
        sessions[key] = session

    if srcip.is_private:
        session.pkt_source = 'client'
    else:
        session.pkt_source = 'server'
    session.pkt_time = time
    session.handle_pkt_major(r)
开发者ID:boardwalk,项目名称:bzr-research,代码行数:56,代码来源:networkdump.py

示例2: checksumcontent

# 需要导入模块: from reader import Reader [as 别名]
# 或者: from reader.Reader import readformat [as 别名]
def checksumcontent(hdr, data):
    if hdr.flags & 0x00000004:
        r = Reader(data)
        if hdr.flags & 0x00000100:
            r.skip(8)
        if hdr.flags & 0x00001000:
            nseq = r.readint()
            r.skip(nseq * 4)
        if hdr.flags & 0x00002000:
            nseq = r.readint()
            r.skip(nseq * 4)
        if hdr.flags & 0x00004000:
            r.skip(4)
        if hdr.flags & 0x00400000:
            r.skip(8)
        if hdr.flags & 0x01000000:
            r.skip(8)
        if hdr.flags & 0x02000000:
            r.skip(4)
        if hdr.flags & 0x04000000:
            r.skip(8)
        if hdr.flags & 0x08000000:
            r.skip(6)
        checksum = checksumdata(data[0 : r.position], True)

        while len(r):
            frag_start = r.position
            r.readformat('Q')
            r.readshort()
            frag_len = r.readshort()
            r.readshort()
            r.readshort()
            r.skip(frag_len - 16)

            frag_checksum = checksumdata(data[frag_start : frag_start + frag_len], True)
            checksum = (checksum + frag_checksum) & 0xFFFFFFFF

        return checksum
    else:
        return checksumdata(data, True)
开发者ID:boardwalk,项目名称:bzr-research,代码行数:42,代码来源:session.py

示例3: range

# 需要导入模块: from reader import Reader [as 别名]
# 或者: from reader.Reader import readformat [as 别名]
numTextures = r.readbyte()

numConnections = r.readbyte()

numVisible = r.readshort()

for i in range(numTextures):
    textureId = r.readshort()
    #print('texture {}: {:04x}'.format(i, textureId))

#r.align()

geometryId = r.readint()
#print('geometryId={:08x}'.format(geometryId))

x, y, z = r.readformat('fff')
rw, rx, ry, rz = r.readformat('ffff')

#print('x={}, y={}, z={}'.format(x, y, z))
#print('rw={}, rx={}, ry={}, rz={}'.format(rw, rx, ry, rz))

for i in range(numConnections):
    a = r.readshort()
    b = r.readshort()
    structId = r.readshort()
    c = r.readshort()
    #print('connection {}: {:04x} {:04x} {:04x} {:04x}'.format(i, a, b, structId, c))

for i in range(numVisible):
    structId = r.readshort()
    #print('visible {}: {:04x}'.format(i, structId))
开发者ID:boardwalk,项目名称:bzr-research,代码行数:33,代码来源:dump-structures.py

示例4: print

# 需要导入模块: from reader import Reader [as 别名]
# 或者: from reader.Reader import readformat [as 别名]
flags = r.readint()

#print("{} {:08x}".format(sys.argv[1], flags))

if flags & 0x01:
    thingie = r.readint()
    print('thingie = {:08x}'.format(thingie))
    #print('thingie = {:08x}'.format(thingie))

if flags & 0x02 or flags & 0x04:
    textureId = r.readint()
    zero = r.readint()
    assert zero == 0
    #print('textureId = {:08x}'.format(textureId))

s, t, p = r.readformat('fff')

if flags & 0x10:
    assert s != 0.0
else:
    assert s == 0.0

assert len(r) == 0

#print('floats = {}, {}, {}'.format(s, t, p))

#
# 00000001 [thing including FF]           00000000  [a float] [a float]
# 00000002 [texture id]         00000000  00000000  [a float] [a float]
# 00000004 [texture id]         00000000  00000000  [a float] [a float]
开发者ID:boardwalk,项目名称:bzr-research,代码行数:32,代码来源:dump-texture-lookups.py

示例5: Reader

# 需要导入模块: from reader import Reader [as 别名]
# 或者: from reader.Reader import readformat [as 别名]
#!/usr/bin/env python
import sys
from reader import Reader

fid = sys.argv[1]

r = Reader(sys.stdin.buffer.raw.read())

#r.dump()

image_id, zero, two, num_palettes = r.readformat('=IIBI')
palettes = [r.readint() for i in range(num_palettes)]

#print("{:08x} {} {} {}".format(image_id, zero, two, num_palettes))

print(fid + ': ' + ' '.join(['{:08x}'.format(p) for p in palettes]) )
#print(palettes)

assert zero == 0
assert two == 2
assert len(r) == 0

#r.dump(1024)

#print("-----")

开发者ID:boardwalk,项目名称:bzr-research,代码行数:27,代码来源:dump-paletted-images.py

示例6: Reader

# 需要导入模块: from reader import Reader [as 别名]
# 或者: from reader.Reader import readformat [as 别名]
import sys
from reader import Reader

r = Reader(sys.stdin.buffer.raw.read())

fid = r.readint()
anim_type = r.readint()
num_parts = r.readint()
num_frames = r.readint()

print('=== fid = {:08x}'.format(fid))

#if anim_type == 1 or anim_type == 3:
if anim_type & 1:
    for i in range(num_frames):
        r.readformat('7I') # there are floats in here

for i in range(num_frames):
    #print("on frame {}".format(i))
    for j in range(num_parts):
        x, y, z = r.readformat('3f')
        rw, rx, ry, rz = r.readformat('4f')
    extra_count = r.readint()
    for j in range(extra_count):
        extra_type = r.readint()
        extra_thing = r.readint()
        assert extra_thing == 0 or extra_thing == 1 or extra_thing == 0xFFFFFFFF
        if extra_type == 0x01:
            a = r.readformat('I')
            assert (a & 0xFF000000) == 0x0A000000
        elif extra_type == 0x02:
开发者ID:boardwalk,项目名称:bzr-research,代码行数:33,代码来源:dump-animation.py

示例7: print

# 需要导入模块: from reader import Reader [as 别名]
# 或者: from reader.Reader import readformat [as 别名]
assert emitter_type >= 0x1 and emitter_type <= 0x2

particle_type = r.readint()
assert particle_type >= 0x1 and particle_type <= 0xc

print('unk = {:08x} emitter_type = {:08x} particle_type = {:08x}'.format(unk, emitter_type, particle_type))

gfxobj_id = r.readint()
print('gfxobj_id = {:08x}'.format(gfxobj_id))
assert gfxobj_id == 0 or (gfxobj_id & 0xFF000000) == 0x01000000

hw_gfxobj_id = r.readint()
print('hw_gfxobj_id = {:08x}'.format(hw_gfxobj_id))
assert hw_gfxobj_id == 0 or (hw_gfxobj_id & 0xFF000000) == 0x01000000

birthrate = r.readformat('d')
print('birthrate = {:.8f}'.format(birthrate))

max_particles = r.readint()
initial_particles = r.readint()
total_particles = r.readint()
print('max_particles = {}, initial_particles = {}, total_particles = {}'.format(max_particles, initial_particles, total_particles))

#r.readint() # pad

total_seconds = r.readformat('d')
lifespan_rand = r.readformat('d')
lifespan = r.readformat('d')
print('total_seconds = {:.2f} lifespan_rand = {:.2f} lifespan = {:.2f}'.format(total_seconds, lifespan_rand, lifespan))

# sorting sphere
开发者ID:boardwalk,项目名称:bzr-research,代码行数:33,代码来源:dump-particle-emitter.py

示例8: range

# 需要导入模块: from reader import Reader [as 别名]
# 或者: from reader.Reader import readformat [as 别名]
    assert mag >= 0.999 and mag <= 1.001

for i in range(numParts):
    modelid = r.readint()
    #print('{:02x} submodel: {:08x}'.format(i, modelid))
    assert modelid & 0xFF000000 == 0x01000000

if flags & 1:
    for i in range(numParts):
        parent = r.readint()
        #print('{:02x} parent: {:08x}'.format(i, parent))
        assert parent < numParts or parent == 0xFFFFFFFF

if flags & 2:
    for i in range(numParts):
        sx, sy, sz = r.readformat('3f')

numHoldLocations = r.readint()

for i in range(numHoldLocations):
    key = r.readint()
    partId = r.readint()
    read_location(r)

numConnectionPoints = r.readint()
assert numConnectionPoints == 0

for i in range(numConnectionPoints):
    key = r.readint()
    partId = r.readint()
    read_location(r)
开发者ID:boardwalk,项目名称:bzr-research,代码行数:33,代码来源:dump-compound-models.py

示例9: Reader

# 需要导入模块: from reader import Reader [as 别名]
# 或者: from reader.Reader import readformat [as 别名]
from reader import Reader

r = Reader(sys.stdin.buffer.raw.read())
#r.dump(1024)

fid = r.readint()
assert fid & 0x0000FFFF == 0x0000FFFE

numCells = r.readint()

numObjects = r.readshort()
r.readshort()

for i in range(numObjects):
    modelId = r.readint()
    x, y, z = r.readformat('3f')
    assert x >= 0.0 and x <= 192.0
    assert y >= 0.0 and y <= 192.0
    #assert z >= 0.0 and z <= 512.0
    rw, rx, ry, rz = r.readformat('4f')

numBuildings = r.readshort()
hasthings = r.readshort()

#print('fid = {:08x} numBuildings = {} thing = {}'.format(fid, numBuildings, thing))

for i in range(numBuildings):
    modelId = r.readint()
    x, y, z = r.readformat('3f')
    assert x >= 0.0 and x <= 192.0
    assert y >= 0.0 and y <= 192.0
开发者ID:boardwalk,项目名称:bzr-research,代码行数:33,代码来源:dump-landblock-objects.py

示例10: print

# 需要导入模块: from reader import Reader [as 别名]
# 或者: from reader.Reader import readformat [as 别名]
        blend_tex_id = r.readint()
        print('{} {} blend_tex_id = {:08x}'.format(i, tcode_name(tcode), blend_tex_id))

parse_blend_tex()
parse_blend_tex()
parse_blend_tex()

nterraintex = r.readint()
assert nterraintex == 0x21

for i in range(nterraintex):
    idx = r.readint()
    assert idx == i
    tex_id = r.readint()
    tex_tiling = r.readint()
    max_vert_bright, min_vert_bright = r.readformat('2I')
    assert max_vert_bright >= min_vert_bright
    max_vert_saturate, min_vert_saturate = r.readformat('2I')
    assert max_vert_saturate >= min_vert_saturate
    max_vert_hue, min_vert_hue = r.readformat('2I')
    assert max_vert_hue >= min_vert_hue
    detail_tex_tiling = r.readint()
    detail_tex_id = r.readint()
    print('tex_id = {:08x} detail_tex_id = {:08x}'.format(tex_id, detail_tex_id))

unk5 = r.readint()
assert unk5 == 1

r.readint() # small map
r.readint() # large map
开发者ID:boardwalk,项目名称:bzr-research,代码行数:32,代码来源:dump-region.py

示例11: print

# 需要导入模块: from reader import Reader [as 别名]
# 或者: from reader.Reader import readformat [as 别名]
unk4 = r.readint()
assert unk4 == 0

unk5 = r.readfloat()
assert unk5 == 1.0

unk6 = r.readfloat()
assert unk6 == 1.0

numcount1 = r.readint()

print('fid = {:08x}'.format(fid))

for i in range(numcount1):
    sound_type = r.readformat('I')
    numcount2 = r.readformat('I')
    for j in range(numcount2):
        sound_gid = r.readformat('I')
        assert (sound_gid & 0xFF000000) == 0x0A000000
        priority = r.readformat('f')
        assert priority >= 0.0 and priority <= 1.0
        probability = r.readformat('f')
        assert probability >= 0.0 and priority <= 1.0
        volume = r.readformat('f')
        assert volume >= 0.0 and priority <= 1.0
        #print('{} {} sound_gid = {:08x} priority = {:.2f} probability = {:.2f} volume = {:.2f}'
        #        .format(i, j, sound_gid, priority, probability, volume))

    unk2 = r.readformat('I')
    assert unk2 == 0
开发者ID:boardwalk,项目名称:bzr-research,代码行数:32,代码来源:dump-stable.py

示例12: range

# 需要导入模块: from reader import Reader [as 别名]
# 或者: from reader.Reader import readformat [as 别名]
        # I don't know wtf this is
        generation = r.readint()
        assert generation in [0x1, 0x2, 0x3, 0xE]

        # larger is slower
        # not sure of units
        speed = r.readfloat()

        typ = r.readint()

        iden2 = r.readint()
        assert iden2 == iden

        if typ == 1 or typ == 7 or typ == 12:
            # duration in seconds
            dur = r.readformat('d')

        if typ == 1 or typ == 12:
            unk2 = r.readint()
            assert unk2 == 0
            unk3 = r.readint()
            assert unk3 == 0xc4268000

        for j in range(8): # components
            r.readint()

        # The visual effect ID
        # see Effect DWORD in protocol docs
        castereffect = r.readint()
        targeteffect = r.readint()
开发者ID:boardwalk,项目名称:bzr-research,代码行数:32,代码来源:dump-unique.py


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