def _init_native_methods(self, vm): for m in vm.get_methods(): cls_name, name, _ = get_method_triple(m) access = get_access_method(m.get_access_flags()) if 'native' in access: self.native_methods.add((cls_name, name))
def write_method(self): access = util.get_access_method(self.method.get_access_flags()) class_name = self.method.get_class_name() _, name, proto = self.method.get_triple() jni_name = JniLongName(class_name, name, proto) self.write("\n/* %s->%s%s */\n" % (class_name, name, proto)) self.write('extern "C" JNIEXPORT %s JNICALL\n' % get_native_type(self.irmethod.rtype)) self.write(jni_name) params = self.irmethod.params if 'static' not in access: params = params[1:] proto = '' if self.irmethod.params_type: proto = ', '.join(['%s p%s' % (get_native_type(p_type), param) for p_type, param in zip(self.irmethod.params_type, params)]) if proto: self.write('(JNIEnv *env, jobject thiz, %s)' % proto) else: self.write('(JNIEnv *env, jobject thiz)') self.write('{\n') nodes = self.irmethod.irblocks for node in nodes: self.visit_node(node) for lp in self.irmethod.landing_pads: self.write('\n') self.visit_landing_pad(lp) return_type = self.irmethod.rtype if return_type[0] != 'V': if return_type[0] == 'L': self.write("EX_UnwindBlock: return NULL;\n") else: self.write("EX_UnwindBlock: return (%s)0;\n" % (get_native_type(return_type))) else: self.write("EX_UnwindBlock: return;\n") self.write('}\n')
def __init__(self, methanalysis): method = methanalysis.get_method() self.method = method self.irmethod = None self.start_block = next(methanalysis.get_basic_blocks().get(), None) self.cls_name = method.get_class_name() self.name = method.get_name() self.lparams = [] self.var_to_name = defaultdict() self.offset_to_node = {} self.graph = None self.access = util.get_access_method(method.get_access_flags()) desc = method.get_descriptor() self.type = desc.split(')')[-1] self.params_type = util.get_params_type(desc) self.triple = method.get_triple() self.exceptions = methanalysis.exceptions.exceptions self.curret_block = None self.var_versions = defaultdict(int) code = self.method.get_code() if code: start = code.registers_size - code.ins_size if 'static' not in self.access: self.lparams.append(start) start += 1 num_param = 0 for ptype in self.params_type: param = start + num_param self.lparams.append(param) num_param += util.get_type_size(ptype) if DEBUG: from androguard.core import bytecode bytecode.method2png('graphs/%s#%s.png' % \ (self.cls_name.split('/')[-1][:-1], self.name), methanalysis)