Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int getMultiplier(String clazz, String field) {
- HashMap<String, Integer> multipliers = new HashMap<String, Integer>();
- for (ClassGen cg : parsedClasses.values()) {
- ConstantPoolGen cpg = cg.getConstantPool();
- for (Method m : cg.getMethods()) {
- if (m.isAbstract() || m.isNative())
- continue;
- try {
- InstructionList il = new InstructionList(m.getCode()
- .getCode());
- InstructionHandle curr = il.getStart();
- while (!curr.equals(il.getEnd())) {
- if (curr.getInstruction() instanceof GETFIELD
- || curr.getInstruction() instanceof GETSTATIC) {
- FieldInstruction fi = (FieldInstruction) curr
- .getInstruction();
- if (fi.getClassName(cpg).equals(clazz)
- && fi.getFieldName(cpg).equals(field)) {
- InstructionHandle mulIns = curr;
- for (int i = 0; i < ((curr.getInstruction() instanceof GETSTATIC) ? 2
- : 5); ++i) {
- if (mulIns.getInstruction() instanceof IMUL)
- break;
- if (mulIns.getNext() == null)
- break;
- mulIns = mulIns.getNext();
- }
- if (!(mulIns.getInstruction() instanceof IMUL))
- break;
- InstructionHandle multi = mulIns;
- for (int i = 0; i < ((curr.getInstruction() instanceof GETSTATIC) ? 2
- : 5); ++i) {
- if (multi.getInstruction() instanceof LDC
- || multi.getInstruction() instanceof LDC_W)
- break;
- if (multi.getPrev() == null)
- break;
- multi = multi.getPrev();
- if (multi.getInstruction() instanceof AALOAD) {
- multi = multi.getPrev();
- multi = multi.getPrev();
- multi = multi.getPrev();
- }
- }
- if (!(multi.getInstruction() instanceof LDC)
- && !(multi.getInstruction() instanceof LDC_W))
- break;
- if (multi.getInstruction() instanceof LDC) {
- int temp = (Integer) ((LDC) multi
- .getInstruction()).getValue(cpg);
- if (temp != 0) {
- if (multipliers.containsKey(temp + ""))
- multipliers
- .put(temp + "", multipliers
- .get(temp + "") + 1);
- else
- multipliers.put(temp + "", 1);
- }
- }
- }
- }
- curr = curr.getNext();
- }
- } catch (Exception e) {
- }
- }
- }
- int max = 0;
- int multi = 1;
- for (String s : multipliers.keySet()) {
- if (multipliers.get(s) > max) {
- multi = Integer.parseInt(s);
- max = multipliers.get(s);
- }
- }
- return multi;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement