MCPcopy Create free account
hub / github.com/albertobsd/keyhunt / readFileAddress

Function readFileAddress

keyhunt.cpp:6131–6299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6129}
6130
6131bool readFileAddress(char *fileName) {
6132 FILE *fileDescriptor;
6133 char fileBloomName[30]; /* Actually it is Bloom and Table but just to keep the variable name short*/
6134 uint8_t checksum[32],hexPrefix[9];
6135 char dataChecksum[32],bloomChecksum[32];
6136 size_t bytesRead;
6137 uint64_t dataSize;
6138 /*
6139 if the FLAGSAVEREADFILE is Set to 1 we need to the checksum and check if we have that information already saved
6140 */
6141 if(FLAGSAVEREADFILE) { /* if the flag is set to REAd and SAVE the file firs we need to check it the file exist*/
6142 if(!sha256_file((const char*)fileName,checksum)){
6143 fprintf(stderr,"[E] sha256_file error line %i\n",__LINE__ - 1);
6144 return false;
6145 }
6146 tohex_dst((char*)checksum,4,(char*)hexPrefix); // we save the prefix (last fourt bytes) hexadecimal value
6147 snprintf(fileBloomName,30,"data_%s.dat",hexPrefix);
6148 fileDescriptor = fopen(fileBloomName,"rb");
6149 if(fileDescriptor != NULL) {
6150 printf("[+] Reading file %s\n",fileBloomName);
6151
6152 //read bloom checksum (expected value to be checked)
6153 //read bloom filter structure
6154 //read bloom filter data
6155 //calculate checksum of the current readed data
6156 //Compare checksums
6157 //read data checksum (expected value to be checked)
6158 //read data size
6159 //read data
6160 //compare the expected datachecksum againts the current data checksum
6161 //compare the expected bloom checksum againts the current bloom checksum
6162
6163
6164 //read bloom checksum (expected value to be checked)
6165 bytesRead = fread(bloomChecksum,1,32,fileDescriptor);
6166 if(bytesRead != 32) {
6167 fprintf(stderr,"[E] Errore reading file, code line %i\n",__LINE__ - 2);
6168 fclose(fileDescriptor);
6169 return false;
6170 }
6171
6172 //read bloom filter structure
6173 bytesRead = fread(&bloom,1,sizeof(struct bloom),fileDescriptor);
6174 if(bytesRead != sizeof(struct bloom)) {
6175 fprintf(stderr,"[E] Error reading file, code line %i\n",__LINE__ - 2);
6176 fclose(fileDescriptor);
6177 return false;
6178 }
6179
6180 printf("[+] Bloom filter for %" PRIu64 " elements.\n",bloom.entries);
6181
6182 bloom.bf = (uint8_t*) malloc(bloom.bytes);
6183 if(bloom.bf == NULL) {
6184 fprintf(stderr,"[E] Error allocating memory, code line %i\n",__LINE__ - 2);
6185 fclose(fileDescriptor);
6186 return false;
6187 }
6188

Callers 1

keyhunt.cppFile · 0.70

Calls 7

tohex_dstFunction · 0.85
sha256_fileFunction · 0.70
sha256Function · 0.70
processOneVanityFunction · 0.70
forceReadFileAddressFunction · 0.70
forceReadFileAddressEthFunction · 0.70
forceReadFileXPointFunction · 0.70

Tested by

no test coverage detected