flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > [IDEA] fdasm - FASM decompiler

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
2



Joined: 26 Sep 2006
Posts: 92
2
Do you mean a disassembler? I use ndisasm which comes with NASM
to disassemble my C programs and find something so I can NOP
it with 0x90 and mess it up. It's fun!
Post 10 Dec 2006, 05:23
View user's profile Send private message Reply with quote
sylwek32



Joined: 27 Apr 2006
Posts: 339
sylwek32
has somebody already made a disassembler for fasm which makes compilable code ?
Post 10 Dec 2006, 20:58
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
vid
sylwek: i bet no
Post 10 Dec 2006, 23:30
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
anyone make a disassembler in fasm itself?
Post 11 Dec 2006, 03:56
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
I havn't read all of this, but the fix to disassembling "mov ax, label-label2" can't be perfect, but instead of placing an address there, it could declare a variable with that address, then comment behind it saying it has no clue how that address was picked. Then some one could use a little intellegence to figure out what it was, but you don't want to make a perfect dissassembler, anyway. It could help some one steal your own code that you worked on for money. Just change a little and claim that you copied their code rather than them copying yours.
Post 11 Dec 2006, 04:08
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386
..


Last edited by DOS386 on 12 Dec 2007, 06:28; edited 2 times in total
Post 12 Dec 2006, 22:19
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Only the program can be sure what their code is supposed to do, even then, sometimes they do not... No machine can think like a human, in turn, there is no perfect decompiler. All you can do is your best.
Post 12 Dec 2006, 22:22
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
ATV



Joined: 31 Aug 2004
Posts: 109
Location: Finland
ATV
One source tells more than 1000 word. This tetris example is not for beginners, it has lots of optimize triks inside.

This source can be compile under FASM but it has 28 different bytes compared with original TASM produced tetris.com (example "xor cl,al" = 32 C8 = 30 C1)
There are many "mov reg,[ofs2-ofs1]" that are very difficult to suppurt even with interactive disassembler.
I was disassembling this side by side with original source.

DASM can also disassembly 32bit code (F10 and change code size), but there isn't any windows related information header/calls/macros just pure asm.

EDIT: L0167h missed call fixed (i fall into my own trick)
Code:
; title Disassembly of file: TETRIS.COM - produced by DASM.EXE v1.02

empty_line      equ     9fa0h
field           equ     0a0a0h
Lff00h          equ     0ff00h

org             0100h

L0100h:         mov     di,empty_line           ;Use keys J,K,L,SPACE
                mov     bp,field                ;also screen segment
                mov     ah,5fh ;'_'             ;mov ah,(fHeight*4-1)
L0108h:         mov     cl,0ah
                xor     cl,al
                rep     stosb
                xor     al,7ch ;'|'
                dec     ah
                jne     L0108h
                mov     ch,01h
                rep     stosb
                mov     al,13h
                int     10h
L011ch:         cwd
                mov     di,seed
                imul    ax,[di],24cdh
                inc     ax
                stosw
                idiv    word [di-2fh]           ;idiv word [di+seven-pieceC]
                xchg    dx,ax
                stosb
                xchg    bx,ax
                mov     ah,[bx+di-0ah]          ;mov ah,[bx+di+tblXY-pieceXY]
                mov     al,50h ;'P'
L0131h:         shr     ax,03h
                je      L0158h
                mov     si,ax
                and     al,07h
                aam     04h
                add     al,03h
                stosw
                xchg    si,ax
                mov     cl,[bp+si]
                jcxz    L0131h
L0144h:         sub     al,20h ;' '             ;sub al,startCh
                jcxz    L019dh
                je      L0100h
;
L014ah:         mov     ah,00h                  ;Keyboard - Get keystroke
                int     16h
                dec     ah
                jne     L0144h
                mov     al,03h
                int     10h
                int     20h                     ;Terminate program
L0158h:         call    L01d9h
                xchg    dx,ax
                sub     dl,[bp-77h]             ;sub dl,[bp+score-field+1]
L015fh:         test    dh,dh
                jns     L0165h
                inc     word [bp-78h]           ;inc word [bp-78]
L0165h          =       $-01h
                db      0d6h                    ;mov dh,dl +hidden dummy setalc
L0167h:         call    L01efh
                dec     dh
                jg      L0167h
                mov     bx,0100h                ;move piece down
                call    L01aah
                jcxz    L015fh
L0176h:         mov     di,bx
                mov     cl,0ah
L017ah:         cmp     [bp+di],ch              ;is field[di] empty
                je      L0194h
                inc     di
                loop    L017ah
L0181h:         mov     cl,[bp+di+Lff00h]       ;mov cl,[bp+di-fieldWidth]
                mov     [bp+di],cl
                dec     di
                jne     L0181h
                shl     ax,1
                add     [bp-78h],ax             ;add [bp+score-field],ax
                mov     cl,dl
                call    L01fah
L0194h:         inc     bh
                cmp     bh,17h
                jnc     L011ch
                jmp     L0176h
L019dh:         jne     L01a1h
                mov     dh,0ffh
L01a1h:         sub     al,4ah ;'J'             ;sub al,leftCh-startCh
                cmp     al,03h
                jnc     L01eeh
                cbw
                dec     ax
                xchg    bx,ax
;
L01aah:         call    L01d9h
                mov     di,si
                mov     cl,04h
L01b1h:         lodsw
                test    bx,bx
                jne     L01c8h
                cmp     [di-01h],ch             ;cmp [di+pieceC-pieceXY],ch
                je      L01d9h
                xchg    al,ah
                neg     ah
                add     ax,[di]
                sub     al,[di+01h]
                add     ah,[di]
                js      L01d9h
L01c8h:         add     ax,bx
                mov     [si+06h],ax             ;save newXY(N)
                xchg    di,ax
                cmp     [bp+di],ch              ;is field[di] free
                xchg    di,ax
                jne     L01d9h
                loop    L01b1h
                movsw                           ;piecxXY(N)=newXY(N)
                movsw
                movsw
                movsw
;
L01d9h:         mov     si,L0267h               ;mov si,pieceC-1
                lodsw
                mov     al,68h ;'h'
                aad     02h
                pusha
                mov     cl,04h
L01e4h:         xchg    di,ax
                lodsw
                xchg    di,ax
                xor     [bp+di],al              ;field[di] xor al
                loop    L01e4h
                popa
                mov     al,0ah
L01eeh:         ret
;
L01efh:         mov     ah,01h                  ;Keyboard - Check for keystroke
                int     16h
                je      L01f8h
                call    L014ah
L01f8h:         mov     cl,01h
;
L01fah:         pusha
                mov     ax,[bp-78h]             ;mov ax,[bp+score-field]
                mov     bx,000ah
                mov     cl,04h
L0203h:         cwd
                div     bx
                pusha
                xchg    cx,ax
                add     al,11h                  ;add al,(fieldX+12/2)-3
                xchg    dx,ax
                add     ax,0230h
                int     10h
                int     29h                     ;Dos - Fast console output
                popa
                loop    L0203h
                mov     si,0b8abh               ;field+(fHeight-1)*fWidth+10Bh
                mov     di,0e670h               ;((fHeight-1)*320+fieldX)*8
L021bh:         mov     dx,010ch
                sub     si,dx
L0220h:         lodsb
                mov     cl,08h
                pusha
                mov     dl,40h ;'@'
                mov     ah,74h ;'t'
L0228h:         mov     bx,cx
                mov     es,bp
                push    di
L022dh:         pusha
                rep     stosb
                popa
                add     di,dx
                dec     bx
                jne     L022dh
                pop     di
                dec     cx
                push    cs
seven:          pop     es                      ;note: dw 7
                db      00h,0e4h                ;add ah,ah
                jnc     L0240h
                adc     di,dx
L0240h:         add     al,ah
                jc      L0228h
                popa
                add     di,cx
                dec     dl
                jne     L0220h
                sub     di,0a60h                ;sub di,(320+10+2)*8
                jnc     L021bh
                int     1ah
                mov     bl,dl
L0255h:         int     1ah
                cmp     bl,dl
                je      L0255h
                popa
                loop    L01fah
                ret
tblXY           db      1dh,3dh,3eh,6eh,30h,17h,3ch
seed            dw      3039h
L0267h          =       $-01h

pieceC:
    


Description: 360 bytes tetris with .dsm data file for DASM
Download
Filename: tetris360.zip
Filesize: 1.37 KB
Downloaded: 418 Time(s)



Last edited by ATV on 18 Dec 2006, 08:10; edited 1 time in total
Post 14 Dec 2006, 12:08
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
Not bad, not bad at all. Smile BUT, the .ZIP only contains the .COM, a .BAT to run DASM, plus the tiny .DSM data file, so anybody wanting to download this should copy/paste the source into Notepad, TDE(W), or whatever and SAVE!

P.S. Here's a screenshot, if anyone's curious:


Description:
Filesize: 1.42 KB
Viewed: 11562 Time(s)

