Skip to content

Path building fixes#36

Merged
nefarius merged 4 commits intomasterfrom
path-handling-fix
Feb 28, 2026
Merged

Path building fixes#36
nefarius merged 4 commits intomasterfrom
path-handling-fix

Conversation

@nefarius
Copy link
Owner

@nefarius nefarius commented Feb 28, 2026

Summary by CodeRabbit

  • Bug Fixes

    • More reliable module path resolution and consistent handling during injection and ejection, reducing failures from ambiguous or relative paths.
  • Chores

    • Updated version number and copyright year to 2026.
  • Configuration

    • Added a new user dictionary settings entry (data-only) to store an indexed value for improved local settings handling.

@nefarius
Copy link
Owner Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

📝 Walkthrough

Walkthrough

Canonicalization and relative-resolution for module paths were added: module matching now compares filenames against canonicalized paths; GetPath was rewritten to resolve relative paths against the injector binary directory. EjectLib parameter type changed to std::wstring. A spell-check dictionary entry was added and version/date strings updated.

Changes

Cohort / File(s) Summary
Settings
Injector.sln.DotSettings
Added a boolean dictionary entry /Default/UserDictionary/Words/=Nefarius/@EntryIndexedValue = True.
Version / Metadata
Injector/Main.cpp
Updated version from 2024021820260228 and copyright range 2012-20242012-2026.
Path resolution & module matching
Injector/Injector.cpp
Rewrote GetPath to canonicalize input via GetFullPathName, resolve relative paths against the injector executable directory, and preserve Unicode/ANSI error handling. Modified GetModuleBaseAddress to derive a canonical search path and compare module filename and canonical exe path (removed temporary found flag; returns on first match). Added Shlwapi.h include.
Callsites & API surface
Injector/Main.cpp
Always obtain module path via Injector::Get()->GetPath(mod) for inject/eject flows; removed conditional path-relativity logic and PathIsRelative dependency. Changed call usage to match Injector::EjectLib(DWORD, std::wstring) (second parameter now std::wstring).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through paths and made them clean,
Filenames matched where full paths had been,
Version bumped, a tiny dictionary cheer,
Wstrings snug, no more stray fear,
A rabbit's patch — concise and keen.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Path building fixes' accurately reflects the main changes across the pull request, which involve rewriting path resolution logic in GetPath, updating path canonicalization in GetModuleBaseAddress, and adjusting module path handling in Main.cpp.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch path-handling-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
Injector/Injector.cpp (1)

273-276: Consider handling paths longer than MAX_PATH.

If the loader path exceeds MAX_PATH characters, GetModuleFileName will truncate and set ERROR_INSUFFICIENT_BUFFER. The current check correctly throws, but the error message could be more specific about truncation. This is a minor edge case on most systems.

♻️ Optional: More specific error message
 		if (!GetModuleFileName(NULL, &LoaderPath[0], static_cast<DWORD>(LoaderPath.size())) ||
 			GetLastError() == ERROR_INSUFFICIENT_BUFFER)
-			throw std::runtime_error("Could not get path to loader.");
+			throw std::runtime_error("Could not get path to loader (path may exceed MAX_PATH).");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Injector/Injector.cpp` around lines 273 - 276, The error handling around
GetModuleFileName using the LoaderPath buffer (std::vector<TCHAR>
LoaderPath(MAX_PATH)) should distinguish a truncated path due to
ERROR_INSUFFICIENT_BUFFER from other failures and provide a clearer message;
update the block that calls GetModuleFileName (and checks GetLastError()) to
detect ERROR_INSUFFICIENT_BUFFER specifically and throw a runtime_error that
mentions the path was truncated/too long (or retry with a larger
buffer/long-path API), referencing the LoaderPath variable and the
GetModuleFileName call in your update.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@Injector/Injector.cpp`:
- Around line 273-276: The error handling around GetModuleFileName using the
LoaderPath buffer (std::vector<TCHAR> LoaderPath(MAX_PATH)) should distinguish a
truncated path due to ERROR_INSUFFICIENT_BUFFER from other failures and provide
a clearer message; update the block that calls GetModuleFileName (and checks
GetLastError()) to detect ERROR_INSUFFICIENT_BUFFER specifically and throw a
runtime_error that mentions the path was truncated/too long (or retry with a
larger buffer/long-path API), referencing the LoaderPath variable and the
GetModuleFileName call in your update.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a67a67b and a8215f4.

📒 Files selected for processing (3)
  • Injector.sln.DotSettings
  • Injector/Injector.cpp
  • Injector/Main.cpp

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
Injector/Injector.cpp (1)

251-291: Well-structured path resolution with good fallback behavior.

The two-phase resolution (CWD first, then injector directory) provides good backward compatibility. The comments clearly document the intent.

Minor consideration: Line 281 assumes GetModuleFileName returns a path containing a backslash. While this is true in practice (it returns absolute paths), a defensive check would make this more robust:

🔧 Optional defensive check
 std::tstring LoaderDir(&LoaderPath[0]);
-LoaderDir = LoaderDir.substr(0, LoaderDir.rfind(_T("\\")) + 1);
+auto LastSep = LoaderDir.rfind(_T('\\'));
+if (LastSep != std::tstring::npos)
+    LoaderDir = LoaderDir.substr(0, LastSep + 1);
+else
+    LoaderDir.clear();
 LoaderDir.append(ModuleName);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Injector/Injector.cpp` around lines 251 - 291, The code assumes
GetModuleFileName(...) yields a path containing a backslash and calls
LoaderDir.rfind(_T("\\")) without checking the result; update the logic in
Injector::GetPath to defensively find the last path separator (use find_last_of
on both '\\' and '/' or verify rfind didn't return npos) before calling substr,
and handle the no-separator case (e.g., treat LoaderDir as empty directory or
use full LoaderDir appropriately) so LoaderDir.substr(...) cannot throw or
produce an invalid range; reference the GetModuleFileName call, the LoaderDir
variable, and the LoaderDir.rfind(...) usage when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@Injector/Injector.cpp`:
- Around line 251-291: The code assumes GetModuleFileName(...) yields a path
containing a backslash and calls LoaderDir.rfind(_T("\\")) without checking the
result; update the logic in Injector::GetPath to defensively find the last path
separator (use find_last_of on both '\\' and '/' or verify rfind didn't return
npos) before calling substr, and handle the no-separator case (e.g., treat
LoaderDir as empty directory or use full LoaderDir appropriately) so
LoaderDir.substr(...) cannot throw or produce an invalid range; reference the
GetModuleFileName call, the LoaderDir variable, and the LoaderDir.rfind(...)
usage when making the change.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8215f4 and 75fdc60.

📒 Files selected for processing (1)
  • Injector/Injector.cpp

@nefarius nefarius linked an issue Feb 28, 2026 that may be closed by this pull request
@nefarius nefarius merged commit 9ab9ebf into master Feb 28, 2026
2 checks passed
@nefarius nefarius deleted the path-handling-fix branch February 28, 2026 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Load library from different path fails (LoadLibrary call fail).

1 participant