mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-27 14:50:45 +00:00
Fixed code style
This commit is contained in:
@@ -40,7 +40,7 @@ public class ABCOutputStream extends OutputStream {
|
||||
|
||||
private final OutputStream os;
|
||||
private long position = 0L;
|
||||
|
||||
|
||||
public ABCOutputStream(OutputStream os) {
|
||||
this.os = os;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class ABCOutputStream extends OutputStream {
|
||||
@Override
|
||||
public void write(byte[] data) throws IOException {
|
||||
os.write(data);
|
||||
position += data.length;
|
||||
position += data.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -378,14 +378,15 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
}
|
||||
|
||||
private class Label {
|
||||
|
||||
public long addr;
|
||||
|
||||
public Label(long addr) {
|
||||
this.addr = addr;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Injects debugfile, debugline instructions into the code.
|
||||
*
|
||||
@@ -445,7 +446,7 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
if (!bodyToFunctionName.containsKey(bodyIndex)) {
|
||||
bodyToFunctionName.put(bodyIndex, method.getProperties().localName);
|
||||
}
|
||||
|
||||
|
||||
bodyToActivationReg.put(bodyIndex, method.getProperties().activationRegIndex);
|
||||
int pos = -1;
|
||||
int regIndex = -1;
|
||||
@@ -464,7 +465,7 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
if (instrOffset == -1) {
|
||||
lonelyBody.add(bodyIndex);
|
||||
break blk;
|
||||
}
|
||||
}
|
||||
try {
|
||||
pos = abc.bodies.get(bodyIndex).getCode().adr2pos(instrOffset);
|
||||
} catch (ConvertException cex) {
|
||||
@@ -480,7 +481,7 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
}
|
||||
//int origPos = bodyLineToPos.get(bodyIndex).containsKey(line) ? bodyLineToPos.get(bodyIndex).get(line) : -1;
|
||||
|
||||
bodyToPosToLine.get(bodyIndex).put(pos, line);
|
||||
bodyToPosToLine.get(bodyIndex).put(pos, line);
|
||||
bodyLineToPos.get(bodyIndex).put(line, pos);
|
||||
} else {
|
||||
lonelyBody.add(bodyIndex);
|
||||
@@ -520,7 +521,7 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
+ cls.replace(";", "{{semicolon}}")
|
||||
+ ".as";
|
||||
filename = filename.replaceAll("\\{(invalid_utf8=[0-9]+)\\}", "[$1]");
|
||||
|
||||
|
||||
//Remove debug info from lonely bodies
|
||||
for (int bodyIndex : lonelyBody) {
|
||||
if (!bodyToPosToLine.keySet().contains(bodyIndex)) {
|
||||
@@ -561,7 +562,7 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
}
|
||||
}
|
||||
List<Object> code2 = new ArrayList<>();
|
||||
|
||||
|
||||
int dpos = 0;
|
||||
code2.add(new AVM2Instruction(0, AVM2Instructions.DebugFile, new int[]{abc.constants.getStringId(filename, true)}));
|
||||
dpos++;
|
||||
@@ -582,7 +583,7 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
activationRegName = bodyToFunctionName.get(bodyIndex) + "$0";
|
||||
}
|
||||
code2.add(new AVM2Instruction(0, AVM2Instructions.Debug, new int[]{1, abc.constants.getStringId(activationRegName, true), activationReg - 1, bodyLine}));
|
||||
}
|
||||
}
|
||||
List<Integer> pos = new ArrayList<>(bodyToPosToLine.get(bodyIndex).keySet());
|
||||
Collections.sort(pos);
|
||||
Collections.reverse(pos);
|
||||
@@ -598,9 +599,9 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
if (delIns.contains(code.get(i))) {
|
||||
continue;
|
||||
}
|
||||
code2.add(code.get(i));
|
||||
code2.add(code.get(i));
|
||||
}
|
||||
for (int i : pos) {
|
||||
for (int i : pos) {
|
||||
int line = bodyToPosToLine.get(bodyIndex).get(i);
|
||||
if (addedLines.contains(line)) {
|
||||
continue;
|
||||
@@ -624,9 +625,9 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
Label lab = (Label) obj;
|
||||
mapOffsets.put(lab.addr, adr);
|
||||
}
|
||||
}
|
||||
}
|
||||
code.clear();
|
||||
|
||||
|
||||
adr = 0;
|
||||
for (int i = 0; i < code2.size(); i++) {
|
||||
Object obj = code2.get(i);
|
||||
@@ -650,13 +651,13 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
if (mapOffsets.containsKey(targetAddr)) {
|
||||
changedAddr = mapOffsets.get(targetAddr);
|
||||
changedOperand = (int) (changedAddr - adr);
|
||||
ins.operands[0] = changedOperand;
|
||||
ins.operands[0] = changedOperand;
|
||||
} else {
|
||||
logger.log(Level.WARNING, "Invalid jump target in script {0}, bodyIndex {1}", new Object[]{toString(), bodyIndex});
|
||||
}
|
||||
for (int k = 2; k < ins.operands.length; k++) {
|
||||
targetAddr = ins.getAddress() + ins.operands[k];
|
||||
if (mapOffsets.containsKey(targetAddr)) {
|
||||
if (mapOffsets.containsKey(targetAddr)) {
|
||||
changedAddr = mapOffsets.get(targetAddr);
|
||||
changedOperand = (int) (changedAddr - adr);
|
||||
ins.operands[k] = changedOperand;
|
||||
@@ -680,12 +681,12 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
ex.start = (int) lstart;
|
||||
ex.target = (int) ltarget;
|
||||
ex.end = (int) lend;
|
||||
}
|
||||
}
|
||||
b.setModified();
|
||||
}
|
||||
|
||||
((Tag) abc.parentTag).setModified(true);
|
||||
}
|
||||
|
||||
((Tag) abc.parentTag).setModified(true);
|
||||
}
|
||||
|
||||
public void injectPCodeDebugInfo(int abcIndex) {
|
||||
|
||||
@@ -718,7 +719,7 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
Trait trait;
|
||||
int traitIndex = -10;
|
||||
if (trt != null && cls != null) {
|
||||
traitIndex = (int) trt.getProperties().index;
|
||||
traitIndex = (int) trt.getProperties().index;
|
||||
}
|
||||
bodyToIdentifier.put(bodyIndex, "abc:" + abcIndex + ",script:" + scriptIndex + ",class:" + classIndex + ",trait:" + traitIndex + ",method:" + methodIndex + ",body:" + bodyIndex);
|
||||
break;
|
||||
|
||||
@@ -2415,7 +2415,7 @@ public class AVM2Code implements Cloneable {
|
||||
}, body);
|
||||
code.remove(pos);
|
||||
//checkValidOffsets(body);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces instruction by another. Properly handles offsets. Note: If
|
||||
|
||||
@@ -871,5 +871,5 @@ public class AVM2ConstantPool implements Cloneable {
|
||||
for (int i = 0; i < constant_multiname.size(); i++) {
|
||||
Multiname.checkTypeNameCyclic(this, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -299,7 +299,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple {
|
||||
public int adr2pos(long adr) {
|
||||
return code.adr2pos(adr);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int adr2pos(long adr, boolean nearest) {
|
||||
return code.adr2pos(adr, nearest);
|
||||
|
||||
+2
-3
@@ -306,18 +306,17 @@ public class AVM2DeobfuscatorRegistersOld extends AVM2DeobfuscatorSimpleOld {
|
||||
public int adr2pos(long adr) {
|
||||
return code.adr2pos(adr);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int adr2pos(long adr, boolean nearest) {
|
||||
return code.adr2pos(adr, nearest);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long pos2adr(int pos) {
|
||||
return code.pos2adr(pos);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<Long> getImportantAddresses() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
|
||||
@@ -58,8 +58,8 @@ public class FastAVM2List implements Collection<AVM2InstructionItem> {
|
||||
|
||||
size = code.size();
|
||||
getJumps(avm2code, actionItemMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public final AVM2InstructionItem insertItemBefore(AVM2InstructionItem item, AVM2Instruction action) {
|
||||
AVM2InstructionItem newItem = new AVM2InstructionItem(action);
|
||||
return insertItemBefore(item, newItem);
|
||||
@@ -77,8 +77,8 @@ public class FastAVM2List implements Collection<AVM2InstructionItem> {
|
||||
public final AVM2InstructionItem insertItemAfter(AVM2InstructionItem item, AVM2Instruction action) {
|
||||
AVM2InstructionItem newItem = new AVM2InstructionItem(action);
|
||||
return insertItemAfter(item, newItem);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public final AVM2InstructionItem insertItemAfter(AVM2InstructionItem item, AVM2InstructionItem newItem) {
|
||||
if (item == null && firstItem == null) {
|
||||
firstItem = newItem;
|
||||
|
||||
@@ -2051,10 +2051,10 @@ public class AVM2Graph extends Graph {
|
||||
protected void processOther(List<GraphTargetItem> list, long lastLoopId) {
|
||||
if (list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int pos = list.size() - 1;
|
||||
|
||||
|
||||
if (list.get(pos) instanceof ContinueItem) {
|
||||
if (((ContinueItem) list.get(pos)).loopId != lastLoopId) {
|
||||
return;
|
||||
@@ -2064,9 +2064,9 @@ public class AVM2Graph extends Graph {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Remove continues from all branches of try...catch block if its continue to parent loop
|
||||
if (list.get(pos) instanceof TryAVM2Item) {
|
||||
if (list.get(pos) instanceof TryAVM2Item) {
|
||||
TryAVM2Item ta = (TryAVM2Item) list.get(pos);
|
||||
for (List<GraphTargetItem> cc : ta.catchCommands) {
|
||||
if (!cc.isEmpty()) {
|
||||
@@ -2094,9 +2094,9 @@ public class AVM2Graph extends Graph {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void finalProcessAfter(List<GraphTargetItem> list, int level, FinalProcessLocalData localData, String path) {
|
||||
super.finalProcessAfter(list, level, localData, path);
|
||||
|
||||
@@ -122,7 +122,7 @@ public class AVM2GraphSource extends GraphSource {
|
||||
public int adr2pos(long adr) {
|
||||
return code.adr2pos(adr);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int adr2pos(long adr, boolean nearest) {
|
||||
return code.adr2pos(adr, true);
|
||||
@@ -131,5 +131,5 @@ public class AVM2GraphSource extends GraphSource {
|
||||
@Override
|
||||
public long pos2adr(int pos) {
|
||||
return code.pos2adr(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -172,7 +172,7 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem {
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Long> getOffsets() {
|
||||
List<Long> ret = new ArrayList<>();
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ public class CoerceAIns extends InstructionDefinition implements CoerceOrConvert
|
||||
|
||||
public CoerceAIns() {
|
||||
super(0x82, "coerce_a", new int[]{}, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
|
||||
|
||||
+7
-6
@@ -24,13 +24,14 @@ import com.jpexs.decompiler.graph.TypeItem;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
|
||||
/**
|
||||
* Store new Activation object. This exists just for the purpose of passing
|
||||
* activation register to the GraphTextWriter to correctly be read
|
||||
* by debug info injector.
|
||||
* Store new Activation object. This exists just for the purpose of passing
|
||||
* activation register to the GraphTextWriter to correctly be read by debug info
|
||||
* injector.
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class StoreNewActivationAVM2Item extends AVM2Item {
|
||||
|
||||
|
||||
public int regIndex;
|
||||
|
||||
public StoreNewActivationAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, int regIndex) {
|
||||
@@ -47,7 +48,7 @@ public class StoreNewActivationAVM2Item extends AVM2Item {
|
||||
public boolean needsSemicolon() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
HighlightData hd = new HighlightData();
|
||||
@@ -69,5 +70,5 @@ public class StoreNewActivationAVM2Item extends AVM2Item {
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -101,7 +101,7 @@ public class ASM3Parser {
|
||||
return label + " at address " + offset;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static int checkMultinameIndex(AVM2ConstantPool constants, int index, int line) throws AVM2ParseException {
|
||||
if ((index < 0) || (index >= constants.getMultinameCount())) {
|
||||
@@ -733,7 +733,7 @@ public class ASM3Parser {
|
||||
}
|
||||
return new ValueKind(value_index, value_kind);
|
||||
}
|
||||
|
||||
|
||||
public static AVM2Code parse(ABC abc, Reader reader, Trait trait, MethodBody body, MethodInfo info) throws IOException, AVM2ParseException, InterruptedException {
|
||||
return parse(abc, reader, trait, null, body, info);
|
||||
}
|
||||
|
||||
+2958
-2740
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -23,7 +23,7 @@ package com.jpexs.decompiler.flash.abc.avm2.parser.pcode;
|
||||
public class ParsedSymbol {
|
||||
|
||||
public int pos;
|
||||
|
||||
|
||||
public int type;
|
||||
|
||||
public Object value;
|
||||
|
||||
+7
-10
@@ -139,14 +139,13 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
return currentFinId++;
|
||||
}
|
||||
|
||||
|
||||
private long uniqLast = 0;
|
||||
|
||||
public String uniqId() {
|
||||
uniqLast++;
|
||||
return "" + uniqLast;
|
||||
}
|
||||
|
||||
|
||||
public static int resolveType(SourceGeneratorLocalData localData, GraphTargetItem item, AbcIndexing abcIndex) throws CompilationException {
|
||||
int name_index = 0;
|
||||
GraphTargetItem typeItem = null;
|
||||
@@ -247,7 +246,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
ret.add(ins(AVM2Instructions.Pop));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
private AVM2Instruction ins(int instructionCode, int... operands) {
|
||||
return new AVM2Instruction(0, instructionCode, operands);
|
||||
}
|
||||
@@ -1819,7 +1818,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
mbCode.add(ins(AVM2Instructions.PushScope));
|
||||
|
||||
int traitScope = 1;
|
||||
|
||||
|
||||
String documentClassStr = localData.documentClass;
|
||||
DottedChain documentClass = null;
|
||||
if (documentClassStr != null && !documentClassStr.isEmpty()) {
|
||||
@@ -1833,13 +1832,11 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
TraitClass tc = (TraitClass) t;
|
||||
DottedChain className = tc.getName(abc).getNameWithNamespace(abc.constants, true);
|
||||
|
||||
|
||||
|
||||
List<Integer> parents = new ArrayList<>();
|
||||
if (documentClass != null && documentClass.equals(className)) {
|
||||
mbCode.add(ins(AVM2Instructions.GetScopeObject, 0));
|
||||
} else {
|
||||
int[] nsset = new int[]{constants.getMultiname(tc.name_index).namespace_index};
|
||||
int[] nsset = new int[]{constants.getMultiname(tc.name_index).namespace_index};
|
||||
mbCode.add(ins(AVM2Instructions.FindPropertyStrict, constants.getMultinameId(Multiname.createMultiname(false, constants.getMultiname(tc.name_index).name_index, constants.getNamespaceSetId(nsset, true)), true)));
|
||||
}
|
||||
traitScope++;
|
||||
@@ -2035,7 +2032,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
ci = ci.parent;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, FalseItem item) throws CompilationException {
|
||||
return GraphTargetItem.toSourceMerge(localData, this, ins(AVM2Instructions.PushFalse));
|
||||
@@ -2926,13 +2923,13 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
}
|
||||
}
|
||||
if (localData.isStatic && item.toString().equals(currentFullClassName)) {
|
||||
return Arrays.asList(ins(AVM2Instructions.GetLocal0));
|
||||
return Arrays.asList(ins(AVM2Instructions.GetLocal0));
|
||||
} else if (globalSlotId > 0) {
|
||||
return GraphTargetItem.toSourceMerge(localData, this, ins(AVM2Instructions.GetGlobalScope), ins(AVM2Instructions.GetSlot, globalSlotId));
|
||||
} else {
|
||||
return GraphTargetItem.toSourceMerge(localData, this, ins(AVM2Instructions.GetLex, resolveType(localData, item, abcIndex)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, PushItem item) throws CompilationException {
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ public final class AbcIndexing {
|
||||
|
||||
if (builtInNs == null) {
|
||||
//we need to avoid modifying the ABC
|
||||
/* builtInIndex = abc.constants.getNamespaceId(Namespace.KIND_NAMESPACE, BUILT_IN_NS, 0, true);
|
||||
/* builtInIndex = abc.constants.getNamespaceId(Namespace.KIND_NAMESPACE, BUILT_IN_NS, 0, true);
|
||||
builtInNsPerAbc.put(abc, builtInIndex);*/
|
||||
builtInIndex = Integer.MIN_VALUE; //??
|
||||
} else {
|
||||
|
||||
+4
-4
@@ -803,7 +803,7 @@ public class ActionScript3Parser {
|
||||
if (classNameStr == null) {
|
||||
isStatic = true;
|
||||
}
|
||||
|
||||
|
||||
s = lex();
|
||||
if (s.type == SymbolType.NAMESPACESUFFIX) {
|
||||
namespace = new NamespaceItem((Integer) s.value);
|
||||
@@ -838,7 +838,7 @@ public class ActionScript3Parser {
|
||||
t = st;
|
||||
} else {
|
||||
t = ft;
|
||||
}
|
||||
}
|
||||
//NOTE: Looks like TraitFunction does not work in FlashPlayer - use MethodTrait instead
|
||||
/*else {
|
||||
t = function(metadata, pkg, isInterface, new Reference<Boolean>(false), importedClasses, namespace, thisType, openedNamespaces, fname, false, new ArrayList<AssignableAVM2Item>());
|
||||
@@ -1894,7 +1894,7 @@ public class ActionScript3Parser {
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*private GraphTargetItem expressionRemainder(TypeItem thisType, String pkg, Reference<Boolean> needsActivation, List<NamespaceItem> openedNamespaces, GraphTargetItem expr, HashMap<String, Integer> registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List<AssignableAVM2Item> variables, List<DottedChain> importedClasses) throws IOException, AVM2ParseException {
|
||||
GraphTargetItem ret = null;
|
||||
@@ -1949,7 +1949,7 @@ public class ActionScript3Parser {
|
||||
}
|
||||
return arrCnt;
|
||||
}
|
||||
|
||||
|
||||
private GraphTargetItem expression(List<List<NamespaceItem>> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference<Boolean> needsActivation, List<DottedChain> importedClasses, List<NamespaceItem> openedNamespaces, HashMap<String, Integer> registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List<AssignableAVM2Item> variables, boolean allowComma) throws IOException, AVM2ParseException, InterruptedException {
|
||||
return expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, false, registerVars, inFunction, inMethod, allowRemainder, variables, allowComma);
|
||||
}
|
||||
|
||||
+1151
-1081
File diff suppressed because it is too large
Load Diff
@@ -104,7 +104,7 @@ public class InstanceInfo {
|
||||
fileName = getName(abc.constants).getNameWithNamespace(abc.constants, false).toRawString();
|
||||
}
|
||||
fileName = Helper.makeFileName(fileName);
|
||||
|
||||
|
||||
if (ct instanceof DefineBinaryDataTag) {
|
||||
writer.appendNoHilight("[Embed(source=\"" + ASSETS_DIR + fileName + ".bin\", mimeType=\"application/octet-stream\")]").newLine();
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public final class MethodBody implements Cloneable {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized AVM2Code getCode() {
|
||||
public synchronized AVM2Code getCode() {
|
||||
if (code == null) {
|
||||
AVM2Code avm2Code;
|
||||
try {
|
||||
@@ -170,7 +170,7 @@ public final class MethodBody implements Cloneable {
|
||||
|
||||
public void markOffsets() {
|
||||
getCode().markOffsets();
|
||||
}
|
||||
}
|
||||
|
||||
public int removeDeadCode(AVM2ConstantPool constants, Trait trait, MethodInfo info) throws InterruptedException {
|
||||
return getCode().removeDeadCode(this);
|
||||
@@ -205,7 +205,7 @@ public final class MethodBody implements Cloneable {
|
||||
*/
|
||||
public void replaceInstruction(int pos, AVM2Instruction instruction) {
|
||||
getCode().replaceInstruction(pos, instruction, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertAll(int pos, List<AVM2Instruction> list) {
|
||||
for (AVM2Instruction ins : list) {
|
||||
@@ -336,8 +336,7 @@ public final class MethodBody implements Cloneable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "";
|
||||
|
||||
@@ -87,7 +87,7 @@ public class MethodInfo {
|
||||
public void setFlagIgnore_Rest() {
|
||||
flags |= FLAG_IGNORE_REST;
|
||||
}
|
||||
|
||||
|
||||
public void setFlagIgnore_Rest(boolean val) {
|
||||
if (val) {
|
||||
setFlagIgnore_Rest();
|
||||
@@ -95,7 +95,7 @@ public class MethodInfo {
|
||||
unsetFlagIgnore_Rest();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void unsetFlagIgnore_Rest() {
|
||||
if (flagIgnore_rest()) {
|
||||
flags -= FLAG_IGNORE_REST;
|
||||
@@ -146,8 +146,6 @@ public class MethodInfo {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void unsetFlagNeed_rest() {
|
||||
if (flagNeed_rest()) {
|
||||
flags -= FLAG_NEED_REST;
|
||||
@@ -157,7 +155,7 @@ public class MethodInfo {
|
||||
public void setFlagNeed_rest() {
|
||||
flags |= FLAG_NEED_REST;
|
||||
}
|
||||
|
||||
|
||||
public void setFlagNeed_rest(boolean val) {
|
||||
if (val) {
|
||||
setFlagNeed_rest();
|
||||
@@ -166,8 +164,6 @@ public class MethodInfo {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void unsetFlagHas_optional() {
|
||||
if (flagHas_optional()) {
|
||||
flags -= FLAG_HAS_OPTIONAL;
|
||||
@@ -177,14 +173,14 @@ public class MethodInfo {
|
||||
public void setFlagHas_optional() {
|
||||
flags |= FLAG_HAS_OPTIONAL;
|
||||
}
|
||||
|
||||
|
||||
public void setFlagHas_optional(boolean val) {
|
||||
if (val) {
|
||||
setFlagHas_optional();
|
||||
} else {
|
||||
unsetFlagHas_optional();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unsetFlagHas_paramnames() {
|
||||
if (flagHas_paramnames()) {
|
||||
@@ -195,7 +191,7 @@ public class MethodInfo {
|
||||
public void setFlagHas_paramnames() {
|
||||
flags |= FLAG_HAS_PARAMNAMES;
|
||||
}
|
||||
|
||||
|
||||
public void setFlagHas_paramnames(boolean val) {
|
||||
if (val) {
|
||||
setFlagHas_paramnames();
|
||||
|
||||
@@ -276,7 +276,7 @@ public class Multiname {
|
||||
}
|
||||
}
|
||||
return kindStr;
|
||||
}
|
||||
}
|
||||
|
||||
public static String namespaceToString(AVM2ConstantPool constants, int index) {
|
||||
if (index == 0) {
|
||||
@@ -338,7 +338,7 @@ public class Multiname {
|
||||
}
|
||||
return constants.getMultiname(index).toString(constants, fullyQualifiedNames);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String kindStr = getKindStr();
|
||||
|
||||
@@ -94,7 +94,7 @@ public class ValueKind {
|
||||
return CONSTANT_StaticProtectedNs;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNamespace() {
|
||||
switch (value_kind) {
|
||||
|
||||
@@ -78,8 +78,6 @@ public class TraitClass extends Trait implements TraitWithSlot {
|
||||
return slot_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void getDependencies(AbcIndexing abcIndex, int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames, List<String> uses) throws InterruptedException {
|
||||
super.getDependencies(abcIndex, scriptIndex, -1, false, customNs, abc, dependencies, ignorePackage == null ? getPackage(abc) : ignorePackage, fullyQualifiedNames, uses);
|
||||
@@ -122,7 +120,7 @@ public class TraitClass extends Trait implements TraitWithSlot {
|
||||
public String toString(ABC abc, List<DottedChain> fullyQualifiedNames) {
|
||||
return "Class " + abc.constants.getMultiname(name_index).toString(abc.constants, fullyQualifiedNames) + " slot=" + slot_id + " class_info=" + class_info + " metadata=" + Helper.intArrToString(metadata);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GraphTextWriter toString(AbcIndexing abcIndex, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List<DottedChain> fullyQualifiedNames, boolean parallel, boolean insideInterface) throws InterruptedException {
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public class TraitFunction extends Trait implements TraitWithSlot {
|
||||
@Override
|
||||
public int getSlotIndex() {
|
||||
return slot_id;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTextWriter toStringHeader(Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List<DottedChain> fullyQualifiedNames, boolean parallel, boolean insideInterface) {
|
||||
|
||||
+2
-2
@@ -54,7 +54,7 @@ public class TraitMethodGetterSetter extends Trait {
|
||||
|
||||
abc.constants.getMultiname(name_index).deleted = d;
|
||||
abc.method_info.get(method_info).delete(abc, d);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertHeader(Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, NulWriter writer, List<DottedChain> fullyQualifiedNames, boolean parallel) {
|
||||
@@ -128,7 +128,7 @@ public class TraitMethodGetterSetter extends Trait {
|
||||
public String toString(ABC abc, List<DottedChain> fullyQualifiedNames) {
|
||||
return "0x" + Helper.formatAddress(fileOffset) + " " + Helper.byteArrToString(bytes) + " MethodGetterSetter " + abc.constants.getMultiname(name_index).toString(abc.constants, fullyQualifiedNames) + " disp_id=" + disp_id + " method_info=" + method_info + " metadata=" + Helper.intArrToString(metadata);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GraphTextWriter toString(AbcIndexing abcIndex, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List<DottedChain> fullyQualifiedNames, boolean parallel, boolean insideInterface) throws InterruptedException {
|
||||
|
||||
|
||||
+2
-2
@@ -69,7 +69,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot {
|
||||
@Override
|
||||
public int getSlotIndex() {
|
||||
return slot_id;
|
||||
}
|
||||
}
|
||||
|
||||
public String getType(AVM2ConstantPool constants, List<DottedChain> fullyQualifiedNames) {
|
||||
String typeStr = "*";
|
||||
@@ -150,7 +150,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString(ABC abc, List<DottedChain> fullyQualifiedNames) {
|
||||
String typeStr = "*";
|
||||
|
||||
+9
-11
@@ -45,12 +45,12 @@ import java.util.List;
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class MultinameUsageDetector implements UsageDetector {
|
||||
|
||||
|
||||
@Override
|
||||
public List<Usage> findUsages(ABC abc, int index) {
|
||||
return findMultinameUsage(abc, index, true);
|
||||
}
|
||||
|
||||
|
||||
public List<Usage> findMultinameUsage(ABC abc, int multinameIndex, boolean exactMatch) {
|
||||
List<Usage> ret = new ArrayList<>();
|
||||
if (multinameIndex == 0) {
|
||||
@@ -77,8 +77,8 @@ public class MultinameUsageDetector implements UsageDetector {
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<List<Usage>> findAllUsage(ABC abc) {
|
||||
List<List<Usage>> ret = new ArrayList<>();
|
||||
@@ -113,8 +113,8 @@ public class MultinameUsageDetector implements UsageDetector {
|
||||
@Override
|
||||
public String getKind() {
|
||||
return "string";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void findAllMultinameUsageInTraits(ABC abc, Traits traits, int traitsType, int scriptIndex, int classIndex, List<List<Usage>> ret, int parentTraitIndex) {
|
||||
for (int t = 0; t < traits.traits.size(); t++) {
|
||||
if (traits.traits.get(t) instanceof TraitClass) {
|
||||
@@ -148,7 +148,7 @@ public class MultinameUsageDetector implements UsageDetector {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void checkAllMultinameUsedInMethod(ABC abc, int methodInfo, List<List<Usage>> ret, int scriptIndex, int classIndex, int traitIndex, int traitsType, boolean isInitializer, Traits traits, int parentTraitIndex) {
|
||||
boolean[] foundMultinames = new boolean[abc.constants.getMultinameCount()];
|
||||
for (int p = 0; p < abc.method_info.get(methodInfo).param_types.length; p++) {
|
||||
@@ -220,7 +220,6 @@ public class MultinameUsageDetector implements UsageDetector {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void findMultinameUsageInTraits(ABC abc, Traits traits, int multinameIndex, boolean exactMatch, int traitsType, int scriptIndex, int classIndex, List<Usage> ret, int parentTraitIndex) {
|
||||
for (int t = 0; t < traits.traits.size(); t++) {
|
||||
if (traits.traits.get(t) instanceof TraitClass) {
|
||||
@@ -239,7 +238,7 @@ public class MultinameUsageDetector implements UsageDetector {
|
||||
}
|
||||
checkMultinameUsedInMethod(abc, multinameIndex, exactMatch, abc.instance_info.get(c).iinit_index, ret, -1/*FIXME*/, c, 0, TraitMultinameUsage.TRAITS_TYPE_INSTANCE, true, null, -1);
|
||||
checkMultinameUsedInMethod(abc, multinameIndex, exactMatch, abc.class_info.get(c).cinit_index, ret, -1/*FIXME*/, c, 0, TraitMultinameUsage.TRAITS_TYPE_CLASS, true, null, -1);
|
||||
findMultinameUsageInTraits(abc, abc.instance_info.get(c).instance_traits, multinameIndex, exactMatch, TraitMultinameUsage.TRAITS_TYPE_INSTANCE, -1/*FIXME*/, c, ret, -1);
|
||||
findMultinameUsageInTraits(abc, abc.instance_info.get(c).instance_traits, multinameIndex, exactMatch, TraitMultinameUsage.TRAITS_TYPE_INSTANCE, -1/*FIXME*/, c, ret, -1);
|
||||
findMultinameUsageInTraits(abc, abc.class_info.get(c).static_traits, multinameIndex, exactMatch, TraitMultinameUsage.TRAITS_TYPE_CLASS, -1/*FIXME*/, c, ret, -1);
|
||||
}
|
||||
if (traits.traits.get(t) instanceof TraitSlotConst) {
|
||||
@@ -261,7 +260,6 @@ public class MultinameUsageDetector implements UsageDetector {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void checkMultinameUsedInMethod(ABC abc, int multinameIndex, boolean exactMatch, int methodInfo, List<Usage> ret, int scriptIndex, int classIndex, int traitIndex, int traitsType, boolean isInitializer, Traits traits, int parentTraitIndex) {
|
||||
for (int p = 0; p < abc.method_info.get(methodInfo).param_types.length; p++) {
|
||||
if (isSameName(abc, multinameIndex, abc.method_info.get(methodInfo).param_types[p], exactMatch)) {
|
||||
@@ -292,7 +290,7 @@ public class MultinameUsageDetector implements UsageDetector {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void filterUsages(ABC abc, UsagesFilter filter) {
|
||||
|
||||
@@ -23,9 +23,10 @@ import com.jpexs.decompiler.flash.abc.ABC;
|
||||
* @author JPEXS
|
||||
*/
|
||||
public interface Usage {
|
||||
|
||||
public ABC getAbc();
|
||||
|
||||
|
||||
public int getIndex();
|
||||
|
||||
|
||||
public String getKind();
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ import java.util.List;
|
||||
* @author JPEXS
|
||||
*/
|
||||
public interface UsageDetector {
|
||||
|
||||
|
||||
public void filterUsages(ABC abc, UsagesFilter filter);
|
||||
|
||||
|
||||
public List<Usage> findUsages(ABC abc, int index);
|
||||
|
||||
|
||||
public List<List<Usage>> findAllUsage(ABC abc);
|
||||
|
||||
|
||||
public String getKind();
|
||||
}
|
||||
|
||||
@@ -21,5 +21,6 @@ package com.jpexs.decompiler.flash.abc.usages;
|
||||
* @author JPEXS
|
||||
*/
|
||||
public interface UsagesFilter {
|
||||
|
||||
public int filterUsage(int originalIndex);
|
||||
}
|
||||
|
||||
+1
-1
@@ -135,5 +135,5 @@ public abstract class MultinameUsage implements Usage {
|
||||
@Override
|
||||
public String getKind() {
|
||||
return "multiname";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class ABCCleaner {
|
||||
|
||||
public void clean(ABC abc) {
|
||||
public void clean(ABC abc) {
|
||||
ABCSimpleUsageDetector usageDetector = new ABCSimpleUsageDetector(abc);
|
||||
usageDetector.detect();
|
||||
Map<ABCSimpleUsageDetector.ItemKind, List<List<String>>> usages = usageDetector.getUsages();
|
||||
@@ -74,8 +74,8 @@ public class ABCCleaner {
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0; i < abc.script_info.size(); i++) {
|
||||
ScriptInfo m = abc.script_info.get(i);
|
||||
m.init_index = handleReplace(ABCSimpleUsageDetector.ItemKind.METHODINFO, m.init_index, replaceMap);
|
||||
@@ -300,7 +300,7 @@ public class ABCCleaner {
|
||||
if (abc.parentTag != null) {
|
||||
((Tag) abc.parentTag).setModified(true);
|
||||
}
|
||||
abc.fireChanged();
|
||||
abc.fireChanged();
|
||||
}
|
||||
|
||||
private int handleReplace(ABCSimpleUsageDetector.ItemKind kind, int index, Map<ABCSimpleUsageDetector.ItemKind, Map<Integer, Integer>> replaceMap) {
|
||||
@@ -376,6 +376,5 @@ public class ABCCleaner {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+72
-75
@@ -57,41 +57,41 @@ public class ABCSimpleUsageDetector {
|
||||
METHODINFO(false),
|
||||
METHODBODY(false),
|
||||
CLASS(false);
|
||||
|
||||
|
||||
private boolean reserveZeroIndex;
|
||||
|
||||
private ItemKind (boolean reserveZeroIndex) {
|
||||
|
||||
private ItemKind(boolean reserveZeroIndex) {
|
||||
this.reserveZeroIndex = reserveZeroIndex;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasReservedZeroIndex() {
|
||||
return reserveZeroIndex;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<ItemKind, List<List<String>>> usages = new HashMap<>();
|
||||
|
||||
private final Map<ItemKind, List<List<String>>> usages = new HashMap<>();
|
||||
private final Map<ItemKind, List<Integer>> zeroUsages = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
private final ABC abc;
|
||||
|
||||
public ABCSimpleUsageDetector(ABC abc) {
|
||||
this.abc = abc;
|
||||
this.abc = abc;
|
||||
}
|
||||
|
||||
|
||||
private void initUsages(ItemKind kind, int itemCount) {
|
||||
List<List<String>> list = new ArrayList<>();
|
||||
if (kind.hasReservedZeroIndex() && itemCount == 0) {
|
||||
itemCount = 1;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
list.add(new ArrayList<>());
|
||||
}
|
||||
usages.put(kind, list);
|
||||
}
|
||||
|
||||
|
||||
public void detect() {
|
||||
usages.clear();
|
||||
|
||||
|
||||
initUsages(ItemKind.INT, abc.constants.getIntCount());
|
||||
initUsages(ItemKind.UINT, abc.constants.getUIntCount());
|
||||
initUsages(ItemKind.DOUBLE, abc.constants.getDoubleCount());
|
||||
@@ -103,7 +103,7 @@ public class ABCSimpleUsageDetector {
|
||||
initUsages(ItemKind.METHODINFO, abc.method_info.size());
|
||||
initUsages(ItemKind.METHODBODY, abc.bodies.size());
|
||||
initUsages(ItemKind.CLASS, abc.class_info.size());
|
||||
|
||||
|
||||
ABCWalker walker = new ABCWalker() {
|
||||
protected void handleUsageNamespace(int index, String usageDescription) {
|
||||
if (!handleUsage(ItemKind.NAMESPACE, index, usageDescription)) {
|
||||
@@ -133,7 +133,7 @@ public class ABCSimpleUsageDetector {
|
||||
if (!handleUsage(ItemKind.MULTINAME, index, usageDescription)) {
|
||||
return;
|
||||
}
|
||||
Multiname m = abc.constants.getMultiname(index);
|
||||
Multiname m = abc.constants.getMultiname(index);
|
||||
if (m == null) {
|
||||
return;
|
||||
}
|
||||
@@ -153,15 +153,15 @@ public class ABCSimpleUsageDetector {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void handleUsageMethodInfo(int index, String usageDescription) {
|
||||
if (!handleUsage(ItemKind.METHODINFO, index, usageDescription)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MethodInfo m = abc.method_info.get(index);
|
||||
|
||||
MethodInfo m = abc.method_info.get(index);
|
||||
handleUsage(ItemKind.STRING, m.name_index, usageDescription + "/name");
|
||||
|
||||
|
||||
if (m.flagHas_paramnames()) {
|
||||
for (int i = 0; i < m.paramNames.length; i++) {
|
||||
handleUsage(ItemKind.STRING, m.paramNames[i], usageDescription + "/param_names/pn" + i);
|
||||
@@ -172,31 +172,31 @@ public class ABCSimpleUsageDetector {
|
||||
handleUsageValueKind(m.optional[i].value_kind, m.optional[i].value_index, usageDescription + "/optional/op" + i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < m.param_types.length; i++) {
|
||||
handleUsageMultiname(m.param_types[i], usageDescription + "/param_types/pt" + i);
|
||||
}
|
||||
|
||||
handleUsageMultiname(m.ret_type, usageDescription + "/return_type");
|
||||
|
||||
|
||||
handleUsageMultiname(m.ret_type, usageDescription + "/return_type");
|
||||
|
||||
int bodyIndex = abc.findBodyIndex(index);
|
||||
if (bodyIndex > -1) {
|
||||
handleUsageMethodBody(bodyIndex, usageDescription + "/method_body");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleUsageMethodBody(int index, String usageDescription) {
|
||||
if (!handleUsage(ItemKind.METHODBODY, index, usageDescription)) {
|
||||
return;
|
||||
}
|
||||
MethodBody body = abc.bodies.get(index);
|
||||
MethodBody body = abc.bodies.get(index);
|
||||
for (int i = 0; i < body.exceptions.length; i++) {
|
||||
handleUsageMultiname(body.exceptions[i].name_index, usageDescription + "/exceptions/ex" + i + "/name");
|
||||
handleUsageMultiname(body.exceptions[i].type_index, usageDescription + "/exceptions/ex" + i + "/type");
|
||||
}
|
||||
List<AVM2Instruction> code = body.getCode().code;
|
||||
for (int i = 0; i < code.size(); i++) {
|
||||
AVM2Instruction ins = code.get(i);
|
||||
AVM2Instruction ins = code.get(i);
|
||||
for (int operandIndex = 0; operandIndex < ins.definition.operands.length; operandIndex++) {
|
||||
int operand = ins.operands[operandIndex];
|
||||
String operandDescription = usageDescription + "/code/ins" + i + "/op" + operandIndex;
|
||||
@@ -228,10 +228,10 @@ public class ABCSimpleUsageDetector {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void handleScript(ABC abc, int index) {
|
||||
|
||||
protected void handleScript(ABC abc, int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -243,9 +243,8 @@ public class ABCSimpleUsageDetector {
|
||||
description += "/instance_info/traits/t" + traitIndex;
|
||||
}
|
||||
description += "/metadata/md" + index;
|
||||
|
||||
|
||||
//?? classIndex
|
||||
|
||||
if (!handleUsage(ItemKind.METADATAINFO, index, description)) {
|
||||
return;
|
||||
}
|
||||
@@ -256,8 +255,8 @@ public class ABCSimpleUsageDetector {
|
||||
}
|
||||
for (int i = 0; i < md.values.length; i++) {
|
||||
handleUsage(ItemKind.STRING, md.values[i], description + "/pairs/p" + i + "/value");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTraitClass(ABC abc, TraitClass trait, int scriptIndex, int scriptTraitIndex) {
|
||||
@@ -265,7 +264,7 @@ public class ABCSimpleUsageDetector {
|
||||
if (!handleUsage(ItemKind.CLASS, trait.class_info, description)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
InstanceInfo ii = abc.instance_info.get(trait.class_info);
|
||||
if ((ii.flags & InstanceInfo.CLASS_PROTECTEDNS) != 0) {
|
||||
handleUsageNamespace(ii.protectedNS, description + "/instance_info/protected_ns");
|
||||
@@ -274,22 +273,21 @@ public class ABCSimpleUsageDetector {
|
||||
handleUsageMultiname(ii.super_index, description + "/instance_info/super");
|
||||
for (int i = 0; i < ii.interfaces.length; i++) {
|
||||
handleUsageMultiname(ii.interfaces[i], description + "/instance_info/interfaces/in" + i);
|
||||
}
|
||||
}
|
||||
/*
|
||||
handleUsageMethodInfo(abc.class_info.get(trait.class_info).cinit_index, description + "/class_info/cinit");
|
||||
handleUsageMethodInfo(abc.instance_info.get(trait.class_info).iinit_index, description + "/instance_info/iinit");
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTraitMethodGetterSetter(ABC abc, TraitMethodGetterSetter trait, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, ABCWalker.WalkType walkType) {
|
||||
handleTraitMethodBase(abc, trait, scriptIndex, scriptTraitIndex, classIndex, traitIndex, walkType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTraitMethodGetterSetter(ABC abc, TraitMethodGetterSetter trait, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, ABCWalker.WalkType walkType) {
|
||||
handleTraitMethodBase(abc, trait, scriptIndex, scriptTraitIndex, classIndex, traitIndex, walkType);
|
||||
}
|
||||
|
||||
|
||||
protected void handleTraitMethodBase(ABC abc, Trait trait, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, ABCWalker.WalkType walkType) {
|
||||
String description = "";
|
||||
if (scriptIndex > -1) {
|
||||
String description = "";
|
||||
if (scriptIndex > -1) {
|
||||
description += "si" + scriptIndex + "/traits/t" + scriptTraitIndex;
|
||||
if (walkType == WalkType.Class && traitIndex > -1) {
|
||||
description += "/class_info/traits/t" + traitIndex;
|
||||
@@ -303,13 +301,12 @@ public class ABCSimpleUsageDetector {
|
||||
description += "ii" + classIndex + "/instance_info/traits/t" + traitIndex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//description += " " + trait.getKindToStr();
|
||||
|
||||
handleUsageMultiname(trait.name_index, description + "/name");
|
||||
//handleUsageMethodInfo(trait.method_info, description + "/method_info");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void handleTraitFunction(ABC abc, TraitFunction trait, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, ABCWalker.WalkType walkType) {
|
||||
handleTraitMethodBase(abc, trait, scriptIndex, scriptTraitIndex, classIndex, traitIndex, walkType);
|
||||
@@ -336,14 +333,14 @@ public class ABCSimpleUsageDetector {
|
||||
case ValueKind.CONSTANT_ExplicitNamespace:
|
||||
case ValueKind.CONSTANT_StaticProtectedNs:
|
||||
case ValueKind.CONSTANT_PrivateNs:
|
||||
handleUsage(ItemKind.NAMESPACE, value_index, description);
|
||||
handleUsage(ItemKind.NAMESPACE, value_index, description);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void handleTraitSlotConst(ABC abc, TraitSlotConst trait, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, int bodyIndex, int bodyTraitIndex, ABCWalker.WalkType walkType, Stack<Integer> callStack) {
|
||||
|
||||
|
||||
String description = "";
|
||||
if (callStack.size() > 1) {
|
||||
if (bodyTraitIndex != -1) {
|
||||
@@ -352,13 +349,13 @@ public class ABCSimpleUsageDetector {
|
||||
}
|
||||
} else if (scriptIndex > -1) {
|
||||
description += "si" + scriptIndex + "/traits/t" + scriptTraitIndex;
|
||||
|
||||
|
||||
if (walkType == WalkType.Class && traitIndex > -1) {
|
||||
description += "/class_info/traits/t" + traitIndex;
|
||||
} else if (walkType == WalkType.Instance && traitIndex > -1) {
|
||||
description += "/instance_info/traits/t" + traitIndex;
|
||||
}
|
||||
|
||||
description += "/instance_info/traits/t" + traitIndex;
|
||||
}
|
||||
|
||||
if (bodyTraitIndex != -1) {
|
||||
description += "/method_info/method_body/traits/t" + bodyTraitIndex;
|
||||
}
|
||||
@@ -366,17 +363,17 @@ public class ABCSimpleUsageDetector {
|
||||
if (walkType == WalkType.Class && traitIndex > -1) {
|
||||
description += "ci" + classIndex + "/class_info/traits/t" + traitIndex;
|
||||
} else if (walkType == WalkType.Instance && traitIndex > -1) {
|
||||
description += "ii" + classIndex + "/instance_info/traits/t" + traitIndex;
|
||||
description += "ii" + classIndex + "/instance_info/traits/t" + traitIndex;
|
||||
} else if (bodyTraitIndex > -1) {
|
||||
description += "mb" + bodyIndex + "/traits/t" + bodyTraitIndex;
|
||||
description += "mb" + bodyIndex + "/traits/t" + bodyTraitIndex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//description += " " + trait.getKindToStr();
|
||||
handleUsageMultiname(trait.name_index, description + "/name");
|
||||
handleUsageMultiname(trait.type_index, description + "/type");
|
||||
handleUsageValueKind(trait.value_kind, trait.value_index, description + "/value_index");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMethodInfo(ABC abc, int index, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, ABCWalker.WalkType walkType, boolean initializer, Stack<Integer> callStack) {
|
||||
@@ -384,7 +381,7 @@ public class ABCSimpleUsageDetector {
|
||||
int prevMethod = callStack.get(callStack.size() - 2);
|
||||
handleUsageMethodInfo(index, "mi" + prevMethod + "/method_body/code");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (initializer) {
|
||||
switch (walkType) {
|
||||
case Class:
|
||||
@@ -404,13 +401,13 @@ public class ABCSimpleUsageDetector {
|
||||
case Script:
|
||||
handleUsageMethodInfo(index, "si" + scriptIndex + "/init");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String description = "";
|
||||
if (scriptIndex > -1) {
|
||||
|
||||
String description = "";
|
||||
if (scriptIndex > -1) {
|
||||
description += "si" + scriptIndex + "/traits/t" + scriptTraitIndex;
|
||||
if (walkType == WalkType.Class && traitIndex > -1) {
|
||||
description += "/class_info/traits/t" + traitIndex;
|
||||
@@ -426,10 +423,10 @@ public class ABCSimpleUsageDetector {
|
||||
}
|
||||
description += "/method_info";
|
||||
handleUsageMethodInfo(index, description);
|
||||
}
|
||||
}
|
||||
};
|
||||
walker.walkABC(abc, false);
|
||||
|
||||
|
||||
zeroUsages.clear();
|
||||
for (ItemKind kind : usages.keySet()) {
|
||||
zeroUsages.put(kind, new ArrayList<>());
|
||||
@@ -440,9 +437,9 @@ public class ABCSimpleUsageDetector {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param kind
|
||||
* @param index
|
||||
* @param usageDescription
|
||||
@@ -452,18 +449,18 @@ public class ABCSimpleUsageDetector {
|
||||
|
||||
List<String> kindList = usages.get(kind).get(index);
|
||||
kindList.add(usageDescription);
|
||||
|
||||
|
||||
return kindList.size() == 1;
|
||||
}
|
||||
|
||||
public Map<ItemKind, List<List<String>>> getUsages() {
|
||||
return Collections.unmodifiableMap(usages);
|
||||
}
|
||||
|
||||
|
||||
public List<String> getUsages(ItemKind kind, int index) {
|
||||
return Collections.unmodifiableList(usages.get(kind).get(index));
|
||||
}
|
||||
|
||||
|
||||
public List<List<String>> getUsages(ItemKind kind) {
|
||||
return Collections.unmodifiableList(usages.get(kind));
|
||||
}
|
||||
@@ -471,11 +468,11 @@ public class ABCSimpleUsageDetector {
|
||||
public Map<ItemKind, List<Integer>> getZeroUsages() {
|
||||
return Collections.unmodifiableMap(zeroUsages);
|
||||
}
|
||||
|
||||
|
||||
public List<Integer> getZeroUsages(ItemKind kind) {
|
||||
return zeroUsages.get(kind);
|
||||
}
|
||||
|
||||
|
||||
public int getZeroUsagesCount() {
|
||||
int cnt = 0;
|
||||
for (ItemKind kind : zeroUsages.keySet()) {
|
||||
@@ -483,7 +480,7 @@ public class ABCSimpleUsageDetector {
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
public int getZeroUsagesCount(ItemKind kind) {
|
||||
return zeroUsages.get(kind).size();
|
||||
}
|
||||
|
||||
@@ -35,27 +35,27 @@ import java.util.Stack;
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public abstract class ABCWalker {
|
||||
|
||||
public abstract class ABCWalker {
|
||||
|
||||
public static enum WalkType {
|
||||
Orphan,
|
||||
Script,
|
||||
Class,
|
||||
Instance
|
||||
}
|
||||
|
||||
public final void walkABC(ABC abc, boolean walkOrphanItems) {
|
||||
|
||||
public final void walkABC(ABC abc, boolean walkOrphanItems) {
|
||||
Set<Integer> handledClasses = new HashSet<>();
|
||||
Set<Integer> handledMethodInfos = new HashSet<>();
|
||||
Set<Integer> handledMethodBodies = new HashSet<>();
|
||||
|
||||
|
||||
for (int i = 0; i < abc.script_info.size(); i++) {
|
||||
handleScript(abc, i);
|
||||
ScriptInfo si = abc.script_info.get(i);
|
||||
optionalHandleMethodInfo(handledMethodBodies, handledMethodInfos, abc, si.init_index, i, -1, -1, -1, WalkType.Script, true, new Stack<>());
|
||||
walkTraits(abc, si.traits, i, -1, -1, -1, -1, handledMethodBodies, handledMethodInfos, handledClasses, WalkType.Script, new Stack<>());
|
||||
}
|
||||
|
||||
|
||||
if (walkOrphanItems) {
|
||||
for (int i = 0; i < abc.method_info.size(); i++) {
|
||||
optionalHandleMethodInfo(handledMethodBodies, handledMethodInfos, abc, i, -1, -1, -1, -1, WalkType.Orphan, false, new Stack<>());
|
||||
@@ -64,31 +64,31 @@ public abstract class ABCWalker {
|
||||
for (int i = 0; i < abc.bodies.size(); i++) {
|
||||
optionalHandleMethodBody(handledMethodBodies, handledMethodInfos, abc, i, -1, -1, -1, -1, WalkType.Orphan, false, new Stack<>());
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < abc.class_info.size(); i++) {
|
||||
optionalHandleClass(handledClasses, handledMethodBodies, handledMethodInfos, abc, i, -1, -1, -1, WalkType.Orphan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean optionalHandleClass(Set<Integer> handledClasses, Set<Integer> handledMethodBodies, Set<Integer> handledMethodInfos, ABC abc, int index, int scriptIndex, int scriptTraitIndex, int traitIndex, WalkType walkType) {
|
||||
if (handledClasses.contains(index)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
handleClass(abc, index, scriptIndex, traitIndex, walkType);
|
||||
|
||||
|
||||
optionalHandleMethodInfo(handledMethodBodies, handledMethodInfos, abc, abc.instance_info.get(index).iinit_index, scriptIndex, scriptTraitIndex, index, -1, WalkType.Instance, true, new Stack<>());
|
||||
walkTraits(abc, abc.instance_info.get(index).instance_traits, scriptIndex, scriptTraitIndex, index, -1, -1, handledMethodBodies, handledMethodInfos, handledClasses, WalkType.Instance, new Stack<>());
|
||||
optionalHandleMethodInfo(handledMethodBodies, handledMethodInfos, abc, abc.class_info.get(index).cinit_index, scriptIndex, scriptTraitIndex, index, -1, WalkType.Class, true, new Stack<>());
|
||||
walkTraits(abc, abc.class_info.get(index).static_traits, scriptIndex, scriptTraitIndex, index, -1, -1, handledMethodBodies, handledMethodInfos, handledClasses, WalkType.Class, new Stack<>());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void optionalHandleMethodInfo(Set<Integer> handledMethodBodies, Set<Integer> handledMethodInfos, ABC abc, int index, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, WalkType walkType, boolean initializer, Stack<Integer> callStack) {
|
||||
if (handledMethodInfos.contains(index)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
handledMethodInfos.add(index);
|
||||
if (callStack != null) {
|
||||
if (callStack.contains(index)) {
|
||||
@@ -105,7 +105,7 @@ public abstract class ABCWalker {
|
||||
callStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void optionalHandleMethodBody(Set<Integer> handledMethodBodies, Set<Integer> handledMethodInfos, ABC abc, int index, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, WalkType walkType, boolean initializer, Stack<Integer> callStack) {
|
||||
if (handledMethodBodies.contains(index)) {
|
||||
return;
|
||||
@@ -122,10 +122,11 @@ public abstract class ABCWalker {
|
||||
}
|
||||
walkTraits(abc, abc.bodies.get(index).traits, scriptIndex, scriptTraitIndex, classIndex, traitIndex, index, handledMethodBodies, handledMethodInfos, handledMethodInfos, walkType, callStack);
|
||||
}
|
||||
|
||||
private void walkTraits(ABC abc, Traits traits, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, int bodyIndex, Set<Integer> handledMethodBodies, Set<Integer> handledMethodInfos, Set<Integer> handledClasses, WalkType walkType, Stack<Integer> callStack) {
|
||||
|
||||
|
||||
int bodyTraitIndex = -1;
|
||||
|
||||
|
||||
for (int i = 0; i < traits.traits.size(); i++) {
|
||||
if (classIndex == -1) {
|
||||
scriptTraitIndex = i;
|
||||
@@ -136,8 +137,8 @@ public abstract class ABCWalker {
|
||||
if (bodyIndex != -1) {
|
||||
bodyTraitIndex = i;
|
||||
}
|
||||
Trait t = traits.traits.get(i);
|
||||
if ((t.kindFlags & Trait.ATTR_Metadata) > 0) {
|
||||
Trait t = traits.traits.get(i);
|
||||
if ((t.kindFlags & Trait.ATTR_Metadata) > 0) {
|
||||
for (int m = 0; m < t.metadata.length; m++) {
|
||||
handleMetadataInfo(abc, t.metadata[m], t, scriptIndex, scriptTraitIndex, classIndex, i, m, walkType);
|
||||
}
|
||||
@@ -164,40 +165,40 @@ public abstract class ABCWalker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void handleMethodInfo(ABC abc, int index, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, WalkType walkType, boolean initializer, Stack<Integer> callStack) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void handleMethodBody(ABC abc, int index, int scriptIndex, int classIndex, int traitIndex, WalkType walkType, boolean initializer) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void handleClass(ABC abc, int index, int scriptIndex, int traitIndex, WalkType walkType) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void handleScript(ABC abc, int index) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void handleTraitSlotConst(ABC abc, TraitSlotConst trait, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, int bodyIndex, int bodyTraitIndex, WalkType walkType, Stack<Integer> callStack) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void handleTraitMethodGetterSetter(ABC abc, TraitMethodGetterSetter trait, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, WalkType walkType) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void handleTraitFunction(ABC abc, TraitFunction trait, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, WalkType walkType) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void handleTraitClass(ABC abc, TraitClass trait, int scriptIndex, int scriptTraitIndex) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void handleMetadataInfo(ABC abc, int index, Trait trait, int scriptIndex, int scriptTraitIndex, int classIndex, int traitIndex, int traitMetadataIndex, WalkType walkType) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user