Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/main/java/com/jarida/jadxfrida/frida/HookScriptGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,9 @@ private static String buildConstantLiteral(ReturnPatchRule patch, String returnT
}
return trimmed;
}
if (TypeUtil.isString(returnType)) {
return JsEscaper.quote(trimmed);
}
return JsEscaper.quote(trimmed);
}

private static String safe(String val) {
return val == null ? "" : val;
}

private static void appendExtraScriptInline(StringBuilder sb, String extraScript, String indent) {
if (extraScript == null || extraScript.trim().isEmpty()) {
return;
Expand Down Expand Up @@ -425,11 +418,11 @@ private static void appendHook(StringBuilder sb, HookSpec spec, int idx) {
sb.append(" enabled: ").append(enabled).append(",\n");
sb.append(" mode: ").append(JsEscaper.quote(patch == null ? "" : patch.getMode().name())).append(",\n");
sb.append(" constValue: ").append(buildConstantLiteral(patch, target.getReturnType())).append(",\n");
sb.append(" expr: ").append(JsEscaper.quote(patch == null ? "" : safe(patch.getExpression()))).append(",\n");
sb.append(" cond: ").append(JsEscaper.quote(patch == null ? "" : safe(patch.getCondition()))).append(",\n");
sb.append(" thenValue: ").append(JsEscaper.quote(patch == null ? "" : safe(patch.getThenValue()))).append(",\n");
sb.append(" elseValue: ").append(JsEscaper.quote(patch == null ? "" : safe(patch.getElseValue()))).append(",\n");
sb.append(" script: ").append(JsEscaper.quote(patch == null ? "" : safe(patch.getScriptBody()))).append("\n");
sb.append(" expr: ").append(JsEscaper.quote(safe(patch == null ? null : patch.getExpression()))).append(",\n");
sb.append(" cond: ").append(JsEscaper.quote(safe(patch == null ? null : patch.getCondition()))).append(",\n");
sb.append(" thenValue: ").append(JsEscaper.quote(safe(patch == null ? null : patch.getThenValue()))).append(",\n");
sb.append(" elseValue: ").append(JsEscaper.quote(safe(patch == null ? null : patch.getElseValue()))).append(",\n");
sb.append(" script: ").append(JsEscaper.quote(safe(patch == null ? null : patch.getScriptBody()))).append("\n");
sb.append(" };\n");

sb.append(" var clazz").append(suffix).append(" = Java.use(TARGET_CLASS").append(suffix).append(");\n");
Expand Down Expand Up @@ -523,4 +516,8 @@ private static void appendHook(StringBuilder sb, HookSpec spec, int idx) {
// avoid noisy "Hooked" logs on auto-reload; extra scripts are injected per-call
sb.append(" } catch (e) { console.log('[JARIDA] Hook error: ' + e); }\n");
}

private static String safe(String value) {
return value == null ? "" : value;
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/jarida/jadxfrida/model/FridaSessionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ public void setAdbPath(String adbPath) {
this.adbPath = adbPath;
}

public FridaSessionConfig copy() {
FridaSessionConfig cfg = new FridaSessionConfig();
cfg.setDeviceMode(deviceMode);
cfg.setDeviceId(deviceId);
cfg.setRemoteHost(remoteHost);
cfg.setRemotePort(remotePort);
cfg.setSpawn(spawn);
cfg.setTargetPackage(targetPackage);
cfg.setTargetProcess(targetProcess);
cfg.setTargetPid(targetPid);
cfg.setExtraFridaArgs(extraFridaArgs);
cfg.setFridaPath(fridaPath);
cfg.setFridaPsPath(fridaPsPath);
cfg.setAdbPath(adbPath);
return cfg;
}

public boolean isCompatibleForReuse(FridaSessionConfig other) {
if (other == null) {
return false;
Expand Down
32 changes: 2 additions & 30 deletions src/main/java/com/jarida/jadxfrida/ui/FridaConfigDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public FridaConfigDialog(JFrame owner, FridaController fridaController, MethodTa
this.fridaController = fridaController;
this.target = target;
this.fixedSessionConfig = fixedSessionConfig;
this.baseSessionConfig = cloneConfig(initialConfig);
this.baseSessionConfig = initialConfig.copy();
this.showReturnTab = showReturnTab;

deviceMode = new JComboBox<>(DeviceMode.values());
Expand Down Expand Up @@ -459,7 +459,7 @@ private JPanel buildButtons() {
}

private void onOk() {
FridaSessionConfig cfg = cloneConfig(fixedSessionConfig != null ? fixedSessionConfig : baseSessionConfig);
FridaSessionConfig cfg = (fixedSessionConfig != null ? fixedSessionConfig : baseSessionConfig).copy();
if (cfg == null) {
cfg = new FridaSessionConfig();
}
Expand Down Expand Up @@ -703,32 +703,4 @@ public String getTemplateContent() {
return templateArea.getText();
}

private static boolean isValidDeviceId(String deviceId) {
if (deviceId == null) {
return false;
}
String trimmed = deviceId.trim();
if (trimmed.isEmpty()) {
return false;
}
String lower = trimmed.toLowerCase();
return !("loading".equals(lower) || "none".equals(lower));
}

private static FridaSessionConfig cloneConfig(FridaSessionConfig src) {
FridaSessionConfig cfg = new FridaSessionConfig();
cfg.setDeviceMode(src.getDeviceMode());
cfg.setDeviceId(src.getDeviceId());
cfg.setRemoteHost(src.getRemoteHost());
cfg.setRemotePort(src.getRemotePort());
cfg.setSpawn(src.isSpawn());
cfg.setTargetPackage(src.getTargetPackage());
cfg.setTargetProcess(src.getTargetProcess());
cfg.setTargetPid(src.getTargetPid());
cfg.setExtraFridaArgs(src.getExtraFridaArgs());
cfg.setFridaPath(src.getFridaPath());
cfg.setFridaPsPath(src.getFridaPsPath());
cfg.setAdbPath(src.getAdbPath());
return cfg;
}
}
15 changes: 2 additions & 13 deletions src/main/java/com/jarida/jadxfrida/ui/JaridaConnectionPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private FridaSessionConfig buildConfig() {
FridaSessionConfig cfg = new FridaSessionConfig();
cfg.setDeviceMode((DeviceMode) deviceMode.getSelectedItem());
AdbDevice dev = (AdbDevice) deviceList.getSelectedItem();
if (dev != null && isValidDeviceId(dev.getId())) {
if (dev != null && AdbUtil.isValidDeviceId(dev.getId())) {
cfg.setDeviceId(dev.getId());
}
cfg.setRemoteHost(remoteHost.getText().trim());
Expand Down Expand Up @@ -455,7 +455,7 @@ private FridaSessionConfig buildConfig() {
return null;
}
}
if (cfg.getDeviceMode() == DeviceMode.USB && !isValidDeviceId(cfg.getDeviceId())) {
if (cfg.getDeviceMode() == DeviceMode.USB && !AdbUtil.isValidDeviceId(cfg.getDeviceId())) {
JOptionPane.showMessageDialog(this, "Select a valid USB device.", "Missing data", JOptionPane.ERROR_MESSAGE);
return null;
}
Expand Down Expand Up @@ -674,15 +674,4 @@ private boolean isExecutablePath(String value) {
return false;
}

private static boolean isValidDeviceId(String deviceId) {
if (deviceId == null) {
return false;
}
String trimmed = deviceId.trim();
if (trimmed.isEmpty()) {
return false;
}
String lower = trimmed.toLowerCase();
return !("loading".equals(lower) || "none".equals(lower));
}
}
20 changes: 12 additions & 8 deletions src/main/java/com/jarida/jadxfrida/util/AdbUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ public final class AdbUtil {
private AdbUtil() {
}

public static List<AdbDevice> listDevices() {
return listDevices("adb");
}

public static List<AdbDevice> listDevices(String adbPath) {
if (adbPath == null || adbPath.trim().isEmpty()) {
adbPath = "adb";
Expand Down Expand Up @@ -56,10 +52,6 @@ public static List<AdbDevice> listDevices(String adbPath) {
return result;
}

public static ProcessResult shell(String deviceId, String command) throws IOException, InterruptedException {
return shell("adb", deviceId, command);
}

public static ProcessResult shell(String adbPath, String deviceId, String command) throws IOException, InterruptedException {
if (adbPath == null || adbPath.trim().isEmpty()) {
adbPath = "adb";
Expand All @@ -75,6 +67,18 @@ public static ProcessResult shell(String adbPath, String deviceId, String comman
return ProcessUtils.run(cmd, DEFAULT_TIMEOUT_MS);
}

public static boolean isValidDeviceId(String deviceId) {
if (deviceId == null) {
return false;
}
String trimmed = deviceId.trim();
if (trimmed.isEmpty()) {
return false;
}
String lower = trimmed.toLowerCase();
return !("loading".equals(lower) || "none".equals(lower));
}

public static List<FridaProcessInfo> findProcessesByPackage(String adbPath, String deviceId, String packageName) {
List<FridaProcessInfo> result = new ArrayList<>();
if (packageName == null || packageName.trim().isEmpty()) {
Expand Down