Author Topic: Trigger Screenshot in nwmain  (Read 2084 times)

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Trigger Screenshot in nwmain
« Reply #15 on: May 14, 2014, 10:36:48 pm »


               Thanks Virusman:
Got it working

finished code is as follows



                Screenshot screenshot = WhiteMagic.Magic.Instance.RegisterDelegate<Screenshot>(0x004269A0);
                RhunDownloader.Memory m = new RhunDownloader.Memory("nwmain");
                uint uPointVal = (uint)m.ReadPointer(0x0092DC50);
                uPointVal = (uint)m.ReadPointer(uPointVal);
                uPointVal += 0x4;
                uPointVal = (uint)m.ReadPointer(uPointVal);
                screenshot(uPointVal, 0x5E, 0x80, 0);
                m.Dispose();

               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Trigger Screenshot in nwmain
« Reply #16 on: May 15, 2014, 01:23:04 am »


               Thanks for the help.
I managed to get my PW Server to now actually trigger Screenshots inside my players Neverwinter Client.
These are then uploaded to our PW Community Facebook page.

The architecture is like this.

Our PW Server has ability to invoke C# Code through nwnx_dotnet
It attempts to make a TCP Connection to the IP Address of a player (if they have upnp routers, or have port forwarding, it should work) Its connecting to a program that my players use to sync the music and resources for the server.
When it connects, it sends a message requesting a screenshot.

Before this however, when nwmain was first started: a c++ bootstrapper DLL was injected from our downloader app, which starts the .net framework within the nwmain process.
This then starts the actual DLL we are using 'RhunDLL.dll'

This is the one that contains the Screenshot functionality.

When a network request comes from our server, and if it manages to get to our Downloader app (which does the injection) - it then triggers the screenshot, and any screenshots for our Server is automatically transferred to our central server, where they are then uploaded to facebook (to a specific album)

I've given it a test run, and now I am just waiting for my players to beta test it.
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Trigger Screenshot in nwmain
« Reply #17 on: May 17, 2014, 02:42:26 pm »


               Hey Virusman,
Did you ever have compatibility issues with DLL Injection across windows xp and more recent OS's?

I have one player who is using Windows XP, but my Bootstrapper DLL crashes his Game Client.
 
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReeserved)
{
   
   switch (ul_reason_for_call)
   {
   case DLL_PROCESS_ATTACH:
      CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartDotNet, 0, 0, NULL);
      break;
   case DLL_THREAD_ATTACH:
   //   CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartDotNet, 0, 0, NULL);
      break;
   case DLL_THREAD_DETACH:
   case DLL_PROCESS_DETACH:
      break;
   }
   test = "loaded";
   
   return TRUE;
}


void StartDotNet()
{

   HRESULT hr;
   ICLRRuntimeHost *pClrHost = NULL;
   ICLRMetaHost *pMetaHost = NULL;
   hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*)&pMetaHost);
   //MessageBox(NULL, L"CLRCreateInstance Done.", NULL, NULL);

   ICLRRuntimeInfo * lpRuntimeInfo = NULL;

   
   hr = pMetaHost->GetRuntime(L"v4.0.30319", IID_ICLRRuntimeInfo, (LPVOID*)&lpRuntimeInfo);
   
   //MessageBox(NULL, L"pMetaHost->GetRuntime Done.", NULL, NULL);

   ICLRRuntimeHost * lpRuntimeHost = NULL;

   hr = lpRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID *)&lpRuntimeHost);
   //MessageBox(NULL, L"lpRuntimeInfo->GetInterface Done.", NULL, NULL);

   hr = lpRuntimeHost->Start();
   //MessageBox(NULL, L"lpRuntimeHost->Start() Done.", NULL, NULL);

   DWORD dwRet = 0;


   hr = lpRuntimeHost->ExecuteInDefaultAppDomain(
      L"RhunDLL.dll",
      L"Inject.MainClass", L"DLLMain", L"Injection Worked", &dwRet);

   

   lpRuntimeHost->Release();

}



He has .Net4 installed, and Visual C++ 2010 Redist

I installed a VirtualBox vm with xp, and confirmed the crash.
CreateThread seems to be working for Windows 7, should I be using CreateRemoteThread instead? or Is there something specific to be done for Windows XP compatibility?



Just double checked
Using RemoteThread in the .net code that actually injects the Bootstrapper.


bool bInject(uint pToBeInjected, string sDllPath)
        {
            IntPtr hndProc = OpenProcess((0x2 | 0x8 | 0x10 | 0x20 | 0x400), 1, pToBeInjected);

            if (hndProc == INTPTR_ZERO)
            {
                return false;
            }

            IntPtr lpLLAddress = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");

            if (lpLLAddress == INTPTR_ZERO)
            {
                return false;
            }

            IntPtr lpAddress = VirtualAllocEx(hndProc, (IntPtr)null, (IntPtr)sDllPath.Length, (0x1000 | 0x2000), 0X40);

            if (lpAddress == INTPTR_ZERO)
            {
                return false;
            }

            byte[] bytes = Encoding.ASCII.GetBytes(sDllPath);

            if (WriteProcessMemory(hndProc, lpAddress, bytes, (uint)bytes.Length, 0) == 0)
            {
                return false;
            }

            if (CreateRemoteThread(hndProc, (IntPtr)null, INTPTR_ZERO, lpLLAddress, lpAddress, 0, (IntPtr)null) == INTPTR_ZERO)
            {
                return false;
            }

            CloseHandle(hndProc);

            return true;
        }

               
               

               
            

Legacy_virusman

  • Sr. Member
  • ****
  • Posts: 448
  • Karma: +0/-0
Trigger Screenshot in nwmain
« Reply #18 on: May 18, 2014, 10:28:45 pm »


               

Where does it crash? Can you pinpoint the exact place? Is it .net part or the memory modification?



               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Trigger Screenshot in nwmain
« Reply #19 on: May 18, 2014, 10:45:54 pm »


               Strange- I recompiled everything, and the Crash seems to have stopped.
The techical information from the error report was reporting that the bootstrapper dll was loaded correctly.
But there was no RhunDLL.dll present in the module list - suggesting that the .Net dll was not correctly loaded.

In anycase- the error seems to have resolved itself, so it might not need thinking about.