Exemple #1
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);
        }
Exemple #2
0
        static AFCError saveDirectoryTree(IntPtr afcClient, string directoryPath, StreamWriter streamWriter, out string lastDirectory)
        {
            lastDirectory = directoryPath;

            AFCError returnCode;
            IntPtr   directoryListPtr;

            returnCode = AFC.afc_read_directory(afcClient, directoryPath, out directoryListPtr);
            if (returnCode == AFCError.AFC_E_READ_ERROR)
            {
                return(AFCError.AFC_E_SUCCESS);
            }
            else if (returnCode != AFCError.AFC_E_SUCCESS)
            {
                return(returnCode);
            }

            List <string> directoryList = LibiMobileDevice.PtrToStringList(directoryListPtr, 2);

            afc_dictionary_free(directoryListPtr);

            if (directoryPath == "/")
            {
                directoryPath = "";
            }

            int tabNumber = directoryPath.Count(x => x == '/');

            directoryList.Sort();
            foreach (string currDirectory in directoryList)
            {
                if (currDirectory == "Photos.sqlite")
                {
                    photoDatabasePath = directoryPath + "/" + currDirectory;
                }

                streamWriter.WriteLine(String.Concat(Enumerable.Repeat("\t", tabNumber)) + currDirectory);
                if ((returnCode = saveDirectoryTree(afcClient, directoryPath + "/" + currDirectory, streamWriter, out lastDirectory))
                    != AFCError.AFC_E_SUCCESS)
                {
                    break;
                }
            }

            return(returnCode);
        }
Exemple #3
0
        public static LockdownError GetProperties(IntPtr lockdownClient, out XDocument result)
        {
            IntPtr        resultPlist;
            LockdownError returnCode = lockdownd_get_value(lockdownClient, null, null, out resultPlist);

            result = new XDocument();
            if (returnCode != LockdownError.LOCKDOWN_E_SUCCESS)
            {
                return(returnCode);
            }

            else if (resultPlist == IntPtr.Zero)
            {
                return(LockdownError.LOCKDOWN_E_UNKNOWN_ERROR);
            }

            result = LibiMobileDevice.PlistToXml(resultPlist);
            return(returnCode);
        }
 internal USBMultiplexArgs(LibiMobileDevice.idevice_event_t cbi, bool locked)
 {
     this.message = cbi.connection_type;
     this.device = cbi.UniqueDeviceID;
     IsLocked = locked;
 }
 internal ConnectEventArgs(LibiMobileDevice.idevice_event_t cbi)
 {
     this.message = cbi.connection_type;
     this.device = cbi.UniqueDeviceID;
 }
Exemple #6
0
        internal void _NotifyCallback(ref LibiMobileDevice.idevice_event_t callback)
        {
            this.attachedToHost = true;
            if (callback.connection_type.ToString() == "1")
            {
                updateDeviceList();
                iDevice id;
                int ndev = Devices.Count;
                this.OnHostAtached(new USBMultiplexArgs(callback, ndev == 0));
                if (ndev == 0)
                {
                    this.lastError = "No accessible Devices found. Enter the passcode and try again.";
                }
                else
                {
                    id = Devices[0];

                    this.iPhoneHandle = id.Handle;
                    //string udid = callback.UniqueDeviceID.ToString();
                    if (this.ConnectToPhone())
                    {
                        this.OnConnect(new ConnectEventArgs(callback));
                    }
                    else
                    {
                        this.lastError = "Device connected but locked; enter passcode and retry.";
                    }
                }
            }
            if (callback.connection_type.ToString() == "2")
            {
                this.connected = false;
                this.attachedToHost = false;
                this.OnHostDisconnected(new USBMultiplexArgs(callback, true));
                this.OnDisconnect(new ConnectEventArgs(callback));
            }
        }