Example #1
0
        public object Process(Node node, bool extractDeleted, bool extractSource)
        {
            ParserResults pr = new ParserResults();

            if (node is FileSystem fs) //这个插件期望node是文件系统
            {
                MetaData meta = new MetaData();
                var      ds   = fs.DataStore;
                try
                {
                    //analyze_csidata
                    //private/var/root/Library/Lockdown/data_ark.plist
                    var data_ark = fs.Search("/Library/Lockdown/data_ark.plist$").FirstOrDefault();
                    if (data_ark != null && data_ark.Type == NodeType.File)
                    {
                        var plist = PlistHelper.ReadPlist <NSDictionary>(data_ark);
                        FetchDeviceInfo(ds.DeviceInfo, plist, DeviceInfoKeys.Language.ToString(), "com.apple.international-Language");
                        FetchDeviceInfo(ds.DeviceInfo, plist, DeviceInfoKeys.BuildVersion.ToString(), "com.apple.who-uptodate_build");
                        FetchDeviceInfo(ds.DeviceInfo, plist, DeviceInfoKeys.LastBackupComputerName.ToString(), "com.apple.iTunes.backup-LastBackupComputerName");
                        FetchDeviceInfo(ds.DeviceInfo, plist, DeviceInfoKeys.DeviceName.ToString(), "-DeviceName");
                        FetchDeviceInfo(ds.DeviceInfo, plist, DeviceInfoKeys.TimeZone.ToString(), "-TimeZone");
                        FetchDeviceInfo(ds.DeviceInfo, plist, DeviceInfoKeys.ActivationStateAcknowledged.ToString(), "-ActivationStateAcknowledged");
                        FetchDeviceInfo(ds.DeviceInfo, plist, DeviceInfoKeys.Locale.ToString(), "com.apple.international-Locale");
                        FetchDeviceInfo(ds.DeviceInfo, plist, DeviceInfoKeys.LastBackupComputerType.ToString(), "com.apple.iTunes.backup-LastBackupComputerType");
                    }

                    //System/Library/LaunchDaemons/com.apple.atc.plist
                    var atcNode = fs.Search("/Preferences/com.apple.atc.plist$").FirstOrDefault();
                    if (atcNode != null && atcNode.Type == NodeType.File)
                    {
                        var plist = PlistHelper.ReadPlist <NSDictionary>(atcNode);
                        if (plist != null)
                        {
                            var diskUsage = plist.SafeGetObject <NSDictionary>("DiskUsage");

                            FileSize GetDiskUsageSize(NSDictionary dict, string key)
                            {
                                var subdict = dict.SafeGetObject <NSDictionary>(key);

                                if (subdict != null)
                                {
                                    return(new FileSize(subdict.SafeGetInt64("_PhysicalSize")));
                                }
                                return(new FileSize(0));
                            }
                            ds.DeviceInfo.Add(new MetaDataField(DeviceInfoKeys.VoiceMemoSize.ToString(),
                                                                GetDiskUsageSize(diskUsage, "VoiceMemo")));
                            ds.DeviceInfo.Add(new MetaDataField(DeviceInfoKeys.UserDataSize.ToString(),
                                                                GetDiskUsageSize(diskUsage, "UserData")));
                            ds.DeviceInfo.Add(new MetaDataField(DeviceInfoKeys.BookDataSize.ToString(),
                                                                GetDiskUsageSize(diskUsage, "Book")));
                            ds.DeviceInfo.Add(new MetaDataField(DeviceInfoKeys.MediaDataSize.ToString(),
                                                                GetDiskUsageSize(diskUsage, "Media")));
                            ds.DeviceInfo.Add(new MetaDataField(DeviceInfoKeys.ApplicationSize.ToString(),
                                                                GetDiskUsageSize(diskUsage, "Application")));
                            ds.DeviceInfo.Add(new MetaDataField(DeviceInfoKeys.LogsSize.ToString(),
                                                                GetDiskUsageSize(diskUsage, "Logs")));
                            ds.DeviceInfo.Add(new MetaDataField(DeviceInfoKeys.RingtoneSize.ToString(),
                                                                GetDiskUsageSize(diskUsage, "Ringtone")));

                            ds.DeviceInfo.Add(new MetaDataField(DeviceInfoKeys.TotalDiskSize.ToString(),
                                                                new FileSize(diskUsage.SafeGetInt64("_PhysicalSize"))));
                            ds.DeviceInfo.Add(new MetaDataField(DeviceInfoKeys.FreeDiskSize.ToString(),
                                                                new FileSize(diskUsage.SafeGetInt64("_FreeSize"))));
                        }
                    }

                    var projFile = ds.ProjectState.ProjectFile;
                    if (!string.IsNullOrEmpty(projFile) && File.Exists(projFile))
                    {
                        var plist = PlistHelper.ReadPlist <NSDictionary>(projFile);
                        if (plist != null)
                        {
                            var deviceInfo = plist.SafeGetObject <NSDictionary>("Device");
                            if (deviceInfo != null)
                            {
                                foreach (var p in deviceInfo)
                                {
                                    var key = p.Key;
                                    var obj = p.Value;
                                    if (obj is NSString nss)
                                    {
                                        ds.DeviceInfo.Add(new MetaDataField(key, nss.Content));
                                    }
                                    else if (obj is NSNumber nsn)
                                    {
                                        if (nsn.isBoolean())
                                        {
                                            ds.DeviceInfo.Add(new MetaDataField(key, nsn.ToBool()));
                                        }
                                        else if (nsn.isInteger())
                                        {
                                            ds.DeviceInfo.Add(new MetaDataField(key, nsn.ToLong()));
                                        }
                                        else if (nsn.isReal())
                                        {
                                            ds.DeviceInfo.Add(new MetaDataField(key, nsn.ToDouble()));
                                        }
                                    }
                                }
                            }
                        }
                    }

                    var lockd = fs.GetByPath("/private/Lockdown.plist");
                    if (lockd != null && lockd.Type == NodeType.File)
                    {
                        var plist = PlistHelper.ReadPlist <NSDictionary>(lockd);
                        if (plist != null)
                        {
                            var keys = Enum.GetNames(typeof(DeviceInfoKeys));
                            foreach (var key in keys)
                            {
                                if (plist.ContainsKey(key))
                                {
                                    var obj = plist.SafeGetObject <NSObject>(key);
                                    if (obj is NSString nss)
                                    {
                                        ds.DeviceInfo.Add(new MetaDataField(key, nss.Content));
                                    }
                                    else if (obj is NSNumber nsn)
                                    {
                                        if (nsn.isBoolean())
                                        {
                                            ds.DeviceInfo.Add(new MetaDataField(key, nsn.ToBool()));
                                        }
                                        else if (nsn.isInteger())
                                        {
                                            ds.DeviceInfo.Add(new MetaDataField(key, nsn.ToLong()));
                                        }
                                        else if (nsn.isReal())
                                        {
                                            ds.DeviceInfo.Add(new MetaDataField(key, nsn.ToDouble()));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    TraceService.TraceError(e);
                }
            }

            //返回空的pr,实际的数据已经存在ds.DeviceInfo里面了,这是特殊情况,一般情况下你应该将数据通过pr存储返回给主程序
            return(pr);
        }