GitHub
家(203118908) 大佬開源的地址
https://github.com/snailuncle/batchJs2Dex
1. JS混淆
JS 混淆 網址 :
http://jshaman.com/protect.html
混淆 配置
-
混淆之前 將 UI 剪切 出來
-
勾選 下圖的 變量和函數名 混淆
-
混淆成功後 將 JS 代碼 粘貼到 VSCode 中 並將 UI代碼 粘貼到 對應的 位置
-
手動批量 將 {{ 綁定值 }} 格式的 UI 綁定 .修改爲 混淆後的變量名
-
使用 VSCode運行 … 確定 無誤後 將 JS 代碼 放入 aaa.js
2. JS轉class
中文 亂碼問題 解決方案:
將JS文件編碼格式改爲 GB2312
然後再 執行 轉class 的命令
自己新建一個 bat 文件, 雙擊 運行
aaa.js 文件 地址 改爲你自己電腦上的路徑
@echo off
Setlocal enabledelayedexpansion
echo org.mozilla.javascript.tools.jsc.Main.main(["E:/Work/GitHub/batchJs2Dex/other/aaa.js"]) | java -jar rhino1772.jar
pause && exit
3. class 轉 dex
使用之前,請確保 自己的 android dx 配置了 環境變量
自己新建一個 bat 文件, 雙擊 運行
start cmd /k "dx --dex --output =aaa.dex aaa.class"
4. 最終目錄結構圖
Dex 熱更新 例子
DexVersion 內容 格式:
代碼
"ui";
var DexName = "aaa.dex";
var DexVersionName = "DexVersion.txt";
//本地文件
var LocalDirPath = "/sdcard/代碼俠輔助/";
var LocalDexPath = LocalDirPath + DexName;
var LocalVersionFilePath = LocalDirPath + DexVersionName;
//網絡文件
var RemoteHost = "自己的網絡地址";
var RemoteDexFilePath = RemoteHost + DexName;
var RemoteVersionFilePath = RemoteHost + DexVersionName;
/**
* 開始運行
*/
function Run() {
try {
var checkState = false;
//檢查更新 join 等待多線程結束
threads
.start(function () {
checkState = CheckVersion();
})
.join();
if (checkState) {
//加載dex並運行, 只能在主線程運行 loadDex,否則Dex裏面的全局變量報錯
runtime.loadDex(LocalDexPath);
new Packages["aaa"]()();
}
} catch (error) {
toast("檢查更新狀態失敗\n請查看日誌");
console.warn("Run Error: " + error);
}
}
/**
* 檢查版本
*/
function CheckVersion() {
var res = true;
try {
if (!files.exists(LocalVersionFilePath)) {
console.log("創建版本文件");
files.createWithDirs(LocalVersionFilePath);
/** 默認值 */
files.write(LocalVersionFilePath, "0.0.0");
}
//本地版本號
var localVersion = files.read(LocalVersionFilePath);
//遠程版本號
var remoteVersion = http.get(RemoteVersionFilePath).body.string();
if (localVersion != remoteVersion || !files.exists(LocalDexPath)) {
console.warn("本地版本: " + localVersion);
console.warn("遠程版本: " + remoteVersion);
//下載Dex
if (DownloadDex()) {
//更新版本號
files.write(LocalVersionFilePath, remoteVersion);
} else {
//res = false;
}
} else {
toast("最新版,無需更新");
}
} catch (error) {
console.warn("CheckVersion Error: " + error);
toast("檢查版本發生異常\n請查看日誌");
OpenLog();
}
return res;
}
/**
* 下載Dex
*/
function DownloadDex() {
var result = false;
try {
console.warn("dex開始更新");
var res = http.get(RemoteDexFilePath);
if (Http200(res)) {
//寫入Dex文件
files.writeBytes(LocalDexPath, res.body.bytes());
if (files.exists(LocalDexPath)) {
console.warn("dex更新成功");
toast("更新成功");
res = true;
}
} else {
console.warn("DownloadDex 下載失敗: " + res);
OpenLog();
threads.shutDownAll();
sleep(99999);
}
} catch (error) {
console.warn("DownloadDex Error: " + error);
toast("下載新的dex 異常.\n具體請查看日誌");
OpenLog();
}
return result;
}
/**
* 判斷是否 不是 空
* @param {any}} content 內容
*/
function IsNotNullOrEmpty(content) {
return content != null && content != undefined && Trim(content).length > 0;
}
/**
* http200驗證
* @param {object} content http返回的json
*/
function Http200(content) {
return (
IsNotNullOrEmpty(content) &&
(content.statusCode == 200 || content.statusCode == "200")
);
}
/**
* 去除左右空格
* @param {string} content
*/
function Trim(content) {
return (content + "").replace(/(^\s*)|(\s*$)/g, "");
}
function OpenLog() {
//ui.run(function () {
// app.startActivity("console");
//});
}
Run();