home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Stone / algo / scut.asm < prev    next >
Assembly Source File  |  2000-05-25  |  6KB  |  621 lines

  1. extrn        GetTickCount    : PROC    ; to get 'random' base information
  2.  
  3. randseed    dd    0        ; 64 bit random seed
  4.  
  5.         dd    0
  6.  
  7. strcpys        dd    0
  8.  
  9. strcpyt        dd    0
  10.  
  11. cmpstr1        dd    0
  12.  
  13. cmpstr2        dd    0
  14.  
  15. cstrlen        dd    0
  16.  
  17. kgincd        db    'keygen include v.2 (c) scut / blizzard'
  18.  
  19.  
  20. ; keygen include v.2, 980818
  21.  
  22. ; (c) scut of blizzard 1998
  23.  
  24. ; free use, as long as you give me credits
  25.  
  26.  
  27.  
  28. comment ⌡
  29.  
  30.  
  31.  
  32. numeric functions:
  33.  
  34. print_hex_32b    will print the number in eax to *edi, in hex, fixed len 8 bytes
  35.  
  36. print_hex_16b    will print the number in ax to *edi, in hex, fixed len 4 bytes
  37.  
  38. print_dec_32b    will print the number in eax to *edi, in dec., no fixed len
  39.  
  40. print_dec_16b    will print the number in ax to *edi, in dec, no ficed len
  41.  
  42. read_dec_32b    will read a decimal from *esi, returning it in eax
  43.  
  44. read_dec_16b    will read a decimal from *esi, returning it in ax
  45.  
  46.  
  47.  
  48. string functions:
  49.  
  50. strnlen        will return the length of the string *esi in eax
  51.  
  52. strcpy        will copy *esi to *edi, if carry set len is eax, else asciiz
  53.  
  54. strcmp        will compare *esi to *edi, if carry set len is eax, else asciiz
  55.  
  56.         returns: clc = equal, stc = unequal
  57.  
  58. strrmv        will all chars same as al from *esi, returning in *edi,
  59.  
  60.         note: esi and edi can be the same, the string will be terminated
  61.  
  62. strloc        will lowercase an asciiz string in *esi
  63.  
  64. strupc        will uppercase an asciiz string in *esi
  65.  
  66.  
  67.  
  68. random functions:
  69.  
  70. randomize    will initialize the random seeds, do this after a delay (user-input)
  71.  
  72. random        will return a pseudo-random number in eax, boundary by eax
  73.  
  74.  
  75.  
  76.  
  77. print_hex_32b    proc
  78.  
  79.     mov    ecx,8            ; 8 digits
  80.  
  81. p2hl0:    rol    eax,4            ; rol left 4 bits
  82.  
  83.     mov    bl,al
  84.  
  85.     and    bl,1111b
  86.  
  87.     cmp    bl,0ah
  88.  
  89.     jl    p2hl0a
  90.  
  91.     add    bl,7
  92.  
  93. p2hl0a:    add    bl,'0'
  94.  
  95.     mov    [edi],bl
  96.  
  97.     inc    edi
  98.  
  99.     dec    ecx
  100.  
  101.     jnz    p2hl0
  102.  
  103.     ret
  104.  
  105. endp    print_hex_32b
  106.  
  107. print_hex_16b    proc
  108.  
  109.     mov    ecx,4
  110.  
  111. p6bl0:    rol    ax,4
  112.  
  113.     mov    bl,al
  114.  
  115.     and    bl,1111b
  116.  
  117.     cmp    bl,0ah
  118.     jl    p6bl0a
  119.  
  120.     add    bl,7
  121.  
  122. p6bl0a:    add    bl,'0'
  123.  
  124.     mov    [edi],bl
  125.  
  126.     inc    edi
  127.  
  128.     dec    ecx
  129.  
  130.     jnz    p6bl0
  131.  
  132.     ret
  133.  
  134. endp    print_hex_16b
  135.  
  136. print_dec_32b    proc
  137.  
  138.     mov    ebx,10
  139.  
  140.     xor    ecx,ecx
  141.  
  142. p2dl1:    xor    edx,edx
  143.  
  144.     div    ebx
  145.  
  146.     push    edx
  147.  
  148.     inc    ecx
  149.  
  150.     or    eax,eax
  151.  
  152.     jne    p2dl1
  153.  
  154. p2dl2:    pop    edx
  155.  
  156.     add    dl,'0'
  157.  
  158.     mov    al,dl
  159.  
  160.     stosb
  161.  
  162.     dec    ecx
  163.  
  164.     jnz    p2dl2
  165.  
  166.     xor    al,al
  167.  
  168.     stosb
  169.  
  170.     ret
  171.  
  172. print_dec_32b    endp
  173.  
  174. print_dec_16b    proc
  175.     mov    bx,ax
  176.  
  177.     xor    eax,eax
  178.  
  179.     mov    ax,bx
  180.  
  181.     mov    ebx,10
  182.  
  183.     xor    ecx,ecx
  184.  
  185. p6dl1:    xor    edx,edx
  186.  
  187.     div    ebx
  188.  
  189.     push    edx
  190.  
  191.     inc    ecx
  192.  
  193.     or    eax,eax
  194.  
  195.     jne    p6dl1
  196.  
  197. p6dl2:    pop    edx
  198.  
  199.     add    dl,'0'
  200.  
  201.     mov    al,dl
  202.  
  203.     stosb
  204.  
  205.     dec    ecx
  206.  
  207.     jnz    p6dl2
  208.  
  209.     xor    al,al
  210.  
  211.     stosb
  212.  
  213.     ret
  214.  
  215. print_dec_16b    endp
  216.  
  217. read_dec_32b    proc
  218.  
  219.     mov    edi,10
  220.  
  221.     mov    ecx,10
  222.  
  223.     xor    ebx,ebx
  224.  
  225.     xor    edx,edx
  226.  
  227. a2tl0:    lodsb
  228.  
  229.     or    al,al
  230.  
  231.     jz    a2tle
  232.  
  233.     sub    al,'0'
  234.  
  235.     xor    ebx,ebx
  236.  
  237.     mov    bl,al
  238.  
  239.     mov    eax,edx
  240.  
  241.     mul    ecx
  242.  
  243.     add    eax,ebx
  244.  
  245.     mov    edx,eax
  246.  
  247.     dec    edi
  248.  
  249.     jnz    a2tl0
  250.  
  251. a2tle:    mov    eax,edx
  252.  
  253.     ret
  254.  
  255. read_dec_32b    endp
  256.  
  257. read_dec_16b    proc
  258.  
  259.     mov    bx,ax
  260.  
  261.     xor    eax,eax
  262.  
  263.     mov    ax,bx
  264.  
  265.     mov    edi,5
  266.  
  267.     mov    ecx,10
  268.  
  269.     xor    ebx,ebx
  270.  
  271.     xor    edx,edx
  272.  
  273. a6tl0:    lodsb
  274.  
  275.     or    al,al
  276.  
  277.     jz    a6tle
  278.  
  279.     sub    al,'0'
  280.  
  281.     xor    ebx,ebx
  282.  
  283.     mov    bl,al
  284.     mov    eax,edx
  285.  
  286.     mul    ecx
  287.  
  288.     add    eax,ebx
  289.  
  290.     mov    edx,eax
  291.  
  292.     dec    edi
  293.  
  294.     jnz    a6tl0
  295.  
  296. a6tle:    mov    eax,edx
  297.  
  298.     ret
  299.  
  300. read_dec_16b    endp
  301.  
  302.  
  303.  
  304. strnlen proc
  305.  
  306.     xor    ecx, ecx
  307.  
  308.     dec    ecx
  309.  
  310. strln0:    lodsb
  311.  
  312.     inc    ecx
  313.  
  314.     or    al,al
  315.  
  316.     jnz    strln0
  317.  
  318.     mov    eax, ecx
  319.  
  320.     ret
  321.  
  322. strnlen    endp
  323.  
  324. strcpy    proc
  325.  
  326.     mov    strcpys,esi
  327.  
  328.     mov    strcpyt,edi
  329.  
  330.     jc    strcl0
  331.  
  332.     mov    ecx,512
  333.  
  334. strcl2: lodsb
  335.     dec    ecx
  336.  
  337.     jz    strcl1
  338.  
  339.     or    al,al
  340.  
  341.     jnz    strcl2
  342.  
  343.     sub    esi,strcpys
  344.  
  345.     mov    ecx,esi
  346.  
  347.     mov    esi,strcpys
  348.  
  349.     jmp    strcl3
  350.  
  351. strcl1:    stc
  352.  
  353.     ret
  354.  
  355. strcl0:    mov    ecx,eax
  356.  
  357. strcl3:    rep    movsb
  358.     clc
  359.  
  360.     ret
  361.  
  362. strcpy    endp
  363.  
  364. strcmp    proc
  365.  
  366.     mov    cmpstr1,esi
  367.  
  368.     mov    cmpstr2,edi
  369.  
  370.     jc    strl0
  371.  
  372.     mov    edi,cmpstr1
  373.  
  374.     xor    al,al
  375.  
  376.     mov    ecx,512
  377.  
  378.     repne    scasb
  379.  
  380.     or    ecx,ecx
  381.  
  382.     jnz    strl0b
  383.  
  384.     stc
  385.  
  386.     ret
  387.  
  388. strl0b:    sub    edi,cmpstr1
  389.  
  390.     mov    eax,edi
  391.  
  392. strl0:    mov    cstrlen,eax
  393.  
  394.     mov    ecx,cstrlen
  395.  
  396.     mov    esi,cmpstr1
  397.  
  398.     mov    edi,cmpstr2
  399.  
  400. strl0a:    lodsb
  401.  
  402.     mov    bl,al
  403.  
  404.     mov    al,es:[edi]
  405.  
  406.     inc    edi
  407.  
  408.     cmp    al,bl
  409.  
  410.     jne    strl1
  411.  
  412.     dec    ecx
  413.  
  414.     or    ecx,ecx
  415.  
  416.     jnz    strl0a
  417.  
  418.     clc
  419.     ret
  420.  
  421. strl1:    stc
  422.  
  423.     ret
  424.  
  425. strcmp    endp
  426.  
  427. strrmv    proc
  428.  
  429.     mov    bl,al
  430.  
  431. rmvl0:    lodsb                ; get char
  432.  
  433.     or    al,al            ; end of string ?
  434.  
  435.     jz    rmvle            ; yes -> eop
  436.  
  437.     cmp    al,bl            ; strip char ?
  438.  
  439.     je    rmvl0            ; yes -> next char
  440.  
  441.     stosb                ; write char if not strip-char
  442.  
  443.     jmp    rmvl0
  444.  
  445. rmvle:    stosb                ; terminate *edi
  446.  
  447.     ret
  448.  
  449. strrmv    endp
  450.  
  451. strloc    proc
  452.  
  453.     mov    edi,esi
  454. locl0:    lodsb
  455.  
  456.     or    al,al
  457.  
  458.     jz    locl3
  459.  
  460.     cmp    al,41h
  461.  
  462.     jl    locl2
  463.  
  464.     cmp    al,5ah
  465.  
  466.     jg    locl2
  467.  
  468.     add    al,'a'-'A'
  469.  
  470. locl2:    stosb
  471.  
  472.     jmp    locl0
  473.  
  474. locl3:    stosb
  475.  
  476.     ret
  477.  
  478. strloc    endp
  479.  
  480. strupc    proc
  481.  
  482.     mov    edi,esi
  483.  
  484. upcl0:    lodsb
  485.  
  486.     or    al,al
  487.  
  488.     jz    upcl3
  489.  
  490.     cmp    al,'a'
  491.  
  492.     jl    upcl2
  493.  
  494.     cmp    al,'z'
  495.  
  496.     jg    upcl2
  497.  
  498.     sub    al,'a'-'A'
  499.  
  500. upcl2:    stosb
  501.  
  502.     jmp    upcl0
  503.  
  504. upcl3:    stosb
  505.  
  506.     ret
  507.  
  508. strupc    endp
  509.  
  510.  
  511.  
  512. randomize    proc
  513.  
  514.     call    GetTickCount
  515.  
  516.     mov    ecx,eax
  517.  
  518.     and    ecx,111b
  519.  
  520.     ror    eax,cl
  521.  
  522.     mov    ebx,eax
  523.  
  524.     call    GetTickCount
  525.  
  526.     add    eax,ebx
  527.  
  528.     mov    dword ptr randseed,eax
  529.  
  530.     rol    eax,4
  531.  
  532.     and    eax,111b
  533.  
  534.     add    eax,010b
  535.  
  536.     mov    ecx,eax
  537.  
  538.     shl    ecx,1
  539.  
  540. rndzl0:    call    GetTickCount
  541.  
  542.     and    eax,111b
  543.  
  544.     dec    ecx
  545.  
  546.     jz    rndzl1
  547.  
  548.     cmp    eax,ebx
  549.  
  550.     jne    rndzl0
  551.  
  552. rndzl1:    call    GetTickCount
  553.  
  554.     mov    ecx,eax
  555.  
  556.     and    ecx,111b
  557.  
  558.     ror    eax,cl
  559.  
  560.     mov    ebx,eax
  561.  
  562.     call    GetTickCount
  563.  
  564.     add    eax,ebx
  565.  
  566.     mov    dword ptr randseed+4,eax
  567.  
  568.     ret
  569.  
  570. randomize    endp
  571.  
  572. random    proc                ; limit in eax, return in eax
  573.  
  574.     mov    ecx,eax
  575.  
  576.     mov    eax,dword ptr randseed+4
  577.  
  578.     mov    ebx,dword ptr randseed
  579.  
  580.     mov    esi,eax
  581.  
  582.     mov    edi,ebx
  583.  
  584.     mov    dx,ax
  585.  
  586.     shl    eax,16
  587.  
  588.     mov    ax,bx
  589.  
  590.     shl    ebx,16
  591.  
  592.     xor    bx,bx
  593.  
  594.     rcr    dx,1
  595.     rcr    eax,1
  596.  
  597.     rcr    ebx,1
  598.  
  599.     adc    ebx,edi
  600.  
  601.     adc    eax,esi
  602.  
  603.     add    ebx,000062e9h
  604.  
  605.     adc    eax,00003619h
  606.  
  607.     mov    dword ptr randseed,ebx
  608.  
  609.     mov    dword ptr randseed+4,eax
  610.  
  611.     xor    edx,edx
  612.  
  613.     div    ecx
  614.  
  615.     mov    eax,edx
  616.  
  617.     ret
  618.  
  619. random    endp
  620.