{"id":42,"date":"2013-10-03T14:31:46","date_gmt":"2013-10-03T14:31:46","guid":{"rendered":""},"modified":"2013-10-03T14:31:46","modified_gmt":"2013-10-03T14:31:46","slug":"","status":"publish","type":"post","link":"http:\/\/weizn.net\/?p=42","title":{"rendered":"\u5378\u8f7d\u8fdb\u7a0bDLL\u6587\u4ef6"},"content":{"rendered":"<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;conio.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;windows.h&gt;<br \/>\n#include &lt;tlhelp32.h&gt;<\/p>\n<p>bool Privilege()<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; \/\/\u63d0\u5347\u5f53\u524d\u8fdb\u7a0b\u7684\u8bbf\u95ee\u4ee4\u724c<br \/>\n&nbsp;&nbsp;&nbsp; HANDLE hToken=NULL;<br \/>\n&nbsp;&nbsp;&nbsp; <br \/>\n&nbsp;&nbsp;&nbsp; if(OpenProcessToken(GetCurrentProcess(),TOKEN_ALL_ACCESS,&amp;hToken)!=TRUE) return false;<br \/>\n&nbsp;&nbsp;&nbsp; TOKEN_PRIVILEGES tp;<br \/>\n&nbsp;&nbsp;&nbsp; tp.PrivilegeCount=1;<br \/>\n&nbsp;&nbsp;&nbsp; LookupPrivilegeValue(NULL,SE_DEBUG_NAME,&amp;tp.Privileges[0].Luid);<br \/>\n&nbsp;&nbsp;&nbsp; tp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;<br \/>\n&nbsp;&nbsp;&nbsp; AdjustTokenPrivileges(hToken,FALSE,&amp;tp,sizeof(tp),NULL,NULL);<br \/>\n&nbsp;&nbsp;&nbsp; <br \/>\n&nbsp;&nbsp;&nbsp; CloseHandle(hToken);<br \/>\n&nbsp;&nbsp;&nbsp; return true;<br \/>\n}<\/p>\n<p>bool ListProcess()<br \/>\n{<br \/>\n&nbsp;HANDLE hProcessSnapshot;<br \/>\n&nbsp;PROCESSENTRY32 pe32;<br \/>\n&nbsp;pe32.dwSize=sizeof(PROCESSENTRY32);<\/p>\n<p>&nbsp;if(!Privilege())<br \/>\n&nbsp;&nbsp;printf(&#8220;\u63d0\u5347\u8fdb\u7a0b\u8bbf\u95ee\u4ee4\u724c\u6743\u9650\u5931\u8d25\u3002\\n&#8221;);<\/p>\n<p>&nbsp;if((hProcessSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,NULL))==INVALID_HANDLE_VALUE)<br \/>\n&nbsp;{<br \/>\n&nbsp;&nbsp;CloseHandle(hProcessSnapshot);<br \/>\n&nbsp;&nbsp;printf(&#8220;\u521b\u5efa\u8fdb\u7a0b\u5feb\u7167\u5931\u8d25\u3002\\n&#8221;);<br \/>\n&nbsp;&nbsp;return false;<br \/>\n&nbsp;}<br \/>\n&nbsp;if(!Process32First(hProcessSnapshot,&amp;pe32))<br \/>\n&nbsp;{<br \/>\n&nbsp;&nbsp;printf(&#8220;\u5217\u4e3e\u8fdb\u7a0b\u5217\u8868\u5931\u8d25\u3002\\n&#8221;);<br \/>\n&nbsp;&nbsp;return false;<br \/>\n&nbsp;}<br \/>\n&nbsp;do <br \/>\n&nbsp;{<br \/>\n&nbsp;&nbsp;printf(&#8220;FileName:%s\\t\\t\\tPID:%d\\n&#8221;,pe32.szExeFile,pe32.th32ProcessID);<br \/>\n&nbsp;} while (Process32Next(hProcessSnapshot,&amp;pe32));<br \/>\n&nbsp;CloseHandle(hProcessSnapshot);<\/p>\n<p>&nbsp;return true;<br \/>\n}<\/p>\n<p>bool ListModule(int pid)<br \/>\n{<br \/>\n&nbsp;int ID=0;<br \/>\n&nbsp;HANDLE hModuleSnapshot;<br \/>\n&nbsp;MODULEENTRY32 me32;<br \/>\n&nbsp;me32.dwSize=sizeof(MODULEENTRY32);<\/p>\n<p>&nbsp;&nbsp;&nbsp; if((hModuleSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,pid))==INVALID_HANDLE_VALUE)<br \/>\n&nbsp;{<br \/>\n&nbsp;&nbsp;CloseHandle(hModuleSnapshot);<br \/>\n&nbsp;&nbsp;printf(&#8220;\u521b\u5efa\u8fdb\u7a0b\u6a21\u5757\u5feb\u7167\u5931\u8d25\u3002\\n&#8221;);<br \/>\n&nbsp;&nbsp;return false;<br \/>\n&nbsp;}<br \/>\n&nbsp;Module32First(hModuleSnapshot,&amp;me32);<br \/>\n&nbsp;do <br \/>\n&nbsp;{<br \/>\n&nbsp;&nbsp;ID++;<br \/>\n&nbsp;&nbsp;printf(&#8220;%s\\t\\t\\tID:%d\\n&#8221;,me32.szExePath,ID);<br \/>\n&nbsp;} while (Module32Next(hModuleSnapshot,&amp;me32));<br \/>\n&nbsp;CloseHandle(hModuleSnapshot);<\/p>\n<p>&nbsp;return true;<br \/>\n}<\/p>\n<p>bool UnloadDLL(int pid,int module_id)<br \/>\n{<br \/>\n&nbsp;int ID=0;<br \/>\n&nbsp;HANDLE hModuleSnapshot;<br \/>\n&nbsp;HANDLE hRemoteProcess;<br \/>\n&nbsp;MODULEENTRY32 me32;<br \/>\n&nbsp;me32.dwSize=sizeof(MODULEENTRY32);<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp; if((hModuleSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,pid))==INVALID_HANDLE_VALUE)<br \/>\n&nbsp;{<br \/>\n&nbsp;&nbsp;CloseHandle(hModuleSnapshot);<br \/>\n&nbsp;&nbsp;printf(&#8220;\u521b\u5efa\u8fdb\u7a0b\u6a21\u5757\u5feb\u7167\u5931\u8d25\u3002\\n&#8221;);<br \/>\n&nbsp;&nbsp;return false;<br \/>\n&nbsp;}<br \/>\n&nbsp;Module32First(hModuleSnapshot,&amp;me32);<br \/>\n&nbsp;do <br \/>\n&nbsp;{<br \/>\n&nbsp;&nbsp;ID++;<br \/>\n&nbsp;&nbsp;if(ID==module_id) break;<br \/>\n&nbsp;} while (Module32Next(hModuleSnapshot,&amp;me32));<br \/>\n&nbsp;CloseHandle(hModuleSnapshot);<br \/>\n&nbsp;if(ID!=module_id) return false;<\/p>\n<p>&nbsp;if((hRemoteProcess=OpenProcess(PROCESS_ALL_ACCESS,false,pid))==INVALID_HANDLE_VALUE)<br \/>\n&nbsp;{<br \/>\n&nbsp;&nbsp;CloseHandle(hRemoteProcess);<br \/>\n&nbsp;&nbsp;printf(&#8220;\u6253\u5f00\u8fdb\u7a0b\u5931\u8d25\u3002\\n&#8221;);<br \/>\n&nbsp;&nbsp;return false;<br \/>\n&nbsp;}<br \/>\n&nbsp;LPTHREAD_START_ROUTINE pFunAddr=(LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle(&#8220;kernel32.dll&#8221;),&#8221;FreeLibrary&#8221;);<br \/>\n&nbsp;if(pFunAddr==NULL)<br \/>\n&nbsp;{<br \/>\n&nbsp;&nbsp;CloseHandle(hRemoteProcess);<br \/>\n&nbsp;&nbsp;printf(&#8220;\u83b7\u53d6\u51fd\u6570\u5730\u5740\u5931\u8d25\u3002\\n&#8221;);<br \/>\n&nbsp;&nbsp;return false;<br \/>\n&nbsp;}<br \/>\n&nbsp;HANDLE hThread=CreateRemoteThread(hRemoteProcess,NULL,0,pFunAddr,me32.hModule,0,NULL);<br \/>\n&nbsp;if(hThread==INVALID_HANDLE_VALUE)<br \/>\n&nbsp;{<br \/>\n&nbsp;&nbsp;CloseHandle(hRemoteProcess);<br \/>\n&nbsp;&nbsp;CloseHandle(hThread);<br \/>\n&nbsp;&nbsp;printf(&#8220;\u8fdc\u7a0b\u7ebf\u7a0b\u6ce8\u5165\u5931\u8d25\u3002&#8221;);<br \/>\n&nbsp;&nbsp;return false;<br \/>\n&nbsp;}<br \/>\n&nbsp;WaitForSingleObject(hThread,INFINITE);<br \/>\n&nbsp;CloseHandle(hThread);<br \/>\n&nbsp;CloseHandle(hRemoteProcess);<\/p>\n<p>&nbsp;return true;<br \/>\n}<\/p>\n<p>int main(int argc,char *argv[])<br \/>\n{<br \/>\n&nbsp;int pid;<br \/>\n&nbsp;int ModuleID;<\/p>\n<p>again:<br \/>\n&nbsp;if(!ListProcess())<br \/>\n&nbsp;{<br \/>\n&nbsp;&nbsp;printf(&#8220;\u5217\u4e3e\u8fdb\u7a0b\u5931\u8d25\u3002\\n&#8221;);<br \/>\n&nbsp;&nbsp;getch();<br \/>\n&nbsp;&nbsp;return -1;<br \/>\n&nbsp;}<br \/>\n&nbsp;printf(&#8220;\u8bf7\u9009\u62e9\u4e00\u4e2a\u8fdb\u7a0bPID:&#8221;);<br \/>\n&nbsp;if(scanf(&#8220;%d&#8221;,&amp;pid)!=1) return -1;<br \/>\n&nbsp;if(!ListModule(pid))<br \/>\n&nbsp;{<br \/>\n&nbsp;&nbsp;printf(&#8220;\u5217\u4e3e\u8fdb\u7a0b\u6a21\u5757\u5931\u8d25\u3002\\n&#8221;);<br \/>\n&nbsp;&nbsp;getch();<br \/>\n&nbsp;&nbsp;return -1;<br \/>\n&nbsp;}<br \/>\n&nbsp;printf(&#8220;\u8bf7\u9009\u62e9\u8981\u5378\u8f7d\u7684ID:&#8221;);<br \/>\n&nbsp;if(scanf(&#8220;%d&#8221;,&amp;ModuleID)!=1) return -1;<br \/>\n&nbsp;if(!UnloadDLL(pid,ModuleID))<br \/>\n&nbsp;{<br \/>\n&nbsp;&nbsp;printf(&#8220;\u5378\u8f7d\u6a21\u5757\u5931\u8d25\u3002\\n&#8221;);<br \/>\n&nbsp;&nbsp;getch();<br \/>\n&nbsp;&nbsp;return -1;<br \/>\n&nbsp;}<br \/>\n&nbsp;printf(&#8220;\u6a21\u5757\u5378\u8f7d\u6210\u529f\u3002\\n&#8221;);<br \/>\n&nbsp;getch();<br \/>\n&nbsp;goto again;<\/p>\n<p>&nbsp;return 0;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;conio.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;windows.h&gt;<br \/>\n#include &lt;tlhelp32.h&gt;<\/p>\n<p>bool Privilege()<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[324],"tags":[],"class_list":["post-42","post","type-post","status-publish","format-standard","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5378\u8f7d\u8fdb\u7a0bDLL\u6587\u4ef6 - Wayne&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/weizn.net\/?p=42\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5378\u8f7d\u8fdb\u7a0bDLL\u6587\u4ef6 - Wayne&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;conio.h&gt; #include &lt;string.h&gt; #include &lt;windows.h&gt; #include &lt;tlhelp32.h&gt;bool Privilege() { &nbsp;&nbsp;&nbsp;...\" \/>\n<meta property=\"og:url\" content=\"http:\/\/weizn.net\/?p=42\" \/>\n<meta property=\"og:site_name\" content=\"Wayne&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2013-10-03T14:31:46+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"zinan\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/weizn.net\/#website\",\"url\":\"http:\/\/weizn.net\/\",\"name\":\"Wayne&#039;s Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/weizn.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/weizn.net\/?p=42#webpage\",\"url\":\"http:\/\/weizn.net\/?p=42\",\"name\":\"\\u5378\\u8f7d\\u8fdb\\u7a0bDLL\\u6587\\u4ef6 - Wayne&#039;s Blog\",\"isPartOf\":{\"@id\":\"http:\/\/weizn.net\/#website\"},\"datePublished\":\"2013-10-03T14:31:46+00:00\",\"dateModified\":\"2013-10-03T14:31:46+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/weizn.net\/?p=42#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/weizn.net\/?p=42\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/weizn.net\/?p=42#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\\u9996\\u9875\",\"item\":\"http:\/\/weizn.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\\u5378\\u8f7d\\u8fdb\\u7a0bDLL\\u6587\\u4ef6\"}]},{\"@type\":\"Article\",\"@id\":\"http:\/\/weizn.net\/?p=42#article\",\"isPartOf\":{\"@id\":\"http:\/\/weizn.net\/?p=42#webpage\"},\"author\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"headline\":\"\\u5378\\u8f7d\\u8fdb\\u7a0bDLL\\u6587\\u4ef6\",\"datePublished\":\"2013-10-03T14:31:46+00:00\",\"dateModified\":\"2013-10-03T14:31:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/weizn.net\/?p=42#webpage\"},\"wordCount\":581,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"articleSection\":[\"C\/C++\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/weizn.net\/?p=42#respond\"]}]},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\",\"name\":\"zinan\",\"logo\":{\"@id\":\"http:\/\/weizn.net\/#personlogo\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5378\u8f7d\u8fdb\u7a0bDLL\u6587\u4ef6 - Wayne&#039;s Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/weizn.net\/?p=42","og_locale":"zh_CN","og_type":"article","og_title":"\u5378\u8f7d\u8fdb\u7a0bDLL\u6587\u4ef6 - Wayne&#039;s Blog","og_description":"#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;conio.h&gt; #include &lt;string.h&gt; #include &lt;windows.h&gt; #include &lt;tlhelp32.h&gt;bool Privilege() { &nbsp;&nbsp;&nbsp;...","og_url":"http:\/\/weizn.net\/?p=42","og_site_name":"Wayne&#039;s Blog","article_published_time":"2013-10-03T14:31:46+00:00","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"zinan","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"http:\/\/weizn.net\/#website","url":"http:\/\/weizn.net\/","name":"Wayne&#039;s Blog","description":"","publisher":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/weizn.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"http:\/\/weizn.net\/?p=42#webpage","url":"http:\/\/weizn.net\/?p=42","name":"\u5378\u8f7d\u8fdb\u7a0bDLL\u6587\u4ef6 - Wayne&#039;s Blog","isPartOf":{"@id":"http:\/\/weizn.net\/#website"},"datePublished":"2013-10-03T14:31:46+00:00","dateModified":"2013-10-03T14:31:46+00:00","breadcrumb":{"@id":"http:\/\/weizn.net\/?p=42#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/weizn.net\/?p=42"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/weizn.net\/?p=42#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/weizn.net\/"},{"@type":"ListItem","position":2,"name":"\u5378\u8f7d\u8fdb\u7a0bDLL\u6587\u4ef6"}]},{"@type":"Article","@id":"http:\/\/weizn.net\/?p=42#article","isPartOf":{"@id":"http:\/\/weizn.net\/?p=42#webpage"},"author":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"headline":"\u5378\u8f7d\u8fdb\u7a0bDLL\u6587\u4ef6","datePublished":"2013-10-03T14:31:46+00:00","dateModified":"2013-10-03T14:31:46+00:00","mainEntityOfPage":{"@id":"http:\/\/weizn.net\/?p=42#webpage"},"wordCount":581,"commentCount":0,"publisher":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"articleSection":["C\/C++"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/weizn.net\/?p=42#respond"]}]},{"@type":["Person","Organization"],"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264","name":"zinan","logo":{"@id":"http:\/\/weizn.net\/#personlogo"}}]}},"_links":{"self":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=42"}],"version-history":[{"count":0,"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts\/42\/revisions"}],"wp:attachment":[{"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}