Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to make a program as console application. I want to get parameters from console like consoleapplication.exe value1 value2 but I want to make this static so then I enter this values into console application. I want to save this to exe. I saw some applications using this methods. Trojans etc..

Sorry for My English.

Thanks for help.
Posted
Updated 15-Mar-11 11:07am
v2
Comments
Toli Cuturicu 15-Mar-11 18:49pm    
Don't.

I'm afraid that's somewhat frowned upon - I would not enjoy being quoted as somebody who contributed to the development of a succesful destructive trojan. Remember that even if your motives aren't sinister at all - everything we do here is open for all to read and learn from.

As you tagged this post with c# I suggest you investigate the possibilities provided with System.Configuration[^]

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Henry Minute 15-Mar-11 17:56pm    
5.Exactly the reason I didn't answer.
Kutayy 15-Mar-11 18:07pm    
thanks for answer.my application is not trojan or virus...but I think we can't modify application settings if it's embedded.am I wrong ?
Espen Harlinn 15-Mar-11 18:24pm    
While modifying the executable might seem like a neat trick, I'd guess it would drive system administrators nuts and antivirus software wouldn't like your application either.

The classes from System.Configuration[^] is the "preferred" mechanism, but you can use the registry, or roll your own mechanism.

As you tagged the posting with c# I guess you are using .Net - so distributing your application as a single executeble probably isn't a real option anyway, it requires the .Net runtime, so you should probably create an installer anyway.
Sergey Alexandrovich Kryukov 15-Mar-11 19:22pm    
You're gravely wrong...
--SA
Sergey Alexandrovich Kryukov 15-Mar-11 19:21pm    
Perfect answer, my 5.
I don't think OP is going to make a trojan, just being sloppy...
--SA
You need to do just the opposite. You (and everyone) need to sign all the assemblies (at least for industrial/commercial applications) so no one would be able to modify any (in a more or less easy way).

The only valid way of modification of the code is re-build of the projects; the only valid way to modify the behavior of the existing software product is the data (including plug-ins: even though they are appear as executable modules, they are considered as data before they are loaded, the selection and loading of them is driven by data, even if this data is a simple command-line string).

Not only you code will be error prone and considered as a virus by a anti-viral/anti-spyware tools, this is the abuse of the technology. You never really need to modify and executable files (more exactly any PE file, including any .NET assembly modules). The benefits of it are questionable or insignificant (if any), the down-side is extremely nasty.

To read about theoretical grounds of this situation, you need to be aware of Von Neumann architecture, http://en.wikipedia.org/wiki/Von_Neumann_architecture[^], this architecture, in turn, implements the Universal Turing machine, http://en.wikipedia.org/wiki/Universal_Turing_machine[^].

Von Neumann architecture goes back to 40th, when the principles of isolation of code and data were recognized and used as a solid fundamental base for all real-life architectures implemented later. One of the purposes of resources embedded in the executable files was making them unmodifiable by putting them under the same umbrella as the code. Violation of these principles always leads to some dead end, at best.

—SA
 
Share this answer
 
v5
Comments
AspDotNetDev 15-Mar-11 19:55pm    
I don't presume to know the OP's intentions, but one popular example of when this is useful is WinZip. With WinZip, you are able to create a self-extracting EXE. That's very useful for users who do not understand files and programs very well. That also has its pitfalls, but my point is that embedding data into an EXE at runtime can be useful.
Sergey Alexandrovich Kryukov 15-Mar-11 20:21pm    
No, no! This is different case. Well, good point though. WinZip does not modify executable, it creates it. Consider WinZip as a compiler (even though it is not). Anyway, this is an exclusion, and not so good. I've written quite successful self-modifying code. Nevertheless, it's best to go away from this situation.

Now, wait! Read properly what I say. I advocate not changing executable. Embedding data in executable I mentioned as a good thing -- read again.

--SA
Espen Harlinn 16-Mar-11 7:20am    
My 5, Good points - security comes first :)
Sergey Alexandrovich Kryukov 16-Mar-11 15:46pm    
Thank you.
Security must be a stack but not a queue: it should come first, go last. :-)
--SA
There is the "simple" way and the hard way. Basically, you create a resource then modify it at runtime, creating a new EXE in the process.
 
Share this answer
 
Comments
Kutayy 15-Mar-11 17:28pm    
I think I have to create new exe in the process.cuz there is not way to edit embedded resource.and I don't want to use linked resource.thanks for answer.do you know how to create exe in the process ?
AspDotNetDev 15-Mar-11 17:37pm    
Read the links in my answer. They don't say to modify the current EXE.
Kutayy 15-Mar-11 18:10pm    
what about create new exe from process ? your links say "Create new resource and Import" I just want to change some static variables in my application.
AspDotNetDev 15-Mar-11 18:13pm    
Not sure what you mean. You can create a property and reference that rather than a static variable. That property can grab the value from the resource. The resource will have been embedded into the EXE dynamically using the processes I described in the two links I gave you.
Sergey Alexandrovich Kryukov 15-Mar-11 19:42pm    
Any way of modification of executable modules (not only .NET assembly modules, but any PE files is bad. (I did not vote for your Answer even though it maybe technically applicable.)
Please see my Answer and discussion to Espen's Answer.
--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