Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of com.apple.mobile.MCInstall #1029

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ethanatwork
Copy link

I implemented com.apple.mobile.MCInstall to manage configuration profiles under mcinstall.c, I also built a command-line utility making use of the implementation, called ideviceprovision. All three files are based on the implementation of com.apple.mobile.misagent. The other changed files are makefiles and documentation. Hope this is helpful.

@droll2571
Copy link

Hey Ethan,

I looked through your merge request and saw that the erase device command was still apart of the backup tool documentation, but the feature was reverted.

File in your changes:
**tools/idevicebackup2.c

The erase device command should be implemented as it goes hand in hand with your new feature. A device will need to be erased before setting it's cloud configuration with supervision.

Thanks,
Dalton

@ethanatwork
Copy link
Author

Hey Dalton,

Thanks for catching that! I was originally going to make the erasure command a separate pull request, but I never went back and created a pull request for it, looks like I missed the references to the command in the documentation when removing the code.

I updated **tools/idevicebackup2.c to include the erase command, as it is definitely helpful when preparing devices.
Hope this is useful to you!

Thanks,
Ethan

@beckietech
Copy link

Hi Ethan,

I'd like to check it out for testing, may I know how to do it? Thanks in adv.

@ethanatwork
Copy link
Author

Hi Ethan,

I'd like to check it out for testing, may I know how to do it? Thanks in adv.

You can build and install this branch the same way as master, where are you running into trouble?

@WHots
Copy link

WHots commented Sep 18, 2021

how can we download this binary ?

@fsinnes
Copy link

fsinnes commented Oct 8, 2021

@WilliamHottzz did you get this binary?

@WHots
Copy link

WHots commented Oct 8, 2021

@fsinnes no not yet. It doesn’t have sln to build it with visual studio … a binary would be helpful

@fsinnes
Copy link

fsinnes commented Oct 8, 2021

@ethanatwork I built the ORIGINAL libimobiledevice myself successfully FINALLY but that doesnt matter when I want this function above all, I tried the same process with this version and I get a few errors in MSYS

@ethanatwork if you dont mind can we get a windows binary of your version? That function to erase through the settings version without the firmware would complete my current project.

@ethanatwork
Copy link
Author

@ethanatwork I built the ORIGINAL libimobiledevice myself successfully FINALLY but that doesnt matter when I want this function above all, I tried the same process with this version and I get a few errors in MSYS

@ethanatwork if you dont mind can we get a windows binary of your version? That function to erase through the settings version with the firmware would complete my current project.

What error are you getting compiling this version that you don't get compiling from master? I don't use windows so I can't compile you a windows binary, but I can try to help get it to build for you.

@fsinnes
Copy link

fsinnes commented Oct 11, 2021

Ok so to help some other people out, here is the list of steps I took to successfully build the windows binaries for LIBIMOBILEDEVICE.

This method was built from several different threads I found where people were trying to get it to work. I don't know what it all does, I just know that it has worked for me after ALOT of trial and error. Whenever I ran into a problem, I would wipe out the MSYS2 installation and start over because I didn't know if leftover files were creating errors as well, still don't I guess.

All you need to do is install MSYS2 (it installs both 32 and 64 but we will be using 32) and I have found that your windows user name having a space in it is a huge issue. (ex: Foo Bar, rather than FooBar)

(using MSYS2 32)

pacman -S mingw-w64-i686-toolchain
pacman -S --needed base-devel msys2-devel
pacman -S openssl-devel
pacman -S libreadline-devel
pacman -S mingw-w64-i686-libusb
pacman -S mingw-w64-i686-libzip
pacman -S mingw-w64-i686-libxml2
pacman -S mingw-w64-i686-libssh2
pacman -S mingw-w64-i686-curl
pacman -S git
git clone https://github.com/libimobiledevice/libplist.git
cd libplist
./autogen.sh
make
make install
cd ~
git clone https://github.com/libimobiledevice/libimobiledevice-glue.git
cd libimobiledevice-glue
./autogen.sh
make

(Here I receive the following, I'm not sure if its an error I should be concerned about)

CC thread.lo
thread.c: In function 'thread_new':
thread.c:31:36: warning: cast between incompatible function types from 'thread_func_t' {aka 'void * (*)(void *)'} to 'DWORD (__attribute__((stdcall)) *)(void *)' {aka 'long unsigned int (__attribute__((stdcall)) *)(void *)'}
[-Wcast-function-type]
31 | HANDLE th = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread_func, data, 0, NULL); | ^

CC utils.lo
utils.c: In function 'stpcpy':
utils.c:58:9: warning: 'nonnull' argument 's1' compared to NULL [-Wnonnull-compare]
58 | if (s1 == NULL || s2 == NULL)
| ^
utils.c:58:23: warning: 'nonnull' argument 's2' compared to NULL [-Wnonnull-compare]
58 | if (s1 == NULL || s2 == NULL)
| ^

make install
cd ~
git clone https://github.com/libimobiledevice/libusbmuxd.git
cd libusbmuxd
./autogen.sh
make

