feat:全局设置增加延迟注入秒数
This commit is contained in:
@@ -253,6 +253,15 @@ public class ConfigManager {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getInjectionDelay() {
|
||||||
|
return config.injectionDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInjectionDelay(int delay) {
|
||||||
|
config.injectionDelay = delay;
|
||||||
|
saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
// Copy SO files directly to app's data directory
|
// Copy SO files directly to app's data directory
|
||||||
private void deploySoFilesToApp(String packageName) {
|
private void deploySoFilesToApp(String packageName) {
|
||||||
AppConfig appConfig = config.perAppConfig.get(packageName);
|
AppConfig appConfig = config.perAppConfig.get(packageName);
|
||||||
@@ -402,6 +411,7 @@ public class ConfigManager {
|
|||||||
public static class ModuleConfig {
|
public static class ModuleConfig {
|
||||||
public boolean enabled = true;
|
public boolean enabled = true;
|
||||||
public boolean hideInjection = false;
|
public boolean hideInjection = false;
|
||||||
|
public int injectionDelay = 2; // Default 2 seconds
|
||||||
public List<SoFile> globalSoFiles = new ArrayList<>();
|
public List<SoFile> globalSoFiles = new ArrayList<>();
|
||||||
public Map<String, AppConfig> perAppConfig = new HashMap<>();
|
public Map<String, AppConfig> perAppConfig = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.text.Editable;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -24,6 +27,8 @@ public class SettingsFragment extends Fragment {
|
|||||||
private RadioGroup radioGroupFilter;
|
private RadioGroup radioGroupFilter;
|
||||||
private RadioButton radioShowAll;
|
private RadioButton radioShowAll;
|
||||||
private RadioButton radioHideSystem;
|
private RadioButton radioHideSystem;
|
||||||
|
private EditText editInjectionDelay;
|
||||||
|
private ConfigManager configManager;
|
||||||
|
|
||||||
private SharedPreferences sharedPreferences;
|
private SharedPreferences sharedPreferences;
|
||||||
private OnSettingsChangeListener settingsChangeListener;
|
private OnSettingsChangeListener settingsChangeListener;
|
||||||
@@ -53,6 +58,9 @@ public class SettingsFragment extends Fragment {
|
|||||||
radioGroupFilter = view.findViewById(R.id.radio_group_filter);
|
radioGroupFilter = view.findViewById(R.id.radio_group_filter);
|
||||||
radioShowAll = view.findViewById(R.id.radio_show_all);
|
radioShowAll = view.findViewById(R.id.radio_show_all);
|
||||||
radioHideSystem = view.findViewById(R.id.radio_hide_system);
|
radioHideSystem = view.findViewById(R.id.radio_hide_system);
|
||||||
|
editInjectionDelay = view.findViewById(R.id.editInjectionDelay);
|
||||||
|
|
||||||
|
configManager = new ConfigManager(getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSharedPreferences() {
|
private void initSharedPreferences() {
|
||||||
@@ -67,6 +75,10 @@ public class SettingsFragment extends Fragment {
|
|||||||
} else {
|
} else {
|
||||||
radioShowAll.setChecked(true);
|
radioShowAll.setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load injection delay
|
||||||
|
int injectionDelay = configManager.getInjectionDelay();
|
||||||
|
editInjectionDelay.setText(String.valueOf(injectionDelay));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupListeners() {
|
private void setupListeners() {
|
||||||
@@ -86,6 +98,32 @@ public class SettingsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Injection delay listener
|
||||||
|
editInjectionDelay.addTextChangedListener(new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
String text = s.toString().trim();
|
||||||
|
if (!text.isEmpty()) {
|
||||||
|
try {
|
||||||
|
int delay = Integer.parseInt(text);
|
||||||
|
// Limit delay between 0 and 60 seconds
|
||||||
|
if (delay < 0) delay = 0;
|
||||||
|
if (delay > 60) delay = 60;
|
||||||
|
|
||||||
|
configManager.setInjectionDelay(delay);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// Ignore invalid input
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnSettingsChangeListener(OnSettingsChangeListener listener) {
|
public void setOnSettingsChangeListener(OnSettingsChangeListener listener) {
|
||||||
|
|||||||
@@ -72,6 +72,77 @@
|
|||||||
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
|
<!-- 注入延迟时间设置 -->
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="16dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="注入延迟时间"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_marginBottom="8dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="设置SO文件注入前的等待时间,以确保应用完全初始化"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textColor="@android:color/darker_gray"
|
||||||
|
android:layout_marginBottom="12dp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="延迟时间(秒):"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:layout_marginEnd="8dp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editInjectionDelay"
|
||||||
|
android:layout_width="80dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="number"
|
||||||
|
android:text="2"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:hint="0-60"
|
||||||
|
android:layout_marginEnd="8dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="秒"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="建议值:2-5秒。某些应用可能需要更长时间。"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:textColor="@android:color/darker_gray"
|
||||||
|
android:layout_marginTop="8dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
<!-- 其他设置可以在这里添加 -->
|
<!-- 其他设置可以在这里添加 -->
|
||||||
<com.google.android.material.card.MaterialCardView
|
<com.google.android.material.card.MaterialCardView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -31,6 +31,13 @@ namespace Config {
|
|||||||
} else if (json[valueStart] == 't' || json[valueStart] == 'f') {
|
} else if (json[valueStart] == 't' || json[valueStart] == 'f') {
|
||||||
// Boolean value
|
// Boolean value
|
||||||
return (json.substr(valueStart, 4) == "true") ? "true" : "false";
|
return (json.substr(valueStart, 4) == "true") ? "true" : "false";
|
||||||
|
} else {
|
||||||
|
// Number value
|
||||||
|
size_t valueEnd = json.find_first_of(",} \t\n", valueStart);
|
||||||
|
if (valueEnd == std::string::npos) {
|
||||||
|
return json.substr(valueStart);
|
||||||
|
}
|
||||||
|
return json.substr(valueStart, valueEnd - valueStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
@@ -118,7 +125,13 @@ namespace Config {
|
|||||||
std::string hideStr = extractValue(json, "hideInjection");
|
std::string hideStr = extractValue(json, "hideInjection");
|
||||||
g_config.hideInjection = (hideStr == "true");
|
g_config.hideInjection = (hideStr == "true");
|
||||||
|
|
||||||
LOGD("Module enabled: %d, hide injection: %d", g_config.enabled, g_config.hideInjection);
|
std::string delayStr = extractValue(json, "injectionDelay");
|
||||||
|
if (!delayStr.empty()) {
|
||||||
|
g_config.injectionDelay = std::stoi(delayStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGD("Module enabled: %d, hide injection: %d, injection delay: %d",
|
||||||
|
g_config.enabled, g_config.hideInjection, g_config.injectionDelay);
|
||||||
|
|
||||||
// Parse perAppConfig
|
// Parse perAppConfig
|
||||||
size_t perAppPos = json.find("\"perAppConfig\"");
|
size_t perAppPos = json.find("\"perAppConfig\"");
|
||||||
@@ -212,4 +225,11 @@ namespace Config {
|
|||||||
}
|
}
|
||||||
return InjectionMethod::STANDARD;
|
return InjectionMethod::STANDARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getInjectionDelay() {
|
||||||
|
if (!g_configLoaded) {
|
||||||
|
readConfig();
|
||||||
|
}
|
||||||
|
return g_config.injectionDelay;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -28,6 +28,7 @@ namespace Config {
|
|||||||
struct ModuleConfig {
|
struct ModuleConfig {
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
bool hideInjection = false;
|
bool hideInjection = false;
|
||||||
|
int injectionDelay = 2; // Default 2 seconds
|
||||||
std::unordered_map<std::string, AppConfig> perAppConfig;
|
std::unordered_map<std::string, AppConfig> perAppConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -45,6 +46,9 @@ namespace Config {
|
|||||||
|
|
||||||
// Get injection method for specific app
|
// Get injection method for specific app
|
||||||
InjectionMethod getAppInjectionMethod(const std::string& packageName);
|
InjectionMethod getAppInjectionMethod(const std::string& packageName);
|
||||||
|
|
||||||
|
// Get injection delay in seconds
|
||||||
|
int getInjectionDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CONFIG_H
|
#endif // CONFIG_H
|
||||||
@@ -88,8 +88,12 @@ void load_so_file_custom_linker(const char *game_data_dir, const Config::SoFile
|
|||||||
void hack_thread_func(const char *game_data_dir, const char *package_name, JavaVM *vm) {
|
void hack_thread_func(const char *game_data_dir, const char *package_name, JavaVM *vm) {
|
||||||
LOGI("Hack thread started for package: %s", package_name);
|
LOGI("Hack thread started for package: %s", package_name);
|
||||||
|
|
||||||
// Wait a bit for app to initialize and files to be copied
|
// Get injection delay from config
|
||||||
sleep(2);
|
int delay = Config::getInjectionDelay();
|
||||||
|
LOGI("Waiting %d seconds before injection", delay);
|
||||||
|
|
||||||
|
// Wait for app to initialize and files to be copied
|
||||||
|
sleep(delay);
|
||||||
|
|
||||||
// Get injection method for this app
|
// Get injection method for this app
|
||||||
Config::InjectionMethod method = Config::getAppInjectionMethod(package_name);
|
Config::InjectionMethod method = Config::getAppInjectionMethod(package_name);
|
||||||
|
|||||||
Reference in New Issue
Block a user