From d13ff11793e4366f8a8e49b241f90043aaac26f7 Mon Sep 17 00:00:00 2001 From: esterTion Date: Sun, 1 Mar 2020 10:06:07 +0800 Subject: [PATCH] device connect --- .gitignore | 246 ++++++ Brokenithm-Evolved-iOS.sln | 31 + .../Brokenithm-Evolved-iOS.vcxproj | 151 ++++ .../Brokenithm-Evolved-iOS.vcxproj.filters | 27 + Brokenithm-Evolved-iOS/libimobiledevice.lib | Bin 0 -> 70256 bytes Brokenithm-Evolved-iOS/main.cpp | 54 ++ dep/libimobiledevice/afc.h | 375 +++++++++ dep/libimobiledevice/debugserver.h | 246 ++++++ dep/libimobiledevice/diagnostics_relay.h | 185 +++++ dep/libimobiledevice/file_relay.h | 165 ++++ dep/libimobiledevice/heartbeat.h | 132 +++ dep/libimobiledevice/house_arrest.h | 179 ++++ dep/libimobiledevice/installation_proxy.h | 504 ++++++++++++ dep/libimobiledevice/libimobiledevice.h | 259 ++++++ dep/libimobiledevice/lockdown.h | 448 ++++++++++ dep/libimobiledevice/misagent.h | 145 ++++ dep/libimobiledevice/mobile_image_mounter.h | 170 ++++ dep/libimobiledevice/mobilebackup.h | 242 ++++++ dep/libimobiledevice/mobilebackup2.h | 211 +++++ dep/libimobiledevice/mobilesync.h | 354 ++++++++ dep/libimobiledevice/notification_proxy.h | 196 +++++ dep/libimobiledevice/property_list_service.h | 169 ++++ dep/libimobiledevice/restore.h | 182 +++++ dep/libimobiledevice/sbservices.h | 176 ++++ dep/libimobiledevice/screenshotr.h | 115 +++ dep/libimobiledevice/service.h | 169 ++++ dep/libimobiledevice/syslog_relay.h | 160 ++++ dep/libimobiledevice/webinspector.h | 134 +++ dep/plist/Array.h | 55 ++ dep/plist/Boolean.h | 48 ++ dep/plist/Data.h | 49 ++ dep/plist/Date.h | 50 ++ dep/plist/Dictionary.h | 68 ++ dep/plist/Integer.h | 48 ++ dep/plist/Key.h | 49 ++ dep/plist/Node.h | 57 ++ dep/plist/Real.h | 48 ++ dep/plist/String.h | 49 ++ dep/plist/Structure.h | 59 ++ dep/plist/Uid.h | 48 ++ dep/plist/plist++.h | 39 + dep/plist/plist.h | 770 ++++++++++++++++++ test.php | 19 + 43 files changed, 6881 insertions(+) create mode 100644 .gitignore create mode 100644 Brokenithm-Evolved-iOS.sln create mode 100644 Brokenithm-Evolved-iOS/Brokenithm-Evolved-iOS.vcxproj create mode 100644 Brokenithm-Evolved-iOS/Brokenithm-Evolved-iOS.vcxproj.filters create mode 100644 Brokenithm-Evolved-iOS/libimobiledevice.lib create mode 100644 Brokenithm-Evolved-iOS/main.cpp create mode 100644 dep/libimobiledevice/afc.h create mode 100644 dep/libimobiledevice/debugserver.h create mode 100644 dep/libimobiledevice/diagnostics_relay.h create mode 100644 dep/libimobiledevice/file_relay.h create mode 100644 dep/libimobiledevice/heartbeat.h create mode 100644 dep/libimobiledevice/house_arrest.h create mode 100644 dep/libimobiledevice/installation_proxy.h create mode 100644 dep/libimobiledevice/libimobiledevice.h create mode 100644 dep/libimobiledevice/lockdown.h create mode 100644 dep/libimobiledevice/misagent.h create mode 100644 dep/libimobiledevice/mobile_image_mounter.h create mode 100644 dep/libimobiledevice/mobilebackup.h create mode 100644 dep/libimobiledevice/mobilebackup2.h create mode 100644 dep/libimobiledevice/mobilesync.h create mode 100644 dep/libimobiledevice/notification_proxy.h create mode 100644 dep/libimobiledevice/property_list_service.h create mode 100644 dep/libimobiledevice/restore.h create mode 100644 dep/libimobiledevice/sbservices.h create mode 100644 dep/libimobiledevice/screenshotr.h create mode 100644 dep/libimobiledevice/service.h create mode 100644 dep/libimobiledevice/syslog_relay.h create mode 100644 dep/libimobiledevice/webinspector.h create mode 100644 dep/plist/Array.h create mode 100644 dep/plist/Boolean.h create mode 100644 dep/plist/Data.h create mode 100644 dep/plist/Date.h create mode 100644 dep/plist/Dictionary.h create mode 100644 dep/plist/Integer.h create mode 100644 dep/plist/Key.h create mode 100644 dep/plist/Node.h create mode 100644 dep/plist/Real.h create mode 100644 dep/plist/String.h create mode 100644 dep/plist/Structure.h create mode 100644 dep/plist/Uid.h create mode 100644 dep/plist/plist++.h create mode 100644 dep/plist/plist.h create mode 100644 test.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..096c1d2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,246 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates +*.dll + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +[Xx]64/ +[Xx]86/ +[Bb]uild/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml + +# TODO: Un-comment the next line if you do not want to checkin +# your web deploy settings because they may include unencrypted +# passwords +#*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Microsoft Azure ApplicationInsights config file +ApplicationInsights.config + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# LightSwitch generated files +GeneratedArtifacts/ +ModelManifest.xml + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ \ No newline at end of file diff --git a/Brokenithm-Evolved-iOS.sln b/Brokenithm-Evolved-iOS.sln new file mode 100644 index 0000000..70ed109 --- /dev/null +++ b/Brokenithm-Evolved-iOS.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29709.97 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Brokenithm-Evolved-iOS", "Brokenithm-Evolved-iOS\Brokenithm-Evolved-iOS.vcxproj", "{F3C0C748-308E-4243-B2B7-D0498196D76E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F3C0C748-308E-4243-B2B7-D0498196D76E}.Debug|x64.ActiveCfg = Debug|x64 + {F3C0C748-308E-4243-B2B7-D0498196D76E}.Debug|x64.Build.0 = Debug|x64 + {F3C0C748-308E-4243-B2B7-D0498196D76E}.Debug|x86.ActiveCfg = Debug|Win32 + {F3C0C748-308E-4243-B2B7-D0498196D76E}.Debug|x86.Build.0 = Debug|Win32 + {F3C0C748-308E-4243-B2B7-D0498196D76E}.Release|x64.ActiveCfg = Release|x64 + {F3C0C748-308E-4243-B2B7-D0498196D76E}.Release|x64.Build.0 = Release|x64 + {F3C0C748-308E-4243-B2B7-D0498196D76E}.Release|x86.ActiveCfg = Release|Win32 + {F3C0C748-308E-4243-B2B7-D0498196D76E}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EA572FF9-3472-4D0B-8190-7131BED0F20A} + EndGlobalSection +EndGlobal diff --git a/Brokenithm-Evolved-iOS/Brokenithm-Evolved-iOS.vcxproj b/Brokenithm-Evolved-iOS/Brokenithm-Evolved-iOS.vcxproj new file mode 100644 index 0000000..e8e59eb --- /dev/null +++ b/Brokenithm-Evolved-iOS/Brokenithm-Evolved-iOS.vcxproj @@ -0,0 +1,151 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {F3C0C748-308E-4243-B2B7-D0498196D76E} + BrokenithmEvolvediOS + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + $(VC_ReferencesPath_x64); + + + false + + + false + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)\dep; + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/Brokenithm-Evolved-iOS/Brokenithm-Evolved-iOS.vcxproj.filters b/Brokenithm-Evolved-iOS/Brokenithm-Evolved-iOS.vcxproj.filters new file mode 100644 index 0000000..a7bf3aa --- /dev/null +++ b/Brokenithm-Evolved-iOS/Brokenithm-Evolved-iOS.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + + + 资源文件 + + + \ No newline at end of file diff --git a/Brokenithm-Evolved-iOS/libimobiledevice.lib b/Brokenithm-Evolved-iOS/libimobiledevice.lib new file mode 100644 index 0000000000000000000000000000000000000000..383775a6762324382b3f7377901066d154071937 GIT binary patch literal 70256 zcmeHQd%WC5bw4*ifQSf4Y1*PiMO2Is0(l{(K@kH)qzJU7lx6R|o7{z)-F0_wLa0S+ zDWwz@K@kBF5%Ix8MDPtFD!vdA6%_#$5h)@f55b7o@4R+iXJ&Wc7yoKLpKpG5=bV{y z=FHp-3s2x( zM{3-JCvesZ4d`$d@a|39O~+d<=OJb?@5Xmgm{Wx&txCYX?68HpuOF-5q zfUA%{iF@z_u0C1=dA}O?1U|jD#-(@ypV?L8LOg-b&eb>%PvCPq zYg~XQ@cBg=SKtX;gYuC;-MR+2c8SJ~cmiKIMB`>Wf$LUiT#G00#bp|w#}l}IFAecG z@TGk;#NWV|5ntkZJb|wuKN45s3EZ%o#)t6)z6$*$K>I52HKZ?bIiA4R=V`zeUkAQ{ z-xA>c2JlV%mbeH{;6~U-;v77IZ*8w}8lJ#STWGuyPvF~|YMh9tz!M5LpGqX~9q>z> zgr~p;gyOJJVN7p zcmh8*xcogv^kk+HX?~osf6Y&&y zLgBF!h$LW($AHH>8js@%{2sgl8(<#^q_qL~!wwpk;t4#lx5k(81pc^84w3)ul0s2k-R63?@dTdP z(YOy!VC$~NLwEwu!f%NO@dUPMX&}Gb0NWzI1mtb|c&&E8YY%zdp@-G>d-dyIb?50+bGk9vSlgUvP_1_G;VW0hob;xURWTm6;_!nHs_nP$Vf!L#b4{mK zUo}yim~J*&{o1N-qe0>Ch^y6D=Q4?(91l`!uc=M7XL^lVz1wZ{`dUm7InBqWx~|!u zs`VOOk@-Y|97~i|uV3%>O+v0pKEcMDY)?N+_J-r6Y)v)rptLQt>WQwDW@20YX4 ziQ}Yr$s&IR9PLh{WjW-pfTP=}Pg)N7E8yrg8jckCE8yrirl)Nh@>j^wooP+f`%Z@X zCM4io*KN9N>Zj#d-RRd;?X5LitJ+d(7?$L&9oJaT#gO5CENM|sf(@~pYwE`}YLm@w zW1`>gs-%OUfOoptQnr+A@|Wch#t%{pf?VD;?X`_sr{15EIqEj-ZOh1>R$CpgC*Jw?0 zsmSnbEYz7bYfyJmu?O@_D*al0;<(zH_9SZ?QCSA`d@9}5Yk578f}mw%H(G0(-F9n@ zcw0?1j;}RZ6VND;u|CK=ds>F~R$wXt_jd5ul%>@xB1vH6>v&Pccf#XXlMRvmTCd-2 zwpM#q^(k>oWjHRTPth@(_0_F*uiu>Lq54nP*ZZwIOC6Ge%y23Jr@g0G`~sOAjV-0q z>UMi_d_8J-l#HRIV!mOffq_A@-EFLHqBz#0>fwJTp#2{{;El$BGUB#GBSB)fB zV{BHRMh_L`S|#dprBduRz>PtklM0g}$CXY|7A~8LqNHN>re^w+?R70C>VTAtJKbn> zxQH@b#gcEzxFIBhQ*lJ?j-%K*AJhEGK8zm8HOB9?XSx%Oo+~^g4U1bduQf-BAdLZw zN^7ct0rz;LZl(dMi{wKSF@$NN2-aQ^$v4*!awyY`8EiBYlHja)ukk3FPY%-W$)^;WV8Scl@MKz6=tg7rLT0{uqHG5(4qV!CV z&)ZllhL^pW@!mwYIo=ppHVo%t&9qYST#6r4F1wg~$R9pk6r+>9fj(h)9BT@L{%M;5 z5kUvVyfc$cTZsgx4Dk6x|6vrh{jLcSlK?s7txdyJwn>EHI?YzE-|4oGUyot`#FUu0 zHKUM_bG+MLhsl{`)B!x7>TxIP)6?Uan?$h!a+t=%R09*9iF&7w)wX88+33~Q)cX@t zPC7}JC@p7w%_{G%x+P+WauDkSwN>qIZG1+QW)0?U^_#1jjjpSTk}!lnAw?GJ!1!7% zr+heWF0cdX1}7NDAW$QKywafK<)v`l&1_%JY^#mZZg8Y7z@P{pMP+0L%o1yl&rS+1=1Y4AE$#2(~42B-N3N7h7)%i@9v{kS8Hs zH1O&AI9^_nAWI74PS*Q%EQr*5J-j1iuVo|0v?z9ivFoG_4Ea$(u)2!z8P<-m!eB)O zgfO0HAbJ!b>!FPpQZg~+n1GGxj23))Z+&Z`=9SVqu(k)1fLehR_iDI^&MArCotqUqi(Ca35hx7UO{LU-K+AJ zk;7@5v@^PP1J%yjWJ3&oJLqx48g2I8LXJ>F(OyFJY*@tYExbDVc;VStswjls?RB;B z`f8`7(0kg=zKAcCYOjY;4wH%sk7Knv*iVcjIl*C^nO0B-bwJ1mJ2ugT#4e6kW&Lm! zYYir)tL0n78FaFNJiq8`Lw4K$h7`}TQ9Pd-%4>JlJ2AvBhNC7%GFB?MWJtg%I}$Yz z5G&#~LP!YWnHS|ifC&irRJ*dt>ff46?#E*@9d^eK$&Bov<$FM_oN|;*OuWceV^GG% z)wE1(Js^|H@M(A)nUrKslQ;MDjtWM zl72gjMUlaaS}DU(hQw5TkLe|n$@pxEG~K~el#)x#$G64fOCY6&&y~^# z8|CQY92s)&K2DS8D@xTj@Q5P(NF&SBrLE37j3CP6Pe^gbhf#_SEfHIEijJ94IvCVP z>9AaGiegn|rnA7?3sk9aluS%p1%rrT{R_x`wPHp4ESwH{gjHLES2sFvZ3iPMq~=oS z*74?)Jy{rAP`H?42$m4+k&~0%RaNoS9$s2kQB^S69vqWk(g;~N-7#|! zW2;)@_zCew3ymI;<1~_$&LgDbg;mZ(<7=Fu`nAc;JkP<%Hv@VvvI$J{3zLiGk6OLc znQr13mN1`=HtE$m6Pk}Pf+W4OClA#O5#h74X{*g))i6SRJz6HVSpo`dr=lAo6JOMA zU#1L6aANKt`ZaYNiZ`)rEG%0pO|@#|DJ~OnSCe9@DfGdD&=DBH1@&86h^euc6YK@Lqm>BVj{!Fq-l@ux+*vm zz*L+dlZkPkw5FzUePEg%$z9cKHG5O8rF2NdDaRj4C^Uu;v$7nyEZqP=1#q3dRI6m~|2I@9QsD)+9C_SXcXi7#6wGaxZ?*3>)B&Qi~h z9TKDXvOjf{l)qW7fer!pAUuvG7H?dAWDV3~lvc;Qd1bc|{8VY#KvCQMUm=HIyDhID zK8V#Gm#1B8t+v>aQ?F$qfep{b>ZPLfY)(5kf)|O30|#=%a+}l)=k?4kD3s%ZRUGWc zVt1jxUhbfn!||ShhjWaOk|>63LV_Wej(hNePsruSrQ{s2;1hBfa_N}Hhrt>4p7^AE zo{>{i(@t~VYJ{Zy2st^j=NfOyOAR^AW4@uO9=~R~HZ)1gq|(#l9rUKotBVcf`9-}6 z*==14DWV;y&7L$RkRx6WYEgR-#Ri4EdfUNrdixNAU}ryo3kyV&nxdla4L={-#Cgb^_b@O z<-_QaTv6atZCt6qPD7*7s;xuU+Nq=8taVze#YUH_&TwWn{U%N(rIPb#>Db66R&|`* z2~}iVMd4$Lwd+-NT&-$%#h6mgGowUUrYJqpyc~IsCILmql-BG`wfp|v5oP5#JQ+(? zh&VB)M#RLRN(^I&W%tD`BC9IdKfAS%rek||*lI93=J)GyBH!7nBD2|M`a_n9Pfy(C z3!{rLmRs7)SIDuKCb;iZld>D;r|i5q4YL#E^P1kqFq+>im;ZVTqWDBVzU;gVzx<); z>wDAf)tHZk7aMvhLOPx_BoocCCPNJheJBSb->-7^?I-@}i#i#z+#<@kDuW(QG+!RKJ{tb1?Evk$90!V4B}A z1unAB!K5T>ycbi3JOxiDOO2ej;F(42C(2A@M{6= ziaYV=1KXVmUSI>zdMEDm14q6Kz7c>GxF>%DuBfvK25S;>S z0FFNw_uhg2dAMH=oc3O#Ip@Qd3b4cb;L8M%(u;2sml>scj z2tFr(gFgu01;EtBNE7IP2v493{{;^K$9@EN^nuPtaYr8LUxIL;i+k|*0jEzy?`ax!UqL#$QR&C0$6b!d~N{Cz6jqO zz+Ttm3GDMFJb@Lsw|_mb_g7#iV7D7kcEEzK;y19@*I+MT-q)cAFz*`(2j+bfzE*&_ zH=qO5?u9)b;lc@M*;z|N1L zOo6$Nf)5bR8cqbB08V%edH|irl~0Bfe-C{&fDhQ=4@d{t`w7$$VA&txw*^@8BcjdrK`vd+ggOFin-46UVgbUdx6 z6X;**jr4DHBE5;;O#e=Aq5q(h=s)RX`Y$?#{+mvv|Dn_9t@Ji}JId=FbOxPC@1%Fp zS@do?o8Cj`(7ALTy_e3X_t6FPe!7r8Ko`*m>03j5jx|M!FKcpYgZS-Tho$jDJ=_mA4`Wf9tKc~Ct7jzH(lI}(0xQ~8C z_tUTG0s0L+NWZ0r=wW(<9z}J2j2@@o(+2tjJwbn@Ckd5uY;0`S*d}9}j%_wJdu;Qu zEylJSn=|(Rwc-D3gRKplV0Q9!e4eOL&qy9jB36w2)V7#+(M(Oe^rXp2Sa3fDKO%|_YlB8Jt`DiM=r|7#Nm7H2^c3d5ldm2b3ZEldeJ_ORdGWWVabYkd* zoDnbjtK?-Pj~9SaL|Zg*M6OI6E|W!b2R{-KFa)<}?G2~@5*vZM3UylBqI5UK@zn5ToJoAYrhzPa4WUlrD&;xJac5*kF6 z2j1*$Z#H?sBi^65&z+?Eg~JFjy}sEpOs3?Nlu1Uvxb6LFKQc1O8=~}Xw4bcgAsa=U zQH0!5^&4qS-K%`w5bieyr=waSEu7nSV%^<`z9%;2J_xv?0Am)tlG<36SP!cih> zfFUf9xfz^@<=A16Q{9o6TeIR)Zz8r~af>UJ%m|W15yY2o6SBDu%U)U34z6U|VQ*Rb z_d0CE5ih)kN{x7XHH?N#uy<86eC`23tG1I6n_Y)qa9uQ1V`kVzP!+-6){5Ur5zW>M zj-=i!qGhYAoCyJ<=BSsv(%>>#+#EuZZ4DvC%b2btmM3>vE>J?&I@RyUt8oF@?-&OXM!evr6XULL ziSv-S#+KoDDi_f*$vL*<^kEIkF&5nfbM)b=t`fGL54yF0Z+OlQL~U5A7O|(?&InX2@+W5plX0p6unE zTmou#lDkUePhHdrTce_kEiC2U-{JHuy?qm>VK(P^vl{9!t72@Z4y7>y2DZ%IiWwoE zo|sEHX4vbR4Laa8iBq@AicB3FaF`=+j8tcyb4P=5Qd$M;Kg3N& zjy#6l1z{qLdXpm=HLL|nk&&-pMCm@2n-y^)(K4+vr&KP{+q$%L<&|7dI&_!c&r(Krd&AJA`(d;RpuxaHFUk7<{+Rz|vRmt^F-GrQj zwQ(hjiPknTjcY>=m#|U(~`5T)qAGM~azI&rL%iVyQTeTsWdH|q8oB5NT>!qYhG ztJU>S;kv5&6sH`S^SORvQ7>So<^B*W2<2M0VR0&_cjA+&f$o9O*u)H#wXw?=Xw8sV z)m=U%!<;iqaL51QI5oA)Z>!{9BKPM3HTf04Ik}AcGb}ArF!<+|*DbdzGR>Vj9ib4Lf1Zr-T{?34z zWjh)%9{9zuM_dJVxKK02rH#Q}KSPpk`(@*a_xIyqVc0m-@5&syQQYk2r%8i-e7jNZ zmUI*<6o~?TJuKNY;V8s^Jy^1AjNaC_rwp_6F7;u;1C?A3(V?QuBB$>{_@KpmN=S-X z#4p$F3 z+UjzMh9XH$9S@+e-w5h1sbcF%qeeFm$zvVdO(7&@KiNAzD zL>r>_ufqWAkl9j#J!_W``dWq*cAwhDaX8ePBukQe(<~+0m9|{gRk0JMccSgapI-iV z9jm%sm}S(VqQtmBRaNbdbHrm;3@pjrz*W1<4$ZpmwSmFTvL!f;RvL??$foL3tLJIt#Vir%YbY2Gd^%i;O~Wf`O;xUJT}92|?c8>>=xcK!yvK$4>BgxP_O z*t`PF?7F5RayfAH!^+Up@M$?r_b731cQsPkIr$RNL=AKF7L_gZ$`_l;Y%MxntV%c_ za7HpLx*JJ&K{V8apF^`->PuCl$jBL^H@IYCh&;P{qdrTtE9#QXmZlsua0J@|^md;% zS=urfL8#qNFS&s|a{Hdy7!;iQU{g<)Ul=H?5r)|j`+#DH#5PEehz9}AC^raGgXuwF>{3b9?E!sREOHiy`t{VIiyY?n<^pDKSB|4W6yrdM-HCIe3*)<9f1JHB zFTZiP%y1kWd_u9KD9O;E&VH5B*$D+q`l&F)OX_yugsQ#~*N@ft&g2-zIo0r}@`uzC}719u^=A z@(iB{Ursw+2PX~ixv-`9N!xQ-eGxr-o6SLlXAk*rYdC5+x3%4CoA~TXuf3|j(~A#% z$xbT|IQSq<_a0l}m(WN6o^kx1w}i;NYP z!v%;4nKB_Vze=L!*-P+%#qun)AtL-G;y?XQq($%=VgJp7{|Casi>Gr-eT4dHD#wVm zX~Dv!np4!KS+X`=4?UIsd~Fi>aQ`{AX-^X_YSZQBhklCMB+}h@wPchMe-1RL)nvPl zilV$V?m2%i$9}3c!WB%`ewo&|P@77&=3C7V{ajAVO>5lCkVLD8>l*K$;M;h19>vDH zK%eUC>cYj^)H@wBhe)*O$&*Fz_d=QbP2Ix?a>U2>3g!LnB3|mwkUEB*NbITW*O+)) zu|iAx_$AI;!_Da{AXE6k@nxouU9id&TVQd*0!yIHCb2f$;SN@jQmZUV=&>90*woj< zA0JdBJy9m2*WXM_509y^f{X3HFp+Oj17~Z=a&bl-hGB)4+IrzazSh40GBpEs>PonpL1N9@{H2P&*w8-nerr5MKaCMBIvJQggUg9 zC)1p_sz`38y*$&Et4?*XLQC7rqD=3wwU#L++V0UYR&a3*UX*AxFN2kz#Y>h4)T)s_ z7(Oy(yp1DW_D}K{Ts3kR4aT|tSm4FT^|o4WaM+F&Tw2b#esMcj?sT(NRlk_a>$9~? z(LFim2CKxI=wU%V$@E5u^J-=?Jx4nl5xEp|$2;T*88MvFy>G2REXo^yAUz%GGw{{%mq`AX%#D3I^p6R1Z1;>7$$Ecm`y$WL7$)Q7X}9apEoZa@c0Kj5ccP(cE@nRVnT{a=Pr!>SC^@IBlALffVbK z>qX}$bdgP`D*1_byBL4(!O9=p4`K_Ww3g=HVGDTq@)8m&yxjVUQG}TJ>;K|}WU-OEHz#?7Dp;yRZiVUPo(|bX zhvJ%_%lkf@T>qF(CABWMhxQ6jhxEk0)ZV%I(lQ~_z4AD;vKLFw>4c58DwNtjzl}pcz(O(%#7ZtDKHJ#je>s73LbA`5= z{O3+=><9Vg;;6Z(TaDCQfAi{CYIq%(Rid=@<>t%#^Ex<(Ls=Cnt$nZIbr3B8H=8Sx zpBZhh;N@puJjG>@*asHpRu0I@uXx0h=nKUT?SZ@=>6cJ>El5~FoSHevksjSQXDdNz z8RYgZSGv;erS@v%W^DdiM{am?o)unh^Gv^ga3tNmpI?pqg^8J-*wcHRBR{=3S6t2+ zdmrLRbk0CXR|D1LH&@I4K9H^*8nA*(bG{ z-jQ0}Xf8L3I?RzM_NQG35Ui1lTT^b{a=4H_@U>vvOjIN{Q@TfZa#q}X1-X1%pTOgg}s@iH#E*co?hp8Gpa&2uYrHAs?z$#E`|J=G(GbLYnN#X|J<>inV8;Jeg zV^i`Y$5pH;ign4IJU`CU#k$9;MsltdO#70J6Rt|EpPTKifn4j1Y2f6C&2Vw8OU%2( z9%jpvJ9II>yp$7fSTXKvbFwQNZ{*I5b`p}+oWyaBR!zAl=3`>_{tcWaV#K39_Ek;! zCtAHYo7nZ_yYAJrm$zyxkf{YdUjxUN94ETC?k8r1VimFPNe&&>RU$nz+L-aAJL^jo z_V>B>&Dxaw^ny=u>(8BFSQp8czHQtpSk-!dV*Vv=Kpr1yq5TMQ#b2EN+?!^-FWGo2 ztVV94){C2$CwOv|Pee{=aZAheGXEOMR6Xs$@gk={v9)t+3~%%_a2(%M(!=J;`QJRr z*^Q#|94FSx#mT4>1G%oJO3vJ+<()g3@Fq`odQ+%WW^Nww=0Ik5ZF8c5Rb712qS=94 zoJ!wknI7fe13d)BS@EUyEVm;1HdlIfA+}g*VvZub)4bi4svRw}SuL(rxtYo7 zLMrDOxx)RB+!< ztC413cX`svm!3X4dCqG)Oj&;_}Gd#X2{m!3a&HSeM)!O6F!*KL3|{lBKe6G1+hnUaU@?}`7ocNU==7WgPeDp5ApJonJ<=| z$@_;BvK#Wl5xntB<>yA9AK~STPRRXoM~cWeMpcbce-yK4yY2{ka#mQWjfeNn(_@9C}?bOfP*sJ*QBqopP%eACL8seU<(=4c}!I zTO>Ctx-zAK`62{cD5W;Ytr31A)F8bDRh;wO-1I6=F8@`aN^FqpudZfw$sA@YwnXl| z^+{H`X{y4({d6NWj4rJSxz_oqfgbX7!LY9=RZ}X7-a_okemd00eyXV&*@+b-u|N13 zUUvHRSzIG>qqxuV(vz>x(pr#f3!e*QyPvjV&0cBFKhI0AEa$nN@ETvX{z_LhdCv8O z*9LMk-vVQmDK7m?oBKkjOA}|kGRFamWoOP;UdPH#7JYHO%bl?LA}f1ij2Lq@@Oobh z{e?ER(2H}QtAStg<;qo@#CPCWWlC#7?rr$xSQqYNbCu|kyJzziUyo6~Xjh3&xs%T~ zggU8Di&Y~xGqe9HE4OAot5=Eq+$i~Lq5SXzfR$*F^JMXLUxNzA$hmj%H)5%IqZjuI zxqb9+2GYeLDSk>++WvFr;ckRf`{l*-fU8($Vzei|cJVDwW_53zT-n~_$=n!knw<1+ zE9vcV@!7eC`U<695a5frxMt;6r*2M5@A2YGOFOqN^BpBU{v>B5y-03ce~XeV?kt4g z{j5ZGZdL5Nkj;OAv--V~#fcH7I4AMFVR|H+Uuhl4S>yXjE!^*o^G z_w`y(@>8{L-I#(pE0Ri)G}xt{dL&_u6O`5)q~Msi|>TiivtospdEIEt;G z+iSjqkv!xQTDkm03lU$wxzm*|W@?#BIHhHs8x8)%lbgGOQz|ugyY;88)L~aq%I%!F zYxlEQa+Q`&^v2>O>0Pd5{W)p2K^5mWSH3^@rB*nz%$ubMcWmng0=GNElWo2)SSb zucB8|A2R2-?u#|@KE2K=P~7fw@3UVeG(g#;Hl2#)FV2i+?q}q)pOI%xQQSTf{jT`N z$FF@o`zRy`}e*b=!p`2#|}^9B2%okO|wOwaTiUV5^7D7AcU7W5!5dxY+xREykc zfZqmM^y|kpYPLZ5g^A)a$hC!sga%lU5w|f->Ek$MySrZ8py}csjUw`@6x$**zJ8d| zq}!X+G-6t$qz4x2pd;M{?D({@j}OV~*VH(WLS^o+w}8NAB@h z>PDE&=e(o--q9dEGSYZZSC^~hHF($deZH9nb;JVLcEw?JZ~CC(=QDbzz1!9=~&pXnyL z_EJ0KMw&Dhv;v$(?9{U2%k!UUg=3Jvu7Sn6UZ){ms)JW-^2Ju1`$Rhst#DRC`k$v2 jZjzAx=Wd0YhI;(jTH$61$s3~;=FWJ`4)sXCg68}m!q|z( literal 0 HcmV?d00001 diff --git a/Brokenithm-Evolved-iOS/main.cpp b/Brokenithm-Evolved-iOS/main.cpp new file mode 100644 index 0000000..e364a58 --- /dev/null +++ b/Brokenithm-Evolved-iOS/main.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +using namespace std; + +#include + +#pragma comment(lib, "libimobiledevice.lib") + +void device_event_callback(const idevice_event_t* event, void* user_data); + +int main(int argc, char** argv) +{ + idevice_error_t status; + status = idevice_event_subscribe(device_event_callback, NULL); + if (status) { + printf("Subscribe for device failed\n"); + } + while (_getch() != 'q') {} + return 0; +} + +map device_map; +void device_event_callback(const idevice_event_t* event, void* user_data) +{ + idevice_error_t status; + bool isAdd = event->event == IDEVICE_DEVICE_ADD; + printf("device %s\tudid: %s\n", isAdd ? "add" : "remove", event->udid); + if (isAdd) { + string udid = event->udid; + //idevice_t* device = (idevice_t*)malloc(sizeof(idevice_t)); + idevice_t* device = new idevice_t; + device_map[udid] = device; + status = idevice_new(device, udid.c_str()); + if (status) { + printf("Create device failed\n"); + device_map.erase(udid); + delete device; + } + } + else { + string udid = event->udid; + idevice_t* device = device_map[udid]; + if (device) { + device_map.erase(udid); + status = idevice_free(*device); + if (status) { + printf("Free device failed\n"); + } + delete device; + } + } +} \ No newline at end of file diff --git a/dep/libimobiledevice/afc.h b/dep/libimobiledevice/afc.h new file mode 100644 index 0000000..13cffd4 --- /dev/null +++ b/dep/libimobiledevice/afc.h @@ -0,0 +1,375 @@ +/** + * @file libimobiledevice/afc.h + * @brief Access the filesystem on the device. + * \internal + * + * Copyright (c) 2010-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2009-2010 Nikias Bassen All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IAFC_H +#define IAFC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define AFC_SERVICE_NAME "com.apple.afc" + +/** Error Codes */ +typedef enum { + AFC_E_SUCCESS = 0, + AFC_E_UNKNOWN_ERROR = 1, + AFC_E_OP_HEADER_INVALID = 2, + AFC_E_NO_RESOURCES = 3, + AFC_E_READ_ERROR = 4, + AFC_E_WRITE_ERROR = 5, + AFC_E_UNKNOWN_PACKET_TYPE = 6, + AFC_E_INVALID_ARG = 7, + AFC_E_OBJECT_NOT_FOUND = 8, + AFC_E_OBJECT_IS_DIR = 9, + AFC_E_PERM_DENIED = 10, + AFC_E_SERVICE_NOT_CONNECTED = 11, + AFC_E_OP_TIMEOUT = 12, + AFC_E_TOO_MUCH_DATA = 13, + AFC_E_END_OF_DATA = 14, + AFC_E_OP_NOT_SUPPORTED = 15, + AFC_E_OBJECT_EXISTS = 16, + AFC_E_OBJECT_BUSY = 17, + AFC_E_NO_SPACE_LEFT = 18, + AFC_E_OP_WOULD_BLOCK = 19, + AFC_E_IO_ERROR = 20, + AFC_E_OP_INTERRUPTED = 21, + AFC_E_OP_IN_PROGRESS = 22, + AFC_E_INTERNAL_ERROR = 23, + AFC_E_MUX_ERROR = 30, + AFC_E_NO_MEM = 31, + AFC_E_NOT_ENOUGH_DATA = 32, + AFC_E_DIR_NOT_EMPTY = 33, + AFC_E_FORCE_SIGNED_TYPE = -1 +} afc_error_t; + +/** Flags for afc_file_open */ +typedef enum { + AFC_FOPEN_RDONLY = 0x00000001, /**< r O_RDONLY */ + AFC_FOPEN_RW = 0x00000002, /**< r+ O_RDWR | O_CREAT */ + AFC_FOPEN_WRONLY = 0x00000003, /**< w O_WRONLY | O_CREAT | O_TRUNC */ + AFC_FOPEN_WR = 0x00000004, /**< w+ O_RDWR | O_CREAT | O_TRUNC */ + AFC_FOPEN_APPEND = 0x00000005, /**< a O_WRONLY | O_APPEND | O_CREAT */ + AFC_FOPEN_RDAPPEND = 0x00000006 /**< a+ O_RDWR | O_APPEND | O_CREAT */ +} afc_file_mode_t; + +/** Type of link for afc_make_link() calls */ +typedef enum { + AFC_HARDLINK = 1, + AFC_SYMLINK = 2 +} afc_link_type_t; + +/** Lock operation flags */ +typedef enum { + AFC_LOCK_SH = 1 | 4, /**< shared lock */ + AFC_LOCK_EX = 2 | 4, /**< exclusive lock */ + AFC_LOCK_UN = 8 | 4 /**< unlock */ +} afc_lock_op_t; + +typedef struct afc_client_private afc_client_private; +typedef afc_client_private *afc_client_t; /**< The client handle. */ + +/* Interface */ + +/** + * Makes a connection to the AFC service on the device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will be set to a newly allocated afc_client_t + * upon successful return. + * + * @return AFC_E_SUCCESS on success, AFC_E_INVALID_ARG if device or service is + * invalid, AFC_E_MUX_ERROR if the connection cannot be established, + * or AFC_E_NO_MEM if there is a memory allocation problem. + */ +afc_error_t afc_client_new(idevice_t device, lockdownd_service_descriptor_t service, afc_client_t *client); + +/** + * Starts a new AFC service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated afc_client_t upon + * successful return. Must be freed using afc_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return AFC_E_SUCCESS on success, or an AFC_E_* error code otherwise. + */ +afc_error_t afc_client_start_service(idevice_t device, afc_client_t* client, const char* label); + +/** + * Frees up an AFC client. If the connection was created by the client itself, + * the connection will be closed. + * + * @param client The client to free. + */ +afc_error_t afc_client_free(afc_client_t client); + +/** + * Get device information for a connected client. The device information + * returned is the device model as well as the free space, the total capacity + * and blocksize on the accessed disk partition. + * + * @param client The client to get device info for. + * @param device_information A char list of device information terminated by an + * empty string or NULL if there was an error. Free with + * afc_dictionary_free(). + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_get_device_info(afc_client_t client, char ***device_information); + +/** + * Gets a directory listing of the directory requested. + * + * @param client The client to get a directory listing from. + * @param path The directory for listing. (must be a fully-qualified path) + * @param directory_information A char list of files in the directory + * terminated by an empty string or NULL if there was an error. Free with + * afc_dictionary_free(). + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_read_directory(afc_client_t client, const char *path, char ***directory_information); + +/** + * Gets information about a specific file. + * + * @param client The client to use to get the information of the file. + * @param path The fully-qualified path to the file. + * @param file_information Pointer to a buffer that will be filled with a + * NULL-terminated list of strings with the file information. Set to NULL + * before calling this function. Free with afc_dictionary_free(). + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_get_file_info(afc_client_t client, const char *filename, char ***file_information); + +/** + * Opens a file on the device. + * + * @param client The client to use to open the file. + * @param filename The file to open. (must be a fully-qualified path) + * @param file_mode The mode to use to open the file. + * @param handle Pointer to a uint64_t that will hold the handle of the file + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_file_open(afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle); + +/** + * Closes a file on the device. + * + * @param client The client to close the file with. + * @param handle File handle of a previously opened file. + */ +afc_error_t afc_file_close(afc_client_t client, uint64_t handle); + +/** + * Locks or unlocks a file on the device. + * + * Makes use of flock on the device. + * @see http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/flock.2.html + * + * @param client The client to lock the file with. + * @param handle File handle of a previously opened file. + * @param operation the lock or unlock operation to perform, this is one of + * AFC_LOCK_SH (shared lock), AFC_LOCK_EX (exclusive lock), or + * AFC_LOCK_UN (unlock). + */ +afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation); + +/** + * Attempts to the read the given number of bytes from the given file. + * + * @param client The relevant AFC client + * @param handle File handle of a previously opened file + * @param data The pointer to the memory region to store the read data + * @param length The number of bytes to read + * @param bytes_read The number of bytes actually read. + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read); + +/** + * Writes a given number of bytes to a file. + * + * @param client The client to use to write to the file. + * @param handle File handle of previously opened file. + * @param data The data to write to the file. + * @param length How much data to write. + * @param bytes_written The number of bytes actually written to the file. + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t length, uint32_t *bytes_written); + +/** + * Seeks to a given position of a pre-opened file on the device. + * + * @param client The client to use to seek to the position. + * @param handle File handle of a previously opened. + * @param offset Seek offset. + * @param whence Seeking direction, one of SEEK_SET, SEEK_CUR, or SEEK_END. + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence); + +/** + * Returns current position in a pre-opened file on the device. + * + * @param client The client to use. + * @param handle File handle of a previously opened file. + * @param position Position in bytes of indicator + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position); + +/** + * Sets the size of a file on the device. + * + * @param client The client to use to set the file size. + * @param handle File handle of a previously opened file. + * @param newsize The size to set the file to. + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + * + * @note This function is more akin to ftruncate than truncate, and truncate + * calls would have to open the file before calling this, sadly. + */ +afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize); + +/** + * Deletes a file or directory. + * + * @param client The client to use. + * @param path The path to delete. (must be a fully-qualified path) + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_remove_path(afc_client_t client, const char *path); + +/** + * Renames a file or directory on the device. + * + * @param client The client to have rename. + * @param from The name to rename from. (must be a fully-qualified path) + * @param to The new name. (must also be a fully-qualified path) + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to); + +/** + * Creates a directory on the device. + * + * @param client The client to use to make a directory. + * @param path The directory's path. (must be a fully-qualified path, I assume + * all other mkdir restrictions apply as well) + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_make_directory(afc_client_t client, const char *path); + +/** + * Sets the size of a file on the device without prior opening it. + * + * @param client The client to use to set the file size. + * @param path The path of the file to be truncated. + * @param newsize The size to set the file to. + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize); + +/** + * Creates a hard link or symbolic link on the device. + * + * @param client The client to use for making a link + * @param linktype 1 = hard link, 2 = symlink + * @param target The file to be linked. + * @param linkname The name of link. + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname); + +/** + * Sets the modification time of a file on the device. + * + * @param client The client to use to set the file size. + * @param path Path of the file for which the modification time should be set. + * @param mtime The modification time to set in nanoseconds since epoch. + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mtime); + +/** + * Deletes a file or directory including possible contents. + * + * @param client The client to use. + * @param path The path to delete. (must be a fully-qualified path) + * @since libimobiledevice 1.1.7 + * @note Only available in iOS 6 and later. + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_remove_path_and_contents(afc_client_t client, const char *path); + +/* Helper functions */ + +/** + * Get a specific key of the device info list for a client connection. + * Known key values are: Model, FSTotalBytes, FSFreeBytes and FSBlockSize. + * This is a helper function for afc_get_device_info(). + * + * @param client The client to get device info for. + * @param key The key to get the value of. + * @param value The value for the key if successful or NULL otherwise. + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char **value); + +/** + * Frees up a char dictionary as returned by some AFC functions. + * + * @param dictionary The char array terminated by an empty string. + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_dictionary_free(char **dictionary); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/debugserver.h b/dep/libimobiledevice/debugserver.h new file mode 100644 index 0000000..19a4f5d --- /dev/null +++ b/dep/libimobiledevice/debugserver.h @@ -0,0 +1,246 @@ +/** + * @file libimobiledevice/debugserver.h + * @brief Communicate with debugserver on the device. + * \internal + * + * Copyright (c) 2014 Martin Szulecki All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IDEBUGSERVER_H +#define IDEBUGSERVER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define DEBUGSERVER_SERVICE_NAME "com.apple.debugserver" + +/** Error Codes */ +typedef enum { + DEBUGSERVER_E_SUCCESS = 0, + DEBUGSERVER_E_INVALID_ARG = -1, + DEBUGSERVER_E_MUX_ERROR = -2, + DEBUGSERVER_E_SSL_ERROR = -3, + DEBUGSERVER_E_RESPONSE_ERROR = -4, + DEBUGSERVER_E_UNKNOWN_ERROR = -256 +} debugserver_error_t; + +typedef struct debugserver_client_private debugserver_client_private; +typedef debugserver_client_private *debugserver_client_t; /**< The client handle. */ + +typedef struct debugserver_command_private debugserver_command_private; +typedef debugserver_command_private *debugserver_command_t; /**< The command handle. */ + +/* Interface */ + +/** + * Connects to the debugserver service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will point to a newly allocated + * debugserver_client_t upon successful return. Must be freed using + * debugserver_client_free() after use. + * + * @return DEBUGSERVER_E_SUCCESS on success, DEBUGSERVER_E_INVALID_ARG when + * client is NULL, or an DEBUGSERVER_E_* error code otherwise. + */ +debugserver_error_t debugserver_client_new(idevice_t device, lockdownd_service_descriptor_t service, debugserver_client_t * client); + +/** + * Starts a new debugserver service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * debugserver_client_t upon successful return. Must be freed using + * debugserver_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return DEBUGSERVER_E_SUCCESS on success, or an DEBUGSERVER_E_* error + * code otherwise. + */ +debugserver_error_t debugserver_client_start_service(idevice_t device, debugserver_client_t * client, const char* label); + +/** + * Disconnects a debugserver client from the device and frees up the + * debugserver client data. + * + * @param client The debugserver client to disconnect and free. + * + * @return DEBUGSERVER_E_SUCCESS on success, DEBUGSERVER_E_INVALID_ARG when + * client is NULL, or an DEBUGSERVER_E_* error code otherwise. + */ +debugserver_error_t debugserver_client_free(debugserver_client_t client); + +/** + * Sends raw data using the given debugserver service client. + * + * @param client The debugserver client to use for sending + * @param data Data to send + * @param size Size of the data to send + * @param sent Number of bytes sent (can be NULL to ignore) + * + * @return DEBUGSERVER_E_SUCCESS on success, + * DEBUGSERVER_E_INVALID_ARG when one or more parameters are + * invalid, or DEBUGSERVER_E_UNKNOWN_ERROR when an unspecified + * error occurs. + */ +debugserver_error_t debugserver_client_send(debugserver_client_t client, const char* data, uint32_t size, uint32_t *sent); + +/** + * Receives raw data using the given debugserver client with specified timeout. + * + * @param client The debugserver client to use for receiving + * @param data Buffer that will be filled with the data received + * @param size Number of bytes to receive + * @param received Number of bytes received (can be NULL to ignore) + * @param timeout Maximum time in milliseconds to wait for data. + * + * @return DEBUGSERVER_E_SUCCESS on success, + * DEBUGSERVER_E_INVALID_ARG when one or more parameters are + * invalid, DEBUGSERVER_E_MUX_ERROR when a communication error + * occurs, or DEBUGSERVER_E_UNKNOWN_ERROR when an unspecified + * error occurs. + */ +debugserver_error_t debugserver_client_receive_with_timeout(debugserver_client_t client, char *data, uint32_t size, uint32_t *received, unsigned int timeout); + +/** + * Receives raw data from the debugserver service. + * + * @param client The debugserver client + * @param data Buffer that will be filled with the data received + * @param size Number of bytes to receive + * @param received Number of bytes received (can be NULL to ignore) + * @note The default read timeout is 10 seconds. + * + * @return DEBUGSERVER_E_SUCCESS on success, + * DEBUGSERVER_E_INVALID_ARG when client or plist is NULL + */ +debugserver_error_t debugserver_client_receive(debugserver_client_t client, char *data, uint32_t size, uint32_t *received); + +/** + * Sends a command to the debugserver service. + * + * @param client The debugserver client + * @param command Command to process and send + * @param response Response received for the command (can be NULL to ignore) + * + * @return DEBUGSERVER_E_SUCCESS on success, + * DEBUGSERVER_E_INVALID_ARG when client or command is NULL + */ +debugserver_error_t debugserver_client_send_command(debugserver_client_t client, debugserver_command_t command, char** response); + +/** + * Receives and parses response of debugserver service. + * + * @param client The debugserver client + * @param response Response received for last command (can be NULL to ignore) + * + * @return DEBUGSERVER_E_SUCCESS on success, + * DEBUGSERVER_E_INVALID_ARG when client is NULL + */ +debugserver_error_t debugserver_client_receive_response(debugserver_client_t client, char** response); + +/** + * Controls status of ACK mode when sending commands or receiving responses. + * + * @see debugserver_client_send_command, debugserver_client_receive_response + * + * @param client The debugserver client + * @param enabled A boolean flag indicating whether the internal ACK mode + * handling should be enabled or disabled. + * + * @return DEBUGSERVER_E_SUCCESS on success, or an DEBUGSERVER_E_* error + * code otherwise. + */ +debugserver_error_t debugserver_client_set_ack_mode(debugserver_client_t client, int enabled); + +/** + * Sets the argv which launches an app. + * + * @param client The debugserver client + * @param argc Number of arguments + * @param argv Array starting with the executable to be run followed by it's arguments + * @param response Response received for the command (can be NULL to ignore) + * + * @return DEBUGSERVER_E_SUCCESS on success, + * DEBUGSERVER_E_INVALID_ARG when client is NULL + */ +debugserver_error_t debugserver_client_set_argv(debugserver_client_t client, int argc, char* argv[], char** response); + +/** + * Adds or sets an environment variable. + * + * @param client The debugserver client + * @param env The environment variable in "KEY=VALUE" notation + * @param response Response received for the command (can be NULL to ignore) + * + * @return DEBUGSERVER_E_SUCCESS on success, + * DEBUGSERVER_E_INVALID_ARG when client is NULL + */ +debugserver_error_t debugserver_client_set_environment_hex_encoded(debugserver_client_t client, const char* env, char** response); + +/** + * Creates and initializes a new command object. + * + * @param name The name of the command which is sent in plain text + * @param argv Array of tokens for the command ment to be encoded + * @param argc Number of items in the token array + * @param command New command object + * + * @return DEBUGSERVER_E_SUCCESS on success, + * DEBUGSERVER_E_INVALID_ARG when name or command is NULL + */ +debugserver_error_t debugserver_command_new(const char* name, int argc, char* argv[], debugserver_command_t* command); + +/** + * Frees memory of command object. + * + * @param command The command object + * + * @return DEBUGSERVER_E_SUCCESS on success, + * DEBUGSERVER_E_INVALID_ARG when command is NULL + */ +debugserver_error_t debugserver_command_free(debugserver_command_t command); + +/** + * Encodes a string into hex notation. + * + * @param buffer String to encode into hex notiation + * @param encoded_buffer The buffer receives a hex encoded string + * @param encoded_length Length of the hex encoded string + */ +void debugserver_encode_string(const char* buffer, char** encoded_buffer, uint32_t* encoded_length); + +/** + * Decodes a hex encoded string. + * + * @param encoded_buffer The buffer with a hex encoded string + * @param encoded_length Length of the encoded buffer + * @param buffer Decoded string to be freed by the caller + */ +void debugserver_decode_string(const char *encoded_buffer, size_t encoded_length, char** buffer); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/diagnostics_relay.h b/dep/libimobiledevice/diagnostics_relay.h new file mode 100644 index 0000000..97ac363 --- /dev/null +++ b/dep/libimobiledevice/diagnostics_relay.h @@ -0,0 +1,185 @@ +/** + * @file libimobiledevice/diagnostics_relay.h + * @brief Request iOS diagnostic information from device. + * \internal + * + * Copyright (c) 2012-2014 Martin Szulecki, All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IDIAGNOSTICS_RELAY_H +#define IDIAGNOSTICS_RELAY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define DIAGNOSTICS_RELAY_SERVICE_NAME "com.apple.mobile.diagnostics_relay" + +/** Error Codes */ +typedef enum { + DIAGNOSTICS_RELAY_E_SUCCESS = 0, + DIAGNOSTICS_RELAY_E_INVALID_ARG = -1, + DIAGNOSTICS_RELAY_E_PLIST_ERROR = -2, + DIAGNOSTICS_RELAY_E_MUX_ERROR = -3, + DIAGNOSTICS_RELAY_E_UNKNOWN_REQUEST = -4, + DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR = -256 +} diagnostics_relay_error_t; + +#define DIAGNOSTICS_RELAY_ACTION_FLAG_WAIT_FOR_DISCONNECT (1 << 1) +#define DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_PASS (1 << 2) +#define DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_FAIL (1 << 3) + +#define DIAGNOSTICS_RELAY_REQUEST_TYPE_ALL "All" +#define DIAGNOSTICS_RELAY_REQUEST_TYPE_WIFI "WiFi" +#define DIAGNOSTICS_RELAY_REQUEST_TYPE_GAS_GAUGE "GasGauge" +#define DIAGNOSTICS_RELAY_REQUEST_TYPE_NAND "NAND" + +typedef struct diagnostics_relay_client_private diagnostics_relay_client_private; +typedef diagnostics_relay_client_private *diagnostics_relay_client_t; /**< The client handle. */ + +/** + * Connects to the diagnostics_relay service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Reference that will point to a newly allocated + * diagnostics_relay_client_t upon successful return. + * + * @return DIAGNOSTICS_RELAY_E_SUCCESS on success, + * DIAGNOSTICS_RELAY_E_INVALID_ARG when one of the parameters is invalid, + * or DIAGNOSTICS_RELAY_E_MUX_ERROR when the connection failed. + */ +diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, diagnostics_relay_client_t *client); + +/** + * Starts a new diagnostics_relay service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * diagnostics_relay_client_t upon successful return. Must be freed using + * diagnostics_relay_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return DIAGNOSTICS_RELAY_E_SUCCESS on success, or an DIAGNOSTICS_RELAY_E_* error + * code otherwise. + */ +diagnostics_relay_error_t diagnostics_relay_client_start_service(idevice_t device, diagnostics_relay_client_t* client, const char* label); + +/** + * Disconnects a diagnostics_relay client from the device and frees up the + * diagnostics_relay client data. + * + * @param client The diagnostics_relay client to disconnect and free. + * + * @return DIAGNOSTICS_RELAY_E_SUCCESS on success, + * DIAGNOSTICS_RELAY_E_INVALID_ARG when one of client or client->parent + * is invalid, or DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR when the was an + * error freeing the parent property_list_service client. + */ +diagnostics_relay_error_t diagnostics_relay_client_free(diagnostics_relay_client_t client); + + +/** + * Sends the Goodbye request signaling the end of communication. + * + * @param client The diagnostics_relay client + * + * @return DIAGNOSTICS_RELAY_E_SUCCESS on success, + * DIAGNOSTICS_RELAY_E_INVALID_ARG when client is NULL, + * DIAGNOSTICS_RELAY_E_PLIST_ERROR if the device did not acknowledge the + * request + */ +diagnostics_relay_error_t diagnostics_relay_goodbye(diagnostics_relay_client_t client); + +/** + * Puts the device into deep sleep mode and disconnects from host. + * + * @param client The diagnostics_relay client + * + * @return DIAGNOSTICS_RELAY_E_SUCCESS on success, + * DIAGNOSTICS_RELAY_E_INVALID_ARG when client is NULL, + * DIAGNOSTICS_RELAY_E_PLIST_ERROR if the device did not acknowledge the + * request + */ +diagnostics_relay_error_t diagnostics_relay_sleep(diagnostics_relay_client_t client); + +/** + * Restart the device and optionally show a user notification. + * + * @param client The diagnostics_relay client + * @param flags A binary flag combination of + * DIAGNOSTICS_RELAY_ACTION_FLAG_WAIT_FOR_DISCONNECT to wait until + * diagnostics_relay_client_free() disconnects before execution and + * DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_FAIL to show a "FAIL" dialog + * or DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_PASS to show an "OK" dialog + * + * @return DIAGNOSTICS_RELAY_E_SUCCESS on success, + * DIAGNOSTICS_RELAY_E_INVALID_ARG when client is NULL, + * DIAGNOSTICS_RELAY_E_PLIST_ERROR if the device did not acknowledge the + * request + */ +diagnostics_relay_error_t diagnostics_relay_restart(diagnostics_relay_client_t client, int flags); + +/** + * Shutdown of the device and optionally show a user notification. + * + * @param client The diagnostics_relay client + * @param flags A binary flag combination of + * DIAGNOSTICS_RELAY_ACTION_FLAG_WAIT_FOR_DISCONNECT to wait until + * diagnostics_relay_client_free() disconnects before execution and + * DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_FAIL to show a "FAIL" dialog + * or DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_PASS to show an "OK" dialog + * + * @return DIAGNOSTICS_RELAY_E_SUCCESS on success, + * DIAGNOSTICS_RELAY_E_INVALID_ARG when client is NULL, + * DIAGNOSTICS_RELAY_E_PLIST_ERROR if the device did not acknowledge the + * request + */ +diagnostics_relay_error_t diagnostics_relay_shutdown(diagnostics_relay_client_t client, int flags); + +/** + * Shutdown of the device and optionally show a user notification. + * + * @param client The diagnostics_relay client + * @param flags A binary flag combination of + * DIAGNOSTICS_RELAY_ACTION_FLAG_WAIT_FOR_DISCONNECT to wait until + * diagnostics_relay_client_free() disconnects before execution and + * DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_FAIL to show a "FAIL" dialog + * or DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_PASS to show an "OK" dialog + * + * @return DIAGNOSTICS_RELAY_E_SUCCESS on success, + * DIAGNOSTICS_RELAY_E_INVALID_ARG when client is NULL, + * DIAGNOSTICS_RELAY_E_PLIST_ERROR if the device did not acknowledge the + * request + */ +diagnostics_relay_error_t diagnostics_relay_request_diagnostics(diagnostics_relay_client_t client, const char* type, plist_t* diagnostics); + +diagnostics_relay_error_t diagnostics_relay_query_mobilegestalt(diagnostics_relay_client_t client, plist_t keys, plist_t* result); + +diagnostics_relay_error_t diagnostics_relay_query_ioregistry_entry(diagnostics_relay_client_t client, const char* name, const char* class, plist_t* result); + +diagnostics_relay_error_t diagnostics_relay_query_ioregistry_plane(diagnostics_relay_client_t client, const char* plane, plist_t* result); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/file_relay.h b/dep/libimobiledevice/file_relay.h new file mode 100644 index 0000000..e41bb2d --- /dev/null +++ b/dep/libimobiledevice/file_relay.h @@ -0,0 +1,165 @@ +/** + * @file libimobiledevice/file_relay.h + * @brief Retrieve compressed CPIO archives. + * \internal + * + * Copyright (c) 2010-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2014 Aaron Burghardt All Rights Reserved. + * Copyright (c) 2010 Nikias Bassen All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IFILE_RELAY_H +#define IFILE_RELAY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define FILE_RELAY_SERVICE_NAME "com.apple.mobile.file_relay" + +/** Error Codes */ +typedef enum { + FILE_RELAY_E_SUCCESS = 0, + FILE_RELAY_E_INVALID_ARG = -1, + FILE_RELAY_E_PLIST_ERROR = -2, + FILE_RELAY_E_MUX_ERROR = -3, + FILE_RELAY_E_INVALID_SOURCE = -4, + FILE_RELAY_E_STAGING_EMPTY = -5, + FILE_RELAY_E_PERMISSION_DENIED = -6, + FILE_RELAY_E_UNKNOWN_ERROR = -256 +} file_relay_error_t; + +typedef struct file_relay_client_private file_relay_client_private; +typedef file_relay_client_private *file_relay_client_t; /**< The client handle. */ + +/** + * Connects to the file_relay service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Reference that will point to a newly allocated + * file_relay_client_t upon successful return. + * + * @return FILE_RELAY_E_SUCCESS on success, + * FILE_RELAY_E_INVALID_ARG when one of the parameters is invalid, + * or FILE_RELAY_E_MUX_ERROR when the connection failed. + */ +file_relay_error_t file_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, file_relay_client_t *client); + +/** + * Starts a new file_relay service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * file_relay_client_t upon successful return. Must be freed using + * file_relay_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return FILE_RELAY_E_SUCCESS on success, or an FILE_RELAY_E_* error + * code otherwise. + */ +file_relay_error_t file_relay_client_start_service(idevice_t device, file_relay_client_t* client, const char* label); + +/** + * Disconnects a file_relay client from the device and frees up the file_relay + * client data. + * + * @param client The file_relay client to disconnect and free. + * + * @return FILE_RELAY_E_SUCCESS on success, + * FILE_RELAY_E_INVALID_ARG when one of client or client->parent + * is invalid, or FILE_RELAY_E_UNKNOWN_ERROR when the was an error + * freeing the parent property_list_service client. + */ +file_relay_error_t file_relay_client_free(file_relay_client_t client); + + +/** + * Request data for the given sources. + * + * @param client The connected file_relay client. + * @param sources A NULL-terminated list of sources to retrieve. + * Valid sources are: + * - AppleSupport + * - Network + * - VPN + * - WiFi + * - UserDatabases + * - CrashReporter + * - tmp + * - SystemConfiguration + * @param connection The connection that has to be used for receiving the + * data using idevice_connection_receive(). The connection will be closed + * automatically by the device, but use file_relay_client_free() to clean + * up properly. + * @param timeout Maximum time in milliseconds to wait for data. + * + * @note WARNING: Don't call this function without reading the data afterwards. + * A directory mobile_file_relay.XXXX used for creating the archive will + * remain in the /tmp directory otherwise. + * + * @return FILE_RELAY_E_SUCCESS on succes, FILE_RELAY_E_INVALID_ARG when one or + * more parameters are invalid, FILE_RELAY_E_MUX_ERROR if a communication + * error occurs, FILE_RELAY_E_PLIST_ERROR when the received result is NULL + * or is not a valid plist, FILE_RELAY_E_INVALID_SOURCE if one or more + * sources are invalid, FILE_RELAY_E_STAGING_EMPTY if no data is available + * for the given sources, or FILE_RELAY_E_UNKNOWN_ERROR otherwise. + */ +file_relay_error_t file_relay_request_sources(file_relay_client_t client, const char **sources, idevice_connection_t *connection); + +/** + * Request data for the given sources. Calls file_relay_request_sources_timeout() with + * a timeout of 60000 milliseconds (60 seconds). + * + * @param client The connected file_relay client. + * @param sources A NULL-terminated list of sources to retrieve. + * Valid sources are: + * - AppleSupport + * - Network + * - VPN + * - WiFi + * - UserDatabases + * - CrashReporter + * - tmp + * - SystemConfiguration + * @param connection The connection that has to be used for receiving the + * data using idevice_connection_receive(). The connection will be closed + * automatically by the device, but use file_relay_client_free() to clean + * up properly. + * + * @note WARNING: Don't call this function without reading the data afterwards. + * A directory mobile_file_relay.XXXX used for creating the archive will + * remain in the /tmp directory otherwise. + * + * @return FILE_RELAY_E_SUCCESS on succes, FILE_RELAY_E_INVALID_ARG when one or + * more parameters are invalid, FILE_RELAY_E_MUX_ERROR if a communication + * error occurs, FILE_RELAY_E_PLIST_ERROR when the received result is NULL + * or is not a valid plist, FILE_RELAY_E_INVALID_SOURCE if one or more + * sources are invalid, FILE_RELAY_E_STAGING_EMPTY if no data is available + * for the given sources, or FILE_RELAY_E_UNKNOWN_ERROR otherwise. + */ +file_relay_error_t file_relay_request_sources_timeout(file_relay_client_t client, const char **sources, idevice_connection_t *connection, unsigned int timeout); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/heartbeat.h b/dep/libimobiledevice/heartbeat.h new file mode 100644 index 0000000..00734b5 --- /dev/null +++ b/dep/libimobiledevice/heartbeat.h @@ -0,0 +1,132 @@ +/** + * @file libimobiledevice/heartbeat.h + * @brief Send "heartbeat" to device to allow service connections over network. + * \internal + * + * Copyright (c) 2013-2014 Martin Szulecki All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IHEARTBEAT_H +#define IHEARTBEAT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define HEARTBEAT_SERVICE_NAME "com.apple.mobile.heartbeat" + +/** Error Codes */ +typedef enum { + HEARTBEAT_E_SUCCESS = 0, + HEARTBEAT_E_INVALID_ARG = -1, + HEARTBEAT_E_PLIST_ERROR = -2, + HEARTBEAT_E_MUX_ERROR = -3, + HEARTBEAT_E_SSL_ERROR = -4, + HEARTBEAT_E_UNKNOWN_ERROR = -256 +} heartbeat_error_t; + +typedef struct heartbeat_client_private heartbeat_client_private; +typedef heartbeat_client_private *heartbeat_client_t; /**< The client handle. */ + +/** + * Connects to the heartbeat service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will point to a newly allocated + * heartbeat_client_t upon successful return. Must be freed using + * heartbeat_client_free() after use. + * + * @return HEARTBEAT_E_SUCCESS on success, HEARTBEAT_E_INVALID_ARG when + * client is NULL, or an HEARTBEAT_E_* error code otherwise. + */ +heartbeat_error_t heartbeat_client_new(idevice_t device, lockdownd_service_descriptor_t service, heartbeat_client_t * client); + +/** + * Starts a new heartbeat service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * heartbeat_client_t upon successful return. Must be freed using + * heartbeat_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return HEARTBEAT_E_SUCCESS on success, or an HEARTBEAT_E_* error + * code otherwise. + */ +heartbeat_error_t heartbeat_client_start_service(idevice_t device, heartbeat_client_t * client, const char* label); + +/** + * Disconnects a heartbeat client from the device and frees up the + * heartbeat client data. + * + * @param client The heartbeat client to disconnect and free. + * + * @return HEARTBEAT_E_SUCCESS on success, HEARTBEAT_E_INVALID_ARG when + * client is NULL, or an HEARTBEAT_E_* error code otherwise. + */ +heartbeat_error_t heartbeat_client_free(heartbeat_client_t client); + + +/** + * Sends a plist to the service. + * + * @param client The heartbeat client + * @param plist The plist to send + * + * @return HEARTBEAT_E_SUCCESS on success, + * HEARTBEAT_E_INVALID_ARG when client or plist is NULL + */ +heartbeat_error_t heartbeat_send(heartbeat_client_t client, plist_t plist); + +/** + * Receives a plist from the service. + * + * @param client The heartbeat client + * @param plist The plist to store the received data + * + * @return HEARTBEAT_E_SUCCESS on success, + * HEARTBEAT_E_INVALID_ARG when client or plist is NULL + */ +heartbeat_error_t heartbeat_receive(heartbeat_client_t client, plist_t * plist); + +/** + * Receives a plist using the given heartbeat client. + * + * @param client The heartbeat client to use for receiving + * @param plist pointer to a plist_t that will point to the received plist + * upon successful return + * @param timeout Maximum time in milliseconds to wait for data. + * + * @return HEARTBEAT_E_SUCCESS on success, + * HEARTBEAT_E_INVALID_ARG when client or *plist is NULL, + * HEARTBEAT_E_PLIST_ERROR when the received data cannot be + * converted to a plist, HEARTBEAT_E_MUX_ERROR when a + * communication error occurs, or HEARTBEAT_E_UNKNOWN_ERROR + * when an unspecified error occurs. + */ +heartbeat_error_t heartbeat_receive_with_timeout(heartbeat_client_t client, plist_t * plist, uint32_t timeout_ms); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/house_arrest.h b/dep/libimobiledevice/house_arrest.h new file mode 100644 index 0000000..31b6401 --- /dev/null +++ b/dep/libimobiledevice/house_arrest.h @@ -0,0 +1,179 @@ +/** + * @file libimobiledevice/house_arrest.h + * @brief Access app folders and their contents. + * \internal + * + * Copyright (c) 2013-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2010 Nikias Bassen, All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IHOUSE_ARREST_H +#define IHOUSE_ARREST_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#define HOUSE_ARREST_SERVICE_NAME "com.apple.mobile.house_arrest" + +/** Error Codes */ +typedef enum { + HOUSE_ARREST_E_SUCCESS = 0, + HOUSE_ARREST_E_INVALID_ARG = -1, + HOUSE_ARREST_E_PLIST_ERROR = -2, + HOUSE_ARREST_E_CONN_FAILED = -3, + HOUSE_ARREST_E_INVALID_MODE = -4, + HOUSE_ARREST_E_UNKNOWN_ERROR = -256 +} house_arrest_error_t; + +typedef struct house_arrest_client_private house_arrest_client_private; +typedef house_arrest_client_private *house_arrest_client_t; /**< The client handle. */ + +/* Interface */ + +/** + * Connects to the house_arrest service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will point to a newly allocated + * housearrest_client_t upon successful return. + * + * @return HOUSE_ARREST_E_SUCCESS on success, HOUSE_ARREST_E_INVALID_ARG when + * client is NULL, or an HOUSE_ARREST_E_* error code otherwise. + */ +house_arrest_error_t house_arrest_client_new(idevice_t device, lockdownd_service_descriptor_t service, house_arrest_client_t *client); + +/** + * Starts a new house_arrest service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * house_arrest_client_t upon successful return. Must be freed using + * house_arrest_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return HOUSE_ARREST_E_SUCCESS on success, or an HOUSE_ARREST_E_* error + * code otherwise. + */ +house_arrest_error_t house_arrest_client_start_service(idevice_t device, house_arrest_client_t* client, const char* label); + +/** + * Disconnects an house_arrest client from the device and frees up the + * house_arrest client data. + * + * @note After using afc_client_new_from_house_arrest_client(), make sure + * you call afc_client_free() before calling this function to ensure + * a proper cleanup. Do not call this function if you still need to + * perform AFC operations since it will close the connection. + * + * @param client The house_arrest client to disconnect and free. + * + * @return HOUSE_ARREST_E_SUCCESS on success, HOUSE_ARREST_E_INVALID_ARG when + * client is NULL, or an HOUSE_ARREST_E_* error code otherwise. + */ +house_arrest_error_t house_arrest_client_free(house_arrest_client_t client); + + +/** + * Sends a generic request to the connected house_arrest service. + * + * @param client The house_arrest client to use. + * @param dict The request to send as a plist of type PLIST_DICT. + * + * @note If this function returns HOUSE_ARREST_E_SUCCESS it does not mean + * that the request was successful. To check for success or failure you + * need to call house_arrest_get_result(). + * @see house_arrest_get_result + * + * @return HOUSE_ARREST_E_SUCCESS if the request was successfully sent, + * HOUSE_ARREST_E_INVALID_ARG if client or dict is invalid, + * HOUSE_ARREST_E_PLIST_ERROR if dict is not a plist of type PLIST_DICT, + * HOUSE_ARREST_E_INVALID_MODE if the client is not in the correct mode, + * or HOUSE_ARREST_E_CONN_FAILED if a connection error occured. + */ +house_arrest_error_t house_arrest_send_request(house_arrest_client_t client, plist_t dict); + +/** + * Send a command to the connected house_arrest service. + * Calls house_arrest_send_request() internally. + * + * @param client The house_arrest client to use. + * @param command The command to send. Currently, only VendContainer and + * VendDocuments are known. + * @param appid The application identifier to pass along with the . + * + * @note If this function returns HOUSE_ARREST_E_SUCCESS it does not mean + * that the command was successful. To check for success or failure you + * need to call house_arrest_get_result(). + * @see house_arrest_get_result + * + * @return HOUSE_ARREST_E_SUCCESS if the command was successfully sent, + * HOUSE_ARREST_E_INVALID_ARG if client, command, or appid is invalid, + * HOUSE_ARREST_E_INVALID_MODE if the client is not in the correct mode, + * or HOUSE_ARREST_E_CONN_FAILED if a connection error occured. + */ +house_arrest_error_t house_arrest_send_command(house_arrest_client_t client, const char *command, const char *appid); + +/** + * Retrieves the result of a previously sent house_arrest_request_* request. + * + * @param client The house_arrest client to use + * @param dict Pointer that will be set to a plist containing the result to + * the last performed operation. It holds a key 'Status' with the value + * 'Complete' on success or a key 'Error' with an error description as + * value. The caller is responsible for freeing the returned plist. + * + * @return HOUSE_ARREST_E_SUCCESS if a result plist was retrieved, + * HOUSE_ARREST_E_INVALID_ARG if client is invalid, + * HOUSE_ARREST_E_INVALID_MODE if the client is not in the correct mode, + * or HOUSE_ARREST_E_CONN_FAILED if a connection error occured. + */ +house_arrest_error_t house_arrest_get_result(house_arrest_client_t client, plist_t *dict); + + +/** + * Creates an AFC client using the given house_arrest client's connection + * allowing file access to a specific application directory requested by + * functions like house_arrest_request_vendor_documents(). + * + * @param client The house_arrest client to use. + * @param afc_client Pointer that will be set to a newly allocated afc_client_t + * upon successful return. + * + * @note After calling this function the house_arrest client will go in an + * AFC mode that will only allow calling house_arrest_client_free(). + * Only call house_arrest_client_free() if all AFC operations have + * completed since it will close the connection. + * + * @return AFC_E_SUCCESS if the afc client was successfully created, + * AFC_E_INVALID_ARG if client is invalid or was already used to create + * an afc client, or an AFC_E_* error code returned by + * afc_client_new_with_service_client(). + */ +afc_error_t afc_client_new_from_house_arrest_client(house_arrest_client_t client, afc_client_t *afc_client); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/installation_proxy.h b/dep/libimobiledevice/installation_proxy.h new file mode 100644 index 0000000..bc23f9d --- /dev/null +++ b/dep/libimobiledevice/installation_proxy.h @@ -0,0 +1,504 @@ +/** + * @file libimobiledevice/installation_proxy.h + * @brief Manage applications on a device. + * \internal + * + * Copyright (c) 2010-2015 Martin Szulecki All Rights Reserved. + * Copyright (c) 2014 Christophe Fergeau All Rights Reserved. + * Copyright (c) 2009-2012 Nikias Bassen All Rights Reserved. + * Copyright (c) 2010 Bryan Forbes All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IINSTALLATION_PROXY_H +#define IINSTALLATION_PROXY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define INSTPROXY_SERVICE_NAME "com.apple.mobile.installation_proxy" + +/** Error Codes */ +typedef enum { + /* custom */ + INSTPROXY_E_SUCCESS = 0, + INSTPROXY_E_INVALID_ARG = -1, + INSTPROXY_E_PLIST_ERROR = -2, + INSTPROXY_E_CONN_FAILED = -3, + INSTPROXY_E_OP_IN_PROGRESS = -4, + INSTPROXY_E_OP_FAILED = -5, + INSTPROXY_E_RECEIVE_TIMEOUT = -6, + /* native */ + INSTPROXY_E_ALREADY_ARCHIVED = -7, + INSTPROXY_E_API_INTERNAL_ERROR = -8, + INSTPROXY_E_APPLICATION_ALREADY_INSTALLED = -9, + INSTPROXY_E_APPLICATION_MOVE_FAILED = -10, + INSTPROXY_E_APPLICATION_SINF_CAPTURE_FAILED = -11, + INSTPROXY_E_APPLICATION_SANDBOX_FAILED = -12, + INSTPROXY_E_APPLICATION_VERIFICATION_FAILED = -13, + INSTPROXY_E_ARCHIVE_DESTRUCTION_FAILED = -14, + INSTPROXY_E_BUNDLE_VERIFICATION_FAILED = -15, + INSTPROXY_E_CARRIER_BUNDLE_COPY_FAILED = -16, + INSTPROXY_E_CARRIER_BUNDLE_DIRECTORY_CREATION_FAILED = -17, + INSTPROXY_E_CARRIER_BUNDLE_MISSING_SUPPORTED_SIMS = -18, + INSTPROXY_E_COMM_CENTER_NOTIFICATION_FAILED = -19, + INSTPROXY_E_CONTAINER_CREATION_FAILED = -20, + INSTPROXY_E_CONTAINER_P0WN_FAILED = -21, + INSTPROXY_E_CONTAINER_REMOVAL_FAILED = -22, + INSTPROXY_E_EMBEDDED_PROFILE_INSTALL_FAILED = -23, + INSTPROXY_E_EXECUTABLE_TWIDDLE_FAILED = -24, + INSTPROXY_E_EXISTENCE_CHECK_FAILED = -25, + INSTPROXY_E_INSTALL_MAP_UPDATE_FAILED = -26, + INSTPROXY_E_MANIFEST_CAPTURE_FAILED = -27, + INSTPROXY_E_MAP_GENERATION_FAILED = -28, + INSTPROXY_E_MISSING_BUNDLE_EXECUTABLE = -29, + INSTPROXY_E_MISSING_BUNDLE_IDENTIFIER = -30, + INSTPROXY_E_MISSING_BUNDLE_PATH = -31, + INSTPROXY_E_MISSING_CONTAINER = -32, + INSTPROXY_E_NOTIFICATION_FAILED = -33, + INSTPROXY_E_PACKAGE_EXTRACTION_FAILED = -34, + INSTPROXY_E_PACKAGE_INSPECTION_FAILED = -35, + INSTPROXY_E_PACKAGE_MOVE_FAILED = -36, + INSTPROXY_E_PATH_CONVERSION_FAILED = -37, + INSTPROXY_E_RESTORE_CONTAINER_FAILED = -38, + INSTPROXY_E_SEATBELT_PROFILE_REMOVAL_FAILED = -39, + INSTPROXY_E_STAGE_CREATION_FAILED = -40, + INSTPROXY_E_SYMLINK_FAILED = -41, + INSTPROXY_E_UNKNOWN_COMMAND = -42, + INSTPROXY_E_ITUNES_ARTWORK_CAPTURE_FAILED = -43, + INSTPROXY_E_ITUNES_METADATA_CAPTURE_FAILED = -44, + INSTPROXY_E_DEVICE_OS_VERSION_TOO_LOW = -45, + INSTPROXY_E_DEVICE_FAMILY_NOT_SUPPORTED = -46, + INSTPROXY_E_PACKAGE_PATCH_FAILED = -47, + INSTPROXY_E_INCORRECT_ARCHITECTURE = -48, + INSTPROXY_E_PLUGIN_COPY_FAILED = -49, + INSTPROXY_E_BREADCRUMB_FAILED = -50, + INSTPROXY_E_BREADCRUMB_UNLOCK_FAILED = -51, + INSTPROXY_E_GEOJSON_CAPTURE_FAILED = -52, + INSTPROXY_E_NEWSSTAND_ARTWORK_CAPTURE_FAILED = -53, + INSTPROXY_E_MISSING_COMMAND = -54, + INSTPROXY_E_NOT_ENTITLED = -55, + INSTPROXY_E_MISSING_PACKAGE_PATH = -56, + INSTPROXY_E_MISSING_CONTAINER_PATH = -57, + INSTPROXY_E_MISSING_APPLICATION_IDENTIFIER = -58, + INSTPROXY_E_MISSING_ATTRIBUTE_VALUE = -59, + INSTPROXY_E_LOOKUP_FAILED = -60, + INSTPROXY_E_DICT_CREATION_FAILED = -61, + INSTPROXY_E_INSTALL_PROHIBITED = -62, + INSTPROXY_E_UNINSTALL_PROHIBITED = -63, + INSTPROXY_E_MISSING_BUNDLE_VERSION = -64, + INSTPROXY_E_UNKNOWN_ERROR = -256 +} instproxy_error_t; + +typedef struct instproxy_client_private instproxy_client_private; +typedef instproxy_client_private *instproxy_client_t; /**< The client handle. */ + +/** Reports the status response of the given command */ +typedef void (*instproxy_status_cb_t) (plist_t command, plist_t status, void *user_data); + +/* Interface */ + +/** + * Connects to the installation_proxy service on the specified device. + * + * @param device The device to connect to + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will be set to a newly allocated + * instproxy_client_t upon successful return. + * + * @return INSTPROXY_E_SUCCESS on success, or an INSTPROXY_E_* error value + * when an error occured. + */ +instproxy_error_t instproxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, instproxy_client_t *client); + +/** + * Starts a new installation_proxy service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * instproxy_client_t upon successful return. Must be freed using + * instproxy_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return INSTPROXY_E_SUCCESS on success, or an INSTPROXY_E_* error + * code otherwise. + */ +instproxy_error_t instproxy_client_start_service(idevice_t device, instproxy_client_t * client, const char* label); + +/** + * Disconnects an installation_proxy client from the device and frees up the + * installation_proxy client data. + * + * @param client The installation_proxy client to disconnect and free. + * + * @return INSTPROXY_E_SUCCESS on success + * or INSTPROXY_E_INVALID_ARG if client is NULL. + */ +instproxy_error_t instproxy_client_free(instproxy_client_t client); + +/** + * List installed applications. This function runs synchronously. + * + * @param client The connected installation_proxy client + * @param client_options The client options to use, as PLIST_DICT, or NULL. + * Valid client options include: + * "ApplicationType" -> "System" + * "ApplicationType" -> "User" + * "ApplicationType" -> "Internal" + * "ApplicationType" -> "Any" + * @param result Pointer that will be set to a plist that will hold an array + * of PLIST_DICT holding information about the applications found. + * + * @return INSTPROXY_E_SUCCESS on success or an INSTPROXY_E_* error value if + * an error occured. + */ +instproxy_error_t instproxy_browse(instproxy_client_t client, plist_t client_options, plist_t *result); + +/** + * List pages of installed applications in a callback. + * + * @param client The connected installation_proxy client + * @param client_options The client options to use, as PLIST_DICT, or NULL. + * Valid client options include: + * "ApplicationType" -> "System" + * "ApplicationType" -> "User" + * "ApplicationType" -> "Internal" + * "ApplicationType" -> "Any" + * @param status_cb Callback function to process each page of application + * information. Passing a callback is required. + * @param user_data Callback data passed to status_cb. + * + * @return INSTPROXY_E_SUCCESS on success or an INSTPROXY_E_* error value if + * an error occured. + */ +instproxy_error_t instproxy_browse_with_callback(instproxy_client_t client, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); + +/** + * Lookup information about specific applications from the device. + * + * @param client The connected installation_proxy client + * @param appids An array of bundle identifiers that MUST have a terminating + * NULL entry or NULL to lookup all. + * @param client_options The client options to use, as PLIST_DICT, or NULL. + * Currently there are no known client options, so pass NULL here. + * @param result Pointer that will be set to a plist containing a PLIST_DICT + * holding requested information about the application or NULL on errors. + * + * @return INSTPROXY_E_SUCCESS on success or an INSTPROXY_E_* error value if + * an error occured. + */ +instproxy_error_t instproxy_lookup(instproxy_client_t client, const char** appids, plist_t client_options, plist_t *result); + +/** + * Install an application on the device. + * + * @param client The connected installation_proxy client + * @param pkg_path Path of the installation package (inside the AFC jail) + * @param client_options The client options to use, as PLIST_DICT, or NULL. + * Valid options include: + * "iTunesMetadata" -> PLIST_DATA + * "ApplicationSINF" -> PLIST_DATA + * "PackageType" -> "Developer" + * If PackageType -> Developer is specified, then pkg_path points to + * an .app directory instead of an install package. + * @param status_cb Callback function for progress and status information. If + * NULL is passed, this function will run synchronously. + * @param user_data Callback data passed to status_cb. + * + * @return INSTPROXY_E_SUCCESS on success or an INSTPROXY_E_* error value if + * an error occured. + * + * @note If a callback function is given (async mode), this function returns + * INSTPROXY_E_SUCCESS immediately if the status updater thread has been + * created successfully; any error occuring during the command has to be + * handled inside the specified callback function. + */ +instproxy_error_t instproxy_install(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); + +/** + * Upgrade an application on the device. This function is nearly the same as + * instproxy_install; the difference is that the installation progress on the + * device is faster if the application is already installed. + * + * @param client The connected installation_proxy client + * @param pkg_path Path of the installation package (inside the AFC jail) + * @param client_options The client options to use, as PLIST_DICT, or NULL. + * Valid options include: + * "iTunesMetadata" -> PLIST_DATA + * "ApplicationSINF" -> PLIST_DATA + * "PackageType" -> "Developer" + * If PackageType -> Developer is specified, then pkg_path points to + * an .app directory instead of an install package. + * @param status_cb Callback function for progress and status information. If + * NULL is passed, this function will run synchronously. + * @param user_data Callback data passed to status_cb. + * + * @return INSTPROXY_E_SUCCESS on success or an INSTPROXY_E_* error value if + * an error occured. + * + * @note If a callback function is given (async mode), this function returns + * INSTPROXY_E_SUCCESS immediately if the status updater thread has been + * created successfully; any error occuring during the command has to be + * handled inside the specified callback function. + */ +instproxy_error_t instproxy_upgrade(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); + +/** + * Uninstall an application from the device. + * + * @param client The connected installation proxy client + * @param appid ApplicationIdentifier of the app to uninstall + * @param client_options The client options to use, as PLIST_DICT, or NULL. + * Currently there are no known client options, so pass NULL here. + * @param status_cb Callback function for progress and status information. If + * NULL is passed, this function will run synchronously. + * @param user_data Callback data passed to status_cb. + * + * @return INSTPROXY_E_SUCCESS on success or an INSTPROXY_E_* error value if + * an error occured. + * + * @note If a callback function is given (async mode), this function returns + * INSTPROXY_E_SUCCESS immediately if the status updater thread has been + * created successfully; any error occuring during the command has to be + * handled inside the specified callback function. + */ +instproxy_error_t instproxy_uninstall(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); + +/** + * List archived applications. This function runs synchronously. + * + * @see instproxy_archive + * + * @param client The connected installation_proxy client + * @param client_options The client options to use, as PLIST_DICT, or NULL. + * Currently there are no known client options, so pass NULL here. + * @param result Pointer that will be set to a plist containing a PLIST_DICT + * holding information about the archived applications found. + * + * @return INSTPROXY_E_SUCCESS on success or an INSTPROXY_E_* error value if + * an error occured. + */ +instproxy_error_t instproxy_lookup_archives(instproxy_client_t client, plist_t client_options, plist_t *result); + +/** + * Archive an application on the device. + * This function tells the device to make an archive of the specified + * application. This results in the device creating a ZIP archive in the + * 'ApplicationArchives' directory and uninstalling the application. + * + * @param client The connected installation proxy client + * @param appid ApplicationIdentifier of the app to archive. + * @param client_options The client options to use, as PLIST_DICT, or NULL. + * Valid options include: + * "SkipUninstall" -> Boolean + * "ArchiveType" -> "ApplicationOnly" + * @param status_cb Callback function for progress and status information. If + * NULL is passed, this function will run synchronously. + * @param user_data Callback data passed to status_cb. + * + * @return INSTPROXY_E_SUCCESS on success or an INSTPROXY_E_* error value if + * an error occured. + * + * @note If a callback function is given (async mode), this function returns + * INSTPROXY_E_SUCCESS immediately if the status updater thread has been + * created successfully; any error occuring during the command has to be + * handled inside the specified callback function. + */ +instproxy_error_t instproxy_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); + +/** + * Restore a previously archived application on the device. + * This function is the counterpart to instproxy_archive. + * @see instproxy_archive + * + * @param client The connected installation proxy client + * @param appid ApplicationIdentifier of the app to restore. + * @param client_options The client options to use, as PLIST_DICT, or NULL. + * Valid options include: + * "ArchiveType" -> "DocumentsOnly" + * @param status_cb Callback function for progress and status information. If + * NULL is passed, this function will run synchronously. + * @param user_data Callback data passed to status_cb. + * + * @return INSTPROXY_E_SUCCESS on success or an INSTPROXY_E_* error value if + * an error occured. + * + * @note If a callback function is given (async mode), this function returns + * INSTPROXY_E_SUCCESS immediately if the status updater thread has been + * created successfully; any error occuring during the command has to be + * handled inside the specified callback function. + */ +instproxy_error_t instproxy_restore(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); + +/** + * Removes a previously archived application from the device. + * This function removes the ZIP archive from the 'ApplicationArchives' + * directory. + * + * @param client The connected installation proxy client + * @param appid ApplicationIdentifier of the archived app to remove. + * @param client_options The client options to use, as PLIST_DICT, or NULL. + * Currently there are no known client options, so passing NULL is fine. + * @param status_cb Callback function for progress and status information. If + * NULL is passed, this function will run synchronously. + * @param user_data Callback data passed to status_cb. + * + * @return INSTPROXY_E_SUCCESS on success or an INSTPROXY_E_* error value if + * an error occured. + * + * @note If a callback function is given (async mode), this function returns + * INSTPROXY_E_SUCCESS immediately if the status updater thread has been + * created successfully; any error occuring during the command has to be + * handled inside the specified callback function. + */ +instproxy_error_t instproxy_remove_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); + +/** + * Checks a device for certain capabilities. + * + * @param client The connected installation_proxy client + * @param capabilities An array of char* with capability names that MUST have a + * terminating NULL entry. + * @param client_options The client options to use, as PLIST_DICT, or NULL. + * Currently there are no known client options, so pass NULL here. + * @param result Pointer that will be set to a plist containing a PLIST_DICT + * holding information if the capabilities matched or NULL on errors. + * + * @return INSTPROXY_E_SUCCESS on success or an INSTPROXY_E_* error value if + * an error occured. + */ +instproxy_error_t instproxy_check_capabilities_match(instproxy_client_t client, const char** capabilities, plist_t client_options, plist_t *result); + +/* Helper */ + +/** + * Gets the name from a command dictionary. + * + * @param command The dictionary describing the command. + * @param name Pointer to store the name of the command. + */ +void instproxy_command_get_name(plist_t command, char** name); + +/** + * Gets the name of a status. + * + * @param status The dictionary status response to use. + * @param name Pointer to store the name of the status. + */ +void instproxy_status_get_name(plist_t status, char **name); + +/** + * Gets error name, code and description from a response if available. + * + * @param status The dictionary status response to use. + * @param name Pointer to store the name of an error. + * @param description Pointer to store error description text if available. + * The caller is reponsible for freeing the allocated buffer after use. + * If NULL is passed no description will be returned. + * @param code Pointer to store the returned error code if available. + * If NULL is passed no error code will be returned. + * + * @return INSTPROXY_E_SUCCESS if no error is found or an INSTPROXY_E_* error + * value matching the error that ẃas found in the status. + */ +instproxy_error_t instproxy_status_get_error(plist_t status, char **name, char** description, uint64_t* code); + +/** + * Gets total and current item information from a browse response if available. + * + * @param status The dictionary status response to use. + * @param total Pointer to store the total number of items. + * @param current_index Pointer to store the current index of all browsed items. + * @param current_amount Pointer to store the amount of items in the + * current list. + * @param list Pointer to store a newly allocated plist with items. + * The caller is reponsible for freeing the list after use. + * If NULL is passed no list will be returned. If NULL is returned no + * list was found in the status. + */ +void instproxy_status_get_current_list(plist_t status, uint64_t* total, uint64_t* current_index, uint64_t* current_amount, plist_t* list); + + +/** + * Gets progress in percentage from a status if available. + * + * @param status The dictionary status response to use. + * @param name Pointer to store the progress in percent (0-100) or -1 if not + * progress was found in the status. + */ +void instproxy_status_get_percent_complete(plist_t status, int *percent); + +/** + * Creates a new client_options plist. + * + * @return A new plist_t of type PLIST_DICT. + */ +plist_t instproxy_client_options_new(void); + +/** + * Adds one or more new key:value pairs to the given client_options. + * + * @param client_options The client options to modify. + * @param ... KEY, VALUE, [KEY, VALUE], NULL + * + * @note The keys and values passed are expected to be strings, except for the + * keys "ApplicationSINF", "iTunesMetadata", "ReturnAttributes" which are + * expecting a plist_t node as value and "SkipUninstall" expects int. + */ +void instproxy_client_options_add(plist_t client_options, ...); + +/** + * Adds attributes to the given client_options to filter browse results. + * + * @param client_options The client options to modify. + * @param ... VALUE, VALUE, [VALUE], NULL + * + * @note The values passed are expected to be strings. + */ +void instproxy_client_options_set_return_attributes(plist_t client_options, ...); + +/** + * Frees client_options plist. + * + * @param client_options The client options plist to free. Does nothing if NULL + * is passed. + */ +void instproxy_client_options_free(plist_t client_options); + +/** + * Queries the device for the path of an application. + * + * @param client The connected installation proxy client. + * @param appid ApplicationIdentifier of app to retrieve the path for. + * @param path Pointer to store the device path for the application + * which is set to NULL if it could not be determined. + * + * @return INSTPROXY_E_SUCCESS on success, INSTPROXY_E_OP_FAILED if + * the path could not be determined or an INSTPROXY_E_* error + * value if an error occured. + */ +instproxy_error_t instproxy_client_get_path_for_bundle_identifier(instproxy_client_t client, const char* bundle_id, char** path); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/libimobiledevice.h b/dep/libimobiledevice/libimobiledevice.h new file mode 100644 index 0000000..016cadb --- /dev/null +++ b/dep/libimobiledevice/libimobiledevice.h @@ -0,0 +1,259 @@ +/** + * @file libimobiledevice/libimobiledevice.h + * @brief Device/Connection handling and communication + * \internal + * + * Copyright (c) 2010-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2014 Christophe Fergeau All Rights Reserved. + * Copyright (c) 2008 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IMOBILEDEVICE_H +#define IMOBILEDEVICE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +/** Error Codes */ +typedef enum { + IDEVICE_E_SUCCESS = 0, + IDEVICE_E_INVALID_ARG = -1, + IDEVICE_E_UNKNOWN_ERROR = -2, + IDEVICE_E_NO_DEVICE = -3, + IDEVICE_E_NOT_ENOUGH_DATA = -4, + IDEVICE_E_BAD_HEADER = -5, + IDEVICE_E_SSL_ERROR = -6 +} idevice_error_t; + +typedef struct idevice_private idevice_private; +typedef idevice_private *idevice_t; /**< The device handle. */ + +typedef struct idevice_connection_private idevice_connection_private; +typedef idevice_connection_private *idevice_connection_t; /**< The connection handle. */ + +/* discovery (events/asynchronous) */ +/** The event type for device add or removal */ +enum idevice_event_type { + IDEVICE_DEVICE_ADD = 1, + IDEVICE_DEVICE_REMOVE +}; + +/* event data structure */ +/** Provides information about the occured event. */ +typedef struct { + enum idevice_event_type event; /**< The event type. */ + const char *udid; /**< The device unique id. */ + int conn_type; /**< The connection type. Currently only 1 for usbmuxd. */ +} idevice_event_t; + +/* event callback function prototype */ +/** Callback to notifiy if a device was added or removed. */ +typedef void (*idevice_event_cb_t) (const idevice_event_t *event, void *user_data); + +/* functions */ + +/** + * Set the level of debugging. + * + * @param level Set to 0 for no debug output or 1 to enable debug output. + */ +void idevice_set_debug_level(int level); + +/** + * Register a callback function that will be called when device add/remove + * events occur. + * + * @param callback Callback function to call. + * @param user_data Application-specific data passed as parameter + * to the registered callback function. + * + * @return IDEVICE_E_SUCCESS on success or an error value when an error occured. + */ +idevice_error_t idevice_event_subscribe(idevice_event_cb_t callback, void *user_data); + +/** + * Release the event callback function that has been registered with + * idevice_event_subscribe(). + * + * @return IDEVICE_E_SUCCESS on success or an error value when an error occured. + */ +idevice_error_t idevice_event_unsubscribe(void); + +/* discovery (synchronous) */ + +/** + * Get a list of currently available devices. + * + * @param devices List of udids of devices that are currently available. + * This list is terminated by a NULL pointer. + * @param count Number of devices found. + * + * @return IDEVICE_E_SUCCESS on success or an error value when an error occured. + */ +idevice_error_t idevice_get_device_list(char ***devices, int *count); + +/** + * Free a list of device udids. + * + * @param devices List of udids to free. + * + * @return Always returnes IDEVICE_E_SUCCESS. + */ +idevice_error_t idevice_device_list_free(char **devices); + +/* device structure creation and destruction */ + +/** + * Creates an idevice_t structure for the device specified by udid, + * if the device is available. + * + * @note The resulting idevice_t structure has to be freed with + * idevice_free() if it is no longer used. + * + * @param device Upon calling this function, a pointer to a location of type + * idevice_t. On successful return, this location will be populated. + * @param udid The UDID to match. + * + * @return IDEVICE_E_SUCCESS if ok, otherwise an error code. + */ +idevice_error_t idevice_new(idevice_t *device, const char *udid); + +/** + * Cleans up an idevice structure, then frees the structure itself. + * This is a library-level function; deals directly with the device to tear + * down relations, but otherwise is mostly internal. + * + * @param device idevice_t to free. + */ +idevice_error_t idevice_free(idevice_t device); + +/* connection/disconnection */ + +/** + * Set up a connection to the given device. + * + * @param device The device to connect to. + * @param port The destination port to connect to. + * @param connection Pointer to an idevice_connection_t that will be filled + * with the necessary data of the connection. + * + * @return IDEVICE_E_SUCCESS if ok, otherwise an error code. + */ +idevice_error_t idevice_connect(idevice_t device, uint16_t port, idevice_connection_t *connection); + +/** + * Disconnect from the device and clean up the connection structure. + * + * @param connection The connection to close. + * + * @return IDEVICE_E_SUCCESS if ok, otherwise an error code. + */ +idevice_error_t idevice_disconnect(idevice_connection_t connection); + +/* communication */ + +/** + * Send data to a device via the given connection. + * + * @param connection The connection to send data over. + * @param data Buffer with data to send. + * @param len Size of the buffer to send. + * @param sent_bytes Pointer to an uint32_t that will be filled + * with the number of bytes actually sent. + * + * @return IDEVICE_E_SUCCESS if ok, otherwise an error code. + */ +idevice_error_t idevice_connection_send(idevice_connection_t connection, const char *data, uint32_t len, uint32_t *sent_bytes); + +/** + * Receive data from a device via the given connection. + * This function will return after the given timeout even if no data has been + * received. + * + * @param connection The connection to receive data from. + * @param data Buffer that will be filled with the received data. + * This buffer has to be large enough to hold len bytes. + * @param len Buffer size or number of bytes to receive. + * @param recv_bytes Number of bytes actually received. + * @param timeout Timeout in milliseconds after which this function should + * return even if no data has been received. + * + * @return IDEVICE_E_SUCCESS if ok, otherwise an error code. + */ +idevice_error_t idevice_connection_receive_timeout(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout); + +/** + * Receive data from a device via the given connection. + * This function is like idevice_connection_receive_timeout, but with a + * predefined reasonable timeout. + * + * @param connection The connection to receive data from. + * @param data Buffer that will be filled with the received data. + * This buffer has to be large enough to hold len bytes. + * @param len Buffer size or number of bytes to receive. + * @param recv_bytes Number of bytes actually received. + * + * @return IDEVICE_E_SUCCESS if ok, otherwise an error code. + */ +idevice_error_t idevice_connection_receive(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes); + +/** + * Enables SSL for the given connection. + * + * @param connection The connection to enable SSL for. + * + * @return IDEVICE_E_SUCCESS on success, IDEVICE_E_INVALID_ARG when connection + * is NULL or connection->ssl_data is non-NULL, or IDEVICE_E_SSL_ERROR when + * SSL initialization, setup, or handshake fails. + */ +idevice_error_t idevice_connection_enable_ssl(idevice_connection_t connection); + +/** + * Disable SSL for the given connection. + * + * @param connection The connection to disable SSL for. + * + * @return IDEVICE_E_SUCCESS on success, IDEVICE_E_INVALID_ARG when connection + * is NULL. This function also returns IDEVICE_E_SUCCESS when SSL is not + * enabled and does no further error checking on cleanup. + */ +idevice_error_t idevice_connection_disable_ssl(idevice_connection_t connection); + +/* misc */ + +/** + * Gets the handle of the device. Depends on the connection type. + */ +idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle); + +/** + * Gets the unique id for the device. + */ +idevice_error_t idevice_get_udid(idevice_t device, char **udid); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/dep/libimobiledevice/lockdown.h b/dep/libimobiledevice/lockdown.h new file mode 100644 index 0000000..076fa9d --- /dev/null +++ b/dep/libimobiledevice/lockdown.h @@ -0,0 +1,448 @@ +/** + * @file libimobiledevice/lockdown.h + * @brief Manage device preferences, start services, pairing and activation. + * \internal + * + * Copyright (c) 2009-2014 Martin S. All Rights Reserved. + * Copyright (c) 2014 Koby Boyango All Rights Reserved. + * Copyright (c) 2010 Bryan Forbes All Rights Reserved. + * Copyright (c) 2008 Zach C. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef ILOCKDOWN_H +#define ILOCKDOWN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/** Error Codes */ +typedef enum { + /* custom */ + LOCKDOWN_E_SUCCESS = 0, + LOCKDOWN_E_INVALID_ARG = -1, + LOCKDOWN_E_INVALID_CONF = -2, + LOCKDOWN_E_PLIST_ERROR = -3, + LOCKDOWN_E_PAIRING_FAILED = -4, + LOCKDOWN_E_SSL_ERROR = -5, + LOCKDOWN_E_DICT_ERROR = -6, + LOCKDOWN_E_NOT_ENOUGH_DATA = -7, + LOCKDOWN_E_MUX_ERROR = -8, + LOCKDOWN_E_NO_RUNNING_SESSION = -9, + /* native */ + LOCKDOWN_E_INVALID_RESPONSE = -10, + LOCKDOWN_E_MISSING_KEY = -11, + LOCKDOWN_E_MISSING_VALUE = -12, + LOCKDOWN_E_GET_PROHIBITED = -13, + LOCKDOWN_E_SET_PROHIBITED = -14, + LOCKDOWN_E_REMOVE_PROHIBITED = -15, + LOCKDOWN_E_IMMUTABLE_VALUE = -16, + LOCKDOWN_E_PASSWORD_PROTECTED = -17, + LOCKDOWN_E_USER_DENIED_PAIRING = -18, + LOCKDOWN_E_PAIRING_DIALOG_RESPONSE_PENDING = -19, + LOCKDOWN_E_MISSING_HOST_ID = -20, + LOCKDOWN_E_INVALID_HOST_ID = -21, + LOCKDOWN_E_SESSION_ACTIVE = -22, + LOCKDOWN_E_SESSION_INACTIVE = -23, + LOCKDOWN_E_MISSING_SESSION_ID = -24, + LOCKDOWN_E_INVALID_SESSION_ID = -25, + LOCKDOWN_E_MISSING_SERVICE = -26, + LOCKDOWN_E_INVALID_SERVICE = -27, + LOCKDOWN_E_SERVICE_LIMIT = -28, + LOCKDOWN_E_MISSING_PAIR_RECORD = -29, + LOCKDOWN_E_SAVE_PAIR_RECORD_FAILED = -30, + LOCKDOWN_E_INVALID_PAIR_RECORD = -31, + LOCKDOWN_E_INVALID_ACTIVATION_RECORD = -32, + LOCKDOWN_E_MISSING_ACTIVATION_RECORD = -33, + LOCKDOWN_E_SERVICE_PROHIBITED = -34, + LOCKDOWN_E_ESCROW_LOCKED = -35, + LOCKDOWN_E_UNKNOWN_ERROR = -256 +} lockdownd_error_t; + +typedef struct lockdownd_client_private lockdownd_client_private; +typedef lockdownd_client_private *lockdownd_client_t; /**< The client handle. */ + +struct lockdownd_pair_record { + char *device_certificate; /**< The device certificate */ + char *host_certificate; /**< The host certificate */ + char *root_certificate; /**< The root certificate */ + char *host_id; /**< A unique HostID for the host computer */ + char *system_buid; /**< A unique system id */ +}; +/** A pair record holding device, host and root certificates along the host_id */ +typedef struct lockdownd_pair_record *lockdownd_pair_record_t; + +struct lockdownd_service_descriptor { + uint16_t port; + uint8_t ssl_enabled; +}; +typedef struct lockdownd_service_descriptor *lockdownd_service_descriptor_t; + +/* Interface */ + +/** + * Creates a new lockdownd client for the device. + * + * @note This function does not pair with the device or start a session. This + * has to be done manually by the caller after the client is created. + * The device disconnects automatically if the lockdown connection idles + * for more than 10 seconds. Make sure to call lockdownd_client_free() as soon + * as the connection is no longer needed. + * + * @param device The device to create a lockdownd client for + * @param client The pointer to the location of the new lockdownd_client + * @param label The label to use for communication. Usually the program name. + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL + */ +lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label); + +/** + * Creates a new lockdownd client for the device and starts initial handshake. + * The handshake consists out of query_type, validate_pair, pair and + * start_session calls. It uses the internal pairing record management. + * + * @note The device disconnects automatically if the lockdown connection idles + * for more than 10 seconds. Make sure to call lockdownd_client_free() as soon + * as the connection is no longer needed. + * + * @param device The device to create a lockdownd client for + * @param client The pointer to the location of the new lockdownd_client + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL, + * LOCKDOWN_E_INVALID_CONF if configuration data is wrong + */ +lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label); + +/** + * Closes the lockdownd client session if one is running and frees up the + * lockdownd_client struct. + * + * @param client The lockdown client + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL + */ +lockdownd_error_t lockdownd_client_free(lockdownd_client_t client); + + +/** + * Query the type of the service daemon. Depending on whether the device is + * queried in normal mode or restore mode, different types will be returned. + * + * @param client The lockdownd client + * @param type The type returned by the service daemon. Pass NULL to ignore. + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL + */ +lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type); + +/** + * Retrieves a preferences plist using an optional domain and/or key name. + * + * @param client An initialized lockdownd client. + * @param domain The domain to query on or NULL for global domain + * @param key The key name to request or NULL to query for all keys + * @param value A plist node representing the result value node + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL + */ +lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value); + +/** + * Sets a preferences value using a plist and optional by domain and/or key name. + * + * @param client an initialized lockdownd client. + * @param domain the domain to query on or NULL for global domain + * @param key the key name to set the value or NULL to set a value dict plist + * @param value a plist node of any node type representing the value to set + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client or + * value is NULL + */ +lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value); + +/** + * Removes a preference node by domain and/or key name. + * + * @note: Use with caution as this could remove vital information on the device + * + * @param client An initialized lockdownd client. + * @param domain The domain to query on or NULL for global domain + * @param key The key name to remove or NULL remove all keys for the current domain + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL + */ +lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key); + +/** + * Requests to start a service and retrieve it's port on success. + * + * @param client The lockdownd client + * @param identifier The identifier of the service to start + * @param descriptor The service descriptor on success or NULL on failure + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG if a parameter + * is NULL, LOCKDOWN_E_INVALID_SERVICE if the requested service is not known + * by the device, LOCKDOWN_E_START_SERVICE_FAILED if the service could not be + * started by the device + */ +lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service); + +/** + * Requests to start a service and retrieve it's port on success. + * Sends the escrow bag from the device's pair record. + * + * @param client The lockdownd client + * @param identifier The identifier of the service to start + * @param descriptor The service descriptor on success or NULL on failure + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG if a parameter + * is NULL, LOCKDOWN_E_INVALID_SERVICE if the requested service is not known + * by the device, LOCKDOWN_E_START_SERVICE_FAILED if the service could not because + * started by the device, LOCKDOWN_E_INVALID_CONF if the host id or escrow bag are + * missing from the device record. + */ +lockdownd_error_t lockdownd_start_service_with_escrow_bag(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service); + +/** + * Opens a session with lockdownd and switches to SSL mode if device wants it. + * + * @param client The lockdownd client + * @param host_id The HostID of the computer + * @param session_id The new session_id of the created session + * @param ssl_enabled Whether SSL communication is used in the session + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when a client + * or host_id is NULL, LOCKDOWN_E_PLIST_ERROR if the response plist had errors, + * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the supplied HostID, + * LOCKDOWN_E_SSL_ERROR if enabling SSL communication failed + */ +lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled); + +/** + * Closes the lockdownd session by sending the StopSession request. + * + * @see lockdownd_start_session + * + * @param client The lockdown client + * @param session_id The id of a running session + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL + */ +lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id); + +/** + * Sends a plist to lockdownd. + * + * @note This function is low-level and should only be used if you need to send + * a new type of message. + * + * @param client The lockdownd client + * @param plist The plist to send + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client or + * plist is NULL + */ +lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist); + +/** + * Receives a plist from lockdownd. + * + * @param client The lockdownd client + * @param plist The plist to store the received data + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client or + * plist is NULL + */ +lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist); + +/** + * Pairs the device using the supplied pair record. + * + * @param client The lockdown client + * @param pair_record The pair record to use for pairing. If NULL is passed, then + * the pair records from the current machine are used. New records will be + * generated automatically when pairing is done for the first time. + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL, + * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong, + * LOCKDOWN_E_PAIRING_FAILED if the pairing failed, + * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected, + * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id + */ +lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record); + +/** + * Validates if the device is paired with the given HostID. If successful the + * specified host will become trusted host of the device indicated by the + * lockdownd preference named TrustedHostAttached. Otherwise the host must be + * paired using lockdownd_pair() first. + * + * @param client The lockdown client + * @param pair_record The pair record to validate pairing with. If NULL is + * passed, then the pair record is read from the internal pairing record + * management. + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL, + * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong, + * LOCKDOWN_E_PAIRING_FAILED if the pairing failed, + * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected, + * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id + */ +lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record); + +/** + * Unpairs the device with the given HostID and removes the pairing records + * from the device and host if the internal pairing record management is used. + * + * @param client The lockdown client + * @param pair_record The pair record to use for unpair. If NULL is passed, then + * the pair records from the current machine are used. + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL, + * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong, + * LOCKDOWN_E_PAIRING_FAILED if the pairing failed, + * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected, + * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id + */ +lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_record_t pair_record); + +/** + * Activates the device. Only works within an open session. + * The ActivationRecord plist dictionary must be obtained using the + * activation protocol requesting from Apple's https webservice. + * + * @param client The lockdown client + * @param activation_record The activation record plist dictionary + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client or + * activation_record is NULL, LOCKDOWN_E_NO_RUNNING_SESSION if no session is + * open, LOCKDOWN_E_PLIST_ERROR if the received plist is broken, + * LOCKDOWN_E_ACTIVATION_FAILED if the activation failed, + * LOCKDOWN_E_INVALID_ACTIVATION_RECORD if the device reports that the + * activation_record is invalid + */ +lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record); + +/** + * Deactivates the device, returning it to the locked “Activate with iTunes” + * screen. + * + * @param client The lockdown client + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL, + * LOCKDOWN_E_NO_RUNNING_SESSION if no session is open, + * LOCKDOWN_E_PLIST_ERROR if the received plist is broken + */ +lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client); + +/** + * Tells the device to immediately enter recovery mode. + * + * @param client The lockdown client + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL + */ +lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client); + +/** + * Sends the Goodbye request to lockdownd signaling the end of communication. + * + * @param client The lockdown client + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client + * is NULL, LOCKDOWN_E_PLIST_ERROR if the device did not acknowledge the + * request + */ +lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client); + +/* Helper */ + +/** + * Sets the label to send for requests to lockdownd. + * + * @param client The lockdown client + * @param label The label to set or NULL to disable sending a label + * + */ +void lockdownd_client_set_label(lockdownd_client_t client, const char *label); + +/** + * Returns the unique id of the device from lockdownd. + * + * @param client An initialized lockdownd client. + * @param udid Holds the unique id of the device. The caller is responsible + * for freeing the memory. + * + * @return LOCKDOWN_E_SUCCESS on success + */ +lockdownd_error_t lockdownd_get_device_udid(lockdownd_client_t control, char **udid); + +/** + * Retrieves the name of the device from lockdownd set by the user. + * + * @param client An initialized lockdownd client. + * @param device_name Holds the name of the device. The caller is + * responsible for freeing the memory. + * + * @return LOCKDOWN_E_SUCCESS on success + */ +lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name); + +/** + * Calculates and returns the data classes the device supports from lockdownd. + * + * @param client An initialized lockdownd client. + * @param classes A pointer to store an array of class names. The caller is responsible + * for freeing the memory which can be done using mobilesync_data_classes_free(). + * @param count The number of items in the classes array. + * + * @return LOCKDOWN_E_SUCCESS on success, + * LOCKDOWN_E_INVALID_ARG when client is NULL, + * LOCKDOWN_E_NO_RUNNING_SESSION if no session is open, + * LOCKDOWN_E_PLIST_ERROR if the received plist is broken + */ +lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd_client_t client, char ***classes, int *count); + +/** + * Frees memory of an allocated array of data classes as returned by lockdownd_get_sync_data_classes() + * + * @param classes An array of class names to free. + * + * @return LOCKDOWN_E_SUCCESS on success + */ +lockdownd_error_t lockdownd_data_classes_free(char **classes); + +/** + * Frees memory of a service descriptor as returned by lockdownd_start_service() + * + * @param sevice A service descriptor instance to free. + * + * @return LOCKDOWN_E_SUCCESS on success + */ +lockdownd_error_t lockdownd_service_descriptor_free(lockdownd_service_descriptor_t service); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/misagent.h b/dep/libimobiledevice/misagent.h new file mode 100644 index 0000000..92165f2 --- /dev/null +++ b/dep/libimobiledevice/misagent.h @@ -0,0 +1,145 @@ +/** + * @file libimobiledevice/misagent.h + * @brief Manage provisioning profiles. + * \internal + * + * Copyright (c) 2013-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2012 Nikias Bassen All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IMISAGENT_H +#define IMISAGENT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define MISAGENT_SERVICE_NAME "com.apple.misagent" + +/** Error Codes */ +typedef enum { + MISAGENT_E_SUCCESS = 0, + MISAGENT_E_INVALID_ARG = -1, + MISAGENT_E_PLIST_ERROR = -2, + MISAGENT_E_CONN_FAILED = -3, + MISAGENT_E_REQUEST_FAILED = -4, + MISAGENT_E_UNKNOWN_ERROR = -256 +} misagent_error_t; + +typedef struct misagent_client_private misagent_client_private; +typedef misagent_client_private *misagent_client_t; /**< The client handle. */ + +/* Interface */ + +/** + * Connects to the misagent service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will point to a newly allocated + * misagent_client_t upon successful return. + * + * @return MISAGENT_E_SUCCESS on success, MISAGENT_E_INVALID_ARG when + * client is NULL, or an MISAGENT_E_* error code otherwise. + */ +misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t service, misagent_client_t *client); + +/** + * Starts a new misagent service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * misagent_client_t upon successful return. Must be freed using + * misagent_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return MISAGENT_E_SUCCESS on success, or an MISAGENT_E_* error + * code otherwise. + */ +misagent_error_t misagent_client_start_service(idevice_t device, misagent_client_t* client, const char* label); + +/** + * Disconnects an misagent client from the device and frees up the + * misagent client data. + * + * @param client The misagent client to disconnect and free. + * + * @return MISAGENT_E_SUCCESS on success, MISAGENT_E_INVALID_ARG when + * client is NULL, or an MISAGENT_E_* error code otherwise. + */ +misagent_error_t misagent_client_free(misagent_client_t client); + + +/** + * Installs the given provisioning profile. Only works with valid profiles. + * + * @param client The connected misagent to use for installation + * @param profile The valid provisioning profile to install. This has to be + * passed as a PLIST_DATA, otherwise the function will fail. + * + * @return MISAGENT_E_SUCCESS on success, MISAGENT_E_INVALID_ARG when + * client is invalid, or an MISAGENT_E_* error code otherwise. + */ +misagent_error_t misagent_install(misagent_client_t client, plist_t profile); + +/** + * Retrieves an array of all installed provisioning profiles. + * + * @param client The connected misagent to use. + * @param profiles Pointer to a plist_t that will be set to a PLIST_ARRAY + * if the function is successful. + * + * @return MISAGENT_E_SUCCESS on success, MISAGENT_E_INVALID_ARG when + * client is invalid, or an MISAGENT_E_* error code otherwise. + * + * @note If no provisioning profiles are installed on the device, this function + * still returns MISAGENT_E_SUCCESS and profiles will just point to an + * empty array. + */ +misagent_error_t misagent_copy(misagent_client_t client, plist_t* profiles); + +/** + * Removes a given provisioning profile. + * + * @param client The connected misagent to use. + * @param profileID Identifier of the provisioning profile to remove. + * This is a UUID that can be obtained from the provisioning profile data. + * @see misagent_copy + * + * @return MISAGENT_E_SUCCESS on success, MISAGENT_E_INVALID_ARG when + * client is invalid, or an MISAGENT_E_* error code otherwise. + */ +misagent_error_t misagent_remove(misagent_client_t client, const char* profileID); + +/** + * Retrieves the status code from the last operation. + * + * @param client The misagent to use. + * + * @return -1 if client is invalid, or the status code from the last operation + */ +int misagent_get_status_code(misagent_client_t client); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/mobile_image_mounter.h b/dep/libimobiledevice/mobile_image_mounter.h new file mode 100644 index 0000000..8d783c4 --- /dev/null +++ b/dep/libimobiledevice/mobile_image_mounter.h @@ -0,0 +1,170 @@ +/** + * @file libimobiledevice/mobile_image_mounter.h + * @brief Mount developer/debug disk images on the device. + * \internal + * + * Copyright (c) 2010-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2010-2014 Nikias Bassen All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IMOBILE_IMAGE_MOUNTER_H +#define IMOBILE_IMAGE_MOUNTER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define MOBILE_IMAGE_MOUNTER_SERVICE_NAME "com.apple.mobile.mobile_image_mounter" + +/** Error Codes */ +typedef enum { + MOBILE_IMAGE_MOUNTER_E_SUCCESS = 0, + MOBILE_IMAGE_MOUNTER_E_INVALID_ARG = -1, + MOBILE_IMAGE_MOUNTER_E_PLIST_ERROR = -2, + MOBILE_IMAGE_MOUNTER_E_CONN_FAILED = -3, + MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED = -4, + MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR = -256 +} mobile_image_mounter_error_t; + +typedef struct mobile_image_mounter_client_private mobile_image_mounter_client_private; +typedef mobile_image_mounter_client_private *mobile_image_mounter_client_t; /**< The client handle. */ + +/** callback for image upload */ +typedef ssize_t (*mobile_image_mounter_upload_cb_t) (void* buffer, size_t length, void *user_data); + +/* Interface */ + +/** + * Connects to the mobile_image_mounter service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will be set to a newly allocated + * mobile_image_mounter_client_t upon successful return. + * + * @return MOBILE_IMAGE_MOUNTER_E_SUCCESS on success, + * MOBILE_IMAGE_MOUNTER_E_INVALID_ARG if device is NULL, + * or MOBILE_IMAGE_MOUNTER_E_CONN_FAILED if the connection to the + * device could not be established. + */ +mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdownd_service_descriptor_t service, mobile_image_mounter_client_t *client); + +/** + * Starts a new mobile_image_mounter service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * mobile_image_mounter_t upon successful return. Must be freed using + * mobile_image_mounter_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return MOBILE_IMAGE_MOUNTER_E_SUCCESS on success, or an MOBILE_IMAGE_MOUNTER_E_* error + * code otherwise. + */ +mobile_image_mounter_error_t mobile_image_mounter_start_service(idevice_t device, mobile_image_mounter_client_t* client, const char* label); + +/** + * Disconnects a mobile_image_mounter client from the device and frees up the + * mobile_image_mounter client data. + * + * @param client The mobile_image_mounter client to disconnect and free. + * + * @return MOBILE_IMAGE_MOUNTER_E_SUCCESS on success, + * or MOBILE_IMAGE_MOUNTER_E_INVALID_ARG if client is NULL. + */ +mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_client_t client); + + +/** + * Tells if the image of ImageType is already mounted. + * + * @param client The client use + * @param image_type The type of the image to look up + * @param result Pointer to a plist that will receive the result of the + * operation. + * + * @note This function may return MOBILE_IMAGE_MOUNTER_E_SUCCESS even if the + * operation has failed. Check the resulting plist for further information. + * + * @return MOBILE_IMAGE_MOUNTER_E_SUCCESS on success, or an error code on error + */ +mobile_image_mounter_error_t mobile_image_mounter_lookup_image(mobile_image_mounter_client_t client, const char *image_type, plist_t *result); + +/** + * Uploads an image with an optional signature to the device. + * + * @param client The connected mobile_image_mounter client. + * @param image_type Type of image that is being uploaded. + * @param image_size Total size of the image. + * @param signature Buffer with a signature of the image being uploaded. If + * NULL, no signature will be used. + * @param signature_size Total size of the image signature buffer. If 0, no + * signature will be used. + * @param upload_cb Callback function that gets the data chunks for uploading + * the image. + * @param userdata User defined data for the upload callback function. + * + * @return MOBILE_IMAGE_MOUNTER_E_SUCCESS on succes, or a + * MOBILE_IMAGE_MOUNTER_E_* error code otherwise. + */ +mobile_image_mounter_error_t mobile_image_mounter_upload_image(mobile_image_mounter_client_t client, const char *image_type, size_t image_size, const char *signature, uint16_t signature_size, mobile_image_mounter_upload_cb_t upload_cb, void* userdata); + +/** + * Mounts an image on the device. + * + * @param client The connected mobile_image_mounter client. + * @param image_path The absolute path of the image to mount. The image must + * be present before calling this function. + * @param signature Pointer to a buffer holding the images' signature + * @param signature_size Length of the signature image_signature points to + * @param image_type Type of image to mount + * @param result Pointer to a plist that will receive the result of the + * operation. + * + * @note This function may return MOBILE_IMAGE_MOUNTER_E_SUCCESS even if the + * operation has failed. Check the resulting plist for further information. + * Note that there is no unmounting function. The mount persists until the + * device is rebooted. + * + * @return MOBILE_IMAGE_MOUNTER_E_SUCCESS on success, + * MOBILE_IMAGE_MOUNTER_E_INVALID_ARG if on ore more parameters are + * invalid, or another error code otherwise. + */ +mobile_image_mounter_error_t mobile_image_mounter_mount_image(mobile_image_mounter_client_t client, const char *image_path, const char *signature, uint16_t signature_size, const char *image_type, plist_t *result); + +/** + * Hangs up the connection to the mobile_image_mounter service. + * This functions has to be called before freeing up a mobile_image_mounter + * instance. If not, errors appear in the device's syslog. + * + * @param client The client to hang up + * + * @return MOBILE_IMAGE_MOUNTER_E_SUCCESS on success, + * MOBILE_IMAGE_MOUNTER_E_INVALID_ARG if client is invalid, + * or another error code otherwise. + */ +mobile_image_mounter_error_t mobile_image_mounter_hangup(mobile_image_mounter_client_t client); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/mobilebackup.h b/dep/libimobiledevice/mobilebackup.h new file mode 100644 index 0000000..6da3bed --- /dev/null +++ b/dep/libimobiledevice/mobilebackup.h @@ -0,0 +1,242 @@ +/** + * @file libimobiledevice/mobilebackup.h + * @brief Backup and restore of all device data. + * \internal + * + * Copyright (c) 2009-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2010 Nikias Bassen All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IMOBILEBACKUP_H +#define IMOBILEBACKUP_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define MOBILEBACKUP_SERVICE_NAME "com.apple.mobilebackup" + +/** Error Codes */ +typedef enum { + MOBILEBACKUP_E_SUCCESS = 0, + MOBILEBACKUP_E_INVALID_ARG = -1, + MOBILEBACKUP_E_PLIST_ERROR = -2, + MOBILEBACKUP_E_MUX_ERROR = -3, + MOBILEBACKUP_E_BAD_VERSION = -4, + MOBILEBACKUP_E_REPLY_NOT_OK = -5, + MOBILEBACKUP_E_UNKNOWN_ERROR = -256 +} mobilebackup_error_t; + +typedef struct mobilebackup_client_private mobilebackup_client_private; +typedef mobilebackup_client_private *mobilebackup_client_t; /**< The client handle. */ + +typedef enum { + MB_RESTORE_NOTIFY_SPRINGBOARD = 1 << 0, + MB_RESTORE_PRESERVE_SETTINGS = 1 << 1, + MB_RESTORE_PRESERVE_CAMERA_ROLL = 1 << 2 +} mobilebackup_flags_t; + +/** + * Connects to the mobilebackup service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will be set to a newly allocated + * mobilebackup_client_t upon successful return. + * + * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID ARG if one + * or more parameters are invalid, or DEVICE_LINK_SERVICE_E_BAD_VERSION if + * the mobilebackup version on the device is newer. + */ +mobilebackup_error_t mobilebackup_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilebackup_client_t * client); + +/** + * Starts a new mobilebackup service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * mobilebackup_client_t upon successful return. Must be freed using + * mobilebackup_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return MOBILEBACKUP_E_SUCCESS on success, or an MOBILEBACKUP_E_* error + * code otherwise. + */ +mobilebackup_error_t mobilebackup_client_start_service(idevice_t device, mobilebackup_client_t* client, const char* label); + +/** + * Disconnects a mobilebackup client from the device and frees up the + * mobilebackup client data. + * + * @param client The mobilebackup client to disconnect and free. + * + * @return MOBILEBACKUP_E_SUCCESS on success, or MOBILEBACKUP_E_INVALID_ARG + * if client is NULL. + */ +mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client); + + +/** + * Polls the device for mobilebackup data. + * + * @param client The mobilebackup client + * @param plist A pointer to the location where the plist should be stored + * + * @return an error code + */ +mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist_t *plist); + +/** + * Sends mobilebackup data to the device + * + * @note This function is low-level and should only be used if you need to send + * a new type of message. + * + * @param client The mobilebackup client + * @param plist The location of the plist to send + * + * @return an error code + */ +mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist_t plist); + +/** + * Request a backup from the connected device. + * + * @param client The connected MobileBackup client to use. + * @param backup_manifest The backup manifest, a plist_t of type PLIST_DICT + * containing the backup state of the last backup. For a first-time backup + * set this parameter to NULL. + * @param base_path The base path on the device to use for the backup + * operation, usually "/". + * @param proto_version A string denoting the version of the backup protocol + * to use. Latest known version is "1.6" + * + * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if + * one of the parameters is invalid, MOBILEBACKUP_E_PLIST_ERROR if + * backup_manifest is not of type PLIST_DICT, MOBILEBACKUP_E_MUX_ERROR + * if a communication error occurs, MOBILEBACKUP_E_REPLY_NOT_OK + */ +mobilebackup_error_t mobilebackup_request_backup(mobilebackup_client_t client, plist_t backup_manifest, const char *base_path, const char *proto_version); + +/** + * Sends a confirmation to the device that a backup file has been received. + * + * @param client The connected MobileBackup client to use. + * + * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if + * client is invalid, or MOBILEBACKUP_E_MUX_ERROR if a communication error + * occurs. + */ +mobilebackup_error_t mobilebackup_send_backup_file_received(mobilebackup_client_t client); + +/** + * Request that a backup should be restored to the connected device. + * + * @param client The connected MobileBackup client to use. + * @param backup_manifest The backup manifest, a plist_t of type PLIST_DICT + * containing the backup state to be restored. + * @param flags Flags to send with the request. Currently this is a combination + * of the following mobilebackup_flags_t: + * MB_RESTORE_NOTIFY_SPRINGBOARD - let SpringBoard show a 'Restore' screen + * MB_RESTORE_PRESERVE_SETTINGS - do not overwrite any settings + * MB_RESTORE_PRESERVE_CAMERA_ROLL - preserve the photos of the camera roll + * @param proto_version A string denoting the version of the backup protocol + * to use. Latest known version is "1.6". Ideally this value should be + * extracted from the given manifest plist. + * + * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if + * one of the parameters is invalid, MOBILEBACKUP_E_PLIST_ERROR if + * backup_manifest is not of type PLIST_DICT, MOBILEBACKUP_E_MUX_ERROR + * if a communication error occurs, or MOBILEBACKUP_E_REPLY_NOT_OK + * if the device did not accept the request. + */ +mobilebackup_error_t mobilebackup_request_restore(mobilebackup_client_t client, plist_t backup_manifest, mobilebackup_flags_t flags, const char *proto_version); + +/** + * Receive a confirmation from the device that it successfully received + * a restore file. + * + * @param client The connected MobileBackup client to use. + * @param result Pointer to a plist_t that will be set to the received plist + * for further processing. The caller has to free it using plist_free(). + * Note that it will be set to NULL if the operation itself fails due to + * a communication or plist error. + * If this parameter is NULL, it will be ignored. + * + * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if + * client is invalid, MOBILEBACKUP_E_REPLY_NOT_OK if the expected + * 'BackupMessageRestoreFileReceived' message could not be received, + * MOBILEBACKUP_E_PLIST_ERROR if the received message is not a valid backup + * message plist, or MOBILEBACKUP_E_MUX_ERROR if a communication error + * occurs. + */ +mobilebackup_error_t mobilebackup_receive_restore_file_received(mobilebackup_client_t client, plist_t *result); + +/** + * Receive a confirmation from the device that it successfully received + * application data file. + * + * @param client The connected MobileBackup client to use. + * @param result Pointer to a plist_t that will be set to the received plist + * for further processing. The caller has to free it using plist_free(). + * Note that it will be set to NULL if the operation itself fails due to + * a communication or plist error. + * If this parameter is NULL, it will be ignored. + * + * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if + * client is invalid, MOBILEBACKUP_E_REPLY_NOT_OK if the expected + * 'BackupMessageRestoreApplicationReceived' message could not be received, + * MOBILEBACKUP_E_PLIST_ERROR if the received message is not a valid backup + * message plist, or MOBILEBACKUP_E_MUX_ERROR if a communication error + * occurs. + */ +mobilebackup_error_t mobilebackup_receive_restore_application_received(mobilebackup_client_t client, plist_t *result); + +/** + * Tells the device that the restore process is complete and waits for the + * device to close the connection. After that, the device should reboot. + * + * @param client The connected MobileBackup client to use. + * + * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if + * client is invalid, MOBILEBACKUP_E_PLIST_ERROR if the received disconnect + * message plist is invalid, or MOBILEBACKUP_E_MUX_ERROR if a communication + * error occurs. + */ +mobilebackup_error_t mobilebackup_send_restore_complete(mobilebackup_client_t client); + +/** + * Sends a backup error message to the device. + * + * @param client The connected MobileBackup client to use. + * @param reason A string describing the reason for the error message. + * + * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if + * one of the parameters is invalid, or MOBILEBACKUP_E_MUX_ERROR if a + * communication error occurs. + */ +mobilebackup_error_t mobilebackup_send_error(mobilebackup_client_t client, const char *reason); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/mobilebackup2.h b/dep/libimobiledevice/mobilebackup2.h new file mode 100644 index 0000000..1f20d40 --- /dev/null +++ b/dep/libimobiledevice/mobilebackup2.h @@ -0,0 +1,211 @@ +/** + * @file libimobiledevice/mobilebackup2.h + * @brief Backup and restore of all device data (mobilebackup2, iOS4+ only) + * \internal + * + * Copyright (c) 2011-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2010-2012 Nikias Bassen All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IMOBILEBACKUP2_H +#define IMOBILEBACKUP2_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define MOBILEBACKUP2_SERVICE_NAME "com.apple.mobilebackup2" + +/** Error Codes */ +typedef enum { + MOBILEBACKUP2_E_SUCCESS = 0, + MOBILEBACKUP2_E_INVALID_ARG = -1, + MOBILEBACKUP2_E_PLIST_ERROR = -2, + MOBILEBACKUP2_E_MUX_ERROR = -3, + MOBILEBACKUP2_E_BAD_VERSION = -4, + MOBILEBACKUP2_E_REPLY_NOT_OK = -5, + MOBILEBACKUP2_E_NO_COMMON_VERSION = -6, + MOBILEBACKUP2_E_UNKNOWN_ERROR = -256 +} mobilebackup2_error_t; + +typedef struct mobilebackup2_client_private mobilebackup2_client_private; +typedef mobilebackup2_client_private *mobilebackup2_client_t; /**< The client handle. */ + + +/** + * Connects to the mobilebackup2 service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will be set to a newly allocated + * mobilebackup2_client_t upon successful return. + * + * @return MOBILEBACKUP2_E_SUCCESS on success, MOBILEBACKUP2_E_INVALID ARG + * if one or more parameter is invalid, or MOBILEBACKUP2_E_BAD_VERSION + * if the mobilebackup2 version on the device is newer. + */ +mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilebackup2_client_t * client); + +/** + * Starts a new mobilebackup2 service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * mobilebackup2_client_t upon successful return. Must be freed using + * mobilebackup2_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return MOBILEBACKUP2_E_SUCCESS on success, or an MOBILEBACKUP2_E_* error + * code otherwise. + */ +mobilebackup2_error_t mobilebackup2_client_start_service(idevice_t device, mobilebackup2_client_t* client, const char* label); + +/** + * Disconnects a mobilebackup2 client from the device and frees up the + * mobilebackup2 client data. + * + * @param client The mobilebackup2 client to disconnect and free. + * + * @return MOBILEBACKUP2_E_SUCCESS on success, or MOBILEBACKUP2_E_INVALID_ARG + * if client is NULL. + */ +mobilebackup2_error_t mobilebackup2_client_free(mobilebackup2_client_t client); + + +/** + * Sends a backup message plist. + * + * @param client The connected MobileBackup client to use. + * @param message The message to send. This will be inserted into the request + * plist as value for MessageName. If this parameter is NULL, + * the plist passed in the options parameter will be sent directly. + * @param options Additional options as PLIST_DICT to add to the request. + * The MessageName key with the value passed in the message parameter + * will be inserted into this plist before sending it. This parameter + * can be NULL if message is not NULL. + */ +mobilebackup2_error_t mobilebackup2_send_message(mobilebackup2_client_t client, const char *message, plist_t options); + +/** + * Receives a DL* message plist from the device. + * This function is a wrapper around device_link_service_receive_message. + * + * @param client The connected MobileBackup client to use. + * @param msg_plist Pointer to a plist that will be set to the contents of the + * message plist upon successful return. + * @param dlmessage A pointer that will be set to a newly allocated char* + * containing the DL* string from the given plist. It is up to the caller + * to free the allocated memory. If this parameter is NULL + * it will be ignored. + * + * @return MOBILEBACKUP2_E_SUCCESS if a DL* message was received, + * MOBILEBACKUP2_E_INVALID_ARG if client or message is invalid, + * MOBILEBACKUP2_E_PLIST_ERROR if the received plist is invalid + * or is not a DL* message plist, or MOBILEBACKUP2_E_MUX_ERROR if + * receiving from the device failed. + */ +mobilebackup2_error_t mobilebackup2_receive_message(mobilebackup2_client_t client, plist_t *msg_plist, char **dlmessage); + +/** + * Send binary data to the device. + * + * @note This function returns MOBILEBACKUP2_E_SUCCESS even if less than the + * requested length has been sent. The fourth parameter is required and + * must be checked to ensure if the whole data has been sent. + * + * @param client The MobileBackup client to send to. + * @param data Pointer to the data to send + * @param length Number of bytes to send + * @param bytes Number of bytes actually sent + * + * @return MOBILEBACKUP2_E_SUCCESS if any data was successfully sent, + * MOBILEBACKUP2_E_INVALID_ARG if one of the parameters is invalid, + * or MOBILEBACKUP2_E_MUX_ERROR if sending of the data failed. + */ +mobilebackup2_error_t mobilebackup2_send_raw(mobilebackup2_client_t client, const char *data, uint32_t length, uint32_t *bytes); + +/** + * Receive binary from the device. + * + * @note This function returns MOBILEBACKUP2_E_SUCCESS even if no data + * has been received (unless a communication error occured). + * The fourth parameter is required and must be checked to know how + * many bytes were actually received. + * + * @param client The MobileBackup client to receive from. + * @param data Pointer to a buffer that will be filled with the received data. + * @param length Number of bytes to receive. The data buffer needs to be large + * enough to store this amount of data. + * @paran bytes Number of bytes actually received. + * + * @return MOBILEBACKUP2_E_SUCCESS if any or no data was received, + * MOBILEBACKUP2_E_INVALID_ARG if one of the parameters is invalid, + * or MOBILEBACKUP2_E_MUX_ERROR if receiving the data failed. + */ +mobilebackup2_error_t mobilebackup2_receive_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes); + +/** + * Performs the mobilebackup2 protocol version exchange. + * + * @param client The MobileBackup client to use. + * @param local_versions An array of supported versions to send to the remote. + * @param count The number of items in local_versions. + * @param remote_version Holds the protocol version of the remote on success. + * + * @return MOBILEBACKUP2_E_SUCCESS on success, or a MOBILEBACKUP2_E_* error + * code otherwise. + */ +mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version); + +/** + * Send a request to the connected mobilebackup2 service. + * + * @param client + * @param request The request to send to the backup service. + * Currently, this is one of "Backup", "Restore", "Info", or "List". + * @param target_identifier UDID of the target device. + * @param source_identifier UDID of backup data? + * @param options Additional options in a plist of type PLIST_DICT. + * + * @return MOBILEBACKUP2_E_SUCCESS if the request was successfully sent, + * or a MOBILEBACKUP2_E_* error value otherwise. + */ +mobilebackup2_error_t mobilebackup2_send_request(mobilebackup2_client_t client, const char *request, const char *target_identifier, const char *source_identifier, plist_t options); + +/** + * Sends a DLMessageStatusResponse to the device. + * + * @param client The MobileBackup client to use. + * @param status_code The status code to send. + * @param status1 A status message to send. Can be NULL if not required. + * @param status2 An additional status plist to attach to the response. + * Can be NULL if not required. + * + * @return MOBILEBACKUP2_E_SUCCESS on success, MOBILEBACKUP2_E_INVALID_ARG + * if client is invalid, or another MOBILEBACKUP2_E_* otherwise. + */ +mobilebackup2_error_t mobilebackup2_send_status_response(mobilebackup2_client_t client, int status_code, const char *status1, plist_t status2); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/mobilesync.h b/dep/libimobiledevice/mobilesync.h new file mode 100644 index 0000000..e6885c7 --- /dev/null +++ b/dep/libimobiledevice/mobilesync.h @@ -0,0 +1,354 @@ +/** + * @file libimobiledevice/mobilesync.h + * @brief Synchronize data classes with a device and computer. + * \internal + * + * Copyright (c) 2010-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2010-2011 Nikias Bassen All Rights Reserved. + * Copyright (c) 2014 Christophe Fergeau All Rights Reserved. + * Copyright (c) 2010 Bryan Forbes All Rights Reserved. + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IMOBILESYNC_H +#define IMOBILESYNC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define MOBILESYNC_SERVICE_NAME "com.apple.mobilesync" + +/** Error Codes */ +typedef enum { + MOBILESYNC_E_SUCCESS = 0, + MOBILESYNC_E_INVALID_ARG = -1, + MOBILESYNC_E_PLIST_ERROR = -2, + MOBILESYNC_E_MUX_ERROR = -3, + MOBILESYNC_E_BAD_VERSION = -4, + MOBILESYNC_E_SYNC_REFUSED = -5, + MOBILESYNC_E_CANCELLED = -6, + MOBILESYNC_E_WRONG_DIRECTION = -7, + MOBILESYNC_E_NOT_READY = -8, + MOBILESYNC_E_UNKNOWN_ERROR = -256 +} mobilesync_error_t; + +/** The sync type of the current sync session. */ +typedef enum { + MOBILESYNC_SYNC_TYPE_FAST, /**< Fast-sync requires that only the changes made since the last synchronization should be reported by the computer. */ + MOBILESYNC_SYNC_TYPE_SLOW, /**< Slow-sync requires that all data from the computer needs to be synchronized/sent. */ + MOBILESYNC_SYNC_TYPE_RESET /**< Reset-sync signals that the computer should send all data again. */ +} mobilesync_sync_type_t; + +typedef struct mobilesync_client_private mobilesync_client_private; +typedef mobilesync_client_private *mobilesync_client_t; /**< The client handle */ + +typedef struct { + char *device_anchor; + char *computer_anchor; +} mobilesync_anchors; +typedef mobilesync_anchors *mobilesync_anchors_t; /**< Anchors used by the device and computer. */ + +/* Interface */ + +/** + * Connects to the mobilesync service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will be set to a newly allocated + * #mobilesync_client_t upon successful return. + * + * @retval MOBILESYNC_E_SUCCESS on success + * @retval MOBILESYNC_E_INVALID_ARG if one or more parameters are invalid + * @retval DEVICE_LINK_SERVICE_E_BAD_VERSION if the mobilesync version on + * the device is newer. + */ +mobilesync_error_t mobilesync_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilesync_client_t * client); + +/** + * Starts a new mobilesync service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * mobilesync_client_t upon successful return. Must be freed using + * mobilesync_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return MOBILESYNC_E_SUCCESS on success, or an MOBILESYNC_E_* error + * code otherwise. + */ +mobilesync_error_t mobilesync_client_start_service(idevice_t device, mobilesync_client_t* client, const char* label); + +/** + * Disconnects a mobilesync client from the device and frees up the + * mobilesync client data. + * + * @param client The mobilesync client to disconnect and free. + * + * @retval MOBILESYNC_E_SUCCESS on success + * @retval MOBILESYNC_E_INVALID_ARG if \a client is NULL. + */ +mobilesync_error_t mobilesync_client_free(mobilesync_client_t client); + + +/** + * Polls the device for mobilesync data. + * + * @param client The mobilesync client + * @param plist A pointer to the location where the plist should be stored + * + * @return an error code + */ +mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist_t *plist); + +/** + * Sends mobilesync data to the device + * + * @note This function is low-level and should only be used if you need to send + * a new type of message. + * + * @param client The mobilesync client + * @param plist The location of the plist to send + * + * @return an error code + */ +mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist_t plist); + + +/** + * Requests starting synchronization of a data class with the device + * + * @param client The mobilesync client + * @param data_class The data class identifier to sync + * @param anchors The anchors required to exchange with the device. The anchors + * allow the device to tell if the synchronization information on the computer + * and device are consistent to determine what sync type is required. + * @param computer_data_class_version The version of the data class storage on the computer + * @param sync_type A pointer to store the sync type reported by the device_anchor + * @param device_data_class_version The version of the data class storage on the device + * @param error_description A pointer to store an error message if reported by the device + * + * @retval MOBILESYNC_E_SUCCESS on success + * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid + * @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid form + * @retval MOBILESYNC_E_SYNC_REFUSED if the device refused to sync + * @retval MOBILESYNC_E_CANCELLED if the device explicitly cancelled the + * sync request + */ +mobilesync_error_t mobilesync_start(mobilesync_client_t client, const char *data_class, mobilesync_anchors_t anchors, uint64_t computer_data_class_version, mobilesync_sync_type_t *sync_type, uint64_t *device_data_class_version, char** error_description); + +/** + * Cancels a running synchronization session with a device at any time. + * + * @param client The mobilesync client + * @param reason The reason to supply to the device for cancelling + * + * @retval MOBILESYNC_E_SUCCESS on success + * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid + */ +mobilesync_error_t mobilesync_cancel(mobilesync_client_t client, const char* reason); + +/** + * Finish a synchronization session of a data class on the device. + * A session must have previously been started using mobilesync_start(). + * + * @param client The mobilesync client + * + * @retval MOBILESYNC_E_SUCCESS on success + * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid + * @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid + * form + */ +mobilesync_error_t mobilesync_finish(mobilesync_client_t client); + + +/** + * Requests to receive all records of the currently set data class from the device. + * The actually changes are retrieved using mobilesync_receive_changes() after this + * request has been successful. + * + * @param client The mobilesync client + * + * @retval MOBILESYNC_E_SUCCESS on success + * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid + */ +mobilesync_error_t mobilesync_get_all_records_from_device(mobilesync_client_t client); + +/** + * Requests to receive only changed records of the currently set data class from the device. + * The actually changes are retrieved using mobilesync_receive_changes() after this + * request has been successful. + * + * @param client The mobilesync client + * + * @retval MOBILESYNC_E_SUCCESS on success + * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid + */ +mobilesync_error_t mobilesync_get_changes_from_device(mobilesync_client_t client); + +/** + * Requests the device to delete all records of the current data class + * + * @note The operation must be called after starting synchronization. + * + * @param client The mobilesync client + * + * @retval MOBILESYNC_E_SUCCESS on success + * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid + * @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid form + */ +mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t client); + + +/** + * Receives changed entitites of the currently set data class from the device + * + * @param client The mobilesync client + * @param entities A pointer to store the changed entity records as a PLIST_DICT + * @param is_last_record A pointer to store a flag indicating if this submission is the last one + * @param actions A pointer to additional flags the device is sending or NULL to ignore + * + * @retval MOBILESYNC_E_SUCCESS on success + * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid + * @retval MOBILESYNC_E_CANCELLED if the device explicitly cancelled the + * session + */ +mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist_t *entities, uint8_t *is_last_record, plist_t *actions); + +/** + * Acknowledges to the device that the changes have been merged on the computer + * + * @param client The mobilesync client + * + * @retval MOBILESYNC_E_SUCCESS on success + * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid + */ +mobilesync_error_t mobilesync_acknowledge_changes_from_device(mobilesync_client_t client); + + +/** + * Verifies if the device is ready to receive changes from the computer. + * This call changes the synchronization direction so that mobilesync_send_changes() + * can be used to send changes to the device. + * + * @param client The mobilesync client + * + * @retval MOBILESYNC_E_SUCCESS on success + * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid + * @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid form + * @retval MOBILESYNC_E_WRONG_DIRECTION if the current sync direction does + * not permit this call + * @retval MOBILESYNC_E_CANCELLED if the device explicitly cancelled the + * session + * @retval MOBILESYNC_E_NOT_READY if the device is not ready to start + * receiving any changes + */ +mobilesync_error_t mobilesync_ready_to_send_changes_from_computer(mobilesync_client_t client); + + +/** + * Sends changed entities of the currently set data class to the device + * + * @param client The mobilesync client + * @param entities The changed entity records as a PLIST_DICT + * @param is_last_record A flag indicating if this submission is the last one + * @param actions Additional actions for the device created with mobilesync_actions_new() + * or NULL if no actions should be passed + * + * @retval MOBILESYNC_E_SUCCESS on success + * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid, + * @retval MOBILESYNC_E_WRONG_DIRECTION if the current sync direction does + * not permit this call + */ +mobilesync_error_t mobilesync_send_changes(mobilesync_client_t client, plist_t entities, uint8_t is_last_record, plist_t actions); + +/** + * Receives any remapped identifiers reported after the device merged submitted changes. + * + * @param client The mobilesync client + * @param mapping A pointer to an array plist containing a dict of identifier remappings + * + * @retval MOBILESYNC_E_SUCCESS on success + * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid + * @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid + * form + * @retval MOBILESYNC_E_WRONG_DIRECTION if the current sync direction does + * not permit this call + * @retval MOBILESYNC_E_CANCELLED if the device explicitly cancelled the + * session + */ +mobilesync_error_t mobilesync_remap_identifiers(mobilesync_client_t client, plist_t *mapping); + +/* Helper */ + +/** + * Allocates memory for a new anchors struct initialized with the passed anchors. + * + * @param device_anchor An anchor the device reported the last time or NULL + * if none is known yet which for instance is true on first synchronization. + * @param computer_anchor An arbitrary string to use as anchor for the computer. + * + * @return A new #mobilesync_anchors_t struct. Must be freed using mobilesync_anchors_free(). + */ +mobilesync_anchors_t mobilesync_anchors_new(const char *device_anchor, const char *computer_anchor); + +/** + * Free memory used by anchors. + * + * @param anchors The anchors to free. + */ +void mobilesync_anchors_free(mobilesync_anchors_t anchors); + + +/** + * Create a new actions plist to use in mobilesync_send_changes(). + * + * @return A new plist_t of type PLIST_DICT. + */ +plist_t mobilesync_actions_new(void); + +/** + * Add one or more new key:value pairs to the given actions plist. + * + * @param actions The actions to modify. + * @param ... KEY, VALUE, [KEY, VALUE], NULL + * + * @note The known keys so far are "SyncDeviceLinkEntityNamesKey" which expects + * an array of entity names, followed by a count paramter as well as + * "SyncDeviceLinkAllRecordsOfPulledEntityTypeSentKey" which expects an + * integer to use as a boolean value indicating that the device should + * link submitted changes and report remapped identifiers. + */ +void mobilesync_actions_add(plist_t actions, ...); + +/** + * Free actions plist. + * + * @param actions The actions plist to free. Does nothing if NULL is passed. + */ +void mobilesync_actions_free(plist_t actions); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/notification_proxy.h b/dep/libimobiledevice/notification_proxy.h new file mode 100644 index 0000000..a9d2d3f --- /dev/null +++ b/dep/libimobiledevice/notification_proxy.h @@ -0,0 +1,196 @@ +/** + * @file libimobiledevice/notification_proxy.h + * @brief Observe and post notifications. + * \internal + * + * Copyright (c) 2010-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2009-2010 Nikias Bassen All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef INOTIFICATION_PROXY_H +#define INOTIFICATION_PROXY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define NP_SERVICE_NAME "com.apple.mobile.notification_proxy" + +/** Error Codes */ +typedef enum { + NP_E_SUCCESS = 0, + NP_E_INVALID_ARG = -1, + NP_E_PLIST_ERROR = -2, + NP_E_CONN_FAILED = -3, + NP_E_UNKNOWN_ERROR = -256 +} np_error_t; + +/** + * @name Notifications that can be send + * + * For use with np_post_notification() (client --> device) + */ +#define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart" +#define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart" +#define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish" +#define NP_SYNC_LOCK_REQUEST "com.apple.itunes-mobdev.syncLockRequest" +/*@}*/ + +/** + * @name Notifications that can be received + * + * For use with np_observe_notification() (device --> client) + */ +/*@{*/ +#define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest" +#define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest" +#define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest" +#define NP_PHONE_NUMBER_CHANGED "com.apple.mobile.lockdown.phone_number_changed" +#define NP_DEVICE_NAME_CHANGED "com.apple.mobile.lockdown.device_name_changed" +#define NP_TIMEZONE_CHANGED "com.apple.mobile.lockdown.timezone_changed" +#define NP_TRUSTED_HOST_ATTACHED "com.apple.mobile.lockdown.trusted_host_attached" +#define NP_HOST_DETACHED "com.apple.mobile.lockdown.host_detached" +#define NP_HOST_ATTACHED "com.apple.mobile.lockdown.host_attached" +#define NP_REGISTRATION_FAILED "com.apple.mobile.lockdown.registration_failed" +#define NP_ACTIVATION_STATE "com.apple.mobile.lockdown.activation_state" +#define NP_BRICK_STATE "com.apple.mobile.lockdown.brick_state" +#define NP_DISK_USAGE_CHANGED "com.apple.mobile.lockdown.disk_usage_changed" /**< iOS 4.0+ */ +#define NP_DS_DOMAIN_CHANGED "com.apple.mobile.data_sync.domain_changed" +#define NP_BACKUP_DOMAIN_CHANGED "com.apple.mobile.backup.domain_changed" +#define NP_APP_INSTALLED "com.apple.mobile.application_installed" +#define NP_APP_UNINSTALLED "com.apple.mobile.application_uninstalled" +#define NP_DEV_IMAGE_MOUNTED "com.apple.mobile.developer_image_mounted" +#define NP_ATTEMPTACTIVATION "com.apple.springboard.attemptactivation" +#define NP_ITDBPREP_DID_END "com.apple.itdbprep.notification.didEnd" +#define NP_LANGUAGE_CHANGED "com.apple.language.changed" +#define NP_ADDRESS_BOOK_PREF_CHANGED "com.apple.AddressBook.PreferenceChanged" +/*@}*/ + +typedef struct np_client_private np_client_private; +typedef np_client_private *np_client_t; /**< The client handle. */ + +/** Reports which notification was received. */ +typedef void (*np_notify_cb_t) (const char *notification, void *user_data); + +/* Interface */ + +/** + * Connects to the notification_proxy on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will be set to a newly allocated np_client_t + * upon successful return. + * + * @return NP_E_SUCCESS on success, NP_E_INVALID_ARG when device is NULL, + * or NP_E_CONN_FAILED when the connection to the device could not be + * established. + */ +np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t service, np_client_t *client); + +/** + * Starts a new notification proxy service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * np_client_t upon successful return. Must be freed using + * np_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return NP_E_SUCCESS on success, or an NP_E_* error + * code otherwise. + */ +np_error_t np_client_start_service(idevice_t device, np_client_t* client, const char* label); + +/** + * Disconnects a notification_proxy client from the device and frees up the + * notification_proxy client data. + * + * @param client The notification_proxy client to disconnect and free. + * + * @return NP_E_SUCCESS on success, or NP_E_INVALID_ARG when client is NULL. + */ +np_error_t np_client_free(np_client_t client); + + +/** + * Sends a notification to the device's notification_proxy. + * + * @param client The client to send to + * @param notification The notification message to send + * + * @return NP_E_SUCCESS on success, or an error returned by np_plist_send + */ +np_error_t np_post_notification(np_client_t client, const char *notification); + +/** + * Tells the device to send a notification on the specified event. + * + * @param client The client to send to + * @param notification The notifications that should be observed. + * + * @return NP_E_SUCCESS on success, NP_E_INVALID_ARG when client or + * notification are NULL, or an error returned by np_plist_send. + */ +np_error_t np_observe_notification(np_client_t client, const char *notification); + +/** + * Tells the device to send a notification on specified events. + * + * @param client The client to send to + * @param notification_spec Specification of the notifications that should be + * observed. This is expected to be an array of const char* that MUST have a + * terminating NULL entry. + * + * @return NP_E_SUCCESS on success, NP_E_INVALID_ARG when client is null, + * or an error returned by np_observe_notification. + */ +np_error_t np_observe_notifications(np_client_t client, const char **notification_spec); + +/** + * This function allows an application to define a callback function that will + * be called when a notification has been received. + * It will start a thread that polls for notifications and calls the callback + * function if a notification has been received. + * In case of an error condition when polling for notifications - e.g. device + * disconnect - the thread will call the callback function with an empty + * notification "" and terminate itself. + * + * @param client the NP client + * @param notify_cb pointer to a callback function or NULL to de-register a + * previously set callback function. + * @param user_data Pointer that will be passed to the callback function as + * user data. If notify_cb is NULL, this parameter is ignored. + * + * @note Only one callback function can be registered at the same time; + * any previously set callback function will be removed automatically. + * + * @return NP_E_SUCCESS when the callback was successfully registered, + * NP_E_INVALID_ARG when client is NULL, or NP_E_UNKNOWN_ERROR when + * the callback thread could no be created. + */ +np_error_t np_set_notify_callback(np_client_t client, np_notify_cb_t notify_cb, void *userdata); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/property_list_service.h b/dep/libimobiledevice/property_list_service.h new file mode 100644 index 0000000..5d5b835 --- /dev/null +++ b/dep/libimobiledevice/property_list_service.h @@ -0,0 +1,169 @@ +/** + * @file libimobiledevice/property_list_service.h + * @brief Definitions for the PropertyList service + * \internal + * + * Copyright (c) 2010-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2010-2014 Nikias Bassen, All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IPROPERTY_LIST_SERVICE_H +#define IPROPERTY_LIST_SERVICE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* Error Codes */ +typedef enum { + PROPERTY_LIST_SERVICE_E_SUCCESS = 0, + PROPERTY_LIST_SERVICE_E_INVALID_ARG = -1, + PROPERTY_LIST_SERVICE_E_PLIST_ERROR = -2, + PROPERTY_LIST_SERVICE_E_MUX_ERROR = -3, + PROPERTY_LIST_SERVICE_E_SSL_ERROR = -4, + PROPERTY_LIST_SERVICE_E_RECEIVE_TIMEOUT = -5, + PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR = -256 +} property_list_service_error_t; + +typedef struct property_list_service_client_private property_list_service_private; +typedef property_list_service_private* property_list_service_client_t; /**< The client handle. */ + +/* Interface */ + +/** + * Creates a new property list service for the specified port. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will be set to a newly allocated + * property_list_service_client_t upon successful return. + * + * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success, + * PROPERTY_LIST_SERVICE_E_INVALID_ARG when one of the arguments is invalid, + * or PROPERTY_LIST_SERVICE_E_MUX_ERROR when connecting to the device failed. + */ +property_list_service_error_t property_list_service_client_new(idevice_t device, lockdownd_service_descriptor_t service, property_list_service_client_t *client); + +/** + * Frees a PropertyList service. + * + * @param client The property list service to free. + * + * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success, + * PROPERTY_LIST_SERVICE_E_INVALID_ARG when client is invalid, or a + * PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR when another error occured. + */ +property_list_service_error_t property_list_service_client_free(property_list_service_client_t client); + +/** + * Sends an XML plist. + * + * @param client The property list service client to use for sending. + * @param plist plist to send + * + * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success, + * PROPERTY_LIST_SERVICE_E_INVALID_ARG when client or plist is NULL, + * PROPERTY_LIST_SERVICE_E_PLIST_ERROR when dict is not a valid plist, + * or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR when an unspecified error occurs. + */ +property_list_service_error_t property_list_service_send_xml_plist(property_list_service_client_t client, plist_t plist); + +/** + * Sends a binary plist. + * + * @param client The property list service client to use for sending. + * @param plist plist to send + * + * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success, + * PROPERTY_LIST_SERVICE_E_INVALID_ARG when client or plist is NULL, + * PROPERTY_LIST_SERVICE_E_PLIST_ERROR when dict is not a valid plist, + * or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR when an unspecified error occurs. + */ +property_list_service_error_t property_list_service_send_binary_plist(property_list_service_client_t client, plist_t plist); + +/** + * Receives a plist using the given property list service client with specified + * timeout. + * Binary or XML plists are automatically handled. + * + * @param client The property list service client to use for receiving + * @param plist pointer to a plist_t that will point to the received plist + * upon successful return + * @param timeout Maximum time in milliseconds to wait for data. + * + * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success, + * PROPERTY_LIST_SERVICE_E_INVALID_ARG when connection or *plist is NULL, + * PROPERTY_LIST_SERVICE_E_PLIST_ERROR when the received data cannot be + * converted to a plist, PROPERTY_LIST_SERVICE_E_MUX_ERROR when a + * communication error occurs, or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR when + * an unspecified error occurs. + */ +property_list_service_error_t property_list_service_receive_plist_with_timeout(property_list_service_client_t client, plist_t *plist, unsigned int timeout); + +/** + * Receives a plist using the given property list service client. + * Binary or XML plists are automatically handled. + * + * This function is like property_list_service_receive_plist_with_timeout + * using a timeout of 10 seconds. + * @see property_list_service_receive_plist_with_timeout + * + * @param client The property list service client to use for receiving + * @param plist pointer to a plist_t that will point to the received plist + * upon successful return + * + * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success, + * PROPERTY_LIST_SERVICE_E_INVALID_ARG when client or *plist is NULL, + * PROPERTY_LIST_SERVICE_E_PLIST_ERROR when the received data cannot be + * converted to a plist, PROPERTY_LIST_SERVICE_E_MUX_ERROR when a + * communication error occurs, or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR when + * an unspecified error occurs. + */ +property_list_service_error_t property_list_service_receive_plist(property_list_service_client_t client, plist_t *plist); + +/** + * Enable SSL for the given property list service client. + * + * @param client The connected property list service client for which SSL + * should be enabled. + * + * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success, + * PROPERTY_LIST_SERVICE_E_INVALID_ARG if client or client->connection is + * NULL, PROPERTY_LIST_SERVICE_E_SSL_ERROR when SSL could not be enabled, + * or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR otherwise. + */ +property_list_service_error_t property_list_service_enable_ssl(property_list_service_client_t client); + +/** + * Disable SSL for the given property list service client. + * + * @param client The connected property list service client for which SSL + * should be disabled. + * + * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success, + * PROPERTY_LIST_SERVICE_E_INVALID_ARG if client or client->connection is + * NULL, or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR otherwise. + */ +property_list_service_error_t property_list_service_disable_ssl(property_list_service_client_t client); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/restore.h b/dep/libimobiledevice/restore.h new file mode 100644 index 0000000..897c07c --- /dev/null +++ b/dep/libimobiledevice/restore.h @@ -0,0 +1,182 @@ +/** + * @file libimobiledevice/restore.h + * @brief Initiate restore process or reboot device. + * @note This service is only available if the device is in restore mode. + * \internal + * + * Copyright (c) 2010-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2010 Joshua Hill. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IRESTORE_H +#define IRESTORE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** Error Codes */ +typedef enum { + RESTORE_E_SUCCESS = 0, + RESTORE_E_INVALID_ARG = -1, + RESTORE_E_INVALID_CONF = -2, + RESTORE_E_PLIST_ERROR = -3, + RESTORE_E_DICT_ERROR = -4, + RESTORE_E_NOT_ENOUGH_DATA = -5, + RESTORE_E_MUX_ERROR = -6, + RESTORE_E_START_RESTORE_FAILED = -7, + RESTORE_E_DEVICE_ERROR = -8, + RESTORE_E_UNKNOWN_ERROR = -256 +} restored_error_t; + +typedef struct restored_client_private restored_client_private; +typedef restored_client_private *restored_client_t; /**< The client handle. */ + +/* Interface */ + +/** + * Creates a new restored client for the device. + * + * @param device The device to create a restored client for + * @param client The pointer to the location of the new restored_client + * @param label The label to use for communication. Usually the program name. + * + * @return RESTORE_E_SUCCESS on success, RESTORE_E_INVALID_ARG when client is NULL + */ +restored_error_t restored_client_new(idevice_t device, restored_client_t *client, const char *label); + +/** + * Closes the restored client session if one is running and frees up the + * restored_client struct. + * + * @param client The restore client + * + * @return RESTORE_E_SUCCESS on success, RESTORE_E_INVALID_ARG when client is NULL + */ +restored_error_t restored_client_free(restored_client_t client); + + +/** + * Query the type of the service daemon. Depending on whether the device is + * queried in normal mode or restore mode, different types will be returned. + * + * @param client The restored client + * @param type The type returned by the service daemon. Pass NULL to ignore. + * @param version The restore protocol version. Pass NULL to ignore. + * + * @return RESTORE_E_SUCCESS on success, RESTORE_E_INVALID_ARG when client is NULL + */ +restored_error_t restored_query_type(restored_client_t client, char **type, uint64_t *version); + +/** + * Queries a value from the device specified by a key. + * + * @param client An initialized restored client. + * @param key The key name to request + * @param value A plist node representing the result value node + * + * @return RESTORE_E_SUCCESS on success, RESTORE_E_INVALID_ARG when client is NULL, RESTORE_E_PLIST_ERROR if value for key can't be found + */ +restored_error_t restored_query_value(restored_client_t client, const char *key, plist_t *value); + +/** + * Retrieves a value from information plist specified by a key. + * + * @param client An initialized restored client. + * @param key The key name to request or NULL to query for all keys + * @param value A plist node representing the result value node + * + * @return RESTORE_E_SUCCESS on success, RESTORE_E_INVALID_ARG when client is NULL, RESTORE_E_PLIST_ERROR if value for key can't be found + */ +restored_error_t restored_get_value(restored_client_t client, const char *key, plist_t *value) ; + +/** + * Sends a plist to restored. + * + * @note This function is low-level and should only be used if you need to send + * a new type of message. + * + * @param client The restored client + * @param plist The plist to send + * + * @return RESTORE_E_SUCCESS on success, RESTORE_E_INVALID_ARG when client or + * plist is NULL + */ +restored_error_t restored_send(restored_client_t client, plist_t plist); + +/** + * Receives a plist from restored. + * + * @param client The restored client + * @param plist The plist to store the received data + * + * @return RESTORE_E_SUCCESS on success, RESTORE_E_INVALID_ARG when client or + * plist is NULL + */ +restored_error_t restored_receive(restored_client_t client, plist_t *plist); + +/** + * Sends the Goodbye request to restored signaling the end of communication. + * + * @param client The restore client + * + * @return RESTORE_E_SUCCESS on success, RESTORE_E_INVALID_ARG when client is NULL, + * RESTORE_E_PLIST_ERROR if the device did not acknowledge the request + */ +restored_error_t restored_goodbye(restored_client_t client); + + +/** + * Requests to start a restore and retrieve it's port on success. + * + * @param client The restored client + * @param options PLIST_DICT with options for the restore process or NULL + * @param version the restore protocol version, see restored_query_type() + * + * @return RESTORE_E_SUCCESS on success, RESTORE_E_INVALID_ARG if a parameter + * is NULL, RESTORE_E_START_RESTORE_FAILED if the request fails + */ +restored_error_t restored_start_restore(restored_client_t client, plist_t options, uint64_t version); + +/** + * Requests device to reboot. + * + * @param client The restored client + * + * @return RESTORE_E_SUCCESS on success, RESTORE_E_INVALID_ARG if a parameter + * is NULL + */ +restored_error_t restored_reboot(restored_client_t client); + +/* Helper */ + +/** + * Sets the label to send for requests to restored. + * + * @param client The restore client + * @param label The label to set or NULL to disable sending a label + * + */ +void restored_client_set_label(restored_client_t client, const char *label); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/sbservices.h b/dep/libimobiledevice/sbservices.h new file mode 100644 index 0000000..0259d97 --- /dev/null +++ b/dep/libimobiledevice/sbservices.h @@ -0,0 +1,176 @@ +/** + * @file libimobiledevice/sbservices.h + * @brief Manage SpringBoard icons and retrieve icon images. + * \internal + * + * Copyright (c) 2010-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2009-2010 Nikias Bassen All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef ISB_SERVICES_H +#define ISB_SERVICES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SBSERVICES_SERVICE_NAME "com.apple.springboardservices" + +/** Error Codes */ +typedef enum { + SBSERVICES_E_SUCCESS = 0, + SBSERVICES_E_INVALID_ARG = -1, + SBSERVICES_E_PLIST_ERROR = -2, + SBSERVICES_E_CONN_FAILED = -3, + SBSERVICES_E_UNKNOWN_ERROR = -256 +} sbservices_error_t; + +/** @name Orientation of the user interface on the device */ +/*@{*/ +typedef enum { + SBSERVICES_INTERFACE_ORIENTATION_UNKNOWN = 0, + SBSERVICES_INTERFACE_ORIENTATION_PORTRAIT = 1, + SBSERVICES_INTERFACE_ORIENTATION_PORTRAIT_UPSIDE_DOWN = 2, + SBSERVICES_INTERFACE_ORIENTATION_LANDSCAPE_RIGHT = 3, + SBSERVICES_INTERFACE_ORIENTATION_LANDSCAPE_LEFT = 4 +} sbservices_interface_orientation_t; +/*@}*/ + +typedef struct sbservices_client_private sbservices_client_private; +typedef sbservices_client_private *sbservices_client_t; /**< The client handle. */ + +/* Interface */ + +/** + * Connects to the springboardservices service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will point to a newly allocated + * sbservices_client_t upon successful return. + * + * @return SBSERVICES_E_SUCCESS on success, SBSERVICES_E_INVALID_ARG when + * client is NULL, or an SBSERVICES_E_* error code otherwise. + */ +sbservices_error_t sbservices_client_new(idevice_t device, lockdownd_service_descriptor_t service, sbservices_client_t *client); + +/** + * Starts a new sbservices service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * sbservices_client_t upon successful return. Must be freed using + * sbservices_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return SBSERVICES_E_SUCCESS on success, or an SBSERVICES_E_* error + * code otherwise. + */ +sbservices_error_t sbservices_client_start_service(idevice_t device, sbservices_client_t* client, const char* label); + +/** + * Disconnects an sbservices client from the device and frees up the + * sbservices client data. + * + * @param client The sbservices client to disconnect and free. + * + * @return SBSERVICES_E_SUCCESS on success, SBSERVICES_E_INVALID_ARG when + * client is NULL, or an SBSERVICES_E_* error code otherwise. + */ +sbservices_error_t sbservices_client_free(sbservices_client_t client); + + +/** + * Gets the icon state of the connected device. + * + * @param client The connected sbservices client to use. + * @param state Pointer that will point to a newly allocated plist containing + * the current icon state. It is up to the caller to free the memory. + * @param format_version A string to be passed as formatVersion along with + * the request, or NULL if no formatVersion should be passed. This is only + * supported since iOS 4.0 so for older firmware versions this must be set + * to NULL. + * + * @return SBSERVICES_E_SUCCESS on success, SBSERVICES_E_INVALID_ARG when + * client or state is invalid, or an SBSERVICES_E_* error code otherwise. + */ +sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist_t *state, const char *format_version); + +/** + * Sets the icon state of the connected device. + * + * @param client The connected sbservices client to use. + * @param newstate A plist containing the new iconstate. + * + * @return SBSERVICES_E_SUCCESS on success, SBSERVICES_E_INVALID_ARG when + * client or newstate is NULL, or an SBSERVICES_E_* error code otherwise. + */ +sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist_t newstate); + +/** + * Get the icon of the specified app as PNG data. + * + * @param client The connected sbservices client to use. + * @param bundleId The bundle identifier of the app to retrieve the icon for. + * @param pngdata Pointer that will point to a newly allocated buffer + * containing the PNG data upon successful return. It is up to the caller + * to free the memory. + * @param pngsize Pointer to a uint64_t that will be set to the size of the + * buffer pngdata points to upon successful return. + * + * @return SBSERVICES_E_SUCCESS on success, SBSERVICES_E_INVALID_ARG when + * client, bundleId, or pngdata are invalid, or an SBSERVICES_E_* error + * code otherwise. + */ +sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, const char *bundleId, char **pngdata, uint64_t *pngsize); + +/** + * Gets the interface orientation of the device. + * + * @param client The connected sbservices client to use. + * @param interface_orientation The interface orientation upon successful return. + * + * @return SBSERVICES_E_SUCCESS on success, SBSERVICES_E_INVALID_ARG when + * client or state is invalid, or an SBSERVICES_E_* error code otherwise. + */ +sbservices_error_t sbservices_get_interface_orientation(sbservices_client_t client, sbservices_interface_orientation_t* interface_orientation); + +/** + * Get the home screen wallpaper as PNG data. + * + * @param client The connected sbservices client to use. + * @param pngdata Pointer that will point to a newly allocated buffer + * containing the PNG data upon successful return. It is up to the caller + * to free the memory. + * @param pngsize Pointer to a uint64_t that will be set to the size of the + * buffer pngdata points to upon successful return. + * + * @return SBSERVICES_E_SUCCESS on success, SBSERVICES_E_INVALID_ARG when + * client or pngdata are invalid, or an SBSERVICES_E_* error + * code otherwise. + */ +sbservices_error_t sbservices_get_home_screen_wallpaper_pngdata(sbservices_client_t client, char **pngdata, uint64_t *pngsize); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/screenshotr.h b/dep/libimobiledevice/screenshotr.h new file mode 100644 index 0000000..0d44255 --- /dev/null +++ b/dep/libimobiledevice/screenshotr.h @@ -0,0 +1,115 @@ +/** + * @file libimobiledevice/screenshotr.h + * @brief Retrieve a screenshot from device. + * @note Requires a mounted developer image. + * \internal + * + * Copyright (c) 2010-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2010 Nikias Bassen All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef ISCREENSHOTR_H +#define ISCREENSHOTR_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SCREENSHOTR_SERVICE_NAME "com.apple.mobile.screenshotr" + +/** Error Codes */ +typedef enum { + SCREENSHOTR_E_SUCCESS = 0, + SCREENSHOTR_E_INVALID_ARG = -1, + SCREENSHOTR_E_PLIST_ERROR = -2, + SCREENSHOTR_E_MUX_ERROR = -3, + SCREENSHOTR_E_BAD_VERSION = -4, + SCREENSHOTR_E_UNKNOWN_ERROR = -256 +} screenshotr_error_t; + +typedef struct screenshotr_client_private screenshotr_client_private; +typedef screenshotr_client_private *screenshotr_client_t; /**< The client handle. */ + + +/** + * Connects to the screenshotr service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will be set to a newly allocated + * screenshotr_client_t upon successful return. + * + * @note This service is only available if a developer disk image has been + * mounted. + * + * @return SCREENSHOTR_E_SUCCESS on success, SCREENSHOTR_E_INVALID ARG if one + * or more parameters are invalid, or SCREENSHOTR_E_CONN_FAILED if the + * connection to the device could not be established. + */ +screenshotr_error_t screenshotr_client_new(idevice_t device, lockdownd_service_descriptor_t service, screenshotr_client_t * client); + +/** + * Starts a new screenshotr service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * screenshotr_client_t upon successful return. Must be freed using + * screenshotr_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return SCREENSHOTR_E_SUCCESS on success, or an SCREENSHOTR_E_* error + * code otherwise. + */ +screenshotr_error_t screenshotr_client_start_service(idevice_t device, screenshotr_client_t* client, const char* label); + +/** + * Disconnects a screenshotr client from the device and frees up the + * screenshotr client data. + * + * @param client The screenshotr client to disconnect and free. + * + * @return SCREENSHOTR_E_SUCCESS on success, or SCREENSHOTR_E_INVALID_ARG + * if client is NULL. + */ +screenshotr_error_t screenshotr_client_free(screenshotr_client_t client); + + +/** + * Get a screen shot from the connected device. + * + * @param client The connection screenshotr service client. + * @param imgdata Pointer that will point to a newly allocated buffer + * containing TIFF image data upon successful return. It is up to the + * caller to free the memory. + * @param imgsize Pointer to a uint64_t that will be set to the size of the + * buffer imgdata points to upon successful return. + * + * @return SCREENSHOTR_E_SUCCESS on success, SCREENSHOTR_E_INVALID_ARG if + * one or more parameters are invalid, or another error code if an + * error occured. + */ +screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, char **imgdata, uint64_t *imgsize); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/service.h b/dep/libimobiledevice/service.h new file mode 100644 index 0000000..13c5df1 --- /dev/null +++ b/dep/libimobiledevice/service.h @@ -0,0 +1,169 @@ +/** + * @file libimobiledevice/service.h + * @brief Generic basic service implementation to inherit. + * \internal + * + * Copyright (c) 2013-2014 Martin Szulecki All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef ISERVICE_H +#define ISERVICE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/** Error Codes */ +typedef enum { + SERVICE_E_SUCCESS = 0, + SERVICE_E_INVALID_ARG = -1, + SERVICE_E_MUX_ERROR = -3, + SERVICE_E_SSL_ERROR = -4, + SERVICE_E_START_SERVICE_ERROR = -5, + SERVICE_E_UNKNOWN_ERROR = -256 +} service_error_t; + +typedef struct service_client_private service_client_private; +typedef service_client_private* service_client_t; /**< The client handle. */ + +#define SERVICE_CONSTRUCTOR(x) (int32_t (*)(idevice_t, lockdownd_service_descriptor_t, void**))(x) + +/* Interface */ + +/** + * Creates a new service for the specified service descriptor. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will be set to a newly allocated + * service_client_t upon successful return. + * + * @return SERVICE_E_SUCCESS on success, + * SERVICE_E_INVALID_ARG when one of the arguments is invalid, + * or SERVICE_E_MUX_ERROR when connecting to the device failed. + */ +service_error_t service_client_new(idevice_t device, lockdownd_service_descriptor_t service, service_client_t *client); + +/** + * Starts a new service on the specified device with given name and + * connects to it. + * + * @param device The device to connect to. + * @param service_name The name of the service to start. + * @param client Pointer that will point to a newly allocated service_client_t + * upon successful return. Must be freed using service_client_free() after + * use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return SERVICE_E_SUCCESS on success, or a SERVICE_E_* error code + * otherwise. + */ +service_error_t service_client_factory_start_service(idevice_t device, const char* service_name, void **client, const char* label, int32_t (*constructor_func)(idevice_t, lockdownd_service_descriptor_t, void**), int32_t *error_code); + +/** + * Frees a service instance. + * + * @param client The service instance to free. + * + * @return SERVICE_E_SUCCESS on success, + * SERVICE_E_INVALID_ARG when client is invalid, or a + * SERVICE_E_UNKNOWN_ERROR when another error occured. + */ +service_error_t service_client_free(service_client_t client); + + +/** + * Sends data using the given service client. + * + * @param client The service client to use for sending. + * @param data Data to send + * @param size Size of the data to send + * @param sent Number of bytes sent (can be NULL to ignore) + * + * @return SERVICE_E_SUCCESS on success, + * SERVICE_E_INVALID_ARG when one or more parameters are + * invalid, or SERVICE_E_UNKNOWN_ERROR when an unspecified + * error occurs. + */ +service_error_t service_send(service_client_t client, const char *data, uint32_t size, uint32_t *sent); + +/** + * Receives data using the given service client with specified timeout. + * + * @param client The service client to use for receiving + * @param data Buffer that will be filled with the data received + * @param size Number of bytes to receive + * @param received Number of bytes received (can be NULL to ignore) + * @param timeout Maximum time in milliseconds to wait for data. + * + * @return SERVICE_E_SUCCESS on success, + * SERVICE_E_INVALID_ARG when one or more parameters are + * invalid, SERVICE_E_MUX_ERROR when a communication error + * occurs, or SERVICE_E_UNKNOWN_ERROR when an unspecified + * error occurs. + */ +service_error_t service_receive_with_timeout(service_client_t client, char *data, uint32_t size, uint32_t *received, unsigned int timeout); + +/** + * Receives data using the given service client. + * + * @param client The service client to use for receiving + * @param data Buffer that will be filled with the data received + * @param size Number of bytes to receive + * @param received Number of bytes received (can be NULL to ignore) + * + * @return SERVICE_E_SUCCESS on success, + * SERVICE_E_INVALID_ARG when one or more parameters are + * invalid, SERVICE_E_MUX_ERROR when a communication error + * occurs, or SERVICE_E_UNKNOWN_ERROR when an unspecified + * error occurs. + */ +service_error_t service_receive(service_client_t client, char *data, uint32_t size, uint32_t *received); + + +/** + * Enable SSL for the given service client. + * + * @param client The connected service client for that SSL should be enabled. + * + * @return SERVICE_E_SUCCESS on success, + * SERVICE_E_INVALID_ARG if client or client->connection is + * NULL, SERVICE_E_SSL_ERROR when SSL could not be enabled, + * or SERVICE_E_UNKNOWN_ERROR otherwise. + */ +service_error_t service_enable_ssl(service_client_t client); + +/** + * Disable SSL for the given service client. + * + * @param client The connected service client for that SSL should be disabled. + * + * @return SERVICE_E_SUCCESS on success, + * SERVICE_E_INVALID_ARG if client or client->connection is + * NULL, or SERVICE_E_UNKNOWN_ERROR otherwise. + */ +service_error_t service_disable_ssl(service_client_t client); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/syslog_relay.h b/dep/libimobiledevice/syslog_relay.h new file mode 100644 index 0000000..0080b54 --- /dev/null +++ b/dep/libimobiledevice/syslog_relay.h @@ -0,0 +1,160 @@ +/** + * @file libimobiledevice/syslog_relay.h + * @brief Capture the syslog output from a device. + * \internal + * + * Copyright (c) 2013-2014 Martin Szulecki All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef ISYSLOG_RELAY_H +#define ISYSLOG_RELAY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SYSLOG_RELAY_SERVICE_NAME "com.apple.syslog_relay" + +/** Error Codes */ +typedef enum { + SYSLOG_RELAY_E_SUCCESS = 0, + SYSLOG_RELAY_E_INVALID_ARG = -1, + SYSLOG_RELAY_E_MUX_ERROR = -2, + SYSLOG_RELAY_E_SSL_ERROR = -3, + SYSLOG_RELAY_E_UNKNOWN_ERROR = -256 +} syslog_relay_error_t; + +typedef struct syslog_relay_client_private syslog_relay_client_private; +typedef syslog_relay_client_private *syslog_relay_client_t; /**< The client handle. */ + +/** Receives each character received from the device. */ +typedef void (*syslog_relay_receive_cb_t)(char c, void *user_data); + +/* Interface */ + +/** + * Connects to the syslog_relay service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will point to a newly allocated + * syslog_relay_client_t upon successful return. Must be freed using + * syslog_relay_client_free() after use. + * + * @return SYSLOG_RELAY_E_SUCCESS on success, SYSLOG_RELAY_E_INVALID_ARG when + * client is NULL, or an SYSLOG_RELAY_E_* error code otherwise. + */ +syslog_relay_error_t syslog_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, syslog_relay_client_t * client); + +/** + * Starts a new syslog_relay service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * syslog_relay_client_t upon successful return. Must be freed using + * syslog_relay_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return SYSLOG_RELAY_E_SUCCESS on success, or an SYSLOG_RELAY_E_* error + * code otherwise. + */ +syslog_relay_error_t syslog_relay_client_start_service(idevice_t device, syslog_relay_client_t * client, const char* label); + +/** + * Disconnects a syslog_relay client from the device and frees up the + * syslog_relay client data. + * + * @param client The syslog_relay client to disconnect and free. + * + * @return SYSLOG_RELAY_E_SUCCESS on success, SYSLOG_RELAY_E_INVALID_ARG when + * client is NULL, or an SYSLOG_RELAY_E_* error code otherwise. + */ +syslog_relay_error_t syslog_relay_client_free(syslog_relay_client_t client); + + +/** + * Starts capturing the syslog of the device using a callback. + * + * Use syslog_relay_stop_capture() to stop receiving the syslog. + * + * @param client The syslog_relay client to use + * @param callback Callback to receive each character from the syslog. + * @param user_data Custom pointer passed to the callback function. + * + * @return SYSLOG_RELAY_E_SUCCESS on success, + * SYSLOG_RELAY_E_INVALID_ARG when one or more parameters are + * invalid or SYSLOG_RELAY_E_UNKNOWN_ERROR when an unspecified + * error occurs or a syslog capture has already been started. + */ +syslog_relay_error_t syslog_relay_start_capture(syslog_relay_client_t client, syslog_relay_receive_cb_t callback, void* user_data); + +/** + * Stops capturing the syslog of the device. + * + * Use syslog_relay_start_capture() to start receiving the syslog. + * + * @param client The syslog_relay client to use + * + * @return SYSLOG_RELAY_E_SUCCESS on success, + * SYSLOG_RELAY_E_INVALID_ARG when one or more parameters are + * invalid or SYSLOG_RELAY_E_UNKNOWN_ERROR when an unspecified + * error occurs or a syslog capture has already been started. + */ +syslog_relay_error_t syslog_relay_stop_capture(syslog_relay_client_t client); + +/* Receiving */ + +/** + * Receives data using the given syslog_relay client with specified timeout. + * + * @param client The syslog_relay client to use for receiving + * @param data Buffer that will be filled with the data received + * @param size Number of bytes to receive + * @param received Number of bytes received (can be NULL to ignore) + * @param timeout Maximum time in milliseconds to wait for data. + * + * @return SYSLOG_RELAY_E_SUCCESS on success, + * SYSLOG_RELAY_E_INVALID_ARG when one or more parameters are + * invalid, SYSLOG_RELAY_E_MUX_ERROR when a communication error + * occurs, or SYSLOG_RELAY_E_UNKNOWN_ERROR when an unspecified + * error occurs. + */ +syslog_relay_error_t syslog_relay_receive_with_timeout(syslog_relay_client_t client, char *data, uint32_t size, uint32_t *received, unsigned int timeout); + +/** + * Receives data from the service. + * + * @param client The syslog_relay client + * @param data Buffer that will be filled with the data received + * @param size Number of bytes to receive + * @param received Number of bytes received (can be NULL to ignore) + * @param timeout Maximum time in milliseconds to wait for data. + * + * @return SYSLOG_RELAY_E_SUCCESS on success, + * SYSLOG_RELAY_E_INVALID_ARG when client or plist is NULL + */ +syslog_relay_error_t syslog_relay_receive(syslog_relay_client_t client, char *data, uint32_t size, uint32_t *received); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/libimobiledevice/webinspector.h b/dep/libimobiledevice/webinspector.h new file mode 100644 index 0000000..d2a99c9 --- /dev/null +++ b/dep/libimobiledevice/webinspector.h @@ -0,0 +1,134 @@ +/** + * @file libimobiledevice/webinspector.h + * @brief WebKit Remote Debugging. + * \internal + * + * Copyright (c) 2013-2014 Martin Szulecki All Rights Reserved. + * Copyright (c) 2013 Yury Melnichek All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IWEBINSPECTOR_H +#define IWEBINSPECTOR_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define WEBINSPECTOR_SERVICE_NAME "com.apple.webinspector" + +/** Error Codes */ +typedef enum { + WEBINSPECTOR_E_SUCCESS = 0, + WEBINSPECTOR_E_INVALID_ARG = -1, + WEBINSPECTOR_E_PLIST_ERROR = -2, + WEBINSPECTOR_E_MUX_ERROR = -3, + WEBINSPECTOR_E_SSL_ERROR = -4, + WEBINSPECTOR_E_UNKNOWN_ERROR = -256 +} webinspector_error_t; + +typedef struct webinspector_client_private webinspector_client_private; +typedef webinspector_client_private *webinspector_client_t; /**< The client handle. */ + + +/** + * Connects to the webinspector service on the specified device. + * + * @param device The device to connect to. + * @param service The service descriptor returned by lockdownd_start_service. + * @param client Pointer that will point to a newly allocated + * webinspector_client_t upon successful return. Must be freed using + * webinspector_client_free() after use. + * + * @return WEBINSPECTOR_E_SUCCESS on success, WEBINSPECTOR_E_INVALID_ARG when + * client is NULL, or an WEBINSPECTOR_E_* error code otherwise. + */ +webinspector_error_t webinspector_client_new(idevice_t device, lockdownd_service_descriptor_t service, webinspector_client_t * client); + +/** + * Starts a new webinspector service on the specified device and connects to it. + * + * @param device The device to connect to. + * @param client Pointer that will point to a newly allocated + * webinspector_client_t upon successful return. Must be freed using + * webinspector_client_free() after use. + * @param label The label to use for communication. Usually the program name. + * Pass NULL to disable sending the label in requests to lockdownd. + * + * @return WEBINSPECTOR_E_SUCCESS on success, or an WEBINSPECTOR_E_* error + * code otherwise. + */ +webinspector_error_t webinspector_client_start_service(idevice_t device, webinspector_client_t * client, const char* label); + +/** + * Disconnects a webinspector client from the device and frees up the + * webinspector client data. + * + * @param client The webinspector client to disconnect and free. + * + * @return WEBINSPECTOR_E_SUCCESS on success, WEBINSPECTOR_E_INVALID_ARG when + * client is NULL, or an WEBINSPECTOR_E_* error code otherwise. + */ +webinspector_error_t webinspector_client_free(webinspector_client_t client); + + +/** + * Sends a plist to the service. + * + * @param client The webinspector client + * @param plist The plist to send + * + * @return DIAGNOSTICS_RELAY_E_SUCCESS on success, + * DIAGNOSTICS_RELAY_E_INVALID_ARG when client or plist is NULL + */ +webinspector_error_t webinspector_send(webinspector_client_t client, plist_t plist); + +/** + * Receives a plist from the service. + * + * @param client The webinspector client + * @param plist The plist to store the received data + * + * @return DIAGNOSTICS_RELAY_E_SUCCESS on success, + * DIAGNOSTICS_RELAY_E_INVALID_ARG when client or plist is NULL + */ +webinspector_error_t webinspector_receive(webinspector_client_t client, plist_t * plist); + +/** + * Receives a plist using the given webinspector client. + * + * @param client The webinspector client to use for receiving + * @param plist pointer to a plist_t that will point to the received plist + * upon successful return + * @param timeout Maximum time in milliseconds to wait for data. + * + * @return WEBINSPECTOR_E_SUCCESS on success, + * WEBINSPECTOR_E_INVALID_ARG when client or *plist is NULL, + * WEBINSPECTOR_E_PLIST_ERROR when the received data cannot be + * converted to a plist, WEBINSPECTOR_E_MUX_ERROR when a + * communication error occurs, or WEBINSPECTOR_E_UNKNOWN_ERROR + * when an unspecified error occurs. + */ +webinspector_error_t webinspector_receive_with_timeout(webinspector_client_t client, plist_t * plist, uint32_t timeout_ms); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dep/plist/Array.h b/dep/plist/Array.h new file mode 100644 index 0000000..745b750 --- /dev/null +++ b/dep/plist/Array.h @@ -0,0 +1,55 @@ +/* + * Array.h + * Array node type for C++ binding + * + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PLIST_ARRAY_H +#define PLIST_ARRAY_H + +#include +#include + +namespace PList +{ + +class Array : public Structure +{ +public : + Array(Node* parent = NULL); + Array(plist_t node, Node* parent = NULL); + Array(const Array& a); + Array& operator=(Array& a); + virtual ~Array(); + + Node* Clone() const; + + Node* operator[](unsigned int index); + void Append(Node* node); + void Insert(Node* node, unsigned int pos); + void Remove(Node* node); + void Remove(unsigned int pos); + unsigned int GetNodeIndex(Node* node) const; + +private : + std::vector _array; +}; + +}; + +#endif // PLIST_ARRAY_H diff --git a/dep/plist/Boolean.h b/dep/plist/Boolean.h new file mode 100644 index 0000000..307a1ff --- /dev/null +++ b/dep/plist/Boolean.h @@ -0,0 +1,48 @@ +/* + * Boolean.h + * Boolean node type for C++ binding + * + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PLIST_BOOLEAN_H +#define PLIST_BOOLEAN_H + +#include + +namespace PList +{ + +class Boolean : public Node +{ +public : + Boolean(Node* parent = NULL); + Boolean(plist_t node, Node* parent = NULL); + Boolean(const Boolean& b); + Boolean& operator=(Boolean& b); + Boolean(bool b); + virtual ~Boolean(); + + Node* Clone() const; + + void SetValue(bool b); + bool GetValue() const; +}; + +}; + +#endif // PLIST_BOOLEAN_H diff --git a/dep/plist/Data.h b/dep/plist/Data.h new file mode 100644 index 0000000..c9c089b --- /dev/null +++ b/dep/plist/Data.h @@ -0,0 +1,49 @@ +/* + * Data.h + * Data node type for C++ binding + * + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PLIST_DATA_H +#define PLIST_DATA_H + +#include +#include + +namespace PList +{ + +class Data : public Node +{ +public : + Data(Node* parent = NULL); + Data(plist_t node, Node* parent = NULL); + Data(const Data& d); + Data& operator=(Data& d); + Data(const std::vector& buff); + virtual ~Data(); + + Node* Clone() const; + + void SetValue(const std::vector& buff); + std::vector GetValue() const; +}; + +}; + +#endif // PLIST_DATA_H diff --git a/dep/plist/Date.h b/dep/plist/Date.h new file mode 100644 index 0000000..510a349 --- /dev/null +++ b/dep/plist/Date.h @@ -0,0 +1,50 @@ +/* + * Date.h + * Date node type for C++ binding + * + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PLIST_DATE_H +#define PLIST_DATE_H + +#include +#include +#include + +namespace PList +{ + +class Date : public Node +{ +public : + Date(Node* parent = NULL); + Date(plist_t node, Node* parent = NULL); + Date(const Date& d); + Date& operator=(Date& d); + Date(timeval t); + virtual ~Date(); + + Node* Clone() const; + + void SetValue(timeval t); + timeval GetValue() const; +}; + +}; + +#endif // PLIST_DATE_H diff --git a/dep/plist/Dictionary.h b/dep/plist/Dictionary.h new file mode 100644 index 0000000..71d40ac --- /dev/null +++ b/dep/plist/Dictionary.h @@ -0,0 +1,68 @@ +/* + * Dictionary.h + * Dictionary node type for C++ binding + * + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PLIST_DICTIONARY_H +#define PLIST_DICTIONARY_H + +#include +#include +#include + +namespace PList +{ + +class Dictionary : public Structure +{ +public : + Dictionary(Node* parent = NULL); + Dictionary(plist_t node, Node* parent = NULL); + Dictionary(const Dictionary& d); + Dictionary& operator=(Dictionary& d); + virtual ~Dictionary(); + + Node* Clone() const; + + typedef std::map::iterator iterator; + typedef std::map::const_iterator const_iterator; + + Node* operator[](const std::string& key); + iterator Begin(); + iterator End(); + iterator Find(const std::string& key); + const_iterator Begin() const; + const_iterator End() const; + const_iterator Find(const std::string& key) const; + iterator Set(const std::string& key, const Node* node); + iterator Set(const std::string& key, const Node& node); + iterator Insert(const std::string& key, Node* node) PLIST_WARN_DEPRECATED("use Set() instead"); + void Remove(Node* node); + void Remove(const std::string& key); + std::string GetNodeKey(Node* key); + +private : + std::map _map; + + +}; + +}; + +#endif // PLIST_DICTIONARY_H diff --git a/dep/plist/Integer.h b/dep/plist/Integer.h new file mode 100644 index 0000000..adbc39a --- /dev/null +++ b/dep/plist/Integer.h @@ -0,0 +1,48 @@ +/* + * Integer.h + * Integer node type for C++ binding + * + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PLIST_INTEGER_H +#define PLIST_INTEGER_H + +#include + +namespace PList +{ + +class Integer : public Node +{ +public : + Integer(Node* parent = NULL); + Integer(plist_t node, Node* parent = NULL); + Integer(const Integer& i); + Integer& operator=(Integer& i); + Integer(uint64_t i); + virtual ~Integer(); + + Node* Clone() const; + + void SetValue(uint64_t i); + uint64_t GetValue() const; +}; + +}; + +#endif // PLIST_INTEGER_H diff --git a/dep/plist/Key.h b/dep/plist/Key.h new file mode 100644 index 0000000..c680f1c --- /dev/null +++ b/dep/plist/Key.h @@ -0,0 +1,49 @@ +/* + * Key.h + * Key node type for C++ binding + * + * Copyright (c) 2012 Nikias Bassen, All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PLIST_KEY_H +#define PLIST_KEY_H + +#include +#include + +namespace PList +{ + +class Key : public Node +{ +public : + Key(Node* parent = NULL); + Key(plist_t node, Node* parent = NULL); + Key(const Key& s); + Key& operator=(Key& s); + Key(const std::string& s); + virtual ~Key(); + + Node* Clone() const; + + void SetValue(const std::string& s); + std::string GetValue() const; +}; + +}; + +#endif // PLIST_KEY_H diff --git a/dep/plist/Node.h b/dep/plist/Node.h new file mode 100644 index 0000000..6c9ae43 --- /dev/null +++ b/dep/plist/Node.h @@ -0,0 +1,57 @@ +/* + * Node.h + * Abstract node type for C++ binding + * + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PLIST_NODE_H +#define PLIST_NODE_H + +#include +#include + +namespace PList +{ + +class Node +{ +public : + virtual ~Node(); + + virtual Node* Clone() const = 0; + + Node * GetParent() const; + plist_type GetType() const; + plist_t GetPlist() const; + + static Node* FromPlist(plist_t node, Node* parent = NULL); + +protected: + Node(Node* parent = NULL); + Node(plist_t node, Node* parent = NULL); + Node(plist_type type, Node* parent = NULL); + plist_t _node; + +private: + Node* _parent; + friend class Structure; +}; + +}; + +#endif // PLIST_NODE_H diff --git a/dep/plist/Real.h b/dep/plist/Real.h new file mode 100644 index 0000000..c2d55f8 --- /dev/null +++ b/dep/plist/Real.h @@ -0,0 +1,48 @@ +/* + * Real.h + * Real node type for C++ binding + * + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PLIST_REAL_H +#define PLIST_REAL_H + +#include + +namespace PList +{ + +class Real : public Node +{ +public : + Real(Node* parent = NULL); + Real(plist_t node, Node* parent = NULL); + Real(const Real& d); + Real& operator=(Real& d); + Real(double d); + virtual ~Real(); + + Node* Clone() const; + + void SetValue(double d); + double GetValue() const; +}; + +}; + +#endif // PLIST_REAL_H diff --git a/dep/plist/String.h b/dep/plist/String.h new file mode 100644 index 0000000..80290b3 --- /dev/null +++ b/dep/plist/String.h @@ -0,0 +1,49 @@ +/* + * String.h + * String node type for C++ binding + * + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PLIST_STRING_H +#define PLIST_STRING_H + +#include +#include + +namespace PList +{ + +class String : public Node +{ +public : + String(Node* parent = NULL); + String(plist_t node, Node* parent = NULL); + String(const String& s); + String& operator=(String& s); + String(const std::string& s); + virtual ~String(); + + Node* Clone() const; + + void SetValue(const std::string& s); + std::string GetValue() const; +}; + +}; + +#endif // PLIST_STRING_H diff --git a/dep/plist/Structure.h b/dep/plist/Structure.h new file mode 100644 index 0000000..eded8b2 --- /dev/null +++ b/dep/plist/Structure.h @@ -0,0 +1,59 @@ +/* + * Structure.h + * Structure node type for C++ binding + * + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PLIST_STRUCTURE_H +#define PLIST_STRUCTURE_H + +#include +#include +#include + +namespace PList +{ + +class Structure : public Node +{ +public : + virtual ~Structure(); + + uint32_t GetSize() const; + + std::string ToXml() const; + std::vector ToBin() const; + + virtual void Remove(Node* node) = 0; + + static Structure* FromXml(const std::string& xml); + static Structure* FromBin(const std::vector& bin); + +protected: + Structure(Node* parent = NULL); + Structure(plist_type type, Node* parent = NULL); + void UpdateNodeParent(Node* node); + +private: + Structure(Structure& s); + Structure& operator=(const Structure& s); +}; + +}; + +#endif // PLIST_STRUCTURE_H diff --git a/dep/plist/Uid.h b/dep/plist/Uid.h new file mode 100644 index 0000000..2d8375b --- /dev/null +++ b/dep/plist/Uid.h @@ -0,0 +1,48 @@ +/* + * Uid.h + * Uid node type for C++ binding + * + * Copyright (c) 2012 Nikias Bassen, All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PLIST_UID_H +#define PLIST_UID_H + +#include + +namespace PList +{ + +class Uid : public Node +{ +public : + Uid(Node* parent = NULL); + Uid(plist_t node, Node* parent = NULL); + Uid(const Uid& i); + Uid& operator=(Uid& i); + Uid(uint64_t i); + virtual ~Uid(); + + Node* Clone() const; + + void SetValue(uint64_t i); + uint64_t GetValue() const; +}; + +}; + +#endif // PLIST_UID_H diff --git a/dep/plist/plist++.h b/dep/plist/plist++.h new file mode 100644 index 0000000..b29fc76 --- /dev/null +++ b/dep/plist/plist++.h @@ -0,0 +1,39 @@ +/* + * plist++.h + * Main include of libplist C++ binding + * + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef LIBPLISTXX_H +#define LIBPLISTXX_H + +#include "plist.h" +#include "Array.h" +#include "Boolean.h" +#include "Data.h" +#include "Date.h" +#include "Dictionary.h" +#include "Integer.h" +#include "Node.h" +#include "Real.h" +#include "Key.h" +#include "Uid.h" +#include "String.h" +#include "Structure.h" + +#endif diff --git a/dep/plist/plist.h b/dep/plist/plist.h new file mode 100644 index 0000000..29b1fce --- /dev/null +++ b/dep/plist/plist.h @@ -0,0 +1,770 @@ +/** + * @file plist/plist.h + * @brief Main include of libplist + * \internal + * + * Copyright (c) 2012-2019 Nikias Bassen, All Rights Reserved. + * Copyright (c) 2008-2009 Jonathan Beck, All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef LIBPLIST_H +#define LIBPLIST_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if _MSC_VER && _MSC_VER < 1700 + typedef __int8 int8_t; + typedef __int16 int16_t; + typedef __int32 int32_t; + typedef __int64 int64_t; + + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; + typedef unsigned __int64 uint64_t; + +#else +#include +#endif + +#ifdef __llvm__ + #if defined(__has_extension) + #if (__has_extension(attribute_deprecated_with_message)) + #ifndef PLIST_WARN_DEPRECATED + #define PLIST_WARN_DEPRECATED(x) __attribute__((deprecated(x))) + #endif + #else + #ifndef PLIST_WARN_DEPRECATED + #define PLIST_WARN_DEPRECATED(x) __attribute__((deprecated)) + #endif + #endif + #else + #ifndef PLIST_WARN_DEPRECATED + #define PLIST_WARN_DEPRECATED(x) __attribute__((deprecated)) + #endif + #endif +#elif (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 5))) + #ifndef PLIST_WARN_DEPRECATED + #define PLIST_WARN_DEPRECATED(x) __attribute__((deprecated(x))) + #endif +#elif defined(_MSC_VER) + #ifndef PLIST_WARN_DEPRECATED + #define PLIST_WARN_DEPRECATED(x) __declspec(deprecated(x)) + #endif +#else + #define PLIST_WARN_DEPRECATED(x) + #pragma message("WARNING: You need to implement DEPRECATED for this compiler") +#endif + +#include +#include + + /** + * \mainpage libplist : A library to handle Apple Property Lists + * \defgroup PublicAPI Public libplist API + */ + /*@{*/ + + + /** + * The basic plist abstract data type. + */ + typedef void *plist_t; + + /** + * The plist dictionary iterator. + */ + typedef void* plist_dict_iter; + + /** + * The plist array iterator. + */ + typedef void* plist_array_iter; + + /** + * The enumeration of plist node types. + */ + typedef enum + { + PLIST_BOOLEAN, /**< Boolean, scalar type */ + PLIST_UINT, /**< Unsigned integer, scalar type */ + PLIST_REAL, /**< Real, scalar type */ + PLIST_STRING, /**< ASCII string, scalar type */ + PLIST_ARRAY, /**< Ordered array, structured type */ + PLIST_DICT, /**< Unordered dictionary (key/value pair), structured type */ + PLIST_DATE, /**< Date, scalar type */ + PLIST_DATA, /**< Binary data, scalar type */ + PLIST_KEY, /**< Key in dictionaries (ASCII String), scalar type */ + PLIST_UID, /**< Special type used for 'keyed encoding' */ + PLIST_NONE /**< No type */ + } plist_type; + + + /******************************************** + * * + * Creation & Destruction * + * * + ********************************************/ + + /** + * Create a new root plist_t type #PLIST_DICT + * + * @return the created plist + * @sa #plist_type + */ + plist_t plist_new_dict(void); + + /** + * Create a new root plist_t type #PLIST_ARRAY + * + * @return the created plist + * @sa #plist_type + */ + plist_t plist_new_array(void); + + /** + * Create a new plist_t type #PLIST_STRING + * + * @param val the sting value, encoded in UTF8. + * @return the created item + * @sa #plist_type + */ + plist_t plist_new_string(const char *val); + + /** + * Create a new plist_t type #PLIST_BOOLEAN + * + * @param val the boolean value, 0 is false, other values are true. + * @return the created item + * @sa #plist_type + */ + plist_t plist_new_bool(uint8_t val); + + /** + * Create a new plist_t type #PLIST_UINT + * + * @param val the unsigned integer value + * @return the created item + * @sa #plist_type + */ + plist_t plist_new_uint(uint64_t val); + + /** + * Create a new plist_t type #PLIST_REAL + * + * @param val the real value + * @return the created item + * @sa #plist_type + */ + plist_t plist_new_real(double val); + + /** + * Create a new plist_t type #PLIST_DATA + * + * @param val the binary buffer + * @param length the length of the buffer + * @return the created item + * @sa #plist_type + */ + plist_t plist_new_data(const char *val, uint64_t length); + + /** + * Create a new plist_t type #PLIST_DATE + * + * @param sec the number of seconds since 01/01/2001 + * @param usec the number of microseconds + * @return the created item + * @sa #plist_type + */ + plist_t plist_new_date(int32_t sec, int32_t usec); + + /** + * Create a new plist_t type #PLIST_UID + * + * @param val the unsigned integer value + * @return the created item + * @sa #plist_type + */ + plist_t plist_new_uid(uint64_t val); + + /** + * Destruct a plist_t node and all its children recursively + * + * @param plist the plist to free + */ + void plist_free(plist_t plist); + + /** + * Return a copy of passed node and it's children + * + * @param node the plist to copy + * @return copied plist + */ + plist_t plist_copy(plist_t node); + + + /******************************************** + * * + * Array functions * + * * + ********************************************/ + + /** + * Get size of a #PLIST_ARRAY node. + * + * @param node the node of type #PLIST_ARRAY + * @return size of the #PLIST_ARRAY node + */ + uint32_t plist_array_get_size(plist_t node); + + /** + * Get the nth item in a #PLIST_ARRAY node. + * + * @param node the node of type #PLIST_ARRAY + * @param n the index of the item to get. Range is [0, array_size[ + * @return the nth item or NULL if node is not of type #PLIST_ARRAY + */ + plist_t plist_array_get_item(plist_t node, uint32_t n); + + /** + * Get the index of an item. item must be a member of a #PLIST_ARRAY node. + * + * @param node the node + * @return the node index or UINT_MAX if node index can't be determined + */ + uint32_t plist_array_get_item_index(plist_t node); + + /** + * Set the nth item in a #PLIST_ARRAY node. + * The previous item at index n will be freed using #plist_free + * + * @param node the node of type #PLIST_ARRAY + * @param item the new item at index n. The array is responsible for freeing item when it is no longer needed. + * @param n the index of the item to get. Range is [0, array_size[. Assert if n is not in range. + */ + void plist_array_set_item(plist_t node, plist_t item, uint32_t n); + + /** + * Append a new item at the end of a #PLIST_ARRAY node. + * + * @param node the node of type #PLIST_ARRAY + * @param item the new item. The array is responsible for freeing item when it is no longer needed. + */ + void plist_array_append_item(plist_t node, plist_t item); + + /** + * Insert a new item at position n in a #PLIST_ARRAY node. + * + * @param node the node of type #PLIST_ARRAY + * @param item the new item to insert. The array is responsible for freeing item when it is no longer needed. + * @param n The position at which the node will be stored. Range is [0, array_size[. Assert if n is not in range. + */ + void plist_array_insert_item(plist_t node, plist_t item, uint32_t n); + + /** + * Remove an existing position in a #PLIST_ARRAY node. + * Removed position will be freed using #plist_free. + * + * @param node the node of type #PLIST_ARRAY + * @param n The position to remove. Range is [0, array_size[. Assert if n is not in range. + */ + void plist_array_remove_item(plist_t node, uint32_t n); + + /** + * Remove a node that is a child node of a #PLIST_ARRAY node. + * node will be freed using #plist_free. + * + * @param node The node to be removed from its #PLIST_ARRAY parent. + */ + void plist_array_item_remove(plist_t node); + + /** + * Create an iterator of a #PLIST_ARRAY node. + * The allocated iterator should be freed with the standard free function. + * + * @param node The node of type #PLIST_ARRAY + * @param iter Location to store the iterator for the array. + */ + void plist_array_new_iter(plist_t node, plist_array_iter *iter); + + /** + * Increment iterator of a #PLIST_ARRAY node. + * + * @param node The node of type #PLIST_ARRAY. + * @param iter Iterator of the array + * @param item Location to store the item. The caller must *not* free the + * returned item. Will be set to NULL when no more items are left + * to iterate. + */ + void plist_array_next_item(plist_t node, plist_array_iter iter, plist_t *item); + + + /******************************************** + * * + * Dictionary functions * + * * + ********************************************/ + + /** + * Get size of a #PLIST_DICT node. + * + * @param node the node of type #PLIST_DICT + * @return size of the #PLIST_DICT node + */ + uint32_t plist_dict_get_size(plist_t node); + + /** + * Create an iterator of a #PLIST_DICT node. + * The allocated iterator should be freed with the standard free function. + * + * @param node The node of type #PLIST_DICT. + * @param iter Location to store the iterator for the dictionary. + */ + void plist_dict_new_iter(plist_t node, plist_dict_iter *iter); + + /** + * Increment iterator of a #PLIST_DICT node. + * + * @param node The node of type #PLIST_DICT + * @param iter Iterator of the dictionary + * @param key Location to store the key, or NULL. The caller is responsible + * for freeing the the returned string. + * @param val Location to store the value, or NULL. The caller must *not* + * free the returned value. Will be set to NULL when no more + * key/value pairs are left to iterate. + */ + void plist_dict_next_item(plist_t node, plist_dict_iter iter, char **key, plist_t *val); + + /** + * Get key associated key to an item. Item must be member of a dictionary. + * + * @param node the item + * @param key a location to store the key. The caller is responsible for freeing the returned string. + */ + void plist_dict_get_item_key(plist_t node, char **key); + + /** + * Get the nth item in a #PLIST_DICT node. + * + * @param node the node of type #PLIST_DICT + * @param key the identifier of the item to get. + * @return the item or NULL if node is not of type #PLIST_DICT. The caller should not free + * the returned node. + */ + plist_t plist_dict_get_item(plist_t node, const char* key); + + /** + * Get key node associated to an item. Item must be member of a dictionary. + * + * @param node the item + * @return the key node of the given item, or NULL. + */ + plist_t plist_dict_item_get_key(plist_t node); + + /** + * Set item identified by key in a #PLIST_DICT node. + * The previous item identified by key will be freed using #plist_free. + * If there is no item for the given key a new item will be inserted. + * + * @param node the node of type #PLIST_DICT + * @param item the new item associated to key + * @param key the identifier of the item to set. + */ + void plist_dict_set_item(plist_t node, const char* key, plist_t item); + + /** + * Insert a new item into a #PLIST_DICT node. + * + * @deprecated Deprecated. Use plist_dict_set_item instead. + * + * @param node the node of type #PLIST_DICT + * @param item the new item to insert + * @param key The identifier of the item to insert. + */ + PLIST_WARN_DEPRECATED("use plist_dict_set_item instead") + void plist_dict_insert_item(plist_t node, const char* key, plist_t item); + + /** + * Remove an existing position in a #PLIST_DICT node. + * Removed position will be freed using #plist_free + * + * @param node the node of type #PLIST_DICT + * @param key The identifier of the item to remove. Assert if identifier is not present. + */ + void plist_dict_remove_item(plist_t node, const char* key); + + /** + * Merge a dictionary into another. This will add all key/value pairs + * from the source dictionary to the target dictionary, overwriting + * any existing key/value pairs that are already present in target. + * + * @param target pointer to an existing node of type #PLIST_DICT + * @param source node of type #PLIST_DICT that should be merged into target + */ + void plist_dict_merge(plist_t *target, plist_t source); + + + /******************************************** + * * + * Getters * + * * + ********************************************/ + + /** + * Get the parent of a node + * + * @param node the parent (NULL if node is root) + */ + plist_t plist_get_parent(plist_t node); + + /** + * Get the #plist_type of a node. + * + * @param node the node + * @return the type of the node + */ + plist_type plist_get_node_type(plist_t node); + + /** + * Get the value of a #PLIST_KEY node. + * This function does nothing if node is not of type #PLIST_KEY + * + * @param node the node + * @param val a pointer to a C-string. This function allocates the memory, + * caller is responsible for freeing it. + */ + void plist_get_key_val(plist_t node, char **val); + + /** + * Get the value of a #PLIST_STRING node. + * This function does nothing if node is not of type #PLIST_STRING + * + * @param node the node + * @param val a pointer to a C-string. This function allocates the memory, + * caller is responsible for freeing it. Data is UTF-8 encoded. + */ + void plist_get_string_val(plist_t node, char **val); + + /** + * Get a pointer to the buffer of a #PLIST_STRING node. + * + * @note DO NOT MODIFY the buffer. Mind that the buffer is only available + * until the plist node gets freed. Make a copy if needed. + * + * @param node The node + * @param length If non-NULL, will be set to the length of the string + * + * @return Pointer to the NULL-terminated buffer. + */ + const char* plist_get_string_ptr(plist_t node, uint64_t* length); + + /** + * Get the value of a #PLIST_BOOLEAN node. + * This function does nothing if node is not of type #PLIST_BOOLEAN + * + * @param node the node + * @param val a pointer to a uint8_t variable. + */ + void plist_get_bool_val(plist_t node, uint8_t * val); + + /** + * Get the value of a #PLIST_UINT node. + * This function does nothing if node is not of type #PLIST_UINT + * + * @param node the node + * @param val a pointer to a uint64_t variable. + */ + void plist_get_uint_val(plist_t node, uint64_t * val); + + /** + * Get the value of a #PLIST_REAL node. + * This function does nothing if node is not of type #PLIST_REAL + * + * @param node the node + * @param val a pointer to a double variable. + */ + void plist_get_real_val(plist_t node, double *val); + + /** + * Get the value of a #PLIST_DATA node. + * This function does nothing if node is not of type #PLIST_DATA + * + * @param node the node + * @param val a pointer to an unallocated char buffer. This function allocates the memory, + * caller is responsible for freeing it. + * @param length the length of the buffer + */ + void plist_get_data_val(plist_t node, char **val, uint64_t * length); + + /** + * Get a pointer to the data buffer of a #PLIST_DATA node. + * + * @note DO NOT MODIFY the buffer. Mind that the buffer is only available + * until the plist node gets freed. Make a copy if needed. + * + * @param node The node + * @param length Pointer to a uint64_t that will be set to the length of the buffer + * + * @return Pointer to the buffer + */ + const char* plist_get_data_ptr(plist_t node, uint64_t* length); + + /** + * Get the value of a #PLIST_DATE node. + * This function does nothing if node is not of type #PLIST_DATE + * + * @param node the node + * @param sec a pointer to an int32_t variable. Represents the number of seconds since 01/01/2001. + * @param usec a pointer to an int32_t variable. Represents the number of microseconds + */ + void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec); + + /** + * Get the value of a #PLIST_UID node. + * This function does nothing if node is not of type #PLIST_UID + * + * @param node the node + * @param val a pointer to a uint64_t variable. + */ + void plist_get_uid_val(plist_t node, uint64_t * val); + + + /******************************************** + * * + * Setters * + * * + ********************************************/ + + /** + * Set the value of a node. + * Forces type of node to #PLIST_KEY + * + * @param node the node + * @param val the key value + */ + void plist_set_key_val(plist_t node, const char *val); + + /** + * Set the value of a node. + * Forces type of node to #PLIST_STRING + * + * @param node the node + * @param val the string value. The string is copied when set and will be + * freed by the node. + */ + void plist_set_string_val(plist_t node, const char *val); + + /** + * Set the value of a node. + * Forces type of node to #PLIST_BOOLEAN + * + * @param node the node + * @param val the boolean value + */ + void plist_set_bool_val(plist_t node, uint8_t val); + + /** + * Set the value of a node. + * Forces type of node to #PLIST_UINT + * + * @param node the node + * @param val the unsigned integer value + */ + void plist_set_uint_val(plist_t node, uint64_t val); + + /** + * Set the value of a node. + * Forces type of node to #PLIST_REAL + * + * @param node the node + * @param val the real value + */ + void plist_set_real_val(plist_t node, double val); + + /** + * Set the value of a node. + * Forces type of node to #PLIST_DATA + * + * @param node the node + * @param val the binary buffer. The buffer is copied when set and will + * be freed by the node. + * @param length the length of the buffer + */ + void plist_set_data_val(plist_t node, const char *val, uint64_t length); + + /** + * Set the value of a node. + * Forces type of node to #PLIST_DATE + * + * @param node the node + * @param sec the number of seconds since 01/01/2001 + * @param usec the number of microseconds + */ + void plist_set_date_val(plist_t node, int32_t sec, int32_t usec); + + /** + * Set the value of a node. + * Forces type of node to #PLIST_UID + * + * @param node the node + * @param val the unsigned integer value + */ + void plist_set_uid_val(plist_t node, uint64_t val); + + + /******************************************** + * * + * Import & Export * + * * + ********************************************/ + + /** + * Export the #plist_t structure to XML format. + * + * @param plist the root node to export + * @param plist_xml a pointer to a C-string. This function allocates the memory, + * caller is responsible for freeing it. Data is UTF-8 encoded. + * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer. + */ + void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length); + + /** + * Frees the memory allocated by plist_to_xml(). + * + * @param plist_xml The buffer allocated by plist_to_xml(). + */ + void plist_to_xml_free(char *plist_xml); + + /** + * Export the #plist_t structure to binary format. + * + * @param plist the root node to export + * @param plist_bin a pointer to a char* buffer. This function allocates the memory, + * caller is responsible for freeing it. + * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer. + */ + void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length); + + /** + * Frees the memory allocated by plist_to_bin(). + * + * @param plist_bin The buffer allocated by plist_to_bin(). + */ + void plist_to_bin_free(char *plist_bin); + + /** + * Import the #plist_t structure from XML format. + * + * @param plist_xml a pointer to the xml buffer. + * @param length length of the buffer to read. + * @param plist a pointer to the imported plist. + */ + void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist); + + /** + * Import the #plist_t structure from binary format. + * + * @param plist_bin a pointer to the xml buffer. + * @param length length of the buffer to read. + * @param plist a pointer to the imported plist. + */ + void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist); + + /** + * Import the #plist_t structure from memory data. + * This method will look at the first bytes of plist_data + * to determine if plist_data contains a binary or XML plist. + * + * @param plist_data a pointer to the memory buffer containing plist data. + * @param length length of the buffer to read. + * @param plist a pointer to the imported plist. + */ + void plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist); + + /** + * Test if in-memory plist data is binary or XML + * This method will look at the first bytes of plist_data + * to determine if plist_data contains a binary or XML plist. + * This method is not validating the whole memory buffer to check if the + * content is truly a plist, it's only using some heuristic on the first few + * bytes of plist_data. + * + * @param plist_data a pointer to the memory buffer containing plist data. + * @param length length of the buffer to read. + * @return 1 if the buffer is a binary plist, 0 otherwise. + */ + int plist_is_binary(const char *plist_data, uint32_t length); + + /******************************************** + * * + * Utils * + * * + ********************************************/ + + /** + * Get a node from its path. Each path element depends on the associated father node type. + * For Dictionaries, var args are casted to const char*, for arrays, var args are caster to uint32_t + * Search is breath first order. + * + * @param plist the node to access result from. + * @param length length of the path to access + * @return the value to access. + */ + plist_t plist_access_path(plist_t plist, uint32_t length, ...); + + /** + * Variadic version of #plist_access_path. + * + * @param plist the node to access result from. + * @param length length of the path to access + * @param v list of array's index and dic'st key + * @return the value to access. + */ + plist_t plist_access_pathv(plist_t plist, uint32_t length, va_list v); + + /** + * Compare two node values + * + * @param node_l left node to compare + * @param node_r rigth node to compare + * @return TRUE is type and value match, FALSE otherwise. + */ + char plist_compare_node_value(plist_t node_l, plist_t node_r); + + #define _PLIST_IS_TYPE(__plist, __plist_type) (__plist && (plist_get_node_type(__plist) == PLIST_##__plist_type)) + + /* Helper macros for the different plist types */ + #define PLIST_IS_BOOLEAN(__plist) _PLIST_IS_TYPE(__plist, BOOLEAN) + #define PLIST_IS_UINT(__plist) _PLIST_IS_TYPE(__plist, UINT) + #define PLIST_IS_REAL(__plist) _PLIST_IS_TYPE(__plist, REAL) + #define PLIST_IS_STRING(__plist) _PLIST_IS_TYPE(__plist, STRING) + #define PLIST_IS_ARRAY(__plist) _PLIST_IS_TYPE(__plist, ARRAY) + #define PLIST_IS_DICT(__plist) _PLIST_IS_TYPE(__plist, DICT) + #define PLIST_IS_DATE(__plist) _PLIST_IS_TYPE(__plist, DATE) + #define PLIST_IS_DATA(__plist) _PLIST_IS_TYPE(__plist, DATA) + #define PLIST_IS_KEY(__plist) _PLIST_IS_TYPE(__plist, KEY) + #define PLIST_IS_UID(__plist) _PLIST_IS_TYPE(__plist, UID) + + /*@}*/ + +#ifdef __cplusplus +} +#endif +#endif diff --git a/test.php b/test.php new file mode 100644 index 0000000..419ab4b --- /dev/null +++ b/test.php @@ -0,0 +1,19 @@ +