Sideloader icon indicating copy to clipboard operation
Sideloader copied to clipboard

The process cannot access the file because it is being used by another process

Open maximedrn opened this issue 1 year ago • 23 comments

Hi, I'm trying to use Sideloader on Windows 11 but I keep getting this Botan related error: Invalid argument: randomInteger: invalid min/max values. I'm not a D-expert so I have no idea why this error occurs 😕. My device is connected via usbmuxd and detected, the error occurs during certificate generation.

Here are the full prompt logs:

C:\Program Files\Sideloader>.\sideloader.exe install <IPA_PATH> -i
cli_frontend INFO  2024-04-03T11:10:14.631 Logging in...
cli_frontend INFO  2024-04-03T11:10:14.631 Please enter your account informations. They will only be sent to Apple servers. 
cli_frontend INFO  2024-04-03T11:10:14.631 See it for yourself at https://github.com/Dadoum/Sideloader/

Apple ID: <email>
21F2D4AD2D0 [/!\ The password will appear in clear text in the terminal]: <password>

server.developersession INFO  2024-04-03T11:10:28.556 Creating DeveloperSession for <email>...
server.appleaccount INFO  2024-04-03T11:10:28.556 Logging in...
server.developersession INFO  2024-04-03T11:10:29.869 DeveloperSession created successfully.
install INFO  2024-04-03T11:10:29.885 Initiating connection the device (UUID: <id>)

Generating a certificate for Sideloader |##########                      | 33/100            
cli_frontend ERROR 2024-04-03T11:10:31.979 botan.utils.exceptn.InvalidArgument at 
C:\Users\runneradmin\AppData\Local\dub\packages\botan-1.13.6\botan\source\botan\math\bigint\bigint.d:1083: 
Invalid argument: randomInteger: invalid min/max values

maximedrn avatar Apr 03 '24 09:04 maximedrn

Yeah the automated build doesn't work for some reason. I haven't got time to investigate but in some other issue I built it manually. you can download that one which should work.

Dadoum avatar Apr 03 '24 10:04 Dadoum

Thanks, I'll give it a try :) I generated my own key and placed it in keys/<hex_of_apple_id>/key.pem but the script is not able to load it. The RNG is somehow broken in source/sideload/certificateidentity.d

maximedrn avatar Apr 03 '24 10:04 maximedrn

Sorry to ask again @Dadoum, but I get this error when trying to install SideStore:

> .\sideloader.exe install SideStore.ipa -i --debug

Creating App IDs for the application |##############                  | 44/100                
sideload DEBUG 2024-04-03T15:01:08.731 App IDs needed: com.SideStore.SideStore.N496ZT279S, com.SideStore.SideStore.N496ZT279S.AltWidget

Installing the application on the device (Transfer) |############################### | 97/100            
cli_frontend ERROR 2024-04-03T15:01:15.669 sideload.AppInstallationException at ../../source/sideload/package.d:215: 
Cannot install the application on the device! APIInternalError: Error Domain=IXErrorDomain Code=13 
"Failed to get bundle ID from /private/var/mobile/Media/PublicStaging\SideStore.app" UserInfo={NSLocalizedDescription=
Failed to get bundle ID from /private/var/mobile/Media/PublicStaging\SideStore.app, FunctionName=
+[IXPlaceholder _placeholderForBundle:client:withParent:installType:metadata:placeholderType:mayBeDeltaPackage:error:], 
SourceFileLine=691, NSLocalizedFailureReason=Missing bundle ID.} (-1)
            
cli_frontend DEBUG 2024-04-03T15:01:15.675 Full exception: 
sideload.AppInstallationException@../../source/sideload/package.d(215): Cannot install the application on the device! 
APIInternalError: Error Domain=IXErrorDomain Code=13 "Failed to get bundle ID from 
/private/var/mobile/Media/PublicStaging\SideStore.app" UserInfo={NSLocalizedDescription=Failed to get bundle ID from 
/private/var/mobile/Media/PublicStaging\SideStore.app, FunctionName=+[IXPlaceholder 
_placeholderForBundle:client:withParent:installType:metadata:placeholderType:mayBeDeltaPackage:error:], SourceFileLine=691, 
NSLocalizedFailureReason=Missing bundle ID.} (-1)

Is there anything to do with the IPAs before installing them?

maximedrn avatar Apr 03 '24 13:04 maximedrn

Oh I think I fixed the issue in the latest commit.

Dadoum avatar Apr 03 '24 20:04 Dadoum

Oh I think I fixed the issue in the latest commit.

But the error Invalid argument : randomInteger : invalid min/max values is still present in the latest binaries.. Can you provide a fix for this error?

maximedrn avatar Apr 03 '24 21:04 maximedrn

Oh yeah I forgot about that ^^'

Dadoum avatar Apr 03 '24 21:04 Dadoum

The error is caused by the output value of RandomNumberGenerator.makeRng(): https://github.com/Dadoum/Sideloader/blob/707a15d90f48b5f492fe5dc056a8be2017fa89f8/source/sideload/certificateidentity.d#L49

Or at least, the error occurs here: https://github.com/Dadoum/Sideloader/blob/707a15d90f48b5f492fe5dc056a8be2017fa89f8/source/sideload/certificateidentity.d#L49-L80

