flat assembler
Message board for the users of flat assembler.

Index > Windows > Converting DOS code into Windows

Author
Thread Post new topic Reply to topic
me239



Joined: 06 Jan 2011
Posts: 200
me239
Hey everyone, I just ran into a bit of a dilemma with my TXT parser I have. The problem is it can't take any files larger that 64kb (obviously) so I would love to convert it to a Windows cmdline driven PE. It's a very simple program, I just don't know too much about Windows file editing. Basically the point of the program is to find multiple occurrences of hex 0x0D and replace them with 0x00.
Code:
org 100h
start:
        mov     ax, 3d02h
        mov     dx, filen
        int     21h
        jc      error
        xchg    ax, bx
        mov     ah, 3fh
        mov     cx, 9ah
        push    cx
        mov     dx, buff
        int     21h
        mov     si, buff
        pop     cx
        mov     word[size], cx
loop1:
        lodsb
        cmp     al, 0dh
        jz      @f
        loop    loop1
        jmp     done
@@:
        lodsb
        cmp     al, 0dh
        jz      @f
        dec     si
        jmp     loop1
@@:
        sub     si, 2
        mov     byte[si], 0
        add     si, 2
        jmp     loop1
done:
        mov     ax, 4200h
        xor     cx, cx
        cwd
        int     21h
        mov     ah, 40h
        mov     dx, buff
        mov     cx, [size]
        int     21h
error:
        int     20h
size    dw      0
filen   db      'enc.txt', 0
buff:
    
Post 29 Sep 2011, 04:33
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
CreateFile()
ReadFile()
cld
mov esi,buff
mov ecx,file_size_or_bytes_read_
@@:
mov ah,0x00
lodsb
cmp al,0dh
jne k
xchg ah,[esi]
k:
dec ecx
jnz @B
WriteFile --- If needed.
CloseHandle()

look up those APIs, i'm posting from my psp so i can't type much
Post 29 Sep 2011, 09:04
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
Good, but LODSB will increment ESI, so "XCHG AH, [ESI-1]" would be better. Also, why not just "MOV [ESI-1], AH"?
Post 29 Sep 2011, 14:17
View user's profile Send private message Send e-mail Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
^^You are right I wasn't thinking there. Very Happy thanks
Post 29 Sep 2011, 16:37
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239
I tried writing a simple program to write "Hello!" to a file with no luck Sad
Code:
Code:
format PE GUI 4.0
entry start
include 'win32a.inc'
start:
        invoke  CreateFile, filen, GENERIC_WRITE, 2, NULL, 3, 80h, NULL, NULL
        invoke  WriteFile, buff, 6
        invoke  ExitProcess
filen   db      'test.txt', 0
rights  db      2
buff    db      'Hello!', 0
section '.idata' import data readable writeable
        library  kernel32, 'KERNEL32.DLL'
        import   kernel32,\
                 CreateFile, 'CreateFileA',\
                 WriteFile, 'WriteFile',\
                 ExitProcess, 'ExitProcess'
    
Post 29 Sep 2011, 17:25
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
lol lmao.......you are really a noob at win32 API (no offense)
hold on let me get on my computer so i can type fast and help you
Post 29 Sep 2011, 17:42
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239
typedef wrote:
lol lmao.......you are really a noob at win32 API (no offense)
hold on let me get on my computer so i can type fast and help you
I got it working
Code:
format PE GUI 4.0
entry start
include 'win32a.inc'
start:
        invoke  CreateFile, filen, GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0
        mov     [hFile], eax
        invoke  WriteFile, [hFile], buff, 6, bwrt, 0
        invoke  ExitProcess
filen   db      'test.txt', 0
rights  db      2
buff    db      'Hello!', 0
hFile   dd      0
bwrt    db      0
section '.idata' import data readable writeable
        library  kernel32, 'KERNEL32.DLL'
        import   kernel32,\
                 CreateFile, 'CreateFileA',\
                 WriteFile, 'WriteFile',\
                 ExitProcess, 'ExitProcess'
    
Post 29 Sep 2011, 18:31
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Yea, sorry.. My friend came over and I was playing MK vs DC & God Of War 3 ... Very Happy
Post 30 Sep 2011, 02:04
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239
nice, I played L4D2
Post 30 Sep 2011, 04:29
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
haven't played that yet. is it online too?
Post 30 Sep 2011, 13:25
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239
typedef wrote:
haven't played that yet. is it online too?
Look up Left 4 Dead 2
Post 01 Oct 2011, 03:22
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.