Skip to content

Commit 977068f

Browse files
committed
use cryptokit by default
add API: string_to_hexstring
1 parent af5ab8e commit 977068f

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

myocamlbuild.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ let _ = dispatch begin function
7676
"pkg_batteries";
7777
"pkg_bitstring";
7878
"pkg_bitstring.syntax";
79+
"pkg_cryptokit";
7980
];
8081

8182
tag_file "src/ocamlExploit.ml" ["syntax_camlp4o";

src/ocamlExploit.ml

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,50 +111,51 @@ let explode s =
111111
in
112112
exp (String.length s - 1) []
113113

114-
let printhex little str =
115-
let print_chunk chunk =
116-
Printf.printf "%08lx" chunk
114+
let string_to_hexstring little str =
115+
let accumulate acc chunk =
116+
Printf.sprintf "%s%08lx" acc chunk
117117
in
118-
let rec print_little_loop bs =
118+
let rec little_loop acc bs =
119119
bitmatch bs with
120120
| {chunk : 32 : littleendian; rest : -1 : bitstring }
121-
when bitstring_length rest = 0 -> print_chunk chunk
121+
when bitstring_length rest = 0 -> accumulate acc chunk
122122
| {chunk : 32 : littleendian;
123123
chunk2 : 24 : littleendian; rest : -1 : bitstring }
124124
when bitstring_length rest = 0 ->
125-
(print_chunk chunk; Printf.printf "%06x\n" chunk2)
125+
let acc = accumulate acc chunk in
126+
Printf.sprintf "%s%06x\n" acc chunk2
126127
| {chunk : 32 : littleendian; rest : -1 : bitstring } ->
127-
(print_chunk chunk; print_little_loop rest)
128+
let acc = accumulate acc chunk in
129+
little_loop acc rest
128130
| {chunk : 8 : littleendian; rest : -1 : bitstring }
129131
when bitstring_length rest = 0 ->
130-
Printf.printf "%02x\n" chunk
132+
Printf.sprintf "%s%02x\n" acc chunk
131133
| {chunk : 16 : littleendian; rest : -1 : bitstring }
132134
when bitstring_length rest = 0 ->
133-
Printf.printf "%04x\n" chunk
135+
Printf.sprintf "%s%04x\n" acc chunk
134136
in
135-
let rec print_big_loop bs =
137+
let rec big_loop acc bs =
136138
bitmatch bs with
137139
| {chunk : 32 : bigendian; rest : -1 : bitstring }
138-
when bitstring_length rest = 0 -> print_chunk chunk
140+
when bitstring_length rest = 0 -> accumulate acc chunk
139141
| {chunk : 32 : bigendian;
140142
chunk2 : 24 : bigendian; rest : -1 : bitstring }
141143
when bitstring_length rest = 0 ->
142-
(print_chunk chunk; Printf.printf "%06x\n" chunk2)
144+
let acc = accumulate acc chunk in
145+
Printf.sprintf "%s%06x\n" acc chunk2
143146
| {chunk : 32 : bigendian; rest : -1 : bitstring } ->
144-
(print_chunk chunk; print_big_loop rest)
147+
let acc = accumulate acc chunk in
148+
big_loop acc rest
145149
| {chunk : 8 : bigendian; rest : -1 : bitstring }
146150
when bitstring_length rest = 0 ->
147-
Printf.printf "%02x\n" chunk
151+
Printf.sprintf "%s%02x\n" acc chunk
148152
| {chunk : 16 : bigendian; rest : -1 : bitstring }
149153
when bitstring_length rest = 0 ->
150-
Printf.printf "%04x\n" chunk
154+
Printf.sprintf "%s%04x\n" acc chunk
151155
in
152156
let bs = bitstring_of_string str in
153-
begin
154-
if little then print_little_loop bs
155-
else print_big_loop bs
156-
end;
157-
flush stdout
157+
if little then little_loop "" bs
158+
else big_loop "" bs
158159

159160
let hexdump str =
160161
bitstring_of_string str |> hexdump_bitstring stdout

src/ocamlExploit.mli

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ val int32_to_hexstring : int32 -> string
4545
(** get a string from a hexstring *)
4646
val hexstring_to_string : string -> string
4747

48+
(** get a hexstring from the given string
49+
little specifies whether the string is little endian or not *)
50+
val string_to_hexstring : bool -> string -> string
51+
4852
(** simple print, but always flush *)
4953
val print : string -> unit
5054

51-
(** print the given string in hexstring,
52-
little specifies whether the string is little endian or not *)
53-
val printhex : bool -> string -> unit
54-
5555
(** print the given string in a format similar to hexdump *)
5656
val hexdump : string -> unit
5757

0 commit comments

Comments
 (0)