Coder Social home page Coder Social logo

libimobiledevice-win32 / imobiledevice-net Goto Github PK

View Code? Open in Web Editor NEW
294.0 16.0 76.0 2.38 MB

.NET (C#, VB.NET,...) bindings for libimobiledevice

License: GNU Lesser General Public License v2.1

C# 99.59% PowerShell 0.03% Batchfile 0.11% Makefile 0.19% Roff 0.05% Shell 0.03%

imobiledevice-net's Introduction

.NET bindings for imobiledevice

Build Status NuGet Status

imobiledevice-net is a library which allows you to interact with iOS devices on Windows, macOS and Linux using .NET languages (such as C# or Visual Basic). It is based on the libimobiledevice library.

imobiledevice-net is compatible with recent versions of .NET Framework and .NET Core.

Installing

You can install imobiledevice-net as a NuGet package

PM> Install-Package imobiledevice-net

Advantages of imobiledevice-net

We've done some work to make sure imobiledevice-net "just works":

  • Better string handling: Strings are marshalled (copied from .NET code to unmanaged code and vice versa) as UTF-8 strings. This is what libimobiledevice uses natively.
  • Better array handling: In most cases, we'll return a ReadOnlyCollection<string> object instead of IntPtr objects when the native API returns an array of strings.
  • Less memory leaks: We give you safe handles instead of IntPtr objects. When you dispose of the safe handle (or you forget, and the framework does it for you), the safe memory is freed, too.
  • Unit testing support: You interact with libimobiledevice through classes such as iDevice or Lockdown. For each of these classes, we also expose an interface, allowing you to unit test your code.
  • XML Documentation: Where possible, we've copied over the documentation of libimobiledevice to imobiledevice-net, giving you IntelliSense support.

How it works

We use libclang to parse the libimobiledevice C headers and generate the C# P/Invoke code.

Documentation

See the API Documentation for more information on imobiledevice-net.

Getting started

Using the library

Before you use the library, you must call NativeLibraries.Load() so that libimobiledevice is loaded correctly:

NativeLibraries.Load();

Listing all iOS devices

The following snippit lists all devices which are currently connected to your PC:

ReadOnlyCollection<string> udids;
int count = 0;

var idevice = LibiMobileDevice.Instance.iDevice;
var lockdown = LibiMobileDevice.Instance.Lockdown;

var ret = idevice.idevice_get_device_list(out udids, ref count);

if (ret == iDeviceError.NoDevice)
{
    // Not actually an error in our case
    return;
}

ret.ThrowOnError();

// Get the device name
foreach (var udid in udids)
{
    iDeviceHandle deviceHandle;
    idevice.idevice_new(out deviceHandle, udid).ThrowOnError();

    LockdownClientHandle lockdownHandle;
    lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();

    string deviceName;
    lockdown.lockdownd_get_device_name(lockdownHandle, out deviceName).ThrowOnError();

    deviceHandle.Dispose();
    lockdownHandle.Dispose();
}

Binary distributions of libimobiledevice for Windows, macOS and Ubuntu Linux

We also provide binary distributions of libimobiledevice for Windows, macOS, and Ubuntu Linux.

For Windows and macOS, you can download a zip file with the libimobiledevice libraries and tools using the GitHub releases page.

For Ubuntu Linux, you can use our PPA (package archive) to install the latest libimobiledevice libraries and tools using apt-get. See the Quamotion PPA for more information.

The native binaries are all built from the various repositories (libplist, libusbmuxd, libimobiledevice, to name a few) in the libimobiledevice-win32 organization.

For macOS and Linux, you can use autotools to compile and install the native binaries from source. For Windows, you can use the Visual Studio solution and projects hosted in the libimobiledevice-vs repository.

Consulting, Training and Support

This repository is maintained by Quamotion. Quamotion develops test software for iOS and Android applications, based on the WebDriver protocol.

Quamotion offers various technologies related to automating iOS devices using computers running Windows or Linux. This includes:

  • The ability to remotely control iOS devices
  • Extensions to libimobiledevice with support for the Instruments protocol
  • Running Xcode UI Tests and Facebook WebDriverAgent tests

In certain cases, Quamotion also offers professional services - such as consulting, training and support - related to imobiledivice-net and libimobiledevice.

Contact us at [email protected] for more information.

imobiledevice-net's People

Contributors

ajdude avatar azure-pipelines[bot] avatar bartsaintgermain avatar qmfrederik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imobiledevice-net's Issues

NativeLibraries.Load() failed on UWP application

Hello I use imobiledevice-net in a Universal Windows Program App (UWP). In Visual Studio works everything fine in Debug mode, but in Release mode or if I tried to upload the App package onto Windows Store crashed my App, on line NativeMethods.LoadLibrary(dllToLoad) in class NativeLibraries.cs.

The reason is, UWP doesn't support a classic DllImport like used in imobiledevice-net.

[DllImport("kernel32", SetLastError = true)] public static extern IntPtr LoadLibrary(string dllToLoad);

To load native dlls, provides Microsoft a new functionality.
[DllImport("api-ms-win-core-libraryloader-l2-1-0.dll", SetLastError = true)] public static extern IntPtr LoadPackagedLibrary([MarshalAs(UnmanagedType.LPWStr)]string dllToLoad, int reserved = 0);

I solved it for me by using compiler directives to make it downward compatible. If you want, add this change in the next update.

All changes:

`
public static class NativeLibraries
{
#if !WINDOWS_UWP
NativeMethods.SetDllDirectory(str1);
#endif
foreach (string str2 in strArray)
{
string dllToLoad = Path.Combine(str1, $"{str2}.dll");
bool libraryFound;
#if WINDOWS_UWP
libraryFound = NativeMethods.LoadPackagedLibrary(dllToLoad) == IntPtr.Zero;
#else
libraryFound = NativeMethods.LoadLibrary(dllToLoad) != IntPtr.Zero;
#endif
if (!libraryFound)
{
int lastWin32Error = Marshal.GetLastWin32Error();
throw new Win32Exception(lastWin32Error, $"Could not load the library {str2} at {dllToLoad}. The error code was {lastWin32Error}");
}
}
LibraryFound = true;
}
internal static class NativeMethods
{
private const string Kernel32 = "kernel32";

    [DllImport("api-ms-win-core-libraryloader-l2-1-0.dll", SetLastError = true)]
    public static extern IntPtr LoadPackagedLibrary([MarshalAs(UnmanagedType.LPWStr)]string dllToLoad, int reserved = 0);

    [DllImport(Kernel32, SetLastError = true)]
    public static extern IntPtr LoadLibrary(string dllToLoad);

    [DllImport(Kernel32, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool SetDllDirectory(string lpPathName);

    [DllImport("dl")]
    public static extern IntPtr dlopen(string filename, DlOpenFlags flags);

    [DllImport("dl")]
    public static extern IntPtr dlerror();
}`

NativeLibraries.cs.txt

Best Tino

System.DllNotfoundException - libdl.so

I'm trying to run this on a Mac

When trying to run the example I'm getting

[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: libdl.so on NativeLibraries.Load();

Is there something I'm missing? Any help would be appreciated.

System.DllNotFoundException: libdl.so
  at (wrapper managed-to-native) iMobileDevice.NativeMethods:dlerror ()
  at iMobileDevice.NativeLibraries.Load (System.String directory) [0x0017c] in <63d012dcb31149abb9533df39eb86897>:0 
  at iMobileDevice.NativeLibraries.Load () [0x0001a] in <63d012dcb31149abb9533df39eb86897>:0 
  at test_adb.MainClass.Main (System.String[] args) [0x00001] in /Program.cs:17 
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: libdl.so
  at (wrapper managed-to-native) iMobileDevice.NativeMethods:dlerror ()
  at iMobileDevice.NativeLibraries.Load (System.String directory) [0x0017c] in <63d012dcb31149abb9533df39eb86897>:0 
  at iMobileDevice.NativeLibraries.Load () [0x0001a] in <63d012dcb31149abb9533df39eb86897>:0 
  at test_adb.MainClass.Main (System.String[] args) [0x00001] in /Program.cs:17 

CallbackOnCollectedDelegate in NotificationProxy

Hello.

I am using this library in order to communicate with my proprietary software package on an iPhone. It uses notifications to notify it's desktop/mobile counterparts to re-read a file.
However sometimes upon receiving a notification it gets the following error:

image

(It also shows the "No Source Available" window so I cannot know where exactly this exception happens)

It may work for a little while, or do that right away. My code is as follows:

        private void MakeReady()
        {
            _isPaired = true;
            LibiMobileDevice.Instance.NotificationProxy.np_client_start_service(_hDev, out _hNotif, "notify").ThrowOnError();
            LibiMobileDevice.Instance.NotificationProxy.np_observe_notification(_hNotif, "redacted");
            LibiMobileDevice.Instance.NotificationProxy.np_set_notify_callback(_hNotif, this._GotNotify, (IntPtr)null);
            _state = IsDaemonRunning() ? SetsuzokuDeviceState.SDVReady : SetsuzokuDeviceState.SDVBroken;
        }

        public void PostNotification(string notification)
        {
            LibiMobileDevice.Instance.NotificationProxy.np_post_notification(_hNotif, notification);
        }

        public string ExpectAnyNotificationInResponseTo(string notification, int timeout)
        {
            string _whatWeGet = "";
            _lastNotification = "";
            IAsyncResult result;
            Action action = () =>
            {
                PostNotification(notification);
                while (_lastNotification == "")
                {
                    Thread.Sleep(10);
                }
                _whatWeGet = _lastNotification;
                _lastNotification = "";
            };

            _state = SetsuzokuDeviceState.SDVPerformingAction;
            result = action.BeginInvoke(null, null);

            if (result.AsyncWaitHandle.WaitOne(timeout))
            {
                _state = SetsuzokuDeviceState.SDVReady;
                Console.WriteLine("Notification successfully received.");
                return _whatWeGet;
            }
            else
            {
                _state = SetsuzokuDeviceState.SDVReady;
                Console.WriteLine("Notification waiting timed out.");
                return null;
            }

        }

        private string _lastNotification = "";
        private void _GotNotify(string notification, IntPtr userData)
        {
            _lastNotification = notification;
        }

The class containing this code is created per every device and is stored in a static List of a static class. So I guess something gets garbage collected on the library side?

Thanks a lot in advance.

Memory issue with PlistHandles

We discovered a memory problem during an iteration through the Iconstate Plist. The appended function ReturnAppList() collects all bundleNames of Apps on the homescreens and returns them in a list of Strings.
The function collects the correct strings, but the program exits either afterwards or during iteration with Code 0x4000001f. We assume, the subentries (e.g. PlistHandle entry) free memory they should not own. (e.g. of PlistHandle screen).
We tried to avoid this manually by using GC.SupressFinalize, but could not defuse this issue completely.

public static List<String> ReturnAppList()
        {          
            // Get IconState in FormatVersion 2
            var sb_instance = LibiMobileDevice.Instance.SpringBoardServices;
            PlistHandle Iconstate;
            sb_instance.sbservices_get_icon_state(springboardhandle, out Iconstate, "2");

            // All App names shall be collected within a List of strings
            List<String> AppList = new List<String>();

            // Iterate through Iconstate
            uint numHomescreens = api.plist_array_get_size(Iconstate);
            for (uint homeScreen = 0; homeScreen < numHomescreens; homeScreen++)
            {
                PlistHandle screen = api.plist_array_get_item(Iconstate, homeScreen);

                uint screen_count = api.plist_array_get_size(screen);
                for (uint item_nr = 0; item_nr < screen_count; item_nr++)
                {
                    PlistHandle entry = api.plist_array_get_item(screen, item_nr);

                    // Get value of bundleIdentifier as string and append to AppList
                    PlistHandle bundleNameNode = api.plist_dict_get_item(entry, "bundleIdentifier");
                    if (bundleNameNode.IsInvalid == false)
                    {
                        String app_identifier;
                        api.plist_get_string_val(bundleNameNode, out app_identifier);
                        AppList.Add(app_identifier);
                    }
                }
            }
            return AppList;
        }

See attachment for a functional little example project.
SpringBoardTest.zip

Disconnecting iOS device on Windows 10 issue

I have a application build in c# running on Windows 10 (32bit or 64bit) that will detect and connect to an iOS device running iOS 11 without issue. There is application on the iOS device that will transfer data back and forth but if I pull the USB cable from the iOS device the iOS application will freeze and cease to respond.

The same behaviour does not occur on Windows 7 (32bit or 64bit) and we are able to handle the issue raised.

Is there a reason why this may be happening or known method to better handle this?

How can I check null of plisthandle?

This is C++ code and my VB.NET code.
They are use "while (NULL == switch_node". But I'm only use vb.net.

How can I check plisthandle is null?

Thank you.

contact_node = plist_array_get_item(array, 0);
switch_node = plist_array_get_item(array, 0);

while (NULL == switch_node
    && check_string(contact_node, "com.apple.Contacts")
    && check_string(switch_node, "SDMessageDeviceReadyToReceiveChanges")) {

	plist_free(array);
	array = NULL;

	array = plist_new_array();
	plist_array_append_item(array, plist_new_string("SDMessageAcknowledgeChangesFromDevice"));
	plist_array_append_item(array, plist_new_string("com.apple.Contacts"));

	ret = mobilesync_send(client, array);
	plist_free(array);
	array = NULL;

	ret = mobilesync_receive(client, &array);

	contact_node = plist_array_get_item(array, 0);
	switch_node = plist_array_get_item(array, 0);
}

Dim _Contact_Node As PlistHandle = PlistHandle.Zero
Dim _Switch_Node As PlistHandle = PlistHandle.Zero

    While _Switch_Node Is Nothing And _Check_String(_Contact_Node, "com.apple.Contacts") And _Check_String(_Switch_Node, "SDMessageDeviceReadyToReceiveChanges")

        _PlistHandle = Nothing
        _PlistHandle = plist_new_array()

        plist_array_append_item(_PlistHandle, plist_new_string("SDMessageAcknowledgeChangesFromDevice"))
        plist_array_append_item(_PlistHandle, plist_new_string("com.apple.Contacts"))

        _Ret = mobilesync_send(_MobileSyncClientHandle, _PlistHandle)
        _PlistHandle = Nothing

        _Ret = mobilesync_receive(_MobileSyncClientHandle, _PlistHandle)

        _Contact_Node = plist_array_get_item(_PlistHandle, 0)
        _Switch_Node = plist_array_get_item(_PlistHandle, 0)

    End While

Remove .exe from native payload

I can't really see a reason why all the sample EXE files are packaged into the package native folder and get automatically deployed together with the required DLLs. If I build a .NET program to use the DLLs as a bridge to the iOS device, I have my own code naturally and I don't need the samples to operate. Could those be removed from the package?

Crash on device unplug with pending read

I have a problem when I physically disconnect the cable from the connected device and I have a pending call to idevice_connection_receive_timeout
Even if I wrap the call in a try catch block, the application stops working. If i try to debug with VS, shows only Your app has entered a break state, but no code is currently executing that is supported by the selected debug engine (e.g. only native runtime code is executing). and if I hit continue, it stops the debug session and kills the app.
I also noticed that this happens before even receiving the device disconnect message on the idevice_event_subscribe handles.
Is there a way to suppress this behavior ? All I want to do is just acknowledge the cable was unplugged while waiting for data and keep going on.

Unable to find an 'mobileactivation_client_new' in DLL 'imobiledevice

MobileactivationClientHandle activation_client;
MobileactivationError ret = activation.mobileactivation_client_new(deviceHandle, serviceDescriptorHandle, out activation_client);

getting an error with Unable to find an entry point named 'mobileactivation_client_new' in DLL 'imobiledevice.

Currently, i'm using version no - 212
Install-Package imobiledevice-net -Version 1.2.1-r212

Distinguish between USB and WiFi (or just ignore the latter)

Hi,
I'm here again asking for your support.
I have a problem with Apple "Sync over WiFi" feature because when I receive the notification of a newly connected device, I have no way to determine if it's a USB connection or one over WiFi.
According to libimobiledevice repo they still need to implement some kind of switch or flag to solve this.
In the mean time, I've found this repo where the guy just drops every notification that he identifies as WiFi (by ... looking at that product_id property). I've been trying rebuild all the components from source applying that change but so far I had no luck: WiFi sync keeps triggering those notification.
Would it be possible to handle this scenario in some way ? All I really need is to ignore those WiFi connections.
Thanks

Runtime library wrong directory

The runtimes are in folders called win-x64 and win-x86 instead of win7-x64 and win7-x86 and the target script references the the latter. zlib,dll should also be renamed to zlib1.dll

Is there any subset of dlls that are required to load required native libraries?

Hi,

To work with nuget package, I need to specify a folder other than "win-x86" for loading native libraries (imobiledevice.dll, ideviceactivation.dll). If I copy only these 2 dlls then I receive following error -
System.ComponentModel.Win32Exception (0x80004005): Could not load the library 'imobiledevice' at '...\imobiledevice.dll'. The error code was 126.

If I copy all the 22 dlls from packages\iMobileDevice-net.1.2.126\runtimes\win-x86\native\ path, then it works.

I want to know if there is any subset of these dlls that if copied, it will work.

Desired features:

  1. Detect iOS device connection (before and after loading native libraries)
  2. Get name, udid of device
  3. Create a tcp connection with device
  4. Detect device detachment from system

Thanks & Regards
Pallavi Garg

Guide and example

Hi, Frederik

I'd like to use this library to develop a project to install ipa and push file to iOS device. It's hard to me to find how to implement it. I also use your sharpadbclient to do the same thing on Android. It's much more straight forward.

Could you share some sample codes?

Thanks.

afc_read_directory returns InvalidArg

ReadOnlyCollection<string> FileListPtr;
var result = afc.afc_read_directory(AfcClient, DirectoryPath, out FileListPtr);

Returns AfcError.InvalidArg. Both AfcClient and DirectoryPath are valid. The extra condition in afc.c is a bit suspicious:

if (!client || !path || !directory_information || (directory_information && *directory_information))
  return AFC_E_INVALID_ARG;

Device keeps getting disconnected

Even when the device is untouched it keeps getting connected, paired and then disconnected. I have tried making a new project with basic code:

static void OnDeviceConnect (ref iDeviceEvent s, IntPtr e) {
      var udid = s.udidString;

      var dev_info = new iMobileDevice.Usbmuxd.UsbmuxdDeviceInfo ();
      LibiMobileDevice.Instance.Usbmuxd.usbmuxd_get_device_by_udid (s.udidString, ref dev_info);

      if (dev_info.product_id <= 0 || dev_info.conn_type == UsbmuxConnectionType.TypeNetwork) return;

      switch (s.@event) {
        case iDeviceEventType.DeviceAdd:
          if (Program.udid == udid) break;

          Console.WriteLine ("iOS Device Connected: " + udid);

          try {
            lib.iDevice.idevice_new (out devH, udid).ThrowOnError ();
            lib.Lockdown.lockdownd_client_new (devH, out lockD, "PhoneInfo").ThrowOnError ();

            bool AttemptPair () {
              LockdownError res;
              try {
                res = lib.Lockdown.lockdownd_pair (lockD, LockdownPairRecordHandle.Zero);
              } catch (Exception excpt) { Log (excpt); return false; }

              if (res == LockdownError.PairingDialogResponsePending ||
                res == LockdownError.PasswordProtected || res == LockdownError.UserDeniedPairing) {
                Task.Delay (1000).ContinueWith (t => AttemptPair ()).ContinueWith (t => Log (t.Exception), TaskContinuationOptions.OnlyOnFaulted);
                return false;
              }
              return res == LockdownError.Success;
            }

            if (!AttemptPair ()) {
              Console.WriteLine ();
              Console.WriteLine ($"ERROR: Could not pair with device: {udid}.");
              Console.WriteLine ();
            }
          } catch (Exception excpt) {
            Log (excpt);
            Console.WriteLine ();
            Console.WriteLine (
              "ERROR: Could not pair to device.");
            Console.WriteLine ();
          }
          break;
        case iDeviceEventType.DevicePaired:
          try {
            if (devH != null) {
              try {
                lib.Lockdown.lockdownd_client_new_with_handshake (devH, out lockD, "PhoneInfo").ThrowOnError ();
                Console.WriteLine ("iOS Device paired: " + udid);
              } catch (Exception er) {
                Log (er);
              }
            }
          } catch (Exception ex) {
            Log (ex);
          }
          break;
        case iDeviceEventType.DeviceRemove:
          Console.WriteLine ("iOS Device Disconnected: " + udid);

          if (devH != null) {
            if (!devH.IsInvalid && !devH.IsClosed) {
              devH.Close ();
            }
            devH.Dispose ();
            devH = null;
          }

          if (lockD != null) {
            if (!lockD.IsInvalid && !lockD.IsClosed) {
              lockD.Close ();
            }
            lockD.Dispose ();
            lockD = null;
          }

          if (connH != null) {
            if (!connH.IsInvalid && !connH.IsClosed) {
              connH.Close ();
            }
            connH.Dispose ();
            connH = null;
          }
          break;
      }
    }

But this is the output I get:

iOS Device Connected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device paired: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Disconnected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Connected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device paired: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Disconnected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Connected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device paired: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Disconnected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Connected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device paired: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Disconnected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Connected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device paired: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Disconnected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Connected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device paired: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Disconnected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Connected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device paired: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Disconnected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Connected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device paired: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Disconnected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Connected: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device paired: 9f65e596e9786ebaf904d73ec89901549ca93855
iOS Device Disconnected: 9f65e596e9786ebaf904d73ec89901549ca93855

I'm not sure what is the problem as it happens with multiple ios devices and in multiple PCs.

win10 loaded libimobiledevice.dll file

我在win10 x64位的系统中编写了代码
全部正确加载dll文件后,能获取udid
但是在与手机握手的时候发生了SSL错误
image

换作其他版本 的时候就能正常获取手机信息
现在怀疑打包文件中缺少了SSL文件

希望能帮忙解答下,我该怎么办

Binaries not available

The mentioned binary can not be found on AppVeyor.

Windows (x64) | libimobiledevice-1.2.1-win-x64.zip | AppVeyor

PlistError

I am using the code snippet provided that gives the list of devices connected.
It is throwing error at the line

lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();

Error is - An Lockdown error occurred, the error code was PlistError.

I am using iPhone 8 with iOS 11.4.1

Dll fails to load if dependent project uses nuget package

I have a solution with two project: MainProj and CoreProj. MainProj depends on CoreProj and CoreProj uses imobiledevice nuget package. When I run this I get this error:

The directory 'C:\MySolution\MainProj\bin\Debug' does not contain a subdirectory for the current architecture. The directory 'C:\MySolution\MainProj\bin\Debug\win7-x64' does not exist.

When I check I see that it really doesn't have that folder there. I see that this folder exists under C:\MySolution\CoreProj\bin\Debug\. So it got copied under the CoreProj but not under the MainProj. Looking online the best I could find is this:

https://stackoverflow.com/questions/19478775/add-native-files-from-nuget-package-to-project-output-directory

But after trying to change the targets file I still didn't manage to get those folders to appear in the MainProj.

I am using VisualStudio 2017 on Window 10.

Memory free issue in Nativelibraries

I am using imobiledevice-net in VS2017.whenever I tried to call some native library's free function such as np_client_free(), it throws an exception saying that System.AccessViolationException

I m providing some debug info below..

Releasing NotificationProxyClientHandle 2470434744832 using iMobileDevice.LibiMobileDevice. This object was created at    at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   at System.Environment.get_StackTrace()
   at iMobileDevice.NotificationProxy.NotificationProxyClientHandle..ctor()
   at iMobileDevice.NotificationProxy.NotificationProxyNativeMethods.np_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, NotificationProxyClientHandle& client)
   at iMobileDevice.NotificationProxy.NotificationProxyApi.np_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, NotificationProxyClientHandle& client)
   .
   .
   .

Exception thrown: 'System.AccessViolationException' in iMobileDevice-net.dll
An unhandled exception of type 'System.AccessViolationException' occurred in iMobileDevice-net.dll
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

'idevice_get_device_list' failing with "connect: No error"

Just running through the basic setup snippet given in the readme, I into this problem. Please note that, I am using Windows.

The call to idevice.idevice_get_device_list is failing with connect: No error and a return value of iDeviceError.NoDevice.

However, this is only when iTunes is not installed. As soon as I install iTunes, I am able to get the whole code working perfectly.

Is there any way to run this without iTunes installed?

How can I get success on mobilebackup2 version exchange?

This is my code for backup iPhone 5C device to my PC...
But I'm trying to 'mobilebackup2_version_exchange', thrown 'error code -6 : NOCOMMONVERSION'

How can I solve this problem?

Try

        Dim _UDIDs As ReadOnlyCollection(Of String) = Nothing
        Dim _COUNT As Integer = 0

        _WriteLog("idevice_get_device_list", idevice_get_device_list(_UDIDs, _COUNT).ToString())

        For Each _UDID In _UDIDs

            Dim _iDeviceHandle As iDeviceHandle = iDeviceHandle.Zero
            _WriteLog("idevice_new", idevice_new(_iDeviceHandle, _UDID).ToString)

            Dim _LockdownClientHandle As LockdownClientHandle = LockdownClientHandle.Zero
            Dim _LockdownServiceDescriptorHandle As LockdownServiceDescriptorHandle = LockdownServiceDescriptorHandle.Zero
            _WriteLog("lockdownd_client_new_with_handshake", lockdownd_client_new_with_handshake(_iDeviceHandle, _LockdownClientHandle, "iDevice").ToString)
            _WriteLog("lockdownd_start_service-AFC", lockdownd_start_service(_LockdownClientHandle, "com.apple.afc", _LockdownServiceDescriptorHandle).ToString)

            Dim _AfcClientHandle As AfcClientHandle = AfcClientHandle.Zero
            _WriteLog("afc_client_new", afc_client_new(_iDeviceHandle, _LockdownServiceDescriptorHandle, _AfcClientHandle).ToString)

            Dim _MobileBackup2ClientHandle As MobileBackup2ClientHandle = MobileBackup2ClientHandle.Zero
            _WriteLog("lockdownd_start_service-MB2", lockdownd_start_service(_LockdownClientHandle, "com.apple.mobilebackup2", _LockdownServiceDescriptorHandle).ToString)
            '_WriteLog("lockdownd_start_service-MB2", lockdownd_start_service_with_escrow_bag(_LockdownClientHandle, "com.apple.mobilebackup2", _LockdownServiceDescriptorHandle).ToString)
            _WriteLog("mobilebackup2_client_new", mobilebackup2_client_new(_iDeviceHandle, _LockdownServiceDescriptorHandle, _MobileBackup2ClientHandle).ToString)

            '/* send Hello message */
            'Dim _Local_Version_Array As Double() = New Double() {2.0, 2.1}
            'Dim _Local_Version As IntPtr = Marshal.AllocCoTaskMem(8 * _Local_Version_Array.Length)
            'Marshal.Copy(_Local_Version_Array, 0, _Local_Version, _Local_Version_Array.Length)

            Dim _Local_Version_Array As Double() = New Double() {2.0, 2.1}
            Dim _Local_Version As IntPtr = Marshal.AllocCoTaskMem(8 * _Local_Version_Array.Length)
            Marshal.Copy(_Local_Version_Array, 0, _Local_Version, _Local_Version_Array.Length)

            Dim _Remote_Version As Double = 0.0
            _WriteLog("mobilebackup2_version_exchange", mobilebackup2_version_exchange(_MobileBackup2ClientHandle, _Local_Version, 2, _Remote_Version).ToString)

            '_iDeviceHandle.Dispose()
            '_LockdownClientHandle.Dispose()

            ListBox1.Items.Add("=====================================================================")

        Next

    Catch ex As Exception

        MsgBox(ex.ToString)

    End Try

Getting Unknown error house_arrest_client_start_service

some time i getting Unknown error when calling house_arrest_client_start_service.
If you call multiple time then it throwing unknown error.
house_arrest_client_start_service(iDeviceHandle device, out HouseArrestClientHandle client, string label);

Problem running on macOS

When trying to build on macOS, I am getting this error where the libraries cannot be loaded. I'm not sure what it means in this context. [I hope it doesn't need libimobiledevice to be installed to actually run?]

