blob: 670f83d04f03b99431c5887539d5d6ab6b6a0d44 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);
}
}
}
|