From c52917e7db77536326ca93102d8f30cbd56e6bb1 Mon Sep 17 00:00:00 2001 From: Jan Peter Stotz Date: Fri, 24 Jun 2022 18:31:26 +0200 Subject: [PATCH 1/2] QuarkReport: data validation added and other minor improvements --- .../gui/plugins/quark/QuarkReportData.java | 35 +++++++++++++++++++ .../gui/plugins/quark/QuarkReportNode.java | 13 ++++--- .../gui/plugins/quark/QuarkReportPanel.java | 4 +-- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportData.java b/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportData.java index 95145610788..4e0f803f85a 100644 --- a/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportData.java +++ b/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportData.java @@ -10,6 +10,7 @@ @SuppressWarnings("MemberName") public class QuarkReportData { + public static class Crime { public String crime; public String confidence; @@ -18,6 +19,22 @@ public static class Crime { List native_api; List combination; List> register; + + public int parseConfidence() { + return Integer.parseInt(confidence.replace("%", "")); + } + + @Override + public String toString() { + return "Crime{" + + "crime='" + crime + '\'' + + ", confidence='" + confidence + '\'' + + ", permissions=" + permissions + + ", native_api=" + native_api + + ", combination=" + combination + + ", register=" + register + + '}'; + } } public static class Method { @@ -46,4 +63,22 @@ public static class InvokePlace { String threat_level; int total_score; List crimes; + + public void validate() { + if (crimes == null) { + throw new RuntimeException("Invalid data: \"crimes\" list missing"); + } + for (Crime crime : crimes) { + if (crime.confidence == null) { + throw new RuntimeException("Confidence value missing: " + crime); + } + try { + crime.parseConfidence(); + } catch (Exception e) { + throw new RuntimeException("Invalid crime entry: " + crime); + } + } + + } + } diff --git a/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportNode.java b/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportNode.java index 43c295ada1e..91cb2ce94b1 100644 --- a/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportNode.java +++ b/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportNode.java @@ -1,5 +1,6 @@ package jadx.gui.plugins.quark; +import java.io.BufferedReader; import java.nio.file.Files; import java.nio.file.Path; @@ -33,12 +34,12 @@ public class QuarkReportNode extends JNode { private static final ImageIcon ICON = UiUtils.openSvgIcon("ui/quark"); - private final Path apkFile; + private final Path reportFile; private ICodeInfo errorContent; - public QuarkReportNode(Path apkFile) { - this.apkFile = apkFile; + public QuarkReportNode(Path reportFile) { + this.reportFile = reportFile; } @Override @@ -59,7 +60,11 @@ public String makeString() { @Override public ContentPanel getContentPanel(TabbedPane tabbedPane) { try { - QuarkReportData data = GSON.fromJson(Files.newBufferedReader(apkFile), QuarkReportData.class); + QuarkReportData data; + try (BufferedReader reader = Files.newBufferedReader(reportFile)) { + data = GSON.fromJson(reader, QuarkReportData.class); + } + data.validate(); return new QuarkReportPanel(tabbedPane, this, data); } catch (Exception e) { LOG.error("Quark report parse error", e); diff --git a/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportPanel.java b/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportPanel.java index 5d680060886..8507cc39f70 100644 --- a/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportPanel.java +++ b/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportPanel.java @@ -70,7 +70,7 @@ protected QuarkReportPanel(TabbedPane panel, QuarkReportNode node, QuarkReportDa } private void prepareData() { - data.crimes.sort(Comparator.comparingInt(c -> -Integer.parseInt(c.confidence.replace("%", "")))); + data.crimes.sort(Comparator.comparingInt(c -> -c.parseConfidence())); } private void initUI() { @@ -290,7 +290,7 @@ public MutableTreeNode resolveMethod(String descr) { } return new MethodTreeNode(javaMethod); } catch (Exception e) { - LOG.error("Failed to parse method descriptor string", e); + LOG.error("Failed to parse method descriptor string: {}", descr, e); return new TextTreeNode(descr); } } From ba59b564a04d0791303b7878a16af0a939d578f2 Mon Sep 17 00:00:00 2001 From: Jan Peter Stotz Date: Fri, 24 Jun 2022 18:58:27 +0200 Subject: [PATCH 2/2] checkStyle --- .../jadx/gui/plugins/quark/QuarkReportData.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportData.java b/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportData.java index 4e0f803f85a..eae4c9c6758 100644 --- a/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportData.java +++ b/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportData.java @@ -26,14 +26,15 @@ public int parseConfidence() { @Override public String toString() { - return "Crime{" + - "crime='" + crime + '\'' + - ", confidence='" + confidence + '\'' + - ", permissions=" + permissions + - ", native_api=" + native_api + - ", combination=" + combination + - ", register=" + register + - '}'; + final StringBuffer sb = new StringBuffer("Crime{"); + sb.append("crime='").append(crime).append('\''); + sb.append(", confidence='").append(confidence).append('\''); + sb.append(", permissions=").append(permissions); + sb.append(", native_api=").append(native_api); + sb.append(", combination=").append(combination); + sb.append(", register=").append(register); + sb.append('}'); + return sb.toString(); } }