<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: Overriding System Functions for Fun and Profit</title> <atom:link href="http://hackerboss.com/overriding-system-functions-for-fun-and-profit/feed/" rel="self" type="application/rss+xml" /><link>http://hackerboss.com/overriding-system-functions-for-fun-and-profit/</link> <description>Developing software and managing development teams.</description> <lastBuildDate>Sun, 08 Aug 2010 20:15:47 +0000</lastBuildDate> <generator>http://wordpress.org/?v=</generator> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>By: Ville Laurikari</title><link>http://hackerboss.com/overriding-system-functions-for-fun-and-profit/comment-page-1/#comment-442</link> <dc:creator>Ville Laurikari</dc:creator> <pubDate>Fri, 16 Oct 2009 06:39:00 +0000</pubDate> <guid
isPermaLink="false">http://hackerboss.com/?p=1014#comment-442</guid> <description>Johnny, I think your problem might be related to a GCC optimization. &lt;a href=&quot;http://nion.modprobe.de/blog/archives/680-gcc-and-printfputs-optimizations.html&quot; rel=&quot;nofollow&quot;&gt;GCC sometimes replaces calls to &lt;code&gt;printf()&lt;/code&gt; with &lt;code&gt;puts()&lt;/code&gt; as an optimization&lt;/a&gt;.A simple test confirms this:
&lt;pre lang=&quot;bash&quot;&gt;
$ cat hello.c
#include &lt;stdio.h&gt;
int main() { printf(&quot;Hello, World!\n&quot;); return 0; }
$ gcc -o hello hello.c
$ nm --undefined-only hello
w _Jv_RegisterClasses
w __gmon_start__
U __libc_start_main@@GLIBC_2.2.5
U puts@@GLIBC_2.2.5
&lt;/pre&gt;My code calls &lt;code&gt;printf()&lt;/code&gt;, but the resulting executable actually calls &lt;code&gt;puts()&lt;/code&gt;!You need to override both &lt;code&gt;puts()&lt;/code&gt; and &lt;code&gt;printf()&lt;/code&gt; to catch all cases.  Another option is to recompile using -fno-builtin-printf, but that&#039;s probably defeating the purpose of using LD_PRELOAD in the first place.</description> <content:encoded><![CDATA[<p>Johnny, I think your problem might be related to a GCC optimization. <a
href="http://nion.modprobe.de/blog/archives/680-gcc-and-printfputs-optimizations.html" rel="nofollow">GCC sometimes replaces calls to <code>printf()</code> with <code>puts()</code> as an optimization</a>.</p><p>A simple test confirms this:</p><div
class="wp_syntax"><div
class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">cat</span> hello.c
<span style="color: #666666; font-style: italic;">#include &lt;stdio.h&gt;</span>
int main<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> <span style="color: #7a0874; font-weight: bold;">printf</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;Hello, World!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>; <span style="color: #7a0874; font-weight: bold;">&#125;</span>
$ <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-o</span> hello hello.c
$ <span style="color: #c20cb9; font-weight: bold;">nm</span> <span style="color: #660033;">--undefined-only</span> hello
                 <span style="color: #c20cb9; font-weight: bold;">w</span> _Jv_RegisterClasses
                 <span style="color: #c20cb9; font-weight: bold;">w</span> __gmon_start__
                 U __libc_start_main<span style="color: #000000; font-weight: bold;">@@</span>GLIBC_2.2.5
                 U puts<span style="color: #000000; font-weight: bold;">@@</span>GLIBC_2.2.5</pre></div></div><p>My code calls <code>printf()</code>, but the resulting executable actually calls <code>puts()</code>!</p><p>You need to override both <code>puts()</code> and <code>printf()</code> to catch all cases.  Another option is to recompile using -fno-builtin-printf, but that&#8217;s probably defeating the purpose of using LD_PRELOAD in the first place.</p> ]]></content:encoded> </item> <item><title>By: Johnny</title><link>http://hackerboss.com/overriding-system-functions-for-fun-and-profit/comment-page-1/#comment-440</link> <dc:creator>Johnny</dc:creator> <pubDate>Fri, 16 Oct 2009 05:07:03 +0000</pubDate> <guid
