aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java')
-rw-r--r--src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java b/src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java
new file mode 100644
index 0000000..670f83d
--- /dev/null
+++ b/src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java
@@ -0,0 +1,31 @@
+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);
+ }
+ }
+}