home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Mendoza / dc_patchers.txt < prev    next >
Text File  |  2000-05-25  |  13KB  |  371 lines

  1.  ---------------------------------
  2. | General Tutorial about Patchers |  by da Cracker/CBE
  3.  ---------------------------------
  4.  
  5.  
  6. Introduction:
  7. ────────────
  8. If you read all my four tutorials (the first doesn't help, I think :( ), you
  9. should know how to crack:
  10. - Basic protections (Hex Workshop)
  11. - A bit harder basic protections (WinRoute Lite)
  12. - Intermediate Protections (Visual Page)
  13.  
  14. With this knowledge, you should be able to crack about ... 40% of the programs!
  15. Well, now, I'm going to make deaper approach to patchers.
  16. I hope that you'll enjoy the tutorial! If you have any
  17. comment, suggestions, .... please e-mail me at dc_cbe@hotmail.com
  18.  
  19.  
  20.  ┌──────────Index──────────┐
  21.  |                         |
  22.  |1) C++ Patchers          |
  23.  |2) Turbo Pascal Patchers |
  24.  |3) Assembler Patchers    |
  25.  |4) Windows Patchers      |
  26.  |5) Final Notes           |
  27.  └─────────────────────────┘
  28.  
  29. 1) C++ Patchers
  30.    ────────────
  31.  
  32. In our days, many programmers use C++ to do their programs... Why? Because
  33. it's a very portable version (ie. Without changing the code, it can work in
  34. Unix, Linux, DOS, Mac, Windows, ...) So if we can do a program in C++, why not
  35. a patcher? Yes, we can, because in C++, there are two functions to open files
  36. as output:
  37.  
  38. A) ofstream myfile(file.exe, ios::binary);
  39. B) fopen("file.exe", "r+")
  40.  
  41. The A method needs the file fstream.h to be included (#include <fstream.h>)
  42. The B method needs the file stdio.h to be included (#include <stdio.h>)
  43.  
  44. But in this tutorial, for C++, we are going to use the method B, because it
  45. also has seek methods (to find the right spot in the exe file)
  46.  
  47. Ok, now comes the source code commented:
  48.  
  49. ------------------------------------cut here----------------------------------
  50. #include <stdio.h> // File required to make fopen work!
  51.  
  52. long filesize(FILE *stream) // A function that get the size of the program (to check)
  53. {
  54.    long curpos, length;
  55.    curpos = ftell(stream);
  56.    fseek(stream, 0L, SEEK_END);
  57.    length = ftell(stream);
  58.    fseek(stream, curpos, SEEK_SET);
  59.    return length;
  60. }
  61. main() { // Program start
  62.  
  63. int   counter;
  64. FILE *filename;
  65. unsigned char readbyte;
  66.  
  67. long int offset[2] = {
  68.     35345, 35346 };
  69.  
  70. unsigned char data[4] = {
  71.         116, 144, 17, 144 }; // The first number is the original data from the first offset, the 2nd
  72.                              // number is the modified data; the 3rd data is the original data from
  73.                              // the second offset, the 4th one is the modified data, etc...
  74.  
  75. printf(" ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄\n"); // \n is a line break
  76. printf("█▀                                   ▀█\n");
  77. printf("█           Visual Page v1.0          █\n"); // Name of the program
  78. printf("█   REMOVES EXPIRATION DATE + NAG     █\n"); // What does it do?
  79. printf("█                                     █\n");
  80. printf("█      E-mail: dc_cbe@hotmail.com     █\n"); // Guess what?
  81. printf("█     Website: http://www.cbe98.org   █\n");
  82. printf("█         IRC: #cbe98 on Efnet        █\n"); // Come and chat with us!
  83. printf("█▄                                   ▄█\n");
  84. printf(" ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀\n\n");
  85. printf("■ OPENING FILE : "); // Self explanatory ;)
  86. if ((filename = fopen("VPAGE.EXE", "r+")) == NULL) { // Replace VPAGE.EXE with the exe file of the program
  87.       printf("SUCCESS!\n■ CHECKING SIZE : ");
  88.  if (filesize(filename) == 1266204) { // Replace 1266204 with the exact size of the program (type "dir" in dos)
  89.       printf("SUCCESS!\n■ CRACKING FILE : ");
  90.        for (counter=1;counter<3;counter++) {
  91.           fseek(filename,offset[counter-1],SEEK_SET);
  92.           fscanf(filename,"%c",&readbyte);
  93.       if (readbyte == data[(counter*2)-2]) {
  94.       fseek(filename,offset[counter-1],SEEK_SET);
  95.       fprintf(filename,"%c",data[(counter*2)-1]);
  96.       } else
  97.           {printf("ERROR!\n■ FILE ALREADY PATCHED OR DIFFERENT!\n"); fclose(filename); return 1; }
  98.       }
  99.        printf("SUCCESS!\n■ PATCH SUCCESSFULL!\n");
  100.    } else printf("ERROR!\n■ FILESIZE MISMATCH!\n");
  101.        fclose(filename);
  102. } else printf("ERROR!\n■ CAN'T OPEN FILE!\n");
  103. return 0;
  104. }
  105. --------------------------------cut here--------------------------------------
  106.  
  107.  
  108. 2) Turbo Pascal Patchers
  109.    ─────────────────────
  110.  
  111. Turbo Pascal is another language used by programmers... Anyway, here's the
  112. source code for a patcher:
  113.  
  114. ------------------------------------cut here----------------------------------
  115. Const Offset : Array [1..2] Of LongInt = (
  116.     35345, 35346 );
  117.  
  118. Const Data : Array [1..4] Of Byte = (
  119.     116, 144, 17, 144 );
  120.  
  121. Var Filename: File;
  122.   Counter : Word;
  123.   Readbyte : Byte;
  124. Begin
  125.   Write (' ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄'+ #13+ #10+);
  126.   Write ('█▀                                   ▀█'+ #13+ #10+);
  127.   Write ('█           Visual Page v1.0          █'+ #13+ #10+);
  128.   Write ('█   REMOVES EXPIRATION DATE + NAG     █'+ #13+ #10+);
  129.   Write ('█                                     █'+ #13+ #10+);
  130.   Write ('█      E-mail: dc_cbe@hotmail.com     █'+ #13+ #10+);
  131.   Write ('█     Website: http://www.cbe98.org   █'+ #13+ #10+);
  132.   Write ('█         IRC: #cbe98 on Efnet        █'+ #13+ #10+);
  133.   Write ('█▄                                   ▄█'+ #13+ #10+);
  134.   Write (' ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀'+ #13+ #10+ #13+ #10);
  135.   Write ('■ OPENING FILE : ');
  136.   Assign (Filename, 'VPAGE.EXE');
  137.   {$I-} Reset (Filename, 1); {$I+}
  138.   If IOResult = 0 Then Begin
  139.     Write ('SUCCESS!'+ #13+ #10+ '■ CHECKING SIZE : ');
  140.     If FileSize (Filename) = 1266204 Then Begin
  141.       Write ('OK!'+ #13+ #10+ '■ CRACKING FILE : ');
  142.       For Counter:= 1 To 2 Do Begin
  143.            Seek (Filename, Offset [Counter] );
  144.         BlockRead (Filename, Readbyte, 1);
  145.         If Readbyte = Data [Counter* 2- 1] Then Begin
  146.           Seek (Filename, Offset [Counter] );
  147.           BlockWrite (Filename, Data [Counter* 2], 1);
  148.         End Else Begin
  149.           WriteLn ('ERROR!'+ #13+ #10+ '■ FILE ALREADY PATCHED OR DIFFERENT!'); Close(Filename); Halt;
  150.         End;
  151.       End;
  152.       Close (Filename);
  153.       WriteLn ('OK!'+ #13+ #10+ '■ PATCH SUCCESSFULL!');
  154.     End Else WriteLn ('ERROR!'+ #13+ #10+ '■ WRONG VERSION OF FILE!');
  155.   End Else WriteLn ('ERROR!'+ #13+ #10+ '■ CAN''T OPEN FILE!');
  156. End.
  157. -------------------------------------cut here---------------------------------
  158.  
  159. 3) Assembler Patchers
  160.    ──────────────────
  161.  
  162. Assembler is a quite hard programming language, because it's a low level one
  163. (right before machine level code)... Well, here's the Assembler source code
  164. for a patcher
  165.  
  166. -------------------------------------cut here---------------------------------
  167. code            segment byte public
  168.         assume    cs:code, ds:code
  169.  
  170.         org    100h
  171. start:
  172.                 mov     dx,offset logo          ; Shows your logo
  173.                 call    write            ; write the message
  174.  
  175.                 call    open_file               ; Guess what ?
  176.         mov    filehandle,ax           ; Put the filehandle in "filehandle"
  177.  
  178.                 mov     dx,offset fsize
  179.                 call    write            ; write the message
  180.  
  181.                 call    check_size        ; Check the current filesize
  182.  
  183.             mov     di,offset data        ; Point di to data table
  184.                 mov     si,offset ofs        ; Point si to offset table
  185.         mov    cx,2            ; Loop ???? times
  186.                 mov     dx,offset crackfile
  187.                 call    write            ; write the message
  188.  
  189. crackit:
  190.         push    cx            ; Save cx
  191.                 call    seek_file         ; Seek in the file
  192.                 call    read_file        ; Read one byte and compare
  193.                 call    seek_file        ; Seek again (back)
  194.                 call    write_file        ; Write the byte
  195.  
  196.                 add     si,4            ; Add 4 to si 2*sizeof(word)
  197.                 add     di,2            ; Add 2 to di 2*sizeof(byte)
  198.         pop    cx            ; Bring cx back
  199.         loop    crackit            ; Loop Crackit
  200.  
  201.                 mov     dx,offset cracksucc
  202.                 jmp     short goback
  203.  
  204. already_patched:
  205.                 mov     dx,offset alreadycrk
  206.                 jmp     short goback
  207.  
  208. size_mismatch:
  209.                 mov     dx,offset sizemismtch
  210.                 jmp     short goback
  211.  
  212. error:
  213.                 mov     dx,offset erroropen
  214. goback:
  215.                 call    write            ; write the message
  216.  
  217.                 call     close_file        ; Close the file
  218.  
  219.                 mov     ah,4Ch                  ; Jump back to the operating system
  220.                 int     21h
  221.  
  222.  
  223. Write           proc    near
  224.               push    ax
  225.                 mov     ah,9
  226.                 int     21h                     ; Display String
  227.             pop    ax
  228.                 retn
  229. Write           endp
  230.  
  231. open_file       proc    near
  232.                 mov     ah,3Dh
  233.                 mov     al,2                    ; open file function 3Dh
  234.                 mov     dx,offset filenaam
  235.                 int     21h
  236.                 jb      error
  237.                 retn
  238. open_file       endp
  239.  
  240. close_file      proc near
  241.                 mov     ah,3Eh                  ; close file function 3Eh
  242.                 mov     bx,filehandle
  243.                 int     21h
  244.                 retn
  245. close_file      endp
  246.  
  247. check_size      proc near
  248.                 mov     bx,ax
  249.                 mov     ax,4202h
  250.                 xor     cx,cx                   ; Check the filelength
  251.                 xor     dx,dx
  252.                 int     21h
  253.                 jb      error
  254.                 cmp     ax, lowsize             ; (Lowbyte)
  255.                 jne     size_mismatch
  256.                 cmp     dx, highsize            ; (Highbyte)
  257.                 jne     size_mismatch
  258.                 retn
  259. check_size      endp
  260.  
  261. read_file       proc near
  262.                 mov     ah,3fh
  263.                 mov     bx,filehandle           ; read file function 3Fh
  264.                 mov     cx,1
  265.                 mov     dx,offset readbyte
  266.                 int     21h
  267.         mov    ah,readbyte
  268.                 cmp     [di],ah                 ; Compare patched bytes
  269.                 jne     already_patched
  270.         jb    error
  271.         retn
  272. read_file       endp
  273.  
  274. write_file      proc near
  275.                 mov     ah,40h
  276.                 mov     bx,filehandle
  277.                 mov     cx,1                    ; write file function 40h
  278.                 mov     dx,di
  279.         inc    dx
  280.                 int     21h
  281.         jb     error
  282.         retn
  283. write_file      endp
  284.  
  285. seek_file       proc    near
  286.                 mov     ah,42h
  287.                 mov     al,0
  288.                 mov     bx,filehandle           ; move file ptr function 42h
  289.                 mov     dx,[si]
  290.         mov    cx,[si+2]
  291.                 int     21h
  292.         jnc     here
  293.                 jmp    error
  294. here:
  295.                 retn
  296. seek_file       endp
  297.  
  298.  
  299. filenaam        db      'VPAGE.EXE', 0
  300. filehandle    dw    0
  301. lowsize         dw      21020
  302. highsize        dw      19
  303. readbyte        db      0
  304.  
  305. logo            db      ' ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄', 0Dh, 0Ah
  306.                 db      '█▀                                   ▀█', 0Dh, 0Ah
  307.                 db      '█           Visual Page v1.0          █', 0Dh, 0Ah
  308.                 db      '█   REMOVES EXPIRATION DATE + NAG     █', 0Dh, 0Ah
  309.                 db      '█                                     █', 0Dh, 0Ah
  310.                 db      '█      E-mail: dc_cbe@hotmail.com     █', 0Dh, 0Ah
  311.                 db      '█     Website: http://www.cbe98.org   █', 0Dh, 0Ah
  312.                 db      '█         IRC: #cbe98 on Efnet        █', 0Dh, 0Ah
  313.                 db      '█▄                                   ▄█', 0Dh, 0Ah
  314.                 db      ' ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀', 0Dh, 0Ah
  315.                 db      '■ OPENING FILE : ','$'
  316. fsize           db      'SUCCESS!',0Dh,0Ah,'■ CHECKING FILESIZE : $'
  317. crackfile       db      'SUCCESS!',0Dh,0Ah,'■ CRACKING FILE : $'
  318. cracksucc       db      'SUCCESS!',0Dh,0Ah,'■ PATCH SUCCESSFULL!',0Dh,0Ah,'$'
  319. alreadycrk      db      'ERROR!',0Dh,0Ah,'■ FILE ALREADY PATCHED OR DIFFERENT!',0Dh,0Ah,'$'
  320. sizemismtch     db      'ERROR!',0Dh,0Ah,'■ WRONG VERSION OF FILE!',0Dh,0Ah,'$'
  321. erroropen       db      'ERROR!',0Dh,0Ah,'■ CAN', 027h,'T OPEN FILE!',0Dh,0Ah,'$'
  322.  
  323. ofs             dw    35345 , 0 , 35346 , 0
  324.  
  325. data            db    116, 144 , 17, 144
  326.  
  327. code        ends
  328.  
  329.         end    start
  330. -------------------------------------cut here---------------------------------
  331.  
  332. 4) Windows Patchers
  333.    ────────────────
  334.  
  335. Many of you guys probably know how to program in a visual language (ie. Visual
  336. Basic, Delphi, Borland C++ Builder, ...) or even in a non visual language
  337. (Visual C++, they call it visual, hahaha). Well, with these programming
  338. languages, you can do patchers. From these languages, I only know Visual Basic,
  339. so I'm going to tell you how to do a visual basic patcher (even though the
  340. users need the Visual Basic runtimes to make it work... But almost everyone has
  341. them):
  342.  
  343. A) Start Visual Basic
  344. B) Choose Create a new exe
  345. C) Do your own design
  346. D) Do a button called "Patch it!", or whatever
  347. E) Double-click on this button (shows the source code)
  348. F) Type "Open file.exe For Binary Access Write As #1"
  349. That's the function who opens a file in binary mode for editing! After, you
  350. have to tell the location that needs to be patched, the data, etc... At the
  351. end, to close the file, type "Close #1".
  352.  
  353.  
  354. 5) Final Notes
  355.    ───────────
  356.  
  357. If you didn't understand ANYTHING in this tutorial, just use a patcher... It's
  358. MUCH easier. For CBE memberz, you can get a patcher in the directory patchers/
  359. from the memberz ftp area... For the others: search the net ;)
  360.  
  361. I hope that you enjoyed reading this tutorial as much as I did writing it!
  362. Good luck!
  363.  
  364. btw, my next cracking tutorial is going to be about ummm, dunno yet... =)
  365.  
  366. -da Cracker/CBE
  367. dc_cbe@hotmail.com
  368. http://www.cbe98.org
  369. #cbe98 on Efnet
  370. Come and chat with us on IRC!
  371.