mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-13 12:18:26 +00:00
allow trait specification in pcode import
This commit is contained in:
@@ -97,7 +97,7 @@ public class ABC {
|
||||
|
||||
public List<MethodBody> bodies = new ArrayList<>();
|
||||
|
||||
private Map<Integer, Integer> bodyIdxFromMethodIdx;
|
||||
private ABCMethodIndexing abcMethodIndexing;
|
||||
|
||||
public static final int MINORwithDECIMAL = 17;
|
||||
|
||||
@@ -128,7 +128,7 @@ public class ABC {
|
||||
|
||||
public int addMethodBody(MethodBody body) {
|
||||
bodies.add(body);
|
||||
bodyIdxFromMethodIdx = null;
|
||||
abcMethodIndexing = null;
|
||||
return bodies.size() - 1;
|
||||
}
|
||||
|
||||
@@ -149,7 +149,6 @@ public class ABC {
|
||||
MethodBody methodBody = new MethodBody();
|
||||
methodBody.method_info = methodInfoId;
|
||||
addMethodBody(methodBody);
|
||||
methodInfo.setBody(methodBody);
|
||||
|
||||
TraitMethodGetterSetter trait = new TraitMethodGetterSetter();
|
||||
trait.name_index = multinameId;
|
||||
@@ -566,13 +565,12 @@ public class ABC {
|
||||
}
|
||||
mb.traits = ais.readTraits("traits");
|
||||
bodies.add(mb);
|
||||
method_info.get(mb.method_info).setBody(mb);
|
||||
ais.endDumpLevel();
|
||||
|
||||
SWFDecompilerPlugin.fireMethodBodyParsed(mb, swf);
|
||||
}
|
||||
|
||||
createBodyIdxFromMethodIdxMap();
|
||||
getMethodIndexing();
|
||||
|
||||
/*for(int i=0;i<script_count;i++){
|
||||
MethodBody bod=bodies.get(bodyIdxFromMethodIdx.get(script_info.get(i).init_index));
|
||||
@@ -690,24 +688,20 @@ public class ABC {
|
||||
}
|
||||
}
|
||||
|
||||
public MethodBody findBody(MethodInfo methodInfo) {
|
||||
return getMethodIndexing().findMethodBody(methodInfo);
|
||||
}
|
||||
|
||||
public MethodBody findBody(int methodInfo) {
|
||||
if (methodInfo < 0) {
|
||||
return null;
|
||||
}
|
||||
return method_info.get(methodInfo).getBody();
|
||||
return getMethodIndexing().findMethodBody(methodInfo);
|
||||
}
|
||||
|
||||
public int findBodyIndex(MethodInfo methodInfo) {
|
||||
return getMethodIndexing().findMethodBodyIndex(methodInfo);
|
||||
}
|
||||
|
||||
public int findBodyIndex(int methodInfo) {
|
||||
if (methodInfo == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Integer result = getBodyIdxFromMethodIdx().get(methodInfo);
|
||||
if (result == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
return getMethodIndexing().findMethodBodyIndex(methodInfo);
|
||||
}
|
||||
|
||||
public MethodBody findBodyByClassAndName(String className, String methodName) {
|
||||
@@ -839,21 +833,12 @@ public class ABC {
|
||||
return deobfuscation;
|
||||
}
|
||||
|
||||
public final void createBodyIdxFromMethodIdxMap() {
|
||||
Map<Integer, Integer> map = new HashMap<>(bodies.size());
|
||||
for (int i = 0; i < bodies.size(); i++) {
|
||||
MethodBody mb = bodies.get(i);
|
||||
map.put(mb.method_info, i);
|
||||
public final ABCMethodIndexing getMethodIndexing() {
|
||||
if (abcMethodIndexing == null) {
|
||||
abcMethodIndexing = new ABCMethodIndexing(this);
|
||||
}
|
||||
|
||||
bodyIdxFromMethodIdx = map;
|
||||
}
|
||||
|
||||
private Map<Integer, Integer> getBodyIdxFromMethodIdx() {
|
||||
if (bodyIdxFromMethodIdx == null) {
|
||||
createBodyIdxFromMethodIdxMap();
|
||||
}
|
||||
return bodyIdxFromMethodIdx;
|
||||
return abcMethodIndexing;
|
||||
}
|
||||
|
||||
public DottedChain nsValueToName(String valueStr) {
|
||||
@@ -1234,7 +1219,7 @@ public class ABC {
|
||||
removeMethodFromTraits(si.traits, index);
|
||||
}
|
||||
|
||||
bodyIdxFromMethodIdx = null;
|
||||
abcMethodIndexing = null;
|
||||
|
||||
method_info.remove(index);
|
||||
}
|
||||
@@ -1302,6 +1287,6 @@ public class ABC {
|
||||
}
|
||||
}
|
||||
|
||||
createBodyIdxFromMethodIdxMap();
|
||||
getMethodIndexing();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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.flash.abc;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.types.ClassInfo;
|
||||
import com.jpexs.decompiler.flash.abc.types.InstanceInfo;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodBody;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitClass;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitFunction;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class ABCMethodIndexing {
|
||||
|
||||
private ABC abc;
|
||||
|
||||
private Map<MethodInfo, Integer> bodyIdxFromMethod = new HashMap<>();
|
||||
|
||||
public ABCMethodIndexing(ABC abc) {
|
||||
this.abc = abc;
|
||||
createBodyIdxFromMethodIdxMap(abc);
|
||||
}
|
||||
|
||||
public final void createBodyIdxFromMethodIdxMap(ABC abc) {
|
||||
List<MethodBody> bodies = abc.bodies;
|
||||
Map<MethodInfo, Integer> map = new HashMap<>(bodies.size());
|
||||
for (int i = 0; i < bodies.size(); i++) {
|
||||
MethodBody mb = bodies.get(i);
|
||||
map.put(abc.method_info.get(mb.method_info), i);
|
||||
}
|
||||
|
||||
bodyIdxFromMethod = map;
|
||||
}
|
||||
|
||||
public int findMethodBodyIndex(MethodInfo methodInfo) {
|
||||
Integer bi = bodyIdxFromMethod.get(methodInfo);
|
||||
if (bi == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return bi;
|
||||
}
|
||||
|
||||
public int findMethodBodyIndex(int methodInfo) {
|
||||
if (methodInfo < 0 || methodInfo >= abc.method_info.size()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
MethodInfo mi = abc.method_info.get(methodInfo);
|
||||
return findMethodBodyIndex(mi);
|
||||
}
|
||||
|
||||
public MethodBody findMethodBody(MethodInfo methodInfo) {
|
||||
int bi = findMethodBodyIndex(methodInfo);
|
||||
if (bi != -1) {
|
||||
return abc.bodies.get(bi);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public MethodBody findMethodBody(int methodInfo) {
|
||||
int bi = findMethodBodyIndex(methodInfo);
|
||||
if (bi != -1) {
|
||||
return abc.bodies.get(bi);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Trait> findMethodTraits(ScriptPack pack, int bodyIndex) {
|
||||
int methodInfo = abc.bodies.get(bodyIndex).method_info;
|
||||
List<Trait> traits = abc.script_info.get(pack.scriptIndex).traits.traits;
|
||||
List<Trait> resultTraits = new ArrayList<>();
|
||||
for (int ti : pack.traitIndices) {
|
||||
Trait t = traits.get(ti);
|
||||
findTraits(abc, t, methodInfo, resultTraits);
|
||||
}
|
||||
|
||||
return resultTraits;
|
||||
}
|
||||
|
||||
private static void findTraits(ABC abc, Trait trait, int methodInfo, List<Trait> result) {
|
||||
if (trait instanceof TraitSlotConst) {
|
||||
TraitSlotConst tsc = (TraitSlotConst) trait;
|
||||
} else if (trait instanceof TraitFunction) {
|
||||
TraitFunction tf = (TraitFunction) trait;
|
||||
if (tf.method_info == methodInfo) {
|
||||
result.add(trait);
|
||||
}
|
||||
} else if (trait instanceof TraitMethodGetterSetter) {
|
||||
TraitMethodGetterSetter tmgs = (TraitMethodGetterSetter) trait;
|
||||
if (tmgs.method_info == methodInfo) {
|
||||
result.add(trait);
|
||||
}
|
||||
} else if (trait instanceof TraitClass) {
|
||||
TraitClass tc = (TraitClass) trait;
|
||||
InstanceInfo instanceInfo = abc.instance_info.get(tc.class_info);
|
||||
for (Trait t : instanceInfo.instance_traits.traits) {
|
||||
findTraits(abc, t, methodInfo, result);
|
||||
}
|
||||
|
||||
ClassInfo classInfo = abc.class_info.get(tc.class_info);
|
||||
for (Trait t : classInfo.static_traits.traits) {
|
||||
findTraits(abc, t, methodInfo, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc;
|
||||
|
||||
import com.jpexs.decompiler.flash.IdentifiersDeobfuscation;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@@ -1674,7 +1674,6 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
List<GraphSourceItem> src = body == null ? new ArrayList<>() : generate(localData, body);
|
||||
|
||||
mbody.method_info = abcIndex.getSelectedAbc().addMethodInfo(mi);
|
||||
mi.setBody(mbody);
|
||||
ArrayList<AVM2Instruction> mbodyCode = toInsList(src);
|
||||
mbody.setCode(new AVM2Code(mbodyCode));
|
||||
|
||||
|
||||
@@ -2524,7 +2524,7 @@ public class ActionScript3Parser {
|
||||
abc.class_info = originalAbc.class_info;
|
||||
abc.script_info = originalAbc.script_info;
|
||||
abc.bodies = originalAbc.bodies;
|
||||
abc.createBodyIdxFromMethodIdxMap();
|
||||
abc.getMethodIndexing();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ public class MethodInfo {
|
||||
|
||||
public void delete(ABC abc, boolean d) {
|
||||
this.deleted = true;
|
||||
MethodBody body = abc.findBody(this);
|
||||
if (body != null) {
|
||||
for (AVM2Instruction ins : body.getCode().code) {
|
||||
if (ins.definition instanceof NewFunctionIns) {
|
||||
@@ -83,8 +84,6 @@ public class MethodInfo {
|
||||
|
||||
public int[] paramNames = new int[0];
|
||||
|
||||
private MethodBody body;
|
||||
|
||||
public void setFlagIgnore_Rest() {
|
||||
flags |= FLAG_IGNORE_REST;
|
||||
}
|
||||
@@ -383,12 +382,4 @@ public class MethodInfo {
|
||||
}
|
||||
return writer.hilightSpecial(rname, HighlightSpecialType.RETURNS);
|
||||
}
|
||||
|
||||
public void setBody(MethodBody body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public MethodBody getBody() {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user