home *** CD-ROM | disk | FTP | other *** search
/ KeyGen Studio 2002 / KeyGen_Studio_2002.iso / Tutorials / ReverseMes / volatility.txt < prev    next >
Encoding:
Text File  |  2001-09-21  |  6.7 KB  |  142 lines

  1.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  2.     ▓▓    ____                     __       __           ▓▓▀█
  3.     ▓▓   /  _/_ _  __ _  ___  ____/ /____ _/ /           ▓▓ █▀█
  4.     ▓▓  _/ //  ' \/  ' \/ _ \/ __/ __/ _ `/ /            ▓▓ █ █
  5.     ▓▓ /___/_/_/_/_/_/_/\___/_/  \__/\_,_/_/             ▓▓ █ █
  6.     ▓▓   ____                          __          __    ▓▓ █ █
  7.     ▓▓  / __ \___ ___ _______ ___  ___/ /__ ____  / /____▓▓ █ █
  8.     ▓▓ / /_/ / -_|_-</ __/ -_) _ \/ _  / _ `/ _ \/ __(_-<▓▓ █ █
  9.     ▓▓/_____/\__/___/\__/\__/_//_/\_,_/\_,_/_//_/\__/___/▓▓ █ █
  10.     ▓▓                                                   ▓▓ █ █
  11.     ▓▓      Web: http://www.ImmortalDescendants.com      ▓▓ █ █
  12.     ▓▓                Author: Volatility                 ▓▓ █ █
  13.     ▓▓                  Date: 01/03/00                   ▓▓ █ █
  14.     ▓▓            Topic: Adding Functionality            ▓▓ █ █
  15.     ▓▓               Level: Intermediate                 ▓▓ █ █
  16.     ▓▓                                                   ▓▓ █ █
  17.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ █ █
  18.       █▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█ █
  19.         █▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█
  20.  
  21. ===============================================================
  22. INTRODUCTION
  23. ===============================================================
  24. Greetings!  This essay is being written specifically for the
  25. Reverse EngineerZINE, as the target, douby's Reverseme is now 
  26. the official practice for the zine, but I'll add it to our 
  27. database as well, as it should serve purpose there too :)  The
  28. target can be found here: 
  29. http://www.ImmortalDescendants.com/re-zine/files/reversme1.zip
  30. What we're going to learn to do today is actually ADDING 
  31. functionality to a program -- this is TRUE reversing in my 
  32. humble opinion :)  I have to thank douby of DREAD right off the 
  33. bat, for holding my hand while entering this uncharted 
  34. territory :)
  35.  
  36. ===============================================================
  37. TOOLS NEEDED
  38. ===============================================================
  39. W32dasm or IDA (I'm using Wdasm in this essay)
  40. Soft-Ice 4.02  (or any version you wish)
  41. HIEW           (or other hex editor)
  42. MSDN
  43.  
  44. ===============================================================
  45. THE ESSAY
  46. ===============================================================
  47. After reading douby's readme file, we'll see that there are
  48. four tasks for this Reverseme: 1) enable the load function 2)
  49. enable the save function 3) enable the exit function and 4)
  50. add a scrollbar to the edit box.
  51.  
  52. For this essay, we'll be completing task 4 - adding the 
  53. scrollbar.  If I complete the other tasks, I may add to this
  54. essay, or I might just write a new one... we'll see :)  Let's 
  55. get started!
  56.  
  57. Before actually digging into the code, we have to complete
  58. some pre-requisite steps.  We know all windows are created 
  59. with CreateWindow or CreateWindowEx, except for dialogs, so 
  60. let's disassemble, and see what it uses.  Once disassembled,
  61. take a look at the imports... from this, we can see that the
  62. program uses CreateWindowExA.
  63.  
  64. Now, get your MSDN cd's ready... if you don't have the cd's,
  65. we'll just use msdn.microsoft.com for now, so load the page
  66. and lets do a search for CreateWindowEx.  There will be 
  67. several links, just click on the first one.  Now we have all
  68. the specifications of the CreateWindowEx function.  What 
  69. we're interested in, is "DWORD dwStyle,      // window style",
  70. since scrollbars are a style.  Let's click on the "dwStyle" 
  71. link, and then the "window styles" link.  What do we see all
  72. the way at the bottom?  WS_VSCROLL :)
  73.  
  74. Now that we have the style, let's look into the actual window
  75. a bit.  Let's go back to the main CreateWindowEx page, and
  76. look for the type of window we'll be working with.  Down 
  77. towards the bottom of the page, we'll get a table of the
  78. class names.  You can probably figure out which of these 
  79. it is...  if not, take a look at "EDIT", and read what it
  80. says :)
  81.  
  82. From all this, we know know that the code would look 
  83. something like the following: 
  84.  
  85. CreateWindowEx(dwExStyle, "EDIT", lpWindowName, dwStyle, etc.)
  86.  
  87. What good does this do us?  Well, take a look at the EDIT 
  88. parameter...  looks like a string, doesn't it?  Now we have
  89. something to look for in Soft-Ice.  Let's set a breakpoint
  90. on CreateWindowExA in Soft-Ice, run the program, then F12 out
  91. and see what we can find.  You should be here:
  92.  
  93. 015F:00401182  68C4008050          PUSH      508000C4
  94. 015F:00401187  6A00                PUSH      00
  95. 015F:00401189  68D4504000          PUSH      004050D4
  96. 015F:0040118E  6A00                PUSH      00
  97. 015F:00401190  FF15D0404000        CALL      [USER32!CreateWindowExA]
  98. 015F:00401196  5F                  POP       EDI
  99. 015F:00401197  A344554000          MOV       [00405544],EAX
  100.  
  101. The first push is the hardcoded value for all the combined
  102. styles.  What should the second push be?  Well, remember the 
  103. "EDIT" string we talked about?  Let's do a d 004050D4, and 
  104. what do we see?
  105.  
  106. Now that we know we're at the right place, how do we add a
  107. scrollbar to the editbox?  We already have the first value:
  108. 508000C4, but we need the value of the WS_VSCROLL parameter.
  109. I remember that this value is 0x00200000, but if you don't,
  110. you can look it up in Winuser.h, which is included with 
  111. programming languages such as VC++, or do an ftpsearch.  
  112. Now, all that's left to do, is OR the values:
  113. 0x508000C4 OR 0x00200000 = 0x50A000C4.  Now let's try a
  114. memory patch to make sure we're on the right track :)
  115.  
  116. Set a breakpoint on CreateWindowExA again, F12 out of there,
  117. and set a breakpoint on one of the pushes above the 
  118. [USER32!CreateWindowExA] call.  The line above the one we
  119. are going to edit (PUSH      508000C4), should work just
  120. fine, so clear, or disable the CreateWindowExA breakpoint,
  121. and set a breakpoint on the line above the one we're going
  122. to edit, and ctrl+d again.
  123.  
  124. Let's clear or disable this breakpoint, and now edit the
  125. value with our new one.  Do a e 015F:00401182 (NOTE: the
  126. first four values will be different on your system, but 
  127. the 00401182 will remain the same).  Now let's edit the 
  128. bytes from C4 00 80 50 to C4 00 A0 50, and press ctrl+d.
  129.  
  130. Task completed!  Now just search for the bytes in a hex
  131. editor, and make the patch permanent.
  132.  
  133. Volatility (Volatility@ImmortalDescendants.com)
  134.  
  135. ===============================================================
  136. GREETINGS (in alphabetical order, not importance :)
  137. ===============================================================
  138. INDIVIDUALS: ACiD_BuRN, alpine, Corn, douby, JosephCo, knotty, 
  139. Latigo, LaZaRuS, Lord Soth, Lucifer48, Neural, _pain, +Sandman, 
  140. S^Witz, Tornado, WarezPup, X-Calibre, Yoshi, and everyone I forgot 
  141. (probably MANY)
  142. GROUPS: DREAD, HellForge, RingZer0, Tres2000