System.DllNotFoundException: "Unable to load shared library 'imobiledevice' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libimobiledevice, 1): image not found"
  at iMobileDevice.iDevice.iDeviceNativeMethods.idevice_event_subscribe(iDeviceEventCallBack callback, IntPtr userData)\n   at iMobileDeviceTest.Program.Main(String[] args) in /Users/writwick/VSProjects/iMobileDeviceTest/Program.cs:14

I have tried using VSCode at first and moved to Visual Studio for mac later on to get the same error every time I tried to run.

This simple code in a new project reproduces this error:

using System;
using iMobileDevice;
using iMobileDevice.iDevice;

namespace iMobileDeviceTest {
    class Program {
        static void Main(string[] args) {
            Console.WriteLine("Hello World!");

            NativeLibraries.Load();

            LibiMobileDevice lib = new LibiMobileDevice();

            lib.iDevice.idevice_event_subscribe((ref iDeviceEvent er, IntPtr p) => { }, IntPtr.Zero);
        }
    }
}

NOTE:

If at all possible, I would like to use VSCode to build and run rather than Visual Studio.

UPDATE:

Adding to the question, when I ran the program with environment variable DYLD_PRINT_LIBRARIES=YES (In Project Default Run Configuration), I got this output just before the error was hit.

dyld: loaded: /usr/lib/libxslt.1.dylib
dyld: loaded: /usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.1.5/libclrjit.dylib
dyld: loaded: /usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.1.5/System.Globalization.Native.dylib
dyld: loaded: /usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.1.5/System.Native.dylib
dyld: loaded: /Users/writwick/.nuget/packages/imobiledevice-net/1.2.67/runtimes/osx-x64/native/libimobiledevice.dylib
dyld: loaded: /Users/writwick/.nuget/packages/imobiledevice-net/1.2.67/runtimes/osx-x64/native/libssl.1.0.0.dylib
dyld: loaded: /Users/writwick/.nuget/packages/imobiledevice-net/1.2.67/runtimes/osx-x64/native/libcrypto.1.0.0.dylib
dyld: loaded: /Users/writwick/.nuget/packages/imobiledevice-net/1.2.67/runtimes/osx-x64/native/libusbmuxd.dylib
dyld: loaded: /Users/writwick/.nuget/packages/imobiledevice-net/1.2.67/runtimes/osx-x64/native/libplist.dylib
dyld: unloaded: /Users/writwick/.nuget/packages/imobiledevice-net/1.2.67/runtimes/osx-x64/native/libimobiledevice.dylib
dyld: unloaded: /Users/writwick/.nuget/packages/imobiledevice-net/1.2.67/runtimes/osx-x64/native/libssl.1.0.0.dylib
dyld: unloaded: /Users/writwick/.nuget/packages/imobiledevice-net/1.2.67/runtimes/osx-x64/native/libcrypto.1.0.0.dylib
dyld: unloaded: /Users/writwick/.nuget/packages/imobiledevice-net/1.2.67/runtimes/osx-x64/native/libusbmuxd.dylib
dyld: unloaded: /Users/writwick/.nuget/packages/imobiledevice-net/1.2.67/runtimes/osx-x64/native/libplist.dylib

