-
-
Save 2over12/2d515216380a8fb5aec815c78c944899 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let unpack_reader_result = function | |
| `Ok x -> x | |
| `Eof -> raise (Failure "expected to parse message") | |
let assert_size_match target received = if target = received then () else raise (Failure "did not read enough bytes") | |
(**this is from Framing.ml**) | |
let t_from_reader reader decoder = | |
let%bind len = Async.Reader.read_line reader >>| (Fn.compose Int.of_string unpack_reader_result) in | |
let buffer = Bytes.make len 'a' in Async.Reader.read reader ~len:len buffer >>= (fun read_result -> assert_size_match len (unpack_reader_result read_result); Bytes.to_string buffer |> decoder |> return) | |
let conn_handler _addr r _w = | |
let parse_message = GhidraATD.Functions_j.ghidra_function_of_string in | |
let message_processor (func_message: GhidraATD.Functions_t.ghidra_function) = (return (print_endline func_message.source): unit Deferred.t) in | |
let rec handle_message () = GhidraATD.Framing.t_from_reader r parse_message >>= message_processor >>> handle_message in | |
return (handle_message ()) | |
let run port = | |
let%bind server = | |
Tcp.Server.create | |
~on_handler_error:`Raise | |
(Tcp.Where_to_listen.of_port port) | |
conn_handler | |
in | |
Tcp.Server.close_finished server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wireshark capture of the message sent to the server