home *** CD-ROM | disk | FTP | other *** search
/ Cracking 101 / C101-90.003 < prev    next >
Encoding:
Text File  |  1990-01-01  |  14.8 KB  |  400 lines

  1.  
  2.                           CRACKING 101 - 1990 edition
  3.  
  4.                                     Lesson 3
  5.  
  6.                     ┌─────────────────────────────────────┐
  7.                     │ CHAMBER OF THE SCI-MUTANT PREISTEST │
  8.                     └─────────────────────────────────────┘
  9.  
  10.  
  11.               Oh shit, I have finally found a newer program that has
  12.          on disk copy protection.  Good, you'all need a refresher
  13.          course on so here it is (YO JB study hard, you might learn
  14.          something).
  15.  
  16.               CHAMBER of the SCI-MUTANT PREISTEST (CSMP) is a really
  17.          fucked up game but was simple to unprotect.  So, lets dive
  18.          right in.  We will be using DEBUG here (although I used
  19.          periscope but then shit I'm special) to do the crack.  Lets
  20.          dive in.  When we first load CSMP (the file ERE.COM) and
  21.          unassemble it here is what we get.
  22.  
  23.          u 100 10B
  24.  
  25.          119A:0100 8CCA          MOV DX,CS
  26.          119A:0102 81C2C101      ADD DX,01C1
  27.          119A:0106 52            PUSH DX
  28.          119A:0107 BA0F00        MOV DX,000F
  29.          119A:010A 52            PUSH DX
  30.          119A:010B CB            RETF
  31.  
  32.               I included the register listing for a reason.  NOTICE
  33.          that this piece of code just seem to stop (the RETF)
  34.          statement.  Well, what is really does is place the address
  35.          (segment and offset) of the real starting point on to the
  36.          stack and the execute a far return to that location.  Now
  37.          this might fool a real beginner (or at least make him worry a
  38.          bit but us...no way).
  39.  
  40.               If you take the current CS value and add 1C1 to it (in
  41.          segment addition) you will get the segment address 135B (that
  42.          is if you are using my example of 119A.  If not then you will
  43.          not get 135B but trust me, it's the right value).
  44.  
  45.               So since we want to be at the real program, execute the
  46.          code until 10B (ie use the command "G 10B") then trace
  47.          through the next instruction.
  48.  
  49.               If you now unassemble the code, here is what it should
  50.          look like.
  51.  
  52.          -u 000f 36
  53.  
  54.          135B:000F 9C            PUSHF
  55.          135B:0010 50            PUSH AX
  56.          135B:0011 1E            PUSH DS
  57.          135B:0012 06            PUSH ES
  58.          135B:0013 0E            PUSH CS
  59.          135B:0014 1F            POP DS
  60.          135B:0015 0E            PUSH CS
  61.          135B:0016 07            POP ES
  62.          135B:0017 FC            CLD
  63.          135B:0018 89260B00      MOV [000B],SP
  64.          135B:001C C70600000102  MOV WORD PTR [0000],0201
  65.          135B:0022 B013          MOV AL,13
  66.          135B:0024 A23500        MOV [0035],AL
  67.          135B:0027 A2FF01        MOV [01FF],AL
  68.          135B:002A A22F02        MOV [022F],AL
  69.          135B:002D A23901        MOV [0139],AL
  70.          135B:0030 B280          MOV DL,80
  71.          135B:0032 B408          MOV AH,08
  72.          135B:0034 CD21          INT 21
  73.          135B:0036 7232          JB 006A
  74.  
  75.  
  76.               Since we are looking for a disk based copy protection,
  77.          it might be a good time to look for INT 13.  So search the
  78.          current segment for INT 13 with the command
  79.  
  80.                               S 135B:0 FFFF CD 13
  81.  
  82.               But shit, nothing.  You mean this program doesn't use
  83.          int 13.  Be real.  Reread the first lesson.  You know the one
  84.          that talks about self modifing code.  This is what we have
  85.          here.  Let's take a closer look at the last bit of code but
  86.          this time, with my comments added.
  87.  
  88.          -u 000f 36
  89.  
  90.          ; The first part of the code simple sets up for the return to
  91.          ; dos as well as sets ES and DS
  92.  
  93.          135B:000F 9C            PUSHF
  94.          135B:0010 50            PUSH AX
  95.          135B:0011 1E            PUSH DS
  96.          135B:0012 06            PUSH ES
  97.          135B:0013 0E            PUSH CS
  98.          135B:0014 1F            POP DS       ; Set DS to CS
  99.          135B:0015 0E            PUSH CS
  100.          135B:0016 07            POP ES       ; Set ES to DS
  101.          135B:0017 FC            CLD
  102.  
  103.          135B:0018 89260B00      MOV [000B],SP
  104.  
  105.          ; The next instruction sets up a variable that is used in the
  106.          ; routine that reads in the sectors from the disk.  More on
  107.          ; later.
  108.  
  109.          135B:001C C70600000102  MOV WORD PTR [0000],0201
  110.  
  111.          ; Now, here is the self modifing code.  Notice at AL is 13
  112.          ; (INT 13h ... Get it).  Look at the first memory location
  113.          ; (35h) and remember that DS = CS.  With this in mind, when
  114.          ; then instuction at 135B:0024 is executed byte at 135B:0035
  115.          ; will be changed to 13h.  That will in fact change the
  116.          ; INT 21h at 135B:0034 to an INT 13h.  And so on, and so on.
  117.  
  118.          135B:0022 B013          MOV AL,13       ; New value
  119.          135B:0024 A23500        MOV [0035],AL   ; Change to INT 13h
  120.          135B:0027 A2FF01        MOV [01FF],AL   ; Change to INT 13h
  121.          135B:002A A22F02        MOV [022F],AL   ; Change to INT 13h
  122.          135B:002D A23901        MOV [0139],AL   ; Change to INT 13h
  123.  
  124.          ; If you lookup DOS function 08 you will find it's CONSOLE
  125.          ; INPUT.  Now does that seem out of place to you.
  126.  
  127.          135B:0030 B280          MOV DL,80
  128.          135B:0032 B408          MOV AH,08
  129.          135B:0034 CD21          INT 21     ; Changed to INT 13h
  130.          135B:0036 7232          JB 006A
  131.  
  132.  
  133.               Whoa, that was tricky.  If you execute up to 135B:30
  134.          here is what it should look like..
  135.  
  136.  
  137.          135B:0030 B280          MOV DL,80
  138.          135B:0032 B408          MOV AH,08
  139.          135B:0034 CD13          INT 13
  140.          135B:0036 7232          JB 006A
  141.  
  142.               AHA, now we are getting somewhere.  If we lookup what
  143.          disk function 08 means, you won't be suprised.  Function 08h
  144.          is GET DRIVE TYPE.  It will tell what type of disk drive we
  145.          have.  Remember, if you are loading off of a hard disk then
  146.          it wants to use a different routine.  Since we want it to
  147.          think we are loading off of disk, then we want to take this
  148.          jump.  So for now, force the jmp by setting IP to 6A.
  149.  
  150.               At 135B:006A you find another jmp instruction
  151.  
  152.          135B:006A EB6B          JMP 00D7
  153.  
  154.  
  155.               This jumps to the routine that does the actual disk
  156.          check.  Here is the outer loop of that code (With my comments
  157.          of course).
  158.  
  159.          ; This first part of this routine simply test to see how many
  160.          ; disk drives you have.
  161.  
  162.  
  163.          135B:00D7 CD11          INT 11
  164.          135B:00D9 25C000        AND AX,00C0
  165.          135B:00DC B106          MOV CL,06
  166.          135B:00DE D3E8          SHR AX,CL
  167.          135B:00E0 FEC0          INC AL
  168.          135B:00E2 FEC0          INC AL
  169.          135B:00E4 A20200        MOV [0002],AL
  170.  
  171.          ; Next, so setup for the actual disk check
  172.  
  173.  
  174.          135B:00E7 C606090000    MOV BYTE PTR [0009],00
  175.          135B:00EC B9F127        MOV CX,27F1
  176.          135B:00EF 8BE9          MOV BP,CX
  177.          135B:00F1 B107          MOV CL,07
  178.          135B:00F3 F8            CLC
  179.  
  180.          ; This calls the protection routine part 1
  181.  
  182.          135B:00F4 E82F00        CALL 0126
  183.  
  184.          135B:00F7 B9DE27        MOV CX,27DE
  185.          135B:00FA 8BE9          MOV BP,CX
  186.          135B:00FC B108          MOV CL,08
  187.          135B:00FE F9            STC
  188.  
  189.          ; This calls the protection routine part 2
  190.  
  191.          135B:00FF E82400        CALL 0126
  192.  
  193.          135B:0102 8D1E5802      LEA BX,[0258]
  194.          135B:0106 8D361C01      LEA SI,[011C]
  195.          135B:010A 8BCD          MOV CX,BP
  196.          135B:010C AC            LODSB
  197.          135B:010D 8AC8          MOV CL,AL
  198.  
  199.          ; This calls the protection routine part 3
  200.  
  201.          135B:010F E8E300        CALL 01F5
  202.  
  203.          ; Makes the final check
  204.  
  205.          135B:0112 7271          JB 0185
  206.          135B:0114 AC            LODSB
  207.          135B:0115 0AC0          OR AL,AL
  208.          135B:0117 75F4          JNZ 010D  ; If not correct, try again
  209.          135B:0119 EB77          JMP 0192  ; Correct, continue program
  210.          135B:011B 90            NOP
  211.  
  212.  
  213.               There are calls to 2 different subroutines.  The routine
  214.          at 126 and the routine at 1F5.  If you examine the routine at
  215.          126 you find that it makes several calls to the routine at
  216.          1F5.  Then you you examine the routine at 1F5 you see the
  217.          actual call to INT 13.  Here is the code for both routine
  218.          with comments
  219.  
  220.  
  221.          ; First, it sets up the sector, head and drive information.
  222.          ; DS:000A holds the sector to read
  223.  
  224.          135B:0126 880E0A00      MOV [000A],CL
  225.          135B:012A 8A160900      MOV DL,[0009]
  226.          135B:012E B600          MOV DH,00
  227.  
  228.          ; Sets the DTA
  229.  
  230.          135B:0130 8D365802      LEA SI,[0258]
  231.          135B:0134 7213          JB 0149
  232.  
  233.          ; Resets the disk
  234.  
  235.          135B:0136 33C0          XOR AX,AX
  236.          135B:0138 CD13          INT 13
  237.  
  238.          ; Calls the the check
  239.  
  240.          135B:013A B90114        MOV CX,1401  ; TRACK 14 sector 1
  241.          135B:013D 8BDE          MOV BX,SI
  242.          135B:013F E8B300        CALL 01F5
  243.  
  244.  
  245.          ; The next track/sector to read in is stored in BP
  246.  
  247.          135B:0142 8BCD          MOV CX,BP
  248.          135B:0144 E8AE00        CALL 01F5
  249.          135B:0147 7234          JB 017D     ; If an error occured,
  250.                                              ; trap it.
  251.  
  252.  
  253.          135B:0149 88160900      MOV [0009],DL   ; Reset drive
  254.          135B:014D 8A0E0A00      MOV CL,[000A]   ; reset sector
  255.          135B:0151 E8A100        CALL 01F5       ; check protection
  256.          135B:0154 722F          JB 0185         ; Check for an error
  257.  
  258.          135B:0156 8D5C20        LEA BX,[SI+20]
  259.  
  260.          135B:0159 8BCD          MOV CX,BP       ; Get next T/S
  261.          135B:015B B010          MOV AL,10       ; Ignore this
  262.          135B:015D E89500        CALL 01F5       ; Check protection
  263.          135B:0160 7223          JB 0185         ; check for error
  264.  
  265.          ; The next sector of code checks to see if what was read in
  266.          ; is the actual protected tracks
  267.  
  268.          ; First check
  269.  
  270.          135B:0162 8DBCAC00      LEA DI,[SI+00AC]
  271.          135B:0166 B91000        MOV CX,0010
  272.          135B:0169 F3            REPZ
  273.          135B:016A A7            CMPSW
  274.  
  275.          ; NOTE: If it was a bad track, it will jmp to 185.  A good
  276.          ; read should just continue
  277.  
  278.          135B:016B 7518          JNZ 0185
  279.  
  280.          ; Second check
  281.  
  282.          135B:016D 8D365802      LEA SI,[0258]
  283.          135B:0171 8D3E3702      LEA DI,[0237]
  284.          135B:0175 B90400        MOV CX,0004
  285.          135B:0178 F3            REPZ
  286.          135B:0179 A7            CMPSW
  287.  
  288.          ; see NOTE above
  289.  
  290.          135B:017A 7509          JNZ 0185
  291.  
  292.          ; This exit back to the main routine.
  293.  
  294.          135B:017C C3            RET
  295.  
  296.          ; Here is the start of the error trap routines.  Basicly what
  297.          ; they do is check an error count.  If it's not 0 then it
  298.          ; retries everything.  If it is 0 then it exit back to dos.
  299.  
  300.          135B:017D FEC2          INC DL
  301.          135B:017F 3A160200      CMP DL,[0002]
  302.          135B:0183 72B1          JB 0136
  303.          135B:0185 E85400        CALL 01DC
  304.          135B:0188 8B260B00      MOV SP,[000B]
  305.          135B:018C 2BC9          SUB CX,CX
  306.          135B:018E 58            POP AX
  307.          135B:018F 50            PUSH AX
  308.          135B:0190 EB1F          JMP 01B1
  309.  
  310.  
  311.          ** Here is the actual code the does the check  **
  312.  
  313.          ; ES:BX points to the buffer
  314.  
  315.          135B:01F5 1E            PUSH DS
  316.          135B:01F6 07            POP ES
  317.  
  318.          ; SI is set to the # of retries
  319.  
  320.          135B:01F7 56            PUSH SI
  321.          135B:01F8 BE0600        MOV SI,0006
  322.  
  323.          ; Remember how I said we would use what was in DS:0000 later.
  324.          ; well, here is where you use it.  It loads in the FUNCTION
  325.          ; and # of sectors from what is stored in DS:0000.  This is
  326.          ; just a trick to make the int 13 call more vague.
  327.  
  328.          135B:01FB A10000        MOV AX,[0000]
  329.          135B:01FE CD13          INT 13
  330.  
  331.          ; If there is no errors, then exit this part of the loop
  332.  
  333.          135B:0200 7309          JNB 020B
  334.          135B:0202 F6C480        TEST AH,80
  335.  
  336.          ; Check to see if it was a drive TIMEOUT.  If so, then set
  337.          ; an error flag and exit
  338.  
  339.          135B:0205 7503          JNZ 020A
  340.  
  341.          ; It must have been a load error.  Retry 6 times
  342.  
  343.          135B:0207 4E            DEC SI
  344.          135B:0208 75F1          JNZ 01FB
  345.  
  346.          ; Set the error flag
  347.  
  348.          135B:020A F9            STC
  349.  
  350.          ; restore SI and return
  351.  
  352.          135B:020B 5E            POP SI
  353.          135B:020C C3            RET
  354.  
  355.  
  356.               If you follow through all of that.  You will see that
  357.          the only real way out is the jmp to "135B:0192" at 135B:0119.
  358.          So, how do we test it.  Simple.  Exit back to dos and let's
  359.          add a temporary patch.
  360.  
  361.               Reload ERE.COM under debug.  Execute the program setting
  362.          a breakpoint at 135B:0022 (if you remember, that is right at
  363.          the begining of the self modifing code).  When execution
  364.          stops, change you IP register to 192.  Now execute the code.
  365.  
  366.               Well shit, we are at the main menu.  We just bypassed
  367.          the entire protection routine.  So, now where to add the
  368.          patch.  We will be adding the patch at 135B:0022.  But what
  369.          should the patch be.  In this case, simply jumping to
  370.          135B:0192 will do.  So, reload ERE.COM under debug.  Execute
  371.          the code until 135B:0022.  Now unassemble it.  Here is the
  372.          code fragment we need.
  373.  
  374.          135B:0022 B013          MOV AL,13
  375.          135B:0024 A23500        MOV [0035],AL
  376.          135B:0027 A2FF01        MOV [01FF],AL
  377.          135B:002A A22F02        MOV [022F],AL
  378.          135B:002D A23901        MOV [0139],AL
  379.  
  380.               Here is the code we want to use as the patch
  381.  
  382.          135B:0022 E96D01        JMP 192
  383.  
  384.               So, to add the patch, we search the file ERE.COM using
  385.          PC-TOOLS.  For our search string we use
  386.  
  387.                  B0 13 A2 35 00 A2 FF 01 A2 2F 02 A2 39 01
  388.  
  389.               PC-TOOLS should find the search string at reletive
  390.          sector #13.  Edit the sector and change "B0 13 A2" to
  391.          "E9 6D 01" (our patch) and save the sector.
  392.  
  393.               BOOM! your done and CSMP is cracked.  Fun huh.  You just
  394.          kicked 5 seconds off of the load time.  Preaty fucken good.
  395.          Well, I hope this textfile helped.
  396.  
  397.  
  398.               -Buckaroo Banzai
  399.                -Cracking Guru
  400.