{"id":223,"date":"2013-02-11T20:30:44","date_gmt":"2013-02-11T12:30:44","guid":{"rendered":"http:\/\/blog.sorayuki.net\/?p=223"},"modified":"2013-09-26T15:10:53","modified_gmt":"2013-09-26T07:10:53","slug":"%e7%94%a8c%e8%af%ad%e8%a8%80%e5%86%99%e8%a2%ab%e5%af%bc%e5%85%a5exe%e7%9a%84%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/blog.sorayuki.net\/?p=223","title":{"rendered":"\u7528C\u8bed\u8a00\u5199\u88ab\u5bfc\u5165EXE\u7684\u4ee3\u7801\u7247\u6bb5"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>\u7528\u8fc7CFF Explorer\u4e4b\u540e\uff0c\u53d1\u73b0\u5b83\u53ef\u4ee5\u7ed9EXE\u6dfb\u52a0Seciton\uff0c\u751a\u81f3\u8fd8\u53ef\u4ee5\u76f4\u63a5\u5bfc\u5165\u4e00\u4e2a\u6587\u4ef6\u4f5c\u4e3aEXE\u4e2d\u4e00\u4e2aSection\uff0c\u529f\u80fd\u597d\u8d5e\u3002\u914d\u5408OllyDBG\u6765\u5bf9\u73b0\u6709\u8f6f\u4ef6\u7684EXE\u505a\u4e00\u4e9b\u5c0f\u5c0f\u7684hack\u611f\u89c9\u6548\u679c\u5f88\u597d\u3002<\/p>\n<p>\u6700\u65e9\u7684\u65f6\u5019\u6211\u662f\u76f4\u63a5\u7528OllyDBG\u6253\u5f00EXE\uff0c\u7136\u540e\u627e\u5230\u4e00\u7247\u90fd\u662f0\u7684\u5730\u65b9\u6765\u6c47\u7f16\u4ee3\u7801\u8fdb\u53bb\u3002\u4f46\u662f\u8fd9\u6837\u53d7\u5230\u7684\u9650\u5236\u5f88\u591a\uff0c\u6700\u76f4\u63a5\u7684\u5c31\u6bd4\u5982\u6709\u7684\u65f6\u5019\u627e\u4e0d\u5230\u4e00\u58060\u7684\u5730\u65b9\uff0c\u627e\u5230\u4e5f\u4e0d\u786e\u5b9a\u80fd\u4e0d\u80fd\u5199\uff1a\u6709\u53ef\u80fd\u8fd9\u4e9b\u90e8\u5206\u5176\u4ed6\u5730\u65b9\u8981\u7528\uff0c\u53c8\u6216\u8005\u6c47\u7f16\u4e86\u4ee3\u7801\u8fdb\u53bb\u8981\u4fdd\u5b58\u7684\u65f6\u5019OllyDBG\u8bf4\u5b58\u4e0d\u4e86\u3002\u73b0\u5728\u53ef\u4ee5\u76f4\u63a5\u81ea\u5df1\u6dfb\u52a0\u4e00\u4e2aSection\uff0c\u4e0d\u4f1a\u51fa\u73b0\u627e\u4e0d\u5230\u7a7a\u95f4\u7684\u60c5\u51b5\u4e86\u3002<\/p>\n<p>\u65e2\u7136\u53ef\u4ee5\u5bfc\u5165\u6587\u4ef6\uff0c\u90a3\u6bd4\u8d77\u76f4\u63a5\u5728OllyDBG\u91cc\u9762\u6572\u6c47\u7f16\uff0c\u7528Nasm\u6765\u5199\u6c47\u7f16\u4ee3\u7801\u8981\u65b9\u4fbf\u5f97\u5f88\u591a\u3002\u5728\u6d4b\u8bd5\u5bfc\u5165Nasm\u5199\u7684\u6c47\u7f16\u4ee5\u540e\uff0c\u6211\u5c31\u5728\u6349\u6478\u7740\u66f4\u52a0\u65b9\u4fbf\u7684\u4e8b\u60c5\uff1a\u7528C\u8bed\u8a00\u6765\u5199\u3002<\/p>\n<p>\u6211\u9009\u7528\u7684\u662fOpenWatcom C\u7f16\u8bd1\u5668\uff0c\u6ca1\u4ec0\u4e48\u592a\u591a\u7406\u7531\uff0c\u6b63\u597d\u6293\u5230\u5b83\u800c\u5df2\u3002\u5b83\u53cd\u6b63\u4e5f\u53ef\u4ee5\u751f\u6210Raw\u4e8c\u8fdb\u5236\u683c\u5f0f\u7684\u6587\u4ef6\u3002<\/p>\n<p>\u7814\u7a76\u4e86\u4e00\u4e0b\u5b83\u7684\u94fe\u63a5\u5668\uff0c\u6700\u7ec8\u7684\u7ed3\u679c\u662f\u7528\u8fd9\u6837\u7684\u53c2\u6570\uff1a<\/p>\n<p>OPTION OFFSET=xxxxxx FORMAT RAW BIN<\/p>\n<p>\u6216\u8005<\/p>\n<p>OUTPUT RAW OFFSET=xxxxxx<\/p>\n<p>\u4e00\u8d77\u7528\u5c31\u4f1a\u51fa\u4e00\u4e9b\u5947\u602a\u7684\u7ed3\u679c\u3002\u8bf4\u660e\u6587\u6863\u975e\u5e38\u957f\uff0c\u4e0d\u77e5\u9053\u662f\u4e0d\u662f\u54ea\u91cc\u6f0f\u6389\u4e86\u4ec0\u4e48\u6ca1\u770b\u5230\u7684\u90e8\u5206\u2026\u2026<\/p>\n<p>\u4e00\u8d77\u7528\u7684\u65f6\u5019\u6709\u7684\u65f6\u5019\u5c31\u51fa\u73b0\u6700\u524d\u976216\u4e2a\u5b57\u8282\u5168\u90e8\u662f0\uff0c\u7136\u540e\u540e\u9762\u7684\u4ee3\u7801\u5168\u90e8\u9519\u4f4d\uff0c\u5927\u6c57\u2026\u2026<\/p>\n<p><!--more--><\/p>\n<p>\u6bd4\u5982gimp 2.8\u7684\u8865\u4e01\uff0c\u5b9e\u9645\u4e0a\u5c31\u662f\u8c03\u7528\u4e00\u4e0bmsvcrt.dll\u91cc\u9762\u7684_putenv\uff0c\u7ed9\u4e00\u4e2aLANG=en\u5c31\u5b8c\u4e8b\u4e86\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>\r\n\r\nvoid __stdcall gimppatch(int param);\r\n\r\nvoid callgp()\r\n{\r\n    gimppatch(1);\r\n}\r\n\r\nextern \"C\" void* (__stdcall **fGetModuleHandleA)(const char*);\r\nextern \"C\" void* (__stdcall **fGetProcAddress)(void*, const char*);\r\n\r\nvoid __stdcall gimppatch(int param)\r\n{\r\n    int* p = &amp;param;\r\n    p--;\r\n    *p = 0x4014b0;\r\n\r\n    void* msvcrt = fGetModuleHandleA(\"msvcrt.dll\");\r\n    int (__cdecl *putenv)(const char*) = (int (__cdecl*)(const char*)) fGetProcAddress(msvcrt, \"_putenv\");\r\n    putenv(\"LANG=en\");\r\n}<\/pre>\n<p>\u51fd\u6570\u6307\u9488\u7684\u89e3\u91ca\uff1a\u56e0\u4e3a\u51fd\u6570\u5730\u5740\u5728\u5bfc\u5165\u8868\u4e2d\uff0c\u4e8e\u662f\u5bfc\u5165\u8868\u5bf9\u5e94\u4f4d\u7f6e\u91cc\u4fdd\u5b58\u7684\u4e8b\u5b9e\u4e0a\u5c31\u662f\u4e00\u4e2a\u51fd\u6570\u6307\u9488\uff0c\u7136\u540e\u5bfc\u5165\u8868\u5bf9\u5e94\u4f4d\u7f6e\u7684\u5730\u5740\uff08 fGetProcAddress \u7684\u503c\uff09\u5c31\u662f\u6307\u5411\u51fd\u6570\u6307\u9488\u7684\u6307\u9488\u3002<\/p>\n<p>\u7136\u540e\u8981\u94fe\u63a5\u561b\uff0c\u94fe\u63a5\u7684\u65f6\u5019\u90a3\u4e9b\u7b26\u53f7\u7531\u53e6\u4e00\u4e2a\u6587\u4ef6\u63d0\u4f9b\uff1a<\/p>\n<pre>section .text\r\n    global _fGetModuleHandleA\r\n    global _fGetProcAddress\r\n\r\nsection .code\r\n_fGetModuleHandleA:\r\n    dd 0x960b54\r\n\r\n_fGetProcAddress:\r\n    dd 0x960b58<\/pre>\n<p>\u4e8e\u662f\u7f16\u8bd1\u94fe\u63a5\uff1a<\/p>\n<p>wpp386 -s gimpPatch.cpp<\/p>\n<p>\u5176\u4e2d -s \u662f\u9632\u6b62\u5b83\u68c0\u67e5\u5806\u6808\u6ea2\u51fa\u5565\u7684\uff0c\u56e0\u4e3a\u4f1a\u5bfc\u81f4\u4e00\u4e2aCHK\u94fe\u63a5\u4e0d\u4e0a<\/p>\n<p>\u7136\u540e\u53e6\u4e00\u8fb9\u5c31\u76f4\u63a5<\/p>\n<p>nasm -f win32 gimpImp.asm<\/p>\n<p>\u94fe\u63a5\u5373\u53ef\uff1a<\/p>\n<p>wlink f gimpPatch.obj f gimpImp.obj form raw bin\u00a0 op off=0x98a000 name gimpPatch.bin<\/p>\n<p>\u5176\u4e2d98a000\u662f\u770b\u4e86gimp-2.8.exe\u7684section\uff0c\u628a\u6700\u540e\u4e00\u4e2asection\u7684\u8d77\u59cb\u5730\u5740\u52a0\u4e0a\u5927\u5c0f\u5f97\u5230\u8981\u589e\u52a0\u7684\u65b0section\u7684\u8d77\u59cb\u5730\u5740\uff1a0x589000 + 0x200 = 0x589200\uff0c\u7136\u540e\u65b0section\u8981\u5bf9\u9f50\u52304k\u8fb9\u754c\uff0c\u5c31\u53d8\u62100x58a000\u4e86\u3002\u7136\u540e\u52a0\u4e0a\u52a0\u8f7d\u7684\u57fa\u57400x400000\u5f97\u52300x98a000\u3002\uff08\u8bdd\u8bf4\u6211\u53d1\u73b0\uff0c\u8fd9\u53c2\u6570\u597d\u50cf\u8fd8\u6709\u987a\u5e8f\u95ee\u9898\u7684\u6837\u5b50\u2026\u2026\uff09<\/p>\n<p>\u7528CFF Explorer\u5bfc\u5165\u4ee5\u540e\uff0c\u627e\u5230\u4e4b\u524dC\u8bed\u8a00callgp\u51fd\u6570\uff0c\u5c31\u7559\u4e0bpush 1\u548ccall\uff0c\u524d\u9762\u7684\u5168\u90e8nop\u6389\u3002\u4e4b\u6240\u4ee5\u8981\u5f04\u4e00\u4e2acallgp\u51fd\u6570\uff0c\u662f\u4e3a\u4e86gimppatch\u6267\u884c\u5b8c\u6bd5\u4e4b\u540e\u80fd\u591f\u6b63\u786e\u8df3\u56deexe\u5165\u53e3\uff0c\u4e8e\u662f\u628agimppatch\u7684\u8fd4\u56de\u5730\u5740\u7ed9\u6539\u6210gimp\u7684\u539f\u5165\u53e3\u5904\u3002\u4e4b\u540e\u6539\u4e00\u4e0bEXE\u7684\u5165\u53e3\uff0c\u5230callgp\u51fd\u6570\u6240\u5728\u4f4d\u7f6e\uff0c\u4fee\u6539\u5c31\u7ed3\u675f\u4e86\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u8ffd\u8bb0\uff1a<\/p>\n<p>1\u3001wlink\u7684\u53c2\u6570\u4f3c\u4e4e\u662f\u6709\u987a\u5e8f\u7684\uff0c\u6ce8\u610f\u90a3\u4e2awarning\uff0c\u53ef\u4ee5\u77e5\u9053offset\u53c2\u6570\u5230\u5e95\u6709\u6ca1\u6709\u6b63\u5e38<\/p>\n<p>2\u3001\u6587\u7ae0\u4e2d\u63d0\u5230\u7684\u65b9\u6cd5\uff0c\u8c03\u7528\u53c2\u6570\u7684\u65f6\u5019\u90fd\u662f\u7528\u7684\u51fd\u6570\u6307\u9488\uff0c\u5f88\u86cb\u75bc\u3002\u5982\u679c\u60f3\u76f4\u63a5#incude &lt;windows.h&gt;\u7684\u8bdd\uff0c\u90a3\u4e2aasm\u6587\u4ef6\u8981\u7a0d\u5fae\u6539\u4e00\u6539\u3002\u6bd4\u5982\u8fd9\u4e2a<\/p>\n<pre>section .text\r\n    global __imp__WriteConsoleW@20\r\n    global __imp__HeapFree@12\r\n    global __imp__MultiByteToWideChar@24\r\n    global __imp__HeapAlloc@12\r\n    global __imp__GetProcessHeap@0\r\n    global __imp__VirtualProtect@16\r\n    global __imp__GetProcAddress@8\r\n    global __imp__GetModuleHandleW@4\r\n    global __imp__RtlMoveMemory@12\r\n \r\nsection .data\r\n    __imp__WriteConsoleW@20 equ 0x60a143\r\n    __imp__HeapFree@12 equ 0x60a14b\r\n    __imp__MultiByteToWideChar@24 equ 0x60a163\r\n    __imp__HeapAlloc@12 equ 0x60a147\r\n    __imp__GetProcessHeap@0 equ 0x60a14f\r\n    __imp__VirtualProtect@16 equ 0x60a157\r\n    __imp__GetProcAddress@8 equ 0x60a153\r\n    __imp__GetModuleHandleW@4 equ 0x60b0d4\r\n    __imp__RtlMoveMemory@12 equ 0x60a15b<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u7528\u8fc7CFF Explorer\u4e4b\u540e\uff0c\u53d1\u73b0\u5b83\u53ef\u4ee5\u7ed9EXE\u6dfb\u52a0Seciton\uff0c\u751a\u81f3\u8fd8\u53ef\u4ee5\u76f4\u63a5\u5bfc\u5165\u4e00\u4e2a\u6587 &hellip; <a href=\"https:\/\/blog.sorayuki.net\/?p=223\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u7528C\u8bed\u8a00\u5199\u88ab\u5bfc\u5165EXE\u7684\u4ee3\u7801\u7247\u6bb5<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-223","post","type-post","status-publish","format-standard","hentry","category-windows"],"_links":{"self":[{"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=\/wp\/v2\/posts\/223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=223"}],"version-history":[{"count":0,"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=\/wp\/v2\/posts\/223\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}