Add code to existing EXE

At school we have been hearing about this in lectures of system protection and since I've never came upon this before I was wondering, is it possible to actualy modify an existing exe file (like notepad.exe) to add come functions to be called on execution? I've found something about modifying it in assembly.

I'm asking if it is possible to do it in C++, adding a simple messagebox like in that example.

I have reviewed this in AutoIt, so I thought it must also work in C++, can anyone show me any examples?
closed account (Dy7SLyTq)
well you can do it at the ml level or if it has a dll replace it with an updated on
ml? is that like machine code as assembler?

and I chose notepad.exe since I'm pretty sure it doesn't have any dlls. Or did you mean I should create a dll to inject it?
Disassemble your program, find an entry point, do a jump after it to some unused area, place ypur code here, jump back.

That an oversimpification of what you need to do.

Then you can write a C++ program which will change some bytes int target exe to do what you want.

TL;DR:
You can, but you still need to know assembly for that.

Edit: There is programs like Joiner which can do almost what you asked, but in a different way. And almost every antivirus software see them as trojans
Last edited on
@MiiNiPaa
So most viruses and stuff are done in assembly?
Are we speaking about polymorfic self-propagating viruses, which can infect file without hampering it workings? If so, then you should know assembly to succesfully write it. However almost any language can be used to write a body of virus (but assembly usually get you smaller files which is important to viruses)

If we speaking about "viruses" which blocks access to registry, settings, displays baner on desctop and intimidating you to send money to somebody or you will be sued for something, then they can be written even in batch files.
tehnically I was just wondering if/how it can be done in c++, just a basic example, since a scripting language like autoit supports it. I came upon this when one of my friends asked me to make an "automated instalation" in autoit for a school project.
There is programs like Joiner which can do almost what you asked, but in a different way. And almost every antivirus software see them as trojans

It is like self-extracting archives with script: it unpack all files you want to run and simle program into temp folder, then runs simple program which take care of running other programs. It will not alter existing files.
MiiNiPaa wrote:
tehnically I was just wondering if/how it can be done in c++, just a basic example, since a scripting language like autoit supports it. I came upon this when one of my friends asked me to make an "automated instalation" in autoit for a school project.



AutoIT does not change any executables, it just simulates keyboard and mouse clicks using APIs like SendInput(). You can use it from C/C++ too.
from what I've seen it merged two files into one, which is hardly mouseclick or keyboard press.
As I say (and not I was quoted for):
It is like self-extracting archives with script: it unpack all files you want to run and simle program into temp folder, then runs simple program which take care of running other programs. It will not alter existing files.

Like explained here: http://techzil.com/file-binding-its-like-mixing-poison-in-a-drink/
Topic archived. No new replies allowed.