Twitter
RSS

ChangeEntryPoint

include 'win32ax.inc'
INVALID_FILE_SIZE = 0xffffffff
.code
start:
stdcall ChangeEntryPoint,"c:\Arreglado.exe",$
.if eax = 0
invoke MessageBox,0,"Ocurrio un error al intentar cambiar el Entry Point" ,0,0
.else
invoke MessageBox,0,"El Entry Point a sido cambiado" ,0,0
.endif
invoke ExitProcess,0


proc ChangeEntryPoint,Path,NewEP:DWORD
locals
Handle dd ?
Tamaño dd ?
Emezeta dd ?
cantidad dd ?
endl
push ebx
invoke CreateFile, [Path], GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0 ;Abrimos el archivo para lectura
cmp eax,INVALID_HANDLE_VALUE
je .error
mov [Handle],eax ;Guardamos el handle
invoke GetFileSize, eax, 0 ;Vemos el tamaño
cmp eax,INVALID_FILE_SIZE
je .error
mov [Tamaño], eax
invoke GlobalAlloc, GPTR, eax
mov [Emezeta], eax
invoke ReadFile, [Handle], [Emezeta], [Tamaño], addr cantidad, 0 ;Leemos el archivo
cmp eax,TRUE
jne .error
invoke CloseHandle,[Handle] ;Cerramos el handle
cmp eax,NULL
je .error

mov ebx,[Emezeta]
cmp word[ebx],"MZ"
jne .error

add ebx,dword[ebx+03ch]
cmp word[ebx],"PE"
jne .error

xor eax,eax
mov eax,[NewEP]
mov dword[ebx+28h],eax ;Cambiamos el EP

invoke CreateFileA,[Path], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0 ;Creamos el archivo borrando el anterior
cmp eax,INVALID_HANDLE_VALUE
je .error
mov [Handle], eax

;Escibimos el archivo
invoke WriteFile, [Handle], [Emezeta] , [Tamaño],addr cantidad, NULL

; "Cerramos" el archivo
invoke CloseHandle,[Handle]

cmp eax,NULL
je .error
mov eax,1
jmp .salir
.error:
xor eax,eax
.salir:
pop ebx
ret
endp
.end start

Comments (0)