Luke
Luke

Reputation: 69

can hard coded strings in a compiled exe be changed?

Lets say you have some code in your app with a hard coded string.

If somevalue = "test123" Then

End If

Once the application is compiled, is it possible for someone to modify the .exe file and change 'test123' to something else? If so, would it only work if the string contained the same number of characters?

Upvotes: 5

Views: 3113

Answers (2)

TheCodeArtist
TheCodeArtist

Reputation: 22487

Strings hard-coded without any obfuscation techniques can easily be found inside compiled executables by openign them up in any HEX-editor. Once found, replacing the string is possible in 2 ways :

1. Easy way (*conditions apply)

If the following conditions apply in your case, this is a very quick-fire way of modifying the hard-coded strings in the executable binary.

  • length(new-string) <= length(old-string)
  • No logic in the code to check for executable modification using CRC.

This is a viable option ONLY if the new string is equal or shorter than the old string. Use a hex-editor to find occurrences of the old string and replace it with the new string. Pad an extra space with NULL i.e. 0x00

For example old-long-string in the binary old long string in a hex-editor

is modified to a shorter new-string and padded with null characters to the same length as the original string in the binary executable file enter image description here

Note that such modifications to the executable files are detected by any code that verifies the checksum of the binary file against the pre-calculate checksum of the original binary executable file.

2. Harder way (applicable in almost all cases)

De-compiling the binary to native code opens up the possibility to modify any strings (and even code) and rebuild it to obtain the new binary executable.

There exist dozens of such de-compiler tools to decompile vb.net (Visual Studio.net, in general). An excellent detailed comparison of the most popular ones (ILspy, JustDecompile, DotPeek, .NET Reflector to name a few ) can be found here.

There do exist scenarios in which even the harder way will NOT be successful. This is the case when the original developer has used obfuscation techniques to prevent the strings from being detected and modified in the executable binary. One such obfuscation technique is storing encrypted strings.

Upvotes: 1

keyboardP
keyboardP

Reputation: 69372

It's possible but not necessarily straightforward. For example, if your string is loaded in memory, someone could use a memory manager tool to modify the value of the string's address directly.

Alternatively, they could decompile your app, change the string, and recompile it to create a new assembly with the new string. However, whether this is likely to happen depends on your app and how important it is for that string to be changed.

You could use an obfuscator to make it a bit harder to do but, ultimately, a determined cracker would be able to do it. The question is whether that string is important enough to worry about and, if so, maybe consider an alternative approach such as using a web service to provide the string.

Upvotes: 1

Related Questions