Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:39:56+00:00 2026-06-12T02:39:56+00:00

With Javassist, is there any way to inject code into a native method? In

  • 0

With Javassist, is there any way to inject code into a native method? In this case, I’m trying to make the OpenGL calls in my game print out their names and values when called, but all my attempts have hit errors when I assume the openGL dll code is added.

The method would look something like:

public static native void glEnable(int paramInt);

Since the methods initially have no body, the only way I’ve found to actually add the code is with something like:

CtBehavior method = cl.getDeclaredBehaviors()[0];
method.setBody("System.out.println(\"Called.\");");

The injection itself works, but then the system fails once the library is loaded saying that the method already has code.

I’d rather not use any premade tools for the call tracking, because of the way I need to format and print out the list for the user. Is there any way to handle this?
If not, is there some way to find all calls to an OpenGL method within another class and append an additional call to a tracker class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:39:58+00:00Added an answer on June 12, 2026 at 2:39 am
    With Javassist, is there any way to inject code into a native method?
    

    Never tried it, but I am not surprised it does not work. Native code is – native. It’s a bunch of platform specific bits that bears no relation to Java byte code. And Javassist is all about Java byte code.

    Have you consider using proxy based AOP? Check out http://static.springsource.org/spring/docs/current/spring-framework-reference/html/aop.html#aop-understanding-aop-proxies

    I’m not recommending you actually use Spring in your program but it might give you some ideas on how to approach the problem. The reason I think proxy-based AOP might work for you is that you leave your OpenGL based class alone and it just uses the normal native methods. You generate a proxy class which is pure Java but has the same methods as your original class. You call methods on the proxy class which contain the desired call tracking code, plus the invocation of the corresponding method on the “plain object” with it’s native methods.

    The documentation in Spring says they use JDK dynamic proxies or CGLIB under the covers. So … I’m thinking that you could use one of these technologies directly as a replacement for your javassist solution.

    Hope this helps.

    [update]

    In the text above I thought you were talking about a class written by you which had primarily instance methods. If you are talking about wrapping the entire OpenGL API, which is primarily static methods, then the AOP proxy method is less appealing. How bad do you want to do this? You could:

    • create a custom class – a singleton class with a factory method. Your singleton class wraps the entire OpenGL API. No logging/tracking code. Just naked calls to the API.
    • modify every single call in your entire app to use your wrapper, instead of calling OpenGL directly

    At this point you have an application that works exactly like what you have now.

    Now enhance the factory method of your singleton class to return either the bare-bones instance which does nothing except OpenGL calls, or it can return a CGLIB generated proxy which logs every method. Now your app can run in either production mode (fast) or tracking mode depending on some config setting.

    And I totally get it if you want to give this up and move on 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to perform client side form validation when JavasSript is disabled
Is there any way to set a default width for a group of divs,
I created a constructor with Javassist which has no real method CtConstructor c =
I'm trying to use JPF to verify my bytecode generated while runtime with javassist.
I have some VBA code that opens a webpage, then calls a javascript function
I am following this tutorial using eclipse EE : hibernate-tutorial-for-begin . There are the
Is there a way to create a click event(or effect) that repeat the last
What I am going to describe is a bit of legacy code. So there
I am trying to add cglib as default byte code provider. I am using
I am trying to code a multiplayer game demo in javascipt using no libraries.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.