[JavaScript] 纯文本查看 复制代码
//调用方法
/*init("http://127.0.0.1", 1, "bYyCDWr0nxaBfFp7LAXjlzSKIP2REohZgG69cqtUu8TvwJHQimkM", "Ia9Ho5SKpmT3jY2vAVN4duX10DbMexytslcrUE6kOJC8gWBPqLh7");
sleep(1000);
KMlogin("ZKTW7XsG8tzsUazDV2");
sleep(1000);
XT("ZKTW7XsG8tzsUazDV2");
sleep(1000);
logoutk("ZKTW7XsG8tzsUazDV2");*/
//只写了卡密部分 //本人不懂PHP JavaScript //全是照着文档一点一点翻译的 //写的烂不要喷 谢谢
var WEB; //全局API
var WEB1; //心跳包 用
var TOKEN; //用户TOKEN
var SOFTID; //软件ID
var SOFTKEY; //软件秘钥
var PWD; //软件加密密码
function POST_v4(url, data) {
if (TOKEN != "") {
var header = {"token": TOKEN};
} else {
header = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36"}
}
let params = {
"url": WEB + url,
"timeout": 5000,
"method": "POST",
"userAgent": null,
"referrer": "baidu.com",
"cookie": null,
"data": data,
"file": null,
"header": header
};
let ret = http.request(params);
return ret.body;
}
//梦亚验证初始化
function init(webUrl, id, Key, Pwd) {
WEB = webUrl + "/apiv4/v4/"; //全局API
SOFTID = id; //全局ID
SOFTKEY = Key; //全局秘钥
PWD = Pwd; //全局加密密钥
WEB1 = webUrl; //心跳包 用
let url = "apply";
let secretKey = DynamicEncryption(SOFTKEY);
// logd(secretKey);
let data = {
"id": SOFTID,
"secretKey": secretKey
}
let ret = POST_v4(url, data);
let tmp = JSON.parse(ret);
logd("初始化: " + tmp.msg);
}
//卡密登录
function KMlogin(camilo) {
machine = DynamicEncryption(getDeviceId());//机器码
let secretKey = DynamicEncryption(SOFTKEY);
let kami = camilo + "MYKCKM";
let url = "kmlogin"
let data = {
"id": SOFTID,
"secretKey": secretKey,
"camilo": kami,//卡密
"machine": machine//机器码
}
let ret = POST_v4(url, data);
if (ret) {
let tmp = JSON.parse(ret);
TOKEN = tmp.data.token;
//logd("token: " + TOKEN);
logd("卡密登录: " + tmp.msg);
} else {
logd("卡密登录 无结果");
}
}
//卡密强制注销
function logoutk(camilo) {
machine = DynamicEncryption(getDeviceId());//机器码
let secretKey = DynamicEncryption(SOFTKEY);
let kami = camilo + "MYKCKM";
let url = "logoutk"
let data = {
"id": SOFTID,
"secretKey": secretKey,
"camilo": kami,
"machine": machine
}
let ret = POST_v4(url, data);
let tmp = JSON.parse(ret);
logd("卡密强制注销: " + tmp.msg);
}
// 心跳
function XT(camilo) {
let url = WEB + "xintiao";
machine = DynamicEncryption(getDeviceId());//机器码
let secretKey = DynamicEncryption(SOFTKEY);
let data = {
"id": SOFTID,
"secretKey": secretKey,
"api":DynamicEncryption(WEB1),
"machine": machine,
"username": "wohenni",
"camilo": camilo + "MYKCKM"
}
let ret = http.postJSON(url, data, 1000, {
"token": TOKEN
})
let tmp = JSON.parse(ret);
logd("心跳: " + tmp.msg);
}
//文本数据动态加密,每次加密结果不一致,但解密数据相同
function DynamicEncryption(data) {
if (typeof (data) == "string") {
data = stringToByte(data);
}
if (data.length % 2 == 1) {
data.push([0]);
}
data = _DataDisruption(data);
let datalen = data.length;
let code = _DataDisruption(stringToByte("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"));
let codelen = code.length;
let pas = _DataDisruption(stringToByte(PWD));
let paslen = pas.length;
let j = 0, k = 0;
let ret = new Array();
for (let i = 1; i <= datalen; i++) {
j = j + 1
if (j > codelen) {
j = 1;
}
k = k + 1
if (k > paslen) {
k = 1;
}
let r = Math.floor((Math.random() * 10) + 1); //1 - 10之间的随机数
let Bus = Math.floor(r / codelen + 1);
let yu = r % codelen + 1;
ret = ret.concat(code.slice(Math.floor(Bus) - 1, Math.floor(Bus)), code.slice(Math.floor(yu) - 1, Math.floor(yu)));
let tembit = data[i - 1] ^ code[j - 1] ^ pas[k - 1] ^ r;
Bus = tembit / codelen + 1;
yu = tembit % codelen + 1;
ret = ret.concat(code.slice(Math.floor(Bus) - 1, Math.floor(Bus)), code.slice(Math.floor(yu) - 1, Math.floor(yu)));
}
// logd(ret);
return (arrToHex(ret));
}
//文本数据动态解密
function DynamicDecryption(data) {
if (typeof (data) == "string") {
data = stringToByte(data);
}
let datalen = data.length;
let code = (_DataDisruption(stringToByte("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")));
let codelen = code.length;
let pas = _DataDisruption(stringToByte(PWD));
let paslen = pas.length;
let j = 0, k = 0;
let ret = new Array();
for (let i = 1; i <= (datalen / 4); i++) {
j = j + 1;
if (j > codelen) {
j = 1;
}
k = k + 1;
if (k > paslen) {
k = 1;
}
let Bus = (data.slice(Math.floor((i - 1) * 4 + 1) - 1, Math.floor((i - 1) * 4 + 1)));
Bus = code.indexOf(Number(Bus));
let yu = (data.slice(Math.floor((i - 1) * 4 + 2) - 1, Math.floor((i - 1) * 4 + 2)));
yu = code.indexOf(Number(yu));
let r = Bus * codelen + yu;
Bus = (data.slice(Math.floor((i - 1) * 4 + 3) - 1, Math.floor((i - 1) * 4 + 3)));
Bus = code.indexOf(Number(Bus));
yu = (data.slice(Math.floor((i - 1) * 4 + 4) - 1, Math.floor((i - 1) * 4 + 4)));
yu = code.indexOf(Number(yu));
let tembit = Bus * codelen + yu;
tembit = tembit ^ code[j - 1] ^ pas[k - 1] ^ r;
ret.push(tembit);
}
// logd(_DataDisruption(ret));
return (arrToStr(_DataDisruption(ret)));
}
//数据打乱
function _DataDisruption(data) {
let arr1 = new Array();
let arr2 = new Array();
arr1 = data.slice(0, Math.floor(data.length / 2));
arr2 = data.slice(Math.ceil(data.length / 2), data.length);
arr1 = arr1.reverse();
arr2 = arr2.reverse();
return arr1.concat(arr2);
}
//数据倒序
function _DataReverse(data) {
return data.reverse();
}
//字符串转字节
function stringToByte(str) {
var len, c;
len = str.length;
var bytes = [];
for (var i = 0; i < len; i++) {
c = str.charCodeAt(i);
if (c >= 0x010000 && c <= 0x10FFFF) {
bytes.push(((c >> 18) & 0x07) | 0xF0);
bytes.push(((c >> 12) & 0x3F) | 0x80);
bytes.push(((c >> 6) & 0x3F) | 0x80);
bytes.push((c & 0x3F) | 0x80);
} else if (c >= 0x000800 && c <= 0x00FFFF) {
bytes.push(((c >> 12) & 0x0F) | 0xE0);
bytes.push(((c >> 6) & 0x3F) | 0x80);
bytes.push((c & 0x3F) | 0x80);
} else if (c >= 0x000080 && c <= 0x0007FF) {
bytes.push(((c >> 6) & 0x1F) | 0xC0);
bytes.push((c & 0x3F) | 0x80);
} else {
bytes.push(c & 0xFF);
}
}
return (bytes);
}
//字节转字符串
function byteToString(arr) {
if (typeof arr === 'string') {
return arr;
}
let str = '',
_arr = arr;
for (let i = 0; i < _arr.length; i++) {
let one = _arr.toString(2),
v = one.match(/^1+?(?=0)/);
if (v && one.length == 8) {
let bytesLength = v[0].length;
let store = _arr.toString(2).slice(7 - bytesLength);
for (let st = 1; st < bytesLength; st++) {
store += _arr[st + i].toString(2).slice(2);
}
str += String.fromCharCode(parseInt(store, 2));
i += bytesLength - 1;
} else {
str += String.fromCharCode(_arr);
}
}
return str;
}
//数组转换为十六进制
function arrToHex(arr) {
let hex = "";
for (let i = 0; i < arr.length; i++) {
hex = hex + String.fromCharCode(arr);
}
return hex;
}
//数组转字符串
function arrToStr(arr) {
let str = "";
for (let i = 0; i < arr.length; i++) {
str = str + String.fromCharCode(arr);
}
return (str);
}
//获取机器码
function getDeviceId() {
return device.getIMEI();
}