From 7bfcac6be2e07710977ef486a72188d966d89232 Mon Sep 17 00:00:00 2001 From: Noble_Fish <1065703286@qq.com> Date: Wed, 11 Nov 2026 16:43:40 +0800 Subject: [PATCH 1/3] Fix automatic DLL discovery matching renamed files --- README.md | 4 ++-- SyringeDebugger.cpp | 9 +++++++++ SyringeDebugger.h | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e04959a..9de5742 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ syringe.exe game.exe --args="-CD. -SPAWN" ### DLL Injection Behavior -By default, Syringe injects **all compatible DLLs** found in the directory. +By default, Syringe injects **all compatible DLLs** found in the directory whose long filenames end in `.dll` (case insensitive). Renaming a DLL to `.dlli`, `.dllbak`, or another extension excludes it from automatic discovery, even when its Windows 8.3 short name still ends in `.DLL`. To load only specific DLLs, use one or more instances of: @@ -52,7 +52,7 @@ Example: syringe.exe game.exe -i=ExtensionA.dll -i=ExtensionB.dll ``` -When at least one `-i=` option is present, **only the specified DLLs** are injected. +When at least one `-i=` option is present, **only the specified DLLs** are injected. Explicit `-i=` selections can use other filename extensions. ### Debugger Detach and Process Lifetime diff --git a/SyringeDebugger.cpp b/SyringeDebugger.cpp index 61eca49..b735206 100644 --- a/SyringeDebugger.cpp +++ b/SyringeDebugger.cpp @@ -1414,6 +1414,15 @@ void SyringeDebugger::FindDLLs() { std::string_view const fn(file->cFileName); + // Win32 wildcards also match 8.3 aliases (e.g. a .dlli file can + // have a .DLL alias). Check the long name for automatic discovery; + // explicit -i selections may intentionally use other extensions. + if (bAutoScanDLLs && (fn.size() < 4 + || _stricmp(fn.data() + fn.size() - 4, ".dll") != 0)) + { + continue; + } + // Log::WriteLine( // __FUNCTION__ ": Potential DLL: \"%.*s\"", printable(fn)); diff --git a/SyringeDebugger.h b/SyringeDebugger.h index 5635ac2..d943c7b 100644 --- a/SyringeDebugger.h +++ b/SyringeDebugger.h @@ -79,6 +79,7 @@ class SyringeDebugger if (dlls.empty()) { + bAutoScanDLLs = true; dlls.emplace_back("*.dll"); } @@ -243,6 +244,7 @@ class SyringeDebugger bool bDetachWhenDone{ false }; bool bWaitForProcessEnd{ true }; bool bHandshakes{ false }; + bool bAutoScanDLLs{ false }; bool bDLLsLoaded{ false }; bool bHooksCreated{ false }; From cea9efdcf24bd4fd719933dcdf577e2c55f501cb Mon Sep 17 00:00:00 2001 From: Noble_Fish <1065703286@qq.com> Date: Fri, 13 Nov 2026 01:55:05 +0800 Subject: [PATCH 2/3] Recheck all DLL selections against long filenames Use PathMatchSpecEx for every returned filename, including explicit -i patterns, so 8.3 aliases cannot select unintended extensions. Replace the default-scan-only suffix check with the same filter for all selections. --- Debugger.vcxproj | 4 ++-- README.md | 2 +- SyringeDebugger.cpp | 9 ++++----- SyringeDebugger.h | 2 -- Tests.vcxproj | 4 ++-- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Debugger.vcxproj b/Debugger.vcxproj index 6c235d2..e4d90bb 100644 --- a/Debugger.vcxproj +++ b/Debugger.vcxproj @@ -94,7 +94,7 @@ MachineX86 true true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;dbghelp.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;dbghelp.lib;shlwapi.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) @@ -140,7 +140,7 @@ MachineX86 true true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;dbghelp.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;dbghelp.lib;shlwapi.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) diff --git a/README.md b/README.md index 9de5742..bbbee00 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Example: syringe.exe game.exe -i=ExtensionA.dll -i=ExtensionB.dll ``` -When at least one `-i=` option is present, **only the specified DLLs** are injected. Explicit `-i=` selections can use other filename extensions. +When at least one `-i=` option is present, **only the specified DLLs** are injected. Selections can use exact filenames or wildcard patterns, including other filename extensions. Every selection is checked against the long filename, so `-i=*.dll` also excludes `.dlli` and `.dll+` files that only match through an 8.3 alias. Use their long names or a matching pattern to select them explicitly. ### Debugger Detach and Process Lifetime diff --git a/SyringeDebugger.cpp b/SyringeDebugger.cpp index b735206..b448e6d 100644 --- a/SyringeDebugger.cpp +++ b/SyringeDebugger.cpp @@ -17,6 +17,7 @@ #include #include +#include using namespace std; @@ -1414,11 +1415,9 @@ void SyringeDebugger::FindDLLs() { std::string_view const fn(file->cFileName); - // Win32 wildcards also match 8.3 aliases (e.g. a .dlli file can - // have a .DLL alias). Check the long name for automatic discovery; - // explicit -i selections may intentionally use other extensions. - if (bAutoScanDLLs && (fn.size() < 4 - || _stricmp(fn.data() + fn.size() - 4, ".dll") != 0)) + // Reject matches that only come from an 8.3 alias. + if (PathMatchSpecExA(file->cFileName, PathFindFileNameA(dll.c_str()), + PMSF_NORMAL | PMSF_DONT_STRIP_SPACES) != S_OK) { continue; } diff --git a/SyringeDebugger.h b/SyringeDebugger.h index d943c7b..5635ac2 100644 --- a/SyringeDebugger.h +++ b/SyringeDebugger.h @@ -79,7 +79,6 @@ class SyringeDebugger if (dlls.empty()) { - bAutoScanDLLs = true; dlls.emplace_back("*.dll"); } @@ -244,7 +243,6 @@ class SyringeDebugger bool bDetachWhenDone{ false }; bool bWaitForProcessEnd{ true }; bool bHandshakes{ false }; - bool bAutoScanDLLs{ false }; bool bDLLsLoaded{ false }; bool bHooksCreated{ false }; diff --git a/Tests.vcxproj b/Tests.vcxproj index 798aabd..421a6fb 100644 --- a/Tests.vcxproj +++ b/Tests.vcxproj @@ -73,7 +73,7 @@ MachineX86 false false - kernel32.lib;user32.lib;gdi32.lib;advapi32.lib;shell32.lib;dbghelp.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;advapi32.lib;shell32.lib;dbghelp.lib;shlwapi.lib;%(AdditionalDependencies) true @@ -102,7 +102,7 @@ MachineX86 true true - kernel32.lib;user32.lib;gdi32.lib;advapi32.lib;shell32.lib;dbghelp.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;advapi32.lib;shell32.lib;dbghelp.lib;shlwapi.lib;%(AdditionalDependencies) true From e34002956aac0cc4ffe49d6d92956602fb51254b Mon Sep 17 00:00:00 2001 From: Noble_Fish <1065703286@qq.com> Date: Fri, 13 Nov 2026 01:58:16 +0800 Subject: [PATCH 3/3] Preserve Win32 wildcard matching semantics Use the native DOS wildcard matcher for the long-name recheck so existing -i patterns keep FindFirstFile behavior, including question marks, extensionless names, and trailing-dot normalization. --- Debugger.vcxproj | 6 ++- FileNamePattern.cpp | 113 ++++++++++++++++++++++++++++++++++++++++++++ FileNamePattern.h | 15 ++++++ README.md | 2 +- SyringeDebugger.cpp | 6 +-- Tests.vcxproj | 5 +- 6 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 FileNamePattern.cpp create mode 100644 FileNamePattern.h diff --git a/Debugger.vcxproj b/Debugger.vcxproj index e4d90bb..7d54a5b 100644 --- a/Debugger.vcxproj +++ b/Debugger.vcxproj @@ -94,7 +94,7 @@ MachineX86 true true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;dbghelp.lib;shlwapi.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;dbghelp.lib;ntdll.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) @@ -140,7 +140,7 @@ MachineX86 true true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;dbghelp.lib;shlwapi.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;dbghelp.lib;ntdll.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) @@ -150,6 +150,7 @@ + @@ -158,6 +159,7 @@ + diff --git a/FileNamePattern.cpp b/FileNamePattern.cpp new file mode 100644 index 0000000..a079ce5 --- /dev/null +++ b/FileNamePattern.cpp @@ -0,0 +1,113 @@ +#include "FileNamePattern.h" + +#include "Handle.h" +#include "Support.h" + +#include +#include + +#include + +// The Windows SDK omits these ntdll declarations. +extern "C" NTSYSAPI BOOLEAN NTAPI RtlIsNameInExpression( + PUNICODE_STRING Expression, PUNICODE_STRING Name, BOOLEAN IgnoreCase, + PWCH UpcaseTable); +extern "C" NTSYSAPI NTSTATUS NTAPI RtlUpcaseUnicodeString( + PUNICODE_STRING DestinationString, PCUNICODE_STRING SourceString, + BOOLEAN AllocateDestinationString); + +namespace +{ + std::wstring ToWide(char const* text) + { + // Match FindFirstFileA's code page. + auto const count = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, + text, -1, nullptr, 0); + if (!count) + { + throw_lasterror_or(ERROR_NO_UNICODE_TRANSLATION, text); + } + + std::wstring result(count, L'\0'); + if (!MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, text, -1, + result.data(), count)) + { + throw_lasterror_or(ERROR_NO_UNICODE_TRANSLATION, text); + } + result.pop_back(); + return result; + } + + UNICODE_STRING AsUnicodeString(std::wstring const& text) + { + constexpr auto MaxLength = std::numeric_limits::max(); + if (text.size() > MaxLength / sizeof(wchar_t)) + { + throw_lasterror(ERROR_FILENAME_EXCED_RANGE, {}); + } + auto const length = static_cast(text.size() * sizeof(wchar_t)); + return { length, length, const_cast(text.data()) }; + } +} + +FileNamePattern::FileNamePattern(char const* pathPattern) +{ + auto const path = ToWide(pathPattern); + std::wstring_view pattern = path; + auto const separator = pattern.find_last_of(L"\\/:"); + if (separator != std::wstring_view::npos) + { + pattern.remove_prefix(separator + 1); + } + + // Normalize trailing dots/spaces except in extended paths. + // A trailing '*.' selects extensionless names. + bool extensionless = false; + if (!path.starts_with(L"\\\\?\\")) + { + auto const endedInDot = pattern.ends_with(L'.'); + auto const last = pattern.find_last_not_of(L" ."); + pattern = pattern.substr(0, last == std::wstring_view::npos ? 0 : last + 1); + extensionless = endedInDot && pattern.ends_with(L'*'); + } + + // Use FindFirstFile's DOS_STAR (<), DOS_QM (>), and DOS_DOT (") translation. + expression.reserve(pattern.size()); + for (size_t i = 0; i < pattern.size(); ++i) + { + auto const ch = pattern[i]; + auto const next = i + 1 < pattern.size() ? pattern[i + 1] : L'\0'; + if (ch == L'*' && (next == L'.' || (extensionless && i + 1 == pattern.size()))) + { + expression.push_back(L'<'); + } + else if (ch == L'?') + { + expression.push_back(L'>'); + } + else if (ch == L'.' && (next == L'*' || next == L'?')) + { + expression.push_back(L'"'); + } + else + { + expression.push_back(ch); + } + } + + // IgnoreCase requires an uppercase expression. + auto source = AsUnicodeString(expression); + auto destination = source; + if (RtlUpcaseUnicodeString(&destination, &source, FALSE) < 0) + { + throw_lasterror(ERROR_INVALID_NAME, pathPattern); + } +} + +bool FileNamePattern::Matches(char const* fileName) const +{ + auto const name = ToWide(fileName); + auto patternString = AsUnicodeString(expression); + auto nameString = AsUnicodeString(name); + return RtlIsNameInExpression(&patternString, &nameString, TRUE, nullptr) != FALSE; +} diff --git a/FileNamePattern.h b/FileNamePattern.h new file mode 100644 index 0000000..a466fcc --- /dev/null +++ b/FileNamePattern.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +// Matches Win32 search patterns against long filenames. +class FileNamePattern +{ +public: + explicit FileNamePattern(char const* pathPattern); + + bool Matches(char const* fileName) const; + +private: + std::wstring expression; +}; diff --git a/README.md b/README.md index bbbee00..2765532 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Example: syringe.exe game.exe -i=ExtensionA.dll -i=ExtensionB.dll ``` -When at least one `-i=` option is present, **only the specified DLLs** are injected. Selections can use exact filenames or wildcard patterns, including other filename extensions. Every selection is checked against the long filename, so `-i=*.dll` also excludes `.dlli` and `.dll+` files that only match through an 8.3 alias. Use their long names or a matching pattern to select them explicitly. +When at least one `-i=` option is present, **only the specified DLLs** are injected. Selections can use exact filenames or Win32 wildcard patterns, including other filename extensions. Every selection is checked against the long filename, so `-i=*.dll` also excludes `.dlli` and `.dll+` files that only match through an 8.3 alias. Use their long names or a matching pattern to select them explicitly. ### Debugger Detach and Process Lifetime diff --git a/SyringeDebugger.cpp b/SyringeDebugger.cpp index b448e6d..8fe1774 100644 --- a/SyringeDebugger.cpp +++ b/SyringeDebugger.cpp @@ -2,6 +2,7 @@ #include "CRC32.h" #include "FindFile.h" +#include "FileNamePattern.h" #include "Handle.h" #include "Log.h" #include "Support.h" @@ -17,7 +18,6 @@ #include #include -#include using namespace std; @@ -1411,13 +1411,13 @@ void SyringeDebugger::FindDLLs() { Log::WriteLine(__FUNCTION__ ": Searching for DLLs matching \"%s\"...", dll.c_str()); + FileNamePattern const pattern(dll.c_str()); for (auto file = FindFile(dll.c_str()); file; ++file) { std::string_view const fn(file->cFileName); // Reject matches that only come from an 8.3 alias. - if (PathMatchSpecExA(file->cFileName, PathFindFileNameA(dll.c_str()), - PMSF_NORMAL | PMSF_DONT_STRIP_SPACES) != S_OK) + if (!pattern.Matches(file->cFileName)) { continue; } diff --git a/Tests.vcxproj b/Tests.vcxproj index 421a6fb..b4449ce 100644 --- a/Tests.vcxproj +++ b/Tests.vcxproj @@ -73,7 +73,7 @@ MachineX86 false false - kernel32.lib;user32.lib;gdi32.lib;advapi32.lib;shell32.lib;dbghelp.lib;shlwapi.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;advapi32.lib;shell32.lib;dbghelp.lib;ntdll.lib;%(AdditionalDependencies) true @@ -102,7 +102,7 @@ MachineX86 true true - kernel32.lib;user32.lib;gdi32.lib;advapi32.lib;shell32.lib;dbghelp.lib;shlwapi.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;advapi32.lib;shell32.lib;dbghelp.lib;ntdll.lib;%(AdditionalDependencies) true @@ -111,6 +111,7 @@ +