Пример #1
0
        /// <summary>
        /// 判断文件是否存在
        /// </summary>
        /// <param name="path">完整设备内路径</param>
        /// <returns>1为存在,0为不存在</returns>
        public unsafe bool Exists(string path)
        {
            void *dict = null;
            int   num  = MobileDevice.AFCFileInfoOpen(this.hAFC, System.Text.Encoding.UTF8.GetBytes(path), ref dict);

            if (num == 0)
            {
                //释放dict指针
                MobileDevice.AFCKeyValueClose(dict);
            }
            return(num == 0);
        }
Пример #2
0
        public bool EnterRecovery()
        {
            int i = MobileDevice.AMDeviceEnterRecovery(this.iPhoneHandle);

            if (i == (int)kAMDError.kAMDSuccess)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
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);
 }
Пример #4
0
 /// <summary>
 /// 链接到设备并开启相应服务,无需单独调用,在NotifyCallback已经调用
 /// </summary>
 /// <returns></returns>
 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);
     }
     //检测是否存在afc2服务
     if (MobileDevice.AMDeviceStartService(this.iPhoneHandle, MobileDevice.CFStringMakeConstantString("com.apple.afc2"), ref this.hService, null) != 0)
     {
         //打开afc服务
         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;
     //开启安装IPA服务
     if (MobileDevice.AMDeviceStartService(this.iPhoneHandle, MobileDevice.CFStringMakeConstantString("com.apple.mobile.installation_proxy"), ref this.installFD, null) != 0)
     {
         return(false);
     }
     return(true);
 }
Пример #5
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, System.Text.Encoding.UTF8.GetBytes(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);
        }
Пример #6
0
        /// <summary>
        /// 配置链接,注册通知回调
        /// </summary>
        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 = "/";
        }
Пример #7
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);
                }
            }
        }
Пример #8
0
 public override unsafe void SetLength(long value)
 {
     int num = MobileDevice.AFCFileRefSetFileSize(this.phone.AFCHandle, this.handle, (uint)value);
 }
 public void reboot()
 {
     MobileDevice.AMRecoveryModeDeviceReboot(this.RecoveryHandle);
 }
 public int setAutoBoot(bool value)
 {
     return(MobileDevice.AMRecoveryModeDeviceSetAutoBoot(this.RecoveryHandle, Conversions.ToByte(Interaction.IIf(value, 1, 0))));
 }
Пример #11
0
        /// <summary>
        /// 上传IPA程序到/var/mobile/Media/PublicStaging
        /// 如果已经越狱,则会传到/PublicStaging,无法被InstallApplication调用,建议对于已经越狱的设备通过AFC操作手动上传IPA
        /// </summary>
        /// <param name="path">PC端IPA文件地址</param>
        public unsafe bool TransferApplication(string path)
        {
            int i = MobileDevice.AMDeviceTransferApplication(this.hService, MobileDevice.CFStringMakeConstantString(path), null, installCallBack, null);

            return(i == (int)kAMDError.kAMDSuccess);
        }
Пример #12
0
 public unsafe bool Rename(string sourceName, string destName)
 {
     return(MobileDevice.AFCRenamePath(this.hAFC, System.Text.Encoding.UTF8.GetBytes(this.FullPath(this.CurrentDirectory, sourceName)), System.Text.Encoding.UTF8.GetBytes(this.FullPath(this.CurrentDirectory, destName))) == 0);
 }
Пример #13
0
        /// <summary>
        /// 卸载IPA功能函数
        /// </summary>
        /// <param name="bundleIdentifier">APP的BundleIdentifier,例如com.tongbu.tui</param>
        /// <returns>是否成功卸载</returns>
        public unsafe bool UnInstallApplication(string bundleIdentifier)
        {
            int i = MobileDevice.AMDeviceUninstallApplication(this.installFD, MobileDevice.CFStringMakeConstantString(bundleIdentifier), IntPtr.Zero, null, null);

            return(i == (int)kAMDError.kAMDSuccess);
        }
Пример #14
0
 public unsafe string GetiPhoneStr(string str)
 {
     return(MobileDevice.AMDeviceCopyValue(this.iPhoneHandle, str));
 }
Пример #15
0
        /// <summary>
        /// 安装IPA程序,支持回调跟踪进度(暂未实现)
        /// </summary>
        /// <param name="path">PC端IPA文件地址</param>
        public unsafe bool InstallApplication(string path)
        {
            int i = MobileDevice.AMDeviceInstallApplication(this.installFD, MobileDevice.CFStringMakeConstantString(path), null, null, null);

            return(i == (int)kAMDError.kAMDSuccess);
        }
Пример #16
0
 /// <summary>
 /// 返回文件系统blocks大小,不知道干什么的= =!~
 /// </summary>
 /// <returns>系统blocks大小</returns>
 public unsafe int FSBlockSize()
 {
     return(MobileDevice.AFCConnectionGetFSBlockSize(this.hAFC));
 }
Пример #17
0
 /// <summary>
 /// 获取UDID
 /// </summary>
 /// <returns></returns>
 public unsafe string GetCopyDeviceIdentifier()
 {
     return(Marshal.PtrToStringAnsi(MobileDevice.AMDeviceCopyDeviceIdentifier(this.iPhoneHandle)));
 }
Пример #18
0
 public override unsafe void Flush()
 {
     MobileDevice.AFCFlushData(this.phone.AFCHandle, this.handle);
 }
Пример #19
0
 /// <summary>
 /// 创建文件夹
 /// </summary>
 /// <param name="path">设备内路径,可以先设定CurrentDirectory,只传入文件夹名即可</param>
 /// <returns></returns>
 public unsafe bool CreateDirectory(string path)
 {
     return(MobileDevice.AFCDirectoryCreate(this.hAFC, this.FullPath(this.CurrentDirectory, path)) == 0);
 }