Skip to content

Commit

Permalink
Extract Hex class resource logic to a separate method (#20)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
omeraydindev authored and pxb1988 committed Aug 31, 2023
1 parent f3fc040 commit e9e05f8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2Asm.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,17 @@ public void convertClass(int dexVersion, DexClassNode classNode, ClassVisitorFac
private static final Set<String> 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
Expand Down

0 comments on commit e9e05f8

Please sign in to comment.