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 7604601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:57:12+00:00 2026-05-30T23:57:12+00:00

I am trying to analyse byte code with javassist using simple class MyData :

  • 0

I am trying to analyse byte code with javassist using simple class MyData:

class MyData {
    private Collection<String> strings = new ArrayList<String>();

        // .....................    
    public void add(String str) {
        strings.add(str); // line number 35
    }
        // .....................    
}

Here is the code I am running against this class:

ClassFile cf = new ClassFile(new DataInputStream(TryJavassist.class.getResourceAsStream("MyData.class")));
MethodInfo minfo = cf.getMethod("add");  
CodeAttribute ca = minfo.getCodeAttribute();
for (CodeIterator ci = ca.iterator(); ci.hasNext();) {
    int index = ci.next();
    int op = ci.byteAt(index);

    System.out.println(op + "=" + Mnemonic.OPCODE[op] + ": " + minfo.getLineNumber(index));
}

It works and prints:

42=aload_0: 35
180=getfield: 35
43=aload_1: 35
185=invokeinterface: 35
87=pop: 35
177=return: 36

Line 35 invokes method add() of collection named strings.
The code snippet I posted retrieves only invokeinterface and line 35. OK, I can know that it was class field (getfield).

I would like to know how to get the rest of information:

  • the field name is strings
  • the interface method being called is add()

Neither googling nor reading API doc have not given any positive result so far.

  • 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-05-30T23:57:13+00:00Added an answer on May 30, 2026 at 11:57 pm

    It is hard work, needing an understanding of the JVM class format and instruction set.
    Any answer can only give partial data. Especially with Javassist. In the instruction typically one parameter is an index in the constant pool, where there is an object with an index to a name, and an index to a type. So be aware of what you are getting into.

    If the class is compiled with debugging info, the private field names are accessible (ClassFile.getFields).

    There is a nice Dump tool packed with javassist.

    private void dumpMyDataClass() throws IOException, BadBytecode, Exception {
        ClassFile cf = new ClassFile(new DataInputStream(getClass().getResourceAsStream("MyData.class")));
    
        // Dump fields:
        for (Object fieldInfoObj : cf.getFields()) {
            FieldInfo fieldInfo = (FieldInfo) fieldInfoObj;
            System.out.printf("Field %s; %s%n", fieldInfo.getName(), fieldInfo.getDescriptor());
        }
    
        MethodInfo minfo = cf.getMethod("add");
        CodeAttribute ca = minfo.getCodeAttribute();
        for (CodeIterator ci = ca.iterator(); ci.hasNext();) {
            int address = ci.next();
            int op = ci.byteAt(address);
    
            String params = "";
            switch (op) {
                case Opcode.INVOKEINTERFACE:
                    int a1 = ci.s16bitAt(address + 1);
                    params += " " + cf.getConstPool().getInterfaceMethodrefName(a1);
                    System.out.println("a1 = " + a1);
                    break;
            }
    
            System.out.printf("Line %4d. Address %7d: %s%s%n", minfo.getLineNumber(address), address, Mnemonic.OPCODE[op], params);
        }
    
        // Command line tool of javassist:
        String pathToClass = System.getProperty("user.dir") + "/target/classes/jeggen/test2/MyData.class";
        Dump.main(new String[] { pathToClass });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to analyse some code here that's been designed using an MVP Approach.
I am trying to analyse the following code in assembly. sub $48, %esp mov
I'm trying to analyse some code (not written by myself) which calls readlink with
I am trying to analyse a site using Jmeter. My plan includes a HTTPS
I've just started using NDepend and am trying to analyse a solution. This warning
I am trying to analyse the IIS log and would like to look at
I'm running python2.5 and trying to use the astLib library to analyse WCS information
I am trying to analyze my agent results from a collection of 20 txt
Using java I am trying to develop a method using recursion to analyze a
I am trying to manipulate an image using a chain of CIFilters, and then

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.