def main(in_base, out_base, files, outfile=None, showasm=0, showast=0, do_verify=0): def _get_outstream(outfile): dir = os.path.dirname(outfile) failed_file = outfile + '_failed' if os.path.exists(failed_file): os.remove(failed_file) if not os.path.exists(dir): try: os.makedirs(dir) except: raise "Can't create output dir '%s'" % dir return open(outfile, 'w') of = outfile tot_files = okay_files = failed_files = verify_failed_files = 0 for file in files: infile = os.path.join(in_base, file) if of: outstream = _get_outstream(outfile) elif out_base is None: outstream = sys.stdout else: outfile = os.path.join(out_base, file) + '_dis' outstream = _get_outstream(outfile) try: decompyle_file(infile, outstream, showasm, showast) tot_files += 1 except KeyboardInterrupt: if outfile: outstream.close() os.remove(outfile) raise except: failed_files += 1 sys.stderr.write("### Can't decompyle %s\n" % file) if outfile: outstream.close() os.rename(outfile, outfile + '_failed') raise else: if outfile: outstream.close() if do_verify: try: verify.compare_code_with_srcfile(infile, outfile) print "+++ okay decompyling", infile, __memUsage() okay_files += 1 except verify.VerifyCmpError, e: verify_failed_files += 1 os.rename(outfile, outfile + '_unverified') print >> sys.stderr, "### Error Verifiying", file print >> sys.stderr, e else: okay_files += 1 print "+++ okay decompyling", infile, __memUsage()
def main(in_base, out_base, files, outfile=None, showasm=0, showast=0, do_verify=0): """ in_base base directory for input files out_base base directory for output files (ignored when files list of filenames to be decompyles (relative to src_base) outfile write output to this filename (overwrites out_base) For rediecting output to - <filename> outfile=<filename> (out_base is ignored) - files below out_base out_base=... - stdout out_base=None, outfile=None """ def _get_outstream(outfile): dir = os.path.dirname(outfile) failed_file = outfile + '_failed' if os.path.exists(failed_file): os.remove(failed_file) if not os.path.exists(dir): try: os.makedirs(dir) except: raise "Can't create output dir '%s'" % dir return open(outfile, 'w') of = outfile tot_files = okay_files = failed_files = verify_failed_files = 0 for file in files: infile = os.path.join(in_base, file) #print >>sys.stderr, infile if of: # outfile was given as parameter outstream = _get_outstream(outfile) elif out_base is None: outstream = sys.stdout else: outfile = os.path.join(out_base, file) + '_dis' outstream = _get_outstream(outfile) #print >>sys.stderr, outfile # try to decomyple the input file try: decompyle_file(infile, outstream, showasm, showast) tot_files += 1 except KeyboardInterrupt: if outfile: outstream.close() os.remove(outfile) raise except: failed_files += 1 sys.stderr.write("### Can't decompyle %s\n" % file) if outfile: outstream.close() os.rename(outfile, outfile + '_failed') raise else: # decompyle successfull if outfile: outstream.close() if do_verify: try: verify.compare_code_with_srcfile(infile, outfile) print "+++ okay decompyling", infile, __memUsage() okay_files += 1 except verify.VerifyCmpError, e: verify_failed_files += 1 os.rename(outfile, outfile + '_unverified') print >>sys.stderr, "### Error Verifiying", file print >>sys.stderr, e else: okay_files += 1 print "+++ okay decompyling", infile, __memUsage()
def main(in_base, out_base, files, codes, outfile=None, showasm=0, showast=0, do_verify=0): ''' in_base base directory for input files out_base base directory for output files (ignored when files list of filenames to be uncompyled (relative to src_base) outfile write output to this filename (overwrites out_base) For redirecting output to - <filename> outfile=<filename> (out_base is ignored) - files below out_base out_base=... - stdout out_base=None, outfile=None ''' def _get_outstream(outfile): dir = os.path.dirname(outfile) failed_file = outfile + '_failed' if os.path.exists(failed_file): os.remove(failed_file) try: os.makedirs(dir) except OSError: pass return open(outfile, 'w') of = outfile tot_files = okay_files = failed_files = verify_failed_files = 0 for code in codes: version = sys.version[:3] # "2.5" with open(code, "r") as f: co = compile(f.read(), "", "exec") uncompyle(sys.version[:3], co, sys.stdout, showasm=showasm, showast=showast) for file in files: infile = os.path.join(in_base, file) #print >>sys.stderr, infile if of: # outfile was given as parameter outstream = _get_outstream(outfile) elif out_base is None: outstream = sys.stdout else: outfile = os.path.join(out_base, file) + '_dis' outstream = _get_outstream(outfile) #print >>sys.stderr, outfile # try to decomyple the input file try: uncompyle_file(infile, outstream, showasm, showast) tot_files += 1 except KeyboardInterrupt: if outfile: outstream.close() os.remove(outfile) sys.stderr.write("\nLast file: %s " % (infile)) raise except: failed_files += 1 if outfile: outstream.close() os.rename(outfile, outfile + '_failed') else: sys.stderr.write("\n# Can't uncompyle %s\n" % infile) import traceback traceback.print_exc() #raise else: # uncompyle successfull if outfile: outstream.close() if do_verify: try: verify.compare_code_with_srcfile(infile, outfile) if not outfile: print '\n# okay decompyling', infile, __memUsage() okay_files += 1 except verify.VerifyCmpError, e: verify_failed_files += 1 os.rename(outfile, outfile + '_unverified') if not outfile: print >>sys.stderr, "### Error Verifiying", file print >>sys.stderr, e else: okay_files += 1 if not outfile: print '\n# okay decompyling', infile, __memUsage()
def main(in_base, out_base, files, codes, outfile=None, showasm=0, showast=0, do_verify=0, py=0, deob=0): """ in_base base directory for input files out_base base directory for output files (ignored when files list of filenames to be uncompyled (relative to src_base) outfile write output to this filename (overwrites out_base) For redirecting output to - <filename> outfile=<filename> (out_base is ignored) - files below out_base out_base=... - stdout out_base=None, outfile=None """ def _get_outstream(outfile): dir = os.path.dirname(outfile) failed_file = outfile + '_failed' if os.path.exists(failed_file): os.remove(failed_file) try: os.makedirs(dir) except OSError: pass return open(outfile, 'w') of = outfile tot_files = okay_files = failed_files = verify_failed_files = 0 for code in codes: version = sys.version[:3] # "2.5" with open(code, "r") as f: co = compile(f.read(), "", "exec") uncompyle(sys.version[:3], co, sys.stdout, showasm=showasm, showast=showast, deob=deob) for file in files: infile = os.path.join(in_base, file) #print >>sys.stderr, infile if of: # outfile was given as parameter outstream = _get_outstream(outfile) elif out_base is None: outstream = sys.stdout else: outfile = os.path.join(out_base, file) if py: outfile = outfile[:-1] else: outfile += '_dis' outstream = _get_outstream(outfile) #print >>sys.stderr, outfile # try to decomyple the input file try: uncompyle_file(infile, outstream, showasm, showast, deob) tot_files += 1 except KeyboardInterrupt: if outfile: outstream.close() os.remove(outfile) raise except: failed_files += 1 sys.stderr.write("### Can't uncompyle %s\n" % infile) if outfile: outstream.close() os.rename(outfile, outfile + '_failed') import traceback traceback.print_exc() #raise else: # uncompyle successfull if outfile: outstream.close() if do_verify: try: verify.compare_code_with_srcfile(infile, outfile) print "+++ okay decompyling", infile, __memUsage() okay_files += 1 except verify.VerifyCmpError, e: verify_failed_files += 1 os.rename(outfile, outfile + '_unverified') print >> sys.stderr, "### Error Verifiying", file print >> sys.stderr, e else: okay_files += 1 print "+++ okay decompyling", infile, __memUsage()