Skip to content

Commit

Permalink
feat: Update to splitted apk
Browse files Browse the repository at this point in the history
  • Loading branch information
O-Isaac committed Aug 15, 2024
1 parent 543b8f0 commit 8ad0688
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 46 deletions.
2 changes: 1 addition & 1 deletion VerCode.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"appVer": "2.67.0", "verCode": "b7c29a7ea5620ce9e9b56e198761f8adabda3b019c32b714a3696ea87464c255"}
{"appVer": "2.67.0", "verCode": "b7c29a7ea5620ce9e9b56e198761f8adabda3b019c32b714a3696ea87464c255"}
4 changes: 3 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os;

# https://fgo.square.ovh/apk/com.aniplex.fategrandorder.en.apk
url_apk = "https://fgo.square.ovh/apk/com.aniplex.fategrandorder.en.apk"
url_apk = "https://fgo.bigcereal.com/apk/com.aniplex.fategrandorder.en.xapk"

# https://gplay-ver.atlasacademy.workers.dev/?id=com.aniplex.fategrandorder
url_version = "https://gplay-ver.atlasacademy.workers.dev/?id=com.aniplex.fategrandorder.en"

apk_name = url_apk.split("/")[-1]

# Temp folder
temp_folder = os.path.join(os.getcwd(), "temp")
Binary file added libs/java/apkeditor.jar
Binary file not shown.
51 changes: 41 additions & 10 deletions libs/python/decompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,61 @@
import os
import subprocess;
import config
import sys;

from libs.python.logger import logger

# java -jar .\apktool.jar d .\fate.apk --output '.\temp\' -f
def decompile_apk():
apktool = os.path.join(os.getcwd(), "libs", "java", "apktool.jar")
apk = os.path.join(config.temp_folder, "fate.apk")
apkeditor = os.path.join(os.getcwd(), "libs", "java", "apkeditor.jar")
apk = os.path.join(config.temp_folder, config.apk_name)

if config.apk_name.endswith("xapk"):
logger.info("XAPK detected. Merging into APK files.")
result = subprocess.run(["java", "-jar", apkeditor, "m", "-i", apk, "-o", apk.replace("xapk", "apk")],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)

# All data is sterr maybe is a error of apkeditor is reported
for line in result.stderr.splitlines():
if line.strip():
logger.info(line)

apk = apk.replace("xapk", "apk")

logger.info("Decompiling apk...")

