Hello.

I am still a beginner in C# and FileWriting is my new learning step.

I created a project. Among other complicated things It needs to do the following:

1. Open EXE file
2. Click a button
3. Write&Save EXE information to a TXT file

Explanation:

There is a program that has an option to extract some information from it. I connected with that program and everything is fine.
Now, I need to make it able when I click EXPORT button to get a TXT file with information from the EXE file provided (I can load any EXE in Main program).

I need to information from EXE and save it to TXT. I already coded everything needed. I just need the code on how to save the contents of that particular section (I got that covered, there are multi sections to be extracted).
Is there some simple code snippet to do this? I already have a directive with all the code needed except code to write information from EXE to a TXT file.

REMEMBER:

I press a button, save a TXT file with data that is in memory waiting to be written.

Because when I press that button, all that information is in the buffer, just need to -> File.txt

Thanks for any help and best regards!

Recommended Answers

All 12 Replies

To write to a text file, use the System.IO.StreamWriter class. Example usage below:

String fileName = @"C:\Temp\myfile.txt";
    System.IO.StreamWriter writer = new System.IO.StreamWriter(fileName);

    writer.WriteLine("Writing a line to the text file");
    writer.Close(); // closing the file
    writer.Dispose(); // cleaning up resources

To write to a text file, use the System.IO.StreamWriter class. Example usage below:

String fileName = @"C:\Temp\myfile.txt";
    System.IO.StreamWriter writer = new System.IO.StreamWriter(fileName);

    writer.WriteLine("Writing a line to the text file");
    writer.Close(); // closing the file
    writer.Dispose(); // cleaning up resources

Thank you! Folks on other forums act like they knew everything the day they were bored so they give smartass answers.

Ok, we have a slight problem with this.

I do NOT NEED to write anything on my own like that writer.WriteLine text.

I need to grab information from memory buffer and put it in TXT file.

I am trying to extract some information from EXE file and I coded everything I need. But, I still need a way to store that extracted information to a TXT file.

1. Press "Dump Header" button
2. Other command line program processes the header dump information request
3. Write that dump information in TXT file

That's it!

Thanks again, you're the best!

Can you post what you have? Particularly the relevant bits about having read in the information about the EXE and identifying what you actually want to save to file.

Can you post what you have? Particularly the relevant bits about having read in the information about the EXE and identifying what you actually want to save to file.

I would really. I would post whole source on pastebin but I can't. It is a private work for a company and source could reveal several weakneses. I am doing this project in C# to practice memory streaming. I do Reverse Engineering for living.

As I tried to explain:

1. Press "Dump Header" button
2. Other command line program processes the header dump information request
3. Write that dump information in TXT file

When I press the button it automatically gathers bunch of information. That information is in the memory buffer and I need a way to write it in TXT file.
Everything else is coded. Information is good.
I JUST NEED A WAY TO PUT THAT INFORMATION FROM MEMORY TO TXT.

I can't explain it simplier.

Do you need what is called a hex-dump?

Nope...

I just need to store TEXT from memory into a output.txt file

>> 3. Write&Save EXE information to a TXT file (from your post #1)
That is exactly what apegram explained to you how to do it, don't you read his posts?

>> 3. Write&Save EXE information to a TXT file (from your post #1)
That is exactly what apegram explained to you how to do it, don't you read his posts?

Read the thread please.

I don't need to write what I want. I need to write WHAT IS IN MEMORY!

Read the thread.

commented: you're a little ungrateful -1

Why don't you say how the info is being stored in memory? Or do you want to dump your entire RAM to disk just to be sure? If the buffer is stored as a MemoryStream the process for writing would be slightly different than, say, a StringBuilder .

Why don't you say how the info is being stored in memory? Or do you want to dump your entire RAM to disk just to be sure? If the buffer is stored as a MemoryStream the process for writing would be slightly different than, say, a StringBuilder .

Process is this.

After pressing DUMP button, another console program is called. That program writes information I need. I could use that console program to dump the information to temp file easily by itself, but I need GUI application and do it with a button.
Example would be "console_dumper.exe -dump sample.exe -> sample.txt
So what I want to exactly that the same but with press of a button instead writing it in the console.

I already coded everything needed so I just need a code that will write down that information that console dumper collected to a TXT file.

So when I press a button, console dumps the EXE and writes the TXT file in local folder.

Dumping entire RAM would be nice =) but I only need information from RAM that I need. But we could try it that way.

I hope I explained well how I get the information from EXE and what needs to be done on a button press.

---------

And thank you guys really much for helping!

Because you don't give us any code, we are only trying to guess what you really want. It's like a blind man, who is trying to hit an egg with a stick, as we say over here.
So is it something like this you want in your button click event handler?

Because you don't give us any code, we are only trying to guess what you really want. It's like a blind man, who is trying to hit an egg with a stick, as we say over here.
So is it something like this you want in your button click event handler?

Thanks for the link. I will check it out now.

Again, I would gladly show the source, but I just can't. I am trying to explain what needs to be done. I can't do much more.
Sorry.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.