home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Mammon_ / textsearch.idc < prev    next >
Text File  |  2000-05-25  |  2KB  |  51 lines

  1. //-------------------------------------------------------------------------------------------------------
  2. //textsearch.idc: Front-end to "search for text in core" enabling you to enter strings
  3. //
  4. // code by mammon_ All rights reversed
  5. //-------------------------------------------------------------------------------------------------------
  6.  
  7. #include <idc.idc>
  8.  
  9. static main()
  10. {
  11.    auto ea, x, y, searchstr, temp_c, binstr, array_id, alphabet, bin_c, cont;
  12.    ea = FirstSeg();
  13.     // ---- Create Array Of ASCII Characters ------------------------
  14.     // ---- Note that the index of each char = its decimal value ----
  15.     array_id = CreateArray("AsciiTable");
  16.     alphabet = "0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz";
  17.     y = 48;
  18.     for (x = 0; x < strlen(alphabet); x = x + 1 ) {
  19.          SetArrayString( array_id, y, substr(alphabet, x, x+1));
  20.         y = y +1;
  21.     }
  22.     // ---- Prompt User For Search String ----------------------------
  23.     searchstr = AskStr("", "Enter a search string:\n");
  24.     // ---- Cycle through array looking for match --------------------
  25.     for (x = 0; x < strlen(searchstr); x = x + 1 ) {
  26.         temp_c = substr(searchstr, x, x + 1 );
  27.         for( y = GetFirstIndex(AR_STR, array_id); y <= GetLastIndex(AR_STR, array_id); y =  GetNextIndex(AR_STR, array_id, y) ) {
  28.             if (temp_c == GetArrayElement(AR_STR, array_id, y)) {
  29.                 bin_c = y;
  30.                 break;
  31.             }                                                        //End "If Match"
  32.         }                                                               //End Array Loop
  33.         binstr = form("%s %X", binstr, bin_c);
  34.     }                                                                //End Search String Loop
  35.     Message("Search string is " + binstr + "\n");    //Debug Control
  36.     // -------- "Search" and "Search Again" Loop... --------------------
  37.     cont = 1;
  38.     while (cont==1) {
  39.         ea = FindBinary(ea, 1, binstr);                    //Search From ea
  40.         if( ea == -1) {                                        //If No Hits
  41.             Warning("No more occurrences");                //MessageBox
  42.             cont = 0;
  43.             break;                                                //Leave
  44.         }
  45.         Jump(ea);                                            //Position Cursor At Hit
  46.         cont = AskYN( 1, "Find next occurence?" );    //Search Again?
  47.     }
  48.     // --------- Cleanup and Exit
  49.    Message("\n" + "Search Complete\n");
  50.     DeleteArray(array_id);
  51. }