Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.40/5 (3 votes)
See more:
I have Exe File. Because I don't Have A Exe Source. I'm Very Bad Speak English so I want you to say by drawing;

http://i.imgur.com/Hg4P4Sm.png

C#
byte[] MyFileAsd = new byte[] { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9 };

  private void button1_Click(object sender, EventArgs e)
  {
      string File = Application.StartupPath + @"\originalExe.exe";

      Process.Start(File);

      //I want to print MyFile.asd to OriginalExe's memory, so MyFile.asd will act like it's on OriginalExe.exe. Thus, OriginalExe.exe will act like it's reading MyFile.asd without any errors, but it'll actually be reading my byte[] MyFileAsd = new byte[] { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9 };

  }

I'm not from the US. because I'm need Help. Do you not understand what I say to ?
Posted
Updated 24-Aug-14 8:37am
v4
Comments
[no name] 24-Aug-14 14:26pm    
Well I am pretty sure that you are not actually from the US and it's pretty obvious that English is not your native language. You might consider going over to google translate and typing your question out in whatever your native language is, translating that to English and then posting the translation here. Posting a link to an unhelpful picture does not really help.

I think I follow. I will try to help in simple English.

Now you have:
  • a data file (asd)
  • an application (originalExe)

Now application can read data file and it does something useful.

Your problem is:
You do not want to use data file. You want to run a second application with data in memory instead. You want to pass values in memory to originalExe without a data file.

This is very easy in UNIX, because applications accept input from stdin and output to stdout but in Windows it is harder. The easy way is make a temporary file.
C#
using System.IO;

byte[] MyFileAsd = new byte[] { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9 };

  private void button1_Click(object sender, EventArgs e)
  {
      // Write data to temporary file.
      string temp = Path.GetTempFileName();
      File.WriteAllBytes(temp, FyFileAsd);
      string exe = Application.StartupPath + @"\originalExe.exe";

      Process.Start(exe, temp);
  }
 
Share this answer
 
v2
Comments
osmanylmz 24-Aug-14 14:49pm    
Thank yo for understand me @Yvan Rodrigues. because I need Safe My File. So I Dont Need make a temporary file. you know?
Sergey Alexandrovich Kryukov 24-Aug-14 15:29pm    
(Sigh...) Sorry: here are your mistakes:
1) A Windows application can use standard input, output and error streams, exactly as with Unix. They can be used through redirection, exactly as I explained in Solution 2.
2) If some of standard streams are used in the application to be started, your approach won't help to access them.
3) You cannot be sure that command-line parameters are required by this application, but even if they are, you cannot be sure that the format is the one you assumed. It could confuse OP. If, for example, the format is "originalExe -f file_name", your command line won't work; and you did not explain why.

I don't think you can say I was unfair to your answer. Sorry, anyway.

—SA
Yvan Rodrigues 24-Aug-14 16:14pm    
1. I agree. Unfortunately for every Windows application that takes input from stdin there are 100 in UNIX that do. It is the norm in UNIX. It is the exception in Windows, which it too bad.
2. My solution makes the assumption that standard streams aren't used. I'm trying to keep the solution simple for the guy. In the unlikely event that his application can handle standard IO streams or even pipes, I doubt either of us could explain redirection in terms he can understand.
3. True. My point was that he probably needs a temporary file, not do his work for him. If he needs a -f or something, he seems bright enough that he can lookup Process.Start.
osmanylmz 24-Aug-14 17:06pm    
Are we really can't do it?
You did not explain the functionality of the OriginalExe.exe application, what is expected on input, how the output is delivered.
It's very usual for applications to have input in a command line, and output could be in a file, or standard output stream. More rarely, interactive input to the standard input stream is required. In all such cases, you can simulate required input and capture output.

For command line input, you can use the second parameter of the method Process.Start, as shown in Solution 2.

If you need to work with standard input or standard output stream, you can use redirection of those stream. Just in case, also use redirection of standard error stream. Redirection is explained here:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardinput(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standarderror(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardinput(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandarderror(v=vs.110).aspx[^],
see also: http://msdn.microsoft.com/en-us/library/0w4h05yb(v=vs.110).aspx[^].

I would also add that relying on some executable without source code could endanger your business. If possible, it would be important to write required functionality by yourself, or use reputed maintained library, instead of System.Diagnostics.Process.Start.

—SA
 
Share this answer
 
Comments
osmanylmz 24-Aug-14 17:06pm    
Are we really can't do it?
Sergey Alexandrovich Kryukov 24-Aug-14 20:14pm    
What are you talking about? Do what? Who are "we"?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900