2014-02-11 52 views
0

我想知道是否可以使用BasicDexFileReader的解析方法來加載解密成字節數組的dexfile?BasicDexFileReader的解析方法

public void parse(byte[] dexBytes) throws IllegalArgumentException, IOException/*, 
    RefNotFoundException */ { 
      // Get a DalvikValueReader on the input stream. 
      reader = new DalvikValueReader(dexBytes, FILE_SIZE_OFFSET); 
      readHeader(); 
      readStrings(); 
      readTypes(); 
    } 

我會很高興,如果有人能解釋什麼是解析方法的目的,可以用我的方式使用它。

感謝

回答

1

看看DexMaker.java,需要解決這個問題,用於生成代碼,而不是對其進行解密。

下面是相關示例:

byte[] dex = ...; 

    /* 
    * This implementation currently dumps the dex to the filesystem. It 
    * jars the emitted .dex for the benefit of Gingerbread and earlier 
    * devices, which can't load .dex files directly. 
    * 
    * TODO: load the dex from memory where supported. 
    */ 
    File result = File.createTempFile("Generated", ".jar", dexCache); 
    result.deleteOnExit(); 
    JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(result)); 
    jarOut.putNextEntry(new JarEntry(DexFormat.DEX_IN_JAR_NAME)); 
    jarOut.write(dex); 
    jarOut.closeEntry(); 
    jarOut.close(); 
    try { 
     return (ClassLoader) Class.forName("dalvik.system.DexClassLoader") 
       .getConstructor(String.class, String.class, String.class, ClassLoader.class) 
       .newInstance(result.getPath(), dexCache.getAbsolutePath(), null, parent); 
    } catch (ClassNotFoundException e) { 
     throw new UnsupportedOperationException("load() requires a Dalvik VM", e); 
    } catch (InvocationTargetException e) { 
     throw new RuntimeException(e.getCause()); 
    } catch (InstantiationException e) { 
     throw new AssertionError(); 
    } catch (NoSuchMethodException e) { 
     throw new AssertionError(); 
    } catch (IllegalAccessException e) { 
     throw new AssertionError(); 
    } 
+0

感謝您的回覆,但你能解釋一下多一點。說我有一個加密的dex,我想通過bytearray加載它..它有可能嗎? – Shoaib

+0

你自己解密。一旦你有一個解密的字節[],你可以使用上面的代碼。 –