Skip to content

About

.NET Framework 4.8 on Windows 98 SE (with KernelEx)

Resources

Stars

13 stars

Watchers

0 watching

Forks

Repository files navigation

.NET Framework 4.8 on Windows 98

Runs .NET Framework 4.8 managed executables on Windows 98 SE (with KernelEx 4.5.2+ and an SSE2-capable CPU), using a set of wrapper DLLs, small binary patches to clr.dll and clrjit.dll, and Microsoft's official redistributable for everything else. Managed programs start by double-click, as on any other Windows.

Quick install

  1. On Windows 98 SE, install KernelEx 4.5.2 (included in the release) and restart.
  2. Download the latest release and extract it on the Windows 98 machine with 7-Zip 9.20.
  3. Copy mscoree.dll from a Windows 10/11 PC (C:\Windows\SysWOW64\mscoree.dll) into the extracted folder.
  4. With the Windows 98 machine online, run WIN98SETUP.BAT from an MS-DOS Prompt.
  5. Restart. Notepad opens with the result of a quick check: HELLO48 OK means it works.

The details, and how to install without an internet connection, are under Install.

Status

What works:

  • Console and WinForms applications, including common and complex controls, dialogs, the clipboard and GDI+ drawing.
  • The base class library: threads, the thread pool, timers, Task/async, file I/O, FileSystemWatcher, memory-mapped files, compression, the registry, processes, reflection and Reflection.Emit, dynamic, LINQ/PLINQ, XML/XSLT, serialization (binary, XML, DataContract, JSON), DataTable, cultures and time zones, regular expressions.
  • Networking: DNS, TCP/UDP sockets, ping, HTTP, and HTTPS/SslStream over TLS 1.0-1.2 (see TLS).
  • Hashing, random numbers, PBKDF2, managed AES, X.509 parsing and DPAPI (ProtectedData).
  • Real applications: the XNA-based CnCNet clients for Dawn of the Tiberium Age and Red Alert 2 / Yuri's Revenge - main menu, CnCNet lobby and chat, the updater, and launching games (RA2/YR with Ares and Phobos needs a patched Syringe). They need some extra DLLs beside the client, which a separate project sets up: cncnet-win98.

The test suite in tests/DN48Test (115 tests) passes 100 on Windows 98 SE and all of them on Windows 10.

Known gaps (the remaining test failures):

  • Cryptography through Windows' crypto providers: AesCryptoServiceProvider, TripleDES, SHA256CryptoServiceProvider, RSACryptoServiceProvider key generation and SHA-256 signatures, and CNG (ECDsaCng). Win98 only has the old base provider. The managed implementations (AesManaged, SHA256Managed, ...) work.
  • Not available on Win98: named pipes, HttpListener (httpapi.dll), WMI (System.Management), WPF (needs DirectWrite).
  • Not yet investigated: isolated storage, Icon.ExtractAssociatedIcon/metafiles, the WinForms WebBrowser control, OLE DB/Jet and late-bound COM automation (both hang).

If you hit a managed API that doesn't work, it is very likely an unimplemented or stubbed KERNEL32 or ADVAPI32 function - see How it works for where to look.

Requirements

  • Windows 98 SE with KernelEx 4.5.2 or later installed first (the 4.5.2 installer is included in the release, in third_party\kernelex-4.5.2).
  • An SSE2-capable CPU.
  • About 1GB of free disk space on the drive you run the installer from, plus roughly 300MB on C: for the installed Framework. The payload cabinets and the _DN48 scratch directory can live on another drive - run WIN98SETUP.BAT from there, or set WORK at the top of it.
  • A 32-bit .NET 4.x-era mscoree.dll from another Windows computer. Microsoft's .NET 4.8 package does not include it (Windows 10 has it built in). On 64-bit Windows 10/11, copy C:\Windows\SysWOW64\mscoree.dll; on 32-bit Windows, C:\Windows\System32\mscoree.dll.
  • An internet connection on the Windows 98 machine, so the installer can download Microsoft's .NET Framework 4.8 package and GDI+ (both are checked against known SHA-1 hashes). Without one, download these on another computer and put them beside WIN98SETUP.BAT:
    • NDP48-x86-x64-AllOS-ENU.exe, the .NET Framework 4.8 offline installer.
    • gdiplus.dll, which System.Drawing and WinForms images need. It is in Microsoft's old GDI+ redistributable, gdiplus_dnld.exe (archived by the Internet Archive; open it with 7-Zip, then the gdiplus.exe inside). Version 5.1.3102.1360 was used for testing.

Install

  1. Install KernelEx 4.5.2+ on the Windows 98 SE machine (the installer is in the release, in third_party\kernelex-4.5.2), and restart.
  2. Download the latest release, dotnet48-win98-<version>.zip, from the Releases page.
  3. Extract it on the Windows 98 machine, keeping its long file names. The simplest way is to copy the .zip across and extract it there with a tool that supports long file names, such as 7-Zip 9.20 (the last version that runs on Windows 98). You can also extract it on another computer and copy the folder across a network share, or on a CD (with Joliet), a USB stick or a disk that keeps long file names.
  4. Put the 32-bit mscoree.dll described above beside WIN98SETUP.BAT.
  5. Without an internet connection: put NDP48-x86-x64-AllOS-ENU.exe and gdiplus.dll beside WIN98SETUP.BAT too.
  6. Open an MS-DOS Prompt, change to the extracted folder and run WIN98SETUP.BAT.
  7. Restart.
  8. After the restart a quick check runs once and opens its results in Notepad: they should show HELLO48 OK and the CLR version. Run C:\DOTNET48\VERIFY.BAT to check again later.

WIN98SETUP.BAT copies wrapper DLLs and the supplied mscoree.dll into C:\WINDOWS\SYSTEM, extracts Microsoft payload files with the bundled bin\7za.exe, copies the Framework files into C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319, imports the .NET registration keys, and sets the KernelEx compatibility mode for mscoree.dll to WINXP. It also adds the DN98FX API library to KernelEx's CORE.INI (the original is kept as CORE.INI.DN98), and leaves DN98INST.EXE and 7ZA.EXE in C:\DOTNET48 for other packages to use, such as cncnet-win98.

Before replacing them, setup saves the mscoree.dll and mscorees.dll already in C:\WINDOWS\SYSTEM (and any existing registration of the taskbar object it registers) in C:\DOTNET48\BACKUP; UNINSTALL.BAT puts them back.

With dotnet9x

dotnet9x (.NET 2.0-3.5 for Windows 9x) can be installed on the same machine. The two keep their files apart - dotnet9x uses Microsoft.NET\Framework\v2.0.50727, v3.5, the C:\WINDOWS\assembly GAC and the wrappers CORKEL32, CORNT, CORUSR and CORSHLW; this project uses v4.0.30319, Microsoft.NET\assembly and DNKERNEL/DNADVAPI - but there is only one mscoree.dll, the loader every .NET program starts through:

  • Install dotnet9x first, then this. Setup saves dotnet9x's mscoree.dll and replaces it with the .NET 4 one; from then on every .NET program, including .NET 2.0-3.5 ones, runs on .NET 4.8. .NET 4 is meant to run most older programs, but this has not been tested with dotnet9x.
  • Installing or repairing dotnet9x afterwards puts its own mscoree.dll back, and .NET 4.8 programs stop starting. Run WIN98SETUP.BAT again (with the .NET 4 mscoree.dll beside it).
  • UNINSTALL.BAT restores dotnet9x's mscoree.dll, so .NET 2.0-3.5 programs run on dotnet9x again.
  • Setup refuses a .NET 2.0 mscoree.dll: it needs the .NET 4 one described under Requirements.

Uninstall

Run this from the project root on the Win98 box:

UNINSTALL.BAT

It removes the v4 Framework directory, v4 GAC tree, C:\DOTNET48, this project's wrapper DLLs, and the v4 CLR CRT files copied into C:\WINDOWS\SYSTEM; puts back the mscoree.dll and mscorees.dll that were there before (or removes them if there were none); removes DN98FX from KernelEx; and removes the .NET 4 detection keys and KernelEx compatibility values added by this project. It leaves gdiplus.dll and dbghelp.dll in place, as other programs may use them. Restart afterwards.

Install scope

This is a runtime-focused install. It copies the CLR native files, CRT files, GAC assemblies under C:\WINDOWS\Microsoft.NET\assembly, this project's wrapper/shim DLLs, registry detection keys, and the KernelEx setting needed for mscoree.dll.

It does not attempt to reproduce every OS integration side effect of Microsoft's MSI install. The runtime-focused path installs the v4 files needed for managed applications to bind and run, but it does not install Explorer namespace extensions, services, developer tools, ASP.NET integration, or MSI product/uninstall registration.

Other .NET Framework pieces are intentionally not installed or not tested here:

  • NGEN service/native image cache (ngen.exe, mscorsvw.exe, native-image registry setup).
  • Developer and administration tools (MSBuild.exe, csc.exe, vbc.exe, CasPol.exe, InstallUtil.exe, RegAsm.exe, RegSvcs.exe, .tlb registration).
  • ASP.NET/IIS integration, performance counters, event-log setup, services, and uninstall/MSI product registration.
  • WPF browser-host/native integration (PresentationHost, PresentationNative, wpfgfx, wpftxt) beyond copying the managed GAC assemblies already listed in install\files.win98.txt.

