开发者

Changing a string literal (connection string) in a program without being able to access the original source

开发者 https://www.devze.com 2023-03-25 12:25 出处:网络
I need to change the connection string that is hard-coded in a single class for a program I created. I no longer have the original source code for the program in question, but I have decompiled it and

I need to change the connection string that is hard-coded in a single class for a program I created. I no longer have the original source code for the program in question, but I have decompiled it and have access to that.

I've tried re-compiling the decompiled source, but run into issues with the decompiled code being slightly different and requiring numerous changes. I've also tried recre开发者_C百科ating the class as a DLL without success. I think either of these approaches could work, but there is something I'm missing. Can anyone point me in the right direction, or suggest something simpler that I'm not thinking of?


If your corrected connection string is the same size or shorter than the old one, you should be able to edit the bytecode directly in a hex editor and overwrite the string with your new one. Just remember to change the string length and add 00 00 at the end:

In the .NET CLR, strings are laid out in memory pretty much the same way that BSTRs were implemented in OLE Automation: as a word-aligned memory buffer consisting of a four-byte integer giving the length of the string, followed by the characters of the string in two-byte chunks of UTF-16 data, followed by two zero bytes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号