Skip to content
Newer
Older
100644 48 lines (43 sloc) 1.29 KB
67562a7 @comex more py files
authored Feb 18, 2011
1 import structdefpatch
2 from block import *
3 import struct, sys
4
5 def probe(ctx):
6 print ctx
7 sys.exit(0)
8
9 Test = Struct('Test',
10 Block('_block1'),
11 Block('_block2'),
12 Block('_block3'),
13 BOffsetSize(lambda ctx: ctx['_block1'],
14 UBInt32('_offset1'),
15 UBInt32('_size1'),
16 ),
17 BOffsetSize(lambda ctx: ctx['_block2'],
18 UBInt32('_offset2'),
19 UBInt32('_size2'),
20 ),
21 BOffsetSize(lambda ctx: ctx['_block3'],
22 UBInt32('_offset3'),
23 UBInt32('_size3'),
24 ),
25 BPointer(lambda ctx: ctx['_block1'], lambda ctx: ctx['_offset1'],
26 UBInt32('one')
27 ),
28 BPointer(lambda ctx: ctx['_block2'], lambda ctx: ctx['_offset2'],
29 Struct('data',
30 BPointer(lambda ctx: ctx['_']['_block3'], lambda ctx: ctx['_']['_offset3'],
31 UBInt32('two')
32 ),
33 #Aligned(BData(probe), 16),
8fbb79f @comex bad crap
authored Mar 9, 2011
34 BData(lambda ctx: ctx['_']['_block3'], align=48, pattern='12'),
67562a7 @comex more py files
authored Feb 18, 2011
35 ),
36 ),
37 BData(lambda ctx: ctx['_block1']),
38 BData(lambda ctx: ctx['_block2']),
39 )
40
8fbb79f @comex bad crap
authored Mar 9, 2011
41 #result = Test.parse(struct.pack('>IIIIIIIIII', 28, 4, 32, 8, 36, 4, 42, 1, 42, 2))
42 #print result
67562a7 @comex more py files
authored Feb 18, 2011
43
8fbb79f @comex bad crap
authored Mar 9, 2011
44 result = Container(one=0x11111111, data=Container(two=0x22222222))
67562a7 @comex more py files
authored Feb 18, 2011
45 Test.build_stream(result, fakestream())
46 packed = Test.build(result)
8fbb79f @comex bad crap
authored Mar 9, 2011
47 sys.stdout.write(packed)
Something went wrong with that request. Please try again.