use of org.objectweb.asm.tree.JumpInsnNode in project Random-Things by lumien231.
the class ClassTransformer method patchInventoryPlayer.
private byte[] patchInventoryPlayer(byte[] basicClass) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(basicClass);
classReader.accept(classNode, 0);
logger.log(Level.DEBUG, "Found InventoryPlayer Class: " + classNode.name);
MethodNode dropAllItems = null;
for (MethodNode mn : classNode.methods) {
if (mn.name.equals(MCPNames.method("func_70436_m"))) {
dropAllItems = mn;
break;
}
}
if (dropAllItems != null) {
logger.log(Level.DEBUG, " - Found dropAllItems (1/2)");
for (int i = 0; i < dropAllItems.instructions.size(); i++) {
AbstractInsnNode ain = dropAllItems.instructions.get(i);
if (ain instanceof JumpInsnNode) {
JumpInsnNode jin = (JumpInsnNode) ain;
if (jin.getOpcode() == Opcodes.IFNE) {
AbstractInsnNode before = dropAllItems.instructions.get(i - 1);
if (before instanceof MethodInsnNode && ((MethodInsnNode) before).name.equals(MCPNames.method("func_190926_b"))) {
LabelNode l0 = jin.label;
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(ALOAD, 0));
toInsert.add(new VarInsnNode(ILOAD, 3));
toInsert.add(new VarInsnNode(ALOAD, 4));
toInsert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, asmHandler, "shouldPlayerDrop", "(Lnet/minecraft/entity/player/InventoryPlayer;ILnet/minecraft/item/ItemStack;)Z", false));
toInsert.add(new JumpInsnNode(IFEQ, l0));
dropAllItems.instructions.insert(jin, toInsert);
i += 5;
logger.log(Level.DEBUG, " - Patched dropAllItems (2/2)");
}
}
}
}
}
CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(writer);
return writer.toByteArray();
}
use of org.objectweb.asm.tree.JumpInsnNode in project maple-ir by LLVM-but-worse.
the class Subroutine method merge.
public boolean merge(final Subroutine subroutine) throws AnalyzerException {
boolean changes = false;
for (int i = 0; i < access.length; ++i) {
if (subroutine.access[i] && !access[i]) {
access[i] = true;
changes = true;
}
}
if (subroutine.start == start) {
for (int i = 0; i < subroutine.callers.size(); ++i) {
JumpInsnNode caller = subroutine.callers.get(i);
if (!callers.contains(caller)) {
callers.add(caller);
changes = true;
}
}
}
return changes;
}
use of org.objectweb.asm.tree.JumpInsnNode in project maple-ir by LLVM-but-worse.
the class JumpInsnNodeSerializer method deserialize.
@Override
public JumpInsnNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = (JsonObject) json;
int opcode = jsonObject.get("opcode").getAsInt();
LabelNode labelNode = context.deserialize(jsonObject.get("local"), List.class);
return new JumpInsnNode(opcode, labelNode);
}
use of org.objectweb.asm.tree.JumpInsnNode in project jphp by jphp-compiler.
the class TryCatchCompiler method write.
@Override
public void write(TryStmtToken token) {
if (token.getBody() == null || token.getBody().getInstructions().isEmpty()) {
if (token.getFinally() != null)
expr.write(BodyStmtToken.class, token.getFinally());
return;
}
expr.writeDefineVariables(token.getLocal());
LabelNode tryStart = expr.writeLabel(node, token.getMeta().getStartLine());
LabelNode tryEnd = new LabelNode();
LabelNode catchStart = new LabelNode();
LabelNode catchEnd = new LabelNode();
LabelNode returnLabel = new LabelNode();
method.node.tryCatchBlocks.add(0, new TryCatchBlockNode(tryStart, tryEnd, catchStart, Type.getInternalName(BaseBaseException.class)));
if (token.getFinally() != null) {
method.getTryStack().push(new MethodStmtCompiler.TryCatchItem(token, returnLabel));
}
expr.write(BodyStmtToken.class, token.getBody());
if (token.getFinally() != null) {
method.getTryStack().pop();
}
add(tryEnd);
add(new JumpInsnNode(GOTO, catchEnd));
add(catchStart);
LocalVariable exception = method.addLocalVariable("~catch~" + method.nextStatementIndex(BaseException.class), catchStart, BaseBaseException.class);
exception.setEndLabel(catchEnd);
expr.makeVarStore(exception);
LabelNode nextCatch = null;
int i = 0, size = token.getCatches().size();
LocalVariable local = null;
LabelNode catchFail = new LabelNode();
for (CatchStmtToken _catch : token.getCatches()) {
if (nextCatch != null) {
add(nextCatch);
}
if (i == size - 1) {
nextCatch = catchFail;
} else {
nextCatch = new LabelNode();
}
local = method.getLocalVariable(_catch.getVariable().getName());
List<FulledNameToken> catchExceptions = _catch.getExceptions();
LabelNode bodyLabel = new LabelNode();
LabelNode nextCatchLocal = new LabelNode();
int j = 0;
for (FulledNameToken catchException : catchExceptions) {
if (j > 0) {
add(nextCatchLocal);
nextCatchLocal = new LabelNode();
}
expr.writePushEnv();
expr.writeVarLoad(exception);
expr.writePushConstString(catchException.toName());
expr.writePushConstString(catchException.toName().toLowerCase());
expr.writeSysDynamicCall(Environment.class, "__throwCatch", Memory.class, BaseBaseException.class, String.class, String.class);
expr.writeVarAssign(local, _catch.getVariable(), true, false);
expr.writePopBoolean();
add(new JumpInsnNode(IFEQ, j == catchExceptions.size() - 1 ? nextCatch : nextCatchLocal));
expr.stackPop();
if (catchExceptions.size() > 1) {
add(new JumpInsnNode(GOTO, bodyLabel));
}
j++;
}
if (catchExceptions.size() > 1) {
add(bodyLabel);
}
expr.write(BodyStmtToken.class, _catch.getBody());
add(new JumpInsnNode(GOTO, catchEnd));
i++;
}
add(catchFail);
if (token.getFinally() != null) {
expr.write(BodyStmtToken.class, token.getFinally());
}
/*if (method.getTryStack().empty()) {
expr.writePushEnv();
expr.writeVarLoad(exception);
expr.writeSysDynamicCall(Environment.class, "__throwFailedCatch", void.class, BaseException.class);
} else {*/
expr.makeVarLoad(exception);
add(new InsnNode(ATHROW));
// }
add(catchEnd);
if (token.getFinally() != null) {
LabelNode skip = new LabelNode();
add(new JumpInsnNode(GOTO, skip));
// finally for return
add(returnLabel);
expr.write(BodyStmtToken.class, token.getFinally());
if (method.getTryStack().empty()) {
// all finally blocks are done
LocalVariable retVar = method.getOrAddLocalVariable("~result~", null, Memory.class);
expr.writeVarLoad(retVar);
add(new InsnNode(ARETURN));
expr.stackPop();
} else {
// goto next finally block
add(new JumpInsnNode(GOTO, method.getTryStack().peek().getReturnLabel()));
}
add(skip);
// other finally
expr.write(BodyStmtToken.class, token.getFinally());
}
expr.writeUndefineVariables(token.getLocal());
method.prevStatementIndex(BaseBaseException.class);
}
use of org.objectweb.asm.tree.JumpInsnNode in project jphp by jphp-compiler.
the class StaticDefinitionCompiler method write.
@Override
public void write(StaticStmtToken token) {
LocalVariable local = method.getLocalVariable(token.getVariable().getName());
assert local != null;
LabelNode end = new LabelNode();
boolean isClosure = method.clazz.isClosure();
if (isClosure)
expr.writeVarLoad(LocalVariable.THIS);
else
expr.writePushEnv();
// writePushConstString(name);
writePushNameForStaticVariable(local);
expr.writeSysDynamicCall(isClosure ? null : Environment.class, "getStatic", Memory.class, String.class);
expr.writePushDup();
add(new JumpInsnNode(IFNONNULL, end));
expr.stackPop();
expr.writePopAll(1);
if (isClosure)
expr.writeVarLoad(LocalVariable.THIS);
else
expr.writePushEnv();
writePushNameForStaticVariable(local);
if (token.getInitValue() != null) {
expr.writeExpression(token.getInitValue(), true, false, true);
} else {
expr.writePushNull();
}
expr.writePopBoxing(true);
expr.writeSysDynamicCall(isClosure ? null : Environment.class, "getOrCreateStatic", Memory.class, String.class, Memory.class);
add(end);
expr.writeVarStore(local, false, false);
}
Aggregations