Tool for writing files

Source: Internet
Author: User

File bundling can be used in many places, such as Trojans. You can also bind the DLL to the end of the EXE file when releasing the software, and then dynamically call the DLL when executing the EXE file ..

Compiling environment: Win2k + vc6.

Let's assume that we want to merge.

To put it bluntly, if a file in PE format does not modify the content in the file header or in the middle of the file, but only adds data to the end of the file, the PE file can be executed normally. You can try
Run copy upload in command line mode.
To execute. OK. This is the problem we want to solve today. This is my idea. Prepare is the program we want to bind.
The structure is as follows:

---------------------------------------
| Aaa.exe | test1.exe | test2.exe |
---------------------------------------

The worker does more work. What he wants to do is to read test2.exe and save it as C:/test2.exe. then, read the content of test1.exe and save it as C:/test1.exe. 2. Call createprocessto create two new processes: test1.exeand test2.exe. 3. Call exitprocess to end its own process.
In this way, our goal is achieved. For example, we can disable the aaa.exe window.

But there is another question. When reading the question, how can we find out which data is test1.exe, and which data is test2.exe? Then we can try to expand the above structure.

-----------------------------------------------------
| Aaa.exe | test1.exe | test2.exe | len2 | len1 |
-----------------------------------------------------

Add two pieces of data at the end of the file to save the length of test1.exeand test2.exe. And the Fixed Length of len2 and len1 is 30 bytes. Contents.

Take a look at the key code of the aaa.exe program:

Cfile fsource (_ pgmptr, cfile: moderead | cfile: modenotruncate); // get the file length to target.exe
Int isourcelength = fsource. getlength ();
Fsource. Seek (iSourceLength-60, cfile: Begin); // move the file to the end of test2.exe

Char buffer [40];
Zeromemory (buffer, 40 );
Fsource. Read (buffer, 30); // read the content of len2and the length of test2.exe.

Int itargetlength = atoi (buffer );
Fsource. Seek (iSourceLength-iTargetLength-60, cfile: Begin); // move the file to the beginning of test2.exe

Cfile ftarget ("C: // test2.exe", cfile: modecreate | cfile: modewrite |

Cfile: modenotruncate); // create a new file: C: // test2.exe

Char * pbuffer = new char [itargetlength]; // allocate a buffer
Zeromemory (pbuffer, itargetlength );
Fsource. Read (pbuffer, itargetlength); // read the test2.exe file to the buffer.
Ftarget. Write (pbuffer, itargetlength); // write the buffer content to C:/test2.exe
Delete [] pbuffer;

Now the test2.exefile has been read, and the process of reading the content of test1.exe is similar.

Fsource. Seek (iSourceLength-30, cfile: Begin); // move the file pointer to the beginning of len1
Zeromemory (buffer, 40 );
Fsource. Read (buffer, 30); // read the content of len1. the content of len1is the length of test1.exe.

Int filelen = atoi (buffer );
Fsource. Seek (iSourceLength-60-filelen-iTargetLength, cfile: Begin); // move the file pointer to the test1.exe File Header
Ftarget. Open ("C: // test2.exe", cfile: modecreate | cfile: modewrite | cfile: modenotruncate );

Pbuffer = new char [filelen];
Zeromemory (pbuffer, filelen );

Fsource. Read (pbuffer, filelen); // read the test1.exe file to the buffer.
Ftarget. Write (pbuffer, filelen); // write the test1.exe file to C:/test1.exe
    
Delete [] pbuffer;
Fsource. Close ();
Ftarget. Close ();

Now we can use CreateProcess to run and create two new processes to run C:/test1.exe and C:/test2.exe. The code for creating a new process is simple and I will not write it.

This part is written, but the part of the bundled file has not been written. Create a new dialog box-based program.

Cfile fsource ("C: // aaa.exe", cfile: modereadwrite | cfile: modenotruncate); // compile your aaa.exe
Fsource. seektoend (); // move the file pointer to the end of the file

Cfile ffirstfile (m_firstfile, cfile: moderead | cfile: modenotruncate); // This code uploads test1.exeto the end of aaa.exe
Int ilen = ffirstfile. getlength ();
Int Len = ilen;
Char * pbuffer = new char [ilen];
Zeromemory (pbuffer, ilen );
Ffirstfile. Read (pbuffer, ilen );
Fsource. Write (pbuffer, ilen );
Ffirstfile. Close ();
Delete pbuffer;

Cfile fsecondfile (m_secondfile, cfile: moderead | cfile: modenotruncate); // This code is bundled with test2.exe
Ilen = fsecondfile. getlength ();
Pbuffer = new char [ilen];
Zeromemory (pbuffer, ilen );
Fsecondfile. Read (pbuffer, ilen );
Fsource. Write (pbuffer, ilen );
Fsecondfile. Close ();
Delete pbuffer;

 

Char tempbuffer [30]; // converts the length of test2.exe to a string. If the length is not 30, add a space to 30 and add it to the end of the file.
Zeromemory (tempbuffer, 30 );
ITOA (ilen, tempbuffer, 10 );
    
While (strlen (tempbuffer) <30)
{
Strcat (tempbuffer ,"");
}

Fsource. Write (tempbuffer, 30 );

Zeromemory (tempbuffer, 30); // converts the length of test2.exe to a string. If the length is not 30, add a space to 30 and add it to the end of the file.
ITOA (Len, tempbuffer, 10 );
    
While (strlen (tempbuffer) <30)
{
Strcat (tempbuffer ,"");
}
    
Fsource. Write (tempbuffer, 30 );

Fsource. Close ();

: MessageBox (null, "bundle completed", "prompt", mb_iconinformation );

OK ,we generated a new file target.exe. the structure of target.exe has been mentioned above. After target.exeis executed, aaa.exeis executed first. Then, both test1.exeand test2.exe are executed. To enhance adequacy, we can write the following code in the oninitdialog () function of aaa.exe:
Modifystyleex (ws_ex_appwindow, ws_ex_toolwindow );
: Movewindow (m_hwnd, 0, 0, 0, 0, true );
In this example, There is no window during execution of aaa.exe, and task entries are not displayed on the taskbar.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.