Fix "OSError: Unable to find libfuse" on Windows

This commit is contained in:
ColdWindScholar 2024-05-04 11:55:05 +08:00
parent 89afbbbe96
commit f8ced92bdf
4 changed files with 112 additions and 112 deletions

Binary file not shown.

Binary file not shown.

View file

@ -1,38 +1,34 @@
from fuse import FuseOSError, Operations, LoggingMixIn from stat import S_IFDIR, S_IFREG
from pathlib import Path
import logging
import os
from stat import S_IFDIR, S_IFLNK, S_IFREG
from time import time
import mmap
import errno
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from time import time
import sys
import os
if not os.environ.get('FUSE_LIBRARY_PATH') and os.name == 'nt':
os.environ.setdefault('FUSE_LIBRARY_PATH', os.path.join(os.path.dirname(__file__), r"bin\winfsp-%s.dll" % ("x64" if sys.maxsize > 0xffffffff else "x86")))
from fuse import Operations, LoggingMixIn
class MtkDaFS(LoggingMixIn, Operations): class MtkDaFS(LoggingMixIn, Operations):
def __init__(self, da_handler, rw=False): def __init__(self, da_handler, rw=False):
self.da_handler = da_handler self.da_handler = da_handler
self.rw = rw self.rw = rw
self.files = {} self.files = {'/': dict(
self.files['/'] = dict(
st_mode=(S_IFDIR | 0o555), st_mode=(S_IFDIR | 0o555),
st_ctime=time(), st_ctime=time(),
st_mtime=time(), st_mtime=time(),
st_atime=time(), st_atime=time(),
st_nlink=2) st_nlink=2), '/emmc_user.bin': dict(
self.files['/emmc_user.bin'] = dict(
st_mode=(S_IFREG | 0o777) if self.rw else (S_IFREG | 0o555), st_mode=(S_IFREG | 0o777) if self.rw else (S_IFREG | 0o555),
st_ctime=time(), st_ctime=time(),
st_mtime=time(), st_mtime=time(),
st_atime=time(), st_atime=time(),
st_nlink=2, st_nlink=2,
st_size = self.da_handler.mtk.daloader.daconfig.flashsize) st_size=self.da_handler.mtk.daloader.daconfig.flashsize), '/partitions': dict(
self.files['/partitions'] = dict(
st_mode=(S_IFDIR | 0o555), st_mode=(S_IFDIR | 0o555),
st_ctime=time(), st_ctime=time(),
st_mtime=time(), st_mtime=time(),
st_atime=time(), st_atime=time(),
st_nlink=2) st_nlink=2)}
for part in self.da_handler.mtk.daloader.get_partition_data(): for part in self.da_handler.mtk.daloader.get_partition_data():
self.files[f'/partitions/{part.name}'] = dict( self.files[f'/partitions/{part.name}'] = dict(
@ -45,7 +41,8 @@ class MtkDaFS(LoggingMixIn, Operations):
offset=part.sector * self.da_handler.mtk.daloader.daconfig.pagesize) offset=part.sector * self.da_handler.mtk.daloader.daconfig.pagesize)
def readdir(self, path, fh): def readdir(self, path, fh):
return ['.', '..'] + [ x.removeprefix(path).removeprefix('/') for x in self.files if x.startswith(path) and x != path] return ['.', '..'] + [x.removeprefix(path).removeprefix('/') for x in self.files if
x.startswith(path) and x != path]
def read(self, path, size, offset, fh): def read(self, path, size, offset, fh):
if size + offset > self.files[path]['st_size']: if size + offset > self.files[path]['st_size']:

13
stage2
View file

