mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-10 04:16:19 +00:00
AS3 PCode serach
This commit is contained in:
@@ -40,6 +40,7 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedText;
|
||||
import com.jpexs.decompiler.flash.helpers.NulWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
|
||||
import com.jpexs.decompiler.flash.search.MethodId;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.treeitems.AS3ClassTreeItem;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
@@ -616,4 +617,15 @@ public class ScriptPack extends AS3ClassTreeItem {
|
||||
|
||||
((Tag) abc.parentTag).setModified(true);
|
||||
}
|
||||
|
||||
public void getMethodInfos(List<MethodId> methodInfos) {
|
||||
int script_init = abc.script_info.get(scriptIndex).init_index;
|
||||
methodInfos.add(new MethodId(-1, script_init));
|
||||
|
||||
List<Trait> traits = abc.script_info.get(scriptIndex).traits.traits;
|
||||
for (int t = 0; t < traitIndices.size(); t++) {
|
||||
Trait trait = traits.get(t);
|
||||
trait.getMethodInfos(abc, -1, methodInfos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.jpexs.decompiler.flash.exporters.script.DependencyType;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.NulWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
|
||||
import com.jpexs.decompiler.flash.search.MethodId;
|
||||
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.helpers.Helper;
|
||||
@@ -110,8 +111,8 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
}
|
||||
if (Configuration.handleSkinPartsAutomatically.get()) {
|
||||
/*
|
||||
private static var _skinParts:Object = {"attr":false,"attr2":true};
|
||||
=>
|
||||
private static var _skinParts:Object = {"attr":false,"attr2":true};
|
||||
=>
|
||||
[SkinPart required="false"]
|
||||
public var attr;
|
||||
[SkinPart required="true"]
|
||||
@@ -509,4 +510,6 @@ public abstract class Trait implements Cloneable, Serializable {
|
||||
public boolean isVisible(boolean isStatic, ABC abc) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract void getMethodInfos(ABC abc, int classIndex, List<MethodId> methodInfos);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.jpexs.decompiler.flash.exporters.script.DependencyType;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.NulWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
|
||||
import com.jpexs.decompiler.flash.search.MethodId;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.decompiler.graph.ScopeStack;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
@@ -275,4 +276,21 @@ public class TraitClass extends Trait implements TraitWithSlot {
|
||||
writer.newLine();
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getMethodInfos(ABC abc, int classIndex, List<MethodId> methodInfos) {
|
||||
InstanceInfo instanceInfo = abc.instance_info.get(class_info);
|
||||
ClassInfo classInfo = abc.class_info.get(class_info);
|
||||
|
||||
//class initializer
|
||||
methodInfos.add(new MethodId(class_info, classInfo.cinit_index));
|
||||
|
||||
//constructor - instance initializer
|
||||
methodInfos.add(new MethodId(class_info, instanceInfo.iinit_index));
|
||||
|
||||
//static variables,constants & methods
|
||||
classInfo.static_traits.getMethodInfos(abc, class_info, methodInfos);
|
||||
|
||||
instanceInfo.instance_traits.getMethodInfos(abc, class_info, methodInfos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.exporters.script.DependencyParser;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.NulWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
|
||||
import com.jpexs.decompiler.flash.search.MethodId;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.decompiler.graph.ScopeStack;
|
||||
import com.jpexs.helpers.Helper;
|
||||
@@ -144,4 +145,9 @@ public class TraitFunction extends Trait implements TraitWithSlot {
|
||||
writer.hilightSpecial(Integer.toString(slot_id), HighlightSpecialType.SLOT_ID);
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getMethodInfos(ABC abc, int classIndex, List<MethodId> methodInfos) {
|
||||
methodInfos.add(new MethodId(classIndex, method_info));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.jpexs.decompiler.flash.exporters.script.DependencyParser;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.NulWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
|
||||
import com.jpexs.decompiler.flash.search.MethodId;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.decompiler.graph.ScopeStack;
|
||||
import com.jpexs.helpers.Helper;
|
||||
@@ -225,4 +226,9 @@ public class TraitMethodGetterSetter extends Trait {
|
||||
writer.newLine();
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getMethodInfos(ABC abc, int classIndex, List<MethodId> methodInfos) {
|
||||
methodInfos.add(new MethodId(classIndex, method_info));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.jpexs.decompiler.flash.exporters.script.DependencyType;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.NulWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
|
||||
import com.jpexs.decompiler.flash.search.MethodId;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
@@ -245,4 +246,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot {
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getMethodInfos(ABC abc, int classIndex, List<MethodId> methodInfos) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
|
||||
import com.jpexs.decompiler.flash.exporters.script.Dependency;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.NulWriter;
|
||||
import com.jpexs.decompiler.flash.search.MethodId;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@@ -250,4 +251,11 @@ public class Traits implements Cloneable, Serializable {
|
||||
t.getDependencies(customNs, abc, dependencies, uses, ignorePackage, fullyQualifiedNames);
|
||||
}
|
||||
}
|
||||
|
||||
public void getMethodInfos(ABC abc, int classIndex, List<MethodId> methodInfos) {
|
||||
for (int t = 0; t < traits.size(); t++) {
|
||||
Trait trait = traits.get(t);
|
||||
trait.getMethodInfos(abc, classIndex, methodInfos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ package com.jpexs.decompiler.flash.exporters.modes;
|
||||
* @author JPEXS
|
||||
*/
|
||||
public enum ScriptExportMode {
|
||||
|
||||
AS, PCODE, PCODE_HEX, HEX, CONSTANTS, AS_METHOD_STUBS;
|
||||
AS,
|
||||
PCODE,
|
||||
PCODE_HEX,
|
||||
HEX,
|
||||
CONSTANTS, // AS1/2 ConstantPool
|
||||
AS_METHOD_STUBS;
|
||||
}
|
||||
|
||||
@@ -26,14 +26,34 @@ public class ABCSearchResult {
|
||||
|
||||
private final ScriptPack scriptPack;
|
||||
|
||||
private final int classIndex;
|
||||
|
||||
private final int methodIndex;
|
||||
|
||||
public ABCSearchResult(ScriptPack scriptPack) {
|
||||
this.scriptPack = scriptPack;
|
||||
classIndex = 0;
|
||||
methodIndex = 0;
|
||||
}
|
||||
|
||||
public ABCSearchResult(ScriptPack scriptPack, int classIndex, int methodIndex) {
|
||||
this.scriptPack = scriptPack;
|
||||
this.classIndex = classIndex;
|
||||
this.methodIndex = methodIndex;
|
||||
}
|
||||
|
||||
public ScriptPack getScriptPack() {
|
||||
return scriptPack;
|
||||
}
|
||||
|
||||
public int getClassIndex() {
|
||||
return classIndex;
|
||||
}
|
||||
|
||||
public int getMethodIndex() {
|
||||
return methodIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return scriptPack.getClassPath().toString();
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package com.jpexs.decompiler.flash.search;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.ScriptPack;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodBody;
|
||||
import com.jpexs.decompiler.flash.cache.ScriptDecompiledListener;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
|
||||
@@ -55,7 +57,10 @@ public class ActionScriptSearch {
|
||||
ASMSource asm = item.getValue();
|
||||
|
||||
if (pcode) {
|
||||
//Main.startWork(workText + " \"" + txt + "\" - (" + pos + "/" + asms.size() + ") " + item.getKey() + "... ", worker);
|
||||
if (listener != null) {
|
||||
listener.onSearch(pos, asms.size(), item.getKey());
|
||||
}
|
||||
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
|
||||
asm.getASMSource(ScriptExportMode.PCODE, writer, null);
|
||||
String text = writer.toString();
|
||||
@@ -137,29 +142,53 @@ public class ActionScriptSearch {
|
||||
}
|
||||
}
|
||||
|
||||
int fpos = pos;
|
||||
Future<HighlightedText> text = SWF.getCachedFuture(pack, new ScriptDecompiledListener<HighlightedText>() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (listener != null) {
|
||||
listener.onDecompile(fpos, allpacks.size(), pack.getClassPath().toString());
|
||||
}
|
||||
if (pcode) {
|
||||
if (listener != null) {
|
||||
listener.onSearch(pos, allpacks.size(), pack.getClassPath().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(HighlightedText result) {
|
||||
if (listener != null) {
|
||||
listener.onSearch(fpos, allpacks.size(), pack.getClassPath().toString());
|
||||
}
|
||||
List<MethodId> methodInfos = new ArrayList<>();
|
||||
pack.getMethodInfos(methodInfos);
|
||||
|
||||
if (pat.matcher(result.text).find()) {
|
||||
ABCSearchResult searchResult = new ABCSearchResult(pack);
|
||||
found.add(searchResult);
|
||||
ABC abc = pack.abc;
|
||||
for (MethodId methodInfo : methodInfos) {
|
||||
int bodyIndex = abc.findBodyIndex(methodInfo.getMethodIndex());
|
||||
if (bodyIndex != -1) {
|
||||
MethodBody body = abc.bodies.get(bodyIndex);
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
|
||||
abc.bodies.get(bodyIndex).getCode().toASMSource(abc.constants, abc.method_info.get(body.method_info), body, ScriptExportMode.PCODE, writer);
|
||||
String text = writer.toString();
|
||||
if (pat.matcher(text).find()) {
|
||||
ABCSearchResult searchResult = new ABCSearchResult(pack, methodInfo.getClassIndex(), methodInfo.getMethodIndex());
|
||||
found.add(searchResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
int fpos = pos;
|
||||
Future<HighlightedText> text = SWF.getCachedFuture(pack, new ScriptDecompiledListener<HighlightedText>() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (listener != null) {
|
||||
listener.onDecompile(fpos, allpacks.size(), pack.getClassPath().toString());
|
||||
}
|
||||
}
|
||||
|
||||
futures.add(text);
|
||||
@Override
|
||||
public void onComplete(HighlightedText result) {
|
||||
if (listener != null) {
|
||||
listener.onSearch(fpos, allpacks.size(), pack.getClassPath().toString());
|
||||
}
|
||||
|
||||
if (pat.matcher(result.text).find()) {
|
||||
ABCSearchResult searchResult = new ABCSearchResult(pack);
|
||||
found.add(searchResult);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
futures.add(text);
|
||||
}
|
||||
}
|
||||
|
||||
for (Future<HighlightedText> future : futures) {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2016 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.search;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class MethodId {
|
||||
|
||||
private final int classIndex;
|
||||
|
||||
private final int methodIndex;
|
||||
|
||||
public MethodId(int classIndex, int methodIndex) {
|
||||
this.classIndex = classIndex;
|
||||
this.methodIndex = methodIndex;
|
||||
}
|
||||
|
||||
public int getClassIndex() {
|
||||
return classIndex;
|
||||
}
|
||||
|
||||
public int getMethodIndex() {
|
||||
return methodIndex;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user