Skip to content

Instantly share code, notes, and snippets.

@2over12
Created January 6, 2021 21:55
Show Gist options
  • Save 2over12/2d515216380a8fb5aec815c78c944899 to your computer and use it in GitHub Desktop.
Save 2over12/2d515216380a8fb5aec815c78c944899 to your computer and use it in GitHub Desktop.
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
@2over12
Copy link
Author

2over12 commented Jan 6, 2021

wireshark capture of the message sent to the server

3528
{"entry_point_location":{"from_program":{"file_id":"some_file.c"},"addr":{"string_representation":"0x1000"}},"source":"undefined8 __thiscall\nCDataBlob<unsigned_char>::create(CDataBlob_unsigned_char_ *this,int param_1,int param_2,int param_3)\n\n{\n  uint uVar1;\n  long *plVar2;\n  int iVar3;\n  int iVar4;\n  long lVar5;\n  basic_ostream *pbVar6;\n  long *plVar7;\n  long lVar8;\n  undefined8 uVar9;\n  undefined auVar10 [16];\n  undefined in_YMM0 [32];\n  \n  auVar10 = SUB3216(in_YMM0,0);\n  if (*(void **)this != (void *)0x0) {\n    _Z7myFree_Pv(*(void **)this);\n    *(undefined8 *)this = 0;\n  }\n  auVar10 = vxorps_avx(auVar10,auVar10);\n  *(undefined (*) [16])(this + 8) = auVar10;\n  *(undefined8 *)(this + 0x18) = 0x3f800000;\n  *(int *)(this + 8) = param_1;\n  *(int *)(this + 0xc) = param_2;\n  *(int *)(this + 0x10) = param_3;\n  iVar3 = (param_3 & 0xffffffe0U) + 0x20;\n  if ((param_3 & 0x1fU) == 0) {\n    iVar3 = param_3;\n  }\n  *(int *)(this + 0x14) = iVar3;\n  lVar5 = _Z7myAllocm((long)iVar3 * (long)param_2 * (long)param_1);\n  *(long *)this = lVar5;\n  if (lVar5 == 0) {\n    std::_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l\n              ((basic_ostream *)&std::cerr,\"Failed to alloc memeory for uint8 data blob: \",0x2d);\n    pbVar6 = (basic_ostream *)\n             std::basic_ostream<char,std::char_traits<char>>::_ZNSolsEi\n                       ((basic_ostream_char_std__char_traits_char__ *)&std::cerr,*(int *)(this + 8))\n    ;\n    std::_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l(pbVar6,\"*\",1)\n    ;\n    pbVar6 = (basic_ostream *)\n             std::basic_ostream<char,std::char_traits<char>>::_ZNSolsEi\n                       ((basic_ostream_char_std__char_traits_char__ *)pbVar6,*(int *)(this + 0xc));\n    std::_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l(pbVar6,\"*\",1)\n    ;\n    plVar7 = (long *)std::basic_ostream<char,std::char_traits<char>>::_ZNSolsEi\n                               ((basic_ostream_char_std__char_traits_char__ *)pbVar6,\n                                *(int *)(this + 0x10));\n    plVar2 = *(long **)((long)plVar7 + *(long *)(*plVar7 + -0x18) + 0xf0);\n    if (plVar2 == (long *)0x0) {\n                    // WARNING: Subroutine does not return\n      std::_ZSt16__throw_bad_castv();\n    }\n    if (*(char *)(plVar2 + 7) == '\\0') {\n      std::ctype<char>::_ZNKSt5ctypeIcE13_M_widen_initEv();\n      (**(code **)(*plVar2 + 0x30))(plVar2,10);\n    }\n    std::basic_ostream<char,std::char_traits<char>>::_ZNSo3putEc((char)plVar7);\n    std::basic_ostream<char,std::char_traits<char>>::_ZNSo5flushEv();\n    uVar9 = 0;\n  }\n  else {\n    iVar3 = *(int *)(this + 0xc);\n    uVar9 = CONCAT71((uint7)(uint3)((uint)param_2 >> 8),1);\n    if (0 < iVar3) {\n      iVar4 = *(int *)(this + 8);\n      lVar5 = 0;\n      do {\n        if (0 < iVar4) {\n          lVar8 = 0;\n          do {\n            iVar3 = *(int *)(this + 0x14);\n            uVar1 = *(uint *)(this + 0x10);\n            if ((int)uVar1 < iVar3) {\n              memset((void *)((iVar4 * lVar5 + lVar8) * (long)iVar3 + (long)(int)uVar1 +\n                             *(long *)this),0,(ulong)(~uVar1 + iVar3) + 1);\n              iVar4 = *(int *)(this + 8);\n            }\n            lVar8 = lVar8 + 1;\n          } while (lVar8 < iVar4);\n          iVar3 = *(int *)(this + 0xc);\n        }\n        lVar5 = lVar5 + 1;\n      } while (lVar5 < iVar3);\n    }\n  }\n  return uVar9;\n}\n\n\n"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment