File tree Expand file tree Collapse file tree 2 files changed +30
-16
lines changed Expand file tree Collapse file tree 2 files changed +30
-16
lines changed Original file line number Diff line number Diff line change 5
5
#include " Common.hpp"
6
6
7
7
// /
8
- // / Scope-managed handles
8
+ // / @brief Scope-managed handles
9
9
// /
10
10
// / @ref https://andreasfertig.blog/2022/08/cpp-insights-lambdas-in-unevaluated-contexts/
11
- // / @link https://developercommunity.visualstudio.com/t/c20-internal-compiler-error-for-lambda-in-decltype/1631476
12
11
// /
13
12
template <typename T, auto Deleter>
14
13
using GenericHandle = std::unique_ptr<
@@ -26,8 +25,30 @@ using GenericHandle = std::unique_ptr<
26
25
#ifdef __linux__
27
26
using UniqueHandle = GenericHandle<FILE, ::fclose>;
28
27
#else
29
- using UniqueHandle = GenericHandle<void , ::CloseHandle>;
28
+
29
+ // /
30
+ // / @brief A unique (as-in `unique_ptr`) Windows handle. It will close itself on scope-exit.
31
+ // /
32
+ using UniqueHandle = GenericHandle<void , ::CloseHandle>;
33
+
34
+ // /
35
+ // / @brief A unique (as-in `unique_ptr`) Windows module handle.
36
+ // /
30
37
using UniqueLibraryHandle = GenericHandle<HINSTANCE__, ::FreeLibrary>;
38
+
39
+ // /
40
+ // / @brief A unique Windows Critical Section.
41
+ // /
42
+ using UniqueCriticalSection = GenericHandle<
43
+ RTL_CRITICAL_SECTION,
44
+ [](RTL_CRITICAL_SECTION* p)
45
+ {
46
+ if ( p )
47
+ {
48
+ ::LeaveCriticalSection (p);
49
+ p = nullptr ;
50
+ }
51
+ }>;
31
52
#endif // __linux__
32
53
33
54
using SharedHandle = std::shared_ptr<UniqueHandle>;
Original file line number Diff line number Diff line change 27
27
GetPebLength ();
28
28
EXTERN_C_END
29
29
30
- using CriticalSection = GenericHandle<
31
- RTL_CRITICAL_SECTION,
32
- [](auto p)
33
- {
34
- ::LeaveCriticalSection (p);
35
- }>;
36
-
37
30
38
31
namespace pwn ::Process
39
32
{
@@ -590,12 +583,12 @@ Process::EnumerateLocalModules()
590
583
{
591
584
std::vector<LDR_DATA_TABLE_ENTRY> res;
592
585
auto peb = Peb ();
593
- CriticalSection csLoaderLock {[&]()
594
- {
595
- auto lock = peb->LoaderLock ;
596
- ::EnterCriticalSection (lock);
597
- return lock;
598
- }()};
586
+ UniqueCriticalSection csLoaderLock {[&]()
587
+ {
588
+ auto lock = peb->LoaderLock ;
589
+ ::EnterCriticalSection (lock);
590
+ return lock;
591
+ }()};
599
592
600
593
if ( !peb->Ldr ->Initialized )
601
594
return Ok (res);
You can’t perform that action at this time.
0 commit comments