none
Call function from a injected Dll in another process in C# RRS feed

  • Question

  • Hi, 

    i have 2 project c++ a dll and C# .exe, the dll is injected in a game and return a data like this: http://prntscr.com/lctkmb

    this stay returning while dll is runing . Now i trying get this return in my C# aplication, i tried Dynamically calling an unmanaged dll, but not work, get this error "Attempt to read or write to protected memory. Usually, this is an indication that another memory is damaged. '"

    My function on dll that return data:

    INT64 GetLocalPlayer_EX() { DWORD64 pClientGameContext = *(DWORD64*)OFFSET_CLIENTGAMECONTEXT; if (!(pClientGameContext)) return 0; DWORD64 pPlayerManager = *(DWORD64*)(pClientGameContext + 0x68); if (!(pPlayerManager)) return 0; DWORD64 pObfuscationMgr = *(DWORD64*)OFFSET_ObfuscationMgr; if (!(pObfuscationMgr)) return 0; DWORD64 LocalPlayerListXorValue = *(DWORD64*)((DWORD64)pPlayerManager + 0xF0); DWORD64 LocalPlayerListKey = LocalPlayerListXorValue ^ *(DWORD64 *)(pObfuscationMgr + 0x70); hashtable<DWORD64>* table = (hashtable<DWORD64>*)(pObfuscationMgr + 8); hashtable_iterator<DWORD64> iterator = { 0 }; hashtable_find(table, &iterator, LocalPlayerListKey); if (iterator.mpNode == table->mpBucketArray[table->mnBucketCount]) return 0; DWORD64 EncryptedPlayerMgr = (DWORD64)iterator.mpNode->mValue.second; if (!(EncryptedPlayerMgr)) return 0; DWORD MaxPlayerCount = *(DWORD *)(EncryptedPlayerMgr + 0x18); if (MaxPlayerCount != 1) return 0; return EncryptedPlayerMgr__GetPlayer(EncryptedPlayerMgr, 0); }

    DWORD WINAPI InitThread(LPVOID)
    {

    CreateConsole();

    while (true)
    {

    printf("LocalPlayer = %I64X\n", GetLocalPlayer_EX());

    Sleep(100);

    }
    return 0;
    }

    extern "C" __declspec(dllexport)  INT64  GetLocalPlayer_EX();


    In my C# code:

            [System.Runtime.InteropServices.DllImportAttribute("BFClient1.dll", EntryPoint = "GetLocalPlayer_EX", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
            public static extern int GetLocalPlayer_EX();
    
            [STAThread]
            static void Main(string[] args)
            {
    
                       Int64 localp = NativeMemory.Read<In64t>(GetLocalPlayer_EX()); //read type int64
    
                        Console.WriteLine("LocalPlayer " + localp.toSctring("X")); //"Attempt to read or write to protected memory. Usually, this is an indication that another memory is damaged. '"
    
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(true);
                        Application.Run();
                
    
    
                Console.ReadKey();
            }

    have away to call that return ?

     


    • Edited by CesarAGS Wednesday, October 31, 2018 7:18 PM
    Wednesday, October 31, 2018 7:16 PM

All replies

  • Hi CesarAGS,

    Thank you for posting here.

    For your question, I could not test the code your provided without some declares. Please check the localp. Is it valid? 

    If it is possible, please provide the code sample which could reproduce the error for us to test.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 1, 2018 7:25 AM
    Moderator