<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic PIN Instrumentation SMC(self modifying code) Support Broken in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/PIN-Instrumentation-SMC-self-modifying-code-Support-Broken/m-p/1132726#M77918</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;I have a piece of self-modifying code that PIN fails with, but dynamorio is able to show the correct behaviour.&amp;nbsp; This is the below self-modifying code -&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;//smc.c
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;windows.h&amp;gt;

void foo() {
    int var = -1;

    asm ("call bar\n\t"
         "bar: pop %%eax\n\t"
         "movl $0xcafebabe, 9(%%eax)\n\t"
         // this is an attempt to replace 0xffffffff                                                                                                                                   
         // with 0xcafebabe in the next instruction                                                                                                                                    
         "movl $0xffffffff,%%eax\n\t"
         : "=rax"(var));
    printf("addr - 0x%x\n", var);
}
int main() {
    DWORD old, new;
    MEMORY_BASIC_INFORMATION minfo;

    VirtualQuery((void *)0x401570, &amp;amp;minfo, 30);
    new = minfo.Protect;
    new = PAGE_EXECUTE_READWRITE;
    if (VirtualProtect((void*)0x401570, 30, new, &amp;amp;old) == 0) {
        printf("VirtualProtect() failed\n");
        fflush(stdout);
    }

    foo();
}

&lt;/PRE&gt;

&lt;P&gt;The above code is compiled on linux using mingw(because it has inline asm) into a MS Windows PE32 Executable using the below command and then run on windows using pin.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;$ i686-w64-mingw32-gcc smc.c&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;If I run it from the console without PIN I get the output&lt;/SPAN&gt;&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
	&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;0xcafebabe&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;which is correct, because from the inline asm, I replace the next instruction where I replace the value 0xFFFFFFFF with 0xcafebabe.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;With PIN I get the output -&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-style: italic;"&gt;0xffffffff&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-style: italic; font-size: 1em;"&gt;which is wrong.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;The issue comes up because the modification happens in the currently running code block, which PIN has already cached and is currently running and PIN won't modify the current code block if it is altered.&amp;nbsp; I saw that pin has support for self modifying code through the API call PIN_SetSmcSupport(SMC_ENABLE), but despite that it is broken.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;But the same self modifying code when run with dynamorio, it shows the correct output and dynamorio is able to track the change to the code basic block and update it on the run, something pin fails to do.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;What am I missing with PIN and SMC support?&lt;/P&gt;</description>
    <pubDate>Thu, 31 May 2018 10:29:29 GMT</pubDate>
    <dc:creator>amann__cress</dc:creator>
    <dc:date>2018-05-31T10:29:29Z</dc:date>
    <item>
      <title>PIN Instrumentation SMC(self modifying code) Support Broken</title>
      <link>https://community.intel.com/t5/Software-Archive/PIN-Instrumentation-SMC-self-modifying-code-Support-Broken/m-p/1132726#M77918</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;I have a piece of self-modifying code that PIN fails with, but dynamorio is able to show the correct behaviour.&amp;nbsp; This is the below self-modifying code -&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;//smc.c
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;windows.h&amp;gt;

void foo() {
    int var = -1;

    asm ("call bar\n\t"
         "bar: pop %%eax\n\t"
         "movl $0xcafebabe, 9(%%eax)\n\t"
         // this is an attempt to replace 0xffffffff                                                                                                                                   
         // with 0xcafebabe in the next instruction                                                                                                                                    
         "movl $0xffffffff,%%eax\n\t"
         : "=rax"(var));
    printf("addr - 0x%x\n", var);
}
int main() {
    DWORD old, new;
    MEMORY_BASIC_INFORMATION minfo;

    VirtualQuery((void *)0x401570, &amp;amp;minfo, 30);
    new = minfo.Protect;
    new = PAGE_EXECUTE_READWRITE;
    if (VirtualProtect((void*)0x401570, 30, new, &amp;amp;old) == 0) {
        printf("VirtualProtect() failed\n");
        fflush(stdout);
    }

    foo();
}

&lt;/PRE&gt;

&lt;P&gt;The above code is compiled on linux using mingw(because it has inline asm) into a MS Windows PE32 Executable using the below command and then run on windows using pin.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;$ i686-w64-mingw32-gcc smc.c&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;If I run it from the console without PIN I get the output&lt;/SPAN&gt;&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
	&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;0xcafebabe&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;which is correct, because from the inline asm, I replace the next instruction where I replace the value 0xFFFFFFFF with 0xcafebabe.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;With PIN I get the output -&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-style: italic;"&gt;0xffffffff&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-style: italic; font-size: 1em;"&gt;which is wrong.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;The issue comes up because the modification happens in the currently running code block, which PIN has already cached and is currently running and PIN won't modify the current code block if it is altered.&amp;nbsp; I saw that pin has support for self modifying code through the API call PIN_SetSmcSupport(SMC_ENABLE), but despite that it is broken.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;But the same self modifying code when run with dynamorio, it shows the correct output and dynamorio is able to track the change to the code basic block and update it on the run, something pin fails to do.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;What am I missing with PIN and SMC support?&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 10:29:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/PIN-Instrumentation-SMC-self-modifying-code-Support-Broken/m-p/1132726#M77918</guid>
      <dc:creator>amann__cress</dc:creator>
      <dc:date>2018-05-31T10:29:29Z</dc:date>
    </item>
    <item>
      <title>Hello,</title>
      <link>https://community.intel.com/t5/Software-Archive/PIN-Instrumentation-SMC-self-modifying-code-Support-Broken/m-p/1132727#M77919</link>
      <description>&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Hello,&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;You might try posting your question here:&amp;nbsp;&lt;A href="https://groups.yahoo.com/neo/groups/pinheads/info"&gt;https://groups.yahoo.com/neo/groups/pinheads/info&lt;/A&gt;&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Regards, Hal&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Intel(R) Developer Zone Support&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;&lt;A href="http://software.intel.com/"&gt;http://software.intel.com&lt;/A&gt;&lt;BR /&gt;
	*Other names and brands may be claimed as the property of others.&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 18:44:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/PIN-Instrumentation-SMC-self-modifying-code-Support-Broken/m-p/1132727#M77919</guid>
      <dc:creator>Harold_G_Intel</dc:creator>
      <dc:date>2018-05-31T18:44:20Z</dc:date>
    </item>
    <item>
      <title>Thanks Hal.</title>
      <link>https://community.intel.com/t5/Software-Archive/PIN-Instrumentation-SMC-self-modifying-code-Support-Broken/m-p/1132728#M77920</link>
      <description>&lt;P&gt;Thanks Hal.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;I have posted my question on the yahoo group pinheads like you directed.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;Is there any way this can be directed at PIN developers, because it looks like a bug to me, since dynamorio handles it, but PIN doesn't?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2018 09:42:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/PIN-Instrumentation-SMC-self-modifying-code-Support-Broken/m-p/1132728#M77920</guid>
      <dc:creator>amann__cress</dc:creator>
      <dc:date>2018-06-01T09:42:23Z</dc:date>
    </item>
  </channel>
</rss>

