mirror of
https://github.com/revanced/Apktool.git
synced 2025-05-01 14:44:26 +02:00
cleaned up XmlPullStreamDecoder
-- removed optimize for manifest bool -- take attr value once, then re-use -- used passed ResTable, instead of re-init
This commit is contained in:
parent
8766cfbb7f
commit
b149d7bd49
@ -48,11 +48,9 @@ public class XmlPullStreamDecoder implements ResStreamDecoder {
|
|||||||
try {
|
try {
|
||||||
XmlPullWrapperFactory factory = XmlPullWrapperFactory.newInstance();
|
XmlPullWrapperFactory factory = XmlPullWrapperFactory.newInstance();
|
||||||
XmlPullParserWrapper par = factory.newPullParserWrapper(mParser);
|
XmlPullParserWrapper par = factory.newPullParserWrapper(mParser);
|
||||||
final ResTable resTable = ((AXmlResourceParser) mParser)
|
final ResTable resTable = ((AXmlResourceParser) mParser).getAttrDecoder().getCurrentPackage().getResTable();
|
||||||
.getAttrDecoder().getCurrentPackage().getResTable();
|
|
||||||
|
|
||||||
XmlSerializerWrapper ser = new StaticXmlSerializerWrapper(mSerial,
|
XmlSerializerWrapper ser = new StaticXmlSerializerWrapper(mSerial, factory) {
|
||||||
factory) {
|
|
||||||
boolean hideSdkInfo = false;
|
boolean hideSdkInfo = false;
|
||||||
boolean hidePackageInfo = false;
|
boolean hidePackageInfo = false;
|
||||||
|
|
||||||
@ -65,16 +63,14 @@ public class XmlPullStreamDecoder implements ResStreamDecoder {
|
|||||||
if ("manifest".equalsIgnoreCase(pp.getName())) {
|
if ("manifest".equalsIgnoreCase(pp.getName())) {
|
||||||
try {
|
try {
|
||||||
hidePackageInfo = parseManifest(pp);
|
hidePackageInfo = parseManifest(pp);
|
||||||
} catch (AndrolibException e) {
|
} catch (AndrolibException ignored) {}
|
||||||
}
|
|
||||||
} else if ("uses-sdk".equalsIgnoreCase(pp.getName())) {
|
} else if ("uses-sdk".equalsIgnoreCase(pp.getName())) {
|
||||||
try {
|
try {
|
||||||
hideSdkInfo = parseAttr(pp);
|
hideSdkInfo = parseAttr(pp);
|
||||||
if (hideSdkInfo) {
|
if (hideSdkInfo) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (AndrolibException e) {
|
} catch (AndrolibException ignored) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (hideSdkInfo && type == XmlPullParser.END_TAG
|
} else if (hideSdkInfo && type == XmlPullParser.END_TAG
|
||||||
&& "uses-sdk".equalsIgnoreCase(pp.getName())) {
|
&& "uses-sdk".equalsIgnoreCase(pp.getName())) {
|
||||||
@ -89,14 +85,17 @@ public class XmlPullStreamDecoder implements ResStreamDecoder {
|
|||||||
|
|
||||||
private boolean parseManifest(XmlPullParser pp)
|
private boolean parseManifest(XmlPullParser pp)
|
||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
|
String attr_name;
|
||||||
|
|
||||||
// read <manifest> for package:
|
// read <manifest> for package:
|
||||||
for (int i = 0; i < pp.getAttributeCount(); i++) {
|
for (int i = 0; i < pp.getAttributeCount(); i++) {
|
||||||
if (pp.getAttributeName(i).equalsIgnoreCase(("package"))) {
|
attr_name = pp.getAttributeName(i);
|
||||||
|
|
||||||
|
if (attr_name.equalsIgnoreCase(("package"))) {
|
||||||
resTable.setPackageRenamed(pp.getAttributeValue(i));
|
resTable.setPackageRenamed(pp.getAttributeValue(i));
|
||||||
} else if (pp.getAttributeName(i).equalsIgnoreCase("versionCode")) {
|
} else if (attr_name.equalsIgnoreCase("versionCode")) {
|
||||||
resTable.addVersionInfo("versionCode", pp.getAttributeValue(i));
|
resTable.addVersionInfo("versionCode", pp.getAttributeValue(i));
|
||||||
} else if (pp.getAttributeName(i).equalsIgnoreCase("versionName")) {
|
} else if (attr_name.equalsIgnoreCase("versionName")) {
|
||||||
resTable.addVersionInfo("versionName", pp.getAttributeValue(i));
|
resTable.addVersionInfo("versionName", pp.getAttributeValue(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,7 +104,6 @@ public class XmlPullStreamDecoder implements ResStreamDecoder {
|
|||||||
|
|
||||||
private boolean parseAttr(XmlPullParser pp)
|
private boolean parseAttr(XmlPullParser pp)
|
||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
ResTable restable = resTable;
|
|
||||||
for (int i = 0; i < pp.getAttributeCount(); i++) {
|
for (int i = 0; i < pp.getAttributeCount(); i++) {
|
||||||
final String a_ns = "http://schemas.android.com/apk/res/android";
|
final String a_ns = "http://schemas.android.com/apk/res/android";
|
||||||
String ns = pp.getAttributeNamespace(i);
|
String ns = pp.getAttributeNamespace(i);
|
||||||
@ -117,25 +115,22 @@ public class XmlPullStreamDecoder implements ResStreamDecoder {
|
|||||||
if (name.equalsIgnoreCase("minSdkVersion")
|
if (name.equalsIgnoreCase("minSdkVersion")
|
||||||
|| name.equalsIgnoreCase("targetSdkVersion")
|
|| name.equalsIgnoreCase("targetSdkVersion")
|
||||||
|| name.equalsIgnoreCase("maxSdkVersion")) {
|
|| name.equalsIgnoreCase("maxSdkVersion")) {
|
||||||
restable.addSdkInfo(name, value);
|
resTable.addSdkInfo(name, value);
|
||||||
} else {
|
} else {
|
||||||
restable.clearSdkInfo();
|
resTable.clearSdkInfo();
|
||||||
return false;// Found unknown flags
|
return false; // Found unknown flags
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resTable.clearSdkInfo();
|
resTable.clearSdkInfo();
|
||||||
|
|
||||||
if (i >= pp.getAttributeCount()) {
|
if (i >= pp.getAttributeCount()) {
|
||||||
return false;// Found unknown flags
|
return false; // Found unknown flags
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (resTable.getAnalysisMode() == true) {
|
|
||||||
return false;
|
return resTable.getAnalysisMode();
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -155,19 +150,11 @@ public class XmlPullStreamDecoder implements ResStreamDecoder {
|
|||||||
|
|
||||||
public void decodeManifest(InputStream in, OutputStream out)
|
public void decodeManifest(InputStream in, OutputStream out)
|
||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
mOptimizeForManifest = true;
|
|
||||||
try {
|
|
||||||
decode(in, out);
|
decode(in, out);
|
||||||
} finally {
|
|
||||||
mOptimizeForManifest = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final XmlPullParser mParser;
|
private final XmlPullParser mParser;
|
||||||
private final ExtXmlSerializer mSerial;
|
private final ExtXmlSerializer mSerial;
|
||||||
|
|
||||||
private boolean mOptimizeForManifest = false;
|
private final static Logger LOGGER = Logger.getLogger(XmlPullStreamDecoder.class.getName());
|
||||||
|
|
||||||
private final static Logger LOGGER = Logger
|
|
||||||
.getLogger(XmlPullStreamDecoder.class.getName());
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user