Aorimn / dislocker

FUSE driver to read/write Windows' BitLocker-ed volumes under Linux / Mac OSX
GNU General Public License v2.0
1.59k stars 196 forks source link

Building on M1, MacOS 11.1 + MacFuse 4.0.5 fails: library not found for -losxfuse_i64 #239

Closed rev111 closed 3 years ago

rev111 commented 3 years ago

Hello, since I have a different processor, OS and OSXFuse version I moved this into a separate issue.

I'm trying to build under OSX Big Sur 11.1 with the new M1/Silicon processor.
I rely on Macports as package manager and installing homebrew along it is not recommended. So I'm trying to build from source. cmake runs successful (albeit with warnings) with this command from issue 223: LIBRARY_PATH=/usr/local/lib:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include cmake .

But make fails:

dislocker2 % make
[ 44%] Built target dislocker
[ 47%] Built target dislocker-bek
[ 47%] Built target dislocker-find
[ 50%] Built target dislocker-file
[ 51%] Linking C executable dislocker-fuse
**ld: library not found for -losxfuse_i64**
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/dislocker-fuse] Error 1
make[1]: *** [src/CMakeFiles/dislocker-fuse.dir/all] Error 2
make: *** [all] Error 2

The libraries below have been installed by the latest version of OSXFuse (now renamed to MacFuse) 4.0.5. Are these the osxfuse libraries that dislocker expects?

dislocker2 % ls -la /usr/local/lib/*fuse*
-rwxr-xr-x  1 root  wheel  580688  2 Jan 03:54 /usr/local/lib/libfuse.2.dylib
lrwxr-xr-x  1 root  wheel      15  3 Jan 22:53 /usr/local/lib/libfuse.dylib -> libfuse.2.dylib
-rwxr-xr-x  1 root  wheel     971  2 Jan 03:54 /usr/local/lib/libfuse.la
lrwxr-xr-x  1 root  wheel      15  3 Jan 22:53 /usr/local/lib/libosxfuse.2.dylib -> libfuse.2.dylib
lrwxr-xr-x  1 root  wheel      15  3 Jan 22:53 /usr/local/lib/libosxfuse_i64.2.dylib -> libfuse.2.dylib

I tried to alter search terms in make/FindFUSE.cmake like this:

# find lib
if (APPLE)
    SET(FUSE_NAMES libfuse.dylib libosxfuse.2.dylib libosxfuse_i64.2.dylib libosxfuse.dylib fuse)
else (APPLE)
    SET(FUSE_NAMES fuse)
endif (APPLE)
FIND_LIBRARY(FUSE_LIBRARIES
        NAMES ${FUSE_NAMES}
        PATHS /lib64 /lib /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib
)

I also tried appending the library path:

dislocker2 % echo $LIBRARY_PATH
/usr/local/lib

as well as presetting it like with the cmake command: LIBRARY_PATH=/usr/local/lib:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include make

But the error remains, and I'm running out of ideas. I'm not even sure where the check for losxfuse_i64 comes from. Maybe somebody knows how to find out which library exactly is expected here and where it should be found? Any help very much appreciated!

rev111 commented 3 years ago

I solved it and can read and write bitlocker-encrypted partitions. For anyone else looking for this, here is a list of steps for building and running on OS X 11 and an M1-processor. It took a few days trying and leaving it and trying again, I hope I haven't forgotten some details:

Building: -OSX Big Sur 11.1 -M1/Silicon processor. -Install MacFuse 4.0.5 (formerly known as OSXFuse). This requires making changes about kernel extensions at boot time. You may verify that it's working by installing and running Veracrypt. -Install the standalone command line tools from Apple, so that they are found later under /Library/Developer/CommandLineTools Maybe the command line tools are also available under /Applications/Xcode/.... but I haven't checked.

Install macports. Then install these packages:

port install cmake
port install mbedtls

Link some include files to be found later by src/dislocker-fuse.c

ln -s /usr/local/include/osxfuse /usr/local/include/fuse/osxfuse
ln -s /usr/local/include/osxfuse /usr/local/include/fuse

Download the dislocker source and make a few changes: Change cmake/FindFUSE.cmake:

FIND_PATH (FUSE_INCLUDE_DIRS fuse.h
        /usr/local/include/osxfuse
    /usr/local/include/fuse

if (APPLE)
    SET(FUSE_NAMES libosxfuse.dylib fuse)

Now start cmake: LIBRARY_PATH=/usr/local/lib:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include cmake .

to make make find the fuse libs, export LIBRARY_PATH:

export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/lib"
make
sudo make install

Attach a bitlocker partition: -Insert a Bitlocker encrypted partition on a mobile device -Find the name of the partition with 'diskutil list'. In this case the partition is at /dev/disk4s1

sudo dislocker -vvv -V /dev/disk4s1 -u /Volumes/bitlocker-partition1
sudo hdiutil attach -imagekey diskimage-class=CRawDiskImage /Volumes/bitlocker-partition1/dislocker-file

the partition name will appear as a new drive in Finder. In this case, the partition's name is BITLOCKER_PARTITION

To de-attach the partition: sudo umount /Volumes/BITLOCKER_PARTITION

Hope this helps someone! Thank you Aorimn!

emads3 commented 3 years ago

@rev111 I wasted almost 3 weeks trying to compile it on M1 but I can't, I have problems in MAKE and CMAKE can you please provide more details or can you provide the compiled version of it, I'd really appreciate it.

rev111 commented 3 years ago

Hi Emad, sorry I’m a bit late. I’m really no expert on this, so I might not be able to help you. However, if you send more info on the problems you face, I can look into it. In the meantime, here is the compiled binary from my M1, hope that helps! dislocker-fuse.zip

My instructions above to mount and umount are a bit outdated, lately I used the gist from here: https://gist.github.com/dumbledore/2c9f2a6410763c3f96516945b65bc5bb which was mentioned here: https://apple.stackexchange.com/questions/239714/open-bitlocker-usb-stick-on-os-x

Edit: Adding .jpg as file extension was a stupid idea, zipped it instead.

qiyan98 commented 1 year ago

I solved it and can read and write bitlocker-encrypted partitions. For anyone else looking for this, here is a list of steps for building and running on OS X 11 and an M1-processor. It took a few days trying and leaving it and trying again, I hope I haven't forgotten some details:

Thanks! This is very helpful. I tested this on M2 macbook air with Ventura 13.4.1.

After installing macfuse, macports and other dependencies, I just ran the following commands:

port install cmake
port install mbedtls
LIBRARY_PATH=/usr/local/lib:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include cmake .
make
sudo make install

Then dislocker is ready to go!

GoelBiju commented 1 year ago

I solved it and can read and write bitlocker-encrypted partitions. For anyone else looking for this, here is a list of steps for building and running on OS X 11 and an M1-processor. It took a few days trying and leaving it and trying again, I hope I haven't forgotten some details:

Thanks! This is very helpful. I tested this on M2 macbook air with Ventura 13.4.1.

After installing macfuse, macports and other dependencies, I just ran the following commands:

port install cmake
port install mbedtls
LIBRARY_PATH=/usr/local/lib:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include cmake .
make
sudo make install

Then dislocker is ready to go!

This is great, thanks @qiyan98. To add, for anyone who is still struggling to set up dislocker and finds this issue, I tested these commands on my M1 Macbook Pro running macOS 14.1 Sonoma.

Make sure to install MacPorts first (https://www.macports.org/). Then install macFUSE through the installer (https://osxfuse.github.io/) and make sure the kernel extensions are enabled.

Perform the commands given by @qiyan98 above to install cmake and mbedtls. Before you go and make the dislocker build, you will have to edit mbedtls slightly to prevent the build from failing, just run sed/gsed (I used gsed) with the following command: https://github.com/Aorimn/dislocker/issues/313#issuecomment-1599710305.

gsed -i 's/^#include "mbedtls\/config.h"/#include "mbedtls\/mbedtls_config.h"/;s/#    define SHA256(input, len, output)         mbedtls_sha256_ret(input, len, output, 0)/#    define SHA256(input, len, output)         mbedtls_sha256(input, len, output, 0)/' include/dislocker/ssl_bindings.h

After this, run the cmake and make install commands in the comment from @qiyan98 and dislocker should be up and running.

5UP4F15H commented 3 months ago

This also works on Sonoma 14.5 M2 & M3 with homebrew instead of macports just need to do the following:

brew install cmake mbedtls@2 pkg-config fuse
LIBRARY_PATH=/usr/local/lib:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include cmake .
make
sudo make install

Compiling dislocker requires the second version of Mbed-TSL (previously PolarSSL). Trying to compile with the latest (third) version causes an error so you have to use

mbedtls@2 

As the mbedlts@2 package is only available as a keg, no symbolic links are created into /usr/local by default. Thankfully, we may easily temporarily replace the linked libraries from mbedtls (if installed) with mbedtls@2:

brew unlink mbedtls
brew link mbedtls@2

Now we may get the latest version of dislocker, compile and install it:

git clone https://github.com/Aorimn/dislocker.git
cd dislocker &&
cmake . &&
make &&
sudo make install

Finally with dislocker installed, we may undo the previous changes and relink to version 3 if you have it installed:

brew unlink mbedtls@2
brew link mbedtls