mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-08 14:33:49 +00:00
replace AtionScript from command line
This commit is contained in:
@@ -855,8 +855,8 @@ public final class SWF implements TreeItem, Timelined {
|
||||
List<MyEntry<ClassPath, ScriptPack>> ret = new ArrayList<>();
|
||||
for (MyEntry<ClassPath, ScriptPack> item : packs) {
|
||||
for (MyEntry<ClassPath, ScriptPack> itemOld : ret) {
|
||||
if (item.key.equals(itemOld.key)) {
|
||||
logger.log(Level.SEVERE, "Duplicate pack path found (" + itemOld.key + ")!");
|
||||
if (item.getKey().equals(itemOld.getKey())) {
|
||||
logger.log(Level.SEVERE, "Duplicate pack path found (" + itemOld.getKey() + ")!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -968,7 +968,7 @@ public final class SWF implements TreeItem, Timelined {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
for (MyEntry<ClassPath, ScriptPack> item : packs) {
|
||||
ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.key, item.value, outdir, abcTags, exportMode, parallel);
|
||||
ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.getKey(), item.getValue(), outdir, abcTags, exportMode, parallel);
|
||||
ret.add(task.call());
|
||||
}
|
||||
return null;
|
||||
@@ -983,7 +983,7 @@ public final class SWF implements TreeItem, Timelined {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(Configuration.parallelThreadCount.get());
|
||||
List<Future<File>> futureResults = new ArrayList<>();
|
||||
for (MyEntry<ClassPath, ScriptPack> item : packs) {
|
||||
Future<File> future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.key, item.value, outdir, abcTags, exportMode, parallel));
|
||||
Future<File> future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.getKey(), item.getValue(), outdir, abcTags, exportMode, parallel));
|
||||
futureResults.add(future);
|
||||
}
|
||||
|
||||
@@ -1970,7 +1970,7 @@ public final class SWF implements TreeItem, Timelined {
|
||||
informListeners("rename", "");
|
||||
int fc = 0;
|
||||
for (MyEntry<DirectValueActionItem, ConstantPool> it : allVariableNames) {
|
||||
String name = it.key.toStringNoH(it.value);
|
||||
String name = it.getKey().toStringNoH(it.getValue());
|
||||
deobfuscation.allVariableNamesStr.add(name);
|
||||
}
|
||||
|
||||
@@ -2029,10 +2029,10 @@ public final class SWF implements TreeItem, Timelined {
|
||||
|
||||
List<GraphTargetItem> vars = new ArrayList<>();
|
||||
for (MyEntry<GraphTargetItem, GraphTargetItem> item : cti.vars) {
|
||||
vars.add(item.key);
|
||||
vars.add(item.getKey());
|
||||
}
|
||||
for (MyEntry<GraphTargetItem, GraphTargetItem> item : cti.staticVars) {
|
||||
vars.add(item.key);
|
||||
vars.add(item.getKey());
|
||||
}
|
||||
for (GraphTargetItem gti : vars) {
|
||||
if (gti instanceof DirectValueActionItem) {
|
||||
@@ -2139,7 +2139,7 @@ public final class SWF implements TreeItem, Timelined {
|
||||
HashSet<String> stringsNoVarH = new HashSet<>();
|
||||
List<DirectValueActionItem> allVariableNamesDv = new ArrayList<>();
|
||||
for (MyEntry<DirectValueActionItem, ConstantPool> it : allVariableNames) {
|
||||
allVariableNamesDv.add(it.key);
|
||||
allVariableNamesDv.add(it.getKey());
|
||||
}
|
||||
for (DirectValueActionItem ti : allStrings.keySet()) {
|
||||
if (!allVariableNamesDv.contains(ti)) {
|
||||
@@ -2150,22 +2150,22 @@ public final class SWF implements TreeItem, Timelined {
|
||||
int vc = 0;
|
||||
for (MyEntry<DirectValueActionItem, ConstantPool> it : allVariableNames) {
|
||||
vc++;
|
||||
String name = it.key.toStringNoH(it.value);
|
||||
String changed = deobfuscation.deobfuscateName(name, false, usageTypes.get(it.key), deobfuscated, renameType, selected);
|
||||
String name = it.getKey().toStringNoH(it.getValue());
|
||||
String changed = deobfuscation.deobfuscateName(name, false, usageTypes.get(it.getKey()), deobfuscated, renameType, selected);
|
||||
if (changed != null) {
|
||||
boolean addNew = false;
|
||||
String h = System.identityHashCode(it.key) + "_" + name;
|
||||
String h = System.identityHashCode(it.getKey()) + "_" + name;
|
||||
if (stringsNoVarH.contains(h)) {
|
||||
addNew = true;
|
||||
}
|
||||
ActionPush pu = (ActionPush) it.key.src;
|
||||
ActionPush pu = (ActionPush) it.getKey().src;
|
||||
if (pu.replacement == null) {
|
||||
pu.replacement = new ArrayList<>();
|
||||
pu.replacement.addAll(pu.values);
|
||||
}
|
||||
if (pu.replacement.get(it.key.pos) instanceof ConstantIndex) {
|
||||
ConstantIndex ci = (ConstantIndex) pu.replacement.get(it.key.pos);
|
||||
ConstantPool pool = it.value;
|
||||
if (pu.replacement.get(it.getKey().pos) instanceof ConstantIndex) {
|
||||
ConstantIndex ci = (ConstantIndex) pu.replacement.get(it.getKey().pos);
|
||||
ConstantPool pool = it.getValue();
|
||||
if (pool == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -2179,7 +2179,7 @@ public final class SWF implements TreeItem, Timelined {
|
||||
pool.constants.set(ci.index, changed);
|
||||
}
|
||||
} else {
|
||||
pu.replacement.set(it.key.pos, changed);
|
||||
pu.replacement.set(it.getKey().pos, changed);
|
||||
}
|
||||
ret++;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import com.jpexs.decompiler.flash.abc.avm2.UnknownInstructionCode;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.executing.CallPropertyIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushStringIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.parser.ParseException;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScriptParser;
|
||||
import com.jpexs.decompiler.flash.abc.types.ABCException;
|
||||
import com.jpexs.decompiler.flash.abc.types.ClassInfo;
|
||||
import com.jpexs.decompiler.flash.abc.types.InstanceInfo;
|
||||
@@ -56,6 +58,9 @@ import com.jpexs.decompiler.flash.abc.usages.TypeNameMultinameUsage;
|
||||
import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin;
|
||||
import com.jpexs.decompiler.flash.helpers.collections.MyEntry;
|
||||
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
|
||||
import com.jpexs.decompiler.flash.tags.SymbolClassTag;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.helpers.MemoryInputStream;
|
||||
import com.jpexs.helpers.utf8.Utf8PrintWriter;
|
||||
import java.io.IOException;
|
||||
@@ -1004,17 +1009,17 @@ public class ABC {
|
||||
name = name.substring(0, name.length() - 2);
|
||||
|
||||
for (MyEntry<ClassPath, ScriptPack> en : allPacks) {
|
||||
if (en.key.toString().startsWith(name)) {
|
||||
ret.add(en.value);
|
||||
if (en.getKey().toString().startsWith(name)) {
|
||||
ret.add(en.getValue());
|
||||
}
|
||||
}
|
||||
} else if (name.endsWith(".*") || name.equals("*") || name.endsWith(".+") || name.equals("+")) {
|
||||
name = name.substring(0, name.length() - 1);
|
||||
for (MyEntry<ClassPath, ScriptPack> en : allPacks) {
|
||||
if (en.key.toString().startsWith(name)) {
|
||||
String rem = name.isEmpty() ? en.key.toString() : en.key.toString().substring(name.length());
|
||||
if (en.getKey().toString().startsWith(name)) {
|
||||
String rem = name.isEmpty() ? en.getKey().toString() : en.getKey().toString().substring(name.length());
|
||||
if (!rem.contains(".")) {
|
||||
ret.add(en.value);
|
||||
ret.add(en.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1031,8 +1036,8 @@ public class ABC {
|
||||
public ScriptPack findScriptPackByPath(String name) {
|
||||
List<MyEntry<ClassPath, ScriptPack>> packs = getScriptPacks();
|
||||
for (MyEntry<ClassPath, ScriptPack> en : packs) {
|
||||
if (en.key.toString().equals(name)) {
|
||||
return en.value;
|
||||
if (en.getKey().toString().equals(name)) {
|
||||
return en.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -1148,6 +1153,34 @@ public class ABC {
|
||||
method_info.remove(index);
|
||||
}
|
||||
|
||||
public void replaceSciptPack(ScriptPack pack, String as) throws ParseException, CompilationException, IOException, InterruptedException {
|
||||
String scriptName = pack.getPathScriptName() + ".as";
|
||||
int oldIndex = pack.scriptIndex;
|
||||
int newIndex = script_info.size();
|
||||
String documentClass = "";
|
||||
loopt:
|
||||
for (Tag t : swf.tags) {
|
||||
if (t instanceof SymbolClassTag) {
|
||||
SymbolClassTag sc = (SymbolClassTag) t;
|
||||
for (int i = 0; i < sc.tags.length; i++) {
|
||||
if (sc.tags[i] == 0) {
|
||||
documentClass = sc.names[i];
|
||||
break loopt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean isDocumentClass = documentClass.equals(pack.getPath().toString());
|
||||
|
||||
script_info.get(oldIndex).delete(this, true);
|
||||
ActionScriptParser.compile(as, this, new ArrayList<ABC>(), isDocumentClass, scriptName);
|
||||
//Move newly added script to its position
|
||||
script_info.set(oldIndex, script_info.get(newIndex));
|
||||
script_info.remove(newIndex);
|
||||
pack(); //removes old classes/methods
|
||||
((Tag) parentTag).setModified(true);
|
||||
}
|
||||
|
||||
public void pack() {
|
||||
for (int c = 0; c < instance_info.size(); c++) {
|
||||
if (instance_info.get(c).deleted) {
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.action.model.clauses;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -91,7 +92,7 @@ public class ClassActionItem extends ActionItem implements Block {
|
||||
}
|
||||
uninitializedVars.addAll(allMembers);
|
||||
for (MyEntry<GraphTargetItem, GraphTargetItem> v : vars) {
|
||||
for (MyEntry<GraphTargetItem, GraphTargetItem> v : vars) {
|
||||
String s = v.getKey().toStringNoQuotes(LocalData.empty);
|
||||
if (uninitializedVars.contains(s)) {
|
||||
uninitializedVars.remove(s);
|
||||
}
|
||||
@@ -169,9 +170,9 @@ public class ClassActionItem extends ActionItem implements Block {
|
||||
|
||||
for (MyEntry<GraphTargetItem, GraphTargetItem> item : vars) {
|
||||
writer.append("var ");
|
||||
writer.append("var ");
|
||||
item.getKey().toStringNoQuotes(writer, localData);
|
||||
writer.append(" = ");
|
||||
writer.append(" = ");
|
||||
item.getValue().toString(writer, localData);
|
||||
writer.append(";").newLine();
|
||||
}
|
||||
for (String v : uninitializedVars) {
|
||||
@@ -181,9 +182,9 @@ public class ClassActionItem extends ActionItem implements Block {
|
||||
}
|
||||
for (MyEntry<GraphTargetItem, GraphTargetItem> item : staticVars) {
|
||||
writer.append("static var ");
|
||||
writer.append("static var ");
|
||||
item.getKey().toStringNoQuotes(writer, localData);
|
||||
writer.append(" = ");
|
||||
writer.append(" = ");
|
||||
item.getValue().toString(writer, localData);
|
||||
writer.append(";").newLine();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.action.parser.script;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
@@ -690,14 +691,14 @@ public class ActionSourceGenerator implements SourceGenerator {
|
||||
}
|
||||
for (MyEntry<GraphTargetItem, GraphTargetItem> en : staticVars) {
|
||||
ifbody.add(new ActionPush(new RegisterNumber(1/*static*/)));
|
||||
ifbody.add(new ActionPush(new RegisterNumber(1/*static*/)));
|
||||
ifbody.add(new ActionPush(getName(en.key)));
|
||||
ifbody.add(new ActionPush(getName(en.getKey())));
|
||||
ifbody.addAll(toActionList(en.getValue().toSource(localData, this)));
|
||||
ifbody.add(new ActionSetMember());
|
||||
}
|
||||
for (MyEntry<GraphTargetItem, GraphTargetItem> en : vars) {
|
||||
ifbody.add(new ActionPush(new RegisterNumber(2/*instance*/)));
|
||||
ifbody.add(new ActionPush(new RegisterNumber(2/*instance*/)));
|
||||
ifbody.add(new ActionPush(getName(en.key)));
|
||||
ifbody.add(new ActionPush(getName(en.getKey())));
|
||||
ifbody.addAll(toActionList(en.getValue().toSource(localData, this)));
|
||||
ifbody.add(new ActionSetMember());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers.collections;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
@@ -26,8 +27,8 @@ import java.util.Objects;
|
||||
*/
|
||||
public class MyEntry<K, V> implements Entry<K, V> {
|
||||
|
||||
|
||||
public K key;
|
||||
private final K key;
|
||||
private V value;
|
||||
|
||||
public MyEntry(K key, V value) {
|
||||
this.key = key;
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers.collections;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -44,7 +45,7 @@ public class MyMap<K, V> implements Map<K, V> {
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
if (kv.getKey().equals(key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -54,7 +55,7 @@ public class MyMap<K, V> implements Map<K, V> {
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
if (kv.getValue().equals(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -64,8 +65,8 @@ public class MyMap<K, V> implements Map<K, V> {
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
if (kv.key.equals(key)) {
|
||||
if (kv.getKey().equals(key)) {
|
||||
return kv.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -74,8 +75,8 @@ public class MyMap<K, V> implements Map<K, V> {
|
||||
@Override
|
||||
public V put(K key, V value) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
if (kv.key.equals(key)) {
|
||||
if (kv.getKey().equals(key)) {
|
||||
kv.setValue(value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -87,9 +88,9 @@ public class MyMap<K, V> implements Map<K, V> {
|
||||
public V remove(Object key) {
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
MyEntry<K, V> kv = values.get(i);
|
||||
MyEntry<K, V> kv = values.get(i);
|
||||
if (kv.getKey().equals(key)) {
|
||||
values.remove(i);
|
||||
values.remove(i);
|
||||
return kv.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -111,7 +112,7 @@ public class MyMap<K, V> implements Map<K, V> {
|
||||
public Set<K> keySet() {
|
||||
Set<K> ret = new MySet<>();
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
ret.add(kv.getKey());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -120,7 +121,7 @@ public class MyMap<K, V> implements Map<K, V> {
|
||||
public Collection<V> values() {
|
||||
Collection<V> ret = new ArrayList<>();
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
ret.add(kv.getValue());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user