一鍵加密檔案夾中的所有JS檔案,JS檔案批量加密。
1、啟動JShaman本地部署專業版;
2、啟動批量加密腳本,後付源碼。
操作視訊:
視訊加載中...
/*
JShaman本地部署專業版 批量加密工具
-=[ JShaman是專業的JavaScript源代碼混淆加密産品 ]=-
注意:本程式會調用JShaman接口,配置選項,請以最新版接口為準
功能:調用JShaman本地部署專業版,對指定目錄中的JS檔案一次性全部加密
本工具在NodeJS環境中運作,如使用時提示缺少依賴,請根據提示使用“npm install 依賴名”進行安裝
使用方法:
1、在代碼中正确設定config、folder、jshaman_url三個變量
config:混淆加密配置選項,各功能1為啟用、0為不啟用,各項含義參考産品介紹
folder:目标檔案夾,可含有任意檔案,但僅會處理JS檔案
jshaman_url:JShaman專業版伺服器位址及功能路徑
2、在NodeJS指令行中執行:node jf
3、等待混淆加密完成
*/
/* 配置資訊,可修改 */
var config = {
"part_variable_identifier_obfuscate": 1,
"global_variable_identifier_obfuscate": 0,
"part_function_identifier_obfuscate":0,
"global_function_identifier_obfuscate": 0,
"member_expression_encode": 1,
"numberic_literal_encode": 1,
"binary_express_obfuscate": 1,
"boolean_encode": 1,
"json_encode":1,
"string_unicode_encode": 1,
"assignment_junk_code":1,
"zombie_code": 1,
"eval_encode": 1,
"control_flow": 1,
"comma_operator": 1,
"string_array": 1,
"string_array_encode": 1,
"vm_execute": 1,
"ast_execute": 1,
"no_beautifier": 1,
"tamper_proof": 1,
"comments": 0,
"compress": 1,
"reserved_word": ["jshaman","wlw"]
}
var folder = "C:\\Users\\WangLiwen\\Desktop\\mutl\\js";
var jshaman_url = "http://127.0.0.1:2080/obfuscate/";
/* 主功能,勿修改 */
var fs = require("fs");
var path = require("path");
var request = require('sync-request');
(function jf(folder, config, jshaman_url){
//同步讀取路徑
var files = fs.readdirSync(folder);
//周遊指定目錄下各檔案或目錄
for(var i=0; i<files.length; i++){
//檔案
var file = folder + "\\" + files[i];
//同步擷取檔案資訊
var file_info = fs.statSync(file)
//如果是目錄
if(file_info.isDirectory()){
//嵌套調用,繼續周遊
jf(file, config, jshaman_url);
}else{
//擷取檔案字尾
var ext = path.extname(folder + file).toLowerCase();
//隻處理JS檔案
if(ext == ".js"){
console.log("正在混淆加密檔案:" + file);
//同步讀取JS檔案
var js_code = fs.readFileSync(file, "utf-8");
//同步請求,向JShaman送出JS代碼,并擷取傳回資料
var res = request("POST", jshaman_url, {json:{
"js_code":js_code,
"vip_code":"demo",
"config":config
}})
var json_res = JSON.parse(res.getBody('utf8'));
//同步寫檔案,把加密後的代碼寫入原檔案
if(json_res.state == 0){
fs.writeFileSync(file, json_res.content);
console.log("已混淆加密:", file);
}else{
console.log("混淆加密出現異常", file, json_res);
}
}
}
}
})(folder,config,jshaman_url);