public override void LoadDevicePartitions()
        {
            if (this.Device.HasPartition)
            {
                return;
            }
            var partlink = new DISK_INFO();
            var result   = FileServiceCoreDll.GetDiskInfo(ref partlink, this.Device.DiskNumber);

            if (result != 0)
            {
                //LogHelper.Error(string.Format(LanguageHelper.Get("LANGKEY_HuoQuCiPanFenQuXinXiShiBaiDiCe_01591"), this.Device.Name, result));
                return;
            }
            if (partlink.part_counts == 0)
            {
                //LogHelper.Info(string.Format(LanguageHelper.Get("LANGKEY_CiPanFenQuGeShuWei_01592"), this.Device.Name));
                return;
            }
            for (int i = 0; i < partlink.part_counts; i++)
            {
                var part      = partlink.pt[i];
                var partition = new FileSystemPartition();
                partition.Name         = part.driver_letter.ToString();
                partition.Discription  = part.vol_name;
                partition.FileSystem   = part.file_system;
                partition.SerialNumber = string.Format("{0:X}", part.serial_num);
                partition.Size         = (ulong)part.sectors.ToSafeInt64() * 512;
                partition.SectorOffset = (ulong)part.start_lba.ToSafeInt64();
                partition.TotalSectors = (ulong)part.sectors.ToSafeInt64();
                this.Device.Parts.Add(partition);
            }
        }
        /// <summary>
        /// 设备关闭
        /// </summary>
        public override void Close()
        {
            if (Device == null || Device.Parts.Count == 0)
            {
                return;
            }

            try
            {
                // 卸载装载分区句柄
                foreach (var part in Device.Parts)
                {
                    var fpart = (FileSystemPartition)part;
                    if (fpart.Mount != IntPtr.Zero)
                    {
                        IntPtr mount    = fpart.Mount;
                        var    nodelist = fpart.NodeLinkList;
                        FileServiceCoreDll.DisposeLinkTableRoom(mount, ref nodelist);
                        MirrorCoreDll.UnmountPartitionHandle(ref mount);
                        fpart.Mount = IntPtr.Zero;

                        LoggerManagerSingle.Instance.Info(string.Format("卸载分区并释放节点链表空间(名称:{0},描述:{1},大小:{2},Mount:{3})", fpart.Name, fpart.Discription, fpart.Size, fpart.Mount));
                    }
                }
                // 释放设备打开句柄
                MirrorCoreDll.CloseDevice(Device.Handle);
                LoggerManagerSingle.Instance.Info(string.Format("关闭设备(名称:{0},大小:{1},Handle:{2})成功", Device.Name, Device.Size, Device.Handle));
            }
            catch (Exception ex)
            {
                LoggerManagerSingle.Instance.Error(string.Format("关闭设备时出错(名称:{0},大小:{1},Handle:{2})时出现错误, 信息:{3}", Device.Name, Device.Size, Device.Handle, ex.Message));
            }
        }
        public override IntPtr OpenDevice()
        {
            IntPtr handle = FileServiceCoreDll.OpenDevice(this.Device.DiskNumber);

            Device.Handle = handle;
            return(handle);
        }
Esempio n. 4
0
        /// <summary>
        /// 装载设备
        /// </summary>
        /// <returns></returns>
        public override IntPtr MountDevice()
        {
            if (this.RunPartition == null)
            {
                return(IntPtr.Zero);
            }
            if (this.RunPartition.Mount != IntPtr.Zero)
            {
                return(this.RunPartition.Mount);
            }
            byte   fs    = (byte)(this.Device.ScanModel == 0xC0 ? 0xFF : this.RunPartition.FileSystem); //高级模式或者RAW模式下设置为0xFF
            IntPtr mount = IntPtr.Zero;

            this.RunPartition.DevType = 0x1B;
            mount = FileServiceCoreDll.MountPartition(this.RunPartition.SnapShotHandle, this.Device.Handle_Flsh,
                                                      this.RunPartition.SectorOffset, this.RunPartition.TotalSectors, fs,
                                                      this.RunPartition.PartType, this.RunPartition.DevType);
            if (mount.ToInt32() == 0)
            {
                //LogHelper.Error(string.Format(LanguageHelper.Get("LANGKEY_ZhuangZaiXiTongFenQuMingChengM_04947"), RunPartition.Name, RunPartition.Discription, RunPartition.Size));
            }

            this.RunPartition.Mount = mount;
            return(mount);
        }
