Created
August 29, 2023 06:28
-
-
Save silverwolfceh/f6dad57b4388b7ff32b371ab83185466 to your computer and use it in GitHub Desktop.
rununcompyle6.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import time | |
import subprocess | |
# Keep UTF-8 environment | |
environ = os.environ.copy() | |
environ['PYTHONIOENCODING'] = 'utf-8' | |
verbose = True | |
enable_filter = False | |
excludes = [ | |
"__init__.pyc", | |
"pyiboot01_bootstrap.pyc", | |
"pyimod01_archive.pyc", | |
"pyimod02_importers.pyc", | |
"pyimod03_ctypes.pyc", | |
"pyimod04_pywin32.pyc", | |
"struct.pyc", | |
"argparse.pyc", | |
"base64.pyc", | |
"bisect.pyc", | |
"bz2.pyc", | |
"calendar.pyc", | |
"contextlib.pyc", | |
"copy.pyc", | |
"datetime.pyc", | |
"ftplib.pyc", | |
"getopt.pyc", | |
"getpass.pyc", | |
"gettext.pyc", | |
"gzip.pyc", | |
"hashlib.pyc", | |
"lzma.pyc", | |
"mimetypes.pyc", | |
"netrc.pyc", | |
"nturl2path.pyc", | |
"optparse.pyc", | |
"pickle.pyc", | |
"pprint.pyc", | |
"py_compile.pyc", | |
"quopri.pyc", | |
"random.pyc", | |
"selectors.pyc", | |
"shlex.pyc", | |
"shutil.pyc", | |
"signal.pyc", | |
"socket.pyc", | |
"ssl.pyc", | |
"string.pyc", | |
"stringprep.pyc", | |
"subprocess.pyc", | |
"tarfile.pyc", | |
"tempfile.pyc", | |
"textwrap.pyc", | |
"threading.pyc", | |
"tracemalloc.pyc", | |
"typing.pyc", | |
"uu.pyc", | |
"zipfile.pyc", | |
"_compat_pickle.pyc", | |
"_compression.pyc", | |
"_py_abc.pyc", | |
"_strptime.pyc", | |
"_threading_local.pyc", | |
"base64mime.pyc", | |
"charset.pyc", | |
"contentmanager.pyc", | |
"encoders.pyc", | |
"errors.pyc", | |
"feedparser.pyc", | |
"generator.pyc", | |
"header.pyc", | |
"headerregistry.pyc", | |
"iterators.pyc", | |
"message.pyc", | |
"parser.pyc", | |
"policy.pyc", | |
"quoprimime.pyc", | |
"utils.pyc", | |
"_encoded_words.pyc", | |
"_header_value_parser.pyc", | |
"_parseaddr.pyc", | |
"_policybase.pyc", | |
"client.pyc", | |
"cookiejar.pyc", | |
"abc.pyc", | |
"machinery.pyc", | |
"util.pyc", | |
"_bootstrap.pyc", | |
"_bootstrap_external.pyc" | |
] | |
max_len = 100 | |
# Specify the program to execute | |
program = "uncompyle6" | |
# Default mode | |
mode = "a" | |
directory = "." | |
# Get the directory name from the command line argument | |
if len(sys.argv) < 3: | |
print("Syntact: rununcompyle6.py [a/c] [dir|configfile]") | |
print("Switch to default mode with decompyle all and current directory. You have 10s to stop") | |
time.sleep(10) | |
else: | |
directory = sys.argv[2] | |
mode = sys.argv[1] | |
def print_data(fmt): | |
global max_len | |
msg = fmt | |
if len(msg) > max_len: | |
max_len = len(msg) + 1 | |
spacenum = max_len - len(msg) | |
print(msg, " "*spacenum, end = '\r') | |
def process_file(root, file): | |
global program | |
# Build the full path to the input file | |
input_file = os.path.join(root, file) | |
if verbose: | |
print_data("Start uncompyle file %s to %s" % (input_file, os.path.splitext(input_file)[0] + ".py")) | |
# Build the full path to the output file | |
output_file = os.path.splitext(input_file)[0] + ".py" | |
# Execute the program with the input and output file paths as arguments | |
result = subprocess.run([program, input_file], capture_output=True, text=True, env=environ, encoding="utf-8") | |
# Write the output to the output file | |
with open(output_file, 'w', encoding='utf-8') as f: | |
f.write(result.stdout) | |
if verbose: | |
print_data("File %s processed" % input_file) | |
if mode == "a": | |
# Walk through the directory tree recursively | |
for root, dirs, files in os.walk(directory): | |
if verbose: | |
print_data("Scan directory %s" % root) | |
print_data("Found %d" % len(files)) | |
# Execute the program for all files with .pyc extension in the current directory | |
for file in files: | |
if file.endswith('.pyc'): | |
if enable_filter and file in excludes: | |
print_data("Filttered %s" % file) | |
elif not enable_filter or file not in excludes: | |
process_file(root, file) | |
elif mode == "c": | |
print("Current working directory: {0}".format(os.getcwd())) | |
with open(directory) as cfile: | |
lines = [line.rstrip('\n') for line in cfile] | |
for l in lines: | |
process_file(os.getcwd(),l+ "c") | |
print_data("Done. ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment