Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ScoreModel(string family, int opcodenum, const vector<vector<int>> malware, const vector<vector<int>> benign)
- {
- std::vector<std::string> fileNameList;
- string parentFolderPath = "./score/" + family + "/";
- boostfs::path p(parentFolderPath);
- for (auto i = boostfs::directory_iterator(p); i != boostfs::directory_iterator(); i++)
- {
- if (!boostfs::is_directory(i->path()))
- {
- string fullFileName = parentFolderPath + i->path().filename().string();
- fileNameList.push_back(fullFileName);
- }
- }
- int noOfFiles = fileNameList.size();
- for (int index = 0; index < noOfFiles; index++)
- {
- std::vector<std::vector<double>> state_trasition;
- std::vector<std::vector<double>> obsv_probab;
- std::vector<double> init_dist;
- boost::char_separator<char> sep(" \t");
- typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
- vector<double> temp[2];
- string tempFileName = fileNameList.at(index);
- ifstream tempReadFile;
- tempReadFile.open(tempFileName);
- string line;
- for (int i = 0; i < 36; i++)
- {
- getline(tempReadFile, line);
- if (i == 0)
- {
- tokenizer tok(line, sep);
- for (tokenizer::iterator it = tok.begin(); it != tok.end(); ++it)
- {
- cout << *it;
- init_dist.push_back(stod(*it));
- }
- }
- else if (i == 2 || i == 3)
- {
- tokenizer tok(line, sep);
- for (tokenizer::iterator it = tok.begin(); it != tok.end(); ++it)
- {
- temp[0].push_back(stod(*it));
- }
- state_trasition.push_back(temp[0]);
- temp[0].clear();
- }
- else if (i > 4)
- {
- tokenizer tok(line, sep);
- int flag = 0;
- for (tokenizer::iterator it = tok.begin(); it != tok.end(); ++it)
- {
- if (flag == 0)
- {
- temp[0].push_back(stod(*it));
- flag = 1;
- }
- else
- {
- temp[1].push_back(stod(*it));
- flag = 0;
- }
- }
- }
- }
- obsv_probab.push_back(temp[0]);
- obsv_probab.push_back(temp[1]);
- temp[0].clear();
- temp[1].clear();
- Hmm model_score;
- model_score.setNumStates(2);
- model_score.setNumObsvSeq(opcodenum+1);
- model_score.setInitDist(init_dist);
- model_score.setStateTrans(state_trasition);
- model_score.setObsvProbab(obsv_probab);
- ofstream out("score/" + family + "/scores/score" + to_string(index) + ".txt");
- streambuf *coutbuf = cout.rdbuf();
- cout.rdbuf(out.rdbuf());
- // Test Malware
- int test_size = malware.size();
- vector<double> test_malscore;
- for (int j = 0; j < test_size; j++)
- {
- test_malscore.push_back(model_score.Score(malware.at(j)));
- cout << test_malscore.back() << "\n" << flush;
- }
- // Test Benign
- test_size = benign.size();
- vector<double> test_benscore;
- for (int j = 0; j < test_size; j++)
- {
- test_benscore.push_back(model_score.Score(benign.at(j)));
- cout << test_benscore.back() << "\n" << flush;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement