<?xml version="1.0"?>
<rss version="2.0">
    <channel>
        <title>OpenRCE: Blog</title>
        <link>http://www.openrce.org/rss/feeds/blog</link>
        <description>OpenRCE: The Open Reverse Code Engineering Community</description>
                <item>
            <title>DelMod2</title>
                            <pubDate>Wed, 16 Mar 2011 07:35:23 -0500</pubDate>
                                        <link>https://www.openrce.org/blog/view/1648/DelMod2</link>
                                        <author>EliCZ &lt;email-suppressed@example.com&gt;</author>
                                                    <description>http://apihooks.com.sweb.cz/EliCZ/export/DelMod2.zip&lt;br /&gt;
/*&lt;br /&gt;
&amp;nbsp;&amp;nbsp;Inspired by http://habrahabr.ru/blogs/windows/77818&lt;br /&gt;
&amp;nbsp;&amp;nbsp;2011-03-16:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;A file can be deleted even if ADS of the file is mapped.&lt;br /&gt;
*/&lt;br /&gt;
</description>
                    </item>
                <item>
            <title>User-mode debugger with SoftICE UI</title>
                            <pubDate>Tue, 14 Jul 2009 09:23:34 -0500</pubDate>
                                        <link>https://www.openrce.org/blog/view/1481/User-mode_debugger_with_SoftICE_UI</link>
                                        <author>EliCZ &lt;email-suppressed@example.com&gt;</author>
                                                    <description>http://ugdbg.sourceforge.net&lt;br /&gt;
I like it.&lt;br /&gt;
</description>
                    </item>
                <item>
            <title>psusp</title>
                            <pubDate>Mon, 15 Jun 2009 04:01:33 -0500</pubDate>
                                        <link>https://www.openrce.org/blog/view/1472/psusp</link>
                                        <author>EliCZ &lt;email-suppressed@example.com&gt;</author>
                                                    <description>- for XP+(x86,x64) suspends a process on an exception or termination.&lt;br /&gt;
Useful for MyAppShouldNotCrashForAnyInput.exe *.* testing.&lt;br /&gt;
It's less intrusive than AeDebug - heap, locks, ... are left intact.&lt;br /&gt;
http://apihooks.com/EliCZ/export/psusp.zip&lt;br /&gt;
</description>
                    </item>
                <item>
            <title>Found what is that &amp;quot;long mode segmentation&amp;quot;</title>
                            <pubDate>Fri, 03 Apr 2009 09:39:30 -0500</pubDate>
                                        <link>https://www.openrce.org/blog/view/1429/Found_what_is_that_&quot;long_mode_segmentation&quot;</link>
                                        <author>EliCZ &lt;email-suppressed@example.com&gt;</author>
                                                    <description>(required by VMware)&lt;br /&gt;
&lt;br /&gt;
http://amd.com.cn/CHCN/assets/content_type/DownloadableAssets/dwamd_kernel_summit_08_RB.pdf&lt;br /&gt;
</description>
                    </item>
                <item>
            <title>Integer overflow</title>
                            <pubDate>Fri, 25 Apr 2008 09:21:42 -0500</pubDate>
                                        <link>https://www.openrce.org/blog/view/1129/Integer_overflow</link>
                                        <author>EliCZ &lt;email-suppressed@example.com&gt;</author>
                                                    <description>How to write integer(32) division in i386 assembly language using idiv instruction so that it doesn't raise an exception?&lt;br /&gt;
