forked from Gh0u1L5/WechatSpellbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
重写apk parser,移除了大量不必要的计算,将~70M的APK解析时间从1500~1700ms降低到大约500ms。
- Loading branch information
Em3rs0n
authored and
Em3rs0n
committed
Nov 24, 2018
1 parent
6613c8e
commit 5bf7804
Showing
7 changed files
with
306 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/com/gh0u1l5/wechatmagician/spellbook/parser/ApkFile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.gh0u1l5.wechatmagician.spellbook.parser | ||
|
||
import java.io.Closeable | ||
import java.io.File | ||
import java.nio.ByteBuffer | ||
import java.util.zip.ZipEntry | ||
import java.util.zip.ZipFile | ||
|
||
@ExperimentalUnsignedTypes | ||
class ApkFile(apkFile: File) : Closeable { | ||
companion object { | ||
const val DEX_FILE = "classes.dex" | ||
const val DEX_ADDITIONAL = "classes%d.dex" | ||
} | ||
|
||
constructor(path: String) : this(File(path)) | ||
|
||
private val zipFile: ZipFile = ZipFile(apkFile) | ||
|
||
private fun readEntry(entry: ZipEntry): ByteArray = | ||
zipFile.getInputStream(entry).use { it.readBytes() } | ||
|
||
override fun close() = | ||
zipFile.close() | ||
|
||
val classTypes: Array<String> by lazy { | ||
var ret = emptyArray<String>() | ||
for (i in 1 until 1000) { | ||
val path = if (i == 1) DEX_FILE else String.format(DEX_ADDITIONAL, i) | ||
val entry = zipFile.getEntry(path) ?: break | ||
val buffer = ByteBuffer.wrap(readEntry(entry)) | ||
ret += DexParser(buffer).parseClassTypes() | ||
} | ||
return@lazy ret | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/kotlin/com/gh0u1l5/wechatmagician/spellbook/parser/DexHeader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.gh0u1l5.wechatmagician.spellbook.parser | ||
|
||
@ExperimentalUnsignedTypes | ||
class DexHeader { | ||
var version: Int = 0 | ||
|
||
var checksum: UInt = 0u | ||
|
||
var signature: ByteArray = ByteArray(kSHA1DigestLen) | ||
|
||
var fileSize: UInt = 0u | ||
|
||
var headerSize: UInt = 0u | ||
|
||
var endianTag: UInt = 0u | ||
|
||
var linkSize: UInt = 0u | ||
|
||
var linkOff: UInt = 0u | ||
|
||
var mapOff: UInt = 0u | ||
|
||
var stringIdsSize: Int = 0 | ||
|
||
var stringIdsOff: UInt = 0u | ||
|
||
var typeIdsSize: Int = 0 | ||
|
||
var typeIdsOff: UInt = 0u | ||
|
||
var protoIdsSize: Int = 0 | ||
|
||
var protoIdsOff: UInt = 0u | ||
|
||
var fieldIdsSize: Int = 0 | ||
|
||
var fieldIdsOff: UInt = 0u | ||
|
||
var methodIdsSize: Int = 0 | ||
|
||
var methodIdsOff: UInt = 0u | ||
|
||
var classDefsSize: Int = 0 | ||
|
||
var classDefsOff: UInt = 0u | ||
|
||
var dataSize: Int = 0 | ||
|
||
var dataOff: UInt = 0u | ||
|
||
companion object { | ||
const val kSHA1DigestLen = 20 | ||
const val kSHA1DigestOutputLen = kSHA1DigestLen * 2 + 1 | ||
} | ||
} |
Oops, something went wrong.