#java -jar .\apktool.jar d .\fate.apk --output '.\temp\' -f
print('[App] Decompiling apk...', file=sys.stdout)
subprocess.run(f"java -jar {apktool} d {apk} --output ./temp/files/ -f")
result = subprocess.run(["java", "-jar", apktool, "d", apk, "--output", "./temp/files/", "-f"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)

for line in result.stdout.splitlines():
if line.strip():
logger.info(line)

logger.info("Decompile apk succesfully!")


def decrypt():
il2cpp = os.path.join(os.getcwd(), "libs", "Il2CppDumper", "Il2CppDumper.exe")
global_metadata = os.path.join(config.temp_folder, "files", "assets", "bin", "Data", "Managed", "Metadata", "global-metadata.dat")
decrypt = os.path.join(config.temp_folder, "decrypt");

print("[App] Getting available libraries directories from apk")
logger.info("Getting available libraries directories from apk")
lib_dir_path = os.path.join(config.temp_folder, "files", "lib")
lib_folders = os.listdir(lib_dir_path)

print(f"[App] ArchLibs avalibles {lib_folders}")
print(f"[App] Getting libil2cpp from {lib_folders[0]}")
logger.info(f"ArchLibs avalibles {lib_folders}")
logger.info(f"Getting libil2cpp from {lib_folders[0]}")
lib_dir_name = lib_folders[0]
libil2cpp = os.path.join(config.temp_folder, "files", "lib", lib_dir_name, "libil2cpp.so")

print('[App] Decrypting Files!', file=sys.stdout)
subprocess.run(f"{il2cpp} {libil2cpp} {global_metadata} {decrypt}");
logger.info('Decrypting Files!')
result = subprocess.run(
[il2cpp, libil2cpp, global_metadata, decrypt],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)

for line in result.stdout.splitlines():
if line.strip():
logger.info(line)
29 changes: 15 additions & 14 deletions libs/python/download.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import requests;
import config;
import os;
import sys
import os
import httpx
import config
from libs.python.logger import logger

def download_latest():
print('[App] Creating folder...', file=sys.stdout)
os.mkdir(config.temp_folder);
os.mkdir(os.path.join(config.temp_folder, "decrypt"));
logger.info('Creating folder...')

print('[App] Downloading latest apk...!', file=sys.stdout)
os.mkdir(config.temp_folder)
os.mkdir(os.path.join(config.temp_folder, "decrypt"))

# Create path to save file
apk = os.path.join(config.temp_folder, "fate.apk")
logger.info('Downloading latest apk...!')

with httpx.stream("GET", config.url_apk, follow_redirects=True) as response:
response.raise_for_status()

# Download and Save the file
response = requests.get(config.url_apk)
open(apk, "wb").write(response.content)
with open(os.path.join(config.temp_folder, config.apk_name), "wb") as file:
for chunk in response.iter_bytes():
file.write(chunk)

print('[App] Apk downloaded!', file=sys.stdout)
logger.info('Apk downloaded!')
11 changes: 11 additions & 0 deletions libs/python/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import logging

logging.basicConfig(
filemode="w",
filename="run.log",
format="%(levelname)s | %(module)s | L%(lineno)d | %(asctime)s: %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S%z",
level=logging.INFO
)

logger = logging.getLogger("VerCode (Extractor)")
22 changes: 10 additions & 12 deletions libs/python/update.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import json
import os
import requests
import config
import sys
import httpx

from libs.python.logger import logger

pathRoot = os.getcwd()
pathVerCode = os.path.join(pathRoot, "VerCode.json")

def get_version():
res = requests.get(config.url_version);
return res.content.decode('utf8')
return httpx.get(config.url_version).text

def is_necesary_update(current, latest):
return current != latest

def check_update():
if os.path.exists(pathVerCode):
with open(pathVerCode) as fVerCode:
dataVerCode = json.load(fVerCode)
versionVerCode = dataVerCode["appVer"]
versionAtlas = get_version()

if (versionVerCode != versionAtlas):
print("Need update!", file=sys.stdout)
return True
else:
print('Is not necesary update!', file=sys.stdout)
return False
logger.info(f"Current installed version: {versionVerCode}, up-to-date with the latest available version: {versionAtlas}.")
return is_necesary_update(versionVerCode, versionAtlas)
else:
print('First Time!', file=sys.stdout)

return True
9 changes: 4 additions & 5 deletions libs/python/verCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import os
import re
import config
import sys

from libs.python.update import get_version;
from libs.python.update import get_version
from libs.python.logger import logger

isNotVerCode = [
"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",
Expand All @@ -18,13 +18,12 @@ def write_verCode_data():
stringLiteral = open(os.path.join(config.temp_folder, "decrypt", "stringliteral.json"), encoding="utf8");
json_data = json.load(stringLiteral)

print("[App] Writing verCode...", file=sys.stdout)
logger.info("Writing verCode...")

for data in json_data:
Value = data['value']

if len(Value) == 64:

isHash = len(re.findall("^[a-fA-F0-9]{64}$", Value)) > 0

if isHash and Value.islower() and not Value in isNotVerCode:
Expand All @@ -38,6 +37,6 @@ def write_verCode_data():
dataVerCode["verCode"] = Value;

json.dump(dataVerCode, file)
return print("[App] VerCode exported succefully!", file=sys.stdout)
return logger.info(f"VerCode {Value} exported succefully!")


4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from libs.python.download import download_latest
from libs.python.decompile import decompile_apk, decrypt
from libs.python.verCode import write_verCode_data
from libs.python.logger import logger

import sys

if check_update():
download_latest()
decompile_apk()
decrypt()
write_verCode_data();
else:
print('[App] Workflow Canceled!', file=sys.stdout)
logger.info("No export needed, the latest version is already exported.")
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests==2.27.1
httpx==0.27.0

0 comments on commit 8ad0688

Please sign in to comment.