public MMSAnalyzer(IPhoneBackup backup, IPhoneFile file)
        {
            _backup = backup;
            _file = file;

            InitializeComponent();
        }
        public HashInfo(IPhoneBackup backup, IPhoneFile file)
        {
            InitializeComponent();

            FileInfo fileInfo = FileManager.Current.GetOriginalFile(backup, file);
            Text = "Hash information [" + file.Path + "]";
            lblFileName.Text = file.Path;
            lblMd5.Text = Util.MD5File(fileInfo);
            lblSha1.Text = Util.SHA1File(fileInfo);
        }
        /// <summary>
        /// Get a working file in the directory Temp/${InvokingClassName}/filename
        /// 
        /// This to avoid confilcts but a will to retain the name
        /// </summary>
        /// <param name="backup"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public FileInfo GetWorkingFileCurrentClass(IPhoneBackup backup, IPhoneFile file)
        {
            StackTrace trace = new StackTrace();
            StackFrame frame = trace.GetFrame(1);
            Type klass = frame.GetMethod().ReflectedType;

            return GetWorkingFile(string.Format("${0}", klass.Name), backup, file, false);
        }
 /// <summary>
 /// Returns a non random file
 /// </summary>
 /// <param name="backup"></param>
 /// <param name="file"></param>
 /// <returns></returns>
 public FileInfo GetWorkingFile(IPhoneBackup backup, IPhoneFile file)
 {
     return GetWorkingFile(backup, file, false);
 }
        /// <summary>
        /// Return a file copy from a temp folder
        /// 
        /// The path will be /Temp/$$idb$/{dir}/{fileName} (or random i.e. Path.GetTempFileName())
        /// 
        /// if verify == true the file from source and the destination hashes will be compared
        /// if the comparsion fail. An IOExcetion is raised.
        /// </summary>
        /// <param name="backup"></param>
        /// <param name="file"></param>
        /// <param name="random"></param>
        /// <param name="dir"></param>
        /// <param name="verify">Verify the files after copy (using md5)</param>
        /// <exception cref="IOException">
        /// Thrown if file copy failed or that the copy cannot be verified
        /// </exception>
        /// <returns></returns>
        public FileInfo GetWorkingFile(string dir, IPhoneBackup backup, IPhoneFile file, bool random, bool verify = true)
        {
            lock (_lock)
            {
                if (!_init)
                    Init();

                string tempPath = Path.Combine(Path.GetTempPath(), BasePath, dir);
                if (!Directory.Exists(tempPath))
                    Directory.CreateDirectory(tempPath);

                FileInfo dest = new FileInfo(Path.GetTempFileName());
                if (!random)
                    dest = new FileInfo(Path.Combine(tempPath, GetFileName(file)));

                FileInfo src = GetOriginalFile(backup, file);
                string srcHash = "", destHash = "";
                if (verify)
                    srcHash = Util.MD5File(src);

                // Dont copy if it exist..
                if (File.Exists(dest.FullName) && Util.MD5File(dest) == srcHash)
                    return dest;

                // if we dent copy to the src
                if (src != dest)
                    File.Copy(src.FullName, dest.FullName, true);

                if (verify)
                {
                    destHash = Util.MD5File(dest);
                    if (srcHash != destHash)
                    {
                        Clean(dest.FullName);
                        throw new IOException("File copy failed. Reason: Hashes do not match!!");
                    }
                }
                return dest;
            }
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="backup"></param>
 /// <param name="file"></param>
 /// <param name="random"></param>
 /// <returns></returns>
 public FileInfo GetWorkingFile(IPhoneBackup backup, IPhoneFile file, bool random)
 {
     return GetWorkingFile("", backup, file, random);
 }
 /// <summary>
 /// This returns a random file in a temporary location with the file
 /// name as Tuple.
 /// 
 /// Item1 = correct fileName
 /// Item2 = the fileInfo about the random file created
 /// </summary>
 /// <param name="backup"></param>
 /// <param name="file"></param>
 /// <returns></returns>
 public Tuple<string, FileInfo> GetRandomFile(IPhoneBackup backup, IPhoneFile file)
 {
     FileInfo fileInfo = GetWorkingFile(backup, file, true);
     string name = GetFileName(file);
     return Tuple.Create(name, fileInfo);
 }
 public FileInfo GetOriginalFile(IPhoneBackup backup, IPhoneFile file)
 {
     string src = Path.Combine(backup.Path, file.Key);
     return new FileInfo(src);
 }
        /// <summary>
        /// Get the filename of an iphone file
        /// 
        /// excluding the directory hirarcy
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public string GetFileName(IPhoneFile file)
        {
            string fileName = "";

            int lastIndex = file.Path.LastIndexOf("/");
            if (lastIndex >= 0)
            {
                fileName = file.Path.Substring(lastIndex + 1, file.Path.Length - lastIndex - 1);
            }
            else
            {
                fileName = file.Path;
            }

            return fileName;
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="backup"></param>
 /// <param name="file"></param>
 /// <param name="dest"></param>
 public void Copy(IPhoneBackup backup, IPhoneFile file, FileInfo dest)
 {
     Copy(backup, file, dest.FullName);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="backup"></param>
 /// <param name="file"></param>
 /// <param name="dest"></param>
 public void Copy(IPhoneBackup backup, IPhoneFile file, string dest)
 {
     lock (_lock)
     {
         string src = Path.Combine(backup.Path, file.Key);
         dest = Path.Combine(dest, GetFileName(file));
         if (src != dest)
             File.Copy(src, dest, true);
     }
 }
        public List<IPhoneApp> GetApps()
        {
            if (File.Exists(System.IO.Path.Combine(Path, "Manifest.mbdb")))
            {
                List<IPhoneApp> list = new List<IPhoneApp>();
                mbdb.MBFileRecord[] files = mbdb.ReadMBDB(Path, false, true);
                PListRoot root = PListRoot.Load(System.IO.Path.Combine(Path, "Manifest.plist"));
                PListDict di = root.Root as PListDict;

                PListDict apps = null;
                if ((apps = di["Applications"] as PListDict) == null)
                    return list;

                Dictionary<string, List<int>> filesByDomain = new Dictionary<string, List<int>>();
                for (int i = 0; i < files.Length; ++i)
                {
                    if ((files[i].Mode & 0xF000) == 0x8000)
                    {
                        string d = files[i].Domain;
                        if (!filesByDomain.ContainsKey(d))
                            filesByDomain.Add(d, new List<int>());

                        filesByDomain[d].Add(i);
                    }
                }

                foreach (var p in apps)
                {
                    IPhoneApp app = new IPhoneApp();

                    app.Key = p.Key;

                    PListDict appd = p.Value as PListDict;

                    KeyValuePair<string, IPListElement> name = appd.FirstOrDefault(x => x.Key == "CFBundleDisplayName");
                    if (name.Value != null)
                        app.DisplayName = name.Value.Value().ToString();

                    KeyValuePair<string, IPListElement> bname = appd.FirstOrDefault(x => x.Key == "CFBundleName");
                    if (bname.Value != null)
                        app.Name = bname.Value.Value().ToString();

                    KeyValuePair<string, IPListElement> ident = appd.FirstOrDefault(x => x.Key == "CFBundleIdentifier");
                    if (ident.Value != null)
                        app.Identifier = ident.Value.Value().ToString();

                    KeyValuePair<string, IPListElement> cont = appd.FirstOrDefault(x => x.Key == "Container");
                    if (cont.Value != null)
                        app.Container = cont.Value.Value().ToString();

                    if (app.Name == null) app.Name = app.Key;
                    if (app.DisplayName == null) app.DisplayName = app.Name;

                    if (filesByDomain.ContainsKey("AppDomain-" + app.Key))
                    {
                        app.Files = new List<IPhoneFile>();

                        foreach (int i in filesByDomain["AppDomain-" + app.Key])
                        {
                            IPhoneFile ff = new IPhoneFile();
                            mbdb.MBFileRecord x = files[i];
                            ff.Key = x.key;
                            ff.Domain = x.Domain;
                            ff.Path = x.Path;
                            ff.ModificationTime = x.aTime.ToString();
                            ff.FileLength = x.FileLength;
                            app.Files.Add(ff);
                        }

                        filesByDomain.Remove("AppDomain-" + app.Key);
                    }
                    list.Add(app);
                }

                IPhoneApp system = new IPhoneApp();
                system.Name = "System";
                system.DisplayName = "---";
                system.Identifier = "---";
                system.Container = "---";
                system.Files = new List<IPhoneFile>();

                foreach (List<int> i in filesByDomain.Values)
                {
                    foreach (int j in i)
                    {
                        IPhoneFile ff = new IPhoneFile();
                        mbdb.MBFileRecord x = files[j];
                        ff.Key = x.key;
                        ff.Domain = x.Domain;
                        ff.Path = x.Path;
                        ff.ModificationTime = x.aTime.ToString();
                        ff.FileLength = x.FileLength;
                        system.Files.Add(ff);
                    }
                }
                list.Add(system);
                return list;
            }
            else
            {
                throw new FileLoadException("Can only handle iTunes <= v9.2");
            }
        }
 public IPhoneFileSelectedArgs(IPhoneFile[] selected)
 {
     Selected = selected;
 }
 private void OnSelectedFiles(IPhoneFile[] file)
 {
     if (SelectedFiles != null)
         SelectedFiles(fileList, new IPhoneFileSelectedArgs(file));
 }
예제 #15
0
        public List <IPhoneApp> GetApps()
        {
            if (File.Exists(System.IO.Path.Combine(Path, "Manifest.mbdb")))
            {
                List <IPhoneApp>    list  = new List <IPhoneApp>();
                mbdb.MBFileRecord[] files = mbdb.ReadMBDB(Path, false, true);
                PListRoot           root  = PListRoot.Load(System.IO.Path.Combine(Path, "Manifest.plist"));
                PListDict           di    = root.Root as PListDict;

                PListDict apps = null;
                if ((apps = di["Applications"] as PListDict) == null)
                {
                    return(list);
                }

                Dictionary <string, List <int> > filesByDomain = new Dictionary <string, List <int> >();
                for (int i = 0; i < files.Length; ++i)
                {
                    if ((files[i].Mode & 0xF000) == 0x8000)
                    {
                        string d = files[i].Domain;
                        if (!filesByDomain.ContainsKey(d))
                        {
                            filesByDomain.Add(d, new List <int>());
                        }

                        filesByDomain[d].Add(i);
                    }
                }

                foreach (var p in apps)
                {
                    IPhoneApp app = new IPhoneApp();

                    app.Key = p.Key;

                    PListDict appd = p.Value as PListDict;

                    KeyValuePair <string, IPListElement> name = appd.FirstOrDefault(x => x.Key == "CFBundleDisplayName");
                    if (name.Value != null)
                    {
                        app.DisplayName = name.Value.Value().ToString();
                    }

                    KeyValuePair <string, IPListElement> bname = appd.FirstOrDefault(x => x.Key == "CFBundleName");
                    if (bname.Value != null)
                    {
                        app.Name = bname.Value.Value().ToString();
                    }

                    KeyValuePair <string, IPListElement> ident = appd.FirstOrDefault(x => x.Key == "CFBundleIdentifier");
                    if (ident.Value != null)
                    {
                        app.Identifier = ident.Value.Value().ToString();
                    }

                    KeyValuePair <string, IPListElement> cont = appd.FirstOrDefault(x => x.Key == "Container");
                    if (cont.Value != null)
                    {
                        app.Container = cont.Value.Value().ToString();
                    }

                    if (app.Name == null)
                    {
                        app.Name = app.Key;
                    }
                    if (app.DisplayName == null)
                    {
                        app.DisplayName = app.Name;
                    }

                    if (filesByDomain.ContainsKey("AppDomain-" + app.Key))
                    {
                        app.Files = new List <IPhoneFile>();

                        foreach (int i in filesByDomain["AppDomain-" + app.Key])
                        {
                            IPhoneFile        ff = new IPhoneFile();
                            mbdb.MBFileRecord x  = files[i];
                            ff.Key              = x.key;
                            ff.Domain           = x.Domain;
                            ff.Path             = x.Path;
                            ff.ModificationTime = x.aTime.ToString();
                            ff.FileLength       = x.FileLength;
                            app.Files.Add(ff);
                        }

                        filesByDomain.Remove("AppDomain-" + app.Key);
                    }
                    list.Add(app);
                }

                IPhoneApp system = new IPhoneApp();
                system.Name        = "System";
                system.DisplayName = "---";
                system.Identifier  = "---";
                system.Container   = "---";
                system.Files       = new List <IPhoneFile>();

                foreach (List <int> i in filesByDomain.Values)
                {
                    foreach (int j in i)
                    {
                        IPhoneFile        ff = new IPhoneFile();
                        mbdb.MBFileRecord x  = files[j];
                        ff.Key              = x.key;
                        ff.Domain           = x.Domain;
                        ff.Path             = x.Path;
                        ff.ModificationTime = x.aTime.ToString();
                        ff.FileLength       = x.FileLength;
                        system.Files.Add(ff);
                    }
                }
                list.Add(system);
                return(list);
            }
            else
            {
                throw new FileLoadException("Can only handle iTunes <= v9.2");
            }
        }