6.3.0 - 新增 ocr / notice / s13n / Color 模块; 新增前台时保持屏幕常亮; 修复构建脚本依赖; 修复并优化控制台浮动窗口

This commit is contained in:
SuperMonster003
2023-04-29 20:07:53 +08:00
parent e2922cf8f5
commit 6ff598d587
511 changed files with 55015 additions and 11139 deletions

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2009-2013 Panxiaobo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pxb.android.arsc;
import pxb.android.axml.Util;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* dump an arsc file
*
* @author bob
*/
public class ArscDumper {
public static void dump(List<Pkg> pkgs) {
for (int x = 0; x < pkgs.size(); x++) {
Pkg pkg = pkgs.get(x);
System.out.println(String.format(" Package %d id=%d name=%s typeCount=%d", x, pkg.id, pkg.name,
pkg.types.size()));
for (Type type : pkg.types.values()) {
System.out.println(String.format(" type %d %s", type.id - 1, type.name));
int resPrefix = pkg.id << 24 | type.id << 16;
for (int i = 0; i < type.specs.length; i++) {
ResSpec spec = type.getSpec(i);
System.out.println(String.format(" spec 0x%08x 0x%08x %s", resPrefix | spec.id, spec.flags,
spec.name));
}
for (int i = 0; i < type.configs.size(); i++) {
Config config = type.configs.get(i);
System.out.println(" config");
List<ResEntry> entries = new ArrayList<ResEntry>(config.resources.values());
for (int j = 0; j < entries.size(); j++) {
ResEntry entry = entries.get(j);
System.out.println(String.format(" resource 0x%08x %-20s: %s",
resPrefix | entry.spec.id, entry.spec.name, entry.value));
}
}
}
}
}
public static void main(String... args) throws IOException {
if (args.length == 0) {
System.err.println("asrc-dump file.arsc");
return;
}
byte[] data = Util.readFile(new File(args[0]));
List<Pkg> pkgs = new ArscParser(data).parse();
dump(pkgs);
}
}

View File

