Exemplo n.º 1
0
def decompileClass(path=[], targets=None, outpath=None, plugins=[], skipMissing=False):
    writeout = script_util.fileDirOut(outpath, '.java')

    e = Environment()
    for part in path:
        e.addToPath(part)

    makeGraph = makeCallback(plugins)
    start_time = time.time()
    # random.shuffle(targets)
    with e: #keep jars open
        for i,target in enumerate(targets):
            print 'processing target {}, {} remaining'.format(target, len(targets)-i)

            try:
                c = e.getClass(target)
                source = javaclass.generateAST(c, makeGraph).print_()
            except ClassLoaderError as err:
                if skipMissing:
                    print 'failed to decompile {} due to missing or invalid class {}'.format(target, err.data)
                    continue
                else:
                    raise

            #The single class decompiler doesn't add package declaration currently so we add it here
            if '/' in target:
                package = 'package {};\n\n'.format(target.replace('/','.').rpartition('.')[0])
                source = package + source

            filename = writeout(c.name, source)
            print 'Class written to', filename
            print time.time() - start_time, ' seconds elapsed'
            deleteUnusued(c)
Exemplo n.º 2
0
def decompileClass(path=[], targets=None, outpath=None, skipMissing=False):
    writeout = script_util.fileDirOut(outpath, '.java')

    e = Environment()
    for part in path:
        e.addToPath(part)

    start_time = time.time()
    # random.shuffle(targets)
    with e: #keep jars open
        for i,target in enumerate(targets):
            script_util.printVerbose('processing target {}, {} remaining'.format(target, len(targets)-i))

            try:
                c = e.getClass(target)
                source = javaclass.generateAST(c, makeGraph).print_()
            except ClassLoaderError as err:
                if skipMissing:
                    print 'failed to decompile {} due to missing or invalid class {}'.format(target, err.data)
                    continue
                else:
                    raise

            #The single class decompiler doesn't add package declaration currently so we add it here
            if '/' in target:
                package = 'package {};\n\n'.format(target.replace('/','.').rpartition('.')[0])
                source = package + source

            filename = writeout(c.name, source)
            script_util.printVerbose('Class written to ' + filename)
            script_util.printVerbose('{} seconds elapsed'.format(time.time() - start_time))
            deleteUnusued(c)
Exemplo n.º 3
0
def disassembleClass(readTarget, targets=None, outpath=None):
    writeout = script_util.fileDirOut(outpath, '.j')

    # targets = targets[::-1]
    start_time = time.time()
    # __import__('random').shuffle(targets)
    for i,target in enumerate(targets):
        script_util.printVerbose('processing target {}, {}/{} remaining'.format(target, len(targets)-i, len(targets)))

        data = readTarget(target)
        stream = Krakatau.binUnpacker.binUnpacker(data=data)
        class_ = ClassFile(stream)
        class_.loadElements(keepRaw=True)

        source = Krakatau.assembler.disassembler.disassemble(class_)
        filename = writeout(class_.name, source)
        script_util.printVerbose('Class written to ' + filename)
        script_util.printVerbose('{} seconds elapsed'.format(time.time() - start_time))
Exemplo n.º 4
0
def disassembleClass(readTarget, targets=None, outpath=None):
    writeout = script_util.fileDirOut(outpath, '.j')

    # targets = targets[::-1]
    start_time = time.time()
    # __import__('random').shuffle(targets)
    for i, target in enumerate(targets):
        print 'processing target {}, {}/{} remaining'.format(
            target,
            len(targets) - i, len(targets))

        data = readTarget(target)
        stream = Krakatau.binUnpacker.binUnpacker(data=data)
        class_ = ClassFile(stream)
        class_.loadElements(keepRaw=True)

        source = Krakatau.assembler.disassembler.disassemble(class_)
        filename = writeout(class_.name, source)
        print 'Class written to', filename
        print time.time() - start_time, ' seconds elapsed'
Exemplo n.º 5
0
def disassembleClass(readTarget, targets=None, outpath=None, outputHandler = consolePrint, logMachine = dummyLogMachineHandle):
    writeout = script_util.fileDirOut(outpath, '.j')

    # targets = targets[::-1]
    start_time = time.time()
    # __import__('random').shuffle(targets)
    for i,target in enumerate(targets):
        outputHandler('processing target {}, {}/{} remaining'.format(target, len(targets)-i, len(targets)))

        data = readTarget(target)
        stream = Krakatau.binUnpacker.binUnpacker(data=data)
        class_ = ClassFile(stream)
        class_.loadElements(keepRaw=True)

        logMachine.beginFile(target)
        source = Krakatau.assembler.disassembler.disassemble(class_, logMachine)
        filename = writeout(class_.name, source)
        
        outputHandler('Class written to', filename)
        outputHandler(time.time() - start_time, ' seconds elapsed')
Exemplo n.º 6
0
def decompileClass(path=[], targets=None, outpath=None, plugins=[]):
    writeout = script_util.fileDirOut(outpath, '.java')

    e = Environment()
    for part in path:
        e.addToPath(part)

    makeGraph = makeCallback(plugins)
    start_time = time.time()
    # random.shuffle(targets)
    with e: #keep jars open
        for i,target in enumerate(targets):
            print 'processing target {}, {} remaining'.format(target, len(targets)-i)
            c = e.getClass(target)
            source = javaclass.generateAST(c, makeGraph).print_()
            #The single class decompiler doesn't add package declaration currently so we add it here
            if '/' in target:
                package = 'package {};\n\n'.format(target.replace('/','.').rpartition('.')[0])
                source = package + source

            filename = writeout(c.name, source)
            print 'Class written to', filename
            print time.time() - start_time, ' seconds elapsed'
            deleteUnusued(c)
Exemplo n.º 7
0
    lexer = tokenize.makeLexer(debug=debug)
    parser = parse.makeParser(debug=debug)
    parse_trees = parser.parse(assembly, lexer=lexer)
    return parse_trees and [assembler.assemble(tree, makeLineNumbers, jasmode, basename) for tree in parse_trees]

if __name__== "__main__":
    print script_util.copyright

    import argparse
    parser = argparse.ArgumentParser(description='Krakatau bytecode assembler')
    parser.add_argument('-out',help='Path to generate files in')
    parser.add_argument('-g', action='store_true', help="Add line number information to the generated class")
    parser.add_argument('-jas', action='store_true', help="Enable Jasmin compatibility mode")
    parser.add_argument('-r', action='store_true', help="Process all files in the directory target and subdirectories")
    parser.add_argument('target',help='Name of file to assemble')
    args = parser.parse_args()

    targets = script_util.findFiles(args.target, args.r, '.j')
    writeout = script_util.fileDirOut(args.out, '.class')

    for i, target in enumerate(targets):
        print 'Processing file {}, {}/{} remaining'.format(target, len(targets)-i, len(targets))
        pairs = assembleClass(target, args.g, args.jas)

        # if pairs is None:
        #     print 'Assembly of ', target, 'failed!'
        #     continue

        for name, data in pairs:
            filename = writeout(name, data)
            print 'Class written to', filename
Exemplo n.º 8
0
    parser.add_argument('-out', help='Path to generate files in')
    parser.add_argument(
        '-g',
        action='store_true',
        help="Add line number information to the generated class")
    parser.add_argument('-jas',
                        action='store_true',
                        help="Enable Jasmin compatibility mode")
    parser.add_argument(
        '-r',
        action='store_true',
        help="Process all files in the directory target and subdirectories")
    parser.add_argument('target', help='Name of file to assemble')
    args = parser.parse_args()

    targets = script_util.findFiles(args.target, args.r, '.j')
    writeout = script_util.fileDirOut(args.out, '.class')

    for i, target in enumerate(targets):
        print 'Processing file {}, {}/{} remaining'.format(
            target,
            len(targets) - i, len(targets))
        pairs = assembleClass(target, args.g, args.jas)

        # if pairs is None:
        #     print 'Assembly of ', target, 'failed!'
        #     continue

        for name, data in pairs:
            filename = writeout(name, data)
            print 'Class written to', filename