mirror of
https://github.com/Mas0nShi/typoraCracker.git
synced 2023-07-10 13:41:20 +08:00
fix the temp folder existence errors.
This commit is contained in:
33
typora.py
33
typora.py
@@ -16,6 +16,7 @@ from loguru import logger as log
|
||||
from masar import extract_asar, pack_asar
|
||||
from shutil import rmtree
|
||||
from argparse import ArgumentParser
|
||||
import struct
|
||||
import sys
|
||||
|
||||
# DEBUG
|
||||
@@ -27,17 +28,13 @@ if DEBUG:
|
||||
else:
|
||||
log.add(sys.stderr, level="INFO")
|
||||
|
||||
key = [0x4B029A9482B3E14E, 0xF157FEB4B4522F80, 0xE25692105308F4BE, 0x6DD58DDDA3EC0DC2]
|
||||
aesKey = b""
|
||||
for akey in key:
|
||||
aesKey += int.to_bytes(akey, byteorder="little", length=8)
|
||||
AES_KEY = struct.pack("<4Q", *[0x4B029A9482B3E14E, 0xF157FEB4B4522F80, 0xE25692105308F4BE, 0x6DD58DDDA3EC0DC2])
|
||||
|
||||
|
||||
def _mkdir(_path):
|
||||
try:
|
||||
makedirs(_path)
|
||||
except FileExistsError:
|
||||
log.warning(f"May FolderExists: {_path}")
|
||||
def _newDir(_path):
|
||||
if exists(_path):
|
||||
rmtree(_path)
|
||||
makedirs(_path)
|
||||
|
||||
|
||||
def decScript(b64: bytes, prettify: bool):
|
||||
@@ -47,7 +44,7 @@ def decScript(b64: bytes, prettify: bool):
|
||||
# cipher text
|
||||
cipherText = lCode[16:]
|
||||
# AES 256 CBC
|
||||
ins = AES.new(key=aesKey, iv=aesIv, mode=AES.MODE_CBC)
|
||||
ins = AES.new(key=AES_KEY, iv=aesIv, mode=AES.MODE_CBC)
|
||||
code = unpad(ins.decrypt(cipherText), 16, 'pkcs7')
|
||||
if prettify:
|
||||
code = beautify(code.decode()).encode()
|
||||
@@ -61,8 +58,8 @@ def extractWdec(asarPath, path, prettify):
|
||||
:return: None
|
||||
"""
|
||||
# try to create empty dir to save extract files
|
||||
path = pjoin(path, "temp")
|
||||
_mkdir(path)
|
||||
path = pjoin(path, "typoraCrackerTemp")
|
||||
_newDir(path)
|
||||
log.info(f"extract asar file: {asarPath}")
|
||||
# extract app.asar to {path}/*
|
||||
extract_asar(asarPath, path)
|
||||
@@ -72,7 +69,7 @@ def extractWdec(asarPath, path, prettify):
|
||||
# construct the save directory {pathRoot}/dec_app
|
||||
outPath = pjoin(psplit(path)[0], "dec_app")
|
||||
# try to create empty dir to save decryption files
|
||||
_mkdir(outPath)
|
||||
_newDir(outPath)
|
||||
log.info(f"set Directory: {outPath}")
|
||||
# enumerate extract files
|
||||
fileArr = listdir(path)
|
||||
@@ -99,7 +96,7 @@ def encScript(_code: bytes, compress):
|
||||
_code = jsmin(_code.decode(), quote_chars="'\"`").encode()
|
||||
aesIv = urandom(16)
|
||||
cipherText = _code
|
||||
ins = AES.new(key=aesKey, iv=aesIv, mode=AES.MODE_CBC)
|
||||
ins = AES.new(key=AES_KEY, iv=aesIv, mode=AES.MODE_CBC)
|
||||
enc = aesIv + ins.encrypt(pad(cipherText, 16, 'pkcs7'))
|
||||
lCode = b64encode(enc)
|
||||
return lCode
|
||||
@@ -115,11 +112,11 @@ def packWenc(path, outPath, compress):
|
||||
if isfile(outPath):
|
||||
log.error("plz input Directory for app.asar")
|
||||
raise NotADirectoryError
|
||||
if not exists(outPath):
|
||||
_mkdir(outPath)
|
||||
|
||||
encFilePath = pjoin(psplit(outPath)[0], "temp")
|
||||
_mkdir(encFilePath)
|
||||
_newDir(outPath)
|
||||
|
||||
encFilePath = pjoin(psplit(outPath)[0], "typoraCrackerTemp")
|
||||
_newDir(encFilePath)
|
||||
|
||||
outFilePath = pjoin(outPath, "app.asar")
|
||||
log.info(f"set outFilePath: {outFilePath}")
|
||||
|
||||
Reference in New Issue
Block a user