isPermaLink="false">http://hackerboss.com/?p=1014#comment-440</guid> <description>I successfully defined my own malloc/free functions, but for printf(), seems there&#039;re some problem. Have you check it? Thanks.</description> <content:encoded><![CDATA[<p>I successfully defined my own malloc/free functions, but for printf(), seems there&#8217;re some problem. Have you check it? Thanks.</p> ]]></content:encoded> </item> <item><title>By: Johnny</title><link>http://hackerboss.com/overriding-system-functions-for-fun-and-profit/comment-page-1/#comment-425</link> <dc:creator>Johnny</dc:creator> <pubDate>Thu, 15 Oct 2009 07:21:30 +0000</pubDate> <guid
isPermaLink="false">http://hackerboss.com/?p=1014#comment-425</guid> <description>It&#039;s what I really need for current project. Thanks.I need to dump all debugging messages sent to console to a file/memory. At least three solutions are available:
1. Deploy wrapped printf all over the system. Our codes are from different team/company, different wrapper functions are used to output to console, so unify them is a little difficult (even inside our team, due to historical reason, printf of system library and wrappers are mix-used, NOT well organized!)
2. Touch UART driver: it&#039;s a good solution, but we don&#039;t want it. No reason.
3. Hook into printf: I find the solution here :-)</description> <content:encoded><![CDATA[<p>It&#8217;s what I really need for current project. Thanks.</p><p>I need to dump all debugging messages sent to console to a file/memory. At least three solutions are available:<br
/> 1. Deploy wrapped printf all over the system. Our codes are from different team/company, different wrapper functions are used to output to console, so unify them is a little difficult (even inside our team, due to historical reason, printf of system library and wrappers are mix-used, NOT well organized!)<br
/> 2. Touch UART driver: it&#8217;s a good solution, but we don&#8217;t want it. No reason.<br
/> 3. Hook into printf: I find the solution here :-)</p> ]]></content:encoded> </item> <item><title>By: lonelycoder</title><link>http://hackerboss.com/overriding-system-functions-for-fun-and-profit/comment-page-1/#comment-348</link> <dc:creator>lonelycoder</dc:creator> <pubDate>Fri, 25 Sep 2009 10:30:59 +0000</pubDate> <guid
isPermaLink="false">http://hackerboss.com/?p=1014#comment-348</guid> <description>I was aware of this ld_preload thing, but I though it was some kind of black magic to use it.  Thanks.</description> <content:encoded><![CDATA[<p>I was aware of this ld_preload thing, but I though it was some kind of black magic to use it.  Thanks.</p> ]]></content:encoded> </item> <item><title>By: hackerboss</title><link>http://hackerboss.com/overriding-system-functions-for-fun-and-profit/comment-page-1/#comment-345</link> <dc:creator>hackerboss</dc:creator> <pubDate>Thu, 24 Sep 2009 10:20:08 +0000</pubDate> <guid
isPermaLink="false">http://hackerboss.com/?p=1014#comment-345</guid> <description>&lt;p&gt;Overriding System Functions for Fun and Profit: &lt;a href=&quot;http://bit.ly/mJzch&quot; rel=&quot;nofollow&quot;&gt;http://bit.ly/mJzch&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;This comment was originally posted on &lt;a href=&quot;http://twitter.com/hackerboss/statuses/4338802037&quot; rel=&quot;nofollow&quot;&gt;Twitter&lt;/a&gt;&lt;/i&gt;&lt;/p&gt;</description> <content:encoded><![CDATA[<p>Overriding System Functions for Fun and Profit: <a
href="http://bit.ly/mJzch" rel="nofollow">http://bit.ly/mJzch</a></p><p><i>This comment was originally posted on <a
href="http://twitter.com/hackerboss/statuses/4338802037" rel="nofollow">Twitter</a></i></p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 1/11 queries in 0.031 seconds using disk

Served from: hackerboss.com @ 2010-09-05 20:17:58 -->