Sumatra PDF is a PDF, ePub, MOBI, CHM, XPS, DjVu, CBZ, CBR reader for Windows

Hacking Sumatra PDF 3.2 to work on WinXP & Server 2003 (x86/x64)

[ Moderator’s Note: Follow the instructions below at your own risk. While they shouldn’t cause any issues if followed properly, no official support will be provided for any such user-modified EXE. The last official Sumatra PDF version for WinXP is 3.1.2. ]

Hello,

I just registered here to show you how to binary-hack Sumatra PDF 3.2 in its portable version to work on Windows XP and Server 2003. That includes the 64-bit version in regards to Windows XP x64 and Windows Server 2003 x64. This might not be interesting for 99% of the user base, but I still wanted to share this.

First, you’ll need NTCore’s CFF Explorer. That’s what we’ll use to modify the PE32/PE32+ header of the program to change the header properties “MajorSubsystemVersion” and “MinorSubsystemVersion”, which correspond to the NT kernel version. Also, we’ll use it to modify the load-time DLL import table of the binary program to hard-remove a dependency on d2d1.dll (this part is essentially software vandalism!).

d2d1.dll is some kind of glue-layer library to make Direct2D work on modern systems, or at least I suspect it to be. I’m not sure. Since we don’t need such a thing on XP, ripping the link to its exported symbols out forcefully might work, right?

Open up CFF Explorer and load SumatraPDF-3.2-64.exe or SumatraPDF-3.2-32.exe into it, depending on whether it’s 32 or 64-bit XP/2003 you wanna run it on. Click on the “Optional Header” thing under “NT Headers”, see here:

Here you can see, that the MajorSubsystemVersion is 0005, with the MinorSubsystemVersion being 0002 (already modified!). That corresponds to Windows Server 2003 or XP x64, which run on the Windows NT 5.2 kernel. 32-bit XP would need 0005 and 0001 here (NT 5.1). This will be set to 0006 and 0000 by default (Windows NT 6.0, which means Win Vista). Modify it to match your target platform. Keep the leading zeroes!

Now, click on the “Import Directory” folder. This is the load-time DLL import table. So, the table that specifies which DLLs the program should load and which functions to import from them at load-time (=when you start the program). Find d2d1.dll, right-click it, and pick “Delete Import Descriptor”:

Now click save, and confirm to overwrite the .exe.

Congratulations, you have just vandalized a beautiful piece of software. :wink: That concludes the hack, nothing else is needed, at least not for version 3.2:

Cheers!

Thanks for sharing, @GrandAdmiralThrawn! Does make me wonder though - if that’s all it takes then has anyone tried simply compiling the program with an older version of Visual Studio and seen if they can get it to work under XP with minimal code changes?

P.S. Added a disclaimer at the top, just in case someone has issues and decides to direct a complaint about it to us. :slight_smile:

Thanks for adding the disclaimer @SumatraPeter, I didn’t think about that!

As for recompiling: It’s probably enough to pick the right platform toolset, like e.g. v141_xp. With that you should be able to compile, at least with VS2017. Could be that the d2d1.h import and d2d1.dll link would have to be removed manually as well, I haven’t looked at the project/solution files yet.

I’ll have access to my Windows build VM on Monday. Not sure if I’ll have time, but if yes, I’ll attempt to compile a build targeting XP / XP x64 directly. Would be cleaner and more proper than the hack I’ve shown above.

I removed XP support in https://github.com/sumatrapdfreader/sumatrapdf/commit/28bd54bd66adb019176eb48c03518ae65f217799 so the first step would be to undo changes to premake files and re-generate the solution.

Re-adding XP support wouldn’t be hard but it was also more work than I was willing to do.

It boils down to using Windows APIs that are no longer available in XP and the XP-compatible SDK no longer being able to compile some of the code and I didn’t have the patience to fix up all those issues.

I’m surprised your hacked binary works at all but I wouldn’t bet that it works in all possible code paths.

1 Like

Speaking of compilation @kjk, how hard would it be to add ARM64 as a target so that users can run native versions of Sumatra on Win10 on ARM devices?

It’s not too hard and it’s on my list.
That being said, I don’t have an ARM device so no way to test it.

Not worth me posting one of my units as they are the $4-40 Raspberry type but you could possibly add a crowdfund hardware option to the donation page (same paypal account)

Is there anything specific one should test, other than all the file formats which are supported? So far I’ve only tried a few PDFs and CBZ with JPEG and PNG files inside on my XP x64. Those files worked fine so far, and blazing fast at that!

Another user I know asked me to re-do the hack for the 32-bit version, because he wants to use it on his retro computers with XP. So far, he’s reported no issues to me.

Will hopefully be able to take a look at the source code tomorrow, that’ll be fun (I’m a highly incapable programmer, at least when it comes to C/C++). :wink:

Thats what I love about XP very little bloat and easy to modify, nothing in 10 is worth upgrading for except more frequent fixes.

Watch out for the issues raised on GitHub towards 3.2.1 a few of those may cause problems whilst testing. Perhaps test a current Pre-release in tandem ?
A Process Monitor comparing side by side with a suported OS such as vista upwards, tracing cascading calls through dlls may spot any process failings ?

Although in this case the “blazing fast” part was more Sumatra PDF than XP. :wink: I compared it with CDisplayEx for a comic book / manga reader, and while CDisplayEx is better suited for this specific task (2-page view includes fold-shade rendering or what you call it, and right-to-left reading), Sumatra is faster.

For PDF I compared it to Adobe Acrobat Reader 10.1 and Foxit Reader 611.1031, and… Well… XP or not, speed-wise, Sumatra just wipes the floor with those. But that’d be common knowledge I guess.

PS.: My XP x64 machine is relatively “modern”; Xeon X5690 hexcore, 48GiB RAM, 1.6TB SSD, 54TiB RAID-6, GTX Titan Black, but programs like Adobe Reader can still make it feel sluggish… whereas Sumatra does not.

Only thing I’ll miss on occasion will be PDF forms. But maybe PDF.js can handle those.

Basic form filling is on the back burner whilst Annotation is in active development.

Personally dont like the prospect of XFA forms support since that requires java or similar exploitable functions (and I have easily used such mods in the past on behalf of an institutional client who could not provide a password for their key online form)

Winners of March " Pwn2Own" was the one click PDF exploit of Acrobat.

Of course MuPDF-GL includes javascript in its forms support which I will use when necessary via a link from SumatraPDF.

Since Embedded text fonts and images such as PNG can be used as attack objects NO PDF aspect is safe.