static void lan_send(lan_data_t *lan, struct iovec *data, int vecs, void *addr, int addr_len) { struct msghdr msg; lan_addr_t *l = addr; int rv; if (debug) { int left, i; lanserv_log(DEBUG, NULL, "Sending message to:\n "); dump_hex(&l->addr, l->addr_len, 16); lanserv_log(DEBUG, NULL, "\nMsg:\n "); left = 16; for (i=0; i<vecs; i++) { left = dump_hex(data[i].iov_base, data[i].iov_len, left); } lanserv_log(DEBUG, NULL, "\n"); } msg.msg_name = &(l->addr); msg.msg_namelen = l->addr_len; msg.msg_iov = data; msg.msg_iovlen = vecs; msg.msg_control = NULL; msg.msg_controllen = 0; msg.msg_flags = 0; rv = sendmsg(l->xmit_fd, &msg, 0); if (rv) { /* FIXME - log an error. */ } }
void diff_records( token_mod_link** differences, tglobal* global_original, tglobal* global_updated, tfixed* fixed_original, tfixed* fixed_updated, tlog* log_original, tlog* log_updated, bool print_diff_info ) { token_mod_link* diff_pair = NULL; /* We may want to print the timestamps of the records * being compared in order to differentiate them, in fact * this is an essential part of the process... */ while( diff_pair = pop_tm_link( differences ) ) { printf( "Difference found on token [%d]\n", diff_pair->original ? (unsigned short)diff_pair->original->token : diff_pair->modified ? (unsigned short)diff_pair->modified->token : (unsigned short)-1 ); printf( "Original:\n" ); if ( diff_pair->original ) { dump_hex( diff_pair->original->buffer, diff_pair->original->length, (size_t)DUMP_BYTES, (size_t)16 ); } else { printf( "NULL\n" ); } printf( "Modified:\n" ); if ( diff_pair->modified ) { dump_hex( diff_pair->modified->buffer, diff_pair->modified->length, (size_t)DUMP_BYTES, (size_t)16 ); } else { printf( "NULL\n" ); } } printf( "Global configuration modifications:\n" ); if ( !diff_global( global_original, global_updated, print_diff_info ) ) { printf( " None.\n" ); } printf( "Fixed configuration modifications:\n" ); if ( !diff_fixed( fixed_original, fixed_updated, print_diff_info ) ) { printf( " None.\n" ); } printf( "Log configuration modifications:\n" ); if ( !diff_log( log_original, log_updated, print_diff_info ) ) { printf( " None.\n" ); } }
int main(void) { uint8_t ct1[32], pt1[32], pt2[32], key[64]; int klen, plen, clen, i, j; serpent_key_t skey; serpent_blk ct2; uint32_t *p; printf("\nserpent-256 test\n"); for (i = 0; i<sizeof(keys) / sizeof(char*); i++) { clen = hex2bin(ct1, cipher[i]); plen = hex2bin(pt1, plain[i]); klen = hex2bin(key, keys[i]); /* set key */ memset(&skey, 0, sizeof(skey)); p = (uint32_t*)&skey.x[0][0]; serpent_set_encrypt_key(&skey, key); printf("\nkey="); for (j = 0; j<sizeof(skey) / sizeof(serpent_subkey_t) * 4; j++) { if ((j % 8) == 0) putchar('\n'); printf("%08X ", p[j]); } /* encrypt */ memcpy(ct2.b, pt1, SERPENT_BLOCK_SIZE); printf("\n\n"); dump_hex("plaintext", ct2.b, 16); serpent_encrypt(pt1,ct2.b, &skey); dump_hex("ciphertext", ct2.b, 16); if (memcmp(ct1, ct2.b, clen) == 0) { printf("\nEncryption OK"); serpent_decrypt(ct2.b,pt1, &skey); if (memcmp(pt1, ct2.b, plen) == 0) { printf("\nDecryption OK"); dump_hex("plaintext", ct2.b, 16); } else { printf("\nDecryption failed"); } } else { printf("\nEncryption failed"); } } return 0; }
static void check_results (const cl_uint num_devices, gpu_ctx_t *gpu_ctxs) { static uint64_t total = 0; for (cl_uint device_id = 0; device_id < num_devices; device_id++) { gpu_ctx_t *gpu_ctx = &gpu_ctxs[device_id]; if (gpu_ctx->num_cached == 0) continue; const size_t size_results = gpu_ctx->num_threads * sizeof (uint32_t); gc_clEnqueueReadBuffer (gpu_ctx->command_queue, gpu_ctx->d_results, CL_TRUE, 0, size_results, gpu_ctx->h_results, 0, NULL, NULL); for (uint32_t thread = 0; thread < gpu_ctx->num_threads; thread++) { if (gpu_ctx->h_results[thread] != 0xffffffff) { uint32_t gid = gpu_ctx->h_results[thread]; fprintf (stdout, "\nGPU #%2d: ALARM! Candidate number %u cracked the hash! Hex dump following:\n\n", device_id, gid); dump_hex (stdout, gpu_ctx->plains_buf[gid], gpu_ctx->plains_len[gid]); FILE *fd = fopen (POTFILE, "ab"); if (fd) // ignore error { fprintf (fd, "\nGPU #%2d: ALARM! Candidate number %u cracked the hash! Hex dump following:\n\n", device_id, gid); dump_hex (fd, gpu_ctx->plains_buf[gid], gpu_ctx->plains_len[gid]); fclose (fd); } exit (0); } } const uint32_t num_cached = gpu_ctx->num_cached; total += num_cached; float ms; timer_get (gpu_ctx->timer, ms); if (ms == 0) continue; float speed = (num_cached / ms) * 1000; printf ("GPU #%2d: %u candidates in %u ms [%u/s] - Total = %llu...\n", device_id, num_cached, (uint32_t) ms, (uint32_t) speed, (long long unsigned int) total); } }
CC_INLINE bool ccsrp_component_equal(char *label, ccsrp_ctx_t srp, cc_unit *a, cc_unit *b) { bool retval = ccn_cmp(ccsrp_ctx_n(srp), a, b) == 0; if(!retval) { size_t bytes_n = ccsrp_ctx_sizeof_n(srp); cc_printf("ccsrp_test_calculations: mismatch for %s:\n", label); cc_printf("\t"); dump_hex((void *) a, bytes_n); cc_printf("\t"); dump_hex((void *) b, bytes_n); cc_printf("\n"); } return retval; }
static void thex_dump_dime_records(const pslist_t *records) { const pslist_t *iter; PSLIST_FOREACH(records, iter) { const struct dime_record *record = iter->data; g_assert(record); dump_hex(stderr, "THEX DIME record type", dime_record_type(record), dime_record_type_length(record)); dump_hex(stderr, "THEX DIME record ID", dime_record_id(record), dime_record_id_length(record)); } }
static void thex_dump_dime_records(const GSList *records) { const GSList *iter; for (iter = records; NULL != iter; iter = g_slist_next(iter)) { const struct dime_record *record; record = iter->data; g_assert(record); dump_hex(stderr, "THEX DIME record type", dime_record_type(record), dime_record_type_length(record)); dump_hex(stderr, "THEX DIME record ID", dime_record_id(record), dime_record_id_length(record)); } }
static int pack_unpack_datatype( void* send_data, ompi_datatype_t *datatype, int count, void* recv_data, checker_t validator, void* validator_arg) { MPI_Aint position = 0, buffer_size; void* buffer; int error; error = ompi_datatype_pack_external_size("external32", count, datatype, &buffer_size); if( MPI_SUCCESS != error ) goto return_error_code; buffer = (void*)malloc(buffer_size); if( NULL == buffer ) { error = MPI_ERR_UNKNOWN; goto return_error_code; } error = ompi_datatype_pack_external("external32", (void*)send_data, count, datatype, buffer, buffer_size, &position); if( MPI_SUCCESS != error ) goto return_error_code; if( 0 != validator(send_data, buffer, datatype, count, validator_arg) ) { printf("Error during pack external. Bailing out\n"); return -1; } printf("packed %ld bytes into a %ld bytes buffer ", position, buffer_size); dump_hex(buffer, position); printf("\n"); position = 0; error = ompi_datatype_unpack_external("external32", buffer, buffer_size, &position, recv_data, count, datatype); if( MPI_SUCCESS != error ) goto return_error_code; free(buffer); return_error_code: return (error == MPI_SUCCESS ? 0 : -1); }
/* * === FUNCTION ====================================================================== * Name: main * Description: * ===================================================================================== */ int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage: HexDump file \n"); return 1; } FILE *file = fopen(argv[1], "rb"); if (!file) { printf("Can't open the file.\n"); return 2; } char str[640000]; int len = 0; char d[17] ; d[16]=0; unsigned int bytes = 0; while (bytes = fread(d, 1, 16, file)) { memcpy(str+len,d,bytes); printf("%s",d); len += bytes; } printf("len = %d\n",len); dump_hex(str,len); fclose(file); return 0; }
bool huge_tth_extract32(const char *buf, size_t len, struct tth *tth, const gnutella_node_t *n) { if (len != TTH_BASE32_SIZE) goto bad; if (TTH_RAW_SIZE != base32_decode(tth->data, sizeof tth->data, buf, len)) goto bad; return TRUE; bad: if (GNET_PROPERTY(share_debug)) { if (is_printable(buf, len)) { g_warning("%s has bad TTH (len=%u): %.*s", gmsg_node_infostr(n), (unsigned) len, (int) MIN(len, (size_t) INT_MAX), buf); } else { g_warning("%s has bad TTH (len=%u", gmsg_node_infostr(n), (unsigned) len); if (len) dump_hex(stderr, "Base32 TTH", buf, len); } } return FALSE; }
bool WriteFdExactly(int fd, const void* buf, size_t len) { const char* p = reinterpret_cast<const char*>(buf); int r; #if ADB_TRACE D("writex: fd=%d len=%d: ", fd, (int)len); if (ADB_TRACING) { dump_hex(reinterpret_cast<const unsigned char*>(buf), len); } #endif while (len > 0) { r = adb_write(fd, p, len); if (r == -1) { D("writex: fd=%d error %d: %s\n", fd, errno, strerror(errno)); if (errno == EAGAIN) { adb_sleep_ms(1); // just yield some cpu time continue; } else if (errno == EPIPE) { D("writex: fd=%d disconnected\n", fd); errno = 0; return false; } else { return false; } } else { len -= r; p += r; } } return true; }
int writex(int fd, const void *ptr, size_t len) { char *p = (char*)ptr; int r; #if ADB_TRACE D("writex: fd=%d len=%d: ", fd, (int)len); dump_hex((const unsigned char *)ptr, len); #endif while (len > 0) { r = adb_write(fd, p, len); if (r > 0) { len -= r; p += r; } else { if (r < 0) { D("writex: fd=%d error %d: %s\n", fd, errno, strerror(errno)); if (errno == EINTR) continue; if (errno == EAGAIN) { adb_sleep_ms(1); // just yield some cpu time continue; } } else { D("writex: fd=%d disconnected\n", fd); } return -1; } } return 0; }
void update_dump() { if(hex_dlg != NULL) dump_hex(); if(text_dlg != NULL) dump_text(); }
void DumpCobol(BYTE level) { BYTE ch; StdOutPrintf(L"\tLevel = %2d", level & 0x7f); if (level & 0x80) { StdOutPuts(L"(Group)"); } loop: // check next byte of type string ch = getbyte(); if ((ch & 0xfe) == 0xc0) { // output linkage informatioon byte DumpCobLinkage (ch); if (Leaf_pos < Leaf_bytes) { ch = getbyte(); } goto loop; } if (Leaf_pos <= Leaf_bytes) { if ((ch & 0xe0) == 0xe0) { // output OCCURS subscript information DumpCobOccurs (ch); goto loop; } } if (Leaf_pos <= Leaf_bytes) { DumpCobItem (ch); } dump_hex((Leaf_bytes - Leaf_pos), true); StdOutPuts(L"\n"); }
int readx(int fd, void *ptr, size_t len) { char *p = ptr; int r; #if ADB_TRACE int len0 = len; #endif D("readx: %d %p %d\n", fd, ptr, (int)len); while(len > 0) { r = adb_read(fd, p, len); if(r > 0) { len -= r; p += r; } else { D("readx: %d %d %s\n", fd, r, strerror(errno)); if((r < 0) && (errno == EINTR)) continue; return -1; } } #if ADB_TRACE D("readx: %d ok: ", fd); dump_hex( ptr, len0 ); #endif return 0; }
/* * * xsocks UDP Response * +------+----------+----------+----------+ * | ATYP | DST.ADDR | DST.PORT | DATA | * +------+----------+----------+----------+ * | 1 | Variable | 2 | Variable | * +------+----------+----------+----------+ * */ static void server_recv_cb(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, const struct sockaddr *addr, unsigned flags) { if (nread > 0) { struct client_context *client = handle->data; reset_timer(client); int mlen = nread - PRIMITIVE_BYTES; uint8_t *m = (uint8_t *)buf->base; int rc = crypto_decrypt(m, (uint8_t *)buf->base, nread); if (rc) { logger_log(LOG_ERR, "invalid packet"); dump_hex(buf->base, nread, "server recv"); goto err; } m -= 3; mlen += 3; memcpy(m, "\x0\x0\x0", 3); // RSV + FRAG forward_to_client(client, m , mlen); return; } else { goto err; } err: free(buf->base - 3); }
bool ReadFdExactly(int fd, void* buf, size_t len) { char* p = reinterpret_cast<char*>(buf); #if ADB_TRACE size_t len0 = len; #endif D("readx: fd=%d wanted=%zu\n", fd, len); while (len > 0) { int r = adb_read(fd, p, len); if (r > 0) { len -= r; p += r; } else if (r == -1) { D("readx: fd=%d error %d: %s\n", fd, errno, strerror(errno)); return false; } else { D("readx: fd=%d disconnected\n", fd); errno = 0; return false; } } #if ADB_TRACE D("readx: fd=%d wanted=%zu got=%zu\n", fd, len0, len0 - len); if (ADB_TRACING) { dump_hex(reinterpret_cast<const unsigned char*>(buf), len0); } #endif return true; }
void Dump_specific_section( uint sect, const uint_8 *data, uint len ) /*******************************************************************/ { sort_tables(); switch( sect ) { case DW_DEBUG_ABBREV: dump_abbrevs( data, len ); break; case DW_DEBUG_INFO: dump_info( data, len ); break; case DW_DEBUG_ARANGES: dump_aranges( data, len ); break; case DW_DEBUG_LINE: Dump_lines( data, len ); break; case DW_DEBUG_REF: dump_ref( data, len ); break; case DW_DEBUG_PUBNAMES: dump_pubnames( data, len ); break; default: dump_hex( data, len ); break; } }
/* * d u m p _ o s e c * * Dump object file section. * * Returns: OK Success * FAILED Invalid arguments */ int dump_osec(long addrfirst, long addrlast, int sec, int full) { long int addrcount; /* check that all offsets are valid */ addrcount = o_sectab[sec].os_flen; if (addrfirst > o_sectab[sec].os_flen || addrlast > o_sectab[sec].os_flen) { fprintf(stderr, "Invalid %s address range 0x%08.8lu to 0x%08.8lu\n", o_secnam[sec], addrfirst, addrlast); return(FAILED); } else { if (opt_l) addrcount = addrlast + 1; addrcount = addrcount - addrfirst; (void) fseek(objfp, o_sectab[sec].os_foff, SEEK_SET); fprintf(stdout, "\n%s%s:\n", full ? "Disassembled " : "", o_secnam[sec]); if (full) (void) dump_odata(objfp, addrfirst, addrcount, sec); else (void) dump_hex(objfp, addrfirst, addrcount); return(OK); } /* NOTREACHED */ }
/* **************************************************************** * Imprime DUMP da memória * **************************************************************** */ void mem_dump (void) { char area[32]; int i; for (EVER) { printf ("\nDê o endereço inicial: "); gets (area); if (area[0] == 'n') /* EOF */ return; i = strtol (area, (const char **)NULL, 0); if (i == -1) /* EOF */ return; for (EVER) { dump_hex ((char *)i, BLSZ, i); printf ("Continua? (s): "); if (askyesno (1) <= 0) break; i += BLSZ; } } } /* end mem_dump */
static void dump_trail(const tdb* db, const uint8_t* uuid, tdb_cursor* c) { #define HEX4 "%02x%02x%02x%02x" printf("cookie " HEX4 HEX4 HEX4 HEX4 "\n", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); #undef HEX4 const tdb_event* e; while((e = tdb_cursor_next(c))) { printf("ts=%" PRIu64 ":\n", e->timestamp); for(uint64_t i = 0; i < e->num_items; ++i) { const char* name = tdb_get_field_name( db, tdb_item_field(e->items[i])); uint64_t v_len = 0; const char* v = tdb_get_item_value( db, e->items[i], &v_len); printf(" %s=", name); dump_hex(v, v_len); putchar('\n'); } putchar('\n'); } }
int writex(int fd, const void *ptr, size_t len) { char *p = (char*) ptr; int r; #if ADB_TRACE_FORCE D("writex: fd=%d len=%d: ", fd, (int)len); dump_hex( ptr, len ); #endif while(len > 0) { r = adb_write(fd, p, len); if(r > 0) { len -= r; p += r; } else { if (r < 0) { D("writex: fd=%d error %d: %s\n", fd, errno, strerror(errno)); if (errno == EINTR) continue; } else { D("writex: fd=%d disconnected\n", fd); } return -1; } } return 0; }
static void dump_packet(const char* name, const char* func, apacket* p) { unsigned command = p->msg.command; int len = p->msg.data_length; char cmd[9]; char arg0[12], arg1[12]; int n; for (n = 0; n < 4; n++) { int b = (command >> (n*8)) & 255; if (b < 32 || b >= 127) break; cmd[n] = (char)b; } if (n == 4) { cmd[4] = 0; } else { /* There is some non-ASCII name in the command, so dump * the hexadecimal value instead */ snprintf(cmd, sizeof cmd, "%08x", command); } if (p->msg.arg0 < 256U) snprintf(arg0, sizeof arg0, "%d", p->msg.arg0); else snprintf(arg0, sizeof arg0, "0x%x", p->msg.arg0); if (p->msg.arg1 < 256U) snprintf(arg1, sizeof arg1, "%d", p->msg.arg1); else snprintf(arg1, sizeof arg1, "0x%x", p->msg.arg1); D("%s: %s: [%s] arg0=%s arg1=%s (len=%d) ", name, func, cmd, arg0, arg1, len); dump_hex(p->data, len); }
int readx(int fd, void *ptr, size_t len) { char *p = (char *)ptr; int r; #if ADB_TRACE_FORCE int len0 = len; #endif D("readx: fd=%d wanted=%d\n", fd, (int)len); while(len > 0) { r = adb_read(fd, p, len); if(r > 0) { len -= r; p += r; } else { if (r < 0) { D("readx: fd=%d error %d: %s\n", fd, errno, strerror(errno)); if (errno == EINTR) continue; } else { D("readx: fd=%d disconnected\n", fd); } return -1; } } #if ADB_TRACE_FORCE D("readx: fd=%d wanted=%d got=%d\n", fd, len0, len0 - len); dump_hex( ptr, len0 ); #endif return 0; }
static size_t put_nodeid(char* str, const char* nodeid) { const size_t SHORT_NODEID_LEN = 6; // size in binary repr char buf[512], *p = str; size_t n; csinfo_t csinfo = get_csinfo(nodeid); if (csinfo.rev >= 0) p += sprintf(p, "%d:", csinfo.rev); dump_hex(nodeid, p, SHORT_NODEID_LEN); p += SHORT_NODEID_LEN * 2; n = get_mq_patchname(buf, nodeid, sizeof(buf)); if (n) { *p = '['; ++p; memcpy(p, buf, n); p += n; *p = ']'; ++p; *p = '\0'; } else { if (csinfo.istip) { strcpy(p, "[tip]"); p += 5; } } return p - str; }
static size_t get_mq_patchname(char* str, const char* nodeid, size_t n) { char buf[1024]; if (read_last_line(".hg/patches/status", buf, 1024)) { char nodeid_s[NODEID_LEN * 2 + 1], *p, *patch, *patch_nodeid_s; dump_hex(nodeid, nodeid_s, NODEID_LEN); debug("read last line from .hg/patches/status: '%s'", buf); p = strchr(buf, ':'); if (!p) return 0; *p = '\0'; patch_nodeid_s = buf; patch = p + 1; debug("patch name found: '%s', nodeid: %s", patch, patch_nodeid_s); if (strcmp(patch_nodeid_s, nodeid_s)) return 0; strncpy(str, patch, n); str[n - 1] = '\0'; return strlen(str); } else { debug("failed to read from .hg/patches/status: assuming no mq patch applied"); return 0; } }
bool WriteFdExactly(int fd, const void* buf, size_t len) { const char* p = reinterpret_cast<const char*>(buf); int r; VLOG(RWX) << "writex: fd=" << fd << " len=" << len << " " << dump_hex(reinterpret_cast<const unsigned char*>(buf), len); while (len > 0) { r = adb_write(fd, p, len); if (r == -1) { D("writex: fd=%d error %d: %s", fd, errno, strerror(errno)); if (errno == EAGAIN) { adb_sleep_ms(1); // just yield some cpu time continue; } else if (errno == EPIPE) { D("writex: fd=%d disconnected", fd); errno = 0; return false; } else { return false; } } else { len -= r; p += r; } } return true; }
bool ReadFdExactly(int fd, void* buf, size_t len) { char* p = reinterpret_cast<char*>(buf); size_t len0 = len; D("readx: fd=%d wanted=%zu", fd, len); while (len > 0) { int r = adb_read(fd, p, len); if (r > 0) { len -= r; p += r; } else if (r == -1) { D("readx: fd=%d error %d: %s", fd, errno, strerror(errno)); return false; } else { D("readx: fd=%d disconnected", fd); errno = 0; return false; } } VLOG(RWX) << "readx: fd=" << fd << " wanted=" << len0 << " got=" << (len0 - len) << " " << dump_hex(reinterpret_cast<const unsigned char*>(buf), len0); return true; }
static void print_hex(uint8_t *input_buf, size_t input_size) { char buf[DUMP_BUF_MAX]; size_t remain = sizeof(buf); dump_hex(buf, &remain, input_buf, input_size); DMSG("%s", buf); }
int Agent_cloud_process(void) { EdpPacket* connect_pkg = NULL; int ret; unsigned char failedcnt = 0; cloud_conn_status.conn_status = SOCK_DONE; #ifndef Devid_RestFul AGAIN: /* 向Onenet服务器发送EDP连接报文 */ connect_pkg = PacketConnect1((char*)SRC_DEVID, (char*)CLOUD_API_KEY); /* dump package data */ log_info("Packet connect data(len:%d):\n", connect_pkg->_write_pos); dump_hex(connect_pkg->_data, connect_pkg->_write_pos); log_info("SRC_DEVID:%s CLOUD_API_KEY:%s\r\n",SRC_DEVID,CLOUD_API_KEY); ret = Socket_TCPClientSendData((char *)connect_pkg->_data, connect_pkg->_write_pos); DeleteBuffer(&connect_pkg); if (ret < 0) { cloud_conn_status.conn_status = CLOUD_CONN_ERROR; log_info("Send connect data failed(ret:%d).\n", ret); failedcnt++; /* 发送连接次数超过3次则退出连接 */ if (failedcnt > 3) { Socket_TCPClientClose(); return -1; } OSTimeDly(50); goto AGAIN; } else { log_notice("Send connect data success.\n"); } #endif /* 主进程用于接收云端服务器的数据 */ while (1) { ret = Socket_TCPClientRecvData(recv_buf, CLOUD_RECV_BUFFER_SIZE); if (ret > 0) { recv_buf[ret] = '\0'; #if (4 & Devid_Mode) //restful方式 log_notice("%s\r\n",recv_buf); RestFul_RecvProcess(recv_buf,ret); #else recv_data_process(recv_buf, ret); #endif } if (ret < 0 || TCPClient_reset_flag == 0xa5 ) { //关闭TCP链接 log_err("Recv tcp client data error(%d)\n", ret); Socket_TCPClientClose(); return -1; } } }