Java Launch4j

Posted on  by 

Launch4J Windows native executable (.exe) java application wrapper. Offers native splash screen, application icon, search for JRE or use bundled one, feedback on startup failure, passes command line arguments. Feb 28, 2012 I don't know why you want to call jars via VM arguments from Launch4J launcher. Launch4J can embed them in the executable. Add the names of jars in the Classpath list under the Classpath tab of the Launch4J GUI. If the jars are under a folder relative to the installation path of the application, prefix each jar with the folder path.

Running launch4j

Mar 10, 2021 Launch4j is a software utility that allows users to wrap Java applications into Windows native executable programs. We all know how tiresome it can get to open a Java-based application on Windows. Launch4j is a software utility that allows users to wrap Java applications into Windows native executable programs. We all know how tiresome it can get to open a Java-based application on Windows.

Java Launch4j Program


Configuration file
Importing 1.x configuration
Ant Task
Debug launching mode

Running launch4j

Run launch4j.exe or launch4j script without commandline arguments to enter the GUI mode.To wrap a jar in console mode use launch4jc.exeandspecify the configuration file.On Linux use the launch4j

Java Launch4j

script.

Configuration file

Launch4j requires an xml configuration file for each output executable.You can create and edit it conveniently using the graphic userinterface or your favorite editor. Alternatively it's possible to passall of the configuration parameters through the Ant task. All filesexcept for <jre><path>may be absolute paths or relative to the configuration file path.
<headerType>
Type of the header used to wrap the application.
Header typeApp typeLauncherSplash screenWait for the application to close
0GUIjavawyeswrapper waits only if stayAlive is set to true, otherwise it terminates immediately or after closing the splash screen.
1consolejavanoalways waits and returns application's exit code.
<outfile>
Output executable file.
<jar>
Depends on <dontWrapJar>, if false (the default) then this element is the executable jar to wrap. When <dontWrapJar> is set to true it's the runtime path of the jar relative to the executable. For example, if the executable launcher and the application jar named calc.exe and calc.jar are in the same directory then you would use <jar>calc.jar</jar>.
<dontWrapJar>
Optional, defaults to false. Launch4j by default wraps jars in native executables, you can prevent this by setting <dontWrapJar> to true. The exe acts then as a launcher and starts the application specified in <jar>
<errTitle>
Optional, sets the title of the error message box that's displayed if Java cannot be found for instance. This usually should contain the name of your application. The console header prefixes error messages with this property (myapp: error...)
Java
<jarArgs>
Optional, constant command line arguments.
<chdir>
Optional. Change current directory to an arbitrary path relative to the executable. If you omit this property or leave it blank it will have no effect. Setting it to . will change the current dir to the same directory as the executable. .. will change it to the parent directory, and so on.
<customProcName>
Optional, defaults to false. Set the process name as the executable filename. Creates a temporary file in launch4j-tmp directory inside the used JRE. These files are deleted by any launch4j wrapped application, which sets the process name and uses the same JRE. The removal takes place when the application starts, so at least one copy of this file will always be present.
<stayAlive>
Optional, defaults to false in GUI header, always true in console header. When enabled the launcher waits for the Java application to finish and returns it's exit code.
<icon>
Application icon in ICO format. May contain multiple color depths/resolutions.
<headerObjects>
Optional, custom headers only. Ordered list of header object files.
<file>
<file>
...
<libs>
Optional, custom headers only. Ordered list of libraries used by header.
<file>
<file>
...
<jre>
Required element that groups JRE settings.
<path>, <minVersion>, <maxVersion>
The <path> property is used to specify the relative path (to the executable) of an embedded JRE, it does not rely on the current directory or <chdir>. Note that this path is not checked until the actual application execution. If you'd like the wrapper to search for a JRE (public or SDK private) use the <minVersion> property, you may also specify the <maxVersion> to prevent it from using higher Java versions. Launch4j will always use the highest version available (in the min/max range of course). You can also combine these properties to change the startup process...
<path>
Run if bundled JRE and javaw.exe are present, otherwise stop with error.
<path> + <minVersion> [+ <maxVersion>]
Use bundled JRE first, if it cannot be located search for Java, if that fails display error message and open the Java download page.
<minVersion> [+ <maxVersion>]
Search for Java, if an appropriate version cannot be found display error message and open the Java download page.
<initialHeapSize>
Optional, initial heap size in MB, 0 - use default.
<maxHeapSize>
Optional, max heap size in MB, 0 - use default.
<args>
Optional, accepts everything you would normally pass to java/javaw launcher: assertion options, system properties and X options. Here you can map environment and special variables EXEDIR (exe's runtime directory), EXEFILE (exe's runtime full file path) to system properties. All variable references must be surrounded with percentage signs and quoted.
<splash>
Optional, groups the splash screen settings. Allowed only in GUI header.
<file>
Splash screen image in BMP format.
<waitForWindow>
Optional, defaults to true. Close the splash screen when an application window or Java error message box appears. If set to false, the splash screen will be closed on timeout.
<timeout>
Optional, defaults to 60. Number of seconds after which the splash screen must be closed. Splash timeout may cause an error depending on <timeoutErr>.
<timeoutErr>
Optional, defaults to true. True signals an error on splash timeout, false closes the splash screen quietly.
<versionInfo>
Optional, version information to be displayed by the Windows Explorer.
<fileVersion>
Version number 'x.x.x.x'
<txtFileVersion>
Free form file version, for example '1.20.RC1'.
<fileDescription>
File description presented to the user.
<copyright>
Legal copyright.
<productVersion>
Version number 'x.x.x.x'
<txtProductVersion>
Free form file version, for example '1.20.RC1'.
<productName>
Text.
<companyName>
Optional text.
<internalName>
Internal name without extension, original filename or module name for example.
<originalFilename>
Original name of the file without the path. Allows to determine whether a file has been renamed by a user.

