vstruct Package

vstruct Package

class vstruct.VArray(elems=())[source]

Bases: vstruct.VStruct

vsAddElement(elem)[source]

Used to add elements to an array

class vstruct.VStruct[source]

Bases: vstruct.primitives.v_base

The VStruct class is the bases for all groups of primitive fields which define a “structure”. Fields may be added with vsAddField() or simply added as attributes (provided you use a VStruct or one of the vstruct.primitives in the initial assignment.)

Example:

import vstruct from vstruct.primitives import *

vs = vstruct.VStruct() vs.fieldone = v_uint32() vs.fieldtwo = v_str(size=30)

bytes = vs.vsEmit()

tree(va=0, reprmax=None)[source]
vsAddField(name, value)[source]
vsAddParseCallback(fieldname, callback)[source]

Register a callback which will be triggered when the field with the given name is set by the parser. This can be used to simplify auto-parsing to change fields sizes or whatnot during parsing.

(You may also name a method pcb_<FieldName> to get a callback for your struct.)

Example:

def updateLengthTarget(vs):
dostuff()

v.vsAddParseCallback(‘lenfield’, updateLengthTarget)

vsCalculate()[source]

Calculate fields which need correction before emitting bytes etc...

(VStruct extenders may call this, then modify fields internally)

vsClearFields()[source]

Clear all fields from the current vstruct object. This may be useful in specialized parsers which populate their structure on vsParse()

vsEmit()[source]

Get back the byte sequence associated with this structure.

vsGetClassPath()[source]

Return the entire class name (including module path).

vsGetField(name)[source]
vsGetFields()[source]

Get a list of (fieldname, fieldobj) tuples for all the kids in this VStruct (non-recursive)

Example:
for kidname, kidobj in x.vsGetFields():
print kidname
vsGetOffset(name)[source]

Return the offset of a member (by name):

vsGetPrims()[source]

return an order’d list of the primitive fields in this structure definition. This is recursive and will return the sub fields of all nested structures.

vsGetPrintInfo(offset=0, indent=0, top=True)[source]
vsGetTypeName()[source]
vsHasField(name)[source]

Test weather this structure contains a field with the given name....

Example:
if x.vsHasField(‘woot’):
print ‘STRUCT HAS WOOT FIELD!’
vsInsertField(name, value, befname)[source]

WARNING: vsInsertField does NOT honor field alignment! # FIXME (AND CAN MESS UP OTHER FIELDS ALIGNMENT!)

vsIsPrim()[source]
vsParse(sbytes, offset=0)[source]

For all the primitives contained within, allow them an opportunity to parse the given data and return the total offset...

Any method named pcb_<FieldName> will be called back when the specified field is set by the parser.

vsParseFd(fd)[source]

Parse from the given file like object as input.

vsSetField(name, value)[source]

Mostly for internal use...

class vstruct.VUnion[source]

Bases: vstruct.VStruct

vsEmit()[source]
vsGetPrintInfo(offset=0, indent=0, top=True)[source]
vsParse(sbytes, offset=0)[source]

For all the primitives contained within, allow them an opportunity to parse the given data and return the total offset...

Any method named pcb_<FieldName> will be called back when the specified field is set by the parser.

vstruct.getModuleNames()[source]
vstruct.getStructNames(modname)[source]
vstruct.getStructure(sname)[source]

Return an instance of the specified structure. The structure name may be a definition that was added with addStructure() or a python path (ie. win32.TEB) of a definition from within vstruct.defs.

vstruct.isVstructType(x)[source]
vstruct.resolve(impmod, nameparts)[source]

Resolve the given (potentially nested) object from within a module.

vstruct.resolvepath(impmod, pathstr)[source]

Resolve an object/module from within the given module by path name (ie. ‘foo.bar.baz’)

Example: x = resolvepath(vstruct.defs, ‘win32.SEH_SCOPETABLE’)

builder Module

VStruct builder! Used to serialize structure definitions etc...

class vstruct.builder.VStructBuilder(defs=(), enums=())[source]
addVStructCtor(sname, ctor)[source]
addVStructDef(vsdef)[source]
addVStructEnumeration(enum)[source]
addVStructNamespace(name, builder)[source]
buildVStruct(vsname)[source]
delVStructCtor(sname)[source]
genVStructPyCode()[source]
getVStructCtorNames()[source]
getVStructNames(namespace=None)[source]
getVStructNamespaceNames()[source]
getVStructNamespaces()[source]
hasVStructNamespace(namespace)[source]
class vstruct.builder.VStructConstructor(builder, vsname)[source]

