从Android设备上的代码访问APK内容

发布于 2024-12-08 12:38:38 字数 757 浏览 3 评论 0原文

我需要从设备上运行的同一应用程序的代码访问我的应用程序 APK 的内容。 我编写的这段代码运行良好,并在我的 2.2 和 2.3.3 设备上返回数据。

但是这是合法的方式吗?它适用于从2.1开始到任何未来或现有版本的所有版本吗?

主要原因是检测apk原始签名或重新打包的apk。

这是我访问 META-INF/CERT.RSA 的代码:

    String path = this.getApplication().getPackageCodePath();
    try
    {
        ZipFile zfile = new ZipFile(path);
        ZipEntry zentry = zfile.getEntry("META-INF/CERT.RSA");
        long siz = zentry.getSize();

        byte[] buf=new byte[(int) siz];
        InputStream istream = zfile.getInputStream(zentry);

        int ret = istream.read(buf);
        istream.close();

    }
    catch (IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

提前谢谢您

I need to access contents of my application APK from the code of this same application running on device.
I wrote this code that works perferctly well and return the datа on my 2.2 and 2.3.3 devices.

But Is it a legal way and will it work on all versions starting from 2.1 to any future or existing version?

The main reason is to detect apk original signature or repacked apk.

Here is my code of accessing META-INF/CERT.RSA:

    String path = this.getApplication().getPackageCodePath();
    try
    {
        ZipFile zfile = new ZipFile(path);
        ZipEntry zentry = zfile.getEntry("META-INF/CERT.RSA");
        long siz = zentry.getSize();

        byte[] buf=new byte[(int) siz];
        InputStream istream = zfile.getInputStream(zentry);

        int ret = istream.read(buf);
        istream.close();

    }
    catch (IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

◇流星雨 2024-12-15 12:38:38

是的,这会起作用。

目前它适用于最新的 Android 3.2,并且该方法中没有任何方法被标记为已弃用。

Yes, this will work.

At present it works up to latest Android 3.2, and no method from this approach is marked as deprecated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文