├── .gitignore ├── AlterLoadDll.sln ├── AlterLoadDll ├── AlterLoadDll.cpp ├── AlterLoadDll.vcxproj └── AlterLoadDll.vcxproj.filters └── 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/main/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 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | -------------------------------------------------------------------------------- /AlterLoadDll.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.9.34622.214 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AlterLoadDll", "AlterLoadDll\AlterLoadDll.vcxproj", "{E2359B2B-9C1B-442C-92DF-210905ADC65C}" 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 | {E2359B2B-9C1B-442C-92DF-210905ADC65C}.Debug|x64.ActiveCfg = Debug|x64 17 | {E2359B2B-9C1B-442C-92DF-210905ADC65C}.Debug|x64.Build.0 = Debug|x64 18 | {E2359B2B-9C1B-442C-92DF-210905ADC65C}.Debug|x86.ActiveCfg = Debug|Win32 19 | {E2359B2B-9C1B-442C-92DF-210905ADC65C}.Debug|x86.Build.0 = Debug|Win32 20 | {E2359B2B-9C1B-442C-92DF-210905ADC65C}.Release|x64.ActiveCfg = Release|x64 21 | {E2359B2B-9C1B-442C-92DF-210905ADC65C}.Release|x64.Build.0 = Release|x64 22 | {E2359B2B-9C1B-442C-92DF-210905ADC65C}.Release|x86.ActiveCfg = Release|Win32 23 | {E2359B2B-9C1B-442C-92DF-210905ADC65C}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {63DCF0AF-6601-4931-84C1-5B901AA8D8A4} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /AlterLoadDll/AlterLoadDll.cpp: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "Psapi.h" 7 | #include "urlmon.h" 8 | #pragma comment(lib,"urlmon.lib") 9 | #pragma comment(lib,"ntdll.lib") 10 | #pragma comment(lib,"kernel32.lib") 11 | #pragma comment(lib, "Dbghelp.lib") 12 | 13 | 14 | #define MODE_LOADLIBRARYA 0 15 | #define MODE_LOADLIBRARYEXA 1 16 | #define MODE_LDRLOADDLL 2 17 | #define MODE_LDRPLOADDLL 3 18 | #define MODE_LDRPLOADDLLINTERNAL 4 19 | #define MODE_LDRPPROCESSWORK 5 20 | 21 | typedef struct _LSA_UNICODE_STRING { 22 | USHORT Length; 23 | USHORT MaximumLength; 24 | PWSTR Buffer; 25 | } LSA_UNICODE_STRING, * PLSA_UNICODE_STRING, UNICODE_STRING, * PUNICODE_STRING; 26 | 27 | struct LDR_UNKSTRUCT 28 | { 29 | PWSTR pInitNameMaybe; 30 | __declspec(align(16)) PWSTR Buffer; 31 | int Flags; 32 | PWSTR pDllName; 33 | char Pad1[84]; 34 | BOOLEAN IsInitedMaybe; 35 | char Pad2[3]; 36 | }; 37 | typedef BOOLEAN(NTAPI* PLDR_INIT_ROUTINE)( 38 | _In_ PVOID DllHandle, 39 | _In_ ULONG Reason, 40 | _In_opt_ PVOID Context 41 | ); 42 | typedef struct _LDR_SERVICE_TAG_RECORD 43 | { 44 | struct _LDR_SERVICE_TAG_RECORD* Next; 45 | ULONG ServiceTag; 46 | } LDR_SERVICE_TAG_RECORD, * PLDR_SERVICE_TAG_RECORD; 47 | typedef struct _LDRP_CSLIST 48 | { 49 | PSINGLE_LIST_ENTRY Tail; 50 | } LDRP_CSLIST, * PLDRP_CSLIST; 51 | typedef enum _LDR_DDAG_STATE 52 | { 53 | LdrModulesMerged = -5, 54 | LdrModulesInitError = -4, 55 | LdrModulesSnapError = -3, 56 | LdrModulesUnloaded = -2, 57 | LdrModulesUnloading = -1, 58 | LdrModulesPlaceHolder = 0, 59 | LdrModulesMapping = 1, 60 | LdrModulesMapped = 2, 61 | LdrModulesWaitingForDependencies = 3, 62 | LdrModulesSnapping = 4, 63 | LdrModulesSnapped = 5, 64 | LdrModulesCondensed = 6, 65 | LdrModulesReadyToInit = 7, 66 | LdrModulesInitializing = 8, 67 | LdrModulesReadyToRun = 9 68 | } LDR_DDAG_STATE; 69 | typedef struct _LDR_DDAG_NODE 70 | { 71 | LIST_ENTRY Modules; 72 | PLDR_SERVICE_TAG_RECORD ServiceTagList; 73 | ULONG LoadCount; 74 | ULONG LoadWhileUnloadingCount; 75 | ULONG LowestLink; 76 | union 77 | { 78 | LDRP_CSLIST Dependencies; 79 | SINGLE_LIST_ENTRY* RemovalLink; 80 | }; 81 | LDRP_CSLIST IncomingDependencies; 82 | LDR_DDAG_STATE State; 83 | SINGLE_LIST_ENTRY* CondenseLink; 84 | ULONG PreorderNumber; 85 | ULONG Pad; 86 | } LDR_DDAG_NODE, * PLDR_DDAG_NODE; 87 | typedef struct _RTL_BALANCED_NODE 88 | { 89 | union 90 | { 91 | struct _RTL_BALANCED_NODE* Children[2]; //0x0 92 | struct 93 | { 94 | struct _RTL_BALANCED_NODE* Left; //0x0 95 | struct _RTL_BALANCED_NODE* Right; //0x4 96 | }; 97 | }; 98 | union 99 | { 100 | struct 101 | { 102 | UCHAR Red : 1; //0x8 103 | UCHAR Balance : 2; //0x8 104 | }; 105 | ULONG ParentValue; //0x8 106 | }; 107 | } RTL_BALANCED_NODE, * PRTL_BALANCED_NODE; 108 | typedef enum _LDR_DLL_LOAD_REASON 109 | { 110 | LoadReasonStaticDependency, 111 | LoadReasonStaticForwarderDependency, 112 | LoadReasonDynamicForwarderDependency, 113 | LoadReasonDelayloadDependency, 114 | LoadReasonDynamicLoad, 115 | LoadReasonAsImageLoad, 116 | LoadReasonAsDataLoad, 117 | LoadReasonEnclavePrimary, // since REDSTONE3 118 | LoadReasonEnclaveDependency, 119 | LoadReasonPatchImage, // since WIN11 120 | LoadReasonUnknown = -1 121 | } LDR_DLL_LOAD_REASON, * PLDR_DLL_LOAD_REASON; 122 | typedef enum _LDR_HOT_PATCH_STATE 123 | { 124 | LdrHotPatchBaseImage, 125 | LdrHotPatchNotApplied, 126 | LdrHotPatchAppliedReverse, 127 | LdrHotPatchAppliedForward, 128 | LdrHotPatchFailedToPatch, 129 | LdrHotPatchStateMax, 130 | } LDR_HOT_PATCH_STATE, * PLDR_HOT_PATCH_STATE; 131 | typedef struct _LDR_DATA_TABLE_ENTRY 132 | { 133 | LIST_ENTRY InLoadOrderLinks; 134 | LIST_ENTRY InMemoryOrderLinks; 135 | union 136 | { 137 | LIST_ENTRY InInitializationOrderLinks; 138 | LIST_ENTRY InProgressLinks; 139 | }; 140 | PIMAGE_DOS_HEADER DllBase; 141 | PLDR_INIT_ROUTINE EntryPoint; 142 | ULONG SizeOfImage; 143 | UNICODE_STRING FullDllName; 144 | UNICODE_STRING BaseDllName; 145 | union 146 | { 147 | UCHAR FlagGroup[4]; 148 | ULONG Flags; 149 | struct 150 | { 151 | ULONG PackagedBinary : 1; 152 | ULONG MarkedForRemoval : 1; 153 | ULONG ImageDll : 1; 154 | ULONG LoadNotificationsSent : 1; 155 | ULONG TelemetryEntryProcessed : 1; 156 | ULONG ProcessStaticImport : 1; 157 | ULONG InLegacyLists : 1; 158 | ULONG InIndexes : 1; 159 | ULONG ShimDll : 1; 160 | ULONG InExceptionTable : 1; 161 | ULONG ReservedFlags1 : 2; 162 | ULONG LoadInProgress : 1; 163 | ULONG LoadConfigProcessed : 1; 164 | ULONG EntryProcessed : 1; 165 | ULONG ProtectDelayLoad : 1; 166 | ULONG ReservedFlags3 : 2; 167 | ULONG DontCallForThreads : 1; 168 | ULONG ProcessAttachCalled : 1; 169 | ULONG ProcessAttachFailed : 1; 170 | ULONG CorDeferredValidate : 1; 171 | ULONG CorImage : 1; 172 | ULONG DontRelocate : 1; 173 | ULONG CorILOnly : 1; 174 | ULONG ChpeImage : 1; 175 | ULONG ChpeEmulatorImage : 1; 176 | ULONG ReservedFlags5 : 1; 177 | ULONG Redirected : 1; 178 | ULONG ReservedFlags6 : 2; 179 | ULONG CompatDatabaseProcessed : 1; 180 | }; 181 | }; 182 | USHORT ObsoleteLoadCount; 183 | USHORT TlsIndex; 184 | LIST_ENTRY HashLinks; 185 | ULONG TimeDateStamp; 186 | struct _ACTIVATION_CONTEXT* EntryPointActivationContext; 187 | PVOID Lock; // RtlAcquireSRWLockExclusive 188 | PLDR_DDAG_NODE DdagNode; 189 | LIST_ENTRY NodeModuleLink; 190 | struct _LDRP_LOAD_CONTEXT* LoadContext; 191 | PVOID ParentDllBase; 192 | PVOID SwitchBackContext; 193 | RTL_BALANCED_NODE BaseAddressIndexNode; 194 | RTL_BALANCED_NODE MappingInfoIndexNode; 195 | ULONG_PTR OriginalBase; 196 | LARGE_INTEGER LoadTime; 197 | ULONG BaseNameHashValue; 198 | LDR_DLL_LOAD_REASON LoadReason; // since WIN8 199 | ULONG ImplicitPathOptions; 200 | ULONG ReferenceCount; // since WIN10 201 | ULONG DependentLoadFlags; 202 | UCHAR SigningLevel; // since REDSTONE2 203 | ULONG CheckSum; // since 22H1 204 | PVOID ActivePatchImageBase; 205 | LDR_HOT_PATCH_STATE HotPatchState; 206 | } LDR_DATA_TABLE_ENTRY, * PLDR_DATA_TABLE_ENTRY; 207 | 208 | typedef struct _LDRP_LOAD_CONTEXT 209 | { 210 | UNICODE_STRING BaseDllName; 211 | LDR_UNKSTRUCT* UnkStruct; 212 | HANDLE SectionHandle; 213 | DWORD Flags; 214 | NTSTATUS* pStatus; 215 | LDR_DATA_TABLE_ENTRY* Entry; 216 | _LIST_ENTRY WorkQueueListEntry; 217 | LDR_DATA_TABLE_ENTRY* ReplacedEntry; 218 | LDR_DATA_TABLE_ENTRY** pvImports; 219 | LDR_DATA_TABLE_ENTRY** IATCheck; 220 | PVOID pvIAT; 221 | ULONG SizeOfIAT; 222 | ULONG CurrentDll; 223 | PIMAGE_IMPORT_DESCRIPTOR pImageImportDescriptor; 224 | ULONG ImageImportDescriptorLen; 225 | __declspec(align(8)) ULONG OriginalIATProtect; 226 | PVOID GuardCFCheckFunctionPointer; 227 | __int64 GuardFlags; 228 | __int64 DllNameLenCompare; 229 | __int64 UnknownFunc; 230 | SIZE_T Size; 231 | __int64 UnknownPtr; 232 | HANDLE FileHandle; 233 | PIMAGE_DOS_HEADER ImageBase; 234 | wchar_t BaseDllNameBuffer[260]; 235 | } LDRP_LOAD_CONTEXT, * PLDRP_LOAD_CONTEXT; 236 | 237 | typedef NTSTATUS(WINAPI* pLdrLoadDll)(PWCHAR PathToFile, ULONG Flags, PUNICODE_STRING ModuleFileName, PHANDLE ModuleHandle); 238 | typedef NTSTATUS(__fastcall* pRtlInitUnicodeStringEx)(PUNICODE_STRING target, PCWSTR source); 239 | typedef NTSTATUS(__fastcall* pLdrpLoadDll)(PUNICODE_STRING DllName, LDR_UNKSTRUCT* DllPathInited, ULONG Flags, LDR_DATA_TABLE_ENTRY** DllEntry); 240 | typedef NTSTATUS(WINAPI* pfnLdrLoadDll)(PWCHAR PathToFile, ULONG Flags, PUNICODE_STRING ModuleFileName, PHANDLE ModuleHandle); 241 | typedef NTSTATUS(__fastcall* pLdrpLoadDllInternal)(PUNICODE_STRING FullPath, LDR_UNKSTRUCT* DllPathInited, ULONG Flags, ULONG LdrFlags, PLDR_DATA_TABLE_ENTRY LdrEntry, PLDR_DATA_TABLE_ENTRY LdrEntry2, PLDR_DATA_TABLE_ENTRY* DllEntry, NTSTATUS* pStatus); 242 | typedef NTSTATUS(__fastcall* pLdrpInitializeDllPath)(PWSTR DllName, PWSTR DllPath, LDR_UNKSTRUCT* DllPathInited); 243 | typedef NTSTATUS(__fastcall* pLdrpPreprocessDllName)(PUNICODE_STRING DllName, PUNICODE_STRING ResName, PULONG pZero, PULONG pFlags); 244 | typedef NTSTATUS(__fastcall* pLdrpFindOrPrepareLoadingModule)(PUNICODE_STRING FullPath, LDR_UNKSTRUCT* DllPathInited, ULONG Flags, ULONG LdrFlags, PLDR_DATA_TABLE_ENTRY LdrEntry, PLDR_DATA_TABLE_ENTRY* pLdrEntryLoaded, NTSTATUS* pStatus); 245 | typedef NTSTATUS(__fastcall* pLdrpProcessWork)(PLDRP_LOAD_CONTEXT LoadContext, BOOLEAN IsLoadOwner); 246 | 247 | bool GetPdbSignature(const std::string& dllPath, GUID& pdbGuid, DWORD& pdbAge) { 248 | if (!SymInitialize(GetCurrentProcess(), NULL, TRUE)) { 249 | return false; 250 | } 251 | HMODULE hModule = LoadLibraryExA(dllPath.c_str(), NULL, DONT_RESOLVE_DLL_REFERENCES); 252 | if (!hModule) { 253 | SymCleanup(GetCurrentProcess()); 254 | return false; 255 | } 256 | MODULEINFO modInfo; 257 | if (!GetModuleInformation(GetCurrentProcess(), hModule, &modInfo, sizeof(modInfo))) { 258 | FreeLibrary(hModule); 259 | SymCleanup(GetCurrentProcess()); 260 | return false; 261 | } 262 | DWORD64 baseAddr = reinterpret_cast(modInfo.lpBaseOfDll); 263 | IMAGEHLP_MODULE64 moduleInfo; 264 | ZeroMemory(&moduleInfo, sizeof(moduleInfo)); 265 | moduleInfo.SizeOfStruct = sizeof(moduleInfo); 266 | 267 | if (!SymGetModuleInfo64(GetCurrentProcess(), (DWORD64)modInfo.lpBaseOfDll, &moduleInfo)) { 268 | FreeLibrary(hModule); 269 | SymCleanup(GetCurrentProcess()); 270 | return false; 271 | } 272 | pdbGuid = moduleInfo.PdbSig70; 273 | pdbAge = moduleInfo.PdbAge; 274 | FreeLibrary(hModule); 275 | SymCleanup(GetCurrentProcess()); 276 | 277 | return true; 278 | } 279 | 280 | bool downloadDebugSymbols(const std::wstring& guid, const std::wstring& filename) { 281 | std::wstring baseUrl = L"https://msdl.microsoft.com/download/symbols"; 282 | std::wstring pdbUrl = baseUrl + L"/" + filename + L"/" + guid + L"/" + filename; 283 | 284 | HRESULT hr = URLDownloadToFileW( 285 | NULL, 286 | pdbUrl.c_str(), 287 | filename.c_str(), 288 | 0, 289 | NULL 290 | ); 291 | 292 | return SUCCEEDED(hr); 293 | } 294 | 295 | FARPROC GetAddressFromSymbols(HANDLE hProcess, LPCSTR fullModulePath, LPCSTR pdbPath, LPCSTR lpProcName) { 296 | if (!SymInitialize(hProcess, NULL, TRUE)) { 297 | printf("SymInitialize failed: %lu\n", GetLastError()); 298 | return 0; 299 | } 300 | if (!SymSetSearchPath(hProcess, pdbPath)) { 301 | printf("SymSetSearchPath failed: %lu\n", GetLastError()); 302 | SymCleanup(hProcess); 303 | return 0; 304 | } 305 | DWORD64 baseOfDll = SymLoadModuleEx(hProcess, NULL, fullModulePath, NULL, 0, 0, NULL, 0); 306 | if (baseOfDll == 0) { 307 | printf("SymLoadModuleEx failed: %lu\n", GetLastError()); 308 | SymCleanup(hProcess); 309 | return 0; 310 | } 311 | SYMBOL_INFO* symbol = (SYMBOL_INFO*)malloc(sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)); 312 | symbol->MaxNameLen = MAX_SYM_NAME; 313 | symbol->SizeOfStruct = sizeof(SYMBOL_INFO); 314 | if (SymFromName(hProcess, lpProcName, symbol)) { 315 | printf("Symbol found: %s at address 0x%0llX\n", symbol->Name, symbol->Address); 316 | FARPROC result = (FARPROC)symbol->Address; 317 | free(symbol); 318 | SymCleanup(hProcess); 319 | return result; 320 | } 321 | else { 322 | printf("SymFromName failed: %lu\n", GetLastError()); 323 | } 324 | free(symbol); 325 | SymCleanup(hProcess); 326 | return 0; 327 | } 328 | 329 | 330 | typedef int (WINAPI* MessageBoxWFunc)( 331 | HWND hWnd, 332 | LPCWSTR lpText, 333 | LPCWSTR lpCaption, 334 | UINT uType 335 | ); 336 | const wchar_t* GetWC(const char* c) 337 | { 338 | const size_t cSize = strlen(c) + 1; 339 | wchar_t* wc = new wchar_t[cSize]; 340 | mbstowcs(wc, c, cSize); 341 | 342 | return wc; 343 | } 344 | int main() 345 | { 346 | //CONFIG START 347 | //SELECT MODE AND DLL NAME TO LOAD 348 | int mode = MODE_LDRPPROCESSWORK; 349 | char dllName[] = "user32.dll"; 350 | //CONFIG END 351 | 352 | GUID pdbGuid; 353 | DWORD pdbAge; 354 | 355 | std::string dllPath = "ntdll.dll"; 356 | GetPdbSignature(dllPath, pdbGuid, pdbAge); 357 | 358 | wchar_t guid_string[MAX_PATH] = {}; 359 | 360 | 361 | swprintf( 362 | guid_string, sizeof(guid_string) / sizeof(guid_string[0]), 363 | L"%08x%04x%04x%02x%02x%02x%02x%02x%02x%02x%02x%01x", 364 | pdbGuid.Data1, pdbGuid.Data2, pdbGuid.Data3, 365 | pdbGuid.Data4[0], pdbGuid.Data4[1], pdbGuid.Data4[2], 366 | pdbGuid.Data4[3], pdbGuid.Data4[4], pdbGuid.Data4[5], 367 | pdbGuid.Data4[6], pdbGuid.Data4[7], pdbAge); 368 | 369 | bool success = downloadDebugSymbols(guid_string, L"ntdll.pdb"); 370 | HMODULE hNtDll = NULL; 371 | hNtDll = LoadLibraryA("ntdll.dll"); 372 | pRtlInitUnicodeStringEx RtlInitUnicodeStringEx = (pRtlInitUnicodeStringEx)GetProcAddress(hNtDll, "RtlInitUnicodeStringEx"); 373 | 374 | HMODULE hResModule = NULL; 375 | 376 | 377 | switch (mode) 378 | { 379 | case MODE_LOADLIBRARYA: { 380 | hResModule = LoadLibraryA(dllName); 381 | break; 382 | } 383 | case MODE_LOADLIBRARYEXA: { 384 | hResModule = LoadLibraryExA(dllName, 0, 0); 385 | break; 386 | } 387 | case MODE_LDRLOADDLL: { 388 | pLdrLoadDll fnLdrLoadDll = (pLdrLoadDll)GetProcAddress(hNtDll, "LdrLoadDll"); 389 | UNICODE_STRING ModuleFileName; 390 | RtlInitUnicodeStringEx(&ModuleFileName, GetWC(dllName)); 391 | HANDLE hModule = NULL; 392 | NTSTATUS status = fnLdrLoadDll((PWSTR)(0x7F08 | 1), 0, &ModuleFileName, &hModule); 393 | break; 394 | } 395 | case MODE_LDRPLOADDLL: { 396 | LDR_UNKSTRUCT someStruct = {}; 397 | LDR_DATA_TABLE_ENTRY* DllEntry = {}; 398 | ULONG flags = 0; 399 | UNICODE_STRING uniDllName; 400 | RtlInitUnicodeStringEx(&uniDllName, GetWC(dllName)); 401 | pLdrpInitializeDllPath ldrpInitializeDllPath = (pLdrpInitializeDllPath)(GetAddressFromSymbols(GetCurrentProcess(), "C:\\Windows\\System32\\ntdll.dll", "./ntdll.pdb", "LdrpInitializeDllPath")); 402 | ldrpInitializeDllPath(uniDllName.Buffer, (PWSTR)(0x7F08 | 1), &someStruct); 403 | pLdrpLoadDll ldrpLoadDll = (pLdrpLoadDll)(GetAddressFromSymbols(GetCurrentProcess(), "C:\\Windows\\System32\\ntdll.dll", "./ntdll.pdb", "LdrpLoadDll")); 404 | ldrpLoadDll(&uniDllName, &someStruct, NULL, &DllEntry); 405 | break; 406 | } 407 | case MODE_LDRPLOADDLLINTERNAL: { 408 | LDR_UNKSTRUCT someStruct = {}; 409 | LDR_DATA_TABLE_ENTRY* DllEntry = {}; 410 | ULONG flags = 0; 411 | UNICODE_STRING uniDllName; 412 | RtlInitUnicodeStringEx(&uniDllName, GetWC(dllName)); 413 | UNICODE_STRING FullDllPath; 414 | WCHAR Buffer[128]; 415 | FullDllPath.Length = 0; 416 | FullDllPath.MaximumLength = MAX_PATH - 4; 417 | FullDllPath.Buffer = Buffer; 418 | Buffer[0] = 0; 419 | pLdrpPreprocessDllName ldrpPreprocessDllName = (pLdrpPreprocessDllName)(GetAddressFromSymbols(GetCurrentProcess(), "C:\\Windows\\System32\\ntdll.dll", "./ntdll.pdb", "LdrpPreprocessDllName")); 420 | pLdrpLoadDllInternal ldrpLoadDllInternal = (pLdrpLoadDllInternal)(GetAddressFromSymbols(GetCurrentProcess(), "C:\\Windows\\System32\\ntdll.dll", "./ntdll.pdb", "LdrpLoadDllInternal")); 421 | 422 | NTSTATUS res = ldrpPreprocessDllName(&uniDllName, &FullDllPath, 0, &flags); 423 | ldrpLoadDllInternal(&FullDllPath, &someStruct, flags, 0x4, 0, 0, &DllEntry, &res); 424 | 425 | break; 426 | } 427 | case MODE_LDRPPROCESSWORK: { 428 | LDR_DATA_TABLE_ENTRY* pLdrEntryLoaded = 0; 429 | LDR_UNKSTRUCT undefStruct = {}; 430 | UNICODE_STRING uniDllName; 431 | RtlInitUnicodeStringEx(&uniDllName, GetWC(dllName)); 432 | pLdrpInitializeDllPath ldrpInitializeDllPath = (pLdrpInitializeDllPath)(GetAddressFromSymbols(GetCurrentProcess(), "C:\\Windows\\System32\\ntdll.dll", "./ntdll.pdb", "LdrpInitializeDllPath")); 433 | ldrpInitializeDllPath(uniDllName.Buffer, (PWSTR)(0x7F08 | 1), &undefStruct); 434 | ULONG flags = 0; 435 | UNICODE_STRING FullDllPath; 436 | WCHAR Buffer[128]; 437 | FullDllPath.Length = 0; 438 | FullDllPath.MaximumLength = MAX_PATH - 4; 439 | FullDllPath.Buffer = Buffer; 440 | Buffer[0] = 0; 441 | pLdrpPreprocessDllName ldrpPreprocessDllName = (pLdrpPreprocessDllName)(GetAddressFromSymbols(GetCurrentProcess(), "C:\\Windows\\System32\\ntdll.dll", "./ntdll.pdb", "LdrpPreprocessDllName")); 442 | NTSTATUS res = ldrpPreprocessDllName(&uniDllName, &FullDllPath, 0, &flags); 443 | pLdrpFindOrPrepareLoadingModule ldrpFindOrPrepareLoadingModule = (pLdrpFindOrPrepareLoadingModule)(GetAddressFromSymbols(GetCurrentProcess(), "C:\\Windows\\System32\\ntdll.dll", "./ntdll.pdb", "LdrpFindOrPrepareLoadingModule")); 444 | NTSTATUS Status = ldrpFindOrPrepareLoadingModule(&FullDllPath, &undefStruct, flags, 0x4, 0, &pLdrEntryLoaded, &res); 445 | pLdrpProcessWork ldrpProcessWork = (pLdrpProcessWork)(GetAddressFromSymbols(GetCurrentProcess(), "C:\\Windows\\System32\\ntdll.dll", "./ntdll.pdb", "LdrpProcessWork")); 446 | 447 | if (Status == STATUS_DLL_NOT_FOUND) 448 | NTSTATUS res = ldrpProcessWork(pLdrEntryLoaded->LoadContext, TRUE); 449 | break; 450 | } 451 | 452 | } 453 | MessageBoxWFunc MessageBoxWPtr = (MessageBoxWFunc)(GetProcAddress(GetModuleHandleA(dllName), "MessageBoxW")); 454 | MessageBoxWPtr(NULL, L":)", L"FunnyWhale", MB_OK); 455 | 456 | return 0; 457 | } -------------------------------------------------------------------------------- /AlterLoadDll/AlterLoadDll.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 | 17.0 23 | Win32Proj 24 | {e2359b2b-9c1b-442c-92df-210905adc65c} 25 | AlterLoadDll 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 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;_CONSOLE;%(PreprocessorDefinitions) 78 | true 79 | 80 | 81 | Console 82 | true 83 | 84 | 85 | 86 | 87 | Level3 88 | true 89 | true 90 | true 91 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 92 | true 93 | 94 | 95 | Console 96 | true 97 | true 98 | true 99 | 100 | 101 | 102 | 103 | Level3 104 | true 105 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 106 | true 107 | 108 | 109 | Console 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | true 118 | true 119 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 120 | true 121 | 122 | 123 | Console 124 | true 125 | true 126 | true 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /AlterLoadDll/AlterLoadDll.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 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AlterLoadDll 2 | Load dll with undocumented functions and debug symbols 3 | 4 | Research: https://habr.com/ru/articles/829892/ 5 | 6 | Telegram: https://t.me/authoritywear 7 | --------------------------------------------------------------------------------