@ -17,6 +17,7 @@ from mtkclient.Library.Hardware.hwcrypto import crypto_setup, hwcrypto
from mtkclient.config.mtk_config import Mtk_Config from mtkclient.config.mtk_config import Mtk_Config
from mtkclient.config.usb_ids import default_ids from mtkclient.config.usb_ids import default_ids
class Stage2(metaclass=LogBase): class Stage2(metaclass=LogBase):
def __init__(self, args, loglevel=logging.INFO): def __init__(self, args, loglevel=logging.INFO):
self.__logger = self.__logger self.__logger = self.__logger
@ -191,7 +192,6 @@ class Stage2(metaclass=LogBase):
if self.cdc.connected: if self.cdc.connected:
self.readflash(type=0, start=start, length=length, display=True, filename=filename) self.readflash(type=0, start=start, length=length, display=True, filename=filename)
def preloader(self, start, length, filename): def preloader(self, start, length, filename):
sectors = 0 sectors = 0
if start != 0: if start != 0:
@ -401,7 +401,8 @@ class Stage2(metaclass=LogBase):
retval["socid"] = hexlify(socid).decode('utf-8') retval["socid"] = hexlify(socid).decode('utf-8')
except Exception as err: except Exception as err:
pass pass
if self.setup.dxcc_base is not None and mode not in ["sej_aes_decrypt","sej_aes_encrypt","sej_sst_decrypt","sej_sst_encrypt","dxcc_sha256"]: if self.setup.dxcc_base is not None and mode not in ["sej_aes_decrypt", "sej_aes_encrypt", "sej_sst_decrypt",
"sej_sst_encrypt", "dxcc_sha256"]:
rpmbkey = self.hwcrypto.aes_hwcrypt(btype="dxcc", mode="rpmb") rpmbkey = self.hwcrypto.aes_hwcrypt(btype="dxcc", mode="rpmb")
rpmb2key = self.hwcrypto.aes_hwcrypt(btype="dxcc", mode="rpmb2") rpmb2key = self.hwcrypto.aes_hwcrypt(btype="dxcc", mode="rpmb2")
fdekey = self.hwcrypto.aes_hwcrypt(btype="dxcc", mode="fde") fdekey = self.hwcrypto.aes_hwcrypt(btype="dxcc", mode="fde")
@ -437,7 +438,8 @@ class Stage2(metaclass=LogBase):
self.config.hwparam.writesetting("provkey", hexlify(provkey).decode('utf-8')) self.config.hwparam.writesetting("provkey", hexlify(provkey).decode('utf-8'))
retval["provkey"] = hexlify(provkey).decode('utf-8') retval["provkey"] = hexlify(provkey).decode('utf-8')
return retval, keyinfo return retval, keyinfo
elif self.setup.sej_base is not None and mode not in ["sej_aes_decrypt","sej_aes_encrypt","sej_sst_decrypt","sej_sst_encrypt","dxcc_sha256"]: elif self.setup.sej_base is not None and mode not in ["sej_aes_decrypt", "sej_aes_encrypt", "sej_sst_decrypt",
"sej_sst_encrypt", "dxcc_sha256"]:
retval = {} retval = {}
rpmbkey = self.hwcrypto.aes_hwcrypt(mode="rpmb", data=meid, otp=otp, btype="sej") rpmbkey = self.hwcrypto.aes_hwcrypt(mode="rpmb", data=meid, otp=otp, btype="sej")
if rpmbkey: if rpmbkey:
@ -501,7 +503,6 @@ class Stage2(metaclass=LogBase):
self.usbwrite(pack(">I", 0x3000)) self.usbwrite(pack(">I", 0x3000))
def getint(valuestr): def getint(valuestr):
if valuestr == '': if valuestr == '':
return None return None
@ -544,7 +545,8 @@ def showcommands():
def main(): def main():
parser = argparse.ArgumentParser(description=info) parser = argparse.ArgumentParser(description=info)
subparsers = parser.add_subparsers(dest="cmd", help='Valid commands are: rpmb, preloader, data, boot2, memread, memwrite, keys') subparsers = parser.add_subparsers(dest="cmd",
help='Valid commands are: rpmb, preloader, data, boot2, memread, memwrite, keys')
parser_rpmb = subparsers.add_parser("rpmb", help="Dump the rpmb") parser_rpmb = subparsers.add_parser("rpmb", help="Dump the rpmb")
parser_rpmb.add_argument('--start', dest='start', type=str, parser_rpmb.add_argument('--start', dest='start', type=str,
@ -743,5 +745,6 @@ def main():
print("Successfully wrote seccfg to seccfg.bin. You need to write seccfg.bin to partition seccfg.") print("Successfully wrote seccfg to seccfg.bin. You need to write seccfg.bin to partition seccfg.")
st2.close() st2.close()
if __name__ == "__main__": if __name__ == "__main__":
main() main()