Esempio n. 1
0
 /// <summary>
 /// Releases the unmanaged resources used by iPhoneFile
 /// </summary>
 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
 unsafe protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (handle != 0)
         {
             MobileDevice.AFCFileRefClose(phone.AFCHandle, handle);
             handle = 0;
         }
     }
     base.Dispose(disposing);
 }
Esempio n. 2
0
        /// <summary>
        /// Creates the directory specified in path
        /// </summary>
        /// <param name="path">The directory path to create</param>
        /// <returns>true if directory was created</returns>
        public bool CreateDirectory(string path)
        {
            string full_path;

            full_path = FullPath(current_directory, path);
            if (MobileDevice.AFCDirectoryCreate(hAFC, full_path) != 0)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Determines whether the given path refers to an existing file or directory on the phone.
        /// </summary>
        /// <param name="path">The path to test.</param>
        /// <returns><c>true</c> if path refers to an existing file or directory, otherwise <c>false</c>.</returns>
        unsafe public bool Exists(string path)
        {
            void *data = null;

            int ret = MobileDevice.AFCFileInfoOpen(hAFC, path, ref data);

            if (ret == 0)
            {
                MobileDevice.AFCKeyValueClose(data);
            }

            return(ret == 0);
        }
Esempio n. 4
0
        /*
         * Valid Value Names:
         *  ActivationState
         *  ActivationStateAcknowledged
         *  BasebandBootloaderVersion
         *  BasebandVersion
         *  BluetoothAddress
         *  BuildVersion
         *  DeviceCertificate
         *  DeviceClass
         *  DeviceName
         *  DevicePublicKey
         *  FirmwareVersion
         *  HostAttached
         *  IntegratedCircuitCardIdentity
         *  InternationalMobileEquipmentIdentity
         *  InternationalMobileSubscriberIdentity
         *  ModelNumber
         *  PhoneNumber
         *  ProductType
         *  ProductVersion
         *  ProtocolVersion
         *  RegionInfo
         *  SBLockdownEverRegisteredKey
         *  SIMStatus
         *  SerialNumber
         *  SomebodySetTimeZone
         *  TimeIntervalSince1970
         *  TimeZone
         *  TimeZoneOffsetFromUTC
         *  TrustedHostAttached
         *  UniqueDeviceID
         *  Uses24HourClock
         *  WiFiAddress
         *  iTunesHasConnected
         */

        public static string AMDeviceCopyValue(TypedPtr <AppleMobileDeviceConnection> device, string name)
        {
            IntPtr result = AMDeviceMethods.CopyValue(device, 0, CFStringMakeConstantString(name));

            if (result != IntPtr.Zero)
            {
                return(MobileDevice.CFStringGetCString(result));
            }
            else
            {
                Console.WriteLine("Error: Call to AMDeviceCopyValue failed");
            }
            return(String.Empty);
        }
Esempio n. 5
0
        /// <summary>
        /// Determines whether the given path refers to an existing file or directory on the phone.
        /// </summary>
        /// <param name="path">The path to test.</param>
        /// <returns><c>true</c> if path refers to an existing file or directory, otherwise <c>false</c>.</returns>
        public bool Exists(string path)
        {
            uint   data_size;
            IntPtr data;

            data = IntPtr.Zero;

            if (MobileDevice.AFCGetFileInfo(hAFC, path, ref data, out data_size) != 0)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 6
0
        public int GoOutDFU()
        {
            int num = 0xff;

            try
            {
                num = MobileDevice.AMRecoveryModeDeviceSetAutoBoot(this.DFUHandle, 1);
                return(MobileDevice.AMRecoveryModeDeviceReboot(this.DFUHandle));
            }
            catch
            {
                return(num);
            }
        }
Esempio n. 7
0
        unsafe private bool ConnectToPhone()
        {
            if (MobileDevice.AMDeviceConnect(iPhoneHandle) == 1)
            {
                //int connid;

                throw new Exception("Phone in recovery mode, support not yet implemented");
                //connid = MobileDevice.AMDeviceGetConnectionID(ref iPhoneHandle);
                //MobileDevice.AMRestoreModeDeviceCreate(0, connid, 0);
                //return false;
            }
            if (MobileDevice.AMDeviceIsPaired(iPhoneHandle) == 0)
            {
                return(false);
            }
            int chk = MobileDevice.AMDeviceValidatePairing(iPhoneHandle);

            if (chk != 0)
            {
                return(false);
            }

            if (MobileDevice.AMDeviceStartSession(iPhoneHandle) == 1)
            {
                return(false);
            }

            if (MobileDevice.AMDeviceStartService(iPhoneHandle, MobileDevice.CFStringMakeConstantString("com.apple.afc2"), ref hService, null) != 0)
            {
                if (MobileDevice.AMDeviceStartService(iPhoneHandle, MobileDevice.CFStringMakeConstantString("com.apple.afc"), ref hService, null) != 0)
                {
                    return(false);
                }
            }
            else
            {
                wasAFC2 = true;
            }

            if (MobileDevice.AFCConnectionOpen(hService, 0, ref hAFC) != 0)
            {
                return(false);
            }

            connected = true;
            return(true);
        }
Esempio n. 8
0
        unsafe public void RefreshFileSystemInfo()
        {
            void * dict = null;
            void * key;
            void * val;
            string skey;
            string sval;
            long   lval;
            int    ival;
            int    ret = MobileDevice.AFCDeviceInfoOpen(hAFC, ref dict);

            if (ret == 0)
            {
                try
                {
                    while ((MobileDevice.AFCKeyValueRead(dict, out key, out val) == 0) && (skey = Marshal.PtrToStringAnsi(new IntPtr(key))) != null && (sval = Marshal.PtrToStringAnsi(new IntPtr(val))) != null)
                    {
                        switch (skey)
                        {
                        case "FSFreeBytes":
                            long.TryParse(sval, out lval);
                            fileSystemFreeBytes = lval;
                            break;

                        case "FSTotalBytes":
                            long.TryParse(sval, out lval);
                            fileSystemTotalBytes = lval;
                            break;

                        case "FSBlockSize":
                            Int32.TryParse(sval, out ival);
                            fileSystemBlockSize = ival;
                            break;

                        default:
                            System.Diagnostics.Trace.WriteLine(skey + ":" + sval);
                            break;
                        }
                    }
                }
                catch (AccessViolationException ave) { }
                finally
                {
                    MobileDevice.AFCKeyValueClose(dict);
                }
            }
        }
Esempio n. 9
0
 public override unsafe void Write(byte[] buffer, int offset, int count)
 {
     byte[] buffer2;
     if (!this.CanWrite)
     {
         throw new NotImplementedException("Stream open for reading only");
     }
     if (offset == 0)
     {
         buffer2 = buffer;
     }
     else
     {
         buffer2 = new byte[count];
         Buffer.BlockCopy(buffer, offset, buffer2, 0, count);
     }
     int num = MobileDevice.AFCFileRefWrite(this.phone.AFCHandle, this.handle, buffer2, (uint)count);
 }
Esempio n. 10
0
        public unsafe Dictionary <string, string> GetFileInfo(string path)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();
            void *dict = null;

            if ((MobileDevice.AFCFileInfoOpen(this.hAFC, path, ref dict) == 0) && (dict != null))
            {
                void *voidPtr2;
                void *voidPtr3;
                while (((MobileDevice.AFCKeyValueRead(dict, out voidPtr2, out voidPtr3) == 0) && (voidPtr2 != null)) && (voidPtr3 != null))
                {
                    string key  = Marshal.PtrToStringAnsi(new IntPtr(voidPtr2));
                    string str2 = Marshal.PtrToStringAnsi(new IntPtr(voidPtr3));
                    dictionary.Add(key, str2);
                }
                MobileDevice.AFCKeyValueClose(dict);
            }
            return(dictionary);
        }
Esempio n. 11
0
        private bool ConnectToPhone()
        {
            if (MobileDevice.AMDeviceConnect(ref iPhoneHandle) == 1)
            {
                //int connid;

                throw new Exception("Phone in recovery mode, support not yet implemented");
                //connid = MobileDevice.AMDeviceGetConnectionID(ref iPhoneHandle);
                //MobileDevice.AMRestoreModeDeviceCreate(0, connid, 0);
                //return false;
            }
            if (MobileDevice.AMDeviceIsPaired(ref iPhoneHandle) == 0)
            {
                return(false);
            }

            if (MobileDevice.AMDeviceValidatePairing(ref iPhoneHandle) != 0)
            {
                return(false);
            }

            if (MobileDevice.AMDeviceStartSession(ref iPhoneHandle) == 1)
            {
                return(false);
            }

            if (MobileDevice.AMDeviceStartService(ref iPhoneHandle, MobileDevice.StringToCFString("com.apple.afc2"), ref hAFC, IntPtr.Zero) != 0)
            {
                if (MobileDevice.AMDeviceStartService(ref iPhoneHandle, MobileDevice.StringToCFString("com.apple.afc"), ref hAFC, IntPtr.Zero) != 0)
                {
                    return(false);
                }
            }

            if (MobileDevice.AFCConnectionOpen(hAFC, 0, ref hAFC) != 0)
            {
                return(false);
            }

            connected = true;
            return(true);
        }
        public bool ConnectToPhone()
        {
            SetLoggingLevel(7);

            // Make sure we can connect to the phone and that it has been paired with this machine previously
            if (MobileDevice.AMDeviceMethods.Connect(iPhoneHandle) != 0)
            {
                return(false);
            }

            if (MobileDevice.AMDeviceMethods.IsPaired(iPhoneHandle) != 1)
            {
                return(false);
            }

            if (MobileDevice.AMDeviceMethods.ValidatePairing(iPhoneHandle) != 0)
            {
                return(false);
            }

            // Start a session
            if (MobileDevice.AMDeviceMethods.StartSession(iPhoneHandle) == 1)
            {
                return(false);
            }

            if (MobileDevice.AMDeviceMethods.StartService(iPhoneHandle, MobileDevice.CFStringMakeConstantString("com.apple.afc"), ref hService, IntPtr.Zero) != 0)
            {
                return(false);
            }


            // Open a file sharing connection
            if (MobileDevice.AFC.ConnectionOpen(hService, 0, out AFCCommsHandle) != 0)
            {
                return(false);
            }

            connected = true;
            return(true);
        }
Esempio n. 13
0
        /// <summary>
        /// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
        /// </summary>
        /// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream.</param>
        /// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
        /// <param name="count">The number of bytes to be written to the current stream.</param>
        unsafe public override void Write(byte[] buffer, int offset, int count)
        {
            if (!CanWrite)
            {
                throw new NotImplementedException("Stream open for reading only");
            }

            byte[] temp;

            if (offset == 0)
            {
                temp = buffer;
            }
            else
            {
                temp = new byte[count];
                Buffer.BlockCopy(buffer, offset, temp, 0, count);
            }

            int ret = MobileDevice.AFCFileRefWrite(phone.AFCHandle, handle, temp, (uint)count);
        }
Esempio n. 14
0
        private unsafe void doConstruction()
        {
            void *voidPtr;

            this.dnc  = new DeviceNotificationCallback(this.NotifyCallback);
            this.drn1 = new DeviceRestoreNotificationCallback(this.DfuConnectCallback);
            this.drn2 = new DeviceRestoreNotificationCallback(this.RecoveryConnectCallback);
            this.drn3 = new DeviceRestoreNotificationCallback(this.DfuDisconnectCallback);
            this.drn4 = new DeviceRestoreNotificationCallback(this.RecoveryDisconnectCallback);
            int num = MobileDevice.AMDeviceNotificationSubscribe(this.dnc, 0, 0, 0, out voidPtr);

            if (num != 0)
            {
                throw new Exception("AMDeviceNotificationSubscribe failed with error " + num);
            }
            num = MobileDevice.AMRestoreRegisterForDeviceNotifications(this.drn1, this.drn2, this.drn3, this.drn4, 0, null);
            if (num != 0)
            {
                throw new Exception("AMRestoreRegisterForDeviceNotifications failed with error " + num);
            }
            this.current_directory = "/";
        }
        public string[] GetFiles(string path, bool bIncludeDirs)
        {
            if (!IsConnected)
            {
                throw new Exception("Not connected to phone");
            }

            string full_path = FullPath(CurrentDirectory, path);

            IntPtr hAFCDir = IntPtr.Zero;

            if (MobileDevice.AFCDirectoryOpen(AFCCommsHandle, full_path, ref hAFCDir) != 0)
            {
                throw new Exception("Path does not exist");
            }

            string    buffer = null;
            ArrayList paths  = new ArrayList();

            MobileDevice.AFCDirectoryRead(AFCCommsHandle, hAFCDir, ref buffer);

            while (buffer != null)
            {
                if (!IsDirectory(FullPath(full_path, buffer)))
                {
                    paths.Add(buffer);
                }
                else
                {
                    if (bIncludeDirs)
                    {
                        paths.Add(buffer + "/");
                    }
                }
                MobileDevice.AFCDirectoryRead(AFCCommsHandle, hAFCDir, ref buffer);
            }
            MobileDevice.AFC.DirectoryClose(AFCCommsHandle, hAFCDir);
            return((string[])paths.ToArray(typeof(string)));
        }
        public bool ConnectToBundle(string BundleName)
        {
            Reconnect();

            TypedPtr <CFString> CFBundleName = MobileDevice.CFStringMakeConstantString(BundleName);

            // Open the bundle
            int Result = MobileDevice.AMDeviceMethods.StartHouseArrestService(iPhoneHandle, CFBundleName, IntPtr.Zero, ref hService, 0);

            if (Result != 0)
            {
                Console.WriteLine("Failed to connect to bundle '{0}' with {1}", BundleName, MobileDevice.GetErrorString(Result));
                return(false);
            }

            // Open a file sharing connection
            if (MobileDevice.AFC.ConnectionOpen(hService, 0, out AFCCommsHandle) != 0)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 17
0
        /// <summary>
        /// Initializes a new iPhone object.
        /// </summary>
        unsafe private void doConstruction()
        {
            dnc  = new DeviceNotificationCallback(NotifyCallback);
            drn1 = new DeviceRestoreNotificationCallback(DfuConnectCallback);
            drn2 = new DeviceRestoreNotificationCallback(RecoveryConnectCallback);
            drn3 = new DeviceRestoreNotificationCallback(DfuDisconnectCallback);
            drn4 = new DeviceRestoreNotificationCallback(RecoveryDisconnectCallback);

            void *notification;
            int   ret = MobileDevice.AMDeviceNotificationSubscribe(dnc, 0, 0, 0, out notification);

            if (ret != 0)
            {
                throw new Exception("AMDeviceNotificationSubscribe failed with error " + ret);
            }

            ret = MobileDevice.AMRestoreRegisterForDeviceNotifications(drn1, drn2, drn3, drn4, 0, null);
            if (ret != 0)
            {
                throw new Exception("AMRestoreRegisterForDeviceNotifications failed with error " + ret);
            }
            current_directory = "/";
        }
Esempio n. 18
0
        /// <summary>
        /// Returns the FileInfo dictionary
        /// </summary>
        /// <param name="path">The file or directory for which to retrieve information.</param>
        unsafe public Dictionary <string, string> GetFileInfo(string path)
        {
            Dictionary <string, string> ans = new Dictionary <string, string>();
            void *data = null;

            int ret = MobileDevice.AFCFileInfoOpen(hAFC, path, ref data);

            if (ret == 0 && data != null)
            {
                void *pname, pvalue;

                while (MobileDevice.AFCKeyValueRead(data, out pname, out pvalue) == 0 && pname != null && pvalue != null)
                {
                    string name  = Marshal.PtrToStringAnsi(new IntPtr(pname));
                    string value = Marshal.PtrToStringAnsi(new IntPtr(pvalue));
                    ans.Add(name, value);
                }

                MobileDevice.AFCKeyValueClose(data);
            }

            return(ans);
        }
Esempio n. 19
0
        public unsafe void GetFileInfo(string path, out ulong size, out bool directory)
        {
            Dictionary <string, string> fileInfo = this.GetFileInfo(path);

            size = fileInfo.ContainsKey("st_size") ? ulong.Parse(fileInfo["st_size"]) : ((ulong)0L);
            bool flag = false;

            directory = false;
            if (fileInfo.ContainsKey("st_ifmt"))
            {
                string str = fileInfo["st_ifmt"];
                if (str != null)
                {
                    if (!(str == "S_IFDIR"))
                    {
                        if (str == "S_IFLNK")
                        {
                            flag = true;
                        }
                    }
                    else
                    {
                        directory = true;
                    }
                }
            }
            if (flag)
            {
                bool  flag3;
                void *dir = null;
                directory = flag3 = MobileDevice.AFCDirectoryOpen(this.hAFC, path, ref dir) == 0;
                if (flag3)
                {
                    MobileDevice.AFCDirectoryClose(this.hAFC, dir);
                }
            }
        }
Esempio n. 20
0
 private unsafe bool ConnectToPhone()
 {
     if (MobileDevice.AMDeviceConnect(this.iPhoneHandle) == 1)
     {
         throw new Exception("Phone in recovery mode, support not yet implemented");
     }
     if (MobileDevice.AMDeviceIsPaired(this.iPhoneHandle) == 0)
     {
         return(false);
     }
     if (MobileDevice.AMDeviceValidatePairing(this.iPhoneHandle) != 0)
     {
         return(false);
     }
     if (MobileDevice.AMDeviceStartSession(this.iPhoneHandle) == 1)
     {
         return(false);
     }
     if (MobileDevice.AMDeviceStartService(this.iPhoneHandle, MobileDevice.CFStringMakeConstantString("com.apple.afc2"), ref this.hService, null) != 0)
     {
         if (MobileDevice.AMDeviceStartService(this.iPhoneHandle, MobileDevice.CFStringMakeConstantString("com.apple.afc"), ref this.hService, null) != 0)
         {
             return(false);
         }
     }
     else
     {
         this.wasAFC2 = true;
     }
     if (MobileDevice.AFCConnectionOpen(this.hService, 0, ref this.hAFC) != 0)
     {
         return(false);
     }
     this.connected = true;
     return(true);
 }
Esempio n. 21
0
 public unsafe bool CreateDirectory(string path)
 {
     return(MobileDevice.AFCDirectoryCreate(this.hAFC, this.FullPath(this.CurrentDirectory, path)) == 0);
 }
Esempio n. 22
0
 public unsafe bool Rename(string sourceName, string destName)
 {
     return(MobileDevice.AFCRenamePath(this.hAFC, this.FullPath(this.CurrentDirectory, sourceName), this.FullPath(this.CurrentDirectory, destName)) == 0);
 }
Esempio n. 23
0
 public unsafe int GotoDFU()
 {
     return(MobileDevice.AMDeviceEnterRecovery(this.iPhoneHandle));
 }
Esempio n. 24
0
        /// <summary>
        /// Sets the length of this stream to the given value.
        /// </summary>
        /// <param name="value">The new length of the stream.</param>
        public override void SetLength(long value)
        {
            int ret;

            ret = MobileDevice.AFCFileRefSetFileSize(phone.AFCHandle, handle, (uint)value);
        }
Esempio n. 25
0
 public unsafe string GetiPhoneStr(string str)
 {
     return(MobileDevice.AMDeviceCopyValue(this.iPhoneHandle, str));
 }
Esempio n. 26
0
 /// <summary>
 /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
 /// </summary>
 public override void Flush()
 {
     MobileDevice.AFCFlushData(phone.AFCHandle, handle);
 }
Esempio n. 27
0
 public unsafe string GetCopyDeviceIdentifier()
 {
     return(Marshal.PtrToStringAnsi(MobileDevice.AMDeviceCopyDeviceIdentifier(this.iPhoneHandle)));
 }
Esempio n. 28
0
 public unsafe int FSBlockSize()
 {
     return(MobileDevice.AFCConnectionGetFSBlockSize(this.hAFC));
 }
Esempio n. 29
0
 public override unsafe void SetLength(long value)
 {
     int num = MobileDevice.AFCFileRefSetFileSize(this.phone.AFCHandle, this.handle, (uint)value);
 }
Esempio n. 30
0
 public override unsafe void Flush()
 {
     MobileDevice.AFCFlushData(this.phone.AFCHandle, this.handle);
 }