Moved publicizeResources() implementation to AndrolibResources.

This commit is contained in:
Ryszard Wiśniewski 2010-06-02 13:27:42 +02:00
parent be3743e967
commit 58e7d6960f
2 changed files with 43 additions and 23 deletions

View File

@ -21,8 +21,6 @@ import brut.androlib.java.AndrolibJava;
import brut.androlib.res.AndrolibResources;
import brut.androlib.res.data.ResPackage;
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;
@ -31,8 +29,6 @@ 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.Map;
import java.util.logging.Logger;
@ -346,25 +342,7 @@ public class Androlib {
}
public void publicizeResources(File arscFile) throws AndrolibException {
try {
FileInputStream in = new FileInputStream(arscFile);
List<FlagsOffset> 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);
}
mAndRes.publicizeResources(arscFile);
}
public boolean isFrameworkApk(ResTable resTable) {

View File

@ -22,6 +22,7 @@ import brut.androlib.err.CantFindFrameworkResException;
import brut.androlib.res.data.*;
import brut.androlib.res.data.value.ResXmlSerializable;
import brut.androlib.res.decoder.*;
import brut.androlib.res.decoder.ARSCDecoder.FlagsOffset;
import brut.androlib.res.util.ExtFile;
import brut.androlib.res.util.ExtMXSerializer;
import brut.common.BrutException;
@ -346,6 +347,47 @@ final public class AndrolibResources {
throw new CantFindFrameworkResException(id);
}
public void publicizeResources(File arscFile) throws AndrolibException {
byte[] data = new byte[(int) arscFile.length()];
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(arscFile);
in.read(data);
publicizeResources(data);
out = new FileOutputStream(arscFile);
out.write(data);
} catch (IOException ex) {
throw new AndrolibException(ex);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ex) {}
}
if (out != null) {
try {
out.close();
} catch (IOException ex) {}
}
}
}
public void publicizeResources(byte[] arsc) throws AndrolibException {
for (FlagsOffset flags :
ARSCDecoder.findFlagsOffsets(new ByteArrayInputStream(arsc))) {
int offset = flags.offset + 3;
int end = offset + 4 * flags.count;
while(offset < end) {
arsc[offset] |= (byte) 0x40;
offset += 4;
}
}
}
private File getFrameworkDir() throws AndrolibException {
File dir = new File(System.getProperty("user.home") +
File.separatorChar + "apktool" + File.separatorChar + "framework");