{"id":199090,"date":"2013-10-26T02:06:04","date_gmt":"2013-10-25T22:06:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=199090"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=199090","title":{"rendered":"<span class=\"post_title\">\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 LD_PRELOAD \u0438\u043b\u0438 \u0437\u0430\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 Linux<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<br \/>  \u0412 2010 \u0433\u043e\u0434\u0443, <a href=\"http:\/\/habrahabr.ru\/users\/shoumikhin\/\" class=\"user_link\">shoumikhin<\/a> \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"http:\/\/habrahabr.ru\/post\/106107\/\">\u041f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0445 ELF-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445<\/a>. \u0422\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u0447\u0435\u043d\u044c \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430, \u043f\u043e\u043b\u043d\u0430\u044f, \u043d\u043e \u043e\u043d\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0445\u0430\u0440\u043a\u043e\u0440\u0434\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043b\u0438\u043d\u043a\u0435\u0440\u0430 \u2014 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f LD_PRELOAD, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432\u0430\u0448\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445.<\/p>\n<h5>\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/h5>\n<p>  \u0414\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u043b\u0438\u043d\u043a\u0435\u0440 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0432\u0430\u0448\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0441 \u0432\u0430\u0448\u0438\u043c\u0438 \u00ab\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c\u0438\u00bb \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043f\u0435\u0440\u0432\u043e\u0439, \u0430 \u043a\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u2014 \u0442\u043e\u0433\u043e \u0438 \u0442\u0430\u043f\u043a\u0438. \u0410 \u0432\u044b \u0438\u0437 \u0441\u0432\u043e\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u0443\u044e, \u0438 \u00ab\u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u00bb \u0432\u044b\u0437\u043e\u0432\u044b, \u043f\u043e\u043f\u0443\u0442\u043d\u043e \u0434\u0435\u043b\u0430\u044f \u0447\u0442\u043e \u0432\u0430\u043c \u0443\u0433\u043e\u0434\u043d\u043e.<\/p>\n<h4>\u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0439 Use-Case #1: \u0411\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c mimeinfo.cache \u0432 Opera<\/h4>\n<p>  \u041c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440 Opera. \u0410 \u0435\u0449\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e KDE. Opera \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0432\u0430\u0436\u0430\u0435\u0442 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 KDE, \u0438, \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e, \u0442\u0430\u043a \u0438 \u043d\u043e\u0440\u043e\u0432\u0438\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0441\u043a\u0430\u0447\u0430\u043d\u043d\u044b\u0439 ZIP-\u0430\u0440\u0445\u0438\u0432 \u0432 mcomix, PDF \u0432 imgur-uploader, \u0432 \u043e\u0431\u0449\u0435\u043c, \u0432\u044b \u0443\u043b\u043e\u0432\u0438\u043b\u0438 \u0441\u0443\u0442\u044c. \u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0435\u0439 \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u044c \u0444\u0430\u0439\u043b mimeinfo.cache, \u0442\u043e \u043e\u043d\u0430 \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u00abkioclient exec\u00bb, \u0430 \u043e\u043d-\u0442\u043e \u0443\u0436 \u043b\u0443\u0447\u0448\u0435 \u0437\u043d\u0430\u0435\u0442, \u0432 \u0447\u0435\u043c \u044f \u0445\u043e\u0447\u0443 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0444\u0430\u0439\u043b.<\/p>\n<p>  \u0427\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b? \u041d\u0430 \u0443\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: <b>fopen<\/b> \u0438 <b>open<\/b>. \u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, opera \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430 64-\u0431\u0438\u0442\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u043e\u0433 fopen \u2014 <b>fopen64<\/b>. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0443\u0442\u0438\u043b\u0438\u0442\u043e\u0439 ltrace, \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0443\u0442\u0438\u043b\u0438\u0442\u043e\u0439 objdump.<a name=\"habracut\"><\/a><\/p>\n<p>  \u0427\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438? \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c, \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<br \/>  \u0421\u0443\u0434\u044f \u043f\u043e <b>man fopen<\/b>, \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f \u0443 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439:  <\/p>\n<pre><code>FILE *fopen(const char *path, const char *mode)<\/code><\/pre>\n<p>\u0418 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u043d\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 FILE, \u043b\u0438\u0431\u043e NULL, \u0435\u0441\u043b\u0438 \u0444\u0430\u0439\u043b \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044c. \u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434:  <\/p>\n<pre><code>#define _GNU_SOURCE #include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;dlfcn.h&gt;  static FILE* (*fopen64_orig)(const char * path, const char * mode) = NULL;  FILE* fopen64(const char * path, const char * mode) {     if (fopen64_orig == NULL)         fopen64_orig = dlsym(RTLD_NEXT, &quot;fopen64&quot;);     if (strstr(path, &quot;mimeinfo.cache&quot;) != NULL) {         printf(&quot;Blocking mimeinfo.cache read\\n&quot;);         return NULL;     }     return fopen64_orig(path, mode); }<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e: \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e fopen64, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u00ab\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e\u00bb (\u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0443\u044e), \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u043d\u0430\u0448\u0435\u0439, \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043d\u0435 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043b\u0438 \u043c\u044b \u0444\u0430\u0439\u043b \u00abmimeinfo.cache\u00bb. \u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:  <\/p>\n<pre><code>gcc -shared -fPIC -ldl -O2 -o opera-block-mime.so opera-block-mime.c<\/code><\/pre>\n<p>  \u0418 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c opera:  <\/p>\n<pre><code>LD_PRELOAD=.\/opera-block-mime.so opera<\/code><\/pre>\n<p>\u0418 \u0432\u0438\u0434\u0438\u043c:<\/p>\n<pre><code>Blocking mimeinfo.cache read Blocking mimeinfo.cache read Blocking mimeinfo.cache read Blocking mimeinfo.cache read<\/code><\/pre>\n<p>  \u0423\u0441\u043f\u0435\u0445!<\/p>\n<h4>\u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0439 Use-Case #2: \u041f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0432 \u0441\u043e\u043a\u0435\u0442<\/h4>\n<p>  \u0415\u0441\u0442\u044c \u0443 \u043c\u0435\u043d\u044f \u043f\u0440\u043e\u043f\u0440\u0438\u0435\u0442\u0430\u0440\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0440\u044f\u043c\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0440\u0438\u043d\u0442\u0435\u0440\u0443 (\u0444\u0430\u0439\u043b \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \/dev\/usb\/lp0). \u0417\u0430\u0445\u043e\u0442\u0435\u043b \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0441\u0432\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432 \u0446\u0435\u043b\u044f\u0445 \u043e\u0442\u043b\u0430\u0434\u043a\u0438. \u0427\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 open()? \u0424\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440. \u0427\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 socket()? \u0422\u0430\u043a\u043e\u0439 \u0436\u0435 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 read() \u0438 write(). \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c:  <\/p>\n<pre><code>#define _GNU_SOURCE #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;dlfcn.h&gt; #include &lt;strings.h&gt; #include &lt;sys\/socket.h&gt; #include &lt;netinet\/in.h&gt;  static int (*orig_open)(char * filename, int flags) = NULL;  int open(char * filename, int flags) {     if (orig_open == NULL)         orig_open = dlsym(RTLD_NEXT, &quot;open&quot;);      if (strcmp(filename, &quot;\/dev\/usb\/lp0&quot;) == 0) {         \/\/opening tcp socket         struct sockaddr_in servaddr, cliaddr;         int socketfd = socket(AF_INET, SOCK_STREAM, 0);          bzero(&servaddr,sizeof(servaddr));         servaddr.sin_family = AF_INET;         servaddr.sin_addr.s_addr=inet_addr(&quot;127.0.0.1&quot;); \/\/ addr         servaddr.sin_port=htons(32000); \/\/ port         if (connect(socketfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == 0)             printf(&quot;[Open] TCP Connected\\n&quot;);         else             printf(&quot;[Open] TCP Connection failed!\\n&quot;);         return socketfd;     }     return orig_open(filename, flags); }<\/code><\/pre>\n<h4>\u041d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 Use-Case #3: \u041f\u0435\u0440\u0435\u0445\u0432\u0430\u0442 C++-\u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/h4>\n<p>  \u0421 C++ \u0432\u0441\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0430\u0447\u0435. \u0421\u043a\u0430\u0436\u0435\u043c, \u0435\u0441\u0442\u044c \u0443 \u043d\u0430\u0441 \u043a\u043b\u0430\u0441\u0441:  <\/p>\n<pre><code>class Testclass {     int var = 0; public:     int setvar(int val);     int getvar(); }; <\/code><\/pre>\n<p>  <\/p>\n<pre><code>#include &lt;stdio.h&gt; #include &quot;class.h&quot;  void Testclass() {     int var = 0; }  int Testclass::setvar(int val) {     printf(&quot;setvar!\\n&quot;);     this-&gt;var = val;     return 0; }  int Testclass::getvar() {     printf(&quot;getvar! %d\\n&quot;, this-&gt;var);     return this-&gt;var; }<\/code><\/pre>\n<p>  \u041d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u00abTestclass::getvar\u00bb \u0438 \u00abTestclass::setvar\u00bb \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u043c \u0444\u0430\u0439\u043b\u0435. \u0427\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430:  <\/p>\n<pre><code>nm -D libclass.so \u2026 0000000000000770 T _Z9Testclassv 00000000000007b0 T _ZN9Testclass6getvarEv 0000000000000780 T _ZN9Testclass6setvarEi<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f name mangling.<br \/>  \u0422\u0443\u0442 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u044b\u0445\u043e\u0434\u0430: \u043b\u0438\u0431\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443-\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043a \u043d\u0430 C++, \u043e\u043f\u0438\u0441\u0430\u0432 \u043a\u043b\u0430\u0441\u0441 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a\u0438\u043c \u043e\u043d \u0431\u044b\u043b \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0435, \u043d\u043e, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0443 \u0432\u0430\u0441, \u0441 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e, \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0443 \u043a\u043b\u0430\u0441\u0441\u0430, \u043b\u0438\u0431\u043e \u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0430 C, \u043d\u0430\u0437\u0432\u0430\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0442\u0430\u043a, \u043a\u0430\u043a \u043e\u043d\u0430 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0432\u0430\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0441\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0438\u043d\u0441\u0442\u0430\u043d\u0441:  <\/p>\n<pre><code>#define _GNU_SOURCE #include &lt;stdio.h&gt; #include &lt;dlfcn.h&gt;   typedef int (*orig_getvar_type)(int instance);  int _ZN9Testclass6getvarEv(int instance) {     printf(&quot;Wrapped getvar! %d\\n&quot;, instance);     orig_getvar_type orig_getvar;     orig_getvar = (orig_getvar_type)dlsym(RTLD_NEXT, &quot;_ZN9Testclass6getvarEv&quot;);     printf(&quot;orig getvar %d\\n&quot;, orig_getvar(instance));     return 0;      }<\/code><\/pre>\n<p>  \u0412\u043e\u0442, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0438 \u0432\u0441\u0435, \u043e \u0447\u0435\u043c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/199090\/\"> http:\/\/habrahabr.ru\/post\/199090\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<br \/>  \u0412 2010 \u0433\u043e\u0434\u0443, <a href=\"http:\/\/habrahabr.ru\/users\/shoumikhin\/\" class=\"user_link\">shoumikhin<\/a> \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"http:\/\/habrahabr.ru\/post\/106107\/\">\u041f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0445 ELF-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445<\/a>. \u0422\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u0447\u0435\u043d\u044c \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430, \u043f\u043e\u043b\u043d\u0430\u044f, \u043d\u043e \u043e\u043d\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0445\u0430\u0440\u043a\u043e\u0440\u0434\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043b\u0438\u043d\u043a\u0435\u0440\u0430 \u2014 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f LD_PRELOAD, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432\u0430\u0448\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445.<\/p>\n<h5>\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/h5>\n<p>  \u0414\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u043b\u0438\u043d\u043a\u0435\u0440 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0432\u0430\u0448\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0441 \u0432\u0430\u0448\u0438\u043c\u0438 \u00ab\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c\u0438\u00bb \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043f\u0435\u0440\u0432\u043e\u0439, \u0430 \u043a\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u2014 \u0442\u043e\u0433\u043e \u0438 \u0442\u0430\u043f\u043a\u0438. \u0410 \u0432\u044b \u0438\u0437 \u0441\u0432\u043e\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u0443\u044e, \u0438 \u00ab\u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u00bb \u0432\u044b\u0437\u043e\u0432\u044b, \u043f\u043e\u043f\u0443\u0442\u043d\u043e \u0434\u0435\u043b\u0430\u044f \u0447\u0442\u043e \u0432\u0430\u043c \u0443\u0433\u043e\u0434\u043d\u043e.<\/p>\n<h4>\u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0439 Use-Case #1: \u0411\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c mimeinfo.cache \u0432 Opera<\/h4>\n<p>  \u041c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440 Opera. \u0410 \u0435\u0449\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e KDE. Opera \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0432\u0430\u0436\u0430\u0435\u0442 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 KDE, \u0438, \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e, \u0442\u0430\u043a \u0438 \u043d\u043e\u0440\u043e\u0432\u0438\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0441\u043a\u0430\u0447\u0430\u043d\u043d\u044b\u0439 ZIP-\u0430\u0440\u0445\u0438\u0432 \u0432 mcomix, PDF \u0432 imgur-uploader, \u0432 \u043e\u0431\u0449\u0435\u043c, \u0432\u044b \u0443\u043b\u043e\u0432\u0438\u043b\u0438 \u0441\u0443\u0442\u044c. \u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0435\u0439 \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u044c \u0444\u0430\u0439\u043b mimeinfo.cache, \u0442\u043e \u043e\u043d\u0430 \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u00abkioclient exec\u00bb, \u0430 \u043e\u043d-\u0442\u043e \u0443\u0436 \u043b\u0443\u0447\u0448\u0435 \u0437\u043d\u0430\u0435\u0442, \u0432 \u0447\u0435\u043c \u044f \u0445\u043e\u0447\u0443 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0444\u0430\u0439\u043b.<\/p>\n<p>  \u0427\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b? \u041d\u0430 \u0443\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: <b>fopen<\/b> \u0438 <b>open<\/b>. \u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, opera \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430 64-\u0431\u0438\u0442\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u043e\u0433 fopen \u2014 <b>fopen64<\/b>. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0443\u0442\u0438\u043b\u0438\u0442\u043e\u0439 ltrace, \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0443\u0442\u0438\u043b\u0438\u0442\u043e\u0439 objdump.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-199090","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/199090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=199090"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/199090\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=199090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=199090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=199090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}