Aggiunta di una funzione nel patcher di Pusillus |
|
|
Data |
by "DaRk PlaGuE" |
|
|
Published by Quequero |
|
Qualche frase che ti piace se vuoi, non è obbligatorio |
Bravo Dark, hai fatto un buona lavoro |
Qualche frase che ti piace se vuoi, non è obbligatorio |
UIC's form |
|
UIC's form |
Difficoltà |
( )NewBies (x)Intermedio ( )Avanzato ( )Master |
Introduzione |
Tools usati |
URL o FTP del programma |
Notizie sul programma |
Essay |
Dunque, io mi riferirò al testo di Pusillus e quindi vi consiglio di averlo sottomano se volete vedere le sue note. Ho inserito solo le mie per non fare confusione.
Let's start
Schema di
principio del prgramma con l'aggiunta:
-----------------
| Winmain | tasto "EXIT"
|--------->|
|----------------> uscita
| -----------------
|
|
|
| tasto "OK"
|
|
|
|
| -----------------
|
|
| errore 1
| |
aprifile |-----------------------------------------|
|
----------------- &
|
|
|
|
|
|OK
|
|
|
|
|
|
|
|
----------------- &
|
| |
controllo | errore
2
|
| | dim.
file |-----------------------------------|
|
|
----------------- &
| |
|
|
| |
|
|OK
| |
|
|
| |
|
----------------- &
| |
| |
controllo | Errore
| |
| | corrispondenza|---------|
| |
| |bytes originali| ------------------
| |
| ----------------- |
Controllo |
| |
|
| | corrispondenza |
| |
|
|OK | bytes patchati |--|
------------
|
| ------------------ | Errore 3 | Tabella |
|
----------------- | OK
|----------| errori |
| | Applicazione | ---------------
| |
| |
patch | | Patch tolta |
------------
| ----------------- ---------------
|
|
|<---------------|
|
|
|
|
|
|<--------------------------------------------|
|
|
|
|
|-------------------
Ed ora esaminiamo il testo in
Asm. Vi ricordo che ho tolto quasi tutte le note di Pusillus e quindi se volete una
analisi più approfondita del programma fate riferimento al suo tutorial.
.386
.model
FLAT, STDCALL
include
winicz2.inc
includelib
user32.lib
includelib
kernel32.lib
includelib
gdi32.lib
UpdateBuffer
PROTO :DWORD,:DWORD
log
PROTO :DWORD,:DWORD
Patch
PROTO :DWORD,:DWORD,:DWORD
PDWORD TYPEDEF
PTR DWORD
.data
DlgName
db "MyDialog",0
;---------------------------------------------------------
;---------Valori
modificabili-----------------------------
AppName
db "Patcher generico",0
TestString
db "Patch modificata da ",0dh,0ah
db "DaRk PlaGuE ",0dh,0ah,0dh,0ah
db "Thanks to Pusillus ",0dh,0ah
;--------Dati
modificabili x la Patch
FileName
db "prova.exe",0 ;nome del programma bersaglio
FileSize
dd 3096
Offset1
dd 020h, 021h, 022h, 024h, 0 ;Offsets dei bytes
Original1
db
00h,00h,00h,00h
;bytes del file originale
Patch1
db 011h,022h,033h,044h ;bytes
x la modifica del file
;---------------------------------------------------------
;---------------------------------------------------------
;---messaggi x la
log window
opening
db "Opening File %s... ",0
checkingSize
db "Checking File Size... ",0
checkingCRC
db "Checking CRC... ",0
Patching
db "Patching... ",0
MsgOk
db "OK",0dh,0ah,0
TuttoOk
db "File PATCHATO !! ",0dh,0ah,0
TuttoriOk
db "Il file ERA patchato ",0dh,0ah,0 ;messaggio che ci
; informa che
il programma era già patchato ma che ora non lo è più
;----messaggi di
errore
errFileNotFound
db 0dh,0ah,"FILE NOT FOUND !!! ",0dh,0ah,0
errBadFileSize
db 0dh,0ah,"BAD FILE SIZE !!! ",0dh,0ah,0
errBadCRC
db 0dh,0ah,"BAD CRC or alredy patched !!! ",0dh,0ah,0
;----puntatore ai
messaggi di errore
Perr
PDWORD errFileNotFound
PDWORD errBadFileSize
PDWORD errBadCRC
.data?
hInstance1
HINSTANCE ?
hInstButt
HINSTANCE ?
CommandLine
LPSTR ?
buffer
db 512 dup(?),0
ReadBuffer
db ?
ptbuffer
dd ?
hFile
dd ?
byteWriRead
dd ?
.const
IDC_EXIT
equ 3003
IDC_BUTTON
equ 3002
IDC_STATIC
equ -1
IDC_EDIT1
equ 3004
.code
start:
mov eax,offset buffer
mov ptbuffer, eax
invoke WinMain, NULL,NULL,NULL, SW_SHOWDEFAULT
invoke ExitProcess,eax
WinMain proc
hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:SDWORD
mov eax, OFFSET DlgProc
invoke DialogBoxParam, hInst, ADDR DlgName,NULL,eax,NULL
ret
WinMain endp
DlgProc proc
hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
mov eax,hWnd
mov hInstance1,eax
mov eax,uMsg
.IF eax==WM_INITDIALOG
invoke GetDlgItem, hWnd,IDC_BUTTON
mov hInstButt,eax
invoke SetWindowText, hWnd, addr AppName
invoke log, addr TestString,NULL
invoke SetFocus,eax
.ELSEIF eax==WM_CLOSE
invoke EndDialog, hWnd,NULL
.ELSEIF eax==WM_COMMAND
mov eax,wParam
.IF ax==IDC_BUTTON
shr eax,16
.IF ax == BN_CLICKED
;se viene premuto il tasto "OK" viene chiamata la routine x la patch
invoke Patch,addr Offset1 ,addr Original1,addr Patch1
.ENDIF
.ELSEIF ax == IDC_EXIT
shr eax,16
.IF ax==BN_CLICKED
invoke EndDialog, hWnd,NULL
.ENDIF
.ENDIF
.ELSE
mov eax,FALSE
ret
.ENDIF
mov eax,TRUE
ret
DlgProc endp
;Routine
principale x la patch
Patch
proc aPatchAddr:DWORD,aOriginalData:DWORD, aPatchData:DWORD
invoke log, addr opening, addr FileName
;-----apertura del file---
invoke CreateFile,addr FileName,GENERIC_READ + GENERIC_WRITE, 0,0,OPEN_EXISTING,0,0
cmp eax,-1
jz @@exit
mov hFile, eax
invoke log, addr MsgOk,NULL
invoke log, addr checkingSize,NULL
invoke GetFileSize, hFile,NULL
cmp eax,[FileSize]
je @@read
mov eax, -2
jmp @@exit
@@read:
invoke log, addr MsgOk,NULL
invoke log, addr checkingCRC,NULL
mov edi, aPatchAddr
mov esi, aOriginalData
xor ebx,ebx
@@loop1:
mov edx,[edi+ebx*4]
test edx,edx
je @@finecomp
invoke SetFilePointer, hFile, edx, 0, FILE_BEGIN
invoke ReadFile,hFile,addr ReadBuffer,1,addr byteWriRead,0
mov al, ReadBuffer
cmp
al,[esi+ebx]
jnz @@errorecomp
inc ebx
jmp @@loop1
@@finecomp:
mov eax,0
jmp @@exit
;Da qui
comincia il mio inserimento
@@errorecomp:
jmp
@@read2
;la comparazione con i bytes originali ha dato esito
;negativo e quindi controlliamo con i bytes patchati
@@errorecomp2:
mov
eax,-3
;flag per esito negativo della comparazione
jmp @@exit
@@read2:
invoke log, addr MsgOk,NULL ;
invoke log, addr checkingCRC,NULL ; messaggi x la log window
mov edi,
aPatchAddr ;
in EDI viene caricato l'indirizzo degli offsets
mov esi,
aPatchData ;
in ESI l'indirizzo dei dati GIA' PATCHATI
xor ebx,ebx
@@loop3:
mov
edx,[edi+ebx*4]
; EDX valore dell'offset, EBX indicizza
test
edx,edx
; se EDX e' 0 termina il controllo. Notare
je
@@finecomp2
; che l'array 'Offset1' e' terminato con 0
invoke SetFilePointer, hFile, edx, 0, FILE_BEGIN ; si sposta all'offset indicato da
; EDX nel file
invoke ReadFile,hFile,addr ReadBuffer,1,addr byteWriRead,0 ;legge un byte
mov al,
ReadBuffer ;
sposta in AL il byte letto
cmp
al,[esi+ebx]
; confronta AL con il contenuto dell'indirizzo puntato
; da ESI indic. EBX
jnz
@@errorecomp2 ; i due
bytes non sono uguali
inc
ebx
; incrementa l'indice
jmp @@loop3
@@finecomp2:
mov
eax,5
; flag x esito POSITIVO della comparazione
jmp @@exit
@@exit:
cmp eax,0
je @@modifica
cmp eax,5 ;Il Flag è 5 solo
se il byte è già patchato
je @@modifica2
neg eax
dec eax
mov esi,dword ptr Perr[eax*4]
invoke log,esi,NULL
jmp @@close
@@modifica:
invoke log, addr MsgOk,NULL
invoke log, addr Patching,NULL
mov edi, aPatchAddr
mov esi, aPatchData
xor ebx,ebx
@@loop2:
mov edx,[edi+ebx*4]
test edx,edx
je @@finescrittura
invoke SetFilePointer, hFile, edx, 0, FILE_BEGIN
invoke WriteFile,hFile,esi,1,addr byteWriRead,0
inc ebx
inc esi
jmp @@loop2
@@finescrittura:
invoke log, addr MsgOk,NULL
invoke log, addr TuttoOk,NULL
jmp @@close
@@modifica2:
; routine x la modifica del file --> togliere la patch
invoke log, addr MsgOk,NULL
invoke log, addr Patching,NULL
mov edi, aPatchAddr ; in EDI l'indirizzo degli offsets
mov esi, aOriginalData ; in ESI l'indirizzo dei bytes ORIGINALI
xor ebx,ebx
@@loop4:
mov edx,[edi+ebx*4] ; routine analoga a quella di comparazione
test edx,edx
je @@finescrittura2
invoke SetFilePointer, hFile, edx, 0, FILE_BEGIN
invoke WriteFile,hFile,esi,1,addr byteWriRead,0
inc ebx
inc esi
jmp @@loop4
@@finescrittura2:
; la patch e' stata tolta
invoke log, addr MsgOk,NULL
invoke log, addr TuttoriOk,NULL
@@close:
invoke EnableWindow,hInstButt,FALSE
invoke CloseHandle,hFile
ret
Patch endp
;routine x
l'aggiornamento del buffer del log
UpdateBuffer
proc aMessage:DWORD,addiction:DWORD
invoke wsprintfA, ptbuffer,aMessage,addiction
add esp, 12
add ptbuffer, eax
ret
UpdateBuffer
endp
;routine x
l'aggiornamento della finestra di log
log
proc aTesto,optional:DWORD
invoke UpdateBuffer,aTesto,optional
invoke SendDlgItemMessage,hInstance1,IDC_EDIT1,WM_SETTEXT,0,addr buffer
invoke SendDlgItemMessage,hInstance1,IDC_EDIT1,EM_LINESCROLL,0,10
ret
log endp
end start
Salvate il tutto come patch2.asm
e siete pronti per assemblarlo.
Per assemblare il programma ho usato il Masm32 versione 4 (lo trovate un po' ovunque).
Questo è l'elenco dei files che servono per assemblarlo:
patch2.asm
--> Programma principale
WinICZ2.inc --> è
richiamato da patch2.asm
patch.rc
--> File di risorse
resource.k e afxres.h
Questi due files sono richiamati da patch.rc
Tutti questi files più il programma prova.exe (non fa nulla, serve solo come bersaglio per la patch) sono contenuti nel file sorgent2.zip che potete scaricare da qui.
I comandi per
assemblarlo sono (ovviamente funzionano solo se avete settato correttamente il Masm):
ml /c /coff /Cp /Zi patch2.asm
rc patch.rc
Link /SUBSYSTEM:WINDOWS /LIBPATH:c:\masm32\lib /DEBUG
/DEBUGTYPE:COFF patch2.obj patch.res
Questi comandi sono spiegati nel tutorial di Pusillus
DaRk PlaGuE
|
Come avrete notato la modifica consisteva molto semplicemente nell'invertire un paio di valori e di ricopiare alcune parti di codice. Bastava solo pensarci. Io sto imparando solo ora a programmare il Assembly e quindi se il patcher ha qualche bug modificatelo pure e scrivetemi ([email protected]) per dirmi dove avevo sbagliato. Ciao
Disclaimer |
Home
Anonimato Assembly
ContactMe CrackMe Links
NewBies News Forum Lezioni
Tools Tutorial