Exemplo n.º 1
0
BOOL Initialize(PVOID BaseAddress)
{
    if (NT_FAILED(CheckIsExplorer()))
        return FALSE;

    AllocConsole();

//    PrintConsoleW(L"session id %d\n", GetCurrentSessionId());
/*
    if (CurrentPeb()->OSMajorVersion > 5)
    switch (GetCurrentSessionId())
    {
        case 0:
        case INVALID_SESSION_ID:
            return FALSE;
    }
*/

    LdrDisableThreadCalloutsForDll(BaseAddress);
    LdrAddRefDll(LDR_ADDREF_DLL_PIN, BaseAddress);
    Ps::CreateThread(
        ThreadLambdaType_(PVOID)
        {
            return HookCallCreateProcess();
        },
        nullptr
    );
Exemplo n.º 2
0
Arquivo: main.c Projeto: Eltechs/wine
/*********************************************************************
 *                  Init
 */
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
  TRACE("(%p, %s, %p) pid(%x), tid(%x), tls(%u)\n",
        hinstDLL, msvcrt_get_reason(fdwReason), lpvReserved,
        GetCurrentProcessId(), GetCurrentThreadId(),
        msvcrt_tls_index);

  switch (fdwReason)
  {
  case DLL_PROCESS_ATTACH:
    msvcrt_init_exception(hinstDLL);
    if (!msvcrt_init_tls())
      return FALSE;
    msvcrt_init_mt_locks();
    if(!msvcrt_init_locale()) {
        msvcrt_free_mt_locks();
        msvcrt_free_tls_mem();
        return FALSE;
    }
    msvcrt_init_math();
    msvcrt_init_io();
    msvcrt_init_console();
    msvcrt_init_args();
    msvcrt_init_signals();
#if _MSVCR_VER == 0
    /* don't allow unloading msvcrt, we can't setup file handles twice */
    LdrAddRefDll( LDR_ADDREF_DLL_PIN, hinstDLL );
#elif _MSVCR_VER >= 80
    MSVCRT__set_printf_count_output(0);
#endif
    TRACE("finished process init\n");
    break;
  case DLL_THREAD_ATTACH:
    break;
  case DLL_PROCESS_DETACH:
    msvcrt_free_io();
    if (lpvReserved) break;
    msvcrt_free_popen_data();
    msvcrt_free_mt_locks();
    msvcrt_free_console();
    msvcrt_free_args();
    msvcrt_free_signals();
    msvcrt_free_tls_mem();
    if (!msvcrt_free_tls())
      return FALSE;
    MSVCRT__free_locale(MSVCRT_locale);
    TRACE("finished process free\n");
    break;
  case DLL_THREAD_DETACH:
    msvcrt_free_tls_mem();
    TRACE("finished thread free\n");
    break;
  }
  return TRUE;
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: dvdhoo/wine
/*********************************************************************
 *                  Init
 */
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
  TRACE("(%p, %s, %p) pid(%x), tid(%x), tls(%u)\n",
        hinstDLL, msvcrt_get_reason(fdwReason), lpvReserved,
        GetCurrentProcessId(), GetCurrentThreadId(),
        msvcrt_tls_index);

  switch (fdwReason)
  {
  case DLL_PROCESS_ATTACH:
    if (!msvcrt_init_tls())
      return FALSE;
    msvcrt_init_mt_locks();
    if(!MSVCRT_setlocale(0, "C")) {
        msvcrt_free_mt_locks();
        msvcrt_free_tls_mem();
        return FALSE;
    }
    msvcrt_init_math();
    msvcrt_init_io();
    msvcrt_init_console();
    msvcrt_init_args();
    msvcrt_init_signals();
    _setmbcp(_MB_CP_LOCALE);
    /* don't allow unloading msvcrt, we can't setup file handles twice */
    LdrAddRefDll( 0, hinstDLL );
    TRACE("finished process init\n");
    break;
  case DLL_THREAD_ATTACH:
    break;
  case DLL_PROCESS_DETACH:
    msvcrt_free_mt_locks();
    msvcrt_free_io();
    msvcrt_free_console();
    msvcrt_free_args();
    msvcrt_free_signals();
    msvcrt_free_tls_mem();
    if (!msvcrt_free_tls())
      return FALSE;
    MSVCRT__free_locale(MSVCRT_locale);
    TRACE("finished process free\n");
    break;
  case DLL_THREAD_DETACH:
    msvcrt_free_tls_mem();
    TRACE("finished thread free\n");
    break;
  }
  return TRUE;
}
Exemplo n.º 4
0
BOOL InitializeNetapi32()
{
    PVOID           module;
    NTSTATUS        Status;
    PLDR_MODULE     Self, Netapi32;
    UNICODE_STRING  SystemRoot;
    PVOID           LoaderLockCookie;

    LdrLockLoaderLock(0, nullptr, &LoaderLockCookie);
    SCOPE_EXIT
    {
        LdrUnlockLoaderLock(0, LoaderLockCookie);
    }
    SCOPE_EXIT_END;

    Self = FindLdrModuleByHandle(&__ImageBase);

    if (Self == nullptr || Self->DllBase != &__ImageBase)
        return TRUE;

    Status = Rtl::GetSystemDirectory(&SystemRoot);
    if (NT_FAILED(Status))
        return 0;

    module = Ldr::LoadDll(String(SystemRoot) + L"wtsapi32.dll");
    RtlFreeUnicodeString(&SystemRoot);

    LdrAddRefDll(LDR_ADDREF_DLL_PIN, module);

    *(PVOID *)&StubWTSFreeMemory                    = GetRoutineAddress(module, "WTSFreeMemory");
    *(PVOID *)&StubWTSQuerySessionInformationW      = GetRoutineAddress(module, "WTSQuerySessionInformationW");
    *(PVOID *)&StubWTSRegisterSessionNotification   = GetRoutineAddress(module, "WTSRegisterSessionNotification");
    *(PVOID *)&StubWTSUnRegisterSessionNotification = GetRoutineAddress(module, "WTSUnRegisterSessionNotification");

    Netapi32 = FindLdrModuleByHandle(module);

    //RemoveEntryList(&Self->InLoadOrderLinks);
    //RemoveEntryList(&Self->InMemoryOrderLinks);
    //RemoveEntryList(&Self->InInitializationOrderLinks);

    //RtlFreeHeap(CurrentPeb()->ProcessHeap, 0, Self);

    Self->DllBase       = Netapi32->DllBase;
    Self->EntryPoint    = Netapi32->EntryPoint;
    Self->SizeOfImage   = Netapi32->SizeOfImage;

    return TRUE;
}
Exemplo n.º 5
0
BOOL InitializeNetapi32()
{
    PVOID           module;
    NTSTATUS        Status;
    PLDR_MODULE     Self, Netapi32;
    UNICODE_STRING  SystemRoot;

    if (StubNetbios != nullptr)
        return TRUE;

    Status = Rtl::GetSystemDirectory(&SystemRoot);
    if (NT_FAILED(Status))
        return 0;

    module = Ldr::LoadDll(ml::String(SystemRoot) + L"netapi32.dll");
    RtlFreeUnicodeString(&SystemRoot);

    LdrAddRefDll(LDR_ADDREF_DLL_PIN, module);

    *(PVOID *)&StubNetbios                  = GetRoutineAddress(module, "Netbios");
    *(PVOID *)&StubNetApiBufferFree         = GetRoutineAddress(module, "NetApiBufferFree");
    *(PVOID *)&StubNetWkstaTransportEnum    = GetRoutineAddress(module, "NetWkstaTransportEnum");
    *(PVOID *)&StubNetWkstaUserGetInfo      = GetRoutineAddress(module, "NetWkstaUserGetInfo");

    Self = FindLdrModuleByHandle(&__ImageBase);
    Netapi32 = FindLdrModuleByHandle(module);

    //RemoveEntryList(&Self->InLoadOrderLinks);
    //RemoveEntryList(&Self->InMemoryOrderLinks);
    //RemoveEntryList(&Self->InInitializationOrderLinks);

    //RtlFreeHeap(CurrentPeb()->ProcessHeap, 0, Self);

    Self->DllBase       = Netapi32->DllBase;
    Self->EntryPoint    = Netapi32->EntryPoint;
    Self->SizeOfImage   = Netapi32->SizeOfImage;

    return TRUE;
}
Exemplo n.º 6
0
/* load the graphics driver */
static const USER_DRIVER *load_driver(void)
{
    static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
    HDC hdc;
    void *ptr;
    HMODULE graphics_driver;
    USER_DRIVER *driver, *prev;

    driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver) );
    *driver = null_driver;

    hdc = CreateDCW( displayW, NULL, NULL, NULL );

    graphics_driver = __wine_get_driver_module( hdc );
    if (graphics_driver)
    {
#define GET_USER_FUNC(name) \
    do { if ((ptr = GetProcAddress( graphics_driver, #name ))) driver->p##name = ptr; } while(0)

        GET_USER_FUNC(ActivateKeyboardLayout);
        GET_USER_FUNC(Beep);
        GET_USER_FUNC(GetAsyncKeyState);
        GET_USER_FUNC(GetKeyNameText);
        GET_USER_FUNC(GetKeyboardLayout);
        GET_USER_FUNC(GetKeyboardLayoutName);
        GET_USER_FUNC(LoadKeyboardLayout);
        GET_USER_FUNC(MapVirtualKeyEx);
        GET_USER_FUNC(RegisterHotKey);
        GET_USER_FUNC(ToUnicodeEx);
        GET_USER_FUNC(UnloadKeyboardLayout);
        GET_USER_FUNC(UnregisterHotKey);
        GET_USER_FUNC(VkKeyScanEx);
        GET_USER_FUNC(CreateCursorIcon);
        GET_USER_FUNC(DestroyCursorIcon);
        GET_USER_FUNC(SetCursor);
        GET_USER_FUNC(GetCursorPos);
        GET_USER_FUNC(SetCursorPos);
        GET_USER_FUNC(ClipCursor);
        GET_USER_FUNC(GetScreenSaveActive);
        GET_USER_FUNC(SetScreenSaveActive);
        GET_USER_FUNC(AcquireClipboard);
        GET_USER_FUNC(EmptyClipboard);
        GET_USER_FUNC(SetClipboardData);
        GET_USER_FUNC(GetClipboardData);
        GET_USER_FUNC(CountClipboardFormats);
        GET_USER_FUNC(EnumClipboardFormats);
        GET_USER_FUNC(IsClipboardFormatAvailable);
        GET_USER_FUNC(EndClipboardUpdate);
        GET_USER_FUNC(ChangeDisplaySettingsEx);
        GET_USER_FUNC(EnumDisplayMonitors);
        GET_USER_FUNC(EnumDisplaySettingsEx);
        GET_USER_FUNC(GetMonitorInfo);
        GET_USER_FUNC(CreateDesktopWindow);
        GET_USER_FUNC(CreateWindow);
        GET_USER_FUNC(DestroyWindow);
        GET_USER_FUNC(GetDC);
        GET_USER_FUNC(MsgWaitForMultipleObjectsEx);
        GET_USER_FUNC(ReleaseDC);
        GET_USER_FUNC(ScrollDC);
        GET_USER_FUNC(SetCapture);
        GET_USER_FUNC(SetFocus);
        GET_USER_FUNC(SetLayeredWindowAttributes);
        GET_USER_FUNC(SetParent);
        GET_USER_FUNC(SetWindowRgn);
        GET_USER_FUNC(SetWindowIcon);
        GET_USER_FUNC(SetWindowStyle);
        GET_USER_FUNC(SetWindowText);
        GET_USER_FUNC(ShowWindow);
        GET_USER_FUNC(SysCommand);
        GET_USER_FUNC(UpdateLayeredWindow);
        GET_USER_FUNC(WindowMessage);
        GET_USER_FUNC(WindowPosChanging);
        GET_USER_FUNC(WindowPosChanged);
#undef GET_USER_FUNC
    }
    else driver_load_error = GetLastError();

    prev = InterlockedCompareExchangePointer( (void **)&USER_Driver, driver, &lazy_load_driver );
    if (prev != &lazy_load_driver)
    {
        /* another thread beat us to it */
        HeapFree( GetProcessHeap(), 0, driver );
        driver = prev;
    }
    else LdrAddRefDll( 0, graphics_driver );

    DeleteDC( hdc );
    return driver;
}
Exemplo n.º 7
0
/* load the graphics driver */
static const USER_DRIVER *load_driver(void)
{
    void *ptr;
    HMODULE graphics_driver;
    USER_DRIVER *driver, *prev;

    driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver) );
    *driver = null_driver;

    graphics_driver = load_desktop_driver( GetDesktopWindow() );
    if (graphics_driver)
    {
#define GET_USER_FUNC(name) \
    do { if ((ptr = GetProcAddress( graphics_driver, #name ))) driver->p##name = ptr; } while(0)

        GET_USER_FUNC(ActivateKeyboardLayout);
        GET_USER_FUNC(Beep);
        GET_USER_FUNC(GetAsyncKeyState);
        GET_USER_FUNC(GetKeyNameText);
        GET_USER_FUNC(GetKeyboardLayout);
        GET_USER_FUNC(GetKeyboardLayoutList);
        GET_USER_FUNC(GetKeyboardLayoutName);
        GET_USER_FUNC(LoadKeyboardLayout);
        GET_USER_FUNC(MapVirtualKeyEx);
        GET_USER_FUNC(RegisterHotKey);
        GET_USER_FUNC(ToUnicodeEx);
        GET_USER_FUNC(UnloadKeyboardLayout);
        GET_USER_FUNC(UnregisterHotKey);
        GET_USER_FUNC(VkKeyScanEx);
        GET_USER_FUNC(DestroyCursorIcon);
        GET_USER_FUNC(SetCursor);
        GET_USER_FUNC(GetCursorPos);
        GET_USER_FUNC(SetCursorPos);
        GET_USER_FUNC(ClipCursor);
        GET_USER_FUNC(UpdateClipboard);
        GET_USER_FUNC(ChangeDisplaySettingsEx);
        GET_USER_FUNC(EnumDisplayMonitors);
        GET_USER_FUNC(EnumDisplaySettingsEx);
        GET_USER_FUNC(GetMonitorInfo);
        GET_USER_FUNC(CreateDesktopWindow);
        GET_USER_FUNC(CreateWindow);
        GET_USER_FUNC(DestroyWindow);
        GET_USER_FUNC(FlashWindowEx);
        GET_USER_FUNC(GetDC);
        GET_USER_FUNC(MsgWaitForMultipleObjectsEx);
        GET_USER_FUNC(ReleaseDC);
        GET_USER_FUNC(ScrollDC);
        GET_USER_FUNC(SetCapture);
        GET_USER_FUNC(SetFocus);
        GET_USER_FUNC(SetLayeredWindowAttributes);
        GET_USER_FUNC(SetParent);
        GET_USER_FUNC(SetWindowRgn);
        GET_USER_FUNC(SetWindowIcon);
        GET_USER_FUNC(SetWindowStyle);
        GET_USER_FUNC(SetWindowText);
        GET_USER_FUNC(ShowWindow);
        GET_USER_FUNC(SysCommand);
        GET_USER_FUNC(UpdateLayeredWindow);
        GET_USER_FUNC(WindowMessage);
        GET_USER_FUNC(WindowPosChanging);
        GET_USER_FUNC(WindowPosChanged);
        GET_USER_FUNC(SystemParametersInfo);
        GET_USER_FUNC(ThreadDetach);
#undef GET_USER_FUNC
    }

    prev = InterlockedCompareExchangePointer( (void **)&USER_Driver, driver, &lazy_load_driver );
    if (prev != &lazy_load_driver)
    {
        /* another thread beat us to it */
        HeapFree( GetProcessHeap(), 0, driver );
        driver = prev;
    }
    else LdrAddRefDll( 0, graphics_driver );

    __wine_set_display_driver( graphics_driver );
    register_builtin_classes();

    return driver;
}