flat assembler
Message board for the users of flat assembler.
Index
> Non-x86 architectures > Assembling JVM bytecode |
Author |
|
Tomasz Grysztar 10 Feb 2012, 18:39
I've been suspecting for a long time that it should be possible to use fasm to assemble Java bytecode, and out of curiosity I tried it this afternoon. I created a set of simple macros for composing the .class file with fasm, and a bunch of even simpler macros for generating bytecode, stitched it all together and got a working class. Perhaps more complex macros could be devised that would allow simpler usage, but with this simple approach the structure of .class file is nicely visualized, and it is anyway easy to play with it if you already know something about JVM and its interfaces.
It can be useful for educational purposes, I doubt one would want to write some programs this way... Or perhaps I'm mistaken? To test it, assemble Test.asm into Test.class and then run "java Test".
|
|||||||||||
10 Feb 2012, 18:39 |
|
Dex4u 10 Feb 2012, 20:46
This looks very interesting, i am not into java, but this could just change my mind.
Thanks, i will have a play with it. |
|||
10 Feb 2012, 20:46 |
|
shutdownall 10 Feb 2012, 22:26
Thank you, sounds interesting.
|
|||
10 Feb 2012, 22:26 |
|
Tomasz Grysztar 10 Feb 2012, 22:37
One more sample - this time a code that looks a little bit more like assembly programming. It loops and displays squares of numbers from 17 down to 1. As you can see there, the JVM's local variables resemble a bit the CPU registers in usage (even though JVM is stack-based architecture).
This is what the "main" method code in second sample looks like: Code: ldc number istore 1 example_loop: iload 1 dup imul invokestatic Integer_toString getstatic System.out swap invokevirtual PrintStream_println iinc 1,-1 iload 1 ifne example_loop
|
|||||||||||
10 Feb 2012, 22:37 |
|
Tomasz Grysztar 11 Feb 2012, 23:49
Just for the sake of it, I tried to write a class that actually does something useful. It implements "getProperty" method that allows to retrieve value of bean-like property from object. For example when it is called with any object as first argument, and "weight" string as second argument, it will return the result of invoking ".getWeight()" method on that object. It is written in a very dirty way and will fail on method names starting with something other than latin letter, or on the too long ones. But it is simple and probably fast. Though while writing it I learned more about the rigor that Java verification facility puts on the bytecode, and it really prevents trying to do some really dirty optimization tricks.
|
|||||||||||
11 Feb 2012, 23:49 |
|
TmX 12 Feb 2012, 14:34
Cool , maybe one day FASM will be listed on this site:
http://www.is-research.de/info/vmlanguages/category/jvm-language/ |
|||
12 Feb 2012, 14:34 |
|
edfed 13 Feb 2012, 13:49
how do you make it work? i'm sure i am doing it wrong.
i tested under win98, win7 and ubuntu, using javaw.exe and javaws.exe from jre1.6... everytime i try to launch a .class or .java bin with the java runtime environment, it don't works, it says "invalid or corrupted file" or "missing field" under win98, i'll post a win98 shot tonight.
|
||||||||||
13 Feb 2012, 13:49 |
|
Tomasz Grysztar 13 Feb 2012, 14:11
There is a TEST.BAT file in the last example, try if it works for you.
|
|||
13 Feb 2012, 14:11 |
|
shutdownall 13 Feb 2012, 16:28
edfed wrote: how do you make it work? i'm sure i am doing it wrong. What do you enter exactly ? The error means, that javaw is missing a java archive (jar). Try to use java (console) instead of javaw. It will automatically expect the extension .class - so just type "java Test" and not "java Test.class" and be sure to call from the directory containing the Test.class file. |
|||
13 Feb 2012, 16:28 |
|
LocoDelAssembly 13 Feb 2012, 17:13
A project that might be of interest on this thread: http://sourceforge.net/projects/rawxmllibrary/?source=directory (fasm, java assembly, .Net assembly)
|
|||
13 Feb 2012, 17:13 |
|
edfed 13 Feb 2012, 22:50
lol, finally i get it. in fact, it worked, i didn't noticed that because of some errors reported by the bat file execution, for 98, only this is needed.
Code: fasm DirtyRetriever.asm java Test pause to get this very beautyfull result: Code: C:\fasmj> C:\fasmj>test.bat C:\fasmj>fasm DirtyRetriever.asm flat assembler version 1.69.14 (138098 kilobytes memory) 2 passes, 847 bytes. C:\fasmj>java Test main ([Ljava/lang/String; )V C:\fasmj>pause Appuyez sur une touche pour continuer . . . sorry for the disturbing quiche problem. tomorrow, i will test again on 7, and maybe XP, maybe i just need to install correctlly java to get it work. the same for ubuntu. and now, let's code a little to see what can be done [edit] bored about win7 tests, nothing wants to work properlly without dealing with this f******* system, then... give it up. |
|||
13 Feb 2012, 22:50 |
|
nocona 11 Mar 2012, 15:16
few years back i did played with jvm bytecode/java class format and also .net clr header and its associated structure in the pe file format. although succeed in building test app manually with fasm, eventually i give up while trying to create set of macros to simplify the programming process. coz i cant find a way to dynamically create the entry in the constant_pool structure in the class file which i think is impossible to achieve.
and for the .net extension to pe... it's just too complex . too bad all my example files are lost.. |
|||
11 Mar 2012, 15:16 |
|
Tomasz Grysztar 11 Mar 2012, 17:25
nocona wrote: eventually i give up while trying to create set of macros to simplify the programming process. coz i cant find a way to dynamically create the entry in the constant_pool structure in the class file which i think is impossible to achieve. |
|||
11 Mar 2012, 17:25 |
|
nocona 18 Mar 2012, 11:45
is there other link where i can download the video? i cant access the link mentioned in that thread http://tokk.biz/fasmcon2009/M2U00510.avi. also maybe any documents which i can read about fasm 2?
|
|||
18 Mar 2012, 11:45 |
|
Madis731 20 Mar 2012, 12:10
Yeah, like OllyDBG 2. FASM 2 should have a special place. People could brainstorm & arrange ideas there and there would be some documents like prelude or something.
|
|||
20 Mar 2012, 12:10 |
|
bitRAKE 23 Aug 2013, 21:47
Is there an error in bytecode.inc?
Code: macro ret index { if index<100h db 0xa9,index else db 0xc4,(index) shr 8,(index) and 0FFh end if } |
|||
23 Aug 2013, 21:47 |
|
uart777 25 Aug 2013, 10:34
bitRAKE: Yes, 0xc4=wide prefix then 0xa9 opcode. 16BIT value after is high-endian. Fourth line should be:
Code: db 0xc4,0xa9,(index) shr 8,(index) and 0FFh JASM: Java Assembler. Example Applet+JFrame Application written in FASM! |
|||
25 Aug 2013, 10:34 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.