diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ac438f..b5305aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,13 +10,21 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(SRC_DIR ${CMAKE_SOURCE_DIR}/src) -link_directories("${CMAKE_SOURCE_DIR}/lib") + +if(WIN32) + link_directories("${CMAKE_SOURCE_DIR}/lib") +endif() # libraries -add_subdirectory(${CMAKE_SOURCE_DIR}/includes/ReflectiveDLLInjection) +if (WIN32) + add_subdirectory(${CMAKE_SOURCE_DIR}/includes/ReflectiveDLLInjection) +endif() # modules add_subdirectory(${SRC_DIR}/libloader) add_subdirectory(${SRC_DIR}/injector) -add_subdirectory(${SRC_DIR}/libinject) +if(WIN32) + add_subdirectory(${SRC_DIR}/libinject) +endif() + add_subdirectory(${SRC_DIR}/libagent) diff --git a/includes/jvm/linux/jawt_md.h b/includes/jvm/linux/jawt_md.h new file mode 100644 index 0000000..2ba3a8e --- /dev/null +++ b/includes/jvm/linux/jawt_md.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#ifndef _JAVASOFT_JAWT_MD_H_ +#define _JAVASOFT_JAWT_MD_H_ + +#include +#include +#include "jawt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * X11-specific declarations for AWT native interface. + * See notes in jawt.h for an example of use. + */ +typedef struct jawt_X11DrawingSurfaceInfo { + Drawable drawable; + Display* display; + VisualID visualID; + Colormap colormapID; + int depth; + /* + * Since 1.4 + * Returns a pixel value from a set of RGB values. + * This is useful for paletted color (256 color) modes. + */ + int (JNICALL *GetAWTColor)(JAWT_DrawingSurface* ds, + int r, int g, int b); +} JAWT_X11DrawingSurfaceInfo; + +#ifdef __cplusplus +} +#endif + +#endif /* !_JAVASOFT_JAWT_MD_H_ */ diff --git a/includes/jvm/linux/jni_md.h b/includes/jvm/linux/jni_md.h new file mode 100644 index 0000000..6e583da --- /dev/null +++ b/includes/jvm/linux/jni_md.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#ifndef _JAVASOFT_JNI_MD_H_ +#define _JAVASOFT_JNI_MD_H_ + +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif + +#ifndef JNIEXPORT + #if (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2))) || __has_attribute(visibility) + #ifdef ARM + #define JNIEXPORT __attribute__((externally_visible,visibility("default"))) + #else + #define JNIEXPORT __attribute__((visibility("default"))) + #endif + #else + #define JNIEXPORT + #endif +#endif + +#if (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2))) || __has_attribute(visibility) + #ifdef ARM + #define JNIIMPORT __attribute__((externally_visible,visibility("default"))) + #else + #define JNIIMPORT __attribute__((visibility("default"))) + #endif +#else + #define JNIIMPORT +#endif + +#define JNICALL + +typedef int jint; +#ifdef _LP64 +typedef long jlong; +#else +typedef long long jlong; +#endif + +typedef signed char jbyte; + +#endif /* !_JAVASOFT_JNI_MD_H_ */ diff --git a/src/injector/CMakeLists.txt b/src/injector/CMakeLists.txt index 135f0dd..e5c2c6d 100644 --- a/src/injector/CMakeLists.txt +++ b/src/injector/CMakeLists.txt @@ -1,2 +1,6 @@ # injector -add_executable(injector injector.c) +if(WIN32) + add_executable(injector injector.c) +else() + add_executable(injector injector_linux.c) +endif() diff --git a/src/injector/injector_linux.c b/src/injector/injector_linux.c new file mode 100644 index 0000000..2ca06ff --- /dev/null +++ b/src/injector/injector_linux.c @@ -0,0 +1,4 @@ +int main(int argc, char *argv[]) { + // TODO: Implement Linux injector + return 0; +} \ No newline at end of file diff --git a/src/libagent/CMakeLists.txt b/src/libagent/CMakeLists.txt index 5ae9e94..e32a4cb 100644 --- a/src/libagent/CMakeLists.txt +++ b/src/libagent/CMakeLists.txt @@ -10,11 +10,17 @@ add_library(agent SHARED ${agent_sources}) target_include_directories(agent PRIVATE ${CMAKE_SOURCE_DIR}/includes ${CMAKE_SOURCE_DIR}/includes/jvm - ${CMAKE_SOURCE_DIR}/includes/jvm/win32 ${CMAKE_CURRENT_SOURCE_DIR}/includes ) -target_link_libraries(agent PRIVATE - ReflectiveDLLInjection - jvm -) \ No newline at end of file +if(WIN32) + target_include_directories(agent PRIVATE + ${CMAKE_SOURCE_DIR}/includes/jvm/win32 + ) + + target_link_libraries(agent PRIVATE jvm) +else() + target_include_directories(agent PRIVATE + ${CMAKE_SOURCE_DIR}/includes/jvm/linux + ) +endif() \ No newline at end of file diff --git a/src/libloader/CMakeLists.txt b/src/libloader/CMakeLists.txt index 6845124..ded398f 100644 --- a/src/libloader/CMakeLists.txt +++ b/src/libloader/CMakeLists.txt @@ -12,6 +12,15 @@ if (WIN32) ) list(APPEND loader_sources ${windows_sources}) +else() + message(STATUS "Detected System: Linux or Other") + + file(GLOB_RECURSE linux_sources CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/platform/linux/*.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/platform/linux/*.c + ) + + list(APPEND loader_sources ${linux_sources}) endif() add_library(loader SHARED ${loader_sources}) @@ -27,11 +36,17 @@ endif() target_include_directories(loader PRIVATE ${CMAKE_SOURCE_DIR}/includes ${CMAKE_SOURCE_DIR}/includes/jvm - ${CMAKE_SOURCE_DIR}/includes/jvm/win32 ${CMAKE_CURRENT_SOURCE_DIR}/includes ) -target_link_libraries(loader PRIVATE - jvm - ReflectiveDLLInjection -) \ No newline at end of file +if(WIN32) + target_include_directories(loader PRIVATE + ${CMAKE_SOURCE_DIR}/includes/jvm/win32 + ) + + target_link_libraries(loader PRIVATE jvm) +else() + target_include_directories(loader PRIVATE + ${CMAKE_SOURCE_DIR}/includes/jvm/linux + ) +endif() \ No newline at end of file