Jump to content
  • Advertisement
Sign in to follow this  
Fil

rename variables in release mode (like C++ #define)

This topic is 2444 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using VB.NET 2008.
I'd like to change variable names from debug to release mode.


I know I can't use a #define preprocessor directive (like in C++)

#if DEBUG
# define MyVarName myDebugVarName
#else
# define MyVarName myReleaseVarName
#endif

and I wonder if there's something I can do to have this kind of result.

I know I can write something like:

#If DEBUG Then
Dim myDebugVarName As Integer = 0
#Else
Dim myReleaseVarName As Integer = 0
#End If

but this is very ugly since now every instruction (or block of instructions) dealing with that var has to be written 2 times, one for debug mode and one for release mode. E.g.:


#If DEBUG Then
myDebugVarName+=1
#Else
myReleaseVarName+=1
#End If

or

#If DEBUG Then
if myDebugVarName > 2 Then
DoSomething(myDebugVarName)
Else
DoSomethingElse(myDebugVarName)
End If
#Else
If myReleaseVarName > 2 Then
DoSomething(myReleaseVarName)

Else
DoSomethingElse(myReleaseVarName)
End If
#End If

The code becomes soon unreadable and it is easy to forget keep the couple of version in sync (violation of DRY principle). sad.png

Renaming variables in MSIL might be an option, but I've not found an easy way to do that. For example I imagine having a table with debug names and release names for each var (maybe a Dictionary) and call a translation of all the names in Release version (so I write only myDebugVarName in my source and in MSIL it changes in myReleaseVarName).
I think I'll apply your suggested methods to change names to some classes and methods.

I hope you see what I mean.
Thank you in advance for any help. smile.png

Share this post


Link to post
Share on other sites
Advertisement
Variable names are for programmer usage, not users'. I'm skeptical that there is any situation where doing what you suggest is acceptable.

Share this post


Link to post
Share on other sites
I don't really see the purpose of doing that. Variable names do not appear in compiled executables, they are strictly for programmer use. As for interpreted languages, you are probably looking for an obfuscator like Alnite suggests (not that I condone the use of those tools).

But if you're desperate, there's always Replace All mellow.png

Share this post


Link to post
Share on other sites
Thank you for your replies. :)
I'm already using an obfuscator (since the exe in .Net is just all the source code without comments) but a lot of classes dealing with WCF services cannot be renamed without compromising communication between clients and server (in fact obfuscator leaves them unchanged). That's why I'd like to change theese names manually. So I can have the class CCustomerInfoService in debug mode and something named C0945 in release mode (the same for model classes, all the methos and members).

I know obfuscators are not a (great) protection, but since it's not an open source project I don't want other to see so easily how I wrote my program, neither I want to give them too many insights about the class diagram I implemented. :P

"Replace All" as Bacterius suggests maybe is not a bad idea (or am I desperate? ;-) :D ): I'm thinking about a String.Replace done on my source code by a little utility as a pre-compilation step. That's will keep in sync release and debug version of source code (so I have no change in how I write programs), and names are changed automagically before compiling release version. If I forgot to rename something it will become a compiler error in release mode, so it should be easy to fix since I'll find a debug name not replaced with its counterpart in release mode.

I think to try this way. :)
Thank you again, your comments have been useful :)

Share this post


Link to post
Share on other sites
Unless you're writing something that is extremely popular, nobody is even going to bother to try to decompile your program. Most likely, you are wasting your time.

Share this post


Link to post
Share on other sites
since it's not an open source project[/quote]

It's written in .Net.

It's open source. .Net provides reflection, which, unlike C or C++, preserves all information by design. Renaming doesn't do a single thing.

Obfuscation in C or C++ isn't better because it generates native code, but because it's lossy. Both languages allow and encourage structural transformations, eliminating information needed to reconstruct the source. .Net (or Java, Python, etc) projects do not allow that.


Look at Minecraft. It's obfuscated, but people have been modding it since day one, working with original source directly.

Share this post


Link to post
Share on other sites
@wack: I hope it will be extremely popular wink.png About decompilation I agree with you. I'll try to spend the least time possible doing renaming :P

@antheus:You're right. I regret a little to have used this kind of tecnology to develop my program. I think I'll rewrite it using VC++ to have native code, but at present I need to complete the first release as soon as possible and I'd like to discourage reading of my exe/source code by casual observers. :P

Thanks for sharing your thoughs. smile.png

Share this post


Link to post
Share on other sites

I regret a little to have used this kind of tecnology to develop my program.

Why? Looking at Antheus's example of Minecraft again, it's pretty clear that the technology choice hasn't hindered the success of the final product. If .NET is allowing you to quickly and easily create a correctly working program, then worrying about the final product being decompiled is probably a poor reason to change to C++.

Concentrate your efforts on creating a good product. smile.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!