int main(){ String s; char* str; init_string( &s ); copy_str( s, "Hello world..." ); print_string( s ); putchar( '\n' ); concat_str( s, " my name is Blur." ); print_string( s ); putchar( '\n' ); copy_str( s, "Hi" ); print_string( s ); putchar( '\n' ); printf( "Is it equal to hi? %d\n", compare_str( s, "hi" ) ); printf( "Is it equal to Hi? %d\n", compare_str( s, "Hi" ) ); printf( "Is it equal to hello? %d\n", compare_str( s, "hello" ) ); printf( "Is it equal to Hello? %d\n", compare_str( s, "Hello" ) ); str = to_c_str( s ); printf( "%s\n", str ); free( str ); clear_string( &s ); return 0; }
int main() { compare_str("h*llo", "heeello"); compare_str("How*are you?", "How the f**k are you?"); compare_str("h*llo", "hlo"); compare_str("D*ck", "Dick"); compare_str("D*ckie\*", "Dickie*"); return 0; }
/* --------------------------------------------------------------------------- decode one entry ---------------------------------------------------------------------- */ void CTIesrDict::decode_entry( char *word, int idx, char *pron ) { char buf[ MAX_STR ]; char pron_def[ MAX_PRON ]; int idx2, i; for( i = 0; i < pron[0] + 1; i++ ) pron_def[i] = pron[i]; /* go up, may be more than one entry, find the first entry of this word */ idx2 = idx; idx2 = dec_entry( idx2 ); if( idx2 >= first ) { buf[0] = '\0'; expand_str( buf, idx2 ); } while( ( idx2 >= first ) && compare_str( word, buf ) == 0 ) { idx = idx2; idx2 = dec_entry( idx2 ); if( idx2 >= first ) { buf[0] = '\0'; expand_str( buf, idx2 ); } } /* go down, starting from first entry of this word */ idx2 = idx; buf[0] = '\0'; expand_str( buf, idx2 ); while( ( idx2 <= last ) && compare_str( word, buf ) == 0 ) { print_pron( word, idx2, pron_def, pron ); return; /* only the first pron, discard multiple pron */ idx2 = inc_entry( idx2 ); if( idx2 <= last ) { buf[0] = '\0'; expand_str( buf, idx2 ); } } }
/* --------------------------------------------------------------------------- dictionary lookup, binary search, it returns: index: first <= index <= last -1: not found ---------------------------------------------------------------------- */ int CTIesrDict::lookup( char *word ) { int idx, icompare, imax, imin; char buf[ MAX_STR ]; imax = last; imin = first; while( imax >= imin ) { idx = mid_entry( imin, imax ); buf[0] = '\0'; expand_str( buf, idx ); icompare = compare_str( word, buf ); if( icompare == 0 ) { return idx; } else if( icompare > 0 ) { imin = inc_entry( idx ); } else { imax = dec_entry( idx ); } } return -1; }
/* Begin OpenMP dynamic scheduling. * Sets chunk_size to chunks. Has no need for slice index * due to the dynamic scheduling. * */ void begin_dynamic_omp(int chunks, char* relative_path_to_output) { int th_id; int found_it = 0; #pragma omp parallel for schedule(dynamic, chunks) shared (str_list, chunks, found_it) private(th_id) for (int i = 0; i < 100000; i++) { th_id = omp_get_thread_num(); compare_str(i, th_id, &found_it, -1, relative_path_to_output, 'B'); } fail_to_find(found_it, relative_path_to_output, 'B'); }
/* Begin OpenMP static scheduling. * Sets chunk_size to chunks and tracks slice_index for each thread. * Slice_index is dec by 1 when comparing because it starts from 1, * as 0%n, n%n, etc will increment the first slice index to 1. * */ void begin_static_omp(int chunks, char* relative_path_to_output) { int slice_index=0; int th_id; int found_it = 0; #pragma omp parallel for schedule(static, chunks) shared (str_list, chunks, found_it) private(th_id, slice_index) for (int i = 0; i < 100000; i++) { th_id = omp_get_thread_num(); if (i%chunks == 0) slice_index++; compare_str(i, th_id, &found_it, slice_index-1, relative_path_to_output, 'A'); } fail_to_find(found_it, relative_path_to_output, 'A'); }
/*** * Function accepts three arguments. 1. String[] (word) to insert extracted line * into. 2. String[] (salt), holding the salt key extracted from encrypted * password provided at execution of program. 3. String[] (encrypted_pwd) * encrypted password provided at execution of program argv[]. The function * calls four two functions. 1. crypt to encrypt the current brute force string * and salt into temp_encrypt. 2. compare_strings which compares if argument 3 * matches the temp_encrypt string. If the match the program has found the * password.. */ void brute_match(char word[], char slt[], char encrypted_pwd[]) { char *temp_encrypt; if ( match == true ) return; temp_encrypt = crypt(word, slt); if ( compare_str(temp_encrypt, encrypted_pwd) == 0 ) { printf("PASSWORD MATCH IS: %s\n", word); match = true; return; } }
char *find_substr(char *main, char *substr) { char *ptr = NULL; while (main) { if (*main == '\n') { break; } if (*substr == *main) { ptr = compare_str(main, substr); if (ptr) { return ptr; } } main++; } return ptr; }
int is_palindrome(char *str) { int check, length; char *reverse; length = str_length(str); reverse = (char*)malloc(length+1); copy_str(reverse, str); reverse_str(reverse); check = compare_str(str, reverse); free(reverse); if ( check == 0 ) return 1; else return 0; }
//--------------------------------------------------------------------------- boolean safe_palindrome( const int dw_palindrome ) { int max_bits; bit_max( max_bits ); //two buffers char forward_text[max_bits + 1]; char reverse_text[max_bits + 1]; //make into str representation int_to_str( forward_text , dw_palindrome ); memcpy( (void*) reverse_text , forward_text , max_bits + 1 ); //reverse string str_reverse( forward_text ); //compare return compare_str( forward_text , reverse_text ); }
/* * Function accepts five arguments. 1. String[] (word) to insert extracted line * into. 2. String[] (salt), holding the salt key extracted from encrypted * password provided at execution of program. 3. String[] (encrypted_pwd) * encrypted password provided at execution of program argv[]. 4. File to read * line from. The function calls six functions. 1. file_line_to_str, which * searches a file list of words, extracts each word into a string. 2. * insert_null. 3. crypt to encrypt the extracted word and salt into * temp_encrypt. 4. compare_strings which compares if argument 3 matches the * temp_encrypt string. If the match the program has found the password. 5. feof * to check if EOF has been reached. 6. brute_sequential to activate the brute * force algorithm. If the match the program has found the password. */ void encryption_match(char word[], char slt[], char encrypted_pwd[], FILE *fptr_words) { void insert_null(char str[]); void brute_sequential(int max_len, char slt[], char encrypted_pwd[]); void file_line_to_str(long int line, char str[], FILE*); printf("\n***DICTIONARY ATTACK RUNNING***\n"); while ( match == false ) { long int line = 1; char *temp_encrypt; /* executes if the dictionary attack did not yield a matching encrypted password. In a later version, a brute force attack will be placed prior to the execution of this code. */ if ( feof(fptr_words) ) { printf("Dictionary attack failed to locate a match. \n\n*** BRUTE" "FORCE ATTACK RUNNING***\n"); brute_sequential(8, slt, encrypted_pwd); break; } file_line_to_str(line, word, fptr_words); insert_null(word); temp_encrypt = crypt(word, slt); if ( compare_str(temp_encrypt, encrypted_pwd) == 0 ) { ++line; printf("PASSWORD MATCH IS: %s\n", word); match = true; } } }
DB_ATTR_TYPE compare_dbline(db_line* l1,db_line* l2,DB_ATTR_TYPE ignorelist) { #define easy_compare(a,b) \ if (!(a&ignorelist)) {\ if(l1->b!=l2->b){\ ret|=a;\ }\ } #define easy_md_compare(a,b,c) \ if (!(a&ignorelist)) { \ if(compare_md_entries(l1->b,l2->b,\ c)==RETFAIL){ \ ret|=a; \ } \ } DB_ATTR_TYPE ret=0; if (!(DB_FTYPE&ignorelist)) { if ((DB_FTYPE&l1->attr && DB_FTYPE&l2->attr) && get_file_type_char(l1->perm)!=get_file_type_char(l2->perm)) { ret|=DB_FTYPE; } } if (!(DB_LINKNAME&ignorelist)) { if(compare_str(l1->linkname, l2->linkname)){ ret|=DB_LINKNAME; } } if (!(DB_SIZEG&ignorelist)) { if ((DB_SIZEG&l1->attr && (DB_SIZEG&l2->attr)) && l1->size>l2->size){ ret|=DB_SIZEG; } } if (!(DB_SIZE&ignorelist)) { if ((DB_SIZE&l1->attr && DB_SIZE&l2->attr) && l1->size!=l2->size){ ret|=DB_SIZE; } } easy_compare(DB_BCOUNT,bcount); if (!(DB_PERM&ignorelist)) { if (DB_PERM&l1->attr && DB_PERM&l2->attr && l1->perm!=l2->perm) { ret|=DB_PERM; } } else { error(0,"Ignoring permissions\n"); } easy_compare(DB_UID,uid); easy_compare(DB_GID,gid); easy_compare(DB_ATIME,atime); easy_compare(DB_MTIME,mtime); easy_compare(DB_CTIME,ctime); if (!(DB_INODE&ignorelist)) { if ((DB_INODE&l1->attr && DB_INODE&l2->attr) && (l1->inode!=l2->inode)){ ret|=DB_INODE; } } easy_compare(DB_LNKCOUNT,nlink); easy_md_compare(DB_MD5,md5,HASH_MD5_LEN); error(255,"Debug, %s, %p %p %llx %llx\n", l1->filename,l1->md5,l2->md5,ret&DB_MD5,ignorelist); easy_md_compare(DB_SHA1,sha1,HASH_SHA1_LEN); easy_md_compare(DB_RMD160,rmd160,HASH_RMD160_LEN); easy_md_compare(DB_TIGER,tiger,HASH_TIGER_LEN); easy_md_compare(DB_SHA256,sha256,HASH_SHA256_LEN); easy_md_compare(DB_SHA512,sha512,HASH_SHA512_LEN); #ifdef WITH_MHASH easy_md_compare(DB_CRC32,crc32,HASH_CRC32_LEN); easy_md_compare(DB_HAVAL,haval,HASH_HAVAL256_LEN); easy_md_compare(DB_GOST,gost,HASH_GOST_LEN); easy_md_compare(DB_CRC32B,crc32b,HASH_CRC32B_LEN); easy_md_compare(DB_WHIRLPOOL,whirlpool,HASH_WHIRLPOOL_LEN); #endif #ifdef WITH_ACL if (!(DB_ACL&ignorelist)) { if(compare_acl(l1->acl,l2->acl)) { ret|=DB_ACL; } } #endif if (!(DB_XATTRS&ignorelist)) { if(compare_xattrs(l1->xattrs,l2->xattrs)) { ret|=DB_XATTRS; } } #ifdef WITH_E2FSATTRS easy_compare(DB_E2FSATTRS,e2fsattrs); #endif if (!(DB_SELINUX&ignorelist)) { if(compare_str(l1->cntx,l2->cntx)) { ret|=DB_SELINUX; } } return ret; }
int START_HERE(int argc,char *argv[]) { /* Byte Order This code is just for little-endian :( */ int word = 1; char *p =(char*) & word ; if(p[0] == 1){ printf("Is Little Endian\n"); } else { printf("Is Big Endian STOP ...\n"); exit(0); } if(argc <= 1 ){ ak_usage(); return 0; } /* Bootstrap */ if(compare_str(argv[1] , "-bs" )){ /*Is big ?.. > 512*/ b_strap_sz(argv[2]); printf(" %s -> %s \n",argv[2],argv[3]); char code_mbr[RUTINE_OCT]; int file_d = open (argv[2], O_RDONLY ); /* Return the file descriptor */ /* Read 440 B and save in code_mbr */ error_r( read(file_d, code_mbr, RUTINE_OCT ) , argv[2] ); close(file_d); char buff_mag[2]= { 0x55, 0xaa } ; int fd = open (argv[3], O_WRONLY ); lseek (fd,0 , SEEK_SET ); error_w( write(fd, code_mbr, RUTINE_OCT ),argv[3] ); /* Write magic */ lseek (fd ,510, SEEK_SET ); error_w( write(fd, buff_mag, 2 ), argv[3] ); close(file_d); return 0; } /* Write BOOT_LOADER */ if( compare_str(argv[1] , "-ak" )){ printf(" %s -> %s \n",argv[2],argv[3]); char buffer_lb_loader[AKERNELLOADER_SZ ]; /* Buffer */ int fd_lb_loader = open (argv[2], O_RDONLY ); /* Return the file descriptor */ /* Read size( AKERNELLOADER_SZ ) and save in buffer */ error_r( read(fd_lb_loader, buffer_lb_loader, AKERNELLOADER_SZ ) , argv[2] ); close(fd_lb_loader); int fd_transfer = open (argv[3], O_WRONLY ); lseek (fd_transfer ,512, SEEK_SET ); error_w( write(fd_transfer, buffer_lb_loader,AKERNELLOADER_SZ ), argv[3] ); close(fd_lb_loader); return 0; } if( compare_str(argv[1] , "-v" )){ puts("Akernelloader version:"_ak_version); return 0; } ak_usage(); /* help */ }
/*////////////////////////*/ unsigned int __stdcall recv_thread(void *a) { WSADATA wsaData; int len; char recv_buf[RECVSIZE]; int nBytesRecv; HANDLE Th; //message char msg[] ="connected\n"; char msg_notstarted[] ="Error;detection is not started"; char msg_start[]="Ack;Start"; char msg_stop[]="Ack;Stop"; char msg_running[]="Ack;Status detection running"; char msg_notrunning[]="Ack;Status detection is not running"; char msg_invalid[]="Invalid Command"; // winsock2の初期化 WSAStartup(MAKEWORD(2,0), &wsaData); // ソケットの作成 sock0 = socket(AF_INET, SOCK_STREAM, 0); // ソケットの設定 addr.sin_family = AF_INET; addr.sin_port = htons(12345); addr.sin_addr.S_un.S_addr = INADDR_ANY; bind(sock0, (struct sockaddr *)&addr, sizeof(addr)); // TCPクライアントからの接続要求を待てる状態にする listen(sock0, 5); // TCPクライアントからの接続要求を受け付ける len = sizeof(client); printf("接続待ち"); sock = accept(sock0, (struct sockaddr *)&client, &len); system("cls"); send(sock,msg,strlen(msg), 0); printf("接続完了\n"); memset(recv_buf,0,sizeof(recv_buf)); while(recv_thread_flag){ nBytesRecv = recv(sock,recv_buf,sizeof(recv_buf),0); recv_buf[nBytesRecv] = '\0'; printf("受信:%s",recv_buf); if(compare_str(recv_buf, "end") == 1){ printf("切断\n"); break; }else if(compare_str(recv_buf,"start")==1){ if(detect_thread_flag==0){ detect_thread_flag=1; Th = (HANDLE)_beginthreadex(NULL, 0, detect, NULL, 0, NULL); send(sock,msg_start,strlen(msg_start), 0); printf("検出開始\n"); }else{ send(sock,msg_notstarted,strlen(msg_running), 0); } }else if(compare_str(recv_buf,"stop")==1){ if(detect_thread_flag==1){ detect_thread_flag=0; send(sock,msg_stop,strlen(msg_stop), 0); printf("検出停止\n"); }else{ send(sock,msg_notstarted,strlen(msg_notstarted), 0); } }else if(compare_str(recv_buf,"status")==1){ if(detect_thread_flag==0){ send(sock,msg_notrunning,strlen(msg_notrunning), 0); printf("%s\n",msg_notrunning); }else{ send(sock,msg_running,strlen(msg_running), 0); printf("%s\n",msg_running); } }else if(recv_buf[0]==0){ //printf("無効なコマンド受信\n"); /// break; } memset(recv_buf,0,sizeof(recv_buf)); Sleep(100); } // TCPセッションの終了 closesocket(sock); // winsock2の終了処理 WSACleanup(); recv_thread_flag=0; return 0; }
/*---------------------------------------------------------------- LocatePron This function locates the one-based Nth pronunciation for a word in the dictionary. N is specified by the argument aEntryNumber. This function returns the byte entry location in the dictionary if the Nth pronunciation for the word exists, otherwise it returns 0. ----------------------------------------------------------------*/ int CTIesrDict::LocatePron( char* aWord, unsigned int aEntryNumber ) { int startLocation; int pronLocation; char dictWord[MAX_STR]; unsigned int entryNumber; int noMatch; char *ucWord; // User should not request the zeroth entry. if( aEntryNumber == 0 ) return 0; try { ucWord = new char[ strlen( aWord ) + 1]; } catch( std::bad_alloc &ex ) { return 0; } strcpy( ucWord, aWord ); chrtoupper( ucWord ); #ifdef _TIESRDICT_USE_TIESRDT if( doLetterMap ) { CTIesrDict::Errors error = map_dt_letters( ucWord ); if( error != ErrNone ) { delete [] ucWord; return 0; } } #endif // Check for existence of the word in the dictionary startLocation = lookup( ucWord ); if( startLocation == -1 ) { delete []ucWord; return 0; } // Found an entry for the word in the dictionary. // Search backward in dictionary to find the first entry of this word. noMatch = 0; while( !noMatch && startLocation > first ) { // Go to prior entry location in dictionary pronLocation = dec_entry( startLocation ); // Prior word at the entry location dictWord[0] = '\0'; expand_str( dictWord, pronLocation ); // If the dictionary word matches the word we want, then continue searching backward noMatch = compare_str( ucWord, dictWord ); if( !noMatch ) { startLocation = pronLocation; } } // If user wants the first entry, it is the present one if( aEntryNumber == 1 ) { delete [] ucWord; return startLocation; } // User wants an entry number > 1 for the word. // Try searching forward for the entry number the user wants entryNumber = 1; noMatch = 0; while( !noMatch && startLocation < last ) { // Go to next entry location in dictionary pronLocation = inc_entry( startLocation ); // Word at the present entry location dictWord[0] = '\0'; expand_str( dictWord, pronLocation ); // If the dictionary word matches the word wanted then increment count // and determine if it is the entry number wanted noMatch = compare_str( ucWord, dictWord ); if( !noMatch ) { entryNumber++; // Return this entry, which is the entry number wanted if( entryNumber == aEntryNumber ) { delete [] ucWord; return pronLocation; } // Continue searching, have not found desired entry number yet startLocation = pronLocation; } else { // No more words match, and the wanted entry has not been found delete [] ucWord; return 0; } } // Did not find the wanted entry number for the wanted word delete [] ucWord; return 0; }
/*---------------------------------------------------------------- GetNumberEntries Get the number of entries in the dictionary for a word specified by aWord. Note that this does NOT include the rule-based default pronunciation, only the number of pronunciations in the dictionary. Hence the number returned in aNumberEntries can be zero. ----------------------------------------------------------------*/ CTIesrDict::Errors CTIesrDict::GetNumberEntries( const char* aWord, unsigned int *aNumberEntries ) { int startLocation; int pronLocation; int noMatch; char dictWord[MAX_STR]; char *ucWord; int numEntries; CTIesrDict::Errors error; *aNumberEntries = 0; numEntries = 0; // convert the word to upper case. try { ucWord = new char[ strlen( aWord ) + 1]; } catch( std::bad_alloc &ex ) { return ErrMemory; } strcpy( ucWord, aWord ); chrtoupper( ucWord ); #ifdef _TIESRDICT_USE_TIESRDT // Convert word to indices if using TIesrDT and letter value >127 if( doLetterMap ) { error = map_dt_letters( ucWord ); if( error != ErrNone ) { delete [] ucWord; return error; } } #endif // Check for existence of the word in the dictionary startLocation = lookup( ucWord ); if( startLocation == -1 ) { delete [] ucWord; return ErrNone; } // Found an entry in the dictionary numEntries++; pronLocation = startLocation; noMatch = 0; // Search backward in dictionary to find all prior entries that match while( !noMatch && pronLocation > first ) { // Go to prior entry location in dictionary pronLocation = dec_entry( pronLocation ); // Prior word at the entry location dictWord[0] = '\0'; expand_str( dictWord, pronLocation ); // If the dictionary word matches the word we want, then increment count noMatch = compare_str( ucWord, dictWord ); if( !noMatch ) { numEntries++; } } // Look forward in the dictionary for subsequent matching entries pronLocation = startLocation; noMatch = 0; while( !noMatch && pronLocation < last ) { // Go to next entry location in dictionary pronLocation = inc_entry( pronLocation ); // Prior word at the entry location dictWord[0] = '\0'; expand_str( dictWord, pronLocation ); // If the dictionary word matches the word we want then increment count noMatch = compare_str( ucWord, dictWord ); if( !noMatch ) { numEntries++; } } *aNumberEntries = numEntries; delete [] ucWord; return ErrNone; }