diff --git a/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java b/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java index 8dd32592..8c82e8bd 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java +++ b/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java @@ -112,7 +112,6 @@ final public class AndrolibResources { Duo duo = getManifestFileDecoder(); ResFileDecoder fileDecoder = duo.m1; - // Set ResAttrDecoder duo.m2.setAttrDecoder(new ResAttrDecoder()); ResAttrDecoder attrDecoder = duo.m2.getAttrDecoder(); @@ -539,8 +538,17 @@ final public class AndrolibResources { } private File getFrameworkDir() throws AndrolibException { - File dir = new File(System.getProperty("user.home") + - File.separatorChar + "apktool" + File.separatorChar + "framework"); + String path; + + /* store in user-home, for Mac OS X */ + if (System.getProperty("os.name").equals("Mac OS X")) { + path = System.getProperty("user.home") + File.separatorChar + + "Library/Application Support/apktool/framework"; } + else { + path = System.getProperty("user.home") + File.separatorChar + + "apktool" + File.separatorChar + "framework"; + } + File dir = new File(path); if (! dir.exists()) { if (! dir.mkdirs()) { throw new AndrolibException("Can't create directory: " + dir); diff --git a/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java b/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java index a8c4fbec..cc5bf6dd 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java +++ b/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java @@ -21,6 +21,7 @@ import brut.androlib.AndrolibException; import brut.androlib.res.data.*; import brut.androlib.res.data.value.*; import brut.util.Duo; +import brut.androlib.res.data.ResTable; import brut.util.ExtDataInput; import com.mindprod.ledatastream.LEDataInputStream; import java.io.*; @@ -247,13 +248,13 @@ public class ARSCDecoder { byte keyboard = mIn.readByte(); byte navigation = mIn.readByte(); byte inputFlags = mIn.readByte(); - mIn.skipBytes(1); + /*inputPad0*/ mIn.skipBytes(1); short screenWidth = mIn.readShort(); short screenHeight = mIn.readShort(); short sdkVersion = mIn.readShort(); - mIn.skipBytes(2); + /*minorVersion, now must always be 0*/ mIn.skipBytes(2); byte screenLayout = 0; byte uiMode = 0; @@ -273,7 +274,7 @@ public class ARSCDecoder { } if (size >= 40) { - mIn.skipBytes(2); + // mIn.skipBytes(2); } int exceedingSize = size - KNOWN_CONFIG_BYTES; @@ -400,7 +401,7 @@ public class ARSCDecoder { private static final Logger LOGGER = Logger.getLogger(ARSCDecoder.class.getName()); - private static final int KNOWN_CONFIG_BYTES = 36; // 42 now. Just need to map them out. + private static final int KNOWN_CONFIG_BYTES = 36; public static class ARSCData { diff --git a/apktool-lib/src/main/java/brut/androlib/res/decoder/XmlPullStreamDecoder.java b/apktool-lib/src/main/java/brut/androlib/res/decoder/XmlPullStreamDecoder.java index 073c343e..c7f21466 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/decoder/XmlPullStreamDecoder.java +++ b/apktool-lib/src/main/java/brut/androlib/res/decoder/XmlPullStreamDecoder.java @@ -17,11 +17,13 @@ package brut.androlib.res.decoder; import brut.androlib.AndrolibException; +import brut.androlib.res.data.ResTable; import brut.androlib.res.util.ExtXmlSerializer; import java.io.*; import java.util.logging.Logger; import org.xmlpull.v1.*; import org.xmlpull.v1.wrapper.*; +import org.xmlpull.v1.wrapper.classic.StaticXmlSerializerWrapper; /** * @author Ryszard Wiśniewski @@ -38,7 +40,56 @@ public class XmlPullStreamDecoder implements ResStreamDecoder { try { XmlPullWrapperFactory factory = XmlPullWrapperFactory.newInstance(); XmlPullParserWrapper par = factory.newPullParserWrapper(mParser); - XmlSerializerWrapper ser = factory.newSerializerWrapper(mSerial); + final ResTable resTable = ((AXmlResourceParser)mParser).getAttrDecoder().getCurrentPackage().getResTable(); + + XmlSerializerWrapper ser = new StaticXmlSerializerWrapper(mSerial, factory){ + boolean hideSdkInfo = false; + @Override + public void event(XmlPullParser pp) throws XmlPullParserException, IOException { + int type = pp.getEventType(); + + if (type == XmlPullParser.START_TAG) { + if ("uses-sdk".equalsIgnoreCase(pp.getName())) { + try { + hideSdkInfo = parseAttr(pp); + if(hideSdkInfo) { + return; + } + } catch (AndrolibException e) {} + } + } else if (hideSdkInfo && type == XmlPullParser.END_TAG && + "uses-sdk".equalsIgnoreCase(pp.getName())) { + return; + } + super.event(pp); + } + + private boolean parseAttr(XmlPullParser pp) throws AndrolibException { + ResTable restable = resTable; + for (int i = 0; i < pp.getAttributeCount(); i++) { + final String a_ns = "http://schemas.android.com/apk/res/android"; + String ns = pp.getAttributeNamespace (i); + if (a_ns.equalsIgnoreCase(ns)) { + String name = pp.getAttributeName (i); + String value = pp.getAttributeValue (i); + if (name != null && value != null) { + if (name.equalsIgnoreCase("minSdkVersion") || + name.equalsIgnoreCase("targetSdkVersion") || + name.equalsIgnoreCase("maxSdkVersion")) { + restable.addSdkInfo(name, value); + } else { + restable.clearSdkInfo(); + return false;//Found unknown flags + } + } + } else { + resTable.clearSdkInfo(); + return false;//Found unknown flags + } + } + return true; + } + }; par.setInput(in, null); ser.setOutput(out, null); @@ -46,7 +97,6 @@ public class XmlPullStreamDecoder implements ResStreamDecoder { while (par.nextToken() != XmlPullParser.END_DOCUMENT) { ser.event(par); } - mSerial.newLine(); ser.flush(); } catch (XmlPullParserException ex) { throw new AndrolibException("Could not decode XML", ex); diff --git a/apktool-lib/src/main/java/brut/androlib/res/util/ExtMXSerializer.java b/apktool-lib/src/main/java/brut/androlib/res/util/ExtMXSerializer.java index 3beed1f6..4fd001da 100644 --- a/apktool-lib/src/main/java/brut/androlib/res/util/ExtMXSerializer.java +++ b/apktool-lib/src/main/java/brut/androlib/res/util/ExtMXSerializer.java @@ -75,4 +75,5 @@ public class ExtMXSerializer extends MXSerializer implements ExtXmlSerializer { private String mDefaultEncoding; private boolean mIsDisabledAttrEscape = false; + }