Better multi packs handling (Alchemy) - direct editing allowed

Better package/class splitting for obfuscated names
This commit is contained in:
Jindra Petřík
2015-06-12 13:08:32 +02:00
parent 47578bd13f
commit 650aefede2
28 changed files with 3747 additions and 3623 deletions
@@ -0,0 +1,106 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.graph;
import com.jpexs.decompiler.flash.IdentifiersDeobfuscation;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
*
* @author JPEXS
*/
public class DottedChain {
public List<String> parts = new ArrayList<>();
public DottedChain(List<String> parts) {
this.parts = new ArrayList<>(parts);
}
public DottedChain(String... parts) {
for (int i = 0; i < parts.length; i++) {
this.parts.add(parts[i]);
}
}
public String getLast() {
if (parts.isEmpty()) {
return "";
} else {
return parts.get(parts.size() - 1);
}
}
public DottedChain getWithoutLast() {
List<String> nparts = new ArrayList<>(parts);
if (!nparts.isEmpty()) {
nparts.remove(nparts.size() - 1);
}
return new DottedChain(nparts);
}
public String toPrintableString() {
String ret = "";
for (int i = 0; i < parts.size(); i++) {
if (i > 0) {
ret += ".";
}
ret += IdentifiersDeobfuscation.printIdentifier(true, parts.get(0));
}
return ret;
}
@Override
public String toString() {
String ret = "";
for (int i = 0; i < parts.size(); i++) {
if (i > 0) {
ret += ".";
}
ret += parts.get(i);
}
return ret;
}
@Override
public int hashCode() {
int hash = 3;
hash = 89 * hash + Objects.hashCode(this.parts);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof String) {
obj = new DottedChain(((String) obj).split("\\."));
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final DottedChain other = (DottedChain) obj;
if (!Objects.equals(this.parts, other.parts)) {
return false;
}
return true;
}
}
@@ -31,33 +31,37 @@ import java.util.Objects;
* @author JPEXS
*/
public class TypeItem extends GraphTargetItem {
public static TypeItem BOOLEAN = new TypeItem("Boolean");
public static TypeItem STRING = new TypeItem("String");
public static TypeItem ARRAY = new TypeItem("Array");
public static UnboundedTypeItem UNBOUNDED = new UnboundedTypeItem();
public String fullTypeName;
public TypeItem(String fullTypeName) {
public DottedChain fullTypeName;
public TypeItem(String s) {
this(s == null ? new DottedChain() : new DottedChain(s.split("\\.")));
}
public TypeItem(DottedChain fullTypeName) {
this(fullTypeName, new ArrayList<GraphTargetItem>());
}
public TypeItem(String fullTypeName, List<GraphTargetItem> subtypes) {
public TypeItem(DottedChain fullTypeName, List<GraphTargetItem> subtypes) {
super(null, NOPRECEDENCE);
this.fullTypeName = fullTypeName;
}
@Override
public int hashCode() {
int hash = 7;
hash = 83 * hash + Objects.hashCode(this.fullTypeName);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
@@ -72,37 +76,33 @@ public class TypeItem extends GraphTargetItem {
}
return true;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (localData.fullyQualifiedNames.contains(fullTypeName)) {
writer.hilightSpecial(IdentifiersDeobfuscation.printNamespace(localData.constantsAvm2 != null, fullTypeName), HighlightSpecialType.TYPE_NAME, fullTypeName);
writer.hilightSpecial(IdentifiersDeobfuscation.printNamespace(localData.constantsAvm2 != null, fullTypeName.toPrintableString()), HighlightSpecialType.TYPE_NAME, fullTypeName.toPrintableString());
} else {
String simpleName = fullTypeName;
if (simpleName.contains(".")) {
simpleName = simpleName.substring(simpleName.lastIndexOf('.') + 1);
}
writer.hilightSpecial(IdentifiersDeobfuscation.printNamespace(localData.constantsAvm2 != null, simpleName), HighlightSpecialType.TYPE_NAME, fullTypeName);
writer.hilightSpecial(IdentifiersDeobfuscation.printIdentifier(localData.constantsAvm2 != null, fullTypeName.getLast()), HighlightSpecialType.TYPE_NAME, fullTypeName.toPrintableString());
}
return writer;
}
@Override
public GraphTargetItem returnType() {
return this;
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public String toString() {
return fullTypeName;
return fullTypeName.toString();
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);