Explicit ResFileDecoder initiazation and add constructors AXmlResourceParser(ResTable resTable) and AndroidManifestResourceParser(ResTable resTable) (#3211)

This commit is contained in:
sv99 2023-07-24 13:43:56 +03:00 committed by GitHub
parent 490b6f8aee
commit c2ddeac3ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 23 deletions

View File

@ -136,12 +136,9 @@ public class ResourcesDecoder {
private void decodeManifest(ResTable resTable, ExtFile apkFile, File outDir)
throws AndrolibException {
AXmlResourceParser axmlParser = new AndroidManifestResourceParser();
ResAttrDecoder attrDecoder = new ResAttrDecoder();
attrDecoder.setResTable(resTable);
axmlParser.setAttrDecoder(attrDecoder);
AXmlResourceParser axmlParser = new AndroidManifestResourceParser(resTable);
XmlPullStreamDecoder fileDecoder = new XmlPullStreamDecoder(axmlParser, getResXmlSerializer());
Directory inApk, out;
try {
inApk = apkFile.getDirectory();
@ -216,10 +213,15 @@ public class ResourcesDecoder {
private void decodeResources(ResTable resTable, ExtFile apkFile, File outDir)
throws AndrolibException {
Duo<ResFileDecoder, AXmlResourceParser> duo = getResFileDecoder();
ResFileDecoder fileDecoder = duo.m1;
ResAttrDecoder attrDecoder = duo.m2.getAttrDecoder();
attrDecoder.setResTable(resTable);
ResStreamDecoderContainer decoders = new ResStreamDecoderContainer();
decoders.setDecoder("raw", new ResRawStreamDecoder());
decoders.setDecoder("9patch", new Res9patchStreamDecoder());
AXmlResourceParser axmlParser = new AXmlResourceParser(resTable);
decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser, getResXmlSerializer()));
ResFileDecoder fileDecoder = new ResFileDecoder(decoders);
Directory in, out;
try {
@ -245,24 +247,12 @@ public class ResourcesDecoder {
generatePublicXml(pkg, out, xmlSerializer);
}
AndrolibException decodeError = duo.m2.getFirstError();
AndrolibException decodeError = axmlParser.getFirstError();
if (decodeError != null) {
throw decodeError;
}
}
private Duo<ResFileDecoder, AXmlResourceParser> getResFileDecoder() {
ResStreamDecoderContainer decoders = new ResStreamDecoderContainer();
decoders.setDecoder("raw", new ResRawStreamDecoder());
decoders.setDecoder("9patch", new Res9patchStreamDecoder());
AXmlResourceParser axmlParser = new AXmlResourceParser();
axmlParser.setAttrDecoder(new ResAttrDecoder());
decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser, getResXmlSerializer()));
return new Duo<>(new ResFileDecoder(decoders), axmlParser);
}
private void generateValuesFile(ResValuesFile valuesFile, Directory out,
ExtXmlSerializer serial) throws AndrolibException {
try {

View File

@ -20,6 +20,7 @@ import android.content.res.XmlResourceParser;
import android.util.TypedValue;
import brut.androlib.exceptions.AndrolibException;
import brut.androlib.res.data.ResID;
import brut.androlib.res.data.ResTable;
import brut.androlib.res.data.arsc.ARSCHeader;
import brut.androlib.res.data.axml.NamespaceStack;
import brut.androlib.res.xml.ResXmlEncoders;
@ -44,8 +45,9 @@ import java.util.logging.Logger;
*/
public class AXmlResourceParser implements XmlResourceParser {
public AXmlResourceParser() {
public AXmlResourceParser(ResTable resTable) {
resetEventInfo();
setAttrDecoder(new ResAttrDecoder(resTable));
}
public AndrolibException getFirstError() {

View File

@ -17,6 +17,7 @@
package brut.androlib.res.decoder;
import android.util.TypedValue;
import brut.androlib.res.data.ResTable;
import java.util.regex.Pattern;
@ -25,6 +26,10 @@ import java.util.regex.Pattern;
*/
public class AndroidManifestResourceParser extends AXmlResourceParser {
public AndroidManifestResourceParser(ResTable resTable) {
super(resTable);
}
/**
* Pattern for matching numeric string meta-data values. aapt automatically infers the
* type for a manifest meta-data value based on the string in the unencoded XML. However,

View File

@ -26,6 +26,11 @@ import brut.androlib.res.data.value.ResAttr;
import brut.androlib.res.data.value.ResScalarValue;
public class ResAttrDecoder {
public ResAttrDecoder(ResTable resTable) {
mResTable = resTable;
}
public String decode(int type, int value, String rawValue, int attrResId)
throws AndrolibException {
ResScalarValue resValue = mResTable.getCurrentResPackage().getValueFactory().factory(type, value, rawValue);