Missing "bcrypt.dll" on Windows XP.

Everything related to MakeMKV
Post Reply
qbm0000
Posts: 6
Joined: Mon Nov 02, 2015 2:17 pm

Missing "bcrypt.dll" on Windows XP.

Post by qbm0000 » Sat Dec 12, 2020 4:25 am

"makemkvcon.exe" depends on "libffm.dll", which depends on "bcrypt.dll", which doesn't exist. It is trying to import 3 symbols: "BCryptCloseAlgorithmProvider", "BCryptGenRandom", and "BCryptOpenAlgorithmProvider".

This is on Windows XP 32 bit SP3. I have just upgraded to MakeMKV 1.15.4. I don't remember what my prior version was, but I was able to rip on Windows XP earlier this year.

A google search found this: http://forum.doom9.org/archive/index.php/t-175173.html

I wonder why ripping a video requires cryptographically secure random numbers? The thought crosses my mind to hack my own bcrypt.dll just to provide those 3 functions, maybe even just stubs. Otherwise, I wonder if an older version of libffm.dll can be dropped in? Otherwise, I might just have to use an older version of MakeMKV with my clock set back.

qbm0000
Posts: 6
Joined: Mon Nov 02, 2015 2:17 pm

Re: Missing "bcrypt.dll" on Windows XP.

Post by qbm0000 » Sat Dec 12, 2020 9:15 am

I hacked a stub, which allows MakeMKV 1.15.4 to run on Windows XP 32 bit.

I used g++ 4.7.1 20120524 (from the MinGW that came with QB64 1.2), and cl 15.00.30729.01 x86 (from Visual C++ 2008 Express).

bcrypt.cpp

Code: Select all

// bcrypt stub to allow newer versions of MakeMKV to run on Windows XP.
// Public domain, 2020 December, Michael Calkins ("qbasicmichael"). No warranty. Use at your own risk.
// Revision 2021 January 01
// Borrows from the "w64 mingw-runtime package", which is also public domain.

// mingw: ----------------------------------- (for older mingw, remove ",--nxcompat".)
// g++.exe -O3 -Wall -shared -Wl,-s,-shared,--enable-auto-image-base,-dy,--nxcompat,--kill-at -o bcrypt.dll bcrypt.cpp

// msvc++:
// cl.exe /O2 /LD /MD bcrypt.cpp bcryptvc.def user32.lib /link /NXCOMPAT
// mt.exe -manifest bcrypt.dll.manifest -outputresource:bcrypt.dll;2

// bcryptvc.def should contain the following:
// LIBRARY bcrypt.dll
// EXPORTS
// BCryptOpenAlgorithmProvider
// BCryptCloseAlgorithmProvider
// BCryptGenRandom
// ThisDllIsJustAStub

// Place the resulting "bcrypt.dll" into the MakeMKV folder. Do not put it in the system32 folder.
// You should probably delete any resulting bcrypt.a or bcrypt.lib files afterwards, so as not to interfere with linking other projects to genuine bcrypt.

#define NOCRYPT
#include <windows.h>

typedef LONG NTSTATUS;
typedef LPVOID BCRYPT_ALG_HANDLE;
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)

extern "C" __declspec(dllexport) NTSTATUS WINAPI BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE *phAlgorithm, LPCWSTR pszAlgId, LPCWSTR pszImplementation, DWORD dwFlags) {
 MessageBoxW(NULL, pszAlgId, L"BCryptOpenAlgorithmProvider", 0);
 return STATUS_SUCCESS;
}

extern "C" __declspec(dllexport) NTSTATUS WINAPI BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE hAlgorithm, ULONG dwFlags) {
 MessageBoxW(NULL, L"", L"BCryptCloseAlgorithmProvider", 0);
 return STATUS_SUCCESS;
}

