| 6392 | } |
| 6393 | |
| 6394 | bool readFileAddress(char *fileName) { |
| 6395 | FILE *fileDescriptor; |
| 6396 | char fileBloomName[30]; /* Actually it is Bloom and Table but just to keep the variable name short*/ |
| 6397 | uint8_t checksum[32],hexPrefix[9]; |
| 6398 | char dataChecksum[32],bloomChecksum[32]; |
| 6399 | size_t bytesRead; |
| 6400 | uint64_t dataSize; |
| 6401 | /* |
| 6402 | if the FLAGSAVEREADFILE is Set to 1 we need to the checksum and check if we have that information already saved |
| 6403 | */ |
| 6404 | if(FLAGSAVEREADFILE) { /* if the flag is set to REAd and SAVE the file firs we need to check it the file exist*/ |
| 6405 | if(!sha256_file((const char*)fileName,checksum)){ |
| 6406 | fprintf(stderr,"[E] sha256_file error line %i\n",__LINE__ - 1); |
| 6407 | return false; |
| 6408 | } |
| 6409 | tohex_dst((char*)checksum,4,(char*)hexPrefix); // we save the prefix (last fourt bytes) hexadecimal value |
| 6410 | snprintf(fileBloomName,30,"data_%s.dat",hexPrefix); |
| 6411 | fileDescriptor = fopen(fileBloomName,"rb"); |
| 6412 | if(fileDescriptor != NULL) { |
| 6413 | printf("[+] Reading file %s\n",fileBloomName); |
| 6414 | |
| 6415 | //read bloom checksum (expected value to be checked) |
| 6416 | //read bloom filter structure |
| 6417 | //read bloom filter data |
| 6418 | //calculate checksum of the current readed data |
| 6419 | //Compare checksums |
| 6420 | //read data checksum (expected value to be checked) |
| 6421 | //read data size |
| 6422 | //read data |
| 6423 | //compare the expected datachecksum againts the current data checksum |
| 6424 | //compare the expected bloom checksum againts the current bloom checksum |
| 6425 | |
| 6426 | |
| 6427 | //read bloom checksum (expected value to be checked) |
| 6428 | bytesRead = fread(bloomChecksum,1,32,fileDescriptor); |
| 6429 | if(bytesRead != 32) { |
| 6430 | fprintf(stderr,"[E] Errore reading file, code line %i\n",__LINE__ - 2); |
| 6431 | fclose(fileDescriptor); |
| 6432 | return false; |
| 6433 | } |
| 6434 | |
| 6435 | //read bloom filter structure |
| 6436 | bytesRead = fread(&bloom,1,sizeof(struct bloom),fileDescriptor); |
| 6437 | if(bytesRead != sizeof(struct bloom)) { |
| 6438 | fprintf(stderr,"[E] Error reading file, code line %i\n",__LINE__ - 2); |
| 6439 | fclose(fileDescriptor); |
| 6440 | return false; |
| 6441 | } |
| 6442 | |
| 6443 | printf("[+] Bloom filter for %" PRIu64 " elements.\n",bloom.entries); |
| 6444 | |
| 6445 | bloom.bf = (uint8_t*) malloc(bloom.bytes); |
| 6446 | if(bloom.bf == NULL) { |
| 6447 | fprintf(stderr,"[E] Error allocating memory, code line %i\n",__LINE__ - 2); |
| 6448 | fclose(fileDescriptor); |
| 6449 | return false; |
| 6450 | } |
| 6451 |
no test coverage detected