@@ -0,0 +1,340 @@
/*
* Copyright (c) 2009-2013 Panxiaobo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pxb.android.arsc;
import pxb.android.ResConst;
import pxb.android.StringItems;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Read the resources.arsc inside an Android apk.
* <p/>
* Usage:
* <p/>
* <pre>
* byte[] oldArscFile= ... ; //
* List&lt;Pkg&gt; pkgs = new ArscParser(oldArscFile).parse(); // read the file
* modify(pkgs); // do what you want here
* byte[] newArscFile = new ArscWriter(pkgs).toByteArray(); // build a new file
* </pre>
* <p/>
* The format of arsc is described here (gingerbread)
* <ul>
* <li>frameworks/base/libs/utils/ResourceTypes.cpp</li>
* <li>frameworks/base/include/utils/ResourceTypes.h</li>
* </ul>
* and the cmd line <code>aapt d resources abc.apk</code> is also good for debug
* (available in android sdk)
* <p/>
* <p/>
* Todos:
* <ul>
* TODO add support to read styled strings
* </ul>
* <p/>
* <p/>
* Thanks to the the following projects
* <ul>
* <li>android4me https://code.google.com/p/android4me/</li>
* <li>Apktool https://code.google.com/p/android-apktool</li>
* <li>Android http://source.android.com/</li>
* </ul>
*
* @author bob
*/
public class ArscParser implements ResConst {
public static final int TYPE_STRING = 0x03;
/**
* If set, this resource has been declared public, so libraries are allowed
* to reference it.
*/
static final int ENGRY_FLAG_PUBLIC = 0x0002;
/**
* If set, this is a complex entry, holding a set of name/value mappings. It
* is followed by an array of ResTable_map structures.
*/
final static short ENTRY_FLAG_COMPLEX = 0x0001;
private static final boolean DEBUG = false;
private int fileSize = -1;
private ByteBuffer in;
private String[] keyNamesX;
private Pkg pkg;
private List<Pkg> pkgs = new ArrayList<Pkg>();
private String[] strings;
private String[] typeNamesX;
public ArscParser(byte[] b) {
this.in = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN);
}
private static void D(String fmt, Object... args) {
if (DEBUG) {
System.out.println(String.format(fmt, args));
}
}
public List<Pkg> parse() throws IOException {
if (fileSize < 0) {
Chunk head = new Chunk();
if (head.type != RES_TABLE_TYPE) {
throw new RuntimeException();
}
fileSize = head.size;
in.getInt();// packagecount
}
while (in.hasRemaining()) {
Chunk chunk = new Chunk();
switch (chunk.type) {
case RES_STRING_POOL_TYPE:
strings = StringItems.read(in);
if (DEBUG) {
for (int i = 0; i < strings.length; i++) {
D("STR [%08x] %s", i, strings[i]);
}
}
break;
case RES_TABLE_PACKAGE_TYPE:
readPackage(in);
}
in.position(chunk.location + chunk.size);
}
return pkgs;
}
private void readEntry(Config config, ResSpec spec) {
D("[%08x]read ResTable_entry", in.position());
int size = in.getShort();
D("ResTable_entry %d", size);
int flags = in.getShort(); // ENTRY_FLAG_PUBLIC
int keyStr = in.getInt();
spec.updateName(keyNamesX[keyStr]);
ResEntry resEntry = new ResEntry(flags, spec);
if (0 != (flags & ENTRY_FLAG_COMPLEX)) {
int parent = in.getInt();
int count = in.getInt();
BagValue bag = new BagValue(parent);
for (int i = 0; i < count; i++) {
Map.Entry<Integer, Value> entry = new AbstractMap.SimpleEntry(in.getInt(), readValue());
bag.map.add(entry);
}
resEntry.value = bag;
} else {
resEntry.value = readValue();
}
config.resources.put(spec.id, resEntry);
}
// private void readConfigFlags() {
// int size = in.getInt();
// if (size < 28) {
// throw new RuntimeException();
// }
// short mcc = in.getShort();
// short mnc = in.getShort();
//
// char[] language = new char[] { (char) in.get(), (char) in.get() };
// char[] country = new char[] { (char) in.get(), (char) in.get() };
//
// byte orientation = in.get();
// byte touchscreen = in.get();
// short density = in.getShort();
//
// byte keyboard = in.get();
// byte navigation = in.get();
// byte inputFlags = in.get();
// byte inputPad0 = in.get();
//
// short screenWidth = in.getShort();
// short screenHeight = in.getShort();
//
// short sdkVersion = in.getShort();
// short minorVersion = in.getShort();
//
// byte screenLayout = 0;
// byte uiMode = 0;
// short smallestScreenWidthDp = 0;
// if (size >= 32) {
// screenLayout = in.get();
// uiMode = in.get();
// smallestScreenWidthDp = in.getShort();
// }
//
// short screenWidthDp = 0;
// short screenHeightDp = 0;
//
// if (size >= 36) {
// screenWidthDp = in.getShort();
// screenHeightDp = in.getShort();
// }
//
// short layoutDirection = 0;
// if (size >= 38 && sdkVersion >= 17) {
// layoutDirection = in.getShort();
// }
//
// }
private void readPackage(ByteBuffer in) throws IOException {
int pid = in.getInt() % 0xFF;
String name;
{
int nextPisition = in.position() + 128 * 2;
StringBuilder sb = new StringBuilder(32);
for (int i = 0; i < 128; i++) {
int s = in.getShort();
if (s == 0) {
break;
} else {
sb.append((char) s);
}
}
name = sb.toString();
in.position(nextPisition);
}
pkg = new Pkg(pid, name);
pkgs.add(pkg);
int typeStringOff = in.getInt();
int typeNameCount = in.getInt();
int keyStringOff = in.getInt();
int specNameCount = in.getInt();
{
Chunk chunk = new Chunk();
if (chunk.type != RES_STRING_POOL_TYPE) {
throw new RuntimeException();
}
typeNamesX = StringItems.read(in);
in.position(chunk.location + chunk.size);
}
{
Chunk chunk = new Chunk();
if (chunk.type != RES_STRING_POOL_TYPE) {
throw new RuntimeException();
}
keyNamesX = StringItems.read(in);
if (DEBUG) {
for (int i = 0; i < keyNamesX.length; i++) {
D("STR [%08x] %s", i, keyNamesX[i]);
}
}
in.position(chunk.location + chunk.size);
}
out:
while (in.hasRemaining()) {
Chunk chunk = new Chunk();
switch (chunk.type) {
case RES_TABLE_TYPE_SPEC_TYPE: {
D("[%08x]read spec", in.position() - 8);
int tid = in.get() & 0xFF;
in.get(); // res0
in.getShort();// res1
int entryCount = in.getInt();
Type t = pkg.getType(tid, typeNamesX[tid - 1], entryCount);
for (int i = 0; i < entryCount; i++) {
t.getSpec(i).flags = in.getInt();
}
}
break;
case RES_TABLE_TYPE_TYPE: {
D("[%08x]read config", in.position() - 8);
int tid = in.get() & 0xFF;
in.get(); // res0
in.getShort();// res1
int entryCount = in.getInt();
Type t = pkg.getType(tid, typeNamesX[tid - 1], entryCount);
int entriesStart = in.getInt();
D("[%08x]read config id", in.position());
int p = in.position();
int size = in.getInt();
// readConfigFlags();
byte[] data = new byte[size];
in.position(p);
in.get(data);
Config config = new Config(data, entryCount);
in.position(chunk.location + chunk.headSize);
D("[%08x]read config entry offset", in.position());
int[] entrys = new int[entryCount];
for (int i = 0; i < entryCount; i++) {
entrys[i] = in.getInt();
}
D("[%08x]read config entrys", in.position());
for (int i = 0; i < entrys.length; i++) {
if (entrys[i] != -1) {
in.position(chunk.location + entriesStart + entrys[i]);
ResSpec spec = t.getSpec(i);
readEntry(config, spec);
}
}
t.addConfig(config);
}
break;
default:
break out;
}
in.position(chunk.location + chunk.size);
}
}
private Object readValue() {
int size1 = in.getShort();// 8
int zero = in.get();// 0
int type = in.get() & 0xFF; // TypedValue.*
int data = in.getInt();
String raw = null;
if (type == TYPE_STRING) {
raw = strings[data];
}
return new Value(type, data, raw);
}
/* pkg */class Chunk {
public final int headSize;
public final int location;
public final int size;
public final int type;
public Chunk() {
location = in.position();
type = in.getShort() & 0xFFFF;
headSize = in.getShort() & 0xFFFF;
size = in.getInt();
D("[%08x]type: %04x, headsize: %04x, size:%08x", location, type, headSize, size);
}
}
}

