Commit 8c43e7f7 authored by Skylot's avatar Skylot

style: fix code formating

parent 9e24a5ab
...@@ -42,7 +42,7 @@ import jadx.core.xmlgen.ResourcesSaver; ...@@ -42,7 +42,7 @@ import jadx.core.xmlgen.ResourcesSaver;
* jadx.load(); * jadx.load();
* jadx.save(); * jadx.save();
* </code></pre> * </code></pre>
* * <p>
* Instead of 'save()' you can iterate over decompiled classes: * Instead of 'save()' you can iterate over decompiled classes:
* <pre><code> * <pre><code>
* for(JavaClass cls : jadx.getClasses()) { * for(JavaClass cls : jadx.getClasses()) {
......
...@@ -65,9 +65,9 @@ public class ResourceFile { ...@@ -65,9 +65,9 @@ public class ResourceFile {
public String toString() { public String toString() {
return "ResourceFile{name='" + name + '\'' + ", type=" + type + "}"; return "ResourceFile{name='" + name + '\'' + ", type=" + type + "}";
} }
public static ResourceFile createResourceFileInstance(JadxDecompiler decompiler, String name, ResourceType type) { public static ResourceFile createResourceFileInstance(JadxDecompiler decompiler, String name, ResourceType type) {
if(!ZipSecurity.isValidZipEntryName(name)) { if (!ZipSecurity.isValidZipEntryName(name)) {
return null; return null;
} }
return new ResourceFile(decompiler, name, type); return new ResourceFile(decompiler, name, type);
......
...@@ -17,9 +17,9 @@ public class ResourceFileContent extends ResourceFile { ...@@ -17,9 +17,9 @@ public class ResourceFileContent extends ResourceFile {
public ResContainer loadContent() { public ResContainer loadContent() {
return ResContainer.singleFile(getName(), content); return ResContainer.singleFile(getName(), content);
} }
public static ResourceFileContent createResourceFileContentInstance(String name, ResourceType type, CodeWriter content) { public static ResourceFileContent createResourceFileContentInstance(String name, ResourceType type, CodeWriter content) {
if(!ZipSecurity.isValidZipEntryName(name)) { if (!ZipSecurity.isValidZipEntryName(name)) {
return null; return null;
} }
return new ResourceFileContent(name, type, content); return new ResourceFileContent(name, type, content);
......
...@@ -100,7 +100,7 @@ public final class ResourcesLoader { ...@@ -100,7 +100,7 @@ public final class ResourcesLoader {
case ARSC: case ARSC:
return new ResTableParser() return new ResTableParser()
.decodeFiles(inputStream); .decodeFiles(inputStream);
case IMG: case IMG:
return ResContainer.singleImageFile(rf.getName(), inputStream); return ResContainer.singleImageFile(rf.getName(), inputStream);
......
...@@ -289,14 +289,14 @@ public class CodeWriter { ...@@ -289,14 +289,14 @@ public class CodeWriter {
} }
public void save(File dir, String subDir, String fileName) { public void save(File dir, String subDir, String fileName) {
if(!ZipSecurity.isValidZipEntryName(subDir) || !ZipSecurity.isValidZipEntryName(fileName)) { if (!ZipSecurity.isValidZipEntryName(subDir) || !ZipSecurity.isValidZipEntryName(fileName)) {
return; return;
} }
save(dir, new File(subDir, fileName).getPath()); save(dir, new File(subDir, fileName).getPath());
} }
public void save(File dir, String fileName) { public void save(File dir, String fileName) {
if(!ZipSecurity.isValidZipEntryName(fileName)) { if (!ZipSecurity.isValidZipEntryName(fileName)) {
return; return;
} }
save(new File(dir, fileName)); save(new File(dir, fileName));
......
...@@ -659,7 +659,7 @@ public class InsnGen { ...@@ -659,7 +659,7 @@ public class InsnGen {
} }
void generateMethodArguments(CodeWriter code, InsnNode insn, int startArgNum, void generateMethodArguments(CodeWriter code, InsnNode insn, int startArgNum,
@Nullable MethodNode callMth) throws CodegenException { @Nullable MethodNode callMth) throws CodegenException {
int k = startArgNum; int k = startArgNum;
if (callMth != null && callMth.contains(AFlag.SKIP_FIRST_ARG)) { if (callMth != null && callMth.contains(AFlag.SKIP_FIRST_ARG)) {
k++; k++;
......
...@@ -44,5 +44,4 @@ public class Annotation { ...@@ -44,5 +44,4 @@ public class Annotation {
public String toString() { public String toString() {
return "Annotation[" + visibility + ", " + atype + ", " + values + "]"; return "Annotation[" + visibility + ", " + atype + ", " + values + "]";
} }
} }
...@@ -48,5 +48,4 @@ public class AnnotationsList implements IAttribute { ...@@ -48,5 +48,4 @@ public class AnnotationsList implements IAttribute {
public String toString() { public String toString() {
return Utils.listToString(map.values()); return Utils.listToString(map.values());
} }
} }
...@@ -28,5 +28,4 @@ public class MethodParameters implements IAttribute { ...@@ -28,5 +28,4 @@ public class MethodParameters implements IAttribute {
public String toString() { public String toString() {
return Utils.listToString(paramList); return Utils.listToString(paramList);
} }
} }
...@@ -78,5 +78,4 @@ public class EnumClassAttr implements IAttribute { ...@@ -78,5 +78,4 @@ public class EnumClassAttr implements IAttribute {
public String toString() { public String toString() {
return "Enum fields: " + fields; return "Enum fields: " + fields;
} }
} }
...@@ -26,5 +26,4 @@ public class ForceReturnAttr implements IAttribute { ...@@ -26,5 +26,4 @@ public class ForceReturnAttr implements IAttribute {
public String toString() { public String toString() {
return "FORCE_RETURN " + Utils.listToString(returnInsn.getArguments()); return "FORCE_RETURN " + Utils.listToString(returnInsn.getArguments());
} }
} }
...@@ -146,5 +146,4 @@ public final class MethodInfo { ...@@ -146,5 +146,4 @@ public final class MethodInfo {
return declClass.getFullName() + "." + name return declClass.getFullName() + "." + name
+ "(" + Utils.listToString(args) + "):" + retType; + "(" + Utils.listToString(args) + "):" + retType;
} }
} }
...@@ -80,5 +80,4 @@ public class ArithNode extends InsnNode { ...@@ -80,5 +80,4 @@ public class ArithNode extends InsnNode {
+ op.getSymbol() + " " + op.getSymbol() + " "
+ getArg(1); + getArg(1);
} }
} }
...@@ -35,7 +35,6 @@ public final class NamedArg extends InsnArg implements Named { ...@@ -35,7 +35,6 @@ public final class NamedArg extends InsnArg implements Named {
return false; return false;
} }
return name.equals(((NamedArg) o).name); return name.equals(((NamedArg) o).name);
} }
@Override @Override
......
...@@ -27,7 +27,6 @@ public class Edge { ...@@ -27,7 +27,6 @@ public class Edge {
} }
Edge edge = (Edge) o; Edge edge = (Edge) o;
return source.equals(edge.source) && target.equals(edge.target); return source.equals(edge.source) && target.equals(edge.target);
} }
@Override @Override
......
...@@ -9,5 +9,4 @@ public interface IBranchRegion extends IRegion { ...@@ -9,5 +9,4 @@ public interface IBranchRegion extends IRegion {
* NOTE: Contains 'null' elements for indicate empty branches. * NOTE: Contains 'null' elements for indicate empty branches.
*/ */
List<IContainer> getBranches(); List<IContainer> getBranches();
} }
...@@ -276,6 +276,7 @@ public class InsnNode extends LineAttrNode { ...@@ -276,6 +276,7 @@ public class InsnNode extends LineAttrNode {
} }
return true; return true;
} }
/** /**
* 'Hard' equals, compare all arguments * 'Hard' equals, compare all arguments
*/ */
......
...@@ -24,7 +24,7 @@ public final class IfInfo { ...@@ -24,7 +24,7 @@ public final class IfInfo {
} }
private IfInfo(IfCondition condition, BlockNode thenBlock, BlockNode elseBlock, private IfInfo(IfCondition condition, BlockNode thenBlock, BlockNode elseBlock,
Set<BlockNode> mergedBlocks, Set<BlockNode> skipBlocks) { Set<BlockNode> mergedBlocks, Set<BlockNode> skipBlocks) {
this.condition = condition; this.condition = condition;
this.thenBlock = thenBlock; this.thenBlock = thenBlock;
this.elseBlock = elseBlock; this.elseBlock = elseBlock;
......
...@@ -24,5 +24,4 @@ public class CatchAttr implements IAttribute { ...@@ -24,5 +24,4 @@ public class CatchAttr implements IAttribute {
public String toString() { public String toString() {
return tryBlock.toString(); return tryBlock.toString();
} }
} }
...@@ -120,5 +120,4 @@ public class ExceptionHandler { ...@@ -120,5 +120,4 @@ public class ExceptionHandler {
return (catchType == null ? "all" return (catchType == null ? "all"
: catchType.getShortName()) + " -> " + InsnUtils.formatOffset(handleOffset); : catchType.getShortName()) + " -> " + InsnUtils.formatOffset(handleOffset);
} }
} }
...@@ -25,5 +25,4 @@ public class SplitterBlockAttr implements IAttribute { ...@@ -25,5 +25,4 @@ public class SplitterBlockAttr implements IAttribute {
public String toString() { public String toString() {
return "Splitter: " + block; return "Splitter: " + block;
} }
} }
...@@ -260,7 +260,7 @@ public class CodeShrinker extends AbstractVisitor { ...@@ -260,7 +260,7 @@ public class CodeShrinker extends AbstractVisitor {
} }
private static boolean canMoveBetweenBlocks(InsnNode assignInsn, BlockNode assignBlock, private static boolean canMoveBetweenBlocks(InsnNode assignInsn, BlockNode assignBlock,
BlockNode useBlock, InsnNode useInsn) { BlockNode useBlock, InsnNode useInsn) {
if (!BlockUtils.isPathExists(assignBlock, useBlock)) { if (!BlockUtils.isPathExists(assignBlock, useBlock)) {
return false; return false;
} }
......
...@@ -207,7 +207,6 @@ public class SimplifyVisitor extends AbstractVisitor { ...@@ -207,7 +207,6 @@ public class SimplifyVisitor extends AbstractVisitor {
return concatInsn; return concatInsn;
} // end of if constructor is for StringBuilder } // end of if constructor is for StringBuilder
} // end of if we found a constructor early in the chain } // end of if we found a constructor early in the chain
} catch (Exception e) { } catch (Exception e) {
LOG.warn("Can't convert string concatenation: {} insn: {}", mth, insn, e); LOG.warn("Can't convert string concatenation: {} insn: {}", mth, insn, e);
} }
......
...@@ -18,5 +18,4 @@ public abstract class AbstractRegionVisitor implements IRegionVisitor { ...@@ -18,5 +18,4 @@ public abstract class AbstractRegionVisitor implements IRegionVisitor {
@Override @Override
public void leaveRegion(MethodNode mth, IRegion region) { public void leaveRegion(MethodNode mth, IRegion region) {
} }
} }
...@@ -61,7 +61,7 @@ public class DepthRegionTraversal { ...@@ -61,7 +61,7 @@ public class DepthRegionTraversal {
} }
private static boolean traverseIterativeStepInternal(MethodNode mth, IRegionIterativeVisitor visitor, private static boolean traverseIterativeStepInternal(MethodNode mth, IRegionIterativeVisitor visitor,
IContainer container) { IContainer container) {
if (container instanceof IRegion) { if (container instanceof IRegion) {
IRegion region = (IRegion) container; IRegion region = (IRegion) container;
if (visitor.visitRegion(mth, region)) { if (visitor.visitRegion(mth, region)) {
......
...@@ -9,5 +9,4 @@ public interface IRegionIterativeVisitor { ...@@ -9,5 +9,4 @@ public interface IRegionIterativeVisitor {
* If return 'true' traversal will be restarted. * If return 'true' traversal will be restarted.
*/ */
boolean visitRegion(MethodNode mth, IRegion region); boolean visitRegion(MethodNode mth, IRegion region);
} }
...@@ -14,5 +14,4 @@ public interface IRegionVisitor { ...@@ -14,5 +14,4 @@ public interface IRegionVisitor {
boolean enterRegion(MethodNode mth, IRegion region); boolean enterRegion(MethodNode mth, IRegion region);
void leaveRegion(MethodNode mth, IRegion region); void leaveRegion(MethodNode mth, IRegion region);
} }
...@@ -126,7 +126,7 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor ...@@ -126,7 +126,7 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
} }
private static LoopType checkArrayForEach(MethodNode mth, InsnNode initInsn, InsnNode incrInsn, private static LoopType checkArrayForEach(MethodNode mth, InsnNode initInsn, InsnNode incrInsn,
IfCondition condition) { IfCondition condition) {
if (!(incrInsn instanceof ArithNode)) { if (!(incrInsn instanceof ArithNode)) {
return null; return null;
} }
......
...@@ -27,5 +27,4 @@ public class SelectTypeVisitor { ...@@ -27,5 +27,4 @@ public class SelectTypeVisitor {
ArgType newType = ArgType.merge(dex, t, t.selectFirst()); ArgType newType = ArgType.merge(dex, t, t.selectFirst());
arg.setType(newType); arg.setType(newType);
} }
} }
...@@ -149,7 +149,7 @@ public class StringUtils { ...@@ -149,7 +149,7 @@ public class StringUtils {
} }
private static String escapeXmlChar(char c) { private static String escapeXmlChar(char c) {
if(c >= 0 && c <= 0x1F) { if (c >= 0 && c <= 0x1F) {
return "\\" + (int) c; return "\\" + (int) c;
} }
switch (c) { switch (c) {
......
...@@ -30,5 +30,4 @@ public class CodegenException extends JadxException { ...@@ -30,5 +30,4 @@ public class CodegenException extends JadxException {
public CodegenException(MethodNode mth, String msg, Throwable th) { public CodegenException(MethodNode mth, String msg, Throwable th) {
super(mth, msg, th); super(mth, msg, th);
} }
} }
...@@ -21,5 +21,4 @@ public class DecodeException extends JadxException { ...@@ -21,5 +21,4 @@ public class DecodeException extends JadxException {
public DecodeException(MethodNode mth, String msg, Throwable th) { public DecodeException(MethodNode mth, String msg, Throwable th) {
super(mth, msg, th); super(mth, msg, th);
} }
} }
...@@ -23,5 +23,4 @@ public class JadxException extends Exception { ...@@ -23,5 +23,4 @@ public class JadxException extends Exception {
public JadxException(MethodNode mth, String msg, Throwable th) { public JadxException(MethodNode mth, String msg, Throwable th) {
super(ErrorsCounter.formatMsg(mth, msg), th); super(ErrorsCounter.formatMsg(mth, msg), th);
} }
} }
...@@ -74,7 +74,9 @@ public class InputFile { ...@@ -74,7 +74,9 @@ public class InputFile {
} }
return; return;
} }
if (skipSources) return; if (skipSources) {
return;
}
throw new DecodeException("Unsupported input file format: " + file); throw new DecodeException("Unsupported input file format: " + file);
} }
......
...@@ -24,13 +24,12 @@ public class ZipSecurity { ...@@ -24,13 +24,12 @@ public class ZipSecurity {
} }
return isInSubDirectoryInternal(baseDir, canonFile.getParentFile()); return isInSubDirectoryInternal(baseDir, canonFile.getParentFile());
} }
public static boolean isInSubDirectory(File baseDir, File file) { public static boolean isInSubDirectory(File baseDir, File file) {
try { try {
file = file.getCanonicalFile(); file = file.getCanonicalFile();
baseDir = baseDir.getCanonicalFile(); baseDir = baseDir.getCanonicalFile();
} } catch (IOException e) {
catch(IOException e) {
return false; return false;
} }
return isInSubDirectoryInternal(baseDir, file); return isInSubDirectoryInternal(baseDir, file);
......
...@@ -55,7 +55,7 @@ public class BinaryXMLParser extends CommonBinaryParser { ...@@ -55,7 +55,7 @@ public class BinaryXMLParser extends CommonBinaryParser {
private boolean isOneLine = true; private boolean isOneLine = true;
private int namespaceDepth = 0; private int namespaceDepth = 0;
private int[] resourceIds; private int[] resourceIds;
private RootNode rootNode; private RootNode rootNode;
private String appPackageName; private String appPackageName;
...@@ -180,9 +180,9 @@ public class BinaryXMLParser extends CommonBinaryParser { ...@@ -180,9 +180,9 @@ public class BinaryXMLParser extends CommonBinaryParser {
int comment = is.readInt32(); int comment = is.readInt32();
int beginPrefix = is.readInt32(); int beginPrefix = is.readInt32();
int beginURI = is.readInt32(); int beginURI = is.readInt32();
String nsValue = getString(beginPrefix); String nsValue = getString(beginPrefix);
if(!nsMap.containsValue(nsValue)) { if (!nsMap.containsValue(nsValue)) {
nsMap.putIfAbsent(getString(beginURI), nsValue); nsMap.putIfAbsent(getString(beginURI), nsValue);
} }
namespaceDepth++; namespaceDepth++;
...@@ -200,9 +200,9 @@ public class BinaryXMLParser extends CommonBinaryParser { ...@@ -200,9 +200,9 @@ public class BinaryXMLParser extends CommonBinaryParser {
int endPrefix = is.readInt32(); int endPrefix = is.readInt32();
int endURI = is.readInt32(); int endURI = is.readInt32();
namespaceDepth--; namespaceDepth--;
String nsValue = getString(endPrefix); String nsValue = getString(endPrefix);
if(!nsMap.containsValue(nsValue)) { if (!nsMap.containsValue(nsValue)) {
nsMap.putIfAbsent(getString(endURI), nsValue); nsMap.putIfAbsent(getString(endURI), nsValue);
} }
} }
...@@ -313,7 +313,7 @@ public class BinaryXMLParser extends CommonBinaryParser { ...@@ -313,7 +313,7 @@ public class BinaryXMLParser extends CommonBinaryParser {
String decodedAttr = ManifestAttributes.getInstance().decode(attrName, attrValData); String decodedAttr = ManifestAttributes.getInstance().decode(attrName, attrValData);
if (decodedAttr != null) { if (decodedAttr != null) {
memorizePackageName(attrName, decodedAttr); memorizePackageName(attrName, decodedAttr);
if(isDeobfCandidateAttr(shortNsName, attrName)) { if (isDeobfCandidateAttr(shortNsName, attrName)) {
decodedAttr = deobfClassName(decodedAttr); decodedAttr = deobfClassName(decodedAttr);
} }
writer.add(StringUtils.escapeXML(decodedAttr)); writer.add(StringUtils.escapeXML(decodedAttr));
...@@ -339,16 +339,16 @@ public class BinaryXMLParser extends CommonBinaryParser { ...@@ -339,16 +339,16 @@ public class BinaryXMLParser extends CommonBinaryParser {
} }
return attrName; return attrName;
} }
private String generateNameForNS(String attrUrl) { private String generateNameForNS(String attrUrl) {
for(int i = 1; ; i++) { for (int i = 1; ; i++) {
String attrName = "ns" + i; String attrName = "ns" + i;
if(!nsMap.containsValue(attrName) && !nsMapGenerated.contains(attrName)) { if (!nsMap.containsValue(attrName) && !nsMapGenerated.contains(attrName)) {
nsMapGenerated.add(attrName); nsMapGenerated.add(attrName);
// do not add generated value to nsMap // do not add generated value to nsMap
// because attrUrl might be used in a neighbor element, but never defined // because attrUrl might be used in a neighbor element, but never defined
writer.add("xmlns:").add(attrName) writer.add("xmlns:").add(attrName)
.add("=\"").add(attrUrl).add("\" "); .add("=\"").add(attrUrl).add("\" ");
return attrName; return attrName;
} }
} }
...@@ -380,8 +380,8 @@ public class BinaryXMLParser extends CommonBinaryParser { ...@@ -380,8 +380,8 @@ public class BinaryXMLParser extends CommonBinaryParser {
} }
private void decodeAttribute(int attributeNS, int attrValDataType, int attrValData, private void decodeAttribute(int attributeNS, int attrValDataType, int attrValData,
String shortNsName, String attrName) { String shortNsName, String attrName) {
if (attrValDataType == TYPE_REFERENCE) { if (attrValDataType == TYPE_REFERENCE) {
// reference custom processing // reference custom processing
String name = styleMap.get(attrValData); String name = styleMap.get(attrValData);
...@@ -419,7 +419,7 @@ public class BinaryXMLParser extends CommonBinaryParser { ...@@ -419,7 +419,7 @@ public class BinaryXMLParser extends CommonBinaryParser {
} else { } else {
String str = valuesParser.decodeValue(attrValDataType, attrValData); String str = valuesParser.decodeValue(attrValDataType, attrValData);
memorizePackageName(attrName, str); memorizePackageName(attrName, str);
if(isDeobfCandidateAttr(shortNsName, attrName)) { if (isDeobfCandidateAttr(shortNsName, attrName)) {
str = deobfClassName(str); str = deobfClassName(str);
} }
writer.add(str != null ? StringUtils.escapeXML(str) : "null"); writer.add(str != null ? StringUtils.escapeXML(str) : "null");
...@@ -454,55 +454,54 @@ public class BinaryXMLParser extends CommonBinaryParser { ...@@ -454,55 +454,54 @@ public class BinaryXMLParser extends CommonBinaryParser {
writer.decIndent(); writer.decIndent();
} }
} }
private String getValidTagAttributeName(String originalName) { private String getValidTagAttributeName(String originalName) {
if(XMLChar.isValidName(originalName)) { if (XMLChar.isValidName(originalName)) {
return originalName; return originalName;
} }
if(tagAttrDeobfNames.containsKey(originalName)) { if (tagAttrDeobfNames.containsKey(originalName)) {
return tagAttrDeobfNames.get(originalName); return tagAttrDeobfNames.get(originalName);
} }
String generated; String generated;
do { do {
generated = generateTagAttrName(); generated = generateTagAttrName();
} }
while(tagAttrDeobfNames.containsValue(generated)); while (tagAttrDeobfNames.containsValue(generated));
tagAttrDeobfNames.put(originalName, generated); tagAttrDeobfNames.put(originalName, generated);
return generated; return generated;
} }
private static String generateTagAttrName() { private static String generateTagAttrName() {
final int length = 6; final int length = 6;
Random r = new Random(); Random r = new Random();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for(int i = 1; i <= length; i++) { for (int i = 1; i <= length; i++) {
sb.append((char)(r.nextInt(26) + 'a')); sb.append((char) (r.nextInt(26) + 'a'));
} }
return sb.toString(); return sb.toString();
} }
private String deobfClassName(String className) { private String deobfClassName(String className) {
String newName = XmlDeobf.deobfClassName(rootNode, className, String newName = XmlDeobf.deobfClassName(rootNode, className,
appPackageName); appPackageName);
if(newName != null) { if (newName != null) {
return newName; return newName;
} }
return className; return className;
} }
private boolean isDeobfCandidateAttr(String shortNsName, String attrName) { private boolean isDeobfCandidateAttr(String shortNsName, String attrName) {
String fullName; String fullName;
if(shortNsName != null) { if (shortNsName != null) {
fullName = shortNsName + ":" + attrName; fullName = shortNsName + ":" + attrName;
} } else {
else {
return false; return false;
} }
return "android:name".equals(fullName); return "android:name".equals(fullName);
} }
private void memorizePackageName(String attrName, String attrValue) { private void memorizePackageName(String attrName, String attrValue) {
if("manifest".equals(currentTag) && "package".equals(attrName)) { if ("manifest".equals(currentTag) && "package".equals(attrName)) {
appPackageName = attrValue; appPackageName = attrValue;
} }
} }
......
...@@ -96,5 +96,4 @@ public class CommonBinaryParser extends ParserConstants { ...@@ -96,5 +96,4 @@ public class CommonBinaryParser extends ParserConstants {
throw new IOException("Decode error: " + message throw new IOException("Decode error: " + message
+ ", position: 0x" + Long.toHexString(is.getPos())); + ", position: 0x" + Long.toHexString(is.getPos()));
} }
} }
...@@ -8,7 +8,6 @@ public class ParserConstants { ...@@ -8,7 +8,6 @@ public class ParserConstants {
protected ParserConstants() { protected ParserConstants() {
} }
protected static final String ANDROID_NS_URL = "http://schemas.android.com/apk/res/android"; protected static final String ANDROID_NS_URL = "http://schemas.android.com/apk/res/android";
/** /**
......
...@@ -84,7 +84,7 @@ public class ResTableParser extends CommonBinaryParser { ...@@ -84,7 +84,7 @@ public class ResTableParser extends CommonBinaryParser {
writer.finish(); writer.finish();
return writer; return writer;
} }
public CodeWriter makeXmlDump() { public CodeWriter makeXmlDump() {
CodeWriter writer = new CodeWriter(); CodeWriter writer = new CodeWriter();
writer.startLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); writer.startLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
...@@ -93,7 +93,7 @@ public class ResTableParser extends CommonBinaryParser { ...@@ -93,7 +93,7 @@ public class ResTableParser extends CommonBinaryParser {
Set<String> addedValues = new HashSet<>(); Set<String> addedValues = new HashSet<>();
for (ResourceEntry ri : resStorage.getResources()) { for (ResourceEntry ri : resStorage.getResources()) {
if(addedValues.add(ri.getTypeName() + "." + ri.getKeyName())) { if (addedValues.add(ri.getTypeName() + "." + ri.getKeyName())) {
String format = String.format("<public type=\"%s\" name=\"%s\" id=\"%s\" />", String format = String.format("<public type=\"%s\" name=\"%s\" id=\"%s\" />",
ri.getTypeName(), ri.getKeyName(), ri.getId()); ri.getTypeName(), ri.getKeyName(), ri.getId());
writer.startLine(format); writer.startLine(format);
......
...@@ -61,28 +61,28 @@ public class ResourcesSaver implements Runnable { ...@@ -61,28 +61,28 @@ public class ResourcesSaver implements Runnable {
String ext = FilenameUtils.getExtension(outFile.getName()); String ext = FilenameUtils.getExtension(outFile.getName());
try { try {
outFile = prepareFile(outFile); outFile = prepareFile(outFile);
if(!ZipSecurity.isInSubDirectory(outDir, outFile)) { if (!ZipSecurity.isInSubDirectory(outDir, outFile)) {
LOG.error("Path traversal attack detected, invalid resource name: {}", LOG.error("Path traversal attack detected, invalid resource name: {}",
outFile.getPath()); outFile.getPath());
return; return;
} }
ImageIO.write(image, ext, outFile); ImageIO.write(image, ext, outFile);
} catch (IOException e) { } catch (IOException e) {
LOG.error("Failed to save image: {}", rc.getName(), e); LOG.error("Failed to save image: {}", rc.getName(), e);
} }
return; return;
} }
if(!ZipSecurity.isInSubDirectory(outDir, outFile)) { if (!ZipSecurity.isInSubDirectory(outDir, outFile)) {
LOG.error("Path traversal attack detected, invalid resource name: {}", LOG.error("Path traversal attack detected, invalid resource name: {}",
rc.getFileName()); rc.getFileName());
return; return;
} }
saveToFile(rc, outFile); saveToFile(rc, outFile);
} }
private void saveToFile(ResContainer rc, File outFile) { private void saveToFile(ResContainer rc, File outFile) {
CodeWriter cw = rc.getContent(); CodeWriter cw = rc.getContent();
if (cw != null) { if (cw != null) {
......
...@@ -12,25 +12,25 @@ import jadx.core.dex.nodes.RootNode; ...@@ -12,25 +12,25 @@ import jadx.core.dex.nodes.RootNode;
*/ */
public class XmlDeobf { public class XmlDeobf {
private static final Map<String, String> deobfMap = new HashMap<>(); private static final Map<String, String> deobfMap = new HashMap<>();
private XmlDeobf() {} private XmlDeobf() {}
public static String deobfClassName(RootNode rootNode, String potencialClassName, public static String deobfClassName(RootNode rootNode, String potencialClassName,
String packageName) { String packageName) {
if(packageName != null && potencialClassName.startsWith(".")) { if (packageName != null && potencialClassName.startsWith(".")) {
potencialClassName = packageName + potencialClassName; potencialClassName = packageName + potencialClassName;
} }
return getNewClassName(rootNode, potencialClassName); return getNewClassName(rootNode, potencialClassName);
} }
private static String getNewClassName(RootNode rootNode, String old) { private static String getNewClassName(RootNode rootNode, String old) {
if(deobfMap.isEmpty()) { if (deobfMap.isEmpty()) {
for(ClassNode classNode : rootNode.getClasses(true)) { for (ClassNode classNode : rootNode.getClasses(true)) {
if(classNode.getAlias() != null) { if (classNode.getAlias() != null) {
String oldName = classNode.getClassInfo().getFullName(); String oldName = classNode.getClassInfo().getFullName();
String newName = classNode.getAlias().getFullName(); String newName = classNode.getAlias().getFullName();
if(!oldName.equals(newName)) { if (!oldName.equals(newName)) {
deobfMap.put(oldName, newName); deobfMap.put(oldName, newName);
} }
} }
......
...@@ -92,5 +92,4 @@ public class BackgroundWorker extends SwingWorker<Void, Void> { ...@@ -92,5 +92,4 @@ public class BackgroundWorker extends SwingWorker<Void, Void> {
protected void done() { protected void done() {
progressPane.setVisible(false); progressPane.setVisible(false);
} }
} }
...@@ -24,5 +24,4 @@ public class DecompileJob extends BackgroundJob { ...@@ -24,5 +24,4 @@ public class DecompileJob extends BackgroundJob {
public String getInfoString() { public String getInfoString() {
return "Decompiling: "; return "Decompiling: ";
} }
} }
...@@ -158,7 +158,7 @@ public class JadxSettings extends JadxCLIArgs { ...@@ -158,7 +158,7 @@ public class JadxSettings extends JadxCLIArgs {
this.showInconsistentCode = showInconsistentCode; this.showInconsistentCode = showInconsistentCode;
} }
public LangLocale getLangLocale(){ public LangLocale getLangLocale() {
return this.langLocale; return this.langLocale;
} }
......
...@@ -82,7 +82,7 @@ public class JadxSettingsAdapter { ...@@ -82,7 +82,7 @@ public class JadxSettingsAdapter {
private static <T> void populate(GsonBuilder builder, String json, Class<T> type, final T into) { private static <T> void populate(GsonBuilder builder, String json, Class<T> type, final T into) {
builder.registerTypeAdapter(type, (InstanceCreator<T>) t -> into) builder.registerTypeAdapter(type, (InstanceCreator<T>) t -> into)
.create() .create()
.fromJson(json, type); .fromJson(json, type);
} }
} }
...@@ -20,7 +20,6 @@ import jadx.gui.utils.NLS; ...@@ -20,7 +20,6 @@ import jadx.gui.utils.NLS;
import static jadx.gui.utils.Utils.FONT_HACK; import static jadx.gui.utils.Utils.FONT_HACK;
public class JadxSettingsWindow extends JDialog { public class JadxSettingsWindow extends JDialog {
private static final long serialVersionUID = -1804570470377354148L; private static final long serialVersionUID = -1804570470377354148L;
...@@ -72,7 +71,7 @@ public class JadxSettingsWindow extends JDialog { ...@@ -72,7 +71,7 @@ public class JadxSettingsWindow extends JDialog {
if (needReload) { if (needReload) {
mainWindow.reOpenFile(); mainWindow.reOpenFile();
} }
if (!settings.getLangLocale().equals(prevLang)){ if (!settings.getLangLocale().equals(prevLang)) {
JOptionPane.showMessageDialog( JOptionPane.showMessageDialog(
this, this,
NLS.str("msg.language_changed", settings.getLangLocale()), NLS.str("msg.language_changed", settings.getLangLocale()),
...@@ -194,7 +193,7 @@ public class JadxSettingsWindow extends JDialog { ...@@ -194,7 +193,7 @@ public class JadxSettingsWindow extends JDialog {
EditorTheme[] editorThemes = CodeArea.getAllThemes(); EditorTheme[] editorThemes = CodeArea.getAllThemes();
JComboBox<EditorTheme> themesCbx = new JComboBox<>(editorThemes); JComboBox<EditorTheme> themesCbx = new JComboBox<>(editorThemes);
for (EditorTheme theme: editorThemes) { for (EditorTheme theme : editorThemes) {
if (theme.getPath().equals(settings.getEditorThemePath())) { if (theme.getPath().equals(settings.getEditorThemePath())) {
themesCbx.setSelectedItem(theme); themesCbx.setSelectedItem(theme);
break; break;
...@@ -275,7 +274,7 @@ public class JadxSettingsWindow extends JDialog { ...@@ -275,7 +274,7 @@ public class JadxSettingsWindow extends JDialog {
private SettingsGroup makeOtherGroup() { private SettingsGroup makeOtherGroup() {
JComboBox<LangLocale> languageCbx = new JComboBox<>(NLS.getI18nLocales()); JComboBox<LangLocale> languageCbx = new JComboBox<>(NLS.getI18nLocales());
for (LangLocale locale: NLS.getI18nLocales()) { for (LangLocale locale : NLS.getI18nLocales()) {
if (locale.equals(settings.getLangLocale())) { if (locale.equals(settings.getLangLocale())) {
languageCbx.setSelectedItem(locale); languageCbx.setSelectedItem(locale);
break; break;
......
...@@ -205,7 +205,7 @@ public class JResource extends JLoadableNode implements Comparable<JResource> { ...@@ -205,7 +205,7 @@ public class JResource extends JLoadableNode implements Comparable<JResource> {
if (ext.equals("html")) { if (ext.equals("html")) {
return SyntaxConstants.SYNTAX_STYLE_HTML; return SyntaxConstants.SYNTAX_STYLE_HTML;
} }
if(ext.equals("arsc")) { if (ext.equals("arsc")) {
return SyntaxConstants.SYNTAX_STYLE_XML; return SyntaxConstants.SYNTAX_STYLE_XML;
} }
return null; return null;
......
...@@ -38,7 +38,7 @@ public class JRoot extends JNode { ...@@ -38,7 +38,7 @@ public class JRoot extends JNode {
} }
JCertificate certificate = getCertificate(wrapper.getResources()); JCertificate certificate = getCertificate(wrapper.getResources());
if(certificate != null) { if (certificate != null) {
add(certificate); add(certificate);
} }
} }
...@@ -84,15 +84,12 @@ public class JRoot extends JNode { ...@@ -84,15 +84,12 @@ public class JRoot extends JNode {
if (rf.getZipRef() != null) { if (rf.getZipRef() != null) {
String rfName = rf.getName().toUpperCase(); String rfName = rf.getName().toUpperCase();
if (rfName.endsWith(".DSA")||rfName.endsWith(".RSA")) { if (rfName.endsWith(".DSA") || rfName.endsWith(".RSA")) {
return new JCertificate(rf); return new JCertificate(rf);
} }
} }
} }
return null; return null;
} }
private JResource getResourceByName(JResource rf, String name) { private JResource getResourceByName(JResource rf, String name) {
......
...@@ -302,8 +302,8 @@ public abstract class CommonSearchDialog extends JDialog { ...@@ -302,8 +302,8 @@ public abstract class CommonSearchDialog extends JDialog {
protected static class ResultsModel extends AbstractTableModel { protected static class ResultsModel extends AbstractTableModel {
private static final long serialVersionUID = -7821286846923903208L; private static final long serialVersionUID = -7821286846923903208L;
private static final String[] COLUMN_NAMES = { private static final String[] COLUMN_NAMES = {
NLS.str("search_dialog.col_node"), NLS.str("search_dialog.col_node"),
NLS.str("search_dialog.col_code") NLS.str("search_dialog.col_code")
}; };
private final transient ArrayList<JNode> rows = new ArrayList<>(); private final transient ArrayList<JNode> rows = new ArrayList<>();
......
...@@ -293,11 +293,10 @@ public class MainWindow extends JFrame { ...@@ -293,11 +293,10 @@ public class MainWindow extends JFrame {
if (resFile != null && JResource.isSupportedForView(resFile.getType())) { if (resFile != null && JResource.isSupportedForView(resFile.getType())) {
tabbedPane.showResource(res); tabbedPane.showResource(res);
} }
}else if (obj instanceof JCertificate) { } else if (obj instanceof JCertificate) {
JCertificate cert = (JCertificate) obj; JCertificate cert = (JCertificate) obj;
tabbedPane.showCertificate(cert); tabbedPane.showCertificate(cert);
} } else if (obj instanceof JNode) {
else if (obj instanceof JNode) {
JNode node = (JNode) obj; JNode node = (JNode) obj;
JClass cls = node.getRootClass(); JClass cls = node.getRootClass();
if (cls != null) { if (cls != null) {
......
...@@ -67,7 +67,7 @@ public class Asset { ...@@ -67,7 +67,7 @@ public class Asset {
@Override @Override
public String toString() { public String toString() {
return name return name
+ ", size: " + String.format("%.2fMB", size / 1024. /1024.) + ", size: " + String.format("%.2fMB", size / 1024. / 1024.)
+ ", downloads count: " + downloadCount + ", downloads count: " + downloadCount
+ ", url: " + downloadUrl + ", url: " + downloadUrl
+ ", date: " + createdAt; + ", date: " + createdAt;
......
...@@ -41,7 +41,7 @@ public class CodeUsageInfo { ...@@ -41,7 +41,7 @@ public class CodeUsageInfo {
} }
private void addUsage(JNode jNode, JavaClass javaClass, private void addUsage(JNode jNode, JavaClass javaClass,
CodeLinesInfo linesInfo, CodePosition codePosition, List<StringRef> lines) { CodeLinesInfo linesInfo, CodePosition codePosition, List<StringRef> lines) {
UsageInfo usageInfo = usageMap.get(jNode); UsageInfo usageInfo = usageMap.get(jNode);
if (usageInfo == null) { if (usageInfo == null) {
usageInfo = new UsageInfo(); usageInfo = new UsageInfo();
......
...@@ -3,32 +3,32 @@ package jadx.gui.utils; ...@@ -3,32 +3,32 @@ package jadx.gui.utils;
import java.util.Locale; import java.util.Locale;
public class LangLocale { public class LangLocale {
private Locale locale; private Locale locale;
public LangLocale(Locale locale) { public LangLocale(Locale locale) {
this.locale = locale; this.locale = locale;
} }
public LangLocale(String l, String c) { public LangLocale(String l, String c) {
this.locale = new Locale(l, c); this.locale = new Locale(l, c);
} }
public Locale get() { public Locale get() {
return locale; return locale;
} }
@Override @Override
public String toString() { public String toString() {
return NLS.str("language.name", this); return NLS.str("language.name", this);
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj instanceof LangLocale && locale.equals(((LangLocale) obj).get()); return obj instanceof LangLocale && locale.equals(((LangLocale) obj).get());
} }
@Override @Override
public int hashCode() { public int hashCode() {
return locale.hashCode(); return locale.hashCode();
} }
} }
...@@ -67,21 +67,21 @@ public class Link extends JLabel implements MouseListener { ...@@ -67,21 +67,21 @@ public class Link extends JLabel implements MouseListener {
String os = System.getProperty("os.name").toLowerCase(); String os = System.getProperty("os.name").toLowerCase();
if (os.contains("win")) { if (os.contains("win")) {
new ProcessBuilder() new ProcessBuilder()
.command(new String[] {"rundll32", "url.dll,FileProtocolHandler", url}) .command(new String[]{"rundll32", "url.dll,FileProtocolHandler", url})
.start(); .start();
return; return;
} }
if (os.contains("mac")) { if (os.contains("mac")) {
new ProcessBuilder() new ProcessBuilder()
.command(new String[] {"open", url}) .command(new String[]{"open", url})
.start(); .start();
return; return;
} }
Map<String, String> env = System.getenv(); Map<String, String> env = System.getenv();
if (env.get("BROWSER") != null) { if (env.get("BROWSER") != null) {
new ProcessBuilder() new ProcessBuilder()
.command(new String[] {env.get("BROWSER"), url}) .command(new String[]{env.get("BROWSER"), url})
.start(); .start();
return; return;
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -7,10 +7,15 @@ import java.util.Map; ...@@ -7,10 +7,15 @@ import java.util.Map;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Vector; import java.util.Vector;
import org.jetbrains.annotations.NotNull;
public class NLS { public class NLS {
private static final Charset JAVA_CHARSET = Charset.forName("ISO-8859-1");
private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
private static Vector<LangLocale> i18nLocales = new Vector<>(); private static Vector<LangLocale> i18nLocales = new Vector<>();
private static Map<LangLocale, Map<String, String>> i18nMessagesMap; private static Map<LangLocale, Map<String, String>> i18nMessagesMap = new HashMap<>();
// Use these two fields to avoid invoking Map.get() method twice. // Use these two fields to avoid invoking Map.get() method twice.
private static Map<String, String> localizedMessagesMap; private static Map<String, String> localizedMessagesMap;
...@@ -19,14 +24,7 @@ public class NLS { ...@@ -19,14 +24,7 @@ public class NLS {
private static LangLocale currentLocale; private static LangLocale currentLocale;
private static LangLocale localLocale; private static LangLocale localLocale;
private static Charset javaCharset;
private static Charset utf8Charset;
static { static {
javaCharset = Charset.forName("ISO-8859-1");
utf8Charset = Charset.forName("UTF-8");
i18nMessagesMap = new HashMap<>();
localLocale = new LangLocale(Locale.getDefault()); localLocale = new LangLocale(Locale.getDefault());
i18nLocales.add(new LangLocale("en", "US")); // As default language i18nLocales.add(new LangLocale("en", "US")); // As default language
...@@ -35,8 +33,9 @@ public class NLS { ...@@ -35,8 +33,9 @@ public class NLS {
i18nLocales.forEach(NLS::load); i18nLocales.forEach(NLS::load);
fallbackMessagesMap = i18nMessagesMap.get(i18nLocales.get(0)); LangLocale defLang = i18nLocales.get(0);
localizedMessagesMap = i18nMessagesMap.get(i18nLocales.get(0)); fallbackMessagesMap = i18nMessagesMap.get(defLang);
localizedMessagesMap = i18nMessagesMap.get(defLang);
} }
private NLS() { private NLS() {
...@@ -45,31 +44,39 @@ public class NLS { ...@@ -45,31 +44,39 @@ public class NLS {
private static void load(LangLocale locale) { private static void load(LangLocale locale) {
ResourceBundle bundle = ResourceBundle.getBundle("i18n/Messages", locale.get()); ResourceBundle bundle = ResourceBundle.getBundle("i18n/Messages", locale.get());
Map<String, String> resMap = new HashMap<>(); Map<String, String> resMap = new HashMap<>();
for (String key : bundle.keySet()) {
for(String key : bundle.keySet()){ String str = bundle.getString(key);
resMap.put(key, new String( resMap.put(key, convertCharset(str));
bundle.getString(key).getBytes(javaCharset),
utf8Charset));
} }
i18nMessagesMap.put(locale, resMap); i18nMessagesMap.put(locale, resMap);
} }
@NotNull
private static String convertCharset(String str) {
return new String(str.getBytes(JAVA_CHARSET), UTF8_CHARSET);
}
public static String str(String key) { public static String str(String key) {
if(localizedMessagesMap.containsKey(key)){ String str = localizedMessagesMap.get(key);
return localizedMessagesMap.get(key); if (str != null) {
return str;
} }
return fallbackMessagesMap.get(key);// definitely exists return fallbackMessagesMap.get(key); // definitely exists
} }
public static String str(String key, LangLocale locale) { public static String str(String key, LangLocale locale) {
if(i18nMessagesMap.get(locale).containsKey(key)){ Map<String, String> strings = i18nMessagesMap.get(locale);
return i18nMessagesMap.get(locale).get(key); if (strings != null) {
String str = strings.get(key);
if (str != null) {
return str;
}
} }
return fallbackMessagesMap.get(key);// definitely exists return fallbackMessagesMap.get(key); // definitely exists
} }
public static void setLocale(LangLocale locale) { public static void setLocale(LangLocale locale) {
if(i18nMessagesMap.containsKey(locale)){ if (i18nMessagesMap.containsKey(locale)) {
currentLocale = locale; currentLocale = locale;
} else { } else {
currentLocale = i18nLocales.get(0); currentLocale = i18nLocales.get(0);
...@@ -77,7 +84,7 @@ public class NLS { ...@@ -77,7 +84,7 @@ public class NLS {
localizedMessagesMap = i18nMessagesMap.get(currentLocale); localizedMessagesMap = i18nMessagesMap.get(currentLocale);
} }
public static Vector<LangLocale> getI18nLocales(){ public static Vector<LangLocale> getI18nLocales() {
return i18nLocales; return i18nLocales;
} }
...@@ -85,12 +92,11 @@ public class NLS { ...@@ -85,12 +92,11 @@ public class NLS {
return currentLocale; return currentLocale;
} }
public static LangLocale defaultLocale(){ public static LangLocale defaultLocale() {
if(i18nMessagesMap.containsKey(localLocale)){ if (i18nMessagesMap.containsKey(localLocale)) {
return localLocale; return localLocale;
} else {
// fallback to english if unsupported
return i18nLocales.get(0);
} }
// fallback to english if unsupported
return i18nLocales.get(0);
} }
} }
...@@ -18,6 +18,7 @@ public class LogCollector extends AppenderBase<ILoggingEvent> { ...@@ -18,6 +18,7 @@ public class LogCollector extends AppenderBase<ILoggingEvent> {
public static final int BUFFER_SIZE = 5000; public static final int BUFFER_SIZE = 5000;
private static final LogCollector INSTANCE = new LogCollector(); private static final LogCollector INSTANCE = new LogCollector();
public static LogCollector getInstance() { public static LogCollector getInstance() {
return INSTANCE; return INSTANCE;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment