Hi John
One obstacle to doing this:
The Assembler produces a script which defines the memory image to be linked and o2link turns this into binary. But this memory image must then be compacted and post-processed to the PE file format.
This is done with the MakePE function in o2hdrs.bas.
Oxygen can emit a machine script for the memory image but not for the PE file itself.
This means you will need to port the MakePE function and its dependencies as well as o2link then feed the output of the linker into this function to generate the PE file.
I am refactoring makePE right now and will post an update soon.
Charles
Here is a machine script for "Hello World!"
`MZ` 90 00
03 00 00 00
04 00 00 00
FF FF 00 00
B8 00 00 00
00 00 00 00
40 00 00 00
$20
hle8
0E 1F BA 0E
00 B4 09 CD
21 B8 01 4C
CD 21
`This program cannot be run in DOS mode.` 0d 0a 00
/e8
`PE` 00 00
hw014c
hw0005
hl4E331D62
hl0
hl0
hw00e0
hw0102
hw010b 'MAGIC
02
00
hl0
hl0
hl00005000
ga _main_
ga _code_
ga base_of_data
hg00400000
hl1000
hl200
hw4
hw0
hw1
hw0
hw4
hw0
hl0
hl5000
hl400
hl0
hw2
hw0
hg00100000
hg00001000
hg00100000
hg00001000
hl0
hl10
hl0 hl0
ga imports hl200
ga resources hl0
$68
`.text` 00 00 00 hl00000000 ga _code_ hl0000 $10 hl60000020
`.data` 00 00 00 hl40000000 ga _data hl0200 $10 hlc0000040
`.bss` 00 00 00 00 hl00005000 ga bssdata hl0000 $10 hlc0000080
`.idata` 00 00 hl02000000 ga imports hl0200 $10 hlc0000040
`.rsrc` 00 00 00 hl02000000 ga resources hl0200 $10 hl40000040
/0ff0 e9 gf _o2_
/+1000
'
._code_ ' ._code_
._main_ ' ._main_
E8 gl get_bss ' call get_bss
8B F8 ' mov edi,eax
E8 gl get_iat ' call get_iat
8B D8 ' mov ebx,eax
89 9F 58 02 00 00 ' mov [edi+600],ebx
6A 00 ' push 0
FF 53 0C ' call [ebx+12]
89 87 60 02 00 00 ' mov [edi+608],eax
9b db e3 ' finit
E8 gf get_oxygen ' call fwd get_oxygen
83 F8 00 ' cmp eax,0
0F 84 gf nend ' jz fwd nend
FF D0 ' call eax
8B D8 ' mov ebx,eax
E8 gf _o2_ ' call fwd _o2_
E8 gl get_bss ' call get_bss
8B F8 ' mov edi,eax
8B 9F 58 02 00 00 ' mov ebx,[edi+600]
8B 87 68 02 00 00 ' mov eax,[edi+616]
83 F8 00 ' cmp eax,0
0F 84 gf noxyfree ' jz fwd noxyfree
50 ' push eax
FF 53 08 ' call [ebx+8]
.noxyfree ' .noxyfree
.nend ' .nend
6A 00 ' push 0
8B C4 ' mov eax,esp
50 ' push eax
FF B7 60 02 00 00 ' push [edi+608]
FF 53 14 ' call [ebx+20]
FF 53 18 ' call [ebx+24]
.get_iat ' .get_iat
E8 gf here ' call fwd here
.here ' .here
58 ' pop eax
81 E8 ga here ' sub eax,here
81 C0 ga import_address_table ' add eax,import_address_table
C3 ' ret
.get_bss ' .get_bss
E8 gf here ' call fwd here
.here ' .here
58 ' pop eax
81 E8 ga here ' sub eax,here
81 C0 ga bssdata ' add eax,bssdata
C3 ' ret
.get_oxygen ' .get_oxygen
57 ' push edi
68 66 67 00 00 ' push 0x00006766
68 65 6E 2E 63 ' push 0x632e6e65
68 6F 78 79 67 ' push 0x6779786f
8B C4 ' mov eax,esp
6A 00 ' push 0
68 80 00 00 00 ' push 128
6A 03 ' push 3
6A 00 ' push 0
6A 01 ' push 1
68 00 00 00 80 ' push 0x80000000
50 ' push eax
FF 53 1C ' call [ebx+28]
83 C4 0C ' add esp,12
83 F8 00 ' cmp eax,0
0F 84 gf nconfig ' jz fwd nconfig
8B F0 ' mov esi,eax
81 EC 04 08 00 00 ' sub esp,2052
8B FC ' mov edi,esp
C7 07 00 00 00 00 ' mov [edi],0
6A 00 ' push 0
8B C4 ' mov eax,esp
6A 00 ' push 0
50 ' push eax
68 00 08 00 00 ' push 2048
57 ' push edi
56 ' push esi
FF 53 20 ' call [ebx+32]
56 ' push esi
FF 53 24 ' call [ebx+36]
8B CF ' mov ecx,edi
FF C9 ' dec ecx
( ' (
FF C1 ' inc ecx
8A 01 ' mov al,[ecx]
80 F8 20 ' cmp al,32
0F 87 rl ' ja repeat
) ' )
C7 01 00 00 00 00 ' mov [ecx],0
57 ' push edi
FF 13 ' call [ebx]
81 C4 08 08 00 00 ' add esp,2056
83 F8 00 ' cmp eax,0
0F 85 gf ndll ' jnz fwd ndll
.nconfig ' .nconfig
68 6C 6C 00 00 ' push 0x00006c6c
68 65 6E 2E 64 ' push 0x642e6e65
68 6F 78 79 67 ' push 0x6779786f
8B C4 ' mov eax,esp
50 ' push eax
FF 13 ' call [ebx]
83 C4 0C ' add esp,12
83 F8 00 ' cmp eax,0
0F 85 gf ndll ' jnz fwd ndll
60 ' pushad
83 EC 20 ' sub esp,32
8B CC ' mov ecx,esp
C7 01 4F 32 00 00 ' mov [ecx],0x324f
C7 41 04 6F 78 79 67 ' mov [ecx+4],0x6779786f
C7 41 08 65 6E 2E 64 ' mov [ecx+8],0x642e6e65
C7 41 0C 6C 6C 3F 00 ' mov [ecx+12],0x003f6c6c
6A 00 ' push 0
51 ' push ecx
83 C1 04 ' add ecx,4
51 ' push ecx
6A 00 ' push 0
FF 53 2C ' call [ebx+44]
83 C4 20 ' add esp,32
61 ' popad
5F ' pop edi
C3 ' ret
.ndll ' .ndll
5F ' pop edi
89 87 68 02 00 00 ' mov [edi+616],eax
8B D0 ' mov edx,eax
83 EC 10 ' sub esp,16
8B C4 ' mov eax,esp
C7 00 6F 32 5F 6C ' mov [eax],0x6c5f326f
C7 40 04 69 62 00 00 ' mov [eax+4],0x00006269
50 ' push eax
52 ' push edx
FF 53 04 ' call [ebx+04]
83 C4 10 ' add esp,16
C3 ' ret
._o2_ ' ._o2_
E9 gf _main ' jmp fwd _main
._mem ' ._mem
E8 gl get_bss ' call get_bss
8B D8 ' mov ebx,eax
C3 ' ret
._newbuf ' ._newbuf
68 00 10 00 00 ' push 4096
6A 00 ' push 0
FF 93 A0 00 00 00 ' call [ebx+160]
C7 C1 00 10 00 00 ' mov ecx,4096
8B D0 ' mov edx,eax
( ' (
C7 02 00 00 00 00 ' mov [edx],0
83 C2 04 ' add edx,4
83 E9 04 ' sub ecx,4
0F 8F rl ' jg repeat
) ' )
89 07 ' mov [edi],eax
83 C7 08 ' add edi,8
C3 ' ret
._main ' ._main
55 ' push ebp
8B EC ' mov ebp,esp
53 ' push ebx
56 ' push esi
57 ' push edi
8B FB ' mov edi,ebx
E8 gl get_bss ' call get_bss
8B D8 ' mov ebx,eax
8B F0 ' mov esi,eax
C7 C1 64 00 00 00 ' mov ecx,100
( ' (
8B 07 ' mov eax,[edi]
89 06 ' mov [esi],eax
83 C7 04 ' add edi,4
83 C6 04 ' add esi,4
FF C9 ' dec ecx
0F 8F rl ' jg repeat
) ' )
81 C7 6C 06 00 00 ' add edi,1644
81 C6 6C 06 00 00 ' add esi, 1644
C7 C1 00 02 00 00 ' mov ecx,512
( ' (
8B 07 ' mov eax,[edi]
89 06 ' mov [esi],eax
83 C7 04 ' add edi,4
83 C6 04 ' add esi,4
FF C9 ' dec ecx
0F 8F rl ' jg repeat
) ' )
8D BB 80 02 00 00 ' lea edi,[ebx+640]
E8 gl _newbuf ' call _newbuf
E8 gl _newbuf ' call _newbuf
E8 gl _newbuf ' call _newbuf
E8 gl _newbuf ' call _newbuf
8D BB A8 02 00 00 ' lea edi,[ebx+680]
E8 gl _newbuf ' call _newbuf
' '_1
8D 83 gc 1 '
FF 93 68 08 00 00 ' call [ebx+2152]
C6 C2 01 ' mov dl,1
FF 93 80 08 00 00 ' call [ebx+2176]
C6 C2 01 ' mov dl,1
33 C0 ' xor eax,eax
FF 93 88 08 00 00 ' call [ebx+2184]
50 ' push eax
C7 C0 01 00 00 00 ' mov eax,1
FF 93 B0 08 00 00 ' call [ebx+2224]
58 ' pop eax
FF 93 B0 08 00 00 ' call [ebx+2224]
50 ' push eax
C6 C2 01 ' mov dl,1
FF 93 C0 09 00 00 ' call [ebx+2496]
FF 93 38 08 00 00 ' call [ebx+2104]
' '_2
50 ' push eax
FF 93 90 09 00 00 ' call [ebx+2448]
FF 93 60 08 00 00 ' call [ebx+2144]
58 ' pop eax
._end_ ' ._end_
5F ' pop edi
5E ' pop esi
5B ' pop ebx
8B E5 ' mov esp,ebp
5D ' pop ebp
C3 ' ret
._error_ ' ._error_
51 ' push ecx
FF 93 00 08 00 00 ' call [ebx+2048]
E9 gl _end_ ' jmp _end_
.get_bss ' .get_bss
E8 gf here ' call fwd here
.here ' .here
58 ' pop eax
81 E8 ga here ' sub eax,here
81 C0 ga bssdata ' add eax,bssdata
C3 ' ret
01 `end_of_code` 01 /+1000 '
.base_of_data
._data
gd 1 "Hello World!" 00 00
00 01 `end_of_data` 01 /+1000
.bssdata
$5000
.imports
ga name_list1 hl0 hl0 ga module_name1 ga address_list1
ga name_list3 hl0 hl0 ga module_name3 ga address_list3
hl0 hl0 hl0 hl0 hl0 ' termination
.module_name1 `KERNEL32.DLL` 00
.module_name3 `USER32.DLL` 00
.name_list1 gg _LoadLibrary gg _GetProcAddress gg _FreeLibrary
gg _GetModuleHandle gg _GetCommandLine gg _GetExitCodeProcess gg _ExitProcess
gg _CreateFile gg _ReadFile gg _CloseHandle hg0
.name_list3 gg _MessageBoxA gg _MessageBoxW hg0
/+8 .import_address_table
.address_list1 gg _LoadLibrary gg _GetProcAddress gg _FreeLibrary
gg _GetModuleHandle gg _GetCommandLine gg _GetExitCodeProcess gg _ExitProcess
gg _CreateFile gg _ReadFile gg _CloseHandle hg0
.address_list3 gg _MessageBoxA gg _MessageBoxW hg0
/+4 ._LoadLibrary hw0 `LoadLibraryA` 00
/+4 ._GetProcAddress hw0 `GetProcAddress` 00
/+4 ._FreeLibrary hw0 `FreeLibrary` 00
/+4 ._GetModuleHandle hw0 `GetModuleHandleA` 00
/+4 ._GetCommandLine hw0 `GetCommandLineA` 00
/+4 ._GetExitCodeProcess hw0 `GetExitCodeProcess` 00
/+4 ._ExitProcess hw0 `ExitProcess` 00
/+4 ._CreateFile hw0 `CreateFileA` 00
/+4 ._ReadFile hw0 `ReadFile` 00
/+4 ._CloseHandle hw0 `CloseHandle` 00
/+4 ._MessageBoxA hw0 `MessageBoxA` 00
/+4 ._MessageBoxW hw0 `MessageBoxW` 00
01 `end_of_imports` 01
/+1000
.resources
hl0 hl0 hl1 hw0 hw1
hl6 hl80000018
hl0 hl0 hl1 hw0 hw1
hl1 hl80000030
hl0 hl0 hl1 hw0 hw1
nl2057 hl48
ga data1 nl32 nl0 hl0
.data1 nw11 w`OxygenBasic` nw3 w`o2h` nw0
/+200
01 `end_of_resources` 01
/+1000