Return function int64 C++ to a C# project
up vote
0
down vote
favorite
i write a dll that is injected on game and return my localplayer and listArrayplayer on server. Ok work fine
code dll project:
C++ code:
__int64 RerturnLocalPlayer()
__int64 player = GetLocalPlayer_EX();// __Int64 GetLocalPlayer_EX() is a function that return type __int64 value
return player;
in main.h:
extern "C"
__declspec(dllexport) __int64 RerturnLocalPlayer();
mt function
extern "C"
__declspec(dllexport) __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);
C# Code:
[System.Runtime.InteropServices.DllImportAttribute("BFClient1.dll", EntryPoint = "RerturnLocalPlayer",
CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static extern Int64 RerturnLocalPlayer();
Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
Console.WriteLine("LocalPlayer " + localp.ToString("X"));
the problem is when i run my c# application my console open and after 3 seconds close and sometimes get error: **Attempt to read or write to protected memory. Usually, this is an indication that another memory is damaged.
can some one try help me?
c# c++ c++11 visual-c++ c#-4.0
add a comment |
up vote
0
down vote
favorite
i write a dll that is injected on game and return my localplayer and listArrayplayer on server. Ok work fine
code dll project:
C++ code:
__int64 RerturnLocalPlayer()
__int64 player = GetLocalPlayer_EX();// __Int64 GetLocalPlayer_EX() is a function that return type __int64 value
return player;
in main.h:
extern "C"
__declspec(dllexport) __int64 RerturnLocalPlayer();
mt function
extern "C"
__declspec(dllexport) __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);
C# Code:
[System.Runtime.InteropServices.DllImportAttribute("BFClient1.dll", EntryPoint = "RerturnLocalPlayer",
CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static extern Int64 RerturnLocalPlayer();
Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
Console.WriteLine("LocalPlayer " + localp.ToString("X"));
the problem is when i run my c# application my console open and after 3 seconds close and sometimes get error: **Attempt to read or write to protected memory. Usually, this is an indication that another memory is damaged.
can some one try help me?
c# c++ c++11 visual-c++ c#-4.0
NativeMemory.Read<Int64> interprets the return value of your function as pointer to an int64 value and reads the value it points to. If this really the case?
– Klaus Gütter
Nov 10 at 17:08
1
Note that if your native library is compiled as x86 (32-bit) code, you might have a mismatching calling convention (your P/Invoke declaresstdcall
calling convention, but your compiled C++ function exports quite possibly usecdecl
calling convention.) Suggested recommendation to fix/avoid such situations: state the calling convention for your exported C/C++ functions explicitly in main.h, and then use the same calling convention in your P/Invoke declaration.
– elgonzo
Nov 10 at 17:25
Klaus Gütter yes is a function to read int64, but i dont need this function.
– CerraossoUC
Nov 10 at 18:13
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
i write a dll that is injected on game and return my localplayer and listArrayplayer on server. Ok work fine
code dll project:
C++ code:
__int64 RerturnLocalPlayer()
__int64 player = GetLocalPlayer_EX();// __Int64 GetLocalPlayer_EX() is a function that return type __int64 value
return player;
in main.h:
extern "C"
__declspec(dllexport) __int64 RerturnLocalPlayer();
mt function
extern "C"
__declspec(dllexport) __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);
C# Code:
[System.Runtime.InteropServices.DllImportAttribute("BFClient1.dll", EntryPoint = "RerturnLocalPlayer",
CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static extern Int64 RerturnLocalPlayer();
Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
Console.WriteLine("LocalPlayer " + localp.ToString("X"));
the problem is when i run my c# application my console open and after 3 seconds close and sometimes get error: **Attempt to read or write to protected memory. Usually, this is an indication that another memory is damaged.
can some one try help me?
c# c++ c++11 visual-c++ c#-4.0
i write a dll that is injected on game and return my localplayer and listArrayplayer on server. Ok work fine
code dll project:
C++ code:
__int64 RerturnLocalPlayer()
__int64 player = GetLocalPlayer_EX();// __Int64 GetLocalPlayer_EX() is a function that return type __int64 value
return player;
in main.h:
extern "C"
__declspec(dllexport) __int64 RerturnLocalPlayer();
mt function
extern "C"
__declspec(dllexport) __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);
C# Code:
[System.Runtime.InteropServices.DllImportAttribute("BFClient1.dll", EntryPoint = "RerturnLocalPlayer",
CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static extern Int64 RerturnLocalPlayer();
Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
Console.WriteLine("LocalPlayer " + localp.ToString("X"));
the problem is when i run my c# application my console open and after 3 seconds close and sometimes get error: **Attempt to read or write to protected memory. Usually, this is an indication that another memory is damaged.
can some one try help me?
c# c++ c++11 visual-c++ c#-4.0
c# c++ c++11 visual-c++ c#-4.0
edited Nov 11 at 12:59
asked Nov 10 at 16:56
CerraossoUC
134
134
NativeMemory.Read<Int64> interprets the return value of your function as pointer to an int64 value and reads the value it points to. If this really the case?
– Klaus Gütter
Nov 10 at 17:08
1
Note that if your native library is compiled as x86 (32-bit) code, you might have a mismatching calling convention (your P/Invoke declaresstdcall
calling convention, but your compiled C++ function exports quite possibly usecdecl
calling convention.) Suggested recommendation to fix/avoid such situations: state the calling convention for your exported C/C++ functions explicitly in main.h, and then use the same calling convention in your P/Invoke declaration.
– elgonzo
Nov 10 at 17:25
Klaus Gütter yes is a function to read int64, but i dont need this function.
– CerraossoUC
Nov 10 at 18:13
add a comment |
NativeMemory.Read<Int64> interprets the return value of your function as pointer to an int64 value and reads the value it points to. If this really the case?
– Klaus Gütter
Nov 10 at 17:08
1
Note that if your native library is compiled as x86 (32-bit) code, you might have a mismatching calling convention (your P/Invoke declaresstdcall
calling convention, but your compiled C++ function exports quite possibly usecdecl
calling convention.) Suggested recommendation to fix/avoid such situations: state the calling convention for your exported C/C++ functions explicitly in main.h, and then use the same calling convention in your P/Invoke declaration.
– elgonzo
Nov 10 at 17:25
Klaus Gütter yes is a function to read int64, but i dont need this function.
– CerraossoUC
Nov 10 at 18:13
NativeMemory.Read<Int64> interprets the return value of your function as pointer to an int64 value and reads the value it points to. If this really the case?
– Klaus Gütter
Nov 10 at 17:08
NativeMemory.Read<Int64> interprets the return value of your function as pointer to an int64 value and reads the value it points to. If this really the case?
– Klaus Gütter
Nov 10 at 17:08
1
1
Note that if your native library is compiled as x86 (32-bit) code, you might have a mismatching calling convention (your P/Invoke declares
stdcall
calling convention, but your compiled C++ function exports quite possibly use cdecl
calling convention.) Suggested recommendation to fix/avoid such situations: state the calling convention for your exported C/C++ functions explicitly in main.h, and then use the same calling convention in your P/Invoke declaration.– elgonzo
Nov 10 at 17:25
Note that if your native library is compiled as x86 (32-bit) code, you might have a mismatching calling convention (your P/Invoke declares
stdcall
calling convention, but your compiled C++ function exports quite possibly use cdecl
calling convention.) Suggested recommendation to fix/avoid such situations: state the calling convention for your exported C/C++ functions explicitly in main.h, and then use the same calling convention in your P/Invoke declaration.– elgonzo
Nov 10 at 17:25
Klaus Gütter yes is a function to read int64, but i dont need this function.
– CerraossoUC
Nov 10 at 18:13
Klaus Gütter yes is a function to read int64, but i dont need this function.
– CerraossoUC
Nov 10 at 18:13
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
__int64 RerturnLocalPlayer()
is a function that returns a 64-bit value through some calling convention. You seem to think it's stdcall
, I think you're wrong. However I don't have your source code so you can bang your head against that wall on your own.
public static extern Int64 RerturnLocalPlayer();
is the right definition (again, calling convention aside, there's no 64-bit register on the 32-bit CPU, so it won't be stdcall
).
However, Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
is just plain bonkers. You're already getting your integer straight from the marshaller as a return value, use it as such! This would be the correct way of calling your function:
Int64 localp = RerturnLocalPlayer();
i update and add my functionon description
– CerraossoUC
Nov 11 at 19:13
@CerraossoUC, ok and? Is it still a problem? Have you tried my suggestion? I still see the same native memory read call in your updated code.
– Blindy
Nov 12 at 16:09
yes, i forget to remove nativememory from description, but i tried Int64 localp = RerturnLocalPlayer(); but have same problem nothing happend and close my app. and yes, i change from StdCall) to CallingConvention.Cdecl). =/
– CerraossoUC
Nov 13 at 11:18
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
__int64 RerturnLocalPlayer()
is a function that returns a 64-bit value through some calling convention. You seem to think it's stdcall
, I think you're wrong. However I don't have your source code so you can bang your head against that wall on your own.
public static extern Int64 RerturnLocalPlayer();
is the right definition (again, calling convention aside, there's no 64-bit register on the 32-bit CPU, so it won't be stdcall
).
However, Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
is just plain bonkers. You're already getting your integer straight from the marshaller as a return value, use it as such! This would be the correct way of calling your function:
Int64 localp = RerturnLocalPlayer();
i update and add my functionon description
– CerraossoUC
Nov 11 at 19:13
@CerraossoUC, ok and? Is it still a problem? Have you tried my suggestion? I still see the same native memory read call in your updated code.
– Blindy
Nov 12 at 16:09
yes, i forget to remove nativememory from description, but i tried Int64 localp = RerturnLocalPlayer(); but have same problem nothing happend and close my app. and yes, i change from StdCall) to CallingConvention.Cdecl). =/
– CerraossoUC
Nov 13 at 11:18
add a comment |
up vote
0
down vote
__int64 RerturnLocalPlayer()
is a function that returns a 64-bit value through some calling convention. You seem to think it's stdcall
, I think you're wrong. However I don't have your source code so you can bang your head against that wall on your own.
public static extern Int64 RerturnLocalPlayer();
is the right definition (again, calling convention aside, there's no 64-bit register on the 32-bit CPU, so it won't be stdcall
).
However, Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
is just plain bonkers. You're already getting your integer straight from the marshaller as a return value, use it as such! This would be the correct way of calling your function:
Int64 localp = RerturnLocalPlayer();
i update and add my functionon description
– CerraossoUC
Nov 11 at 19:13
@CerraossoUC, ok and? Is it still a problem? Have you tried my suggestion? I still see the same native memory read call in your updated code.
– Blindy
Nov 12 at 16:09
yes, i forget to remove nativememory from description, but i tried Int64 localp = RerturnLocalPlayer(); but have same problem nothing happend and close my app. and yes, i change from StdCall) to CallingConvention.Cdecl). =/
– CerraossoUC
Nov 13 at 11:18
add a comment |
up vote
0
down vote
up vote
0
down vote
__int64 RerturnLocalPlayer()
is a function that returns a 64-bit value through some calling convention. You seem to think it's stdcall
, I think you're wrong. However I don't have your source code so you can bang your head against that wall on your own.
public static extern Int64 RerturnLocalPlayer();
is the right definition (again, calling convention aside, there's no 64-bit register on the 32-bit CPU, so it won't be stdcall
).
However, Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
is just plain bonkers. You're already getting your integer straight from the marshaller as a return value, use it as such! This would be the correct way of calling your function:
Int64 localp = RerturnLocalPlayer();
__int64 RerturnLocalPlayer()
is a function that returns a 64-bit value through some calling convention. You seem to think it's stdcall
, I think you're wrong. However I don't have your source code so you can bang your head against that wall on your own.
public static extern Int64 RerturnLocalPlayer();
is the right definition (again, calling convention aside, there's no 64-bit register on the 32-bit CPU, so it won't be stdcall
).
However, Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
is just plain bonkers. You're already getting your integer straight from the marshaller as a return value, use it as such! This would be the correct way of calling your function:
Int64 localp = RerturnLocalPlayer();
answered Nov 10 at 20:14
Blindy
43.2k765107
43.2k765107
i update and add my functionon description
– CerraossoUC
Nov 11 at 19:13
@CerraossoUC, ok and? Is it still a problem? Have you tried my suggestion? I still see the same native memory read call in your updated code.
– Blindy
Nov 12 at 16:09
yes, i forget to remove nativememory from description, but i tried Int64 localp = RerturnLocalPlayer(); but have same problem nothing happend and close my app. and yes, i change from StdCall) to CallingConvention.Cdecl). =/
– CerraossoUC
Nov 13 at 11:18
add a comment |
i update and add my functionon description
– CerraossoUC
Nov 11 at 19:13
@CerraossoUC, ok and? Is it still a problem? Have you tried my suggestion? I still see the same native memory read call in your updated code.
– Blindy
Nov 12 at 16:09
yes, i forget to remove nativememory from description, but i tried Int64 localp = RerturnLocalPlayer(); but have same problem nothing happend and close my app. and yes, i change from StdCall) to CallingConvention.Cdecl). =/
– CerraossoUC
Nov 13 at 11:18
i update and add my functionon description
– CerraossoUC
Nov 11 at 19:13
i update and add my functionon description
– CerraossoUC
Nov 11 at 19:13
@CerraossoUC, ok and? Is it still a problem? Have you tried my suggestion? I still see the same native memory read call in your updated code.
– Blindy
Nov 12 at 16:09
@CerraossoUC, ok and? Is it still a problem? Have you tried my suggestion? I still see the same native memory read call in your updated code.
– Blindy
Nov 12 at 16:09
yes, i forget to remove nativememory from description, but i tried Int64 localp = RerturnLocalPlayer(); but have same problem nothing happend and close my app. and yes, i change from StdCall) to CallingConvention.Cdecl). =/
– CerraossoUC
Nov 13 at 11:18
yes, i forget to remove nativememory from description, but i tried Int64 localp = RerturnLocalPlayer(); but have same problem nothing happend and close my app. and yes, i change from StdCall) to CallingConvention.Cdecl). =/
– CerraossoUC
Nov 13 at 11:18
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241237%2freturn-function-int64-c-to-a-c-sharp-project%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
NativeMemory.Read<Int64> interprets the return value of your function as pointer to an int64 value and reads the value it points to. If this really the case?
– Klaus Gütter
Nov 10 at 17:08
1
Note that if your native library is compiled as x86 (32-bit) code, you might have a mismatching calling convention (your P/Invoke declares
stdcall
calling convention, but your compiled C++ function exports quite possibly usecdecl
calling convention.) Suggested recommendation to fix/avoid such situations: state the calling convention for your exported C/C++ functions explicitly in main.h, and then use the same calling convention in your P/Invoke declaration.– elgonzo
Nov 10 at 17:25
Klaus Gütter yes is a function to read int64, but i dont need this function.
– CerraossoUC
Nov 10 at 18:13