Question

I am not trying to compile my source code into an executable. Please read before marking as duplicate.

With that said, I apologize if this question has been asked before. The countless "how do I compile java | C++ to exe" questions filled up all my searches.

I am looking for a library that facilitates the creation of windows executable (.exe) files. To be specific, I want to be able to be able to generate a series of assembly instructions at runtime (these will be very simple) and create an executable that will execute them. I can generate the assembly myself; I would just like to have a library to help deal with all of the headers and other parts of the .exe file (I started looking into Portable Executable File Format but it far too complicated for me to deal with. I'm not lazy but as a high-level programmer I feel that this stuff is way under my head). The specific mechanics of the library are not important as long as it works for either Java or C++. Java is highly preferred, however.

Any knowledge pertaining to any sort of framework that would be helpful in this regard would be appreciated.

Was it helpful?

Solution 2

Okay, so what I ended up doing was searching around the bin folder of my MASM32 installation, where I found the assembler: ml.exe. I then write assembly to a text file and invoke the assembler on it using: Runtime.exec():

Runtime.getRuntime().exec(
            "C:/masm32/bin/ml.exe "        //directory of assembler
            +"/coff "                      //create COFF header (needed for Win32)
            +"/Bl C:/masm32/bin/link.exe " //directory of linker 
            +"/Fe src/" + fileName + ".exe " //executable file
            +"/Fo src/" + fileName + ".obj " //object file
            + fileName + ".asm");            //assembly file (source)

User n.m. gave me the idea, but as they didn't post it as answer after a month I decided to just answer it myself.

OTHER TIPS

Why not roll you own? Emit code for the lowest common denominator (CPU). By doing this you will probably add much to your skill set. I am currently writing a scripting engine and looking to introduce a JIT compiler to generate code for Windows platforms. To achieve this, I add code listings to projects to see assembly code generated by the compiler. Not perfect I know, but gives a solid starting direction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top