Im starting to learn how to reverse engineer as its something that looks enjoyed.
My issue is im calling GetModuleHandle to get a handle to CSteamworks.dll (A .Net wrapper for the steam api). I used GetProcAddress to get a function to open the steam overlay and called it. It all worked well but im having an issue with strings.
When ever I call a function that returns a string I eithr getting an empty string or some weird symbols. Same with passing parameters, The target code seems to assume my parament is an empty string. Im currently using System::String as I was told this should be used to exchange strings between c++ and c#.
Here is my entire DLL right now, Thanks if anyone can help.
(Just so you know it gets and calls the function fine, Its just the return values and parameters that are wrong)
//My DLL code
[CODE]typedef System::String ^ (*GetPersonaName_)();
char* GetPersonaName() {
GetPersonaName_ GetPersonaNameFunc = (GetPersonaName_)GetProcAddress((HMODULE)steam, (LPCSTR)"ISteamFriends_GetFriendPersonaName");
if (GetPersonaNameFunc == NULL) {
cout << "Faileds to get ISteamFriends_ActivateGameOverlay function!!!" << endl;
return "ERR";
}
System::String^ ss_name = GetPersonaNameFunc();
return (char*)Marshal::StringToHGlobalUni(ss_name).ToPointer();
}[/CODE]
After I call that it then cout's the return value, Which always seems to be an empty string.
//The source code for the function im trying to call.
[CODE] public static class SteamFriends {
/// <summary>
/// <para> returns the local players name - guaranteed to not be NULL.</para>
/// <para> this is the same name as on the users community profile page</para>
/// <para> this is stored in UTF-8 format</para>
/// <para> like all the other interface functions that return a char *, it's important that this pointer is not saved</para>
/// <para> off; it will eventually be free'd or re-allocated</para>
/// </summary>
public static string GetPersonaName() {
InteropHelp.TestIfAvailableClient();
return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamFriends_GetPersonaName());
}[/CODE]
Thank you.
[QUOTE=0V3RR1D3;50565594]My issue is im calling GetModuleHandle to get a handle to CSteamworks.dll (A .Net wrapper for the steam api). I used GetProcAddress to get a function to open the steam overlay and called it. It all worked well but im having an issue with strings.[/QUOTE]
Don't. If i understood you correctly, you are using GetModuleHandle and GetProcAddress to get a .NET dll. You don't have to do that. Just add a reference to said dll when compiling your project (which i assume is also .NET), and when you load it in your target process, it will automatically find the .NET dll in memory.
[editline]24th June 2016[/editline]
You'd just use the standard API CSteamworks.dll exports.
[editline]24th June 2016[/editline]
Another thing you should look into is string marshalling. I forgot the exact syntax for C++/CLI but you should use System.Runtime.InteropServices.MarshalAsAttribute.
Sorry, you need to Log In to post a reply to this thread.