Hello there i have some code that i need to make it easier to understand.I mean transforming the jne .... onto .if .....==.... instructions, or .elseif or else instructions.



The problem is no matter what i try when i disaqssemble my own code it is t not the same, and the program not work properly.

Therer are few conditional jumps inside, that are hard to undertand in what part of the block they are. I jut want to rebuild it and uderstand what exactly works with .else instructios, .if (!eax) ; .if ; .else if and stuff...and how the ml assembler deals with it if they are deep inside the main code.

Here is the coding
____________________________________________________

WndProc proc hWnd :DWORD,
Msg :DWORD,
wParam :DWORD,
lParam :DWORD,


(...some code)
cmp eax, WM_CLOSE
jnz short loc_40125C ; It is .If eax==WM_CLOSE

(...some code)
jmp IsEndIf


loc_40125C:
cmp eax, WM_INITDIALOG ; It is .elseif WM_INITDIALOG
jnz loc_401303
(...some code)
jmp IsEndIf


loc_401303:
cmp eax, WM_COMMAND
jnz loc_4013B0
(...some code)
cmp ax, IDC_CancelBtn
jnz short loc_401324

(...some code)
jmp IsEndIf

loc_401324:
cmp ax, IDC_PushBtn
jnz short loc_401350
(...some code)
cmp ax, TRUE
jnz IsEndIf

(...some code)
jmp IsEndIf


loc_401350:
cmp ax, IDC_TextBtn
jnz short loc_401394
shr eax, 16
cmp ax, WM_CUT
jnz short loc_401390

invoke GetDlgItemText, hWnd, IDC_TextBtn, addr Sz_GrabFileName, 257
xor eax, eax
cmp byte ptr , 0

setnz al

invoke EnableWindow, dhWnd, eax
jmp short IsEndIf


loc_401390:
jmp short elseif_endif

jmp short IsEndIf


loc_401394:
cmp ax, IDC_UnpackBtn
jnz short IsEndIf

(...some code)
jmp short IsEndIf


loc_4013B0:
cmp eax, WM_SYSCOMMAND
jnz short IsEndIf
mov eax, wParam
and ax, 0FFF0h
cmp ax, WM_CLOSE
jnz short elseif_endif

(...some code)

jmp short IsEndIf


elseif_endif: It is .else

(...some code)
retn


IsEndIf: It is .endif
xor eax, eax
retn
WndProc endp

____________________________________________________


Can anyone help me, please ?
Posted on 2002-01-29 09:06:03 by Beyond2000!
jnz = jne = Jump if Not Equal. Thus, a compare is made. If it's not
the right case, jump on to the next compare. If it's the right case,
execute the code, and skip the rest of the comparisons.

The "cmp eax, whatever" and "jnz loc_blablabla" can be replaced
by ".IF EAX == whatever", and the "jmp isEndIF" by a .ELSEIF.
(Well, not *exactly* that way, but you should see what I mean).

Also, realize that posting disassembled stuff here can be a dangerous
thing to do :). However, the disassembly looks just like a normal
masm program, so... I'll let it live. It's not like disassembly automatically
means "bad stuff".
Posted on 2002-01-29 09:12:10 by f0dder
Yep, the code is a regular masm, it's just a part of a dialog proc.

I didn't wrote the main code...I just tryiong to recreate it on a better way...

The jmp isEndIF can be replaced by .elseif....

The problem is i tryed to follow the instructions and replacing them, but the result is not the same one.

He has an else instructin before isEndIF, that it called 02 times before the end of the code.

Just like:

.if bla bla bla.

.elsif bla bla bba
Posted on 2002-01-29 09:31:54 by Beyond2000!
Sotty, i as said

it just have other places inside the code before the else instruction.

Like

.if ,,,,,

.elseif.....
.if.....
.if.......
.endif
.else
.endif
.elseif...
.endif


See, i followed the code replacing the proper instructions, but a tryed many times, and it seems to not be the same.

