How to use the apkutils.dex.dalvikformats.decode 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 / dalvik.py View on Github external
def parseInstruction(dex, insns_start_pos, shorts, pos):
    word = shorts[pos]
    opcode = word & 0xFF
    newpos, args = dalvikformats.decode(shorts, pos, opcode)

    # parse special data instructions
    switchdata = None
    fillarrdata = None
    if word == 0x100 or word == 0x200:  # switch
        size = shorts[pos + 1]
        st = dex.stream(insns_start_pos + pos * 2 + 4)

        if word == 0x100:  # packed
            first_key = st.u32()
            targets = [st.u32() for _ in range(size)]
            newpos = pos + 2 + (1 + size) * 2
            switchdata = {(i + first_key): x for i, x in enumerate(targets)}
        else:  # sparse
            keys = [st.u32() for _ in range(size)]
            targets = [st.u32() for _ in range(size)]