├── .gitignore ├── Callback Extension ├── Callback Extension.sln └── Callbacks │ ├── Callbacks.vcxproj │ ├── Callbacks.vcxproj.filters │ ├── callbacks.cpp │ ├── callbacks.h │ ├── dllmain.cpp │ ├── framework.h │ ├── pch.cpp │ └── pch.h ├── Images └── all.PNG └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /Callback Extension/Callback Extension.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31005.135 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Callbacks", "Callbacks\Callbacks.vcxproj", "{C0384D36-D080-41BC-AC7C-3BCF5B0AF64D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {C0384D36-D080-41BC-AC7C-3BCF5B0AF64D}.Debug|x64.ActiveCfg = Debug|x64 17 | {C0384D36-D080-41BC-AC7C-3BCF5B0AF64D}.Debug|x64.Build.0 = Debug|x64 18 | {C0384D36-D080-41BC-AC7C-3BCF5B0AF64D}.Debug|x86.ActiveCfg = Debug|Win32 19 | {C0384D36-D080-41BC-AC7C-3BCF5B0AF64D}.Debug|x86.Build.0 = Debug|Win32 20 | {C0384D36-D080-41BC-AC7C-3BCF5B0AF64D}.Release|x64.ActiveCfg = Release|x64 21 | {C0384D36-D080-41BC-AC7C-3BCF5B0AF64D}.Release|x64.Build.0 = Release|x64 22 | {C0384D36-D080-41BC-AC7C-3BCF5B0AF64D}.Release|x86.ActiveCfg = Release|Win32 23 | {C0384D36-D080-41BC-AC7C-3BCF5B0AF64D}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {A6CD035B-83FA-4D24-BF58-CA45C323E807} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Callback Extension/Callbacks/Callbacks.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {c0384d36-d080-41bc-ac7c-3bcf5b0af64d} 25 | Callbacks 26 | 10.0 27 | 28 | 29 | 30 | DynamicLibrary 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | DynamicLibrary 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | DynamicLibrary 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | DynamicLibrary 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;CALLBACKS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 90 | true 91 | Use 92 | pch.h 93 | stdcpp17 94 | stdc17 95 | MultiThreaded 96 | 97 | 98 | Windows 99 | true 100 | false 101 | dbgeng.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 102 | 103 | 104 | 105 | 106 | Level3 107 | true 108 | true 109 | true 110 | WIN32;NDEBUG;CALLBACKS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 111 | true 112 | Use 113 | pch.h 114 | stdcpp17 115 | stdc17 116 | MultiThreaded 117 | 118 | 119 | Windows 120 | true 121 | true 122 | true 123 | false 124 | dbgeng.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 125 | 126 | 127 | 128 | 129 | Level3 130 | true 131 | _DEBUG;CALLBACKS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 132 | true 133 | Use 134 | pch.h 135 | stdcpp17 136 | stdc17 137 | MultiThreaded 138 | 139 | 140 | Windows 141 | true 142 | false 143 | dbgeng.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 144 | 145 | 146 | 147 | 148 | Level3 149 | true 150 | true 151 | true 152 | NDEBUG;CALLBACKS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 153 | true 154 | Use 155 | pch.h 156 | stdcpp17 157 | stdc17 158 | MultiThreaded 159 | 160 | 161 | Windows 162 | true 163 | true 164 | true 165 | false 166 | dbgeng.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | Create 179 | Create 180 | Create 181 | Create 182 | 183 | 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /Callback Extension/Callbacks/Callbacks.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | 29 | 30 | Source Files 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | -------------------------------------------------------------------------------- /Callback Extension/Callbacks/callbacks.cpp: -------------------------------------------------------------------------------- 1 | // callbacks.cpp : Defines the exported functions for the DLL. 2 | // 3 | 4 | #include "pch.h" 5 | #include "framework.h" 6 | #include "callbacks.h" 7 | 8 | WINDBG_EXTENSION_APIS ExtensionApis; 9 | 10 | PIDebugClient g_pDebugClient = nullptr; 11 | PIDebugControl g_pDebugControl = nullptr; 12 | PIDebugSymbols g_pSymbols = nullptr; 13 | 14 | /// 15 | /// Init will intiate the global variables used by this extension to use printing, symbols, etc. 16 | /// 17 | /// S_OK if successful 18 | HRESULT init() 19 | { 20 | HRESULT hResult = DebugCreate(__uuidof(IDebugClient), reinterpret_cast(&g_pDebugClient)); 21 | if (FAILED(hResult)) 22 | { 23 | g_pDebugControl->Output(DEBUG_OUTPUT_ERROR, "[%ws::%d] Failed with status: %d\n", __FUNCTIONW__, __LINE__, hResult); 24 | return hResult; 25 | } 26 | 27 | hResult = g_pDebugClient->QueryInterface(__uuidof(IDebugControl), reinterpret_cast(&g_pDebugControl)); 28 | if (FAILED(hResult)) 29 | { 30 | g_pDebugControl->Output(DEBUG_OUTPUT_ERROR, "[%ws::%d] Failed with status: %d\n", __FUNCTIONW__, __LINE__, hResult); 31 | return hResult; 32 | } 33 | 34 | ExtensionApis.nSize = sizeof(ExtensionApis); 35 | hResult = g_pDebugControl->GetWindbgExtensionApis64(&ExtensionApis); 36 | if (FAILED(hResult)) 37 | { 38 | g_pDebugControl->Output(DEBUG_OUTPUT_ERROR, "[%ws::%d] Failed with status: %d\n", __FUNCTIONW__, __LINE__, hResult); 39 | return hResult; 40 | } 41 | 42 | hResult = g_pDebugClient->QueryInterface(__uuidof(IDebugSymbols), reinterpret_cast(&g_pSymbols)); 43 | if (FAILED(hResult)) 44 | { 45 | g_pDebugControl->Output(DEBUG_OUTPUT_ERROR, "[%ws::%d] Failed with status: %d\n", __FUNCTIONW__, __LINE__, hResult); 46 | return hResult; 47 | } 48 | return hResult; 49 | } 50 | 51 | /// 52 | /// This will enumerate all Load Image Routine callbacks registered on a system. It will show the pointer 53 | /// that it's located at, as well as the function of that callback. 54 | /// 55 | /// S_OK if successful 56 | HRESULT enumerateLoadImageRoutines() 57 | { 58 | std::string SymbolName(MAX_SYMBOL_LENGTH, '\0'); 59 | std::ostringstream ss; 60 | 61 | ULONG64 PspLoadImageNotifyRoutine = 0; 62 | ULONG64 PspLoadImageNotifyRoutineCount = 0; 63 | 64 | ULONG64 LoadImageRoutineCount = 0; 65 | ULONG64 temp = 0; 66 | 67 | HRESULT hResult = g_pSymbols->GetOffsetByName("nt!PspLoadImageNotifyRoutine", &PspLoadImageNotifyRoutine); 68 | if (FAILED(hResult)) 69 | { 70 | g_pDebugControl->Output(DEBUG_OUTPUT_ERROR, "[%ws::%d] Failed with status: %d\n", __FUNCTIONW__, __LINE__, hResult); 71 | return hResult; 72 | } 73 | 74 | hResult = g_pSymbols->GetOffsetByName("nt!PspLoadImageNotifyRoutineCount", &PspLoadImageNotifyRoutineCount); 75 | if (FAILED(hResult)) 76 | { 77 | g_pDebugControl->Output(DEBUG_OUTPUT_ERROR, "[%ws::%d] Failed with status: %d\n", __FUNCTIONW__, __LINE__, hResult); 78 | return hResult; 79 | } 80 | 81 | // 82 | // Get the total count for PspLoadImageNotifyRoutineCount 83 | // 84 | ReadPointer(PspLoadImageNotifyRoutineCount, &LoadImageRoutineCount); 85 | 86 | g_pDebugControl->Output(DEBUG_OUTPUT_DEBUGGEE, "The following Load Image Notify routines are registered on the system:\n"); 87 | for (int i = 0; i < LoadImageRoutineCount; i++) 88 | { 89 | UINT64 ImageCallbackPointer = 0; 90 | UINT64 ImageCallbackAddress = 0; 91 | 92 | ULONG64 Displacement = 0; 93 | 94 | ReadPointer(PspLoadImageNotifyRoutine, &ImageCallbackPointer); 95 | ImageCallbackPointer &= ~15; 96 | ImageCallbackPointer += sizeof(ImageCallbackPointer); 97 | 98 | ReadPointer(ImageCallbackPointer, &ImageCallbackAddress); 99 | 100 | hResult = g_pSymbols->GetNameByOffset(ImageCallbackAddress, &SymbolName[0], static_cast(SymbolName.size()), NULL, &Displacement); 101 | if (FAILED(hResult)) 102 | { 103 | return hResult; 104 | } 105 | 106 | if (Displacement != 0) 107 | { 108 | ss << std::hex << "+" << Displacement; 109 | 110 | SymbolName.insert(strlen(SymbolName.c_str()), ss.str().c_str()); 111 | 112 | ss.str(std::string()); 113 | } 114 | 115 | g_pDebugControl->Output(DEBUG_OUTPUT_DEBUGGEE, "%p: %s\n", ImageCallbackPointer, SymbolName.c_str()); 116 | PspLoadImageNotifyRoutine += sizeof(PspLoadImageNotifyRoutine); 117 | } 118 | 119 | return hResult; 120 | } 121 | 122 | /// 123 | /// This will enumerate all Create Thread Routine callbacks registered on a system. It will show the pointer 124 | /// that it's located at, as well as the function of that callback. 125 | /// 126 | /// S_OK if successful 127 | HRESULT enumerateCreateThreadRoutines() 128 | { 129 | std::string SymbolName(MAX_SYMBOL_LENGTH, '\0'); 130 | std::ostringstream ss; 131 | 132 | ULONG64 PspCreateThreadNotifyRoutineNonSystemCount = 0; 133 | ULONG64 PspCreateThreadNotifyRoutineCount = 0; 134 | ULONG64 PspCreateThreadNotifyRoutine = 0; 135 | 136 | ULONG64 ThreadCallbacksCount = 0; 137 | ULONG64 temp = 0; 138 | 139 | // 140 | // Not quite sure if this particular symbol is needed, but it doesn't hurt to include it 141 | // 142 | HRESULT hResult = g_pSymbols->GetOffsetByName("nt!PspCreateThreadNotifyRoutineNonSystemCount", &PspCreateThreadNotifyRoutineNonSystemCount); 143 | if (FAILED(hResult)) 144 | { 145 | g_pDebugControl->Output(DEBUG_OUTPUT_ERROR, "[%ws::%d] Failed with status: %d\n", __FUNCTIONW__, __LINE__, hResult); 146 | return hResult; 147 | } 148 | 149 | hResult = g_pSymbols->GetOffsetByName("nt!PspCreateThreadNotifyRoutineCount", &PspCreateThreadNotifyRoutineCount); 150 | if (FAILED(hResult)) 151 | { 152 | g_pDebugControl->Output(DEBUG_OUTPUT_ERROR, "[%ws::%d] Failed with status: %d\n", __FUNCTIONW__, __LINE__, hResult); 153 | return hResult; 154 | } 155 | 156 | hResult = g_pSymbols->GetOffsetByName("nt!PspCreateThreadNotifyRoutine", &PspCreateThreadNotifyRoutine); 157 | if (FAILED(hResult)) 158 | { 159 | g_pDebugControl->Output(DEBUG_OUTPUT_ERROR, "[%ws::%d] Failed with status: %d\n", __FUNCTIONW__, __LINE__, hResult); 160 | return hResult; 161 | } 162 | 163 | // 164 | // Get the total count for PspCreateThreadNotifyRoutine 165 | // 166 | ReadPointer(PspCreateThreadNotifyRoutineNonSystemCount, &temp); 167 | ThreadCallbacksCount += temp; 168 | 169 | ReadPointer(PspCreateThreadNotifyRoutineCount, &temp); 170 | ThreadCallbacksCount += temp; 171 | 172 | g_pDebugControl->Output(DEBUG_OUTPUT_DEBUGGEE, "The following Create Thread Notify routines are registered on the system:\n"); 173 | for (int i = 0; i < ThreadCallbacksCount; i++) 174 | { 175 | UINT64 ThreadCallbackPointer = 0; 176 | UINT64 ThreadCallbackAddress = 0; 177 | ULONG64 Displacement = 0; 178 | 179 | ReadPointer(PspCreateThreadNotifyRoutine, &ThreadCallbackPointer); 180 | ThreadCallbackPointer &= ~15; 181 | ThreadCallbackPointer += sizeof(ThreadCallbackPointer); 182 | 183 | ReadPointer(ThreadCallbackPointer, &ThreadCallbackAddress); 184 | 185 | hResult = g_pSymbols->GetNameByOffset(ThreadCallbackAddress, &SymbolName[0], static_cast(SymbolName.size()), NULL, &Displacement); 186 | if (FAILED(hResult)) 187 | { 188 | return hResult; 189 | } 190 | 191 | if (Displacement != 0) 192 | { 193 | ss << std::hex << "+" << Displacement; 194 | 195 | SymbolName.insert(strlen(SymbolName.c_str()), ss.str().c_str()); 196 | 197 | ss.str(std::string()); 198 | } 199 | 200 | g_pDebugControl->Output(DEBUG_OUTPUT_DEBUGGEE, "%p: %s\n", ThreadCallbackPointer, SymbolName.c_str()); 201 | PspCreateThreadNotifyRoutine += sizeof(PspCreateThreadNotifyRoutine); 202 | } 203 | 204 | return hResult; 205 | } 206 | 207 | /// 208 | /// This will enumerate all Create Process Routine callbacks registered on a system. It will show the pointer 209 | /// that it's located at, as well as the function of that callback. 210 | /// 211 | /// S_OK if successful 212 | HRESULT enumerateCreateProcessRoutines() 213 | { 214 | std::string SymbolName(MAX_SYMBOL_LENGTH, '\0'); 215 | std::ostringstream ss; 216 | 217 | ULONG64 PspCreateProcessNotifyRoutineExCount = 0; 218 | ULONG64 PspCreateProcessNotifyRoutineCount = 0; 219 | ULONG64 PspCreateProcessNotifyRoutine = 0; 220 | 221 | ULONG64 ProcessCallbacksCount = 0; 222 | ULONG64 temp = 0; 223 | 224 | HRESULT hResult = g_pSymbols->GetOffsetByName("nt!PspCreateProcessNotifyRoutineExCount", &PspCreateProcessNotifyRoutineExCount); 225 | if (FAILED(hResult)) 226 | { 227 | g_pDebugControl->Output(DEBUG_OUTPUT_ERROR, "[%ws::%d] Failed with status: %d\n", __FUNCTIONW__, __LINE__, hResult); 228 | return hResult; 229 | } 230 | 231 | hResult = g_pSymbols->GetOffsetByName("nt!PspCreateProcessNotifyRoutineCount", &PspCreateProcessNotifyRoutineCount); 232 | if (FAILED(hResult)) 233 | { 234 | g_pDebugControl->Output(DEBUG_OUTPUT_ERROR, "[%ws::%d] Failed with status: %d\n", __FUNCTIONW__, __LINE__, hResult); 235 | return hResult; 236 | } 237 | 238 | hResult = g_pSymbols->GetOffsetByName("nt!PspCreateProcessNotifyRoutine", &PspCreateProcessNotifyRoutine); 239 | if (FAILED(hResult)) 240 | { 241 | g_pDebugControl->Output(DEBUG_OUTPUT_ERROR, "[%ws::%d] Failed with status: %d\n", __FUNCTIONW__, __LINE__, hResult); 242 | return hResult; 243 | } 244 | 245 | // 246 | // Get the total count for both PspCreateProcessNotifyRoutine/Ex 247 | // 248 | ReadPointer(PspCreateProcessNotifyRoutineExCount, &temp); 249 | ProcessCallbacksCount += temp; 250 | 251 | ReadPointer(PspCreateProcessNotifyRoutineCount, &temp); 252 | ProcessCallbacksCount += temp; 253 | 254 | g_pDebugControl->Output(DEBUG_OUTPUT_DEBUGGEE, "The following Create Process Notify routines are registered on the system:\n"); 255 | for (int i = 0; i < ProcessCallbacksCount; i++) 256 | { 257 | UINT64 ProcessCallbackPointer = 0; 258 | UINT64 ProcessCallbackAddress = 0; 259 | ULONG64 Displacement = 0; 260 | 261 | ReadPointer(PspCreateProcessNotifyRoutine, &ProcessCallbackPointer); 262 | ProcessCallbackPointer &= ~15; 263 | ProcessCallbackPointer += sizeof(ProcessCallbackPointer); 264 | 265 | ReadPointer(ProcessCallbackPointer, &ProcessCallbackAddress); 266 | 267 | hResult = g_pSymbols->GetNameByOffset(ProcessCallbackAddress, &SymbolName[0], static_cast(SymbolName.size()), NULL, &Displacement); 268 | if (FAILED(hResult)) 269 | { 270 | return hResult; 271 | } 272 | 273 | if (Displacement != 0) 274 | { 275 | ss << std::hex << "+" << Displacement; 276 | 277 | SymbolName.insert(strlen(SymbolName.c_str()), ss.str().c_str()); 278 | 279 | ss.str(std::string()); 280 | } 281 | 282 | g_pDebugControl->Output(DEBUG_OUTPUT_DEBUGGEE, "%p: %s\n", ProcessCallbackPointer, SymbolName.c_str()); 283 | PspCreateProcessNotifyRoutine += sizeof(PspCreateProcessNotifyRoutine); 284 | } 285 | 286 | return hResult; 287 | } 288 | 289 | void cleanUpAndExit() 290 | { 291 | if (g_pSymbols != nullptr) 292 | { 293 | g_pSymbols->Release(); 294 | } 295 | 296 | if (g_pDebugControl != nullptr) 297 | { 298 | g_pDebugControl->Release(); 299 | } 300 | 301 | if (g_pDebugClient != nullptr) 302 | { 303 | g_pDebugClient->Release(); 304 | } 305 | } 306 | 307 | CALLBACK_API HRESULT callbacks(PIDebugClient, PCSTR args) 308 | { 309 | if (*args == NULL) 310 | { 311 | g_pDebugControl->Output(DEBUG_OUTPUT_DEBUGGEE, "Please specify a type of callback or check out the help command.\n"); 312 | return S_FALSE; 313 | } 314 | 315 | if (strcmp(args, "process") == 0) 316 | { 317 | enumerateCreateProcessRoutines(); 318 | } 319 | else if (strcmp(args, "thread") == 0) 320 | { 321 | enumerateCreateThreadRoutines(); 322 | } 323 | else if (strcmp(args, "image") == 0) 324 | { 325 | enumerateLoadImageRoutines(); 326 | } 327 | else if (strcmp(args, "all") == 0) 328 | { 329 | enumerateCreateProcessRoutines(); 330 | g_pDebugControl->Output(DEBUG_OUTPUT_DEBUGGEE, "\n"); 331 | 332 | enumerateCreateThreadRoutines(); 333 | g_pDebugControl->Output(DEBUG_OUTPUT_DEBUGGEE, "\n"); 334 | 335 | enumerateLoadImageRoutines(); 336 | } 337 | else if (strcmp(args, "help") == 0) 338 | { 339 | g_pDebugControl->Output(DEBUG_OUTPUT_DEBUGGEE, 340 | "Provide a callback type you are interested in.\n" 341 | "The different types are: process, thread, image, or all\n" 342 | ); 343 | } 344 | else 345 | { 346 | g_pDebugControl->Output(DEBUG_OUTPUT_DEBUGGEE, "Unable to recognize the callback argument: %s.\n", args); 347 | return S_FALSE; 348 | } 349 | 350 | return S_OK; 351 | } 352 | 353 | 354 | /// EOF -------------------------------------------------------------------------------- /Callback Extension/Callbacks/callbacks.h: -------------------------------------------------------------------------------- 1 | // The following ifdef block is the standard way of creating macros which make exporting 2 | // from a DLL simpler. All files within this DLL are compiled with the DLL11_EXPORTS 3 | // symbol defined on the command line. This symbol should not be defined on any project 4 | // that uses this DLL. This way any other project whose source files include this file see 5 | // DLL11_API functions as being imported from a DLL, whereas this DLL sees symbols 6 | // defined with this macro as being exported. 7 | 8 | #ifndef CALLBACK_EXPORTS 9 | #define CALLBACK_API __declspec(dllexport) 10 | #else 11 | #define CALLBACK_API __declspec(dllimport) 12 | #endif 13 | 14 | typedef IDebugClient* PIDebugClient; 15 | typedef IDebugControl* PIDebugControl; 16 | typedef IDebugSymbols* PIDebugSymbols; 17 | 18 | HRESULT init(); 19 | HRESULT enumerateLoadImageRoutines(); 20 | HRESULT enumerateCreateThreadRoutines(); 21 | HRESULT enumerateCreateProcessRoutines(); 22 | void cleanUpAndExit(); 23 | 24 | EXTERN_C CALLBACK_API HRESULT CALLBACK callbacks( 25 | _In_ PIDebugClient, 26 | _In_ PCSTR args 27 | ); 28 | 29 | 30 | /// EOF -------------------------------------------------------------------------------- /Callback Extension/Callbacks/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #include "pch.h" 3 | 4 | EXTERN_C 5 | __declspec(dllexport) 6 | HRESULT CALLBACK DebugExtensionInitialize( 7 | _In_ PULONG Version, 8 | _In_ PULONG 9 | ) 10 | { 11 | *Version = DEBUG_EXTENSION_VERSION(MAJOR, MINOR); 12 | 13 | return init(); 14 | } 15 | 16 | EXTERN_C 17 | __declspec(dllexport) 18 | void CALLBACK DebugExtensionNotify( 19 | _In_ ULONG, 20 | _In_ ULONG64 21 | ) 22 | { 23 | return; 24 | } 25 | 26 | EXTERN_C 27 | __declspec(dllexport) 28 | void CALLBACK DebugExtensionUninitialize() 29 | { 30 | cleanUpAndExit(); 31 | return; 32 | } 33 | 34 | 35 | /// EOF -------------------------------------------------------------------------------- /Callback Extension/Callbacks/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef WIN32_LEAN_AND_MEAN 4 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 5 | #endif // !WIN32_LEAN_AND_MEAN 6 | 7 | #ifndef KDEXT_64BIT 8 | #define KDEXT_64BIT 9 | #endif // !KDEXT_64BIT 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "callbacks.h" 18 | 19 | #define MAJOR 1 20 | #define MINOR 0 21 | #define MAX_SYMBOL_LENGTH 256 22 | 23 | 24 | /// EOF -------------------------------------------------------------------------------- /Callback Extension/Callbacks/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: source file corresponding to the pre-compiled header 2 | 3 | #include "pch.h" 4 | 5 | // When you are using pre-compiled headers, this source file is necessary for compilation to succeed. 6 | -------------------------------------------------------------------------------- /Callback Extension/Callbacks/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: This is a precompiled header file. 2 | // Files listed below are compiled only once, improving build performance for future builds. 3 | // This also affects IntelliSense performance, including code completion and many code browsing features. 4 | // However, files listed here are ALL re-compiled if any one of them is updated between builds. 5 | // Do not add files here that you will be updating frequently as this negates the performance advantage. 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // add headers that you want to pre-compile here 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | 15 | 16 | /// EOF -------------------------------------------------------------------------------- /Images/all.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ch3rn0byl/WinDbg-Extensions/9b056b323c941d2c47f0089fe8f78040db4b37ac/Images/all.PNG -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WinDbg-Extensions 2 | ## Callback Extension 3 | Callbacks.dll is a WinDbg extension that will enumerate all pointers inside of the following symbols for callbacks that are registered on the system: 4 | 1. nt!PspCreateProcessNotifyRoutine 5 | 2. nt!PspCreateThreadNotifyRoutine 6 | 3. nt!PspLoadImageNotifyRoutine 7 | 8 | ![picture](https://github.com/ch3rn0byl/WinDbg-Extensions/blob/main/Images/all.PNG) 9 | 10 | ## How to use? 11 | The extension takes in either of the four parameters: _process_, _image_, _thread_, or _all_. 12 | This just makes life a little bit easier when you're doing whatever it is you're doing with them. 13 | 14 | This just lists the callbacks, nothing more nothing less but as I continue working on my shenanigans...I will make sure to continue adding on to this. 15 | 16 | Have fun! 17 | --------------------------------------------------------------------------------