Package net.sf.rej.java.instruction

Examples of net.sf.rej.java.instruction.DecompilationContext


     * @param lvAttr LocalVariableTableAttribute
     */
    public void printCode(PrintStream out, LineNumberTableAttribute lnAttr, LocalVariableTableAttribute lvAttr) {
      InstructionHints hints = new InstructionHints();
        out.println("---- code starts ----");
        DecompilationContext dc = createDecompilationContext();
        for (Instruction instruction : this.code) {
            String posStr = String.valueOf(dc.getPosition());
            while (posStr.length() < 5)
                posStr = " " + posStr;

            String hint = hints.getHint(instruction);
            if (hint.length() > 0)
                hint = "  (" + hint + ")";
            String lineNumberStr = "     ";
            if (lnAttr != null) {
                int lineNumber = lnAttr.getLineNumber(dc.getPosition());
                if (lineNumber != -1) {
                    lineNumberStr = String.valueOf(lineNumber);
                    while (lineNumberStr.length() < 5)
                        lineNumberStr = " " + lineNumberStr;
                }
            }


            out.println(lineNumberStr + "  " + posStr + " " + " "
                    + instruction.getMnemonic() + " "
                    + instruction.getParameters() + hint);
            dc.incrementPosition(instruction);
        }

        out.println("---- code ends ----");
    }
View Full Code Here


    }

    public byte[] getData() {
        updateLabelPositions();
        ByteSerializer ser = new ByteSerializer(true);
        DecompilationContext dc = createDecompilationContext();
        for (Instruction instruction : this.code) {
            ser.addBytes(instruction.getData(dc));
            dc.incrementPosition(instruction);
        }

        return ser.getBytes();
    }
View Full Code Here

    public DecompilationContext createDecompilationContext() {
        return this.context.createNew();
    }

    public void addInstructionAtPC(int pc, Instruction instruction) {
      DecompilationContext dc = createDecompilationContext();
        int pos = -1;
        for (int i = 0; i < this.code.size(); i++) {
            Instruction otherInst = this.code.get(i);
            if (dc.getPosition() == pc) {
                pos = i; // get the last match, so insert will be after labels
            } else if (dc.getPosition() > pc) {
                break;
            }
            dc.incrementPosition(otherInst);
        }

        if (pc == 0) {
          pos = 0;
        }

        if (pos == -1) {
          if (dc.getPosition() == pc) {
            pos = this.code.size();
          } else {
            throw new RuntimeException("Could not find given pc " + pc);
          }
        }
View Full Code Here

        invalidateLineNumbers();
    }

    public void updateLabelPositions() {
        DecompilationContext dc = createDecompilationContext();
        for (Instruction instruction : this.code) {
            if (instruction instanceof Label) {
                ((Label) instruction).setPosition(dc.getPosition());
            }

            dc.incrementPosition(instruction);
        }
    }
View Full Code Here

            dc.incrementPosition(instruction);
        }
    }

    public int getMaxPC() {
        DecompilationContext dc = createDecompilationContext();
        for (Instruction instruction : this.code) {
            dc.incrementPosition(instruction);
        }
        return dc.getPosition();
    }
View Full Code Here

        if (codeAttr.getAttributes() != null) {
          lnAttr = codeAttr.getAttributes().getLineNumberTable();
          lvs = codeAttr.getAttributes().getLocalVariableTable();
        }
        Code code = codeAttr.getCode();
        DecompilationContext dc = code.createDecompilationContext();
        dc.setPosition(0);
        for (Instruction instruction : code.getInstructions()) {

          if (instruction instanceof Label) {
            LabelRow lr = new LabelRow((Label) instruction, mdr);
            lr.setParentCode(code);
            this.rows.add(lr);
            mdr.addCodeRow(lr);
          } else {
            int lineNumber = -1;

            if (lnAttr != null) {
              lineNumber = lnAttr.getLineNumber(dc.getPosition());
            }
            if (lvs != null) {
              List locals = lvs
                  .getLocalVariable(dc.getPosition());
              for (int k = 0; k < locals.size(); k++) {
                LocalVariable lv = (LocalVariable) locals
                    .get(k);
                LocalVariableDefRow lvdr = new LocalVariableDefRow(
                    lv, mdr);
                this.rows.add(lvdr);
                mdr.addLocalVariable(lvdr);
              }
            }

            CodeRow cd = new CodeRow(cf, mdr, instruction);
            cd.setPosition(dc.getPosition());
            cd.setDecompilationContext(dc);
            cd.setParentCode(code);
            cd.setBreakpoint(EditorFacade.getInstance()
                .getBreakpoint(cf.getFullClassName(),
                    method.getName(),
                    method.getDescriptor(),
                    dc.getPosition()));

            if (lineNumber != -1) {
              cd.setLineNumber(lineNumber);
            }

            this.rows.add(cd);
            mdr.addCodeRow(cd);

            dc.incrementPosition(instruction);
          }

        }

        this.rows.add(new MethodDefRow(cf, method, false, true));
View Full Code Here

        code = mdr.getMethod().getAttributes().getCode().getCode();
        lvAttr = mdr.getMethod().getAttributes().getCode().getAttributes().getLocalVariableTable();
      }
      int pc = 0;
      if (code != null && mdr.isClosing() && mdr.getCodeRows().size() > 0) {
        DecompilationContext dc = code.createDecompilationContext();
        EditorRow er = mdr.getCodeRows().get(
            mdr.getCodeRows().size() - 1);
        if (er instanceof CodeRow) {
          CodeRow cr = (CodeRow) er;
          pc = cr.getPosition();
          dc.setPosition(pc);
          pc += cr.getInstruction().getSize(dc);
        }
      }
     
      insertInstruction(mdr, pc, lvAttr, code);
View Full Code Here

    }

    Object row = this.list.getSelectedValue();
    if (row instanceof CodeRow) {
      CodeRow cr = (CodeRow) row;
      DecompilationContext dc = cr.getDecompilationContext();
      int pos = cr.getPosition();
      if (!before) {
        dc.setPosition(pos);
        pos += cr.getInstruction().getSize(dc);
      }
      insertInstruction(cr.getEnclosingMethodDef(), pos, dc.getLocalVariableTable(), cr.getEnclosingMethodDef().getMethod().getAttributes().getCode().getCode());
    }

  }
View Full Code Here

TOP

Related Classes of net.sf.rej.java.instruction.DecompilationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.