Rockstarを動かしてみる

# 0.はじめに
こんにちは。普段科オリやCTFなど色々やってるもちもちと申します。
CTFで必要になったので今回はRockstarという言語の環境構築を備忘録もかねてやります。
Rockstarとは「1980年代ハードロック・パワーバラードの歌詞に大きく影響を受けた、歌詞として通用するプログラムが書けるようにデザインされた新言語」みたいです。例えば
```txt
Pico's a CTFFFFFFF
my mind is waitin
It's waitin

Put my mind of Pico into This
...
```
こんな風に一見ただの歌詞にしか見えないがちゃんとプログラムとして動きます


# 1.環境
Windows11
WSl:Ubuntu-22.04

# 2.環境構築
上から順にコマンド打っていく
```bash
$ git clone https://github.com/lkwq007/rockstar-ml.git
$ cd rockstar-ml
$ brew install ocaml opam
#Ubuntuデスクトップ版ならすでに入ってるらしい
$ sudo apt install bubblewrap
$ opam init
$ eval $(opam env)
$ opam install menhir
$ sudo apt install ocamlbuild
$ make
```
# 3.動かしてみる


<details><summary>Rockstarのデモコード(FizzBuzz)</summary><div>

```txt
Midnight takes your heart and your soul (function)
While your heart is as high as your soul (loop, comparison, conditional)
Put your heart without your soul into your heart (assign, arithmetic)

Give back your heart


Desire is a lovestruck ladykiller
My world is nothing 
Fire is ice
Hate is water
Until my world is Desire
Build my world up
If Midnight taking my world, Fire is nothing and Midnight taking my world, Hate is nothing
Shout "FizzBuzz!" (output)
Take it to the top (break)

If Midnight taking my world, Fire is nothing (if, comparison, conditional, function)
Shout "Fizz!"
Take it to the top

If Midnight taking my world, Hate is nothing
Say "Buzz!" (test comment)
Take it to the top

Whisper my world

Listen to my words (input)
Put my words into your soul
Say your soul

Nothing is true
Everything is premitted
Octocat says nothing
Say Octocat
Octocat is nobody
Say Octocat
Octocat is true
Say Octocat

C is a
If C is greater than 1
Say C

Else
Build C up
Say C

While C is lower than 100
Build C up
Say C
If C is greater than 5
Break it down

Else
While C is lower than 5
If Octocat is true and false ain't t'r'u'e'''''''''''''''''
Say "Nyan"

Build C up


Say C

D
Say it
```
</div></details>


実行結果
```
1.2.Fizz!4.Buzz!Fizz!7.8.Fizz!Buzz!11.Fizz!13.14.FizzBuzz!16.17.Fizz!19.Buzz!Fizz!22.23.Fizz!Buzz!26.Fizz!28.29.FizzBuzz!31.32.Fizz!34.Buzz!Fizz!37.38.Fizz!Buzz!41.Fizz!43.44.FizzBuzz!46.47.Fizz!49.Buzz!Fizz!52.53.Fizz!Buzz!56.Fizz!58.59.FizzBuzz!61.62.Fizz!64.Buzz!Fizz!67.68.Fizz!Buzz!71.Fizz!73.74.FizzBuzz!76.77.Fizz!79.Buzz!Fizz!82.83.Fizz!Buzz!86.Fizz!88.89.FizzBuzz!91.92.Fizz!94.Buzz!Fizz!97.98.Fizz!Buzz!
```

# 4.picoCTF:mus1c(300pt)
実際にCTFの問題を解いてみる
<details><summary>問題文</summary><div>

```
Pico's a CTFFFFFFF
my mind is waitin
It's waitin

Put my mind of Pico into This
my flag is not found
put This into my flag
put my flag into Pico


shout Pico
shout Pico
shout Pico

My song's something
put Pico into This

Knock This down, down, down
put This into CTF

shout CTF
my lyric is nothing
Put This without my song into my lyric
Knock my lyric down, down, down

shout my lyric

Put my lyric into This
Put my song with This into my lyric
Knock my lyric down

shout my lyric

Build my lyric up, up ,up

shout my lyric
shout Pico
shout It

Pico CTF is fun
security is important
Fun is fun
Put security with fun into Pico CTF
Build Fun up
shout fun times Pico CTF
put fun times Pico CTF into my song

build it up

shout it
shout it

build it up, up
shout it
shout Pico
```
</div></details>

実行結果
```
$ ./rockstar-ml/rockstar.native lyrics.rock 
lyrics.rock:6:16: syntax error
```
## は？

仕様を読みに行く
```
Spec - Implementation

    ❌File format - ocamllex not support UTF-8
    ✔️Comments
    🐛Variables - Still some bugs, as the spec is ambiguous
        ✔️Common variables
        ✔️Proper variables
        ✔️Pronouns - don't know variable scope, so assume global scope, using the previous parsed variable
    ✔️Types - Not support dec64
        ✔️Mysterious
        ✔️Null
        ✔️Boolean
        ❌Number - not support dec64, use float instead
        ✔️String
        ❌Object - lack details in spec

```


・・・・・・


https://codewithrockstar.com/online

```
114
114
114
111
99
107
110
114
110
48
49
49
51
114
```
```py
N=(114,114,114,111,99,107,110,114,110,48,49,49,51,114)
flag=''.join(chr(i) for i in N)
print(flag)
```
picoCTF{rrrocknrn0113r}
無事解けました！




参考文献

https://github.com/lkwq007/rockstar-ml