microsoft / Detours

Detours is a software package for monitoring and instrumenting API calls on Windows. It is distributed in source code form.
MIT License
5.01k stars 979 forks source link

Enable compilation time configuration of maximum section count and expose DetourIsFunctionImported #225

Closed JohnMcPMS closed 2 years ago

JohnMcPMS commented 2 years ago

A few minor changes:

  1. Expose detour_is_imported via a new public function DetourIsFunctionImported
  2. Make certain runtime checks happy by masking pbTarget before casting to smaller type
  3. Enable user to compile with a different number of supported section headers (leaves default at 32)
Microsoft Reviewers: Open in CodeFlow
JohnMcPMS commented 2 years ago

DetourEnumerateModules appears to be flaky; failing in one flavor last build and two this time (both debug/2019).

-------------------------------------------------------------------------------
DetourEnumerateModules
  Passing nullptr, results in current module being returned
-------------------------------------------------------------------------------
test_module_api.cpp(237)
...............................................................................

test_module_api.cpp(243): PASSED:
  REQUIRE( GetLastError() == 0L )
with expansion:
  0 == 0

test_module_api.cpp(244): FAILED:
  REQUIRE( mod == reinterpret_cast<HMODULE>(&__ImageBase) )
with expansion:
  0x005b0000 == 0x01260000

0.000 s: Passing nullptr, results in current module being returned
0.000 s: DetourEnumerateModules
-------------------------------------------------------------------------------

None of my changes should have affected this function. Maybe ASLR is enabled on the 2019 server images? This test expects that the first module in memory is the exe, and given the behavior it seems the most likely culprit.

jaykrell commented 2 years ago

That sounds plausible. The base address of .exes used to be quite predictable.

bgianfo commented 2 years ago

I sent out PR #227 to fix the test, thanks for pointing that out!

ghost commented 2 years ago

This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days.

JohnMcPMS commented 2 years ago

@bgianfo , what changes are still needed?

bgianfo commented 2 years ago

@bgianfo , what changes are still needed?

Sorry, no re-review was requested, so I didn't know it was ready. Merged, thanks!