Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. void ScoreModel(string family, int opcodenum, const vector<vector<int>> malware, const vector<vector<int>> benign)
  2. {
  3. std::vector<std::string> fileNameList;
  4. string parentFolderPath = "./score/" + family + "/";
  5.  
  6. boostfs::path p(parentFolderPath);
  7. for (auto i = boostfs::directory_iterator(p); i != boostfs::directory_iterator(); i++)
  8. {
  9. if (!boostfs::is_directory(i->path()))
  10. {
  11. string fullFileName = parentFolderPath + i->path().filename().string();
  12. fileNameList.push_back(fullFileName);
  13. }
  14. }
  15.  
  16. int noOfFiles = fileNameList.size();
  17.  
  18. for (int index = 0; index < noOfFiles; index++)
  19. {
  20. std::vector<std::vector<double>> state_trasition;
  21. std::vector<std::vector<double>> obsv_probab;
  22. std::vector<double> init_dist;
  23. boost::char_separator<char> sep(" \t");
  24. typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
  25. vector<double> temp[2];
  26. string tempFileName = fileNameList.at(index);
  27. ifstream tempReadFile;
  28. tempReadFile.open(tempFileName);
  29.  
  30. string line;
  31.  
  32. for (int i = 0; i < 36; i++)
  33. {
  34. getline(tempReadFile, line);
  35.  
  36. if (i == 0)
  37. {
  38. tokenizer tok(line, sep);
  39. for (tokenizer::iterator it = tok.begin(); it != tok.end(); ++it)
  40. {
  41. cout << *it;
  42. init_dist.push_back(stod(*it));
  43. }
  44. }
  45. else if (i == 2 || i == 3)
  46. {
  47. tokenizer tok(line, sep);
  48. for (tokenizer::iterator it = tok.begin(); it != tok.end(); ++it)
  49. {
  50. temp[0].push_back(stod(*it));
  51. }
  52. state_trasition.push_back(temp[0]);
  53. temp[0].clear();
  54. }
  55. else if (i > 4)
  56. {
  57. tokenizer tok(line, sep);
  58. int flag = 0;
  59. for (tokenizer::iterator it = tok.begin(); it != tok.end(); ++it)
  60. {
  61. if (flag == 0)
  62. {
  63. temp[0].push_back(stod(*it));
  64. flag = 1;
  65. }
  66. else
  67. {
  68. temp[1].push_back(stod(*it));
  69. flag = 0;
  70. }
  71. }
  72. }
  73. }
  74.  
  75. obsv_probab.push_back(temp[0]);
  76. obsv_probab.push_back(temp[1]);
  77. temp[0].clear();
  78. temp[1].clear();
  79.  
  80. Hmm model_score;
  81.  
  82. model_score.setNumStates(2);
  83. model_score.setNumObsvSeq(opcodenum+1);
  84. model_score.setInitDist(init_dist);
  85. model_score.setStateTrans(state_trasition);
  86. model_score.setObsvProbab(obsv_probab);
  87.  
  88. ofstream out("score/" + family + "/scores/score" + to_string(index) + ".txt");
  89. streambuf *coutbuf = cout.rdbuf();
  90. cout.rdbuf(out.rdbuf());
  91.  
  92. // Test Malware
  93. int test_size = malware.size();
  94. vector<double> test_malscore;
  95. for (int j = 0; j < test_size; j++)
  96. {
  97. test_malscore.push_back(model_score.Score(malware.at(j)));
  98. cout << test_malscore.back() << "\n" << flush;
  99. }
  100.  
  101. // Test Benign
  102. test_size = benign.size();
  103. vector<double> test_benscore;
  104. for (int j = 0; j < test_size; j++)
  105. {
  106. test_benscore.push_back(model_score.Score(benign.at(j)));
  107. cout << test_benscore.back() << "\n" << flush;
  108. }
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement