flat assembler
Message board for the users of flat assembler.

Index > Windows > Question: win16 application

Author
Thread Post new topic Reply to topic
tutenhamon



Joined: 16 Jan 2010
Posts: 27
Location: Polska (Poland)
tutenhamon
How I create win16 application using a FASM ?
I must use a format MZ directive and I ... ? (what's next?)
Post 22 Sep 2010, 17:21
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
You can't actually, fasm has no support for Win16 (NE format?). MZ format is for MS-DOS executables.
Post 22 Sep 2010, 17:44
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
Code:
format binary as 'exe'    

_________________
This is a block of text that can be added to posts you make.
Post 23 Sep 2010, 11:58
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
mindcooler wrote:
Code:
format binary as 'exe'    
Code:
format binary as 'exe'
db 'NE'
;...    
Post 23 Sep 2010, 12:15
View user's profile Send private message Visit poster's website Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael
LocoDelAssembly wrote:
You can't actually, fasm has no support for Win16 (NE format?).
Untrue, it's possible to create a NE file, using the method alluded to by mindcooler and revolution. Razz
Post 23 Sep 2010, 13:22
View user's profile Send private message Reply with quote
tutenhamon



Joined: 16 Jan 2010
Posts: 27
Location: Polska (Poland)
tutenhamon
Code:
format binary as 'exe'
use16
db 'MZ'
;dos header
db 'NE'       ;ID='NE'
db 0      ;Linker major version
db 0   ;Linker minor version
dw entry_table ;Offset of entry table (see below)
dw end_entry_table - entry_table  ;Length of entry table in bytes
dd 0 ;File load CRC (0 in Borland's TPW)
db 0b   ;Program flags, bitmapped :
             ;0-1 - DGroup type :
        ;0 - none
           ;1 - single shared
              ;2 - multiple
               ;3 - (null)
         ;2 - Global initialization
          ;3 - Protected mode only
            ;4 - 8086 instructions
              ;5 - 80286 instructions
             ;6 - 80386 instructions
             ;7 - 80x87 instructions
db 0b        ;Application flags, bitmapped
               ;0-2 - Application type
                     ;1 - Full screen (not aware of Windows/P.M. API)
                    ;2 - Compatible with Windows/P.M. API
                       ;3 - Uses Windows/P.M. API
          ;3 - OS/2 family application
                ;4 - reserved?
              ;5 - Errors in image/executable
             ;6 - "non-conforming program" whatever
            ;7 - DLL or driver (SS:SP info invalid, CS:IP points at FAR init routine called with
            ;AX=module handle which returns AX=0000h on failure, AX nonzero on successful initialization)
db 0       ;Auto data segment index
dw 0        ;Initial local heap size
dw 0        ;Initial stack size
dd start ;Entry point (CS:IP), CS is index into segment table
dd 0        ;Initial stack pointer (SS:SP) SS is index into segment table
dw 0       ;Segment count
dw 0  ;Module reference count
dw 0 ;Size of nonresident names table in bytes
dw 0       ;Offset of segment table (see below)
dw resource     ;Offset of resource table
dw 0       ;Offset of resident names table
dw 0 ;Offset of module reference table
dw 0       ;Offset of imported names table
                                                              ;(array of counted strings, terminated with a
                                                            ;string of length 00h)
dd 0    ;Offset from start of file to nonresident names table
dw 0   ;Count of moveable entry point listed in entry table
dw 0    ;File alignment size shift count 0 is equivalent to 9 (default 512-byte pages)
dw 0  ;Number of resource table entries
db 0       ;Target operating system
            ;0 - unknown
                ;1 - OS/2
           ;2 - Windows
                ;3 - European MS-DOS 4.x
            ;4 - Windows 386
            ;5 - BOSS (Borland Operating System Services)
db 0b  ;Other OS/2 EXE flags, bitmapped
            ;0 - Long filename support
          ;1 - 2.x protected mode
             ;2 - 2.x proportional fonts
         ;3 - Executable has gangload area
dw 0       ;Offset to return thunks or start of gangload area - whatever that means.
dw 0       ;offset to segment reference thunks or length of gangload area.
dw 0 ;Minimum code swap area size
db 0,1  ;Expected Windows version (minor version first)

start:
ret

entry_table:
end_entry_table:

resource:
    


what's next?
dos header?
entry table?
resource?
Post 24 Sep 2010, 22:01
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
tutenhamon,

You've forgot about IMAGE_DOS_HEADER.e_lfanew. That's how loader finds New Executable (and LE/LX/PE too). There was something with .e_lfarlc but I don't remember correctly what it was (.e_lfarlc > 0x1C, probably).

I've made simple NE in fasm as a container for .Fon font libraries (resource-only DLL); if you're interested, I can post it.
Post 25 Sep 2010, 05:02
View user's profile Send private message Reply with quote
tutenhamon



Joined: 16 Jan 2010
Posts: 27
Location: Polska (Poland)
tutenhamon
baldr Yes I'am interested this code.
Post 25 Sep 2010, 13:54
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
tutenhamon,

Remember, this is not supposed to do anything: it was written as a container for bitmap font resources.
Code:
use16 format binary as "Fon"

..fileoffset = 0

mz.header:

.magic          dw      'MZ'    ;00
.cblp           dw      mz.size mod 512 ;02
.cp             dw      (mz.size-1)/512 + 1 ;04
.crlc           dw      0       ;06
.cparhdr        dw      mz.header.size shr 4 ;08
.minalloc       dw      8       ;0a
.maxalloc       dw      8       ;0c
.ss             dw      0       ;0e
.sp             dw      160     ;10
.csum           dw      0       ;12
.ip             dw      mz.image.entry ;14
.cs             dw      0       ;16
.lfarlc         dw      mz.size ;18
.ovno           dw      0       ;1a
.res            rd      1       ;1c
                align   16      ;padding

..fileoffset = ..fileoffset+$-$$
.size = ..fileoffset

mz.image:
                org     0

.message        db      'Font library.',13,10,'$'

.entry:         mov     ah, 9
                mov     dx, .message+0x100
                int     0x21
                mov     ah, 0x4c
                int     0x21

                rb      0x3c-(mz.image+$-$$) ;padding
.e_lfanew       dd      ne.header

..fileoffset = ..fileoffset+$-$$
mz.size = ..fileoffset

ne.header = ..fileoffset
                org     0

.magic          dw      'NE'
.ver            db      5
.rev            db      1
.enttab         dw      ne.enttab
.cbenttab       dw      ne.enttab.size
.crc            dd      0
.flags          dw      0x8000
.autodata       dw      0
.heap           dw      0
.stack          dw      0
.csip           dd      0
.sssp           dd      0
.cseg           dw      0
.cmodref        dw      0
.cbnrestab      dw      ne.nresnametab.size
.segtab         dw      ne.segtab
.rsrctab        dw      ne.rsrctab
.resnametab     dw      ne.resnametab
.modreftab      dw      ne.modreftab
.impnametab     dw      ne.impnametab
.nresnametab    dd      ..nresnametab
.cmovent        dw      0
.align          dw      4
.cres           dw      0
.exetyp         db      2
.flagsother     db      0
.pretthunks     dw      0
.psegrefbytes   dw      0
.swaparea       dw      0
.expver         dw      0x030a

ne:
.segtab:
.segtab.size = $-.segtab

.rsrctab:
                dw      4
                dw      0
.rsrctab.size = $-.rsrctab

struc cstr [data] {
  local ..end
  db ..end-($+1),data
  ..end:
}

.resnametab:
.modname        cstr    "72DPI"
                dw      0
.last           cstr    ""
.resnametab.size = $-.resnametab

.modreftab:
.modreftab.size = $-.modreftab

.impnametab:
.impnametab.size = $-.impnametab

.enttab:
                db      0
.enttab.size = $-ne.enttab

..nresnametab = ..fileoffset+$-$$
.nresnametab:
.fontname       cstr    "FONTRES 100,72,72:72DPI (16)"
                dw      0
                db      0
.nresnametab.size = $-.nresnametab    
Post 25 Sep 2010, 13:58
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
OpenWatcom supports Win16 code, so you could take a look there for more details.
Post 05 Oct 2010, 04:50
View user's profile Send private message Visit poster's website Reply with quote
Kenneth Zheng



Joined: 30 Apr 2008
Posts: 14
Location: Shanghai, China
Kenneth Zheng
objconv can covert 16bit and 32bit COFF format.
You can use below weblink to find it:

http://www.agner.org/optimize

[/url]

_________________
Pure Assembly Language Funs
Post 07 Oct 2010, 14:29
View user's profile Send private message MSN Messenger Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
Kenneth, you keep calling it COFF, which is confusing. Unless I'm mistaken, COFF doesn't support 16-bit (maybe GNU extensions, I dunno). Are you talking about OMF/OBJ or COFF as in DJGPP?
Post 11 Oct 2010, 20:04
View user's profile Send private message Visit poster's website 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.

Powered by rwasa.