def set_bitmap_unsigned(): x = bitmap.new(0xf000000000000000,64) #x = bitmap.set(x, 60, count=4) print bitmap.string(x) y,res = bitmap.shift(x, 4) print res,bitmap.string(y) x = bitmap.new(0,0) x = bitmap.push(x, (0x1,4) ) x = bitmap.push(x, (0x2,4) ) x = bitmap.push(x, (0x3,4) ) x = bitmap.push(x, (0x4,4) ) print x,bitmap.string(x) x = bitmap.new(0,0) x = bitmap.insert(x, (0x1,4) ) x = bitmap.insert(x, (0x2,4) ) x = bitmap.insert(x, (0x3,4) ) x = bitmap.insert(x, (0x4,4) ) print x,bitmap.string(x) x = bitmap.consumer('\x12\x34') print x.consume(4) print x.consume(4) print x.consume(4) print x.consume(4) x = bitmap.new(0, 4) for i in six.moves.range(6): print x x = bitmap.add(x, 3) for i in six.moves.range(6): print x x = bitmap.sub(x, 6) x = bitmap.new(4,4) print bitmap.string(bitmap.ror(bitmap.ror(bitmap.ror(x))))
def set_bitmap_unsigned(): x = bitmap.new(0xf000000000000000, 64) #x = bitmap.set(x, 60, count=4) print(bitmap.string(x)) y, res = bitmap.shift(x, 4) print(res, bitmap.string(y)) x = bitmap.new(0, 0) x = bitmap.push(x, (0x1, 4)) x = bitmap.push(x, (0x2, 4)) x = bitmap.push(x, (0x3, 4)) x = bitmap.push(x, (0x4, 4)) print(x, bitmap.string(x)) x = bitmap.new(0, 0) x = bitmap.insert(x, (0x1, 4)) x = bitmap.insert(x, (0x2, 4)) x = bitmap.insert(x, (0x3, 4)) x = bitmap.insert(x, (0x4, 4)) print(x, bitmap.string(x)) x = bitmap.consumer(b'\x12\x34') print(x.consume(4)) print(x.consume(4)) print(x.consume(4)) print(x.consume(4)) x = bitmap.new(0, 4) for i in range(6): print(x) x = bitmap.add(x, 3) for i in range(6): print(x) x = bitmap.sub(x, 6) x = bitmap.new(4, 4) print(bitmap.string(bitmap.ror(bitmap.ror(bitmap.ror(x)))))
def encode(self, object, **kwds): szone,pu = self.getparent(szone_t),object.get() cookie = szone['cookie'].li.int() csum = self.generate_checksum(pu^cookie) t = bitmap.new(pu, object.size()*8) t = bitmap.rol(t, 4) cs = bitmap.new(bitmap.number(t)|csum, bitmap.size(t)) cs = bitmap.ror(cs, 4) logging.info("{:s}.ptr_union.encode : Encoded pointer 0x{:x} with 0x{:x} results in checksum 0x{:x} : {:s}".format(__name__, pu, cookie, csum, bitmap.hex(cs))) res = object.copy().set(bitmap.number(cs)) return super(ptr_union,self).encode(res, **kwds)
def encode(self, object, **kwds): szone, pu = self.getparent(szone_t), object.get() cookie = szone['cookie'].li.int() csum = self.generate_checksum(pu ^ cookie) t = bitmap.new(pu, object.size() * 8) t = bitmap.rol(t, 4) cs = bitmap.new(bitmap.number(t) | csum, bitmap.size(t)) cs = bitmap.ror(cs, 4) logging.info( "{:s}.ptr_union.encode : Encoded pointer 0x{:x} with 0x{:x} results in checksum 0x{:x} : {:s}" .format(__name__, pu, cookie, csum, bitmap.hex(cs))) res = object.copy().set(bitmap.number(cs)) return super(ptr_union, self).encode(res, **kwds)
def bitmap_ror4_value(): res = bitmap.new(0b0110, 4) if bitmap.int(bitmap.ror(res, 4)) == 0b0110: raise Success
def bitmap_ror2_value(): res = bitmap.new(0b0110, 4) if bitmap.int(bitmap.ror(res, 2)) == 0b1001: raise Success
def bitmap_rorX_size(): res = bitmap.new(0b0110, 4) if bitmap.size(bitmap.ror(res, 8)) == 4: raise Success