简体   繁体   中英

Accessing a compressed file in an apk from native code (read a zip from inside a zip)

The background:

In trying to make the codebase (C/C++) for my app more portable, I would like to minimize my use of android's native AAssetManager and switch to libzip for loading assets from the APK. I had a look at libzip; merged it into the project and - lo and behold - I can read my files directly from the APK using libzip.

Now, I would like to obfuscate my assets (or at least make access to them non-trivial), so I thought I'd package them into an encrypted zip archive and include that archive in the APK (basically, a zip in a zip).

My question:

What would be the easiest/most effective way to access the files in the archive directly from within the APK using native code?

I was hoping for a similar approach as with libzip, where I can simply specify a filename and then get a buffer with uncompressed data.

I have tried opening the compressed archive directly from within the APK using libzip, but I'm coming up empty... it appears libzip will only open a zip file using a directory and not from a buffer in memory (which is as far as I got).

I suppose zlib would be an obvious choice, but I admit I have no clue how to go about it.

I also thought about copying the archive out of the APK, but I would like to waste as little space as possible (lots of assets == big archive). Delivery of the assets as a separate download is also something I'd like to avoid.

Helpful suggestions or pointers are welcome.

From your question it sounds like you've already got past getting to the asset stream in your APK, so I'll jump right to this: As you say, zlib is an obvious choice. There are tons and tons of examples online to process in-memory streams. For example, In Memory Decompression: GZIP . With zlib you also have the benefit that it's already available via the NDK (eg you don't need to build and link in your own).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM