blob: 0a2113851dbd8a48e941ca41629c7636ba7064a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
(*Generated by Lem from elf_string_table.lem.*)
open Elf_header
open Elf_section_header
open Elf_types
open Bitstring
open Error
open Missing_pervasives
open Lem_basic_classes
open Lem_list
open Lem_maybe
open Lem_num
open Lem_string
open Show
let get_strings_of_string_table bs =
(let strings = (Bitstring.string_of_bitstring bs) in
Ml_bindings.split_string_on_char strings '\000')
let read_elf32_string_table hdr sections bs : ( string list) error =
((match sections with
| None -> return []
| Some sections ->
let idx = (Int64.to_int hdr.elf32_shstrndx) in
let string_table = (Lem_list.list_index sections idx) in
(match string_table with
| None -> Fail "read_elf32_string_table: string table index too large"
| Some string_table ->
let offset = (Int64.to_int string_table.elf32_sh_offset) in
let size = (Int64.to_int string_table.elf32_sh_size) in
let (_, initial) = (Utility.partition_bitstring (offset * 8) bs) in
let (relevant, _) = (Utility.partition_bitstring (size * 8) initial) in
return (get_strings_of_string_table relevant)
)
))
let rec read_elf32_string_tables' offset_sizes (bs : Bitstring.bitstring) : ( string list) list =
((match offset_sizes with
| [] -> []
| x::xs ->
let (offset, size) = x in
let (_, relevant) = (Utility.partition_bitstring offset bs) in
let (cut, _) = (Utility.partition_bitstring size relevant) in
let strings = (get_strings_of_string_table cut) in
let tail = (read_elf32_string_tables' xs bs) in
strings::tail
))
let read_elf32_string_tables sections bs : ( string list) list =
((match sections with
| None -> []
| Some sections ->
let offsets_sizes = (List.concat (List.map (fun sect ->
if Int64.to_int sect.elf32_sh_type = sht_strtab then
let offset = ((Int64.to_int sect.elf32_sh_offset) * 8) in
let size =
(let _ = (print_endline ("YYY size: " ^ natShow (Int64.to_int sect.elf32_sh_size * 8))) in
Int64.to_int sect.elf32_sh_size * 8)
in
[(offset, size)]
else
[]
) sections))
in
read_elf32_string_tables' offsets_sizes bs
))
let string_of_elf32_string_table tbl =
("String table contents:" ^ ("\n\t" ^
(List.fold_right (^) tbl "" ^ "\n\n")))
let string_of_elf32_dynamic_string_table tbl =
("Dynamic string table contents:" ^ ("\n\t" ^
(List.fold_right (^) tbl "" ^ "\n\n")))
|