C++ Win32 替换可执行文件中的字符串

发布于 2024-10-05 09:08:58 字数 529 浏览 4 评论 0原文

我正在寻找一种好方法来替换本机 win32 编译的 exe 中的多个字符串。例如,我的代码中有以下内容:

const char *updateSite = "http://www.place.com"
const char *updateURL  = "/software/release/updater.php"

我需要用 exe 中的其他任意长度字符串修改这些字符串。我意识到我可以将这种类型的配置存储在其他地方,但将其保留在 exe 中可以满足我的应用程序的可移植性要求。我将不胜感激任何有关最佳方法的帮助和/或建议。

谢谢!

更新:我在 Metasploit 项目中发现了一些代码似乎可以做到这一点: MSF:Util:Exe

I'm looking for a good way to replace several strings inside a native win32 compiled exe. For example, I have the following in my code:

const char *updateSite = "http://www.place.com"
const char *updateURL  = "/software/release/updater.php"

I need to modify these strings with other arbitrary length strings within the exe. I realize I could store this type of configuration elsewhere, but keeping it in the exe meets the portability requirements for my app. I would appreciate any help and/or advice on the best way to do this.

Thanks!

Update: I found some code in the Metasploit project that seems to do this:
MSF:Util:Exe

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

零崎曲识 2024-10-12 09:08:58

我不会搞乱 EXE 本身,如果您确实需要 1 个文件,那么请执行旧的 zip 附加技巧并将您的配置放在那里。

可能看起来像这样:

> BINARY DATA
> ZIP FILE DATA
> 32bit unsigned int which's value is the size of the appended zip file

优点:

  • 易于扩展/维护
  • 你不会弄乱 exe 本身,
  • 你可以在其中放置很多东西

缺点:

  • 你需要链接一些压缩库

如果你不想压缩它,那么只需自己编写一些简单的未压缩存档。

I would not mess around the the EXE itself, if you really need 1 file, then do the old zip append trick and put your configs in there.

Could look like this:

> BINARY DATA
> ZIP FILE DATA
> 32bit unsigned int which's value is the size of the appended zip file

Pros:

  • easy to extend / maintain
  • you don't mess with the exe itself
  • you can put lots of stuff in there

Contras:

  • You need to link some compression lib

If you don't want to zip it, then just write some simple uncompressed archive thing your own.

无敌元气妹 2024-10-12 09:08:58

PE 文件中有全局重定位表 - 它是必须由 PE 加载器更改的地址列表(例如,必须运行时存储的全局变量或常量,例如字符串)。如果您知道这个特定变量是哪个条目,您可以获取它的地址,然后手动更改它。然而,这将是一个彻头彻尾的问题,您需要深入了解您最喜欢的编译器和 PE 格式。使用 XML 或 Lua 或其他完全可移植的东西会更容易 - 它们正是为了这种目的而发明的。

编辑:

为什么不只使用 const char** ?这是一个正常的运行时变量有什么问题吗?

In a PE file is the global relocations table- it is a list of addresses (for example, global variables or constants that must be runtime-stored, like, say, strings) that must be altered by the PE loader. If you knew which entry this particular variable was, you could get it's address and then alter it manually. However, this would be a total bitch and you'd need an in-depth knowledge of your favourite compiler and the PE format. Easier just to use XML or Lua or something else that's totally portable - they were invented for exactly this kind of purpose.

Edit:

Why not just use a const char**? Is there something wrong with this being a normal runtime variable?

简美 2024-10-12 09:08:58

IMO 是将字符串存储在字符串表资源中的最佳位置。它已合并到您的 .EXE 文件中,因此可移植性不会受到影响。

使用 Visual Studio 编辑器进行更改那个值。

使用 LoadString WinAPI,或更好的 CString::LoadString 方法,在您的代码中加载值。

还有第 3 方软件允许您修改已编译的 .EXE 中的字符串,而无需重新编译。一个例子是资源黑客

IMO the best place to store that strings in a string table resource. It's incorporated into your .EXE file, so the portability will not be compromised.

Use the visual studio editor to alter that values.

Use LoadString WinAPI, or better, CString::LoadString method, in your code, to load the values.

There's also 3-rd party software allowing you to modify the strings in the compiled .EXE, without recompilation. An example is Resource Hacker.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文