Files
mars_nwe_pcab/cross/generate-nt4-inf.py

100 lines
4.9 KiB
Python

#!/usr/bin/env python3
"""Generate a local NT4 installer from the operator's NT4 DDK sample.
No DDK source is bundled with this generator. Output requires NT4 VM validation.
"""
import argparse, os, pathlib, re
p=argparse.ArgumentParser()
p.add_argument('ddk', type=pathlib.Path)
p.add_argument('output', type=pathlib.Path)
a=p.parse_args()
mac=os.environ.get('MARS_NT4_NETWORK_ADDRESS', '')
if mac and (not re.fullmatch(r'[0-9a-fA-F]{12}', mac) or int(mac[:2],16)&1 or int(mac,16)==0):
p.error('MARS_NT4_NETWORK_ADDRESS must be a nonzero unicast MAC: 12 hex digits')
paths=list(a.ddk.rglob('OEMNADE2.INF'))
if len(paths)!=1: p.error('Expected one NT4 Ethernet installer sample OEMNADE2.INF')
s=paths[0].read_text(encoding='latin1').replace('\x1a','')
# Strip comments from template; retain a provenance notice for the generated file.
s='\n'.join(line for line in s.splitlines() if not line.lstrip().startswith(';'))
# No bus/resource detection for a software-only adapter.
start=s.index(' Debug-Output "OEMNADE2.INF: ====')
end=s.index('installadapter = +',start)
s=s[:start]+' Goto $(StartLabel)\n\n'+s[end:]
start=s.index(' Set CurrParamSettings = {}')
end=s.index('configureadapter = +',start)
s=s[:start]+' goto adaptersetup\n\n'+s[end:]
start=s.index(' set ValueName = ""',s.index('configureadapter = +'))
end=s.index('skipoptions =+',start)
s=s[:start]+''' CloseRegKey $(KeyParameters)
CloseRegKey $(KeyProduct)
goto successful
adaptersetup = +
Ifstr $(NetworkAddress) == ""
set Error = "Set NetworkAddress in OEMSETUP.INF to the physical IPX node (12 hex digits), then install again."
goto fatal
endif
goto skipoptions
'''+s[end:]
start=s.index(' Set NewValueList = {{Transceiver',s.index('writeparameters = +'))
end=s.index(' Shell $(UtilityInf), AddValueList',start)
s=s[:start]+''' Set NewValueList = {{BusType,$(NoTitle),$(!REG_VT_DWORD),0},+
{BusNumber,$(NoTitle),$(!REG_VT_DWORD),0},+
{NetworkAddress,$(NoTitle),$(!REG_VT_SZ),$(NetworkAddress)}}
'''+s[end:]
# Bindings are handled by NCPA's NetRules engine, not an ISA setup dialog.
s=s.replace(' set Error = "Binding: Sorry, not yet implemented."\n goto fatal',' goto successful')
start=s.index('[DebugConfiguration]'); end=s.index('[Install-Option]',start)
s=s[:start]+s[end:]
s=re.sub(r'\[PlatformsSupported\].*?\[Options\]', '[PlatformsSupported]\n ISA\n EISA\n PCI\n Internal\n\n[Options]',s,flags=re.S)
s=re.sub('elnkii', 'MARSNET3',s,flags=re.I).replace('OEMNADE2.INF','OEMSETUP.INF').replace('Elink II','MARS Virtual Ethernet')
s=s.replace('Manufacturer = "Microsoft"','Manufacturer = "MARS VME"')
s=s.replace('ProductOpSupport = 134', 'ProductOpSupport = 130') # display/remove; no resource properties
s=s.replace('NetRuleHardwareClass = {"MARSNET3Adapter basic"}', 'NetRuleHardwareClass = {"MARSNET3Adapter basic", "ndisEthernet basic"}')
s=s.replace('[FileConstants]', '[FileConstants]\nNetworkAddress = "'+mac.upper()+'"')
s=s.replace('ifstr(i) !(NTN_RegBase)', 'ifstr(i) $(!NTN_RegBase)')
s=s.replace('successful = +\n goto end','successful = +\n set CommonStatus = STATUS_REBOOT\n goto end')
s+='''
[ProductType]
STF_PRODUCT = Winnt
STF_PLATFORM = I386
[Source Media Descriptions]
1 = "MARS NDIS3 NT4 driver", TAGFILE = MARSNET3.SYS
[Files-MARSNET3]
1, MARSNET3.SYS, SIZE=65536
[LanguagesSupported]
ENG, GER
'''
for lang in ('ENG','GER'):
s+='''
[OptionsTextLANG]
MARSNET3 = "MARS Virtual IPX Ethernet NDIS3 (experimental)"
[FileConstantsLANG]
FunctionTitle = "MARS NDIS3 NT4 Setup"
ProductSoftwareDescription = "MARS virtual Ethernet driver"
ProductSoftwareTitle = "MARS NDIS3 driver"
ProductHardwareMARSNET3Description = "MARS virtual Ethernet"
ProductHardwareMARSNET3Title = "MARS virtual Ethernet adapter"
ShellCodeErrorTitle = "MARS NT4 Setup error"
ShellCodeErrorText = "NT4 setup helper failed. See setup log."
ProCaption = "MARS NT4 Setup"
ProCancel = "Cancel"
ProCancelMsg = "Cancel driver setup?"
ProCancelCap = "MARS NT4 Setup"
ProText1 = "Copying:"
ProText2 = "To:"
[DialogConstantsLANG]
OK = "OK"
Continue = "Continue"
Cancel = "Cancel"
'''.replace('LANG',lang)
s='; MARS NT4 x86 experimental installer. Runtime UNTESTED.\n; Adapted locally from Microsoft NT4 DDK OEMNADE2.INF.\n; Original sample provenance: Microsoft NT4 DDK, Ethernet setup example.\n'+s
# Catch dangling static branches left by template surgery.
labels={m.lower() for m in re.findall(r'^([A-Za-z][A-Za-z0-9_]*)\s*=\s*\+',s,re.M)}
for target in re.findall(r'^\s*goto\s+([A-Za-z][A-Za-z0-9_]*)\s*$',s,re.M|re.I):
if target.lower() not in labels: p.error('Unresolved branch: '+target)
a.output.parent.mkdir(parents=True,exist_ok=True)
a.output.write_bytes(s.replace('\n','\r\n').encode('ascii'))
print(str(a.output)+': generated; NT4 installation/binding not runtime tested')