The download sample program code combines multiple files into a final executable, and when running this final file, it is equivalent to running multiple files before the merge. This program will often use in Trojan program, do you want to know how it is implemented? Below I use the example code of a file bundle made with VC6.0 to tell you that the interface is running as follows: Figure one basic composition of thought: in fact, the composition of the idea is very simple. Create a new binary, first write your bundle data and its file length, then write the data of the first file you want to bundle and its file length, then write directly to the second you want to bundle Data and file length of files ..., in the end, you can write directly to the last file you want to bundle (no file length). The final file is executed, that is, the above method is inverted. (The following example only tells you how to implement the bundle of two files, as for the bundle of multiple files, readers only need to change the change or both, please read the instance code after downloading.) Let me talk about how to specifically To achieve: 1. Bundle multiple files for an executable first get the file length of your own bundle and the first file length to bundle file, enumerate the first to bundle the file, there is an icon, if you use It is an icon that eventually generates files, otherwise use the default icon with your own bundle to do the icon that finally generates files. Write the data of your own bundle in the new binary file and its file length, then write the first data to bundled files and its file length, and finally written directly to the second file can be used. The bundle number code is implemented as follows: // Bind multiple files as an executable Bool cbindfiledlg :: bind_files ()
{
File * myself; // own file
File * out; // final synthetic file
FILE * IN; // Terfer to be bound
Int Bytesin;
INT TOTALBYTES = 0;
Struct_stat st;
Unsigned int founder = 0x12345678;
Unsigned Int I, K;
INT L = 1; // status display
CHAR BUFF [20]; // State display
His_name = strfirstfilepath; // The first bound file name
_stat (my_name, & st);
Modify_data.my_length = st.st_size;
IF (MODIFY_DATA.MY_LENGTH == 0)
{
MessageBox ("Bind file, the length of your own file is zero when it is zero!", "Error");
Return False;
}
BUF = (Byte *) Malloc (MODIFY_DATA.MY_LENGTH);
IF (buf == NULL)
{
MessageBox ("Binding files, error when allocating your own file length!", "Error");
Return False;
}
myself = fopen (my_name, "rb"); // Open your own file
IF (myself == null)
{
Free (BUF);
MessageBox ("Binding files, make an error when you open your own file!", "Error");
Return False;
}
BYTESIN = FREAD (buf, 1, modify_data.my_length, myself);
Fclose (Myself);
IF (Bytesin! = modify_data.my_length)
{
Free (BUF);
MessageBox ("Binding files, you can't fully read your own file content!", "Error"); return false;
}
For (i = 0; i { For (k = 0; K { IF (BUF [i K]! = ((byte *) & finder) [K]) Break; } IF (k == sizeof (finder)) // positions and saves its own data file size { Memcpy (Buf I, & Modify_Data, Sizeof (MODIFY_DATA)); Break; } } IF (i> = modify_data.my_length - sizeof (finder)) { Free (BUF); MessageBox ("Bind file, error when you can locate your own file!", "Error"); Return False; } IF (_stat (strfirstfilepath, & st)! = 0 || St.st_size == 0) { Free (BUF); MessageBox ("Binding files, read the first error when you want to bind files!", "Error"); Return False; } List_my_icons (); OUT = FOPEN (StrfinalFilePath, "WB"); // Creating the final synthetic file IF (out == NULL) { Free (BUF); MessageBox ("Binding files, errors when creating bindings!", "Error"); Return False; } TotalBytes = fwrite (buf, 1, bytesin, out); IN = fopen (strfirstfilepath, "rb"); // Open the first file to be bound IF (in == NULL) { Free (BUF); Messagebox ("Bind file, open the first error when you want to bind the file!", "Error"); Return False; } // Write the first length to bind files to the synthetic file TotalBytes = fwrite (& St.st_size, 1, sizeof (st.st_size), out); // Write the flag bit (synchronous or asynchronous execution) of the file execution mode after the final decomposition Updatedata (TRUE); / / transmission control value to variable m_sync Totalbytes = fwrite (& M_Sync, 1, Sizeof (int), out); While (Bytesin = FREAD (BUF, 1, Modify_Data.my_length, in)) { TotalBytes = fwrite (buf, 1, bytesin, out); } Fclose (in); // Close the first binding file handle // Set the progress bar display M_Progress.SetRange (0,500); For (int m = 0; M <500; M ) M_Progress.SETPOS (M); m_parts = _LTOA (L, BUFF, 10); m_parts = _t ("a file is bound"); Updatedata (false); l ; IN = fopen (strSecondFilePath, "RB"); // Open the second file to be bound IF (in == NULL) { Free (BUF); MessageBox ("Binding files, open the second to bind files, error!", "Error"); Return False; } While (Bytesin = FREAD (BUF, 1, Modify_Data.my_length, in)) { TotalBytes = fwrite (buf, 1, bytesin, out); } // Set the progress bar display M_Progress.SetRange (0,500); For (int N = 0; n <500; n ) M_Progress.SETPOS (N); m_parts = _LTOA (L, BUFF, 10); m_parts = _t ("a file is bound"); Updatedata (FALSE); l ; Fclose (in); // Close the second binding file handle Fclose (out); // Close the final synthetic file handle Free (BUF); // Release buffer Return True; } 2, release the final synthesis file and run them at the same time. Open your own file, you get the file length of your own bundle, you can locate the file pointer to the first bundled file, read its file length and its data, and read the data to the first new file. in. Similarly, the number of bytes of the two file length values can be saved by the file length of the read self-bundle file and the file length of the first bundled file, can accurately position the second bundled file. Read their data and write into the second new file. At the same time, running these two files, and finally deleting these two files can be used. The code that releases the final synthesis file is implemented as follows: // Decompose the merged file, and run them void cbindfiledlg :: unbind () { File * myself; // own file FILE * OUT; // After breaking the file Int Bytesin; INT TOTALBYTES = 0; Char Temp_exe1 [] = "temp1.exe"; // Decomposed binding file name Char Temp_exe2 [] = "Temp2.exe"; // Decomposed binding file name two INT syncflag; // File final execution flag BUF = (Byte *) Malloc (MODIFY_DATA.MY_LENGTH); Myself = fopen (my_name, "rb"); // Open the final synthesis file IF (myself == null) { Free (BUF); Messagebox ("I have an error in the Isolated File!", "Error"); Return; } OUT = FOPEN (Temp_exe1, "WB"); // Create the first bound file IF (out == NULL) { Free (BUF); MessageBox ("In the Isolate file, create the first binding file, error!", "Error"); Return; } // Position the file pointer to the length of the bundle program FSeek (myself, modify_data.my_length, seek_set); // Read the length of the first binding file IF (& PROG1_LENGTH, SIZEOF (PROG1_LENGTH), 1, Myself) == 0) { Free (BUF); Messagebox ("Separate file, read the first binding file length!", "Error"); Return; } / / Read the final file execution mode (synchronous or asynchronous execution) IF (& SyncFlag, Sizeof (int), 1, myself) == 0) { Free (BUF); Messagebox ("Separate file, read the first binding file length!", "Error"); Return; } / / Read the first file content and write While (bytesin = fread (buf, 1, sizeof (buf), myself) { IF (Totalbytes Bytesin> PROG1_LENGTH) BYTESIN = PROG1_LENGTH - TOTALBYTES; TotalBytes = fwrite (buf, 1, bytesin, out); } Fclose (out); // Close the first binding file handle #ifdef debug_print FPRINTF (stderr, "copy% D byte! / n", totalbytes); #ENDIF Debug_Print TotalBytes = 0; OUT = FOPEN (Temp_exe2, "WB"); // Create a second binding file IF (out == NULL) { Free (BUF); MessageBox ("In the Isolation file, create a second binding file when you have a binding file!", "Error"); Return; } // Position the file pointer to the second binding file header in the final synthesis file, offset == // (Bundlers own file length Save the first binding file length Charter number Save the final file execution flag accounts bytes first binding file length) FSeek (myself, modify_data.my_length sizeof (modify_data.my_length) sizeof (int) prog1_length, seek_set); / / Read the second binding file content and write While (bytesin = fread (buf, 1, sizeof (buf), myself) { TotalBytes = fwrite (buf, 1, bytesin, out); } Fclose (out); // Close the second binding file handle #ifdef debug_print FPrintf (stderr, "replicated% D byte / n", totalbytes); #ENDIF Debug_Print Fclose (myself); // Close the final synthetic file handle IF (totalbytes == 0) { Free (BUF); MessageBox ("Separation file, there is no separated object in your own file!", "Error"); Return; } Free (BUF); // Release buffer IF (! syncflag) // 0 - Synchronous execution, 1 - asynchronous execution { // After being decomposed, it is performed for synchronous execution. Create_Process (Temp_exe1, False); Create_Process (Temp_exe2, False); Else { // After being decomposed, it is an asynchronous execution method. CREATE_PROCESS (TEMP_EXE1, TRUE); CREATE_PROCESS (TEMP_EXE2, TRUE); } } In the specific implementation details, you can carefully view the (detailed note) after downloading the instance code.