Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int Run(const std::vector<std::string>& arguments)
{
MessageBoxA(
nullptr, "Syringe cannot be run like that.\n\n"
"Usage:\nSyringe.exe <exe name> [-i=<injectedfile.dll> ...] [--args=\"<arguments>\"]",
"Usage:\nSyringe.exe <exe name> [-i=<injectedfile.dll> ...] [-- <arguments>]",
VersionString, MB_OK | MB_ICONINFORMATION);

Log::WriteLine(
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ syringe.exe game.exe

### Passing Arguments to the Target Executable

Use `--args="..."` to provide arguments for the launched process:
Use `--` as a delimiter to pass arguments to the launched process. All arguments after `--` will be forwarded directly to the target executable:

```
syringe.exe game.exe --args="-CD. -SPAWN"
syringe.exe game.exe -- -CD. -SPAWN
```

### DLL Injection Behavior
Expand Down
35 changes: 25 additions & 10 deletions Support.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ inline auto trim(std::string_view string) noexcept

inline auto parse_command_line(const std::vector<std::string>& arguments)
{
static constexpr std::string_view ARGS_FLAG = "--args=";

struct argument_set
{
std::vector<std::string> syringe_arguments;
Expand All @@ -45,32 +43,49 @@ inline auto parse_command_line(const std::vector<std::string>& arguments)
// First non-flag argument becomes executable name
bool exe_found = false;

bool exe_arguments = false;

for (const auto& arg : arguments)
{
// executable name: first argument not starting with '-'
if (!exe_found && !arg.starts_with("-"))
{
exe_found = true;
ret.executable_name = arg;
if (arg.starts_with('"') && arg.ends_with('"'))
ret.executable_name = arg.substr(1, arg.length() - 2);
else
ret.executable_name = arg;

continue;
}

// game arguments: --args="blob"
if (arg.starts_with(ARGS_FLAG))
if (arg == "--")
{
// extract after --args=
std::string blob = arg.substr(ARGS_FLAG.size());
ret.game_arguments = blob;
exe_arguments = true;
continue;
}

// Syringe arguments
ret.syringe_arguments.push_back(arg);
if (exe_arguments)
{
// game arguments
ret.game_arguments += " ";
ret.game_arguments += arg;
}
else
{
// Syringe arguments
if (arg.starts_with("-i=\"") && arg.ends_with('"'))
ret.syringe_arguments.push_back("-i=" + arg.substr(4, arg.length() - 5));
else
ret.syringe_arguments.push_back(arg);
}
}

if (!exe_found || ret.executable_name.empty())
throw invalid_command_arguments{};

ret.game_arguments = ret.game_arguments.substr(1);

return ret;
}

Expand Down