修改 exe 内字符串的程序
我正在寻找程序示例,该程序修改其 exe 内的字符串。
我在 Windows 下使用 C++、Visual Studio。
我在 Windows 中搜索了工作示例,但找不到任何工作代码。
我需要简单的代码,它将询问用户字符串:
string strTest = "";
(if strTest != "")
{
cout << "Modified: " << strTest << endl;
}
cin >> strText;
并且代码应该重写:
string strTest = "";
到键入用户的字符串:
string strTest = "SomeStringFromUser";
在 C++ 中,如何将字符串(从字符串 strTest =“”)修改为字符串,用户键入的内容? (例如 strTest = "foo")?
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")?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当 EXE 在 Windows 计算机上运行时,exe 文件作为
CreateFileMapping
对象保持打开状态,其页面标记为 READONLY 或 COPY_ON_WRITE。因此,当 exe 写入自身时,文件不会被修改。它只是创建一个由交换文件支持的新页面。但由于该文件保持打开状态,因此其他人也无法打开该 EXE 文件并对其进行写入。
除了破解页面保护以关闭 COPY_ON_WRITE - 我不确定这是否可能。我能想到的唯一方法是编写一个小程序,在 exe 完成后运行并打开 .exe 文件并向其写入内容。
我必须相信,无论你想做什么,都有更好的方法来实现。
--- 稍后 ----
好的,我现在明白了。你正在寻找给你的exe添加水印。事情是这样的,在 exe 启动之前,这在安装程序中很容易完成。但是一旦 .exe 运行起来就很难了。
这就是我要做的。
const char g_szWatermark[100] = "";
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] = "";
基于某种开放的、已建立的加密机制的许可方案将是您最强大的解决方案。使用标准 PKI 的方法应该比尝试实现自修改代码更简单、更安全。
但老实说,有很多公司花费大量资金进行研发以创建复制保护,而这些系统在发布后几天内就被破解了。因此,如果你想阻止破解者,那么你前面的路还很长、很艰难。
如果您只是想让诚实的人保持诚实,使用 GUID 作为“许可证密钥”的简单在线激活将非常有效。
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.
这个怎么样:
How about this: