flat assembler
Message board for the users of flat assembler.
Index
> Windows > [solved]:playing with 16bit winincludes Goto page Previous 1, 2, 3 |
Author |
|
ProMiNick 07 Apr 2020, 23:39
Thanks, Tomasz.
I update package with thour fix https://yadi.sk/d/HTs1wxZvp6BmYw to pass 2 zeroes to stack in win16 I used different constructions: Code: dword 0 dword 0:0 0:0 far 0:0 NULL:NULL I placed fasmd.exe to bin with approptiate ini. I replaced all whitespaces in paths and check for 8.3 format them again - look all forced to this format. about exports as donor I used krnl386.exe & its exports: Code: KRNL386.EXE NE($400) NE.EntryTable = $11D ($51D) NE.SizeOfEntryTable = $9B7 NE.SizeOfNonResNamesTable = $1093 NE.ResNamesTable = $10C ($50C) NE.OffStartNonResNamesTable = $00000ED4 NE.MovEntryCount = $EA (234) ResNamesTable: 06 4B 45 52 4E 45 4C 00 00 04 5F 5F 47 50 56 01 00 len| name| ord .1: 6,'KERNEL',$0000 .2: 4, '__GP',$0156 .end: 0 EntryTable: count| segidx flags|int $3F|movsegidx|offset ;comment .1:{header} 2, 1 {items} NE_ET_EXPORTED, $9C42 (FATALEXIT) ord#1 NE_ET_EXPORTED, $82DB (EXITKERNEL) ord#2 .2:{header} 12, NE_SEGNDX_MOVABLE {items} NE_ET_EXPORTED,int $3F, 3, $056E (GETVERSION) ord#3 NE_ET_EXPORTED,int $3F, 2, $3523 (LOCALINIT) ord#4 NE_ET_EXPORTED,int $3F, 2, $0136 (LOCALALLOC) ord#5 NE_ET_EXPORTED,int $3F, 2, $017A (LOCALREALLOC) ord#6 NE_ET_EXPORTED,int $3F, 2, $0152 (LOCALFREE) ord#7 NE_ET_EXPORTED,int $3F, 2, $0166 (LOCALLOCK) ord#8 NE_ET_EXPORTED,int $3F, 2, $01B0 (LOCALUNLOCK) ord#9 NE_ET_EXPORTED,int $3F, 2, $019C (LOCALSIZE) ord#10 NE_ET_EXPORTED,int $3F, 2, $33B6 (LOCALHANDLE) ord#11 NE_ET_EXPORTED,int $3F, 2, $01C4 (LOCALFLAGS) ord#12 NE_ET_EXPORTED,int $3F, 2, $33D1 (LOCALCOMPACT) ord#13 NE_ET_EXPORTED,int $3F, 2, $01D8 (LOCALNOTIFY) ord#14 .3:{header} 12, 1 {items} NE_ET_EXPORTED, $00C0 (GLOBALALLOC) ord#15 NE_ET_EXPORTED, $0121 (GLOBALREALLOC) ord#16 NE_ET_EXPORTED, $00DC (GLOBALFREE) ord#17 NE_ET_EXPORTED, $010D (GLOBALLOCK) ord#18 NE_ET_EXPORTED, $0160 (GLOBALUNLOCK) ord#19 NE_ET_EXPORTED, $014C (GLOBALSIZE) ord#20 NE_ET_EXPORTED, $00F9 (GLOBALHANDLE) ord#21 NE_ET_EXPORTED, $017D (GLOBALFLAGS) ord#22 NE_ET_EXPORTED, $0248 (LOCKSEGMENT) ord#23 NE_ET_EXPORTED, $025C (UNLOCKSEGMENT) ord#24 NE_ET_EXPORTED, $3DC5 (GLOBALCOMPACT) ord#25 NE_ET_EXPORTED, $3B01 (GLOBALFREEALL) ord#26 .4:{header} 1, NE_SEGNDX_MOVABLE {items} NE_ET_EXPORTED,int $3F, 2, $00A7 (GETMODULENAME) ord#27 .5:{header} 6, 1 {items} NE_ET_EXPORTED, $3E5F (GLOBALMASTERHANDLE) ord#28 NE_ET_EXPORTED, $5A46 (YIELD) ord#29 NE_ET_EXPORTED, $59CC (WAITEVENT) ord#30 NE_ET_EXPORTED, $5AE5 (POSTEVENT) ord#31 NE_ET_EXPORTED, $5C8F (SETPRIORITY) ord#32 NE_ET_EXPORTED, $5FB1 (LOCKCURRENTTASK) ord#33 .6:{header} 1, 0 SKIPPED ord#34 .7:{header} 2, 1 {items} NE_ET_EXPORTED, $5B14 (GETTASKQUEUE) ord#35 NE_ET_EXPORTED, $60EA (GETCURRENTTASK) ord#36 .8:{header} 1, NE_SEGNDX_MOVABLE {items} NE_ET_EXPORTED,int $3F, 3, $2BCE (GETCURRENTPDB) ord#37 .9:{header} 3, 0 SKIPPED ord#38 SKIPPED ord#39 SKIPPED ord#40 .10:{header} 2, 1 {items} NE_ET_EXPORTED, $8220 (ENABLEDOS) ord#41 NE_ET_EXPORTED, $8220 (DISABLEDOS) ord#42 .11:{header} 2, 0 SKIPPED ord#43 SKIPPED ord#44 .12:{header} 8, NE_SEGNDX_MOVABLE {items} NE_ET_EXPORTED,int $3F, 2, $0102 (LOADMODULE) ord#45 NE_ET_EXPORTED,int $3F, 2, $0004 (FREEMODULE) ord#46 NE_ET_EXPORTED,int $3F, 2, $0049 (GETMODULEHANDLE) ord#47 NE_ET_EXPORTED,int $3F, 2, $0060 (GETMODULEUSAGE) ord#48 NE_ET_EXPORTED,int $3F, 2, $0074 (GETMODULEFILENAME) ord#49 NE_ET_EXPORTED,int $3F, 2, $002C (GETPROCADDRESS) ord#50 NE_ET_EXPORTED,int $3F, 3, $01A9 (MAKEPROCINSTANCE) ord#51 NE_ET_EXPORTED,int $3F, 3, $01C6 (FREEPROCINSTANCE) ord#52 .13:{header} 1, 1 {items} NE_ET_EXPORTED, $0655 (CALLPROCINSTANCE) ord#53 ... .N:{header} 2,NE_SEGNDX_REFCONST {items} NE_ET_EXPORTED, $0003 (__AHSHIFT) ord#113 NE_ET_EXPORTED, $0008 (__AHINCR) ord#114 ... .O:{header} 2,NE_SEGNDX_REFCONST {items} NE_ET_EXPORTED, $F000 (__ROMBIOS) ord#173 NE_ET_EXPORTED, $A000 (__A000H) ord#174 .P:{header} 3, 1 {items} NE_ET_EXPORTED, $4911 (ALLOCSELECTOR) ord#175 NE_ET_EXPORTED, $0092 (FREESELECTOR) ord#176 NE_ET_EXPORTED, $00A6 (PRESTOCHANGOSELECTOR) ord#177 ... .Q:{header} 2,NE_SEGNDX_REFCONST {items} NE_ET_EXPORTED, $0001 (__WINFLAGS) ord#178 NE_ET_EXPORTED, $D000 (__D000H) ord#179 ... .R:{header} 1, 4 {items} NE_ET_EXPORTED+NE_ET_SHARED, $2320 (__GP) ord#342 ... .end: 0 NonResNamesTable: len| name| ord ;comment .1: 47,'Microsoft Windows Kernel Interface Version 4.00',$0000 .2: 11, 'NETBIOSCALL',$0067 (103) .3: 13, 'SWITCHSTACKTO',$006C (108) .4: 4, 'K213',$00D5 (213) .5: 24, 'GETPRIVATEPROFILESECTION',$01A2 (418) .6: 8, 'FINDATOM',$0045 (69) .7: 10, 'GLOBALFREE',$0011 (17) ... .end: 0 exports of other dlls are mixed in ResNamesTable & NonResNamesTable. as etalon(kernel from MS) they all should be in NonResNamesTable. becaause of ResNamesTable is splitted from EntryTable by imports and NonResNamesTable follows just after EntryTable it is more convinient. to be continued... |
|||
07 Apr 2020, 23:39 |
|
Tomasz Grysztar 09 Apr 2020, 08:37
ProMiNick wrote: I update package with thour fix BTW, for FASMD using relative paths in INCLUDE is not very useful, because navigating the file system to find and open file causes the current directory to be changed. |
|||
09 Apr 2020, 08:37 |
|
ProMiNick 09 Apr 2020, 23:10
https://yadi.sk/d/HTs1wxZvp6BmYw updated (eax to ax corrected too)
new: realized export macro (all demos & project rewritten to use it passively). other NE macros modified to interact with export if such interaction present. Code: macro export dllname,[label,string] { common local module,addresses,names,ordinal,count,bundle,type,tmp modulename dllname count = 0 type = -1 EntryTable: ;export ordinals match any,label \{ forward local ordnum,ordtype,bundlesize,bundletype count = count + 1 ordnum = count match ,label \\{ match skipcount,string \\\{ count = count + skipcount - 1 \\\} ordtype = 0 \\} match first:second,label:& \\{ match &,second \\\{ ordtype = NE_SEGNDX_REFCONST \\\} match offs:&,second \\\{ match any more rest,first:: \\\\{ match :,rest \\\\\{ ordtype = movableof@\\\\#any \\\\\} match ::,rest \\\\\{ ordtype = movableof@\\\\#more \\\\\} \\\\} \\\} \\} if type<>ordtype bundletype = type type = ordtype end if common type = -1 count = 0 reverse if type<>ordtype count = 1 else count = count + 1 end if match ,label \\{ match skipcount,string \\\{ count = count + skipcount - 1 \\\} \\} if defined bundletype bundlesize = count end if forward if defined bundletype db bundlesize,bundletype end if match any =shared rest,:label:shared: \\{ match :,any \\\{ db NE_ET_EXPORTED+NE_ET_SHARED \\\} match :,rest \\\{ db NE_ET_EXPORTED \\\} \\} if ordtype = NE_SEGNDX_MOVABLE int $3F match hasseg:offs,label \\{ match any more rest,hasseg:: \\\{ match :,rest \\\\{ db idxof@\\\#any \\\\} match ::,rest \\\\{ db idxof@\\\#more \\\\} \\\} \\} end if match hasseg:offs,label \\{ dw offs \\} if ordtype = NE_SEGNDX_REFCONST match any more rest,label:: \\\{ match :,rest \\\\\{ dw any \\\\\} match ::,rest \\\\\{ dw more \\\\\} match first:rest,label:& \\{ match &,rest \\\{ ordtype = NE_SEGNDX_REFCONST \\\} match offs:&,rest \\\{ match expr scnd rest1,first:: \\\\{ match :,rest1 \\\\\{ ordtype = movableof@\\\\#expr \\\\\} match ::,rest1 \\\\\{ ordtype = movableof@\\\\#scnd \\\\\} \\\\} \\\} \\} common \} db 0 SizeOfEntryTable = $-EntryTable org $% NonResNamesTable: ;export names if defined moduledescriptionsize db moduledescriptionsize repeat moduledescriptionsize load tmp byte from ..moduledescription:%-1 db tmp end repeat dw 0 end if match any,label \{ forward match any,label \\{ match more,string \\\{ pascalstr string dw ordnum \\\} \\} common \} db 0 SizeOfNonResNamesTable = $-NonResNamesTable } and this (not included in attachment by link) Code: macro noexports { local tmp EntryTable: db 0 SizeOfEntryTable = 1 org $% NonResNamesTable: if defined moduledescriptionsize db moduledescriptionsize repeat moduledescriptionsize load tmp byte from ..moduledescription:%-1 db tmp end repeat dw 0 end if db 0 SizeOfNonResNamesTable = $-NonResNamesTable } this (a kind of syntax shugar) looks more friendly in case of no exports |
|||
09 Apr 2020, 23:10 |
|
ProMiNick 10 Apr 2020, 09:22
previous update was very buggy - fixed
https://yadi.sk/d/HTs1wxZvp6BmYw - updated again: unclosed ifs - fixed [EDITED: before was stupid post relative with next]same names used as match params on different nesting levels - fixed. unwanted definition of bundle elements flag when no data of elements should be - fixed in package present 2 rudiments: 1. test.ASM in root with testing of all variants that could take place in label param of macro export. 2. one more minipad.asm in projects with testing of export (not dll but...) [EDITED 2020/04/10 18:45] https://yadi.sk/d/HTs1wxZvp6BmYw - updated again in header added ability to produce DLL flags contents in NE structure, in projects added usedll with donor, when I intermix working exe with my dll, my exe with working dll and compare it with donor exe & dll interaction - all 3 cases differs. Content that produce my macros has binary output as I expect, so need investigation of aspects I still dont know. [EDITED 2020/04/11 2:07] not updated link (additions offline) in nedemo I described registers values: Code: start: ;registers at entry to application ;ax - zero ;bx - size of stack ;cx - size of heap ;di - app. instance ;si - prev. app. instance ;bp - zero ;es - segment address of PSP ;ds - segment address of automatic data segment ;ss - same as ds register ;sp - app. top stack invoke InitTask ; ;register values returned by InitTask ;ax - 0(error),1(OK) ;es:bx - lpCmdLine ;cx - stack limit ;di - task instance (interesting its the same as app. instance or not) ;si - prev. program instance (interesting its the same as prev. app. instance or not) ;dx - nCmdShow parameter ;es - segment address of PSP ;16 bytes at ds:[0] - information about the stack or ax, ax jz .err in demodll I described registers values too: Code: proc16 DLLEntry far ;registers at entry to library ;ax - module handle ;bx - ? size of stack??? ;cx - size of heap ;di - app. instance ;ds - lib. data segment (case of SINGLEDATA), caller data segment (case NOAUTODATA or MULTIPLEDATA) ;es:si - lpCmdLine ;ss - ? caller data segment??? invoke LocalInit,ds:0,cx or ax,ax jnz .skipUnlock invoke UnlockSegment, -1 .skipUnlock: mov ax,TRUE ret endp |
|||
10 Apr 2020, 09:22 |
|
ProMiNick 12 Apr 2020, 04:15
https://yadi.sk/d/HTs1wxZvp6BmYw updated again
new: pair "DLLCALL.exe" & "DLLSRC.dll" from "\PROJECTS\EXECS\WINDOWS\WIN16\BASIC\USEDLL" are now worked. "DLLSRC.dll" from "\PROJECTS\EXECS\WINDOWS\WIN16\BASIC\USEDLL\DONOR" compiled with Borland C++ at 1991 and reduced to 480 bytes by cutting HLL (~8kb HLL) is able to be called by both my "DLLCALL.exe" & "DLLCALL.exe" from "\PROJECTS\EXECS\WINDOWS\WIN16\BASIC\USEDLL\DONOR" compiled with Borland C++ at 1991 and reduced to 480 bytes by cutting HLL (~5kb HLL). But mine dll not friends with Borland C++ compiled exe. Because of that all still in projects. So, I missed smthing in DLL, or Borland created exe with redundant requirements. well here is comparison of "DLLCALL.exe": Code: Differences: Fasm port borland C++ original (of couse C++ produce more huge code, this is what left after cutting HLL rudiments) (I cut them very accuracy) Program Entry Point (CS:IP) 0001:0010 0001:0000 Initial Stack Pointer (SS:SP) 0002:0000 0002:0000 Initial Local Heap Size 0000h ( 0. ) 0400h ( 1024. ) Program Flags (0310): Application (000A): Application No data Multiple data Uses windowing API Protected mode Other EXE Flags (0008): Fastload area (0000): (start: 00000130, size: 000000A0) IMPORTS via names via ordinals ============================== ============================== ============================= Segment Number: 1 Alloc Size: 0040h 004Eh Offset in the file:0130h,Length:0040h 004Eh Attributes (0D50): CODE (1D50): CODE Moveable Moveable Preloaded Preloaded Relocations Relocations DPL: 3 Discardable DPL: 3 db 10h dup(0) start: call InitTask call InitTask or ax, ax or ax, ax jz .error jz .error mov [word_20], di push -1 call LockSegment push 0 push 0 call WaitEvent call WaitEvent push di push [word_20] call InitApp call InitApp or ax, ax or ax, ax jz .error jz .error push ds push ss push _msgText push _msgText call @Msg$QNZC call @Msg$QNZC push -1 call UnockSegment xor ax, ax jmp .exit jmp .exit .error: mov al, 1 mov al, -1 .exit: mov ah, 4Ch mov ah, 4Ch call Dos3Call int 21h retf db 0Bh dup(0) align 4 db 0 (interesting this byte should be 16th byte of 2nd segment, why it here, and it in cseg01:0040 that address is outer of 1st segment end) ============================== ============================== ============================= Segment Number: 2 Alloc Size: 0020h 0022h Offset in the file:01B0h,Length:0020h 0022h Attributes (0C51): DATA (0C51): DATA Moveable Moveable Preloaded Preloaded DPL: 3 DPL: 3 ;org 1 ;org 0 db 0Fh dup(0) db 10h dup(0) dseg02:0010 _msgText db 'Hello from DLL!',0 db 'Hello from DLL!',0 word_20 dw 0 align 10h code differences: in original locksegment around all payload logic, using ss instead of ds, retf that never be executed, redundant preserve of di, that is untrashable by api calls. flag differences: in original protected mode & multyinstancing of autodata segment instead of absence of autodata segment. more flag differences: in original fast load area is absent. And here is comparison of "DLLSRC.dll": Code: Differences: Fasm port borland C++ original Program Entry Point (CS:IP) 0001:0010 0001:0000 Initial Stack Pointer (SS:SP) 0002:0000 0002:0000 Initial Stack Size 2000h ( 8192. ) 0000h ( 0. ) Program Flags (8301): DLL (8009): DLL Single data Single data Uses windowing API Protected mode Other EXE Flags (0008): Fastload area (0000): (start: 00000140, size: 000000C0) IMPORTS via names via ordinals EXPORTS via nonresident names table via nonresident names table (originaly was via resident names table - patched) ============================== ============================== ============================= Segment Number: 1 Alloc Size: 0064h 005Eh Offset in the file:0140h,Length:0064h ...:0130h,Length:005Eh Attributes (0D50): CODE (1D50): CODE Moveable Moveable Preloaded Preloaded Relocations Relocations DPL: 3 Discardable DPL: 3 db 10h dup(0) start: push si push si push di push di push ds push ds push 0 push 0 push cx push cx call LocalInit call LocalInit or ax, ax or ax, ax jz .locret jz .locret sub sp, 6 sub sp, 6 mov ax, seg dseg02 mov ax, seg dseg02 mov ds, ax mov ds, ax pop cx pop cx pop ax pop ax jcxz .skip_unlock jcxz .skip_unlock push -1 push -1 call UnockSegment call UnockSegment .skip_unlock: mov ax, TRUE mov ax, TRUE pop ds pop ds .locret: pop di pop di pop si pop si retf retf External Entry #1 Attributes (0003): Moveable Exported Shared dataseg WEP: push bp mov bp, sp mov ax, TRUE mov ax, TRUE leave retf 2 retf 2 External Entry #1 External Entry #2 Attributes (0001): Moveable Attributes (0003): Moveable Exported Exported Shared dataseg @MSG$QNZC: oldbp = word ptr 0 farret = dword ptr 2 arg_0 = word ptr 6 arg_2 = word ptr 8 push bp push bp mov bp, sp mov bp, sp push ds push ds mov ax, seg dseg02 mov ax, seg dseg02 mov ds, ax mov ds, ax push 0 push 0 push [bp+arg_2] push [bp+arg_2] push [bp+arg_0] push [bp+arg_0] push ds push ds push _title push _title call MessageBox call MessageBox pop ds pop ds pop bp pop bp retf 4 retf 4 align 10h db 0Eh dup(0) align 4 ============================== ============================== ============================= Segment Number: 2 Alloc Size: 0018h 001Ah Offset in the file:01B0h,Length:0018h ...:01C0h,Length:001Ah Attributes (0C51): DATA (0C71): DATA Moveable Moveable Preloaded Pure DPL: 3 Preloaded DPL: 3 db 10h dup(0) db 10h dup(0) dseg02:0010 _title db 'DLLDEMO',0 db 'DLLSRC',0 align 10h db 3 dup(0) align 8 maybe all is simpler than I thought: my exe imports by name (original C++ variant by ordinal), exports named properly in both dlls, but their ordinals are different. |
|||
12 Apr 2020, 04:15 |
|
ProMiNick 12 Apr 2020, 20:37
all was because of error in export macro:
Code: common type = -1 count = 0 reverse if type<>ordtype count = 1 type = ordtype ; this line was absent previously else count = count + 1 end if match ,label \\{ match skipcount,string \\\{ count = count + skipcount - 1 \\\} \\} if defined bundletype bundlesize = count end if forward for now dont updated. I test solution. names could be imported in any mixed register, but export allow only A-Z@$_, not a-z. |
|||
12 Apr 2020, 20:37 |
|
ProMiNick 12 Apr 2020, 23:35
https://yadi.sk/d/HTs1wxZvp6BmYw updated again.
DLLSRC.ASM & DLLCALL.ASM are now in DEMOS:"\DEMOS\EXECS\WINDOWS\WIN16\BASIC\DLL" - because they work as expected in all aspects (sources I used as donor from 15.04.94, soon would be 26 years ). |
|||
12 Apr 2020, 23:35 |
|
ProMiNick 15 Apr 2020, 20:33
https://yadi.sk/d/HTs1wxZvp6BmYw updated: small fixes in proc16.inc. win16 strucs corrected and extended with commctrl (analog to comctl32) structs some equates are extended too (windows equates share all bitnesses). in resources added RT_TOOLBAR implementation.
dialog still not processed by procedure that assigned to it as dlgproc - but it isn`t related to NE format. (I played with dialod in donor without result, when I patched in dialog creation parent window to 0 it even not created, so maybe it requires parent window other then desktop) So NE specification I think is done. Tomasz, can thou produce fasmg implementation? and moreover can thou support NE in fasm natively? thanks anyway. Because there is no splitting on GUI & CUI I could suggest format: format NE APP 3.0 as 'exe' and format NE DLL 3.0 as 'exe' and format NE DLL 3.0 as 'dll'. And I placed uninitialized data in segments because I couldn`t prevent this data to go to output. And If think about guys that reversing NE I would prefer that all relocated segments had size $XXXE, so way reloc size end paragraph and each reloc pair would be aligned at $10 border. [EDITED 16/04/2020 17:16] https://yadi.sk/d/HTs1wxZvp6BmYw updated. nothing specialy related to NE or win16 unchanged. But fixed old bug of this my package in structs macros, that ignores anonymous members for union size calculation (maybe not fixed finally). [EDITED 18/04/2020] https://yadi.sk/d/HTs1wxZvp6BmYw updated. bugfix of previous update successfully tested. for PEB & TEB declaration used another approach: defined only members as constants. PEBs defined completely, but TEBs defined only with common to all windowses parts (it is enought at current state). Last edited by ProMiNick on 18 Apr 2020, 01:02; edited 3 times in total |
|||
15 Apr 2020, 20:33 |
|
Tomasz Grysztar 16 Apr 2020, 07:59
ProMiNick wrote: Tomasz, can thou produce fasmg implementation? and moreover can thou support NE in fasm natively? However, if anyone attempts a project like fasmg NE formatter based on your work for fasm 1, I'm willing to provide as much support as I can, giving hints and helping to solve potential problems. As for the native formatters, I no longer consider working on any - even with Mach-O, which was initially planned for inclusion in fasm 1, I ended up making a fasmg implementation only. The macro-based formatters are so much more flexible, powerful and easier to maintain, that I see no good reason to go back to making fasm-like native ones. Especially since now we have CALM to make everything better. |
|||
16 Apr 2020, 07:59 |
|
alexfru 16 Jul 2020, 06:54
ProMiNick wrote:
FYI, this has been fixed in NASM 2.15.03rc7. |
|||
16 Jul 2020, 06:54 |
|
Goto page Previous 1, 2, 3 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.