Skip to content

Commit ac7e6fc

Browse files
committed
Add setup script and update READM.md
1 parent f1984a3 commit ac7e6fc

File tree

3 files changed

+101
-21
lines changed

3 files changed

+101
-21
lines changed

Dockerfile

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,15 @@ RUN cd "${BASE}/explode-js/vendor/graphjs" \
6262
&& sudo pip install --break-system-packages -r ./requirements.txt \
6363
&& cd ./parser && sudo npm install && npm exec tsc
6464

65-
RUN opam init --disable-sandboxing --shell-setup -y \
65+
RUN opam init --bare --disable-sandboxing --shell-setup -y \
66+
&& sudo apt update \
6667
&& opam switch create -y ecma-sl 5.3.0 \
6768
&& eval $(opam env --switch=ecma-sl) \
6869
&& opam update \
6970
&& echo "eval \$(opam env --switch=ecma-sl)" >> ~/.bash_profile
7071

7172
RUN cd "${BASE}/explode-js/" && eval $(opam env --switch=ecma-sl) \
72-
&& opam install z3 -y --confirm-level=unsafe-yes
73-
74-
RUN cd "${BASE}/explode-js/" && eval $(opam env --switch=ecma-sl) \
75-
&& sudo apt update \
76-
&& cd ./vendor/ECMA-SL && opam install -y . --deps-only --confirm-level=unsafe-yes \
77-
&& dune build -p ecma-sl --profile release && dune install -p ecma-sl \
78-
&& cd ../../ && opam install -y . --deps-only --confirm-level=unsafe-yes \
79-
&& dune build @install --profile release \
80-
&& dune install
73+
&& ./setup.ml --skip-graphjs
8174

8275
# Cleanup unavailable resources
8376
RUN cd "${BASE}/explode-js/" && \

README.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,56 @@
11
# Explode-js
22

3-
Automatic exploit generation for Node.js applications. See [examples]
3+
Automatic exploit generation for Node.js applications.
44

55
### Build from source
66

7-
- Install the library dependencies:
7+
When building **Explode-js** from source, it is recommended that you first
8+
ensure the following:
89

10+
- Install [opam](https://opam.ocaml.org/doc/Install.html) and bootstrap
11+
the OCaml compiler:
12+
13+
<!-- $MDX skip -->
914
```sh
10-
git clone https://github.com/formalsec/explode-js.git
11-
cd explode-js
12-
opam install . --deps-only
15+
$ opam init
16+
$ opam switch create 5.3.0 5.3.0
1317
```
1418

15-
- Build and test:
19+
- Setup a managed Python environment using either [direnv](https://direnv.net/) or
20+
[virtualenv](https://docs.python.org/3/library/venv.html).
21+
22+
Then, you can proceed with the installation of Explode-js:
23+
24+
- Clone the repository and its dependencies, then run the `setup.ml` script:
1625

26+
<!-- $MDX skip -->
1727
```sh
18-
dune build
19-
dune runtest
28+
$ git clone https://github.com/formalsec/explode-js.git
29+
$ git submodule update --init
30+
# Or, if you only want to run explode-js and not the evaluation, use:
31+
# $ git submodule update --init bench/graphjs bench/ECMA-SL
32+
$ cd explode-js
33+
$ ./setup.ml
2034
```
2135

22-
- Install `explode-js` on your path by running:
36+
- To run tests:
2337

38+
<!-- $MDX skip -->
2439
```sh
25-
dune install
40+
$ dune runtest
2641
```
2742

43+
### Examples
44+
45+
For examples on how to run explode-js in different settings, see [examples].
46+
2847
### Evaluation
2948

3049
For benchmarking and evaluation see [bench]
3150

3251
[bench]: ./bench
3352
[examples]: ./example
3453

35-
3654
## Coding Practices
3755

3856
In this project I adopted some practices that made some parts of the code more

setup.ml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env ocaml
2+
3+
let skip_python = ref false
4+
5+
let () =
6+
let usage = Format.sprintf "%s [--skip-graphjs]" Sys.argv.(0) in
7+
let spec_list =
8+
[ ( "--skip-graphjs"
9+
, Arg.Set skip_python
10+
, "Skip graphjs's python configuration" )
11+
]
12+
in
13+
Arg.parse spec_list ignore usage
14+
15+
let with_dir fpath f =
16+
let cwd = Sys.getcwd () in
17+
Sys.chdir fpath;
18+
Fun.protect ~finally:(fun () -> Sys.chdir cwd) f
19+
20+
let on_fail res msg = if res <> 0 then Format.ksprintf failwith "Error: %s" msg
21+
22+
let opam_install pkg =
23+
Format.ksprintf Sys.command "opam install %s -y --confirm-level=unsafe-yes"
24+
pkg
25+
26+
let opam_exec rest = Format.ksprintf Sys.command "opam exec -- %s" rest
27+
28+
let setup_graphjs () =
29+
Format.printf "Installing graphjs ...@.";
30+
with_dir "vendor/graphjs" @@ fun () ->
31+
on_fail
32+
(Sys.command "pip install -r ./requirements.txt")
33+
"Could not install graphjs's python requirements";
34+
with_dir "parser" @@ fun () ->
35+
on_fail
36+
(Sys.command "npm install")
37+
"Could not install graphjs's normalizer dependencies";
38+
on_fail (Sys.command "npm exec tsc") "Could not compile graphjs's normalizer"
39+
40+
let setup_z3 () =
41+
Format.printf "Installing Z3 ...@.";
42+
on_fail (opam_install "z3") "Could not install z3 through opam!"
43+
44+
let setup_ecmasl () =
45+
Format.printf "Installing ECMA-SL ...@.";
46+
with_dir "vendor/ECMA-SL" @@ fun () ->
47+
on_fail
48+
(opam_install ". --deps-only")
49+
"Could not install ECMA-SL's dependencies";
50+
on_fail
51+
(opam_exec "dune build -p ecma-sl --profile release")
52+
"Could not build ECMA-SL!";
53+
on_fail (opam_exec "dune install -p ecma-sl") "Could not install ECMA-SL!"
54+
55+
let setup_explodejs () =
56+
Format.printf "Installing Explode-js ...@.";
57+
on_fail
58+
(opam_install ". --deps-only")
59+
"Could not install Explode-js's dependencies";
60+
on_fail
61+
(opam_exec "dune build @install --profile release")
62+
"Could not build Explode-js!";
63+
on_fail (opam_exec "dune install") "Could not install Explode-js!"
64+
65+
let () =
66+
if !skip_python then () else setup_graphjs ();
67+
setup_z3 ();
68+
setup_ecmasl ();
69+
setup_explodejs ()

0 commit comments

Comments
 (0)