extern "C" __declspec(dllexport) NTSTATUS WINAPI BCryptGenRandom(BCRYPT_ALG_HANDLE hAlgorithm, PUCHAR pbBuffer, ULONG cbBuffer, ULONG dwFlags) {
 MessageBoxW(NULL, L"", L"BCryptGenRandom", 0);
 return STATUS_SUCCESS;
}

extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
 return TRUE;
}

extern "C" __declspec(dllexport) const char * WINAPI ThisDllIsJustAStub(void) {
 return "This bcrypt.dll is just a stub to get MakeMKV to work on WinXP.";
}
MinGW files:

bcryptgcc.def

Code: Select all

LIBRARY bcrypt.dll
EXPORTS
BCryptOpenAlgorithmProvider@16 = bcrypt.dll.BCryptOpenAlgorithmProvider
BCryptCloseAlgorithmProvider@8 = bcrypt.dll.BCryptCloseAlgorithmProvider
BCryptGenRandom@16 = bcrypt.dll.BCryptGenRandom
ThisDllIsJustAStub@0 = bcrypt.dll.ThisDllIsJustAStub
bcryptoldgcc.def

Code: Select all

LIBRARY bcrypt.dll
EXPORTS
BCryptOpenAlgorithmProvider@16 = BCryptOpenAlgorithmProvider
BCryptCloseAlgorithmProvider@8 = BCryptCloseAlgorithmProvider
BCryptGenRandom@16 = BCryptGenRandom
ThisDllIsJustAStub@0 = ThisDllIsJustAStub
testbcryptgcc.cpp

Code: Select all

// Code to test the message boxes in the bcrypt stub. mingw version.
// Revision 2021 January 01.
// Note: the console window can cover and hide the message box.

// for older mingw, remove ",--nxcompat" from command line, and "bcrypt.dll." from before the function names on the def file lines.

// dlltool.exe -k -l bcrypt.a -d bcryptgcc.def
// g++.exe -O3 -Wall -Wl,-s,-dy,--nxcompat,--enable-stdcall-fixup -o testbcryptgcc.exe testbcryptgcc.cpp bcrypt.a

// bcryptgcc.def should contain the following:
// LIBRARY bcrypt.dll
// EXPORTS
// BCryptOpenAlgorithmProvider@16 = bcrypt.dll.BCryptOpenAlgorithmProvider
// BCryptCloseAlgorithmProvider@8 = bcrypt.dll.BCryptCloseAlgorithmProvider
// BCryptGenRandom@16 = bcrypt.dll.BCryptGenRandom
// ThisDllIsJustAStub@0 = bcrypt.dll.ThisDllIsJustAStub

#define NOCRYPT
#include <windows.h>

typedef LONG NTSTATUS;
typedef LPVOID BCRYPT_ALG_HANDLE;
extern "C" __declspec(dllimport) NTSTATUS WINAPI BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE *phAlgorithm, LPCWSTR pszAlgId, LPCWSTR pszImplementation, DWORD dwFlags);
extern "C" __declspec(dllimport) NTSTATUS WINAPI BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE hAlgorithm, ULONG dwFlags);
extern "C" __declspec(dllimport) NTSTATUS WINAPI BCryptGenRandom(BCRYPT_ALG_HANDLE hAlgorithm, PUCHAR pbBuffer, ULONG cbBuffer, ULONG dwFlags);
extern "C" __declspec(dllimport) const char * WINAPI ThisDllIsJustAStub(void);

BCRYPT_ALG_HANDLE hAlgorithm = 0;
LPCWSTR pszAlgId = L"fghij";
LPCWSTR pszImplementation = L"abcde";
DWORD dwFlags = 0;
UCHAR bBuffer[16] = {};
ULONG cbBuffer = sizeof(bBuffer);

int main() {
 BCryptOpenAlgorithmProvider(& hAlgorithm, pszAlgId, pszImplementation, dwFlags);
 BCryptCloseAlgorithmProvider(hAlgorithm, dwFlags);
 BCryptGenRandom(hAlgorithm, bBuffer, cbBuffer, dwFlags);
 MessageBoxA(NULL, ThisDllIsJustAStub(), "", 0);
 return 0;
}
mbcryptgcc.bat

