mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-24 21:33:16 +08:00
Merge branch 'package_same' into fuck_taobao
This commit is contained in:
commit
b88a240f07
1
autojs-tool-encrypt/.gitignore
vendored
Normal file
1
autojs-tool-encrypt/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
||||
49
autojs-tool-encrypt/build.gradle
Normal file
49
autojs-tool-encrypt/build.gradle
Normal file
@ -0,0 +1,49 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
task makeEncryptJar(type: Copy) {
|
||||
dependsOn build
|
||||
// 删除存在的
|
||||
delete 'build/libs/encrypt-sdk.jar'
|
||||
// 设置拷贝的文件
|
||||
from('build/intermediates/packaged-classes/release/')
|
||||
// 打进jar包后的文件目录
|
||||
into('build/libs/')
|
||||
// 将classes.jar放入build/libs/目录下
|
||||
// include ,exclude参数来设置过滤
|
||||
//(我们只关心classes.jar这个文件)
|
||||
include('classes.jar')
|
||||
// 重命名
|
||||
rename ('classes.jar', 'encrypt-sdk.jar')
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
api project(path: ':autojs')
|
||||
}
|
||||
2
autojs-tool-encrypt/src/main/AndroidManifest.xml
Normal file
2
autojs-tool-encrypt/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,2 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.tony.autojs.tool.encrypt" />
|
||||
@ -0,0 +1,66 @@
|
||||
package com.tony.autojs.tool.encrypt;
|
||||
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
public class AESEncrypt {
|
||||
public static SecretKey loadKeyByBytes(byte[] keyBytes) {
|
||||
return new SecretKeySpec(keyBytes, 0, keyBytes.length, "AES");
|
||||
}
|
||||
|
||||
public static byte[] generateAesKey() throws NoSuchAlgorithmException {
|
||||
KeyGenerator generator = KeyGenerator.getInstance("AES");
|
||||
// The AES key size in number of bits
|
||||
generator.init(128);
|
||||
SecretKey secKey = generator.generateKey();
|
||||
return secKey.getEncoded();
|
||||
}
|
||||
|
||||
public static byte[] encrypt(byte[] content, SecretKey key) {
|
||||
Cipher aesCipher = null;
|
||||
try {
|
||||
aesCipher = Cipher.getInstance("AES");
|
||||
aesCipher.init(Cipher.ENCRYPT_MODE, key);
|
||||
return aesCipher.doFinal(content);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
System.err.println("非可用算法");
|
||||
} catch (NoSuchPaddingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (BadPaddingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalBlockSizeException e) {
|
||||
System.err.println("明文长度不正确");
|
||||
} catch (InvalidKeyException e) {
|
||||
System.err.println("秘钥已损坏");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static byte[] decrypt(byte[] content, SecretKey key) {
|
||||
Cipher aesCipher = null;
|
||||
try {
|
||||
aesCipher = Cipher.getInstance("AES");
|
||||
aesCipher.init(Cipher.DECRYPT_MODE, key);
|
||||
return aesCipher.doFinal(content);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
System.err.println("非可用算法");
|
||||
} catch (NoSuchPaddingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (BadPaddingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalBlockSizeException e) {
|
||||
System.err.println("密文长度不正确");
|
||||
} catch (InvalidKeyException e) {
|
||||
System.err.println("秘钥已损坏");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
package com.tony.autojs.tool.encrypt;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
import com.stardust.autojs.execution.ExecutionConfig;
|
||||
import com.stardust.autojs.runtime.api.Engines;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
public class DecryptRunner {
|
||||
|
||||
private EnginesDelegate engines;
|
||||
private Context context;
|
||||
private Activity activity;
|
||||
private boolean isPro;
|
||||
private SecretKey secretKey;
|
||||
|
||||
/**
|
||||
* @param engines
|
||||
* @param context
|
||||
* @param activity
|
||||
*/
|
||||
public DecryptRunner(Engines engines, Context context, Activity activity) {
|
||||
this.engines = new EnginesDelegate(engines);
|
||||
this.context = context;
|
||||
this.activity = activity;
|
||||
this.isPro = this.context.getPackageName().equals("org.autojs.autojspro");
|
||||
}
|
||||
|
||||
public void executeDecryptScriptString(String script, String workingDir) {
|
||||
ExecutionConfig config = new ExecutionConfig();
|
||||
config.setWorkingDirectory(workingDir);
|
||||
if (!this.isPro) {
|
||||
engines.execScript("tmp", script, config);
|
||||
} else {
|
||||
engines.execScript(activity, "tmp", script, config);
|
||||
}
|
||||
}
|
||||
|
||||
public void decryptAndRun(String filePath, String workingDir) {
|
||||
executeDecryptScriptString(decryptData(filePath), workingDir);
|
||||
}
|
||||
|
||||
public void encryptScript(String originFilePath, String destFilePath) {
|
||||
File originFile = new File(originFilePath);
|
||||
if (originFile.exists()) {
|
||||
try (
|
||||
FileInputStream fileInputStream = new FileInputStream(originFile);
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(destFilePath);
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
) {
|
||||
byte[] buffer = new byte[8192];
|
||||
int len = 0;
|
||||
while ((len = fileInputStream.read(buffer)) > 0) {
|
||||
byteArrayOutputStream.write(buffer, 0, len);
|
||||
}
|
||||
byte[] bytes = AESEncrypt.encrypt(byteArrayOutputStream.toByteArray(), secretKey);
|
||||
if (bytes != null) {
|
||||
fileOutputStream.write(bytes);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String decryptData(String filePath) {
|
||||
try (
|
||||
FileInputStream fileInputStream = new FileInputStream(filePath);
|
||||
BufferedInputStream reader = new BufferedInputStream(fileInputStream);
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
) {
|
||||
byte[] buffer = new byte[8192];
|
||||
int length = -1;
|
||||
while ((length = reader.read(buffer)) > 0) {
|
||||
byteArrayOutputStream.write(buffer, 0, length);
|
||||
}
|
||||
byte[] bytes = AESEncrypt.decrypt(byteArrayOutputStream.toByteArray(), secretKey);
|
||||
if (bytes != null) {
|
||||
return new String(bytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public SecretKey getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
public void setSecretKey(SecretKey secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package com.tony.autojs.tool.encrypt;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.stardust.autojs.execution.ExecutionConfig;
|
||||
import com.stardust.autojs.execution.ScriptExecution;
|
||||
import com.stardust.autojs.runtime.api.Engines;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class EnginesDelegate {
|
||||
private Engines originEngine;
|
||||
|
||||
public EnginesDelegate(Engines originEngine) {
|
||||
this.originEngine = originEngine;
|
||||
}
|
||||
|
||||
public ScriptExecution execScript(String name, String script, ExecutionConfig config) {
|
||||
return originEngine.execScript(name, script, config);
|
||||
}
|
||||
|
||||
public void execScript(Activity activity, String name, String script, ExecutionConfig config) {
|
||||
try {
|
||||
Method execScriptMethod = originEngine.getClass().getMethod("execScript", Activity.class, String.class, String.class, ExecutionConfig.class);
|
||||
execScriptMethod.invoke(originEngine, activity, name, script, config);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -424,6 +424,7 @@ public class ScriptRuntime {
|
||||
});
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
ignoresException(images::releaseScreenCapturer);
|
||||
ignoresException(images::recycle);
|
||||
}
|
||||
ignoresException(sensors::unregisterAll);
|
||||
ignoresException(timers::recycle);
|
||||
|
||||
@ -267,7 +267,6 @@ public class Images {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && mScreenCapturer != null) {
|
||||
mScreenCapturer.release();
|
||||
}
|
||||
mScriptRuntime = null;
|
||||
}
|
||||
|
||||
public Point findImage(ImageWrapper image, ImageWrapper template) {
|
||||
@ -366,4 +365,8 @@ public class Images {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void recycle() {
|
||||
mScriptRuntime = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
include ':app', ':automator', ':common', ':autojs', ':inrt', ':autojs-tool-color-center'
|
||||
include ':autojs-tool-download'
|
||||
include ':autojs-tool-webview'
|
||||
include ':autojs-tool-encrypt'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user