def get_api_list(self, dex_obj, dex_method, api_list, permission_list): if dex_method.dexCode is None: return offset = 0 insns_size = dex_method.dexCode.insnsSize * 4 while offset < insns_size: op_code = int(dex_method.dexCode.insns[offset:offset + 2], 16) decoded_instruction = dex_parser.dexDecodeInstruction( dex_obj, dex_method.dexCode, offset) smali_code = decoded_instruction.smaliCode if smali_code is None: #logger.warning("smali code is None.") continue # Next Instruction. offset += decoded_instruction.length if smali_code == 'nop': break # 4 invokes from 0x6e to 0x72 if 0x6e <= op_code <= 0x72: if decoded_instruction.getApi in self.k_api_v_permission: api_list.append(decoded_instruction.getApi) for permission in self.k_api_v_permission[ decoded_instruction.getApi]: permission_list.add(permission) return
def get_api_list(self, dex_method, api_list, permission_list): if dex_method.dexCode is None: return offset = 0 insns_size = dex_method.dexCode.insnsSize * 4 while offset < insns_size: op_code = int(dex_method.dexCode.insns[offset:offset + 2], 16) decoded_instruction = dex_parser.dexDecodeInstruction(self.dex, dex_method.dexCode, offset) smali_code = decoded_instruction.smaliCode if smali_code is None: logger.warning("smali code is None.") continue # Next Instruction. offset += decoded_instruction.length if smali_code == 'nop': break # 4 invokes from 0x6e to 0x72 if 0x6e <= op_code <= 0x72: if decoded_instruction.getApi in self.k_api_v_permission: api_list.append(decoded_instruction.getApi) for permission in self.k_api_v_permission[decoded_instruction.getApi][0]: permission_list.add(permission) return #compute the Hash value of each method methodmd5 = hashlib.md5() methodmd5.update(method_opcode_str) method_md5_index =methodmd5.hexdigest() method_name_list.append(filename) set_invoke_info = set(invoke_info) method_info.append(set_invoke_info) method_info.append(method_md5_index) method_dict[filename] = method_info
def get_api_list(self, dex_method, api_list): if dex_method.dexCode is None: return offset = 0 insns_size = dex_method.dexCode.insnsSize * 4 while offset < insns_size: op_code = int(dex_method.dexCode.insns[offset:offset + 2], 16) decoded_instruction = dex_parser.dexDecodeInstruction( self.dex, dex_method.dexCode, offset) smali_code = decoded_instruction.smaliCode if smali_code is None: logger.warning("smali code is None.") if decoded_instruction == 0: break else: offset += decoded_instruction.length continue # Next Instruction. offset += decoded_instruction.length if smali_code == 'nop': break # 4 invokes from 0x6e to 0x72 if 0x6e <= op_code <= 0x72: if decoded_instruction.getApi in self.invokes: api_list.append(decoded_instruction.getApi) return
def parseMethod(dexMethod, dex_object): methodFeature = {'registersSize':0, 'insSize':0, 'outsSize':0, 'triesSize':0, 'debugInfoOff':0, 'insnsSize':0, 'opInsNum':0, 'mathInsNum':0, 'aInsNum':0, 'aInsDict':{ 'naNum':0, 'alNum':0, 'fadNum':0, 'fnaNum':0, 'fnarNum':0, 'agNum':0, 'apNum':0, }, 'nalNum':0, 'nalDict':{}, } if dexMethod.dexCode == None: return None methodFeature['registersSize'] = dexMethod.dexCode.registersSize methodFeature['insSize'] = dexMethod.dexCode.insSize methodFeature['outsSize'] = dexMethod.dexCode.outsSize methodFeature['triesSize'] = dexMethod.dexCode.triesSize methodFeature['debugInfoOff'] = dexMethod.dexCode.debugInfoOff methodFeature['insnsSize'] = dexMethod.dexCode.insnsSize offset = 0 insnsSize = dexMethod.dexCode.insnsSize * 4 cdict = {} while offset < insnsSize: opcode = int(dexMethod.dexCode.insns[offset:offset + 2], 16) formatIns, _ = dex_parser.getOpCode(opcode) decodedInstruction = dex_parser.dexDecodeInstruction(dex_object, dexMethod.dexCode, offset) smaliCode = decodedInstruction.smaliCode if smaliCode == None: continue opFlag = False for ins in opIns: if ins in decodedInstruction.op: opFlag = True methodFeature['opInsNum'] += 1 if decodedInstruction.op in constIns: cdict[decodedInstruction.vA] = int(decodedInstruction.vB) elif decodedInstruction.op in arrayIns: methodFeature['aInsNum'] += 1 if decodedInstruction.op == 'new-array': methodFeature['aInsDict']['naNum'] += 1 try: naLen = cdict[decodedInstruction.vA] if naLen in methodFeature['nalDict'].keys(): methodFeature['nalDict'][naLen] += 1 else: methodFeature['nalDict'][naLen] = 1 methodFeature['nalNum'] += 1 except: pass elif decodedInstruction.op == 'arrary-lengh': methodFeature['aInsDict']['alNum'] += 1 elif decodedInstruction.op == 'fill-array-data': methodFeature['aInsDict']['fadNum'] += 1 elif decodedInstruction.op == 'filled-new-array': methodFeature['aInsDict']['fnaNum'] += 1 elif decodedInstruction.op == 'filled-new-array/range': methodFeature['aInsDict']['fnarNum'] += 1 elif decodedInstruction.op.startswith('aget'): methodFeature['aInsDict']['agNum'] += 1 else: methodFeature['aInsDict']['apNum'] += 1 break if not opFlag: methodFeature['mathInsNum'] += 1 insns = dexMethod.dexCode.insns[decodedInstruction.offset:decodedInstruction.offset + decodedInstruction.length] offset += len(insns) if smaliCode == 'nop': break return methodFeature