Example #1
0
def getParams(data):
    """ return the parameters as tuple for the opcode at position 0

    special treatment is done for the opcode with variable parameters
    """
    code = data[0]
    params = []
    ofs = 1
    for p in opparams[code]:
        params.append({1: u1, 2: u2, 4: u4}[p](data[ofs:]))
        ofs += p

    if code == opcode["ilookupswitch"]:
        npairs = params[1]
        for i in range(npairs):
            params.append((u4(data[ofs:]), u2(data[ofs+4:]), ))
            ofs += 6
    elif code == opcode["itableswitch"]:
        lowbytes = utils.signed4(params[1])
        highbytes = utils.signed4(params[2])
        for i in range(highbytes - lowbytes):
            params.append(u2(data[ofs:]))
            ofs += 2
    elif code == opcode["slookupswitch"]:
        npairs = params[1]
        for i in range(npairs):
            params.append((u2(data[ofs:]), u2(data[ofs+2:]), ))
            ofs += 4
    elif code == opcode["stableswitch"]:
        lowbytes = utils.signed2(params[1])
        highbytes = utils.signed2(params[2])
        for i in range(highbytes - lowbytes + 1):
            params.append(u2(data[ofs:]))
            ofs += 2
    return ofs, params
Example #2
0
def getParams(data):
    """ return the parameters as tuple for the opcode at position 0

    special treatment is done for the opcode with variable parameters
    """
    code = data[0]
    params = []
    ofs = 1
    for p in opparams[code]:
        params.append({1: u1, 2: u2, 4: u4}[p](data[ofs:]))
        ofs += p

    if code == opcode["ilookupswitch"]:
        npairs = params[1]
        for i in xrange(npairs):
            params.append((u4(data[ofs:]), u2(data[ofs+4:]), ))
            ofs += 6
    elif code == opcode["itableswitch"]:
        lowbytes = utils.signed4(params[1])
        highbytes = utils.signed4(params[2])
        for i in xrange(highbytes - lowbytes):
            params.append(u2(data[ofs:]))
            ofs += 2
    elif code == opcode["slookupswitch"]:
        npairs = params[1]
        for i in xrange(npairs):
            params.append((u2(data[ofs:]), u2(data[ofs+2:]), ))
            ofs += 4
    elif code == opcode["stableswitch"]:
        lowbytes = utils.signed2(params[1])
        highbytes = utils.signed2(params[2])
        for i in xrange(highbytes - lowbytes + 1):
            params.append(u2(data[ofs:]))
            ofs += 2
    return ofs, params
Example #3
0
 def __init__(self, offset, cap_file, resolver):
     self.offset = offset
     sf = cap_file.StaticField
     if offset < sf.array_init_count * 2:
         offset = offset // 2
         aii = sf.array_init[offset]
         convertfunc = {
             2:
             lambda x: bool(x[0]),
             3:
             lambda x: utils.signed1(x[0]),
             4:
             lambda x: utils.signed2((x[0] << 8) + x[1]),
             5:
             lambda x: utils.signed4((x[0] << 24) + (x[1] << 16) +
                                     (x[2] << 8) + x[3])
         }[aii.type]
         elemsize = {2: 1, 3: 1, 4: 2, 5: 4}[aii.type]
         index = 0
         value = []
         while index < aii.count:
             value.append(convertfunc(aii.values[index:]))
             index += elemsize
         self.val = value
     elif offset < sf.reference_count * 2:
         self.val = None
     else:
         offset -= sf.reference_count * 2
         if offset <= sf.default_value_count:
             self.val = None
         else:
             print("I am a non-default primitive type")
             raise NotImplementedError("non default primitive static field")
Example #4
0
 def __init__(self, offset, cap_file, resolver):
     self.offset = offset
     sf = cap_file.StaticField
     if offset < sf.array_init_count * 2:
         offset = offset // 2
         aii = sf.array_init[offset]
         convertfunc = {2: lambda x: bool(x[0]), 
                        3: lambda x: utils.signed1(x[0]), 
                        4: lambda x: utils.signed2((x[0] << 8) + 
                                                   x[1]), 
                        5: lambda x: utils.signed4((x[0] << 24) + 
                                                   (x[1] << 16) + 
                                                   (x[2] << 8) + 
                                                   x[3])
                        }[aii.type]
         elemsize = {2: 1, 3: 1, 4: 2, 5: 4}[aii.type]
         index = 0
         value = []
         while index < aii.count:
             value.append(convertfunc(aii.values[index:]))
             index += elemsize
         self.val = value
     elif offset < sf.reference_count * 2:
         self.val = None
     else:
         offset -= sf.reference_count * 2
         if offset <= sf.default_value_count:
             self.val = None
         else:
             print "I am a non-default primitive type"
             raise NotImplementedError("non default primitive static field")
Example #5
0
def getPar(data):
    """ return the size of the parameters for the opcode at index 0 """
    code = data[0]
    if code == opcode["ilookupswitch"]:
        npairs = u2(data[3:5])
        return npairs*6 + 4
    elif code == opcode["itableswitch"]:
        lowbytes = utils.signed2(u4(data[3:7]))
        highbytes = utils.signed4(u4(data[7:11]))
        return (highbytes - lowbytes + 1)*2 + 10
    elif code == opcode["slookupswitch"]:
        npairs = u2(data[3:5])
        return npairs*4 + 4
    elif code == opcode["stableswitch"]:
        lowbytes = utils.signed2(u2(data[3:5]))
        highbytes = utils.signed2(u2(data[5:7]))
        return (highbytes - lowbytes + 1)*2 + 6
    else:
        return oppar[code]
Example #6
0
def getPar(data):
    """ return the size of the parameters for the opcode at index 0 """
    code = data[0]
    if code == opcode["ilookupswitch"]:
        npairs = u2(data[3:5])
        return npairs*6 + 4
    elif code == opcode["itableswitch"]:
        lowbytes = utils.signed2(u4(data[3:7]))
        highbytes = utils.signed4(u4(data[7:11]))
        return (highbytes - lowbytes + 1)*2 + 10
    elif code == opcode["slookupswitch"]:
        npairs = u2(data[3:5])
        return npairs*4 + 4
    elif code == opcode["stableswitch"]:
        lowbytes = utils.signed2(u2(data[3:5]))
        highbytes = utils.signed2(u2(data[5:7]))
        return (highbytes - lowbytes + 1)*2 + 6
    else:
        return oppar[code]