Git Product home page Git Product logo

Comments (4)

SergiusTheBest avatar SergiusTheBest commented on August 12, 2024

Hi @mdevans

It's very interesting. Could you provide a complete code sample? Or at least describe when do you call plog::init and what compiler do you use?

from plog.

mdevans avatar mdevans commented on August 12, 2024

Thanks for your response @SergiusTheBest . I am using VS2015 C++ compiler. I am using the complex reflective dll injection technique as described by Dan Staples here: https://github.com/dismantl/ImprovedReflectiveDLLInjection. If you call plog::init within his "MyFunction()" (delayed dll init after dllmain()) the problem occurs. If I use standard injection technique using LoadLibrary() and CreateRemoteThread() plog::init works ok. I expect there is something in the way the image is loaded by ReflectiveLoader() which is omitting some critical init code? (nUserdataLen is 0 within MyFunction, a bug I haven't tracked down yet).

#include "ReflectiveLoader.h"
#include <stdio.h>
#include "plog\Log.h"

extern "C" DLLEXPORT BOOL
MyFunction(LPVOID lpUserdata, DWORD nUserdataLen)
{
    LPSTR str = (LPSTR)malloc(80 + nUserdataLen);

    sprintf_s(str, 80 + nUserdataLen, "Hello from MyFunction: %s!", (char*)lpUserdata);
    MessageBoxA(NULL, str, (LPCSTR)lpUserdata, MB_OK);

    plog::init(plog::verbose, "MDETEST.LOG"); 

    if (!plog::get<0>())
        OutputDebugString(L"Nope");
    else
        OutputDebugString(L"Yes");

    free(str);
    return TRUE;
}

from plog.

SergiusTheBest avatar SergiusTheBest commented on August 12, 2024

I did a little research and found out:

  1. VS2015 implements thread-safe static variables initialization with the help of a thread-local storage (TLS).
  2. ReflectiveLoader doesn't process TLS callbacks in the DLL image.

As the result constructors of static variables are not called.

Workaround: Use /Zc:threadSafeInit- compiler switch to turn off thread-safe static variables initialization.

from plog.

mdevans avatar mdevans commented on August 12, 2024

Fascinating... thank-you very much Sergius, makes complete sense now. (switch works btw)

from plog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.