void check_avalanche_effect() { unsigned int yyyymmdd; unsigned int yyyymmdd_1; int in; unsigned char h1[HASH_LENGTH]; unsigned char h2[HASH_LENGTH]; fputs("YYYYMMDD: ", stdout); in = scanf("%8u", &yyyymmdd); if (EOF == in) { perror("failed to get your birth date"); } else if (1 != in) { fputs("your birth date should be eight-digit unsigned integer", stderr); exit(EXIT_FAILURE); } yyyymmdd_1 = yyyymmdd ^ 0x01; SHA3_256(h1, (unsigned char *) &yyyymmdd, sizeof(yyyymmdd)); print_hash("SHA3_256", yyyymmdd, h1, 0); SHA3_256(h2, (unsigned char *) &yyyymmdd_1, sizeof(yyyymmdd_1)); print_hash("SHA3_256", yyyymmdd, h2, 1); print_hdist(h1, h2); }
int sce_encrypt_header(u8 *ptr, struct key *k) { u32 meta_offset; u32 meta_len; u64 header_len; u8 iv[16]; meta_offset = be32(ptr + 0x0c); header_len = be64(ptr + 0x10); meta_len = header_len - meta_offset; printf("Key"); print_hash(k->key, 0x10); printf("\n"); print_hash(ptr + meta_offset + 0x60, 0x10); printf("\n"); memcpy(iv, ptr + meta_offset + 0x40, 0x10); aes128ctr(ptr + meta_offset + 0x20, iv, ptr + meta_offset + 0x60, meta_len - 0x60, ptr + meta_offset + 0x60); aes256cbc_enc(k->key, k->iv, ptr + meta_offset + 0x20, 0x40, ptr + meta_offset + 0x20); print_hash(ptr + meta_offset + 0x20, 0x10); printf("\n"); return 0; }
static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /* {{{ */ { switch (Z_TYPE_P(expr)) { case IS_ARRAY: smart_str_appends(buf, "Array\n"); if (Z_REFCOUNTED_P(expr)) { if (Z_IS_RECURSIVE_P(expr)) { smart_str_appends(buf, " *RECURSION*"); return; } Z_PROTECT_RECURSION_P(expr); } print_hash(buf, Z_ARRVAL_P(expr), indent, 0); if (Z_REFCOUNTED_P(expr)) { Z_UNPROTECT_RECURSION_P(expr); } break; case IS_OBJECT: { HashTable *properties; int is_temp; zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr)); smart_str_appends(buf, ZSTR_VAL(class_name)); zend_string_release(class_name); smart_str_appends(buf, " Object\n"); if (Z_IS_RECURSIVE_P(expr)) { smart_str_appends(buf, " *RECURSION*"); return; } if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) { break; } Z_PROTECT_RECURSION_P(expr); print_hash(buf, properties, indent, 1); Z_UNPROTECT_RECURSION_P(expr); if (is_temp) { zend_hash_destroy(properties); FREE_HASHTABLE(properties); } break; } case IS_LONG: smart_str_append_long(buf, Z_LVAL_P(expr)); break; case IS_REFERENCE: zend_print_zval_r_to_buf(buf, Z_REFVAL_P(expr), indent); break; default: { zend_string *str = zval_get_string(expr); smart_str_append(buf, str); zend_string_release(str); } break; } }
int main() { unsigned char text1[]={"abc"}, text2[]={"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"}, text3[]={"aaaaaaaaaa"}, hash[32]; int idx; SHA256_CTX ctx; // Hash one sha256_init(&ctx); sha256_update(&ctx,text1,strlen(text1)); sha256_final(&ctx,hash); print_hash(hash); // Hash two sha256_init(&ctx); sha256_update(&ctx,text2,strlen(text2)); sha256_final(&ctx,hash); print_hash(hash); // Hash three sha256_init(&ctx); for (idx=0; idx < 100000; ++idx) sha256_update(&ctx,text3,strlen(text3)); sha256_final(&ctx,hash); print_hash(hash); getchar(); return 0; }
ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent) { switch(expr->type) { case IS_ARRAY: ZEND_PUTS_EX("Array\n"); if (++expr->value.ht->nApplyCount>1) { ZEND_PUTS_EX(" *RECURSION*"); expr->value.ht->nApplyCount--; return; } print_hash(write_func, expr->value.ht, indent); expr->value.ht->nApplyCount--; break; case IS_OBJECT: { zend_object *object = Z_OBJ_P(expr); if (++object->properties->nApplyCount>1) { ZEND_PUTS_EX(" *RECURSION*"); object->properties->nApplyCount--; return; } zend_printf("%s Object\n", object->ce->name); print_hash(write_func, object->properties, indent); object->properties->nApplyCount--; break; } default: zend_print_zval_ex(write_func, expr, indent); break; } }
static int sha_verify(fence_req_t *req, void *key, size_t key_len) { unsigned char hash[SHA512_LENGTH]; unsigned char pkt_hash[SHA512_LENGTH]; HASHContext *h = NULL; HASH_HashType ht; unsigned int rlen; int ret; switch(req->hashtype) { case HASH_SHA1: ht = HASH_AlgSHA1; break; case HASH_SHA256: ht = HASH_AlgSHA256; break; case HASH_SHA512: ht = HASH_AlgSHA512; break; default: dbg_printf(3, "%s: no-op (HASH_NONE)\n", __FUNCTION__); return 0; } if (!key || !key_len) { dbg_printf(3, "%s: Hashing requested when we have no key data\n", __FUNCTION__); return 0; } memset(hash, 0, sizeof(hash)); h = HASH_Create(ht); if (!h) return 0; memcpy(pkt_hash, req->hash, sizeof(pkt_hash)); memset(req->hash, 0, sizeof(req->hash)); HASH_Begin(h); HASH_Update(h, key, key_len); HASH_Update(h, (void *)req, sizeof(*req)); HASH_End(h, hash, &rlen, sizeof(hash)); HASH_Destroy(h); memcpy(req->hash, pkt_hash, sizeof(req->hash)); ret = !memcmp(hash, pkt_hash, sizeof(hash)); if (!ret) { printf("Hash mismatch:\nPKT = "); print_hash(pkt_hash, sizeof(pkt_hash)); printf("\nEXP = "); print_hash(hash, sizeof(hash)); printf("\n"); } return ret; }
static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /* {{{ */ { ZVAL_DEREF(expr); switch (Z_TYPE_P(expr)) { case IS_ARRAY: smart_str_appends(buf, "Array\n"); if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) && ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) { smart_str_appends(buf, " *RECURSION*"); Z_ARRVAL_P(expr)->u.v.nApplyCount--; return; } print_hash(buf, Z_ARRVAL_P(expr), indent, 0); if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) { Z_ARRVAL_P(expr)->u.v.nApplyCount--; } break; case IS_OBJECT: { HashTable *properties; int is_temp; zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr)); smart_str_appends(buf, ZSTR_VAL(class_name)); zend_string_release(class_name); smart_str_appends(buf, " Object\n"); if (Z_OBJ_APPLY_COUNT_P(expr) > 0) { smart_str_appends(buf, " *RECURSION*"); return; } if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) { break; } Z_OBJ_INC_APPLY_COUNT_P(expr); print_hash(buf, properties, indent, 1); Z_OBJ_DEC_APPLY_COUNT_P(expr); if (is_temp) { zend_hash_destroy(properties); FREE_HASHTABLE(properties); } break; } case IS_LONG: smart_str_append_long(buf, Z_LVAL_P(expr)); break; default: { zend_string *str = zval_get_string(expr); smart_str_append(buf, str); zend_string_release(str); } break; } }
static void print_hash(struct nhash *h) { if (h == NULL) return; printf("%s ", h->key); print_hash(h->l); print_hash(h->r); }
ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */ { ZVAL_DEREF(expr); switch (Z_TYPE_P(expr)) { case IS_ARRAY: ZEND_PUTS_EX("Array\n"); if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) && ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) { ZEND_PUTS_EX(" *RECURSION*"); Z_ARRVAL_P(expr)->u.v.nApplyCount--; return; } print_hash(write_func, Z_ARRVAL_P(expr), indent, 0); if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) { Z_ARRVAL_P(expr)->u.v.nApplyCount--; } break; case IS_OBJECT: { HashTable *properties; int is_temp; zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr)); ZEND_PUTS_EX(ZSTR_VAL(class_name)); zend_string_release(class_name); ZEND_PUTS_EX(" Object\n"); if (Z_OBJ_APPLY_COUNT_P(expr) > 0) { ZEND_PUTS_EX(" *RECURSION*"); return; } if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) { break; } Z_OBJ_INC_APPLY_COUNT_P(expr); print_hash(write_func, properties, indent, 1); Z_OBJ_DEC_APPLY_COUNT_P(expr); if (is_temp) { zend_hash_destroy(properties); FREE_HASHTABLE(properties); } break; } default: zend_print_zval_ex(write_func, expr, indent); break; } }
void testrun_twister512(void){ twister512_hash_t hash; char* testv[]={ "", "a", "abc", "message digest", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "12345678901234567890123456789012345678901234567890123456789012345678901234567890"}; uint32_t i; uart_putstr_P(PSTR("\r\n=== TWISTER-512 test suit (MD5 test values) ===")); for(i=0; i<7; ++i){ uart_putstr_P(PSTR("\r\n TWISTER-512 (\"")); uart_putstr(testv[i]); uart_putstr_P(PSTR("\") = \r\n\t")); twister512(&hash, testv[i], strlen(testv[i])*8); print_hash(hash); // return; } uart_putstr_P(PSTR("\r\n\r\n=== TWISTER-512 test suit (short test values) ===")); uint8_t stestv[]= {0x00, 0x00, 0xC0, 0xC0, 0x80, 0x48, 0x50}; uint8_t stestl[]= { 0, 1, 2, 3, 4, 5, 6}; for(i=0; i<7; ++i){ uart_putstr_P(PSTR("\r\n TWISTER-512 (\"")); uart_hexdump(&(stestv[i]), 1); uart_putstr_P(PSTR("\") = \r\n\t")); twister512(hash, &(stestv[i]), stestl[i]); print_hash(hash); } #ifdef TWISTER_LONGTEST uart_putstr_P(PSTR("\r\n\r\n=== TWISTER-512 test suit (long test) ===")); char* ltest= "abcdefghbcdefghicdefghijdefghijk" "efghijklfghijklmghijklmnhijklmno"; twister512_ctx_t ctx; twister512_init(&ctx); uart_putstr_P(PSTR("\r\n TWISTER-512 ( 16777216 x \"")); uart_putstr(ltest); uart_putstr_P(PSTR("\") = \r\n\t")); for(i=0; i<16777216; ++i){ twister512_nextBlock(&ctx, ltest); } twister512_ctx2hash(hash, &ctx); print_hash(hash); #endif }
//Digests the file then encrypts the digest with the supplied key //length of verification will be stored in len unsigned char *create_file_verification(unsigned char *key, char *filename, int *len) { //printf("Creating file verification for %s\n", filename); unsigned char *digest = digest_file(filename, len); unsigned char *out = NULL; //printf("%s DIGEST: ", filename); print_hash(digest, *len); if(digest != NULL) { out = blowfish_enc(key, digest, *len); //printf("Enc Digest: "); print_hash(out, *len); free(digest); } return out; }
int main (void) { struct hash_table *ht = make_string_hash_table (0); char line[80]; while ((fgets (line, sizeof (line), stdin))) { int len = strlen (line); if (len <= 1) continue; line[--len] = '\0'; if (!hash_table_contains (ht, line)) hash_table_put (ht, strdup (line), "here I am!"); #if 1 if (len % 5 == 0) { char *line_copy; if (hash_table_get_pair (ht, line, &line_copy, NULL)) { hash_table_remove (ht, line); xfree (line_copy); } } #endif } #if 0 print_hash (ht); #endif #if 1 printf ("%d %d\n", ht->count, ht->size); #endif return 0; }
int main(int argc, char **argv) { guchar image_data[width * height * 3]; collect_data(image_data); print_hash(width*height*3, image_data); draw_image(argc, argv, image_data); }
int main(int argc, char* argv[]) { char hash[ 1024/8 ]; hash_file = argv[0]; params( argc, argv ); int fd = open( hash_file, 0 ); if ( -1 == fd ) { perror( NULL ); return EXIT_FAILURE; } off_t data_size = lseek( fd, 0, SEEK_END ); if ( -1 == data_size ) { perror ( NULL ); return EXIT_FAILURE; } void* data = mmap( NULL, data_size, PROT_READ, MAP_SHARED | MAP_NORESERVE, fd, 0 ); if ( MAP_FAILED == data ) { perror( NULL ); return EXIT_FAILURE; } Hash( hash_size << 3, data, data_size << 3, hash ); munmap( data, data_size ); close( fd ); print_hash( hash, hash_size ); fprintf( stdout, "\n" ); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { aes_block key= { 0xdeadbeef, 0xceedcaca, 0xcafebabe, 0xff010204 }; __u8 hash[16]; char *str = argv[1]; aes_context_mac ctx; if (str==NULL) { fprintf(stderr, "pasame el str\n"); return 255; } AES_xcbc_mac_set_key(&ctx, (__u8 *)&key, sizeof(key)); AES_xcbc_mac_hash(&ctx, str, strlen(str), hash); print_hash(hash); str[2]='x'; AES_xcbc_mac_hash(&ctx, str, strlen(str), hash); print_hash(hash); return 0; }
/* sharing some chunks but with different hash/minhash */ void collect_distinct_files(){ init_iterator("CHUNK"); struct chunk_rec r; memset(&r, 0, sizeof(r)); int count = 0; while(iterate_chunk(&r, 1) == 0){ if(r.rcount > 1 && r.fcount > 1){ struct file_rec files[r.fcount]; memset(files, 0, sizeof(files)); int i = 0; for(; i < r.fcount; i++){ files[i].fid = r.list[r.rcount + i]; search_file(&files[i]); } for(i=1; i<r.fcount; i++){ if(memcmp(files[i].minhash, files[i-1].minhash, sizeof(files[i].minhash)) != 0){ char suffix[8]; printf("CHUK %d ", r.fcount); print_hash(r.hash, 10); int j = 0; for(; j<r.fcount; j++){ parse_file_suffix(files[j].fname, suffix, sizeof(suffix)); if(strncmp(suffix, "edu,", 4) == 0){ strcpy(suffix, "edu,?"); }else if(strlen(suffix) == 0){ strcpy(suffix, ".None"); } printf("FILE %d %" PRId64 " %s %s ", files[j].fid, files[j].fsize, files[j].fname, suffix); print_hash(files[j].minhash, 10); } count++; break; } } } } fprintf(stderr, "%d chunks are shared between distinct files\n", count); close_iterator(); }
static void show_hash(const char *data, size_t len) { if (s_options & O_HASH_MOD) print_hash("hash-mod", bmz_hash_mod(data, len, s_b1, s_m)); if (s_options & O_HASH_MOD16X2) print_hash("hash-mod16x2", bmz_hash_mod16x2(data, len, s_b1, s_b2, s_m1, s_m2)); if (s_options & O_HASH_MASK16X2) print_hash("hash-mask16X2", bmz_hash_mask16x2(data, len, s_b1, s_b2)); if (s_options & O_HASH_MASK) print_hash("hash-mask", bmz_hash_mask(data, len, s_b1)); if (s_options & O_HASH_MASK32X2) print_hash("hash-mask32x2", bmz_hash_mask32x2(data, len, s_b1, s_b2)); }
int collect_identical_files(){ init_iterator("FILE"); struct file_rec r; memset(&r, 0, sizeof(r)); GHashTable* hashset = g_hash_table_new_full(g_int_hash, hash_equal, NULL, free_file_list); while(iterate_file(&r) == 0){ if(r.fsize > 0){ struct file_list* fl = g_hash_table_lookup(hashset, r.hash); if(fl == NULL){ fl = malloc(sizeof(struct file_list)); fl->head = NULL; memcpy(fl->hash, r.hash, sizeof(r.hash)); g_hash_table_insert(hashset, fl->hash, fl); } struct file_item* item = malloc(sizeof(*item) + strlen(r.fname) + 1); item->fid = r.fid; item->fsize = r.fsize; strcpy(item->fname, r.fname); fl->head = g_list_prepend(fl->head, item); } } close_iterator(); g_hash_table_foreach_remove(hashset, only_one_item, NULL); GHashTableIter iter; gpointer key, value; g_hash_table_iter_init(&iter, hashset); char suffix[8]; while(g_hash_table_iter_next(&iter, &key, &value)){ struct file_list* fl = value; printf("HASH %d ", g_list_length(fl->head)); print_hash(fl->hash, 10); GList* elem = g_list_first(fl->head); do{ struct file_item* item = elem->data; parse_file_suffix(item->fname, suffix, sizeof(suffix)); if(strncmp(suffix, "edu,", 4) == 0){ strcpy(suffix, "edu,?"); }else if(strlen(suffix) == 0){ strcpy(suffix, ".None"); } printf("FILE %d %" PRId64 " %s %s\n", item->fid, item->fsize, item->fname, suffix); }while((elem = g_list_next(elem))); } g_hash_table_destroy(hashset); return 0; }
/* Calculates Blockhashes in a simple loop. */ int bitcoin_simple() { printf("Starting bitcoin_simple\n"); // Start, end time unsigned long start,end; // Set start time start = current_time_millis(); // Creates and retrieves the Block-Header information Blockheader * blockheader = malloc(sizeof(Blockheader)); // The getWork method fills an empty Blockheader struct with all the neccesary information needed to calcualte the Hash of a Block. getWork(blockheader); // The nonce is the value that is incremented in each run to get a different hash value char * n = malloc(sizeof(char)*4); memcpy(n,&(blockheader->nonce),sizeof(char)*4); // The values in the Blockheader are actually in reverse byte order and need to be reversed in order to increment the nonce value. byte_reversal(n,sizeof(char)*4); // Convert the 4 byte long raw data into an unsinged long unsigned long starting_nonce = n[0] << 24 | n[1] << 16 | n[2] << 8 | n[3]; // The nonce value we received in the getWork method is the actual starting nonce value. We start to calculate hashes with this initial nonce and increase it by one in each run. unsigned long nonce = starting_nonce; char * hash; // In practice it is very hard to find a valid hash, so in this exercise we will limit the amount of hashes we calculate. for(;nonce<=(starting_nonce+MAX_HASHES);nonce++) { // put current nonce in blockheader object // first, shift long back to char[4] n[0] = nonce >> 24; n[1] = nonce >> 16; n[2] = nonce >> 8; n[3] = nonce; // reverse byte order byte_reversal(n,sizeof(char)*4); // put n into blockheader blockheader->nonce[0] = n[0]; blockheader->nonce[1] = n[1]; blockheader->nonce[2] = n[2]; blockheader->nonce[3] = n[3]; // calculate the hash using the sha-256 hashing algorithm size_t size = getData(blockheader,&hash); size = sha256_digest(hash,size,&hash); // To calculate a valid hash, we need to do two hashing passes size = sha256_digest(hash,size,&hash); if(check_hash(hash,(int)size)) { printf("%ld : ", nonce); print_hash(hash,size); } } end = current_time_millis(); printf("Calculation finished after %.3fs\n", (double) (end - start) / 1000); free(blockheader); return EXIT_SUCCESS; }
static int verify_existence(struct starsystem_info *ss, int should_already_exist) { unsigned char pwdhash[20]; unsigned char buffer[200]; struct packed_buffer *pb; int i, rc; unsigned char pass; unsigned char printable_hash[100]; int send_update = 0; fprintf(stderr, "snis_multiverse: verify_existence 1: should %salready exist\n", should_already_exist ? "" : "not "); rc = read_and_unpack_fixed_size_buffer(ss, buffer, 20, "r", pwdhash, (uint16_t) 20); if (rc != 0) return rc; snis_format_sha1_hash(pwdhash, printable_hash, 100); printable_hash[40] = '\0'; pthread_mutex_lock(&data_mutex); fprintf(stderr, "snis_multiverse: lookup hash %s\n", printable_hash); i = lookup_ship_by_hash(pwdhash); fprintf(stderr, "snis_multiverse: verify existence pwdhash lookup returns %d\n", i); if (i < 0) { if (should_already_exist) { /* It doesn't exist, but it should */ fprintf(stderr, "snis_multiverse: hash %s does not exist, but should.\n", printable_hash); pass = SNISMV_VERIFICATION_RESPONSE_FAIL; } else { /* doesn't exist, but we asked to create it, so that is expected */ fprintf(stderr, "snis_multiverse: hash %s does not exist, as expected.\n", printable_hash); pass = SNISMV_VERIFICATION_RESPONSE_PASS; rc = create_new_ship(pwdhash); if (rc) /* We failed to create it. */ pass = SNISMV_VERIFICATION_RESPONSE_TOO_MANY_BRIDGES; } } else { /* It exists, pass if it should exist, fail otherwise */ if (should_already_exist) { fprintf(stderr, "snis_multiverse: hash %s exists, as expected.\n", printable_hash); pass = SNISMV_VERIFICATION_RESPONSE_PASS; send_update = 1; } else { fprintf(stderr, "snis_multiverse: hash %s exists, but should not.\n", printable_hash); pass = SNISMV_VERIFICATION_RESPONSE_FAIL; } } print_hash("checking hash ", pwdhash); fprintf(stderr, "snis_multiverse: verify existence pass=%d\n", pass); pthread_mutex_unlock(&data_mutex); pb = packed_buffer_allocate(22); packed_buffer_append(pb, "bbr", SNISMV_OPCODE_VERIFICATION_RESPONSE, pass, pwdhash, 20); packed_buffer_queue_add(&ss->write_queue, pb, &ss->write_queue_mutex); if (send_update) send_bridge_update_to_snis_server(ss, pwdhash); return 0; }
void initSymbolTable() { gbl_value_true = hash_add(SYMBOL_LITERAL_BOOL, CODEGEN_VAL_TRUE); gbl_value_false = hash_add(SYMBOL_LITERAL_BOOL, CODEGEN_VAL_FALSE); gbl_format_d = hash_add(SYMBOL_LITERAL_STRING, CODEGEN_FORMAT_D); gbl_format_f = hash_add(SYMBOL_LITERAL_STRING, CODEGEN_FORMAT_F); gbl_format_c = hash_add(SYMBOL_LITERAL_STRING, CODEGEN_FORMAT_C); gbl_format_s = hash_add(SYMBOL_LITERAL_STRING, CODEGEN_FORMAT_S); print_hash(); }
void nhash_show(NHASH hash) { int i; for (i = 0; i < HASH_SIZE; i++) { printf("%2d: ", i); print_hash(hash[i]); printf("\n"); } }
int main( int argc, char * argv[] ) { TreeNode * syntaxTree; char pgm[120]; /* source code file name */ hash_new(&h); if (argc < 2) { fprintf(stderr,"usage: %s <filename>\n",argv[0]); exit(1); } if (argc == 3) { if(strcmp(argv[2], "-a") == 0) { TraceScan = FALSE; TraceAnalyze = FALSE; } else if(strcmp(argv[2], "-s") == 0) { TraceScan = FALSE; TraceParse = FALSE; } } strcpy(pgm,argv[1]) ; if (strchr (pgm, '.') == NULL) strcat(pgm,".cm"); source = fopen(pgm,"r"); if (source==NULL) { fprintf(stderr,"File %s not found\n",pgm); exit(1); } listing = stdout; /* send listing to screen */ fprintf(listing,"\nC Minus compilation: %s\n",pgm); #if NO_PARSE //if(a_flag == 0) while( (ttype=getToken())!= 0 ) printToken( ttype, tokenString ); #else syntaxTree = parse(); if (TraceParse) { fprintf(listing,"\nSyntax tree:\n"); printTree(syntaxTree); } if(TraceAnalyze) { fprintf(listing, "\nSymbol Table:\n"); print_hash(h); } list_kill(l); hash_kill(&h); #endif fclose(source); return 0; }
int main(int argc, char* argv[]) { unsigned char hash_buffer[EVP_MAX_MD_SIZE]; unsigned int hash_length; if(!argv[1]) { printf("Usage: mdtest digestname filename\n"); exit(1); } if(hash_file(argv[1], hash_buffer, &hash_length) == 0) { print_hash(hash_buffer, &hash_length); }else{ printf("There was an error hashing your file (%s)\n", strerror(errno)); } return 0; }
u8 patch_sdk(u32 size, u8 *ptr) { u32 i; u8 patched; patched = 0; for (i = 0 ; i < size ; i++) { if (memcmp(ptr + i, sys_proc_param, 4) == 0) { patched = 1; printf("Found at offset %08x\n", i); print_hash((ptr + i), 0x10); printf("\n"); printf("Replace %04x with %04x\n", be16(ptr+i+9), 0x3400); wbe16(ptr + i + 9, 0x3400); print_hash((ptr + i), 0x10); printf("\n"); break; } } return patched; }
/** * Main entry point for the test program. * @param argc Unused. * @param argv argv[1] contains the file to hash. * @return Returns negative on failure, zero on success. */ int main(int argc, char** argv) { char* mbsfilename = argv[1]; /* Convert the filename from char* to wchar_t* to test the * library. It's a pain, but it's designed to be called from * python, not C. */ locale_t utf8 = newlocale(LC_ALL_MASK, NULL, NULL); size_t size = mbstowcs_l(NULL, mbsfilename, 0, utf8); wchar_t* wfilename = (wchar_t*)malloc(size * sizeof(wchar_t)); size = mbstowcs_l(wfilename, mbsfilename, size, utf8); if (size == -1) { fprintf(stderr, "Error converting string.\n"); return -1; } /* Set up our hash request. */ HashRequest request; memset(&request, 0, sizeof(HashRequest)); request.tag = 15; request.filename = wfilename; request.options = OPTION_ED2K; /* Hash the file. */ int result = HashFileWithSyncIO(&request, HashCallback); /* Print the results. */ printf("\nresult: %d\n", result); if (result == 0) { print_hash(" ED2K", &request.result[0], 16); print_hash(" CRC32", &request.result[16], 4); print_hash(" MD5", &request.result[20], 16); print_hash(" SHA1", &request.result[36], 20); } return 0; }
static int update_bridge(struct starsystem_info *ss) { unsigned char pwdhash[20]; int i, rc; unsigned char buffer[250]; struct packed_buffer pb; struct snis_entity *o; #define bytes_to_read (sizeof(struct update_ship_packet) - 9 + 25 + 5 + \ sizeof(struct power_model_data) + \ sizeof(struct power_model_data) - 1 - 1) fprintf(stderr, "snis_multiverse: update bridge 1\n"); memset(buffer, 0, sizeof(buffer)); memset(pwdhash, 0, sizeof(pwdhash)); rc = read_and_unpack_fixed_size_buffer(ss, buffer, 20, "r", pwdhash, (uint16_t) 20); if (rc != 0) return rc; print_hash("update bridge 2, read 20 bytes: ", pwdhash); BUILD_ASSERT(sizeof(buffer) > bytes_to_read); memset(buffer, 0, sizeof(buffer)); rc = snis_readsocket(ss->socket, buffer, bytes_to_read); if (rc != 0) return rc; fprintf(stderr, "snis_multiverse: update bridge 3\n"); pthread_mutex_lock(&data_mutex); i = lookup_ship_by_hash(pwdhash); if (i < 0) { fprintf(stderr, "snis_multiverse: Unknown ship hash\n"); pthread_mutex_unlock(&data_mutex); return rc; } fprintf(stderr, "snis_multiverse: update bridge 4\n"); o = &ship[i].entity; if (!o->tsd.ship.damcon) { o->tsd.ship.damcon = malloc(sizeof(*o->tsd.ship.damcon)); memset(o->tsd.ship.damcon, 0, sizeof(*o->tsd.ship.damcon)); } packed_buffer_init(&pb, buffer, bytes_to_read); unpack_bridge_update_packet(o, &pb); ship[i].initialized = 1; pthread_mutex_unlock(&data_mutex); rc = 0; fprintf(stderr, "snis_multiverse: update bridge 10\n"); return rc; }
void print_trans_tok(struct trans_tok *t) { if(t == NULL) { printf("PRINTING NULL TOKEN\n"); return; } printf("TRANS TOKEN:\n"); printf("\tPAYER: "); if(t->payer != NULL) printf("%s",t->payer); else printf("NULL"); printf("\t SERIAL: %u\t VALUE: %u",t->serial, t->value); printf("\n\t"); print_hash(t->bank_sig, t->sig_len); printf("\t SIG_LEN: %u\n", t->sig_len); }
void tracker_dump_table() { int i; tracker_node *n; peer *p; for(i=0; i<TRACKER_TABLE_SIZE; i++) { if(tracker_table[i] == NULL) { continue; } for(n=tracker_table[i]; n != NULL; n = n->next) { printf("%02x: ", i); print_hash(n->file_hash); printf("%d peer(s):\n", ((n->p) ? n->p->npeers : 0)); for(p=n->p; p != NULL; p=p->next) { printf("\t%s\n", p->host); } } } }
void print_object(FILE *fp, UnionType o) { if (!fp) fp = stdout; //fprintf(stderr, "type = [%d]\n", TYPE(o)); switch (TYPE(o.o)) { case Int: fprintf(fp, "%d", (int)to_Int(o.o)); break; case Double: fprintf(fp, "%f", o.d); break; case String: fprintf(fp, "%s", (to_String(o.o))->s); break; case Array: if (fp != stdout) { _print_with_handler(fp, to_Array(o.o)); } else { print(to_Array(o.o)); } break; case ArrayRef: fprintf(fp, "ARRAY(%p)", to_Ptr(o.o)); break; case Hash: print_hash(fp, to_Hash(o.o)); break; case HashRef: fprintf(fp, "HASH(%p)", to_Ptr(o.o)); break; case CodeRef: fprintf(fp, "CODE(%p)", to_Ptr(o.o)); break; case ObjectType: { Object *object = to_Object(o.o); print_object(fp, object->v); break; } case BlessedObjectType: fprintf(fp, "%s=HASH(%p)", (to_BlessedObject(o.o))->pkg_name, to_Ptr(o.o)); break; default: break; } }