この質問は少し複雑になるので、ご容赦ください。インストール後にプログラムで変更しようとしている apk ファイルがあります。別のアプリで編集しています。最初に、zip ファイル管理用に組み込みの Java クラスを使用してこれを実行しようとしましたが、変更したいファイルを除くすべてのファイルを完全にコピーして、変更したいファイルを変更しようとすると、アプリが実行されなくなります。これは署名か何かによるものだと思いますが、winRAR で同じことを行うと (すべてのファイルを解凍し、新しい zip アーカイブを作成し、すべてのファイルを通常の圧縮で新しい zip アーカイブにコピーします)、新しい apk を /data/ に ssh します。 app フォルダ、正常に動作します。私の質問は、なぜこれが起こっているのかです。zipヘッダーなどに関係していると思いますが、何かアイデアはありますか?
PS: これは、zip ファイルを書き直すために使用している Java プロセスの例です。
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 で通常のソフトウェアを使用して実行しました。出力を winRAR で開くことができ、変更したアセット ファイルを除いて同じように見えます。