(Here I receive the following, I'm not sure if its an error I should be concerned about)

CC libusbmuxd.lo
libusbmuxd.c:85:14: warning: declaration of 'stpncpy' shadows a built-in function [-Wshadow]
85 | static char* stpncpy(char *dst, const char *src, size_t len)
| ^~~~~~~

CCLD iproxy.exe
libtool: error: Could not determine the host path corresponding to
libtool: error: 'C:/msys64/mingw32/lib:C:/msys64/mingw32/bin:/home/test/libusbmuxd/src/.libs:/mingw32/lib:/mingw32/bin'
libtool: error: Continuing, but uninstalled executables may not work.

CCLD inetcat.exe
libtool: error: Could not determine the host path corresponding to
libtool: error: 'C:/msys64/mingw32/lib:C:/msys64/mingw32/bin:/home/test/libusbmuxd/src/.libs:/mingw32/lib:/mingw32/bin'
libtool: error: Continuing, but uninstalled executables may not work.

make install
cd ~

Now for the next part you will replace the repo reference to
git clone https://github.com/libimobiledevice/libimobiledevice.git
after the next "make install" you should have executable files, I cannot remember the link to the exact files but if you start a search in the MSYS64 folder for "ideviceinfo" you should find where it puts them all
I will be using the fork mentioned above in this next part

git clone https://github.com/ethanatwork/libimobiledevice.git
cd libimobiledevice
./autogen.sh
make

(Here is the error I get for the fork)

CC socket.lo
socket.c: In function '_sockaddr_in6_scope_id':
socket.c:361:6: warning: implicit declaration of function 'getifaddrs' [-Wimplicit-function-declaration]
361 | if (getifaddrs(&ifaddr) == -1) {
| ^~~~~~~~~~
socket.c:367:43: error: invalid use of undefined type 'struct ifaddrs'
367 | for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
| ^~
socket.c:369:10: error: invalid use of undefined type 'struct ifaddrs'
369 | if (ifa->ifa_addr == NULL) {
| ^~
socket.c:374:10: error: invalid use of undefined type 'struct ifaddrs'
374 | if (ifa->ifa_addr->sa_family != AF_INET6) {
| ^~
socket.c:379:11: error: invalid use of undefined type 'struct ifaddrs'
379 | if ((ifa->ifa_flags & IFF_UP) == 0) {
| ^~
socket.c:384:11: error: invalid use of undefined type 'struct ifaddrs'
384 | if ((ifa->ifa_flags & IFF_RUNNING) == 0) {
| ^~
socket.c:384:25: error: 'IFF_RUNNING' undeclared (first use in this function)
384 | if ((ifa->ifa_flags & IFF_RUNNING) == 0) {
| ^~~~~~~~~~~
socket.c:384:25: note: each undeclared identifier is reported only once for each function it appears in
socket.c:388:59: error: invalid use of undefined type 'struct ifaddrs'
388 | struct sockaddr_in6* addr_in = (struct sockaddr_in6*)ifa->ifa_addr;
| ^~
socket.c:412:11: error: invalid use of undefined type 'struct ifaddrs'
412 | if ((ifa->ifa_flags & IFF_LOOPBACK) != 0) {
| ^~
socket.c:430:2: warning: implicit declaration of function 'freeifaddrs' [-Wimplicit-function-declaration]
430 | freeifaddrs(ifaddr);
| ^~~~~~~~~~~

make install

I tried "make install" anyway and got the same error. Hope I was descriptive enough.

CC @ethanatwork @WilliamHottzz

@WHots
Copy link

WHots commented Oct 11, 2021

@ethanatwork

What file would we have to build? in MSYS2 i did gcc idevicebackup2.c -o erasedevice and it returns with

idevicebackup2.c:40:47: fatal error: libimobiledevice/libimobiledevice.h: No such file or directory
 #include <libimobiledevice/libimobiledevice.h>
                                               ^
compilation terminated.

Edit:

Or if it's easier could you kinda drop an explanation on what idevicebackup2 -erase is doing? I only skimmed through it and looks like it's creating a backup and possibly editing it? because I could probably just make a native windows binary if i know the steps on performing a reset.

Like a step-by-step how to perform the erase function.

@fsinnes
Copy link

fsinnes commented Oct 11, 2021

@WilliamHottzz I was under the impression there was no actual backup happening here, that we were just triggering the settings version of the "erase all data" function.

@WHots
Copy link

WHots commented Oct 11, 2021 via email

@fsinnes
Copy link

fsinnes commented Oct 11, 2021

@WilliamHottzz I've been thinking the same thing since I found your comments in the main branch, mine is spewkihecks#2640

@WHots
Copy link

WHots commented Oct 12, 2021

@ethanatwork

In your version for CMD_ERASE you have
mobilebackup2_send_message(mobilebackup2, "EraseDevice", NULL);

But in mobilebackup2.c the method is ...

mobilebackup2_send_message(mobilebackup2_client_t client, const char *message, plist_t options)
if (!client || !client->parent || (!message && !options))
        return MOBILEBACKUP2_E_INVALID_ARG;

    if (options && (plist_get_node_type(options) != PLIST_DICT)) {
        return MOBILEBACKUP2_E_INVALID_ARG;
    }

The third param plist_t options cannot be null ... this is the only issue im having, what goes in the third param?

@ethanatwork
Copy link
Author

It works for me with the options as null. Is that the line that the compiler errors on for you? If that's all that's preventing it from compiling you could try using an empty plist_t instead of null.

The erase command isn't creating a backup at all, it's just sending a message to Erase the device. Check out the code for changing the backup password to see another use of the mobilebackup2_send_message method.

Sorry I'm not on here more often, I'd be up for joining a discord to work on this stuff if you have one set up.

Hope this helps

@WHots
Copy link

WHots commented Oct 14, 2021 via email

@codehimanshu-lt
Copy link

How much time on average does this erase command take?
A rough idea (seconds, minutes, 10s of minutes) would be helpful.

Thanks in advance!

@ethanatwork
Copy link
Author

How much time on average does this erase command take?

A rough idea (seconds, minutes, 10s of minutes) would be helpful.

Thanks in advance!

Running the actual command takes seconds. The device will run a "erase all content and settings" which takes approximately 10 minutes or less. The device does not need to remain connected after the command is sent.

@ankit125664
Copy link

Hi ethana,
I want to use the functionality of the mcinstall module.But this functionality is not showing in main branch.Please guide me how to use it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants