TBone
April 19th, 2004, 15:55
As part of my ongoing effort to modernize my knowledge of how program execution works from top to bottom, I'm reading through the Intel IA-32 Architecture Software Developer's Manuals to brush up on assembly before I tackle more complex topics like PE/COFF format, etc. I haven't really studied the subject since the DOS days, when things were decidely simpler, heh.
Anyway, I came across this opcode and thought it was kind of amusing, so I played around with it a little. Intel's specifications indicate that it's functionally equivalent to NOP except that it raises an invalid opcode exception (#UD). Ok, sounds fun. So I wrote a little .asm file to test it out. It turns out that MASM doesn't know how to assemble a UD2 opcode, so I just assembled two NOPS instead:
Then I pulled out a hex editor and changed the 90 90 to 0F 0B (UD2).
Executing the binary does nothing, which isn't all that surprising, but I thought that maybe Windows would at least bark about an invalid opcode exception. I tried loading it with OllyDbg and it generated the exception as soon as you start exceution. Passing the exception to the program caused it to transfer control to ntdll.dll. I don't have an import library built yet, so it's a little hard to tell what happens after that. According to Olly, the application couldn't handle the exception, and it terminates. Hmm, ok. It sounds like Windows itself just doesn't handle that exception. Am I interpreting this right?
Secondly, if you load the executable with IDA, it doesn't seem to know what to do with that opcode. W32DASM at least shows it as "invalid opcode", but IDA just makes a mess of it:
With a little undefining and manual defining, I can at least get:
Is there some way to define that opcode for IDA? It's not really a big deal; I just found it odd that the most highly esteemed decompiler had no idea how to handle it.
Anyway, I came across this opcode and thought it was kind of amusing, so I played around with it a little. Intel's specifications indicate that it's functionally equivalent to NOP except that it raises an invalid opcode exception (#UD). Ok, sounds fun. So I wrote a little .asm file to test it out. It turns out that MASM doesn't know how to assemble a UD2 opcode, so I just assembled two NOPS instead:
Code:
.386
.model flat, stdcall
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
.code
start:
NOP
NOP
invoke ExitProcess, NULL
end start
Then I pulled out a hex editor and changed the 90 90 to 0F 0B (UD2).
Executing the binary does nothing, which isn't all that surprising, but I thought that maybe Windows would at least bark about an invalid opcode exception. I tried loading it with OllyDbg and it generated the exception as soon as you start exceution. Passing the exception to the program caused it to transfer control to ntdll.dll. I don't have an import library built yet, so it's a little hard to tell what happens after that. According to Olly, the application couldn't handle the exception, and it terminates. Hmm, ok. It sounds like Windows itself just doesn't handle that exception. Am I interpreting this right?
Secondly, if you load the executable with IDA, it doesn't seem to know what to do with that opcode. W32DASM at least shows it as "invalid opcode", but IDA just makes a mess of it:
Code:
.text:00401000 _text segment para public 'CODE' use32
.text:00401000 assume cs:_text
.text:00401000 ;org 401000h
.text:00401000 assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing
.text:00401000 public start
.text:00401000 start dd 6A0B0Fh, 1E8h, 25FFCC00h, 402000h, 7Ch dup(0)
.text:00401000 _text ends
With a little undefining and manual defining, I can at least get:
Code:
.text:00401000 ; Segment type: Pure code
.text:00401000 _text segment para public 'CODE' use32
.text:00401000 assume cs:_text
.text:00401000 ;org 401000h
.text:00401000 assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing
.text:00401000 public start
.text:00401000 start db 0Fh ;
.text:00401001 db 0Bh ;
.text:00401002 ; ---------------------------------------------------------------------------
.text:00401002 push 0
.text:00401004 call ExitProcess
.text:00401009 int 3 ; Trap to Debugger
.text:0040100A ; [00000006 BYTES: COLLAPSED FUNCTION ExitProcess. PRESS KEYPAD "+" TO EXPAND]
.text:00401010 align 200h
.text:00401010 _text ends
Is there some way to define that opcode for IDA? It's not really a big deal; I just found it odd that the most highly esteemed decompiler had no idea how to handle it.