use of org.objectweb.asm.tree.AbstractInsnNode in project Engine by VoltzEngine-Project.
the class InstructionComparator method insnListMatchesL.
private static InsnListSection insnListMatchesL(InsnList haystack, InsnList needle, int start, HashSet<LabelNode> controlFlowLabels) {
int h = start, n = 0;
for (; h < haystack.size() && n < needle.size(); h++) {
AbstractInsnNode insn = haystack.get(h);
if (insn.getType() == 15) {
continue;
}
if (insn.getType() == 8 && !controlFlowLabels.contains(insn)) {
continue;
}
if (!insnEqual(haystack.get(h), needle.get(n))) {
return null;
}
n++;
}
if (n != needle.size()) {
return null;
}
return new InsnListSection(haystack, start, h - 1);
}
use of org.objectweb.asm.tree.AbstractInsnNode in project Engine by VoltzEngine-Project.
the class InstructionComparator method insnListFindL.
public static List<InsnListSection> insnListFindL(InsnList haystack, InsnList needle) {
HashSet<LabelNode> controlFlowLabels = new HashSet<>();
for (AbstractInsnNode insn = haystack.getFirst(); insn != null; insn = insn.getNext()) {
switch(insn.getType()) {
case 8:
case 15:
break;
case 7:
JumpInsnNode jinsn = (JumpInsnNode) insn;
controlFlowLabels.add(jinsn.label);
break;
case 11:
TableSwitchInsnNode tsinsn = (TableSwitchInsnNode) insn;
for (LabelNode label : tsinsn.labels) {
controlFlowLabels.add(label);
}
break;
case 12:
LookupSwitchInsnNode lsinsn = (LookupSwitchInsnNode) insn;
for (LabelNode label : lsinsn.labels) {
controlFlowLabels.add(label);
}
break;
}
}
LinkedList<InsnListSection> list = new LinkedList<>();
nextsection: for (int start = 0; start <= haystack.size() - needle.size(); start++) {
InsnListSection section = insnListMatchesL(haystack, needle, start, controlFlowLabels);
if (section != null) {
for (InsnListSection asection : list) {
if (asection.last == section.last) {
continue nextsection;
}
}
list.add(section);
}
}
return list;
}
use of org.objectweb.asm.tree.AbstractInsnNode in project robolectric by robolectric.
the class ClassInstrumentor method rewriteMethodBody.
/**
* Filters methods that might need special treatment because of various reasons
*/
private void rewriteMethodBody(MutableClass mutableClass, MethodNode callingMethod) {
ListIterator<AbstractInsnNode> instructions = callingMethod.instructions.iterator();
while (instructions.hasNext()) {
AbstractInsnNode node = instructions.next();
switch(node.getOpcode()) {
case Opcodes.NEW:
TypeInsnNode newInsnNode = (TypeInsnNode) node;
newInsnNode.desc = mutableClass.config.mappedTypeName(newInsnNode.desc);
break;
case Opcodes.GETFIELD:
/* falls through */
case Opcodes.PUTFIELD:
/* falls through */
case Opcodes.GETSTATIC:
/* falls through */
case Opcodes.PUTSTATIC:
FieldInsnNode fieldInsnNode = (FieldInsnNode) node;
// todo test
fieldInsnNode.desc = mutableClass.config.mappedTypeName(fieldInsnNode.desc);
break;
case Opcodes.INVOKESTATIC:
/* falls through */
case Opcodes.INVOKEINTERFACE:
/* falls through */
case Opcodes.INVOKESPECIAL:
/* falls through */
case Opcodes.INVOKEVIRTUAL:
MethodInsnNode targetMethod = (MethodInsnNode) node;
targetMethod.desc = mutableClass.config.remapParams(targetMethod.desc);
if (isGregorianCalendarBooleanConstructor(targetMethod)) {
replaceGregorianCalendarBooleanConstructor(instructions, targetMethod);
} else if (mutableClass.config.shouldIntercept(targetMethod)) {
interceptInvokeVirtualMethod(mutableClass, instructions, targetMethod);
}
break;
case Opcodes.INVOKEDYNAMIC:
/* no unusual behavior */
break;
default:
break;
}
}
}
use of org.objectweb.asm.tree.AbstractInsnNode in project bytecode-viewer by Konloch.
the class RegexInsnFinder method findAllGroups.
/**
* Searches for a regex in the instruction list and returns all groups for
* all matches.
*
* @param regex the regular expression
* @return a list with all sets of groups with matching instructions
*/
public List<AbstractInsnNode[][]> findAllGroups(final String regex) {
final List<AbstractInsnNode[][]> results = new ArrayList<>();
try {
final Matcher regexMatcher = Pattern.compile(processRegex(regex), Pattern.MULTILINE).matcher(insnString);
if (regexMatcher.find()) {
final AbstractInsnNode[][] result = new AbstractInsnNode[regexMatcher.groupCount() + 1][0];
for (int i = 0; i <= regexMatcher.groupCount(); i++) {
result[i] = makeResult(regexMatcher.start(i), regexMatcher.end(i));
}
results.add(result);
}
} catch (final PatternSyntaxException ex) {
BytecodeViewer.handleException(ex);
}
return results;
}
use of org.objectweb.asm.tree.AbstractInsnNode in project bytecode-viewer by Konloch.
the class RegexInsnFinder method refresh.
/**
* Refreshes the internal instruction list when you have made changes to the
* method.
*/
public void refresh() {
origInstructions = cleanInsn(mn.instructions);
final List<AbstractInsnNode> il = new ArrayList<>();
for (final AbstractInsnNode ain : mn.instructions.toArray()) if (ain.getOpcode() >= 0) {
il.add(ain);
}
AbstractInsnNode[] instructions = il.toArray(new AbstractInsnNode[0]);
offsets = new int[instructions.length];
StringBuilder insnStringBuilder = new StringBuilder();
for (int i = 0; i < instructions.length; i++) {
offsets[i] = -1;
final AbstractInsnNode ain = instructions[i];
if (ain.getOpcode() >= 0) {
if (ain.getOpcode() >= opcodes.length) {
try {
throw new UnexpectedException("Unknown opcode encountered: " + ain.getOpcode());
} catch (final UnexpectedException e) {
BytecodeViewer.handleException(e);
}
}
offsets[i] = insnStringBuilder.length();
insnStringBuilder.append(opcodes[ain.getOpcode()]);
insnStringBuilder = new StringBuilder(getInsString(ain));
insnStringBuilder.append(" ");
}
}
insnString = insnStringBuilder.toString();
}
Aggregations