0

Basically, I just wan't to know how can this be achieved.

For example, suppose that I have to exe files, app1.exe and app2.exe. Now, app2.exe does a specific job basing on some settings defined on it's variables. I wan't to know how can I code the app1.exe to generate app2.exe files while defining different settings (variables) for it, without using any config file, registry or similar.

I don't have a specific project with this problem, but I was just wondering how this can be done.

--Inspired by the famous Trojan Horse ProRat. It does the same thing, it generates server.exe file with predefined settings from its server creator (another exe file). Furthermore it can bound with other files such as images, audio, video etc.

Trim Kadriu
  • 421
  • 3
  • 19
  • 1
    Define _generate_. Do you mean change the source code and compile? – Jacob Seleznev May 15 '14 at 21:56
  • Does this *generate* imply you only have app1.exe, run it, then you have app2.exe as well? – Jongware May 15 '14 at 21:59
  • @JacobSeleznev Well, I really don't know how else can this be done. If I take the ProRat example, I don't think it works this way, since it doesn't have any compiler or any external tool to do that. – Trim Kadriu May 15 '14 at 22:01
  • @Jongware Not necesarely all the app2.exe file should be created from scratch. Maybe app2.exe can exist as an embeeded resource of app1.exe and than somehow from app1.exe change only some variables of app2.exe and extract it from itself. Btw I'm just guessing how this may work. – Trim Kadriu May 15 '14 at 22:06
  • You can start reading about [reflection emit scenarios](http://msdn.microsoft.com/en-us/library/a6x89439(v=vs.110).aspx) – Jacob Seleznev May 16 '14 at 04:41
  • Thanks for your comments guys, I will start reading about reflection. Anyway, I found some interesting ideas for this problem that I will try if they works. Here it is: https://stackoverflow.com/questions/12718530/how-to-store-user-settings-completely-internally-in-an-exe-with-c-c – Trim Kadriu May 16 '14 at 22:55

1 Answers1

0

After this period of time, I found a solution to this problem by using code injection on file.

Below is my solution on steps:

  1. Since both exe files (app1.exe and app2.exe) are created by same person, you can create the app2.exe with some predefined variable values (like string setting1 = "${MYVAR}"), then compile and save the exe (app2.exe).
  2. Include app2.exe as an embeded resource on app1.exe (the app2.exe generator), and get input (usually from user) that will be used to replace setting1 variables value of app2.exe
  3. Read byte array of app2.exe on app1.exe (since it is embedded on it's resources) and convert it to HEX string
  4. From the string (that is converted from byte array) find value of setting1 variable (by firstly converting it also in byte array then in HEX string), and then replace it with the input you got in step 2 (by also converting in byte array then in HEX string).
  5. Convert the whole string (after replacing the values) back to byte array and save it as a file (app2.exe).

If someone want to see an example, I can put some code as proof of concept.

Trim Kadriu
  • 421
  • 3
  • 19