aboutsummaryrefslogtreecommitdiff
path: root/nosession_libc
diff options
context:
space:
mode:
Diffstat (limited to 'nosession_libc')
-rw-r--r--nosession_libc/build.gradle.kts60
-rw-r--r--nosession_libc/src/main/cpp/libc.cpp31
-rw-r--r--nosession_libc/src/main/cpp/libc.h29
3 files changed, 120 insertions, 0 deletions
diff --git a/nosession_libc/build.gradle.kts b/nosession_libc/build.gradle.kts
new file mode 100644
index 0000000..0f64343
--- /dev/null
+++ b/nosession_libc/build.gradle.kts
@@ -0,0 +1,60 @@
+import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.archivesName
+
+plugins {
+ `cpp-library`
+ `java-base`
+
+}
+val lib by configurations.creating
+
+library {
+ linkage.set(listOf(Linkage.SHARED))
+}
+
+project.afterEvaluate {
+ tasks.withType(CppCompile::class) {
+ val javaHome = rootProject.the<JavaToolchainService>()
+ .compilerFor(rootProject.the<JavaPluginExtension>().toolchain)
+ .map { it.metadata.installationPath.asFile }
+ val includeDir = javaHome.map { it.resolve("include") }
+ val os = targetPlatform.get().operatingSystem
+ compilerArgs.add("-I")
+ compilerArgs.add(includeDir.map { it.absolutePath })
+ compilerArgs.add("-I")
+ compilerArgs.add(includeDir.map {
+ it.resolve(
+ when {
+ os.isMacOsX -> "darwin"
+ os.isLinux -> "linux"
+ os.isWindows -> "win32"
+ os.isFreeBSD -> "freebsd"
+ else -> TODO("Unsupported operating system")
+ }
+ ).absolutePath
+ })
+ if (os.isLinux) {
+ compilerArgs.add("-D_FILE_OFFSET_BITS=64")
+ }
+ if (os.isMacOsX) {
+ compilerArgs.add("-mmacosx-version-min=10.4")
+ }
+ }
+
+ tasks.withType(AbstractLinkTask::class) {
+ if (targetPlatform.get().operatingSystem.isMacOsX)
+ linkerArgs.add("-mmacosx-version-min=10.4")
+ }
+ val linkRelease: AbstractLinkTask by tasks
+ val archive by tasks.creating(Zip::class) {
+ archivesName.set("archive.jar")
+ destinationDirectory.set(layout.buildDirectory.dir("libs"))
+ from(linkRelease.linkedFile) {
+ val targetPlatform = linkRelease.targetPlatform.get()
+ into("native/" + when(val arch = targetPlatform.architecture.name) {
+ "x86-64" -> "amd64"
+ else -> arch
+ } + "/" +targetPlatform.operatingSystem.name)
+ }
+ }
+ artifacts.add(lib.name, archive)
+}
diff --git a/nosession_libc/src/main/cpp/libc.cpp b/nosession_libc/src/main/cpp/libc.cpp
new file mode 100644
index 0000000..060e83e
--- /dev/null
+++ b/nosession_libc/src/main/cpp/libc.cpp
@@ -0,0 +1,31 @@
+#include <jni.h>
+#include "unistd.h"
+#include <fcntl.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: gq_malwarefight_nosession_linux_libc_Libc
+ * Method: geteuid
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_gq_malwarefight_nosession_linux_libc_Libc_geteuid
+ (JNIEnv *, jclass) {
+ return (int) geteuid();
+}
+
+/*
+ * Class: gq_malwarefight_nosession_linux_libc_Libc
+ * Method: unlink
+ * Signature: (Ljava/lang/String;)I
+ */
+JNIEXPORT void JNICALL Java_gq_malwarefight_nosession_linux_libc_Libc_unlink
+ (JNIEnv* env, jclass, jstring string) {
+ const char* path = env->GetStringUTFChars(string, NULL);
+ unlink(path);
+ env->ReleaseStringUTFChars(string, path);
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/nosession_libc/src/main/cpp/libc.h b/nosession_libc/src/main/cpp/libc.h
new file mode 100644
index 0000000..6aaa1a6
--- /dev/null
+++ b/nosession_libc/src/main/cpp/libc.h
@@ -0,0 +1,29 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class gq_malwarefight_nosession_linux_libc_Libc */
+
+#ifndef _Included_gq_malwarefight_nosession_linux_libc_Libc
+#define _Included_gq_malwarefight_nosession_linux_libc_Libc // NOLINT(bugprone-reserved-identifier)
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: gq_malwarefight_nosession_linux_libc_Libc
+ * Method: geteuid
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_gq_malwarefight_nosession_linux_libc_Libc_geteuid
+ (JNIEnv *, jclass);
+
+/*
+ * Class: gq_malwarefight_nosession_linux_libc_Libc
+ * Method: unlink
+ * Signature: (Ljava/lang/String;)
+ */
+JNIEXPORT void JNICALL Java_gq_malwarefight_nosession_linux_libc_Libc_unlink
+ (JNIEnv *, jclass, jstring);
+
+#ifdef __cplusplus
+}
+#endif
+#endif