How to use the apkutils.dex.util.signExtend function in apkutils

To help you get started, we’ve selected a few apkutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mikusjelly / apkutils / apkutils / dex / dexparser.py View on Github external
stream.uleb128()
            encodedValue(dex, stream)
        return None
    if vtype == 0x1e:  # NULL
        return None

    # For the rest, we just return it as unsigned integers without recording type
    # extended to either u32 or u64 depending on int/float or long/double
    if vtype == 0x1f:  # BOOLEAN
        return b'I', varg
    # the rest are an int encoded into varg + 1 bytes in some way
    size = varg + 1
    val = sum(stream.u8() << (i * 8) for i in range(size))

    if vtype == 0x00:  # BYTE
        return b'I', signExtend(val, 8) % (1 << 32)
    if vtype == 0x02:  # SHORT
        return b'I', signExtend(val, 16) % (1 << 32)
    if vtype == 0x03:  # CHAR
        return b'I', val
    if vtype == 0x04:  # INT
        return b'I', val

    if vtype == 0x06:  # LONG
        return b'J', val

    # floats are 0 extended to the right
    if vtype == 0x10:  # FLOAT
        return b'F', val << (32 - size * 8)
    if vtype == 0x11:  # DOUBLE
        return b'D', val << (64 - size * 8)
github mikusjelly / apkutils / apkutils / dex / byteio.py View on Github external
def _leb128(self, signed=False):
        result = 0
        size = 0
        while self.data[self.pos] >> 7:
            result ^= (self.data[self.pos] & 0x7f) << size
            size += 7
            self.pos += 1
        result ^= (self.data[self.pos] & 0x7f) << size
        size += 7
        self.pos += 1

        if signed:
            result = signExtend(result, size)
        return result
github mikusjelly / apkutils / apkutils / dex / dexparser.py View on Github external
return None
    if vtype == 0x1e:  # NULL
        return None

    # For the rest, we just return it as unsigned integers without recording type
    # extended to either u32 or u64 depending on int/float or long/double
    if vtype == 0x1f:  # BOOLEAN
        return b'I', varg
    # the rest are an int encoded into varg + 1 bytes in some way
    size = varg + 1
    val = sum(stream.u8() << (i * 8) for i in range(size))

    if vtype == 0x00:  # BYTE
        return b'I', signExtend(val, 8) % (1 << 32)
    if vtype == 0x02:  # SHORT
        return b'I', signExtend(val, 16) % (1 << 32)
    if vtype == 0x03:  # CHAR
        return b'I', val
    if vtype == 0x04:  # INT
        return b'I', val

    if vtype == 0x06:  # LONG
        return b'J', val

    # floats are 0 extended to the right
    if vtype == 0x10:  # FLOAT
        return b'F', val << (32 - size * 8)
    if vtype == 0x11:  # DOUBLE
        return b'D', val << (64 - size * 8)

    if vtype == 0x17:  # STRING
        return b'Ljava/lang/String;', dex.string(val)