View File

@@ -0,0 +1,395 @@
/*
* Copyright (c) 2009-2013 Panxiaobo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pxb.android.arsc;
import pxb.android.ResConst;
import pxb.android.StringItem;
import pxb.android.StringItems;
import pxb.android.axml.Util;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.*;
/**
* Write pkgs to an arsc file
*
* @author bob
* @see ArscParser
*/
public class ArscWriter implements ResConst {
private List<PkgCtx> ctxs = new ArrayList<PkgCtx>(5);
private List<Pkg> pkgs;
private Map<String, StringItem> strTable = new TreeMap<String, StringItem>();
private StringItems strTable0 = new StringItems();
public ArscWriter(List<Pkg> pkgs) {
this.pkgs = pkgs;
}
private static void D(String fmt, Object... args) {
}
public static void main(String... args) throws IOException {
if (args.length < 2) {
System.err.println("asrc-write-test in.arsc out.arsc");
return;
}
byte[] data = Util.readFile(new File(args[0]));
List<Pkg> pkgs = new ArscParser(data).parse();
// ArscDumper.dump(pkgs);
byte[] data2 = new ArscWriter(pkgs).toByteArray();
// ArscDumper.dump(new ArscParser(data2).parse());
Util.writeFile(data2, new File(args[1]));
}
private void addString(String str) {
if (strTable.containsKey(str)) {
return;
}
StringItem stringItem = new StringItem(str);
strTable.put(str, stringItem);
strTable0.add(stringItem);
}
private int count() {
int size = 0;
size += 8 + 4;// chunk, pkgcount
{
int stringSize = strTable0.getSize();
if (stringSize % 4 != 0) {
stringSize += 4 - stringSize % 4;
}
size += 8 + stringSize;// global strings
}
for (PkgCtx ctx : ctxs) {
ctx.offset = size;
int pkgSize = 0;
pkgSize += 8 + 4 + 256;// chunk,pid+name
pkgSize += 4 * 4;
ctx.typeStringOff = pkgSize;
{
int stringSize = ctx.typeNames0.getSize();
if (stringSize % 4 != 0) {
stringSize += 4 - stringSize % 4;
}
pkgSize += 8 + stringSize;// type names
}
ctx.keyStringOff = pkgSize;
{
int stringSize = ctx.keyNames0.getSize();
if (stringSize % 4 != 0) {
stringSize += 4 - stringSize % 4;
}
pkgSize += 8 + stringSize;// key names
}
for (Type type : ctx.pkg.types.values()) {
type.wPosition = size + pkgSize;
pkgSize += 8 + 4 + 4 + 4 * type.specs.length; // trunk,id,entryCount,
// configs
for (Config config : type.configs) {
config.wPosition = pkgSize + size;
int configBasePostion = pkgSize;
pkgSize += 8 + 4 + 4 + 4; // trunk,id,entryCount,entriesStart
int size0 = config.id.length;
if (size0 % 4 != 0) {
size0 += 4 - size0 % 4;
}
pkgSize += size0;// config
if (pkgSize - configBasePostion > 0x0038) {
throw new RuntimeException("config id too big");
} else {
pkgSize = configBasePostion + 0x0038;
}
pkgSize += 4 * config.entryCount;// offset
config.wEntryStart = pkgSize - configBasePostion;
int entryBase = pkgSize;
for (ResEntry e : config.resources.values()) {
e.wOffset = pkgSize - entryBase;
pkgSize += 8;// size,flag,keyString
if (e.value instanceof BagValue) {
BagValue big = (BagValue) e.value;
pkgSize += 8 + big.map.size() * 12;
} else {
pkgSize += 8;
}
}
config.wChunkSize = pkgSize - configBasePostion;
}
}
ctx.pkgSize = pkgSize;
size += pkgSize;
}
return size;
}
private List<PkgCtx> prepare() throws IOException {
for (Pkg pkg : pkgs) {
PkgCtx ctx = new PkgCtx();
ctx.pkg = pkg;
ctxs.add(ctx);
for (Type type : pkg.types.values()) {
ctx.addTypeName(type.id - 1, type.name);
for (ResSpec spec : type.specs) {
ctx.addKeyName(spec.name);
}
for (Config config : type.configs) {
for (ResEntry e : config.resources.values()) {
Object object = e.value;
if (object instanceof BagValue) {
travelBagValue((BagValue) object);
} else {
travelValue((Value) object);
}
}
}
}
ctx.keyNames0.prepare();
ctx.typeNames0.addAll(ctx.typeNames);
ctx.typeNames0.prepare();
}
strTable0.prepare();
return ctxs;
}
public byte[] toByteArray() throws IOException {
prepare();
int size = count();
ByteBuffer out = ByteBuffer.allocate(size).order(ByteOrder.LITTLE_ENDIAN);
write(out, size);
return out.array();
}
private void travelBagValue(BagValue bag) {
for (Map.Entry<Integer, Value> e : bag.map) {
travelValue(e.getValue());
}
}
private void travelValue(Value v) {
if (v.raw != null) {
addString(v.raw);
}
}
private void write(ByteBuffer out, int size) throws IOException {
out.putInt(RES_TABLE_TYPE | (0x000c << 16));
out.putInt(size);
out.putInt(ctxs.size());
{
int stringSize = strTable0.getSize();
int padding = 0;
if (stringSize % 4 != 0) {
padding = 4 - stringSize % 4;
}
out.putInt(RES_STRING_POOL_TYPE | (0x001C << 16));
out.putInt(stringSize + padding + 8);
strTable0.write(out);
out.put(new byte[padding]);
}
for (PkgCtx pctx : ctxs) {
if (out.position() != pctx.offset) {
throw new RuntimeException();
}
final int basePosition = out.position();
out.putInt(RES_TABLE_PACKAGE_TYPE | (0x011c << 16));
out.putInt(pctx.pkgSize);
out.putInt(pctx.pkg.id);
int p = out.position();
out.put(pctx.pkg.name.getBytes("UTF-16LE"));
out.position(p + 256);
out.putInt(pctx.typeStringOff);
out.putInt(pctx.typeNames0.size());
out.putInt(pctx.keyStringOff);
out.putInt(pctx.keyNames0.size());
{
if (out.position() - basePosition != pctx.typeStringOff) {
throw new RuntimeException();
}
int stringSize = pctx.typeNames0.getSize();
int padding = 0;
if (stringSize % 4 != 0) {
padding = 4 - stringSize % 4;
}
out.putInt(RES_STRING_POOL_TYPE | (0x001C << 16));
out.putInt(stringSize + padding + 8);
pctx.typeNames0.write(out);
out.put(new byte[padding]);
}
{
if (out.position() - basePosition != pctx.keyStringOff) {
throw new RuntimeException();
}
int stringSize = pctx.keyNames0.getSize();
int padding = 0;
if (stringSize % 4 != 0) {
padding = 4 - stringSize % 4;
}
out.putInt(RES_STRING_POOL_TYPE | (0x001C << 16));
out.putInt(stringSize + padding + 8);
pctx.keyNames0.write(out);
out.put(new byte[padding]);
}
for (Type t : pctx.pkg.types.values()) {
D("[%08x]write spec", out.position(), t.name);
if (t.wPosition != out.position()) {
throw new RuntimeException();
}
out.putInt(RES_TABLE_TYPE_SPEC_TYPE | (0x0010 << 16));
out.putInt(4 * 4 + 4 * t.specs.length);// size
out.putInt(t.id);
out.putInt(t.specs.length);
for (ResSpec spec : t.specs) {
out.putInt(spec.flags);
}
for (Config config : t.configs) {
D("[%08x]write config", out.position());
int typeConfigPosition = out.position();
if (config.wPosition != typeConfigPosition) {
throw new RuntimeException();
}
out.putInt(RES_TABLE_TYPE_TYPE | (0x0038 << 16));
out.putInt(config.wChunkSize);// size
out.putInt(t.id);
out.putInt(t.specs.length);
out.putInt(config.wEntryStart);
D("[%08x]write config ids", out.position());
out.put(config.id);
int size0 = config.id.length;
int padding = 0;
if (size0 % 4 != 0) {
padding = 4 - size0 % 4;
}
out.put(new byte[padding]);
out.position(typeConfigPosition + 0x0038);
D("[%08x]write config entry offsets", out.position());
for (int i = 0; i < config.entryCount; i++) {
ResEntry entry = config.resources.get(i);
if (entry == null) {
out.putInt(-1);
} else {
out.putInt(entry.wOffset);
}
}
if (out.position() - typeConfigPosition != config.wEntryStart) {
throw new RuntimeException();
}
D("[%08x]write config entrys", out.position());
for (ResEntry e : config.resources.values()) {
D("[%08x]ResTable_entry", out.position());
boolean isBag = e.value instanceof BagValue;
out.putShort((short) (isBag ? 16 : 8));
int flag = e.flag;
if (isBag) { // add complex flag
flag |= ArscParser.ENTRY_FLAG_COMPLEX;
} else { // remove
flag &= ~ArscParser.ENTRY_FLAG_COMPLEX;
}
out.putShort((short) flag);
out.putInt(pctx.keyNames.get(e.spec.name).index);
if (isBag) {
BagValue bag = (BagValue) e.value;
out.putInt(bag.parent);
out.putInt(bag.map.size());
for (Map.Entry<Integer, Value> entry : bag.map) {
out.putInt(entry.getKey());
writeValue(entry.getValue(), out);
}
} else {
writeValue((Value) e.value, out);
}
}
}
}
}
}
private void writeValue(Value value, ByteBuffer out) {
out.putShort((short) 8);
out.put((byte) 0);
out.put((byte) value.type);
if (value.type == ArscParser.TYPE_STRING) {
out.putInt(strTable.get(value.raw).index);
} else {
out.putInt(value.data);
}
}
private static class PkgCtx {
public int keyStringOff;
Map<String, StringItem> keyNames = new HashMap<String, StringItem>();
StringItems keyNames0 = new StringItems();
int offset;
Pkg pkg;
int pkgSize;
List<StringItem> typeNames = new ArrayList<StringItem>();
StringItems typeNames0 = new StringItems();
int typeStringOff;
public void addKeyName(String name) {
if (keyNames.containsKey(name)) {
return;
}
StringItem stringItem = new StringItem(name);
keyNames.put(name, stringItem);
keyNames0.add(stringItem);
}
public void addTypeName(int id, String name) {
while (typeNames.size() <= id) {
typeNames.add(null);
}
StringItem item = typeNames.get(id);
if (item == null) {
typeNames.set(id, new StringItem(name));
} else {
throw new RuntimeException();
}
}
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2009-2013 Panxiaobo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pxb.android.arsc;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class BagValue {
public final int parent;
public List<Entry<Integer, Value>> map = new ArrayList<Entry<Integer, Value>>();
public BagValue(int parent) {
this.parent = parent;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof BagValue))
return false;
BagValue other = (BagValue) obj;
if (map == null) {
if (other.map != null)
return false;
} else if (!map.equals(other.map))
return false;
if (parent != other.parent)
return false;
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((map == null) ? 0 : map.hashCode());
result = prime * result + parent;
return result;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(String.format("{bag%08x", parent));
for (Entry<Integer, Value> e : map) {
sb.append(",").append(String.format("0x%08x", e.getKey()));
sb.append("=");
sb.append(e.getValue());
}
return sb.append("}").toString();
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2009-2013 Panxiaobo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pxb.android.arsc;
import java.util.Map;
import java.util.TreeMap;
public class Config {
public final int entryCount;
public final byte[] id;
public Map<Integer, ResEntry> resources = new TreeMap<Integer, ResEntry>();
/* package */ int wChunkSize;
/* package */ int wEntryStart;
/* package */ int wPosition;
public Config(byte[] id, int entryCount) {
super();
this.id = id;
this.entryCount = entryCount;
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2009-2013 Panxiaobo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pxb.android.arsc;
import java.util.TreeMap;
public class Pkg {
public final int id;
public String name;
public TreeMap<Integer, Type> types = new TreeMap<Integer, Type>();
public Pkg(int id, String name) {
super();
this.id = id;
this.name = name;
}
public Type getType(int tid, String name, int entrySize) {
Type type = types.get(tid);
if (type != null) {
if (name != null) {
if (type.name == null) {
type.name = name;
} else if (!name.endsWith(type.name)) {
throw new RuntimeException();
}
if (type.specs.length != entrySize) {
throw new RuntimeException();
}
}
} else {
type = new Type();
type.id = tid;
type.name = name;
type.specs = new ResSpec[entrySize];
types.put(tid, type);
}
return type;
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2009-2013 Panxiaobo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pxb.android.arsc;
public class ResEntry {
public final int flag;
public final ResSpec spec;
/**
* {@link BagValue} or {@link Value}
*/
public Object value;
/* package */ int wOffset;
public ResEntry(int flag, ResSpec spec) {
super();
this.flag = flag;
this.spec = spec;
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2009-2013 Panxiaobo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pxb.android.arsc;
public class ResSpec {
public final int id;
public int flags;
public String name;
public ResSpec(int id) {
super();
this.id = id;
}
public void updateName(String s) {
String name = this.name;
if (name == null) {
this.name = s;
} else if (!s.equals(name)) {
throw new RuntimeException();
}
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2009-2013 Panxiaobo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pxb.android.arsc;
import java.util.ArrayList;
import java.util.List;
public class Type {
public List<Config> configs = new ArrayList<Config>();
public int id;
public String name;
public ResSpec[] specs;
/* package */ int wPosition;
public void addConfig(Config config) {
if (config.entryCount != specs.length) {
throw new RuntimeException();
}
configs.add(config);
}
public ResSpec getSpec(int resId) {
ResSpec res = specs[resId];
if (res == null) {
res = new ResSpec(resId);
specs[resId] = res;
}
return res;
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2009-2013 Panxiaobo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pxb.android.arsc;
public class Value {
public final int data;
public final int type;
public String raw;
public Value(int type, int data, String raw) {
super();
this.type = type;
this.data = data;
this.raw = raw;
}
public String toString() {
if (type == 0x03) {
return raw;
}
return String.format("{t=0x%02x d=0x%08x}", type, data);
}
}