dev commits.

This commit is contained in:
MasOnShi
2022-04-03 19:50:15 +08:00
parent df83d9cae4
commit 2a7fd5622a
3 changed files with 108 additions and 2 deletions

View File

@@ -0,0 +1,11 @@
from utils import get_version, download_file
import os
if __name__ == '__main__':
DOWNLOAD_URL = "https://typora.io/windows/typora-setup-x64.exe"
BASE_DIR = os.path.join(os.path.dirname(__file__), "win/x64")
download_path = os.path.join(BASE_DIR, os.path.basename(DOWNLOAD_URL))
download_file(DOWNLOAD_URL, download_path)
version = get_version(download_path)

86
auto-analysis/utils.py Normal file
View File

@@ -0,0 +1,86 @@
# -*- coding:utf-8 -*-
"""
@Author: Mas0n
@File: utils.py
@Time: 2022/4/3 18:36
@Desc: It's all about getting better.
"""
from loguru import logger as log
import subprocess
import json
import os
# Usage:
# innoextract
#
BASE_DIR = os.path.dirname(__file__)
DOWNLOAD_LINK = {
"win": {
"x86": "https://typora.io/windows/typora-setup-ia32.exe",
"x64": "https://typora.io/windows/typora-setup-x64.exe",
"arm": "https://typora.io/windows/typora-setup-arm64.exe",
},
"linux": {
"x64": "https://download.typora.io/linux/Typora-linux-x64.tar.gz",
"arm": "https://download.typora.io/linux/Typora-linux-arm64.tar.gz",
},
}
def get_version(to_path):
package_file_path = os.path.join(to_path, "app/resources/package.json")
package_info = open(package_file_path, "r").read()
package_obj = json.loads(package_info)
return package_obj["version"]
def download_file(from_link, to_path):
log.info(f"downloading from {from_link}")
subprocess.check_call(["wget", from_link, "-O", to_path])
log.info("ready extract package")
def patch_file(_key, _iv):
patch_file_path = os.path.join(BASE_DIR, "../typora.py")
fd = open(patch_file_path, "a")
content = fd.read()
content = content.replace("{AES_KEY}", f"b''.fromhex('{_key}')")
content = content.replace("{AES_IV}", f"b''.fromhex('{_iv}')")
fd.write(content)
def win_x64_run():
from win.x64 import analysis
basedir = os.path.join(BASE_DIR, "win/x64")
link = DOWNLOAD_LINK["win"]["x64"]
download_path = os.path.join(basedir, os.path.basename(link))
download_file(link, download_path)
subprocess.check_call(["innoextract", download_path])
log.info("preparation stage completed")
main_node_path = os.path.join(basedir, "app/resources/app.asar.unpacked/main.node")
log.info("auto analysis start")
key, iv = analysis.get_aes_key_and_iv(main_node_path)
log.success("analysis done")
patch_file(key.hex(), iv.hex())
log.success("patch done")
if __name__ == '__main__':
win_x64_run()
# hashString = open("LATEST_VERSION", "r").read()
# if hashString == "":
# log.info("not history for typora version")
# exit()
# basedir = os.path.dirname(__file__)
# for h1 in DOWNLOAD_LINK.keys():
# h1dir = os.path.join(basedir, h1)
# for h2 in DOWNLOAD_LINK.get(h1).keys():
# h2dir = os.path.join(h1dir, h2)
# print(h2dir)

View File

@@ -7,6 +7,7 @@
"""
from loguru import logger as log
import subprocess
import json
import os
# Usage:
@@ -26,12 +27,17 @@ DOWNLOAD_LINK = {
},
}
def get_version(to_path):
package_file_path = os.path.join(to_path, "app/resources/package.json")
package_info = open(package_file_path, "r").read()
package_obj = json.loads(package_info)
return package_obj["version"]
def download_file(from_link, to_path):
log.info(f"downloading from {from_link}")
subprocess.check_call(["wget", from_link, "-O", to_path])
log.info("ready extract package")
subprocess.check_call(["md5sum", "-b", to_path, ">", "LATEST_VERSION"])
@@ -48,15 +54,18 @@ def win_x64_run():
from win.x64 import analysis
basedir = os.path.join(BASE_DIR, "win/x64")
link = DOWNLOAD_LINK["win"]["x64"]
download_path = os.path.join(basedir, os.path.basename(link))
download_path = os.path.join(basedir, os.path.basename(link))
download_file(link, download_path)
subprocess.check_call(["innoextract", download_path])
log.info("preparation stage completed")
main_node_path = os.path.join(basedir, "app/resources/app.asar.unpacked/main.node")
log.info("auto analysis start")
key, iv = analysis.get_aes_key_and_iv(main_node_path)
log.success("analysis done")
patch_file(key.hex(), iv.hex())
log.success("patch done")