{"id":292,"date":"2021-09-26T10:33:49","date_gmt":"2021-09-26T02:33:49","guid":{"rendered":"http:\/\/pareto.fun\/?p=292"},"modified":"2021-09-26T10:33:49","modified_gmt":"2021-09-26T02:33:49","slug":"elf-%e5%86%85%e5%ad%98dump%e4%bf%ae%e5%a4%8d-sofix%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"http:\/\/pareto.fun\/?p=292","title":{"rendered":"ELF \u5185\u5b58dump\u4fee\u590d\u2014\u2014sofix\u5206\u6790"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. \u91cd\u5efaphdr<\/h2>\n\n\n\n<p>\u7531\u4e8e\u4ece\u5185\u5b58\u4e2ddump\uff0c\u5c06\u6587\u4ef6\u504f\u79fb\u548c\u5927\u5c0f \u8986\u5199\u4e3a \u5185\u5b58\u5927\u5c0f\u548c\u504f\u79fb\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u83b7\u53d6Dynamic load<\/h2>\n\n\n\n<p>\u725b\u7684 \uff0c \u4eceprogram header \u4e2d\u83b7\u53d6\u627e\u5230PT_DYNAMIC \u3002\u5c06dynamic \u4f5c\u4e3a\u6784\u5efasection header \u7684\u5173\u952e\u4fe1\u606f\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u91cd\u5efasection header<\/h2>\n\n\n\n<p>\u6211\u4eec\u77e5\u9053dynamic \u8bb0\u5f55\u4e2d\u6709\u5f88\u591a\u4fe1\u606f\uff0c\u5982\u56fe<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"482\" height=\"472\" src=\"http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210922113236445.png\" alt=\"\" class=\"wp-image-293\" srcset=\"http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210922113236445.png 482w, http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210922113236445-300x294.png 300w\" sizes=\"(max-width: 482px) 100vw, 482px\" \/><\/figure>\n\n\n\n<p>\u8fd9\u5176\u5b9e\u548csection entry \u5f88\u591a\u4fe1\u606f\u6709\u5f88\u591a\u91cd\u5408\u90e8\u5206\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"478\" height=\"1024\" src=\"http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210922114239284-478x1024.png\" alt=\"\" class=\"wp-image-294\" srcset=\"http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210922114239284-478x1024.png 478w, http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210922114239284-140x300.png 140w, http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210922114239284.png 564w\" sizes=\"(max-width: 478px) 100vw, 478px\" \/><\/figure>\n\n\n\n<p>\u4ec5\u5c06dynamic \u5b58\u5728\u7684\u8bb0\u5f55\u8fd8\u539f\u5230section header\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"658\" height=\"641\" src=\"http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210922114933301.png\" alt=\"\" class=\"wp-image-295\" srcset=\"http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210922114933301.png 658w, http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210922114933301-300x292.png 300w\" sizes=\"(max-width: 658px) 100vw, 658px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u91cd\u5efa\u91cd\u5b9a\u4f4d<\/h2>\n\n\n\n<p>\u539f\u672c\u4ee5\u4e3asofix \u8fd9\u4e2a\u9879\u76ee\u4e0d\u7528\u4f20\u57fa\u5740\uff0c\u662f\u6709\u7279\u6b8a\u65b9\u6cd5\u7b97\u51fa\u6765\u3002\u7ed3\u679c\u662f\u4e0d\u4f20\u504f\u79fb\u90a3\u4e48\u5c31\u4e0d\u505a\u91cd\u5b9a\u4f4d\u8868\u7684\u4fee\u590d\u3002<\/p>\n\n\n\n<p>\u5185\u90e8\u6a21\u5757\u7684\u91cd\u5b9a\u4f4d \uff1a *\u76ee\u6807\u5730\u5740 = *\u76ee\u6807\u5730\u5740 &#8211; base<\/p>\n\n\n\n<p>\u5916\u90e8\u6a21\u5757\u7684\u91cd\u5b9a\u4f4d\uff1a \u8bb2\u9053\u7406\u6ca1\u6709\u770b\u61c2 \uff0c \u5b9e\u9645\u4e0a\u53ef\u80fd\u4e0d\u9700\u8981\u505a\u4fee\u590d\u3002*\u76ee\u6807\u5730\u5740 = syminfo.st_value ? \u8fd9\u4e2a\u503c\u7684\u4f5c\u7528\uff0c\u8fd9\u4e2a\u4ecb\u7ecd\u8bf4\u53ef\u80fd\u662f\u4e00\u4e2a\u5730\u5740\u4e5f\u53ef\u80fd\u662f\u4e00\u4e2a\u504f\u79fb\u3002\u3002\u3002\uff0c\u3002\u3002\u3002\u55ef\u3002\u3002\u6ca1\u6709\u8bf4\u51fa\u5177\u4f53\u4ec0\u4e48\u60c5\u51b5\u662f\u504f\u79fb,\u4ec0\u4e48\u65f6\u5019\u662f\u4e2a\u5730\u5740\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>template &lt;bool isRela>\nvoid ElfRebuilder::relocate(uint8_t * base, Elf_Rel* rel, Elf_Addr dump_base) {\n    if(rel == nullptr) return ;\n#ifndef __SO64__\n    auto type = ELF32_R_TYPE(rel->r_info);\n    auto sym = ELF32_R_SYM(rel->r_info);\n#else\n    auto type = ELF64_R_TYPE(rel->r_info);\n    auto sym = ELF64_R_SYM(rel->r_info);\n#endif\n    auto prel = reinterpret_cast&lt;Elf_Addr *>(base + rel->r_offset);\n    switch (type) {\n        \/\/ I don't known other so info, if i want to fix it, I must dump other so file\n        case R_386_RELATIVE:\n        case R_ARM_RELATIVE:\n            *prel = *prel - dump_base;\n            break;\n        case 0x402:{\n            auto syminfo = si.symtab&#91;sym];\n            if (syminfo.st_value != 0) {\n                *prel = syminfo.st_value;\n            } else {\n                auto load_size = si.max_load - si.min_load;\n                *prel = load_size + external_pointer;\n                external_pointer += sizeof(*prel);\n            }\n            break;\n        }\n        default:\n            break;\n    }\n    if (isRela){\n        Elf_Rela* rela = (Elf_Rela*)rel;\n        switch (type){\n            case 0x403:\n                *prel = rela->r_addend;\n                break;\n            default:\n                break;\n        }\n    }\n};<\/code><\/pre>\n\n\n\n<p>\u62ff\u4e86\u4e00\u4e2a\u6709\u503c\u6570\u636e\u6765\u770b\uff0c\u8fd9\u91cc\u8fd9\u4e2a\u6570\u636e\u662f\u4e2a\u504f\u79fb<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"876\" height=\"254\" src=\"http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210923112151962.png\" alt=\"\" class=\"wp-image-296\" srcset=\"http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210923112151962.png 876w, http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210923112151962-300x87.png 300w, http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210923112151962-768x223.png 768w\" sizes=\"(max-width: 876px) 100vw, 876px\" \/><\/figure>\n\n\n\n<p>\u4ece\u5185\u5b58\u4e2d\u5c06\u8fd9\u4e2a\u504f\u79fb\u7684\u503c\u6253\u5370\u51fa\u6765\u3002\u6307\u5411\u4e86libc++\u7684\u5730\u5740\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"442\" height=\"259\" src=\"http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210923112239764.png\" alt=\"\" class=\"wp-image-297\" srcset=\"http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210923112239764.png 442w, http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210923112239764-300x176.png 300w\" sizes=\"(max-width: 442px) 100vw, 442px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"873\" height=\"127\" src=\"http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210923113212143.png\" alt=\"\" class=\"wp-image-298\" srcset=\"http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210923113212143.png 873w, http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210923113212143-300x44.png 300w, http:\/\/pareto.fun\/wp-content\/uploads\/2021\/09\/image-20210923113212143-768x112.png 768w\" sizes=\"(max-width: 873px) 100vw, 873px\" \/><\/figure>\n\n\n\n<p>\u8fd9\u91cc \u7c7b\u578b\u4e3a403 404 \uff0c\u4eceelf\u6587\u4ef6\u7c7b\u578b\u4e2d\u786e\u5b9e\u6ca1\u6709\u627e\u5230\uff0c\u76f2\u731c\u662f\u5916\u90e8\u6a21\u5757\u7684\u7b26\u53f7\uff0c\u5373\u5bfc\u5165\u7684\u7b26\u53f7\uff0c\u4e0d\u8fc7\u8fd9\u79cd\u5728elf\u6587\u4ef6\u91cd\u5b9a\u4f4d\u9636\u6bb5 \uff0c \u76ee\u6807\u5730\u5740\u4f1a\u88ab\u91cd\u5199\u6709\u9700\u8981\u91cd\u5199\u5417\uff1f<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u6d4b\u8bd5\u4e0b\u8be5\u5de5\u5177\u4fee\u590d\u540e\u7684ELF\u6587\u4ef6\uff0c\u8dd1\u4e0d\u8d77\u6765\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u91cd\u5efaphdr \u7531\u4e8e\u4ece\u5185\u5b58\u4e2ddump\uff0c\u5c06\u6587\u4ef6\u504f\u79fb\u548c\u5927\u5c0f \u8986\u5199\u4e3a \u5185\u5b58\u5927\u5c0f\u548c\u504f\u79fb\u3002 2. \u83b7\u53d6Dy [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[19],"tags":[],"_links":{"self":[{"href":"http:\/\/pareto.fun\/index.php?rest_route=\/wp\/v2\/posts\/292"}],"collection":[{"href":"http:\/\/pareto.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pareto.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pareto.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/pareto.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=292"}],"version-history":[{"count":1,"href":"http:\/\/pareto.fun\/index.php?rest_route=\/wp\/v2\/posts\/292\/revisions"}],"predecessor-version":[{"id":299,"href":"http:\/\/pareto.fun\/index.php?rest_route=\/wp\/v2\/posts\/292\/revisions\/299"}],"wp:attachment":[{"href":"http:\/\/pareto.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pareto.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=292"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pareto.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}