Esempio n. 5
0
        /// <summary>
        /// 获取设备分区
        /// </summary>
        public override void LoadDevicePartitions()
        {
            if (this.Device.Parts.Count != 0)
            {
                return;
            }
            var    link         = new DSK_PART_TABLE();
            UInt64 totalSectors = 0;
            var    result1      = FileServiceCoreDll.DeviceTotalSectors(this.Device.Handle_Flsh, ref totalSectors);
            var    handle       = FileServiceCoreDll.MountDisk(this.Device.Handle_Flsh, -1, totalSectors, 0x1B);
            var    result2      = FileServiceCoreDll.GetPhysicalPartitions(handle, ref link);

            if (result2 != 0)
            {
                //LogHelper.Error(LanguageHelper.Get("LANGKEY_HuoQuSaiBanJingXiangWenJianFen_04946") + result2);
                return;
            }
            var parts = this.CreatePartition(link);

            foreach (var part in parts)
            {
                part.DevType  = 0x12;
                part.PartType = 0;
                this.Device.Parts.Add(part);
            }
            FileServiceCoreDll.FreePartitionTableHandle(ref link);
        }
Esempio n. 6
0
        /// <summary>
        /// 设备关闭
        /// </summary>
        public override void Close()
        {
            if (null == this.Device || null == this.Device.Parts || this.Device.Parts.Count == 0)
            {
                return;
            }
            // 卸载装载分区句柄
            foreach (var part in this.Device.Parts)
            {
                var fpart = (FileSystemPartition)part;
                if (fpart.Mount != IntPtr.Zero)
                {
                    //LogHelper.Info(string.Format(LanguageHelper.Get("LANGKEY_XieZaiFenQuBingShiFangJieDianL_04948"), fpart.Name, fpart.Discription, fpart.Size, fpart.Mount));
                    IntPtr mount    = fpart.Mount;
                    var    nodelist = fpart.NodeLinkList;
                    FileServiceCoreDll.DisposeLinkTableRoom(mount, ref nodelist);
                    MirrorCoreDll.UnmountPartitionHandle(ref mount);
                    fpart.Mount = IntPtr.Zero;
                }
            }
            // 卸载设备句柄
            IntPtr handle = this.Device.Handle_Flsh;

            FileServiceCoreDll.UnmountDeviceHandle(ref handle);
            //LogHelper.Info(string.Format(LanguageHelper.Get("LANGKEY_XieZaiSheBeiJuBingMingChengDaX_04949"), Device.Name, Device.Size, Device.Handle_Flsh));
            // 释放设备句柄
            MirrorCoreDll.CloseDevice(this.Device.Handle);
            //LogHelper.Info(string.Format(LanguageHelper.Get("LANGKEY_ShiFangSheBeiJuBingMingChengDa_04950"), Device.Name, Device.Size, Device.Handle));
        }
