write-ups-challenges-2019-2020/pharo-challenge/CTF/REPL.class.st

36 lines
1014 B
Smalltalk
Raw Normal View History

2022-11-24 21:43:03 +00:00
Class {
#name : #REPL,
#superclass : #Object,
#category : #CTF
}
{ #category : #running }
REPL class >> run [
| running command answer |
running := true.
Transcript show:'Welcome to Pharo 7.0 (Smalltalk Environment) Pharo.org'; cr; cr;
show: 'To get started create an instance of the class Challenge and, like so:'; cr;
show: '> Challenge new.'; cr;
show: 'This wil result in a value called "a Challenge"'; cr;
show: 'To obtain the flag run the following'; cr;
show: '> Challenge new flag.'; cr; cr;
show: 'Does it show up? '; cr.
[ 5 minutes wait. running := false. ] fork.
[ running ] whileTrue: [
Transcript show:'> '.
command := FileStream stdin nextLine .
(command = 'exit') ifTrue: [
running := false
] ifFalse: [
answer := [self class compiler evaluate: command] on:Exception do: [ :exception | Transcript show: 'Whoops, an error occured '. exception asString ] .
Transcript show:answer asString .
Transcript cr.
]
].
^ nil.
]