| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
#include "CaptureSoapServer.h" |
|---|
| 6 |
#include "soapH.h" |
|---|
| 7 |
#include "capture.nsmap" |
|---|
| 8 |
#include "Visitor.h" |
|---|
| 9 |
#include "b64.h" //nice small 3rd party lib for base64 encode/decode |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
struct soap soap; |
|---|
| 15 |
|
|---|
| 16 |
std::list<struct ns__regkey> regList; |
|---|
| 17 |
std::list<struct ns__regkey> regDeallocList; |
|---|
| 18 |
std::list<struct ns__processFile> fileList; |
|---|
| 19 |
std::list<struct ns__processFile> fileDeallocList; |
|---|
| 20 |
std::list<struct ns__osProcess> procList; |
|---|
| 21 |
std::list<struct ns__osProcess> procDeallocList; |
|---|
| 22 |
void dealloc_events(); |
|---|
| 23 |
|
|---|
| 24 |
CaptureSoapServer::CaptureSoapServer(Visitor* v, RegistryMonitor * r, FileMonitor * f, ProcessMonitor * p){ |
|---|
| 25 |
registryMonitor = r; |
|---|
| 26 |
fileMonitor = f; |
|---|
| 27 |
processMonitor = p; |
|---|
| 28 |
CaptureSoapServerThread = new Thread(this); |
|---|
| 29 |
CaptureSoapServerThread->start("CaptureSoapServer"); |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
CaptureSoapServer::~CaptureSoapServer(){ |
|---|
| 33 |
soap_destroy(&soap); |
|---|
| 34 |
soap_end(&soap); |
|---|
| 35 |
soap_done(&soap); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
void |
|---|
| 39 |
CaptureSoapServer::run(){ |
|---|
| 40 |
|
|---|
| 41 |
char debug = 0; |
|---|
| 42 |
SOCKET m, s; |
|---|
| 43 |
|
|---|
| 44 |
onProcessEventConnection = processMonitor->connect_onProcessEvent(boost::bind(&CaptureSoapServer::onProcessEvent, this, _1, _2, _3, _4, _5, _6)); |
|---|
| 45 |
onRegistryEventConnection = registryMonitor->connect_onRegistryEvent(boost::bind(&CaptureSoapServer::onRegistryEvent, this, _1, _2, _3, _4, _5)); |
|---|
| 46 |
onFileEventConnection = fileMonitor->connect_onFileEvent(boost::bind(&CaptureSoapServer::onFileEvent, this, _1, _2, _3, _4, _5)); |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
soap_init(&soap); |
|---|
| 50 |
|
|---|
| 51 |
m = soap_bind(&soap, "0.0.0.0", 1234, 100); |
|---|
| 52 |
if (m < 0) |
|---|
| 53 |
soap_print_fault(&soap, stderr); |
|---|
| 54 |
else |
|---|
| 55 |
{ |
|---|
| 56 |
if(debug) fprintf(stderr, "Socket connection successful: master socket = %d\n", m); |
|---|
| 57 |
for (int i = 1; ; i++) |
|---|
| 58 |
{ |
|---|
| 59 |
s = soap_accept(&soap); |
|---|
| 60 |
if (s < 0) |
|---|
| 61 |
{ |
|---|
| 62 |
soap_print_fault(&soap, stderr); |
|---|
| 63 |
break; |
|---|
| 64 |
} |
|---|
| 65 |
if(debug) fprintf(stderr, "%d: accepted connection from IP=%d.%d.%d.%d socket=%d\n", i, |
|---|
| 66 |
(soap.ip >> 24)&0xFF, (soap.ip >> 16)&0xFF, (soap.ip >> 8)&0xFF, soap.ip&0xFF, s); |
|---|
| 67 |
if (soap_serve(&soap) != SOAP_OK) |
|---|
| 68 |
soap_print_fault(&soap, stderr); |
|---|
| 69 |
if(debug) fprintf(stderr, "you got served!\n"); |
|---|
| 70 |
soap_destroy(&soap); |
|---|
| 71 |
soap_end(&soap); |
|---|
| 72 |
dealloc_events(); |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|
| 75 |
soap_done(&soap); |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
void CaptureSoapServer::onRegistryEvent (wstring registryEventType, wstring time, |
|---|
| 84 |
wstring processPath, wstring registryEventPath, |
|---|
| 85 |
vector<wstring> extra) |
|---|
| 86 |
{ |
|---|
| 87 |
char debug = 0; |
|---|
| 88 |
if(debug) printf("CaptureSoapServer::onRegistryEvent got an event for time = %ls, length = %d\n", time.c_str(), time.length()); |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
ns__regkey_t r; |
|---|
| 92 |
r.created_at = (char *)malloc(time.length()+1); |
|---|
| 93 |
sprintf(r.created_at, "%ls", time.c_str()); |
|---|
| 94 |
|
|---|
| 95 |
r.event_type = (char *)malloc(registryEventType.length()+1); |
|---|
| 96 |
sprintf(r.event_type, "%ls", registryEventType.c_str()); |
|---|
| 97 |
|
|---|
| 98 |
char * tmp = (char *)malloc(extra.at(0).length()+1); |
|---|
| 99 |
sprintf(tmp, "%ls", extra.at(0).c_str()); |
|---|
| 100 |
r.pid = atoi(tmp); |
|---|
| 101 |
free(tmp); |
|---|
| 102 |
|
|---|
| 103 |
r.proc_name = (char *)malloc(processPath.length()+1); |
|---|
| 104 |
sprintf(r.proc_name, "%ls", processPath.c_str()); |
|---|
| 105 |
|
|---|
| 106 |
r.name = (char *)malloc(registryEventPath.length()+1); |
|---|
| 107 |
sprintf(r.name, "%ls", registryEventPath.c_str()); |
|---|
| 108 |
|
|---|
| 109 |
r.value_name = (char *)malloc(extra.at(1).length()+1); |
|---|
| 110 |
sprintf(r.value_name, "%ls", extra.at(1).c_str()); |
|---|
| 111 |
|
|---|
| 112 |
r.value_type = (char *)malloc(extra.at(2).length()+1); |
|---|
| 113 |
sprintf(r.value_type, "%ls", extra.at(2).c_str()); |
|---|
| 114 |
|
|---|
| 115 |
r.value = (char *)malloc(extra.at(3).length()+1); |
|---|
| 116 |
sprintf(r.value, "%ls", extra.at(3).c_str()); |
|---|
| 117 |
|
|---|
| 118 |
if(debug){ |
|---|
| 119 |
int * b = (int *)&r; |
|---|
| 120 |
for(int i = 0; i < 8; i++){ |
|---|
| 121 |
printf("r[%d] = %#x\n", i, b[i]); |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
regList.push_back(r); |
|---|
| 126 |
if(debug) printf("added one event to regList. Now there are %d elements in the list\n", regList.size()); |
|---|
| 127 |
} |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
void CaptureSoapServer::onFileEvent(wstring fileEventType, wstring time, |
|---|
| 132 |
wstring processPath, wstring fileEventPath, |
|---|
| 133 |
vector<wstring> extra) |
|---|
| 134 |
{ |
|---|
| 135 |
char debug = 0; |
|---|
| 136 |
if(debug) printf("CaptureSoapServer::onFileEvent got an event for time = %ls\n", time.c_str()); |
|---|
| 137 |
ns__processFile_t f; |
|---|
| 138 |
f.created_at = (char *)malloc(time.length()+1); |
|---|
| 139 |
sprintf(f.created_at, "%ls", time.c_str()); |
|---|
| 140 |
|
|---|
| 141 |
f.event_type = (char *)malloc(fileEventType.length()+1); |
|---|
| 142 |
sprintf(f.event_type, "%ls", fileEventType.c_str()); |
|---|
| 143 |
|
|---|
| 144 |
char * tmp = (char *)malloc(extra.at(0).length()+1); |
|---|
| 145 |
sprintf(tmp, "%ls", extra.at(0).c_str()); |
|---|
| 146 |
f.pid = atoi(tmp); |
|---|
| 147 |
free(tmp); |
|---|
| 148 |
|
|---|
| 149 |
f.proc_name = (char *)malloc(processPath.length()+1); |
|---|
| 150 |
sprintf(f.proc_name, "%ls", processPath.c_str()); |
|---|
| 151 |
|
|---|
| 152 |
f.name = (char *)malloc(fileEventPath.length()+1); |
|---|
| 153 |
sprintf(f.name, "%ls", fileEventPath.c_str()); |
|---|
| 154 |
|
|---|
| 155 |
if(debug){ |
|---|
| 156 |
int * b = (int *)&f; |
|---|
| 157 |
for(int i = 0; i < 5; i++){ |
|---|
| 158 |
printf("f[%d] = %#x\n", i, b[i]); |
|---|
| 159 |
} |
|---|
| 160 |
} |
|---|
| 161 |
fileList.push_back(f); |
|---|
| 162 |
if(debug) printf("added one event to fileList. Now there are %d elements in the list\n", fileList.size()); |
|---|
| 163 |
|
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
void CaptureSoapServer::onProcessEvent(BOOLEAN created, wstring time, |
|---|
| 167 |
DWORD parentProcessId, wstring parentProcess, |
|---|
| 168 |
DWORD processId, wstring process) |
|---|
| 169 |
{ |
|---|
| 170 |
char debug = 0; |
|---|
| 171 |
if(debug) printf("CaptureSoapServer::onProcessEvent got an event for time = %ls\n", time.c_str()); |
|---|
| 172 |
ns__osProcess_t p; |
|---|
| 173 |
p.created_at = (char *)malloc(time.length()+1); |
|---|
| 174 |
sprintf(p.created_at, "%ls", time.c_str()); |
|---|
| 175 |
|
|---|
| 176 |
p.event_type = (char *)malloc(11); |
|---|
| 177 |
if(created){ |
|---|
| 178 |
sprintf(p.event_type, "created"); |
|---|
| 179 |
} |
|---|
| 180 |
else{ |
|---|
| 181 |
sprintf(p.event_type, "terminated"); |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
p.parent_pid = parentProcessId; |
|---|
| 185 |
|
|---|
| 186 |
p.parent_name = (char *)malloc(parentProcess.length()+1); |
|---|
| 187 |
sprintf(p.parent_name, "%ls", parentProcess.c_str()); |
|---|
| 188 |
|
|---|
| 189 |
p.pid = processId; |
|---|
| 190 |
|
|---|
| 191 |
p.name = (char *)malloc(process.length()+1); |
|---|
| 192 |
sprintf(p.name, "%ls", process.c_str()); |
|---|
| 193 |
|
|---|
| 194 |
procList.push_back(p); |
|---|
| 195 |
if(debug) printf("added one event to procList. Now there are %d elements in the list\n", procList.size()); |
|---|
| 196 |
|
|---|
| 197 |
} |
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
int ns__ping(struct soap *soap, char * a, char ** result) |
|---|
| 201 |
{ |
|---|
| 202 |
printf("%s\n", a); |
|---|
| 203 |
*result = "pong"; |
|---|
| 204 |
|
|---|
| 205 |
return SOAP_OK; |
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
int ns__visitURL(struct soap *soap, char * url, int &result){ |
|---|
| 210 |
char debug = 1; |
|---|
| 211 |
wchar_t xURL[1024]; |
|---|
| 212 |
wsprintf(xURL, L"%hs", url); |
|---|
| 213 |
|
|---|
| 214 |
typedef boost::signal<void (Element*)> signal_serverEvent; |
|---|
| 215 |
Attribute att; |
|---|
| 216 |
att.name = L"url"; |
|---|
| 217 |
att.value = xURL; |
|---|
| 218 |
Element e; |
|---|
| 219 |
e.name = L"visit"; |
|---|
| 220 |
e.attributes.push_back(att); |
|---|
| 221 |
e.data = NULL; |
|---|
| 222 |
e.dataLength = 0; |
|---|
| 223 |
if(debug) printf("visitURL to %s\n", url); |
|---|
| 224 |
EventController::getInstance()->notifyListeners(&e); |
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
result = 1; |
|---|
| 235 |
|
|---|
| 236 |
return SOAP_OK; |
|---|
| 237 |
} |
|---|
| 238 |
|
|---|
| 239 |
int ns__sendFileBase64(struct soap *soap, char * fileName, char * data, unsigned int encodedLength, unsigned int decodedLength, int &result){ |
|---|
| 240 |
char debug = 0; |
|---|
| 241 |
if(debug) printf("in ns__sendFileBase64\n"); |
|---|
| 242 |
|
|---|
| 243 |
if(debug) printf("encodedLength = %d, decodedLength = %d, data[0][1][2][3] = %c%c%c%c\n", encodedLength, decodedLength, |
|---|
| 244 |
data[0], data[1], data[2], data[3]); |
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
if(decodedLength != b64::b64_decode(data, encodedLength, NULL, NULL)){ |
|---|
| 248 |
printf("The decode will not be correct. Exiting\n"); |
|---|
| 249 |
return SOAP_ERR; |
|---|
| 250 |
} |
|---|
| 251 |
|
|---|
| 252 |
char * decodedData = new char[decodedLength]; |
|---|
| 253 |
b64::b64_decode(data, encodedLength, decodedData, decodedLength); |
|---|
| 254 |
|
|---|
| 255 |
printf("decodedData[0][1] = %c%c\n", decodedData[0], decodedData[1]); |
|---|
| 256 |
|
|---|
| 257 |
HANDLE myHandle = CreateFileA(fileName, (GENERIC_READ | GENERIC_WRITE), |
|---|
| 258 |
NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
|---|
| 259 |
if(myHandle == INVALID_HANDLE_VALUE){ |
|---|
| 260 |
printf("CreateFile failed with %d\n", GetLastError()); |
|---|
| 261 |
return SOAP_ERR; |
|---|
| 262 |
} |
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
DWORD numWrote; |
|---|
| 266 |
BOOL b = WriteFile(myHandle, decodedData, decodedLength, &numWrote, NULL); |
|---|
| 267 |
if(b){ |
|---|
| 268 |
if(debug) printf("Wrote %d bytes of data to %s\n", numWrote, fileName); |
|---|
| 269 |
} |
|---|
| 270 |
CloseHandle(myHandle); |
|---|
| 271 |
delete[] decodedData; |
|---|
| 272 |
|
|---|
| 273 |
result = 1; |
|---|
| 274 |
|
|---|
| 275 |
return SOAP_OK; |
|---|
| 276 |
|
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
int ns__receiveFileBase64(struct soap *soap, char * fileName, ns__receiveFileStruct &result){ |
|---|
| 283 |
int debug = 0; |
|---|
| 284 |
|
|---|
| 285 |
if(debug) printf("in ns__receiveFileBase64, about to open %s\n", fileName); |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
HANDLE myHandle = CreateFileA(fileName, GENERIC_READ, NULL, NULL, |
|---|
| 289 |
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
|---|
| 290 |
if(myHandle == INVALID_HANDLE_VALUE){ |
|---|
| 291 |
printf("couldn't open the file %s. Exiting\n", fileName); |
|---|
| 292 |
return SOAP_ERR; |
|---|
| 293 |
} |
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
unsigned int fileSize = (unsigned int)GetFileSize(myHandle, NULL); |
|---|
| 297 |
if(fileSize <= 0){ |
|---|
| 298 |
printf("Error, or zero-length file\n"); |
|---|
| 299 |
return SOAP_ERR; |
|---|
| 300 |
} |
|---|
| 301 |
char * buffer = new char[fileSize]; |
|---|
| 302 |
memset(buffer, 0, fileSize); |
|---|
| 303 |
|
|---|
| 304 |
DWORD numRead = 0; |
|---|
| 305 |
BOOL b = ReadFile(myHandle, buffer, fileSize, &numRead,NULL); |
|---|
| 306 |
if(!b || numRead != fileSize){ |
|---|
| 307 |
printf("ReadFile error\n"); |
|---|
| 308 |
return SOAP_ERR; |
|---|
| 309 |
} |
|---|
| 310 |
else{ |
|---|
| 311 |
if(debug) printf("Read the file successfully\n"); |
|---|
| 312 |
} |
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
unsigned int encodedLength = (unsigned int)b64::b64_encode(buffer, fileSize, NULL, NULL); |
|---|
| 316 |
if(debug) printf("encodedLength = %d\n", encodedLength); |
|---|
| 317 |
|
|---|
| 318 |
char * encodedData = new char[encodedLength]; |
|---|
| 319 |
memset(encodedData, 0, encodedLength); |
|---|
| 320 |
size_t ret = b64::b64_encode(buffer, fileSize, encodedData, encodedLength); |
|---|
| 321 |
if(ret == 0){ |
|---|
| 322 |
printf("size of the buffer was insufficient, or the length of the * converted buffer was longer than destLen\n"); |
|---|
| 323 |
return SOAP_ERR; |
|---|
| 324 |
} |
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
result.data = encodedData; |
|---|
| 328 |
result.encodedLength = encodedLength; |
|---|
| 329 |
result.decodedLength = fileSize; |
|---|
| 330 |
|
|---|
| 331 |
if(debug) printf("cleaning up\n"); |
|---|
| 332 |
CloseHandle(myHandle); |
|---|
| 333 |
delete[] buffer; |
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
if(debug) printf("cleaned up successfully\n"); |
|---|
| 337 |
|
|---|
| 338 |
return SOAP_OK; |
|---|
| 339 |
} |
|---|
| 340 |
|
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
int ns__openDocument(struct soap *soap, char * fileName, int waitTimeMillisec, int &result){ |
|---|
| 352 |
int debug = 0; |
|---|
| 353 |
if(debug) printf("in ns__openDocument, waitTimeMillisec = %d\n", waitTimeMillisec); |
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
wchar_t * docName = new wchar_t[1024]; |
|---|
| 357 |
wsprintf(docName, L"/K %hs", fileName); |
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
HANDLE myJobObj = CreateJobObject(NULL, NULL); |
|---|
| 364 |
if(myJobObj == NULL){ |
|---|
| 365 |
printf("CreateJobObject failed with error %d\n", GetLastError()); |
|---|
| 366 |
} |
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
STARTUPINFO myStart; |
|---|
| 370 |
memset(&myStart, 0, sizeof(STARTUPINFO)); |
|---|
| 371 |
PROCESS_INFORMATION procInfo; |
|---|
| 372 |
BOOL b = CreateProcess(L"C:\\WINDOWS\\system32\\cmd.exe", docName, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, |
|---|
| 373 |
NULL, NULL, &myStart, &procInfo); |
|---|
| 374 |
if(!b){ |
|---|
| 375 |
printf("CreateProcess failed with error %d\n", GetLastError()); |
|---|
| 376 |
return SOAP_ERR; |
|---|
| 377 |
} |
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
b = AssignProcessToJobObject(myJobObj, procInfo.hProcess); |
|---|
| 381 |
if(!b){ |
|---|
| 382 |
printf("AssignProcessToJobObject failed with error %d\n", GetLastError()); |
|---|
| 383 |
return SOAP_ERR; |
|---|
| 384 |
} |
|---|
| 385 |
|
|---|
| 386 |
if(debug) printf("dwProcessId = %d, dwThreadId = %d\n", procInfo.dwProcessId, procInfo.dwThreadId); |
|---|
| 387 |
if(debug) printf("Sleeping for %d seconds\n", (DWORD)waitTimeMillisec/1000); |
|---|
| 388 |
Sleep((DWORD)waitTimeMillisec); |
|---|
| 389 |
if(debug) printf("\n\nDone sleeping\n\n"); |
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 |
|
|---|
| 395 |
b = TerminateJobObject(myJobObj, 0); |
|---|
| 396 |
if(!b){ |
|---|
| 397 |
printf("TerminateProcess failed with error %d\n", GetLastError()); |
|---|
| 398 |
return SOAP_ERR; |
|---|
| 399 |
} |
|---|
| 400 |
CloseHandle(procInfo.hProcess); |
|---|
| 401 |
CloseHandle(procInfo.hThread); |
|---|
| 402 |
|
|---|
| 403 |
result = 1; |
|---|
| 404 |
return SOAP_OK; |
|---|
| 405 |
} |
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
int ns__returnRegistryEvents(struct soap *soap, int maxEventsToReturn, struct ns__dynRegArray **result){ |
|---|
| 409 |
char debug = 1; |
|---|
| 410 |
|
|---|
| 411 |
struct ns__dynRegArray * dRegArray; |
|---|
| 412 |
|
|---|
| 413 |
dRegArray = soap_new_ns__dynRegArray(soap,1); |
|---|
| 414 |
dRegArray->__ptr = NULL; |
|---|
| 415 |
dRegArray->__size = regList.size(); |
|---|
| 416 |
|
|---|
| 417 |
|
|---|
| 418 |
if(maxEventsToReturn < dRegArray->__size && maxEventsToReturn != -1){ |
|---|
| 419 |
dRegArray->__size = maxEventsToReturn; |
|---|
| 420 |
} |
|---|
| 421 |
if(debug) printf("Sending back %d registy events\n",dRegArray->__size); |
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
struct ns__regkey * ns__regkeyArray = (struct ns__regkey *)soap_malloc(soap, dRegArray->__size*sizeof(struct ns__regkey)); |
|---|
| 426 |
dRegArray->__ptr = ns__regkeyArray; |
|---|
| 427 |
|
|---|
| 428 |
for(unsigned int i = 0; i < dRegArray->__size; i++){ |
|---|
| 429 |
if(debug){ |
|---|
| 430 |
printf("i = %d\n", i); |
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
int * b = (int *)®List.front(); |
|---|
| 436 |
for(int i = 0; i < 8; i++){ |
|---|
| 437 |
printf("regEvent[%d] = %#x\n", i, b[i]); |
|---|
| 438 |
} |
|---|
| 439 |
} |
|---|
| 440 |
memcpy(&ns__regkeyArray[i],®List.front(), sizeof(struct ns__regkey)); |
|---|
| 441 |
regDeallocList.push_back(regList.front()); |
|---|
| 442 |
regList.pop_front(); |
|---|
| 443 |
} |
|---|
| 444 |
*result = dRegArray; |
|---|
| 445 |
return SOAP_OK; |
|---|
| 446 |
} |
|---|
| 447 |
int ns__returnFileEvents(struct soap *soap, int maxEventsToReturn, struct ns__dynFileArray **result){ |
|---|
| 448 |
char debug = 1; |
|---|
| 449 |
|
|---|
| 450 |
struct ns__dynFileArray * dFileArray; |
|---|
| 451 |
dFileArray = soap_new_ns__dynFileArray(soap,1); |
|---|
| 452 |
dFileArray->__ptr = NULL; |
|---|
| 453 |
dFileArray->__size = fileList.size(); |
|---|
| 454 |
printf("SIZE= %d",dFileArray->__size); |
|---|
| 455 |
printf("MAX= %d",maxEventsToReturn); |
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 |
if(maxEventsToReturn < dFileArray->__size && maxEventsToReturn != -1){ |
|---|
| 459 |
dFileArray->__size = maxEventsToReturn; |
|---|
| 460 |
} |
|---|
| 461 |
if(debug) printf("Sending back %d file events\n",dFileArray->__size); |
|---|
| 462 |
|
|---|
| 463 |
struct ns__processFile * ns__processFileArray = (struct ns__processFile *)soap_malloc(soap, dFileArray->__size*sizeof(struct ns__processFile)); |
|---|
| 464 |
dFileArray->__ptr = ns__processFileArray; |
|---|
| 465 |
|
|---|
| 466 |
for(unsigned int i = 0; i < dFileArray->__size; i++){ |
|---|
| 467 |
memcpy(&ns__processFileArray[i],&fileList.front(), sizeof(struct ns__processFile)); |
|---|
| 468 |
fileDeallocList.push_back(fileList.front()); |
|---|
| 469 |
fileList.pop_front(); |
|---|
| 470 |
} |
|---|
| 471 |
|
|---|
| 472 |
*result = dFileArray; |
|---|
| 473 |
return SOAP_OK; |
|---|
| 474 |
} |
|---|
| 475 |
int ns__returnProcessEvents(struct soap *soap, int maxEventsToReturn, struct ns__dynProcArray **result){ |
|---|
| 476 |
char debug = 1; |
|---|
| 477 |
|
|---|
| 478 |
struct ns__dynProcArray * dProcArray; |
|---|
| 479 |
dProcArray = soap_new_ns__dynProcArray(soap,1); |
|---|
| 480 |
dProcArray->__ptr = NULL; |
|---|
| 481 |
dProcArray->__size = procList.size(); |
|---|
| 482 |
|
|---|
| 483 |
if(maxEventsToReturn < dProcArray->__size && maxEventsToReturn != -1){ |
|---|
| 484 |
dProcArray->__size = maxEventsToReturn; |
|---|
| 485 |
} |
|---|
| 486 |
if(debug) printf("Sending back %d process events\n",dProcArray->__size); |
|---|
| 487 |
|
|---|
| 488 |
struct ns__osProcess * ns__osProcessArray = (struct ns__osProcess *)soap_malloc(soap, dProcArray->__size*sizeof(struct ns__osProcess)); |
|---|
| 489 |
dProcArray->__ptr = ns__osProcessArray; |
|---|
| 490 |
|
|---|
| 491 |
for(unsigned int i = 0; i < dProcArray->__size; i++){ |
|---|
| 492 |
memcpy(&ns__osProcessArray[i],&procList.front(), sizeof(struct ns__osProcess)); |
|---|
| 493 |
procDeallocList.push_back(procList.front()); |
|---|
| 494 |
procList.pop_front(); |
|---|
| 495 |
} |
|---|
| 496 |
|
|---|
| 497 |
*result = dProcArray; |
|---|
| 498 |
return SOAP_OK; |
|---|
| 499 |
} |
|---|
| 500 |
int ns__returnEvents(struct soap *soap, int maxEventsToReturn, ns__allEvents **result){ |
|---|
| 501 |
char debug = 1; |
|---|
| 502 |
|
|---|
| 503 |
ns__allEvents * all = soap_new_ns__allEvents(soap, 1); |
|---|
| 504 |
all->regkeys = NULL; |
|---|
| 505 |
all->process_files = NULL; |
|---|
| 506 |
all->os_processes = NULL; |
|---|
| 507 |
if(regList.empty() || maxEventsToReturn == 0){ |
|---|
| 508 |
printf("No registry events to send back\n"); |
|---|
| 509 |
} |
|---|
| 510 |
else{ |
|---|
| 511 |
ns__returnRegistryEvents(soap,maxEventsToReturn,&all->regkeys); |
|---|
| 512 |
} |
|---|
| 513 |
if(fileList.empty() || maxEventsToReturn == 0){ |
|---|
| 514 |
printf("No file events to send back\n"); |
|---|
| 515 |
} |
|---|
| 516 |
else{ |
|---|
| 517 |
ns__returnFileEvents(soap,maxEventsToReturn,&all->process_files); |
|---|
| 518 |
} |
|---|
| 519 |
if(procList.empty() || maxEventsToReturn == 0){ |
|---|
| 520 |
printf("No process events to send back\n"); |
|---|
| 521 |
} |
|---|
| 522 |
else{ |
|---|
| 523 |
ns__returnProcessEvents(soap,maxEventsToReturn,&all->os_processes); |
|---|
| 524 |
} |
|---|
| 525 |
|
|---|
| 526 |
*result = all; |
|---|
| 527 |
if(debug) printf("all->regkeys = %#x, all->process_files = %#x, all->os_processes = %#x\n", all->regkeys, all->process_files, all->os_processes); |
|---|
| 528 |
if(debug) printf("regList.size() = %d, fileList.size() = %d, procList.size() = %d\n", regList.size(), fileList.size(), procList.size()); |
|---|
| 529 |
|
|---|
| 530 |
return SOAP_OK; |
|---|
| 531 |
} |
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 |
void dealloc_events(){ |
|---|
| 535 |
|
|---|
| 536 |
if(!regDeallocList.empty()){ |
|---|
| 537 |
for(int i = 0; i < regDeallocList.size(); i++){ |
|---|
| 538 |
free(regDeallocList.front().created_at); |
|---|
| 539 |
free(regDeallocList.front().event_type); |
|---|
| 540 |
free(regDeallocList.front().proc_name); |
|---|
| 541 |
free(regDeallocList.front().name); |
|---|
| 542 |
free(regDeallocList.front().value_name); |
|---|
| 543 |
free(regDeallocList.front().value_type); |
|---|
| 544 |
free(regDeallocList.front().value); |
|---|
| 545 |
regDeallocList.pop_front(); |
|---|
| 546 |
} |
|---|
| 547 |
} |
|---|
| 548 |
|
|---|
| 549 |
if(!fileDeallocList.empty()){ |
|---|
| 550 |
for(int i = 0; i < fileDeallocList.size(); i++){ |
|---|
| 551 |
free(fileDeallocList.front().created_at); |
|---|
| 552 |
free(fileDeallocList.front().event_type); |
|---|
| 553 |
free(fileDeallocList.front().proc_name); |
|---|
| 554 |
free(fileDeallocList.front().name); |
|---|
| 555 |
fileDeallocList.pop_front(); |
|---|
| 556 |
} |
|---|
| 557 |
} |
|---|
| 558 |
|
|---|
| 559 |
if(!procDeallocList.empty()){ |
|---|
| 560 |
for(int i = 0; i < procDeallocList.size(); i++){ |
|---|
| 561 |
free(procDeallocList.front().created_at); |
|---|
| 562 |
free(procDeallocList.front().event_type); |
|---|
| 563 |
free(procDeallocList.front().parent_name); |
|---|
| 564 |
free(procDeallocList.front().name); |
|---|
| 565 |
procDeallocList.pop_front(); |
|---|
| 566 |
} |
|---|
| 567 |
} |
|---|
| 568 |
|
|---|
| 569 |
} |
|---|
| 570 |
|
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 |
int ns__sendMIME(struct soap *soap, int magicNumber, int &result){ |
|---|
| 575 |
printf("In ns__sendMIME\n"); |
|---|
| 576 |
|
|---|
| 577 |
|
|---|
| 578 |
struct soap_multipart * attachment; |
|---|
| 579 |
for(attachment = soap->mime.list; attachment; attachment = attachment->next){ |
|---|
| 580 |
printf("MIME attachment:\n"); |
|---|
| 581 |
printf("Memory=%p\n", (*attachment).ptr); |
|---|
| 582 |
printf("Size=%ul\n", (*attachment).size); |
|---|
| 583 |
printf("Encoding=%d\n", (int)(*attachment).encoding); |
|---|
| 584 |
printf("Type=%s\n", (*attachment).type?(*attachment).type:"null"); |
|---|
| 585 |
printf("ID=%s\n", (*attachment).id?(*attachment).id:"null"); |
|---|
| 586 |
printf("Location=%s\n", (*attachment).location?(*attachment).location:"null"); |
|---|
| 587 |
printf("Description=%s\n", (*attachment).description?(*attachment).description:"null"); |
|---|
| 588 |
} |
|---|
| 589 |
|
|---|
| 590 |
printf("magicNumber = %#x\n", magicNumber); |
|---|
| 591 |
if(magicNumber == 123){ |
|---|
| 592 |
result = 42; |
|---|
| 593 |
} |
|---|
| 594 |
else{ |
|---|
| 595 |
result = 0; |
|---|
| 596 |
} |
|---|
| 597 |
|
|---|
| 598 |
return SOAP_OK; |
|---|
| 599 |
} |
|---|