maximedrn avatar Apr 03 '24 21:04 maximedrn

The weird thing is that it doesn't happen with builds made on my computer. I will attempt to update the compiler to see if it was due to that (but I don't think it was).

thank you for the investigation.

Dadoum avatar Apr 03 '24 21:04 Dadoum

The new LDC2 version makes it work! ~How long does it take to sign the package? I've been stuck at 79% for a few minutes~

Moreover, if the installation fails, the temporary directory of the unzipped IPA persists in the Windows temp directory, hence the following error on a new attempt:

Full exception: std.file.FileException@std\file.d(885): 
C:\Users\Maxime\AppData\Local\Temp\
SideStore.ipa\Payload\SideStore.app\Frameworks\AltStoreCore.frameworkAltStoreCore: 
The process cannot access the file because it is being used by another process.

Perhaps you should rename the folder to avoid this ;)

maximedrn avatar Apr 03 '24 21:04 maximedrn

The folder should be removed at each run. That's weird.

And signing should be fast, so it probably froze.

Dadoum avatar Apr 03 '24 22:04 Dadoum

It is now fixed :) Thanks for your quick help 🫶

maximedrn avatar Apr 03 '24 22:04 maximedrn

Thank you for your very detailed comments on the issues. <3

Dadoum avatar Apr 03 '24 22:04 Dadoum

Moreover, if the installation fails, the temporary directory of the unzipped IPA persists in the Windows temp directory, hence the following error on a new attempt:

Full exception: std.file.FileException@std\file.d(885): 
C:\Users\Maxime\AppData\Local\Temp\
SideStore.ipa\Payload\SideStore.app\Frameworks\AltStoreCore.frameworkAltStoreCore: 
The process cannot access the file because it is being used by another process.

This error occurs for some IPAs, depending on their structure. I tried to install this IPA: https://github.com/pkuxw/YTMusicUltimate/releases/tag/YTMusicUltimate-v1, and I keep getting this error. Even when deleting temporary files and folders, the script seems to be trying to access the same file from two parallel processes. Only SideStore installs as it should, even if the application doesn't work as the developers claim (the file extracted from jitterbugpair isn't read correctly by the application, the VPN doesn't work and the application crashes after 20 seconds 🫠.)


By the way, it would be really cool if your project evolved like AltServer but with the advantages of working on all platforms, with wifi-refresh (maybe netmuxd could be added?), but without the bloatwares that are iCloud and iTunes

maximedrn avatar Apr 04 '24 10:04 maximedrn

did my new fix work?

Dadoum avatar Apr 06 '24 11:04 Dadoum

did my new fix work?

Yes it does :)

maximedrn avatar Apr 06 '24 18:04 maximedrn

the file extracted from jitterbugpair isn't read correctly by the application

Sideloader has a tool to install the pairing file automatically!

Dadoum avatar Apr 06 '24 20:04 Dadoum

the file extracted from jitterbugpair isn't read correctly by the application

Sideloader has a tool to install the pairing file automatically!

It worked the first time, but after SideStore requests it, it's unable to connect to the device, so refreshing via the custom VPN doesn't work. That's why it would be great if your tool could refresh apps (and through wifi for perfection!).

I don't know if wifi-refresh is possible on Windows without iTunes: I've uninstalled it but libmobiledevice, usbmuxd or netmuxd do not detect my iPhone even with Bonjour. It should be possible on Linux using usbmuxd2 (https://github.com/tihmstar/usbmuxd2) but it is only for Linux.

maximedrn avatar Apr 06 '24 21:04 maximedrn

I don't know if wifi-refresh is possible on Windows without iTunes

I could take 3utools approach: download iTunes setup and extract the driver from it. It would require the user to have administration privileges to install it though. Also maybe wifi refresh can be done just with the driver shipped by default on Windows 11 (but I don't think pairing would be possible, though I still have to check with a netmuxd build with usb support enabled to see if that driver suffices).

Dadoum avatar Apr 06 '24 21:04 Dadoum

download iTunes setup and extract the driver from it.

I installed Apple Mobile Device and Bonjour from the iTunes executable, the first one is required for usbmuxd; and Bonjour is supposed to enable wifi sync, but it seems that none of the tools that work(ed) under Linux (netmuxd, etc) work under Windows: only iTunes is able to detect the iPhone (that's what AltServer uses for wifi sync at the moment)

maximedrn avatar Apr 06 '24 21:04 maximedrn

was the driver running when you tried? There is an entry to enable in services.msc if I recall correctly.

Dadoum avatar Apr 06 '24 21:04 Dadoum

Both services are enabled and working, but nothing happens with .\device_id.exe -n

maximedrn avatar Apr 06 '24 21:04 maximedrn

I will maybe some day investigate the possibility to add a driver based on libusb (that would still require admin rights but not infringe any Apple's IP) and zeroconf (for wireless communication). But that won't be soon for sure!

Dadoum avatar Apr 06 '24 22:04 Dadoum

Both services are enabled and working, but nothing happens with .\device_id.exe -n

Just fixed it.. Apple Application Support from iCloud is also required

maximedrn avatar Apr 06 '24 22:04 maximedrn