0

I am trying to compile xmrig as a dll file, i compile it correctly as an executable downloading the source from here . For compiling it to dll, I use cmake and run these commands similarly to what i do for executable .exe here.

Dll commands:

cmake .. -G "Visual Studio 15 2017" -A x64 -DXMRIG_DEPS=c:\xmrig-deps\msvc2017\x64 -DBUILD_SHARED_LIBS=TRUE
cmake --build . --config Release

I also changed the name of the add_executable()function in cmakelists.txt to add_library()for compiling as a dll.

In my dll, i have this source code, that i downloaded from the source , i only modifed the xmrig.cpp file before running the cmake commands to compile as a dll.

extern "C"{
  __declspec(dllexport) void some();
}

void some(){

    using namespace xmrig;

    char **argvPass;
    //argvPass[0] = "deneme.exe";
    int argcPass = 1;   

    Process process(argcPass, argvPass);

    const Entry::Id entry = Entry::get(process);
    if (entry) {
        Entry::exec(process, entry);
    }

    App app(&process);

    int x = app.exec();

}

My question is, it successfully compiles the dll file and i get xmrig.dll, i load the dll file using, LoadLibrary() and i call the some() function above (which is a modification of xmrig.cpp from the source), the dllloader loads the function, but on the line Process process(argcPass, argvPass); it seems to crash, this happens during runtime of the dll. For more illustration, i will put the dll loader.cpp here:

int main() {
  HINSTANCE hGetProcIDDLL = LoadLibrary("xmrig.dll");

  if (hGetProcIDDLL == NULL) {
    std::cout << "cannot locate the .dll file" << std::endl;
  } else {
    std::cout << "it has been called" << std::endl;
    
  }
  
   
  FARPROC xf = GetProcAddress(hGetProcIDDLL, "some");
if(GetProcAddress(hGetProcIDDLL, "printer") == NULL){
    
}else{
    std::cout <<"not null" << std::endl;
}

    std::cout << GetLastError() << " err" << std::endl;
    
    
    xf();
    //getchar();
    //return 0;
}

As the executable runs fine with the exact same code, what could be the reason that it crashes at that line? Could it be the arguments that i am passing through the Process::Process() function. Can someone please confirm me with this trying to get this done? The dll is very much needed on our side and i would appreciate any kind of help..

Moreover, why does the function fail, maybe it could be due to my Visual Studio version, or due to the arguemnts being passed through, i really want to know. Thank you

3
  • 1
    Leaving aside the question of why you'd even want/need the miner as a DLL, you probably get a crash simply because you are passing an uninitialized array (argvPass) to the Process constructor and stating it has 1 element (argcPass = 1).
    – jtgrassie
    Feb 2, 2021 at 7:13
  • @jtgrassie i have reasons Feb 2, 2021 at 7:35
  • it got fixed, and that was the reason why it crashed @jtgrassie Feb 2, 2021 at 7:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.