示例#1
0
    def set(self, string):
        if string in self._values_.viewvalues():
            res = dict((v, k) for k, v in self._values_.viewitems())
            return self.set(res[string])

        res = map(int, string.split('.'))
        val = [res.pop(0)*40 + res.pop(0)]
        for n in res:
            if n <= 127:
                val.append(n)
                continue

            # convert integer to a bitmap
            x = bitmap.new(0,0)
            while n > 0:
                x = bitmap.insert(x, (n&0xf,4))
                n //= 0x10

            # shuffle bitmap into oid components
            y = []
            while bitmap.size(x) > 0:
                x,v = bitmap.consume(x, 7)
                y.insert(0, v)

            val.extend([x|0x80 for x in y[:-1]] + [y[-1]])
        return super(OBJECT_IDENTIFIER, self).set(str().join(map(six.int2byte, val)))
示例#2
0
    def enumerate(self):
        index, res = 0, self.header()
        while bitmap.size(res) > 1:
            # check to see if the msize moves us to a header bit that's unset
            if bitmap.int(bitmap.get(res, 0, 1))  == 0:
                fixup = bitmap.runlength(res, 0, 0)
                logging.warn('Index {:d} of header is not set. Possibly corrupt? Forced to consume {:d} bits.'.format(index, fixup))
                res, _ = bitmap.consume(res, fixup)
                if bitmap.size(res) == 0: break

            # search for how long this run is
            msize = bitmap.runlength(res, 0, 1) + 1
            yield index, msize

            # consume msize bits
            index += msize
            res, _ = bitmap.consume(res, msize)
        return
示例#3
0
    def enumerate(self):
        index, res = 0, self.header()
        while bitmap.size(res) > 1:
            # check to see if the msize moves us to a header bit that's unset
            if bitmap.int(bitmap.get(res, 0, 1)) == 0:
                fixup = bitmap.runlength(res, 0, 0)
                logging.warn(
                    'Index {:d} of header is not set. Possibly corrupt? Forced to consume {:d} bits.'
                    .format(index, fixup))
                res, _ = bitmap.consume(res, fixup)
                if bitmap.size(res) == 0: break

            # search for how long this run is
            msize = bitmap.runlength(res, 0, 1) + 1
            yield index, msize

            # consume msize bits
            index += msize
            res, _ = bitmap.consume(res, msize)
        return
示例#4
0
    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)
示例#5
0
    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)
示例#6
0
    def used(self):
        m, res = self.getparent(magazine_t), self.header()
        index = m['mag_bytes_free_at_start'].int() / self.QUANTUM
        sentinel = (m['num_bytes_in_magazine'].int() - m['mag_bytes_free_at_end'].int()) / self.QUANTUM
        while index <= sentinel:
            # check to see if the msize moves us to a header bit that's unset
            if bitmap.int(bitmap.get(res, 0, 1))  == 0:
                fixup = bitmap.runlength(res, 0, 0)
                logging.warn('Index {:d} of header is not set. Possibly corrupt? Forced to consume {:d} bits.'.format(index, fixup))
                res, _ = bitmap.consume(res, fixup)
                if bitmap.size(res) == 0: break

            # search for how long this run is
            msize = bitmap.runlength(res, 0, 1) + 1
            yield index, msize

            # consume msize bits
            index += msize
            res, _ = bitmap.consume(res, msize)
        return
示例#7
0
    def set(self, string):
        res = map(int, string.split('.'))
        val = [res.pop(0) * 40 + res.pop(0)]
        for n in res:
            if n <= 127:
                val.append(n)
                continue

            # convert integer to a bitmap
            x = bitmap.new(0, 0)
            while n > 0:
                x = bitmap.insert(x, (n & 0xf, 4))
                n /= 0x10

            # shuffle bitmap into oid components
            y = []
            while bitmap.size(x) > 0:
                x, v = bitmap.consume(x, 7)
                y.insert(0, v)

            val.extend([x | 0x80 for x in y[:-1]] + [y[-1]])
        return super(OBJECT_IDENTIFIER).set(''.join(map(chr, val)))
示例#8
0
    def used(self):
        m, res = self.getparent(magazine_t), self.header()
        index = m['mag_bytes_free_at_start'].int() / self.QUANTUM
        sentinel = (m['num_bytes_in_magazine'].int() -
                    m['mag_bytes_free_at_end'].int()) / self.QUANTUM
        while index <= sentinel:
            # check to see if the msize moves us to a header bit that's unset
            if bitmap.int(bitmap.get(res, 0, 1)) == 0:
                fixup = bitmap.runlength(res, 0, 0)
                logging.warn(
                    'Index {:d} of header is not set. Possibly corrupt? Forced to consume {:d} bits.'
                    .format(index, fixup))
                res, _ = bitmap.consume(res, fixup)
                if bitmap.size(res) == 0: break

            # search for how long this run is
            msize = bitmap.runlength(res, 0, 1) + 1
            yield index, msize

            # consume msize bits
            index += msize
            res, _ = bitmap.consume(res, msize)
        return
示例#9
0
 def bitmap_rorX_size():
     res = bitmap.new(0b0110, 4)
     if bitmap.size(bitmap.ror(res, 8)) == 4:
         raise Success
示例#10
0
 def bitmap_rol4_size():
     res = bitmap.new(0b0110, 4)
     if bitmap.size(bitmap.rol(res, 4)) == 4:
         raise Success
示例#11
0
 def iterate(self):
     res = self.bitmap()
     while bitmap.size(res) > 0:
         res, val = bitmap.consume(res, 1)
         yield val
     return
示例#12
0
 def summary(self):
     res = self.bitmap()
     return "{:s} ({:s}, {:d})".format(self.__element__(), bitmap.hex(res),
                                       bitmap.size(res))
示例#13
0
 def iterate(self):
     res = self.bitmap()
     while bitmap.size(res) > 0:
         res, val = bitmap.consume(res, 1)
         yield val
     return