Exemplo n.º 1
0
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved )
{
  BOOL	  bResult = TRUE;
  PHookFn hook;
  LPSTR   name;

  if (dwReason == DLL_PROCESS_ATTACH)
  {
#if defined(_WIN64) || defined(W32ON64)
    hDllNameType = hDllName - 6 +
#endif
    GetModuleFileName( hInstance, hDllName, lenof(hDllName) );

    hDllInstance = hInstance; // save Dll instance handle

    // Don't hook WriteFile in errout.exe (static load).
    name = Hooks[lenof(Hooks)-2].name;
    if (lpReserved != NULL)
      Hooks[lenof(Hooks)-2].name = NULL;

    // Get the entry points to the original functions.
    hKernel = GetModuleHandleA( APIKernel );
    for (hook = Hooks; hook->name; ++hook)
      hook->oldfunc = GetProcAddress( hKernel, hook->name );

    bResult = HookAPIAllMod( Hooks, FALSE );
    DisableThreadLibraryCalls( hInstance );

    Hooks[lenof(Hooks)-2].name = name;

#ifdef W32ON64
    if (global.hStdOut == NULL)
      CopyGlobals();
#endif
  }
  else if (dwReason == DLL_PROCESS_DETACH)
  {
    // Unhook if it's being unloaded, but not if the process is exiting.
    if (lpReserved == NULL)
      HookAPIAllMod( Hooks, TRUE );
  }

  return( bResult );
}
Exemplo n.º 2
0
void Console::InitEnv()
{
    lua_State *state = GetScripting()->GetState();

    // Start with the standard global environment.
    CopyGlobals();

    lua_pushlightuserdata(state, this);  // table this
    lua_pushcclosure(state, Console::LClear, 1);  // table fn
    lua_pushstring(state, "clear");  // table fn str
    lua_insert(state, -2);  // table str fn
    lua_rawset(state, -3);  // table

    /*
    lua_pushlightuserdata(state, this);
    lua_pushcclosure(state, Console::LReset, 1);
    lua_setglobal(state, "reset");

    lua_pushlightuserdata(state, this);
    lua_pushcclosure(state, Console::LSandbox, 1);
    lua_setglobal(state, "sandbox");
    */
}