diff --git a/README.md b/README.md index 8fdd4c04..8e979e0a 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Build Status](https://travis-ci.org/skylot/jadx.png?branch=master)](https://travis-ci.org/skylot/jadx) [![Code Coverage](https://codecov.io/gh/skylot/jadx/branch/master/graph/badge.svg)](https://codecov.io/gh/skylot/jadx) +[![Alerts from lgtm.com](https://img.shields.io/lgtm/alerts/g/skylot/jadx.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/skylot/jadx/alerts/) [![SonarQube Bugs](https://sonarcloud.io/api/project_badges/measure?project=jadx&metric=bugs)](https://sonarcloud.io/dashboard?id=jadx) [![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) diff --git a/jadx-core/src/main/java/jadx/core/clsp/NMethod.java b/jadx-core/src/main/java/jadx/core/clsp/NMethod.java index a9fff026..70cf7c08 100644 --- a/jadx-core/src/main/java/jadx/core/clsp/NMethod.java +++ b/jadx-core/src/main/java/jadx/core/clsp/NMethod.java @@ -1,5 +1,7 @@ package jadx.core.clsp; +import java.util.Arrays; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -82,7 +84,7 @@ public class NMethod implements Comparable { @Override public String toString() { return "NMethod{'" + shortId + '\'' - + ", argTypes=" + genericArgs + + ", argTypes=" + Arrays.toString(genericArgs) + ", retType=" + retType + ", varArgs=" + varArgs + '}'; diff --git a/jadx-core/src/main/java/jadx/core/codegen/json/JsonCodeGen.java b/jadx-core/src/main/java/jadx/core/codegen/json/JsonCodeGen.java index ddf29bfc..cc05de0a 100644 --- a/jadx-core/src/main/java/jadx/core/codegen/json/JsonCodeGen.java +++ b/jadx-core/src/main/java/jadx/core/codegen/json/JsonCodeGen.java @@ -193,7 +193,7 @@ public class JsonCodeGen { jsonCodeLine.setSourceLine(lineMapping.get(line)); Object obj = annotations.get(new CodePosition(line, 0)); if (obj instanceof InsnNode) { - int offset = ((InsnNode) obj).getOffset(); + long offset = ((InsnNode) obj).getOffset(); jsonCodeLine.setOffset("0x" + Long.toHexString(mthCodeOffset + offset * 2)); } codeLines.add(jsonCodeLine); diff --git a/jadx-core/src/main/java/jadx/core/utils/Utils.java b/jadx-core/src/main/java/jadx/core/utils/Utils.java index 9d6f8264..79a2c3f0 100644 --- a/jadx-core/src/main/java/jadx/core/utils/Utils.java +++ b/jadx-core/src/main/java/jadx/core/utils/Utils.java @@ -180,8 +180,11 @@ public class Utils { if (len == 0) { return Collections.emptyMap(); } + if (len % 2 != 0) { + throw new IllegalArgumentException("Incorrect arguments count: " + len); + } Map result = new HashMap<>(len / 2); - for (int i = 0; i < len; i += 2) { + for (int i = 0; i < len - 1; i += 2) { result.put(parameters[i], parameters[i + 1]); } return Collections.unmodifiableMap(result); diff --git a/jadx-core/src/main/java/jadx/core/utils/android/Res9patchStreamDecoder.java b/jadx-core/src/main/java/jadx/core/utils/android/Res9patchStreamDecoder.java index 669df893..1be0be7b 100644 --- a/jadx-core/src/main/java/jadx/core/utils/android/Res9patchStreamDecoder.java +++ b/jadx-core/src/main/java/jadx/core/utils/android/Res9patchStreamDecoder.java @@ -50,12 +50,12 @@ public class Res9patchStreamDecoder { drawVLine(im2, w + 1, np.padTop + 1, h - np.padBottom); int[] xDivs = np.xDivs; - for (int i = 0; i < xDivs.length; i += 2) { + for (int i = 0; i < xDivs.length - 1; i += 2) { drawHLine(im2, 0, xDivs[i] + 1, xDivs[i + 1]); } int[] yDivs = np.yDivs; - for (int i = 0; i < yDivs.length; i += 2) { + for (int i = 0; i < yDivs.length - 1; i += 2) { drawVLine(im2, 0, yDivs[i] + 1, yDivs[i + 1]); } diff --git a/jadx-core/src/main/java/jadx/core/xmlgen/entry/ValuesParser.java b/jadx-core/src/main/java/jadx/core/xmlgen/entry/ValuesParser.java index 42b44010..56fe7dcf 100644 --- a/jadx-core/src/main/java/jadx/core/xmlgen/entry/ValuesParser.java +++ b/jadx-core/src/main/java/jadx/core/xmlgen/entry/ValuesParser.java @@ -40,11 +40,12 @@ public class ValuesParser extends ParserConstants { } private static void decodeAndroid(RootNode root) throws IOException { - InputStream inputStream = new BufferedInputStream(ValuesParser.class.getResourceAsStream("/resources.arsc")); - ResTableParser androidParser = new ResTableParser(root); - androidParser.decode(inputStream); - androidStrings = androidParser.getStrings(); - androidResMap = androidParser.getResStorage().getResourcesNames(); + try (InputStream inputStream = new BufferedInputStream(ValuesParser.class.getResourceAsStream("/resources.arsc"))) { + ResTableParser androidParser = new ResTableParser(root); + androidParser.decode(inputStream); + androidStrings = androidParser.getStrings(); + androidResMap = androidParser.getResStorage().getResourcesNames(); + } } @Nullable diff --git a/jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java b/jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java index 74b2a50b..b126a4d4 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java @@ -13,6 +13,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.io.FileInputStream; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -924,12 +925,12 @@ public class MainWindow extends JFrame { } private void setEditorTheme(String editorThemePath) { - try { - editorTheme = Theme.load(getClass().getResourceAsStream(editorThemePath)); + try (InputStream is = getClass().getResourceAsStream(editorThemePath)) { + editorTheme = Theme.load(is); } catch (Exception e) { LOG.error("Can't load editor theme from classpath: {}", editorThemePath); - try { - editorTheme = Theme.load(new FileInputStream(editorThemePath)); + try (InputStream is = new FileInputStream(editorThemePath)) { + editorTheme = Theme.load(is); } catch (Exception ex) { LOG.error("Can't load editor theme from file: {}", editorThemePath); }