How do application compatibility shims work?

Posted: (EET/GMT+2)

 

Since a new Windows operating system, Windows 7, is now here, application compatibility is again a issue in developer's and IT administrator's minds. From a management perspective, you might have run into the term shim, which are ways to make application better compatible with the new Windows version.

Shims can be created with utilities in the Application Compatibility Toolkit, but how do shims technically speaking work? The idea of using shims comes from the fact that application compatibility can be caused by applications not using Windows API functions exactly correctly, or behaving erratically if the APIs return something that is not expected, such as a new version number or flags with unaccounted-for bits set.

Shims, then, are ways to force Windows API call results to be more in line with what the problematic applications expect. Yes, it's a problem on the application side, and not on Windows'. But sometimes, source code for an older but critical application might not be available anymore, or the vendor that originally created the application is no longer in business.

When the operating system loads an executable into memory, Windows API function pointers are mapped by the OS loader. There is a memory table called the Address Table (IAT) that points to API function entry points, and then your application can simply jump to a correct memory location to call that API function. But when shims are present (administrative opt-in specifies this), Windows alters the function pointers so that instead of calling for example GetVersionEx function directly, a separate wrapper function is called instead.

This wrapper does eventually call the original API function, but might chance the parameter values used in the call, or alternatively might change the results slightly before returning to the original caller, i.e. your application. This way, your (old) application can still be compatible and run with Windows 7, even though it wouldn't be exactly so just out of the box. This is what shims are for, and how they work.