Beispiel #1
0
        public static AFCError CollectData(iDevice device, string savePath)
        {
            //CollectionForm.logWriter.WriteLine("[INFO] Starting AFC client.");
            IntPtr   afcClient;
            AFCError returnCode = afc_client_start_service(device.Handle, out afcClient, "iOSLibDataCollector");

            if (returnCode != AFCError.AFC_E_SUCCESS || afcClient == IntPtr.Zero)
            {
                //CollectionForm.logWriter.WriteLine("[ERROR] Couldn't start AFC client. AFC error " + (int)returnCode + ": " + returnCode + ".");
                return(returnCode);
            }
            //CollectionForm.logWriter.WriteLine("[INFO] AFC client has been successfully started.");

            int    fileNumber = 0;
            string iOSVersion = device.iOSVersion.Replace(".", "_");
            string fileName;

            do
            {
                fileName = iOSVersion + (fileNumber != 0 ? " (" + fileNumber + ")" : "");
                fileNumber++;
            } while (File.Exists(savePath + @"\" + fileName + ".sqlite") ||
                     File.Exists(savePath + @"\" + fileName + ".sqlite-shm") ||
                     File.Exists(savePath + @"\" + fileName + ".sqlite-wal") ||
                     File.Exists(savePath + @"\" + fileName + ".txt"));
            savePath += @"\" + fileName;

            StreamWriter treeWriter = new StreamWriter(savePath + ".txt");

            //CollectionForm.logWriter.WriteLine("[INFO] Saving directory tree.");
            photoDatabasePath = "";
            string lastDirectory;

            if ((returnCode = saveDirectoryTree(afcClient, "/", treeWriter, out lastDirectory)) != AFCError.AFC_E_SUCCESS)
            {
                //CollectionForm.logWriter.WriteLine("[ERROR] Couldn't save directory tree. An error occurred while reading \"" + lastDirectory
                //+ "\". AFC error " + (int)returnCode + ": " + returnCode + ".");
            }
            //CollectionForm.logWriter.WriteLine("[INFO] Directory saving has been finished.");

            if (photoDatabasePath != "")
            {
                //CollectionForm.logWriter.WriteLine("[INFO] Photos database file is located at " + photoDatabasePath + ".");
            }

            else
            {
                //CollectionForm.logWriter.WriteLine("[ERROR] Couldn't find photo database file.");
            }

            treeWriter.WriteLine("\n\r" + photoDatabasePath);
            treeWriter.Close();

            //CollectionForm.logWriter.WriteLine("[INFO] Saving photos database.");
            returnCode = savePhotosDatabase(afcClient, savePath + ".sqlite");

            afc_client_free(afcClient);
            return(returnCode);
        }
Beispiel #2
0
        internal static AFCError closePhoto(IntPtr afcClient, ulong fileHandle)
        {
            AFCError returnCode = afc_file_close(afcClient, fileHandle);

            if (afcClient != IntPtr.Zero)
            {
                returnCode = afc_client_free(afcClient);
            }

            return(returnCode);
        }
Beispiel #3
0
        internal static AFCError copyToDisk(IntPtr afcClient, string filePath, string savePath)
        {
            IntPtr   infoPtr;
            AFCError returnCode = afc_get_file_info(afcClient, filePath, out infoPtr);

            if (returnCode != AFCError.AFC_E_SUCCESS)
            {
                return(returnCode);
            }

            List <string> infoList = LibiMobileDevice.PtrToStringList(infoPtr, 0);
            long          fileSize = Convert.ToInt64(infoList[infoList.FindIndex(x => x == "st_size") + 1]);

            ulong fileHandle;

            returnCode = afc_file_open(afcClient, filePath, FileOpenMode.AFC_FOPEN_RDONLY, out fileHandle);
            if (returnCode != AFCError.AFC_E_SUCCESS)
            {
                return(returnCode);
            }

            FileStream fileStream = new FileStream(savePath, FileMode.Create, FileAccess.Write);
            const int  bufferSize = 4194304;

            for (int i = 0; i < fileSize / bufferSize + 1; i++)
            {
                uint bytesRead;

                long   remainder      = fileSize - i * bufferSize;
                int    currBufferSize = remainder >= bufferSize ? bufferSize : (int)remainder;
                byte[] currBuffer     = new byte[currBufferSize];

                if ((returnCode = afc_file_read(afcClient, fileHandle, currBuffer, Convert.ToUInt32(currBufferSize), out bytesRead))
                    != AFCError.AFC_E_SUCCESS)
                {
                    afc_file_close(afcClient, fileHandle);
                    return(returnCode);
                }

                fileStream.Write(currBuffer, 0, currBufferSize);
            }

            fileStream.Close();
            returnCode = afc_file_close(afcClient, fileHandle);

            return(returnCode);
        }
Beispiel #4
0
        internal static AFCError copyToDevice(IntPtr afcClient, string filePath, string savePath)
        {
            byte[] fileContent = File.ReadAllBytes(filePath);

            ulong    fileHandle;
            AFCError returnCode = afc_file_open(afcClient, savePath, FileOpenMode.AFC_FOPEN_WRONLY, out fileHandle);

            if (returnCode != AFCError.AFC_E_SUCCESS)
            {
                return(returnCode);
            }

            uint bytesWritten;

            returnCode = afc_file_write(afcClient, fileHandle, fileContent, Convert.ToUInt32(fileContent.Length), out bytesWritten);
            afc_file_close(afcClient, fileHandle);
            return(returnCode);
        }
Beispiel #5
0
        internal static AFCError openPhoto(Photo photo, string photoPath, iDevice device, FileOpenMode openMode, out IntPtr afcClient, out ulong fileHandle)
        {
            fileHandle = 0;
            AFCError returnCode = afc_client_start_service(device.handle, out afcClient, "iOSLib");

            if (returnCode != AFCError.AFC_E_SUCCESS)
            {
                return(returnCode);
            }

            if ((returnCode = afc_file_open(afcClient, photoPath + photo.getName(), openMode, out fileHandle))
                != AFCError.AFC_E_SUCCESS)
            {
                afc_client_free(afcClient);
            }

            return(returnCode);
        }