injectdll.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Name: injectdll
  3. * Version: 0.1.0
  4. * Description: A simple program to inject a DLL in a running process
  5. * Dependencies: bzb
  6. */
  7. #include "bzbio.h"
  8. #include "bzbfile.h"
  9. #include "bzbmem.h"
  10. #include "bzbutil.h"
  11. constexpr int VERSION_MAJOR = 0;
  12. constexpr int VERSION_MINOR = 1;
  13. constexpr int VERSION_PATCH = 0;
  14. using namespace bzbio;
  15. int main(int argc, char const *argv[]) {
  16. std::string exename;
  17. std::string dllname;
  18. println("Executable name:");
  19. getline(std::cin, exename);
  20. println("DLL name:");
  21. getline(std::cin, dllname);
  22. auto pids = bzbmem::get_pid_by_name(exename);
  23. if(pids.size() == 0) {
  24. println("No process found...");
  25. exit(0);
  26. }
  27. println("Processes created by ", exename);
  28. for(size_t i = 0; i < pids.size(); ++i) {
  29. println('[', i, ']', "\t", pids[i]);
  30. }
  31. size_t selection;
  32. print("\n> ");
  33. std::cin >> selection;
  34. if(selection > pids.size()) {
  35. println("ERROR Incorrect value");
  36. exit(1);
  37. }
  38. int pid = pids[selection];
  39. unsigned long int ret;
  40. println("Injecting DLL into process with PID ", pid, "...");
  41. try {
  42. ret = bzbmem::inject_dll(pid, dllname);
  43. } catch (std::system_error err) {
  44. println("ERROR ", err.what());
  45. exit(1);
  46. }
  47. println("Process PID: ", ret);
  48. return 0;
  49. }