Initial commit
This commit is contained in:
commit
01aa4a8c8c
8 changed files with 65 additions and 0 deletions
4
bin/dune
Normal file
4
bin/dune
Normal file
|
@ -0,0 +1,4 @@
|
|||
(executable
|
||||
(public_name solo5_elftool)
|
||||
(name main)
|
||||
(libraries solo5_elftool owee cstruct cmdliner))
|
19
bin/main.ml
Normal file
19
bin/main.ml
Normal file
|
@ -0,0 +1,19 @@
|
|||
let hex_dump file =
|
||||
Owee_buf.map_binary file
|
||||
|> Solo5_elftool.foo
|
||||
|> Result.iter (fun s ->
|
||||
Cstruct.of_string s |> Cstruct.hexdump)
|
||||
|
||||
let file =
|
||||
let doc = "Solo5 executable" in
|
||||
Cmdliner.Arg.(required & pos 0 (some file) None &
|
||||
info ~doc ~docv:"EXECUTABLE" [])
|
||||
|
||||
let hex_dump_cmd =
|
||||
let doc = "hexdump solo5 manifest" in
|
||||
Cmdliner.Term.(
|
||||
pure hex_dump $ file,
|
||||
info ~doc "query-manifest")
|
||||
|
||||
let () =
|
||||
ignore (Cmdliner.Term.eval hex_dump_cmd)
|
2
dune-project
Normal file
2
dune-project
Normal file
|
@ -0,0 +1,2 @@
|
|||
(lang dune 2.9)
|
||||
(name solo5_elftool)
|
3
lib/dune
Normal file
3
lib/dune
Normal file
|
@ -0,0 +1,3 @@
|
|||
(library
|
||||
(name solo5_elftool)
|
||||
(libraries owee))
|
35
lib/solo5_elftool.ml
Normal file
35
lib/solo5_elftool.ml
Normal file
|
@ -0,0 +1,35 @@
|
|||
type mft_type =
|
||||
| Dev_block_basic
|
||||
| Dev_net_basic
|
||||
| Reserved_first
|
||||
|
||||
let int_of_mft_type = function
|
||||
| Dev_block_basic -> 1
|
||||
| Dev_net_basic -> 2
|
||||
| Reserved_first -> 1 lsl 30
|
||||
|
||||
let mft_type_of_int = function
|
||||
| 1 -> Dev_block_basic
|
||||
| 2 -> Dev_net_basic
|
||||
| 1073741824 -> Reserved_first
|
||||
| _ -> assert false
|
||||
|
||||
let ( let* ) = Result.bind
|
||||
|
||||
let mft_max_entries = 64
|
||||
|
||||
let foo buf =
|
||||
let _header, sections = Owee_elf.read_elf buf in
|
||||
let* section =
|
||||
Owee_elf.find_section sections ".note.solo5.manifest"
|
||||
|> Option.to_result ~none:(`Msg "section .note.solo5.manifest not found")
|
||||
in
|
||||
let body = Owee_elf.section_body buf section in
|
||||
let cursor = Owee_buf.cursor body in
|
||||
let descsz =
|
||||
Owee_elf_notes.read_desc_size cursor
|
||||
~expected_owner:"Solo5"
|
||||
~expected_type:0x3154464d
|
||||
in
|
||||
let desc = Owee_buf.Read.fixed_string cursor descsz in
|
||||
Ok desc
|
0
solo5_elftool.opam
Normal file
0
solo5_elftool.opam
Normal file
2
test/dune
Normal file
2
test/dune
Normal file
|
@ -0,0 +1,2 @@
|
|||
(test
|
||||
(name solo5_elftool))
|
0
test/solo5_elftool.ml
Normal file
0
test/solo5_elftool.ml
Normal file
Loading…
Reference in a new issue