{"id":417,"date":"2022-08-26T12:22:40","date_gmt":"2022-08-26T04:22:40","guid":{"rendered":"http:\/\/pareto.fun\/?p=417"},"modified":"2022-08-26T12:22:41","modified_gmt":"2022-08-26T04:22:41","slug":"patchelf-%e6%89%a7%e8%a1%8c%e6%b5%81%e7%a8%8b%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"http:\/\/pareto.fun\/?p=417","title":{"rendered":"patchELF \u6267\u884c\u6d41\u7a0b\u5206\u6790"},"content":{"rendered":"\n<p><a href=\"https:\/\/github.com\/NixOS\/patchelf\">https:\/\/github.com\/NixOS\/patchelf<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u52a8\u673a<\/h1>\n\n\n\n<p>\u589e\u52a0\u9879\u76ee\u7684\u7ef4\u62a4\u80fd\u529b\u3002<\/p>\n\n\n\n<p>\u5173\u6ce8\u70b9<\/p>\n\n\n\n<ol><li>\u65b0\u589esegment\u6d41\u7a0b \uff1b \u65b0\u589e\u5230\u6587\u4ef6\u672b\u5c3e\uff0c\u589e\u5927program header\u7684\u7a7a\u95f4\uff08\u53ef\u80fd\u4f1a\u4e0esection \u53d1\u751f\u5806\u53e0\uff09\uff0c\u5199\u5165\u8bb0\u5f55\u3002<\/li><li>dynamic \u62d3\u5c55\u7a7a\u95f4\u3001\u5e76\u79fb\u52a8\u6d41\u7a0b\uff1b\u539f\u59cb\u7684dynamic\u90fd\u4f1a\u88ab\u5220\u9664\uff0c\u88ab\u4fee\u6539\u7684section \u4f1a\u88ab\u8ffd\u52a0\u5230\u6587\u4ef6\u672b\u5c3e\uff0c\u4fee\u6539section header \u8bb0\u5f55\uff0c \u4fee\u6539.dynamic \u5185\u90e8\u6570\u636e<\/li><\/ol>\n\n\n\n<p>\u542f\u52a8\u53c2\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">patchelf --add-needed libjjrt.so  home\/pareto\/Desktop\/libil2cpp.so --output libil2cpp.so<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4ee3\u7801\u5206\u6790<\/h2>\n\n\n\n<p>mainWrapped \u51fd\u6570\u4e2d\u5904\u7406\u547d\u4ee4\u884c\u53c2\u6570\u9009\u9879 \u3002<\/p>\n\n\n\n<p>\u5c06\u9700\u8981\u6dfb\u52a0\u7684so\u4f9d\u8d56\u540d\u79f0\u5b58\u5165neededLibsToAdd<\/p>\n\n\n\n<p>\u76ee\u6807so \u540d\u79f0\u653e\u5165fileNames<\/p>\n\n\n\n<p>\u8c03\u7528patchElf2<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">patchElf2<\/h3>\n\n\n\n<ol><li>\u83b7\u53d6dynamic \u548c dynstr \u6bb5\u3002<\/li><li>\u521b\u5efa\u65b0\u7684dynstr \u548c \u65b0\u7684dynamic\uff0c\u5e76\u5199\u5165\u65b0\u7684\u6570\u636e\u3002<\/li><li>rewriteSection \uff0c\u5224\u65ad\u662f\u52a8\u6001\u5e93\uff0c<strong>rewriteSectionLibrary<\/strong> \uff0c<\/li><li>\u5199\u6587\u4ef6<\/li><\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">rewriteSectionLibrary<\/h4>\n\n\n\n<p>startPage \u65b0\u589eSegment \u7684\u8d77\u59cb\u5730\u5740<\/p>\n\n\n\n<ol><li>\u589e\u52a0program header table \u7684\u5927\u5c0f\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7b2c\u4e00\u4e2asection \u548cprogram header \u7684\u5185\u5b58\u5806\u53e0\uff0c\u9700\u8981\u79fb\u52a8\u524d\u51e0\u5757segments\u3002<ol><li>\u83b7\u53d6\u88ab\u5360\u7528\u7684section \uff0c\u540e\u7eed\u5c06\u5176\u5199\u5230\u6587\u4ef6\u5c3e\u90e8\u3002<\/li><li>\u83b7\u53d6\u6587\u4ef6\u9700\u8981\u65b0\u589e\u7684\u7a7a\u95f4 \uff0c\u5305\u542b\u65b0\u589e\u7684dynstr \u3001 dynamic \u548c section\u3002<\/li><li>\u521b\u5efa\u65b0\u7684program header\u3002<\/li><li>normalizeNoteSegments() ,\u8fd9\u4e2a\u64cd\u4f5c\u6709\u70b9\u795e\u5947\uff0c\u731c\u6d4b\u4e3a\u88ab\u5360\u7528section \u65b0\u5efaprogram header \uff0c\u5e76\u5199\u5165\u76f8\u5e94\u6570\u636e, <strong>\u540e\u7eed\u53ef\u4ee5\u7ec6\u770b<\/strong>\u3002<\/li><li>writeReplacedSections \uff0c \u5c06\u539fsection \u8986\u76d6\u4e3a&#8217;X&#8217; , \u4f9d\u6b21\u5c06\u65b0\u66fe\u7684section \u5199\u5165\u6587\u4ef6\uff0c\u5e76\u4fee\u6539\u76f8\u5e94\u7684section header entry \uff0c \u5982\u679csectionName == \u201c.dynamic\u201d , \u540c\u65f6\u4fee\u6539dynamic Segment\u3002<\/li><li>rewriteHeaders \uff0c \u4fee\u6539program table \u4e2dPT_PHDR segment \uff0c \u4fee\u6539program header\uff0c\u9700\u8981dynamic\u6bb5\u5185\u90e8\u5b57\u6bb5\u3002<\/li><\/ol><\/li><\/ol>\n\n\n\n<p>rdi \uff0c\u6539\u53d8\u76f8\u5e94\u7684\u6570\u636e\u7c7b\u578b\u7684\u7aef\u5e8f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">template&lt;ElfFileParams&gt;<br>template&lt;class I&gt;<br>I ElfFile&lt;ElfFileParamNames&gt;::rdi(I i) const<br>{<br> &nbsp;  I r = 0;<br> &nbsp;  if (littleEndian) {<br> &nbsp; &nbsp; &nbsp;  for (unsigned int n = 0; n &lt; sizeof(I); ++n) {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  r |= ((I) *(((unsigned char *) &amp;i) + n)) &lt;&lt; (n * 8);<br> &nbsp; &nbsp; &nbsp;  }<br> &nbsp;  } else {<br> &nbsp; &nbsp; &nbsp;  for (unsigned int n = 0; n &lt; sizeof(I); ++n) {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  r |= ((I) *(((unsigned char *) &amp;i) + n)) &lt;&lt; ((sizeof(I) - n - 1) * 8);<br> &nbsp; &nbsp; &nbsp;  }<br> &nbsp;  }<br> &nbsp;  return r;<br>}<br>\u200b<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/github.com\/NixOS\/patchelf \u52a8\u673a \u589e\u52a0\u9879\u76ee\u7684\u7ef4\u62a4\u80fd\u529b\u3002 \u5173\u6ce8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/pareto.fun\/index.php?rest_route=\/wp\/v2\/posts\/417"}],"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=417"}],"version-history":[{"count":2,"href":"http:\/\/pareto.fun\/index.php?rest_route=\/wp\/v2\/posts\/417\/revisions"}],"predecessor-version":[{"id":419,"href":"http:\/\/pareto.fun\/index.php?rest_route=\/wp\/v2\/posts\/417\/revisions\/419"}],"wp:attachment":[{"href":"http:\/\/pareto.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pareto.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=417"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pareto.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}