I looking for example of program, that modifies a string inside its exe.
I work with C++, Visual Studio under Windows.
I searched working examples in Windows, but I can't find any working code.
I need simple code, that will ask user for string:
string strTest = "";
(if strTest != "")
{
cout << "Modified: " << strTest << endl;
}
cin >> strText;
And code should rewrite:
string strTest = "";
To string that typed user:
string strTest = "SomeStringFromUser";
How, in C++, do you modify a string (from string strTest = ""), to string, what a user typed? (for example to strTest = "foo")?
A licensing scheme based on some open, established cryptographic mechanism is going to be your most robust solution. Something using standard PKI should be much simpler and more secure than attempting to implement self-modifying code.
To be honest though, there are a lot of companies that spend a lot of money on R&D creating copy protection and those systems are cracked within days of release. So if you're trying to thwart crackers then you have a long, hard road ahead.
If you just want to keep the honest people honest, a simple online activation using a GUID as the "license key" would be quite effective.
When an EXE is running on a Windows machine, the exe file is held open as a
CreateFileMapping
object with pages marked either as READONLY or COPY_ON_WRITE.So when the exe writes to itself, the file is not modified. It just creates a new page backed by the swap file. But since the file is kept open, no-one else can open the EXE file and write to it either.
Other than hacking the page protection to turn off COPY_ON_WRITE - Which I'm not sure is even possible. The only way I can think to do this would be to write a little program that runs after your exe finishes and opens the .exe file and writes to it.
I've gotta believe that whatever you are trying to do, there is a better way to go about it.
--- Later ----
Ok, I get it now. you are looking to watermark your exe. Here's the thing, this is pretty easy to do in your installer before the exe starts. But once the .exe is running it's MUCH harder to do.
Here's what I would do.
const char g_szWatermark[100] = "";
How about this: