Знающий
Регистрация: 26.07.2009
Адрес: Россия, Москва
Сообщений: 318
Написано 103 полезных сообщений (для 331 пользователей)
|
Ответ: Потестируйте
Сообщение от jimon
хорошая манера - возможность указывать патчеру что патчить
|
Дык все есть. Прога ищет некую сигнатуру в файлах exe и dll, если находит - добавляет имя файла в checklistbox. Потом если юзверю поставит галки будет патчить. Алгоритм примерно такой, только просто с гуи и рекурсивным обходом каталогов:

Type
BufferType = Array[0..MaxLongInt-1] of Byte;
pBuffer = ^BufferType;
Const
Id : Array [0..23,0..7] of Byte = ( // [7] - length, 01 - replace char
($3d,$47,$65,$6e,$75,$00,$00,$05),($3d,$69,$6e,$65,$49,$00,$00,$05),($3d,$6e,$74,$65,$6c,$00,$00,$05), //cmp eax
($81,$fb,$47,$65,$6e,$75,$00,$06),($81,$fb,$69,$6e,$65,$49,$00,$06),($81,$fb,$6e,$74,$65,$6c,$00,$06), //cmp ebx
($81,$f9,$47,$65,$6e,$75,$00,$06),($81,$f9,$69,$6e,$65,$49,$00,$06),($81,$f9,$6e,$74,$65,$6c,$00,$06), //cmp ecx
($81,$fa,$47,$65,$6e,$75,$00,$06),($81,$fa,$69,$6e,$65,$49,$00,$06),($81,$fa,$6e,$74,$65,$6c,$00,$06), //cmp edx
($81,$fd,$47,$65,$6e,$75,$00,$06),($81,$fd,$69,$6e,$65,$49,$00,$06),($81,$fd,$6e,$74,$65,$6c,$00,$06), //cmp ebp
($81,$fe,$47,$65,$6e,$75,$00,$06),($81,$fe,$69,$6e,$65,$49,$00,$06),($81,$fe,$6e,$74,$65,$6c,$00,$06), //cmp esi
($81,$ff,$47,$65,$6e,$75,$00,$06),($81,$ff,$69,$6e,$65,$49,$00,$06),($81,$ff,$6e,$74,$65,$6c,$00,$06), //cmp edi
($81,$7d,$01,$47,$65,$6e,$75,$07),($81,$7d,$01,$69,$6e,$65,$49,$07),($81,$7d,$01,$6e,$74,$65,$6c,$07) // cmpl -0x4(%ebp)
);
Rp : Array [0..23,0..7] of Byte = (
($a9,$00,$00,$00,$00,$FF,$FF,$05),($a9,$00,$00,$00,$00,$FF,$FF,$05),($a9,$00,$00,$00,$00,$FF,$FF,$05),
($f7,$c3,$00,$00,$00,$00,$FF,$06),($f7,$c3,$00,$00,$00,$00,$FF,$06),($f7,$c3,$00,$00,$00,$00,$FF,$06),
($f7,$c1,$00,$00,$00,$00,$FF,$06),($f7,$c1,$00,$00,$00,$00,$FF,$06),($f7,$c1,$00,$00,$00,$00,$FF,$06),
($f7,$c2,$00,$00,$00,$00,$FF,$06),($f7,$c2,$00,$00,$00,$00,$FF,$06),($f7,$c2,$00,$00,$00,$00,$FF,$06),
($f7,$c5,$00,$00,$00,$00,$FF,$06),($f7,$c5,$00,$00,$00,$00,$FF,$06),($f7,$c5,$00,$00,$00,$00,$FF,$06),
($f7,$c6,$00,$00,$00,$00,$FF,$06),($f7,$c6,$00,$00,$00,$00,$FF,$06),($f7,$c6,$00,$00,$00,$00,$FF,$06),
($f7,$c7,$00,$00,$00,$00,$FF,$06),($f7,$c7,$00,$00,$00,$00,$FF,$06),($f7,$c7,$00,$00,$00,$00,$FF,$06),
($f7,$45,$01,$00,$00,$00,$00,$07),($f7,$45,$01,$00,$00,$00,$00,$07),($f7,$45,$01,$00,$00,$00,$00,$07)
);
AsmC : Array [0..23] of String[40] = (
'cmp eax,0756E6547 ;"uneG"',
'cmp eax,049656E69 ;"Ieni"',
'cmp eax,06C65746E ;"letn"',
'cmp ebx,0756E6547 ;"uneG"',
'cmp ebx,049656E69 ;"Ieni"',
'cmp ebx,06C65746E ;"letn"',
'cmp ecx,0756E6547 ;"uneG"',
'cmp ecx,049656E69 ;"Ieni"',
'cmp ecx,06C65746E ;"letn"',
'cmp edx,0756E6547 ;"uneG"',
'cmp edx,049656E69 ;"Ieni"',
'cmp edx,06C65746E ;"letn"',
'cmp ebp,0756E6547 ;"uneG"',
'cmp ebp,049656E69 ;"Ieni"',
'cmp ebp,06C65746E ;"letn"',
'cmp esi,0756E6547 ;"uneG"',
'cmp esi,049656E69 ;"Ieni"',
'cmp esi,06C65746E ;"letn"',
'cmp edi,0756E6547 ;"uneG"',
'cmp edi,049656E69 ;"Ieni"',
'cmp edi,06C65746E ;"letn"',
'cmpl [ebp][-04],0756E6547 ;"Genu"',
'cmpl [ebp][-0C],049656E69 ;"Ieni"',
'cmpl [ebp][-14],06C65746E ;"letn"');
Var
F : File;
Buf : Pointer;
i,j,k,tmp,count,
Size : cardinal;
CB : Byte; //current byte;
SB : Byte; //save original byte
function IntToHex(IntValue: cardinal; Digits: integer): string;
var
i, j: cardinal;
s: string;
begin
s := '';
if IntValue > 0 then
begin
i := IntValue;
while i>0 do
begin
j := i mod 16;
if (j<10) then
s := Chr(Ord('0') + j) + s
else
s := Chr(Ord('A') + (j - 10)) + s;
i := i div 16;
end;
end;
if Digits < 1 then Digits := 1;
i := Digits - Length(s);
while i>0 do
begin
s := '0' + s;
i := i - 1;
end;
IntToHex := s;
end;
Begin
WriteLn(#13+#10+'Patcher for Intel Compiler(TM), disable "GenuineIntel" checking.'+#13+#10+
'Original perl version (C) Copyright M. D Mackey 2004.'+#13+#10+
'Port to Win32/PE v0.3 (C) Copyright Tronix 2010.'+#13+#10);
If ParamCount < 1 then
Begin
Writeln('Usage: icc_patch <filename> [option]'#13#10#13#10+
' Options: /F - force patching');
Halt;
End;
Count := 0;
Assign(F,{'e:\vp21\out.w32\1.txt'}Paramstr(1));
Reset(F,1);
If IOResult <> 0 then
Begin
WriteLn('Error open file ',Paramstr(1));
Halt;
End;
Size := FileSize(F);
GetMem(Buf,Size);
Write('Reading file into memory...');
BlockRead(F,pBuffer(Buf)^,Size);
Close(F);
Writeln(' done!'+#13+#10+'Searching...');
For i := 0 to Size-1 do
Begin
tmp := i; //save current POS
For k := 0 to 23 do
Begin
asm
xor eax,eax //j = 0,
mov edi, Buf
mov edx, i //i
cmp edx,size
ja @exit
mov esi, offset Id
mov ebx, k
shl ebx, 3
mov cl, [esi+ebx+7] //al = id[k][7]
mov ch, [esi+ebx] //cb := id[k][j]
@loop:
cmp ch, [edi+edx]
jne @exit
cmp al,cl
jnb @exit
inc edx // inc(i)
inc eax // inc(j)
inc ebx
mov ch, [esi+ebx]
cmp ch,1
jne @loop
mov ch, [edi+edx]
mov sb, ch
jmp @loop
@exit:
mov j,eax
end;
If j = Id[k][7] then // if positive
Begin
i := tmp; // i = start offset
WriteLn('Found at pos: ',IntToHex(i,8),' ',AsmC[k]);
inc(count);
For j := 0 to Id[k][7]-1 do
Begin
If Rp[k][j] = 1 then
pBuffer(Buf)^[i] := sb
else
pBuffer(Buf)^[i] := Rp[k][j];
Inc(i);
End;
//Dec(I);
End
else i := tmp;
End;
End;
If count = 0 then WriteLn('Nothing to patch!')
else
If (count mod 3 = 0) or (Upcase(ParamStr(2)[2]) = 'F') then
Begin
WriteLn('Rename ',Paramstr(1),' to ',Paramstr(1)+'.orig');
Rename(F,Paramstr(1)+'.orig');
If IOResult <> 0 then
begin
Writeln('Error rename file to '+Paramstr(1)+'.orig');
FreeMem(Buf,Size);
Halt;
end;
Assign(F,Paramstr(1));
Rewrite(f,1);
Write('Patching...');
BlockWrite(f,Buf^,Size);
Close(f);
Writeln(' done!');
End
Else
WriteLn('Count should be a multiple of 3! Skipping this file');
FreeMem(Buf,Size);
End.
|