package gq.malwarefight.nosession.linux.libc; import gq.malwarefight.nosession.utils.Utils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.File; import java.io.InputStream; import java.nio.file.Files; public class Libc { private static final Logger log = LogManager.getLogger(); public static native int geteuid(); public static native void unlink(String pathname); static { try { File tempFile = Files.createTempFile("nosession_libc", ".so").toFile(); try (InputStream is = Libc.class.getResourceAsStream("/native/" + System.getProperty("os.arch") + "/" + System.getProperty("os.name") + "/" + System.mapLibraryName("linux"))) { assert is != null: "Native library not compiled"; Utils.copy(is, Files.newOutputStream(tempFile.toPath())); } System.load(tempFile.getAbsolutePath()); Runtime.getRuntime().addShutdownHook( new Thread(() -> Libc.unlink(tempFile.getAbsolutePath())) ); } catch (Exception e) { log.error("Failed to load the native Linux modules, native libraries may fail", e); } } }