Troubleshooting

  • CLRPROBE.EXE fails before the managed smoke test: check C:\DOTNET48\CLRPROBE.LOG. This usually means a native DLL is missing, the wrong mscoree.dll was supplied, or the wrapper DLLs were not copied to C:\WINDOWS\SYSTEM.
  • WIN98SETUP.BAT stops before extracting: place Microsoft's NDP48-x86-x64-AllOS-ENU.exe beside it and rerun. If you already extracted the redist elsewhere, place netfx_Full.mzz and Windows10.0-KB4486153-x86.cab beside it.
  • If the managed smoke test fails early and mscoree.dll was supplied manually: use a 32-bit .NET 4.x-era copy. On 64-bit Windows, that means C:\Windows\SysWOW64\mscoree.dll, not C:\Windows\System32\mscoree.dll.
  • HelloDotNet48.exe does not print HELLO48 OK: verify that DN98INST.EXE PATCH C:\WINDOWS completed and that clr.dll/clrjit.dll in C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 have .PRE_WIN98_TLS_HOTPATCH backups.
  • Direct-launching a managed app fails but HelloDotNet48.exe works: check for NETSHIM_FATAL.LOG next to NETSHIM.DLL in the Framework directory. For detailed assembly-load diagnostics, set NETSHIM_LOG=1 before launching the app.
  • An app reports a vague error ("One or more errors occurred", a TypeInitializationException): set NETSHIM_LOG=1 and run it again. NETSHIM_EXCEPTIONS.LOG (beside NETSHIM.DLL) then lists every exception as it is thrown, with its stack trace - usually the original cause.
  • A Framework assembly fails to load with 0x8007001F ("A device attached to the system is not functioning"): look beside the app for old copies of this project's DLLs (DNADVAPI.DLL, DNKERNEL.DLL, CORADV32.DLL, BCRYPT.DLL, W2_32W.DLL, TLS98.DLL) and delete them. Windows loads a copy in the app's folder before the one in C:\WINDOWS\SYSTEM.
  • HTTPS fails with a trust error for every site: check that C:\WINDOWS\SYSTEM\CACERT.PEM exists and the system clock is right. Set TLS98_LOG=1 and look at C:\DOTNET48\TLS98.LOG.
  • After changing KernelEx settings or replacing runtime DLLs, reboot Win98 before retesting.
  • Run WIN98SETUP.BAT from an MS-DOS Prompt inside Windows, not from command-prompt-only mode. Real-mode DOS has no long-filename support, and both the batch file's own name and the Microsoft payload names are long. Same reason the payloads are unpacked with 7za.exe instead of EXTRACT.EXE: real-mode DOS tools cannot create the cabinets' member names.
  • If Explorer shows the extracted files with short names like WIN98S~1.BAT or FILES~1.TXT, the long file names were lost on the way, and the install will fail. Extract the release .zip on the Windows 98 machine itself (install step 3), or use a copy method that keeps long names. A plain ISO9660 Level 1 CD (no Joliet) truncates everything to 8.3.

How it works

Four problems, four fixes:

  1. The CLR calls hundreds of KERNEL32/ADVAPI32 functions Win98 doesn't have, and does version checks that reject anything below Windows XP. Fix: the installer (DN98INST.EXE; src/wrappers/patch_imports.py does the same on another computer) rewrites the name string in each native DLL's import table (KERNEL32.DLL→DNKERNEL.DLL, same length, no relocation needed) to point at our own wrapper DLLs (src/wrappers/dnkernel.c/dnadvapi.c, generated by gen.py from the import lists in analysis/). Most exports are naked trampolines straight through to the real DLL; ~90 are reimplemented (reimpl_k32.c/reimpl_adv.c) - version spoofing, TLS/condition-variable fixes, a manual SEC_IMAGE PE mapper (Win98's CreateFileMapping can't do SEC_IMAGE, which the CLR requires to map assemblies), a working VirtualAlloc guard-page workaround, and more. Each reimplementation has a comment explaining the specific Win98 behavior it works around.
  2. Inline TLS fast paths in clr.dll and clrjit.dll read the NT thread-environment-block layout directly (fs:[TEB]), which doesn't exist on Win98 and faults. Fix: DN98INST.EXE flips the relevant conditional branches on the Win98 machine so both the CLR and JIT take their generic, safe TLS-access paths instead.
  3. Double-click launch goes through a CLR code path that fails on this OS for reasons never fully identified. Fix: we replace mscoree!_CorExeMain with our own entry point (dnk_hook_corexemain in reimpl_k32.c) that hosts the CLR directly and loads the exe by path via NETSHIM.DLL (src/shim/netshim.cs) instead. DNKERNEL resolves NETSHIM.DLL from the CLR runtime directory, so it follows the installed Framework location rather than a separate tools directory.
  4. Win98 has no TLS stack .NET can use. Its secur32.dll has no SChannel package and its crypt32 cannot verify SHA-256 certificate signatures. Fix: TLS98.DLL (src/tls98) implements the SChannel client side of SSPI on top of BearSSL, and DNKERNEL routes .NET's secur32 P/Invokes to it. See "TLS" below.

TLS

TLS98.DLL gives .NET's SslStream (and so HttpWebRequest, WebClient and HttpClient) TLS 1.0, 1.1 and 1.2 as a client, using BearSSL 0.6 (third_party/bearssl-0.6). There is no TLS 1.3, server mode, client-certificate support or session resumption.

Server certificates are checked during the handshake against CACERT.PEM in C:\WINDOWS\SYSTEM: Mozilla's trusted root CAs as extracted by the curl project (third_party/cacert). To update the trusted roots, replace that file with a newer cacert.pem. As with SChannel, a certificate that fails the check does not end the handshake: .NET receives the verdict through TLS98's CertGetCertificateChain/CertVerifyCertificateChainPolicy and reports it to the application (RemoteCertificateValidationCallback, or a WebException by default). Set TLS98_LOG=1 to log to C:\DOTNET48\TLS98.LOG.

Building

The binaries in bin/ are built from the source in this repo. Rebuilding them needs Visual C++ 6.0 (VC98) and the .NET Framework 4.x C# compiler; one script builds everything:

.\build-all.ps1                  # everything into bin\ (application shims into bin\compat\)
.\build-all.ps1 -Out build\x     # or into another directory

src/native-tools/dn98inst.c is the Win98-side installer helper (downloading, unpacking, copying and patching). src/native-tools/clrprobe.c and src/smoke-test/HelloDotNet48.cs are the two checks C:\DOTNET48\VERIFY.BAT runs.

The pieces can also be built on their own. The two main wrapper DLLs:

cd src\wrappers
.\build.ps1 -src dnkernel.c -def dnkernel.def -out ..\..\bin\DNKERNEL.DLL -extraLibs "kernel32.lib advapi32.lib user32.lib"
.\build.ps1 -src dnadvapi.c -def dnadvapi.def -out ..\..\bin\DNADVAPI.DLL -extraLibs "kernel32.lib advapi32.lib user32.lib"

TLS98.DLL has its own script, which also builds BearSSL:

cd src\tls98
.\build.ps1

src/tls98/tlstest.c is a small native client that drives TLS98.DLL without .NET (tlstest host [path] [dll]).

To regenerate dnkernel.c/.def/dnadvapi.c/.def from a different import list (e.g. after targeting a different .NET 4.8 build), edit analysis/k32_needed.txt/adv_needed.txt and run python gen.py from src/wrappers/.

Debug logging (DNK_LOG) is off by default. To build a logging variant, add /DDNK_LOG to the CL.EXE line in src\wrappers\build.ps1 (needs user32.lib): DNKERNEL then writes C:\DOTNET48\REIMPL.LOG and DNADVAPI C:\DOTNET48\DNADVAPI.LOG. For managed shim assembly-load diagnostics, set NETSHIM_LOG=1; those logs are written next to the installed NETSHIM.DLL.

Test suite

tests/DN48Test is a console program with 115 tests across the .NET 4.8 surface: core types, threading, I/O, networking, crypto, text, data, serialization, WinForms and Win32 interop. Build it with tests\DN48Test\build.ps1 (output in build\tests), copy DN48TEST.EXE and DN48TEST.EXE.config to the Win98 machine and run it. Results go to the console and to DN48TEST.LOG beside the exe. --list lists the tests, --only <names> and --skip <names> select them, and --timeout <seconds> changes the per-test limit.

Credits

  • dotnet9x by itsmattkc, which brought .NET 2.0-3.5 to Windows 95/98 and showed the approach (video).
  • KernelEx, which provides most of the newer Windows API this builds on (GPL; installer in third_party/kernelex-4.5.2).
  • BearSSL by Thomas Pornin, the TLS implementation in TLS98.DLL (MIT).
  • Mozilla's CA certificate list, as extracted by the curl project (MPL 2.0).
  • 7-Zip (7za.exe, LGPL), which unpacks Microsoft's payloads.
  • The Internet Archive, whose copy of Microsoft's GDI+ redistributable the installer uses.

.NET Framework is Microsoft's. This project does not redistribute any of it: the installer downloads Microsoft's redistributable, or uses one you supply, and patches it on your machine.

About

.NET Framework 4.8 on Windows 98 SE (with KernelEx)

Resources

Stars

13 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages