1

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

4
  • 4
    This is very ill-advised, if it's even possible to do reliably. Can you post those portability requirements, to clarify why this is the best way? Commented Nov 27, 2010 at 1:03
  • 3
    Is it possible to change your code to use strings from a embedded resource string table rather than hard coded strings? Commented Nov 27, 2010 at 1:20
  • Steve-I'm trying to have a single file solution. Thanks for your comment. I had a feeling this would be a somewhat hacky thing to try. Commented Nov 27, 2010 at 2:11
  • Merick- I was just looking into that! Seems like a good solution. Commented Nov 27, 2010 at 2:12

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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?

Comments

1

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.

3 Comments

You mention there is 3-rd party software that allows the direct modification of the binary. Please provide a name or a link along with it.
@julaine I would try that one first: en.wikipedia.org/wiki/Resource_Hacker
I have found another solution to my original problem so I cannot evaluate that, but that does seem like the kind of tool that would answer the question (rather than the "do-something-else"-answer or the 404-link in the question)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.