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

Similar Messages

  • 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.

  • 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?

  • How to read XKOMV-EDATU, XKOMV-KBETR fields inside java

    How do get the 
    XKOMV-EDATU date and pass it to ItemUserExit.java for database read and filtering.
    a. The code in ItemUserExit has to filter ZCPI2-ZSPMON for this date XKOMV-EDATU, the delivery date.
    This does not work. prItem.getPricingTimestamp returns the current date always, NOT delivery date.
    What is the method call that will grab this date.?
    b. How do I have to pass this XKOMV-EDATU date to ItemUserExit.java for database read / filtering.
    c. The field XKOMV-KBETR has to be read based on the KSCHL = ‘ZCP1’ and / or KSCHL =’PR00’.
    These are abap structures. But I am not sure how to read this value inside java.
    How would I extract the structure XKOMV-KBETR(the rate) for KBETR(conditionType)=’PR00’ .
    Please note that I get an error mandatory condition PR00 is missing. (see attached error message ).
    d. “CPIW_A” set up in ItemUserExit.java :: itemUserExitAccess.addItemAttributeBinding("CPIW_A", ZVALUE_CPIW_A );
    is NOT available at PricingUserExits.java with the code:
    prItem.getItemAttributeBinding("CPIW_A") ,
    though they are registered in the method
    “determineRelevantAttributesForValueFormula” as per the help html pages.
    I had attached the code.
    Can you scan thru the code and give feedback.
    Can I call you in the morning.
    Thanks.
    TK
    PS:
    I get an error “PR00” mandatory condition is missing from the log file.
    ======
    OP="ChangeDocument" ID="34800003" STATUS="200" />objectIds[1]=07F9101FD1D0AD4686B2411E3EFB2DF1&messageTypes[1]=E&messages[1]=Pricing error: Mandatory condition PR00 is missing&areas[1]=SPE&numbers[1]=801&args1[1]=PR00&args2[1]=&args3[1]=&args4[1]=Nov 11, 2005 12:41:37... ...p.sxe.socket.server.rfc.RFCConnection JCO.ServerThread-3 Info: response time of command C
    However, I get the response header as:
    availableItemConditionTypeNames[1]=PR00&availableItemConditionTypeNames[2]=VA00&availableItemConditionTypeNames[3]=ZA00&availableItemConditionTypeNames[4]=ZOUT&availableItemConditionTypeNames[5]=ZCRT&availableItemConditionTypeNames[6]=K004&availableItemConditionTypeNames[7]=RA01&availableItemConditionTypeNames[8]=RB00&availableItemConditionTypeNames[9]=ZB00&availableH
    CODE:
    ItemUserExit.java snippet:
              qrypair2[0]  = new sys_query_pair("ZCPI", <b>"200501"</b>, sys_query_pair.GREATER); //
              projection = new String[] { "ZCPI" } ;
              sorting = new String[] { "ZCPI" } ;           res resultSet = database.db_read_first_row("ZCPI2", qrypair2, projection, sorting);
    I need to pass the XKOMV-EDATU date field in the above bolded date field.  I think this field is available thru the API for IPricingItemUserExit  inside the overwriteConditionValue method's parameter .
    METHOD
    overwriteConditionValue:
         public BigDecimal overwriteConditionValue(IPricingItemUserExit      prItem,
                                                             ILastPrice                lastPrice,
                                                             IPricingConditionUserExit prCondition,
                                                             int                       valueFormNo) {
              String sold2party = "", strCPIW_A = "", strCPIW_B = "";
              BigDecimal condValue = prCondition.getConditionValue().getValue();
              BigDecimal netValue  = prItem.getNetValue().getValue();
              String prod = (prItem.getProduct()!=null)? prItem.getProduct().toString(): "NULL";
              SAPTimestamp  priceTstamp = prCondition.getConditionFindingTimestamp(); //prItem.getDefaultConditionAccessTimestamp();  //getPricingTimestamp();
              String strTstamp = priceTstamp.formatYYYYMMDD();
              //KOMP-EDATU ??
              logInfo("valueFormNo: " + valueFormNo +  " Condition Table type:"  + prCondition.getConditionTypeName() +
                         ", condVal:" + condValue + ", netValue:" + netValue + ", KOMP-EDATU:" + strTstamp );
              switch (valueFormNo) {
                   case 601:
                             try{
                               sold2party = prItem.getHeaderAttributeBinding("SOLD_TO_PARTY").getValue().getValue();
                               IAttributeBinding iamCPIW_B  = prItem.getItemAttributeBinding("CPIW_B");
                               IAttributeBinding iamCPIW_A  = prItem.getItemAttributeBinding("CPIW_A");
                               if( iamCPIW_A !=null) strCPIW_A = iamCPIW_A.getValue().getValue();
                               if( iamCPIW_B !=null) strCPIW_B = iamCPIW_B.getValue().getValue();
                             }catch(Exception e) {
                                  logInfo("EXCEPTION @ GetAttributeBinding exception : " + e.getMessage());
                             logInfo("sold2party: " + sold2party + " strCPIW_A, strCPIW_B: " + strCPIW_A + ", " + strCPIW_B);
                             String CPIW_A = null, CPIW_B = null, BASE_PRICE = null;
                             logInfo("overwriteConditionValue " +
                                   "_CPIW_A: " + _CPIW_A + ", _CPIW_B: " + _CPIW_B + ", _BASE_PRICE: " + _BASE_PRICE );
                             double l_cpiw_a, l_cpiw_b, l_base;
                             if( _CPIW_A == null || _CPIW_B == null || _BASE_PRICE == null) {
                                  logInfo("overwriteConditionValue *tk* static _CPIW_A.... NULL. returning 999999L" );
                                  return BigDecimal.valueOf( 0L );
                             }else{
                                  l_cpiw_a = Double.valueOf(_CPIW_A).doubleValue();
                                  l_cpiw_b = Double.valueOf(_CPIW_B).doubleValue();
                                  l_base   = Double.valueOf(_BASE_PRICE).doubleValue();
                                  logInfo("overwriteConditionValue *tk* ???? using STATIC Class Variables" );
                             logInfo("overwriteConditionValue " +
                                   "cpiw_a: " + l_cpiw_a + ", l_cpiw_b: " + l_cpiw_b + ", l_base: " + l_base );
                             double fraction = (l_cpiw_a - l_cpiw_b)/l_cpiw_b;
                             logInfo("overwriteConditionValue " +
                                       "*tk* double fraction: " + fraction );                                               
                             double result = l_base * fraction;
                             logInfo("overwriteConditionValue " +
                                       "*tk* double calculated Result: " + result );                       
                             BigDecimal retValue = BigDecimal.valueOf (Math.round(result));
                             condValue = retValue;
                             try{
                                  prCondition.setConditionRate(retValue , "USD");     
                             }catch(Exception convEx){
                                  logInfo("overwriteConditionValue " +
                                                           "*tk* converstion Rate Exception " + retValue );
                             prItem.setObjectForUserExits("XKOMV_KBETR_C", retValue);
                             logInfo("overwriteConditionValue: 601 conditionRate Return Value: " + retValue );
                             return retValue;
                   case 602:
                             /* Forecasted CPI-W value = ( ( D * ( ( A – B ) / B ) )  – ( D + C ) ) */
                        double A = Double.valueOf( PricingUserExits.ZCPI2_ZCPI ).doubleValue();
                        double B = Double.valueOf( PricingUserExits._CPIW_B ).doubleValue();
                        double C=0, D=0;
                        BigDecimal bdC = (BigDecimal)prItem.getObjectForUserExits("XKOMV_KBETR_C");
                        C = bdC.doubleValue();
                        D = C * 0.8;  // just for calculation verification.
                        // C = Double.valueOf( PricingUserExits.XKMOV_KBETR_C ).doubleValue();
                        // D = Double.valueOf( PricingUserExits.XKMOV_KBETR_D ).doubleValue();
                        logInfo("overwriteConditionValue " +
                                                           "*tk* A, B, C, D: " + A + ", " + B + ", " + C + ", " + D);
                        double res1 =  A - B ;
                               res1 =  res1 /B ;
                               res1 =  D * res1;
                        double res2 =  D + C ;
                        double CPI_W ;
                               CPI_W = res1 - res2; //– res2;
                        BigDecimal retn =  new BigDecimal(CPI_W) ;
                       logInfo("overwriteConditionValue *tk* case 602 returning - " + retn );
                        return retn; // new BigDecimal(99999L);
                   default:
                        throw new FormulaNotImplementedException(prItem, "value formula", valueFormNo);

    Java != javascript.
    You can not call java directly from javascript.
    The lifecycle:
    Request received
    Java/JSP runs produces an HTML page
    Java stops running
    Javascript runs on page when page is loaded.
    The only way to call java code again is to submit a request and get the result back in a response. Traditionally the response is a new JSP page to replace the old one.
    Using AJAX the response can be just information that you then alter the current page with.
    The first example given by skp71 will probably NOT be what you are after. The java code is executed when you load the page, NOT when you push the button which is most probably what you are after.
    AJAX is a solution, as is loading a new page.
    Cheers,
    evnafets

  • Error when embedding the plugin inside java

    I have IE wrapped inside java, and when IE loads a page with java, I get the error message "Attachment to a running Virtual Machine failed." I guess the plugin gets confused by the allready running VM.
    Do I need to supply some hooks for the plugin?
    My code is a http://nothome.com/IEcanvas/

    My organization is also trying to embed IE 6.0 inside of a Java application using the IECanvas code, http://www.nothome.com/IECanvas/. That code was derived from work done at The Code Project, http://www.codeproject.com/java/javacom.asp.
    We are attempting to use the Java 1.4 release candidate with this code. Everything seems to work well, until IE attempts to load a Web page that has an imbedded Java applet that requires the Java Plugin. We have insured that IE is calling the exact same version of Java, version 1.4, when loading the plugin. Unfortunately, when the Java plugin starts loading, the error "Attachment to a running Virtual Machine failed" is presented in a dialog box titled "Java(TM) Plug-in 1.4 Fatal Error".
    After this IE asks if the user wishes to install the Java 1.4 plugin. Essentially, no Java 2 applets will work in IE once it is embedded in our Java application.
    I have done some research, and discovered that it should be possible to run more than one instance of the Java Virtual Machine in the same process space. I would like it if someone knows how to force the Java plugin to start a new Virtual Machine instance instead of trying to connect the the already running instance in the encompassing Java application.
    Thanks!
    Warren

  • HOW TO PRINT  THE EXCEL CELL COMMENT IN JAVA SWING FRAME ?

    How to print the excel cell comment in java swing frame
    user can print the data of cell with comment in bracket in java swing frame.
    please make one java code to read an excel spreed sheet and print the output in Java swing frame as follows
    EMP NO - 1, 2, 3
    EMP NAME - aname (amitesh:very good), bname (amitesh: average), cname (amitesh: very bad)
    EMP AGE - 11, 22, 33
    EMP DESG - ad, bd, cd
    Note: the bracket portion is the excel comments put in that cell

    hello everyone i'm new to this forum..how are you all...
    Jack Brosnan
    [mobile phone|http://www.mobilephonesforsale.net.au/apple-iphone-f-2.html]

  • Any news or comment on Java to H.264

    Is this forum of the used Forum on JMF?
    I would like to hear more news and comments on Java to H.264? Any codec developed by anyone to this new standard? Is Java fast enough to run H.264 codec on moderate computer, like PC with P3 800Mhz? Anyway, the more information, the better.

    Do you know if somebody have already implemented java apis for H.264? I need to estract a video flow from MPEG-4 streaming coded with h.264.I'm also interested in purchasing that implementation.
    Regards
    Fabrizio Scimia

  • 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/

  • Execute DOS command inside java

    I have a java program that reads each new user from an inputfile and writes that same user to an output file. The program works fine and is shown below:
    import java.io.*;
    public class FileStreamsTest {
    public static void main(String[] args) {
    try {
    File inputFile = new File("newbousrs.txt");
    File outputFile = new File("outagain.txt");
    FileInputStream fis = new FileInputStream(inputFile);
    FileOutputStream fos = new FileOutputStream(outputFile);
    int c;
    while ((c = fis.read()) != -1) {
    fos.write(c);
    fis.close();
    fos.close();
    } catch (FileNotFoundException e) {
    System.err.println("FileStreamsTest: " + e);
    } catch (IOException e) {
    System.err.println("FileStreamsTest: " + e);
    What I would like to do after each write is to execute a DOS command that looks something like this: supervsr.exe -USER username -PASS password -IMPORTUSERS importfile.txt
    The DOS command above will add each user to the system I want to as the loop goes through each user record.
    How do I execute the DOS command above inside java?

    Tried what but still having a problem...here is my code:
    import java.io.*;
    public class ReadSource {
    public static void main(String[] arguments) {
    try {
    FileReader file = new FileReader("newbousrs.txt");
                                  //FileWriter letters = new FileWriter("outagain.txt");
                                  //PrintWriter pw = new PrintWriter(new FileWriter("outagain.txt"));
    BufferedReader buff = new BufferedReader(file);
                                  Runtime rt = Runtime.getRuntime();
    boolean eof = false;
    while (!eof) {
    String line = buff.readLine();
    if (line == null)
    eof = true;
    else
    System.out.println(line);
                                                 Process proc = rt.exec("\\Blowfish\\droot\\Program Files\\Business Objects\\BusinessObjects 5.0\\supervsr.exe -USER xxxxx -PASS yyyy -IMPORTUSERS \\Blowfish\\droot\\accsp\\public\\newusers\\newbousrs.txt");
                                                 //System.out.println(line.substring(4, 10));
                                                 //System.out.println(line.substring(3,line.indexOf(',',3)));
    buff.close();
    } catch (IOException e) {
    System.out.println("Error -- " + e.toString());
    There error I get is this:
    C:\jakarta-tomcat-4.0.3\webapps\webdav\WEB-INF\classes\accsp>java ReadSource
    NU,Public,Steve Mcnealy,Steve Mcnealy,U,N,N,Y,N,N,PC,F,Y,N,N
    Error -- java.io.IOException: CreateProcess: \Blowfish\droot\Program Files\Busin
    ess Objects\BusinessObjects 5.0\supervsr.exe -USER accsp -PASS fish -IMPORTUSERS
    \Blowfish\droot\accsp\public\newusers\newbousrs.txt error=3

  • HOW to play flash inside java application program

    Do java provide any API for playing flash inside java application ?Pleae give me some help about it .Thank You ..

    pingyi wrote:
    Do java provide any API for playing flash inside java application ?Pleae give me some help about it .Thank You ..bro... I found out there from the internet... but you need to purchase it.
    hope it meets your expectation...
    JFlashPlayer is a Flash Player API Java package that lets developers play and interact with Adobe? Flash Player movies within Java applications. Advanced animations can improve the user experience and add to the professional appearance of an application. JFlashPlayer allows programmers to quickly add Flash movies to their Java application development for Windows.taken from: JflashPlayer

  • How to register own Transport implementation inside java

    Hi,
    My application is running on a shared host where I do not have admin rights.
    I have written my own implementation of the SMTP Transport.
    In order to be able to use it, it appears that I have to register it in
    $JAVA_HOME/jre/lib/javamail.providers
    with the line
    protocol=smtp_my; type=transport; class=com.my.app.mail.SMTPTransportMy; vendor=Me;
    this, is however not possible in all environments I want to run my app.
    Is there a way to do it inside java similar to the MailcapCommandMap approach?
    Any hints would be highly appreciated!
    Ralf
    https://www.privasphere.com/e.do?email=hauser(at)acm.org
    Just for reference how it is done there!
    MailcapCommandMap mc = (MailcapCommandMap) CommandMap
    .getDefaultCommandMap();
    mc .addMailcap("text/enriched;;x-java-content-handler=com.sun.mail.handlers.text_plain");
    //.addMailcap("text/*;;x-java-content-handler=com.sun.mail.handlers.text_plain");
    CommandMap.setDefaultCommandMap(mc);

    I don't understand what you mean by register a bean inside another bean.

  • Hi, where can i find specification of the Java ByteCode language ?

    Hi all.
    I need the java Bytecode language RFC/Specification i must create an sample language which must be translated to Java Bytecode but i cant fnid java bytecode specification
    i mean what structures and operations are available under Java Interpretator language and etc.

    here

  • Loading jmf player inside java 3d virtual space

    I need help in loading a jmf video player inside java 3d virtual class room.. Please help. I have created a player.. I have done the class room using texture mapping.
    I tried to do this using texture mapping itself.. but i failed.. So please help me... I need to do this for my project...

    I also get a fatal error after installing cf11.
    # A fatal error has been detected by the Java Runtime Environment:
    #  EXCEPTION_IN_PAGE_ERROR (0xc0000006) at pc=0x00000095d4acc035, pid=1636, tid=2996
    # JRE version: Java(TM) SE Runtime Environment (8.0_25-b18) (build 1.8.0_25-b18)
    # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.25-b02 mixed mode windows-amd64 compressed oops)
    # Problematic frame:
    # J 3290 C2 java.nio.MappedByteBuffer.load()Ljava/nio/MappedByteBuffer; (119 bytes) @ 0x00000095d4acc035 [0x00000095d4acbe20+0x215]
    This error occurs on every installation attempt. It is the only coldfusion version on the computer. Win 8.1 64bit.

  • How to run exe file from inside java

    I wan to run an exe file from inside java code. How can I do it?
    Thanks

    Hi Oakam
    This is very simple. Just go through the given code below
    in place of FILEANDPATHNAME just give the exe's path and name
    Note :- adding ".exe " is not necessary
    public class exep
    public static void main(String args[])
    Runtime r = Runtime.getRuntime();
    Process p = null;
    try{
    p = r.exec("FILEANDPATHNAME");
    catch(Exception e)
    Give ur feedback
    Thanx
    Ottran

  • 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.

Maybe you are looking for