Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top