I proceeded to add a new variable DYLD_FALLBACK_LIBRARY_PATH to the environment variables, pointing to the path for the libraries where nuget unpacked them: /Users/writwick/.nuget/packages/imobiledevice-net/1.2.67/runtimes/osx-x64/native/ (in my system).

The code runs perfectly now. Interestingly, all the dyld: unloaded lines disappeared.
(I'm not sure if its meant to be done this way).

My question would be how to handle this during deployment for a different system.

MobileBackup2 version exchange <real> error

The following plist is being sent to the device in the version exchange:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
        <string>DLMessageProcessMessage</string>
        <dict>
                <key>SupportedProtocolVersions</key>
                <array>
                        <real>2.000000</real>
                        <real>2.100000</real>
                </array>
                <key>MessageName</key>
                <string>Hello</string>
        </dict>
</array>
</plist>

The device kicks back an error because of the <real>2.100000</real> not being 2.1. I'm trying this with an iPhone 6 on iOS 12.1.1.

Error Plist:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
        <string>DLMessageProcessMessage</string>
        <dict>
                <key>ErrorCode</key>
                <integer>0</integer>
                <key>ProtocolVersion</key>
                <real>2.100000</real>
                <key>MessageName</key>
                <string>Response</string>
        </dict>
</array>
</plist>

My code:

// Send the hello message
double[] localVersionArray = {2.0, 2.1};
IntPtr localVersions = Marshal.AllocCoTaskMem(8 * localVersionArray.Length);
Marshal.Copy(localVersionArray, 0, localVersions, localVersionArray.Length);
double remoteVersion = 0;

backup.mobilebackup2_version_exchange(clientHandle, localVersions, 2, ref remoteVersion);

I'm using v1.2.72 downloaded with NuGet.

'An Lockdown error occurred. The error code was SslError'

When attempting to run the code below, it throws an exception saying 'An Lockdown error occurred. The error code was SslError'.

Code: lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();

Can't find a fix for this.

NuGet package not working with .NET Framework greater than 4.0

I've tried to add a reference to the imobiledevice-net package on NuGet but if I target .NET Framework v 4.5 i get a runtime error telling me it can't load the dependent dlls.
Retargeting the same project to target .NET Framework 4.0 works.
Could you please add support for newer framework versions too ?

multiple notifications with np_observe_notifications

The method signature is: LibiMobileDevice.NotificationProxy.np_observe_notifications(NotificationProxyClientHandle client, out string notificationSpec).

How to call this if I want to monitor multiple notifications? Since it takes only a string as input I am unsure how to construct the string with the multiple notification data.

Ideviceinstaller and idevicesyslog failing to start proxies

I downloaded the build from a month ago and tested on an iOS 11.2 device.

  • Ideviceinfo works fine
  • Ideviceinstaller fails: could not start com.apple.notification_proxy
  • Idevicesyslog fails: could not start service com.apple.syslog.relay
  • ideviceimagemouter fails: mount_image returned -3 (connection failed??). Note that -h and -l no longer work. Error: stat: -h: No such file or directory.
  • idevicedebug fails: could not start com.apple.debugserver

XML comment has badly formed XML

Add missing equals sign between cref and \.

File: iMobileDevice.Generator/ApiExtractor.cs

Code: constructor.Comments.Add(new CodeCommentStatement($"Initializes a new instance of the <see cref\"{nativeClass.Name}\"/> class", true));

System.DllNotFoundExeption: imobiledevice on mac

PROGRAM

Demo app in repo

ERROR

System.DllNotFoundException: imobiledevice

CONSOLE LOG

dyld: loaded: /Library/Frameworks/Mono.framework/Versions/5.12.0/lib/mono/4.5/mscorlib.dll.dylib
dyld: unloaded: /Library/Frameworks/Mono.framework/Versions/5.12.0/lib/mono/4.5/mscorlib.dll.dylib
dyld: loaded: /Library/Frameworks/Mono.framework/Versions/5.12.0/lib/mono/4.5/mscorlib.dll.dylib
dyld: unloaded: /Library/Frameworks/Mono.framework/Versions/5.12.0/lib/mono/4.5/mscorlib.dll.dylib
Starting the imobiledevice-net demo
The application was terminated by a signal: SIGHUP
Unhandled Exception:
System.DllNotFoundException: imobiledevice
at (wrapper managed-to-native) iMobileDevice.iDevice.iDeviceNativeMethods.idevice_get_device_list(intptr&,int&)
at iMobileDevice.iDevice.iDeviceNativeMethods.idevice_get_device_list (System.Collections.ObjectModel.ReadOnlyCollection1[System.String]& devices, System.Int32& count) [0x0000d] in D:\a\1\s\imobiledevice-net\iDevice\iDeviceNativeMethods.Extensions.cs:34
at iMobileDevice.iDevice.iDeviceApi.idevice_get_device_list (System.Collections.ObjectModel.ReadOnlyCollection1[System.String]& devices, System.Int32& count) [0x00000] in D:\a\1\s\imobiledevice-net\iDevice\iDeviceApi.cs:126
at Robotic.LocalRecorder.Program.Main (System.String[] args)

I added DYLD_PRINT_LIBRARIES=YES line to env. variable. It gives info that loaded all libraries. However, i see the last 2 libraries have problem. And program gives error DLLNotFoundException on var ret = idevice.idevice_get_device_list(out udids, ref count); line of demo app.

Lockdown error occurred. The error code was InvalidArg

hello,iphone xs max 12.0 .NET4.6.1
lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();
throw Lockdown error occurred. The error code was InvalidArg
How do I solve this problem?

x86 lose libeay32.dll

Hello,
When i use imobiledevice-net (Version 1.2.1-r189)
call ... NativeLibraries.Load();
System.IO.FileNotFoundException: 'Could not load the library 'libeay32' at 'C:...\win7-x86\libeay32.dll', because the file does not exist'

PS: win7-x64 is OK.

"Allow the computer to access information on xxxxx"

If I have not "Allow the computer to access information on 'iPod'" via iTunes, I will get iMobileDevice.Lockdown.LockdownException: 'An Lockdown error occurred. The error code was InvalidConf' when calling lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();.

Is it possible to do the "allow" action via the library, so that the user no need to open the iTunes (but of course have installed it)?

Or better..... is it possible that not requiring the user install iTunes, just included everything in my C# application?

Thank you!

Populating the API property of various PlistHandle

The API property of PlistHandle objects which are returned by various API calls are not populated.
Examples include:
1 Callbacks (e.g. in the InstallationProxyStatusCallBack)
2 Methods that create new PlistHandle values (e.g. InstallationProxy.instproxy_client_options_new)

For 2, this is probably because the handle is a return value and not an out value, and that's why we missed it.
For 1, it's a bit more tricky, and an option may be to pass the Api as the state variable (although this may require pinning). To be investigated.

Read and Write on .Libray dictonary.

We able to perform read and write on Document folder but we getting permission denied error when we try to write or create a file in Library dictionary.

we using VendDocuments for house arrest commnad
houseassest.house_arrest_send_command(house_client, "VendDocuments", appId);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.