Changeset 1661
- Timestamp:
- 07/21/08 00:47:21 (3 months ago)
- Files:
-
- libemu/trunk/tools/sctest/Makefile.am (modified) (1 diff)
- libemu/trunk/tools/sctest/nanny.c (added)
- libemu/trunk/tools/sctest/nanny.h (added)
- libemu/trunk/tools/sctest/sctestmain.c (modified) (5 diffs)
- libemu/trunk/tools/sctest/userhooks.c (modified) (5 diffs)
- libemu/trunk/tools/sctest/userhooks.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libemu/trunk/tools/sctest/Makefile.am
r1654 r1661 18 18 sctest_SOURCES += userhooks.c 19 19 sctest_SOURCES += userhooks.h 20 #sctest_SOURCES += nanny.c21 #sctest_SOURCES += nanny.h20 sctest_SOURCES += nanny.c 21 sctest_SOURCES += nanny.h 22 22 libemu/trunk/tools/sctest/sctestmain.c
r1654 r1661 96 96 #include "dot.h" 97 97 #include "tests.h" 98 #include "nanny.h" 99 98 100 99 101 struct run_time_options opts; … … 131 133 struct emu_env *env = emu_env_new(e); 132 134 135 struct nanny *na = nanny_new(); 133 136 // lenv->profile = wenv->profile; 134 137 … … 151 154 if ( opts.interactive == true ) 152 155 { 156 157 emu_env_w32_load_dll(env->env.win,"msvcrt.dll"); 158 emu_env_w32_export_hook(env, "fclose", user_hook_fclose, na); 159 emu_env_w32_export_hook(env, "fopen", user_hook_fopen, na); 160 emu_env_w32_export_hook(env, "fwrite", user_hook_fwrite, na); 161 153 162 emu_env_w32_export_hook(env, "CreateProcessA", user_hook_CreateProcess, NULL); 154 163 emu_env_w32_export_hook(env, "WaitForSingleObject", user_hook_WaitForSingleObject, NULL); 164 emu_env_w32_export_hook(env, "CreateFileA", user_hook_CreateFile, na); 165 emu_env_w32_export_hook(env, "WriteFile", user_hook_WriteFile, na); 166 emu_env_w32_export_hook(env, "CloseHandle", user_hook_CloseHandle, na); 167 155 168 156 169 emu_env_w32_load_dll(env->env.win,"ws2_32.dll"); … … 159 172 emu_env_w32_export_hook(env, "closesocket", user_hook_closesocket, NULL); 160 173 emu_env_w32_export_hook(env, "connect", user_hook_connect, NULL); 161 emu_env_w32_export_hook(env, "fclose", user_hook_fclose, NULL);162 emu_env_w32_export_hook(env, "fopen", user_hook_fopen, NULL);163 emu_env_w32_export_hook(env, "fwrite", user_hook_fwrite, NULL);164 174 165 175 emu_env_w32_export_hook(env, "listen", user_hook_listen, NULL); … … 402 412 403 413 emu_profile_debug(env->profile); 404 emu_profile_dump(env->profile, opts.profile_file); 414 415 if (opts.profile_file) 416 emu_profile_dump(env->profile, opts.profile_file); 405 417 406 418 if (eh != NULL) libemu/trunk/tools/sctest/userhooks.c
r1653 r1661 86 86 #include "userhooks.h" 87 87 #include "options.h" 88 #include "nanny.h" 88 89 89 90 #include <stdint.h> … … 340 341 printf("Hook me Captain Cook!\n"); 341 342 printf("%s:%i %s\n",__FILE__,__LINE__,__FUNCTION__); 342 return 0; 343 //int fclose(FILE *fp); 344 345 va_list vl; 346 va_start(vl, hook); 347 FILE *f = va_arg(vl, FILE *); 348 va_end(vl); 349 350 struct nanny_file *nf = nanny_get_file(hook->hook.win->userdata, (uint32_t)f); 351 352 if (nf != NULL) 353 { 354 FILE *f = nf->real_file; 355 nanny_del_file(hook->hook.win->userdata, (uint32_t)f); 356 return fclose(f); 357 } 358 else 359 return 0; 360 343 361 } 344 362 … … 348 366 printf("Hook me Captain Cook!\n"); 349 367 printf("%s:%i %s\n",__FILE__,__LINE__,__FUNCTION__); 350 return 0; 368 369 va_list vl; 370 va_start(vl, hook); 371 372 char *filename = va_arg(vl, char *); 373 /*char *mode = */(void)va_arg(vl, char *); 374 va_end(vl); 375 376 377 char *localfile; 378 asprintf(&localfile, "/tmp/%s-XXXXXX",filename); 379 int fd = mkstemp(localfile); 380 close(fd); 381 382 FILE *f = fopen(localfile,"w"); 383 384 uint32_t file; 385 nanny_add_file(hook->hook.win->userdata, localfile, &file, f); 386 387 return file; 351 388 } 352 389 … … 355 392 printf("Hook me Captain Cook!\n"); 356 393 printf("%s:%i %s\n",__FILE__,__LINE__,__FUNCTION__); 357 return 0; 394 395 /* size_t fwrite(const void *ptr, size_t size, size_t nmemb, 396 FILE *stream); 397 */ 398 va_list vl; 399 va_start(vl, hook); 400 void *data = va_arg(vl, void *); 401 size_t size = va_arg(vl, size_t); 402 size_t nmemb = va_arg(vl, size_t); 403 FILE *f = va_arg(vl, FILE *); 404 va_end(vl); 405 406 struct nanny_file *nf = nanny_get_file(hook->hook.win->userdata, (uint32_t)f); 407 408 if (nf != NULL) 409 return fwrite(data, size, nmemb, nf->real_file); 410 else 411 return size*nmemb; 412 358 413 } 359 414 … … 450 505 } 451 506 507 508 uint32_t user_hook_CreateFile(struct emu_env *env, struct emu_env_hook *hook, ...) 509 { 510 printf("Hook me Captain Cook!\n"); 511 printf("%s:%i %s\n",__FILE__,__LINE__,__FUNCTION__); 512 /* 513 HANDLE CreateFile( 514 LPCTSTR lpFileName, 515 DWORD dwDesiredAccess, 516 DWORD dwShareMode, 517 LPSECURITY_ATTRIBUTES lpSecurityAttributes, 518 DWORD dwCreationDisposition, 519 DWORD dwFlagsAndAttributes, 520 HANDLE hTemplateFile 521 ); 522 */ 523 524 va_list vl; 525 va_start(vl, hook); 526 char *lpFileName = va_arg(vl, char *); 527 /*int dwDesiredAccess =*/(void)va_arg(vl, int); 528 /*int dwShareMode =*/(void)va_arg(vl, int); 529 /*int lpSecurityAttributes =*/(void)va_arg(vl, int); 530 /*int dwCreationDisposition =*/(void)va_arg(vl, int); 531 /*int dwFlagsAndAttributes =*/(void)va_arg(vl, int); 532 /*int hTemplateFile =*/(void)va_arg(vl, int); 533 va_end(vl); 534 535 char *localfile; 536 asprintf(&localfile, "/tmp/%s-XXXXXX",lpFileName); 537 int fd = mkstemp(localfile); 538 close(fd); 539 540 FILE *f = fopen(localfile,"w"); 541 542 uint32_t handle; 543 nanny_add_file(hook->hook.win->userdata, localfile, &handle, f); 544 545 return (uint32_t)handle; 546 } 547 548 uint32_t user_hook_WriteFile(struct emu_env *env, struct emu_env_hook *hook, ...) 549 { 550 printf("Hook me Captain Cook!\n"); 551 printf("%s:%i %s\n",__FILE__,__LINE__,__FUNCTION__); 552 /* 553 BOOL WriteFile( 554 HANDLE hFile, 555 LPCVOID lpBuffer, 556 DWORD nNumberOfBytesToWrite, 557 LPDWORD lpNumberOfBytesWritten, 558 LPOVERLAPPED lpOverlapped 559 ); 560 */ 561 562 va_list vl; 563 va_start(vl, hook); 564 FILE *hFile = va_arg(vl, FILE *); 565 void *lpBuffer = va_arg(vl, void *); 566 int nNumberOfBytesToWrite = va_arg(vl, int); 567 /* int *lpNumberOfBytesWritten =*/(void)va_arg(vl, int*); 568 /* int *lpOverlapped =*/(void)va_arg(vl, int*); 569 va_end(vl); 570 571 struct nanny_file *nf = nanny_get_file(hook->hook.win->userdata, (uint32_t)hFile); 572 573 if (nf != NULL) 574 fwrite(lpBuffer, nNumberOfBytesToWrite, 1, nf->real_file); 575 else 576 printf("shellcode tried to write data to not existing handle\n"); 577 578 return 1; 579 580 } 581 582 583 uint32_t user_hook_CloseHandle(struct emu_env *env, struct emu_env_hook *hook, ...) 584 { 585 printf("Hook me Captain Cook!\n"); 586 printf("%s:%i %s\n",__FILE__,__LINE__,__FUNCTION__); 587 /* 588 BOOL CloseHandle( 589 HANDLE hObject 590 ); 591 */ 592 593 va_list vl; 594 va_start(vl, hook); 595 FILE *hObject = va_arg(vl, FILE *); 596 va_end(vl); 597 598 struct nanny_file *nf = nanny_get_file(hook->hook.win->userdata, (uint32_t)hObject); 599 600 if (nf != NULL) 601 { 602 FILE *f = nf->real_file; 603 nanny_del_file(hook->hook.win->userdata, (uint32_t)hObject); 604 fclose(f); 605 } 606 else 607 { 608 printf("shellcode tried to close not existing handle (maybe closed it already?)\n"); 609 } 610 611 612 return 0; 613 614 } 615 libemu/trunk/tools/sctest/userhooks.h
r1653 r1661 18 18 uint32_t user_hook_WSASocket(struct emu_env *env, struct emu_env_hook *hook, ...); 19 19 20 uint32_t user_hook_CreateFile(struct emu_env *env, struct emu_env_hook *hook, ...); 21 uint32_t user_hook_WriteFile(struct emu_env *env, struct emu_env_hook *hook, ...); 22 uint32_t user_hook_CloseHandle(struct emu_env *env, struct emu_env_hook *hook, ...);