Importing 1.x configuration

It's possible to import a 1.x configuration file using the GUIinterface. Open the file, correct the paths and save it as a new xmlconfiguration.

Ant task

You may set a launch4j directory property or change the task definition.Define the task in your Ant build script.Execute the task!You can set or override the following configuration properties...
<jar>
<outfile>
<versionInfo>
<fileVersion>
<txtFileVersion>
<productVersion>
<txtProductVersion>
You can also define the entire configuration in the task, but it willnot be possible to edit such a file in the GUI mode. All paths exceptfor <chdir> and <jre><path> arecalculated using the basedir project attribute.

Debug launching mode

Java Launch4j Software

To make sure the output executable is configured correctly you can use thedebug launching mode which displays various information before starting the Java application.To enable it set the environment variable launch4j=debug and run the wrappedprogram.

Unpacking Launch4j 3.5: Extracting The Jar File:

Welcome to this short tutorial for unpacking Launch4j. Launch4j is a Java executable wrapper for Windows which makes the process of deploying a Java application on windows a little less arduous. It bundles the Java application with all of its command line arguments into a single executable and passes itself directly to the java runtime or 'java.exe' upon execution. The goal of this tutorial is to show you how to recover/extract/unpack the original jar file and retrieve the command line arguments from the executable. While most protection detecting utilities do not detect launch4j, it is quite easy to identify this wrapper by using string references to find the string 'Launch4j'.
The application we will be working with is the demo project included with Launch4j called SimpleApp. It is located in the Launch4j installation directory in the folder '%Launch4j%demoSimpleApp'. To begin, we will open our file 'SimpleApp.exe' in LordPE and click the sections button. This window will allow us to determine the Raw Offset and size of the resource section which usually has the name '.rsrc'.
As we can see in the picture, the raw offset is '6000h' and its raw size is '1C00h'. The jar file is always located directly after the end of the last section and spans all the way until the end of the file, so '6000h + 1C00h= 7C00h'. This means that 7C00h is the raw offset of the Jar file. Let's open the application up in winhex to verify.
As you can see here, we have reached the beginning of the Jar archive which is indicated by the 'PK' file type identifier. As stated above, the end of the archive will be the last byte in our file. In order to make sure we select everything correctly, we need to mark this offset as the 'beginning of block' through the right click menu.
Once you have done this, we can simply scroll to the last offset and mark it as the 'end of block'.

Launch4j Java 11

This will automatically select all of the bytes in our archive and allow us to extract and save them as another file. To do this, right click the selection and click the 'Edit' button.





From here, another menu will appear. Go to the option 'Copy Block' and in the sub-menu, click 'Into New File'.











Afterwards, a save dialog will appear. In this example, I decided to name the file 'SimpleApp2.jar'.












After clicking save, let's run our extracted file and see the results.









As you can see, our extraction was successful and the file runs correctly, so our work is done.
While this file runs correctly as is, in some cases, the author may pass additional command line arguments to the java runtime. If we do not recover these parameters, some applications may not run correctly. To do so, we can open the original file in ollydbg and set a breakpoint on the API CreateProcessA. After running the application, we will shortly break here and we can read the arguments off of the stack. Below, we can look at the following example from another target.



In this example, we can can see that application is passing the parameters -Xms256M and -Xmx800M which tells the application the minimum and maximum ram amount to allocate to the process. Without these parameters, the application may not have the ram it requires to perform certain tasks. That is why it is crucial to recover these parameters to insure that the extracted jar will work correctly.
Another approach to recovering these parameters would be to search for them with a resource editor. While this approach may not be as reliable as the one above, it may be best when working with malicious code.

Java Launch4j Tutorial









Java launch4j

Java Launch4j Gradle


Java Launch4j Linux

In this example, I was able to find the parameters stored in the RC Data directory of the resource table.
I hope that you were able to walk away with some new knowledge. If there is something that you are not quite able to grasp or understand, please feel free to post your questions or comments below. Until next time, happy reversing.

Coments are closed