int search_pattern_double(char * string_x ,char * string_y , int chess_flag) { if ( search_pattern(string_x ,string_y,chess_flag)) return 1; else if (search_pattern(string_y ,string_x,chess_flag)) return 1; else return 0; }
int main (int argc, char *argv []) { progname = argv[0]; if (argc < 3) usage (); get_pattern (argc - 2, argv + 2); inputname = argv[1]; inputfd = open (inputname, O_RDONLY); if (inputfd == -1) { fprintf (stderr, "%s: cannot open '%s'\n", progname, inputname); exit (3); } filesize = get_filesize (inputfd); madr = mmap (0, filesize, PROT_READ, MAP_PRIVATE, inputfd, 0); if (madr == MAP_FAILED) { fprintf (stderr, "mmap error = %d\n", errno); close (inputfd); exit (4); } search_pattern (); if (munmap (madr, filesize)) fprintf (stderr, "munmap error = %d\n", errno); if (close (inputfd)) fprintf (stderr, "%s: error %d closing '%s'\n", progname, errno, inputname); fprintf (stderr, "number of pattern matches = %d\n", num_matches); if (num_matches == 0) firstloc = ~0; printf ("%ld\n", firstloc); fprintf (stderr, "%ld\n", firstloc); exit (num_matches ? 0 : 2); }
int main(int argc, char *argv[]) { if (argc != 2) { std::cout << "Usage: batch_deobfuscate.exe batch_file" << std::endl; return 0; } std::string ifile, ofile; try { ifile = argv[1]; ofile = ifile + ".decrypted"; std::ifstream ifs(ifile); if (!ifs.is_open()) throw std::runtime_error("Can't open " + ifile + " for reading"); std::ofstream ofs(ofile); if (!ofs.is_open()) throw std::runtime_error("Can't open " + ofile + " for writing"); std::string content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); ifs.close(); std::smatch found; std::regex search_pattern("^set\\s([^\\s%]+?)=(.+)$"), replace_pattern; std::map<std::string, std::string> env_variables; size_t offset = 0; std::string search_substring = content.substr(offset); while (std::regex_search(search_substring, found, search_pattern)) { if (found.size() < 3) break; offset += found.position(2); env_variables[found[1]] = found[2]; for (auto it = env_variables.cbegin(); it != env_variables.cend(); ++it) { replace_pattern.assign("%" + (*it).first + "%"); content = std::regex_replace(content, replace_pattern, (*it).second); } search_substring = content.substr(offset); } ofs << content; ofs.close(); std::cout << "Done! Check " << ofile << std::endl; std::getchar(); } catch (const std::exception& e) { std::cout << e.what() << std::endl; std::getchar(); return -1; } return 0; }
/**************************************************************** * * * cherche une chaŒne * * * ****************************************************************/ void search_secteur(windowptr thewin, boolean diff_majmin, boolean start_to_end) { char *buffer, *buffer_frontiere; OBJECT *search = Dialog[WAIT].tree; int taille, start; long secteur = thewin -> fonction.secteur.secteur, max = thewin -> fonction.secteur.max; int width, i; char *secteur_text; char pattern[SEARCH_PATTERN_SIZE]; long offset; int size_buff_sect; int dummy; #ifndef TEST_VERSION if (thewin -> fonction.secteur.dirty && write_secteur(thewin, MENU_DEPLACEMENT)) return; #endif thewin -> fonction.secteur.dirty = FALSE; /* attend la fin des redessins */ Event_Timer(0, 0, TRUE); search[WAIT_MESSAGE].ob_spec.free_string = Messages(SEARCH_2); search[WAIT_INFO].ob_spec.tedinfo -> te_ptext = Messages(REORG_14); width = search[SLIDE_PERE].ob_width -3; search[SLIDE_FILS].ob_width = (int)((long)width * secteur / max) +3; secteur_text = search[INDICATEUR_WAIT].ob_spec.tedinfo -> te_ptext; sprintf(secteur_text, "%ld", secteur); sprintf(search[MAX_WAIT].ob_spec.free_string, "/%ld", max); my_open_dialog(&Dialog[WAIT], AUTO_DIAL|NO_ICONIFY|MODAL, FAIL); /* attend la fin des redessins */ Event_Timer(0, 0, TRUE); /* allocation des buffers, on d‚passe un peu … cause de l'approximation de la taille dans and_buffer() */ buffer = malloc(20L+ 512L * (thewin -> fonction.secteur.device < 2 ? SIZEBUFFLOP : SIZEBUFHARD)); if (buffer == NULL) { error_msg(Z_NOT_ENOUGH_MEMORY); return; } if ((buffer_frontiere = malloc(20L+ SEARCH_PATTERN_SIZE*2L + 16L)) == NULL) { free(buffer); error_msg(Z_NOT_ENOUGH_MEMORY); return; } /* mise … z‚ro */ memset(buffer_frontiere, 0, 20L+ SEARCH_PATTERN_SIZE*2L + 16L); /* pr‚pare le pattern */ if (diff_majmin) for (i=0; i<SearchLength; i++) pattern[i] = SearchString[i]; else for (i=0; i<SearchLength; i++) pattern[i] = SearchString[i] & ~('a'-'A'); /* octet de d‚part */ start = thewin -> fonction.secteur.curseur_x < 0 ? thewin -> fonction.secteur.page *512 : thewin -> fonction.secteur.page *512 + thewin -> fonction.secteur.curseur_y*32 + thewin -> fonction.secteur.curseur_x/2 +1; /* recherche d'abord dans le secteur en m‚moire */ memcpy(buffer, thewin -> fonction.secteur.secteurBin, thewin -> fonction.secteur.sector_size*512L); if ((offset = search_pattern(buffer + start, thewin -> fonction.secteur.sector_size*512L - start, pattern, diff_majmin, start_to_end)) >= 0) { my_close_dialog(&Dialog[WAIT]); free(buffer_frontiere); free(buffer); search_found(thewin, secteur, offset + start); return; } /* remplis de n'importe quoi sauf du motif recherch‚ */ memset(buffer_frontiere, SearchString[0] ^ 0xAA, (long)SEARCH_PATTERN_SIZE); /* nombre max de secteurs … lire */ size_buff_sect = (thewin -> fonction.secteur.device < 2 ? SIZEBUFFLOP : SIZEBUFHARD) / thewin -> fonction.secteur.sector_size; /* taille du bloc … lire */ if (max - secteur > (long)size_buff_sect) taille = size_buff_sect; else taille = (int)(max - secteur); while (taille > 0) { /* charge le buffer */ if ((taille = load_buffer(thewin, buffer, secteur, taille, start_to_end)) < 0) { /* erreur */ my_close_dialog(&Dialog[WAIT]); free(buffer); return; } /* recherche sur la frontiŠre */ memcpy(buffer_frontiere + SEARCH_PATTERN_SIZE, buffer, (long)SEARCH_PATTERN_SIZE); if ((offset = search_pattern(buffer_frontiere, SEARCH_PATTERN_SIZE, pattern, diff_majmin, start_to_end)) >= 0) { my_close_dialog(&Dialog[WAIT]); free(buffer_frontiere); free(buffer); search_found(thewin, secteur-taille, offset + (thewin -> fonction.secteur.device < 2 ? SIZEBUFFLOP*512L - SEARCH_PATTERN_SIZE : SIZEBUFHARD*512L - SEARCH_PATTERN_SIZE)); return; } /* recherche en cours */ if ((offset = search_pattern(buffer+start, taille * thewin -> fonction.secteur.sector_size * 512L - start, pattern, diff_majmin, start_to_end)) >= 0) { my_close_dialog(&Dialog[WAIT]); free(buffer_frontiere); free(buffer); search_found(thewin, secteur, offset+start); return; } /* on n'a un d‚calage que la premiŠre fois */ start = 0; /* copie la fin du bloc pour la frontiŠre */ memcpy(buffer_frontiere, buffer + (thewin -> fonction.secteur.device < 2 ? SIZEBUFFLOP*512L - SEARCH_PATTERN_SIZE : SIZEBUFHARD*512L - SEARCH_PATTERN_SIZE), (long)SEARCH_PATTERN_SIZE); /* on avance */ secteur += taille; /* taille du bloc … lire */ if (max - secteur > (long)size_buff_sect) taille = size_buff_sect; else taille = (int)(max - secteur); /* test les boutons */ if (evnt_multi(MU_TIMER | MU_BUTTON, 256+1, 3, 0, /* button */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* mouse */ NULL, /* message */ 1, 0, /* timer */ &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) == MU_BUTTON && my_alert(1, 2, X_ICN_QUESTION, Messages(SEARCH_3), Messages(BOOT_32)) == 0) { /* on n'a pas trouv‚ mais on s'arrˆte */ my_close_dialog(&Dialog[WAIT]); free(buffer_frontiere); free(buffer); search_found(thewin, secteur, -1L); return; } /* met … jour la barre */ search[SLIDE_FILS].ob_width = (int)((long)width * secteur / max) +3; ob_draw(Dialog[WAIT].info, SLIDE_FILS); /* met … jour le compteur */ sprintf(secteur_text, "%ld", secteur); ob_draw(Dialog[WAIT].info, INDICATEUR_WAIT); /* attend la fin des redessins */ Event_Timer(0, 0, TRUE); } free(buffer_frontiere); free(buffer); my_close_dialog(&Dialog[WAIT]); /* un petit bruit */ if (Sound) Cconout(7); } /* search_secteur */