IDA C++ SDK 9.2
Loading...
Searching...
No Matches
network.hpp
Go to the documentation of this file.
1#ifndef NETWORK_HPP
2#define NETWORK_HPP
3
4#include <pro.h>
5#include <md5.h>
6
7#ifdef __NT__
8# if !defined(AF_MAX)
9# ifndef NOMINMAX
10# define NOMINMAX
11# endif
12# include <ws2tcpip.h>
13# endif
14# define SYSTEM "Windows"
15# define socklen_t int
16# define SHUT_RD SD_RECEIVE
17# define SHUT_WR SD_SEND
18# define SHUT_RDWR SD_BOTH
19#else // not NT, i.e. UNIX
20# include <netinet/in.h>
21# include <netinet/tcp.h>
22# include <arpa/inet.h>
23# include <netdb.h>
24# define closesocket(s) close(s)
25# define SOCKET size_t
26# define INVALID_SOCKET size_t(-1)
27# define SOCKET_ERROR (-1)
28# if defined(__LINUX__)
29# if defined(__ARM__)
30# if defined(__ANDROID__)
31# define SYSTEM "Android"
32# else
33# define SYSTEM "ARM Linux"
34# endif
35# else
36# if defined(__ANDROID__)
37# define SYSTEM "Android x86"
38# define SYSTEM "Android x86"
39# else
40# define SYSTEM "Linux"
41# endif
42# endif
43 // linux debugger cannot be multithreaded because it uses thread_db.
44 // i doubt that this library is meant to be used with multiple
45 // applications simultaneously.
46# define __SINGLE_THREADED_SERVER__
47# elif defined(__MAC__)
48# define SYSTEM "Mac OS X"
49# else
50# error "Unknown platform"
51# endif
52# include <sys/socket.h>
53# include <netinet/in.h>
54#endif
55
56#ifndef __X86__
57# define _SYSBITS " 64-bit"
58#else
59# define _SYSBITS " 32-bit"
60#endif
61
62#ifdef TESTABLE_BUILD
63# ifdef __EA64__
64# define SYSBITS _SYSBITS " (sizeof ea=64)"
65# else
66# define SYSBITS _SYSBITS " (sizeof ea=32)"
67# endif
68#else
69# define SYSBITS _SYSBITS
70#endif
71
72#ifdef __SINGLE_THREADED_SERVER__
73# define __SERVER_TYPE__ "ST"
74#else
75# define __SERVER_TYPE__ "MT"
76#endif
77
78#define TIMEOUT (1000/25) // timeout for polling (ms)
79#define TIMEOUT_INFINITY -1
80#define RECV_TIMEOUT_PERIOD 10000 // timeout for recv (ms)
81
82// bidirectional codes (client <-> server)
84{
85 RPC_OK = 0, // response: function call succeeded
86 RPC_UNK, // response: unknown function code
87 RPC_MEM, // response: no memory
89};
90
91#define RPC_OPEN 3 // server->client: i'm ready, the very first packet
92
93#define RPC_EVENT 4 // server->client: debug event ready, followed by debug_event
94#define RPC_EVOK 5 // client->server: event processed (in response to RPC_EVENT)
95#define RPC_CANCELLED 6 // client->server: operation was cancelled by the user
96// we need EVOK to handle the situation when the debug
97// event was detected by the server during polling and
98// was sent to the client using RPC_EVENT but client has not received it yet
99// and requested GET_DEBUG_EVENT. In this case we should not
100// call remote_get_debug_event() but instead force the client
101// to use the event sent by RPC_EVENT.
102// In other words, if the server has sent RPC_EVENT but has not
103// received RPC_EVOK, it should fail all GET_DEBUG_EVENTS.
104
105// client->server codes
106#define RPC_INIT 10
107#define RPC_TERM 11
108#define RPC_GET_PROCESSES 12
109#define RPC_START_PROCESS 13
110#define RPC_EXIT_PROCESS 14
111#define RPC_ATTACH_PROCESS 15
112#define RPC_DETACH_PROCESS 16
113#define RPC_GET_DEBUG_EVENT 17
114#define RPC_PREPARE_TO_PAUSE_PROCESS 18
115#define RPC_STOPPED_AT_DEBUG_EVENT 19
116#define RPC_CONTINUE_AFTER_EVENT 20
117#define RPC_TH_SUSPEND 21
118#define RPC_TH_CONTINUE 22
119#define RPC_SET_RESUME_MODE 23
120#define RPC_GET_MEMORY_INFO 24
121#define RPC_READ_MEMORY 25
122#define RPC_WRITE_MEMORY 26
123#define RPC_UPDATE_BPTS 27
124#define RPC_UPDATE_LOWCNDS 28
125#define RPC_EVAL_LOWCND 29
126#define RPC_ISOK_BPT 30
127#define RPC_READ_REGS 31
128#define RPC_WRITE_REG 32
129#define RPC_GET_SREG_BASE 33
130#define RPC_SET_EXCEPTION_INFO 34
131
132#define RPC_OPEN_FILE 35
133#define RPC_CLOSE_FILE 36
134#define RPC_READ_FILE 37
135#define RPC_WRITE_FILE 38
136#define RPC_IOCTL 39 // both client and the server may send this packet
137#define RPC_UPDATE_CALL_STACK 40
138#define RPC_APPCALL 41
139#define RPC_CLEANUP_APPCALL 42
140#define RPC_REXEC 43
141#define RPC_GET_SCATTERED_IMAGE 44
142#define RPC_GET_IMAGE_UUID 45
143#define RPC_GET_SEGM_START 46
144#define RPC_BIN_SEARCH 47
145#define RPC_GET_DYNREGS 48
146
147// server->client codes
148#define RPC_SET_DEBUG_NAMES 50
149#define RPC_SYNC_STUB 51
150#define RPC_ERROR 52
151#define RPC_MSG 53
152#define RPC_WARNING 54
153#define RPC_HANDLE_DEBUG_EVENT 55
154#define RPC_REPORT_IDC_ERROR 56
155#define RPC_IMPORT_DLL 57
156
157#pragma pack(push, 1)
158
159struct PACKED rpc_packet_t
160{ // fields are always sent in the network order
161 uint32 length; // length of the packet (do not count length & code)
162 uchar code; // function code
163};
164CASSERT(sizeof(rpc_packet_t) == 5);
165#pragma pack(pop)
166
174
175#define DEFINE_ONE_NOTIFICATION_FUNCTION(FuncName, NotifCode, RpcEngineInst) \
176 AS_PRINTF(2, 3) void FuncName(const char *format, ...) \
177 { \
178 va_list va; \
179 va_start(va, format); \
180 dvnotif(NotifCode, RpcEngineInst, format, va); \
181 va_end(va); \
182 }
183
184#define DEFINE_ALL_NOTIFICATION_FUNCTIONS(RpcEngineInst) \
185 DEFINE_ONE_NOTIFICATION_FUNCTION(dmsg, 0, RpcEngineInst) \
186 DEFINE_ONE_NOTIFICATION_FUNCTION(dwarning, 1, RpcEngineInst) \
187 DEFINE_ONE_NOTIFICATION_FUNCTION(derror, -1, RpcEngineInst)
188
189class rpc_engine_t;
191
192//-------------------------------------------------------------------------
193AS_PRINTF(2, 0) ssize_t dvnotif_client(
194 int code,
195 const char *format,
196 va_list va);
197
198#ifdef __NT__
199# define IRSERR_TIMEOUT WAIT_TIMEOUT
200#else
201# define IRSERR_TIMEOUT ETIME
202#endif
203#define IRSERR_CANCELLED -0xE5CA7E // escape
204#define IRSERR_SKIP_ITER -0x5217 // skip recv() in rpc_engine_t's recv_data loop
205
206//-------------------------------------------------------------------------
207// idarpc_stream_t
208//-------------------------------------------------------------------------
209// the idarpc_stream_t structure is not defined.
210// it is used as an opaque type provided by the transport level.
211// the transport level defines its own local type for it.
212struct idarpc_stream_t;
213
214idarpc_stream_t *irs_new(bool use_tls=false);
215
216//-------------------------------------------------------------------------
218{
221
223 host_port_t(const qstring &_host, ushort _port) : host(_host), port(_port) {}
224
225 void clear() { host.clear(); port = 0; }
226 bool is_valid() const { return !host.empty() && port != 0; }
227
228 bool operator==(const host_port_t &r) const
229 {
230 return host == r.host && port == r.port;
231 }
232
234 {
235 host.swap(r.host);
236 qswap(port, r.port);
237 }
238
239 qstring connstr(int default_port=0) const
240 {
241 qstring s;
242 if ( port != 0 && port != default_port )
243 {
244 if ( host[0] != '[' && host.find(':') != qstring::npos )
245 s.sprnt("[%s]:%u", host.c_str(), port); // IPv6 address
246 else
247 s.sprnt("%s:%u", host.c_str(), port);
248 }
249 else
250 {
251 s = host;
252 }
253 return s;
254 }
255};
257
258//-------------------------------------------------------------------------
260{
262 // holds passwords provided through command-line parameters,
263 // or environment variable. A password retrieved from the
264 // keychain is not stored here.
266
269 : host_port_t(_host, _port) {}
270
271 //-------------------------------------------------------------------------
272 void clear()
273 {
275 username.clear();
276 password_override.clear();
277 }
278
279 //-------------------------------------------------------------------------
280 // Accepts the following schemes:
281 // `hostname:port`
282 // `user@hostname:port`
283 // `user:pass@hostname:port`
284#define PCF_MERGE 1
285 static bool parse_connstr(
287 const qstring &s,
288 uint32 flags=0)
289 {
290 if ( (flags & PCF_MERGE) == 0 )
291 out->clear();
292 if ( s.empty() )
293 return false;
294 qstrvec_t parts;
295 s.split(&parts, "@");
296 if ( parts.size() > 2 )
297 return false;
298 int addr_idx = 0;
299 if ( parts.size() == 2 )
300 { // the username is present
301 const qstring &p0 = parts[0];
302 if ( p0.empty() )
303 return false;
304 qstrvec_t identity_parts;
305 p0.split(&identity_parts, ":");
306 if ( identity_parts.size() > 2 )
307 return false;
308 out->username.swap(identity_parts[0]);
309 if ( identity_parts.size() == 2 )
310 out->password_override.swap(identity_parts[1]);
311 addr_idx = 1;
312 }
314 qstring &addr = parts[addr_idx];
315 const char *ptr = addr.c_str();
316 const char *colon = nullptr;
317 if ( ptr[0] == '[' ) // IPv6 address?
318 {
319 const char *br = strchr(ptr, ']');
320 if ( br == nullptr || br == ptr+1 )
321 return false;
322 host = qstring(ptr+1, br-ptr-1);
323 addr.remove(0, br-ptr);
324 ptr = addr.c_str();
325 if ( ptr[0] == ':' )
326 colon = ptr;
327 }
328 else
329 {
330 if ( strnieq(ptr, "::ffff:", 7) // IPv6 prefix for IPv4 addresses
331 && strchr(ptr, '.') != nullptr ) // old style IPv4 address seems to follow
332 {
333 ptr += 7; // skip the prefix
334 }
335 colon = strchr(ptr, ':');
336 }
337 if ( colon != nullptr )
338 {
339 char *end;
340 int port = strtoul(++colon, &end, 10);
341 if ( colon == end )
342 return false;
343 while ( *end == ' ' )
344 ++end;
345 if ( *end != '\0' )
346 return false;
347 addr.resize(colon - ptr - 1);
348 out->port = port;
349 }
350 out->host.swap(host.empty() ? addr : host);
351 return true;
352 }
353
354 //-------------------------------------------------------------------------
355 bool parse_connstr(const qstring &s, uint32 flags=0)
356 {
357 return parse_connstr(this, s, flags);
358 }
359
360#define BCF_INCLUDE_USER 1
361#define BCF_INCLUDE_PASS 2
363 qstring *out,
364 uint32 flags=0) const
365 {
366 if ( host.empty() )
367 return;
368
369 qstring buf;
370 if ( (flags & BCF_INCLUDE_USER) != 0 && !username.empty() )
371 buf.append(username);
372 if ( (flags & BCF_INCLUDE_PASS) != 0 && !password_override.empty() )
373 {
374 if ( !buf.empty() )
375 buf.append(':');
377 }
378 if ( !buf.empty() )
379 buf.append('@');
380 buf.append(connstr());
381 out->swap(buf);
382 }
384 {
385 qstring tmp;
386 build_connstr(&tmp, flags);
387 return tmp;
388 }
389};
391
392//-------------------------------------------------------------------------
393typedef bool irs_cancel_connect_cb_t(void *);
394
401typedef progress_loop_ctrl_t irs_progress_cb_t(bool receiving, size_t processed, size_t total, void *);
402void irs_set_progress_cb(idarpc_stream_t *irs, int ms, irs_progress_cb_t cb, void *ud=nullptr);
404{
405 idarpc_stream_t *irs;
406 irs_cancellable_op_t(idarpc_stream_t *_irs, bool receiving, size_t goal=0);
408 void inc_progress(size_t progress);
409};
410
411//-------------------------------------------------------------------------
412template <typename T>
414{
415 T *cb;
416 void *ud;
417 int ms;
418
420 void reset()
421 {
422 cb = nullptr;
423 ud = nullptr;
424 ms = -1;
425 }
426
427 bool set(int _ms, T *_cb, void *_ud)
428 {
429 reset();
430 if ( _cb != nullptr && _ms > -1 )
431 {
432 cb = _cb;
433 ud = _ud;
434 ms = _ms;
435 }
436 return cb != nullptr;
437 }
438
439 T *get(int *out_ms=nullptr, void **out_ud=nullptr) const
440 {
441 if ( out_ms != nullptr )
442 *out_ms = ms;
443 if ( out_ud != nullptr )
444 *out_ud = ud;
445 return cb;
446 }
447};
448
451
452//-------------------------------------------------------------------------
465
466//-------------------------------------------------------------------------
468{
469 size_t cb = sizeof(*this);
473
475 irs_server_opts_t(const qstring &_host, int _port)
476 : bind(_host, _port) {}
477};
479
480bool irs_init_client(idarpc_stream_t *irs, const irs_client_opts_t &options);
481bool irs_init_server(idarpc_stream_t *irs, const irs_server_opts_t &options);
482bool irs_accept(idarpc_stream_t *irs, idarpc_stream_t *listener);
483bool irs_handshake(idarpc_stream_t *irs, int timeout_ms = -1);
484int irs_ready(idarpc_stream_t *irs, int timeout_ms = -1);
485ssize_t irs_recv(idarpc_stream_t *irs, void *buf, size_t n);
486ssize_t irs_send(idarpc_stream_t *irs, const void *buf, size_t n);
487void irs_term(idarpc_stream_t **pirs, int shutdown_flags = -1);
488int irs_get_error(idarpc_stream_t *irs);
489const char *irs_strerror(idarpc_stream_t *irs);
490bool irs_peername(idarpc_stream_t *irs, qstring *out, bool lookupname = true);
491bool irs_sockname(idarpc_stream_t *irs, qstring *out, bool lookupname = true);
492bool irs_sockport(idarpc_stream_t *irs, int *out);
493// convenience functions
494ssize_t irs_send_data(idarpc_stream_t *irs, const void *buf, size_t n);
496 idarpc_stream_t *irs,
497 void *buf,
498 size_t n,
499 int timeout_ms = -1);
500bool irs_recv_str(idarpc_stream_t *irs, qstring *out, int timeout_ms = -1);
501bool irs_send_str(idarpc_stream_t *irs, const qstring &str);
502
503//-------------------------------------------------------------------------
505constexpr uint32 TIMESTAMP_UTC = 0x01;
506constexpr uint32 TIMESTAMP_ISO8601 = 0x02;
507constexpr uint32 TIMESTAMP_WITH_MS = 0x04;
508
509//-------------------------------------------------------------------------
510idaman THREAD_SAFE bool ida_export parse_timestamp(
511 utc_timestamp_t *out,
512 const char *in,
513 uint32 flags = 0);
514
515//-------------------------------------------------------------------------
516constexpr size_t TIMESTAMP_BUFSZ = 25;
517idaman THREAD_SAFE bool ida_export format_timestamp(
518 char *out,
519 size_t out_size,
521 uint32 flags = 0);
522
523//-------------------------------------------------------------------------
524typedef uint64 lofi_timestamp_t; // low-fidelity timestamp. Only encodes up to 1/10th seconds
525//-------------------------------------------------------------------------
527{
528 const uint64 s = get_secs(ts);
529 const uint64 us = get_usecs(ts);
530 return s * 10 + us / (100 * 1000);
531}
532
533//-------------------------------------------------------------------------
535{
536 return make_qtime64(uint32(lts / 10), (lts % 10) * (100 * 1000));
537}
538
539//-------------------------------------------------------------------------
540// base_dispatcher_t + network_client_handler_t
541//-------------------------------------------------------------------------
543{
544 FILE *channels[16];
545 idarpc_stream_t *irs;
550
553 int find_free_channel() const;
554
555 network_client_handler_t(idarpc_stream_t *_irs, bool _verbose);
557
558 virtual bool handle() = 0; // true - delete this
559 virtual void shutdown_gracefully(int signum) = 0;
560
561 void term_irs();
562
563 AS_PRINTF(2, 3) int lprintf(const char *format, ...) const
564 {
565 va_list va;
567 int code = vlprintf(format, va);
569 return code;
570 }
571 AS_PRINTF(2, 0) int vlprintf(const char *format, va_list va) const;
572
573private:
574 DECLARE_UNCOPYABLE(network_client_handler_t);
575};
576
577//-------------------------------------------------------------------------
579{
580 typedef std::map<network_client_handler_t *, qthread_t> storage_t;
582
584 virtual void lock() {}
585 virtual void unlock() {}
586 virtual bool is_multi_threaded() const { return false; }
587};
588
589//-------------------------------------------------------------------------
591{
592 qmutex_t mutex;
593
594 mt_client_handlers_list_t() { mutex = qmutex_create(); QASSERT(1540, mutex != nullptr); }
596 virtual void lock() override { qmutex_lock(mutex); }
597 virtual void unlock() override { qmutex_unlock(mutex); }
598 virtual bool is_multi_threaded() const override { return true; }
599};
600
601#define SERVER_CLIOPT_DEFAULTS 0x0
602#define SERVER_CLIOPT_NOTLS 0x1 // note: will always be enabled for TESTABLE_BUILD
603#define SERVER_CLIOPT_RECORDING 0x2 // note: will always be enabled for TESTABLE_BUILD
604
605//-------------------------------------------------------------------------
607{
611 idarpc_stream_t *irs = nullptr;
615 bool use_tls = true;
616 bool verbose = false;
617
618 base_dispatcher_t(bool multi_threaded);
620 void dispatch();
621
622 virtual void collect_cliopts(cliopts_t *out, uint32 features);
623
624 //
626
627 //
628 virtual network_client_handler_t *new_client_handler(idarpc_stream_t *_irs) = 0;
630
631 virtual void shutdown_gracefully(int signum);
632
633private:
634 void handle_session(network_client_handler_t *handler);
635 void add_to_clients_list(network_client_handler_t *handler, qthread_t t);
636 DECLARE_UNCOPYABLE(base_dispatcher_t);
637};
638
639// [-
640//-------------------------------------------------------------------------
641// server_dispatcher_t
642//-------------------------------------------------------------------------
650
651struct product_entry_t;
653struct license_info_t;
654
655namespace licsrv_rpc
656{
657 struct license_t;
658}
659
660//-------------------------------------------------------------------------
662 qstring *out_matched_macaddr,
663 const licsrv_rpc::license_t &lic);
664
665//-------------------------------------------------------------------------
666void default_print_license_info(const licsrv_rpc::license_t &lic);
667
668//-------------------------------------------------------------------------
670{
671 virtual void check_license_type(
672 const licsrv_rpc::license_t & /*lic*/)
673 {
674 }
675
677 qstring *out_matched_macaddr,
678 const licsrv_rpc::license_t &lic)
679 {
680 default_check_license_activation(out_matched_macaddr, lic);
681 }
682
683 virtual void fill_server_info(
684 const product_entry_t & /*p*/,
685 const qstring & /*name*/,
686 const qstring & /*email*/,
687 const qstring & /*macaddr*/)
688 {
689 }
690
691 virtual int on_parse_error(int code) { return code; }
692
693 virtual void print_license_info(const licsrv_rpc::license_t &lic) const
694 {
696 }
697};
698
699//-------------------------------------------------------------------------
700struct licmgr_logger_t;
702{
704
706 qstring badreqdir; // directory holding a dump of requests that caused an INTERR or unexpected exceptions
707 FILE *log_file = nullptr;
708 licmgr_logger_t *licmgr_logger = nullptr;
710 bool may_upgrade_schema = false;
712#ifdef TESTABLE_BUILD
714#endif
715
717 bool _multi_threaded,
718 int default_port,
719 const char *default_license_file_name);
722 const licsrv_rpc::license_t *read_license_file(license_file_visitor_t &lv) const;
724
725 virtual void collect_cliopts(cliopts_t *out, uint32 features) override;
729
730 void log_request(const bytevec_t &request, int interr_code=-1) const;
731};
732
733NORETURN AS_PRINTF(2, 3) void lerror(int code, const char *format, ...);
734// ]-
735
736//-------------------------------------------------------------------------
737// packing/unpacking utils
738//-------------------------------------------------------------------------
741
742//-------------------------------------------------------------------------
743// rpc_engine_t
744//-------------------------------------------------------------------------
745#define VERBOSE_ENABLED
746#ifdef VERBOSE_ENABLED
747#define verb(x) do { if ( verbose ) msg x; } while(0)
748#define verb_eng(engine, x) do { if ( (engine)->verbose ) msg x; } while(0)
749#else
750#define verb(x) //msg x
751#define verb_eng(engine, x)
752#endif
753#define verbev(x) //msg x
754
755//-------------------------------------------------------------------------
757{
759
760 rpc_packet_data_t(uchar _code) : code(_code) {}
762 virtual void serialize(bytevec_t *out, int version) const = 0;
763 virtual bool deserialize(const uchar **ptr, size_t len, int version) = 0;
764};
765
766//-------------------------------------------------------------------------
767typedef int ioctl_handler_t(
768 class rpc_engine_t *rpc,
769 int fn,
770 const void *buf,
771 size_t size,
772 void **poutbuf,
773 ssize_t *poutsize);
774
775//-------------------------------------------------------------------------
776typedef rpc_packet_data_t *rpc_packet_instantiator_t(const uchar *ptr, size_t len, int version);
777
778//-------------------------------------------------------------------------
787
788//-------------------------------------------------------------------------
790{
792 int recv_timeout; // miliseconds
793};
794
795//---------------------------------------------------------------------------
797{
798public:
799 bool network_error = false;
801
802 // pointer to the ioctl request handler, in case you
803 // need to handle ioctl requests from the server.
805
806 // This array specifies non-standard timeouts for some RPC calls
808 size_t n_pkt_timeouts = 0;
809
811 bool is_client = false;
812 bool logged_in = false;
813
814protected:
815 void register_packet_type_descs(const rpc_packet_type_desc_t *ptypes, size_t cnt);
817 const rpc_packet_type_desc_t *find_packet_type_desc(const char *name) const;
818 int get_timeout_for_request(uchar pkt_code) const;
819
820public:
822 bool _is_client,
823 int _recv_timeout,
824 const rpc_pkt_timeout_t *_pkt_timeouts = nullptr,
825 size_t _n_pkt_timeouts = 0);
826 virtual ~rpc_engine_t() {}
827
828 int handle_ioctl_packet(bytevec_t &pkt, const uchar *ptr, const uchar *end);
829
830 // low-level: deal with bytes, and don't handle "conversations".
833
835
836 virtual idarpc_stream_t *get_irs() const = 0;
837 AS_PRINTF(3, 0) virtual ssize_t send_notif(int code, const char *format, va_list va);
838
839 virtual bool get_broken_connection(void) { return false; }
840 virtual void set_broken_connection(void) {}
841
842 int send_ioctl(int fn, const void *buf, size_t size, void **poutbuf, ssize_t *poutsize);
844 void set_pkt_timeouts(const rpc_pkt_timeout_t *_pkt_timeouts, size_t _n_pkt_timeouts)
845 {
846 pkt_timeouts = _pkt_timeouts;
847 n_pkt_timeouts = _n_pkt_timeouts;
848 }
849
851
852private:
854
855 int recv_data(void *out, size_t len, int timeout_ms);
856
857 AS_PRINTF(3,0) static ssize_t dvnotif(int code, rpc_engine_t *rpc, const char *format, va_list va);
858};
859
860//-------------------------------------------------------------------------
862{
863#ifdef TESTABLE_BUILD
864 struct
865 {
866 FILE *fp = nullptr;
868 mutable uint64 packet_nr = 0;
869 } recording;
870#endif
871 idarpc_stream_t *rpc_irs;
872 bool our_irs; // should we terminate rpc_irs in the destructor?
873 int protocol_version;
874
875protected:
876 void record(
877 const rpc_packet_data_t &data,
878 const uchar *bytes,
879 size_t len,
880 bool as_input) const;
881 void record_input(const rpc_packet_data_t &data, const rpc_packet_t *rp) const;
882 void record_output(const rpc_packet_data_t &data, const bytevec_t &bytes) const;
883 // must be implemented if an instance is meant to be able to record.
884 virtual bool get_conversation_name(qstring * /*out*/) const newapi { INTERR(1581); }
885 // formatter is mandatory
886 virtual void format_packet_data(
887 qstring *out,
888 const struct rpc_packet_data_t &data,
889 const char *line_prefix=nullptr) const newapi;
890 virtual void get_packet_name(
891 qstring *out,
892 const struct rpc_packet_data_t &data) const newapi;
893 bool reinit_irs(qstring *errbuf, bool use_tls, const char *server_host, int port);
894
895public:
897 const rpc_packet_type_desc_t *descs,
898 size_t cnt,
899 idarpc_stream_t *_irs,
900 bool _our_irs,
901 bool _is_client,
902 int _recv_timeout,
903 const rpc_pkt_timeout_t *_pkt_timeouts = nullptr,
904 size_t _n_pkt_timeouts = 0,
905 int _protocol_version = 0)
906 : rpc_engine_t(_is_client, _recv_timeout, _pkt_timeouts, _n_pkt_timeouts),
907 rpc_irs(_irs), our_irs(_our_irs), protocol_version(_protocol_version)
908 {
909 register_packet_type_descs(descs, cnt);
910 }
912
913 bool start_recording(const qstring &convs_dir);
915 bool is_recording() const;
916
918 const rpc_packet_data_t &request) newapi;
921 virtual idarpc_stream_t *get_irs() const override { return rpc_irs; }
922 bool is_our_irs() const { return our_irs; }
924 int get_protocol_version() const { return protocol_version; }
925 void set_protocol_version(int _protocol_version)
926 {
927#ifdef TESTABLE_BUILD
928 QASSERT(2757, _protocol_version <= protocol_version);
929#endif
930 protocol_version = _protocol_version;
931 }
932};
933
934//-------------------------------------------------------------------------
935// This class can automatically reconnect if the connections drops.
937{
938 typedef recording_rpc_engine_t *rpc_engine_creator_t(idarpc_stream_t *_irs);
939
940protected:
941 rpc_engine_creator_t *create_rpc_engine;
943private:
944 qstring wait_dialog_contents;
945 const char *const server_name;
946 bool started_receiving_response = false;
947 bool was_user_cancelled = false;
948
949 virtual void init(idarpc_stream_t *_irs);
950
951public:
953 const char *_server_name,
954 rpc_engine_creator_t *engine_creator,
955 idarpc_stream_t *_irs)
956 : create_rpc_engine(engine_creator),
957 server_name(_server_name)
958 {
959 generic_client_t::init(_irs);
960 }
963protected:
964 virtual bool try_reconnect(qstring *errbuf) = 0;
965 virtual rpc_packet_data_t *create_failure_packet(const char *errmsg) = 0;
966 virtual bool is_handshake_packet(const rpc_packet_data_t &) { return false; }
967};
968
969//-------------------------------------------------------------------------
970AS_PRINTF(3, 0) ssize_t dvnotif_rpc(
971 int code,
973 const char *format,
974 va_list va);
975
976//---------------------------------------------------------------------------
977AS_PRINTF(1, 0) int vlprintf(const char *format, va_list va);
978AS_PRINTF(1, 2) int lprintf(const char *format, ...);
979ssize_t lwrite(const void *data, size_t size);
980void set_lprintf_output(FILE *out);
981
982//---------------------------------------------------------------------------
984 qstrvec_t *out,
985 const uchar *buf,
986 size_t size,
987 bool for_comments,
988 size_t nhex_per_line=16);
989
990#define REPEAT_THRESHOLD 100 // that many or more equal bytes will
991 // be printed using the REPEAT_BYTES_MARKER
992#define REPEAT_BYTES_MARKER '#'
993
994//-------------------------------------------------------------------------
995struct login_credentials_t;
996#define LCRED_HELPER_DEFINITIONS(decl) \
997decl bool ida_export lcred_process_switch(login_credentials_t *lc, const char *args);
998LCRED_HELPER_DEFINITIONS(idaman)
999
1000//-------------------------------------------------------------------------
1001struct login_credentials_t : public endpoint_credentials_t
1002{
1003 LCRED_HELPER_DEFINITIONS(friend)
1005#define LCS_NO_TLS 0x1
1006#define LCS_SEEN_PROXY_OPTION 0x2
1007#define LCS_RESERVED_BITS 8
1008 uint32 state = 0;
1009
1010 login_credentials_t(const qstring &_host, ushort _port)
1011 : endpoint_credentials_t(_host, _port) {}
1012 virtual ~login_credentials_t() {}
1013 virtual bool process_switch(const char *args) newapi
1014 {
1015 return lcred_process_switch(this, args);
1016 }
1017 virtual void clear() newapi { this->endpoint_credentials_t::clear(); proxy.clear(); state = 0; }
1018
1019 bool load_password(qstring *out, qstring *errbuf) const
1020 {
1021 if ( !password_override.empty() )
1022 {
1023 *out = password_override;
1024 return true;
1025 }
1026 return do_load_password(out, errbuf);
1027 }
1028
1029 bool load_proxy_password(qstring *out, qstring *errbuf) const
1030 {
1031 if ( !proxy.password_override.empty() )
1032 {
1033 *out = proxy.password_override;
1034 return true;
1035 }
1036 return do_load_proxy_password(out, errbuf);
1037 }
1038
1039 bool use_tls() const { return (state & LCS_NO_TLS) == 0; }
1040 void set_use_tls(bool use_tls) { setflag(state, LCS_NO_TLS, !use_tls); }
1041 bool has_seen_proxy_option() const { return (state & LCS_SEEN_PROXY_OPTION) != 0; }
1042 friend struct login_credentials_internal_t;
1043
1044protected:
1045 bool _process_switch(const char *args);
1046 bool load_pass_from_keychain(qstring * /*out*/, qstring * /*errbuf*/, const char * /*app_name*/) const;
1047 virtual bool do_load_password(qstring * /*out*/, qstring * /*errbuf*/) const newapi { return false; }
1048 virtual bool do_load_proxy_password(qstring * /*out*/, qstring * /*errbuf*/) const newapi { return false; }
1049 virtual bool write(qstring * /*errbuf*/) const newapi { return false; }
1050};
1051
1052//-------------------------------------------------------------------------
1053#define VAULT_APP_NAME "hexvault"
1054#define VAULT_PROXY_APP_NAME VAULT_APP_NAME "_proxy"
1055#define DEFAULT_VAULT_HOST "hexvault"
1056#define DEFAULT_VAULT_PORT 65433
1057
1058//-------------------------------------------------------------------------
1060{
1061 // during the call to `validate()`,
1062 // `login_credentials_t::password_override` will hold
1063 // the candidate new password to be used for validation.
1064 virtual bool validate(login_credentials_t &cred) = 0;
1065};
1066
1067//-------------------------------------------------------------------------
1069
1070//-------------------------------------------------------------------------
1072{
1073 AUR_CANCELLED = 0, // user rejected the prompt
1074 AUR_VALID, // the validator (if any) succeeded
1075 AUR_INVALID, // the validator (if any) failed
1076};
1077
1078//-------------------------------------------------------------------------
1079struct vault_credentials_t;
1080#define VCRED_HELPER_DEFINITIONS(decl) \
1081decl void ida_export vcred_init(vault_credentials_t *vc);\
1082decl bool ida_export vcred_process_switch(vault_credentials_t *vc, const char *arg);\
1083decl bool ida_export vcred_do_load_password(const vault_credentials_t *vc, qstring *out, qstring *errbuf);\
1084decl bool ida_export vcred_do_load_proxy_password(const vault_credentials_t *vc, qstring *out, qstring *errbuf);\
1085decl bool ida_export vcred_write(const vault_credentials_t *vc, qstring *errbuf);\
1086decl ask_user_result_t ida_export vcred_ask_user(vault_credentials_t *vc, credential_validator_t *validator, qstring *errbuf, uint32 auf_flags);\
1087decl bool ida_export vcred_reg_should_store_info();\
1088decl void ida_export vcred_reg_set_store_info(bool store_pass);\
1089decl bool ida_export vcred_reg_del_store_info();\
1090decl bool ida_export vcred_reg_should_auto_connect();\
1091decl void ida_export vcred_reg_set_auto_connect(bool auto_connect);\
1092decl bool ida_export vcred_reg_del_auto_connect();\
1093decl void ida_export vcred_reg_set_site(const vault_credentials_t *vc, const char *site);\
1094decl bool ida_export vcred_load_site(vault_credentials_t *vc);
1095VCRED_HELPER_DEFINITIONS(idaman)
1096
1097//-------------------------------------------------------------------------
1098struct vault_credentials_t : public login_credentials_t
1099{
1100 VCRED_HELPER_DEFINITIONS(friend)
1101 typedef login_credentials_t inherited;
1102 qstring sitename;
1103#define VCS_SEEN_SITE_OPTION (0x1 << LCS_RESERVED_BITS)
1104#define VCS_UPDATE_REG_INFO (0x2 << LCS_RESERVED_BITS)
1105#define VCS_USE_PROXY (0x4 << LCS_RESERVED_BITS)
1106
1107 vault_credentials_t() : login_credentials_t(DEFAULT_VAULT_HOST, DEFAULT_VAULT_PORT) {}
1108 virtual ~vault_credentials_t() {}
1109 void init() { vcred_init(this); }
1110 virtual bool process_switch(const char *arg) override { return vcred_process_switch(this, arg); }
1111 virtual void clear() override
1112 {
1113 this->login_credentials_t::clear();
1114 sitename.clear();
1115 }
1116 virtual bool do_load_password(qstring *out, qstring *errbuf) const override
1117 {
1118 return vcred_do_load_password(this, out, errbuf);
1119 }
1120
1121 virtual bool do_load_proxy_password(qstring *out, qstring *errbuf) const override
1122 {
1123 return vcred_do_load_proxy_password(this, out, errbuf);
1124 }
1125 virtual bool write(qstring *errbuf) const override
1126 {
1127 return vcred_write(this, errbuf);
1128 }
1129#define AUF_SILENT_UPDATE_FAILURE 0x1 // don't warn user if persisting the credentials failed
1130 ask_user_result_t ask_user(
1131 credential_validator_t *validator,
1132 qstring *errbuf,
1133 uint32 auf_flags=0)
1134 {
1135 return vcred_ask_user(this, validator, errbuf, auf_flags);
1136 }
1137
1138 bool update(qstring *errbuf) const; // set/del reg info depending on 'VCS_UPDATE_REG_INFO'
1139 bool del(qstring *errbuf) const;
1140 void reg_set_site(const char *site) const { vcred_reg_set_site(this, site); }
1141
1142 bool load_site() { return vcred_load_site(this); }
1143 void load_proxy_info();
1144
1145 bool has_seen_site_option() const { return (state & VCS_SEEN_SITE_OPTION) != 0; }
1146
1147 static bool reg_should_store_info() { return vcred_reg_should_store_info(); }
1148 static void reg_set_store_info(bool store_pass) { vcred_reg_set_store_info(store_pass); }
1149 static bool reg_del_store_info() { return vcred_reg_del_store_info(); }
1150 static bool reg_should_auto_connect() { return vcred_reg_should_auto_connect(); }
1151 static void reg_set_auto_connect(bool auto_connect) { vcred_reg_set_auto_connect(auto_connect); }
1152 static bool reg_del_auto_connect() { return vcred_reg_del_auto_connect(); }
1153
1154private:
1155 void _init();
1156 ask_user_result_t _ask_user(
1157 credential_validator_t *validator,
1158 qstring *errbuf,
1159 uint32 auf_flags);
1160 bool _write(qstring *errbuf) const;
1161 void _reg_set_site(const char *site) const;
1162 void get_reg_key(qstring *out) const;
1163};
1164
1165//-------------------------------------------------------------------------
1166#ifdef IDAFREE
1167# define PUBLIC_LUMINA_HOST "public-lumina.hex-rays.com"
1168# define PUBLIC_DEC_HOST "public-lumina.hex-rays.com"
1169# define PUBLIC_TLM_HOST "public-lumina.hex-rays.com"
1170#else
1171# define PUBLIC_LUMINA_HOST "lumina.hex-rays.com"
1172# define PUBLIC_DEC_HOST "lumina.hex-rays.com"
1173# define PUBLIC_TLM_HOST "tlm.hex-rays.com"
1174#endif
1175#define DEFAULT_LUMINA_PORT 443
1176#define PUBLIC_DEC_PORT 443
1177#define PUBLIC_TLM_PORT 443
1178
1179#define LUMINA_APP_NAME "lumina"
1180
1181//-------------------------------------------------------------------------
1182struct lumina_credentials_t : public login_credentials_t
1183{
1185
1187 : login_credentials_t("", 0)
1188 {}
1190
1191 void init(bool set_as_primary=true);
1192
1193 virtual bool do_load_password(qstring *out, qstring *errbuf) const override;
1194 virtual bool write(qstring *errbuf) const override;
1195};
1196
1197//-------------------------------------------------------------------------
1198struct dec_credentials_t : public login_credentials_t
1199{
1200 dec_credentials_t() : login_credentials_t(PUBLIC_DEC_HOST, PUBLIC_DEC_PORT) {}
1202};
1203
1204//-------------------------------------------------------------------------
1205struct tlm_credentials_t : public login_credentials_t
1206{
1207 tlm_credentials_t() : login_credentials_t(PUBLIC_TLM_HOST, PUBLIC_TLM_PORT) {}
1209
1210 void init();
1211};
1212
1213//-------------------------------------------------------------------------
1214#define NOSIG -1
1215void call_exit_handlers(int signum);
1218
1220{
1221 virtual void handle(int signum) = 0;
1222
1227};
1228
1229
1230struct kc_ctx_t;
1232
1233void ensure_one_server(const char *name);
1234
1235
1237
1238#define VPAF_NATURE_FILE 0x01
1239#define VPAF_NATURE_DIR 0x02
1240#define VPAF_NATURE_ABSENT 0x03
1241#define VPAF_NATURE_MASK 0x0F
1242#define VPAF_RESTRICTED 0x10 // must not be world-readable (not available on Windows)
1243
1245 const char *path_identity,
1246 const char *path,
1247 uint32 flags);
1248
1249#endif // NETWORK_HPP
void swap(_qstring< qchar > &r)
Swap contents of two qstrings. see qvector::swap()
Definition pro.h:3198
bool empty(void) const
Does the qstring have 0 non-null elements?
Definition pro.h:3244
void resize(size_t s, qchar c)
Resize to the given size.
Definition pro.h:3207
static constexpr size_t npos
Definition pro.h:3769
void split(qvector< _qstring< qchar > > *out, const qchar *sep, uint32 flags=0) const
Split a string on SEP, appending the parts to OUT.
_qstring & remove(size_t idx, size_t cnt)
Remove characters from the qstring.
Definition pro.h:3484
_qstring & append(qchar c)
Append c to the end of the qstring.
Definition pro.h:3569
const qchar * c_str(void) const
Convert the qstring to a char *.
Definition pro.h:3246
void clear(void)
Clear qstring and free memory.
Definition pro.h:3242
Vector of bytes (use for dynamic memory)
Definition pro.h:3850
virtual ~generic_client_t()
virtual rpc_packet_data_t * create_failure_packet(const char *errmsg)=0
generic_client_t(const char *_server_name, rpc_engine_creator_t *engine_creator, idarpc_stream_t *_irs)
Definition network.hpp:952
virtual bool try_reconnect(qstring *errbuf)=0
rpc_engine_creator_t * create_rpc_engine
Definition network.hpp:941
virtual bool is_handshake_packet(const rpc_packet_data_t &)
Definition network.hpp:966
recording_rpc_engine_t * rpc_engine
Definition network.hpp:942
friend struct generic_client_internal_t
Definition network.hpp:962
Reimplementation of vector class from STL.
Definition pro.h:2262
size_t size(void) const
Get the number of elements in the qvector.
Definition pro.h:2494
Definition network.hpp:862
virtual rpc_packet_data_t * request_and_response(const rpc_packet_data_t &request) new api
int get_protocol_version() const
Definition network.hpp:924
void record(const rpc_packet_data_t &data, const uchar *bytes, size_t len, bool as_input) const
virtual ~recording_rpc_engine_t()
void record_output(const rpc_packet_data_t &data, const bytevec_t &bytes) const
bool reinit_irs(qstring *errbuf, bool use_tls, const char *server_host, int port)
virtual idarpc_stream_t * get_irs() const override
Definition network.hpp:921
uint64 packet_nr
Definition network.hpp:868
void record_input(const rpc_packet_data_t &data, const rpc_packet_t *rp) const
qstring dumps_dir_path
Definition network.hpp:867
virtual rpc_packet_t * send_request_and_receive_reply(uchar pkt_code, bytevec_t &pkt) override
void set_protocol_version(int _protocol_version)
Definition network.hpp:925
recording_rpc_engine_t(const rpc_packet_type_desc_t *descs, size_t cnt, idarpc_stream_t *_irs, bool _our_irs, bool _is_client, int _recv_timeout, const rpc_pkt_timeout_t *_pkt_timeouts=nullptr, size_t _n_pkt_timeouts=0, int _protocol_version=0)
Definition network.hpp:896
virtual bool get_conversation_name(qstring *) const newapi
Definition network.hpp:884
rpc_packet_data_t * packet_data_from_raw(const rpc_packet_t *rp)
bool is_our_irs() const
Definition network.hpp:922
virtual void get_packet_name(qstring *out, const struct rpc_packet_data_t &data) const newapi
bool start_recording(const qstring &convs_dir)
FILE * fp
Definition network.hpp:866
virtual void format_packet_data(qstring *out, const struct rpc_packet_data_t &data, const char *line_prefix=nullptr) const newapi
bool is_recording() const
Definition network.hpp:797
void register_packet_type_descs(const rpc_packet_type_desc_t *ptypes, size_t cnt)
bool logged_in
Definition network.hpp:812
rpc_packet_t * recv_packet(uchar pkt_code)
int handle_ioctl_packet(bytevec_t &pkt, const uchar *ptr, const uchar *end)
virtual rpc_packet_t * send_request_and_receive_reply(uchar pkt_code, bytevec_t &pkt)=0
virtual bool get_broken_connection(void)
Definition network.hpp:839
void set_pkt_timeouts(const rpc_pkt_timeout_t *_pkt_timeouts, size_t _n_pkt_timeouts)
Definition network.hpp:844
int get_timeout_for_request(uchar pkt_code) const
int recv_timeout
Definition network.hpp:810
rpc_engine_t(bool _is_client, int _recv_timeout, const rpc_pkt_timeout_t *_pkt_timeouts=nullptr, size_t _n_pkt_timeouts=0)
qstring last_errstr
Definition network.hpp:800
const char va_list va
Definition network.hpp:837
const rpc_pkt_timeout_t * pkt_timeouts
Definition network.hpp:807
AS_PRINTF(3, 0) virtual ssize_t send_notif(int code
virtual idarpc_stream_t * get_irs() const =0
bool is_client
Definition network.hpp:811
void set_ioctl_handler(ioctl_handler_t *h)
Definition network.hpp:843
DEFINE_ALL_NOTIFICATION_FUNCTIONS(this)
virtual void set_broken_connection(void)
Definition network.hpp:840
size_t n_pkt_timeouts
Definition network.hpp:808
const char * format
Definition network.hpp:837
int send_ioctl(int fn, const void *buf, size_t size, void **poutbuf, ssize_t *poutsize)
ioctl_handler_t * ioctl_handler
Definition network.hpp:804
bool network_error
Definition network.hpp:799
const rpc_packet_type_desc_t * find_packet_type_desc(const char *name) const
virtual ~rpc_engine_t()
Definition network.hpp:826
int send_data(bytevec_t &data)
const rpc_packet_type_desc_t * find_packet_type_desc(int code) const
idaman THREAD_SAFE va_list va
See qsscanf()
Definition err.h:21
idaman THREAD_SAFE const char * format
Definition fpro.h:78
idaman THREAD_SAFE AS_PRINTF(1, 0) void ida_export vqperror(const char *format
Print error message to stderr (analog of perror)
idaman const char * end
Definition pro.h:1004
int code
Definition fpro.h:88
idaman size_t n
Definition pro.h:1000
cexpr_t * e
Definition hexrays.hpp:7705
carglist_t * args
Definition hexrays.hpp:7720
idaman size_t len
Definition kernwin.hpp:1389
asize_t size
Definition kernwin.hpp:6701
void(idaapi *range_marker)(ea_t ea
Pointer to range marker function (for idaviews and hexviews) This pointer is initialized by setup_ran...
unsigned __int64 uint64
Definition llong.hpp:13
qvector< qstring > qstrvec_t
Definition lumina.hpp:831
Definition network.hpp:656
void irs_set_progress_cb(idarpc_stream_t *irs, int ms, irs_progress_cb_t cb, void *ud=nullptr)
const char * format
Definition network.hpp:195
CASSERT(sizeof(rpc_packet_t)==5)
DECLARE_TYPE_AS_MOVABLE(host_port_t)
constexpr uint32 TIMESTAMP_ISO8601
Definition network.hpp:506
void ensure_one_server(const char *name)
THREAD_SAFE qtime64_t from_lofi_timestamp(lofi_timestamp_t lts)
Definition network.hpp:534
idaman THREAD_SAFE bool ida_export parse_timestamp(utc_timestamp_t *out, const char *in, uint32 flags=0)
idaman THREAD_SAFE bool ida_export format_timestamp(char *out, size_t out_size, utc_timestamp_t ts, uint32 flags=0)
qvector< rpc_packet_type_desc_t > rpc_packet_type_desc_vec_t
Definition network.hpp:786
bool irs_sockname(idarpc_stream_t *irs, qstring *out, bool lookupname=true)
const char * irs_strerror(idarpc_stream_t *irs)
void set_lprintf_output(FILE *out)
void default_check_license_activation(qstring *out_matched_macaddr, const licsrv_rpc::license_t &lic)
void format_hex_dump(qstrvec_t *out, const uchar *buf, size_t size, bool for_comments, size_t nhex_per_line=16)
ask_user_result_t
Definition network.hpp:1072
@ AUR_VALID
Definition network.hpp:1074
@ AUR_CANCELLED
Definition network.hpp:1073
@ AUR_INVALID
Definition network.hpp:1075
qvector< product_entry_t > prodvec_t
Definition network.hpp:652
int ioctl_handler_t(class rpc_engine_t *rpc, int fn, const void *buf, size_t size, void **poutbuf, ssize_t *poutsize)
Definition network.hpp:767
bool irs_cancel_connect_cb_t(void *)
Definition network.hpp:393
int irs_ready(idarpc_stream_t *irs, int timeout_ms=-1)
void default_print_license_info(const licsrv_rpc::license_t &lic)
ssize_t irs_send_data(idarpc_stream_t *irs, const void *buf, size_t n)
progress_loop_ctrl_t irs_progress_cb_t(bool receiving, size_t processed, size_t total, void *)
Definition network.hpp:401
rpc_engine_t * rpc
Definition network.hpp:972
bool irs_sockport(idarpc_stream_t *irs, int *out)
progress_loop_ctrl_t
Definition network.hpp:396
@ plc_proceed
Definition network.hpp:397
@ plc_cancel
Definition network.hpp:399
@ plc_skip_iter
Definition network.hpp:398
uint64 lofi_timestamp_t
Definition network.hpp:524
void finalize_packet(bytevec_t &pkt)
bool irs_peername(idarpc_stream_t *irs, qstring *out, bool lookupname=true)
idarpc_stream_t * irs_new(bool use_tls=false)
irs_cb_info_t< irs_cancel_connect_cb_t > cancel_connect_cb_info_t
Definition network.hpp:450
constexpr size_t TIMESTAMP_BUFSZ
Definition network.hpp:516
ssize_t irs_recv(idarpc_stream_t *irs, void *buf, size_t n)
irs_cb_info_t< irs_progress_cb_t > progress_cb_info_t
Definition network.hpp:449
bool irs_init_server(idarpc_stream_t *irs, const irs_server_opts_t &options)
THREAD_SAFE lofi_timestamp_t to_lofi_timestamp(qtime64_t ts)
Definition network.hpp:526
void validate_path_argument(const char *path_identity, const char *path, uint32 flags)
constexpr uint32 TIMESTAMP_WITH_MS
Definition network.hpp:507
bool irs_init_client(idarpc_stream_t *irs, const irs_client_opts_t &options)
const char va_list va
Definition network.hpp:196
AS_PRINTF(2, 0) ssize_t dvnotif_client(int code
int irs_get_error(idarpc_stream_t *irs)
rpc_packet_data_t * rpc_packet_instantiator_t(const uchar *ptr, size_t len, int version)
Definition network.hpp:776
bool irs_recv_str(idarpc_stream_t *irs, qstring *out, int timeout_ms=-1)
bool license_server_enabled()
qtime64_t utc_timestamp_t
Definition network.hpp:504
bool irs_send_str(idarpc_stream_t *irs, const qstring &str)
void irs_term(idarpc_stream_t **pirs, int shutdown_flags=-1)
ssize_t lwrite(const void *data, size_t size)
ssize_t irs_send(idarpc_stream_t *irs, const void *buf, size_t n)
void call_exit_handlers()
kc_ctx_t * get_keychain_context()
bool irs_accept(idarpc_stream_t *irs, idarpc_stream_t *listener)
base_packet_id_t
Definition network.hpp:84
@ RPC_UNK
Definition network.hpp:86
@ RPC_MEM
Definition network.hpp:87
@ RPC_OK
Definition network.hpp:85
@ base_packet_id_last
Definition network.hpp:88
rpc_notification_type_t
Definition network.hpp:168
@ rnt_warning
Definition network.hpp:171
@ rnt_msg
Definition network.hpp:170
@ rnt_unknown
Definition network.hpp:169
@ rnt_error
Definition network.hpp:172
NORETURN const char bytevec_t prepare_rpc_packet(uchar code)
constexpr uint32 TIMESTAMP_UTC
Definition network.hpp:505
void install_signal_and_exit_handlers()
ssize_t irs_recv_data(idarpc_stream_t *irs, void *buf, size_t n, int timeout_ms=-1)
bool irs_handshake(idarpc_stream_t *irs, int timeout_ms=-1)
This is the first header included in the IDA project.
idaman size_t const char time_t t
Definition pro.h:606
idaman THREAD_SAFE qtime64_t ida_export qtime64(void)
Get the current time with microsecond resolution (in fact the resolution is worse on windows)
unsigned int uint32
unsigned 32 bit value
Definition pro.h:352
uint64 qtime64_t
64-bit time value expressed as seconds and microseconds since the Epoch
Definition pro.h:503
unsigned char uchar
unsigned 8 bit value
Definition pro.h:341
INLINE THREAD_SAFE qtime64_t make_qtime64(uint32 secs, DEFARG(int32 usecs, 0))
Get a qtime64_t instance from a seconds value and microseconds value.
Definition pro.h:526
THREAD_SAFE void qswap(T &a, T &b)
Swap 2 objects of the same type using memory copies.
Definition pro.h:1728
INLINE THREAD_SAFE uint32 get_secs(qtime64_t t)
Get the 'seconds since the epoch' part of a qtime64_t.
Definition pro.h:508
idaman THREAD_SAFE bool ida_export qmutex_unlock(qmutex_t m)
Unlock a mutex.
idaman THREAD_SAFE bool ida_export qmutex_free(qmutex_t m)
Free a mutex.
idaman THREAD_SAFE bool ida_export qmutex_lock(qmutex_t m)
Lock a mutex.
idaman THREAD_SAFE qmutex_t ida_export qmutex_create(void)
Create a new mutex.
ptrdiff_t ssize_t
Signed size_t - used to check for size overflows when the counter becomes negative.
Definition pro.h:385
unsigned short ushort
unsigned 16 bit value
Definition pro.h:342
INLINE THREAD_SAFE uint32 get_usecs(qtime64_t t)
Get the microseconds part of a qtime64_t.
Definition pro.h:516
void idaapi setflag(T &where, U bit, bool cnd)
Set a 'bit' in 'where' if 'value' is not zero.
Definition pro.h:1530
_qstring< char > qstring
regular string
Definition pro.h:3771
unsigned int
Definition pronet.h:99
utc_timestamp_t start_time
Definition network.hpp:613
qstring privkey
Definition network.hpp:610
void delete_client_handler(network_client_handler_t *inst)
virtual void collect_cliopts(cliopts_t *out, uint32 features)
virtual void shutdown_gracefully(int signum)
virtual ~base_dispatcher_t()
idarpc_stream_t * irs
Definition network.hpp:611
client_handlers_list_t * clients_list
Definition network.hpp:612
qstring certchain
Definition network.hpp:609
bool verbose
Definition network.hpp:616
ushort port_number
Definition network.hpp:614
void install_signal_handlers()
bool use_tls
Definition network.hpp:615
virtual network_client_handler_t * new_client_handler(idarpc_stream_t *_irs)=0
qstring ipv4_address
Definition network.hpp:608
base_dispatcher_t(bool multi_threaded)
Definition network.hpp:579
virtual void lock()
Definition network.hpp:584
std::map< network_client_handler_t *, qthread_t > storage_t
Definition network.hpp:580
storage_t storage
Definition network.hpp:581
virtual void unlock()
Definition network.hpp:585
virtual ~client_handlers_list_t()
Definition network.hpp:583
virtual bool is_multi_threaded() const
Definition network.hpp:586
Definition network.hpp:1060
virtual bool validate(login_credentials_t &cred)=0
dec_credentials_t()
Definition network.hpp:1200
virtual ~dec_credentials_t()
Definition network.hpp:1201
Definition network.hpp:260
void build_connstr(qstring *out, uint32 flags=0) const
Definition network.hpp:362
void clear()
Definition network.hpp:272
endpoint_credentials_t(const qstring &_host, ushort _port)
Definition network.hpp:268
qstring password_override
Definition network.hpp:265
qstring username
Definition network.hpp:261
bool parse_connstr(const qstring &s, uint32 flags=0)
Definition network.hpp:355
static bool parse_connstr(endpoint_credentials_t *out, const qstring &s, uint32 flags=0)
Definition network.hpp:285
qstring build_connstr(uint32 flags=0) const
Definition network.hpp:383
endpoint_credentials_t()
Definition network.hpp:267
exit_handler_t & operator=(const exit_handler_t &r)=delete
virtual ~exit_handler_t()
exit_handler_t(const exit_handler_t &)=delete
virtual void handle(int signum)=0
Definition network.hpp:218
void clear()
Definition network.hpp:225
bool operator==(const host_port_t &r) const
Definition network.hpp:228
qstring connstr(int default_port=0) const
Definition network.hpp:239
host_port_t()
Definition network.hpp:222
qstring host
Definition network.hpp:219
host_port_t(const qstring &_host, ushort _port)
Definition network.hpp:223
ushort port
Definition network.hpp:220
bool is_valid() const
Definition network.hpp:226
void swap(host_port_t &r)
Definition network.hpp:233
idarpc_stream_t * irs
Definition network.hpp:405
irs_cancellable_op_t(idarpc_stream_t *_irs, bool receiving, size_t goal=0)
void inc_progress(size_t progress)
Definition network.hpp:414
T * get(int *out_ms=nullptr, void **out_ud=nullptr) const
Definition network.hpp:439
void reset()
Definition network.hpp:420
int ms
Definition network.hpp:417
bool set(int _ms, T *_cb, void *_ud)
Definition network.hpp:427
irs_cb_info_t()
Definition network.hpp:419
irs_progress_cb_t * cb
Definition network.hpp:415
void * ud
Definition network.hpp:416
Definition network.hpp:454
cancel_connect_cb_info_t cancel_connect_cb_info
Definition network.hpp:458
irs_client_opts_t()
Definition network.hpp:460
endpoint_credentials_t server
Definition network.hpp:456
size_t cb
Definition network.hpp:455
endpoint_credentials_t proxy
Definition network.hpp:457
irs_client_opts_t(const qstring &_host, int _port)
Definition network.hpp:461
Definition network.hpp:468
qstring privkey_path
Definition network.hpp:472
irs_server_opts_t()
Definition network.hpp:474
qstring certchain_path
Definition network.hpp:471
irs_server_opts_t(const qstring &_host, int _port)
Definition network.hpp:475
size_t cb
Definition network.hpp:469
host_port_t bind
Definition network.hpp:470
Definition network.hpp:670
virtual void check_license_type(const licsrv_rpc::license_t &)
Definition network.hpp:671
virtual void check_license_activation(qstring *out_matched_macaddr, const licsrv_rpc::license_t &lic)
Definition network.hpp:676
virtual void print_license_info(const licsrv_rpc::license_t &lic) const
Definition network.hpp:693
virtual void fill_server_info(const product_entry_t &, const qstring &, const qstring &, const qstring &)
Definition network.hpp:683
virtual int on_parse_error(int code)
Definition network.hpp:691
void init(bool set_as_primary=true)
bool is_primary
Definition network.hpp:1184
virtual bool write(qstring *errbuf) const override
virtual ~lumina_credentials_t()
Definition network.hpp:1189
virtual bool do_load_password(qstring *out, qstring *errbuf) const override
lumina_credentials_t()
Definition network.hpp:1186
virtual void unlock() override
Definition network.hpp:597
virtual bool is_multi_threaded() const override
Definition network.hpp:598
mt_client_handlers_list_t()
Definition network.hpp:594
qmutex_t mutex
Definition network.hpp:592
virtual void lock() override
Definition network.hpp:596
virtual ~mt_client_handlers_list_t()
Definition network.hpp:595
Definition network.hpp:543
virtual void shutdown_gracefully(int signum)=0
virtual bool handle()=0
virtual ~network_client_handler_t()
AS_PRINTF(2, 0) int vlprintf(const char *format
qstring peer_name
Definition network.hpp:546
AS_PRINTF(2, 3) int lprintf(const char *format
utc_timestamp_t session_start
Definition network.hpp:548
const
Definition network.hpp:564
idarpc_stream_t * irs
Definition network.hpp:545
network_client_handler_t(idarpc_stream_t *_irs, bool _verbose)
FILE * channels[16]
Definition network.hpp:544
bool verbose
Definition network.hpp:549
int code
Definition network.hpp:567
int find_free_channel() const
uint32 session_id
Definition network.hpp:547
Definition network.hpp:757
virtual bool deserialize(const uchar **ptr, size_t len, int version)=0
virtual void serialize(bytevec_t *out, int version) const =0
rpc_packet_data_t(uchar _code)
Definition network.hpp:760
uchar code
Definition network.hpp:758
virtual ~rpc_packet_data_t()
Definition network.hpp:761
Definition network.hpp:160
uchar code
Definition network.hpp:162
uint32 length
Definition network.hpp:161
Definition network.hpp:780
rpc_packet_instantiator_t * instantiate
Definition network.hpp:783
uchar code
Definition network.hpp:781
const char * name
Definition network.hpp:782
Definition network.hpp:790
int recv_timeout
Definition network.hpp:792
uchar pkt_code
Definition network.hpp:791
Definition network.hpp:644
qstring log_file_path
Definition network.hpp:646
qstring connection_string
Definition network.hpp:645
qstring config_file_path
Definition network.hpp:648
qstring license_file_path
Definition network.hpp:647
const licsrv_rpc::license_t * read_license_file(license_file_visitor_t &lv) const
bool may_upgrade_schema
Definition network.hpp:710
void check_license_file(license_file_visitor_t &lv) const
FILE * log_file
Definition network.hpp:707
bool check_license_activation
Definition network.hpp:713
void log_request(const bytevec_t &request, int interr_code=-1) const
bool should_recreate_schema
Definition network.hpp:709
qstring badreqdir
Definition network.hpp:706
void get_license_file_contents(bytevec_t *data) const
virtual void collect_cliopts(cliopts_t *out, uint32 features) override
void maybe_start_recording(recording_rpc_engine_t *e)
server_dispatcher_t(bool _multi_threaded, int default_port, const char *default_license_file_name)
base_dispatcher_t inherited
Definition network.hpp:703
virtual ~server_dispatcher_t()
qstring convdir
Definition network.hpp:711
qstring license_file_name
Definition network.hpp:705
licmgr_logger_t * licmgr_logger
Definition network.hpp:708
virtual ~tlm_credentials_t()
Definition network.hpp:1208
tlm_credentials_t()
Definition network.hpp:1207