IOS Android 手机助手原理以及源码(iTunesMobileDevice.dll 函数)

来源:互联网 发布:华雄深孔钻编程视频 编辑:程序博客网 时间:2024/05/18 16:57

       IOS 手机助手第一步就是需要发现并且自动识别设备,iTunes 使用 iTunesMobileDevice.dll 来实现(mac 下面用的Mobiledevice.Framework)。 iTunesMobileDevice.dll 导出了很多函数,这些用来连接设备,操作设备上的文件系统,启动设备服务等等。如果是识别和连接手机话的话,仅仅只需要使用这个dll 就可以了。我们可以使用IDA 工具来查看dll的导出函数。



IDA 这个工具是一个静态反汇编工具,非常强大,可以查看模块的导出函数,而且还能看到函数的参数个数,以及参数占用的字节数。

比如导出函数

AMDeviceNotificationSubscribe 双击这个函数名字,然后F5 按键,就可以看到函数的一些声明信息



下面是助手需要用到的所有的导出函数

#ifdef XW64
#ifdef WIN32
typedef __int64 XPInt;
#else
typedef long long XPInt;
#endif
#else
typedef int XPInt ;
#endif

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#define BOOST_SPIRIT_UNICODE
#include <Windows.h>
#include <io.h>
#define __XT(x)      L ## x
typedef  wchar_t XCHAR;
typedef  __int64 XINT64;
typedef unsigned __int64 XUINT64;
typedef  std::wstring XString;


//兼容APPLE 的数据类型
typedef void* CFStringRef;
typedef CFStringRef CFNumberRef;
typedef CFStringRef CFBooleanRef;
typedef CFStringRef CFDateRef;
typedef CFStringRef CFDataRef;
typedef CFStringRef CFDictionaryRef;
typedef CFStringRef CFArrayRef;
typedef CFStringRef CFMutableDataRef;
typedef CFStringRef CFMutableArrayRef;
typedef CFStringRef CFMutableDictionaryRef;
typedef CFStringRef CFWriteStreamRef;
typedef int CFPropertyListFormat;
typedef void* CFAllocatorRef;
typedef void* CFPropertyListRef;
typedef void* CFTypeRef;
typedef void CFArrayCallBacks;
typedef void CFDictionaryKeyCallBacks;
typedef void CFDictionaryValueCallBacks;
typedef unsigned long CFOptionFlags;
typedef int CFTypeID;
typedef XPInt CFIndex;
typedef double CFAbsoluteTime;
    typedef bool Boolean;

enum CFStringEncoding{
kCFStringEncodingMacRoman = 0,
kCFStringEncodingWindowsLatin1 = 0x0500, /* ANSI codepage 1252 */
kCFStringEncodingISOLatin1 = 0x0201, /* ISO 8859-1 */
kCFStringEncodingNextStepLatin = 0x0B01, /* NextStep encoding*/
kCFStringEncodingASCII = 0x0600, /* 0..127 (in creating CFString, values greater than 0x7F are treated as corresponding Unicode value) */
kCFStringEncodingUnicode = 0x0100, /* kTextEncodingUnicodeDefault  + kTextEncodingDefaultFormat (aka kUnicode16BitFormat) */
kCFStringEncodingUTF8 = 0x08000100, /* kTextEncodingUnicodeDefault + kUnicodeUTF8Format */
kCFStringEncodingNonLossyASCII = 0x0BFF /* 7bit Unicode variants used by Cocoa & Java */
};


enum CFNumberType {
/* Fixed-width types */
kCFNumberSInt8Type = 1,
kCFNumberSInt16Type = 2,
kCFNumberSInt32Type = 3,
kCFNumberSInt64Type = 4,
kCFNumberFloat32Type = 5,
kCFNumberFloat64Type = 6,/* 64-bit IEEE 754 */
/* Basic C types */
kCFNumberCharType = 7,
kCFNumberShortType = 8,
kCFNumberIntType = 9,
kCFNumberLongType = 10,
kCFNumberLongLongType = 11,
kCFNumberFloatType = 12,
kCFNumberDoubleType = 13,
/* Other */
kCFNumberCFIndexType = 14,
kCFNumberNSIntegerType = 15,
kCFNumberCGFloatType = 16,
kCFNumberMaxType = 16
};

#endif




typedef int (*PAMDeviceNotificationSubscribe)(am_device_notification_callback callback, unsigned int unused1, 
                                              unsigned int unused2, void *, struct am_device_notification* notif);
