diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 1edbb1788..536c96625 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -124,6 +124,12 @@ + + + + + + diff --git a/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java b/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java index fa041f47f..1db22fea4 100644 --- a/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java +++ b/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java @@ -65,8 +65,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; public abstract class IntegrationTest extends TestUtils { - private static final Logger LOG = LoggerFactory.getLogger(IntegrationTest.class); + private static final String TEST_DIRECTORY = "src/test/java"; private static final String TEST_DIRECTORY2 = "jadx-core/" + TEST_DIRECTORY; @@ -150,7 +150,7 @@ public abstract class IntegrationTest extends TestUtils { assertThat("File list is empty", files, not(empty())); return getClassNodeFromFiles(files, clazz.getName()); } catch (Exception e) { - e.printStackTrace(); + LOG.error("Failed to get class node", e); fail(e.getMessage()); } return null; @@ -194,7 +194,7 @@ public abstract class IntegrationTest extends TestUtils { try { d.load(); } catch (Exception e) { - e.printStackTrace(); + LOG.error("Load failed", e); d.close(); fail(e.getMessage()); return null; @@ -332,7 +332,7 @@ public abstract class IntegrationTest extends TestUtils { runDecompiledAutoCheck(cls); } } catch (Exception e) { - e.printStackTrace(); + LOG.error("Auto check failed", e); fail("Auto check exception: " + e.getMessage()); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inline/TestIssue86.java b/jadx-core/src/test/java/jadx/tests/integration/inline/TestIssue86.java index 47c38b392..060a5c7bc 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inline/TestIssue86.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inline/TestIssue86.java @@ -11,6 +11,7 @@ import jadx.tests.api.IntegrationTest; import static jadx.tests.api.utils.JadxMatchers.containsOne; import static org.hamcrest.MatcherAssert.assertThat; +@SuppressWarnings("checkstyle:printstacktrace") public class TestIssue86 extends IntegrationTest { public static class TestCls { diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithTryCatch.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithTryCatch.java index 121da0a09..dba88fd67 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithTryCatch.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithTryCatch.java @@ -8,6 +8,7 @@ import jadx.tests.api.IntegrationTest; import static jadx.tests.api.utils.JadxMatchers.countString; import static org.hamcrest.MatcherAssert.assertThat; +@SuppressWarnings("checkstyle:printstacktrace") public class TestSwitchWithTryCatch extends IntegrationTest { public static class TestCls { void test(int a) { diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatch2.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatch2.java index dc623d2bf..4361a1199 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatch2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatch2.java @@ -11,6 +11,7 @@ import jadx.tests.api.IntegrationTest; import static jadx.tests.api.utils.JadxMatchers.containsOne; import static org.hamcrest.MatcherAssert.assertThat; +@SuppressWarnings("checkstyle:printstacktrace") public class TestMultiExceptionCatch2 extends IntegrationTest { public static class TestCls { diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch7.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch7.java index 5a710cbf6..0bca0f1a0 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch7.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch7.java @@ -8,6 +8,7 @@ import jadx.tests.api.IntegrationTest; import static jadx.tests.api.utils.JadxMatchers.containsOne; import static org.hamcrest.MatcherAssert.assertThat; +@SuppressWarnings("checkstyle:printstacktrace") public class TestTryCatch7 extends IntegrationTest { public static class TestCls { diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally.java index bd6d3943b..2906594d2 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally.java @@ -7,6 +7,7 @@ import jadx.tests.api.IntegrationTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; +@SuppressWarnings("checkstyle:printstacktrace") public class TestTryCatchFinally extends IntegrationTest { public static class TestCls { diff --git a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables4.java b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables4.java index c5f4f5528..6c37c09be 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables4.java @@ -11,6 +11,7 @@ import jadx.tests.api.IntegrationTest; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; +@SuppressWarnings("checkstyle:printstacktrace") public class TestVariables4 extends IntegrationTest { public static class TestCls { diff --git a/jadx-gui/src/main/java/jadx/gui/device/debugger/BreakpointManager.java b/jadx-gui/src/main/java/jadx/gui/device/debugger/BreakpointManager.java index b3f4fe2a3..c10ea404e 100644 --- a/jadx-gui/src/main/java/jadx/gui/device/debugger/BreakpointManager.java +++ b/jadx-gui/src/main/java/jadx/gui/device/debugger/BreakpointManager.java @@ -1,6 +1,5 @@ package jadx.gui.device.debugger; -import java.io.IOException; import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -15,6 +14,9 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Objects; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -24,6 +26,8 @@ import jadx.gui.device.debugger.smali.Smali; import jadx.gui.treemodel.JClass; public class BreakpointManager { + private static final Logger LOG = LoggerFactory.getLogger(BreakpointManager.class); + private static Gson gson = null; private static final Type TYPE_TOKEN = new TypeToken>>() { }.getType(); @@ -56,8 +60,8 @@ public class BreakpointManager { try { byte[] bytes = Files.readAllBytes(savePath); bpm = gson.fromJson(new String(bytes, StandardCharsets.UTF_8), TYPE_TOKEN); - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + LOG.error("Failed to read breakpoints config: {}", savePath, e); } } if (bpm == null) { @@ -147,8 +151,8 @@ public class BreakpointManager { private static void sync() { try { Files.write(savePath, gson.toJson(bpm).getBytes(StandardCharsets.UTF_8)); - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + LOG.error("Failed to write breakpoints config: {}", savePath, e); } } diff --git a/jadx-gui/src/main/java/jadx/gui/device/debugger/DbgUtils.java b/jadx-gui/src/main/java/jadx/gui/device/debugger/DbgUtils.java index 37d94ffd8..620bdbf3a 100644 --- a/jadx-gui/src/main/java/jadx/gui/device/debugger/DbgUtils.java +++ b/jadx-gui/src/main/java/jadx/gui/device/debugger/DbgUtils.java @@ -6,6 +6,8 @@ import java.util.Map; import java.util.Map.Entry; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import jadx.api.JavaClass; import jadx.api.ResourceFile; @@ -18,6 +20,7 @@ import jadx.gui.treemodel.JNode; import jadx.gui.ui.MainWindow; public class DbgUtils { + private static final Logger LOG = LoggerFactory.getLogger(DbgUtils.class); private static Map smaliCache = Collections.emptyMap(); @@ -156,7 +159,7 @@ public class DbgUtils { return androidManifest.loadContent().getText().getCodeStr(); } } catch (Exception e) { - e.printStackTrace(); + LOG.error("AndroidManifest.xml search error", e); } return ""; } diff --git a/jadx-gui/src/main/java/jadx/gui/device/debugger/DebugController.java b/jadx-gui/src/main/java/jadx/gui/device/debugger/DebugController.java index 76a079d88..b4c1dddac 100644 --- a/jadx-gui/src/main/java/jadx/gui/device/debugger/DebugController.java +++ b/jadx-gui/src/main/java/jadx/gui/device/debugger/DebugController.java @@ -13,6 +13,9 @@ import java.util.concurrent.Executors; import javax.swing.tree.DefaultMutableTreeNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.reactivex.annotations.NonNull; import io.reactivex.annotations.Nullable; @@ -42,6 +45,8 @@ import jadx.gui.ui.panel.JDebuggerPanel.ValueTreeNode; import static jadx.gui.device.debugger.SmaliDebugger.RuntimeType; public final class DebugController implements SmaliDebugger.SuspendListener, IDebugController { + private static final Logger LOG = LoggerFactory.getLogger(DebugController.class); + private static final String ONCREATE_SIGNATURE = "onCreate(Landroid/os/Bundle;)V"; private static final Map TYPE_MAP = new HashMap<>(); private static final RuntimeType[] POSSIBLE_TYPES = { RuntimeType.OBJECT, RuntimeType.INT, RuntimeType.LONG }; @@ -924,16 +929,17 @@ public final class DebugController implements SmaliDebugger.SuspendListener, IDe private void logErr(Exception e, String extra) { debuggerPanel.log(e.getMessage()); debuggerPanel.log(extra); - e.printStackTrace(); + LOG.error(extra, e); } private void logErr(Exception e) { debuggerPanel.log(e.getMessage()); - e.printStackTrace(); + LOG.error("Debug error", e); } private void logErr(String e) { debuggerPanel.log(e); + LOG.error("Debug error: {}", e); } private void scrollToPos(long codeOffset) { diff --git a/jadx-gui/src/main/java/jadx/gui/device/debugger/SmaliDebugger.java b/jadx-gui/src/main/java/jadx/gui/device/debugger/SmaliDebugger.java index 7143a4760..c8d57118a 100644 --- a/jadx-gui/src/main/java/jadx/gui/device/debugger/SmaliDebugger.java +++ b/jadx-gui/src/main/java/jadx/gui/device/debugger/SmaliDebugger.java @@ -17,6 +17,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.atomic.AtomicInteger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.github.hqktech.JDWP; import io.github.hqktech.JDWP.ArrayReference.Length.LengthReplyData; import io.github.hqktech.JDWP.ByteBuffer; @@ -78,6 +81,7 @@ import jadx.gui.utils.ObjectPool; public class SmaliDebugger { + private static final Logger LOG = LoggerFactory.getLogger(SmaliDebugger.class); private final JDWP jdwp; private int localTcpPort; private InputStream inputStream; @@ -375,7 +379,7 @@ public class SmaliDebugger { try { resume(); } catch (SmaliDebuggerException e) { - e.printStackTrace(); + LOG.error("Resume failed", e); } } }); @@ -410,13 +414,13 @@ public class SmaliDebugger { eventListenerMap.remove(reqID); } } catch (SmaliDebuggerException e) { - e.printStackTrace(); + LOG.error("Method entry failed", e); } finally { if (!removeListener) { try { resume(); } catch (SmaliDebuggerException e) { - e.printStackTrace(); + LOG.error("Resume failed", e); } } } @@ -690,7 +694,7 @@ public class SmaliDebugger { printUnexpectedID(res.getID()); } } catch (SmaliDebuggerException e) { - e.printStackTrace(); + LOG.error("Error in debugger decoding loop", e); if (!errFromCallback) { // fatal error break; } @@ -721,8 +725,8 @@ public class SmaliDebugger { sendCommand(buf, res -> { try { store.put(res); - } catch (InterruptedException e) { - e.printStackTrace(); + } catch (Exception e) { + LOG.error("Command send failed", e); } }); Integer id = syncQueueID.getAndAdd(1); @@ -757,11 +761,7 @@ public class SmaliDebugger { for (JDWP.EventRequestDecoder event : data.events) { EventListenerAdapter listener = eventListenerMap.get(event.getRequestID()); if (listener == null) { - try { - printUnexpectedID(event.getRequestID()); - } catch (Exception e) { - e.printStackTrace(); - } + LOG.error("Missing handler for id: {}", event.getRequestID()); continue; } if (event instanceof VMStartEvent) { diff --git a/jadx-gui/src/main/java/jadx/gui/device/protocol/ADB.java b/jadx-gui/src/main/java/jadx/gui/device/protocol/ADB.java index f18aa684d..d08d3c817 100644 --- a/jadx-gui/src/main/java/jadx/gui/device/protocol/ADB.java +++ b/jadx-gui/src/main/java/jadx/gui/device/protocol/ADB.java @@ -14,11 +14,16 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.reactivex.annotations.NonNull; import jadx.core.utils.StringUtils; public class ADB { + private static final Logger LOG = LoggerFactory.getLogger(ADB.class); + private static final int DEFAULT_PORT = 5037; private static final String DEFAULT_ADDR = "localhost"; @@ -138,8 +143,8 @@ public class ADB { try { proc.waitFor(3, TimeUnit.SECONDS); // for listening to a port, 3 sec should be more than enough. proc.exitValue(); - } catch (InterruptedException e) { - e.printStackTrace(); + } catch (Exception e) { + LOG.error("Start server error", e); proc.destroyForcibly(); return false; } @@ -155,10 +160,9 @@ public class ADB { Socket sock = new Socket(host, port); sock.close(); return true; - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + return false; } - return false; } /** @@ -404,8 +408,8 @@ public class ADB { if (list.size() != 0) { androidReleaseVer = list.get(0); } - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + LOG.error("Failed to get android release version", e); androidReleaseVer = ""; } return androidReleaseVer; @@ -510,8 +514,8 @@ public class ADB { if (jdwpListenerSock != null) { try { jdwpListenerSock.close(); - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + LOG.error("JDWP socket close failed", e); } } this.jdwpListenerSock = null; diff --git a/jadx-gui/src/main/java/jadx/gui/ui/TabbedPane.java b/jadx-gui/src/main/java/jadx/gui/ui/TabbedPane.java index 0e9282701..037d9d991 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/TabbedPane.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/TabbedPane.java @@ -195,7 +195,7 @@ public class TabbedPane extends JTabbedPane { jumpPos.setPos(offs); codeArea.scrollToPos(offs); } catch (BadLocationException e) { - e.printStackTrace(); + LOG.error("Failed to jump to position: {}", pos, e); codeArea.scrollToLine(line); } } diff --git a/jadx-gui/src/main/java/jadx/gui/ui/codearea/AbstractCodeArea.java b/jadx-gui/src/main/java/jadx/gui/ui/codearea/AbstractCodeArea.java index d3c91a1e9..8a542eaf2 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/codearea/AbstractCodeArea.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/codearea/AbstractCodeArea.java @@ -142,6 +142,7 @@ public abstract class AbstractCodeArea extends RSyntaxTextArea { return lastText; } + @Nullable public String getWordUnderCaret() { return getWordByPosition(getCaretPosition()); } @@ -156,7 +157,7 @@ public abstract class AbstractCodeArea extends RSyntaxTextArea { } start++; } catch (BadLocationException e) { - e.printStackTrace(); + LOG.error("Failed to find word start", e); start = -1; } return start; @@ -171,29 +172,26 @@ public abstract class AbstractCodeArea extends RSyntaxTextArea { } while (end < max && !StringUtils.isWordSeparator(getText(end, 1).charAt(0))); } } catch (BadLocationException e) { - e.printStackTrace(); + LOG.error("Failed to find word end", e); end = max; } return end; } + @Nullable public String getWordByPosition(int pos) { - String text; int len = getDocument().getLength(); int start = getWordStart(pos); int end = getWordEnd(pos, len); try { - if (end > start) { - text = getText(start, end - start); - } else { - text = null; + if (end <= start) { + return null; } + return getText(start, end - start); } catch (BadLocationException e) { - e.printStackTrace(); - System.out.printf("start: %d end: %d%n", start, end); - text = null; + LOG.error("Failed to get word at pos: {}, start: {}, end: {}", pos, start, end, e); + return null; } - return text; } /** diff --git a/jadx-gui/src/main/java/jadx/gui/ui/codearea/SmaliArea.java b/jadx-gui/src/main/java/jadx/gui/ui/codearea/SmaliArea.java index e320f8367..aac02b748 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/codearea/SmaliArea.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/codearea/SmaliArea.java @@ -32,6 +32,8 @@ import org.fife.ui.rtextarea.GutterIconInfo; import org.fife.ui.rtextarea.IconRowHeader; import org.fife.ui.rtextarea.RTextArea; import org.fife.ui.rtextarea.RTextAreaUI; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import jadx.gui.device.debugger.BreakpointManager; import jadx.gui.device.debugger.DbgUtils; @@ -44,6 +46,8 @@ import jadx.gui.utils.NLS; import jadx.gui.utils.UiUtils; public final class SmaliArea extends AbstractCodeArea { + private static final Logger LOG = LoggerFactory.getLogger(SmaliArea.class); + private static final long serialVersionUID = 1334485631870306494L; private static final Icon ICON_BREAKPOINT = UiUtils.openSvgIcon("debugger/db_set_breakpoint"); @@ -260,8 +264,8 @@ public final class SmaliArea extends AbstractCodeArea { int line; try { line = getLineOfOffset(pos); - } catch (BadLocationException badLocationException) { - badLocationException.printStackTrace(); + } catch (BadLocationException e) { + LOG.error("Failed to get line by offset: {}", pos, e); return; } BreakpointLine bpLine = bpMap.remove(line); @@ -287,7 +291,7 @@ public final class SmaliArea extends AbstractCodeArea { int line = getLineOfOffset(pos); runningHighlightTag = addLineHighlight(line, DEBUG_LINE_COLOR); } catch (BadLocationException e) { - e.printStackTrace(); + LOG.error("Failed to get line by offset: {}", pos, e); } } @@ -296,7 +300,7 @@ public final class SmaliArea extends AbstractCodeArea { int line = getLineOfOffset(pos); bpMap.computeIfAbsent(line, k -> new BreakpointLine(line)).setDisabled(true); } catch (BadLocationException e) { - e.printStackTrace(); + LOG.error("Failed to get line by offset: {}", pos, e); } } @@ -377,7 +381,7 @@ public final class SmaliArea extends AbstractCodeArea { try { iconInfo = gutter.addLineTrackingIcon(line, ICON_BREAKPOINT_DISABLED); } catch (BadLocationException e) { - e.printStackTrace(); + LOG.error("Failed to add line tracking icon", e); } } } else { @@ -387,7 +391,7 @@ public final class SmaliArea extends AbstractCodeArea { iconInfo = gutter.addLineTrackingIcon(line, ICON_BREAKPOINT); highlightTag = addLineHighlight(line, BREAKPOINT_LINE_COLOR); } catch (BadLocationException e) { - e.printStackTrace(); + LOG.error("Failed to remove line tracking icon", e); } } } diff --git a/jadx-gui/src/main/java/jadx/gui/ui/dialog/ADBDialog.java b/jadx-gui/src/main/java/jadx/gui/ui/dialog/ADBDialog.java index 5c14c9a9b..2afd6f5af 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/dialog/ADBDialog.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/dialog/ADBDialog.java @@ -10,7 +10,6 @@ import java.awt.Label; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.File; -import java.io.IOException; import java.net.Socket; import java.util.ArrayList; import java.util.Collections; @@ -36,6 +35,9 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import jadx.core.utils.StringUtils; import jadx.core.utils.exceptions.JadxRuntimeException; import jadx.gui.device.debugger.DbgUtils; @@ -44,11 +46,14 @@ import jadx.gui.treemodel.JClass; import jadx.gui.ui.MainWindow; import jadx.gui.ui.panel.IDebugController; import jadx.gui.utils.NLS; +import jadx.gui.utils.SystemInfo; import jadx.gui.utils.UiUtils; import static jadx.gui.device.protocol.ADB.Device.ForwardResult; public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.JDWPProcessListener { + private static final Logger LOG = LoggerFactory.getLogger(ADBDialog.class); + private static final long serialVersionUID = -1111111202102181630L; private static final ImageIcon ICON_DEVICE = UiUtils.openSvgIcon("adb/androidDevice"); private static final ImageIcon ICON_PROCESS = UiUtils.openSvgIcon("adb/addToWatch"); @@ -185,8 +190,8 @@ public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.J if (deviceSocket != null) { try { deviceSocket.close(); - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + LOG.error("Failed to close device socket", e); } deviceSocket = null; } @@ -197,13 +202,7 @@ public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.J } private void detectADBPath() { - boolean isWinOS; - try { - isWinOS = System.getProperty("os.name").startsWith("Windows"); - } catch (Exception e) { - e.printStackTrace(); - return; - } + boolean isWinOS = SystemInfo.IS_WINDOWS; String slash = isWinOS ? "\\" : "/"; String adbName = isWinOS ? "adb.exe" : "adb"; String sdkPath = System.getenv("ANDROID_HOME"); @@ -244,9 +243,9 @@ public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.J } else { tip = NLS.str("adb_dialog.start_fail", portTextField.getText()); } - } catch (Exception except) { - tip = except.getMessage(); - except.printStackTrace(); + } catch (Exception e) { + LOG.error("Failed to start adb server", e); + tip = e.getMessage(); } UiUtils.showMessageBox(mainWindow, tip); tipLabel.setText(tip); @@ -265,8 +264,8 @@ public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.J } else { tip = NLS.str("adb_dialog.connect_fail"); } - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + LOG.error("Failed to connect to adb", e); tip = e.getMessage(); UiUtils.showMessageBox(mainWindow, tip); } @@ -346,26 +345,25 @@ public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.J } private static boolean attachProcess(MainWindow mainWindow) { - boolean ok = false; if (debugSetter == null) { - return ok; + return false; } debugSetter.clearForward(); String rst = debugSetter.forwardJDWP(); if (!rst.isEmpty()) { UiUtils.showMessageBox(mainWindow, rst); - return ok; + return false; } try { - ok = mainWindow.getDebuggerPanel().showDebugger( + return mainWindow.getDebuggerPanel().showDebugger( debugSetter.name, debugSetter.device.getDeviceInfo().adbHost, debugSetter.forwardTcpPort, debugSetter.ver); - } catch (Exception except) { - except.printStackTrace(); + } catch (Exception e) { + LOG.error("Failed to attach to process", e); + return false; } - return ok; } public static boolean launchForDebugging(MainWindow mainWindow, String fullAppPath, boolean autoAttach) { @@ -379,7 +377,7 @@ public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.J return attachProcess(mainWindow); } } catch (Exception e) { - e.printStackTrace(); + LOG.error("Failed to launch app", e); } } return false; @@ -416,8 +414,8 @@ public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.J private void listenJDWP(ADB.Device device) { try { device.listenForJDWP(this); - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + LOG.error("Failed listen for JDWP", e); } } @@ -451,8 +449,8 @@ public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.J * otherwise we may not get its real name but the state text. */ procs = device.getProcessList(); - } catch (IOException | InterruptedException e) { - e.printStackTrace(); + } catch (Exception e) { + LOG.error("Failed to get device process list", e); procs = Collections.emptyList(); } List procList = new ArrayList<>(id.size()); @@ -470,7 +468,7 @@ public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.J try { node = getDeviceNode(device); } catch (Exception e) { - e.printStackTrace(); + LOG.error("Failed to find device", e); return; } node.tNode.removeAllChildren(); @@ -521,7 +519,7 @@ public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.J try { device.launchApp(fullName); } catch (Exception e) { - e.printStackTrace(); + LOG.error("Failed to launch app: {}", fullName, e); UiUtils.showMessageBox(mainWindow, e.getMessage()); } } @@ -652,8 +650,8 @@ public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.J resultDesc = rst.desc; break; } while (true); - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + LOG.error("JDWP forward error", e); } if (StringUtils.isEmpty(resultDesc)) { resultDesc = NLS.str("adb_dialog.forward_fail"); @@ -676,14 +674,14 @@ public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.J try { device.removeForward(field.substring("tcp:".length())); } catch (Exception e) { - e.printStackTrace(); + LOG.error("JDWP remove forward error", e); } } } } } - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + LOG.error("JDWP clear forward error", e); } } @@ -698,8 +696,8 @@ public class ADBDialog extends JDialog implements ADB.DeviceStateListener, ADB.J return !s.contains(tcpPort); } } - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + LOG.error("ADB list forward error", e); } return false; } diff --git a/jadx-gui/src/main/java/jadx/gui/ui/popupmenu/VarTreePopupMenu.java b/jadx-gui/src/main/java/jadx/gui/ui/popupmenu/VarTreePopupMenu.java index 93a35a717..e5b7ec88b 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/popupmenu/VarTreePopupMenu.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/popupmenu/VarTreePopupMenu.java @@ -10,6 +10,9 @@ import javax.swing.AbstractAction; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import jadx.core.dex.instructions.args.ArgType; import jadx.gui.ui.MainWindow; import jadx.gui.ui.dialog.SetValueDialog; @@ -18,6 +21,8 @@ import jadx.gui.utils.NLS; import jadx.gui.utils.UiUtils; public class VarTreePopupMenu extends JPopupMenu { + private static final Logger LOG = LoggerFactory.getLogger(VarTreePopupMenu.class); + private static final long serialVersionUID = -1111111202103170724L; private final MainWindow mainWindow; @@ -63,14 +68,14 @@ public class VarTreePopupMenu extends JPopupMenu { private static final long serialVersionUID = -1111111202103171120L; @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(ActionEvent event) { try { mainWindow.getDebuggerPanel() .getDbgController() .modifyRegValue(valNode, ArgType.INT, 0); - } catch (Exception except) { - except.printStackTrace(); - UiUtils.showMessageBox(mainWindow, except.getMessage()); + } catch (Exception e) { + LOG.error("Change to zero failed", e); + UiUtils.showMessageBox(mainWindow, e.getMessage()); } } }); @@ -78,14 +83,14 @@ public class VarTreePopupMenu extends JPopupMenu { private static final long serialVersionUID = -1111111202103171121L; @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(ActionEvent event) { try { mainWindow.getDebuggerPanel() .getDbgController() .modifyRegValue(valNode, ArgType.INT, 1); - } catch (Exception except) { - except.printStackTrace(); - UiUtils.showMessageBox(mainWindow, except.getMessage()); + } catch (Exception e) { + LOG.error("Change to one failed", e); + UiUtils.showMessageBox(mainWindow, e.getMessage()); } } });