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 Jun 6, 2022
1 parent 63334e7 commit 0bb5e1c
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 @@ -561,8 +561,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(Constants.ASM_VERSION) {
@Override
Expand Down

0 comments on commit 0bb5e1c

Please sign in to comment.