Anybody write Java assembly code?
I recently stumbled onto the Jasmin (http://jasmin.sourceforge.net/) and BCEL (http://jakarta.apache.org/bcel/) projects and have a question for all the Java developers out there.
Have any of you ever written Java assembly/byte code directly instead of writing Java source code? You're probably asking "why the hell would someone write Java bytecode when they have a great high-level language like Java?" Well that's what I want to find out. Why would you write Java assembly code? What cool things have you done with Java assembly code?
-insert tracing instruction before every executable statement of code for dynamic coverage analysis.
-insert timing instructions at the top and bottom of every method for dynamic profiling
-generate dynamic stubs/ adapter code
Folks generally don't program using java assembly, as far as I know, but use these tools to programmatically create/alter code.
Similar Messages
-
I am a java beginner. i need to know which interface i can use to write java code
Hi ,
u can write java code in many places
notepad,
edit plus ,
eclipse ,
netbeans ,
NWDS (in j2ee perspective thisis for sap side )
all the thing u need to install jdk first ...
set your class path .
go to command promt -> type cmd
ur command prompt opens .
open note pad write some code
execute in command promt by typing javac abc.java
i fno errors type java abc
ur code will be executed and result displayed
regards ,
venkat p -
How to write java code to read the pixel color in some place of screen?
Hello all:
How to write java code to read the pixel color in some place of screen?
The java application iteself doesn't have any GUI.
thank you
-DanelSee java.awt.Robot
-
Can i write java code in JavaScript function
I want to call JavaBeans within JavaScript function. Can I do it?
I have a button in JSP . When the button be clicked,the data be inputted will be checked by JavaScript function. If check is ok, then call a Bean's function to write the data to database.
Please Help!well indeed u can write java code in javascript functions. But probably it will not work the way u want it to.
when u say that u click a button, it means that some client side action is performed. Now if u wud require a java bean to be called then it means that the server needs to be contacted for the same, and if that has to be done, necessarily the form needs to be submitted.
U can populate values from a java bean and then the same can be made available to a javascript variable / function when the page is loaded rather than, when the button is clicked.
What u can do is on click of button u can process [display / calulate..etc ] the information which has already been got by the java bean.
Kris -
Hi,
im a fresher in java
im trying to develop my own java decompiler which translates class file to java file ,can anyone help me please how to start and give some guidelines .. wud b really helpful
looking forward for your support .. thanks !!A decompiler is a very advanced project to take on, not for a "fresher".
1. You must write a disassembler first.
This involves being able to parse the binary class file, and convert it into java
byte code instructions.
As mentioned, the class file format is documented here, and is the sole reference I needed to write a disassembler.
http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html
2. After you have the disassembled instructions, you can then try to reassemble
them into higher level java source code.
This isn't a trivial project.
In my free time, I spent ( on and off ), 1 year writing my own disassembler to support Java 1.5, and I haven't even attempted a decompiler ( yet ).
It has 279 classes, most fairly complex.
Just to give you an idea of my experience, 7 years java, 5 years C++ and assembly. And you'll need some experience/concepts of assembly language to work out the stack frame to break the java byte code instructions into java statements.
In my opinion, you're better off experimenting with the BCEL ( byte code engineering lab ), to extract details about the class file.
regards,
Owen -
Java assembler?? for Javap utility??
Hi frends!!
when a small program like
class Hello{
public static void main(String arg[])
System.out.println("HEllo World");
was compiled and then i took the java byte code instruction
through JAVAP option
the byte code instructions for the above program was
Compiled from "Hello.java"
class Hello extends java.lang.Object{
Hello();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc #3; //String HEllo World
5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/Str
ing;)V
8: return
without giving the program "Hello.java"
to the JVM how can i run the "Hello" program through JVM by giving the
above byte code instructions "which was gained by using the javap
option" to the JVM??
basicaly I want to get the output of "Hello World" by giving the below
byte code instructions to the JVM
Compiled from "Hello.java"
class Hello extends java.lang.Object{
Hello();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc #3; //String HEllo World
5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/Str
ing;)V
8: return
Is there a way That I can convert the above code to java Class File format??? and so that I can run the program through JVM!!
If someone knows the way I can do it!! Please send me the method
my e-mail: [email protected]
thanks
- MalindaPerhaps you noticed my post at
http://forum.java.sun.com/thread.jspa?forumID=37&threadID=603213
I get the bytes of a class and then load them into my own class loader. My intention in that post was to create many large classes in order to test a limit of the JVM. I started with a class in the Java language, compiled it, used javap (or an equivalent) and then recorded the bytes back into a byte array back in the java language.
I am not sure what your primarily interest is:
1. Interested in compiler details of javac (starts with com.sun.tools.javac.Main) but compilers are a pretty big subject
2. Avoid the Java language and compose your code in Java assembler. It is not clear to me how easy you can get from what javah prints to what, say, Jasmin will accept.
(see http://jasmin.sourceforge.net/)
3. Manage your own class bytes (having them perhaps in a database rather than files)
4. Loading your own class file bytes into a JVM
It is hard to compose the class directly in the class bytes because you have to manage the local storage pool. Note that I used Gnu's gcf-dump to get more info about the pool than javap would give. If you interest is in composing in Java Assembler, then Jasmine would be a good start, but I suspect that it had to invent some of the assembler syntax for the assembler source. If you later change to some other Java assembler, you might have to change your assembler source.
If you are focused on seeing the class bytes, here is the bytes of your Hello program with some annotations being loaded. As you can see, the opcodes take up very little space. It is all of the storage and wrapping that take up 15 (5 for "<init>" plus 9 for "main") of the 335 or so bytes used.
If you tempted to change the byte array, keep in mind that the string start with a byte count that must be maintain correctly. Same for the attribute blocks and opcode blocks.
What I did to demonstrate is to write a small program to load a class directly from a byte array. Rather than learn all about class files, I did a quick hack on a small class file.
Load the bytes into my own class loader.
The original class was simply:
public class Hello {
public static void main(String arg[]) {
System.out.println("Hello World");
Compiled with:
javac -g:none Hello.java
If you want code details, compile the above try 'javap -v -c Hello'
Also, jcf-dump from Gnu gives more detail
http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html
// import java.lang.ClassLoader;
import java.lang.reflect.Method;
public class malinda {
public static void main(String ar[]) {
// Use an int array just to avoid warnings that result from signed bytes
int cl_blob1[] = {
0xca,0xfe,0xba,0xbe, // magic
0x00,0x00, 0x00,0x2e, // class format version
// Constant pool
0x00,0x1a,
0x0a,0x00,0x06,0x00,0x0c,
0x09,0x00,0x0d,0x00,0x0e,
0x08,0x00,0x0f,
0x0a,0x00,0x10,0x00,0x11,
0x07,0x00,0x12,
0x07,0x00,0x13,
0x01,0x00,0x06,0x3c,0x69,0x6e,0x69,0x74,0x3e, // <init>
0x01,0x00,0x03,0x28,0x29, 0x56,// ()V
0x01,0x00,0x04,0x43,0x6f,0x64,0x65, // Code
0x01,0x00,0x04,0x6d,0x61,0x69,0x6e, // main
0x01,0x00,0x16,0x28,0x5b,0x4c,0x6a,0x61,0x76,0x61,0x2f,0x6c,0x61,0x6e,0x67,0x2f,0x53,
0x74,0x72,0x69,0x6e,0x67,0x3b,0x29,0x56, // ([Ljava/lang/String;)V
0x0c,0x00,0x07,0x00,
0x08,0x07,0x00,0x14,
0x0c,0x00,0x15,0x00,0x16,
0x01,0x00,0x0b,0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,0x72,0x6c,0x64, // Hello World
0x07,0x00,0x17,
0x0c,0x00,0x18,0x00,0x19,
0x01,0x00,0x05,0x48,0x65,0x6c,0x6c,0x6f, // Hello
0x01,0x00,0x10,0x6a,0x61,0x76,0x61,0x2f,0x6c,0x61,0x6e,0x67,0x2f,0x4f,0x62,0x6a,0x65,0x63,0x74, // java/lang/Object
0x01,0x00,0x10,0x6a,0x61,0x76,0x61,0x2f,0x6c,0x61,0x6e,0x67,0x2f,0x53,0x79,0x73,0x74,0x65,0x6d, // java/lang/System
0x01,0x00,0x03,0x6f,0x75,0x74, // out
0x01,0x00,0x15,0x4c,0x6a,0x61,0x76,0x61,0x2f,0x69,0x6f,0x2f,0x50,0x72,
0x69,0x6e,0x74,0x53,0x74,0x72,0x65,0x61,0x6d,0x3b, // Ljava/io/PrintStream;
0x01,0x00,0x13,0x6a,0x61,0x76,0x61,0x2f,0x69,0x6f,0x2f,0x50,0x72,0x69,0x6e,0x74,0x53,
0x74,0x72,0x65,0x61,0x6d, // java/io/PrintStream
0x01,0x00,0x07,0x70,0x72,0x69,0x6e,0x74,0x6c,0x6e, // println
0x01,0x00,0x15,0x28,0x4c,0x6a,0x61,0x76,0x61,0x2f,0x6c,0x61,0x6e,0x67,0x2f,0x53,0x74,0x72,0x69,
0x6e,0x67,0x3b,0x29,0x56, // (Ljava/lang/String;)V
0x00,0x21, // Access flags: public super
0x00,0x05, // This class
0x00,0x06, // Super class
0x00,0x00, // interface_count=0
0x00,0x00, // field_count=0
0x00,0x02, // Method count = 2
0x00,0x01, // Start of <init>
0x00,0x07,
0x00,0x08, // Signature
0x00,0x01,
0x00,0x09, // attribute_name_index
0x00,0x00,0x00,0x11,// attribute length = 17 for opcodes
0x00,0x01, // max_stack
0x00,0x01, // max_local
0x00,0x00,0x00,0x05, // code length
0x2a, // aload_0
0xb7,0x00,0x01, // invokespecial #1
0xb1, // return
0x00,0x00,
0x00,0x00,
0x00,0x09, // Start main
0x00,0x0a,
0x00,0x0b, // Signature
0x00,0x01,
0x00,0x09, // attribute_name_index
0x00,0x00,0x00,0x15,// attribute length = 21
0x00,0x02, // max_stack
0x00,0x01, // max_local
0x00,0x00,0x00,0x09, // code length
0xb2,0x00,0x02,// getstatic #2
0x12,0x03, // ldc #3
0xb6,0x00,0x04, // invokevirtual #4
0xb1, // return
0x00,0x00,
0x00,0x00,
0x00,0x00,
// Covert the ints to bytes and load them into a class
MyLoader cld1 = new MyLoader();
byte cl_bytes [] = new byte[cl_blob1.length];
for(int i = 0; i< cl_blob1.length; i++){
cl_bytes[i] = (byte) cl_blob1;
try{
Class cl1 = cld1.doClass("Hello", cl_bytes);
Object o1 = cl1.newInstance();
String m_args[] = new String[0];
Class sig = m_args.getClass();
Class ca[] = {sig};
Method m = cl1.getDeclaredMethod("main", ca);
Object args[] = {m_args};
m.invoke(null,args);
}catch (Exception ex){
ex.printStackTrace();
// Make real loader with public version of defineClass()
static class MyLoader extends ClassLoader {
Class doClass(String name, byte b[]){
return defineClass(name, b,0,b.length); -
Java source code to compare XML based on ExamXML XML diff tool
I’m working on a project that includes comparing XML files and I need a source code on Java to compare XML fragments.
I’m using ExamXML from http://www.a7soft.com to compare XML files but I need the Java source code.
Can anybody help me.You didn't notice there's a "Support" link on that page you referred to? Ask them for the source code. If they won't give it to you, then you are effectively asking us to give you a stolen copy of it. Don't ask for such things on this site.
-
I heard about the possibilty of decompiling the java code and getting back the source code, is this flaw specific to java or is it common among all programming langauges?
how is it possible to protect the source code? and how expensive is the solution?
thank youBack to poster: To my knowledge, the ability tode-compile back to valid source code is unique to
Java.
No it's not. Any program files can be decompiledback
to source code.
If not their original C or C++ code, then at least
assembly code.You cannot decompile C or C++ code to anything but
assembler language. Which even when written by a good
programmer is considered obfuscated by others. I
doubt that anyone has lifted C or C++ code from
another application using a decompiler.yes you can, all binaries can be reverse compiled, logically speaking they have to be!
However, the readability of the output is not going to be as high as that obtained from decompiled java.
>
I would say that de-compilation is not a flaw in Javawhen compared to
powerful features it has to offer. Of course it's a flaw (so I disagree with you here).
People don't want this behavior, but it exists. As I
stated earlier (and I'm agreeing with you on this
one), it was an issue of priorites, and the
developers of Java decided that it was OK because it
allowed "powerful features"...it is a feature - whether it is a desirable feature is another argument entirely.
>
Here's a list of projects where the developers arenot interested in
hiding the source code from you, in fact they let youhave it for free:
Notice the words developers, not software companies.
I believe in open source and participate in it when
not bound by non-disclosure which is 99% of the time.
But I would stand by my statement that there are no
o software companies selling retail software that
believe the ability to decompile Java back to Java
source code is OK or good for them in anyway. I would
gently suggest that providing open source code, and
providing the ability to decompile to source code
really don't belong in the same discussion...Protecting code is not the job of programmers, it is the job of the Law.
rob, -
i need to write java code in JSF. can i use scriptlet <%%> as i use in JSP? if not than How can i write?
thanks..The short answer is no.
The medium answer is yes you can, no you may not.
The long answer is that there is always a better way to do it than writing code on the page. Its very tempting, it can be fast, it may even work. Either you or whoever comes after you will regret the decision. The problem is you'll probably end up not knowing what decisions your code is making and where they are being made. Force yourself to do it the "right" way and coming back to your pages to make changes will be a much more pleasant task. -
HI!
I am searching for an API to parse java source code, modify it (add new methods, change method names,....) and write it to a new file.
any suggestions?
mfg
MKthere is no such Java API
-
Insert Assembly Code into C++?
Hi, every one,
I am writing a segment of assembly code inserted into the C++ code. During the compiling using Solatis Sparc v8 C++ compiler, I felt a bit confused at the following error:
Linking
Undefined Symbol first referenced in file
lock ..../libatsup.so( this is my created lib)
My code looks like:
Error atomic_lock(volatile int *lock)
asm("retry:");
asm("ldstub [lock], %l0");
My question is how to declare the variable "lock" in the atomic_lock?
Any help will be appreciated.
-YuzhongSorry for the confusion. I was assuming that your assembly routine is simple enough to be leaf routine. So, it need not have a save in the prologue. If you have a save, your input args. will be in %i0-%i6. Depending on the prototype of the atomic lock function you are writing, access the arguments in %i0 and so on. If you don't need new register window, (don't call other function and no stack space needed) the args. will be in %o0-%o6. The easiest way is to write a similar(skeleton) code and compile it into assembly and fill in atomic instructions.
You have to declare the function as
extern "C" {
void atomic_op(int *lock,......); // exact code depends on your design
in other files where you refer it.
-Ananth. -
How can I write the analogous code to the logic:iterate tag functionality
Hai This is Rayalu .And I am very new to the Java World. I have a doubt?.How can I write the analogous code to the<logic:iterate> tag functionality using the JSP Tag Libraries . Pleae Send me some examples .
Hi,
SELECT objnr objid aufnr
from afih
into table t_afih.
SELECT objnr
from JEST
into table t_JEST
where stat = 'A0045'
OR stat = 'A0046'
AND inact 'X'.
SELECT objnr
from COBRB
into table t_cobrb.
SELECT arbpl werks objid objty
from crhd
INTO table it_crhd
FOR ALL ENTRIES IN it_afih
WHERE objty eq 'D'
AND gewrk = it_afih-objid.
SELECT aufnr objnr auart txjcd pspel gstrp werks aufnr
FROM caufv
INTO table t_caufv
FOR ALL ENTRIES IN it_afih
WHERE aufnr = it_afih-aufnr
And pspel = ' '
AND txjcd = ' '
ANd objnr ne it_crhd-objnr
AND auart in s_wtype
AND werks in s_plant.
AND objnr ne it_jest-objnr.
dont use NE in the select statements, it may effect performance also. Instead use if statements inside
loops.
loop at t_caufv.
read table it_chrd............
if t_caufv-objnr ne it_chrd-objnr.
read table it_jest..........
if if t_caufv-objnr ne it_jest-objnr.
(proceed further).
endif.
endif.
endloop.
hope this helps.
Reward if useful.
Regards,
Anu -
Java.policy code delays JVM loading
Hello All!!
My java.policy code has 46 grant lines due to different permissions of different applets and servers.
When I want to run some of this applets I've a delay of 90 seconds to load the JVM.
I think I'm verifying that exist all of my servers in java.policy because i've a very high delay, but I think it wouldn't be that way.
My questions are: will do I encrease the delay if I encrease the number of applets or servers? I'm working with JDK1.3, does anybody knows if this verssion is limited?Nowhere. Use the -Xbootclasspath option of 'java'.
-
How to Use the JAVA SCRIPT code in .htm page of the component
Hi .
In my requirement i have to use Java Script Function in .htm code ..how to use the java script code and functions in .htm???
thank you
B.ManiCheck this document [Arun's Blog|http://wiki.sdn.sap.com/wiki/display/CRM/CRMWebClientUI-TalkingwithJava+Script]
Regards
Kavindra -
How to read the Java source code (in Netbeans)
I use OS X10.5.5, NetBeans 6.1 and JSE 6 on a 64 bit mac.
When I downloaded NB6.1 it had JSE 5 as it's default (and only) java platform. I ran Software Update to get Java 6 from Apple, used the Java Prefrences utitlity to set JSE6 as default. In NB I added the JDK6 platform, registered the JDK6 javadocs and noticed that I also have the option of registering the Java source code.
I have three questions:
1) How do I make JDK6 the default in NetBeans. The JDK5 keeps being default after I did the steps above and I don't see anywhere to change that.
2) How do I read the Java 6 source code? I can see sun provides [source code| http://download.java.net/jdk6/] for their supported platforms. I dont see Apple doing the same for its JDK port. What would I need to do to get to read the java SE6 sources? or is it actually hiding somewhere in the /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home hierarchy?
3) Where does the JVM look for the binary code to run when I make a call to, say java.util.ArrayList or any other library. In my naivety I would have assumed it would be a .class file somewhere in the java Home folder, but I don't see anything like it.
thanks in advance,
chrisThis is taken from the help included with netbeans. In response to question 1.
By default, the IDE uses the version of the Java SE platform (JDK) with which the IDE runs as the default Java platform
for compilation, execution, and debugging. You can view your IDE's JDK version by choosing Help > About and clicking the
Detail tab. The JDK version is listed in the Java field.
You can run the IDE with a different JDK version by starting the IDE with the --jdkhome jdk-home-dir switch on the command line
or in your IDE-HOME/etc/netbeans.conf file. For more information, see IDE Startup Parameters.
In the IDE, you can register multiple Java platforms and attach Javadoc and source code to each platform. For example, if you
want to work with the new features introduced in JDK 5.0, you would either run the IDE on JDK 5.0 or register JDK 5.0 as a
platform and attach the source code and Javadoc to the platform.
In , you can switch the target JDK in the Project Properties dialog box. In , you have to set the target JDK in the Ant script itself,
then specify the source/binary format in the Project Properties dialog box.
To register a new Java platform:
Choose Tools > Java Platforms from the main window.
Click New Platform and select the directory that contains the Java platform. Java platform directories are marked with a
in the file chooser.
Use the Sources and Javadoc tabs to attach Javadoc documentation and source code for debugging to the platform.
Click Close.
To set the default Java platform for a standard project:
Right-click the project's root node in the Projects window and choose Properties.
In the Project Properties dialog box, select the Libraries node in the left pane.
Choose the desired Java platform in the Java Platform combo box.
Switching the target JDK for a standard project does the following:
Offers the new target JDK's classes for code completion.
If available, displays the target JDK's source code and Javadoc documentation.
Uses the target JDK's executables (javac and java) to compile and execute your application.
Compiles your source code against the target JDK's libraries.
If you want to register additional Java platforms with the IDE, you can do so by clicking the Manage Platforms button.
Then click the Add Platform button and navigate to the desired platform.
To set the target Java platform for a free-form project:
In your Ant script, set the target JDK as desired in the javac, java, and javadoc tasks.
Right-click the project's root node in the Projects window and choose Properties.
In the Sources panel, set the level of JDK you want your application to be run on in the Source/Binary Format combo box.
When you access Javadoc or source code for JDK classes, the IDE searches the Java platforms registered in the
Java Platform Manager for a platform with a matching version number. If no matching platform is found, the IDE's default platform is used instead.
See Also
Managing the Classpath
Declaring the Classpath in a Free-Form Project
Stepping Through Your Program
Legal Notices
Maybe you are looking for
-
How can I implement a status bar at the bottom of a resizable application?
Hello all, I am a JavaFx newbie and I am implementing an application (a Sokoban game), with a menu at the top of the frame and a gaming area covering the rest of the frame. To support the game, I have to load images at certain positions in the gaming
-
My Verizon broadband was always crashing (some software issue that has been resolved) and after that my Thunderbird email stopped working saying I needed a password. I have tried everything in every option and still cannot change the password and log
-
OBIA -'Financials_Oracle R12'
After installation of OBIA we are trying to run out of box 'Financials_Oracle R12' execution plan. And it failed right at the start with following error. Error while loading nodes. ERROR: Circular Dependency detected. Check server log for details. 'T
-
Can we put Gradient In UIResource (example: component background) when customizing L&F of Swing components or we're just limited on ColorUIResource for (r,g,b) colors?
-
Hi, I have macbook pro 15 10.9.4 ios, yesterday my mouse start behaving strange it was moving itself all the back round images start appearing on my screen with chrome safari and all. system went to sleep for 10 mins after that all chats history gone