cparse Module

primitives Module

class vstruct.primitives.GUID(guidstr=None)[source]

Bases: vstruct.primitives.v_prim

vsEmit()[source]
vsGetValue()[source]
vsParse(fbytes, offset=0)[source]
vsSetValue(guidstr)[source]
class vstruct.primitives.v_base[source]

Bases: object

vsCalculate()[source]
vsGetMeta(name, defval=None)[source]
vsGetTypeName()[source]
vsIsPrim()[source]
vsParse(bytes)[source]
vsSetMeta(name, value)[source]
class vstruct.primitives.v_bytes(size=0, vbytes=None)[source]

Bases: vstruct.primitives.v_prim

v_bytes is used for fixed width byte fields.

vsEmit()[source]
vsParse(fbytes, offset=0)[source]
vsSetLength(size)[source]
vsSetValue(val)[source]
class vstruct.primitives.v_enum[source]
class vstruct.primitives.v_int16(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_number

class vstruct.primitives.v_int24(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_number

class vstruct.primitives.v_int32(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_number

class vstruct.primitives.v_int64(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_number

class vstruct.primitives.v_int8(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_number

class vstruct.primitives.v_number(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_prim

vsEmit()[source]

Emit the bytes for this numeric type...

vsGetValue()[source]
vsParse(fbytes, offset=0)[source]

Parse the given numeric type from the given bytes...

vsSetValue(value)[source]

Assure that the value is long() able for all numeric types.

class vstruct.primitives.v_prim[source]

Bases: vstruct.primitives.v_base

vsEmit()[source]

Return the actual bytes which represent this field

vsGetTypeName()[source]
vsGetValue()[source]

Get the type specific value for this field. (Used by the structure dereference method to return a python native for the field by name)

vsIsPrim()[source]
vsParse(bytes, offset=0)[source]

Parser for primitives which assumes we are calling parse directly.

vsParseFd(fd)[source]
vsSetLength(size)[source]

Set the length of this primitive type. This may be used to dynamically update the length of string fields, etc...

vsSetValue(value)[source]

Set the type specific value for this field.

class vstruct.primitives.v_ptr(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_size_t

class vstruct.primitives.v_ptr32(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_ptr

class vstruct.primitives.v_ptr64(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_ptr

class vstruct.primitives.v_size_t(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_number

class vstruct.primitives.v_str(size=4, val='')[source]

Bases: vstruct.primitives.v_prim

A string placeholder class which will automagically return up to a null terminator (and will keep it’s size by null padding when assigned to)

vsEmit()[source]
vsGetValue()[source]
vsParse(fbytes, offset=0)[source]
vsSetLength(size)[source]
vsSetValue(val)[source]
class vstruct.primitives.v_uint16(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_number

class vstruct.primitives.v_uint24(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_number

class vstruct.primitives.v_uint32(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_number

class vstruct.primitives.v_uint64(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_number

class vstruct.primitives.v_uint8(value=0, bigend=False)[source]

Bases: vstruct.primitives.v_number

class vstruct.primitives.v_wstr(size=4, encode='utf-16le', val='')[source]

Bases: vstruct.primitives.v_str

Unicode variant of the above string class

NOTE: the size paramater is in WCHARs!

vsEmit()[source]
vsGetValue()[source]
vsParse(fbytes, offset=0)[source]
vsSetValue(val)[source]
class vstruct.primitives.v_zstr(val='')[source]

Bases: vstruct.primitives.v_prim

A string placeholder class which will automagically return up to a null terminator dynamically.

vsEmit()[source]
vsGetValue()[source]
vsParse(fbytes, offset=0)[source]
vsSetLength(size)[source]
vsSetValue(val)[source]

unittest Module

vstruct.unittest.test(vs, hexstr)[source]
vstruct.unittest.updatelen(vs)[source]
class vstruct.unittest.woot[source]

Bases: vstruct.VStruct

pcb_lenfield()[source]

Table Of Contents

This Page