Giter Site home page Giter Site logo

sgodbillon / bytecodeparser Goto Github PK

View Code? Open in Web Editor NEW
41.0 4.0 10.0 1.74 MB

A Java library to parse JVM bytecode, simulate the stack and extract as much information as possible

Home Page: http://sgodbillon.github.com/BytecodeParser/

License: Other

CSS 0.83% Java 99.17%

bytecodeparser's Introduction

BytecodeParser

BytecodeParser is a java library that can help you statically to parse java bytecode by extracting as much information as possible. It is based upon javassist.

It can also statically analyze each method’s frame, for particular purposes like retrieving the names of the local variable names given as parameters of a method call (its original purpose), check if all the frames are reachable, etc.

BytecodeParser simulates the stack operations made by the opcodes in the CodeAttribute. It can give you the state of the stack before and after the frame is run.

BytecodeParser is released under the LGPL, version 3. It is actively developped. You can download the latest version (v0.3), explore its capabilities and extend it if you need to.

How to use it

See the project’s website for detailed examples and more information. You can also browse the API.

A small example

ClassPool cp = new ClassPool();
CtClass ctClass = cp.getCtClass("org.myapp.MyClass");
for(CtMethod method: ctClass.getMethods()) {
    StackAnalyzer stackAnalyzer = new StackAnalyzer(method);
    for(Frame frame: stackAnalyzer.analyze()) {
        // you can get the state of the stack before or after this frame with frame.stackBefore and frame.stackAfter
        System.out.println(frame.stackBefore + " => " + frame.stackAfter);
        // you can also get some extended information about this frame with frame.decodedOp
        if(frame.decodedOp instanceof DecodedMethodInvocationOp) {
            DecodedMethodInvocationOp dmio = (DecodedMethodInvocationOp) frame.decodedOp;
            MethodParams methodParams = DecodedMethodInvocationOp.resolveParameters(frame);
            MethodParam[] params = methodParams.merge();
            System.out.println("method '" + dmio.getName() + "' has been called with the following arguments: " + java.util.Arrays.toString(params));
        }
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.