home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Mib / PATCHER.ZIP / PATCHER.ASM < prev    next >
Encoding:
Assembly Source File  |  1998-08-18  |  12.4 KB  |  430 lines

  1. ;Patcher v1.0
  2. ;Written by Cruehead as the second part of the 1999 +HCU strainer
  3. ;TASM version
  4.  
  5. .386
  6. locals
  7. jumps
  8. .model flat,STDCALL
  9. include win32.inc                                ;Some very usefull includes
  10.  
  11. ;-------------------------------------------
  12. ; .-.-.- Begining of the DATA segment -.-.-.
  13. ;-------------------------------------------
  14.  
  15. .data
  16.  
  17. FILE_ATTRIBUTE_NORMAL    EQU        080h            ;Some constants that we declare here
  18. GENERIC_WRITE            EQU        40000000h
  19. GENERIC_READ            EQU        80000000h
  20. OPEN_EXISTING            EQU        3h
  21. FILE_BEGIN                EQU        0h
  22. FILE_CURRENT            EQU        1h
  23. SW_SHOWNORMAL              EQU        1h
  24.  
  25.  
  26. MyHwnd             dd 0                            ;We'll save the handle for the window here
  27. GoButHwnd        dd 0                            ;The handle for the 'Patch it" button
  28. ExitButHwnd        dd 0                            ;The handle for the 'Exit' button
  29. EditHwnd        dd 0                            ;The handle for the edit field
  30.  
  31. msg             MSGSTRUCT   <?>
  32. wc              WNDCLASS    <?>
  33. lppaint         PAINTSTRUCT <?>
  34.  
  35. szNULL           db 0
  36. ymenu            dd 0
  37.  
  38. hInst           dd 0
  39. hMenu           dd 0
  40. hDlg            dd 0
  41.  
  42. TitleName       db 'Crack for ACDsee 32 v2.22b2 - Written By Cruehead',0
  43. ClassName       db 'ASMCLASS32',0
  44. ClassButton        db 'BUTTON',0
  45. ClassEdit        db 'EDIT',0
  46. PatchText        db 'Lets go - Patch it!',0
  47. ExitText        db 'Exit!',0
  48.  
  49. ;--- Different action messages so the user knows what's happening ---
  50.  
  51. EditWaiting        db '                         Action: Waiting...',0
  52. Error1             db '           Error: ACDSEE32.EXE not found!',0
  53. Error2             db ' Error: File already cracked / Wrong version!',0
  54. Error3            db '                    Error: Wrong filesize!',0
  55. Done             db '                        Done! Enjoy it!',0
  56.  
  57. ;--- What we need to open the file ---
  58.  
  59. filename        db 'ACDSEE32.EXE',0                
  60. handle            dd 0
  61.  
  62. ;--- What we need to read the file ---
  63.  
  64. ReadBuffer        db 2 dup (0)                    ;We will read two bytes to this location
  65. BytesRead        dd 0                            ;Will hold how many bytes actually read
  66.  
  67. ;--- What we need to write to the file ---
  68.  
  69. WriteBuffer     dw 001B0h                        ;We will patch the program with this word
  70.                                                 ;(the bytes are in reverse order)
  71. BytesWritten    dd 0                            ;Will hold how many bytes actually written
  72.  
  73. CorrectFileSize    dd 0C9600h                        ;FileSize of the correct file
  74. Original        dw 0D8F7h                        ;This is the original word that we will change
  75.                                                 ;(the bytes are in reverse order)
  76. ;----------------------------------------
  77. ; .-.-.- Code Segment starts here -.-.-.
  78. ;----------------------------------------
  79.  
  80. .code
  81.  
  82. start:
  83.         push    0
  84.         call    GetModuleHandle                 ;get hmod (in eax)
  85.         mov     [hInst], eax                    ;hInstance is same as HMODULE
  86.                                                 ;in the Win32 world
  87.         push    0
  88.         push    offset ClassName
  89.         call    FindWindow              
  90.         or      eax,eax                         ;More than one program opened?
  91.         jz      reg_class              
  92.         ret                                        ;No, only one open at time
  93.  
  94. reg_class:
  95. ;
  96. ; initialize the WndClass structure
  97. ;
  98.  
  99.         mov     [wc.clsStyle], CS_HREDRAW + CS_VREDRAW + CS_GLOBALCLASS
  100.         mov     [wc.clsLpfnWndProc], offset WndProc
  101.         mov     [wc.clsCbClsExtra], 0
  102.         mov     [wc.clsCbWndExtra], 0
  103.  
  104.         mov     eax, [hInst]
  105.         mov     [wc.clsHInstance], eax
  106.  
  107.         push    IDC_ARROW             
  108.         push    0
  109.         call    LoadCursor
  110.         mov     [wc.clsHCursor], eax
  111.  
  112.         mov     [wc.clsHbrBackground], COLOR_BACKGROUND
  113.         mov     dword ptr [wc.clsLpszClassName], offset ClassName
  114.  
  115.         push    offset wc
  116.         call    RegisterClass
  117.  
  118. ;Create the main window
  119.  
  120.         push    0                                  ;lpParam
  121.         push    [hInst]                          ;hInstance
  122.         push    0                                  ;menu
  123.         push    0                                  ;parent hwnd
  124.         push    150                               ;height
  125.         push    390                               ;width
  126.         push    150                                ;y
  127.         push    170                                ;x
  128.         push    WS_OVERLAPPEDWINDOW                ;Style
  129.         push    offset TitleName                   ;Title string
  130.         push    offset ClassName                   ;Class name
  131.         push    0                                   ;Extra style
  132.         call    CreateWindowEx
  133.         mov     [MyHwnd], eax                    ;Save the handle for later use
  134.  
  135. ;This creates the 'Patch it' Button
  136.  
  137.         push    0                                  ;lpParam
  138.         push    0                                 ;hInstance
  139.         push    0                                  ;menu
  140.         push    [MyHwnd]                           ;parent hwnd
  141.         push    30                               ;height
  142.         push    140                               ;width
  143.         push    15                                ;y
  144.         push    120                                ;x
  145.         push    WS_CHILD+BS_DEFPUSHBUTTON        ;Style
  146.         push    offset PatchText                 ;Title string
  147.         push    offset ClassButton                 ;Class name
  148.         push    0                                   ;Extra style
  149.         call    CreateWindowEx
  150.         mov     [GoButHwnd], eax                ;Save this handle
  151.  
  152. ;This creates the 'Exit' Button
  153.  
  154.         push    0                                  ;lpParam
  155.         push    0                                 ;hInstance
  156.         push    0                                  ;menu
  157.         push    [MyHwnd]                           ;parent hwnd
  158.         push    30                               ;height
  159.         push    140                               ;width
  160.         push    43                                ;y
  161.         push    120                                ;x
  162.         push    WS_CHILD+BS_DEFPUSHBUTTON        ;Style
  163.         push    offset ExitText                 ;Title string
  164.         push    offset ClassButton                 ;Class name
  165.         push    0                                   ;Extra style
  166.         call    CreateWindowEx
  167.         mov     [ExitButHwnd], eax                ;Save the handle
  168.  
  169. ;Create the edit field
  170.  
  171.         push    0                                  ;lpParam
  172.         push    0                                 ;hInstance
  173.         push    0                                  ;menu
  174.         push    [MyHwnd]                           ;parent hwnd
  175.         push    20                               ;height
  176.         push    300                               ;width
  177.         push    90                                ;y
  178.         push    40                                ;x
  179.         push    WS_CHILD+ES_READONLY            ;Style
  180.         push    offset EditWaiting                 ;Title string
  181.         push    offset ClassEdit                 ;Class name
  182.         push    WS_EX_CLIENTEDGE                ;Extra style
  183.         call    CreateWindowEx
  184.         mov     [EditHwnd], eax                    ;Save the handle
  185.  
  186.         push    SW_SHOWNORMAL                    ;Show the Main window
  187.         push    [MyHwnd]
  188.         call    ShowWindow
  189.  
  190.         push    SW_SHOWNORMAL                    ;Show the 'Patch it" button
  191.         push    [GoButHwnd]
  192.         call    ShowWindow
  193.         
  194.         push    SW_SHOWNORMAL                    ;Show the 'Exit" button
  195.         push    [ExitButHwnd]
  196.         call    ShowWindow
  197.  
  198.         push    SW_SHOWNORMAL                    ;Show the edit filed
  199.         push    [EditHwnd]
  200.         call    ShowWindow
  201.          
  202.         push    [MyHwnd]                        ;We have to do this in order to 
  203.         call    UpdateWindow                    ;show the buttons and the edit field
  204.  
  205. ;Here we come to the messageloop - A very important thing in a win32 program
  206.  
  207. msg_loop:
  208.         push    0
  209.         push    0
  210.         push    0
  211.         push    offset msg
  212.         call    GetMessage
  213.  
  214.         cmp     ax, 0
  215.         je      end_loop
  216.  
  217.         push    offset msg
  218.         call    TranslateMessage
  219.  
  220.         push    offset msg
  221.         call    DispatchMessage
  222.  
  223.         jmp     msg_loop
  224.  
  225. end_loop:
  226.         push    [msg.msWPARAM]
  227.         call    ExitProcess             
  228.  
  229.  
  230. ;----------------------------------------------------------------------------
  231. ; WARNING: Win32 requires that EBX, EDI, and ESI be preserved!  
  232. ;
  233. ; Here we put the events we want to respond on.
  234. ;----------------------------------------------------------------------------
  235.  
  236. WndProc proc hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  237.         push    esi
  238.         push    edi
  239.         push    ebx
  240.         LOCAL   theDC:DWORD
  241.  
  242.         cmp     [wmsg], WM_DESTROY
  243.         je      wmdestroy
  244.         cmp        [wmsg], WM_PAINT
  245.         je        wmpaint    
  246.         cmp     [wmsg], WM_SIZE
  247.         je      wmsize
  248.         cmp        [wmsg], WM_COMMAND
  249.         je        wmcommand
  250.         jmp     defwndproc
  251.  
  252. wmcommand:
  253.         mov        eax ,[lparam]
  254.         cmp        [GoButHwnd], eax                ;Did the user click on the 'Patch it' button?
  255.         je        StartMeUp                        ;Then jump
  256.         cmp        [ExitButHwnd], eax                ;Did the user click on the 'Exit' button?
  257.         je        wmdestroy                        ;If so - lets jump
  258.         mov        eax,0
  259.         jmp        finish
  260.  
  261. ;----
  262. ; Here is the start of the real patching part
  263. ;                                         ----
  264.  
  265. StartMeUp:                
  266.         push    0                                ;Must be zero if win95
  267.         push    FILE_ATTRIBUTE_NORMAL            ;We're dealing with a normal file
  268.         push     OPEN_EXISTING                    ;Opens a file if it exists, otherwise error
  269.         push    0                                ;Cant be inherited
  270.         push    0                                ;File can't be shared
  271.         push    GENERIC_READ+GENERIC_WRITE        ;Read and write access
  272.         push    offset filename                    ;offset to our filename
  273.         call    CreateFileA
  274.  
  275.         cmp        eax,-1                            ;Did an error occur?
  276.         jnz        FileFound                        ;Take the jump if everything is ok
  277.  
  278.         push    -1
  279.         call    MessageBeep                        ;Just a cute litle beep
  280.  
  281.         push    offset Error1                    ;"File not found" message
  282.         push    [EditHwnd]
  283.         call    SetWindowTextA
  284.  
  285.         push    [EditHwnd]                        ;We need to do this in order to show the
  286.         call    UpdateWindow                    ;above message
  287.  
  288.         mov        eax,0
  289.         jmp        finish
  290.  
  291.     FileFound:
  292.         mov        handle,eax
  293.  
  294.         push    0
  295.         push    [handle]
  296.         call    GetFileSize                        ;Get the filesize in eax
  297.  
  298.         cmp        eax,CorrectFileSize                ;Is it the correct filesize?
  299.         je        GoodFileSize                    ;If yes - take the jump and continue
  300.  
  301.         push    [handle]                        ;Close the file
  302.         call    CloseHandle
  303.     
  304.         push    -1
  305.         call    MessageBeep                        ;Just a cute litle beep
  306.  
  307.         push    offset Error3                    ;"File length dont match" message
  308.         push    [EditHwnd]
  309.         call    SetWindowTextA
  310.  
  311.         push    [EditHwnd]                        ;We need to do this in order to show the
  312.         call    UpdateWindow                    ;above message
  313.  
  314.         mov        eax,0
  315.         jmp        finish
  316.  
  317.     GoodFileSize:        
  318.         push    FILE_BEGIN                        ;Move the filepointer from the start of the file
  319.         push    0
  320.         push    048F6h                            ;Here is the address where we shall read/patch
  321.         push    handle                            ;Filehandle
  322.         call    SetFilePointer
  323.  
  324. ;We could do some error checking here but as it's VERY unlikely that this function fails
  325. ;we can safely ignore it
  326. ;        cmp        eax,-1                            ;If eax=-1 then the function failed
  327. ;        jnz     and so on...                
  328.         
  329.         push    0        
  330.         push    offset BytesRead                ;How many bytes actually read
  331.         push    2                                ;Read 2 bytes
  332.         push    offset ReadBuffer                ;Address to the readbuffer
  333.         push    [handle]                        ;Filehandle
  334.         call    ReadFile
  335.  
  336.         mov        ax,word ptr [ReadBuffer]        ;Get the word we just read from the file in ax
  337.         cmp        ax, Original                    ;Compare this word with what it should be if
  338.                                                 ;this is an uncracked version
  339.         je        LetsPatch                        ;If they matches everything is ok, take the jump
  340.  
  341.         push    [handle]                        ;Close the file
  342.         call    CloseHandle
  343.  
  344.         push    -1
  345.         call    MessageBeep                        ;Just a cute litle beep
  346.  
  347.         push    offset Error2                    ;"Already Patched / wrong version" message
  348.         push    [EditHwnd]
  349.         call    SetWindowTextA
  350.  
  351.         push    [EditHwnd]                        ;We need to do this in order to show the
  352.         call    UpdateWindow                    ;above message
  353.  
  354.         mov        eax,0
  355.         jmp        finish
  356.  
  357.     LetsPatch:
  358.  
  359. ;--- Because the ReadFile functions also increases the filepointer we have to move it ---
  360. ; backwards in order to make it point to the correct patching posision. We read two bytes
  361. ; and so the filepointer was moved two bytes ahead - we must move it back two bytes backwards
  362. ; to make it point to the correct position
  363.  
  364.         push    FILE_CURRENT                    ;Move the filepointer from the current position
  365.         push    0
  366.         push    -2                                ;Move the filepointer two bytes backwards
  367.         push    handle                            ;Filehandle
  368.         call    SetFilePointer
  369.  
  370.         push    0
  371.         push    offset BytesWritten                ;How many bytes actually written
  372.         push    2                                ;Write 2 bytes
  373.         push    offset WriteBuffer                ;Write from this buffer
  374.         push    [handle]                        ;the file handle
  375.         call    WriteFile
  376.  
  377.         push    [handle]                        ;Now we're ready so lets close the file
  378.         call    CloseHandle
  379.  
  380.         push    offset Done                        ;"Everything went ok" message
  381.         push    [EditHwnd]
  382.         call    SetWindowTextA
  383.  
  384.         push    [EditHwnd]                        ;We need to do this in order to show the
  385.         call    UpdateWindow                    ;above message
  386.  
  387.         mov        eax,0
  388.         jmp        finish
  389.  
  390. wmpaint:
  391.         push    offset lppaint
  392.         push    [hwnd]
  393.         call    BeginPaint
  394.  
  395.         push    offset lppaint
  396.         push    [hwnd]
  397.         call    EndPaint
  398.  
  399.         mov        eax,0
  400.         jmp        finish
  401.  
  402. defwndproc:
  403.         push    [lparam]
  404.         push    [wparam]
  405.         push    [wmsg]
  406.         push    [hwnd]
  407.         call    DefWindowProc
  408.         jmp     finish
  409.  
  410. wmdestroy:
  411.  
  412.         push    0
  413.         call    PostQuitMessage
  414.         mov     eax, 0
  415.         jmp     finish
  416.  
  417. wmsize:
  418.         mov     eax, 0
  419.         jmp     finish
  420.         
  421. finish:
  422.         pop     ebx                             ;Remember we must restore these registers
  423.         pop     edi                             ;because the OS need them
  424.         pop     esi
  425.         ret
  426. WndProc          endp
  427.  
  428. public WndProc
  429. end start
  430.