Skip to content

Commit

Permalink
feat: Expose opcode maps in blw util
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Sep 14, 2024
1 parent 7d44c7d commit 4710223
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.darknet.assembler.util;

import dev.xdark.blw.code.JavaOpcodes;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Field;
import java.util.HashMap;
Expand All @@ -9,6 +10,7 @@
public class BlwOpcodes {

private static final Map<String, Integer> opcodes = new HashMap<>();
private static final Map<String, Integer> filteredOpcodes = new HashMap<>();

public static int opcode(String name) {
if (name.endsWith("interface")) {
Expand All @@ -21,6 +23,14 @@ public static int opcode(String name) {
return opcodes.get(name);
}

public static @NotNull Map<String, Integer> getOpcodes() {
return opcodes;
}

public static @NotNull Map<String, Integer> getFilteredOpcodes() {
return filteredOpcodes;
}

static {
Field[] fields = JavaOpcodes.class.getFields();
for (Field field : fields) {
Expand All @@ -31,6 +41,15 @@ public static int opcode(String name) {
}
}
opcodes.put("line", -1);
}

// Filtered
filteredOpcodes.putAll(opcodes);
filteredOpcodes.remove("ldc_w");
filteredOpcodes.remove("ldc2_w");
filteredOpcodes.remove("jsr");
filteredOpcodes.remove("ret");
filteredOpcodes.put("invokestaticinterface", JavaOpcodes.INVOKESTATIC);
filteredOpcodes.put("invokevirtualinterface", JavaOpcodes.INVOKEINTERFACE);
filteredOpcodes.put("invokespecialinterface", JavaOpcodes.INVOKESPECIAL);
}
}

0 comments on commit 4710223

Please sign in to comment.