<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PELock Blog &#187; Assembler</title>
	<atom:link href="http://www.pelock.com/blog/category/assembler/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pelock.com/blog</link>
	<description>Assembler, software protection, code obfuscation and other crazy stuff.</description>
	<lastBuildDate>Fri, 04 Apr 2008 11:05:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Really easy scripting with ODbgScript</title>
		<link>http://www.pelock.com/blog/2007/09/06/really-easy-scripting-with-odbgscript/</link>
		<comments>http://www.pelock.com/blog/2007/09/06/really-easy-scripting-with-odbgscript/#comments</comments>
		<pubDate>Wed, 05 Sep 2007 23:30:31 +0000</pubDate>
		<dc:creator>Bartosz</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[ODbgScript]]></category>
		<category><![CDATA[OllyDbg]]></category>

		<guid isPermaLink="false">http://www.pelock.com/blog/2007/09/06/really-easy-scripting-with-odbgscript/</guid>
		<description><![CDATA[ODbgScript is an extension for OllyDbg debugger (note to myself: so mr smartass there&#8217;s life except SoftICE heh  )...]]></description>
			<content:encoded><![CDATA[<p><a href="http://odbgscript.sourceforge.net/">ODbgScript</a> is an extension for <a href="http://www.ollydbg.de/">OllyDbg</a> debugger (<em>note to myself: so mr smartass there&#8217;s life except SoftICE heh <img src='http://www.pelock.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em>).</p>
<p>I was always a little bit afraid of using it becouse i thought it&#8217;s easier to write separate application than to code in this <em>weird</em> scripting language.</p>
<p>But today i need a tool to dump decrypted strings from one application (while it&#8217;s running). I wanted to start coding live dumper based on <a href="http://msdn2.microsoft.com/en-us/library/ms679303.aspx">WinApi&#8217;s debug functions</a> but i though what the heck, let&#8217;s try to do it in ODbgScript.</p>
<p>Here&#8217;s the result:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">; declare variables</span>
        var     string_ptr
        var     file_name
        var     file_index
        var     file_size
        var     x
&nbsp;
<span style="color: #666666; font-style: italic;">; set breakpoint at the instruction where we</span>
<span style="color: #666666; font-style: italic;">; intercepts decrypted strings</span>
        <span style="color: #00007f;">bp</span>     <span style="color: #0000ff;">401020</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; initialize file_index variable</span>
        <span style="color: #00007f; font-weight: bold;">mov</span>     file_index<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; run application after setting the breakpoint</span>
again<span style="color: #339933;">:</span>
        run
&nbsp;
<span style="color: #666666; font-style: italic;">; if we're here, it means application hit the breakpoint</span>
<span style="color: #666666; font-style: italic;">; continue to execute script after breakpoint is hit</span>
<span style="color: #666666; font-style: italic;">; (don't stop in OllyDbg)</span>
        cob
&nbsp;
<span style="color: #666666; font-style: italic;">; pointer to the encrypted string is stored</span>
<span style="color: #666666; font-style: italic;">; at [ebp-14] let's grab it</span>
        <span style="color: #00007f; font-weight: bold;">mov</span>     x<span style="color: #339933;">,</span> <span style="color: #00007f;">ebp</span>
        <span style="color: #00007f; font-weight: bold;">sub</span>     x<span style="color: #339933;">,</span> <span style="color: #0000ff;">14</span>
        <span style="color: #00007f; font-weight: bold;">mov</span>     x<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>x<span style="color: #009900; font-weight: bold;">&#93;</span>
&nbsp;
        <span style="color: #00007f; font-weight: bold;">mov</span>     string_ptr<span style="color: #339933;">,</span> x
&nbsp;
<span style="color: #666666; font-style: italic;">; strings are null terminated, let's find its</span>
<span style="color: #666666; font-style: italic;">; size so we can dump it (LEN command didn't work</span>
<span style="color: #666666; font-style: italic;">; here, it always returns 0FFh)</span>
        find    string_ptr<span style="color: #339933;">,</span> #<span style="color: #0000ff;">00</span>#
&nbsp;
        <span style="color: #00007f; font-weight: bold;">cmp</span>     $RESULT<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span>
        <span style="color: #00007f; font-weight: bold;">je</span>      skip_file
&nbsp;
<span style="color: #666666; font-style: italic;">; calculate string size</span>
        <span style="color: #00007f; font-weight: bold;">mov</span>     x<span style="color: #339933;">,</span> $RESULT
        <span style="color: #00007f; font-weight: bold;">sub</span>     x<span style="color: #339933;">,</span> string_ptr
&nbsp;
        <span style="color: #00007f; font-weight: bold;">mov</span>     file_size<span style="color: #339933;">,</span> x
&nbsp;
<span style="color: #666666; font-style: italic;">; format file name for decrypted string, name it using</span>
<span style="color: #666666; font-style: italic;">; file_index value and .txt extension, eval works almost</span>
<span style="color: #666666; font-style: italic;">; like wsprintf</span>
        eval    <span style="color: #7f007f;">&quot;C:\Test\{file_index}.txt&quot;</span>
        <span style="color: #00007f; font-weight: bold;">mov</span>     file_name<span style="color: #339933;">,</span> $RESULT
&nbsp;
<span style="color: #666666; font-style: italic;">; dump memory area to the file</span>
        dm      string_ptr<span style="color: #339933;">,</span> file_size<span style="color: #339933;">,</span> file_name
&nbsp;
<span style="color: #666666; font-style: italic;">; log action</span>
        eval    <span style="color: #7f007f;">&quot;{file_index} - VA = {string_ptr},
                 SIZE = {file_size}&quot;</span>
        log     $RESULT<span style="color: #666666; font-style: italic;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; increase index value</span>
        <span style="color: #00007f; font-weight: bold;">inc</span>     file_index
&nbsp;
skip_file<span style="color: #339933;">:</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; run application again after dumping</span>
        <span style="color: #00007f; font-weight: bold;">jmp</span>     again</pre></div></div>

<p>At first it might look confusing, but after playing with it for 5 minutes you will love it, especially if you know how to code in assembler.</p>
<p>And if you make mistakes in the script, don&#8217;t worry, it has its own, built-in debugger, available directly from OllyDbg so you can spot every mistake you did, trace down the script, modify its variables etc.</p>
<p>In other words viva la ODbgScript <img src='http://www.pelock.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><em>PS. And don&#8217;t ask me why i didn&#8217;t use it before <img src='http://www.pelock.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pelock.com/blog/2007/09/06/really-easy-scripting-with-odbgscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSE5 on the way</title>
		<link>http://www.pelock.com/blog/2007/09/02/sse5-on-the-way/</link>
		<comments>http://www.pelock.com/blog/2007/09/02/sse5-on-the-way/#comments</comments>
		<pubDate>Sun, 02 Sep 2007 15:57:53 +0000</pubDate>
		<dc:creator>Bartosz</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[SIMD]]></category>
		<category><![CDATA[SSE5]]></category>

		<guid isPermaLink="false">http://www.pelock.com/blog/2007/09/02/sse5-on-the-way/</guid>
		<description><![CDATA[With the introduction of SSE5, many new 128-bit instructions have been added to the existing instruction set detailed in the AMD64 Architecture Programmer&#8217;s Manuals...]]></description>
			<content:encoded><![CDATA[<blockquote><p>With the introduction of SSE5, many new 128-bit instructions have been added to the existing instruction set detailed in the AMD64 Architecture Programmer&#8217;s Manuals. Included are 46 base instructions that expand to 170 total instructions, enabling improved performance and reduced loads.
</p></blockquote>
<p>Source:<br />
<a href="http://developer.amd.com/sse5.jsp">http://developer.amd.com/sse5.jsp</a></p>
<p>PDF Documentation:<br />
<a href="http://developer.amd.com/assets/sse5_43479_BDAPMU_3-00_8-27-07.pdf">AMD64 Technology 128-Bit SSE5 Instruction Set</a></p>
<p>I wonder in how many years will it be used as a default set of instructions?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pelock.com/blog/2007/09/02/sse5-on-the-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMware detection (anti-debugging trick against TRW)</title>
		<link>http://www.pelock.com/blog/2007/04/15/vmware-detection-anti-debugging-trick-against-trw/</link>
		<comments>http://www.pelock.com/blog/2007/04/15/vmware-detection-anti-debugging-trick-against-trw/#comments</comments>
		<pubDate>Sun, 15 Apr 2007 19:44:26 +0000</pubDate>
		<dc:creator>Bartosz</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[VMware]]></category>

		<guid isPermaLink="false">http://www.pelock.com/blog/2007/04/15/vmware-detection-anti-debugging-trick-against-trw/</guid>
		<description><![CDATA[Some of the anti-debugging tricks can be used to detect VMware, one of them is an old anti TRW (TRW was a popular debugger in 9x days) trick...]]></description>
			<content:encoded><![CDATA[<p>Some of the anti-debugging tricks can be used to detect VMware, one of them is an old anti <a href="http://www.softpedia.com/get/Programming/Debuggers-Decompilers-Dissasemblers/TRW.shtml">TRW</a> (TRW was a popular debugger in 9x days) trick.</p>
<p>This anti-debugging trick works fine on a real Windows 9x installations (95, 98, ME) but it raises an exception under VMware (while reading IDT entry).</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">BOOL IsVMware9xTrw<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">// detect NT/XP/Vista</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span>GetVersion<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span> <span style="color: #208080;">0x80000000</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">return</span> FALSE<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #666666;">// detect VMWare (anti debugging trick against TRW)</span>
    <span style="color: #666666;">// VMware isn't detected with vm acceleration disabled</span>
    __try
    <span style="color: #008000;">&#123;</span>
        __asm
        <span style="color: #008000;">&#123;</span>
            sub    esp, <span style="color: #0000dd;">6</span>
            sidt   fword ptr <span style="color: #008000;">&#91;</span>esp<span style="color: #008000;">&#93;</span>
            pop    ax
            pop    eax
            mov    al, byte ptr <span style="color: #008000;">&#91;</span>eax <span style="color: #000040;">+</span> 00Eh<span style="color: #008000;">&#93;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    __except<span style="color: #008000;">&#40;</span>EXCEPTION_EXECUTE_HANDLER<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">return</span> TRUE<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> FALSE<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Binaries and source code:<br />
<a href="http://www.pelock.com/download.php?f=vmware_trw.zip">http://www.pelock.com/download.php?f=vmware_trw.zip</a> (18 kB)</p>
<p>Please test this code on your own systems and tell me about the results.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pelock.com/blog/2007/04/15/vmware-detection-anti-debugging-trick-against-trw/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
