2020-01-10 15:09:55 +08:00
|
|
|
const exec = require('child_process');
|
2022-08-24 21:12:13 +08:00
|
|
|
const path = require('path')
|
|
|
|
const fs = require('fs')
|
|
|
|
const { POINT_CONVERSION_HYBRID } = require('constants');
|
2020-01-10 15:09:55 +08:00
|
|
|
const iconv = require('iconv-lite')
|
|
|
|
var encoding = 'GBK';
|
|
|
|
var binaryEncoding = 'binary';
|
2022-08-24 21:12:13 +08:00
|
|
|
window.exec_ = function (ext, fun) {
|
|
|
|
|
|
|
|
exec.exec(ext, { encoding: 'binary' }, (err, stdout, stderr) => {
|
|
|
|
if (stderr != '') {
|
|
|
|
fun(iconv.decode(new Buffer(stderr, binaryEncoding), encoding), true)
|
|
|
|
} else if (stdout != '') {
|
|
|
|
fun(iconv.decode(new Buffer(stdout, binaryEncoding), encoding), false)
|
|
|
|
} else if (err != '') {
|
|
|
|
try {
|
|
|
|
fun(iconv.decode(new Buffer(err, binaryEncoding), encoding), true)
|
|
|
|
} catch (error) {
|
|
|
|
fun(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2020-01-10 15:09:55 +08:00
|
|
|
fun("异常错误")
|
|
|
|
}
|
2022-08-24 21:12:13 +08:00
|
|
|
|
2020-01-10 15:09:55 +08:00
|
|
|
})
|
|
|
|
}
|
2022-08-24 21:12:13 +08:00
|
|
|
window.adb = function (ext, fun) {
|
|
|
|
let adb = getAdb()
|
|
|
|
let _exec = ext.replace('adb', adb)
|
|
|
|
//ext="dir"
|
|
|
|
console.log(_exec)
|
|
|
|
exec.exec(_exec, { encoding: 'binary' }, (err, stdout, stderr) => {
|
|
|
|
if (stderr != '') {
|
|
|
|
fun(iconv.decode(new Buffer(stderr, binaryEncoding), encoding), true)
|
|
|
|
} else if (stdout != '') {
|
|
|
|
fun(iconv.decode(new Buffer(stdout, binaryEncoding), encoding), false)
|
|
|
|
} else if (err != '') {
|
|
|
|
fun(iconv.decode(new Buffer(err, binaryEncoding), encoding), true)
|
|
|
|
} else {
|
|
|
|
fun("异常错误")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
window.unapk = function (file, fun) {
|
|
|
|
let apktool = getApkTools();
|
|
|
|
let _exec = getJavaRuntimer()+"java -jar \"" + apktool + "\" d -f \"" + file + "\" --only-main-classes -out=\"" + getFilePath(file) + path.sep + getFileNotExtName(file) + "\""
|
|
|
|
exec_(_exec, fun)
|
|
|
|
}
|
|
|
|
window.apkinfo = function (file, fun) {
|
|
|
|
let aapt = getAapt()
|
|
|
|
let _exec = aapt + " dump badging " + file
|
|
|
|
exec_(_exec, fun)
|
|
|
|
}
|
|
|
|
window.packapk = function (dir, fun) {
|
|
|
|
let apktool = getApkTools();
|
|
|
|
let _exec = getJavaRuntimer()+"java -jar " + apktool + " -r b -f " + dir + " -o " + dir + path.sep + "game.apk"
|
|
|
|
exec_(_exec, fun)
|
|
|
|
}
|
|
|
|
window.signapk = function (file, fun) {
|
|
|
|
let sign = getSign()
|
|
|
|
let _exec =getJavaRuntimer()+ sign + " -verbose -keystore " + utools.db.get('sign').data + ' -keypass ' + utools.db.get('password').data
|
|
|
|
+ ' -storepass ' + utools.db.get('aliasPassword').data + ' -signedjar \"' + file + '_sign.apk\" \"'
|
|
|
|
+ file + '\" ' + utools.db.get('alias').data
|
|
|
|
console.log(_exec)
|
|
|
|
exec_(_exec, fun)
|
|
|
|
}
|
|
|
|
window.readSignDialog = function (fun) {
|
|
|
|
console.log('read file')
|
|
|
|
let data = fs.readFileSync('sign_dialog.txt');
|
|
|
|
console.log(data)
|
|
|
|
fun(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getApkTools() {
|
|
|
|
return utools.getPath('documents') + path.sep + 'utools_adb_libs' + path.sep + 'apktool.jar'
|
|
|
|
}
|
|
|
|
function getAdb() {
|
|
|
|
return utools.getPath('documents') + path.sep + 'utools_adb_libs' + path.sep + 'adb.exe';
|
|
|
|
}
|
|
|
|
function getAapt() {
|
|
|
|
return utools.getPath('documents') + path.sep + 'utools_adb_libs' + path.sep + 'aapt.exe';
|
|
|
|
}
|
|
|
|
function getSign() {
|
|
|
|
return 'jarsigner.exe';
|
|
|
|
}
|
|
|
|
function getSignTools() {
|
|
|
|
return utools.getPath('documents') + path.sep + 'utools_adb_libs' + path.sep + 'sign'+path.sep+'bin';
|
|
|
|
}
|
|
|
|
function getJavaRuntimer(){
|
|
|
|
return "path="+getSignTools()+"&"
|
|
|
|
}
|
|
|
|
function getFilePath(file) {
|
|
|
|
return path.dirname(file)
|
|
|
|
}
|
|
|
|
function getFileNotExtName(file) {
|
|
|
|
return path.basename(file, path.extname(file))
|
|
|
|
}
|