tags:

views:

41

answers:

3

Hello,

So I have this VB.Net Application. It uses SQL Server database, for which it "hard-codes" the IP Address of the database inside its compiled code.

The server IP has changed and I can't start the software anymore. Also, I can't change the IP Address of the server (another server is using the same IP and it can't be changed).

It is just 2 EXE files with no external DLLs or anything else. So I opened both of them in HEX Editor, tried to search for the ascii of my IP address, but couldn't find it, tried also a HEX search but with no result.

Then I used .NET REFLECTOR (http://www.red-gate.com/products/reflector/), and exported the code. I could see where the IP address is located: in Form2 a string variable named "strMyConnectionString". However, recompiling from the files exported by Reflector didn't work for me: I got 100 error and alot of warnings; obviously, the forms were missing but only their codes where decompiled. It has like 100 forms, and it is hard to redesign them (if that is even a considered a solution - not sure).

How do you suggest solving this? I need to change the IP as I can't use the software anymore!

Thanks!

A: 

You could try editing your local DNS settings. Open C:\WINDOWS\system32\drivers\etc\hosts and specify a redirect from the old IP to the new one.

You could also try contacting the original author and requesting a new build.

If you authored it you should definitely not hard code changeable variables such as IP addresses and domain names :)

Tom Gullen
I can't do it because another server is now using that old IP and I can't change it. Also, does this way means Windows will convert any IP address that I enter in that hosts file into the alias I type next to it? I tried it, but it still didn't work though. I am now trying to restart my machine to see if that takes effect.The original author is not reachable anymore.
johnshaddad
hosts is like a DNS, so it only works on names. Once you have an IP, it doesn't need DNS (or hosts). The only want to route is by changing the routes to your own router that routes the IP to the server you want (don't recommend)
Lou Franco
A: 

Instead of reflector, try ildasm

http://www.mactech.com/articles/mactech/Vol.19/19.12/NETbinaries/index.html

Lou Franco
Yup, this is what I am trying now.
johnshaddad
A: 

If you have a .NET exe that you don't have the source code for, you're going to need to brush up on Ildasm and Ilasm. Use Ildasm to covert the .EXE into Microsoft's Intermediate Language. Change the code there - it'll be in a text format, but the IL code will look more like assembly language than a 3GL. Once you've changed the IL, you can recompile to an .EXE with Ilasm. Yucky, but functional and probably your best choice without the original source.

mattmc3
I tried this yesterday, I could get the IL file, 150 MB, but was lazy to go open it in a suitable text editor - but now I am shifting to my lovely Linux machine to VIM it xDOnce I try I will let you know if I still can't get it to work. Thanks!
johnshaddad
cygwin is your friend for this. I inevitably need find or grep or vim and have to install it (or which!)
Lou Franco
So ildasm succesfully created the IL file. I found the IP inside it, changed it, and now when I used ilasm, I used the following command: ilasm /OUTPUT=file.exe source.il /exeIt said "****FAILURE****" Am I using the correct syntax? What is wrong?
johnshaddad
It said that "Could not open source.il"
johnshaddad
`ilasm source.il` should be all you need to run as /exe is the default. Be sure you're running it from the dir where source.il is located, or you'll have to specify the whole path. You should get source.exe out, which you can then rename whatever you want.
mattmc3
BTW - I think, I *THINK* - ildasm is what Reflector is using behind the scenes. I believe it takes a .NET library or EXE, calls ildasm or its API, and then converts the disassembled .il back to whatever language you've chosen as your view in Reflector. That's why public methods all have the correct naming, but when you look at the guts of a method you get the condensed internal names for locally scoped variables.
mattmc3
True, and thanks you solved my problem! I just needed a push to get "find" where ilasm was located on my machine LOL (I found ildasm yesterday, but couldn't find ilasm, so I gave up :P). Thanks again!
johnshaddad