commit 01aa4a8c8cc7bb84244345e8ba33717a82382ddd Author: Reynir Björnsson Date: Tue Dec 7 22:51:25 2021 +0100 Initial commit diff --git a/bin/dune b/bin/dune new file mode 100644 index 0000000..351ff70 --- /dev/null +++ b/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name solo5_elftool) + (name main) + (libraries solo5_elftool owee cstruct cmdliner)) diff --git a/bin/main.ml b/bin/main.ml new file mode 100644 index 0000000..f66321a --- /dev/null +++ b/bin/main.ml @@ -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) diff --git a/dune-project b/dune-project new file mode 100644 index 0000000..8cf77e8 --- /dev/null +++ b/dune-project @@ -0,0 +1,2 @@ +(lang dune 2.9) +(name solo5_elftool) diff --git a/lib/dune b/lib/dune new file mode 100644 index 0000000..5dc0680 --- /dev/null +++ b/lib/dune @@ -0,0 +1,3 @@ +(library + (name solo5_elftool) + (libraries owee)) diff --git a/lib/solo5_elftool.ml b/lib/solo5_elftool.ml new file mode 100644 index 0000000..a83ee3d --- /dev/null +++ b/lib/solo5_elftool.ml @@ -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 diff --git a/solo5_elftool.opam b/solo5_elftool.opam new file mode 100644 index 0000000..e69de29 diff --git a/test/dune b/test/dune new file mode 100644 index 0000000..42159bc --- /dev/null +++ b/test/dune @@ -0,0 +1,2 @@ +(test + (name solo5_elftool)) diff --git a/test/solo5_elftool.ml b/test/solo5_elftool.ml new file mode 100644 index 0000000..e69de29