| 6452 | |
| 6453 | |
| 6454 | bool forceReadFileXPoint(char *fileName) { |
| 6455 | /* Here we read the original file as usual */ |
| 6456 | FILE *fileDescriptor; |
| 6457 | uint64_t numberItems,i; |
| 6458 | size_t r,lenaux; |
| 6459 | uint8_t rawvalue[100]; |
| 6460 | char aux[1000],*hextemp; |
| 6461 | Tokenizer tokenizer_xpoint; //tokenizer |
| 6462 | fileDescriptor = fopen(fileName,"r"); |
| 6463 | if(fileDescriptor == NULL) { |
| 6464 | fprintf(stderr,"[E] Error opening the file %s, line %i\n",fileName,__LINE__ - 2); |
| 6465 | return false; |
| 6466 | } |
| 6467 | /*Count lines in the file*/ |
| 6468 | numberItems = 0; |
| 6469 | while(!feof(fileDescriptor)) { |
| 6470 | hextemp = fgets(aux,1000,fileDescriptor); |
| 6471 | trim(aux," \t\n\r"); |
| 6472 | if(hextemp == aux) { |
| 6473 | r = strlen(aux); |
| 6474 | if(r >= 40) { |
| 6475 | numberItems++; |
| 6476 | } |
| 6477 | } |
| 6478 | } |
| 6479 | fseek(fileDescriptor,0,SEEK_SET); |
| 6480 | |
| 6481 | MAXLENGTHADDRESS = 20; /*20 bytes beacuase we only need the data in binary*/ |
| 6482 | |
| 6483 | printf("[+] Allocating memory for %" PRIu64 " elements: %.2f MB\n",numberItems,(double)(((double) sizeof(struct address_value)*numberItems)/(double)1048576)); |
| 6484 | addressTable = (struct address_value*) malloc(sizeof(struct address_value)*numberItems); |
| 6485 | checkpointer((void *)addressTable,__FILE__,"malloc","addressTable" ,__LINE__ - 1); |
| 6486 | |
| 6487 | N = numberItems; |
| 6488 | |
| 6489 | if(!initBloomFilter(&bloom,N)) |
| 6490 | return false; |
| 6491 | |
| 6492 | i= 0; |
| 6493 | while(i < N) { |
| 6494 | memset(aux,0,1000); |
| 6495 | hextemp = fgets(aux,1000,fileDescriptor); |
| 6496 | memset((void *)&addressTable[i],0,sizeof(struct address_value)); |
| 6497 | if(hextemp == aux) { |
| 6498 | trim(aux," \t\n\r"); |
| 6499 | stringtokenizer(aux,&tokenizer_xpoint); |
| 6500 | hextemp = nextToken(&tokenizer_xpoint); |
| 6501 | lenaux = strlen(hextemp); |
| 6502 | if(isValidHex(hextemp)) { |
| 6503 | switch(lenaux) { |
| 6504 | case 64: /*X value*/ |
| 6505 | r = hexs2bin(aux,(uint8_t*) rawvalue); |
| 6506 | if(r) { |
| 6507 | memcpy(addressTable[i].value,rawvalue,20); |
| 6508 | bloom_add(&bloom,rawvalue,MAXLENGTHADDRESS); |
| 6509 | } |
| 6510 | else { |
| 6511 | fprintf(stderr,"[E] error hexs2bin\n"); |
no test coverage detected