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 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)
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)
def decompileClass(path=[], targets=None, outpath=None, skip_errors=False, add_throws=False, magic_throw=False): out = script_util.makeWriter(outpath, '.java') e = Environment() for part in path: e.addToPath(part) start_time = time.time() # random.shuffle(targets) with e, out: printer = visitor.DefaultVisitor() for i, target in enumerate(targets): if isinstance(target, unicode): target = target.encode('utf8') print('processing target {}, {} remaining'.format( target, len(targets) - i)) try: c = e.getClass(target) makeGraphCB = functools.partial(makeGraph, magic_throw) source = printer.visit( javaclass.generateAST(c, makeGraphCB, skip_errors, add_throws=add_throws)) except Exception as err: if not skip_errors: raise if isinstance(err, ClassLoaderError): print( 'Failed to decompile {} due to missing or invalid class {}' .format(target, err.data)) else: import traceback print(traceback.format_exc()) continue # The single class decompiler doesn't add package declaration currently so we add it here if '/' in target: package = 'package {};\n\n'.format( escapeString(target.replace('/', '.').rpartition('.')[0])) source = package + source filename = out.write(c.name.encode('utf8'), source) print('Class written to', filename) print(time.time() - start_time, ' seconds elapsed') deleteUnusued(c) print(len(e.classes) - len(targets), 'extra classes loaded')
def decompileClass(path=[], target=None, outpath=None, skip_errors=False, add_throws=False, magic_throw=False): out = open(outPath, "w") e = Environment() for part in path: e.addToPath(part) start_time = time.time() # random.shuffle(targets) with e, out: printer = visitor.DefaultVisitor() try: c = None with open(target, "rb") as targetF: stream = Reader(data=targetF.read()) c = ClassFile(stream) c.env = e e.classes[c.name] = c makeGraphCB = functools.partial(makeGraph, magic_throw) source = printer.visit( javaclass.generateAST(c, makeGraphCB, skip_errors, add_throws=add_throws)) except Exception as err: if not skip_errors: raise if isinstance(err, ClassLoaderError): print( 'Failed to decompile {} due to missing or invalid class {}' .format(target, err.data)) else: import traceback print(traceback.format_exc()) return # The single class decompiler doesn't add package declaration currently so we add it here if '/' in target: package = 'package {};\n\n'.format( escapeString(target.replace('/', '.').rpartition('.')[0])) source = package + source out.write(source) print(time.time() - start_time, ' seconds elapsed') deleteUnusued(c) print(len(e.classes) - 1, 'extra classes loaded')
def decompileClass(path=[], targets=None, outpath=None, skip_errors=False, rename_classes=None, add_throws=False): out = script_util.makeWriter(outpath, '.java') e = Environment() for part in path: e.addToPath(part) start_time = time.time() # random.shuffle(targets) with e, out: print rename_classes if rename_classes is None: printer = visitor.DefaultVisitor() else: printer = visitor.RenameClassesVisitor(targets, rename_classes) for i,target in enumerate(targets): print 'processing target {}, {} remaining'.format(target.encode('utf8'), len(targets)-i) try: c = e.getClass(target) source = printer.visit(javaclass.generateAST(c, makeGraph, skip_errors, add_throws=add_throws)) except Exception as err: if not skip_errors: raise if isinstance(err, ClassLoaderError): print 'Failed to decompile {} due to missing or invalid class {}'.format(target.encode('utf8'), err.data.encode('utf8')) else: import traceback print traceback.format_exc() continue #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 = out.write(printer.className(c.name), source) print 'Class written to', filename.encode('utf8') print time.time() - start_time, ' seconds elapsed' deleteUnusued(c)
def decompileClass(path=[], targets=None, outpath=None, disassemble=False): if outpath is None: outpath = os.getcwd() e = Environment() for part in path: e.addToPath(part) # 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) c = e.getClass(target) if disassemble: source = Krakatau.assembler.disassembler.disassemble(c) else: 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 outpath2 = outpath if os.path.isdir(outpath2): outpath2 = os.path.join(outpath2, *c.name.split('/')) outpath2 += '.java' if not disassemble else '.j' dirpath = os.path.dirname(outpath2) if dirpath and not os.path.exists(dirpath): os.makedirs(dirpath) print 'writing generated source to', outpath2 with open(outpath2,'w') as f: f.write(source) print time.time() - start_time, ' seconds elapsed'