basefiles.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. struct option
  2. {
  3. int proc = 0;
  4. int mode = 0;
  5. int log = 0;
  6. int high = 0;
  7. std::string str_search;
  8. std::string rgx_search;
  9. std::string outputfile;
  10. };
  11. option conf;
  12. int config()
  13. {
  14. std::ifstream conffile ("sygcpp.conf");
  15. if(!conffile) // проверка наличия конфига
  16. {
  17. std::cout << " Configuration file not found... ";
  18. conffile.close();
  19. std::ofstream newconf ("sygcpp.conf"); // создание конфига
  20. if(!newconf)
  21. {
  22. std::cerr << "CREATION FAILED" << std::endl;
  23. return -1;
  24. }
  25. newconf << "####################################################################\n"
  26. << "# SimpleYggGen C++ configuraton file #\n"
  27. << "# If you have some errors, try delete this file and run SYG again. #\n"
  28. << "####################################################################\n\n"
  29. << "* Count of thread: 1\n\n"
  30. << " 0 - by pattern, 1 - high address, 2 - search by pattern & high\n"
  31. << " 3 - regexp, 4 - search by regexp & high.\n"
  32. << "* Mining option: 1\n\n"
  33. << " 0 - console output only, 1 - log to file.\n"
  34. << "* Logging mode: 1\n\n"
  35. << " High address search. Parameter is set in decimal notation (0-9),\n"
  36. << " displayed in the address in hexadecimal (0-9, a-f).\n"
  37. << "* Start position: 15\n\n"
  38. << " Used when \"Mining mode\" set as 0 or 2.\n"
  39. << "* Pattern: ::\n\n"
  40. << " Used when \"Mining mode\" set as 3 or 4. Extended grep type.\n"
  41. << "* Regexp: ^2..:ffff.*.eeee$";
  42. newconf.close();
  43. std::ifstream conffile ("sygcpp.conf");
  44. if(conffile)
  45. std::cout << "CREATED" << std::endl;
  46. config();
  47. return 0;
  48. } else { // чтение конфигурации
  49. std::string str_temp_read;
  50. std::string str_read;
  51. while(getline(conffile, str_temp_read))
  52. str_read += str_temp_read;
  53. conffile.close();
  54. std::istringstream ss_input(str_read); // чтение конфига
  55. while(!ss_input.eof())
  56. {
  57. ss_input >> str_temp_read;
  58. if(str_temp_read == "thread:") // поиск параметра по предыдущему слову
  59. {
  60. ss_input >> conf.proc; // запись в соответствующую переменную
  61. if(ss_input.fail())
  62. {
  63. std::cerr << " Count of thread value incorrect." << std::endl;
  64. return -2;
  65. }
  66. }
  67. if(str_temp_read == "option:")
  68. {
  69. ss_input >> conf.mode;
  70. if(ss_input.fail() || (conf.mode > 4 || conf.mode < 0))
  71. {
  72. std::cerr << " Mining option value incorrect." << std::endl;
  73. return -3;
  74. }
  75. }
  76. if(str_temp_read == "mode:")
  77. {
  78. ss_input >> conf.log;
  79. if(ss_input.fail() || (conf.log != 0 && conf.log != 1))
  80. {
  81. std::cerr << " Logging mode value incorrect." << std::endl;
  82. return -4;
  83. }
  84. }
  85. if(str_temp_read == "position:")
  86. {
  87. ss_input >> conf.high;
  88. if(ss_input.fail())
  89. {
  90. std::cerr << " Start position value incorrect." << std::endl;
  91. return -5;
  92. }
  93. }
  94. if(str_temp_read == "Pattern:")
  95. {
  96. ss_input >> conf.str_search;
  97. if(ss_input.fail())
  98. {
  99. std::cerr << " Pattern value incorrect." << std::endl;
  100. return -6;
  101. }
  102. }
  103. if(str_temp_read == "Regexp:")
  104. {
  105. ss_input >> conf.rgx_search;
  106. if(ss_input.fail())
  107. {
  108. std::cerr << " Regexp value incorrect." << std::endl;
  109. return -7;
  110. }
  111. }
  112. }
  113. return 0;
  114. }
  115. }
  116. void config_print()
  117. {
  118. // вывод конфигурации на экран
  119. std::cout << " Threads: " << conf.proc << ", ";
  120. if(conf.mode == 0)
  121. std::cout << "search by pattern (" << conf.str_search << "), ";
  122. else if(conf.mode == 1)
  123. std::cout << "search high addresses (" << conf.high << "), ";
  124. else if(conf.mode == 2)
  125. std::cout << "search by pattern & high (" << conf.str_search << " & " << conf.high << "), ";
  126. else if(conf.mode == 3)
  127. std::cout << "search by regexp (" << conf.rgx_search << "), ";
  128. else if(conf.mode == 4)
  129. std::cout << "search by regexp & high (" << conf.rgx_search << " & " << conf.high << "), ";
  130. if(conf.log)
  131. std::cout << "logging to text file.";
  132. else
  133. std::cout << "console log only.";
  134. std::cout << std::endl << std::endl;
  135. }
  136. void testoutput()
  137. {
  138. if(conf.log) // проверка включено ли логирование
  139. {
  140. if(conf.mode == 0)
  141. conf.outputfile = "syg-pattern.txt";
  142. else if(conf.mode == 1)
  143. conf.outputfile = "syg-high.txt";
  144. else if(conf.mode == 2)
  145. conf.outputfile = "syg-pattern-high.txt";
  146. else if(conf.mode == 3)
  147. conf.outputfile = "syg-regexp.txt";
  148. else if(conf.mode == 4)
  149. conf.outputfile = "syg-regexp-high.txt";
  150. std::ifstream test(conf.outputfile);
  151. if(!test) // проверка наличия выходного файла
  152. {
  153. test.close();
  154. std::ofstream output(conf.outputfile);
  155. output << "**************************************************************************\n"
  156. << "Change EncryptionPublicKey and EncryptionPrivateKey to your yggdrasil.conf\n"
  157. << "Windows: C:\\ProgramData\\Yggdrasil\\yggdrasil.conf\n"
  158. << "Debian: /etc/yggdrasil.conf\n"
  159. << "**************************************************************************\n";
  160. output.close();
  161. } else test.close();
  162. }
  163. }