{"id":20217394,"url":"https://github.com/windowsnt/hotpatch","last_synced_at":"2026-02-24T11:02:26.473Z","repository":{"id":80700399,"uuid":"154197341","full_name":"WindowsNT/hotpatch","owner":"WindowsNT","description":"Hotpatching in Windows with 5 methods. ","archived":false,"fork":false,"pushed_at":"2018-10-23T12:16:47.000Z","size":85,"stargazers_count":64,"open_issues_count":1,"forks_count":17,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-10T16:06:55.162Z","etag":null,"topics":["hotfix","hotpatch","win32","win64"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WindowsNT.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-22T18:45:16.000Z","updated_at":"2024-12-03T18:25:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"f445a490-5afc-42a4-8573-4740c7107448","html_url":"https://github.com/WindowsNT/hotpatch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/WindowsNT/hotpatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindowsNT%2Fhotpatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindowsNT%2Fhotpatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindowsNT%2Fhotpatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindowsNT%2Fhotpatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WindowsNT","download_url":"https://codeload.github.com/WindowsNT/hotpatch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindowsNT%2Fhotpatch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29780604,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-24T10:45:18.109Z","status":"ssl_error","status_checked_at":"2026-02-24T10:45:09.911Z","response_time":75,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hotfix","hotpatch","win32","win64"],"created_at":"2024-11-14T06:33:55.348Z","updated_at":"2026-02-24T11:02:26.437Z","avatar_url":"https://github.com/WindowsNT.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HotPatch\nA single-header C++ library for Windows to create hotpatchable images and apply hotpatches with 5 methods\n\nArticle at CodeProject: https://www.codeproject.com/Articles/1043089/HotPatching-Deep-Inside\n\n## Executable to be hot-patched preparation\n\n1. Build the executable in ***release*** mode from solution\n2. The solution is automatically configured to run the executable with parameter /postbuildpatch which updates itself with the patch information. It uses BeginUpdateResource and EndUpdateResource.\nNote that these are frequently stopped by antivirus. You can also use the included pig.exe which is a standalone app to read a file and its pdf, and put the hotpatch data inside it.\n\n## Method 1: Using a DLL to patch an Executable \n\n1. Load the DLL from the executable and call an exported function (say, Patch()).\n2. Call hp.ApplyPatchFor() for each function you want to be patched:\n\n\n```C++\nhr = hp.ApplyPatchFor(hM, L\"FOO::PatchableFunction1\", PatchableFunction1, \u0026xPatch);\n```\n\n## Method 2: Using the same executable as a COM server\n\n1. Call hp.PrepareExecutableForCOMPatching();\n2. If embedding, start the COM server, specifying the patches and installing a message loop:\n\n```C++\n\nvoid EmbeddingStart()\n{\n\thp.StartCOMServer(GUID_TEST, [](vector\u003cHOTPATCH::NAMEANDPOINTER\u003e\u0026 w) -\u003e HRESULT\n\t{\n\t\tw.clear();\n\t\tHOTPATCH::NAMEANDPOINTER nap;\n\t\tnap.n = L\"PatchableFunction1\";\n\t\tnap.f = [](size_t*) -\u003e size_t\n\t\t{\n\t\t\tMessageBox(0, L\"Patch from COM Patcher\", L\"Patched\", MB_ICONINFORMATION);\n\t\t\treturn 0;\n\t\t};\n\t\tw.push_back(nap);\n\t\treturn S_OK;\n\t},\n\n\t[]()\n\t{\n\t\t// We are closing...\n\t\tPostThreadMessage(mtid, WM_QUIT, 0, 0);\n\t}\n\t);\n}\n\n// main\nif (argc == 2 \u0026\u0026 (_wcsicmp(wargv[1], L\"-embedding\") == 0 || _wcsicmp(wargv[1], L\"/embedding\") == 0))\n{\n\tmtid = GetCurrentThreadId();\n\tEmbeddingStart();\n\tMSG msg;\n\twhile (GetMessage(\u0026msg, 0, 0, 0))\n\t{\n\t\tTranslateMessage(\u0026msg);\n\t\tDispatchMessage(\u0026msg);\n\t}\n\treturn 0;\n}\n\t\n```\n\nIf main, start the patching process\n\n```C++\nhp.StartCOMPatching();\nvector\u003cwstring\u003e pns;\nhp.AckGetPatchNames(pns);\nfor (auto\u0026 aa : pns)\n{\n\thp.ApplyCOMPatchFor(xPatch, GetModuleHandle(0), aa.c_str());\n}\n...\n// End app\nhp.FinishCOMPatching();\n```\n\n## Method 3: Using the same executable with shared memory\n\n1. Call hp.PrepareExecutableForUSMPatching();\n2. If patching mode, start the USM server, specifying the patches and installing a message loop:\n\n```C++\n\nvoid USMStart()\n{\n\thp.StartUSMServer(GUID_TEST, [](vector\u003cHOTPATCH::NAMEANDPOINTER\u003e\u0026 w) -\u003e HRESULT\n\t{\n\t\tHOTPATCH::NAMEANDPOINTER nap;\n\t\tnap.n = L\"PatchableFunction1\";\n\n\t\tTCHAR cidx[1000] = { 0 };\n\t\tStringFromGUID2(GUID_TEST, cidx, 1000);\n\t\tswprintf_s(cidx + wcslen(cidx), 1000 - wcslen(cidx), L\"-%u\", 0);\n\t\tnap.mu = (mutual*)new mutual(cidx, [\u0026](unsigned long long)\n\t\t{\n\t\t\tMessageBox(0, L\"Patch from USM Patcher\", L\"Patched\", MB_ICONINFORMATION);\n\t\t\treturn;\n\t\t}, 0, true);\n\t\tw.push_back(nap);\n\n\t\treturn S_OK;\n\t},\n\n\t\t[]()\n\t{\n\t\t// We are closing...\n\t\tPostThreadMessage(mtid, WM_QUIT, 0, 0);\n\t}\n\t);\n\n}\n\n\n\n// main\nif (argc == 2 \u0026\u0026 (_wcsicmp(wargv[1], L\"-usm\") == 0 || _wcsicmp(wargv[1], L\"/usm\") == 0))\n{\n\tmtid = GetCurrentThreadId();\n\tUSMStart();\n\tMSG msg;\n\twhile (GetMessage(\u0026msg, 0, 0, 0))\n\t{\n\t\tTranslateMessage(\u0026msg);\n\t\tDispatchMessage(\u0026msg);\n\t}\n\treturn 0;\n}\n\n\t\n```\n\nIf main, start the patching process\n\n```C++\n// a has path name to patcher\nwcscat_s(a, 1000, L\" /usm\");\n\n// Run it with /USM\nSTARTUPINFO sInfo = { 0 };\nsInfo.cb = sizeof(sInfo);\nPROCESS_INFORMATION pi = { 0 };\nif (!CreateProcess(0, a, 0, 0, 0, 0, 0, 0, \u0026sInfo, \u0026pi))\n\treturn 0;\nCloseHandle(pi.hThread);\nCloseHandle(pi.hProcess);\n\n// Get the names\nvector\u003cwstring\u003e pns;\nhp.AckGetPatchNames(pns);\nfor (size_t i = 0; i \u003c pns.size(); i++)\n{\n\tauto\u0026 aa = pns[i];\n\thp.ApplyUSMPatchFor(xPatch, GetModuleHandle(0), aa.c_str(), i);\n}\n...\n\n// End app\nhp.FinishCOMPatching();\n```\n\n## Method 4 : Self-EXE\n\nThis method is based on my article at https://www.codeproject.com/Articles/1045674/Load-EXE-as-DLL-Mission-Possible , which describes how to load an EXE as a DLL.\nHowever this is a highly hackish method and should not be used.\n\n## Method 5 : Self-DLL\n\nThe final method requires your app to be build itself as DLL. Therefore, the post-build event is now  *rundll32 .\\test.dll,PostBuildPatch*, the debugger run command is now *rundll32 .\\test.dll,dmain*\nand you can have the program and the patcher inside the same DLL.\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindowsnt%2Fhotpatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwindowsnt%2Fhotpatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindowsnt%2Fhotpatch/lists"}