Git Product home page Git Product logo

native-intercept's Introduction

NativeIntercept is a small library that uses bytecode generation to instrument classes with native
methods to allow those methods to be handled by java code rather than native code.

Notes:
- This is currently pre-alpha. It's had limited testing and mostly works, but there's probably a lot
  of bugs.
- This requires Java 1.6 or higher. While the Java agent functionality was available in Java 1.5,
  this library uses the Instrumentation#setNativePrefix method which was added in 1.6.
- This library uses the excellent ASM bytecode manipulation library. That project can be found at:
  http://asm.ow2.org
  This also uses the JarJar library to package the version of asm that's expected in the
  distribution jar without conflicting with another version of the library that may be on the
  classpath. That project can be found at: http://code.google.com/p/jarjar/

native-intercept's People

Forkers

chenyiliang

native-intercept's Issues

How To ??

Hello,

Can anyone please put a guide how to use the native-intercept ?

Thanks

Original issue reported on code.google.com by [email protected] on 12 Jun 2012 at 3:15

int native parameter causes exception

What steps will reproduce the problem?
1. Create class with "native void someMethod(int x)".
2. Intercept native calls for the class from #1.
3. Invoke someMethod().


What is the expected output? What do you see instead?
Expected to have InvocationHandler invoked for the method. I got an
exception instead:

Exception in thread "main" java.lang.IllegalStateException: Unexpected
exception thrown in interceptor
    at com.google.nativeproxy.ContainsNative.nativeMethod_V_I(ContainsNative.java)
    at com.google.nativeproxy.NpDemo.run(NpDemo.java:27)
    at com.google.nativeproxy.NpDemo.main(NpDemo.java:34)
Caused by: java.lang.NoClassDefFoundError: I
    ... 3 more
Caused by: java.lang.ClassNotFoundException: I
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
    ... 3 more

What version of the product are you using? On what operating system?
0.1.1-pre-alpha

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 27 Jul 2009 at 11:19

IllegalStateException when invoking a native declared in a superclass.

What steps will reproduce the problem?
1. Subclass a class declaring a native.
2. Invoke the native through the subclass.
3.

What is the expected output? What do you see instead?
Expected to have InvocationHandler invoked for native method. Got an
exception instead:

java.lang.IllegalStateException: Attempt to intercept non-existent native
method
    at org.synth.intercept.NativeInvocationHandler.findMethod(Unknown Source)
    at org.synth.intercept.NativeInvocationHandler.handleObject(Unknown Source)
...

What version of the product are you using? On what operating system?
0.1.1 prealpha

Please provide any additional information below.
It looks like NativeInvocationHandler.findMethod should keep looking at
parent classes if it can't find a declared method.

Original issue reported on code.google.com by [email protected] on 27 Jul 2009 at 11:26

HasNative annotation and "check documentation" IllegalStateException

Hello,

this is my test program:

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import org.synth.intercept.NativeInterceptor;
public class Test {
    public static void main(String[] args) throws ClassNotFoundException {
        NativeInterceptor.intercept(Class.forName("java.net.PlainSocketImpl"),
                new MyInvocationHandler());
    }
    static class MyInvocationHandler implements InvocationHandler {
        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            System.out.println("Proxy: " + proxy + "\nMethod: " + method + "\n");
            return null;
        }
    }
}

and this is how I'm invoking it (CLASSPATH is set, tools.jar is added too):

java -javaagent:../lib/native-interceptor-0.1.3-alpha.jar Test

However I get following exception:

Exception in thread "main" java.lang.IllegalStateException: Cannot instrument 
class to intercept native methods...see documentation for causes
    at org.synth.intercept.NativeInterceptor.intercept(NativeInterceptor.java:58)
    at org.synth.intercept.NativeInterceptor.intercept(NativeInterceptor.java:29)
    at Test.main(Test.java:13)

I checked the code (from SVN, not sure if it's same as in 0.1.3-alpha) and this 
exception is thrown if following check fails:

if (type.getAnnotation(HasNatives.class) == null)
    throw new ...

Is it neccessary to use @HasNative annotation?

Thank you.

Original issue reported on code.google.com by [email protected] on 8 Jun 2011 at 3:52

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.