[Android] apkファイルを展開して圧縮したら元に戻ったwww

| トラックバック(0) |

「そんな事する奴おらんやろ~」的な話で申し訳ないのですが、

Android アプリのプログラム内から自身の apk ファイルを展開し、再度、(SDカードへ)圧縮してみました。

結果は見事に成功で、ちゃんとインストールできて動作します(当り前か・・・)。

※ファイルサイズが微妙に違うのは、zipalign の差?

※展開中は、1ファイル(=エントリ)毎の識別ができますので、○○だったらゴニョゴニョみたいなこともできます

※もちろん、書き換えたら署名が必要なので、その辺は自前でやるしかなさそうです^^;

 

ソースコード 

// /data/app/com.adakoda.android.ziptest.apk
String inPath = getPackageCodePath();
// /sdcard/ZipTest.apk
String outPath = Environment.getExternalStorageDirectory()
        + File.separator + "ZipTest.apk";
File inFile = new File(inPath);
File outFile = new File(outPath);
ZipInputStream inZip = null;
ZipOutputStream outZip = null;
try {
    inZip = new ZipInputStream(new BufferedInputStream(
            new FileInputStream(inFile)));
    outZip = new ZipOutputStream(new BufferedOutputStream(
            new FileOutputStream(outFile)));
    ZipEntry entry = null;
    byte[] buffer = new byte[1024];
    while ((entry = inZip.getNextEntry()) != null) {
        Log.v("entry name = ", entry.getName());
        outZip.putNextEntry(entry);
        int size = 0;
        while ((size = inZip.read(buffer, 0, buffer.length)) != -1) {
            outZip.write(buffer, 0, size);
        }
        outZip.closeEntry();
    }
    outZip.close();
    inZip.close();
} catch (IOException e) {
    e.printStackTrace();
} finally {
}

関連記事

トラックバック(0)

トラックバックURL: http://mt.adakoda.com/mt-tb.cgi/443

2016年8月

  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31