简体   繁体   English

从本机代码访问apk中的压缩文件(从zip内部读取zip)

[英]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. 在尝试使我的应用程序的代码库(C / C ++)更具可移植性时,我想尽量减少使用android的本机AAssetManager并切换到libzip以从APK加载资源。 I had a look at libzip; 我看了一下libzip; merged it into the project and - lo and behold - I can read my files directly from the APK using libzip. 将它合并到项目中 - 并且 - 看哪 - 我可以使用libzip直接从APK中读取我的文件。

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). 现在,我想混淆我的资产(或者至少让它们访问它们非常重要),所以我想我会将它们打包成一个加密的zip存档并在APK中包含该存档(基本上是一个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? 使用本机代码直接从APK中访问存档中文件的最简单/最有效的方法是什么?

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. 我希望有类似于libzip的方法,我可以简单地指定一个文件名,然后获得一个带有未压缩数据的缓冲区。

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). 我尝试使用libzip直接从APK中打开压缩存档,但我现在空了......看来libzip只会使用目录而不是内存中的缓冲区打开一个zip文件(这就是我有)。

I suppose zlib would be an obvious choice, but I admit I have no clue how to go about it. 我认为zlib是一个明显的选择,但我承认我不知道如何去做。

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). 我还考虑过从APK复制存档,但我想浪费尽可能少的空间(很多资产==大档案)。 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. 从你的问题来看,听起来你已经过去了你的APK中的资产流,所以我会跳到这个:正如你所说,zlib是一个明显的选择。 There are tons and tons of examples online to process in-memory streams. 网上有大量的例子可以处理内存流。 For example, In Memory Decompression: GZIP . 例如, 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). 使用zlib,您还可以通过NDK获得它的好处(例如,您不需要自己构建和链接)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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