int ReadPasswordCharset (NPKIBruteForce *bforce) { FILE *fp = NULL; long cslen = 0; // 파일 길이 cslen = ReadFileSize(bforce->pw_charset_path); if (MAX_PW_CHARSET < cslen) // 그대로 두면 Overflow 발생 -> Abort JVErrorHandle(JVERR_PW_CHARSET_TOO_LONG); // 내용을 읽는다. fp = fopen(bforce->pw_charset_path, "rt"); for (long i = 0; i < cslen; i++) bforce->pw_charset[i] = fgetc(fp); fclose(fp); // 중복되는 문자가 없는지 검사 for (long i = 0; i < cslen; i++) { // printf(""); charset_dic[(uint8_t) bforce->pw_charset[i]]++; } for (long i = 0; i < cslen; i++) { if (2 <= charset_dic[i]) return FALSE; // 검증 실패 } // 길이 저장 charset_len = strlen(bforce->pw_charset); return TRUE; }
void readfieldfrommap_() { float field[3] = {0., 0., 0.}; float *fieldPtr = field; //int printFieldToFile = 1; // if = 0 don't print to .txt file, if = 1 then print field to .txt file // Get the directory where the fieldmap is stored from the environment variable char* fieldmap_location = "/Users/YeYang/Documents/COMET/information/fieldMaps/140624/"; int iSeg = 0; for (iSeg = 0; iSeg < nSegments; ++iSeg) { char seg_map_location[120]; strcpy(seg_map_location, fieldmap_location); strcat(seg_map_location, SegNames[iSeg]); // Read in the file if it hasn't been read before if (SegMapX[iSeg] == 0 || SegMapY[iSeg] == 0 || SegMapZ[iSeg] == 0 || SegMapBx[iSeg] == 0 || SegMapBy[iSeg] == 0 || SegMapBz[iSeg] == 0) { SegFileHeaderPtr[iSeg] = &SegmentFileHeaders[iSeg]; // Find out how many lines of data there are ReadFileSize(seg_map_location, SegFileHeaderPtr[iSeg]); // Allocate enough memory for all the files SegMapX[iSeg] = malloc(SegFileHeaderPtr[iSeg]->i_max * sizeof (float)); SegMapY[iSeg] = malloc(SegFileHeaderPtr[iSeg]->i_max * sizeof (float)); SegMapZ[iSeg] = malloc(SegFileHeaderPtr[iSeg]->i_max * sizeof (float)); SegMapBx[iSeg] = malloc(SegFileHeaderPtr[iSeg]->i_max * sizeof (float)); SegMapBy[iSeg] = malloc(SegFileHeaderPtr[iSeg]->i_max * sizeof (float)); SegMapBz[iSeg] = malloc(SegFileHeaderPtr[iSeg]->i_max * sizeof (float)); // Read the data in readFile(seg_map_location, SegFileHeaderPtr[iSeg], SegMapX[iSeg], SegMapY[iSeg], SegMapZ[iSeg], SegMapBx[iSeg], SegMapBy[iSeg], SegMapBz[iSeg]); } } //printf("x=%f, y=%f, z=%f\n", rzforc_.xcc, rzforc_.ycc, rzforc_.zcc); for (iSeg = 0; iSeg < nSegments; ++iSeg) { // Only try and find field at that point if it is in the segment if (rzforc_.xcc>=SegFileHeaderPtr[iSeg]->x_min && rzforc_.xcc<=SegFileHeaderPtr[iSeg]->x_max && rzforc_.ycc>=(-SegFileHeaderPtr[iSeg]->y_max) && rzforc_.ycc<=SegFileHeaderPtr[iSeg]->y_max && rzforc_.zcc>=SegFileHeaderPtr[iSeg]->z_min && rzforc_.zcc<=SegFileHeaderPtr[iSeg]->z_max) { findFieldAtPoint(rzforc_.xcc, rzforc_.ycc, rzforc_.zcc, fieldPtr, SegMapX[iSeg], SegMapY[iSeg], SegMapZ[iSeg], SegMapBx[iSeg], SegMapBy[iSeg], SegMapBz[iSeg], SegFileHeaderPtr[iSeg]); //printf("readfieldfrommap\n pos = %f %f %f\n field = %f %f %f\n", rzforc_.xcc, rzforc_.ycc, rzforc_.zcc, field[0], field[1], field[2]); } if (iSeg == ts1) { // printf("Before: %f\n", field[1]); field[1] += 0.0561; // printf("After: %f\n", field[1]); } } //printf("R=%lf Z=%lf Br=%lf Bz= %lf \n", rzforc_.rc, rzforc_.zc, field[0], field[1]); rzforc_.bxc = field[0]; rzforc_.byc = field[1]; rzforc_.bzc = field[2]; }
/* Func: SetFilename Accept: filename - String for the filename of disk Desc: Sets the file pointer Reads the file size and last modifed time to store in the class Splits up the filename and dir path */ void CFile::SetFilename ( String filename ) { String file = filename.FindReplace ( "\\", "/" ).FindReplace ( "//", "/" ); int tok = file.NumToken ( '/' ); m_sFullDir = file.GetToken ( 1, tok - 1, '/' ); m_sName = file.GetToken ( tok, '/' ); ReadFileSize (); ReadLastModified (); }
int ReadRawNPKIPrivateKey (NPKIPrivateKey *pkey, const char* PrivateKeyPath) { FILE *fp = fopen(PrivateKeyPath, "rb"); pkey->rawkey_len = ReadFileSize(PrivateKeyPath); pkey->rawkey = (uint8_t *)malloc(pkey->rawkey_len * sizeof(uint8_t)); fread((void*) (pkey->rawkey), 1, pkey->rawkey_len, fp); #ifdef _DEBUG puts("== Private Key =="); DumpBinary(pkey->rawkey, pkey->rawkey_len); #endif return 0; }