Advertisement
EliteAnax17

filemon v2

Apr 29th, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. // Copyright 2013 Dolphin Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4.  
  5. #include <algorithm>
  6. #include <cctype>
  7. #include <cstring>
  8. #include <string>
  9. #include <unordered_set>
  10. #include <vector>
  11.  
  12. #include <winsock2.h>
  13. #include <WS2tcpip.h>
  14. #include <Windows.h>
  15.  
  16. #include <stdio.h>
  17.  
  18. #include "Common/CommonTypes.h"
  19. #include "Common/StringUtil.h"
  20. #include "Common/Logging/LogManager.h"
  21.  
  22. #include "Core/ConfigManager.h"
  23. #include "Core/Core.h"
  24. #include "Core/Boot/Boot.h"
  25.  
  26. #include "DiscIO/FileMonitor.h"
  27. #include "DiscIO/Filesystem.h"
  28. #include "DiscIO/Volume.h"
  29. #include "DiscIO/VolumeCreator.h"
  30.  
  31. namespace FileMon
  32. {
  33.  
  34. static DiscIO::IVolume *OpenISO = nullptr;
  35. static DiscIO::IFileSystem *pFileSystem = nullptr;
  36. static std::vector<const DiscIO::SFileInfo *> DiscFiles;
  37. static std::string ISOFile = "", CurrentFile = "";
  38. static bool FileAccess = true;
  39.  
  40. void test(int argc, const char*argv)
  41. {
  42. WARN_LOG(COMMON, "%s", "step 1");
  43. int sockfd, n;
  44. WARN_LOG(COMMON, "%s", "step 2");
  45. struct sockaddr_in servaddr, cliaddr;
  46. WARN_LOG(COMMON, "%s", "step 3");
  47. char sendline[1000];
  48. WARN_LOG(COMMON, "%s", "step 4");
  49. char recvline[1000];
  50. WARN_LOG(COMMON, "%s", "step 5");
  51.  
  52. sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  53. WARN_LOG(COMMON, "%s", "step 6");
  54.  
  55. memset(&servaddr, 0, sizeof(servaddr));
  56. servaddr.sin_family = AF_INET;
  57. servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  58. servaddr.sin_port = htons(7000);
  59. WARN_LOG(COMMON, "%s", "step 7");
  60.  
  61. memset(sendline, 0, 1000);
  62. memcpy(sendline, argv, strlen(argv));
  63.  
  64. int senddata = sendto(sockfd, sendline, strlen(sendline), 0,
  65. (struct sockaddr *)&servaddr, sizeof(servaddr));
  66. }
  67.  
  68. // Filtered files
  69. bool IsSoundFile(const std::string& filename)
  70. {
  71. std::string extension;
  72. SplitPath(filename, nullptr, nullptr, &extension);
  73. std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
  74.  
  75. static std::unordered_set<std::string> extensions = {
  76. ".adp", // 1080 Avalanche, Crash Bandicoot, etc.
  77. ".adx", // Sonic Adventure 2 Battle, etc.
  78. ".afc", // Zelda WW
  79. ".ast", // Zelda TP, Mario Kart
  80. ".brstm", // Wii Sports, Wario Land, etc.
  81. ".dsp", // Metroid Prime
  82. ".hps", // SSB Melee
  83. ".ogg", // Tony Hawk's Underground 2
  84. ".sad", // Disaster
  85. ".snd", // Tales of Symphonia
  86. ".song", // Tales of Symphonia
  87. ".ssm", // Custom Robo, Kirby Air Ride, etc.
  88. ".str", // Harry Potter & the Sorcerer's Stone
  89. };
  90.  
  91. return extensions.find(extension) != extensions.end();
  92. }
  93.  
  94.  
  95. // Read the file system
  96. void ReadFileSystem(const std::string& filename)
  97. {
  98. // Should have an actual Shutdown procedure or something
  99. if (OpenISO != nullptr)
  100. {
  101. delete OpenISO;
  102. OpenISO = nullptr;
  103. }
  104. if (pFileSystem != nullptr)
  105. {
  106. delete pFileSystem;
  107. pFileSystem = nullptr;
  108. }
  109.  
  110. // DiscFiles' pointers are no longer valid after pFileSystem is cleared
  111. DiscFiles.clear();
  112. OpenISO = DiscIO::CreateVolumeFromFilename(filename);
  113. if (!OpenISO)
  114. return;
  115.  
  116. if (!OpenISO->IsWadFile())
  117. {
  118. pFileSystem = DiscIO::CreateFileSystem(OpenISO);
  119.  
  120. if (!pFileSystem)
  121. return;
  122.  
  123. pFileSystem->GetFileList(DiscFiles);
  124. }
  125.  
  126. FileAccess = true;
  127. }
  128.  
  129. // Logs a file if it passes a few checks
  130. void CheckFile(const std::string& file, u64 size)
  131. {
  132. int testarg = 6;
  133. // Don't do anything if the log is unselected
  134. if (!LogManager::GetInstance()->IsEnabled(LogTypes::FILEMON, LogTypes::LWARNING))
  135. return;
  136. // Do nothing if we found the same file again
  137. if (CurrentFile == file)
  138. return;
  139.  
  140. if (size > 0)
  141. size = (size / 1000);
  142.  
  143. std::string str = StringFromFormat("%s kB %s", ThousandSeparate(size, 7).c_str(), file.c_str());
  144. if (IsSoundFile(file))
  145. {
  146. INFO_LOG(FILEMON, "%s", str.c_str());
  147. }
  148. else
  149. {
  150. WARN_LOG(FILEMON, "%s", str.c_str());
  151. if (file.compare(0, 4, "pkx_") == 0)
  152. {
  153. std::string strnumber = file.substr(4, 3);
  154. const char* cstring = str.c_str();
  155. int number = atoi(strnumber.c_str());
  156. std::string presend = std::to_string(number);
  157. const char* sendthis = presend.c_str();
  158. // const char args[] = { number };
  159. // WARN_LOG(COMMON, "%s", args);
  160. if (sendthis != "601")
  161. {
  162. test(2, sendthis);
  163. }
  164. }
  165. else if (file.compare(0, 8, "fn_tr_00") == 0)
  166. {
  167. test(2, "BT/PRE/BEG/END");
  168. };
  169. }
  170.  
  171. // Update the current file
  172. CurrentFile = file;
  173. }
  174.  
  175.  
  176. // Find the filename
  177. void FindFilename(u64 offset)
  178. {
  179. // Don't do anything if a game is not running
  180. if (Core::GetState() != Core::CORE_RUN)
  181. return;
  182.  
  183. // Or if the log is unselected
  184. if (!LogManager::GetInstance()->IsEnabled(LogTypes::FILEMON, LogTypes::LWARNING))
  185. return;
  186.  
  187. // Or if we don't have file access
  188. if (!FileAccess)
  189. return;
  190.  
  191. if (!pFileSystem || ISOFile != SConfig::GetInstance().m_LastFilename)
  192. {
  193. FileAccess = false;
  194. ReadFileSystem(SConfig::GetInstance().m_LastFilename);
  195. ISOFile = SConfig::GetInstance().m_LastFilename;
  196. INFO_LOG(FILEMON, "Opening '%s'", ISOFile.c_str());
  197. return;
  198. }
  199.  
  200. const std::string filename = pFileSystem->GetFileName(offset);
  201.  
  202. if (filename.empty())
  203. return;
  204.  
  205. CheckFile(filename, pFileSystem->GetFileSize(filename));
  206. }
  207.  
  208. void Close()
  209. {
  210. if (OpenISO != nullptr)
  211. {
  212. delete OpenISO;
  213. OpenISO = nullptr;
  214. }
  215.  
  216. if (pFileSystem != nullptr)
  217. {
  218. delete pFileSystem;
  219. pFileSystem = nullptr;
  220. }
  221.  
  222. // DiscFiles' pointers are no longer valid after pFileSystem is cleared
  223. DiscFiles.clear();
  224.  
  225. ISOFile = "";
  226. CurrentFile = "";
  227. FileAccess = true;
  228. }
  229.  
  230.  
  231. } // FileMon
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement