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

  1. Software Reverse Engineering - Finding Correct Serial Numbers Using The HMEMCPY Function
  2. Copyright (c) 1998 Volatility
  3. Document Courtesy of The Immortal Descendants - http://pages.prodigy.net/volatility
  4.  
  5. ---------------------------------------------------------------------------------------------
  6. TABLE OF CONTENTS
  7. ---------------------------------------------------------------------------------------------
  8. I.    Tools You'll Need For This Tutorial
  9.  
  10. II.   Understanding The HMEMCPY Function
  11.       A.  What Is HMEMCPY?
  12.       B.  Which Applications Use HMEMCPY?
  13.  
  14. III.  Software Reverse Engineering Using HMEMCPY
  15.  
  16.       A.  When Will HMEMCPY Work?
  17.       B.  Setting Up Your Debugger To Break On HMEMCPY
  18.       C.  Common Things To Look For
  19.  
  20. IV.   Finding A Correct Serial Number Using HMEMCPY
  21.       A.  Prepare To Crack
  22.       B.  Making The Crack
  23.  
  24. V.    Final Thoughts
  25.  
  26. ---------------------------------------------------------------------------------------------
  27. I.  Tools You'll Need For This Tutorial
  28. ---------------------------------------------------------------------------------------------
  29. Target:  Page 'O Labels For Mailing Labels v2.8 - (polml32.exe) 437,872 bytes.  Download this at:
  30.  
  31.                       http://members.aol.com/rksftp5/polml32.exe
  32.  
  33.     NOTE: This method will work for ALL software at http://www.rks-software.com
  34.  
  35. Tools Needed:      Soft-Ice (any version)
  36.  
  37. ---------------------------------------------------------------------------------------------
  38. II.  Understanding The HMEMCPY Function
  39. ---------------------------------------------------------------------------------------------
  40.  
  41. A.  What Is HMEMCPY?
  42.  
  43.     HMEMCPY is a Windows API call, which uses memory (RAM) to read, manipulate, compare
  44. and store strings (text you've entered into a program).  The function takes the information
  45. you've entered (such as name and serial number in a registration screen) and puts them into
  46. memory.  The function then proceeds to manipulate these strings, by moving and comparing
  47. them (for example, comparing the serial number you entered to the correct one), and then 
  48. decides wether your string is correct or incorrect.  The function then sends this information
  49. back to the application, and you proceed as good guy, or bad guy.
  50.  
  51. B.  Which Applications Use HMEMCPY?
  52.  
  53.     Many programs use HMEMCPY for many different reasons.  For our purposes in this 
  54. tutorial, we're mainly interested in shareware programs.  The registration screens in
  55. shareware programs often utilize the HMEMCPY function to compare the information you entered
  56. with the correct information.  If incorrect, you're still unregistered.. if correct, you're
  57. registered.
  58.  
  59. ---------------------------------------------------------------------------------------------
  60. III.  Software Reverse Engineering Using HMEMCPY
  61. ---------------------------------------------------------------------------------------------
  62.  
  63. A.  When Will HMEMCPY Work?
  64.  
  65.     HMEMCPY can be used to "trap" valid serial numbers for shareware programs.  Using a
  66. debugger such as Soft-Ice, you can set a "breakpoint" on HMEMCPY, so that the debugger pops
  67. up when HMEMCPY is called.  Now that your serial number, and most likely the correct one are
  68. stored in RAM, you can proceed to "fish" for your valid serial number.
  69.  
  70.     Many shareware programs utilize HMEMCPY for comparisons of serial numbers, and this
  71. method is extremely effective on applications written in Delphi or Visual Basic.
  72.  
  73. B.  Setting Up Your Debugger To Break On HMEMCPY
  74.  
  75.     In order to "break" into the routine where your serial number is compared with the
  76. correct one, you'll need to set up a "breakpoint" to "pop" your debugger up when the function
  77. is called.
  78.  
  79.     Using Soft-Ice, this couldn't be more simple.  Run your program, go to the registration
  80. screen and enter in some "test" data.  Press Cntrl+D to enter Soft-Ice, and type BPX HMEMCPY.
  81. BPX means Breakpoint on Execution, and you're telling Soft-Ice to break when HMEMCPY is called.
  82. After setting the breakpoint, press Cntrl+D again to exit back out to the program.  Press the
  83. "Ok", "Register", or whichever button, and Soft-Ice will pop up.  To get into the routine, you
  84. need to press F11.
  85.  
  86.     Now that you're inside the routine, you'll most likely see a string such as "USER(0A)"
  87. or (USER(01) on the line right above the command window.  This isn't where you need to be.  You
  88. need to be inside the program routine.  If, for example, your program is called "Crack Me", 
  89. you'll need to press F10 to step through the code, until you see a string such as "CRACKME!CODE"
  90. on the line above the command window.
  91.  
  92.     You'll need to press F10 to step through the code many times before you get to the place
  93. you need to be (I've found that a common number of times you need to press F10 is 79).  You'll 
  94. see different strings such as "USER(01)", "USER(1C)", "KERNEL32!_FREQASM", etc., as you step 
  95. through the code.  Normally, the program code is found  right after "KERNEL32!_FREQASM".
  96.  
  97.     If you had to enter just a serial number, you can normally stop at the first instance
  98. of your program's code, but if you had to enter a user name AND a serial number, you'll need to
  99. continue stepping through all the functions again, until you get back to your program's code
  100. again.  The first instance just manipulates the user name you entered, while the second instance
  101. manipulates your serial number.
  102.  
  103. C.  Common Things To Look For
  104.  
  105.     Once you get into your program's code, you'll need to start looking for a compare function
  106. (CMP, TEST) and/or a jump function (JZ, JNZ, JE, JNE, etc).  When you find a compare, followed by
  107. a jump, this is usually right where you can find your valid serial number.  A VERY common routine
  108. you'll see is as follows:
  109.  
  110. ---------------------------------------------------------------------------------------------
  111. CALL     0041EF84
  112. MOV      EAX,[EBP-14]     <the serial we entered stored in EAX
  113. MOV      EDX,[004738D4]   <the correct serial stored in EDX
  114. CALL     00403D8C         <call the routine to compare the serials
  115. JNZ      00466E39         <jump to registered if good (not zero)
  116. MOV      EAX,00466F34     -------.
  117. CALL     0043C650                |
  118. JMP      00466EA2                |-- if no good, get a zero, and proceed to
  119. MOV      EAX,004738D4            |   unregistered.
  120. MOV      EDX,00466F7C            |
  121. CALL     00403A54         -------'
  122. ---------------------------------------------------------------------------------------------
  123.  
  124.     The numbers will no doubt be different, but the routine will be very similar.  To find
  125. the serial number we entered in the above example, you need to step through the line 
  126. "MOV      EAX,[EBP-14]" so that the line "MOV      EDX,[004738D4]" is highlighted.  You can now
  127. display the EAX register by typing: d EAX.  You should now see the serial number you entered
  128. in the display window.  To find the correct serial number, step through the line
  129. "MOV      EDX,[004738D4]" so that the line "CALL     00403D8C" is highlighted.  You can now 
  130. display the EDX register by typing: d EDX.  And, voila!  Your correct serial number!
  131.  
  132.     NOTE:  You often have to scroll up or down a little bit using the Alt key plus your up/
  133.                down arrows to find your correct serial number.
  134.  
  135.     This example will not work in all programs, and the registers will be different, but
  136. the above routine is a very common one, and will be very similar.
  137.  
  138.     Another very common routine is as follows:
  139.  
  140. ---------------------------------------------------------------------------------------------
  141. PUSH     EAX                        <various functions to put the correct
  142. CALL     004067CC                   <serial and our serial in memory
  143. ADD      ESP,04                     <
  144. TEST     EAX,EAX                    <compare our serial with the correct one
  145. JNZ      00402B68                   <jump to registered if not zero
  146. PUSH     0040B61B                   <hmm....what is this? :)
  147. PUSH     64
  148. PUSH     EBX
  149. CALL     00402133
  150. ---------------------------------------------------------------------------------------------
  151.  
  152.     Again, the numbers and registers will be different, but the routine will be very
  153. similar.  This example "PUSHes" our correct serial into memory.  So, to find our correct
  154. serial in the above example, we need to step through the jump "JNZ      00402B68" so that
  155. the line "PUSH     0040B61B" is highlighted.  Now we can find our correct serial number by
  156. displaying the memory location like so: d 0040B61B.
  157.  
  158. ---------------------------------------------------------------------------------------------
  159. IV.  Finding A Correct Serial Number Using HMEMCPY
  160. ---------------------------------------------------------------------------------------------
  161.  
  162. A.  Prepare To Crack
  163.  
  164.     Fire Up The Program Page 'O Labels For Mailing Labels (polml.exe) and go to the
  165. registration screen - "Help", "Enter Serial Number".  We know from the registration screen
  166. that we'll need to step through the first function, to get to it a second time.
  167.  
  168.     Enter some test data (Cracked By Volatility [ID] and 272727 for mine) and press
  169. Cntrl+D to get into Soft-Ice.  Set a breakpoint on HMEMCPY (BPX HMEMCPY) and press Cntrl+D
  170. to exit back out to the program.  Press the "Ok" button, and Soft-Ice Will pop up.  Press 
  171. F11 to get into the routine, and you should be here:
  172.  
  173. ---------------------------------------------------------------------------------------------
  174. CALL     KERNEL!HMEMCPY
  175. PUSH     WORD PTR [DI]
  176. CALL     KERNEL!LOCALUNLOCK
  177. MOV      AX,SI
  178. POP      SI
  179. POP      DI
  180. LEAVE
  181. RET      000A
  182. ENTER    0006,00
  183. PUSH     SI
  184. MOV      SI,[BP+0A]
  185. ---------------------------------------------------------------------------------------------
  186.  
  187. B.  Making The Crack
  188.  
  189.     You'll see the string "USER(0A)" on the line above the command window, and this isn't
  190. where you need to be, so step through the code by pressing F10 (exactly 79 times) until you
  191. see the string "POLML!CODE" on the line.  You should now be here:
  192.  
  193. ---------------------------------------------------------------------------------------------
  194. CALL     USER32!CallWindowProcA
  195. MOV      [ESI+0C],EAX
  196. JMP      00416533
  197. MOV      EDX,ESI
  198. MOV      EAX,EBX
  199. CALL     00414C5C
  200. POP      EBP
  201. POP      EDI
  202. POP      ESI
  203. POP      EBX
  204. RET
  205. ---------------------------------------------------------------------------------------------
  206.  
  207.     Now you could step through the code, find a compare or jump, and display some registers,
  208. but all you'll find in this routine is the user name you entered being manipulated.  We need
  209. to be in the routine where our serial number is being manipulated.  So, step through the code
  210. by pressing F10 MANY more times until you see "POLML!CODE" on the line above the command window.
  211.  
  212.     This is the routine we need to be in.  Now you must look for a compare and/or jump, for 
  213. this is where we will find our correct serial number.  To save you time, if you press F10 exactly
  214. 28 times, you'll land here:
  215.  
  216. ---------------------------------------------------------------------------------------------
  217. CALL     00414428
  218. MOV      ECX,[EBX+000001CC]
  219. MOV      EDX,[EBP-08]                        <serial number you entered
  220. MOV      EAX,[EBP-04]                        <correct serial number
  221. CALL     0043D024                            <call the function to compare the serials
  222. TEST     AL,AL                               <compare the serials
  223. JZ       0043D85C                            <jump to "registered" if zero (0=good flag)
  224. MOV      DWORD PTR [EBX+00000128],00000001   <otherwise, get a one (1=bad flag)
  225. JMP      0043D883                            <and jump to "unregistered">
  226. PUSH     00
  227. CALL     USER32!MessageBeep
  228. ---------------------------------------------------------------------------------------------
  229.  
  230.     To display the serial number you entered, step through the line "MOV      EDX,[EBP-08]"
  231. so that the line "MOV      EAX,[EBP-04]" is highlighted.  Now display the EDX register by 
  232. typing: d EDX.  To display the correct serial number, press F10 twice so that the line
  233. "TEST     AL,AL" is highlighted, and display the EDX register again.  Press Alt plus your down
  234. arrow key a few times, and there's your correct serial number!  Mine was "RKS-4059199".
  235.  
  236. ---------------------------------------------------------------------------------------------
  237. V.  Final Thoughts
  238. ---------------------------------------------------------------------------------------------
  239.  
  240.     I hope that this tutorial has given you some insight on finding correct serial numbers
  241. using the HMEMCPY function.  If not, trash it!  I won't be offended.
  242.  
  243.     If you feel I should add anything, or didn't clarify enough, feel free to let me know.
  244. You can contact me at: volatility@prodigy.net.
  245.  
  246.     Shout-Outs! - The Sandman (for his excellent website, tutorials and forums.  Without
  247. them I'd be lost), Razzia (for his excellent tutorials on cracking Visual Basic programs),
  248. +Fravia (for the most comprehensive knowledge base on software reverse engineering available),
  249. and all fellow newbie crackers - don't give up!  Failure is just the opportunity to start over
  250. again more intelligently!
  251.  
  252. -Volatility-
  253.  
  254.