typedef int (*PAMDeviceNotificationUnsubscribe)(struct am_device_notification* conn);


typedef int (*PAMDeviceGetInterfaceType)(am_device* device);
typedef CFStringRef (*PAMDeviceCopyDeviceIdentifier)(am_device* device);
typedef CFTypeID (*PCFGetTypeID)(CFTypeRef cf);


typedef CFTypeID (*PCFStringGetTypeID)();
typedef CFTypeID (*PCFNumberGetTypeID)();
typedef CFTypeID (*PCFBooleanGetTypeID)();
typedef CFTypeID (*PCFDateGetTypeID)();
typedef CFTypeID (*PCFDataGetTypeID)();
typedef CFTypeID (*PCFArrayGetTypeID)();
typedef CFTypeID (*PCFDictionaryGetTypeID)();
typedef Boolean (*PCFStringGetCString)(CFStringRef theString, char *buffer, CFIndex bufferSize, CFStringEncoding encoding);
typedef CFIndex (*PCFStringGetLength)(CFStringRef theString);
typedef CFNumberType (*PCFNumberGetType)(CFNumberRef number);
typedef Boolean (*PCFNumberGetValue)(CFNumberRef number, CFNumberType theType, void *valuePtr);
typedef Boolean (*PCFBooleanGetValue)(CFBooleanRef boolean);
typedef CFAbsoluteTime (*PCFDateGetAbsoluteTime)(CFDateRef theDate);
typedef CFIndex (*PCFDataGetLength)(CFDataRef theData);
typedef const byte *(*PCFDataGetBytePtr)(CFDataRef theData);






typedef void (*cfDictKeyValue)(const void *key, const void *value, void *context);
typedef void (*PCFDictionaryApplyFunction)(CFDictionaryRef theDict, cfDictKeyValue applier, void *context);
typedef CFIndex (*PCFArrayGetCount)(CFArrayRef theArray);
typedef const void *(*PCFArrayGetValueAtIndex)(CFArrayRef theArray, CFIndex idx);
typedef void (*PCFRelease)(CFTypeRef cf);
typedef CFMutableDataRef (*PCFDataCreateMutable)(CFAllocatorRef allocator, CFIndex capacity);
typedef void (*PCFDataAppendBytes)(CFMutableDataRef theData, const byte *bytes, CFIndex length);


typedef CFPropertyListRef (*PCFPropertyListCreateFromXMLData)(CFAllocatorRef allocator, CFDataRef xmlData, CFOptionFlags mutabilityOption, CFStringRef *errorString);


typedef int (*PAFCFileRefOpen)(afc_connection* conn,const char* path, XINT64 dwMode, XINT64 *handle);
typedef int (*PAFCFileRefRead)(afc_connection* conn, XINT64 handle, void* buffer, unsigned int * len);
typedef int (*PAFCFileRefWrite)(afc_connection *conn, XINT64 handle, const void *buf, unsigned int len);
typedef int (*PAFCFileRefSeek)(afc_connection *conn, XINT64 ref, XINT64 offset1, XINT64 offset2);
typedef int (*PAFCFileRefClose)(afc_connection *conn, XINT64 ref);
typedef int (*PAFCFileRefTell)(afc_connection* conn, XINT64 handle, XINT64* position);


typedef int (*PAMDeviceConnect)(am_device* device);
typedef int (*PAMDeviceDisconnect)(am_device* device);
typedef int (*PAMDeviceStartSession)(am_device* device);
typedef int (*PAMDeviceStopSession)(am_device* device);




typedef int (*PAMDeviceIsPaired)(am_device* device);
typedef int (*PAMDevicePair)(am_device* device);
typedef int (*PAMDeviceUnpair)(am_device* device);
typedef int (*PAMDeviceValidatePairing)(am_device* device);
typedef CFStringRef (*P__CFStringMakeConstantString)(const char*);


typedef int (*PAMDServiceConnectionSend)(XPInt server,const char* buffer,int len);
typedef int (*PAMDServiceConnectionReceive)(XPInt server,char* buffer,int len);
typedef int (*PAMDeviceSecureStartService)(struct am_device *device, CFStringRef
  service_name,int timeout, XPInt *socket_fd);
typedef int (*PAMDServiceConnectionInvalidate)(XPInt server);
typedef int (*PAMDServiceConnectionGetSocket)( XPInt socket_fd);
typedef int (*PAFCConnectionOpen)(int socket_fd, unsigned int io_timeout,
struct afc_connection **conn);
typedef void* (*PAMDServiceConnectionGetSecureIOContext)(XPInt socket_fd);