&lt;br /&gt;
mov&amp;nbsp;&amp;nbsp; eax, Dividend&lt;br /&gt;
mov&amp;nbsp;&amp;nbsp; ecx, Divisor&lt;br /&gt;
idiv&amp;nbsp;&amp;nbsp;ecx&lt;br /&gt;
&lt;br /&gt;
It can throw #DE, add Divisor == 0 check:&lt;br /&gt;
&lt;br /&gt;
mov&amp;nbsp;&amp;nbsp; eax, Dividend&lt;br /&gt;
mov&amp;nbsp;&amp;nbsp; ecx, Divisor&lt;br /&gt;
jecxz DontIdiv&lt;br /&gt;
idiv&amp;nbsp;&amp;nbsp;ecx&lt;br /&gt;
&lt;br /&gt;
It can still throw #DE, edx must be initialized for (i)div.&lt;br /&gt;
AMD64 manual : &amp;quot;To avoid overflow problems, precede this instruction (idiv) with a CBW, CWD, CDQ, or CQO instruction to sign-extend the dividend.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
mov&amp;nbsp;&amp;nbsp; eax, Dividend&lt;br /&gt;
mov&amp;nbsp;&amp;nbsp; ecx, Divisor&lt;br /&gt;
jecxz DontIdiv&lt;br /&gt;
cdq&lt;br /&gt;
idiv&amp;nbsp;&amp;nbsp;ecx&lt;br /&gt;
&lt;br /&gt;
It looks fixed (C compilers think so), can it throw #DE now?&lt;br /&gt;
&lt;br /&gt;
Yes, it can - I didn't avoid overflow problems.&lt;br /&gt;
There is still one combination that will raise #DE:&lt;br /&gt;
Dividend = INT_MIN and Divisor = -1.&lt;br /&gt;
&lt;br /&gt;
mov&amp;nbsp;&amp;nbsp; eax, Dividend&lt;br /&gt;
mov&amp;nbsp;&amp;nbsp; ecx, Divisor&lt;br /&gt;
jecxz DontIdiv&lt;br /&gt;
cmp&amp;nbsp;&amp;nbsp; eax, INT_MIN&lt;br /&gt;
sete&amp;nbsp;&amp;nbsp;dl&lt;br /&gt;
cmp&amp;nbsp;&amp;nbsp; ecx, -1&lt;br /&gt;
sete&amp;nbsp;&amp;nbsp;dh&lt;br /&gt;
test&amp;nbsp;&amp;nbsp;dl, dh&lt;br /&gt;
jne&amp;nbsp;&amp;nbsp; DontIdiv&lt;br /&gt;
cdq&lt;br /&gt;
idiv&amp;nbsp;&amp;nbsp;ecx&lt;br /&gt;
&lt;br /&gt;
Other integer arithmetic instructions set OF only and the result for 0-INT_MIN is INT_MIN.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do C compilers (CPUs, OSes) handle the integer overflow?&lt;br /&gt;
&lt;br /&gt;
neg32.c:&lt;br /&gt;
int neg32(int x) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return(-x);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
neg64.c:&lt;br /&gt;
long long neg64(long long x) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return(-x);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
idiv32.c:&lt;br /&gt;
int idiv32(int x, int y) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return(x/y);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
idiv64.c:&lt;br /&gt;
#define __USE_ISOC99&lt;br /&gt;
#include &amp;lt;limits.h&amp;gt;&lt;br /&gt;
#ifndef LLONG_MIN&lt;br /&gt;
&amp;nbsp;&amp;nbsp;#ifdef LONG_LONG_MIN&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#define LLONG_MIN LONG_LONG_MIN&lt;br /&gt;
&amp;nbsp;&amp;nbsp;#else&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#define LLONG_MIN -9223372036854775808LL&lt;br /&gt;
&amp;nbsp;&amp;nbsp;#endif&lt;br /&gt;
#endif&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
long long idiv64(long long x, long long y) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return(x/y);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;long long x = LLONG_MIN;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;long long y = -1;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;long long r = 1234;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;r = idiv64(x, y);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return(printf(&amp;quot;%lli\n&amp;quot;, r));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Sometimes a (CRT) function is used instead of division performing instruction,&lt;br /&gt;
especially for integer64 division in 32bit builds.&lt;br /&gt;
(int)-INT_MIN == INT_MIN always.&lt;br /&gt;
&lt;br /&gt;
architecture/os/compilers/builds neg32 | neg64 | idiv32 | idiv64&lt;br /&gt;
i386/winnt/msc|dmc/32 INT_MIN | LLONG_MIN | crash | LLONG_MIN&lt;br /&gt;
i386/winnt/wc/32&amp;nbsp;&amp;nbsp;INT_MIN | LLONG_MIN | print exception info and exit | LLONG_MIN&lt;br /&gt;
i386/linux/gcc/32 INT_MIN | LLONG_MIN | &amp;quot;Floating point exception&amp;quot; | LLONG_MIN&lt;br /&gt;
amd64/winnt/msc/64 INT_MIN | LLONG_MIN | crash | crash&lt;br /&gt;
amd64/linux/gcc/64 INT_MIN | LLONG_MIN | &amp;quot;Floating point exception&amp;quot; | &amp;quot;Floating point exception&amp;quot;&lt;br /&gt;
ia64/winnt/msc/32 INT_MIN | LLONG_MIN | long pause and exit | LLONG_MIN&lt;br /&gt;
ia64/winnt/msc/64 INT_MIN | LLONG_MIN | INT_MIN | LLONG_MIN&lt;br /&gt;
power/aix/gcc|xlc/32 INT_MIN | LLONG_MIN | 0 | LLONG_MIN&lt;br /&gt;
power/aix/gcc|xlc/64 INT_MIN | LLONG_MIN | 0 | 0&lt;br /&gt;
sparc/solaris/gcc|suncc/32|64 INT_MIN | LLONG_MIN | INT_MIN | LLONG_MIN&lt;br /&gt;
&lt;br /&gt;
See you at caro workshop.&lt;br /&gt;
</description>
                    </item>
            </channel>
</rss>
