
; (c)1999 R!SC (see what i do instead of cracking...duh)
; requires tasm5.0 and import32.lib (comes with tasm..)
; change info in ;-=-Patch datas-=-=-=- section and recompile..
; well, change wtf you want, but please protect your loader

.386P
Locals

.Model Flat ,StdCall


Extrn       MessageBoxA:PROC  

Extrn       WriteProcessMemory:PROC
Extrn       ReadProcessMemory:PROC
Extrn       CreateProcessA:PROC
Extrn       CloseHandle:PROC
Extrn       ExitProcess:PROC


;-=-Normal data-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
.Data                                        
CSiR_Tag            db ' PE LOADER & CRACKER---R!SC 1999 http://csir.cjb.net ',0    ; tag, unused, cept in wdasm..

CSiR_Error          db 'Error!!!',0     ; messagebox title, for all errors
OpenERR_txt         db 'CreateProcess Error :(or file not found!)',0
ReadERR_txt         db 'ReadProcessMemory Error :(',0
WriteERR_txt        db 'WriteProcessMemory Error :P',0
VersionERR_txt      db 'Incorrect Version of application :(',0
CSiR_ProcessInfo    dd 4 dup (0)        ;process handles
CSiR_StartupInfo    dd 44h
                    db 44h dup (0)      ;startup info for the process were opening
CSiR_RPBuffer       db 100h dup (0)     ;read buffer, for checking data
Ptimer  dd 0
;-=-Patch datas-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

; kills splash and exit dialog in pe-crypt 1.02
    
    
prva    dd pi1,pi2,0            ; addresses of data's, null terminated, i.e, pi1,pi2,pi3,pi4,0
                                ; prva = p(atch)r(elative)v(irtual)a(ddress)'s

pi1     dw  2                 ; firendly name == p(atch)i(nfo)1
        dd  4015b0h
        db  6ah,24h,0ebh,1eh  ; script data (size of patch/address to patch/check/patch)
                              ;                ^ DW ^           ^ DD ^      ^DB^  ^DB^

pi2     dw  2           ; size of data
        dd  4064b2h     ; address to patch
        db  6ah,0       ; bytes to check for...
        db  0ebh,14h    ; bytes to patch
        
CSiR_AppName    db 'Pe-crypt.exe',0     ; process name (pe-crypt 1.02)

p_timeout    dd 0ffffh                ; process timer (checks for patch data xx times before quitting)


.Code                                  
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Main:
    push    offset CSiR_Tag
    mov     dword ptr [CSiR_StartupInfo],44h ; (the size in bytes of the structure)
    push    offset CSiR_ProcessInfo          ; Typedef struct _PROCESS_INFORMATION 
    push    offset CSiR_StartupInfo          ; Pointer to STARTUPINFO structure
    push    0
    push    0
    push    20h                              ; Creation flags
    push    0
    push    0
    push    0
    push    0
    push    offset CSiR_AppName              ; Pointer to name of executable mod
    call    CreateProcessA
    test    eax,eax
    jz      OpenERR
    
    lea     esi, prva
    
startpatch:
    mov     edi, dword ptr [esi]
    add     esi,04
    test    edi,edi                         ; check [prva] for 0, je finished
    jz      endofpatch
    xor     ebx,ebx
    mov     bx, word ptr [edi]              ; put amount of bytes to check/patch in ebx
    mov     ecx, dword ptr [edi+2]          ; get rva of bytes to patch
    add     edi,6                           ; point edi to patch data now, db blah blah
    mov     dword ptr [Ptimer],0
waitagain:
    add     dword ptr [Ptimer],01
    push    eax
    mov     eax, dword ptr [p_timeout]
    cmp     dword ptr [Ptimer],eax
    pop     eax
    je      VersionERR                      ; whoops, xxxx checks failed, quitting

    pushad
Check_Data:

    push    0                               ; BytesRead
    push    ebx                             ; Length
    push    offset CSiR_RPBuffer            ; Destination (to read them to)
    push    ecx                             ; Source
    push    dword ptr [CSiR_ProcessInfo]    ; Process whose memory we are to read
    call    ReadProcessMemory
    test    eax,eax
    popad
    jz      ReadERR
    ;...
    ;int 03 ;-)
    pushad
    cld
    lea     esi, CSiR_RPBuffer

    mov     ecx, ebx
    rep     cmpsb                           ; compare read bytes against check bytes
    popad
    jnz     waitagain                       ; jump if not equal to check again 
                                            ; (cause a few milliseconds have passed, and they may? be there)
    
    add     edi,ebx
    ;...
Patch_the_mother:
    push    0                               ; Pointer to byteswritten (i like null though)
    push    ebx                             ; Length
    push    edi                             ; Source
    push    ecx                             ; Destination
    push    dword ptr [CSiR_ProcessInfo]    ; Process whose memory we are to patch
    call    WriteProcessMemory              ; Call Kernel32!WriteProcessMenory
    test    eax,eax
    jz      WriteERR
    jmp     startpatch
endofpatch:    
Close_This_app:
    push    dword ptr [CSiR_ProcessInfo]
    call    CloseHandle
    push    dword ptr [CSiR_ProcessInfo+4]
    call    CloseHandle
    
Exit_Proc:
    jmp @11
doingit:    db  "  R!SC RtL iN '99    Loader created with R!SC's Process Patcher v1.2i  "
@11:
    Push LARGE-1
    Call ExitProcess

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
VersionERR:
    lea     eax, VersionERR_txt
    jmp     abort
ReadERR:
    lea     eax, ReadERR_txt
    jmp     abort
OpenERR:
    lea     eax, OpenERR_txt
    jmp     abort
WriteERR:
    lea     eax, WriteERR_txt
abort:
    push 0
    push offset CSiR_Error                  ; Title
    push eax                                ; Message
    push 0
    call MessageBoxA

    jmp Close_This_app
    
End Main
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
