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
This commit is contained in:
Mike Anderson 2022-06-06 19:12:46 +03:00 committed by Bob Pan
parent f3fc040a09
commit e9e05f8936

View File

@ -529,8 +529,17 @@ public class Dex2Asm {
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