void a7800_partialhash(char *dest, const unsigned char *data, unsigned long length, unsigned int functions) { if (length <= 128) return; hash_compute(dest, &data[128], length - 128, functions); }
/* Her elemani bir bagli liste gostericisi olan table * dizisi parametre olarak veriliyor. Bu table dizisi * aslinda hash veriyapisini temsil eder. * * str ile verilen string hash'te var ise adresi * dondurulur. Yoksa ve create == 1 ise, hash * veriyapisina bu string eklenir.*/ Key* hash_lookup(Key **table, const char *str, int create) { /* TODO 1 */ int n=hash_compute(str); if(table[n]!=NULL){ struct key *tmp=table[n]; while(tmp->next!=NULL){ if(tmp->word==str){ return tmp; } tmp=tmp->next; } } /* Bulunmazsa eklensin mi? */ if (create) { /* TODO 2 */ struct key *tmp=malloc(sizeof(Key)); tmp->word=strdup(str); tmp->next=table[n]; table[n]=tmp; return tmp; } return NULL; }
static int run_hash(mess_image *image, void (*partialhash)(char *, const unsigned char *, unsigned long, unsigned int), char *dest, unsigned int hash_functions) { UINT32 size; UINT8 *buf = NULL; *dest = '\0'; size = (UINT32) image_length(image); buf = (UINT8 *) malloc(size); if (!buf) return FALSE; /* read the file */ image_fseek(image, 0, SEEK_SET); image_fread(image, buf, size); if (partialhash) partialhash(dest, buf, size, hash_functions); else hash_compute(dest, buf, size, hash_functions); /* cleanup */ if (buf) free(buf); image_fseek(image, 0, SEEK_SET); return TRUE; }
static void identify_data(const char *name, const UINT8 *data, int length, romident_status *status) { char hash[HASH_BUF_SIZE]; UINT8 *tempjed = NULL; astring *basename; int found = 0; jed_data jed; /* if this is a '.jed' file, process it into raw bits first */ if (core_filename_ends_with(name, ".jed") && jed_parse(data, length, &jed) == JEDERR_NONE) { /* now determine the new data length and allocate temporary memory for it */ length = jedbin_output(&jed, NULL, 0); tempjed = malloc(length); if (tempjed == NULL) return; /* create a binary output of the JED data and use that instead */ jedbin_output(&jed, tempjed, length); data = tempjed; } /* compute the hash of the data */ hash_data_clear(hash); hash_compute(hash, data, length, HASH_SHA1 | HASH_CRC); /* output the name */ status->total++; basename = core_filename_extract_base(astring_alloc(), name, FALSE); mame_printf_info("%-20s", astring_c(basename)); astring_free(basename); /* see if we can find a match in the ROMs */ match_roms(hash, length, &found); /* if we didn't find it, try to guess what it might be */ if (found == 0) { /* if not a power of 2, assume it is a non-ROM file */ if ((length & (length - 1)) != 0) { mame_printf_info("NOT A ROM\n"); status->nonroms++; } /* otherwise, it's just not a match */ else mame_printf_info("NO MATCH\n"); } /* if we did find it, count it as a match */ else status->matches++; /* free any temporary JED data */ if (tempjed != NULL) free(tempjed); }