From e9e05f89365a84930055cf2bc0e64333fa3b9070 Mon Sep 17 00:00:00 2001 From: Mike Anderson <45513948+MikeAndrson@users.noreply.github.com> Date: Mon, 6 Jun 2022 19:12:46 +0300 Subject: [PATCH] Extract Hex class resource logic to a separate method (#20) * feat: Extract Hex class resource logic to a separate method Sorry for the weird commit message, I couldn't find a way to word it better. Anyways.. This commit extracts the `getResourceAsStream` call to a separate, protected method so it can be overrided, and we can provide the Hex class from a different source. * fix: Check if Hex class stream is null --- .../src/main/java/com/googlecode/d2j/dex/Dex2Asm.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2Asm.java b/dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2Asm.java index 003c61a02..ea95142f1 100644 --- a/dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2Asm.java +++ b/dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2Asm.java @@ -529,8 +529,17 @@ public void convertClass(int dexVersion, DexClassNode classNode, ClassVisitorFac private static final Set HEX_DECODE_METHODS = new HashSet<>(Arrays.asList("decode_J", "decode_I", "decode_S", "decode_B")); + protected InputStream getHexClassAsStream() { + return Dex2Asm.class.getResourceAsStream("/" + HEX_CLASS_LOCATION + ".class"); + } + private void addHexDecodeMethod(ClassVisitor outCV, String className, String hexDecodeMethodNameBase) { - try (InputStream is = Dex2Asm.class.getResourceAsStream("/" + HEX_CLASS_LOCATION + ".class")) { + InputStream hexClassStream = getHexClassAsStream(); + if (hexClassStream == null) { + return; + } + + try (InputStream is = hexClassStream) { ClassReader cr = new ClassReader(is); cr.accept(new ClassVisitor(Opcodes.ASM9) { @Override