I am tryong to understand exactly how it works without any errors.
Posted on 2002-01-29 09:37:17 by Beyond2000!
Here is a translation of .if-.elseif-.else-.endif. The .elseif block can be repeated as often as necessary. I show two .elseif's, but there can be as few as none. If there is no .else block, the jump before the .endif is redundant and needn't be generated.

.if eax == 1

...case 1...
.elseif eax == 2
...case 2...
.elseif eax == 3
...case 3...
.else
...default case...
.endif
; .if block

cmp eax,1
jne not_case1
...case 1...
jmp endcase
not_case1:

; .elseif block
cmp eax,2
jne not_case2
...case 2...
jmp endcase
not_case2:

; .elseif block
cmp eax,3
jne not_case3
...case 3...
jmp endcase
not_case3:

; .else block
...default case...
endcase:
Posted on 2002-01-29 13:39:10 by tank
Thanks tank, i tryed that kinda before, but i got stucked on block3.

Right above the else block there is some code that cannot be .elseif instructions due to the order of the jumps, that's why i assume they are .if instructions, but they are inside other instructions that i cannot translate.


Just like that:

code:
_____________________

.if eax==WM_CLOSE
...case 1...

.elseif eax==WM_INITDIALOG
...case 2...

.elseif eax==WM_COMMAND
...case 3... This is where i got stuck

.else
...default case...
.endif


That looks exactly as

code:

_____________

; .if block -1st block this is OK

cmp eax, WM_CLOSE
jnz not_case1
...case 1...
jmp endcase

not_case1:

; .elseif block -2nd block this is OK

cmp eax, WM_INITDIALOG
jnz not_case2
...case 2...
jmp endcase

not_case2:

; .elseif block -3nd block this is where the trouble begins


cmp eax, WM_COMMAND ; .elseif eax==WM_COMMAND
jnz not_case3, The end (not_case3) seems not to be elseif
...case 3...

cmp ax, IDC_CancelBtn ; The firts .if inside.
jnz not_case_inside1
...case 4...
jmp endcase

not_case_inside1: ; The 1st .elseif inside ?
cmp ax, IDC_PushBtn
jnz not_case_inside2
...case 5...
cmp ax, TRUE ; Probably .if ax==TRUE
jnz endcase
...case 6... ; .endif
jmp endcase

not_case_inside2: ; The 2nd .elseif inside ?
cmp ax, IDC_TextBtn
jnz not_case_inside3
...case 7...
cmp ax, WM_CUT
jnz not_case_inside_inside ; ???? How that happens ?
...case 8...; another .elseif or just .if followed by an end ?
jmp endcase

not_case_inside_inside:

jmp else ; How ????
jmp endcase ; How ???

not_case_inside3:
cmp ax, IDC_UnpackBtn; an .elseif here ? how ?
jnz endcase
...case 9...
jmp endcase ; Maybe an .endif here ?

not_case3:
cmp eax, WM_SYSCOMMAND
jnz endcase ;(1) Not elseif because the jumps 1 and 2
; probably it is .if Inside the case3
; without .endif
...some case...

cmp eax, WM_CLOSE
jnz else ; (2)
...some case... ; probably it is .if Inside the case3
; with .endif that is due to jmp endcase
jmp endcase


; .else block

else:
...default case...

endcase:

I don't know how it jumps in the middle of the code to outside the main block and how therer are 02 points to the else instruction.
Posted on 2002-01-29 17:14:33 by Beyond2000!
In hand-coded stuff, a programmer may take shortcuts and jump directly to the very end of the nested case structure if no other processing is needed.

WM_COMMAND will usually look like this:
.elseif eax == WM_COMMAND

; case 3
.if ax == control1
...case 3.1...
.elseif ax == control2
...case 3.2...
; other .elseif's
.endif
; Hand-coded source may skip jumping to here
; One may guess that MASM will generate a JMP here
.elseif eax == (next WM_ code)
; case 4
Posted on 2002-01-29 21:19:21 by tank