tetris360.png




Last edited by rugxulo on 15 Dec 2006, 21:11; edited 1 time in total
Post 15 Dec 2006, 21:05
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
I wish i didn't loose my floppy long ago... I don't see any special formatting, so i'm assuming that it would run off of a floppy. (and i might be wrong, the whole ms-dos thing was never explained to me very well...)

EDIT: Heck, the screenshot is bigger than the actual program itself...
Post 15 Dec 2006, 21:10
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
ATV



Joined: 31 Aug 2004
Posts: 109
Location: Finland
ATV
Sorry I have write too little information. Writing is not my best part.

That dsm file is data file for DASM that can be found in first page of this thread.
It has code/data tables and labels and comments. Unpack it same dir as DASM and run bat
then press F5 to save asm file, so asm file is not needed inside zip.
rugxulo, it's almost like steganography, asm file hidden inside data file.

Few important keys to use DASM:
F1 - Help
F4 - Set instruction type code/ascii/data
F5 - Save to asm file
F6 - Scan file to build label table
F9 - Set label
Shift+F9 - Set comment
F10 - change parameters
Post 18 Dec 2006, 08:11
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Quote:
C:\Documents and Settings\Kohlrak\Local Settings\Temporary Internet Files\Conten
t.IE5\MEXQ1YV1\Dasm102[1]\Dasm>dasm tetris.com
The system cannot execute the specified program.

C:\Documents and Settings\Kohlrak\Local Settings\Temporary Internet Files\Conten
t.IE5\MEXQ1YV1\Dasm102[1]\Dasm>pause
Press any key to continue . . .


I woudln't mind having it disassemble to another assembler and then moving it to fasm format, but that's kinda difficult for me. Maybe it's my computer, cause i don't have alot of software installed that others usually use. I'm usually just missing a program or have a setting different or something than everyone else.
Post 19 Dec 2006, 06:15
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
ATV



Joined: 31 Aug 2004
Posts: 109
Location: Finland
ATV
kohlrak, that error tells that windows can't find dasm.exe you should have dasm.exe + dtetris.bat + tetris.com + tetris.dsm all in same directory.
If you don't want to use 7zip or winzip or any other zip handling programs you should create new directory by yourself and copy those 4 files there.
Windows own zip handling is not good.

PS. You can also copy dasm.exe into your windows directory, so it always availabe.
Post 19 Dec 2006, 13:08
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
i did, maybe i did something wrong and didn't notice it, but oh well... I do specifically recal placing them in the same directory.
Post 19 Dec 2006, 21:36
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
ds316



Joined: 01 Jan 2007
Posts: 7
ds316
kohlrak wrote:
Only the program can be sure what their code is supposed to do, even then, sometimes they do not... No machine can think like a human, in turn, there is no perfect decompiler. All you can do is your best.


OllyDbg's analyzing engine is damn good at distinguishing between code/data.
And I'm pretty sure that OllyDbg plugins can make use of this engine, so it might be best to do it this way.
Post 01 Jan 2007, 09:44
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4225
Location: 2018
edfed
i think a decompiler is an emulator

an emulator translates instructions
Post 22 Oct 2007, 20:47
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386
> i think a decompiler is an emulator

NO. Shocked

A decompiler translates binary (back) into a higher language, including ASM at worst case. Disassembler is just a decompiler producing ASM output.

> an emulator translates instructions

NO. Shocked

An emulator executes them.

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 22 Oct 2007, 21:54
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386
> has somebody already made a disassembler for fasm which makes compilable code ?

NOT exactly, but:

FAQ

Nevertheless, the challenge is not to make compilable code, but understandable and modifiable code ...

Here NDISASM, DISTORM and BIEW are not ideal, the famous "IDA" might be marginally better, but it produces horrible MA$M syntax, is not free (?), and dropped DOS support 10 years ago Sad
Post 22 Oct 2007, 22:01
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4225
Location: 2018
edfed
to make compilable code i can :
db x,x,x,x,x,x,x
db x,x,x,x,x,x,x
etc etc...

to make modifiable code i need to analyse:

where are instructions
where are pointers
where are datas
what are equates
what is the memory model
what is the size of the datas
and creating labels for branchs and calls

__________________________________________________________________
to make a good program, you need to know axactlly what you want a long time before editing the first code line
_________________________________________________________________
Post 22 Oct 2007, 22:33
View user's profile Send private message Visit poster's website Reply with quote
penang



Joined: 01 Oct 2004
Posts: 59
penang
Is this project dead?
Post 04 May 2008, 15:14
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.