int main(int argc, char *argv[]) { if (argc == 2) { print_hex(argv[1], strlen(argv[1])); } else { exit(1); } return 0; }
void print_result(DRESULT result) { switch (result) { case 0: break; default: ser_puts(" :( "); print_hex((BYTE)result); ser_nl(); break; } }
static bool transmit_bytes (const uint8_t *pbtTx, const size_t szTx) { // Show transmitted command if (!quiet_output) { printf ("Sent bits: "); print_hex (pbtTx, szTx); } // Transmit the command bytes if (nfc_initiator_transceive_bytes (pnd, pbtTx, szTx, abtRx, &szRx, 0) < 0) return false; // Show received answer if (!quiet_output) { printf ("Received bits: "); print_hex (abtRx, szRx); } // Succesful transfer return true; }
int main(int argc, char * const argv[]) { // Let's try sone hashing. unsigned char input[] = {'H', 'a', 'l', 'l', 'o', ' ', 'W', 'e', 'l', 't'}; unsigned char hash[20]; // sha1 hash is always 20 bytes long SHA1(input, 10, hash); // (input, input-length, output) printf("SHA1 Hash of \"Hallo Welt\": "); print_hex(hash, 20); return 0; }
static void print_bar_pbar(struct foo_t* bar, struct pfoo_t* pbar) { print_hex(&bar->i[0], sizeof(int), 1); print_hex(&bar->i[2], sizeof(int), 1); print_hex(&bar->d[0], sizeof(double), 1); print_hex(&bar->d[2], sizeof(double), 1); fprintf(stderr, "\n"); print_hex(&pbar->i[0], sizeof(int), 1); print_hex(&pbar->i[1], sizeof(int), 1); print_hex(&pbar->d[0], sizeof(double), 1); print_hex(&pbar->d[1], sizeof(double), 1); fprintf(stderr, "\n"); }
void challenge_30() { unsigned char message[128] = "comment1=cooking%20MCs;userdata=foo;" "comment2=%20like%20a%20pound%20of%20bacon"; int mlen = 77, plen; unsigned char padded_message[256] = {0}; memcpy(padded_message, message, 128); unsigned char append[16] = ";admin=true"; int alen = 11; unsigned char mac[16], forged_mac[16], test_mac[16]; print_str("Base MAC"); md4_keyed_mac(message, strlen((char *) message), (unsigned char *) get_static_word(), strlen(get_static_word()), mac); print_hex(mac, 16); print_str("\nForged MAC"); // Assumes secret length 8, but will be the same for any // secret length that doesn't increase or decrease the // number of 64 byte blocks in the hash input + padding md4_length_extension(mac, mlen + 8 + sha1_pad_length(mlen + 8), append, alen, forged_mac); print_hex(forged_mac, 16); print_str("\nPlaintext verified by server: "); int i; for (i = 0; i < 16; ++i) { plen = md4_pad(padded_message, mlen, i); memcpy(padded_message + plen, append, alen); plen += alen; md4_keyed_mac(padded_message, plen, (unsigned char *) get_static_word(), strlen(get_static_word()), test_mac); //print_hex(test_mac, 16); //print_binary(padded_message, plen); if (memcmp(forged_mac, test_mac, 16) == 0) { print_hex(test_mac, 16); print_binary(padded_message, plen); } } }
int main(void) { sodium_init(); printf("HKDF as described in RFC 5869 based on HMAC-SHA512256!\n\n"); unsigned char output_key[200]; size_t output_key_length = sizeof(output_key); //create random salt unsigned char salt[crypto_auth_KEYBYTES]; randombytes_buf(salt, crypto_auth_KEYBYTES); printf("Salt (%i Bytes):\n", crypto_auth_KEYBYTES); print_hex(salt, crypto_auth_KEYBYTES, 30); putchar('\n'); //create key to derive from unsigned char input_key[100]; size_t input_key_length = sizeof(input_key); randombytes_buf(input_key, input_key_length); printf("Input key (%zu Bytes):\n", input_key_length); print_hex(input_key, input_key_length, 30); putchar('\n'); //info unsigned char* info = (unsigned char*) "This is some info!"; size_t info_length = sizeof(info); printf("Info (%zu Bytes):\n", info_length); //this could also be binary data printf("%s\n\n", info); int status; status = hkdf(output_key, output_key_length, salt, input_key, input_key_length, info, info_length); if (status != 0) { fprintf(stderr, "ERROR: Failed to derive key. %i\n", status); return EXIT_FAILURE; } printf("Derived key (%zu Bytes):\n", output_key_length); print_hex(output_key, output_key_length, 30); putchar('\n'); return EXIT_SUCCESS; }
void zzuf_destroy_hex(zzuf_hexdump_t *ctx) { /* Print the last line, if non-empty */ if (ctx->count & 15) print_hex(ctx, (unsigned)(ctx->count & 15)); /* Print the last offset */ printf("%08x\n", (uint32_t)ctx->count); free(ctx); fflush(stdout); }
int main(int argc, char **argv) { int iterations = 10; char *salt = "pepper"; int length = 32; char *password; int c; char *key; while ((c = getopt(argc, argv, "i:s:l:")) != -1) { switch (c) { case 'i': iterations = atoi(optarg); if ( (iterations < 1) || (iterations > 10000000)) usage(); break; case 's': salt = optarg; break; case 'l': length = atoi(optarg); if ( (length < 1) || (length > 5000) ) usage(); break; case '?': usage(); default: abort(); } } if (optind != (argc - 1)) usage(); password = argv[optind]; key = alloca(length); pkcs5_derive_key(make_hmac_algorithm(&sha1_algorithm), strlen(password), password, strlen(salt), salt, iterations, length, key); printf("Key:"); print_hex(length, key); printf("\n"); return 0; }
bool transmit_bytes(const uint8_t *pbtTx, const size_t szTx) { //! Show transmitted command #ifdef DEBUG_PRINTF fprintf(stderr,"Sent bits: "); #endif print_hex(pbtTx, szTx); //! Transmit the command bytes int res; if ((res = nfc_initiator_transceive_bytes(pnd, pbtTx, szTx, abtRx, sizeof(abtRx), 0)) < 0) { return false; } //! Show received answer #ifdef DEBUG_PRINTF fprintf(stderr,"Received bits: "); #endif print_hex(abtRx, res); //! Succesful transfer return true; }
void msft_dump(void) { int i; dump_msft_header(); for(i=0; i < typeinfo_cnt; i++) print_hex_id("typeinfo %d offset", i); if(header_flags & HELPDLLFLAG) print_hex("help dll offset"); print_offset(); printf("\n"); dump_msft_segdir(); while(!msft_eof) { if(!dump_offset()) print_hex("unknown"); } }
/** print %x */ static void print_num_x(char **at, size_t * left, int *ret, unsigned int value, int minw, int precision, int prgiven, int zeropad, int minus, int plus, int space) { char buf[PRINT_DEC_BUFSZ]; int negative = 0; int zero = (value == 0); int len = print_hex(buf, (int)sizeof(buf), value); print_num(at, left, ret, minw, precision, prgiven, zeropad, minus, plus, space, zero, negative, buf, len); }
int main(int argc, char *argv[]) { const char sid[] = { 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B }; const char rid[] = { 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D }; char id[sizeof(sid)+sizeof(rid)]; unsigned char strategy = DOMAIN_LOCAL; /*NODE_LOCAL;*/ ba_handle ba; memcpy(id, sid, sizeof(sid)); memcpy(id+sizeof(sid), rid, sizeof(rid)); if (argc >= 2) strategy = (unsigned char)atoi(argv[1]); ba = ba_instance(1); ba_publish_scope(ba, sid, sizeof(rid), "", 0, strategy, (void *)0, 0); ba_publish_info(ba, rid, sizeof(rid), sid, sizeof(sid), strategy, (void *)0, 0); do { ba_event ev = ba_event_new(); unsigned char *_type = NULL, type; ba_get_event(ba, ev); ba_event_type(ev, &_type); type = *_type; ba_event_delete(ev); if (type == 0) goto disconnect; if (type == START_PUBLISH) break; } while (1); do { char buf[101]; int nitems; unsigned int len; printf("What shall I publish, Sir/Madam? (ctrl-d to quit)\n"); nitems = scanf("%100s", buf); /* XXX */ if (nitems == EOF) break; len = strlen(buf); print_hex(NULL, buf, len); ba_publish_data(ba, id, sizeof(id), strategy, (void *)0, 0, buf, len); } while (1); disconnect: ba_disconnect(ba); ba_delete(ba); return 0; }
int main(int argc, char** argv) { int sock, n; char buffer[2048]; char sendbuf[2048]; struct ifreq ethreq; struct sockaddr_ll saddr; int packet_num = 1; int i; for(i = 0; i < 2048; i++) { buffer[i] = 0; sendbuf[i] = 0; } if ( (sock=socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)))<0){ perror("socket"); exit(1); } /* Set the network card in promiscuos mode */ strncpy(ethreq.ifr_name,"nf0",IFNAMSIZ); if (ioctl(sock,SIOCGIFINDEX,ðreq)==-1) { perror("ioctl"); close(sock); exit(1); } saddr.sll_family = AF_PACKET; saddr.sll_protocol = htons(ETH_P_ALL); saddr.sll_ifindex = ethreq.ifr_ifindex; if (bind(sock, (struct sockaddr*)(&(saddr)), sizeof(saddr)) < 0) { perror("Bind"); close(sock); exit(1); } sendbuf[0] = 0xfe;sendbuf[1] = 0xca;sendbuf[2] = 0xae; sendbuf[7] = 0x03; sendbuf[32] = 0x0a;sendbuf[33] = 0x0b;sendbuf[34] = 0x0c;sendbuf[35] = 0x0d; sendbuf[36] = 0x1a;sendbuf[37] = 0x1b;sendbuf[38] = 0x1c;sendbuf[39] = 0x1d; // sendbuf[32] = 1;sendbuf[33] = 0;sendbuf[34] = 0xad;sendbuf[35] = 0xde; //if(sendto(sock, sendbuf,100, 0, NULL, 0) <= 0) printf("Error send\n");; while (1) { n = recvfrom(sock,buffer,2048,0,NULL,NULL); printf("Packet%d -----------------------------------------------------\n", packet_num); print_hex(buffer, n); packet_num++; } return 0; }
int main(int argc, const char *argv[]) { system("clear"); nfc_device *pnd; nfc_target nt; // Allocate only a pointer to nfc_context nfc_context *context; // Initialize libnfc and set the nfc_context nfc_init(&context); // Display libnfc version const char *acLibnfcVersion = nfc_version(); printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion); // Open, using the first available NFC device. pnd = nfc_open(context, NULL); if (pnd == NULL) { warnx("ERROR: %s", "Unable to open NFC device."); return EXIT_FAILURE; } // Set opened NFC device to initiator mode if (nfc_initiator_init(pnd) < 0) { nfc_perror(pnd, "nfc_initiator_init"); exit(EXIT_FAILURE); } printf("NFC reader: %s opened\n", nfc_device_get_name(pnd)); printf("...\n", nfc_device_get_name(pnd)); while (true){ // Poll for a ISO14443A (MIFARE) tag const nfc_modulation nmMifare = { .nmt = NMT_ISO14443A, .nbr = NBR_106, }; if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) > 0) { print_hex(nt.nti.nai.abtUid, nt.nti.nai.szUidLen); } sleep(1); } // Close NFC device nfc_close(pnd); // Release the context nfc_exit(context); return EXIT_SUCCESS; }
int ikev2_pld_certreq(struct iked *env, struct ikev2_payload *pld, struct iked_message *msg, size_t offset, size_t left) { struct iked_sa *sa = msg->msg_sa; struct ikev2_cert cert; u_int8_t *buf; ssize_t len; u_int8_t *msgbuf = ibuf_data(msg->msg_data); if (ikev2_validate_certreq(msg, offset, left, pld, &cert)) return (-1); offset += sizeof(cert); buf = msgbuf + offset; len = betoh16(pld->pld_length) - sizeof(*pld) - sizeof(cert); log_debug("%s: type %s length %zd", __func__, print_map(cert.cert_type, ikev2_cert_map), len); /* This will actually be caught by earlier checks. */ if (len < 0) { log_debug("%s: invalid certificate request length", __func__); return (-1); } print_hex(buf, 0, len); if (!ikev2_msg_frompeer(msg)) return (0); if (cert.cert_type == IKEV2_CERT_X509_CERT) { if (!len || (len % SHA_DIGEST_LENGTH) != 0) { log_debug("%s: invalid certificate request", __func__); return (-1); } } if (msg->msg_sa == NULL) return (-1); /* Optional certreq for PSK */ if (sa->sa_hdr.sh_initiator) sa->sa_stateinit |= IKED_REQ_CERT; else sa->sa_statevalid |= IKED_REQ_CERT; ca_setreq(env, &sa->sa_hdr, &sa->sa_policy->pol_localid, cert.cert_type, buf, len, PROC_CERT); return (0); }
void print_hex(int nb) { char c; if (nb / 16) print_hex(nb / 16); nb %= 16; if (nb >= 0 && nb <= 9) c = nb + '0'; else if (nb >= 10 && nb <= 15) c = nb + 87; write(1, &c, 1); }
void pkt_process(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes) { printf("\n\n ############ One New Packet ############### \n"); printf("Capture pcaket time is %s", ctime((const time_t *)&h->ts.tv_sec)); printf("Cpature pcaket length is %d\n", h->caplen); printf("Pcaket real length is %d\n", h->len); length = h->caplen; print_hex((char *)bytes, length); process_ether((char *)bytes); }
int main() { int file; int rc = 0; //static char buf[] = {0x03, 0x07, 0x1B, 0x01, 0x00, 0x00, 0x27, //0x47}; if ((file = open(filename, O_RDWR)) < 0) { /* ERROR HANDLING: you can check errno to see what went wrong */ perror("Failed to open the i2c bus"); exit(1); } if(sizeof(buf) != write(file,buf,sizeof(buf))){ perror("Write failed\n"); exit(1); } else{ printf("Wrote %lu bytes\n", sizeof(buf)); } if (sizeof(recv_buf) != read(file,recv_buf,sizeof(recv_buf))){ perror("Read failed\n"); exit(1); } else{ printf("Read %lu bytes\n", sizeof(recv_buf)); print_hex("Received data", recv_buf, sizeof(recv_buf)); } if (test_single_byte_read(file) != 0){ printf("Single byte read failed\n"); rc = 1; goto close_exit; } if (test_multiple_open()){ printf("Multiple open failed\n"); rc = 1; goto close_exit; } close_exit: close(file); return rc; }
/*Reads data from inputfile/stdin and prepares the input for hexdump conversion. Reads 1 byte at a time and when it reaches 16, passes it to the hexdump function. */ void read_data(FILE *fp) { unsigned char * buff1 = (unsigned char*) malloc(16); // buffer to read input. unsigned char * buff2 = (unsigned char *)malloc(16); int i =0, k; if(buff1== NULL) { fprintf(stderr, "Error: malloc() malfunctioning.\n"); } while(!feof(fp)) { fread(&buff1[i], sizeof(char) , 1, fp); i++; if(i>=16) { print_hex(buff1,i); i=0; for(k=0;k<16;k++) buff1[k] = '\0'; // when buffer reaches 16, clear the buffer and read next 16 characters. } } if(i) // if buffer is less than 16 and input has reached its end. { print_hex(buff1,i-1); i=0; } fclose(fp); free(buff1); free(buff2); }
void print_memory(const void *addr, size_t size) { unsigned char *ptr; int i = 0; int count_pass; int tcpt; ptr = (unsigned char *)addr; while (i < (int)size) { count_pass = 0; tcpt = i; while (tcpt < (int)size && count_pass < 16) { print_hex(ptr[tcpt]); tcpt++; count_pass++; if (tcpt < (int)size) { print_hex(ptr[tcpt]); count_pass++; tcpt++; } write(1, " ", 1); } print_pad(calc_pad(count_pass)); count_pass = 0; tcpt = i; while (tcpt < (int)size && count_pass < 16) { print_ascii(ptr[tcpt]); count_pass++; tcpt++; } write(1, "\n", 1); i += count_pass; } }
void print_key(struct crypto_key_t *key, bool newline) { switch(key->method) { case CRYPTO_KEY: print_hex(key->u.key, 16, false); break; case CRYPTO_USBOTP: printf("USB-OTP(%04x:%04x)", key->u.vid_pid >> 16, key->u.vid_pid & 0xffff); break; case CRYPTO_NONE: printf("none"); break; case CRYPTO_XOR_KEY: print_hex(&key->u.xor_key[0].key[0], 64, false); print_hex(&key->u.xor_key[1].key[0], 64, false); break; default: printf("unknown"); } if(newline) printf("\n"); }
// curry without offset calculation int (*(*__curry_no (int (*f) (int, int))) (int)) (int) { intptr_t size = (intptr_t) end_f1 - (intptr_t) f1; unsigned char *c = memcpy(valloc(size), f1, size); mprotect(c, size, PROT_READ | PROT_WRITE | PROT_EXEC); *(ptr_t*)(c+f1_f) = (ptr_t)f; // set the function call #ifdef DEBUG print_hex("c", c, size); #endif return (int (*(*) (int)) (int))c; }
static int nfcforum_tag2_io(struct nfc_emulator *emulator, const uint8_t *data_in, const size_t data_in_len, uint8_t *data_out, const size_t data_out_len) { int res = 0; uint8_t *nfcforum_tag2_memory_area = (uint8_t *)(emulator->user_data); printf(" In: "); print_hex(data_in, data_in_len); switch (data_in[0]) { case READ: if (data_out_len >= 16) { memcpy(data_out, nfcforum_tag2_memory_area + (data_in[1] * 4), 16); res = 16; } else { res = -ENOSPC; } break; case HALT: printf("HALT sent\n"); res = -ECONNABORTED; break; default: printf("Unknown command: 0x%02x\n", data_in[0]); res = -ENOTSUP; } if (res < 0) { ERR("%s (%d)", strerror(-res), -res); } else { printf(" Out: "); print_hex(data_out, res); } return res; }
void print_services() { int i; // printf(",Services_type:%u", ap.services_type); printf(",Services:"); switch (ap.services_type) { case 0x02: // AD Type == Incomplete List of 16-bit Service Class UUIDs case 0x03: // AD Type == Complete List of 16-bit Service Class UUIDs printf("["); for(i=0; i<ap.services_len; i+=2) { printf("0x%02x%02x,", ap.services[i+1], ap.services[i]); } printf("]"); break; case 0x04: // AD Type == Incomplete List of 32-bit Service Class UUIDs case 0x05: // AD Type == Complete List of 32-bit Service Class UUIDs printf("["); for(i=0; i<ap.services_len; i+=4) { printf("0x%02x%02x%02x%02x,", ap.services[i+3], ap.services[i+2], ap.services[i+1], ap.services[i]); } printf("]"); break; case 0x06: // AD Type == Incomplete List of 128-bit Service Class UUIDs case 0x07: // AD Type == Complete List of 128-bit Service Class UUIDs printf("["); for(i=0; i<ap.services_len; i+=16) { print_hex(ap.services+i, 16); printf(","); } printf("]"); default: print_hex(ap.services, ap.services_len); } }
void printf(char* frmt, ...) { // Pointer to the current argument uint32_t *args = (uint32_t*)(&frmt) + 1; // Prints the format string while (*frmt != '\0') { // If a format code is found if (*frmt == '%') { frmt++; switch (*frmt) { case '%': // Escapes the % character putc('%'); break; case 'c': // Inserts a character putc(*((char*)args)); args++; break; case 's': // Inserts a string puts(*((char**)args)); args++; break; case 'd': // Inserts a signed integer print_int(*((int*)args)); args++; break; case 'x': // Inserts an unsigned hexadecimal integer print_hex(*((int*)args)); args++; break; default: break; } } else { putc(*frmt); } frmt++; } }
void wimdump_metadata (struct wimheader *wh, int image_index) { struct reshdr_disk mdrh; struct wim_security *sec; struct wim_direntry *dir, *dir_end; int i; char *sec_descriptors; char prefix[32]; int need_to_free; size_t md_size; if ((find_metadata_reshdr (wh, &mdrh, image_index)) == -1) return; need_to_free = expand_if_required (wh, (struct reshdr_disk_short *) &mdrh, (void **) &sec, &md_size); if (need_to_free == -1) { error (0, 0, "unable to expand metadata"); return; } dir = (void *) sec + sec->total_length; dir_end = (void *) sec + mdrh.original_size; printf ("security.total_length = %" PRIu32 "\n", sec->total_length); printf ("security.num_entries = %" PRIu32 "\n", sec->num_entries); for (i = 0; i < sec->num_entries; i++) printf ("security.entry_length[%i] = %" PRIu64 "\n", i, sec->entry_length[i]); sec_descriptors = (void *) &sec->entry_length + (sec->num_entries + sizeof (sec->entry_length[0])); for (i = 0; i < sec->num_entries; i++) { printf ("security_descriptor[%i] = ", i); print_hex (sec_descriptors, (size_t) sec->entry_length[i]); printf ("\n"); sec_descriptors += sec->entry_length[i]; } i = 0; while (dir < dir_end) { printf ("\n"); snprintf (prefix, sizeof (prefix), "direntry[%i]", i); print_wim_direntry (prefix, dir); dir = (void *) dir + dir->length; while (dir < dir_end && dir->length == 0) dir = (void *) dir + 8; i++; } if (need_to_free) free (sec); }
int main(int argc, const char *argv[]) { nfc_device *pnd; nfc_target nt; // Allocate only a pointer to nfc_context nfc_context *context; // Initialize libnfc and set the nfc_context nfc_init(&context); if (context == NULL) { exit(EXIT_FAILURE); } // Display libnfc version const char *acLibnfcVersion = nfc_version(); (void)argc; // Open, using the first available NFC device which can be in order of selection: // - default device specified using environment variable or // - first specified device in libnfc.conf (/etc/nfc) or // - first specified device in device-configuration directory (/etc/nfc/devices.d) or // - first auto-detected (if feature is not disabled in libnfc.conf) device pnd = nfc_open(context, NULL); if (pnd == NULL) { exit(EXIT_FAILURE); } // Set opened NFC device to initiator mode if (nfc_initiator_init(pnd) < 0) { nfc_perror(pnd, "nfc_initiator_init"); exit(EXIT_FAILURE); } // Poll for a ISO14443A (MIFARE) tag nfc_modulation nmMifare; nmMifare.nmt = NMT_ISO14443A; nmMifare.nbr = NBR_106; if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) > 0) print_hex(nt.nti.nai.abtUid, nt.nti.nai.szUidLen); // Close NFC device nfc_close(pnd); // Release the context nfc_exit(context); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { int ret; unsigned char *key; int key_length; /* *** initialization *** */ key = NULL; key_length = 0; ret = 1; /* *** check cmd line argument *** */ if(argc != 2) { fprintf(stderr, "usage: %s <key_length>\n", argv[0]); return -1; } key_length = atoi(argv[1]); if(key_length <= 0) { fprintf(stderr, "error: key_length must be > 0\n"); return -1; } /* *** allocate space for key *** */ key = (unsigned char *)malloc(key_length * sizeof(char)); if(key == NULL) { fprintf(stderr, "error: memory allocation failed\n"); return -1; } /* *** generate key *** */ ret = gen_key(key, key_length); if(ret != 0) goto cleanup; /* *** print the key *** */ print_hex(key, key_length, "key = "); ret = 0; cleanup: /* *** cleanup and return *** */ memset(key, 0x00, key_length); free(key); key = NULL; key_length = 0; return ret; }
static void draw_instr() { U8 field_it = 0; gotoxy(XPOS, 0); textcolor(COLOR_GREEN); cputs("instr "); print_hex(VIEW_INSTR); gotoxy(XPOS + 8, YPOS + 1); textcolor(COLOR_BLUE); cputs("filter"); while (field_it < FIELD_COUNT) { draw_field(field_it++); } }