asm support

This commit is contained in:
Brian Seymour 2018-09-28 15:24:24 -05:00
parent de7ecffd37
commit f84ab7e50d
5 changed files with 26 additions and 27 deletions

View File

@ -33,7 +33,6 @@ func main() {
} }
func Execute(res http.ResponseWriter, req *http.Request) { func Execute(res http.ResponseWriter, req *http.Request) {
var found = false
res.Header().Set("Content-Type", "application/json") res.Header().Set("Content-Type", "application/json")
// get json // get json
@ -42,22 +41,16 @@ func Execute(res http.ResponseWriter, req *http.Request) {
message.Decode(&inbound) message.Decode(&inbound)
whitelist := []string{ whitelist := []string{
"python", "python", "python2", "python3",
"python2",
"python3",
"ruby", "ruby",
"javascript", "javascript", "js", "node",
"js",
"node",
"c", "c",
"cpp", "cpp", "c++",
"c++",
"go", "go",
"r", "r",
"php", "php",
"c#", "c#", "csharp", "cs",
"csharp", "nasm", "asm",
"cs",
} }
// check if the supplied language is supported // check if the supplied language is supported
@ -70,7 +63,6 @@ func Execute(res http.ResponseWriter, req *http.Request) {
} }
// now only called when the language is not supported // now only called when the language is not supported
if !found {
problem := problem{ problem := problem{
Code: "unsupported_language", Code: "unsupported_language",
Message: inbound.Language + " is not supported by Piston", Message: inbound.Language + " is not supported by Piston",
@ -79,24 +71,22 @@ func Execute(res http.ResponseWriter, req *http.Request) {
pres, _ := json.Marshal(problem) pres, _ := json.Marshal(problem)
res.Write(pres) res.Write(pres)
return
}
} }
func launch(inbound2 inbound, res http.ResponseWriter){ func launch(request inbound, res http.ResponseWriter) {
var ext string = "code"; var ext string = "code";
if inbound2.Language == "go" { if request.Language == "go" {
ext = "go" ext = "go"
} }
// write the code to temp dir // write the code to temp dir
filename := fmt.Sprintf("/tmp/%d." + ext, time.Now().UnixNano()) filename := fmt.Sprintf("/tmp/%d." + ext, time.Now().UnixNano())
ioutil.WriteFile(filename, []byte(inbound2.Source), 0644) ioutil.WriteFile(filename, []byte(request.Source), 0644)
// set up the execution // set up the execution
cmd := exec.Command("../docker/execute", inbound2.Language, filename) cmd := exec.Command("../docker/execute", request.Language, filename)
// capture out/err // capture out/err
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer

View File

@ -17,6 +17,7 @@ RUN apt-get -y install golang
RUN apt-get -y install php7.2 RUN apt-get -y install php7.2
RUN apt-get -y install r-base RUN apt-get -y install r-base
RUN apt-get -y install mono-complete RUN apt-get -y install mono-complete
RUN apt-get -y install nasm
RUN useradd -m runner RUN useradd -m runner

View File

@ -47,6 +47,9 @@ case "$lang" in
"php") "php")
bin=executor_php bin=executor_php
;; ;;
"nasm" | "asm")
bin=executor_nasm
;;
*) *)
echo "invalid language" echo "invalid language"
exit exit
@ -68,6 +71,7 @@ docker run \
-v $dir/executors/csharp:/executor_csharp:ro \ -v $dir/executors/csharp:/executor_csharp:ro \
-v $dir/executors/r:/executor_r:ro \ -v $dir/executors/r:/executor_r:ro \
-v $dir/executors/php:/executor_php:ro \ -v $dir/executors/php:/executor_php:ro \
-v $dir/executors/nasm:/executor_nasm:ro \
piston \ piston \
runuser \ runuser \
-l runner \ -l runner \

4
docker/executors/nasm Normal file
View File

@ -0,0 +1,4 @@
#!/bin/sh
nasm -f elf64 -o binary.o $1
ld binary.o -o binary

View File

@ -13,7 +13,7 @@ from from EMKC contests and challenges. It's also used in the Engineer Man Disco
- `docker/execute <lang> <path to file>` - `docker/execute <lang> <path to file>`
#### Supported Languages #### Supported Languages
Currently python2, python3, c, c++, go, node, ruby, r, c#, and php is supported. Currently python2, python3, c, c++, go, node, ruby, r, c#, nasm, and php is supported.
#### Principle of Operation #### Principle of Operation
Piston utilizes Docker as the primary mechanism for sandboxing. There is a small API written in Go which takes Piston utilizes Docker as the primary mechanism for sandboxing. There is a small API written in Go which takes