Esempio n. 7
0
        /// <summary>
        /// 装载UFED镜像
        /// </summary>
        /// <param name="mirrors"></param>
        /// <returns></returns>
        private IntPtr MountRaid(IList <string> mirrors)
        {
            var raid = new RAID_INFO_EX
            {
                dvi = new DEVICE_BASE_INFO[128]
            };

            for (var i = 0; i < mirrors.Count; i++)
            {
                var file = mirrors[i];
                if (!System.IO.File.Exists(file))
                {
                    //LogHelper.Error(string.Format(LanguageHelper.Get("LANGKEY_WenJianBuCunZai_01571"), file));
                    continue;
                }
                var info = new DEVICE_BASE_INFO();
                info.dev_type   = 0x11;
                info.offset_sec = 0;
                info.len        = (ulong)FileHelper.GetFileLength(file);
                info.secs       = (info.len + 511) / 512;
                info.hDev       = FileServiceCoreDll.OpenFile(file);
                raid.dvi[i]     = info;
            }
            // 阵列类型
            raid.raid_type = 0x8000;
            // 磁盘个数
            raid.dsk_counts = (uint)mirrors.Count;
            var resut = FileServiceCoreDll.MountRaid(ref raid);

            this.RaidInfoEx = raid;
            return(resut);
        }
 /// <summary>
 /// 获取打开设备句柄
 /// </summary>
 /// <returns></returns>
 public override IntPtr OpenDevice()
 {
     if (Device == null)
     {
         LoggerManagerSingle.Instance.Error("Invalid device");
         return(IntPtr.Zero);
     }
     Device.Handle = FileServiceCoreDll.OpenFile(Device.Source.ToString());
     return(Device.Handle);
 }
        /// <summary>
        /// 获取设备分区
        /// </summary>
        public override void LoadDevicePartitions()
        {
            try
            {
                Asyn?.Advance(1, LanguageHelperSingle.Instance.GetLanguageByKey(Languagekeys.FileServiceLanguage_File_JiaZaiXiTongFenQuLieBiao));

                var rootTable = new DSK_PART_TABLE();
                var result    = FileServiceCoreDll.GetMirrorFilePartitions(ref rootTable, Device.Source.ToString());
                if (result != 0)
                {
                    LoggerManagerSingle.Instance.Error("1/123获取镜像文件的分区信息失败并返回");
                    return;
                }
                if (rootTable.next == IntPtr.Zero)  //无法读取分区,需要进行深度分区扫描
                {
                    var handle = FileServiceCoreDll.MountDisk(Device.Handle, -1, (ulong)Device.TotalSectors, 0x12);
                    if (handle == IntPtr.Zero)
                    {
                        LoggerManagerSingle.Instance.Error(string.Format("2/123获取镜像文件的分区信息成功;无法读取分区,需要进行深度分区扫描;加载磁盘句柄失败(句柄:{0}, disNum:{1},扇区数:{2},设备类型:0x12)", Device.Handle, -1, Device.TotalSectors));
                    }

                    FindVolumeCallBack fv = (ref FIND_VOLUME_PROGRESS pdi) => { return(0); };
                    try
                    {
                        result = FileServiceCoreDll.GetPhysicalPartitionsByScall(handle, fv, 0, 1, ref rootTable);
                    }
                    catch (Exception ex)
                    {
                        LoggerManagerSingle.Instance.Error("深度查找分区异常", ex);
                    }

                    if (result != 0)
                    {
                        LoggerManagerSingle.Instance.Error("3/123获取镜像文件的分区信息成功; 无法读取分区,需要进行深度分区扫描; 深度查找分区失败并返回");
                        return;
                    }

                    var parts = CreatePartition(rootTable);
                    Device.Parts.AddRange(parts);
                    FileServiceCoreDll.UnloadDeviceHandle(ref handle);
                }
                else
                {
                    var parts = CreatePartition(rootTable);
                    Device.Parts.AddRange(parts);
                }
            }
            catch (Exception ex)
            {
                LoggerManagerSingle.Instance.Error("获取设备分区异常", ex);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 分层扫描接口 扫描文件夹
        /// </summary>
        /// <param name="partition">分区</param>
        /// <returns></returns>
        public List <FNodeX> GetFileSystemByDir(FNodeX pNode)
        {
            LINK_DIR_FILE_NODE_INFO link = new LINK_DIR_FILE_NODE_INFO();
            var result = FileServiceCoreDll.ScanFilesByDir(pNode.Mount, GetFileSystemByDirScanCallBack, pNode.Key, ref link);

            if (0 != result)
            {
            }

            // 加载树结构;
            var source = BuildDataDictionary(link);

            BuildTree(pNode, source);

            return(pNode.Collection);
        }
Esempio n. 11
0
        private bool RecoveryFile(FNodeX source, string savePath)
        {
            var node = source.Source;
            FILE_RECOVERY_INFO file = new FILE_RECOVERY_INFO();

            file.Attr         = node.FileAttribute;
            file.FileId       = node.FileId;
            file.OffSet       = node.OffsetBytes;
            file.OffsetSec    = node.OffsetSec;
            file.ParentFileId = node.ParentFileId;
            file.Size         = node.Size;

            CHECK_SUM_INFO check = new CHECK_SUM_INFO();

            int res = 0;

            IntPtr fileHandle = IntPtr.Zero;

            try
            {
                fileHandle = FileServiceCoreDll.CreateNewFile(savePath);

                res = FileServiceCoreDll.RecoveryFile(source.Mount, fileHandle, LpfnRecoveryFileProgressEx, ref file, ref check);

                if (0 != res)
                {
                    LoggerManagerSingle.Instance.Error(string.Format("提取文件时底层库FileServiceCoreDll.RecoveryFile失败!错误码:{0}", res));
                }
            }
            catch (Exception ex)
            {
                LoggerManagerSingle.Instance.Error("提取文件时底层库FileServiceCoreDll.RecoveryFile出现异常!", ex);
            }
            finally
            {
                if (IntPtr.Zero != fileHandle)
                {
                    FileServiceCoreDll.CloseDevice(fileHandle);
                }
            }

            return(res == 0);
        }
Esempio n. 12
0
        private byte[] ReadFileBytes(FNodeX source, int offset = 0, int len = 0)
        {
            var node = source.Source;
            FILE_RECOVERY_INFO file = new FILE_RECOVERY_INFO();

            file.Attr         = node.FileAttribute;
            file.FileId       = node.FileId;
            file.OffSet       = node.OffsetBytes;
            file.OffsetSec    = node.OffsetSec;
            file.ParentFileId = node.ParentFileId;
            file.Size         = node.Size;
            byte[] buff = new byte[len];
            try
            {
                FileServiceCoreDll.ReadFileByBottom(source.Mount, ref file, (ulong)offset, len, buff);
            }
            catch (Exception ex)
            {
                LoggerManagerSingle.Instance.Error("提取文件时底层库FileServiceCoreDll.ReadFileByBottom出现异常!", ex);
            }
            return(buff);
        }
Esempio n. 13
0
        /// <summary>
        /// 停止当前工作
        /// </summary>
        public override void Stop()
        {
            base.Stop();
            if (RunPartition == null)
            {
                return;
            }
            try
            {
                FileServiceCoreDll.Stop(RunPartition.Mount);
                if (RunPartition.Mount != IntPtr.Zero)
                {
                    LoggerManagerSingle.Instance.Error(string.Format("停止操作并卸载分区(名称:{0},描述:{1},大小:{2},Mount:{3})", RunPartition.Name,
                                                                     RunPartition.Discription, RunPartition.Size, RunPartition.Mount));

                    IntPtr mount    = RunPartition.Mount;
                    var    nodelist = RunPartition.NodeLinkList;
                    int    result   = FileServiceCoreDll.DisposeLinkTableRoom(mount, ref nodelist);
                    MirrorCoreDll.UnmountPartitionHandle(ref mount);
                    if (result == 0)
                    {
                        LoggerManagerSingle.Instance.Error(string.Format("释放目录文件节点链表空间(不会释放自己定义的顶层节点空间)(名称:{0},描述:{1},大小:{2},Mount:{3})成功,错误码:{4},卸载分区", RunPartition.Name, RunPartition.Discription, RunPartition.Size, RunPartition.Mount, result));
                    }
                    else
                    {
                        LoggerManagerSingle.Instance.Error(string.Format("释放目录文件节点链表空间(不会释放自己定义的顶层节点空间)(名称:{0},描述:{1},大小:{2},Mount:{3})失败,错误码:{4},卸载分区", RunPartition.Name, RunPartition.Discription, RunPartition.Size, RunPartition.Mount, result));
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerManagerSingle.Instance.Error(string.Format("停止分区(名称:{0},描述:{1},大小:{2},Mount:{3})时出现错误, 信息:{4}", RunPartition.Name, RunPartition.Discription, RunPartition.Size, RunPartition.Mount, ex.Message));
            }
            finally
            {
                RunPartition.Mount = IntPtr.Zero;
                _isStop            = true;
            }
        }
Esempio n. 14
0
        private FNodeX ScanFileSystem(IFileSystemDevice device, FileSystemPartition partition)
        {
            ScanCallBack            callBack = (ref ScanCallBackData pdi) => { };
            LINK_DIR_FILE_NODE_INFO link     = new LINK_DIR_FILE_NODE_INFO();
            LIST_FILE_RAW_TYPE_INFO raw      = CreatRawLink();

            try
            {
                var result = FileServiceCoreDll.ScanFiles(partition.Mount, callBack, ref link, device.ScanModel, ref raw, 0);
                if (result != 0)
                {
                    LoggerManagerSingle.Instance.Error(string.Format("获取文件系统(名称:{ 0},描述: { 1},大小: { 2})失败,错误码: { 3}", partition.Name, partition.Discription, partition.Size, result));

                    return(null);
                }
                partition.NodeLinkList = link;
            }
            catch (Exception ex)
            {
                LoggerManagerSingle.Instance.Error(string.Format("获取文件系统(名称:{0},描述:{1},大小:{2},Mount:{3})时底层dll出错", partition.Name, partition.Discription, partition.Size, partition.Mount), ex);
                return(null);
            }

            // 构建当前分区节点
            var treeNode = new FNodeX
            {
                Source      = link.NodeDataInfo,
                FileName    = partition.VolName,
                IsRoot      = true,
                IsPartition = true,
                Key         = link.NodeDataInfo.FileId,
                ParentKey   = link.NodeDataInfo.ParentFileId
            };
            // 加载树结构;
            var source = BuildDataDictionary(link);

            BuildTree(treeNode, source);
            return(treeNode);
        }
Esempio n. 15
0
        /// <summary>
        /// 装载设备
        /// </summary>
        /// <returns></returns>
        public virtual IntPtr MountDevice()
        {
            if (RunPartition == null)
            {
                return(IntPtr.Zero);
            }
            if (RunPartition.Mount != IntPtr.Zero)
            {
                return(RunPartition.Mount);
            }
            byte fs =
                (byte)
                (Device.ScanModel == 0xC0           //this.Device.ScanModel == 0x87 ||
                        ? 0xFF
                        : RunPartition.FileSystem); //高级模式或者RAW模式下设置为0xFF
            IntPtr mount = IntPtr.Zero;

            try
            {
                mount = FileServiceCoreDll.MountPartition(RunPartition.SnapShotHandle, Device.Handle,
                                                          RunPartition.SectorOffset, RunPartition.TotalSectors, fs,
                                                          RunPartition.PartType, RunPartition.DevType);
                if (mount == IntPtr.Zero)
                {
                    LoggerManagerSingle.Instance.Error(string.Format("装载系统分区(名称:{0},描述:{1},大小:{2})失败!", RunPartition.Name, RunPartition.Discription, RunPartition.Size));
                }
            }
            catch (Exception)
            {
                LoggerManagerSingle.Instance.Error(string.Format("FileServiceCoreDll.MountPartition({0},{1},{2},{3},{4},{5},{6}) error!",
                                                                 RunPartition.SnapShotHandle, Device.Handle,
                                                                 RunPartition.SectorOffset, RunPartition.TotalSectors, fs,
                                                                 RunPartition.PartType, RunPartition.DevType));
            }

            RunPartition.Mount = mount;
            return(mount);
        }
Esempio n. 16
0
        /// <summary>
        /// 分层扫描接口 扫描分区
        /// </summary>
        /// <param name="partition">分区</param>
        /// <returns></returns>
        public List <FNodeX> GetFileSystemByDir(FileSystemPartition partition)
        {
            RunPartition = partition;
            MountDevice();

            VOL_BPB_INFO vol = new VOL_BPB_INFO();

            var result = FileServiceCoreDll.GetPartInfo(partition.Mount, ref vol);

            if (0 != result)
            {
            }

            LINK_DIR_FILE_NODE_INFO link = new LINK_DIR_FILE_NODE_INFO();

            result = FileServiceCoreDll.ScanFilesByDir(partition.Mount, GetFileSystemByDirScanCallBack, vol.root_ino, ref link);
            if (0 != result)
            {
            }

            // 构建当前分区节点
            var treeNode = new FNodeX
            {
                Source      = link.NodeDataInfo,
                FileName    = partition.VolName,
                IsRoot      = true,
                IsPartition = true,
                Key         = link.NodeDataInfo.FileId,
                ParentKey   = link.NodeDataInfo.ParentFileId
            };
            // 加载树结构;
            var source = BuildDataDictionary(link);

            BuildTree(treeNode, source);

            return(treeNode.Collection);
        }
Esempio n. 17
0
        private void DoOneDeviceMonitor()
        {
            //1.获取当前连接列表
            var devices = new List <SDCardDevice>();

            var bottomdiskinfo = new DISK_INFO();

            for (byte index = 0; index < 16; index++)
            {
                var result = FileServiceCoreDll.GetDiskInfo(ref bottomdiskinfo, index);
                if (result != 0 || !bottomdiskinfo.controller.Contains("USB driver"))
                {
                    continue;
                }
                var device = new SDCardDevice();
                device.DiskNumber = bottomdiskinfo.disk_num;
                device.Name       = string.Format("Disk:{0}-{1}", index, bottomdiskinfo.sModelNumber);
                device.Size       = (ulong)bottomdiskinfo.sectors.ToSafeInt64() * 512;
                devices.Add(device);
            }

            //2.获取新增设备和断开连接设备
            var newConnecnted = devices.Except(CurConnectDevs).ToList();
            var disConnecteds = CurConnectDevs.Except(devices).ToList();

            foreach (var add in newConnecnted)
            {
                OnConnected(add);
                CurConnectDevs.Add(add);
            }

            foreach (var dis in disConnecteds)
            {
                OnDisconnected(dis);
                CurConnectDevs.Remove(dis);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// 获取打开设备句柄
        /// </summary>
        /// <returns></returns>
        public override IntPtr OpenDevice()
        {
            base.OpenDevice();
            if (null == this.Device || this.Device.Handle == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }
            FileInfo file       = new FileInfo(this.Device.Source.ToString());
            long     l_fileSize = file.Length;
            UInt64   u_fileSize = (UInt64)l_fileSize;
            IntPtr   handle     = FileServiceCoreDll.MountDeviceHandle(this.Device.Handle, u_fileSize, (byte)this.Device.DevType, (uint)this.Device.FlshType);

            if (handle == IntPtr.Zero)
            {
                this.Device.Handle_Flsh = IntPtr.Zero;
                //LogHelper.Error(LanguageHelper.Get("LANGKEY_ZhuangZaiSheBeiJuBingShiBai_04944"));
            }
            else
            {
                this.Device.Handle_Flsh = handle;;
                //LogHelper.Error(LanguageHelper.Get("LANGKEY_ZhuangZaiSheBeiJuBingChengGong_04945"));
            }
            return(this.Device.Handle_Flsh);
        }