Help reading java bytecode

I need read java bytecode to understand the structure of a class. I need know the variable and the method of a class.
I do this using the library javassist. I would like to know wich method are called inside a method. I think I should interpratate the javabytecode. Is it technical possible do this? Any idea o useful link to read?
Edited by: orsvon on Sep 10, 2010 5:02 AM

Thanks for your useful link!
I get the method called inside a method using javap -c ClassFileName. Then I parse the output looking for the instraction invokevirtual.
Is there a clen way to do this?

Similar Messages

  • HT3633 I have an error message that reads: java.lang.noclassdefFounder - need to fix can anyone help?

    I have an error message that reads: java.lang.noclassdefFounder - need to fix can anyone help?

    That's a bug in whatever Java program you're running.
    That's not an error specific to OS X.
    (There's usually a whole lot more text dumped by Java, too.)
    Check with whoever wrote or is supporting the package you're working with.

  • Java Bytecode error

    I am programming a program in Java Bytecode as an assignment. I am using Jasmin to compile the code.
    My program generates a random int between 0-1000 then converts that number into a string that is the binary equivalent of that number, then prints it out.
    I am getting an error though and I am not sure what the error means, or where the error is happening...so I heard the people here on the java forums can be very helpful so I decided to see if you could help me. Any Suggestions?
    Error:
    Exception in thread "main" java.lang.NoClassDefFoundError: java/util at IntToBinary.main(IntToBinary.j)
    .class public IntToBinary
    .super java/lang/Object
    ; standard initializer
    .method public <init>()V
       aload_0
       invokenonvirtual java/lang/Object/<init>()V
       return
    .end method
    .method public static main([Ljava/lang/String;)V
           ; set limits used by this method
           .limit locals 4
           .limit stack 4
           ;generates a Printsteam and stores it
           getstatic java/lang/System/out Ljava/io/PrintStream;
           astore_0
           ;Generates a Random Object
           getstatic     java/util/Random Ljava/util/Random;
           ;Push 1001 on stack, cause we only want numbers inbetween 0-1000
           sipush 1001
           ;This now gets me a random integer between 0-1000
           invokevirtual     java/util/Random.nextInt(I)I
           ;This takes in the int and puts out the binary equivalent in a string
           invokestatic     java/lang/Integer/toBinaryString(I)Ljava/lang/String;
           ;These are the methods/variables to print our result off
           astore_3
           aload_0    ; push the PrintStream object
           aload_3    ; push the string we just created - then ...
           invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
           ; done
           return
    .end method

           ;Generates a Random Object
           getstatic     java/util/Random Ljava/util/Random;The comment's wrong. It doesn't generate anything. Instead it tries to get the field Random from the class java.util - hence the error you're seeing.

  • Comments inside java bytecode

    I have heard rumors of a way to add a comment block inside java bytecode. Can anyone point me to a reference that spells this out more clearly?

    Thanks for the help Owen.
    I'd like to add comments to bytecode so that I can create add annotations than an extended java bytecode typechecker can check. See SafeJava
    http://www.eecs.umich.edu/~bchandra/publications/phd.pdf
    Can you tell me more about using the CODE attribute?
    I'm sure they're talking about java source code, not
    byte code.
    Java bytecode is a strict list of approx 200 byte
    code instructions.
    What you "might" be able to do (but only you could
    read them) is to create your own "custom attribute"
    attached to a CODE attribute in the Java class file.
    The VM ignores any attributes it doesn't recognise.
    So, if you write your own dissassembler, it would
    recognise the custom attributes. But I don't see
    what this would accomplish for you....
    Why would you want comments in byte code ? ( the
    class file )
    It would only help people greatly to reverse engineer
    and decompile your code.
    regards,
    Owen

  • Java ByteCode

    Hi guys,
    I have some questions about java bytecode..
    1-java bytecode is cointained in the .Class file,that is autogenerated by Ecliplse(the ide I'm using) or by javac.
    I need to extract the bytecode from a .class file,and actually I'm using this piece of code :          //leggo il codice dal file java e lo memorizzo come byte
              file=new File(path);
              InputStream is;
              try {
                   is = new FileInputStream(file);
                   long length = file.length();// Get the size of the file
                   // You cannot create an array using a long type.
                   // It needs to be an int type.
                   // Before converting to an int type, check
                   // to ensure that file is not larger than Integer.MAX_VALUE.
                   if (length > Integer.MAX_VALUE) {
                        // File is too large
                   // Create the byte array to hold the data
                   dati = new byte[(int)length];
                   // Read in the bytes
                   int offset = 0;
                   int numRead = 0;
                   while (offset < dati.length
                             && (numRead=is.read(dati, offset,dati.length-offset))>=0) {
                        offset += numRead;
                   // Ensure all the bytes have been read in
                   if (offset < dati.length) {
                        throw new IOException("Could not completely read file "+file.getName());
                   // Close the input stream and return bytes
                   is.close(); Is it right?(I think so..)
    2-Then my program will serialize and send through TCP socket the bytes loaded from the .class.The receiver need to create an instance of the .class received...how do I do this...(note that I know the name of the class)?
    Thanks a lot guys...BYE!--JAVA ROCKS

    1. Looks okay.
    2. Create a suitable subclass of ClassLoader. The API doc for it is reasonable helpful.

  • XI Mail Adapter: sending emails with attachment with help of java mapping

    Hi ,
    On trying out the scenerio mentioned in the blog, using the java mapping provided
    "XI Mail Adapter: An approach for sending emails with attachment with help of Java mapping
    The scenerio works just fine.
    But the payload as the content of the attachment is not getting generated in proper XML format.
    I suppose it's because of the replace special characters code part..
    Can anyone help me state the modification required in the code.
    Thanks!
    Regards,
    Faria Mithani

    It might be a codepage issue. Is your original payload UTF-8?

  • Please help with Java program

    Errors driving me crazy! although compiles fine
    I am working on a project for an online class - I am teaching myself really! My last assignment I cannot get to work. I had a friend who "knows" what he is doing help me. Well that didn't work out too well, my class is a beginner and he put stuff in that I never used yet. I am using Jgrasp and Eclipse. I really am trying but, there really is no teacher with this online class. I can't get questions answered in time and stuff goes past due. I am getting this error:
    Exception in thread "main" java.lang.NullPointerException
    at java.io.Reader.<init>(Reader.java:61)
    at java.io.InputStreamReader.<init>(InputStreamReader .java:55)
    at java.util.Scanner.<init>(Scanner.java:590)
    at ttest.main(ttest.java:54)
    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.
    This is my code:
    import java.util.*;
    import java.io.*;
    public class ttest
    static Scanner console = new Scanner(System.in);
    public static void main(String[] args)throws IOException
    FileInputStream fin = null; // input file reference
    PrintStream floser = null; // output file references
    PrintStream fwinner = null;
    Scanner rs; // record scanner
    Scanner ls; // line scanner
    String inputrec; // full record buffer
    int wins; // data read from each record
    int losses;
    double pctg;
    String team;
    String best = null; // track best/worst team(s)
    String worst = null;
    double worst_pctg = 2.0; // track best/worst pctgs
    double best_pctg = -1.0;
    int winner_count = 0; // counters for winning/losing records
    int loser_count = 0;
    // should check args.length and if not == 1 generate error
    try
    Scanner inFile = new Scanner(new FileReader("football.txt"));
    catch( FileNotFoundException e )
    System.exit( 1 );
    try
    floser = new PrintStream( new FileOutputStream( "loser.txt" ) );
    fwinner = new PrintStream( new FileOutputStream( "winner.txt" ) );
    catch( FileNotFoundException e )
    System.out.printf( "unable to open an output file: %s\n", e.toString() );
    System.exit( 1 );
    try
    rs = new Scanner( fin );
    while( rs.hasNext( ) )
    inputrec = rs.nextLine( ); /* read next line */
    ls = new Scanner( inputrec ); /* prevents stumble if record has more than expected */
    team = ls.next( );
    wins = ls.nextInt();
    losses = ls.nextInt();
    if( wins + losses > 0 )
    pctg = ((double) wins)/(wins + losses);
    else
    pctg = 0.0;
    if( pctg > .5 )
    if( pctg > best_pctg )
    best_pctg = pctg;
    best = team;
    else
    if( pctg == best_pctg )
    best += ", " + team;
    fwinner.printf( "%10s %2d %2d %5.3f\n", team, wins, losses, pctg );
    winner_count++;
    else
    if( pctg < worst_pctg )
    worst_pctg = pctg;
    worst = team;
    else
    if( pctg == worst_pctg )
    worst += ", " + team;
    floser.printf( "%10s %2d %2d %5.3f\n", team, wins, losses, pctg );
    loser_count++;
    fin.close( );
    floser.close( );
    fwinner.close( );
    catch( IOException e ) {
    System.out.printf( "I/O error: %s\n", e.toString() );
    System.exit( 1 );
    System.out.printf( "%d teams have winning records; %d teams have losing records\n", winner_count, loser_count );
    System.out.printf( "Team(s) with best percentage: %5.3f %s\n", best_pctg, best );
    System.out.printf( "Team(s) with worst percentage: %5.3f %s\n", worst_pctg, worst );
    The assignment is:
    Create a Java program to read in an unknown number of lines from a data file. You will need to create the data file. The contents of the file can be found at the bottom of this document. This file contains a football team's name, the number of games they have won, and the number of games they have lost.
    Your program should accomplish the following tasks:
    1. Process all data until it reaches the end-of-file. Calculate the win percentage for each team.
    2. Output to a file ("top.txt") a listing of all teams with a win percentage greater than .500. This file should contain the team name and the win percentage.
    3. Output to a file ("bottom.txt") a listing of all teams with a win percentage of .500 or lower. This file should contain the team name and the win percentage.
    4. Count and print to the screen the number of teams with a record greater then .500 and the number of teams with a record of .500 and below, each appropriately labeled.
    5. Output in a message box: the team with the highest win percentage and the team with the lowest win percentage, each appropriately labeled. If there is a tie for the highest win percentage or a tie for the lowest win percentage, you must output all of the teams.
    Dallas 5 2
    Philadelphia 4 3
    Washington 3 4
    NY_Giants 3 4
    Minnesota 6 1
    Green_Bay 3 4

    import java.util.*;
    import java.io.*;
    public class ttest
    static Scanner console = new Scanner(System.in);
    public static void main(String[] args)throws IOException
    FileInputStream fin = null; // input file reference
    PrintStream floser = null; // output file references
    PrintStream fwinner = null;
    Scanner rs; // record scanner
    Scanner ls; // line scanner
    String inputrec; // full record buffer
    int wins; // data read from each record
    int losses;
    double pctg;
    String team;
    String best = null; // track best/worst team(s)
    String worst = null;
    double worst_pctg = 2.0; // track best/worst pctgs
    double best_pctg = -1.0;
    int winner_count = 0; // counters for winning/losing records
    int loser_count = 0;
    // should check args.length and if not == 1 generate error
    try
    Scanner inFile = new Scanner(new FileReader("football.txt"));
    catch( FileNotFoundException e )
    System.exit( 1 );
    try
    floser = new PrintStream( new FileOutputStream( "loser.txt" ) );
    fwinner = new PrintStream( new FileOutputStream( "winner.txt" ) );
    catch( FileNotFoundException e )
    System.out.printf( "unable to open an output file: %s\n", e.toString() );
    System.exit( 1 );
    try
    rs = new Scanner( fin );
    while( rs.hasNext( ) )
    inputrec = rs.nextLine( ); /* read next line */
    ls = new Scanner( inputrec ); /* prevents stumble if record has more than expected */
    team = ls.next( );
    wins = ls.nextInt();
    losses = ls.nextInt();
    if( wins + losses > 0 )
    pctg = ((double) wins)/(wins + losses);
    else
    pctg = 0.0;
    if( pctg > .5 )
    if( pctg > best_pctg )
    best_pctg = pctg;
    best = team;
    else
    if( pctg == best_pctg )
    best += ", " + team;
    fwinner.printf( "%10s %2d %2d %5.3f\n", team, wins, losses, pctg );
    winner_count++;
    else
    if( pctg < worst_pctg )
    worst_pctg = pctg;
    worst = team;
    else
    if( pctg == worst_pctg )
    worst += ", " + team;
    floser.printf( "%10s %2d %2d %5.3f\n", team, wins, losses, pctg );
    loser_count++;
    fin.close( );
    floser.close( );
    fwinner.close( );
    catch( IOException e ) {
    System.out.printf( "I/O error: %s\n", e.toString() );
    System.exit( 1 );
    System.out.printf( "%d teams have winning records; %d teams have losing records\n", winner_count, loser_count );
    System.out.printf( "Team(s) with best percentage: %5.3f %s\n", best_pctg, best );
    System.out.printf( "Team(s) with worst percentage: %5.3f %s\n", worst_pctg, worst );
    }

  • Need help in java.security, please............

    I need to implement encryption in my java card.
    My sdk is v.2.2.1.
    At first, I just write a easy code and test adpu command in jcwde and it works well. (response 90)
    But every time when I trying to put
    desKey = (DESKey)KeyBuilder.buildKey (KeyBuilder.TYPE_DES,KeyBuilder.LENGTH_DES,false);"
    into procedure, the response becomes 6444, which means install error.
    Some people said in the forum that javacard.security only provide key interface, but is it the same in v2.2.1? If it is,then what's the function of KeyBuilder?
    Below is a part of my code.
    private SimCipher(byte[] bArray, short bOffset, byte bLength)
         desKey = (DESKey)KeyBuilder.buildKey (KeyBuilder.TYPE_DES,KeyBuilder.LENGTH_DES,false);
              register();

    Thank you for your reply. Actually, I was trying to implement AES in smart card, and I decide to write it myself. It is sucessed.
    Thank you again for your help.

  • Needed help on java script and html in PL/SQL doing nothing

    Hi,
    Created a procedure which takes username and password and changes OID, database password for that user with that password.
    I created a page in oracle portal and trying to call this below script package:
    BEGIN
    user_name := portal.wwctx_api.get_user;
    HTP.p
         <!-- BEGIN CODE FRAGMENT -->
         <script language="javascript">
         <!--
         function ValidatePass()
         var passStr = document.getElementByid("p_password").value;
         var confPassStr = document.getElementByid("Confirm_Password").value;
              var pattern = /[^a-zA-Z0-9]/;
              if (passStr == null || passStr == "") {
                   alert("Password value missing");
                   return;
              if (confPassStr == null || confPassStr == "") {
                   alert("Confirm password value missing");
                   return;
              if (passStr.match(pattern) == null && confPassStr.match(pattern) == null) {
                   if (passStr == confPassStr) {
                        document.form.submit();
                   } else {
                        alert("Your entries did not match. Please try again!");
              } else {
                   alert("Invalid charcters entered");
         //-->
         </script>
         <form name="changepassword"
         action="http://<hostname>:7777/pls/sys/sys.gx_user_mgt.globally_update_password"
              method="post" AutoComplete="Off">
    <input type="hidden" name="username" value=" '
    || user_name
    || ' " id="p_username"/>
    New Password:
    <input type="password" name="p_password" id="p_password">
    <br>
    <br>
    Confirm Password:
    <input type="password" name="Confirm_Password" id="Confirm_Password">
    <br>
    <br>
    <input style="padding:2px;" type="submit" value=Login onClick="ValidatePass();">
    </form>
    END;
    This gx_user_mgt.globally_update_password is the custom procedure I should call passing username and p_password
    Thanks in advance.

    Friends I want to try something but I am totally lost on how to achieve it.Just to let u know that I have not worked in JAVASCRPT at all.And I am in great hurry to finish this work.
    What I am looking for is :
    1) a JSP page is thrown
    2) a button is clicked
    3)Moment the button is clicked I want a file to be created with an extension HTML (having all the info from the database) by using FileWriter class .After the file is created and ready ,Then I want to open this file in another browser window.
    I know that to achieve this I have to use Javascript,but I am totally lost on how to do that.
    I mean can I say in JAVASCRIPT that if this button is clicked then execute a java method which retrives data from the oracle database in the server and writes it to a HTML file and then after the writing is done,open it another window.
    Please help.

  • Call Oracle Help for Java in Oracle forms running in the web

    Hi, everyone,
    We are developing a web-enabled Oracle database application
    system. Oracle suggested us to use Oracle Help for Java(OHJ) to
    create an online help system for the web environment. We
    successfully created a OHJ program which can be independently.
    But we still have no idea how to call this OHJ program from the
    forms running in the web environment.
    Could anyone help us out?
    Thanks.
    null

    I would like to know if anyone has been able to do this too. Could someone respond if they have successfully gotten this to work?
    Thanks!!

  • Rename exported file in ODI with help of Java

    Hi.
    We have to implement new scenarios into execution repository. I marked scenarios and I exported them with help of procedure:
    OdiExportScen "-SCEN_NAME=#scen_name" "-SCEN_VERSION=-1" "-FILE_NAME=#DEP_EXPORT_DIRECTORY\SCEN_#SCEN_NAME 001.xml" "-FORCE_OVERWRITE=YES" "-RECURSIVE_EXPORT=YES" "-XML_VERSION=1.0" "-XML_CHARSET=windows-1251" "-JAVA_CHARSET=cp1251"
    But I have to put space between variable #SCEN_NAME and another part of file name. After export I want to rename file with help of Java script, but I get an error when I try to read list of files.
    import java.io.*;
    public class RenameFiles
         public static void main(String[] args)
              String dirPath = new String ("D:\\ODI");
              File dir = new File(dirPath);
              String dirList[] = dir.list(); /* I get error there*/
              for(int i=0; i<dirList.length; i++)
                   File oldFileName = new File(dirPath+"\\"+dirList);
                   File newFileName = new File(dirPath+"\\"+dirList[i].replaceAll(" ","_"));
                   oldFileName.renameTo(newFileName);
    Error in ODI Operator looks like:
    org.apache.bsf.BSFException: BeanShell script error: Parse error at line 9, column 31. Encountered: [ BSF info: Rem at line: 0 column: columnNo
         at bsh.util.BeanShellBSFEngine.eval(Unknown Source)
         at bsh.util.BeanShellBSFEngine.exec(Unknown Source)
         at com.sunopsis.dwg.codeinterpretor.k.a(k.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.scripting(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSqlS.treatTaskTrt(SnpSessTaskSqlS.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand(DwgCommandSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
         at com.sunopsis.dwg.cmd.e.k(e.java)
         at com.sunopsis.dwg.cmd.g.A(g.java)
         at com.sunopsis.dwg.cmd.e.run(e.java)
         at java.lang.Thread.run(Thread.java:662)

    I fixed it.
    All I need - put slashes at end of directory name. Also I removed implementation of class.
    import java.io.*;
    String dirPath = new String ("D:\\ODI");
    File dir = new File(dirPath+"\\");                // I put \\ at the end of directory name
    String[] dirList = dir.list();
    for(int i=0; i<dirList.length; i++)
         File oldFileName = new File(dirPath+"\\"+dirList);
         File newFileName = new File(dirPath+"\\"+dirList[i].replaceAll(" ","_"));
         oldFileName.renameTo(newFileName);
    Edited by: user12281180 on Apr 14, 2011 7:44 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Oracle Help for Java 4.2.0 and 4.1.17

    Attention to all: Oracle Help for Java 4.2.0 and 4.1.17 are now available for download at
    http://otn.oracle.com/software/tech/java/help/content.html
    OHJ 4.2.0 features a new Ice Browser and enhancements related to the known modal dialog problem. It requires JDK 1.3 and is a recommended upgrade for all clients using JDK 1.3 or higher.

    4.1.17 appears to work correctly with RoboHelp.
    4.2 gives an error when attempting to generate fts.idx via RoboHelp.

  • Where to learn about the java bytecode?

    I want to learn the JAVA bytecode. Where to find information about that?

    The list of opcodes, list of data types, and how to use them is here:
    http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html
    I personally use BCEL to manipulate class files.
    http://jakarta.apache.org/bcel/
    Some report they prefer Soot.
    http://www.sable.mcgill.ca/soot/

  • "quick Look Helper (32bit)" java se6 runtime

    hi everyone, i have just upgraded to Mountain Lion, everything is working as it was before, EXCEPT when i visit the Apple Store i keep getting this window pop up, i dont understand what it is all about, but so far i have always declined to Install it, because i can still do exactly what i wanted to do, which was download, uncompress and install an App
    so why do i keep getting this pop up ?, is it harmfull ?, i understand that JAVA is dodgy and should be avoided !!!.
    tim

    Mr. Toad,
    In fact, the issue with Java is NOT a load of hype. You are best advised to disable it if you do not have an urgent requirement to use it. There are legitimate exploits in the wild, and recent patches to Java have not resolved all of the security concerns. Best to wait...
    As for your Quicklook issue, I suspect you have (or had) some 32-bit Quicklook Plugins in your plugins folder
    (/Users/"your user name"/Library/QuickLook/)
    If you go there and select a plugin and choose "Get Info" from the file menu, you will see in the "General" section near the top of the window "Kind" followed by "Quick Look Generator (32-bit)" if the plugin is actually 32-bit.
    In my case, I had some animated GIF files in a folder and an old 32-bit animated GIF quicklook plugin. Once I deleted the plugin, the problem went away.
    Realize this reply is long after your post and hopefully you resolved your issue. If not, this should help.

  • Migrating from JavaHelp to Oracle Help for Java

    Currently we have a product in which we have implemented Sun Microsystem's JavaHelp as the Help delivery system. However, after evaluating Oracle Help for Java we would like to migrate from Javahelp to OHJ.
    My question is, how difficult would this migration be from the Development side? I have been reviewing the Oracle Help for Java Developer's Guide and comparing it against the JavaHelp documentation but I haven't been able to get a clear idea of how different the implementation is.
    Thanks,
    Theresa

    Hello Theresa,
    Thanks for considering Oracle Help.
    There isn't much you have to do with your source content and control files. With the exception of the full text search index, the Oracle Help control file formats (helpset, index, map, etc.) extend the JavaHelp formats. So you can use the JavaHelp control files as is, or you can extend them with the Oracle Help extensions. For a quick overview of differences, see the following page in the Oracle Help Guide:
    1. Go to http://otn.oracle.com/ohguide/help/.
    2. Click "Oracle Help File Formats."
    3. Click "Comparision to Javahelp File Formats."
    To create an Oracle Help full text search index, run through the Helpset Authoring Wizard and remove the existing JavaHelp search view and have the wizard generate an Oracle Help Search index
    on the following wizard page. For the Helpset Authoring Wizard doc:
    1. Go to http://otn.oracle.com/ohguide/help/.
    2. Click "Authoring Oracle Help Systems."
    3. Click "Using the HelpSet Authoring Wizard."
    Alternatively, change the helpset file by hand. For the doc:
    1. Go to http://otn.oracle.com/ohguide/help/.
    2. Click "Oracle Help File Formats."
    3. Click "Helpset File."
    Then run the indexer. For doc:
    1. Go to http://otn.oracle.com/ohguide/help/.
    2. Click "Authoring Oracle Help Systems."
    3. Click "Using the Full-text Search Indexer."
    On the development side, the APIs are different, but they are also very
    simple. You create a Help object, add HelpSets, and associate topic-ids
    with java UI components using the CSHManager as described in the
    Oracle Help Guide:
    1. Go to http://otn.oracle.com/ohguide/help/.
    2. Click "Oracle Help for Java Developer's Guide."

Maybe you are looking for