Code: Select all

\qb64\internal\c\c_compiler\bin\g++.exe -O3 -Wall -shared -Wl,-s,-shared,--enable-auto-image-base,-dy,--nxcompat,--kill-at -o bcrypt.dll bcrypt.cpp
mtestbcryptgcc.bat

Code: Select all

\qb64\internal\c\c_compiler\bin\dlltool.exe -k -l bcrypt.a -d bcryptgcc.def
\qb64\internal\c\c_compiler\bin\g++.exe -O3 -Wall -Wl,-s,-dy,--nxcompat,--enable-stdcall-fixup -o testbcryptgcc.exe testbcryptgcc.cpp bcrypt.a
mbcryptoldgcc.bat

Code: Select all

c:\dev-cpp\bin\g++.exe -O3 -Wall -shared -Wl,-s,-shared,--enable-auto-image-base,-dy,--kill-at -o bcrypt.dll bcrypt.cpp
mtestbcryptoldgcc.bat

Code: Select all

c:\dev-cpp\bin\dlltool.exe -k -l bcrypt.a -d bcryptoldgcc.def
c:\dev-cpp\bin\g++.exe -O3 -Wall -Wl,-s,-dy,--enable-stdcall-fixup -o testbcryptgcc.exe testbcryptgcc.cpp bcrypt.a
MSVC++ files:

bcryptvc.def

Code: Select all

LIBRARY bcrypt.dll
EXPORTS
BCryptOpenAlgorithmProvider
BCryptCloseAlgorithmProvider
BCryptGenRandom
ThisDllIsJustAStub
testbcryptvc.cpp

Code: Select all

// Code to test the message boxes in the bcrypt stub. msvc++ version.
// Revision 2021 January 01.
// Note: the console window can cover and hide the message box.

// cl.exe /O2 /MD testbcryptvc.cpp bcrypt.lib user32.lib /link /NXCOMPAT
// mt.exe -manifest testbcryptvc.exe.manifest -outputresource:testbcryptvc.exe;1

#include <windows.h>

extern "C" __declspec(dllimport) const char * WINAPI ThisDllIsJustAStub(void);

BCRYPT_ALG_HANDLE hAlgorithm = 0;
LPCWSTR pszAlgId = L"fghij";
LPCWSTR pszImplementation = L"abcde";
DWORD dwFlags = 0;
UCHAR bBuffer[16] = {};
ULONG cbBuffer = sizeof(bBuffer);

int main() {
 BCryptOpenAlgorithmProvider(& hAlgorithm, pszAlgId, pszImplementation, dwFlags);
 BCryptCloseAlgorithmProvider(hAlgorithm, dwFlags);
 BCryptGenRandom(hAlgorithm, bBuffer, cbBuffer, dwFlags);
 MessageBoxA(NULL, ThisDllIsJustAStub(), "", 0);
 return 0;
}
mbcryptvc.bat

Code: Select all

cl.exe /O2 /LD /MD \c\bcrypt.cpp bcryptvc.def user32.lib /link /NXCOMPAT
mt.exe -manifest bcrypt.dll.manifest -outputresource:bcrypt.dll;2
mtestbcryptvc.bat

Code: Select all

cl.exe /O2 /MD testbcryptvc.cpp bcrypt.lib user32.lib /link /NXCOMPAT
mt.exe -manifest testbcryptvc.exe.manifest -outputresource:testbcryptvc.exe;1
If you use the bat files, you'll have to adjust the paths. (The reason for the \c\ path on the bcrypt.cpp is so that I could have only one copy of that, because it's identical for both compilers.) (The source files should contain the same lines in the comments, but without the paths.)

The commands for msvc++ need to be run from the msvc++ command prompt shortcut, so that the environment variables will be set.

Hopefully I didn't make too many mistakes.

It seems to work. It seems like MakeMKV doesn't even call those functions, at least when ripping DVD files from a folder. I'm about to try ripping from an actual disk.

Happy ripping to my fellow XP users.

Edit: It also ripped a DVD from disk without calling those functions.
Edit: updated the bcryptvc.def within the comments in bcrypt.cpp

Edit: 2021 Jan 1:

Accommodated g++ 3.4.2, which comes with Dev-C++ 4.9.9.2. I refer to this as "older MinGW" and "oldgcc". This involves removing ",--nxcompat" from the command lines, and "bcrypt.dll." from the def lines.

Changed testbcrypt to zero initialize bBuffer, and have cbBuffer use sizeof instead of hardcoding.

Added a comment that the message boxes can be underneath and thus hidden by the console window. (I think when launching it from Windows Explorer, the initial message box can be created a fraction of a second prior to the console window.)

Come to think of it, I should have put the revision date in text strings so it'd be in the binaries. Maybe next time, if I revise them again...
bcrypt 2021 01 01.7z
(1.85 KiB) Downloaded 29 times
Last edited by qbm0000 on Fri Jan 01, 2021 8:40 am, edited 2 times in total.

preserve
Posts: 649
Joined: Sun Sep 13, 2015 10:21 pm
Location: Canada

Re: Missing "bcrypt.dll" on Windows XP.

Post by preserve » Sat Dec 26, 2020 6:52 am

qbm0000 wrote:
Sat Dec 12, 2020 9:15 am
I hacked a stub, which allows MakeMKV 1.15.4 to run on Windows XP 32 bit.
^ I normally think of myself as a technical person, but unfortunately, this is mostly beyond me. This is C++ that needs to be compiled? Can you share the compiled result?

I run a Windows XP SP3 machine solely for ripping, and while it's been fine through 1.15.3 (though Mike keeps nagging me to get off XP), with 1.15.4 I can confirm the same error that you encountered.

Perhaps Mike can address this within MakeMKV for 1.15.5.

Image
Using: ASUS BW-16D1HT 3.00

gonca
Posts: 16
Joined: Mon Feb 19, 2018 10:35 pm

Re: Missing "bcrypt.dll" on Windows XP.

Post by gonca » Sat Dec 26, 2020 1:46 pm

Try this link
https://www.dll-files.com/bcrypt.dll.html
Pick the correct one and download

NOTE
Please sandbox and check for malware before using.
I never had need to use that site before so I can't tell you if they are legit or not

dcoke22
Posts: 301
Joined: Wed Jul 22, 2020 11:25 pm

Re: Missing "bcrypt.dll" on Windows XP.

Post by dcoke22 » Sat Dec 26, 2020 6:27 pm

Out of curiosity… why continue to run a Windows XP machine only for ripping?

qbm0000
Posts: 6
Joined: Mon Nov 02, 2015 2:17 pm

Re: Missing "bcrypt.dll" on Windows XP.

Post by qbm0000 » Fri Jan 01, 2021 6:22 am

preserve wrote:
Sat Dec 26, 2020 6:52 am
Can you share the compiled result?
I just happened to check back on a whim, and noticed your response.

I'm not comfortable uploading binaries here.

I'll walk you through it using the old version of MinGW (3.4.2) that comes with the old version of Bloodshed Dev-C++ (4.9.9.2). This is a very old compiler, but it should be sufficient for this. The download is <9MB.

https://sourceforge.net/projects/dev-cp ... e/download

Proceed through the setup.

On the "Choose components" part, it's up to you. Definitely leave "MinGW compiler system" checked. Starting from "Typical", I would suggest leaving "Help files" and "Create shortcuts in Start Menu" checked. I would recommend unchecking "Associate C and C++ files" and "Create Quick Launch shortcut". (I like having the files associated with Notepad.)

The default folder is "C:\Dev-Cpp", and I'll assume you install there.

It asks whether you want to install for all users. It probably won't matter, but I'm choosing "Yes".

After installation, you don't have to run Dev-C++. If you do, it will ask you a few configuration questions. But we won't be using the IDE. We'll be compiling directly from the command line.

