def decompileClass(path=[], targets=None, outpath=None, plugins=[]): if outpath is None: outpath = os.getcwd() 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 = script_util.writeFile(outpath, c.name, '.java', source) print 'Class written to', filename print time.time() - start_time, ' seconds elapsed' deleteUnusued(c)
def decompileClass(path=[], targets=None, outpath=None): if outpath is None: outpath = os.getcwd() 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): print 'processing target {}, {} remaining'.format(target, len(targets)-i) c = e.getClass(target) deco = javaclass.ClassDecompiler(c, makeGraph) source = deco.generateSource() #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 = script_util.writeFile(outpath, c.name, '.java', source) print 'Class written to', filename print time.time() - start_time, ' seconds elapsed' deleteUnusued(c)
def disassembleClass(readTarget, targets=None, outpath=None): if outpath is None: outpath = os.getcwd() # targets = targets[::-1] start_time = time.time() # 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) source = Krakatau.assembler.disassembler.disassemble(class_) filename = script_util.writeFile(outpath, class_.name, '.j', source) print 'Class written to', filename print time.time() - start_time, ' seconds elapsed'
def disassembleClass(readTarget, targets=None, outpath=None): if outpath is None: outpath = os.getcwd() # 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 = script_util.writeFile(outpath, class_.name, '.j', source) print 'Class written to', filename print time.time() - start_time, ' seconds elapsed'
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') base_path = args.out if args.out is not None else os.getcwd() 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 = script_util.writeFile(base_path, name, '.class', data) print 'Class written to', filename
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 'Krakatau Copyright (C) 2012-13 Robert Grosse' 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') base_path = args.out if args.out is not None else os.getcwd() 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 = script_util.writeFile(base_path, name, '.class', data) print 'Class written to', filename