Seregon/Hermes

Hermes/Dyforge is a program written in c++ allows you to inject a dll that can analyze all processes in a program, can be used for mod and reverse engeneering

C/3.8 KB/No license
DyForge/src/reporting/ReportingManager.cpp
Hermes / DyForge / src / reporting / ReportingManager.cpp
1#include "../../include/DyForge.h"
2#include <stdexcept>
3#include <sstream>
4#include <fstream>
5#include <chrono>
6#include <iomanip>
7#include <nlohmann/json.hpp>
8 
9namespace DyForge {
10 
11// Constructor
12ReportingManager::ReportingManager(AnalysisManager& analysisManager)
13 : m_analysisManager(analysisManager) {
14}
15 
16// Destructor
17ReportingManager::~ReportingManager() {
18}
19 
20// Reporting
21bool ReportingManager::GenerateReport(const std::wstring& outputPath) {
22 if (!m_analysisManager.IsAnalysisRunning()) {
23 throw std::runtime_error("Analysis is not running");
24 }
25
26 // Request analysis data
27 const char* command = "GET_ANALYSIS_DATA";
28 DyHexInjectError error = DyHexInject_SendCommand(
29 m_analysisManager.GetInjectionManager().GetCommunication(),
30 command,
31 strlen(command)
32 );
33
34 if (error != DYHEXINJECT_SUCCESS) {
35 std::stringstream ss;
36 ss << "Failed to send get analysis data command: "
37 << DyHexInject_GetErrorString(error);
38 throw std::runtime_error(ss.str());
39 }
40
41 // Receive analysis data
42 char responseBuffer[4096];
43 size_t bytesReceived;
44 error = DyHexInject_ReceiveResponse(
45 m_analysisManager.GetInjectionManager().GetCommunication(),
46 responseBuffer,
47 sizeof(responseBuffer),
48 &bytesReceived
49 );
50
51 if (error != DYHEXINJECT_SUCCESS) {
52 std::stringstream ss;
53 ss << "Failed to receive analysis data: "
54 << DyHexInject_GetErrorString(error);
55 throw std::runtime_error(ss.str());
56 }
57
58 // Parse JSON data
59 try {
60 nlohmann::json analysisData = nlohmann::json::parse(
61 std::string(responseBuffer, bytesReceived)
62 );
63
64 // Generate report
65 std::ofstream reportFile(outputPath);
66 if (!reportFile.is_open()) {
67 throw std::runtime_error("Failed to open report file");
68 }
69
70 // Write report header
71 auto now = std::chrono::system_clock::now();
72 auto time = std::chrono::system_clock::to_time_t(now);
73 reportFile << "DyForge Analysis Report\n"
74 << "Generated: " << std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S") << "\n\n";
75
76 // Write process information
77 const auto& processInfo = m_analysisManager.GetInjectionManager().GetProcessManager().GetProcessInfo();
78 reportFile << "Process Information:\n"
79 << " PID: " << m_analysisManager.GetInjectionManager().GetProcessManager().GetCurrentProcessId() << "\n"
80 << " Name: " << processInfo.processName << "\n"
81 << " Path: " << processInfo.processPath << "\n"
82 << " Architecture: " << (processInfo.is64Bit ? "64-bit" : "32-bit") << "\n\n";
83
84 // Write analysis data
85 reportFile << "Analysis Results:\n";
86 for (const auto& [key, value] : analysisData.items()) {
87 reportFile << " " << key << ": " << value.dump(2) << "\n";
88 }
89
90 reportFile.close();
91 return true;
92 }
93 catch (const std::exception& e) {
94 throw std::runtime_error(std::string("Failed to generate report: ") + e.what());
95 }
96}
97 
98bool ReportingManager::ExportData(const std::wstring& format, const std::wstring& outputPath) {
99 if (!m_analysisManager.IsAnalysisRunning()) {
100 throw std::runtime_error("Analysis is not running");
101 }
102
103 // Request analysis data
104 const char* command = "GET_ANALYSIS_DATA";
105 DyHexInjectError error = DyHexInject_SendCommand(
106 m_analysisManager.GetInjectionManager().GetCommunication(),
107 command,
108 strlen(command)
109 );
110
111 if (error != DYHEXINJECT_SUCCESS) {
112 std::stringstream ss;
113 ss << "Failed to send get analysis data command: "
114 << DyHexInject_GetErrorString(error);
115 throw std::runtime_error(ss.str());
116 }
117
118 // Receive analysis data
119 char responseBuffer[4096];
120 size_t bytesReceived;
121 error = DyHexInject_ReceiveResponse(
122 m_analysisManager.GetInjectionManager().GetCommunication(),
123 responseBuffer,
124 sizeof(responseBuffer),
125 &bytesReceived
126 );
127
128 if (error != DYHEXINJECT_SUCCESS) {
129 std::stringstream ss;
130 ss << "Failed to receive analysis data: "
131 << DyHexInject_GetErrorString(error);
132 throw std::runtime_error(ss.str());
133 }
134
135 // Export data based on format
136 if (format == L"json") {
137 // Export as JSON
138 std::ofstream exportFile(outputPath);
139 if (!exportFile.is_open()) {
140 throw std::runtime_error("Failed to open export file");
141 }
142 exportFile << std::string(responseBuffer, bytesReceived);
143 exportFile.close();
144 }
145 else if (format == L"csv") {
146 // Export as CSV
147 try {
148 nlohmann::json analysisData = nlohmann::json::parse(
149 std::string(responseBuffer, bytesReceived)
150 );
151
152 std::ofstream exportFile(outputPath);
153 if (!exportFile.is_open()) {
154 throw std::runtime_error("Failed to open export file");
155 }
156
157 // Write CSV header
158 for (const auto& [key, value] : analysisData.items()) {
159 exportFile << key << ",";
160 }
161 exportFile << "\n";
162
163 // Write CSV data
164 for (const auto& [key, value] : analysisData.items()) {
165 exportFile << value.dump() << ",";
166 }
167 exportFile << "\n";
168
169 exportFile.close();
170 }
171 catch (const std::exception& e) {
172 throw std::runtime_error(std::string("Failed to export data: ") + e.what());
173 }
174 }
175 else {
176 throw std::runtime_error("Unsupported export format: " + std::string(format.begin(), format.end()));
177 }
178
179 return true;
180}
181 
182} // namespace DyForge