Initial commit
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,74 @@
|
||||
#include <stdio.h>
|
||||
// gcc hirnfick.c -o hirnfick -Wl,-z,norelro -no-pie
|
||||
#define match(from, to, ptr, dir, level) \
|
||||
while (*(dir ptr)) { \
|
||||
if (*ptr == to && level == 0) \
|
||||
break; \
|
||||
if (*ptr == from) \
|
||||
++level; \
|
||||
if (*ptr == to) \
|
||||
--level; \
|
||||
}
|
||||
|
||||
int debug = 0;
|
||||
char data[1024] = {0};
|
||||
char code[1024] = {0};
|
||||
|
||||
void exec() {
|
||||
char *pc = code;
|
||||
char *p = data;
|
||||
;
|
||||
int level = 0;
|
||||
int ch;
|
||||
while (*pc) {
|
||||
switch (*pc) {
|
||||
case '>':
|
||||
++p;
|
||||
break;
|
||||
case '<':
|
||||
--p;
|
||||
break;
|
||||
case '+':
|
||||
++*p;
|
||||
break;
|
||||
case '-':
|
||||
--*p;
|
||||
break;
|
||||
case '.':
|
||||
putchar(*p);
|
||||
break;
|
||||
case ',':
|
||||
*p = ((ch = getchar()) == EOF) ? 0 : ch;
|
||||
break;
|
||||
case '[':
|
||||
if (!*p)
|
||||
match('[', ']', pc, ++, level);
|
||||
break;
|
||||
case ']':
|
||||
if (*p)
|
||||
match(']', '[', pc, --, level);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
pc++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
FILE *fp = fopen(argv[1], "r");
|
||||
char *pc = code;
|
||||
int ch;
|
||||
puts("HirnFick 1.0");
|
||||
while ((ch = fgetc(fp)) != EOF) {
|
||||
if (ch == '>' || ch == '<' || ch == '+' || ch == '-' || ch == '[' ||
|
||||
ch == ']' || ch == '.' || ch == ',')
|
||||
*(pc++) = ch;
|
||||
}
|
||||
fclose(fp);
|
||||
exec();
|
||||
if (debug) {
|
||||
puts(data);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>HirnFick</title>
|
||||
<link
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
|
||||
rel="stylesheet"
|
||||
integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM"
|
||||
crossorigin="anonymous"
|
||||
/>
|
||||
<style>
|
||||
#input,
|
||||
#output {
|
||||
height: 500px;
|
||||
}
|
||||
|
||||
:root {
|
||||
--bs-body-bg: var(--bs-gray-100);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="/">HirnFick</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container my-5">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<label for="input" class="form-label">Input</label>
|
||||
<textarea class="form-control font-monospace" id="input"></textarea>
|
||||
</div>
|
||||
<div class="col">
|
||||
<label for="output" class="form-label">Output</label>
|
||||
<textarea
|
||||
class="form-control font-monospace"
|
||||
id="output"
|
||||
disabled
|
||||
></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="my-2 w-100 btn btn-primary" onclick="run()">
|
||||
Run
|
||||
</button>
|
||||
</div>
|
||||
<script
|
||||
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
|
||||
integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"
|
||||
crossorigin="anonymous"
|
||||
></script>
|
||||
</body>
|
||||
<script>
|
||||
function run() {
|
||||
var inputEl = document.querySelector("#input");
|
||||
var outputEl = document.querySelector("#output");
|
||||
|
||||
var code = inputEl.value;
|
||||
|
||||
fetch("/api/run", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ code }),
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.then((r) => (outputEl.value = atob(r.output).slice(13)));
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
@@ -0,0 +1,2 @@
|
||||
uvicorn==0.23.2
|
||||
fastapi==0.103.1
|
||||
@@ -0,0 +1,35 @@
|
||||
import tempfile
|
||||
from base64 import b64encode
|
||||
from subprocess import check_output
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import FileResponse
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Input(BaseModel):
|
||||
code: bytes
|
||||
|
||||
|
||||
class Output(BaseModel):
|
||||
output: bytes
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def index():
|
||||
return FileResponse("index.html")
|
||||
|
||||
|
||||
@app.post("/api/run")
|
||||
def run(input: Input):
|
||||
code = input.code
|
||||
|
||||
with tempfile.NamedTemporaryFile() as fp:
|
||||
fp.write(code)
|
||||
fp.seek(0)
|
||||
output = check_output(["./hirnfick", fp.name])
|
||||
|
||||
return Output(output=b64encode(output))
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
/usr/sbin/sshd -D &
|
||||
/bin/su -s /bin/bash -c "uvicorn server:app --host 0.0.0.0 --port 8000" nobody
|
||||
Reference in New Issue
Block a user