编程编辑在java中的apk文件 [英] Programmatically editing apk files in java

查看:108
本文介绍了编程编辑在java中的apk文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题变得有点复杂,所以请多多包涵:
我有我试图在安装后编程修改apk文件。我与其他应用进行编辑。我第一次尝试用内置的Java类的压缩文件管理要做到这一点,但是当我试图把所有的文件完全照搬除非我想修改,改变我要修改的应用程序将不再运行该文件的文件。我想这是因为签约什么的,但是当我用WinRAR同样的事情(解压缩所有文件,创建一个新的zip压缩文件,所有文件复制到正常的COM pression新的zip压缩包)的和SSH新的APK成我的/数据/ app文件夹,它工作正常。我的问题是为什么发生这种情况。我想这可能与拉链头之类的东西做的没有任何人有什么想法?

This question gets a little complicated so please bear with me: I have an apk file I am attempting to modify programmatically after installation. I am editing it with another app. I first attempted to do this with the built in java classes for zip file management but when i attempt to completely copy all the files except the file i want to modify and change the file i want to modify the app will not run anymore. I assume this is because of signing or something but when I do the same thing with winRAR (unzip all files, create a new zip archive, copy all files into new zip archive with normal compression) and ssh the new apk into my /data/app folder, it works fine. My question is why this is happening. I think it may have to do with zip headers or something like that does anyone have any ideas?

PS:这是我使用的Java进程的一个例子重新写zip文件:

PS: this is an example of the java process i am using to re-write the zip file:

p = Runtime.getRuntime().exec("su");
ZipInputStream in = new ZipInputStream(new FileInputStream("This is the apk containing the asset I want to use to replace the other asset"));
ZipEntry e;
while((e = in.getNextEntry()) != null)
{
    if(e.getName().equals("asset i want to use to replace the other asset"))
        break;
}
ZipOutputStream out = new ZipOutputStream(new FileOutputStream("the output zip file"));
ZipInputStream original = new ZipInputStream(new FileInputStream("the apk i am trying to modify"));
ZipEntry f;
byte[] buf = new byte[1024];
while((f = original.getNextEntry()) != null)
{
    if(!f.getName().equals("the asset i want to replace"))
    {
        out.putNextEntry(new ZipEntry(f.getName()));
        int len;
        while ((len = original.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        original.closeEntry();
        out.closeEntry();
    }
    else
    {
        out.putNextEntry(new ZipEntry(e.getName()));
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        out.closeEntry();
    }
}
in.close();
out.close();
original.close();

我已经在Android系统和Windows使用常规的软件运行过程中,我可以打开在Wi​​nRAR的输出,它似乎是除了资源文件我改变了一样。

I have run this process on the android system and on windows using regular software, i can open the output in winRAR and it appears to be the same except for the asset file i changed.

推荐答案

的唯一一件事你应该知道的是如何运作签署的apk工具(变通校验和 - 他们是ZIP条目的目标文件夹是META-INF与CERT .RSA - 有present EN codeD校验和调试其他信息,CERT.SF和MANIFEST.MF - 与SHA1消化 - Base64的EN codeD哈希(它们很容易自行检测))。
但是,这是一个真正的黑客!这code可能是有用的(以及许多聪明的程序员用于为前dinamically更改应用程序的图片),并可能是危险的 - 因为你的APK文件可提高到GB的大小 - 如果你写了这么

The only one thing you should know is how works signing apk tool (work around check sums - they are zip entries. A target folder is META-INF with CERT.RSA - there's present encoded checksum and else debug info, CERT.SF and MANIFEST.MF - with SHA1-Digest - Base64 encoded hashes (they are easy to detect by yourself)). But this is a real hacking! That code can be useful (and used by many "smart programmers" for dinamically changing of picture of application for ex.) and can be dangerous - because your apk file can be increased to GB sizes - if you'll write so.

这招不应该是世界性的comunity人之间采用S preaded,我认为 - 它会保存在程序员短圆

This trick shouldn't be spreaded between world-wide comunity people and I think - it will be kept in short circles of programmers.

这篇关于编程编辑在java中的apk文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