basic cli parsing

This commit is contained in:
nganhkhoa 2024-08-18 03:49:34 +07:00
commit 6328b43957
11 changed files with 127 additions and 0 deletions

30
.gitignore vendored Normal file
View File

@ -0,0 +1,30 @@
### OCaml ###
*.annot
*.cmo
*.cma
*.cmi
*.a
*.o
*.cmx
*.cmxs
*.cmxa
# ocamlbuild working directory
_build/
# ocamlbuild targets
*.byte
*.native
# oasis generated files
setup.data
setup.log
# Merlin configuring file for Vim and Emacs
.merlin
# Dune generated files
*.install
# Local OPAM switch
_opam/

10
bin/detect.ml Normal file
View File

@ -0,0 +1,10 @@
(** detection module
detect a given file for formats or ISA
*)
open Printf
let runner isa file =
printf "Detect file isa=%b %s\n" isa file

6
bin/dune Normal file
View File

@ -0,0 +1,6 @@
(env (dev (flags :standard -warn-error -27-32)))
(executable
(public_name firmex)
(name main)
(libraries firmex cmdliner))

4
bin/extract.ml Normal file
View File

@ -0,0 +1,4 @@
open Printf
let runner dry file =
printf "Extract file dry=%b %s\n" dry file

32
bin/main.ml Normal file
View File

@ -0,0 +1,32 @@
(** Firmware extractor
1. Verify if the file is a welknown archive format
2. Checking internal bytes for common filesystem
3. Recursive
Some files might require different approach
Common archive file formats are ZIP XZ TAR
Common filesystem are SQUASHFS JIFFS
*)
open Cmdliner
let extract =
let info = Cmd.info "extract" ~doc:"Extract the file." in
let dry = Arg.(value & opt bool false & info ["d"; "dry"] ~docv:"false" ~doc:"Dry run") in
let file = Arg.(required & pos 0 (some string) None & info [] ~docv:"FILE") in
Cmd.v info Term.(const Extract.runner $ dry $ file)
let detect =
let info = Cmd.info "detect" ~doc:"Detect the file type and its internal contents." in
let isa = Arg.(value & opt bool false & info ["isa"] ~docv:"false" ~doc:"Detect Instruction Set Architecture") in
let file = Arg.(required & pos 0 (some string) None & info [] ~docv:"FILE") in
Cmd.v info Term.(const Detect.runner $ isa $ file)
let cmd =
let info = Cmd.info "firmex group" ~version:"0.0.0-alpha" in
Cmd.group info [extract; detect;]
let () = exit (Cmd.eval cmd)

26
dune-project Normal file
View File

@ -0,0 +1,26 @@
(lang dune 3.16)
(name firmex)
(generate_opam_files true)
(source
(github username/reponame))
(authors "Author Name")
(maintainers "Maintainer Name")
(license LICENSE)
(documentation https://url/to/documentation)
(package
(name firmex)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml dune cmdliner)
(tags
(topics "to describe" your project)))
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html

0
firmex.opam Normal file
View File

14
lib/archive/zip.ml Normal file
View File

@ -0,0 +1,14 @@
(** This modules handle zip archive format
ZIP file format is actually really easy to parse
the file is a list of files compressed
each entry is appended with a header
ZIP file supports multiple compression algorithm,
the most frequently used is LZMA
files can be encrypted using a weak algorithm
which has been deprecated or AES
*)
let signature = Bytes.of_string "PK\x00\x00"

3
lib/dune Normal file
View File

@ -0,0 +1,3 @@
(include_subdirs qualified)
(library
(name firmex))

2
test/dune Normal file
View File

@ -0,0 +1,2 @@
(test
(name test_firmex))

0
test/test_firmex.ml Normal file
View File