def decompile(file): if (os.path.isdir(file)): dir = file files = os.listdir(dir) for f in files: f = dir + "\\" + f if (os.path.isdir(f)): decompile(f) else: base, ext = os.path.splitext(f) if ext == ".pyc" or ext == ".pyo": print("file: " + f) newfile = base +".uncompyled.py" print("new file: " + newfile) with open(newfile, "wb") as fileobj: uncompyle2.uncompyle_file(f, fileobj) elif (os.path.isfile(file)): print("file: " + file) base, ext = os.path.splitext(file) if ext == ".pyc" or ext == ".pyo": newfile = base + ".uncompyled.py" print("new file: " + newfile) fileToDecompile = file with open(newfile, "wb") as fileobj: uncompyle2.uncompyle_file(fileToDecompile, fileobj) else: print("Error: file not found!") raw_input() exit(1)
def uncompyle_decompilation(file_name): """ uncompyle2 support decompilation for Python 1.5 - 2.7a0 (details on magics.py) Return (reversed source code) .py file path """ py_file = ".".join([os.path.splitext(file_name)[0], 'py']) with open(py_file, 'w') as file_obj: try: uncompyle_file(file_name, file_obj) except (IndexError, Walker.ParserError): return None return py_file
import uncompyle2 with open("uncompiled.py", "wb") as fileobj: uncompyle2.uncompyle_file("ps2_verify_movement27.pyc", fileobj)
""" import os import sys import uncompyle2 from shutil import copyfile, rmtree SOURCE_DIR = '/mnt/ExternalHDD/E/workspace/ethereal-machines/astro-test-version/AstroBox/src/' TARGET_DIR = '/mnt/ExternalHDD/E/workspace/ethereal-machines/astro-test-version/AstroBox/de_src/' # SOURCE_DIR = input("Please enter root directory:\n") gen_tree = os.walk(SOURCE_DIR) for dir, subdir, files in gen_tree: if os.path.exists(dir.replace(SOURCE_DIR, TARGET_DIR)): # os.rmdir(dir.replace(SOURCE_DIR, TARGET_DIR)) rmtree(dir.replace(SOURCE_DIR, TARGET_DIR)) current_dir = dir.replace(SOURCE_DIR, TARGET_DIR) os.mkdir(current_dir) print "+---" + dir + ":" if files.count > 0: for file in files: if file.endswith('.pyo'): print '\t' + file with open( os.path.join(current_dir, file.replace('.pyo', '.py')), "wb") as fileobj: uncompyle2.uncompyle_file(os.path.join(dir, file), fileobj) else: copyfile(os.path.join(dir, file), os.path.join(current_dir, file))
def main(dbg=None, sys_argv=list(sys.argv)): """Routine which gets run if we were invoked directly""" # Save the original just for use in the restart that works via exec. orig_sys_argv = list(sys_argv) opts, dbg_opts, sys_argv = Moptions.process_options(__title__, __version__, sys_argv) if opts.server: connection_opts={'IO': 'TCP', 'PORT': opts.port} intf = Mserver.ServerInterface(connection_opts=connection_opts) dbg_opts['interface'] = intf if 'FIFO' == intf.server_type: print('Starting FIFO server for process %s.' % os.getpid()) elif 'TCP' == intf.server_type: print('Starting TCP server listening on port %s.' % intf.inout.PORT) pass elif opts.client: Mclient.main(opts, sys_argv) return dbg_opts['orig_sys_argv'] = orig_sys_argv if dbg is None: dbg = Mdebugger.Debugger(dbg_opts) dbg.core.add_ignore(main) pass Moptions._postprocess_options(dbg, opts) # process_options has munged sys.argv to remove any options that # options that belong to this debugger. The original options to # invoke the debugger and script are in global sys_argv if len(sys_argv) == 0: # No program given to debug. Set to go into a command loop # anyway mainpyfile = None else: mainpyfile = sys_argv[0] # Get script filename. if not os.path.isfile(mainpyfile): mainpyfile=Mclifns.whence_file(mainpyfile) is_readable = Mfile.readable(mainpyfile) if is_readable is None: print("%s: Python script file '%s' does not exist" % (__title__, mainpyfile,), file=sys.stderr) sys.exit(1) elif not is_readable: print("%s: Can't read Python script file '%s'" % (__title__, mainpyfile, ), file=sys.stderr) sys.exit(1) return if Mfile.is_compiled_py(mainpyfile): try: from uncompyle2 import uncompyle_file except ImportError: print("%s: Compiled python file '%s', but uncompyle2 not found" % (__title__, mainpyfile), file=sys.stderr) sys.exit(1) short_name = os.path.basename(mainpyfile).strip('.pyc') fd = tempfile.NamedTemporaryFile(suffix='.py', prefix=short_name + "_", delete=False) try: uncompyle_file(mainpyfile, fd) except: print("%s: error uncompyling '%s'" % (__title__, mainpyfile), file=sys.stderr) sys.exit(1) mainpyfile = fd.name fd.close() # If mainpyfile is an optimized Python script try to find and # use non-optimized alternative. mainpyfile_noopt = Mfile.file_pyc2py(mainpyfile) if mainpyfile != mainpyfile_noopt \ and Mfile.readable(mainpyfile_noopt): print("%s: Compiled Python script given and we can't use that." % __title__, file=sys.stderr) print("%s: Substituting non-compiled name: %s" % ( __title__, mainpyfile_noopt,), file=sys.stderr) mainpyfile = mainpyfile_noopt pass # Replace trepan's dir with script's dir in front of # module search path. sys.path[0] = dbg.main_dirname = os.path.dirname(mainpyfile) # XXX If a signal has been received we continue in the loop, otherwise # the loop exits for some reason. dbg.sig_received = False # if not mainpyfile: # print('For now, you need to specify a Python script name!') # sys.exit(2) # pass while True: # Run the debugged script over and over again until we get it # right. try: if dbg.program_sys_argv and mainpyfile: normal_termination = dbg.run_script(mainpyfile) if not normal_termination: break else: dbg.core.execution_status = 'No program' dbg.core.processor.process_commands() pass dbg.core.execution_status = 'Terminated' dbg.intf[-1].msg("The program finished - quit or restart") dbg.core.processor.process_commands() except Mexcept.DebuggerQuit: break except Mexcept.DebuggerRestart: dbg.core.execution_status = 'Restart requested' if dbg.program_sys_argv: sys.argv = list(dbg.program_sys_argv) part1 = ('Restarting %s with arguments:' % dbg.core.filename(mainpyfile)) args = ' '.join(dbg.program_sys_argv[1:]) dbg.intf[-1].msg(Mmisc.wrapped_lines(part1, args, dbg.settings['width'])) else: break except SystemExit: # In most cases SystemExit does not warrant a post-mortem session. break except: # FIXME: Should be handled above without this mess exception_name = str(sys.exc_info()[0]) if exception_name == str(Mexcept.DebuggerQuit): break elif exception_name == str(Mexcept.DebuggerRestart): dbg.core.execution_status = 'Restart requested' if dbg.program_sys_argv: sys.argv = list(dbg.program_sys_argv) part1 = ('Restarting %s with arguments:' % dbg.core.filename(mainpyfile)) args = ' '.join(dbg.program_sys_argv[1:]) dbg.intf[-1].msg( Mmisc.wrapped_lines(part1, args, dbg.settings['width'])) pass else: raise pass # Restore old sys.argv sys.argv = orig_sys_argv return
#https://github.com/wibiti/uncompyle2 #https://pypi.python.org/pypi/uncompyle2/1.1 #sudo python setup.py install import uncompyle2 filename = 'game' with open('{}.py'.format(filename), "wb") as f: uncompyle2.uncompyle_file('{}.pyc'.format(filename), f)
import os import zlib from shutil import copyfile import uncompyle2 PACKET_DIR = "C:\\EVE\\bin\\packets_\\" for i in os.listdir(PACKET_DIR): with open(PACKET_DIR + i, 'rb') as f: header = ord(f.read(1)) if header == 126: copyfile(PACKET_DIR + i, PACKET_DIR + i + '.eve') continue try: raw = zlib.decompress(open(PACKET_DIR + i, 'rb').read()) raw_file = open(PACKET_DIR + i + '.eve', 'wb') raw_file.write(raw) raw_file.close() # OK this is actually not being sent over the network. # it seems to be an after effect of late loading from code.ccp # Keeping it in as it marks that the file was processed correctly # though it is not related to the network protocol at all. if ord(raw[0]) == 3: uncompyle2.uncompyle_file(PACKET_DIR + i + '.eve', open(PACKET_DIR + i + '.eve.py', 'w')) except zlib.error: print "zlib.error", i except: print "unknown except!" import sys print sys.exc_info()
import uncompyle2 with open("zipfile.py", "wb") as fileobj: uncompyle2.uncompyle_file("C:\\temp\\zipfile.pyo", fileobj)