程序修改其exe中的字符串 [英] Program that modifes string inside its exe

查看:962
本文介绍了程序修改其exe中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用C ++,Windows下的Visual Studio。



我在Windows中搜索工作示例,但我找不到任何工作代码。



我需要简单的代码, string:

  string strTest =; 
(如果strTest!=)
{
cout< Modified:<< strTest< endl;
}
cin>> strText;

而且代码应该重写:

  string strTest =; 

键入的用户的字符串:

  string strTest =SomeStringFromUser; 

如何在C ++中修改字符串(从字符串strTest =)到字符串,用户键入什么? (例如到strTest =foo)?

解决方案

当EXE在Windows机器上运行时,exe文件作为 CreateFileMapping 对象打开,页面标记为READONLY或 COPY_ON_WRITE



因此,当exe写入自身时,文件不会被修改。它只是创建一个由交换文件支持的新页面。但是由于文件保持打开,没有人可以打开EXE文件并写入它。



除了破解页面保护功能以关闭COPY_ON_WRITE之外 - 我甚至不确定。我可以这么想的唯一方法是写一个小程序,运行之后,exe完成并打开.exe文件并写入它。



我不得不相信,无论你想做什么,都有更好的办法。



---后来----



好吧,你正在寻找水印你的EXE。这里的东西,这是很容易做的在你的安装程序在exe开始之前。但是一旦.exe运行它就更难了。



这里是我会做的。




  • 声明一个必要大小的全局字符串变量,例如 const char g_szWatermark [100] = / code>

  • 创建我的exe,然后查看地图文件以查找其段内变量的地址(记住C ++名称装饰)

  • 解析EXE头以找到段在exe中开始的位置。

  • 添加这两个数字以获取exe文件中字符串的位置,将此数字赋予我的安装程序

  • 让安装程序运行一下程序,询问用户的信息,然后将其写入.exe。注意:你在exe运行之前就这样做了,否则它不会工作!


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")?

解决方案

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.

  • declare a global string variable of the necessary size, say const char g_szWatermark[100] = "";
  • Build my exe, then look in the map file to find the address of the variable within its segment (remember about C++ name decoration)
  • parse the EXE header to find the where the segment begins in the exe.
  • add these two numbers to get the location of the string within the exe file, give this number to my installer
  • have the installer run a little program that asks the user for information and then writes it into the .exe. Note: you have do do this before the exe runs or it won't work!

这篇关于程序修改其exe中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