class CLSID(pstruct.type): from ptypes.pint import littleendian, bigendian _fields_ = [ (littleendian(pint.uint32_t), 'a'), (littleendian(pint.uint16_t), 'b'), (littleendian(pint.uint16_t), 'c'), # 64 (bigendian(pint.uint16_t), 'd'), (bigendian(dyn.clone(pint.uint_t, length=6)), 'e') ] def summary(self): result = [] for k, v in self.items(): count = v.size() * 2 fmt = '%0' + str(count) + 'x' result.append(fmt % int(v)) return '{' + '-'.join(result) + '}'
class DOUBLE(pfloat.double): pass ## int types class SI8(pint.int8_t): pass class SI16(pint.int16_t): pass class SI24(pint.int_t): length = 3 class SI32(pint.int32_t): pass class SI64(pint.int64_t): pass class UI8(pint.int8_t): pass class UI16(pint.int16_t): pass class UI24(pint.int_t): length = 3 class UI32(pint.int32_t): pass class UI64(pint.int64_t): pass (SI8, UI8, SI16, UI16, SI32, UI32, UI64) = ( littleendian(x) for x in (SI8,UI8,SI16,UI16,SI32,UI32,UI64) ) ## fixed-point types class SI8_8(pfloat.sfixed_t): length,fractional = 2,8 class SI16_16(pfloat.sfixed_t): length,fractional = 4,16 class UI8_8(pfloat.fixed_t): length,fractional = 2,8 class UI16_16(pfloat.fixed_t): length,fractional = 4,16 class FIXED(UI16_16): pass class FIXED8(SI8_8): pass class STRING(pstr.szstring): pass class Empty(ptype.type): initialized = property(fget=lambda x: True, fset=lambda x,v: None) value = ''
def test_int_littleendian_set(): b = pint.littleendian(pint.uint32_t)(source=provider.string(string2)).l b.set(0x0abcdef0) if b.int() == 0x0abcdef0 and b.serialize() == string2: raise Success print b, b.serialize().encode('hex')
def test_int_littleendian_set(): b = pint.littleendian(pint.uint32_t)(source=provider.bytes(string2)).l b.set(0x0abcdef0) if b.int() == 0x0abcdef0 and b.serialize() == string2: raise Success print(b, tohex(b.serialize()))