Now, you can create a new folder. I'll assume you create a folder named "bcrypt" in your "C:" drive.

Extract the following Zip file into that folder.
bcrypt 2021 01 01 oldgcc.zip
(2.74 KiB) Downloaded 42 times
Now, go to the "Start" menu, "All Programs", "Accessories", and run "Command Prompt".

Type:

Code: Select all

c:
cd \bcrypt
mbcryptoldgcc
copy bcrypt.dll "c:\program files\makemkv\"
The result should look something like this:
bcrypt screenshot.png
bcrypt screenshot.png (46.48 KiB) Viewed 2052 times
That should do it.

I edited my earlier post to update the source code.

Please let me know if it works, or if you have trouble.

preserve
Posts: 649
Joined: Sun Sep 13, 2015 10:21 pm
Location: Canada

Re: Missing "bcrypt.dll" on Windows XP.

Post by preserve » Sat Jan 02, 2021 8:15 am

qbm0000 wrote:
Fri Jan 01, 2021 6:22 am
I'll walk you through it using the old version of MinGW ... Please let me know if it works, or if you have trouble.
Worked perfectly, thank you very much for making this, and taking the time to write out the instructions!
dcoke22 wrote:
Sat Dec 26, 2020 6:27 pm
Out of curiosity… why continue to run a Windows XP machine only for ripping?
Just because I have a lot to rip, and I'm often gaming, processing video, etc. on my primary system, so until I get a new system, I've been using my old XP system for ripping, and I haven't had the time or the energy to look into whether a newer Windows would even run on that system... it's currently the path of least resistance lol.
Using: ASUS BW-16D1HT 3.00

qbm0000
Posts: 6
Joined: Mon Nov 02, 2015 2:17 pm

Re: Missing "bcrypt.dll" on Windows XP.

Post by qbm0000 » Sat Jan 02, 2021 11:41 am

preserve wrote:
Sat Jan 02, 2021 8:15 am
Worked perfectly, thank you very much for making this, and taking the time to write out the instructions!
That's good. You're welcome. I'm glad it was useful.

schreiberstein
Posts: 1
Joined: Wed Jan 13, 2021 10:46 pm

Re: Missing "bcrypt.dll" on Windows XP.

Post by schreiberstein » Wed Jan 13, 2021 11:09 pm

qbm0000 wrote:
Fri Jan 01, 2021 6:22 am
preserve wrote:
Sat Dec 26, 2020 6:52 am
Can you share the compiled result?
Please let me know if it works, or if you have trouble.
Hello qbasic michael,

thank you very much for your effort to keep achieve Windows XP compatibility.
Sadly, I am experiencing problems with the latest MakeMKVversion 1.15.4.0 on Windows XP.
I successfully built the stub library and copied it to the program directory, but the program crashes.
First, a child process (?)gets terminated in the background "MakeMKV console application has encountered a problem and needs to close."
The main program window launches though. I can also see that it tries to establish a server connection.
Then a corrupted error message appears (black window - see attached screenshot) and the program hangs and needs to be terminated.

IDA Pro Debugger is able to detect these errors:

Debugged application message: OpenThemeData() failed for theme 5 (MENU). (Element not found.)
[...]
Debugged application message: OpenThemeData() failed for theme 11 (TASKDIALOG). (Element not found.)
[ ...]

Debugger: thread 5688 has exited (code 0)
Debugger: thread 5160 has exited (code 0)
Debugger: thread 5328 has exited (code 0)
Debugger: process has exited (exit code 0)

Do you have any idea how to fix this?

On another note: I am not an experienced programmer, but I think it should be possible to make the library load of bcrypt.dll conditional (e.g. NT VERSION > NT5) in makemkv's main source code. If backwards compatibility is desired, that is.

Cheers,
schreiberstein
Attachments
Error message
Error message
makemkv-11540-winxp.PNG (29.87 KiB) Viewed 659 times

Post Reply