예제 #1
0

# CFG
for method in a.get_methods():
    g = x.get_method( method )

    # Display only methods with exceptions
    if method.get_code() == None:
      continue

    if method.get_code().tries_size <= 0:
      continue

    print method.get_class_name(), method.get_name(), method.get_descriptor(), method.get_code().get_length(), method.get_code().registers_size

    idx = 0
    for i in g.basic_blocks.get():
        print "\t %s %x %x" % (i.name, i.start, i.end), '[ NEXT = ', ', '.join( "%x-%x-%s" % (j[0], j[1], j[2].get_name()) for j in i.childs ), ']', '[ PREV = ', ', '.join( j[2].get_name() for j in i.fathers ), ']'

        for ins in i.get_instructions():
            print "\t\t %x" % idx, ins.get_name(), ins.get_output()
            idx += ins.get_length()

        print ""

    for i in g.exceptions.gets():
        print '%x %x %s' % (i.start, i.end, i.exceptions)

    print dvm.determineException(a.get_vm(), method)

예제 #2
0
    def __init__(self, vm, method):
        self.__vm = vm
        self.method = method

        self.basic_blocks = BasicBlocks(self.__vm)
        self.exceptions = Exceptions(self.__vm)

        code = self.method.get_code()
        if code is None:
            return

        current_basic = DVMBasicBlock(0, self.__vm, self.method,
                                      self.basic_blocks)
        self.basic_blocks.push(current_basic)

        ##########################################################

        bc = code.get_bc()
        l = []
        h = {}
        idx = 0

        debug("Parsing instructions")
        for i in bc.get_instructions():
            for j in BasicOPCODES:
                if j.match(i.get_name()) is not None:
                    v = dvm.determineNext(i, idx, self.method)
                    h[idx] = v
                    l.extend(v)
                    break

            idx += i.get_length()

        debug("Parsing exceptions")
        excepts = dvm.determineException(self.__vm, self.method)
        for i in excepts:
            l.extend([i[0]])
            for handler in i[2:]:
                l.append(handler[1])

        debug("Creating basic blocks in %s" % self.method)
        idx = 0
        for i in bc.get_instructions():
            # index is a destination
            if idx in l:
                if current_basic.get_nb_instructions() != 0:
                    current_basic = DVMBasicBlock(current_basic.get_end(),
                                                  self.__vm, self.method,
                                                  self.basic_blocks)
                    self.basic_blocks.push(current_basic)

            current_basic.push(i)

            # index is a branch instruction
            if idx in h:
                current_basic = DVMBasicBlock(current_basic.get_end(),
                                              self.__vm, self.method,
                                              self.basic_blocks)
                self.basic_blocks.push(current_basic)

            idx += i.get_length()

        if current_basic.get_nb_instructions() == 0:
            self.basic_blocks.pop(-1)

        debug("Settings basic blocks childs")

        for i in self.basic_blocks.get():
            try:
                i.set_childs(h[i.end - i.get_last_length()])
            except KeyError:
                i.set_childs([])

        debug("Creating exceptions")

        # Create exceptions
        self.exceptions.add(excepts, self.basic_blocks)

        for i in self.basic_blocks.get():
            # setup exception by basic block
            i.set_exception_analysis(
                self.exceptions.get_exception(i.start, i.end - 1))

        del h, l
예제 #3
0
for method in d.get_methods():
    g = dx.get_method(method)

    # Display only methods with exceptions
    if method.get_code() == None:
        continue

    if method.get_code().tries_size <= 0:
        continue

    print(method.get_class_name(), method.get_name(), method.get_descriptor(
    ), method.get_code().get_length(), method.get_code().registers_size)

    idx = 0
    for i in g.basic_blocks.get():
        print("\t %s %x %x" % (i.name, i.start, i.end), '[ NEXT = ', ', '.join(
            "%x-%x-%s" % (j[0], j[1], j[2].get_name())
            for j in i.childs), ']', '[ PREV = ', ', '.join(
                j[2].get_name() for j in i.fathers), ']')

        for ins in i.get_instructions():
            print("\t\t %x" % idx, ins.get_name(), ins.get_output())
            idx += ins.get_length()

        print("")

    for i in g.exceptions.gets():
        print('%x %x %s' % (i.start, i.end, i.exceptions))

    print(dvm.determineException(d, method))
예제 #4
0
    def __init__(self, vm, method):
        self.__vm = vm
        self.method = method

        self.basic_blocks = BasicBlocks(self.__vm)
        self.exceptions = Exceptions(self.__vm)

        code = self.method.get_code()
        if code == None:
            return

        current_basic = DVMBasicBlock(0, self.__vm, self.method, self.basic_blocks)
        self.basic_blocks.push(current_basic)

        ##########################################################

        bc = code.get_bc()
        l = []
        h = {}
        idx = 0

        debug("Parsing instructions")
        instructions = [i for i in bc.get_instructions()]
        for i in instructions:
            for j in BasicOPCODES:
                if j.match(i.get_name()) != None:
                    v = dvm.determineNext(i, idx, self.method)
                    h[idx] = v
                    l.extend(v)
                    break

            idx += i.get_length()

        debug("Parsing exceptions")
        excepts = dvm.determineException(self.__vm, self.method)
        for i in excepts:
            l.extend([i[0]])
            for handler in i[2:]:
                l.append(handler[1])

        debug("Creating basic blocks in %s" % self.method)
        idx = 0
        for i in instructions:
            # index is a destination
            if idx in l:
                if current_basic.get_nb_instructions() != 0:
                    current_basic = DVMBasicBlock(current_basic.get_end(),
                                                  self.__vm, self.method,
                                                  self.basic_blocks)
                    self.basic_blocks.push(current_basic)

            current_basic.push(i)

            # index is a branch instruction
            if idx in h:
                current_basic = DVMBasicBlock(current_basic.get_end(),
                                              self.__vm, self.method,
                                              self.basic_blocks)
                self.basic_blocks.push(current_basic)

            idx += i.get_length()

        if current_basic.get_nb_instructions() == 0:
            self.basic_blocks.pop(-1)

        debug("Settings basic blocks childs")

        for i in self.basic_blocks.get():
            try:
                i.set_childs(h[i.end - i.get_last_length()])
            except KeyError:
                i.set_childs([])

        debug("Creating exceptions")

        # Create exceptions
        self.exceptions.add(excepts, self.basic_blocks)

        for i in self.basic_blocks.get():
            # setup exception by basic block
            i.set_exception_analysis(self.exceptions.get_exception(i.start,
                                                                   i.end - 1))

        del instructions
        del h, l
예제 #5
0
for method in a.get_methods():
    g = x.get_method(method)

    # Display only methods with exceptions
    if method.get_code() == None:
        continue

    if method.get_code().tries_size <= 0:
        continue

    print method.get_class_name(), method.get_name(), method.get_descriptor(
    ), method.get_code().get_length(), method.get_code().registers_size

    idx = 0
    for i in g.basic_blocks.get():
        print "\t %s %x %x" % (i.name, i.start, i.end), '[ NEXT = ', ', '.join(
            "%x-%x-%s" % (j[0], j[1], j[2].get_name())
            for j in i.childs), ']', '[ PREV = ', ', '.join(
                j[2].get_name() for j in i.fathers), ']'

        for ins in i.get_instructions():
            print "\t\t %x" % idx, ins.get_name(), ins.get_output()
            idx += ins.get_length()

        print ""

    for i in g.exceptions.gets():
        print '%x %x %s' % (i.start, i.end, i.exceptions)

    print dvm.determineException(a.get_vm(), method)
예제 #6
0
for method in d.get_methods():
    g = dx.get_method(method)

    # Display only methods with exceptions
    if method.get_code() == None:
        continue

    if method.get_code().tries_size <= 0:
        continue

    print method.get_class_name(), method.get_name(), method.get_descriptor(
    ), method.get_code().get_length(), method.get_code().registers_size

    idx = 0
    for i in g.basic_blocks.get():
        print "\t %s %x %x" % (i.name, i.start, i.end), '[ NEXT = ', ', '.join(
            "%x-%x-%s" % (j[0], j[1], j[2].get_name())
            for j in i.childs), ']', '[ PREV = ', ', '.join(
                j[2].get_name() for j in i.fathers), ']'

        for ins in i.get_instructions():
            print "\t\t %x" % idx, ins.get_name(), ins.get_output()
            idx += ins.get_length()

        print ""

    for i in g.exceptions.gets():
        print '%x %x %s' % (i.start, i.end, i.exceptions)

    print dvm.determineException(d, method)