uwpinject.c
/* TODO: make this function more readable */
/* windows will suspend the app's process and call us back with "-p pid" */
make this function more readable
windows will suspend the app's process and call us back with "-p pid"
make this function more readable windows will suspend the app ' s process and call us back with " - p pid "
void cli_inject(int argc, wchar_t* argv[]) {
  wchar_t fullpath[MAX_PATH];
  wchar_t* p;
  int pid = 0;
  int i;
  HANDLE find;
  WIN32_FIND_DATAW fd;
  DWORD err;
  int success = 1;
  for (i = 1; i < argc - 1; ++i) {
    if (!wcscmp(argv[i], L"-p")) {
      pid = _wtoi(argv[i + 1]);
      break;
    }
  }
  wcscpy_s(fullpath, sizeof(fullpath), argv[0]);
  p = &fullpath[wcslen(fullpath) - 1];
  for (; p > fullpath && *p != '\\'; --p);
  *p = 0;
  wcscat_s(fullpath, sizeof(fullpath), L"\\dlls\\*.dll");
  find = FindFirstFileW(fullpath, &fd);
  if (find == INVALID_HANDLE_VALUE) {
    win32_perror((int)GetLastError(), L"FindFirstFileW failed");
    success = 0;
    goto cleanup;
  }
  p = &fullpath[wcslen(fullpath) - 1];
  for (; p > fullpath && *p != '\\'; --p);
  *p = 0;
  do {
    wprintf(L"%s\n", fd.cFileName);
    if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
      continue;
    }
    *p = 0;
    wcscat_s(fullpath, sizeof(fullpath), L"\\");
    wcscat_s(fullpath, sizeof(fullpath), fd.cFileName);
    wprintf(L"injecting %s into process %d\n", fullpath, pid);
    uwp_fileperm(fullpath);
    if (!win32_inject(pid, fullpath)) {
      success = 0;
      goto cleanup;
    }
  } while (FindNextFileW(find, &fd));
  err = GetLastError();
  if (err != ERROR_NO_MORE_FILES) {
    win32_perror((int)err, L"FindNextFileW failed");
    success = 0;
    goto cleanup;
  }
cleanup:
  if (!win32_resume(pid) || !success) {
    for (;;) {
      Sleep(1000);
    }
  }
}
void cli_inject ( int argc , wchar_t * argv [ ] ) { wchar_t fullpath [ MAX_PATH ] ; wchar_t * p ; int pid = 0 ; int i ; HANDLE find ; WIN32_FIND_DATAW fd ; DWORD err ; int success = 1 ; for ( i = 1 ; i < argc - 1 ; ++ i ) { if ( ! wcscmp ( argv [ i ] , L" " ) ) { pid = _wtoi ( argv [ i + 1 ] ) ; break ; } } wcscpy_s ( fullpath , sizeof ( fullpath ) , argv [ 0 ] ) ; p = & fullpath [ wcslen ( fullpath ) - 1 ] ; for ( ; p > fullpath && * p != ' \\ ' ; -- p ) ; * p = 0 ; wcscat_s ( fullpath , sizeof ( fullpath ) , L" \\ \\ " ) ; find = FindFirstFileW ( fullpath , & fd ) ; if ( find == INVALID_HANDLE_VALUE ) { win32_perror ( ( int ) GetLastError ( ) , L" " ) ; success = 0 ; goto cleanup ; } p = & fullpath [ wcslen ( fullpath ) - 1 ] ; for ( ; p > fullpath && * p != ' \\ ' ; -- p ) ; * p = 0 ; do { wprintf ( L" \n " , fd . cFileName ) ; if ( fd . dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { continue ; } * p = 0 ; wcscat_s ( fullpath , sizeof ( fullpath ) , L" \\ " ) ; wcscat_s ( fullpath , sizeof ( fullpath ) , fd . cFileName ) ; wprintf ( L" \n " , fullpath , pid ) ; uwp_fileperm ( fullpath ) ; if ( ! win32_inject ( pid , fullpath ) ) { success = 0 ; goto cleanup ; } } while ( FindNextFileW ( find , & fd ) ) ; err = GetLastError ( ) ; if ( err != ERROR_NO_MORE_FILES ) { win32_perror ( ( int ) err , L" " ) ; success = 0 ; goto cleanup ; } cleanup : if ( ! win32_resume ( pid ) || ! success ) { for ( ; ; ) { Sleep ( 1000 ) ; } } }
TODO: make this function more readable
windows will suspend the app's process and call us back with "-p pid"
TODO : make this function more readable windows will suspend the app ' s process and call us back with " - p pid "
/* get full path to dlls by stripping last element from argv[0] */