mirror of
https://github.com/revanced/Apktool.git
synced 2024-12-12 13:57:46 +01:00
Code cleanups
This commit is contained in:
parent
2cbefeb91d
commit
94ed86db28
@ -186,7 +186,7 @@ public class Main {
|
|||||||
} catch (CantFindFrameworkResException ex) {
|
} catch (CantFindFrameworkResException ex) {
|
||||||
System.err
|
System.err
|
||||||
.println("Can't find framework resources for package of id: "
|
.println("Can't find framework resources for package of id: "
|
||||||
+ String.valueOf(ex.getPkgId())
|
+ ex.getPkgId()
|
||||||
+ ". You must install proper "
|
+ ". You must install proper "
|
||||||
+ "framework files, see project website for more info.");
|
+ "framework files, see project website for more info.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
@ -509,17 +509,17 @@ public class Main {
|
|||||||
listFrameworkOptions.addOption(frameIfDirOption);
|
listFrameworkOptions.addOption(frameIfDirOption);
|
||||||
|
|
||||||
// add all, loop existing cats then manually add advance
|
// add all, loop existing cats then manually add advance
|
||||||
for (Object op : normalOptions.getOptions()) {
|
for (Option op : normalOptions.getOptions()) {
|
||||||
allOptions.addOption((Option)op);
|
allOptions.addOption(op);
|
||||||
}
|
}
|
||||||
for (Object op : DecodeOptions.getOptions()) {
|
for (Option op : DecodeOptions.getOptions()) {
|
||||||
allOptions.addOption((Option)op);
|
allOptions.addOption(op);
|
||||||
}
|
}
|
||||||
for (Object op : BuildOptions.getOptions()) {
|
for (Option op : BuildOptions.getOptions()) {
|
||||||
allOptions.addOption((Option)op);
|
allOptions.addOption(op);
|
||||||
}
|
}
|
||||||
for (Object op : frameOptions.getOptions()) {
|
for (Option op : frameOptions.getOptions()) {
|
||||||
allOptions.addOption((Option)op);
|
allOptions.addOption(op);
|
||||||
}
|
}
|
||||||
allOptions.addOption(apiLevelOption);
|
allOptions.addOption(apiLevelOption);
|
||||||
allOptions.addOption(analysisOption);
|
allOptions.addOption(analysisOption);
|
||||||
@ -561,7 +561,7 @@ public class Main {
|
|||||||
if (isAdvanceMode()) {
|
if (isAdvanceMode()) {
|
||||||
System.out.println("Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0)\n");
|
System.out.println("Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0)\n");
|
||||||
}else {
|
}else {
|
||||||
System.out.println("");
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4 usage outputs (general, frameworks, decode, build)
|
// 4 usage outputs (general, frameworks, decode, build)
|
||||||
@ -573,10 +573,8 @@ public class Main {
|
|||||||
formatter.printHelp("apktool " + verbosityHelp() + "publicize-resources <file_path>", emptyOptions);
|
formatter.printHelp("apktool " + verbosityHelp() + "publicize-resources <file_path>", emptyOptions);
|
||||||
formatter.printHelp("apktool " + verbosityHelp() + "empty-framework-dir [options]", emptyFrameworkOptions);
|
formatter.printHelp("apktool " + verbosityHelp() + "empty-framework-dir [options]", emptyFrameworkOptions);
|
||||||
formatter.printHelp("apktool " + verbosityHelp() + "list-frameworks [options]", listFrameworkOptions);
|
formatter.printHelp("apktool " + verbosityHelp() + "list-frameworks [options]", listFrameworkOptions);
|
||||||
System.out.println("");
|
|
||||||
} else {
|
|
||||||
System.out.println("");
|
|
||||||
}
|
}
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
// print out more information
|
// print out more information
|
||||||
System.out.println(
|
System.out.println(
|
||||||
|
@ -30,5 +30,5 @@ public interface XmlResourceParser extends XmlPullParser, AttributeSet {
|
|||||||
* Close this interface to the resource. Calls on the interface are no
|
* Close this interface to the resource. Calls on the interface are no
|
||||||
* longer value after this call.
|
* longer value after this call.
|
||||||
*/
|
*/
|
||||||
public void close();
|
void close();
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public interface AttributeSet {
|
|||||||
|
|
||||||
int getAttributeNameResource(int index);
|
int getAttributeNameResource(int index);
|
||||||
|
|
||||||
int getAttributeListValue(int index, String options[], int defaultValue);
|
int getAttributeListValue(int index, String[] options, int defaultValue);
|
||||||
|
|
||||||
boolean getAttributeBooleanValue(int index, boolean defaultValue);
|
boolean getAttributeBooleanValue(int index, boolean defaultValue);
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ public interface AttributeSet {
|
|||||||
String getAttributeValue(String namespace, String attribute);
|
String getAttributeValue(String namespace, String attribute);
|
||||||
|
|
||||||
int getAttributeListValue(String namespace, String attribute,
|
int getAttributeListValue(String namespace, String attribute,
|
||||||
String options[], int defaultValue);
|
String[] options, int defaultValue);
|
||||||
|
|
||||||
boolean getAttributeBooleanValue(String namespace, String attribute,
|
boolean getAttributeBooleanValue(String namespace, String attribute,
|
||||||
boolean defaultValue);
|
boolean defaultValue);
|
||||||
|
@ -217,7 +217,7 @@ public class TypedValue {
|
|||||||
|
|
||||||
private static final float MANTISSA_MULT = 1.0f / (1 << TypedValue.COMPLEX_MANTISSA_SHIFT);
|
private static final float MANTISSA_MULT = 1.0f / (1 << TypedValue.COMPLEX_MANTISSA_SHIFT);
|
||||||
private static final float[] RADIX_MULTS = new float[] {
|
private static final float[] RADIX_MULTS = new float[] {
|
||||||
1.0f * MANTISSA_MULT, 1.0f / (1 << 7) * MANTISSA_MULT,
|
MANTISSA_MULT, 1.0f / (1 << 7) * MANTISSA_MULT,
|
||||||
1.0f / (1 << 15) * MANTISSA_MULT, 1.0f / (1 << 23) * MANTISSA_MULT };
|
1.0f / (1 << 15) * MANTISSA_MULT, 1.0f / (1 << 23) * MANTISSA_MULT };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -251,7 +251,7 @@ public class TypedValue {
|
|||||||
* @return String The coerced string value. If the value is null or the type
|
* @return String The coerced string value. If the value is null or the type
|
||||||
* is not known, null is returned.
|
* is not known, null is returned.
|
||||||
*/
|
*/
|
||||||
public static final String coerceToString(int type, int data) {
|
public static String coerceToString(int type, int data) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TYPE_NULL:
|
case TYPE_NULL:
|
||||||
return null;
|
return null;
|
||||||
@ -262,11 +262,11 @@ public class TypedValue {
|
|||||||
case TYPE_FLOAT:
|
case TYPE_FLOAT:
|
||||||
return Float.toString(Float.intBitsToFloat(data));
|
return Float.toString(Float.intBitsToFloat(data));
|
||||||
case TYPE_DIMENSION:
|
case TYPE_DIMENSION:
|
||||||
return Float.toString(complexToFloat(data))
|
return complexToFloat(data)
|
||||||
+ DIMENSION_UNIT_STRS[(data >> COMPLEX_UNIT_SHIFT)
|
+ DIMENSION_UNIT_STRS[(data >> COMPLEX_UNIT_SHIFT)
|
||||||
& COMPLEX_UNIT_MASK];
|
& COMPLEX_UNIT_MASK];
|
||||||
case TYPE_FRACTION:
|
case TYPE_FRACTION:
|
||||||
return Float.toString(complexToFloat(data) * 100)
|
return complexToFloat(data) * 100
|
||||||
+ FRACTION_UNIT_STRS[(data >> COMPLEX_UNIT_SHIFT)
|
+ FRACTION_UNIT_STRS[(data >> COMPLEX_UNIT_SHIFT)
|
||||||
& COMPLEX_UNIT_MASK];
|
& COMPLEX_UNIT_MASK];
|
||||||
case TYPE_INT_HEX:
|
case TYPE_INT_HEX:
|
||||||
@ -286,22 +286,19 @@ public class TypedValue {
|
|||||||
res = res.substring(2);
|
res = res.substring(2);
|
||||||
break;
|
break;
|
||||||
case TYPE_INT_COLOR_ARGB4:// #AARRGGBB->#ARGB
|
case TYPE_INT_COLOR_ARGB4:// #AARRGGBB->#ARGB
|
||||||
res = new StringBuffer().append(vals[0]).append(vals[2])
|
res = String.valueOf(vals[0]) + vals[2] +
|
||||||
.append(vals[4]).append(vals[6]).toString();
|
vals[4] + vals[6];
|
||||||
break;
|
break;
|
||||||
case TYPE_INT_COLOR_RGB4:// #FFRRGGBB->#RGB
|
case TYPE_INT_COLOR_RGB4:// #FFRRGGBB->#RGB
|
||||||
res = new StringBuffer().append(vals[2]).append(vals[4])
|
res = String.valueOf(vals[2]) + vals[4] +
|
||||||
.append(vals[6]).toString();
|
vals[6];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return "#" + res;
|
return "#" + res;
|
||||||
} else if (type >= TYPE_FIRST_INT && type <= TYPE_LAST_INT) {
|
} else if (type >= TYPE_FIRST_INT && type <= TYPE_LAST_INT) {
|
||||||
String res;
|
String res = null;
|
||||||
switch (type) {
|
if (type == TYPE_INT_DEC) {
|
||||||
default:
|
res = Integer.toString(data);
|
||||||
case TYPE_INT_DEC:
|
|
||||||
res = Integer.toString(data);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ import brut.androlib.res.data.ResUnknownFiles;
|
|||||||
import brut.common.InvalidUnknownFileException;
|
import brut.common.InvalidUnknownFileException;
|
||||||
import brut.common.RootUnknownFileException;
|
import brut.common.RootUnknownFileException;
|
||||||
import brut.common.TraversalUnknownFileException;
|
import brut.common.TraversalUnknownFileException;
|
||||||
import brut.directory.ExtFile;
|
|
||||||
import brut.androlib.res.xml.ResXmlPatcher;
|
import brut.androlib.res.xml.ResXmlPatcher;
|
||||||
import brut.androlib.src.SmaliBuilder;
|
import brut.androlib.src.SmaliBuilder;
|
||||||
import brut.androlib.src.SmaliDecoder;
|
import brut.androlib.src.SmaliDecoder;
|
||||||
@ -48,7 +47,7 @@ import java.util.zip.ZipOutputStream;
|
|||||||
public class Androlib {
|
public class Androlib {
|
||||||
private final AndrolibResources mAndRes = new AndrolibResources();
|
private final AndrolibResources mAndRes = new AndrolibResources();
|
||||||
protected final ResUnknownFiles mResUnknownFiles = new ResUnknownFiles();
|
protected final ResUnknownFiles mResUnknownFiles = new ResUnknownFiles();
|
||||||
public ApkOptions apkOptions;
|
public final ApkOptions apkOptions;
|
||||||
private int mMinSdkVersion = 0;
|
private int mMinSdkVersion = 0;
|
||||||
|
|
||||||
public Androlib() {
|
public Androlib() {
|
||||||
@ -779,8 +778,8 @@ public class Androlib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isModified(File[] working, File[] stored) {
|
private boolean isModified(File[] working, File[] stored) {
|
||||||
for (int i = 0; i < stored.length; i++) {
|
for (File file : stored) {
|
||||||
if (!stored[i].exists()) {
|
if (!file.exists()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,12 +165,10 @@ public class ApkDecoder {
|
|||||||
|
|
||||||
mAndrolib.decodeRawFiles(mApkFile, outDir, mDecodeAssets);
|
mAndrolib.decodeRawFiles(mApkFile, outDir, mDecodeAssets);
|
||||||
mAndrolib.decodeUnknownFiles(mApkFile, outDir);
|
mAndrolib.decodeUnknownFiles(mApkFile, outDir);
|
||||||
mUncompressedFiles = new ArrayList<String>();
|
mUncompressedFiles = new ArrayList<>();
|
||||||
mAndrolib.recordUncompressedFiles(mApkFile, mUncompressedFiles);
|
mAndrolib.recordUncompressedFiles(mApkFile, mUncompressedFiles);
|
||||||
mAndrolib.writeOriginalFiles(mApkFile, outDir);
|
mAndrolib.writeOriginalFiles(mApkFile, outDir);
|
||||||
writeMetaFile();
|
writeMetaFile();
|
||||||
} catch (Exception ex) {
|
|
||||||
throw ex;
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
mApkFile.close();
|
mApkFile.close();
|
||||||
|
@ -24,7 +24,7 @@ public class ApkOptions {
|
|||||||
public boolean debugMode = false;
|
public boolean debugMode = false;
|
||||||
public boolean verbose = false;
|
public boolean verbose = false;
|
||||||
public boolean copyOriginalFiles = false;
|
public boolean copyOriginalFiles = false;
|
||||||
public boolean updateFiles = false;
|
public final boolean updateFiles = false;
|
||||||
public boolean isFramework = false;
|
public boolean isFramework = false;
|
||||||
public boolean resourcesAreCompressed = false;
|
public boolean resourcesAreCompressed = false;
|
||||||
public boolean useAapt2 = false;
|
public boolean useAapt2 = false;
|
||||||
|
@ -29,7 +29,7 @@ public class StringExConstructor extends Constructor {
|
|||||||
|
|
||||||
private class ConstructStringEx extends AbstractConstruct {
|
private class ConstructStringEx extends AbstractConstruct {
|
||||||
public Object construct(Node node) {
|
public Object construct(Node node) {
|
||||||
String val = (String) constructScalar((ScalarNode) node);
|
String val = constructScalar((ScalarNode) node);
|
||||||
return YamlStringEscapeUtils.unescapeString(val);
|
return YamlStringEscapeUtils.unescapeString(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ final public class AndrolibResources {
|
|||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
LOGGER.info("Loading resource table...");
|
LOGGER.info("Loading resource table...");
|
||||||
ResPackage[] pkgs = getResPackagesFromApk(apkFile, resTable, sKeepBroken);
|
ResPackage[] pkgs = getResPackagesFromApk(apkFile, resTable, sKeepBroken);
|
||||||
ResPackage pkg = null;
|
ResPackage pkg;
|
||||||
|
|
||||||
switch (pkgs.length) {
|
switch (pkgs.length) {
|
||||||
case 1:
|
case 1:
|
||||||
@ -71,14 +71,11 @@ final public class AndrolibResources {
|
|||||||
case 2:
|
case 2:
|
||||||
if (pkgs[0].getName().equals("android")) {
|
if (pkgs[0].getName().equals("android")) {
|
||||||
LOGGER.warning("Skipping \"android\" package group");
|
LOGGER.warning("Skipping \"android\" package group");
|
||||||
pkg = pkgs[1];
|
|
||||||
break;
|
|
||||||
} else if (pkgs[0].getName().equals("com.htc")) {
|
} else if (pkgs[0].getName().equals("com.htc")) {
|
||||||
LOGGER.warning("Skipping \"htc\" package group");
|
LOGGER.warning("Skipping \"htc\" package group");
|
||||||
pkg = pkgs[1];
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
pkg = pkgs[1];
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
pkg = selectPkgWithMostResSpecs(pkgs);
|
pkg = selectPkgWithMostResSpecs(pkgs);
|
||||||
break;
|
break;
|
||||||
@ -128,7 +125,7 @@ final public class AndrolibResources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pkg.getId() != id) {
|
if (pkg.getId() != id) {
|
||||||
throw new AndrolibException("Expected pkg of id: " + String.valueOf(id) + ", got: " + pkg.getId());
|
throw new AndrolibException("Expected pkg of id: " + id + ", got: " + pkg.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
resTable.addPackage(pkg, false);
|
resTable.addPackage(pkg, false);
|
||||||
@ -619,7 +616,7 @@ final public class AndrolibResources {
|
|||||||
|
|
||||||
String aaptPath = apkOptions.aaptPath;
|
String aaptPath = apkOptions.aaptPath;
|
||||||
boolean customAapt = !aaptPath.isEmpty();
|
boolean customAapt = !aaptPath.isEmpty();
|
||||||
List<String> cmd = new ArrayList<String>();
|
List<String> cmd = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String aaptCommand = AaptManager.getAaptExecutionCommand(aaptPath, getAaptBinaryFile());
|
String aaptCommand = AaptManager.getAaptExecutionCommand(aaptPath, getAaptBinaryFile());
|
||||||
@ -705,7 +702,7 @@ final public class AndrolibResources {
|
|||||||
axmlParser.setAttrDecoder(new ResAttrDecoder());
|
axmlParser.setAttrDecoder(new ResAttrDecoder());
|
||||||
decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser, getResXmlSerializer()));
|
decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser, getResXmlSerializer()));
|
||||||
|
|
||||||
return new Duo<ResFileDecoder, AXmlResourceParser>(new ResFileDecoder(decoders), axmlParser);
|
return new Duo<>(new ResFileDecoder(decoders), axmlParser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Duo<ResFileDecoder, AXmlResourceParser> getManifestFileDecoder(boolean withResources) {
|
public Duo<ResFileDecoder, AXmlResourceParser> getManifestFileDecoder(boolean withResources) {
|
||||||
@ -717,7 +714,7 @@ final public class AndrolibResources {
|
|||||||
}
|
}
|
||||||
decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser,getResXmlSerializer()));
|
decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser,getResXmlSerializer()));
|
||||||
|
|
||||||
return new Duo<ResFileDecoder, AXmlResourceParser>(new ResFileDecoder(decoders), axmlParser);
|
return new Duo<>(new ResFileDecoder(decoders), axmlParser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtMXSerializer getResXmlSerializer() {
|
public ExtMXSerializer getResXmlSerializer() {
|
||||||
@ -783,15 +780,10 @@ final public class AndrolibResources {
|
|||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
try {
|
try {
|
||||||
Directory dir = apkFile.getDirectory();
|
Directory dir = apkFile.getDirectory();
|
||||||
BufferedInputStream bfi = new BufferedInputStream(dir.getFileInput("resources.arsc"));
|
try (BufferedInputStream bfi = new BufferedInputStream(dir.getFileInput("resources.arsc"))) {
|
||||||
try {
|
|
||||||
return ARSCDecoder.decode(bfi, false, keepBroken, resTable).getPackages();
|
return ARSCDecoder.decode(bfi, false, keepBroken, resTable).getPackages();
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
bfi.close();
|
|
||||||
} catch (IOException ignored) {}
|
|
||||||
}
|
}
|
||||||
} catch (DirectoryException ex) {
|
} catch (DirectoryException | IOException ex) {
|
||||||
throw new AndrolibException("Could not load resources.arsc from file: " + apkFile, ex);
|
throw new AndrolibException("Could not load resources.arsc from file: " + apkFile, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -808,7 +800,7 @@ final public class AndrolibResources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apk = new File(dir, String.valueOf(id) + ".apk");
|
apk = new File(dir, id + ".apk");
|
||||||
if (apk.exists()) {
|
if (apk.exists()) {
|
||||||
return apk;
|
return apk;
|
||||||
}
|
}
|
||||||
@ -888,8 +880,8 @@ final public class AndrolibResources {
|
|||||||
ARSCData arsc = ARSCDecoder.decode(new ByteArrayInputStream(data), true, true);
|
ARSCData arsc = ARSCDecoder.decode(new ByteArrayInputStream(data), true, true);
|
||||||
publicizeResources(data, arsc.getFlagsOffsets());
|
publicizeResources(data, arsc.getFlagsOffsets());
|
||||||
|
|
||||||
File outFile = new File(getFrameworkDir(), String.valueOf(arsc
|
File outFile = new File(getFrameworkDir(), arsc
|
||||||
.getOnePackage().getId())
|
.getOnePackage().getId()
|
||||||
+ (tag == null ? "" : '-' + tag)
|
+ (tag == null ? "" : '-' + tag)
|
||||||
+ ".apk");
|
+ ".apk");
|
||||||
|
|
||||||
|
@ -59,9 +59,6 @@ public class ResID {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final ResID other = (ResID) obj;
|
final ResID other = (ResID) obj;
|
||||||
if (this.id != other.id) {
|
return this.id == other.id;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,10 @@ public class ResPackage {
|
|||||||
private final ResTable mResTable;
|
private final ResTable mResTable;
|
||||||
private final int mId;
|
private final int mId;
|
||||||
private final String mName;
|
private final String mName;
|
||||||
private final Map<ResID, ResResSpec> mResSpecs = new LinkedHashMap<ResID, ResResSpec>();
|
private final Map<ResID, ResResSpec> mResSpecs = new LinkedHashMap<>();
|
||||||
private final Map<ResConfigFlags, ResType> mConfigs = new LinkedHashMap<ResConfigFlags, ResType>();
|
private final Map<ResConfigFlags, ResType> mConfigs = new LinkedHashMap<>();
|
||||||
private final Map<String, ResTypeSpec> mTypes = new LinkedHashMap<String, ResTypeSpec>();
|
private final Map<String, ResTypeSpec> mTypes = new LinkedHashMap<>();
|
||||||
private final Set<ResID> mSynthesizedRes = new HashSet<ResID>();
|
private final Set<ResID> mSynthesizedRes = new HashSet<>();
|
||||||
|
|
||||||
private ResValueFactory mValueFactory;
|
private ResValueFactory mValueFactory;
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ public class ResPackage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<ResResSpec> listResSpecs() {
|
public List<ResResSpec> listResSpecs() {
|
||||||
return new ArrayList<ResResSpec>(mResSpecs.values());
|
return new ArrayList<>(mResSpecs.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasResSpec(ResID resID) {
|
public boolean hasResSpec(ResID resID) {
|
||||||
@ -80,7 +80,7 @@ public class ResPackage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<ResResource> listFiles() {
|
public Set<ResResource> listFiles() {
|
||||||
Set<ResResource> ret = new HashSet<ResResource>();
|
Set<ResResource> ret = new HashSet<>();
|
||||||
for (ResResSpec spec : mResSpecs.values()) {
|
for (ResResSpec spec : mResSpecs.values()) {
|
||||||
for (ResResource res : spec.listResources()) {
|
for (ResResource res : spec.listResources()) {
|
||||||
if (res.getValue() instanceof ResFileValue) {
|
if (res.getValue() instanceof ResFileValue) {
|
||||||
@ -92,13 +92,13 @@ public class ResPackage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Collection<ResValuesFile> listValuesFiles() {
|
public Collection<ResValuesFile> listValuesFiles() {
|
||||||
Map<Duo<ResTypeSpec, ResType>, ResValuesFile> ret = new HashMap<Duo<ResTypeSpec, ResType>, ResValuesFile>();
|
Map<Duo<ResTypeSpec, ResType>, ResValuesFile> ret = new HashMap<>();
|
||||||
for (ResResSpec spec : mResSpecs.values()) {
|
for (ResResSpec spec : mResSpecs.values()) {
|
||||||
for (ResResource res : spec.listResources()) {
|
for (ResResource res : spec.listResources()) {
|
||||||
if (res.getValue() instanceof ResValuesXmlSerializable) {
|
if (res.getValue() instanceof ResValuesXmlSerializable) {
|
||||||
ResTypeSpec type = res.getResSpec().getType();
|
ResTypeSpec type = res.getResSpec().getType();
|
||||||
ResType config = res.getConfig();
|
ResType config = res.getConfig();
|
||||||
Duo<ResTypeSpec, ResType> key = new Duo<ResTypeSpec, ResType>(type, config);
|
Duo<ResTypeSpec, ResType> key = new Duo<>(type, config);
|
||||||
ResValuesFile values = ret.get(key);
|
ResValuesFile values = ret.get(key);
|
||||||
if (values == null) {
|
if (values == null) {
|
||||||
values = new ResValuesFile(this, type, config);
|
values = new ResValuesFile(this, type, config);
|
||||||
@ -163,13 +163,10 @@ public class ResPackage {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final ResPackage other = (ResPackage) obj;
|
final ResPackage other = (ResPackage) obj;
|
||||||
if (this.mResTable != other.mResTable && (this.mResTable == null || !this.mResTable.equals(other.mResTable))) {
|
if (!Objects.equals(this.mResTable, other.mResTable)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.mId != other.mId) {
|
return this.mId == other.mId;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,7 +30,7 @@ public class ResResSpec {
|
|||||||
private final String mName;
|
private final String mName;
|
||||||
private final ResPackage mPackage;
|
private final ResPackage mPackage;
|
||||||
private final ResTypeSpec mType;
|
private final ResTypeSpec mType;
|
||||||
private final Map<ResConfigFlags, ResResource> mResources = new LinkedHashMap<ResConfigFlags, ResResource>();
|
private final Map<ResConfigFlags, ResResource> mResources = new LinkedHashMap<>();
|
||||||
|
|
||||||
public ResResSpec(ResID id, String name, ResPackage pkg, ResTypeSpec type) {
|
public ResResSpec(ResID id, String name, ResPackage pkg, ResTypeSpec type) {
|
||||||
this.mId = id;
|
this.mId = id;
|
||||||
@ -38,7 +38,7 @@ public class ResResSpec {
|
|||||||
|
|
||||||
ResResSpec resResSpec = type.getResSpecUnsafe(name);
|
ResResSpec resResSpec = type.getResSpecUnsafe(name);
|
||||||
if (resResSpec != null) {
|
if (resResSpec != null) {
|
||||||
cleanName = String.format("APKTOOL_DUPLICATE_%s_%s", type.toString(), id.toString());
|
cleanName = String.format("APKTOOL_DUPLICATE_%s_%s", type, id.toString());
|
||||||
} else {
|
} else {
|
||||||
cleanName = ((name == null || name.isEmpty()) ? ("APKTOOL_DUMMYVAL_" + id.toString()) : name);
|
cleanName = ((name == null || name.isEmpty()) ? ("APKTOOL_DUMMYVAL_" + id.toString()) : name);
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ public class ResResSpec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<ResResource> listResources() {
|
public Set<ResResource> listResources() {
|
||||||
return new LinkedHashSet<ResResource>(mResources.values());
|
return new LinkedHashSet<>(mResources.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResResource getResource(ResType config) throws AndrolibException {
|
public ResResource getResource(ResType config) throws AndrolibException {
|
||||||
|
@ -26,10 +26,10 @@ import java.util.*;
|
|||||||
public class ResTable {
|
public class ResTable {
|
||||||
private final AndrolibResources mAndRes;
|
private final AndrolibResources mAndRes;
|
||||||
|
|
||||||
private final Map<Integer, ResPackage> mPackagesById = new HashMap<Integer, ResPackage>();
|
private final Map<Integer, ResPackage> mPackagesById = new HashMap<>();
|
||||||
private final Map<String, ResPackage> mPackagesByName = new HashMap<String, ResPackage>();
|
private final Map<String, ResPackage> mPackagesByName = new HashMap<>();
|
||||||
private final Set<ResPackage> mMainPackages = new LinkedHashSet<ResPackage>();
|
private final Set<ResPackage> mMainPackages = new LinkedHashSet<>();
|
||||||
private final Set<ResPackage> mFramePackages = new LinkedHashSet<ResPackage>();
|
private final Set<ResPackage> mFramePackages = new LinkedHashSet<>();
|
||||||
|
|
||||||
private String mPackageRenamed;
|
private String mPackageRenamed;
|
||||||
private String mPackageOriginal;
|
private String mPackageOriginal;
|
||||||
@ -38,8 +38,8 @@ public class ResTable {
|
|||||||
private boolean mSharedLibrary = false;
|
private boolean mSharedLibrary = false;
|
||||||
private boolean mSparseResources = false;
|
private boolean mSparseResources = false;
|
||||||
|
|
||||||
private Map<String, String> mSdkInfo = new LinkedHashMap<>();
|
private final Map<String, String> mSdkInfo = new LinkedHashMap<>();
|
||||||
private VersionInfo mVersionInfo = new VersionInfo();
|
private final VersionInfo mVersionInfo = new VersionInfo();
|
||||||
|
|
||||||
public ResTable() {
|
public ResTable() {
|
||||||
mAndRes = null;
|
mAndRes = null;
|
||||||
@ -124,7 +124,7 @@ public class ResTable {
|
|||||||
public void addPackage(ResPackage pkg, boolean main) throws AndrolibException {
|
public void addPackage(ResPackage pkg, boolean main) throws AndrolibException {
|
||||||
Integer id = pkg.getId();
|
Integer id = pkg.getId();
|
||||||
if (mPackagesById.containsKey(id)) {
|
if (mPackagesById.containsKey(id)) {
|
||||||
throw new AndrolibException("Multiple packages: id=" + id.toString());
|
throw new AndrolibException("Multiple packages: id=" + id);
|
||||||
}
|
}
|
||||||
String name = pkg.getName();
|
String name = pkg.getName();
|
||||||
if (mPackagesByName.containsKey(name)) {
|
if (mPackagesByName.containsKey(name)) {
|
||||||
|
@ -22,7 +22,7 @@ import java.util.*;
|
|||||||
|
|
||||||
public class ResType {
|
public class ResType {
|
||||||
private final ResConfigFlags mFlags;
|
private final ResConfigFlags mFlags;
|
||||||
private final Map<ResResSpec, ResResource> mResources = new LinkedHashMap<ResResSpec, ResResource>();
|
private final Map<ResResSpec, ResResource> mResources = new LinkedHashMap<>();
|
||||||
|
|
||||||
public ResType(ResConfigFlags flags) {
|
public ResType(ResConfigFlags flags) {
|
||||||
this.mFlags = flags;
|
this.mFlags = flags;
|
||||||
|
@ -28,7 +28,7 @@ public final class ResTypeSpec {
|
|||||||
public static final String RES_TYPE_NAME_ATTR = "attr";
|
public static final String RES_TYPE_NAME_ATTR = "attr";
|
||||||
|
|
||||||
private final String mName;
|
private final String mName;
|
||||||
private final Map<String, ResResSpec> mResSpecs = new LinkedHashMap<String, ResResSpec>();
|
private final Map<String, ResResSpec> mResSpecs = new LinkedHashMap<>();
|
||||||
|
|
||||||
private final ResTable mResTable;
|
private final ResTable mResTable;
|
||||||
private final ResPackage mPackage;
|
private final ResPackage mPackage;
|
||||||
|
@ -17,13 +17,14 @@
|
|||||||
package brut.androlib.res.data;
|
package brut.androlib.res.data;
|
||||||
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ResValuesFile {
|
public class ResValuesFile {
|
||||||
private final ResPackage mPackage;
|
private final ResPackage mPackage;
|
||||||
private final ResTypeSpec mType;
|
private final ResTypeSpec mType;
|
||||||
private final ResType mConfig;
|
private final ResType mConfig;
|
||||||
private final Set<ResResource> mResources = new LinkedHashSet<ResResource>();
|
private final Set<ResResource> mResources = new LinkedHashSet<>();
|
||||||
|
|
||||||
public ResValuesFile(ResPackage pkg, ResTypeSpec type, ResType config) {
|
public ResValuesFile(ResPackage pkg, ResTypeSpec type, ResType config) {
|
||||||
this.mPackage = pkg;
|
this.mPackage = pkg;
|
||||||
@ -62,13 +63,10 @@ public class ResValuesFile {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final ResValuesFile other = (ResValuesFile) obj;
|
final ResValuesFile other = (ResValuesFile) obj;
|
||||||
if (this.mType != other.mType && (this.mType == null || !this.mType.equals(other.mType))) {
|
if (!Objects.equals(this.mType, other.mType)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.mConfig != other.mConfig && (this.mConfig == null || !this.mConfig.equals(other.mConfig))) {
|
return Objects.equals(this.mConfig, other.mConfig);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,17 +51,17 @@ public class ResArrayValue extends ResBagValue implements
|
|||||||
serializer.attribute(null, "name", res.getResSpec().getName());
|
serializer.attribute(null, "name", res.getResSpec().getName());
|
||||||
|
|
||||||
// lets check if we need to add formatted="false" to this array
|
// lets check if we need to add formatted="false" to this array
|
||||||
for (int i = 0; i < mItems.length; i++) {
|
for (ResScalarValue item : mItems) {
|
||||||
if (mItems[i].hasMultipleNonPositionalSubstitutions()) {
|
if (item.hasMultipleNonPositionalSubstitutions()) {
|
||||||
serializer.attribute(null, "formatted", "false");
|
serializer.attribute(null, "formatted", "false");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add <item>'s
|
// add <item>'s
|
||||||
for (int i = 0; i < mItems.length; i++) {
|
for (ResScalarValue mItem : mItems) {
|
||||||
serializer.startTag(null, "item");
|
serializer.startTag(null, "item");
|
||||||
serializer.text(mItems[i].encodeAsResXmlNonEscapedItemValue());
|
serializer.text(mItem.encodeAsResXmlNonEscapedItemValue());
|
||||||
serializer.endTag(null, "item");
|
serializer.endTag(null, "item");
|
||||||
}
|
}
|
||||||
serializer.endTag(null, type);
|
serializer.endTag(null, type);
|
||||||
@ -72,16 +72,16 @@ public class ResArrayValue extends ResBagValue implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String type = mItems[0].getType();
|
String type = mItems[0].getType();
|
||||||
for (int i = 0; i < mItems.length; i++) {
|
for (ResScalarValue mItem : mItems) {
|
||||||
if (mItems[i].encodeAsResXmlItemValue().startsWith("@string")) {
|
if (mItem.encodeAsResXmlItemValue().startsWith("@string")) {
|
||||||
return "string";
|
return "string";
|
||||||
} else if (mItems[i].encodeAsResXmlItemValue().startsWith("@drawable")) {
|
} else if (mItem.encodeAsResXmlItemValue().startsWith("@drawable")) {
|
||||||
return null;
|
return null;
|
||||||
} else if (mItems[i].encodeAsResXmlItemValue().startsWith("@integer")) {
|
} else if (mItem.encodeAsResXmlItemValue().startsWith("@integer")) {
|
||||||
return "integer";
|
return "integer";
|
||||||
} else if (!"string".equals(type) && !"integer".equals(type)) {
|
} else if (!"string".equals(type) && !"integer".equals(type)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (!type.equals(mItems[i].getType())) {
|
} else if (!type.equals(mItem.getType())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,9 +96,9 @@ public class ResAttr extends ResBagValue implements ResValuesXmlSerializable {
|
|||||||
for (; i < items.length; i++) {
|
for (; i < items.length; i++) {
|
||||||
int resId = items[i].m1;
|
int resId = items[i].m1;
|
||||||
pkg.addSynthesizedRes(resId);
|
pkg.addSynthesizedRes(resId);
|
||||||
attrItems[j++] = new Duo<ResReferenceValue, ResIntValue>(
|
attrItems[j++] = new Duo<>(
|
||||||
factory.newReference(resId, null),
|
factory.newReference(resId, null),
|
||||||
(ResIntValue) items[i].m2);
|
(ResIntValue) items[i].m2);
|
||||||
}
|
}
|
||||||
switch (type & 0xff0000) {
|
switch (type & 0xff0000) {
|
||||||
case TYPE_ENUM:
|
case TYPE_ENUM:
|
||||||
|
@ -80,5 +80,5 @@ public class ResEnumAttr extends ResAttr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final Duo<ResReferenceValue, ResIntValue>[] mItems;
|
private final Duo<ResReferenceValue, ResIntValue>[] mItems;
|
||||||
private final Map<Integer, String> mItemsCache = new HashMap<Integer, String>();
|
private final Map<Integer, String> mItemsCache = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import org.xmlpull.v1.XmlSerializer;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
public class ResFlagsAttr extends ResAttr {
|
public class ResFlagsAttr extends ResAttr {
|
||||||
ResFlagsAttr(ResReferenceValue parent, int type, Integer min, Integer max,
|
ResFlagsAttr(ResReferenceValue parent, int type, Integer min, Integer max,
|
||||||
@ -55,8 +54,7 @@ public class ResFlagsAttr extends ResAttr {
|
|||||||
FlagItem[] flagItems = new FlagItem[mFlags.length];
|
FlagItem[] flagItems = new FlagItem[mFlags.length];
|
||||||
int[] flags = new int[mFlags.length];
|
int[] flags = new int[mFlags.length];
|
||||||
int flagsCount = 0;
|
int flagsCount = 0;
|
||||||
for (int i = 0; i < mFlags.length; i++) {
|
for (FlagItem flagItem : mFlags) {
|
||||||
FlagItem flagItem = mFlags[i];
|
|
||||||
int flag = flagItem.flag;
|
int flag = flagItem.flag;
|
||||||
|
|
||||||
if ((intVal & flag) != flag) {
|
if ((intVal & flag) != flag) {
|
||||||
@ -74,20 +72,18 @@ public class ResFlagsAttr extends ResAttr {
|
|||||||
@Override
|
@Override
|
||||||
protected void serializeBody(XmlSerializer serializer, ResResource res)
|
protected void serializeBody(XmlSerializer serializer, ResResource res)
|
||||||
throws AndrolibException, IOException {
|
throws AndrolibException, IOException {
|
||||||
for (int i = 0; i < mItems.length; i++) {
|
for (FlagItem item : mItems) {
|
||||||
FlagItem item = mItems[i];
|
|
||||||
|
|
||||||
serializer.startTag(null, "flag");
|
serializer.startTag(null, "flag");
|
||||||
serializer.attribute(null, "name", item.getValue());
|
serializer.attribute(null, "name", item.getValue());
|
||||||
serializer.attribute(null, "value",
|
serializer.attribute(null, "value",
|
||||||
String.format("0x%08x", item.flag));
|
String.format("0x%08x", item.flag));
|
||||||
serializer.endTag(null, "flag");
|
serializer.endTag(null, "flag");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSubpartOf(int flag, int[] flags) {
|
private boolean isSubpartOf(int flag, int[] flags) {
|
||||||
for (int i = 0; i < flags.length; i++) {
|
for (int j : flags) {
|
||||||
if ((flags[i] & flag) == flag) {
|
if ((j & flag) == flag) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,12 +91,12 @@ public class ResFlagsAttr extends ResAttr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String renderFlags(FlagItem[] flags) throws AndrolibException {
|
private String renderFlags(FlagItem[] flags) throws AndrolibException {
|
||||||
String ret = "";
|
StringBuilder ret = new StringBuilder();
|
||||||
for (int i = 0; i < flags.length; i++) {
|
for (FlagItem flag : flags) {
|
||||||
ret += "|" + flags[i].getValue();
|
ret.append("|").append(flag.getValue());
|
||||||
}
|
}
|
||||||
if (ret.isEmpty()) {
|
if (ret.length() == 0) {
|
||||||
return ret;
|
return ret.toString();
|
||||||
}
|
}
|
||||||
return ret.substring(1);
|
return ret.substring(1);
|
||||||
}
|
}
|
||||||
@ -115,8 +111,7 @@ public class ResFlagsAttr extends ResAttr {
|
|||||||
FlagItem[] flags = new FlagItem[mItems.length];
|
FlagItem[] flags = new FlagItem[mItems.length];
|
||||||
int flagsCount = 0;
|
int flagsCount = 0;
|
||||||
|
|
||||||
for (int i = 0; i < mItems.length; i++) {
|
for (FlagItem item : mItems) {
|
||||||
FlagItem item = mItems[i];
|
|
||||||
if (item.flag == 0) {
|
if (item.flag == 0) {
|
||||||
zeroFlags[zeroFlagsCount++] = item;
|
zeroFlags[zeroFlagsCount++] = item;
|
||||||
} else {
|
} else {
|
||||||
@ -127,13 +122,7 @@ public class ResFlagsAttr extends ResAttr {
|
|||||||
mZeroFlags = Arrays.copyOf(zeroFlags, zeroFlagsCount);
|
mZeroFlags = Arrays.copyOf(zeroFlags, zeroFlagsCount);
|
||||||
mFlags = Arrays.copyOf(flags, flagsCount);
|
mFlags = Arrays.copyOf(flags, flagsCount);
|
||||||
|
|
||||||
Arrays.sort(mFlags, new Comparator<FlagItem>() {
|
Arrays.sort(mFlags, (o1, o2) -> Integer.compare(Integer.bitCount(o2.flag), Integer.bitCount(o1.flag)));
|
||||||
@Override
|
|
||||||
public int compare(FlagItem o1, FlagItem o2) {
|
|
||||||
return Integer.valueOf(Integer.bitCount(o2.flag)).compareTo(
|
|
||||||
Integer.bitCount(o1.flag));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final FlagItem[] mItems;
|
private final FlagItem[] mItems;
|
||||||
|
@ -32,8 +32,8 @@ public class ResPluralsValue extends ResBagValue implements
|
|||||||
super(parent);
|
super(parent);
|
||||||
|
|
||||||
mItems = new ResScalarValue[6];
|
mItems = new ResScalarValue[6];
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (Duo<Integer, ResScalarValue> item : items) {
|
||||||
mItems[items[i].m1 - BAG_KEY_PLURALS_START] = items[i].m2;
|
mItems[item.m1 - BAG_KEY_PLURALS_START] = item.m2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ public class ResStyleValue extends ResBagValue implements
|
|||||||
|
|
||||||
mItems = new Duo[items.length];
|
mItems = new Duo[items.length];
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
mItems[i] = new Duo<ResReferenceValue, ResScalarValue>(
|
mItems[i] = new Duo<>(
|
||||||
factory.newReference(items[i].m1, null), items[i].m2);
|
factory.newReference(items[i].m1, null), items[i].m2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,16 +49,16 @@ public class ResStyleValue extends ResBagValue implements
|
|||||||
} else if (res.getResSpec().getName().indexOf('.') != -1) {
|
} else if (res.getResSpec().getName().indexOf('.') != -1) {
|
||||||
serializer.attribute(null, "parent", "");
|
serializer.attribute(null, "parent", "");
|
||||||
}
|
}
|
||||||
for (int i = 0; i < mItems.length; i++) {
|
for (Duo<ResReferenceValue, ResScalarValue> mItem : mItems) {
|
||||||
ResResSpec spec = mItems[i].m1.getReferent();
|
ResResSpec spec = mItem.m1.getReferent();
|
||||||
|
|
||||||
if (spec == null) {
|
if (spec == null) {
|
||||||
LOGGER.fine(String.format("null reference: m1=0x%08x(%s), m2=0x%08x(%s)",
|
LOGGER.fine(String.format("null reference: m1=0x%08x(%s), m2=0x%08x(%s)",
|
||||||
mItems[i].m1.getRawIntValue(), mItems[i].m1.getType(), mItems[i].m2.getRawIntValue(), mItems[i].m2.getType()));
|
mItem.m1.getRawIntValue(), mItem.m1.getType(), mItem.m2.getRawIntValue(), mItem.m2.getType()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = null;
|
String name;
|
||||||
String value = null;
|
String value = null;
|
||||||
|
|
||||||
ResValue resource = spec.getDefaultResource().getValue();
|
ResValue resource = spec.getDefaultResource().getValue();
|
||||||
@ -66,14 +66,14 @@ public class ResStyleValue extends ResBagValue implements
|
|||||||
continue;
|
continue;
|
||||||
} else if (resource instanceof ResAttr) {
|
} else if (resource instanceof ResAttr) {
|
||||||
ResAttr attr = (ResAttr) resource;
|
ResAttr attr = (ResAttr) resource;
|
||||||
value = attr.convertToResXmlFormat(mItems[i].m2);
|
value = attr.convertToResXmlFormat(mItem.m2);
|
||||||
name = spec.getFullName(res.getResSpec().getPackage(), true);
|
name = spec.getFullName(res.getResSpec().getPackage(), true);
|
||||||
} else {
|
} else {
|
||||||
name = "@" + spec.getFullName(res.getResSpec().getPackage(), false);
|
name = "@" + spec.getFullName(res.getResSpec().getPackage(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
value = mItems[i].m2.encodeAsResXmlValue();
|
value = mItem.m2.encodeAsResXmlValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
@ -59,7 +59,7 @@ public class ARSCDecoder {
|
|||||||
private ARSCDecoder(InputStream arscStream, ResTable resTable, boolean storeFlagsOffsets, boolean keepBroken) {
|
private ARSCDecoder(InputStream arscStream, ResTable resTable, boolean storeFlagsOffsets, boolean keepBroken) {
|
||||||
arscStream = mCountIn = new CountingInputStream(arscStream);
|
arscStream = mCountIn = new CountingInputStream(arscStream);
|
||||||
if (storeFlagsOffsets) {
|
if (storeFlagsOffsets) {
|
||||||
mFlagsOffsets = new ArrayList<FlagsOffset>();
|
mFlagsOffsets = new ArrayList<>();
|
||||||
} else {
|
} else {
|
||||||
mFlagsOffsets = null;
|
mFlagsOffsets = null;
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ public class ARSCDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mType = flags.isInvalid && !mKeepBroken ? null : mPkg.getOrCreateConfig(flags);
|
mType = flags.isInvalid && !mKeepBroken ? null : mPkg.getOrCreateConfig(flags);
|
||||||
HashMap<Integer, EntryData> offsetsToEntryData = new HashMap<Integer, EntryData>();
|
HashMap<Integer, EntryData> offsetsToEntryData = new HashMap<>();
|
||||||
|
|
||||||
for (int offset : entryOffsets) {
|
for (int offset : entryOffsets) {
|
||||||
if (offset == -1 || offsetsToEntryData.containsKey(offset)) {
|
if (offset == -1 || offsetsToEntryData.containsKey(offset)) {
|
||||||
@ -327,7 +327,7 @@ public class ARSCDecoder {
|
|||||||
if (mKeepBroken) {
|
if (mKeepBroken) {
|
||||||
mType.addResource(res, true);
|
mType.addResource(res, true);
|
||||||
spec.addResource(res, true);
|
spec.addResource(res, true);
|
||||||
LOGGER.warning(String.format("Duplicate Resource Detected. Ignoring duplicate: %s", res.toString()));
|
LOGGER.warning(String.format("Duplicate Resource Detected. Ignoring duplicate: %s", res));
|
||||||
} else {
|
} else {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
@ -347,12 +347,10 @@ public class ARSCDecoder {
|
|||||||
resId = mIn.readInt();
|
resId = mIn.readInt();
|
||||||
resValue = readValue();
|
resValue = readValue();
|
||||||
|
|
||||||
if (resValue instanceof ResScalarValue) {
|
if (!(resValue instanceof ResScalarValue)) {
|
||||||
items[i] = new Duo<Integer, ResScalarValue>(resId, (ResScalarValue) resValue);
|
|
||||||
} else {
|
|
||||||
resValue = new ResStringValue(resValue.toString(), resValue.getRawIntValue());
|
resValue = new ResStringValue(resValue.toString(), resValue.getRawIntValue());
|
||||||
items[i] = new Duo<Integer, ResScalarValue>(resId, (ResScalarValue) resValue);
|
|
||||||
}
|
}
|
||||||
|
items[i] = new Duo<>(resId, (ResScalarValue) resValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return factory.bagFactory(parent, items, mTypeSpec);
|
return factory.bagFactory(parent, items, mTypeSpec);
|
||||||
@ -574,7 +572,7 @@ public class ARSCDecoder {
|
|||||||
private int mResId;
|
private int mResId;
|
||||||
private int mTypeIdOffset = 0;
|
private int mTypeIdOffset = 0;
|
||||||
private boolean[] mMissingResSpecs;
|
private boolean[] mMissingResSpecs;
|
||||||
private HashMap<Integer, ResTypeSpec> mResTypeSpecs = new HashMap<>();
|
private final HashMap<Integer, ResTypeSpec> mResTypeSpecs = new HashMap<>();
|
||||||
|
|
||||||
private final static short ENTRY_FLAG_COMPLEX = 0x0001;
|
private final static short ENTRY_FLAG_COMPLEX = 0x0001;
|
||||||
private final static short ENTRY_FLAG_PUBLIC = 0x0002;
|
private final static short ENTRY_FLAG_PUBLIC = 0x0002;
|
||||||
|
@ -345,7 +345,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
if (resourceId != 0) {
|
if (resourceId != 0) {
|
||||||
value = mAttrDecoder.decodeManifestAttr(getAttributeNameResource(index));
|
value = mAttrDecoder.decodeManifestAttr(getAttributeNameResource(index));
|
||||||
}
|
}
|
||||||
} catch (AndrolibException | NullPointerException e) { }
|
} catch (AndrolibException | NullPointerException ignored) {}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -601,12 +601,12 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
m_data = new int[32];
|
m_data = new int[32];
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void reset() {
|
public void reset() {
|
||||||
m_dataLength = 0;
|
m_dataLength = 0;
|
||||||
m_depth = 0;
|
m_depth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getCurrentCount() {
|
public int getCurrentCount() {
|
||||||
if (m_dataLength == 0) {
|
if (m_dataLength == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -614,7 +614,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
return m_data[offset];
|
return m_data[offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getAccumulatedCount(int depth) {
|
public int getAccumulatedCount(int depth) {
|
||||||
if (m_dataLength == 0 || depth < 0) {
|
if (m_dataLength == 0 || depth < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -631,7 +631,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
return accumulatedCount;
|
return accumulatedCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void push(int prefix, int uri) {
|
public void push(int prefix, int uri) {
|
||||||
if (m_depth == 0) {
|
if (m_depth == 0) {
|
||||||
increaseDepth();
|
increaseDepth();
|
||||||
}
|
}
|
||||||
@ -645,7 +645,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
m_dataLength += 2;
|
m_dataLength += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean pop() {
|
public boolean pop() {
|
||||||
if (m_dataLength == 0) {
|
if (m_dataLength == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -663,23 +663,23 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getPrefix(int index) {
|
public int getPrefix(int index) {
|
||||||
return get(index, true);
|
return get(index, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getUri(int index) {
|
public int getUri(int index) {
|
||||||
return get(index, false);
|
return get(index, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int findPrefix(int uri) {
|
public int findPrefix(int uri) {
|
||||||
return find(uri, false);
|
return find(uri, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getDepth() {
|
public int getDepth() {
|
||||||
return m_depth;
|
return m_depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void increaseDepth() {
|
public void increaseDepth() {
|
||||||
ensureDataCapacity(2);
|
ensureDataCapacity(2);
|
||||||
int offset = m_dataLength;
|
int offset = m_dataLength;
|
||||||
m_data[offset] = 0;
|
m_data[offset] = 0;
|
||||||
@ -688,7 +688,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
m_depth += 1;
|
m_depth += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void decreaseDepth() {
|
public void decreaseDepth() {
|
||||||
if (m_dataLength == 0) {
|
if (m_dataLength == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -712,7 +712,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
m_data = newData;
|
m_data = newData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int find(int prefixOrUri, boolean prefix) {
|
private int find(int prefixOrUri, boolean prefix) {
|
||||||
if (m_dataLength == 0) {
|
if (m_dataLength == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -736,7 +736,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int get(int index, boolean prefix) {
|
private int get(int index, boolean prefix) {
|
||||||
if (m_dataLength == 0 || index < 0) {
|
if (m_dataLength == 0 || index < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -762,7 +762,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
private int m_depth;
|
private int m_depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int getAttributeOffset(int index) {
|
private int getAttributeOffset(int index) {
|
||||||
if (m_event != START_TAG) {
|
if (m_event != START_TAG) {
|
||||||
throw new IndexOutOfBoundsException("Current event is not START_TAG.");
|
throw new IndexOutOfBoundsException("Current event is not START_TAG.");
|
||||||
}
|
}
|
||||||
@ -773,7 +773,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int findAttribute(String namespace, String attribute) {
|
private int findAttribute(String namespace, String attribute) {
|
||||||
if (m_strings == null || attribute == null) {
|
if (m_strings == null || attribute == null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -791,7 +791,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void resetEventInfo() {
|
private void resetEventInfo() {
|
||||||
m_event = -1;
|
m_event = -1;
|
||||||
m_lineNumber = -1;
|
m_lineNumber = -1;
|
||||||
m_name = -1;
|
m_name = -1;
|
||||||
@ -802,7 +802,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
m_styleAttribute = -1;
|
m_styleAttribute = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void doNext() throws IOException {
|
private void doNext() throws IOException {
|
||||||
// Delayed initialization.
|
// Delayed initialization.
|
||||||
if (m_strings == null) {
|
if (m_strings == null) {
|
||||||
m_reader.skipCheckInt(CHUNK_AXML_FILE, CHUNK_AXML_FILE_BROKEN);
|
m_reader.skipCheckInt(CHUNK_AXML_FILE, CHUNK_AXML_FILE_BROKEN);
|
||||||
@ -938,7 +938,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
private boolean m_operational = false;
|
private boolean m_operational = false;
|
||||||
private StringBlock m_strings;
|
private StringBlock m_strings;
|
||||||
private int[] m_resourceIDs;
|
private int[] m_resourceIDs;
|
||||||
private NamespaceStack m_namespaces = new NamespaceStack();
|
private final NamespaceStack m_namespaces = new NamespaceStack();
|
||||||
private final String android_ns = "http://schemas.android.com/apk/res/android";
|
private final String android_ns = "http://schemas.android.com/apk/res/android";
|
||||||
private boolean m_decreaseDepth;
|
private boolean m_decreaseDepth;
|
||||||
private int m_event;
|
private int m_event;
|
||||||
|
@ -111,14 +111,12 @@ public class Res9patchStreamDecoder implements ResStreamDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImageIO.write(im2, "png", out);
|
ImageIO.write(im2, "png", out);
|
||||||
} catch (IOException ex) {
|
} catch (IOException | NullPointerException ex) {
|
||||||
throw new AndrolibException(ex);
|
throw new AndrolibException(ex);
|
||||||
} catch (NullPointerException ex) {
|
} // In my case this was triggered because a .png file was
|
||||||
// In my case this was triggered because a .png file was
|
// containing a html document instead of an image.
|
||||||
// containing a html document instead of an image.
|
// This could be more verbose and try to MIME ?
|
||||||
// This could be more verbose and try to MIME ?
|
|
||||||
throw new AndrolibException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private NinePatch getNinePatch(byte[] data) throws AndrolibException,
|
private NinePatch getNinePatch(byte[] data) throws AndrolibException,
|
||||||
|
@ -21,6 +21,6 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
public interface ResStreamDecoder {
|
public interface ResStreamDecoder {
|
||||||
public void decode(InputStream in, OutputStream out)
|
void decode(InputStream in, OutputStream out)
|
||||||
throws AndrolibException;
|
throws AndrolibException;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ResStreamDecoderContainer {
|
public class ResStreamDecoderContainer {
|
||||||
private final Map<String, ResStreamDecoder> mDecoders = new HashMap<String, ResStreamDecoder>();
|
private final Map<String, ResStreamDecoder> mDecoders = new HashMap<>();
|
||||||
|
|
||||||
public void decode(InputStream in, OutputStream out, String decoderName)
|
public void decode(InputStream in, OutputStream out, String decoderName)
|
||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
|
@ -177,7 +177,7 @@ public class StringBlock {
|
|||||||
if (pos == -1) {
|
if (pos == -1) {
|
||||||
builder.append(tag);
|
builder.append(tag);
|
||||||
} else {
|
} else {
|
||||||
builder.append(tag.substring(0, pos));
|
builder.append(tag, 0, pos);
|
||||||
if (!close) {
|
if (!close) {
|
||||||
boolean loop = true;
|
boolean loop = true;
|
||||||
while (loop) {
|
while (loop) {
|
||||||
@ -187,7 +187,7 @@ public class StringBlock {
|
|||||||
// prematurely end style tags, if recreation
|
// prematurely end style tags, if recreation
|
||||||
// cannot be created.
|
// cannot be created.
|
||||||
if (pos2 != -1) {
|
if (pos2 != -1) {
|
||||||
builder.append(' ').append(tag.substring(pos + 1, pos2)).append("=\"");
|
builder.append(' ').append(tag, pos + 1, pos2).append("=\"");
|
||||||
pos = tag.indexOf(';', pos2 + 1);
|
pos = tag.indexOf(';', pos2 + 1);
|
||||||
|
|
||||||
String val;
|
String val;
|
||||||
@ -305,11 +305,11 @@ public class StringBlock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int getShort(byte[] array, int offset) {
|
private static int getShort(byte[] array, int offset) {
|
||||||
return (array[offset + 1] & 0xff) << 8 | array[offset] & 0xff;
|
return (array[offset + 1] & 0xff) << 8 | array[offset] & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int[] getUtf8(byte[] array, int offset) {
|
private static int[] getUtf8(byte[] array, int offset) {
|
||||||
int val = array[offset];
|
int val = array[offset];
|
||||||
int length;
|
int length;
|
||||||
// We skip the utf16 length of the string
|
// We skip the utf16 length of the string
|
||||||
@ -331,7 +331,7 @@ public class StringBlock {
|
|||||||
return new int[] { offset, length};
|
return new int[] { offset, length};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int[] getUtf16(byte[] array, int offset) {
|
private static int[] getUtf16(byte[] array, int offset) {
|
||||||
int val = ((array[offset + 1] & 0xFF) << 8 | array[offset] & 0xFF);
|
int val = ((array[offset + 1] & 0xFF) << 8 | array[offset] & 0xFF);
|
||||||
|
|
||||||
if ((val & 0x8000) != 0) {
|
if ((val & 0x8000) != 0) {
|
||||||
@ -350,8 +350,8 @@ public class StringBlock {
|
|||||||
private int[] m_styles;
|
private int[] m_styles;
|
||||||
private boolean m_isUTF8;
|
private boolean m_isUTF8;
|
||||||
|
|
||||||
private final CharsetDecoder UTF16LE_DECODER = Charset.forName("UTF-16LE").newDecoder();
|
private final CharsetDecoder UTF16LE_DECODER = StandardCharsets.UTF_16LE.newDecoder();
|
||||||
private final CharsetDecoder UTF8_DECODER = Charset.forName("UTF-8").newDecoder();
|
private final CharsetDecoder UTF8_DECODER = StandardCharsets.UTF_8.newDecoder();
|
||||||
private final CharsetDecoder CESU8_DECODER = Charset.forName("CESU8").newDecoder();
|
private final CharsetDecoder CESU8_DECODER = Charset.forName("CESU8").newDecoder();
|
||||||
private static final Logger LOGGER = Logger.getLogger(StringBlock.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(StringBlock.class.getName());
|
||||||
|
|
||||||
|
@ -22,11 +22,11 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public interface ExtXmlSerializer extends XmlSerializer {
|
public interface ExtXmlSerializer extends XmlSerializer {
|
||||||
|
|
||||||
public ExtXmlSerializer newLine() throws IOException;
|
ExtXmlSerializer newLine() throws IOException;
|
||||||
|
|
||||||
public void setDisabledAttrEscape(boolean disabled);
|
void setDisabledAttrEscape(boolean disabled);
|
||||||
|
|
||||||
public static final String PROPERTY_SERIALIZER_INDENTATION = "http://xmlpull.org/v1/doc/properties.html#serializer-indentation";
|
String PROPERTY_SERIALIZER_INDENTATION = "http://xmlpull.org/v1/doc/properties.html#serializer-indentation";
|
||||||
public static final String PROPERTY_SERIALIZER_LINE_SEPARATOR = "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator";
|
String PROPERTY_SERIALIZER_LINE_SEPARATOR = "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator";
|
||||||
public static final String PROPERTY_DEFAULT_ENCODING = "DEFAULT_ENCODING";
|
String PROPERTY_DEFAULT_ENCODING = "DEFAULT_ENCODING";
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,6 @@ import org.xmlpull.v1.XmlSerializer;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public interface ResValuesXmlSerializable {
|
public interface ResValuesXmlSerializable {
|
||||||
public void serializeToResValuesXml(XmlSerializer serializer,
|
void serializeToResValuesXml(XmlSerializer serializer,
|
||||||
ResResource res) throws IOException, AndrolibException;
|
ResResource res) throws IOException, AndrolibException;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ package brut.androlib.res.xml;
|
|||||||
import brut.androlib.AndrolibException;
|
import brut.androlib.AndrolibException;
|
||||||
|
|
||||||
public interface ResXmlEncodable {
|
public interface ResXmlEncodable {
|
||||||
public String encodeAsResXmlAttr() throws AndrolibException;
|
String encodeAsResXmlAttr() throws AndrolibException;
|
||||||
|
|
||||||
public String encodeAsResXmlValue() throws AndrolibException;
|
String encodeAsResXmlValue() throws AndrolibException;
|
||||||
}
|
}
|
||||||
|
@ -102,15 +102,13 @@ public final class ResXmlEncoders {
|
|||||||
wasSpace = false;
|
wasSpace = false;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '\\':
|
case '\\':
|
||||||
|
case '"':
|
||||||
out.append('\\');
|
out.append('\\');
|
||||||
break;
|
break;
|
||||||
case '\'':
|
case '\'':
|
||||||
case '\n':
|
case '\n':
|
||||||
enclose = true;
|
enclose = true;
|
||||||
break;
|
break;
|
||||||
case '"':
|
|
||||||
out.append('\\');
|
|
||||||
break;
|
|
||||||
case '<':
|
case '<':
|
||||||
isInStyleTag = true;
|
isInStyleTag = true;
|
||||||
if (enclose) {
|
if (enclose) {
|
||||||
@ -154,7 +152,7 @@ public final class ResXmlEncoders {
|
|||||||
int pos = 0;
|
int pos = 0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Integer sub : subs) {
|
for (Integer sub : subs) {
|
||||||
out.append(str.substring(pos, ++sub)).append(++count).append('$');
|
out.append(str, pos, ++sub).append(++count).append('$');
|
||||||
pos = sub;
|
pos = sub;
|
||||||
}
|
}
|
||||||
out.append(str.substring(pos));
|
out.append(str.substring(pos));
|
||||||
|
@ -324,11 +324,8 @@ public final class ResXmlPatcher {
|
|||||||
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||||
// Not using the parse(File) method on purpose, so that we can control when
|
// Not using the parse(File) method on purpose, so that we can control when
|
||||||
// to close it. Somehow parse(File) does not seem to close the file in all cases.
|
// to close it. Somehow parse(File) does not seem to close the file in all cases.
|
||||||
FileInputStream inputStream = new FileInputStream(file);
|
try (FileInputStream inputStream = new FileInputStream(file)) {
|
||||||
try {
|
return docBuilder.parse(inputStream);
|
||||||
return docBuilder.parse(inputStream);
|
|
||||||
} finally {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,15 +69,15 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
protected int depth = 0;
|
protected int depth = 0;
|
||||||
|
|
||||||
// element stack
|
// element stack
|
||||||
protected String elNamespace[] = new String[2];
|
protected String[] elNamespace = new String[2];
|
||||||
protected String elName[] = new String[elNamespace.length];
|
protected String[] elName = new String[elNamespace.length];
|
||||||
protected String elPrefix[] = new String[elNamespace.length];
|
protected String[] elPrefix = new String[elNamespace.length];
|
||||||
protected int elNamespaceCount[] = new int[elNamespace.length];
|
protected int[] elNamespaceCount = new int[elNamespace.length];
|
||||||
|
|
||||||
// namespace stack
|
// namespace stack
|
||||||
protected int namespaceEnd = 0;
|
protected int namespaceEnd = 0;
|
||||||
protected String namespacePrefix[] = new String[8];
|
protected String[] namespacePrefix = new String[8];
|
||||||
protected String namespaceUri[] = new String[namespacePrefix.length];
|
protected String[] namespaceUri = new String[namespacePrefix.length];
|
||||||
|
|
||||||
protected boolean finished;
|
protected boolean finished;
|
||||||
protected boolean pastRoot;
|
protected boolean pastRoot;
|
||||||
@ -92,9 +92,9 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
|
|
||||||
// buffer output if needed to write escaped String see text(String)
|
// buffer output if needed to write escaped String see text(String)
|
||||||
private static final int BUF_LEN = Runtime.getRuntime().freeMemory() > 1000000L ? 8 * 1024 : 256;
|
private static final int BUF_LEN = Runtime.getRuntime().freeMemory() > 1000000L ? 8 * 1024 : 256;
|
||||||
protected char buf[] = new char[BUF_LEN];
|
protected char[] buf = new char[BUF_LEN];
|
||||||
|
|
||||||
protected static final String precomputedPrefixes[];
|
protected static final String[] precomputedPrefixes;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
precomputedPrefixes = new String[32]; // arbitrary number ...
|
precomputedPrefixes = new String[32]; // arbitrary number ...
|
||||||
@ -103,7 +103,7 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkNamesInterned = false;
|
private final boolean checkNamesInterned = false;
|
||||||
|
|
||||||
private void checkInterning(String name) {
|
private void checkInterning(String name) {
|
||||||
if (namesInterned && name != name.intern()) {
|
if (namesInterned && name != name.intern()) {
|
||||||
@ -157,7 +157,7 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
+ elStackSize + " ==> " + newSize);
|
+ elStackSize + " ==> " + newSize);
|
||||||
}
|
}
|
||||||
final boolean needsCopying = elStackSize > 0;
|
final boolean needsCopying = elStackSize > 0;
|
||||||
String[] arr = null;
|
String[] arr;
|
||||||
// reuse arr local variable slot
|
// reuse arr local variable slot
|
||||||
arr = new String[newSize];
|
arr = new String[newSize];
|
||||||
if (needsCopying)
|
if (needsCopying)
|
||||||
@ -242,7 +242,7 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
* requested chnages.
|
* requested chnages.
|
||||||
*/
|
*/
|
||||||
protected void rebuildIndentationBuf() {
|
protected void rebuildIndentationBuf() {
|
||||||
if (doIndent == false)
|
if (!doIndent)
|
||||||
return;
|
return;
|
||||||
final int maxIndent = 65; // hardcoded maximum indentation size in characters
|
final int maxIndent = 65; // hardcoded maximum indentation size in characters
|
||||||
int bufSize = 0;
|
int bufSize = 0;
|
||||||
@ -277,7 +277,7 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
|
|
||||||
protected void writeIndent() throws IOException {
|
protected void writeIndent() throws IOException {
|
||||||
final int start = writeLineSepartor ? 0 : offsetNewLine;
|
final int start = writeLineSepartor ? 0 : offsetNewLine;
|
||||||
final int level = (depth > maxIndentLevel) ? maxIndentLevel : depth;
|
final int level = Math.min(depth, maxIndentLevel);
|
||||||
|
|
||||||
out.write(indentationBuf, start, ((level - 1) * indentationJump) + offsetNewLine);
|
out.write(indentationBuf, start, ((level - 1) * indentationJump) + offsetNewLine);
|
||||||
}
|
}
|
||||||
@ -288,15 +288,19 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
if (name == null) {
|
if (name == null) {
|
||||||
throw new IllegalArgumentException("property name can not be null");
|
throw new IllegalArgumentException("property name can not be null");
|
||||||
}
|
}
|
||||||
if (PROPERTY_SERIALIZER_INDENTATION.equals(name)) {
|
switch (name) {
|
||||||
indentationString = (String) value;
|
case PROPERTY_SERIALIZER_INDENTATION:
|
||||||
} else if (PROPERTY_SERIALIZER_LINE_SEPARATOR.equals(name)) {
|
indentationString = (String) value;
|
||||||
lineSeparator = (String) value;
|
break;
|
||||||
} else if (PROPERTY_LOCATION.equals(name)) {
|
case PROPERTY_SERIALIZER_LINE_SEPARATOR:
|
||||||
location = (String) value;
|
lineSeparator = (String) value;
|
||||||
} else {
|
break;
|
||||||
throw new IllegalStateException("unsupported property " + name);
|
case PROPERTY_LOCATION:
|
||||||
}
|
location = (String) value;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("unsupported property " + name);
|
||||||
|
}
|
||||||
writeLineSepartor = lineSeparator != null && lineSeparator.length() > 0;
|
writeLineSepartor = lineSeparator != null && lineSeparator.length() > 0;
|
||||||
writeIndentation = indentationString != null
|
writeIndentation = indentationString != null
|
||||||
&& indentationString.length() > 0;
|
&& indentationString.length() > 0;
|
||||||
@ -314,15 +318,16 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
if (name == null) {
|
if (name == null) {
|
||||||
throw new IllegalArgumentException("property name can not be null");
|
throw new IllegalArgumentException("property name can not be null");
|
||||||
}
|
}
|
||||||
if (PROPERTY_SERIALIZER_INDENTATION.equals(name)) {
|
switch (name) {
|
||||||
return indentationString;
|
case PROPERTY_SERIALIZER_INDENTATION:
|
||||||
} else if (PROPERTY_SERIALIZER_LINE_SEPARATOR.equals(name)) {
|
return indentationString;
|
||||||
return lineSeparator;
|
case PROPERTY_SERIALIZER_LINE_SEPARATOR:
|
||||||
} else if (PROPERTY_LOCATION.equals(name)) {
|
return lineSeparator;
|
||||||
return location;
|
case PROPERTY_LOCATION:
|
||||||
} else {
|
return location;
|
||||||
return null;
|
default:
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLocation() {
|
private String getLocation() {
|
||||||
@ -370,7 +375,7 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
if (standalone != null) {
|
if (standalone != null) {
|
||||||
out.write(" standalone=");
|
out.write(" standalone=");
|
||||||
out.write(attributeUseApostrophe ? '\'' : '"');
|
out.write(attributeUseApostrophe ? '\'' : '"');
|
||||||
if (standalone.booleanValue()) {
|
if (standalone) {
|
||||||
out.write("yes");
|
out.write("yes");
|
||||||
} else {
|
} else {
|
||||||
out.write("no");
|
out.write("no");
|
||||||
@ -462,9 +467,9 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
continue;
|
continue;
|
||||||
// now check that prefix is still in scope
|
// now check that prefix is still in scope
|
||||||
for (int p = namespaceEnd - 1; p > i; --p) {
|
for (int p = namespaceEnd - 1; p > i; --p) {
|
||||||
if (prefix == namespacePrefix[p])
|
if (prefix == namespacePrefix[p]) {
|
||||||
continue; // too bad - prefix is redeclared with different namespace
|
} // too bad - prefix is redeclared with different namespace
|
||||||
}
|
}
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -487,8 +492,8 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
// make sure this prefix is not declared in any scope (avoid hiding in-scope prefixes)!
|
// make sure this prefix is not declared in any scope (avoid hiding in-scope prefixes)!
|
||||||
for (int i = namespaceEnd - 1; i >= 0; --i) {
|
for (int i = namespaceEnd - 1; i >= 0; --i) {
|
||||||
if (prefix == namespacePrefix[i]) {
|
if (prefix == namespacePrefix[i]) {
|
||||||
continue; // prefix is already declared - generate new and try again
|
// prefix is already declared - generate new and try again
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// declare prefix
|
// declare prefix
|
||||||
|
|
||||||
@ -713,8 +718,7 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
if (startTagIncomplete) {
|
if (startTagIncomplete) {
|
||||||
writeNamespaceDeclarations();
|
writeNamespaceDeclarations();
|
||||||
out.write(" />"); // space is added to make it easier to work in XHTML!!!
|
out.write(" />"); // space is added to make it easier to work in XHTML!!!
|
||||||
--depth;
|
} else {
|
||||||
} else {
|
|
||||||
if (doIndent && seenTag) {
|
if (doIndent && seenTag) {
|
||||||
writeIndent();
|
writeIndent();
|
||||||
}
|
}
|
||||||
@ -726,9 +730,9 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
}
|
}
|
||||||
out.write(name);
|
out.write(name);
|
||||||
out.write('>');
|
out.write('>');
|
||||||
--depth;
|
}
|
||||||
}
|
--depth;
|
||||||
namespaceEnd = elNamespaceCount[depth];
|
namespaceEnd = elNamespaceCount[depth];
|
||||||
startTagIncomplete = false;
|
startTagIncomplete = false;
|
||||||
seenTag = true;
|
seenTag = true;
|
||||||
return this;
|
return this;
|
||||||
@ -1009,7 +1013,7 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final String printable(String s) {
|
protected static String printable(String s) {
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
@ -1022,7 +1026,7 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
return retval.toString();
|
return retval.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final String printable(char ch) {
|
protected static String printable(char ch) {
|
||||||
StringBuffer retval = new StringBuffer();
|
StringBuffer retval = new StringBuffer();
|
||||||
addPrintable(retval, ch);
|
addPrintable(retval, ch);
|
||||||
return retval.toString();
|
return retval.toString();
|
||||||
@ -1049,7 +1053,7 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
retval.append("\\\"");
|
retval.append("\\\"");
|
||||||
break;
|
break;
|
||||||
case '\'':
|
case '\'':
|
||||||
retval.append("\\\'");
|
retval.append("\\'");
|
||||||
break;
|
break;
|
||||||
case '\\':
|
case '\\':
|
||||||
retval.append("\\\\");
|
retval.append("\\\\");
|
||||||
@ -1057,7 +1061,7 @@ public class MXSerializer implements XmlSerializer {
|
|||||||
default:
|
default:
|
||||||
if (ch < 0x20 || ch > 0x7e) {
|
if (ch < 0x20 || ch > 0x7e) {
|
||||||
final String ss = "0000" + Integer.toString(ch, 16);
|
final String ss = "0000" + Integer.toString(ch, 16);
|
||||||
retval.append("\\u" + ss.substring(ss.length() - 4));
|
retval.append("\\u").append(ss.substring(ss.length() - 4));
|
||||||
} else {
|
} else {
|
||||||
retval.append(ch);
|
retval.append(ch);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public abstract class TestUtils {
|
|||||||
|
|
||||||
int eventType;
|
int eventType;
|
||||||
String key = null;
|
String key = null;
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<>();
|
||||||
while ((eventType = xpp.next()) != XmlPullParser.END_DOCUMENT) {
|
while ((eventType = xpp.next()) != XmlPullParser.END_DOCUMENT) {
|
||||||
switch (eventType) {
|
switch (eventType) {
|
||||||
case XmlPullParser.START_TAG:
|
case XmlPullParser.START_TAG:
|
||||||
@ -78,14 +78,14 @@ public abstract class TestUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyResourceDir(Class class_, String dirPath, File out) throws BrutException {
|
public static void copyResourceDir(Class<?> class_, String dirPath, File out) throws BrutException {
|
||||||
if (!out.exists()) {
|
if (!out.exists()) {
|
||||||
out.mkdirs();
|
out.mkdirs();
|
||||||
}
|
}
|
||||||
copyResourceDir(class_, dirPath, new FileDirectory(out));
|
copyResourceDir(class_, dirPath, new FileDirectory(out));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyResourceDir(Class class_, String dirPath, Directory out) throws BrutException {
|
public static void copyResourceDir(Class<?> class_, String dirPath, Directory out) throws BrutException {
|
||||||
if (class_ == null) {
|
if (class_ == null) {
|
||||||
class_ = Class.class;
|
class_ = Class.class;
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ public class BuildAndDecodeTest extends BaseTest {
|
|||||||
public void storedMp3FilesAreNotCompressedTest() throws BrutException {
|
public void storedMp3FilesAreNotCompressedTest() throws BrutException {
|
||||||
ExtFile extFile = new ExtFile(sTmpDir, "testapp.apk");
|
ExtFile extFile = new ExtFile(sTmpDir, "testapp.apk");
|
||||||
Integer built = extFile.getDirectory().getCompressionLevel("res/raw/rain.mp3");
|
Integer built = extFile.getDirectory().getCompressionLevel("res/raw/rain.mp3");
|
||||||
assertEquals(new Integer(0), built);
|
assertEquals(Integer.valueOf(0), built);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -79,7 +79,7 @@ public class UnknownCompressionTest extends BaseTest {
|
|||||||
// Check that control = rebuilt (both stored)
|
// Check that control = rebuilt (both stored)
|
||||||
// Add extra check for checking = 0 to enforce check for stored just in case control breaks
|
// Add extra check for checking = 0 to enforce check for stored just in case control breaks
|
||||||
assertEquals(control, rebuilt);
|
assertEquals(control, rebuilt);
|
||||||
assertEquals(new Integer(0), rebuilt);
|
assertEquals(Integer.valueOf(0), rebuilt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -88,7 +88,7 @@ public class UnknownCompressionTest extends BaseTest {
|
|||||||
Integer rebuilt = sTestNewDir.getDirectory().getCompressionLevel("test.json");
|
Integer rebuilt = sTestNewDir.getDirectory().getCompressionLevel("test.json");
|
||||||
|
|
||||||
assertEquals(control, rebuilt);
|
assertEquals(control, rebuilt);
|
||||||
assertEquals(new Integer(8), rebuilt);
|
assertEquals(Integer.valueOf(8), rebuilt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -97,6 +97,6 @@ public class UnknownCompressionTest extends BaseTest {
|
|||||||
Integer rebuilt = sTestNewDir.getDirectory().getCompressionLevel("950x150.png");
|
Integer rebuilt = sTestNewDir.getDirectory().getCompressionLevel("950x150.png");
|
||||||
|
|
||||||
assertEquals(control, rebuilt);
|
assertEquals(control, rebuilt);
|
||||||
assertEquals(new Integer(8), rebuilt);
|
assertEquals(Integer.valueOf(8), rebuilt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ import java.nio.file.Paths;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class DecodeKotlinCoroutinesTest extends BaseTest {
|
public class DecodeKotlinCoroutinesTest extends BaseTest {
|
||||||
private static String apk = "test-kotlin-coroutines.apk";
|
private static final String apk = "test-kotlin-coroutines.apk";
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception {
|
public static void beforeClass() throws Exception {
|
||||||
|
@ -272,8 +272,8 @@ public abstract class AbstractDirectory implements Directory {
|
|||||||
|
|
||||||
|
|
||||||
private class ParsedPath {
|
private class ParsedPath {
|
||||||
public String dir;
|
public final String dir;
|
||||||
public String subpath;
|
public final String subpath;
|
||||||
public ParsedPath(String dir, String subpath) {
|
public ParsedPath(String dir, String subpath) {
|
||||||
this.dir = dir;
|
this.dir = dir;
|
||||||
this.subpath = subpath;
|
this.subpath = subpath;
|
||||||
@ -281,8 +281,8 @@ public abstract class AbstractDirectory implements Directory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class SubPath {
|
private class SubPath {
|
||||||
public AbstractDirectory dir;
|
public final AbstractDirectory dir;
|
||||||
public String path;
|
public final String path;
|
||||||
|
|
||||||
public SubPath(AbstractDirectory dir, String path) {
|
public SubPath(AbstractDirectory dir, String path) {
|
||||||
this.dir = dir;
|
this.dir = dir;
|
||||||
|
@ -41,8 +41,8 @@ public class DirUtil {
|
|||||||
|
|
||||||
public static void copyToDir(Directory in, Directory out,
|
public static void copyToDir(Directory in, Directory out,
|
||||||
String[] fileNames) throws DirectoryException {
|
String[] fileNames) throws DirectoryException {
|
||||||
for (int i = 0; i < fileNames.length; i++) {
|
for (String fileName : fileNames) {
|
||||||
copyToDir(in, out, fileNames[i]);
|
copyToDir(in, out, fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,8 +73,8 @@ public class DirUtil {
|
|||||||
|
|
||||||
public static void copyToDir(Directory in, File out, String[] fileNames)
|
public static void copyToDir(Directory in, File out, String[] fileNames)
|
||||||
throws DirectoryException {
|
throws DirectoryException {
|
||||||
for (int i = 0; i < fileNames.length; i++) {
|
for (String fileName : fileNames) {
|
||||||
copyToDir(in, out, fileNames[i]);
|
copyToDir(in, out, fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,41 +21,41 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface Directory {
|
public interface Directory {
|
||||||
public Set<String> getFiles();
|
Set<String> getFiles();
|
||||||
public Set<String> getFiles(boolean recursive);
|
Set<String> getFiles(boolean recursive);
|
||||||
public Map<String, Directory> getDirs();
|
Map<String, Directory> getDirs();
|
||||||
public Map<String, Directory> getDirs(boolean recursive);
|
Map<String, Directory> getDirs(boolean recursive);
|
||||||
|
|
||||||
public boolean containsFile(String path);
|
boolean containsFile(String path);
|
||||||
public boolean containsDir(String path);
|
boolean containsDir(String path);
|
||||||
|
|
||||||
public InputStream getFileInput(String path) throws DirectoryException;
|
InputStream getFileInput(String path) throws DirectoryException;
|
||||||
public OutputStream getFileOutput(String path) throws DirectoryException;
|
OutputStream getFileOutput(String path) throws DirectoryException;
|
||||||
public Directory getDir(String path) throws PathNotExist;
|
Directory getDir(String path) throws PathNotExist;
|
||||||
public Directory createDir(String path) throws DirectoryException;
|
Directory createDir(String path) throws DirectoryException;
|
||||||
|
|
||||||
public boolean removeFile(String path);
|
boolean removeFile(String path);
|
||||||
|
|
||||||
public void copyToDir(Directory out) throws DirectoryException;
|
void copyToDir(Directory out) throws DirectoryException;
|
||||||
public void copyToDir(Directory out, String[] fileNames)
|
void copyToDir(Directory out, String[] fileNames)
|
||||||
throws DirectoryException;
|
throws DirectoryException;
|
||||||
public void copyToDir(Directory out, String fileName)
|
void copyToDir(Directory out, String fileName)
|
||||||
throws DirectoryException;
|
throws DirectoryException;
|
||||||
public void copyToDir(File out) throws DirectoryException;
|
void copyToDir(File out) throws DirectoryException;
|
||||||
public void copyToDir(File out, String[] fileNames)
|
void copyToDir(File out, String[] fileNames)
|
||||||
throws DirectoryException;
|
throws DirectoryException;
|
||||||
public void copyToDir(File out, String fileName)
|
void copyToDir(File out, String fileName)
|
||||||
throws DirectoryException;
|
throws DirectoryException;
|
||||||
|
|
||||||
public long getSize(String fileName)
|
long getSize(String fileName)
|
||||||
throws DirectoryException;
|
throws DirectoryException;
|
||||||
public long getCompressedSize(String fileName)
|
long getCompressedSize(String fileName)
|
||||||
throws DirectoryException;
|
throws DirectoryException;
|
||||||
public int getCompressionLevel(String fileName)
|
int getCompressionLevel(String fileName)
|
||||||
throws DirectoryException;
|
throws DirectoryException;
|
||||||
|
|
||||||
|
|
||||||
public void close() throws IOException;
|
void close() throws IOException;
|
||||||
|
|
||||||
public final char separator = '/';
|
char separator = '/';
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
|
||||||
public class FileDirectory extends AbstractDirectory {
|
public class FileDirectory extends AbstractDirectory {
|
||||||
private File mDir;
|
private final File mDir;
|
||||||
|
|
||||||
public FileDirectory(ExtFile dir, String folder) throws DirectoryException {
|
public FileDirectory(ExtFile dir, String folder) throws DirectoryException {
|
||||||
this(new File(dir.toString().replaceAll("%20", " "), folder));
|
this(new File(dir.toString().replaceAll("%20", " "), folder));
|
||||||
@ -101,19 +101,18 @@ public class FileDirectory extends AbstractDirectory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadAll() {
|
private void loadAll() {
|
||||||
mFiles = new LinkedHashSet<String>();
|
mFiles = new LinkedHashSet<>();
|
||||||
mDirs = new LinkedHashMap<String, AbstractDirectory>();
|
mDirs = new LinkedHashMap<>();
|
||||||
|
|
||||||
File[] files = getDir().listFiles();
|
File[] files = getDir().listFiles();
|
||||||
for (int i = 0; i < files.length; i++) {
|
for (File file : files) {
|
||||||
File file = files[i];
|
|
||||||
if (file.isFile()) {
|
if (file.isFile()) {
|
||||||
mFiles.add(file.getName());
|
mFiles.add(file.getName());
|
||||||
} else {
|
} else {
|
||||||
// IMPOSSIBLE_EXCEPTION
|
// IMPOSSIBLE_EXCEPTION
|
||||||
try {
|
try {
|
||||||
mDirs.put(file.getName(), new FileDirectory(file));
|
mDirs.put(file.getName(), new FileDirectory(file));
|
||||||
} catch (DirectoryException e) {}
|
} catch (DirectoryException ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,8 @@ import java.util.zip.ZipEntry;
|
|||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
public class ZipRODirectory extends AbstractDirectory {
|
public class ZipRODirectory extends AbstractDirectory {
|
||||||
private ZipFile mZipFile;
|
private final ZipFile mZipFile;
|
||||||
private String mPath;
|
private final String mPath;
|
||||||
|
|
||||||
public ZipRODirectory(String zipFileName) throws DirectoryException {
|
public ZipRODirectory(String zipFileName) throws DirectoryException {
|
||||||
this(zipFileName, "");
|
this(zipFileName, "");
|
||||||
@ -129,8 +129,8 @@ public class ZipRODirectory extends AbstractDirectory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadAll() {
|
private void loadAll() {
|
||||||
mFiles = new LinkedHashSet<String>();
|
mFiles = new LinkedHashSet<>();
|
||||||
mDirs = new LinkedHashMap<String, AbstractDirectory>();
|
mDirs = new LinkedHashMap<>();
|
||||||
|
|
||||||
int prefixLen = getPath().length();
|
int prefixLen = getPath().length();
|
||||||
Enumeration<? extends ZipEntry> entries = getZipFile().entries();
|
Enumeration<? extends ZipEntry> entries = getZipFile().entries();
|
||||||
|
@ -41,8 +41,8 @@ public class BrutIO {
|
|||||||
|
|
||||||
public static long recursiveModifiedTime(File[] files) {
|
public static long recursiveModifiedTime(File[] files) {
|
||||||
long modified = 0;
|
long modified = 0;
|
||||||
for (int i = 0; i < files.length; i++) {
|
for (File file : files) {
|
||||||
long submodified = recursiveModifiedTime(files[i]);
|
long submodified = recursiveModifiedTime(file);
|
||||||
if (submodified > modified) {
|
if (submodified > modified) {
|
||||||
modified = submodified;
|
modified = submodified;
|
||||||
}
|
}
|
||||||
@ -54,8 +54,8 @@ public class BrutIO {
|
|||||||
long modified = file.lastModified();
|
long modified = file.lastModified();
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
File[] subfiles = file.listFiles();
|
File[] subfiles = file.listFiles();
|
||||||
for (int i = 0; i < subfiles.length; i++) {
|
for (File subfile : subfiles) {
|
||||||
long submodified = recursiveModifiedTime(subfiles[i]);
|
long submodified = recursiveModifiedTime(subfile);
|
||||||
if (submodified > modified) {
|
if (submodified > modified) {
|
||||||
modified = submodified;
|
modified = submodified;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package brut.util;
|
package brut.util;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Duo<T1, T2> {
|
public class Duo<T1, T2> {
|
||||||
public final T1 m1;
|
public final T1 m1;
|
||||||
public final T2 m2;
|
public final T2 m2;
|
||||||
@ -34,13 +36,10 @@ public class Duo<T1, T2> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Duo<T1, T2> other = (Duo<T1, T2>) obj;
|
final Duo<T1, T2> other = (Duo<T1, T2>) obj;
|
||||||
if (this.m1 != other.m1 && (this.m1 == null || !this.m1.equals(other.m1))) {
|
if (!Objects.equals(this.m1, other.m1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.m2 != other.m2 && (this.m2 == null || !this.m2.equals(other.m2))) {
|
return Objects.equals(this.m2, other.m2);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -80,9 +80,9 @@ public class ExtDataInput extends DataInputDelegate {
|
|||||||
*/
|
*/
|
||||||
public final int skipBytes(int n) throws IOException {
|
public final int skipBytes(int n) throws IOException {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
int cur = 0;
|
int cur;
|
||||||
|
|
||||||
while ((total < n) && ((cur = (int) super.skipBytes(n - total)) > 0)) {
|
while ((total < n) && ((cur = super.skipBytes(n - total)) > 0)) {
|
||||||
total += cur;
|
total += cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||||||
public abstract class Jar {
|
public abstract class Jar {
|
||||||
private static final Map<String, File> mExtracted = new HashMap<>();
|
private static final Map<String, File> mExtracted = new HashMap<>();
|
||||||
|
|
||||||
public static File getResourceAsFile(String name, Class clazz) throws BrutException {
|
public static File getResourceAsFile(String name, Class<?> clazz) throws BrutException {
|
||||||
File file = mExtracted.get(name);
|
File file = mExtracted.get(name);
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
file = extractToTmp(name, clazz);
|
file = extractToTmp(name, clazz);
|
||||||
@ -36,11 +36,11 @@ public abstract class Jar {
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File extractToTmp(String resourcePath, Class clazz) throws BrutException {
|
public static File extractToTmp(String resourcePath, Class<?> clazz) throws BrutException {
|
||||||
return extractToTmp(resourcePath, "brut_util_Jar_", clazz);
|
return extractToTmp(resourcePath, "brut_util_Jar_", clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File extractToTmp(String resourcePath, String tmpPrefix, Class clazz) throws BrutException {
|
public static File extractToTmp(String resourcePath, String tmpPrefix, Class<?> clazz) throws BrutException {
|
||||||
try {
|
try {
|
||||||
InputStream in = clazz.getResourceAsStream(resourcePath);
|
InputStream in = clazz.getResourceAsStream(resourcePath);
|
||||||
if (in == null) {
|
if (in == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user