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

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

Open
maximedrn opened this issue Apr 3, 2024 · 23 comments

Comments

@maximedrn
Copy link

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
@Dadoum
Copy link
Owner

Dadoum commented Apr 3, 2024

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.

@maximedrn
Copy link
Author

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
Copy link
Author

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?

Dadoum added a commit that referenced this issue Apr 3, 2024
@Dadoum
Copy link
Owner

Dadoum commented Apr 3, 2024

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

@Dadoum Dadoum closed this as completed in b9fbb01 Apr 3, 2024
Dadoum added a commit that referenced this issue Apr 3, 2024
@maximedrn
Copy link
Author

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?

@Dadoum
Copy link
Owner

Dadoum commented Apr 3, 2024

Oh yeah I forgot about that ^^'

@Dadoum Dadoum reopened this Apr 3, 2024
@maximedrn
Copy link
Author

The error is caused by the output value of RandomNumberGenerator.makeRng():

rng = RandomNumberGenerator.makeRng();

Or at least, the error occurs here:

rng = RandomNumberGenerator.makeRng();
auto teams = appleAccount.listTeams().unwrap();
auto team = teams[0];
if (file.exists(keyFile)) {
log.debug_("A key has already been generated");
privateKey = RSAPrivateKey(loadKey(keyFile, rng));
log.debug_("Checking if any certificate online is matching the private key...");
auto certificates = appleAccount.listAllDevelopmentCerts!iOS(team).unwrap();
auto sideloaderCertificates = certificates.find!((cert) => cert.machineName == applicationName);
if (sideloaderCertificates.length != 0) {
Vector!ubyte certContent;
Vector!ubyte ourPublicKey = privateKey.x509SubjectPublicKey();
foreach (cert; sideloaderCertificates) {
certContent = Vector!ubyte(cert.certContent);
auto x509cert = X509Certificate(certContent, false);
if (x509cert.subjectPublicKey().x509SubjectPublicKey() == ourPublicKey) {
log.debug_("Matching certificate found.");
certificate = X509Certificate(Vector!ubyte(certContent), false);
return;
}
// +/
}
}
} else {
log.debug_("Generating a new RSA key");
privateKey = RSAPrivateKey(rng, 2048);
file.write(keyFile, botan.pubkey.pkcs8.PEM_encode(privateKey));
}

@Dadoum
Copy link
Owner

Dadoum commented Apr 3, 2024

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.

@maximedrn
Copy link
Author

maximedrn commented Apr 3, 2024

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 ;)

@Dadoum
Copy link
Owner

Dadoum commented Apr 3, 2024

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

And signing should be fast, so it probably froze.

@maximedrn
Copy link
Author

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

@Dadoum
Copy link
Owner

Dadoum commented Apr 3, 2024

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

@maximedrn
Copy link
Author

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 maximedrn reopened this Apr 4, 2024
@maximedrn maximedrn changed the title Invalid argument: randomInteger: invalid min/max values The process cannot access the file because it is being used by another process Apr 4, 2024
maximedrn pushed a commit to maximedrn/Sideloader that referenced this issue Apr 4, 2024
Dadoum added a commit that referenced this issue Apr 5, 2024
@Dadoum
Copy link
Owner

Dadoum commented Apr 6, 2024

did my new fix work?

@maximedrn
Copy link
Author

did my new fix work?

Yes it does :)

@Dadoum
Copy link
Owner

Dadoum commented Apr 6, 2024

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

Sideloader has a tool to install the pairing file automatically!

@maximedrn
Copy link
Author

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.

@Dadoum
Copy link
Owner

Dadoum commented Apr 6, 2024

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).

@maximedrn
Copy link
Author

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)

@Dadoum
Copy link
Owner

Dadoum commented Apr 6, 2024

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

@maximedrn
Copy link
Author

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

@Dadoum
Copy link
Owner

Dadoum commented Apr 6, 2024

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!

@maximedrn
Copy link
Author

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

@Dadoum Dadoum reopened this Apr 6, 2024
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

No branches or pull requests

2 participants