From 329d9b4b3f19767563660efbc244333d16150f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryszard=20Wi=C5=9Bniewski?= Date: Wed, 28 Apr 2010 12:17:48 +0200 Subject: [PATCH] +Androlib.publicizeResources() --- src/brut/androlib/Androlib.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/brut/androlib/Androlib.java b/src/brut/androlib/Androlib.java index 33c62f11..162524f0 100644 --- a/src/brut/androlib/Androlib.java +++ b/src/brut/androlib/Androlib.java @@ -20,6 +20,8 @@ package brut.androlib; import brut.androlib.java.AndrolibJava; import brut.androlib.res.AndrolibResources; import brut.androlib.res.data.ResTable; +import brut.androlib.res.decoder.ARSCDecoder; +import brut.androlib.res.decoder.ARSCDecoder.FlagsOffset; import brut.androlib.res.util.ExtFile; import brut.androlib.src.SmaliBuilder; import brut.androlib.src.SmaliDecoder; @@ -28,6 +30,9 @@ import brut.directory.*; import brut.util.BrutIO; import brut.util.OS; import java.io.*; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel.MapMode; +import java.util.List; import java.util.logging.Logger; /** @@ -305,6 +310,28 @@ public class Androlib { new File(appDir, APK_DIRNAME), assetDir, false, true); } + public void publicizeResources(File arscFile) throws AndrolibException { + try { + FileInputStream in = new FileInputStream(arscFile); + List offsets = ARSCDecoder.findFlagsOffsets(in); + in.close(); + + RandomAccessFile raf = new RandomAccessFile(arscFile, "rw"); + MappedByteBuffer buf = raf.getChannel().map(MapMode.READ_WRITE, 0, arscFile.length()); + for (FlagsOffset flags : offsets) { + int offset = flags.offset + 3; + int end = offset + 4 * flags.count; + while(offset < end) { + buf.put(offset, (byte) (buf.get(offset) | (byte) 0x40)); + offset += 4; + } + } + raf.close(); + } catch (IOException ex) { + throw new AndrolibException(ex); + } + } + private boolean isModified(File working, File stored) { if (! stored.exists()) { return true;