0

I tried to change value of gHotSpotVMStructs to 0 to prevent using HotSpot Debugger but while i tried to compile my code - my compiler thrown an error

CMakeFiles\JavaHotspotAttachCrasher.dir/objects.a(library.cpp.obj):library.cpp:(.rdata$.refptr.gHotSpotVMStructs[.refptr.gHotSpotVMStructs]+0x0): undefined reference to gHotSpotVMStructs
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\JavaHotspotAttachCrasher.dir\build.make:96: libJavaHotspotAttachCrasher.dll] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:110: CMakeFiles/JavaHotspotAttachCrasher.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:117: CMakeFiles/JavaHotspotAttachCrasher.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:136: JavaHotspotAttachCrasher] Error 2

My CMAKE file

cmake_minimum_required(VERSION 3.20)
project(JavaHotspotAttachCrasher)

set(CMAKE_CXX_FLAGS "-s -O3")
set(CMAKE_CXX_STANDARD 14)

include_directories("C:/Program Files/Java/jdk1.8.0_311/jre/bin/server")

add_library(SecretLib SHARED "C:/Program Files/Java/jdk1.8.0_311/jre/bin/server/jvm.dll")
set_target_properties(SecretLib PROPERTIES LINKER_LANGUAGE CXX)


add_library(JavaHotspotAttachCrasher SHARED library.cpp)

target_link_libraries(JavaHotspotAttachCrasher SecretLib)

My C++ file

#include <iostream>
extern void *gHotSpotVMStructs;

void hello() {
    std::cout << "Disabled gHotSpot" << std::endl;
    gHotSpotVMStructs = 0;
}

Any ideas how to compile it?

Kaspek
  • 159
  • 1
  • 11
  • According to your code, you intended to make library `SecretLib` target to reflect the **external library** `C:/Program Files/Java/jdk1.8.0_311/jre/bin/server/jvm.dll`, but you actually defined an empty library. Needing to set `LINKER_LANGUAGE` property should signal you that something goes wrong, but you ignored that signal. The library needs to be `IMPORTED`. See duplicate question and its answers for more details. – Tsyvarev Mar 26 '22 at 09:32
  • @Tsyvarev i added that and i got an error ```# Your-external "mylib", add GLOBAL if the imported library is located in directories above the current. add_library(mylib SHARED IMPORTED) # You can define two import-locations: one for debug and one for release. set_target_properties(mylib PROPERTIES IMPORTED_LOCATION "C:/Program Files/Java/jdk1.8.0_311/jre/bin/server/jvm.dll") TARGET_LINK_LIBRARIES(JavaHotspotAttachCrasher mylib)``` Error: `CMake Error in CMakeLists.txt: IMPORTED_IMPLIB not set for imported target "mylib" configuration "Debug".` – Kaspek Mar 26 '22 at 09:36
  • On Windows you cannot directly link with `.dll` file. You need to link with `.lib` file, which represents "import library". See e.g. that question: https://stackoverflow.com/questions/7845886/linking-dll-in-visual-studio – Tsyvarev Mar 26 '22 at 09:40
  • @Tsyvarev but how i can use then jvm.dll I tried to use that method: [link](https://stackoverflow.com/questions/48056863/disable-classdump-to-a-running-jvm-process-by-using-sa-jli) nvm solved – Kaspek Mar 26 '22 at 09:45
  • But the [referenced answer](https://stackoverflow.com/a/48066590/3440745) doesn't link with `jvm.dll`. You could create your library `JavaHotspotAttachCrasher` as MODULE (instead of SHARED): for such libraries undefined symbols are not checked. Note also, that referenced answer creates C library (not C++) and uses `-nostdlib` flag to not link with the standard library. – Tsyvarev Mar 26 '22 at 09:53

0 Answers0