typedef void* (*PAFCConnectionSetSecureContext)(afc_connection* afc,void* content);
typedef int (*PAMDSecureObserveNotification)(XPInt socket, CFStringRef notification);


typedef void (*notify_callback)(CFStringRef notification, void* data);
typedef int (*PAMDSecureListenForNotifications)(XPInt socket, notify_callback cb, void* data);


typedef CFStringRef (*PAMDeviceCopyValue)(struct am_device *device, CFStringRef domain, CFStringRef cfstring);


typedef int (*PAFCDeviceInfoOpen)(struct afc_connection *conn, struct
 afc_dictionary **info);


typedef int  (*PAFCKeyValueRead)(struct afc_dictionary *dict, char **key, char **val);


typedef int (*PAFCKeyValueClose)(struct afc_dictionary *dict);
typedef int (*PAFCDirectoryOpen)(struct afc_connection *conn,const char *path, struct
afc_directory **dir);


typedef int  (*PAFCDirectoryCreate)(afc_connection* conn, char* path);
typedef int(*PAFCDirectoryClose)(struct afc_connection *conn, afc_directory *dir);


typedef int (*PAFCDirectoryRead)(struct afc_connection *conn, struct afc_directory *dir, char **dirent);
typedef int (*PAFCFileInfoOpen)(struct afc_connection *conn,const char *path, struct
afc_dictionary **info);


typedef CFDataRef (*PCFDataCreate)(CFAllocatorRef allocator, const byte *bytes, CFIndex length);
typedef CFStringRef (*PCFStringCreateFromExternalRepresentation)(CFAllocatorRef allocator,CFDataRef data,CFStringEncoding encode);
typedef CFNumberRef (*PCFNumberCreate)(CFAllocatorRef allocator,CFNumberType theType,const void* value);
typedef CFDateRef (*PCFDateCreate)(CFAllocatorRef allocator,double value);
typedef CFMutableArrayRef (*PCFArrayCreateMutable)(CFAllocatorRef allocator, CFIndex iLength, const CFArrayCallBacks *CallBacks);
typedef void (*PCFArrayAppendValue)(CFMutableArrayRef dest,const void *src);
typedef CFMutableDictionaryRef (*PCFDictionaryCreateMutable)(CFAllocatorRef allocator, CFIndex iLength,const CFDictionaryKeyCallBacks *keyCallBacks, const CFDictionaryValueCallBacks *valueCallBacks);
typedef void (*PCFDictionaryAddValue)(CFMutableDictionaryRef dest,const void* key,const void* value);
typedef CFWriteStreamRef (*PCFWriteStreamCreateWithAllocatedBuffers)(CFAllocatorRef allocator,CFAllocatorRef bufferAlloc);
typedef Boolean (*PCFWriteStreamOpen)(CFWriteStreamRef buffer);
typedef void (*PCFWriteStreamClose)(CFWriteStreamRef buffer);


typedef CFIndex (*PCFPropertyListWriteToStream)(CFPropertyListRef propList,CFWriteStreamRef stream,CFPropertyListFormat format,CFStringRef* error);
typedef CFTypeRef (*PCFWriteStreamCopyProperty)(CFWriteStreamRef stream,CFStringRef propName);


//AT 同步
#ifdef XW64
typedef CFStringRef(*PATHostConnectionReadMessage)(void* handle, void*, void*, void*);
typedef void* (*PATHostConnectionCreateWithLibrary)(CFStringRef prefID, CFStringRef identify, CFStringRef athPath, CFBooleanRef);
typedef int(*PATHostConnectionSendPowerAssertion)(void* handle, CFBooleanRef value,void*);
#else
typedef CFStringRef(*PATHostConnectionReadMessage)(void* handle);
typedef void* (*PATHostConnectionCreateWithLibrary)(CFStringRef prefID, CFStringRef identify,void* );
typedef int(*PATHostConnectionSendPowerAssertion)(void* handle, CFBooleanRef value);
#endif // XW64

typedef int (*PATHostConnectionRetain)(void *handle);
typedef int(*PATHostConnectionSendHostInfo)(void* handle, CFStringRef value);


typedef int(*PATHostConnectionSendSyncRequest)(void* handle, CFStringRef v1, CFStringRef v2, CFStringRef v3);
typedef int(*PATHostConnectionGetGrappaSessionId)(void* handle);




下载地址:

http://115.29.237.15:8080/MobileAssist/Product/MobileTools.7z


QQ:2506314894


1 0
原创粉丝点击