Skip to content

Commit

Permalink
Add colors for readability, can decrypt other files than .lua like .j…
Browse files Browse the repository at this point in the history
…son. Removed all python dependencies
  • Loading branch information
jooapa committed Feb 4, 2024
1 parent be06f16 commit 1e996ce
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 41 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ If you don't know how to install Angry Birds PC ports, [here](https://archive.or
### Automatic decrypting

Firstly install [Python 3](https://www.python.org/downloads/).

pip install py7zr
You need to have [7z](https://www.7-zip.org/download.html) installed in the terminal.

Drag and drop the .lua file to birdout.py and choose what angry birds game it is. Then it will decrypt it for you automatically.
or you can run it in the terminal with:
Expand Down
125 changes: 86 additions & 39 deletions birdout.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,64 @@
import os, sys, subprocess
import py7zr

class col:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
GREY = '\033[90m'

arg_files = sys.argv[1:]
files = []

# counting the number of directories

org_path = os.path.dirname(os.path.realpath(__file__))
# get directory of first file
path_to_current_lua_file = []

if len(arg_files) == 0:
print("Usage: birdout.py <file.lua> <file.lua> ...")
print(col.FAIL + "Usage: birdout.py <file.lua> <file.lua> ..." + col.ENDC)
print("You can also pass a directory as an argument to decrypt all .lua files in it.")
sys.exit(1)

onlyLuaFiles = True

while True:
onlyLuaFiles = input("\nDo you want to decrypt only .lua files? " + col.GREY + "(y/n): " + col.ENDC)
if onlyLuaFiles == "y" or onlyLuaFiles == "n":
if onlyLuaFiles == "y":
onlyLuaFiles = True
else:
onlyLuaFiles = False
break
else:
print(f"{col.FAIL}Invalid input! nöf nöf!{col.ENDC}")


for file in arg_files:
# if directory
if os.path.isdir(file):
# loop through all files in directory and if extension is .lua, add to list
for root, dirs, files_in_dir in os.walk(file):
for file_in_dir in files_in_dir:
if file_in_dir.endswith(".lua"):
if file_in_dir.endswith(".lua") or not onlyLuaFiles:
file_path = os.path.join(root, file_in_dir)
print("Found file: " + file_path)
print(col.OKGREEN + "Found file: " + file_path + col.ENDC)
files.append(file_path)

elif os.path.isfile(file):
print("Found file: " + file)
print(col.OKGREEN + "Found file: " + file + col.ENDC)
files.append(file)
else:
print("File not found: " + file)
print(col.FAIL + "File not found: " + file + col.ENDC)

if len(files) == 0:
print("No valid files found!")
print(col.FAIL + "No valid Files!" + col.ENDC)
sys.exit(1)

# get directory of each file
Expand All @@ -42,18 +68,18 @@
# remove the path from files
# files = [os.path.basename(file) for file in files]

print(col.HEADER)
print("\nAngry Birds Lua Decryptor"+ col.ENDC +", works on for decrypting Angry Birds game files.")
print("For " + col.UNDERLINE + "Encrypting" + col.ENDC + " files back to og, " + col.BOLD + "Check README.md" + col.ENDC)

print("\nAngry Birds Lua Decryptor, works on for decrypting Angry Birds Lua files.")
print("For Encrypting Luad files back, Chech README.md")

inp = input('''
CHOOSE Angry Birds Game:
1. Angry Birds
2. Angry Birds Rio
3. Angry Birds Seasons
4. Angry Birds Space
5. Angry Birds Star Wars
6. Angry Birds Star Wars II
inp = input(f'''
{col.HEADER}CHOOSE Angry Birds Game: {col.ENDC}
{col.BOLD}1.{col.ENDC} Angry Birds
{col.BOLD}2.{col.ENDC} Angry Birds Rio
{col.BOLD}3.{col.ENDC} Angry Birds Seasons
{col.BOLD}4.{col.ENDC} Angry Birds Space
{col.BOLD}5.{col.ENDC} Angry Birds Star Wars
6{col.BOLD}.{col.ENDC} Angry Birds Star Wars II
''')

if inp == '1': # Angry Birds
Expand All @@ -69,21 +95,25 @@
elif inp == '6': # Angry Birds Star Wars II
hex = "4230706D3354416C7A6B4E3967687A6F65324E697A456C6C50644E3068516E69"
else:
print("Invalid input! nöf nöf!")
print(f"{col.FAIL}Invalid input! nöf nöf!{col.ENDC}")
sys.exit(1)

def extract_7z(archive_path, extract_path):
print("Extracting " + archive_path + "...")
print(f"Extracting {col.OKBLUE}" + archive_path + f"{col.ENDC}...")
try:
with py7zr.SevenZipFile(archive_path, mode='r') as archive:
archive.extractall(extract_path)
except py7zr.exceptions.Bad7zFile:
print("Error: Not a 7z archive! File might be corrupted somehow or it already has been decrypted.")
if '7Z' in os.environ:
seven_zip_path = os.environ['7Z']
else:
seven_zip_path = "7z" # Default path if the environment variable is not set

subprocess.run([seven_zip_path, "x", archive_path, f"-o{extract_path}"])
except subprocess.CalledProcessError:
print(f"{col.FAIL}Error: Not a 7z archive! File might be corrupted somehow or it already has been decrypted.{col.ENDC}")
os.remove(archive_path)
sys.exit(1)

def decrypt_file(hex, file):
print("Decrypting " + file + "...")
print(f"Decrypting {col.OKBLUE}" + file + f"{col.ENDC}...")
output_file = file + ".7z"

combined_path = os.path.join(org_path, "bin/openssl")
Expand All @@ -93,24 +123,41 @@ def decrypt_file(hex, file):
decryption_result = subprocess.run(["wine", combined_path, "enc", "-aes-256-cbc", "-d", "-K", hex, "-iv", "0", "-in", file, "-out", output_file], capture_output=True)

if decryption_result.returncode != 0:
print("You might have entered the wrong game file or the file is corrupted. Decrypting failed! nöf nöf!")
print(f"{col.FAIL}You might have entered the wrong game file or the file is corrupted. Decrypting failed! nöf nöf! \nor the file has been already decrypted{col.ENDC}")
os.remove(file + ".7z")
sys.exit(1)

while True:
continue_still = input(f"\nDo you want to continue with the next file? " + col.GREY + "(y/n): " + col.ENDC)
if continue_still == "y" or continue_still == "n":
if continue_still == "y":
pass
else:
sys.exit(1)
break
else:
print(f"{col.FAIL}Invalid input! nöf nöf!{col.ENDC}")
return

extract_7z(output_file, extract_path)
os.remove(output_file)
os.remove(file)
# run java -jar bin/unluac.jar out/<file> > out/<file>.lua
combined_jar_path = os.path.join(org_path, "bin/unluac.jar")
# subprocess.call(["java", "-jar", "bin/unluac.jar", "out/" + file], stdout=open("out/" + file + ".decrypt", "w"))
subprocess.call(["java", "-jar", combined_jar_path, "out/" + file], stdout=open("out/" + file + ".decrypt", "w"))
# move decrypted file to root
os.rename("out/" + file + ".decrypt", file)
# remove out folder and its contents
os.remove("out/" + file)
os.rmdir("out")

print("Done!", file + " decrypted!")
if onlyLuaFiles:
# run java -jar bin/unluac.jar out/<file> > out/<file>.lua
combined_jar_path = os.path.join(org_path, "bin/unluac.jar")
# subprocess.call(["java", "-jar", "bin/unluac.jar", "out/" + file], stdout=open("out/" + file + ".decrypt", "w"))
subprocess.call(["java", "-jar", combined_jar_path, "out/" + file], stdout=open("out/" + file + ".decrypt", "w"))
# move decrypted file to root
os.rename("out/" + file + ".decrypt", file)
# remove out folder and its contents
os.remove("out/" + file)
os.rmdir("out")
else:
# move file to parent directory
os.rename("out/" + file, file)
# remove out folder
os.rmdir("out")

print(f"{col.OKCYAN}Done! {file} decrypted!{col.ENDC}")

extract_path = "out"

Expand All @@ -122,4 +169,4 @@ def decrypt_file(hex, file):
file = os.path.basename(file)
decrypt_file(hex, file)

print("nöf nöf! Done!")
print(col.OKGREEN + "nöf nöf! Done!" + col.ENDC)

0 comments on commit 1e996ce

Please sign in to comment.