{"id":17383490,"url":"https://github.com/yurisizuku/win-memorymodule","last_synced_at":"2025-04-13T02:11:34.283Z","repository":{"id":50455996,"uuid":"470470889","full_name":"YuriSizuku/win-MemoryModule","owner":"YuriSizuku","description":"A flexible PE loader, loading module in memory. Most of the functions can be inline, compatible for shellcode.","archived":false,"fork":false,"pushed_at":"2025-02-21T10:00:03.000Z","size":162,"stargazers_count":189,"open_issues_count":1,"forks_count":69,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-04T04:49:09.260Z","etag":null,"topics":["dll-injection","shellcode","shellcode-injection","windows"],"latest_commit_sha":null,"homepage":"","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/YuriSizuku.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":"2022-03-16T07:10:08.000Z","updated_at":"2025-04-02T14:28:00.000Z","dependencies_parsed_at":"2023-12-18T18:17:25.904Z","dependency_job_id":"22992589-0b16-425e-b03f-52dfb41b05de","html_url":"https://github.com/YuriSizuku/win-MemoryModule","commit_stats":null,"previous_names":["yurisizuku/win-memorymodule","yurisizuku/memorymodule"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YuriSizuku%2Fwin-MemoryModule","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YuriSizuku%2Fwin-MemoryModule/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YuriSizuku%2Fwin-MemoryModule/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YuriSizuku%2Fwin-MemoryModule/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YuriSizuku","download_url":"https://codeload.github.com/YuriSizuku/win-MemoryModule/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654089,"owners_count":21140236,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["dll-injection","shellcode","shellcode-injection","windows"],"created_at":"2024-10-16T07:42:56.653Z","updated_at":"2025-04-13T02:11:34.257Z","avatar_url":"https://github.com/YuriSizuku.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MemoryModule  \n\n![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/yurisizuku/win-MemoryModule?color=green\u0026label=MemoryModule)![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/YuriSizuku/win-MemoryModule/build.yml?label=build)  \n\n☘️ A flexible PE loader, loading module in memory.\nMost of the functions can be inline,  compatible for shellcode.\n\n**compatible list:**\n\n- [x] windows xp\n- [x] windows 7\n- [x] windows 8\n- [x] windows 10\n- [x] windows 11\n- [x] linux wine\n\n## build\n\nYou can use `clang`(llvm-mingw), `gcc`(mingw-w64) or `tcc`  and `msvc`(visual studio 2022) to compile.  \n\nHere's a example for using `llvm-mingw`\n\n```shell\ngit clone https://github.com/YuriSizuku/MemoryModule.git --recursive\nmake winmemdll_shellcode CC=x86_64-w64-mingw32-clang # only if you want to generate shellcode\nmake winmemdll CC=i686-w64-mingw32-gcc BUILD_TYPE=32d # x86 debug\n```\n\n## Usage\n\n``` mermaid\n%%{init: {'theme':'forest'}}%%\ngraph LR;\nf1[winpe_findspace]\nf2[winpe_memreloc];\nf3[winpe_membindiat]\nf4[winpe_membindtls]\nf5[pfnDllMain]\n\nf1 --\u003e f2 --\u003e f3 --\u003e f4 --\u003e f5\n```\n\n### load DLL in memory\n\n```c\nconst char *dllpath = \"test.dll\";\nsize_t mempesize = 0;\nvoid *memdll = NULL;\n\n// load the pe file in memory and align it to memory align\nvoid *mempe = winpe_memload_file(dllpath, \u0026mempesize, TRUE); \n\n// memory loadlibrary\nmemdll = winpe_memLoadLibrary(mempe);\nwinpe_memFreeLibrary(memdll);\n\n// memory loadlibrary at specific address\nsize_t targetaddr = sizeof(size_t) \u003e 4 ? 0x140030000: 0x90000;\nmemdll = winpe_memLoadLibraryEx(mempe, targetaddr, \n    WINPE_LDFLAG_MEMALLOC, (PFN_LoadLibraryA)winpe_findloadlibrarya(), \n    (PFN_GetProcAddress)winpe_memGetProcAddress);\nwinpe_memFreeLibrary(memdll);\nfree(mempe);\n```\n\n### attach DLL in exe\n\n```shell\nwin_injectmemdll.exe exepath dllpath [outpath]\n```\n\n### API\n\nThese functions are essential to load memory module in windows.  \n\nSee [winpe.h](https://github.com/YuriSizuku/ReverseTool/blob/master/src/winpe.h)  in detail.\n\n```c\n/**\n * load the origin rawpe file in memory buffer by mem align\n * mempe means the pe in memory alignment\n * @param pmemsize mempe buffer size\n * @return mempe buf\n*/\nWINPE_API\nvoid* STDCALL winpe_memload_file(const char *path, size_t *pmemsize, bool_t same_align);\n\n/**\n * load the mempe in a valid imagebase, will call dll entry\n * @param imagebase if 0, will load on mempe, else in imagebase\n * @param flag WINPE_LDFLAG_MEMALLOC 0x1, will alloc memory to imagebase\n *             WINPE_LDFLAG_MEMFIND 0x2, will find a valid space, \n * @return hmodule base\n*/\nWINPE_API\nvoid* STDCALL winpe_memLoadLibraryEx(void *mempe, size_t imagebase, DWORD flag,\n    PFN_LoadLibraryA pfnLoadLibraryA, PFN_GetProcAddress pfnGetProcAddress);\n\n/**\n * similar to FreeLibrary, will call dll entry\n * @return True on successful\n*/\nWINPE_API\nBOOL STDCALL winpe_memFreeLibrary(void *mempe);\n\n/**\n * similar to GetProcAddress\n * @return function va\n*/\nWINPE_API\nPROC STDCALL winpe_memGetProcAddress(void *mempe, const char *funcname);\n\n/**\n * use peb and ldr list, similar as GetModuleHandleA\n * @return ldr module address\n*/\nWINPE_API\nvoid* STDCALL winpe_findmodulea(const char *modulename)\n{\n    return winpe_findmoduleaex(NULL, modulename);\n}\n```\n\n## Known issues\n\n- [x] attach x64 DLL to exe crash on calling some windows API\n  problem occured by `movaps xmm0, xmmword ptr ss:[rsp]`\n  fixed by stack memory align with 0x10  \n\n## Todo\n\n- [x] TLS initialize support, finished, but not tested, because I didn't find DLL with TLS example.  \n- [x] support ASLR finished  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyurisizuku%2Fwin-memorymodule","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyurisizuku%2Fwin-memorymodule","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyurisizuku%2Fwin-memorymodule/lists"}