def _struct(cls, subcon, prefixed=True): """Return a construct Struct for this class. Args: subcon: Can be a subcon or fixed size, depending on value of `prefixed`. prefixed: True if this is a PrefixedArray. """ if prefixed: return construct.PrefixedArray(subcon, LiveParser._struct()) else: return construct.Array(subcon, LiveParser._struct())
def _struct(cls): return construct.Struct( 'version' / _LsbVersionValidator(construct.Int32ul), 'flags' / construct.Byte, 'command_count' / construct.Int32ul, 'param_stream_size' / construct.Int32ul, 'command_params' / construct.Array( construct.this.command_count, _ParamStreamAdapter( construct.Bytes(construct.this.param_stream_size)), ), 'commands' / construct.PrefixedArray( construct.Int32ul, construct.Select(*_command_structs)), )
def _struct(cls): return construct.Struct( "version" / LsbVersionValidator(construct.Int32ul), "flags" / construct.Byte, "command_count" / construct.Int32ul, "param_stream_size" / construct.Int32ul, "command_params" / construct.Array( construct.this.command_count, _ParamStreamAdapter( construct.Bytes(construct.this.param_stream_size)), ), "commands" / construct.PrefixedArray( construct.Int32ul, construct.Select(*_command_structs)), )
def ObjectList(obj): return con.PrefixedArray(IdaVarInt32, obj)
TxHash = c.Transformed(c.Bytes(32), lambda b: b[::-1], 32, lambda b: b[::-1], 32) """Transaction hash, encoded as a reversed sequence of bytes.""" TxInput = c.Struct( "tx" / TxHash, "index" / c.Int32ul, "script_sig" / BitcoinBytes, "sequence" / c.Int32ul, ) """Transaction input.""" TxOutput = c.Struct("value" / c.Int64ul, "script_pubkey" / BitcoinBytes) """Transaction output.""" TxInputWitness = c.PrefixedArray(CompactUint, BitcoinBytes) """Array of witness records.""" Transaction = c.Struct( "version" / c.Int32ul, "segwit" / ConstFlag(b"\x00\x01"), "inputs" / c.PrefixedArray(CompactUint, TxInput), "outputs" / c.PrefixedArray(CompactUint, TxOutput), "witness" / c.If(c.this.segwit, TxInputWitness[c.len_(c.this.inputs)]), "lock_time" / c.Int32ul, c.Terminated, ) """Bitcoin transaction. If the `segwit` flag is present (which would otherwise mean 0 inputs, 1 output), we expect a `witness` field with entries corresponding to each input.
CompactUint = CompactUintAdapter(CompactUintStruct) TxInput = c.Struct( "tx" / c.Bytes(32), "index" / c.Int32ul, # TODO coinbase tx "script" / c.Prefixed(CompactUint, c.GreedyBytes), "sequence" / c.Int32ul, ) TxOutput = c.Struct( "value" / c.Int64ul, "pk_script" / c.Prefixed(CompactUint, c.GreedyBytes), ) StackItem = c.Prefixed(CompactUint, c.GreedyBytes) TxInputWitness = c.PrefixedArray(CompactUint, StackItem) Transaction = c.Struct( "version" / c.Int32ul, "segwit" / ConstFlag(b"\x00\x01"), "inputs" / c.PrefixedArray(CompactUint, TxInput), "outputs" / c.PrefixedArray(CompactUint, TxOutput), "witness" / c.If(this.segwit, TxInputWitness[len_(this.inputs)]), "lock_time" / c.Int32ul, c.Terminated, ) print(Transaction.parse(tx_bin))
def _struct(cls): return construct.Struct( "entries" / construct.PrefixedArray(construct.Int32ul, OpeData._struct()), )
# Class definition handling ClassMemberDefinition = Struct( "name" / DataPointer(Int64ul, CString("utf8"), "names"), "type" / Byte, "unkn" / Byte, "size" / Byte, "_unknData" / C.Default(Byte[69], [0 for _ in range(69)]), ) ClassDefinition = DataPointer( Int64ul, Struct("hash" / Int64ul, "members" / C.PrefixedArray(Int64ul, ClassMemberDefinition)), "definitionData") ClassDefinitionList = C.FocusedSeq( "definitions", "_count" / C.Rebuild(Int32ul, C.len_(this.definitions)), "definitions" / C.Prefixed( Int32ul, C.Aligned( 8, C.FocusedSeq( "definitions", "definitions" / ClassDefinition[this._._count], DataEntries("definitionData"), DataEntries("names"), ))))
def _struct(cls): return construct.Struct( "signature" / construct.Const(b"LivePrevMenu"), "version" / LPMVersionValidator(_LPMVersionAdapter(construct.Bytes(3))), "unk1" / construct.Bytes(8), "buttons" / construct.PrefixedArray( construct.Int32ul, construct.Struct( "width" / construct.Int32ul, "height" / construct.Int32ul, "src" / construct.PascalString(construct.Int32ul, "cp932"), "unk2" / construct.Byte, "name" / construct.PascalString(construct.Int32ul, "cp932"), "src_selected" / construct.PascalString(construct.Int32ul, "cp932"), "unk3" / construct.PascalString(construct.Int32ul, "cp932"), "unk4" / construct.PascalString(construct.Int32ul, "cp932"), "unk5" / construct.If( construct.this._._.version > 100, construct.PascalString(construct.Int32ul, "cp932"), ), "unk6" / construct.If( construct.this._._.version > 102, construct.Struct( construct.PascalString(construct.Int32ul, "cp932"), construct.PascalString(construct.Int32ul, "cp932"), ), ), "unk7" / construct.PascalString(construct.Int32ul, "cp932"), "unk8" / construct.PascalString(construct.Int32ul, "cp932"), "unk9" / construct.PascalString(construct.Int32ul, "cp932"), "unk10" / construct.If( construct.this._._.version > 101, construct.Struct( construct.PascalString(construct.Int32ul, "cp932"), construct.PascalString(construct.Int32ul, "cp932"), ), ), "unk15" / construct.Int32ul, "unk16" / construct.Int32ul, "unk17" / construct.PascalString(construct.Int32ul, "cp932"), "unk18" / construct.If( construct.this._._.version > 103, construct.Struct( construct.PascalString(construct.Int32ul, "cp932"), construct.PascalString(construct.Int32ul, "cp932"), construct.PascalString(construct.Int32ul, "cp932"), construct.PascalString(construct.Int32ul, "cp932"), construct.PascalString(construct.Int32ul, "cp932"), construct.Int32ul, ), ), "unk19" / construct.If( construct.this._._.version > 104, construct.PascalString(construct.Int32ul, "cp932"), ), "unk20" / construct.If( construct.this._._.version > 105, construct.PascalString(construct.Int32ul, "cp932"), ), ), ), )
def _struct(cls): return construct.Struct( "version" / LsbVersionValidator(construct.Int32ul), "project_name" / construct.PascalString(construct.Int32ul, "cp932"), "unk1" / construct.Int64ul, "unk2" / construct.Int64ul, "init_lsb" / construct.PascalString(construct.Int32ul, "cp932"), "exit_lsb" / construct.If( construct.this.version > 0x6D, construct.PascalString(construct.Int32ul, "cp932"), ), "project_dir" / construct.PascalString(construct.Int32ul, "cp932"), "unk3" / construct.Int32ul, "bool1" / construct.Byte, "bool2" / construct.If( construct.this.version >= 0x6A, construct.Byte, ), "audio_formats" / construct.If( construct.this.version >= 0x6D, construct.PascalString(construct.Int32ul, "cp932"), ), "bool3" / construct.If( construct.this.version >= 0x71, construct.Byte, ), "bool4" / construct.If( construct.this.version >= 0x72, construct.Byte, ), "bool5" / construct.If( construct.this.version >= 0x74, construct.Byte, ), "insert_disk_prompt" / construct.PascalString(construct.Int32ul, "cp932"), "exit_prompt" / construct.PascalString(construct.Int32ul, "cp932"), "system_settings" / construct.PrefixedArray( construct.Int32ul, construct.Struct( "type" / construct.Enum(construct.Byte, ParamType), "name" / construct.PascalString(construct.Int32ul, "cp932"), "value" / construct.Switch( construct.this.type, { "Int": construct.Int32sl, "Float": construct.ExprAdapter( construct.Bytes(10), lambda obj, ctx: numpy.frombuffer( obj.rjust(16, b"\x00"), dtype=numpy.longdouble), lambda obj, ctx: numpy.longdouble(obj).tobytes( )[-10:], ), "Flag": construct.Byte, "Str": construct.PascalString(construct.Int32ul, "cp932"), }, ), ), ), )
from enum import Enum from trio_socks.socks5.constructs import PackEnum, IPv4Address, IPv6Address class AuthMethod(Enum): no_auth = 0x0 gssap = 0x1 username_password = 0x2 auth_methods = AuthMethod ClientGreeting = construct.Struct( 'version' / construct.Default(construct.Const(5, construct.Byte), 5), 'auth_methods' / construct.PrefixedArray(construct.Byte, PackEnum(AuthMethod))) ServerChoice = construct.Struct( 'version' / construct.Default(construct.Const(5, construct.Byte), 5), 'auth_choice' / PackEnum(AuthMethod)) ClientAuthRequest = construct.Struct( 'version' / construct.Default(construct.Byte, 1), 'username' / construct.PascalString(construct.Byte, 'utf-8'), 'password' / construct.PascalString(construct.Byte, 'utf-8'), ) ServerAuthResponse = construct.Struct( 'version' / construct.Default(construct.Byte, 1), 'status' / construct.Flag, )