Skip to content

Commit 0bb5e1c

Browse files
authored
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
1 parent 63334e7 commit 0bb5e1c

File tree

1 file changed

+10
-1
lines changed
  • dex-translator/src/main/java/com/googlecode/d2j/dex

1 file changed

+10
-1
lines changed

dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2Asm.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,17 @@ public void convertClass(int dexVersion, DexClassNode classNode, ClassVisitorFac
561561
private static final Set<String> HEX_DECODE_METHODS =
562562
new HashSet<>(Arrays.asList("decode_J", "decode_I", "decode_S", "decode_B"));
563563

564+
protected InputStream getHexClassAsStream() {
565+
return Dex2Asm.class.getResourceAsStream("/" + HEX_CLASS_LOCATION + ".class");
566+
}
567+
564568
private void addHexDecodeMethod(ClassVisitor outCV, String className, String hexDecodeMethodNameBase) {
565-
try (InputStream is = Dex2Asm.class.getResourceAsStream("/" + HEX_CLASS_LOCATION + ".class")) {
569+
InputStream hexClassStream = getHexClassAsStream();
570+
if (hexClassStream == null) {
571+
return;
572+
}
573+
574+
try (InputStream is = hexClassStream) {
566575
ClassReader cr = new ClassReader(is);
567576
cr.accept(new ClassVisitor(Constants.ASM_VERSION) {
568577
@Override

0 commit comments

Comments
 (0)