def __init__(self, methanalysis): """ :param androguard.core.analysis.analysis.MethodAnalysis methanalysis: """ method = methanalysis.get_method() self.method = method 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.writer = None self.graph = None self.ast = 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 code = method.get_code() if code is None: logger.debug('No code : %s %s', self.name, self.cls_name) else: start = code.registers_size - code.ins_size if 'static' not in self.access: self.var_to_name[start] = ThisParam(start, self.cls_name) self.lparams.append(start) start += 1 num_param = 0 for ptype in self.params_type: param = start + num_param self.lparams.append(param) self.var_to_name[param] = Param(param, ptype) num_param += util.get_type_size(ptype) if not __debug__: from androguard.core import bytecode # TODO: use tempfile to create a correct tempfile (cross platform compatible) bytecode.method2png( '/tmp/dad/graphs/{}#{}.png'.format( self.cls_name.split('/')[-1][:-1], self.name), methanalysis)
def __init__(self, methanalysis): """ :param androguard.core.analysis.analysis.MethodAnalysis methanalysis: """ method = methanalysis.get_method() self.method = method 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.writer = None self.graph = None self.ast = 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 code = method.get_code() if code is None: logger.debug('No code : %s %s', self.name, self.cls_name) else: start = code.registers_size - code.ins_size if 'static' not in self.access: self.var_to_name[start] = ThisParam(start, self.cls_name) self.lparams.append(start) start += 1 num_param = 0 for ptype in self.params_type: param = start + num_param self.lparams.append(param) self.var_to_name[param] = Param(param, ptype) num_param += util.get_type_size(ptype) if not __debug__: from androguard.core import bytecode # TODO: use tempfile to create a correct tempfile (cross platform compatible) bytecode.method2png('/tmp/dad/graphs/{}#{}.png'.format(self.cls_name.split('/')[-1][:-1], self.name), methanalysis)
def __init__(self, methanalysis): method = methanalysis.get_method() self.method = method 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.writer = None self.graph = None self.ast = 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 code = method.get_code() if code is None: logger.debug("No code : %s %s", self.name, self.cls_name) else: start = code.registers_size - code.ins_size if "static" not in self.access: self.var_to_name[start] = ThisParam(start, self.cls_name) self.lparams.append(start) start += 1 num_param = 0 for ptype in self.params_type: param = start + num_param self.lparams.append(param) self.var_to_name[param] = Param(param, ptype) num_param += util.get_type_size(ptype) if not __debug__: from androguard.core import bytecode bytecode.method2png( "/tmp/dad/graphs/%s#%s.png" % (self.cls_name.split("/")[-1][:-1], self.name), methanalysis )
def __init__(self, methanalysis, adi): method = methanalysis.get_method() self.method = method 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.adi = adi self.writer = None self.graph = None self.ast = 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 code = method.get_code() if code is None: logger.debug('No code : %s %s', self.name, self.cls_name) else: start = code.registers_size - code.ins_size if 'static' not in self.access: self.var_to_name[start] = ThisParam(start, self.cls_name) self.lparams.append(start) start += 1 num_param = 0 for ptype in self.params_type: param = start + num_param self.lparams.append(param) self.var_to_name[param] = Param(param, ptype) num_param += util.get_type_size(ptype) if self.adi != None: method_idx = method.get_method_idx() method_annotations = [ x.get_annotations_off() for x in self.adi.get_method_annotations() if x.get_method_idx() == method_idx ] param_annotations = [ x for x in self.adi.get_parameter_annotations() if x.get_method_idx() == method_idx ] self.method_annotations = get_annotations(method.CM, method_annotations) if len(param_annotations) > 0: self.param_annotations = get_parameter_annotations( method.CM, param_annotations) if len(self.param_annotations) != len(self.params_type): if len(self.params_type) - len( self.param_annotations) == 1: self.param_annotations.insert(0, []) else: print( "Failed to extract annotation from {} - {}".format( self.cls_name, self.name)) self.param_annotations = [[]] * len(self.params_type) else: self.param_annotations = [[]] * len(self.params_type) else: self.method_annotations = [] self.param_annotations = [[]] * len(self.params_type) if not __debug__: from androguard.core import bytecode # TODO: use tempfile to create a correct tempfile (cross platform compatible) bytecode.method2png( '/tmp/dad/graphs/{}#{}.png'.format( self.cls_name.split('/')[-1][:-1], self.name), methanalysis)