├── .gitignore ├── ClassFactory.cpp ├── ClassFactory.hpp ├── ComActionCpp.sln ├── ComActionCpp.vcxproj ├── ComActionCpp.vcxproj.filters ├── README.md ├── Source.def ├── TaskHandler.cpp ├── TaskHandler.hpp ├── config.h ├── dllmain.cpp └── stager ├── Common.h └── stager_main.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/c,c++,visualstudio 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=c,c++,visualstudio 3 | 4 | ### C ### 5 | # Prerequisites 6 | *.d 7 | 8 | # Object files 9 | *.o 10 | *.ko 11 | *.obj 12 | *.elf 13 | 14 | # Linker output 15 | *.ilk 16 | *.map 17 | *.exp 18 | 19 | # Precompiled Headers 20 | *.gch 21 | *.pch 22 | 23 | # Libraries 24 | *.lib 25 | *.a 26 | *.la 27 | *.lo 28 | 29 | # Shared objects (inc. Windows DLLs) 30 | *.dll 31 | *.so 32 | *.so.* 33 | *.dylib 34 | 35 | # Executables 36 | *.exe 37 | *.out 38 | *.app 39 | *.i*86 40 | *.x86_64 41 | *.hex 42 | 43 | # Debug files 44 | *.dSYM/ 45 | *.su 46 | *.idb 47 | *.pdb 48 | 49 | # Kernel Module Compile Results 50 | *.mod* 51 | *.cmd 52 | .tmp_versions/ 53 | modules.order 54 | Module.symvers 55 | Mkfile.old 56 | dkms.conf 57 | 58 | ### C++ ### 59 | # Prerequisites 60 | 61 | # Compiled Object files 62 | *.slo 63 | 64 | # Precompiled Headers 65 | 66 | # Compiled Dynamic libraries 67 | 68 | # Fortran module files 69 | *.mod 70 | *.smod 71 | 72 | # Compiled Static libraries 73 | *.lai 74 | 75 | # Executables 76 | 77 | ### VisualStudio ### 78 | ## Ignore Visual Studio temporary files, build results, and 79 | ## files generated by popular Visual Studio add-ons. 80 | ## 81 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 82 | 83 | # User-specific files 84 | *.rsuser 85 | *.suo 86 | *.user 87 | *.userosscache 88 | *.sln.docstates 89 | 90 | # User-specific files (MonoDevelop/Xamarin Studio) 91 | *.userprefs 92 | 93 | # Mono auto generated files 94 | mono_crash.* 95 | 96 | # Build results 97 | [Dd]ebug/ 98 | [Dd]ebugPublic/ 99 | [Rr]elease/ 100 | [Rr]eleases/ 101 | x64/ 102 | x86/ 103 | [Ww][Ii][Nn]32/ 104 | [Aa][Rr][Mm]/ 105 | [Aa][Rr][Mm]64/ 106 | bld/ 107 | [Bb]in/ 108 | [Oo]bj/ 109 | [Ll]og/ 110 | [Ll]ogs/ 111 | 112 | # Visual Studio 2015/2017 cache/options directory 113 | .vs/ 114 | # Uncomment if you have tasks that create the project's static files in wwwroot 115 | #wwwroot/ 116 | 117 | # Visual Studio 2017 auto generated files 118 | Generated\ Files/ 119 | 120 | # MSTest test Results 121 | [Tt]est[Rr]esult*/ 122 | [Bb]uild[Ll]og.* 123 | 124 | # NUnit 125 | *.VisualState.xml 126 | TestResult.xml 127 | nunit-*.xml 128 | 129 | # Build Results of an ATL Project 130 | [Dd]ebugPS/ 131 | [Rr]eleasePS/ 132 | dlldata.c 133 | 134 | # Benchmark Results 135 | BenchmarkDotNet.Artifacts/ 136 | 137 | # .NET Core 138 | project.lock.json 139 | project.fragment.lock.json 140 | artifacts/ 141 | 142 | # ASP.NET Scaffolding 143 | ScaffoldingReadMe.txt 144 | 145 | # StyleCop 146 | StyleCopReport.xml 147 | 148 | # Files built by Visual Studio 149 | *_i.c 150 | *_p.c 151 | *_h.h 152 | *.meta 153 | *.iobj 154 | *.ipdb 155 | *.pgc 156 | *.pgd 157 | *.rsp 158 | *.sbr 159 | *.tlb 160 | *.tli 161 | *.tlh 162 | *.tmp 163 | *.tmp_proj 164 | *_wpftmp.csproj 165 | *.log 166 | *.tlog 167 | *.vspscc 168 | *.vssscc 169 | .builds 170 | *.pidb 171 | *.svclog 172 | *.scc 173 | 174 | # Chutzpah Test files 175 | _Chutzpah* 176 | 177 | # Visual C++ cache files 178 | ipch/ 179 | *.aps 180 | *.ncb 181 | *.opendb 182 | *.opensdf 183 | *.sdf 184 | *.cachefile 185 | *.VC.db 186 | *.VC.VC.opendb 187 | 188 | # Visual Studio profiler 189 | *.psess 190 | *.vsp 191 | *.vspx 192 | *.sap 193 | 194 | # Visual Studio Trace Files 195 | *.e2e 196 | 197 | # TFS 2012 Local Workspace 198 | $tf/ 199 | 200 | # Guidance Automation Toolkit 201 | *.gpState 202 | 203 | # ReSharper is a .NET coding add-in 204 | _ReSharper*/ 205 | *.[Rr]e[Ss]harper 206 | *.DotSettings.user 207 | 208 | # TeamCity is a build add-in 209 | _TeamCity* 210 | 211 | # DotCover is a Code Coverage Tool 212 | *.dotCover 213 | 214 | # AxoCover is a Code Coverage Tool 215 | .axoCover/* 216 | !.axoCover/settings.json 217 | 218 | # Coverlet is a free, cross platform Code Coverage Tool 219 | coverage*.json 220 | coverage*.xml 221 | coverage*.info 222 | 223 | # Visual Studio code coverage results 224 | *.coverage 225 | *.coveragexml 226 | 227 | # NCrunch 228 | _NCrunch_* 229 | .*crunch*.local.xml 230 | nCrunchTemp_* 231 | 232 | # MightyMoose 233 | *.mm.* 234 | AutoTest.Net/ 235 | 236 | # Web workbench (sass) 237 | .sass-cache/ 238 | 239 | # Installshield output folder 240 | [Ee]xpress/ 241 | 242 | # DocProject is a documentation generator add-in 243 | DocProject/buildhelp/ 244 | DocProject/Help/*.HxT 245 | DocProject/Help/*.HxC 246 | DocProject/Help/*.hhc 247 | DocProject/Help/*.hhk 248 | DocProject/Help/*.hhp 249 | DocProject/Help/Html2 250 | DocProject/Help/html 251 | 252 | # Click-Once directory 253 | publish/ 254 | 255 | # Publish Web Output 256 | *.[Pp]ublish.xml 257 | *.azurePubxml 258 | # Note: Comment the next line if you want to checkin your web deploy settings, 259 | # but database connection strings (with potential passwords) will be unencrypted 260 | *.pubxml 261 | *.publishproj 262 | 263 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 264 | # checkin your Azure Web App publish settings, but sensitive information contained 265 | # in these scripts will be unencrypted 266 | PublishScripts/ 267 | 268 | # NuGet Packages 269 | *.nupkg 270 | # NuGet Symbol Packages 271 | *.snupkg 272 | # The packages folder can be ignored because of Package Restore 273 | **/[Pp]ackages/* 274 | # except build/, which is used as an MSBuild target. 275 | !**/[Pp]ackages/build/ 276 | # Uncomment if necessary however generally it will be regenerated when needed 277 | #!**/[Pp]ackages/repositories.config 278 | # NuGet v3's project.json files produces more ignorable files 279 | *.nuget.props 280 | *.nuget.targets 281 | 282 | # Microsoft Azure Build Output 283 | csx/ 284 | *.build.csdef 285 | 286 | # Microsoft Azure Emulator 287 | ecf/ 288 | rcf/ 289 | 290 | # Windows Store app package directories and files 291 | AppPackages/ 292 | BundleArtifacts/ 293 | Package.StoreAssociation.xml 294 | _pkginfo.txt 295 | *.appx 296 | *.appxbundle 297 | *.appxupload 298 | 299 | # Visual Studio cache files 300 | # files ending in .cache can be ignored 301 | *.[Cc]ache 302 | # but keep track of directories ending in .cache 303 | !?*.[Cc]ache/ 304 | 305 | # Others 306 | ClientBin/ 307 | ~$* 308 | *~ 309 | *.dbmdl 310 | *.dbproj.schemaview 311 | *.jfm 312 | *.pfx 313 | *.publishsettings 314 | orleans.codegen.cs 315 | 316 | # Including strong name files can present a security risk 317 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 318 | #*.snk 319 | 320 | # Since there are multiple workflows, uncomment next line to ignore bower_components 321 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 322 | #bower_components/ 323 | 324 | # RIA/Silverlight projects 325 | Generated_Code/ 326 | 327 | # Backup & report files from converting an old project file 328 | # to a newer Visual Studio version. Backup files are not needed, 329 | # because we have git ;-) 330 | _UpgradeReport_Files/ 331 | Backup*/ 332 | UpgradeLog*.XML 333 | UpgradeLog*.htm 334 | ServiceFabricBackup/ 335 | *.rptproj.bak 336 | 337 | # SQL Server files 338 | *.mdf 339 | *.ldf 340 | *.ndf 341 | 342 | # Business Intelligence projects 343 | *.rdl.data 344 | *.bim.layout 345 | *.bim_*.settings 346 | *.rptproj.rsuser 347 | *- [Bb]ackup.rdl 348 | *- [Bb]ackup ([0-9]).rdl 349 | *- [Bb]ackup ([0-9][0-9]).rdl 350 | 351 | # Microsoft Fakes 352 | FakesAssemblies/ 353 | 354 | # GhostDoc plugin setting file 355 | *.GhostDoc.xml 356 | 357 | # Node.js Tools for Visual Studio 358 | .ntvs_analysis.dat 359 | node_modules/ 360 | 361 | # Visual Studio 6 build log 362 | *.plg 363 | 364 | # Visual Studio 6 workspace options file 365 | *.opt 366 | 367 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 368 | *.vbw 369 | 370 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 371 | *.vbp 372 | 373 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 374 | *.dsw 375 | *.dsp 376 | 377 | # Visual Studio 6 technical files 378 | 379 | # Visual Studio LightSwitch build output 380 | **/*.HTMLClient/GeneratedArtifacts 381 | **/*.DesktopClient/GeneratedArtifacts 382 | **/*.DesktopClient/ModelManifest.xml 383 | **/*.Server/GeneratedArtifacts 384 | **/*.Server/ModelManifest.xml 385 | _Pvt_Extensions 386 | 387 | # Paket dependency manager 388 | .paket/paket.exe 389 | paket-files/ 390 | 391 | # FAKE - F# Make 392 | .fake/ 393 | 394 | # CodeRush personal settings 395 | .cr/personal 396 | 397 | # Python Tools for Visual Studio (PTVS) 398 | __pycache__/ 399 | *.pyc 400 | 401 | # Cake - Uncomment if you are using it 402 | # tools/** 403 | # !tools/packages.config 404 | 405 | # Tabs Studio 406 | *.tss 407 | 408 | # Telerik's JustMock configuration file 409 | *.jmconfig 410 | 411 | # BizTalk build output 412 | *.btp.cs 413 | *.btm.cs 414 | *.odx.cs 415 | *.xsd.cs 416 | 417 | # OpenCover UI analysis results 418 | OpenCover/ 419 | 420 | # Azure Stream Analytics local run output 421 | ASALocalRun/ 422 | 423 | # MSBuild Binary and Structured Log 424 | *.binlog 425 | 426 | # NVidia Nsight GPU debugger configuration file 427 | *.nvuser 428 | 429 | # MFractors (Xamarin productivity tool) working folder 430 | .mfractor/ 431 | 432 | # Local History for Visual Studio 433 | .localhistory/ 434 | 435 | # Visual Studio History (VSHistory) files 436 | .vshistory/ 437 | 438 | # BeatPulse healthcheck temp database 439 | healthchecksdb 440 | 441 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 442 | MigrationBackup/ 443 | 444 | # Ionide (cross platform F# VS Code tools) working folder 445 | .ionide/ 446 | 447 | # Fody - auto-generated XML schema 448 | FodyWeavers.xsd 449 | 450 | # VS Code files for those working on multiple tools 451 | .vscode/* 452 | !.vscode/settings.json 453 | !.vscode/tasks.json 454 | !.vscode/launch.json 455 | !.vscode/extensions.json 456 | *.code-workspace 457 | 458 | # Local History for Visual Studio Code 459 | .history/ 460 | 461 | # Windows Installer files from build outputs 462 | *.cab 463 | *.msi 464 | *.msix 465 | *.msm 466 | *.msp 467 | 468 | # JetBrains Rider 469 | *.sln.iml 470 | 471 | ### VisualStudio Patch ### 472 | # Additional files built by Visual Studio 473 | 474 | # End of https://www.toptal.com/developers/gitignore/api/c,c++,visualstudio -------------------------------------------------------------------------------- /ClassFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "ClassFactory.hpp" 2 | 3 | 4 | STDMETHODIMP ClassFactory::CreateInstance( 5 | _In_opt_ IUnknown* pUnknownOuter, 6 | _In_ REFIID riid, 7 | _COM_Outptr_ LPVOID* ppv) 8 | { 9 | COM_CLASS_NAME* pTaskHandler; 10 | 11 | if (!ppv) { return E_INVALIDARG; } 12 | 13 | if (pUnknownOuter) { return CLASS_E_NOAGGREGATION; } 14 | 15 | pTaskHandler = new COM_CLASS_NAME(); 16 | 17 | if (!pTaskHandler) { return E_OUTOFMEMORY; } 18 | 19 | return pTaskHandler->QueryInterface(riid, ppv); 20 | } 21 | 22 | STDMETHODIMP ClassFactory::LockServer(_In_ BOOL bLock) 23 | { 24 | UNREFERENCED_PARAMETER(bLock); 25 | return S_OK; 26 | } 27 | 28 | STDMETHODIMP ClassFactory::QueryInterface( 29 | _In_ REFIID riid, 30 | _COM_Outptr_ LPVOID* ppv) 31 | { 32 | 33 | if (!ppv) { return E_INVALIDARG; } 34 | 35 | 36 | if (IsEqualGUID(riid, IID_IUnknown)) 37 | { 38 | *ppv = static_cast(this); 39 | } 40 | else if (IsEqualGUID(riid, IID_IClassFactory)) 41 | { 42 | *ppv = static_cast(this); 43 | } 44 | else { 45 | *ppv = NULL; 46 | return E_NOINTERFACE; 47 | } 48 | 49 | AddRef(); 50 | return S_OK; 51 | } 52 | 53 | STDMETHODIMP_(ULONG) ClassFactory::AddRef() 54 | { 55 | return InterlockedIncrement(&m_nRefCount); 56 | } 57 | 58 | STDMETHODIMP_(ULONG) ClassFactory::Release() 59 | { 60 | LONG nRefCount = 0; 61 | nRefCount = InterlockedDecrement(&m_nRefCount); 62 | if (nRefCount == 0) delete this; 63 | return nRefCount; 64 | } -------------------------------------------------------------------------------- /ClassFactory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "TaskHandler.hpp" 5 | 6 | //just in case I want to switch to another class for testing 7 | #define COM_CLASS_NAME CTaskHandler 8 | 9 | class ClassFactory : public IClassFactory 10 | { 11 | public: 12 | ClassFactory() 13 | { 14 | InterlockedIncrement(&m_nRefCount); 15 | } 16 | 17 | ~ClassFactory() 18 | { 19 | InterlockedDecrement(&m_nRefCount); 20 | } 21 | 22 | 23 | //IUnknown 24 | STDMETHODIMP QueryInterface(_In_ REFIID riid, _COM_Outptr_ LPVOID* ppObj) override; 25 | STDMETHODIMP_(ULONG) AddRef() override; 26 | STDMETHODIMP_(ULONG) Release() override; 27 | 28 | 29 | //IClassFactory 30 | 31 | 32 | STDMETHODIMP CreateInstance(_In_opt_ IUnknown* pUnknownOuter, _In_ REFIID riid, _COM_Outptr_ LPVOID* ppv); 33 | STDMETHODIMP LockServer(_In_ BOOL bLock); 34 | 35 | private: 36 | long m_nRefCount; 37 | }; -------------------------------------------------------------------------------- /ComActionCpp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32319.34 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ComActionCpp", "ComActionCpp.vcxproj", "{DB6A3B34-B0D7-45EF-9D66-AD5830FEFB0E}" 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 | {DB6A3B34-B0D7-45EF-9D66-AD5830FEFB0E}.Debug|x64.ActiveCfg = Debug|x64 17 | {DB6A3B34-B0D7-45EF-9D66-AD5830FEFB0E}.Debug|x64.Build.0 = Debug|x64 18 | {DB6A3B34-B0D7-45EF-9D66-AD5830FEFB0E}.Debug|x86.ActiveCfg = Debug|Win32 19 | {DB6A3B34-B0D7-45EF-9D66-AD5830FEFB0E}.Debug|x86.Build.0 = Debug|Win32 20 | {DB6A3B34-B0D7-45EF-9D66-AD5830FEFB0E}.Release|x64.ActiveCfg = Release|x64 21 | {DB6A3B34-B0D7-45EF-9D66-AD5830FEFB0E}.Release|x64.Build.0 = Release|x64 22 | {DB6A3B34-B0D7-45EF-9D66-AD5830FEFB0E}.Release|x86.ActiveCfg = Release|Win32 23 | {DB6A3B34-B0D7-45EF-9D66-AD5830FEFB0E}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {A15D18AF-49D5-4B31-B8DC-48719E8E92DF} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /ComActionCpp.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 | {db6a3b34-b0d7-45ef-9d66-ad5830fefb0e} 25 | ComActionCpp 26 | 10.0 27 | 28 | 29 | 30 | DynamicLibrary 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | DynamicLibrary 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | DynamicLibrary 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | DynamicLibrary 50 | false 51 | v143 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 | 75 | Level3 76 | true 77 | WIN32;_DEBUG;COMACTIONCPP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 78 | true 79 | NotUsing 80 | pch.h 81 | MultiThreadedDebug 82 | 83 | 84 | Windows 85 | true 86 | false 87 | Source.def 88 | 89 | 90 | 91 | 92 | Level3 93 | true 94 | true 95 | true 96 | WIN32;NDEBUG;COMACTIONCPP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 97 | true 98 | NotUsing 99 | pch.h 100 | MultiThreaded 101 | 102 | 103 | Windows 104 | true 105 | true 106 | true 107 | false 108 | Source.def 109 | 110 | 111 | 112 | 113 | Level3 114 | true 115 | _DEBUG;COMACTIONCPP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 116 | true 117 | NotUsing 118 | pch.h 119 | MultiThreadedDebug 120 | 121 | 122 | Windows 123 | true 124 | false 125 | Source.def 126 | 127 | 128 | 129 | 130 | Level3 131 | true 132 | true 133 | false 134 | NDEBUG;COMACTIONCPP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 135 | false 136 | NotUsing 137 | 138 | 139 | MaxSpeed 140 | false 141 | MultiThreaded 142 | 143 | 144 | Windows 145 | true 146 | true 147 | false 148 | false 149 | 150 | Source.def 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /ComActionCpp.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 | {53e901c7-a4a0-4f74-82b3-15f17fa6a798} 18 | 19 | 20 | {2d7b4bcb-4df2-42ad-8c75-dbc5bcb9b14c} 21 | 22 | 23 | {c330bb8f-3abd-4825-952d-2696024d3441} 24 | 25 | 26 | {cbf65ce7-267c-4357-a1e2-813fa1a5e9dd} 27 | 28 | 29 | 30 | 31 | Header Files\stager 32 | 33 | 34 | Header Files\com 35 | 36 | 37 | Header Files\com 38 | 39 | 40 | Header Files\com 41 | 42 | 43 | 44 | 45 | Source Files\stager 46 | 47 | 48 | Source Files\com 49 | 50 | 51 | Source Files\com 52 | 53 | 54 | Source Files\com 55 | 56 | 57 | 58 | 59 | Source Files\com 60 | 61 | 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yaxser/Itaskhandler/48126a0008f0504b2f56f964242d69a9c28c570c/README.md -------------------------------------------------------------------------------- /Source.def: -------------------------------------------------------------------------------- 1 | LIBRARY ComActionCpp 2 | EXPORTS 3 | DllCanUnloadNow PRIVATE 4 | DllGetClassObject PRIVATE -------------------------------------------------------------------------------- /TaskHandler.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "TaskHandler.hpp" 3 | #include 4 | #include "stager/Common.h" 5 | 6 | DEFINE_GUID(IID_ITaskHandler, 7 | 0x839d7762, 0x5121, 0x4009, 0x92, 0x34, 0x4f, 0x0d, 0x19, 0x39, 0x4f, 0x04); 8 | 9 | 10 | CTaskHandler::CTaskHandler() 11 | { 12 | InterlockedIncrement(&m_nRefCount); 13 | } 14 | 15 | CTaskHandler::~CTaskHandler() 16 | { 17 | InterlockedDecrement(&m_nRefCount); 18 | } 19 | 20 | 21 | STDMETHODIMP CTaskHandler::Start(IUnknown* handler, BSTR data) 22 | { 23 | 24 | STARTUPINFOA si; 25 | PROCESS_INFORMATION pi; 26 | 27 | ZeroMemory(&si, sizeof(si)); 28 | si.cb = sizeof(si); 29 | ZeroMemory(&pi, sizeof(pi)); 30 | 31 | init(); 32 | return S_OK; 33 | } 34 | 35 | STDMETHODIMP CTaskHandler::Stop(HRESULT* retCode) 36 | { 37 | ExitProcess(0); 38 | return S_OK; 39 | } 40 | 41 | STDMETHODIMP CTaskHandler::Pause() 42 | { 43 | ExitProcess(0); 44 | return S_OK; 45 | } 46 | 47 | STDMETHODIMP CTaskHandler::Resume() 48 | { 49 | return S_OK; 50 | } 51 | 52 | STDMETHODIMP CTaskHandler::QueryInterface( 53 | _In_ REFIID riid, 54 | _COM_Outptr_ LPVOID* ppv) 55 | { 56 | 57 | if (!ppv) { return E_INVALIDARG; } 58 | 59 | 60 | if (IsEqualGUID(riid, IID_IUnknown)) 61 | { 62 | *ppv = static_cast(this); 63 | } 64 | else if (IsEqualGUID(riid, IID_ITaskHandler)) 65 | { 66 | *ppv = static_cast(this); 67 | } 68 | else { 69 | *ppv = NULL; 70 | return E_NOINTERFACE; 71 | } 72 | 73 | AddRef(); 74 | return S_OK; 75 | } 76 | 77 | STDMETHODIMP_(ULONG) CTaskHandler::AddRef() 78 | { 79 | return InterlockedIncrement(&m_nRefCount); 80 | } 81 | 82 | STDMETHODIMP_(ULONG) CTaskHandler::Release() 83 | { 84 | LONG nRefCount = 0; 85 | nRefCount = InterlockedDecrement(&m_nRefCount); 86 | if (nRefCount == 0) delete this; 87 | return nRefCount; 88 | } -------------------------------------------------------------------------------- /TaskHandler.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | extern long g_nComObjsInUse; 7 | 8 | class CTaskHandler : 9 | public ITaskHandler 10 | { 11 | public: 12 | CTaskHandler(); 13 | virtual ~CTaskHandler(); 14 | 15 | //IUnknown 16 | STDMETHODIMP QueryInterface(_In_ REFIID riid, _COM_Outptr_ LPVOID* ppObj) override; 17 | STDMETHODIMP_(ULONG) AddRef() override; 18 | STDMETHODIMP_(ULONG) Release() override; 19 | 20 | //Task Handler interface 21 | STDMETHODIMP Start(IUnknown* handler, BSTR data) override; 22 | STDMETHODIMP Stop(HRESULT* retCode) override; 23 | STDMETHODIMP Pause() override; 24 | STDMETHODIMP Resume() override; 25 | private: 26 | long m_nRefCount; 27 | }; -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | 5 | #define CFG_COM_HANDLER_LOCATION "C:\\demos\\other\\com_handler.dll" 6 | 7 | 8 | // this must be changed to the CLSID specified in the registry 9 | //ECABD3A3-725D-4334-AAFC-BB13234F1202 10 | extern "C" { 11 | DEFINE_GUID(CLSID_TaskHandler, 12 | 0xECABD3A3, 0x725D, 0x4334, 0xAA, 0xFC, 0xBB, 0x13, 0x23, 0x4F, 0x12, 0x02 13 | ); 14 | } -------------------------------------------------------------------------------- /dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | 3 | #include 4 | #include "config.h" 5 | #include "stager/Common.h" 6 | #include "ClassFactory.hpp" 7 | #include "TaskHandler.hpp" 8 | 9 | 10 | 11 | extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) 12 | { 13 | return TRUE; 14 | } 15 | 16 | #pragma warning(push) //disable different annotation warnings 17 | #pragma warning(disable: 28252) 18 | #pragma warning(disable: 28251) 19 | STDAPI DllGetClassObject(_In_ REFCLSID clsid, _In_ REFIID iid, _Outptr_ LPVOID FAR* ppv) 20 | { 21 | if (IsEqualGUID(clsid, CLSID_TaskHandler)) //check if the guid passed by CoCreateInstance is a one that we support 22 | { 23 | ClassFactory* pAddFact = new ClassFactory(); //create the class factory 24 | if (pAddFact == NULL) 25 | return E_OUTOFMEMORY; 26 | else 27 | { 28 | return pAddFact->QueryInterface(iid, ppv); //return the class factory to the COM runtime. The runtime will call CreateInstance 29 | } 30 | } 31 | return CLASS_E_CLASSNOTAVAILABLE; 32 | } 33 | 34 | 35 | STDAPI DllCanUnloadNow(void) 36 | { 37 | if (g_nComObjsInUse == 0) 38 | { 39 | return S_OK; 40 | } 41 | else 42 | { 43 | return S_FALSE; 44 | } 45 | } 46 | #pragma warning(pop) -------------------------------------------------------------------------------- /stager/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //export 4 | #define DllExport __declspec( dllexport ) 5 | 6 | 7 | #if __cplusplus 8 | extern "C" { 9 | #endif 10 | DWORD WINAPI init(); 11 | long g_nComObjsInUse; 12 | #if __cplusplus 13 | } 14 | #endif -------------------------------------------------------------------------------- /stager/stager_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | DWORD WINAPI init() { 5 | MessageBoxA(NULL, "Hello", "From COM Handler", 0); 6 | return 0; 7 | } 8 | --------------------------------------------------------------------------------