Skip to content

Commit

Permalink
Explicit ResFileDecoder initiazation and add constructors AXmlResourc…
Browse files Browse the repository at this point in the history
…eParser(ResTable resTable) and AndroidManifestResourceParser(ResTable resTable) (#3211)
  • Loading branch information
sv99 authored Jul 24, 2023
1 parent 490b6f8 commit c2ddeac
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,9 @@ public void decodeManifest(File outDir) throws AndrolibException {
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();
Expand Down Expand Up @@ -216,10 +213,15 @@ public ResTable decodeResources(File outDir) throws AndrolibException {

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 {
Expand All @@ -245,24 +247,12 @@ private void decodeResources(ResTable resTable, ExtFile apkFile, File outDir)
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand All @@ -44,8 +45,9 @@
*/
public class AXmlResourceParser implements XmlResourceParser {

public AXmlResourceParser() {
public AXmlResourceParser(ResTable resTable) {
resetEventInfo();
setAttrDecoder(new ResAttrDecoder(resTable));
}

public AndrolibException getFirstError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package brut.androlib.res.decoder;

import android.util.TypedValue;
import brut.androlib.res.data.ResTable;

import java.util.regex.Pattern;

Expand All @@ -25,6 +26,10 @@
*/
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
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);
Expand Down

0 comments on commit c2ddeac

Please sign in to comment.