Click here to Skip to main content
15,924,039 members
Home / Discussions / C#
   

C#

 
GeneralRe: Design time collection problem Pin
kanchoette30-Dec-08 11:51
kanchoette30-Dec-08 11:51 
GeneralRe: Design time collection problem Pin
Wendelius30-Dec-08 11:56
mentorWendelius30-Dec-08 11:56 
QuestionReceiving Email prob using c# Pin
Abdul Rahman Hamidy30-Dec-08 9:20
Abdul Rahman Hamidy30-Dec-08 9:20 
AnswerRe: Receiving Email prob using c# Pin
EliottA30-Dec-08 14:27
EliottA30-Dec-08 14:27 
GeneralRe: Receiving Email prob using c# Pin
Abdul Rahman Hamidy30-Dec-08 15:05
Abdul Rahman Hamidy30-Dec-08 15:05 
GeneralRe: Receiving Email prob using c# Pin
Christian Graus30-Dec-08 18:02
protectorChristian Graus30-Dec-08 18:02 
GeneralRe: Receiving Email prob using c# Pin
Abdul Rahman Hamidy30-Dec-08 18:44
Abdul Rahman Hamidy30-Dec-08 18:44 
QuestionHow to find/replace a hard coded connection string in a binary file? Pin
Ryan Neil Shaw30-Dec-08 7:43
Ryan Neil Shaw30-Dec-08 7:43 
Hello fellow developers,

I have written an application to find and replace just about anything. It even has a nice web interface and keeps everything stored in a SQL Server DB.

I have no problem finding what I am looking for, the issue comes when I replace a hard coded string inside of an EXE or DLL.

For simplicity sake I just grab the whole file as bytes, use Encoding to get me a string, and use a RegEx to Find / Replace what I am searching for. I then take the string with the values replaced and use Encoding to switch it back to bytes and overwrite the file.

This works fine on text, but DLLs and EXEs appear to have been corrupted. I get the following error when I try to execute the EXE or and executable that references a DLL I have replaced the strings inside of.
Here is a copy of the Exception, 'ConfigurationManagement.Controllers' is the DLL I changed:
System.BadImageFormatException was unhandled
Message: Could not load file or assembly 'ConfigurationManagement.Controllers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The module was expected to contain an assembly manifest.

I am assuming I am writing the file incorrectly and by adding new bytes to it, that there is some internal data inside the DLL or EXE that does not match its file size and locations anymore.

Does anyone know how to correctly edit the strings inside of a binary file?

Kind Regards,
Ryan
GeneralRe: How to find/replace a hard coded connection string in a binary file? Pin
Luc Pattyn30-Dec-08 7:48
sitebuilderLuc Pattyn30-Dec-08 7:48 
GeneralWow... any File I/O experts around Pin
Ryan Neil Shaw30-Dec-08 8:05
Ryan Neil Shaw30-Dec-08 8:05 
GeneralRe: Wow... any File I/O experts around Pin
Luc Pattyn30-Dec-08 9:49
sitebuilderLuc Pattyn30-Dec-08 9:49 
GeneralRe: Wow... any File I/O experts around Pin
Ryan Neil Shaw30-Dec-08 10:17
Ryan Neil Shaw30-Dec-08 10:17 
GeneralRe: Wow... any File I/O experts around Pin
Luc Pattyn30-Dec-08 10:27
sitebuilderLuc Pattyn30-Dec-08 10:27 
AnswerRe: How to find/replace a hard coded connection string in a binary file? Pin
Dave Kreskowiak30-Dec-08 7:59
mveDave Kreskowiak30-Dec-08 7:59 
GeneralGood Point Pin
Ryan Neil Shaw30-Dec-08 8:08
Ryan Neil Shaw30-Dec-08 8:08 
AnswerRe: How to find/replace a hard coded connection string in a binary file? Pin
Giorgi Dalakishvili30-Dec-08 8:29
mentorGiorgi Dalakishvili30-Dec-08 8:29 
GeneralCool! Pin
Ryan Neil Shaw30-Dec-08 8:36
Ryan Neil Shaw30-Dec-08 8:36 
QuestionHow to catch a exception from another class? Pin
softwarejaeger30-Dec-08 4:13
softwarejaeger30-Dec-08 4:13 
AnswerRe: How to catch a exception from another class? Pin
Christian Graus30-Dec-08 4:25
protectorChristian Graus30-Dec-08 4:25 
GeneralRe: How to catch a exception from another class? Pin
softwarejaeger30-Dec-08 4:31
softwarejaeger30-Dec-08 4:31 
AnswerRe: How to catch a exception from another class? Pin
karoitay30-Dec-08 4:29
karoitay30-Dec-08 4:29 
AnswerRe: How to catch a exception from another class? Pin
PIEBALDconsult30-Dec-08 4:43
mvePIEBALDconsult30-Dec-08 4:43 
AnswerRe: How to catch a exception from another class? Pin
Wendelius30-Dec-08 5:35
mentorWendelius30-Dec-08 5:35 
AnswerRe: How to catch a exception from another class? Pin
#realJSOP30-Dec-08 6:58
professional#realJSOP30-Dec-08 6:58 
AnswerRe: How to catch a exception from another class? Pin
Daniel Grunwald30-Dec-08 8:51
Daniel Grunwald30-Dec-08 8:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.