How to set or make FreeBSD report its OS as "Linux" to fool a (Java) app?

I'm trying to run a Java app written for Linux on FreeBSD 13.
The Java app reports the operating system "FreeBSD" as being not recognized.
Is there anyway to set or make FreeBSD output its name as "Linux" to "fool" the Java app?
 

I found this page has some information about OS detection, but also mentions how you could possibly change the detected OS. The most relevant part, is fairly far down towards the bottom. The main thing,is more of how the app does the detection (you may need to read through the various responses on what to look on.

If you're working in a security sensitive environment, then please read this through.


Please refrain from ever trusting a property obtained via the System#getProperty(String) subroutine! Actually, almost every property including os.arch, os.name, and os.version isn't readonly as you'd might expect — instead, they're actually quite the opposite.


First of all, any code with sufficient permission of invoking the System#setProperty(String, String) subroutine can modify the returned literal at will. However, that's not necessarily the primary issue here, as it can be resolved through the use of a so called SecurityManager, as described in greater detail over here.


The actual issue is that any user is able to edit these properties when running the JAR in question (through -Dos.name=, -Dos.arch=, etc.). A possible way to avoid tampering with the application parameters is by querying the RuntimeMXBean as shown here. The following code snippet should provide some insight into how this may be achieved.
 
An OS-dependent Java app seems completely contrary to the point of Java :)

Probably one of the easiest workarounds is to patch the OpenJDK and build your own version, so it reports the OS name and version as Linux 5.10 or something no matter what.

Alternatives might include trying to binary-patch the class files so they accept FreeBSD, running in a Linux jail*, or patching the FreeBSD kernel so it claims to be Linux.

* If the app is looking for Linux so that it can run JNIs, you may just have to go the jail route.
 
An OS-dependent Java app seems completely contrary to the point of Java :)
More likely and less obnoxious explanation: The program is actually OS dependent. For example, it might be using facilities like sysctl (on *BSD) versus the /sys file system (on Linux), or have path dependencies that can't be worked around. We have to recognize that efforts to make programs OS-independent (which includes Codasyl, POSIX, Java, ...) have reasonable well succeeded for user-level programs, but when it gets into system tasks, life is still OS dependent. So pretending that FreeBSD is Linux (with a hacked JVM or the UNAME_... environment variable override) is likely to just expose that this program won't work anyway.
 
Back
Top