home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dosdisas.zip / dispsrch.zip / DISPSRCH.TXT < prev    next >
Text File  |  1994-03-28  |  8KB  |  222 lines

  1.             DISPSIG and SRCHSIG
  2.                         ===================
  3.  
  4. 1 What are DispSig and SrchSig?
  5.  
  6. 2 How do I use DispSig?
  7.  
  8. 3 How do I use SrchSig?
  9.  
  10. 4 What can I do with the binary pattern file from DispSig?
  11.  
  12. 5 How can I create a binary pattern file for SrchSig?
  13.  
  14.  
  15.  
  16. 1 What are DispSig and SrchSig?
  17. -------------------------------
  18.  
  19. SrchSig is a program to display the name of a function, given a
  20. signature (pattern).
  21. DispSig is a program to display a signature, given a function name.
  22. Dispsig also writes the signature to a binary file, so you can
  23. disassemble it, or use it in Srchsig to see if some other signature
  24. file has the same pattern.
  25.  
  26.  
  27. 2 How do I use DispSig?
  28. -----------------------
  29. Just type
  30. DispSig <SignatureFileName> <FunctionName> <BinaryFileName>
  31.  
  32. For example:
  33.  
  34. dispsig dccb2s.sig strcmp strcmp.bin
  35. Function index 58
  36. 55 8B EC 56 57 8C D8 8E C0 FC 33 C0 8B D8 8B 7E 06 8B F7 32 C0 B9 F4 
  37.  
  38. This tells us that the function was the 59th function in the
  39. signature file (and that the signature above will hash to 58
  40. (decimal)). We can see that it is a standard C function, since it
  41. starts with "55 8B EC", which is the standard C function prologue.
  42. The rest of it is a bit hard to follow, but fortunately we have also
  43. written the pattern to a binary file, strcmp.bin. See section 4 on
  44. how to disassemble this pattern.
  45.  
  46. If I type
  47.  
  48. dispsig dcct4p.sig writeln wl.bin
  49.  
  50. I get
  51. Function writeln not found!
  52.  
  53. In fact, there is no one function that performs the writeln function;
  54. there are functions like WriteString, WriteInt, CrLf (Carriage
  55. return, linefeed), and so on. Dispsig is case insensitive, so:
  56.  
  57. dispsig dcct4p.sig writestring wl.bin
  58. produces
  59.  
  60. Function WriteString index 53
  61. 55 8B EC C4 7E 0C E8 F4 F4 75 25 C5 76 08 8B 4E 06 FC AC F4 F4 2B C8 
  62.  
  63.  
  64. 3 How do I use SrchSig?
  65. -----------------------
  66. Just type
  67.  
  68. srchsig <SignatureFileName> <BinaryFileName>
  69.  
  70. dispsig dcct4p.sig writeln wl.bin
  71. where BinaryFileName contains a pattern. See section 5 for how to
  72. create one of these. For now, we can use the pattern file from the
  73. first example:
  74.  
  75. srchsig dccb2s.sig strcmp.bin
  76.  
  77. Pattern:
  78. 55 8B EC 56 57 8C D8 8E C0 FC 33 C0 8B D8 8B 7E 06 8B F7 32 C0 B9 F4 
  79. Pattern hashed to 58 (0x3A), symbol strcmp
  80. Pattern matched
  81.  
  82. Note that the pattern reported above need not be exactly the same as
  83. the one we provided in <BinaryFileName>. The pattern displayed is the
  84. wildcarded and chopped version of the pattern provided; it will have
  85. F4s (wildcards) and possibly zeroes at the end; see the file
  86. makedstp.txt for a simple explanation of wildcarding and chopping.
  87.  
  88. If we type
  89.  
  90. srchsig dccb2s.sig ws.bin
  91.  
  92. we get
  93.  
  94. Pattern:
  95. 55 8B EC C4 7E 0C E8 F4 F4 75 25 C5 76 08 8B 4E 06 FC AC F4 F4 2B C8 
  96. Pattern hashed to 0 (0x0), symbol _IOERROR
  97. Pattern mismatch: found following pattern
  98. 55 8B EC 56 8B 76 04 0B F6 7C 14 83 FE 58 76 03 BE F4 F4 89 36 F4 F4 
  99. 300
  100.  
  101. The pattern often hashes to zero when the pattern is unknown, due to
  102. the sparse nature of the tables used in the hash function. The first
  103. pattern in dccb2s.sig happens to be _IOERROR, and its pattern is
  104. completely different, apart from the first three bytes. The "300" at
  105. the end is actually a running count of signatures searched linearly,
  106. in case there is a problem with the hash function.
  107.  
  108.  
  109.  
  110. 4 What can I do with the binary pattern file from DispSig?
  111. ----------------------------------------------------------
  112.  
  113. You can feed it into SrchSig; this might make sense if you wanted to
  114. know if, e.g. the signature for printf was the same for version 2 as
  115. it is for version 3. In this case, you would use DispSig on the
  116. version 2 signature file, and SrchSig on the version 3 file.
  117.  
  118. You can also disassemble it, using debug (it comes with MS-DOS). For
  119. example
  120. debug strcmp.bin
  121. -u100 l 17
  122.  
  123. 1754:0100 55            PUSH    BP                                 
  124. 1754:0101 8BEC          MOV    BP,SP                              
  125. 1754:0103 56            PUSH    SI                                 
  126. 1754:0104 57            PUSH    DI                                 
  127. 1754:0105 8CD8          MOV    AX,DS                              
  128. 1754:0107 8EC0          MOV    ES,AX                              
  129. 1754:0109 FC            CLD                                       
  130. 1754:010A 33C0          XOR    AX,AX                              
  131. 1754:010C 8BD8          MOV    BX,AX                              
  132. 1754:010E 8B7E06        MOV    DI,[BP+06]                         
  133. 1754:0111 8BF7          MOV    SI,DI                              
  134. 1754:0113 32C0          XOR    AL,AL                              
  135. 1754:0115 B9F42B        MOV    CX,2BF4                            
  136. -q
  137.  
  138. Note that the "2B" at the end is actually past the end of the
  139. signature. (Signatures are 23 bytes (17 in hex) long, so only
  140. addresses 100-116 are valid). Remember that most 16 bit operands will
  141. be "wildcarded", so don't believe the resultant addresses.
  142.  
  143.  
  144. 5 How can I create a binary pattern file for SrchSig?
  145. -----------------------------------------------------
  146.  
  147. Again, you can use debug. Suppose you have found an interesing piece
  148. of code at address 05BE (this example comes from a hello world
  149. program):
  150.  
  151. -u 5be
  152. 15FF:05BE 55            PUSH    BP                                 
  153. 15FF:05BF 8BEC          MOV    BP,SP                              
  154. 15FF:05C1 83EC08        SUB    SP,+08                             
  155. 15FF:05C4 57            PUSH    DI                                 
  156. 15FF:05C5 56            PUSH    SI                                 
  157. 15FF:05C6 BE1E01        MOV    SI,011E                            
  158. 15FF:05C9 8D4606        LEA    AX,[BP+06]                         
  159. 15FF:05CC 8946FC        MOV    [BP-04],AX                         
  160. 15FF:05CF 56            PUSH    SI                                 
  161. 15FF:05D0 E8E901        CALL    07BC                               
  162. 15FF:05D3 83C402        ADD    SP,+02                             
  163. 15FF:05D6 8BF8          MOV    DI,AX                              
  164. 15FF:05D8 8D4606        LEA    AX,[BP+06]                         
  165. 15FF:05DB 50            PUSH    AX                                 
  166. 15FF:05DC FF7604        PUSH    [BP+04]                            
  167. -mcs:5be l 17 cs:100
  168. -u100 l 17
  169. 15FF:0100 55            PUSH    BP                                 
  170. 15FF:0101 8BEC          MOV    BP,SP                              
  171. 15FF:0103 83EC08        SUB    SP,+08                             
  172. 15FF:0106 57            PUSH    DI                                 
  173. 15FF:0107 56            PUSH    SI                                 
  174. 15FF:0108 BE1E01        MOV    SI,011E                            
  175. 15FF:010B 8D4606        LEA    AX,[BP+06]                         
  176. 15FF:010E 8946FC        MOV    [BP-04],AX                         
  177. 15FF:0111 56            PUSH    SI                                 
  178. 15FF:0112 E8E901        CALL    02FE                               
  179. 15FF:0115 83C41F        ADD    SP,+1F                             
  180. -nfoo.bin
  181. -rcx
  182. CS 268A
  183. :17
  184. -w
  185. Writing 0017 bytes
  186. -q
  187. c>dir foo.bin
  188. foo.bin            23   3-25-94  12:04 
  189. c>
  190.  
  191. The binary file has to be exactly 23 bytes long; that's why we
  192. changed cx to the value 17 (hex 17 = decimal 23). If you are studying
  193. a large file (> 64K) remember to set bx to 0 as well. The m (block
  194. move) command moves the code of interest to cs:100, which is where
  195. debug will write the file from. The "rcx" changes the length of the
  196. save, and the "nfoo.bin" sets the name of the file to be saved. Now
  197. we can feed this into srchsig:
  198.  
  199. srchsig dccb2s.sig foo.bin
  200. Pattern:
  201. 55 8B EC 83 EC 08 57 56 BE F4 F4 8D 46 06 89 46 FC 56 E8 F4 F4 83 C4 
  202. Pattern hashed to 278 (0x116), symbol sleep
  203. Pattern mismatch: found following pattern
  204. 55 8B EC 83 EC 04 56 57 8D 46 FC 50 E8 F4 F4 59 80 7E FE 5A 76 05 BF 
  205. 300 
  206.  
  207. Hmmm. Not a Borland C version 2 small model signature. Perhaps its a
  208. Microsoft Version 5 signature:
  209.  
  210. Pattern:
  211. 55 8B EC 83 EC 08 57 56 BE F4 F4 8D 46 06 89 46 FC 56 E8 F4 F4 83 C4 
  212. Pattern hashed to 31 (0x1F), symbol printf
  213. Pattern matched
  214.  
  215. Yes, it was good old printf. Of course, no need for you to guess, DCC
  216. will figure out the vendor, version number, and model for you.
  217.  
  218.  
  219.  
  220.  
  221.  
  222.