-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
Support local Anisette generation #2
Comments
I doubt this can be included in the pypi package, since building pyprovision requires a D compiler which is not really a default install usually. |
I have don't have much experience with lower-lever languages, but I was actually messing with this yesterday and it's pretty simple to build a python wheel that includes libprovision.so. The downside is that it still relies on externally installed libraries; I did briefly try to "repair" the wheel using https://github.com/pypa/auditwheel, but it wasn't able to find all external dependencies. That would still require a separate wheel for each architecture / OS / python version though, and would probably be tricky in terms of licensing, to say the least. That project looks quite interesting though, worth keeping an eye at! |
I've just made https://github.com/JayFoxRox/pyprovision-uc public.
I made this when I wasn't able to make pyprovision / D compiler work on my setup within a couple of hours. It's still unfinished and still needs to be cleaned up. I had a lot of problems with the There's also good chances that there's issues with endianess or 32-bit (because I'm using host There's also a chance that the VM will become unstable over time. I also plan to modify the API a bit in the future - I don't like how it operates on a real filesystem. |
Oh that's really cool! I just tried it out myself and while I did have to fix some things (create the directories, some |
I was able to make dadoum (D written) work in my dockerfile: FROM python:3.11-slim
RUN pip install --upgrade pip
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install dub git gcc -y
RUN git clone https://github.com/Dadoum/pyprovision /tmp/pyprovision
RUN cd /tmp/pyprovision && pip install .
... And I managed (I believe) to write the LocalAnisetteProvider: class LocalAnisetteProvider(BaseAnisetteProvider):
"""Anisette provider. Generates headers without a remote server using pyprovision."""
def __init__(self, libary_path, provisioning_path, device_json_path):
self.adi = ADI(libary_path)
self.adi.provisioning_path = provisioning_path
self.device = Device(device_json_path)
if not self.device.initialized:
# Pretend to be a MacBook Pro
self.device.server_friendly_description = "<MacBookPro13,2> <macOS;13.1;22C65> <com.apple.AuthKit/1 (com.apple.dt.Xcode/3594.4.19)>"
self.device.unique_device_identifier = str(uuid.uuid4()).upper()
self.device.adi_identifier = secrets.token_hex(8).lower()
self.device.local_user_uuid = secrets.token_hex(32).upper()
self.adi.identifier = self.device.adi_identifier
self.dsid = c_ulonglong(-2).value
self.provisioning_session = ProvisioningSession(self.adi, self.device)
self.provisioning_session.provision(self.dsid)
self.otpObj = self.adi.request_otp(self.dsid)
@property
@override
def otp(self) -> str:
return self.otpObj.one_time_password
@property
@override
def machine(self) -> str:
return self.otpObj.machine_identifier
@override
async def close(self) -> None:
"""See `BaseAnisetteProvider.close`_.""" Based of @Dadoum's example... but I get this error:
Any clue? I know that this is not even implemented, but maybe knows what this error indicates. Also, If what I did can help you, I can try and open a PR... |
@hkfuertes you might want to change your password, people subscribed to this got it in their email. |
Thank you! It was a mistake... I didn't thought of email subscription... Edit: Changed!, @biemster thank you for the heads up! |
I think I'm able to answer myself: FindMy.py/findmy/reports/anisette.py Line 71 in d82b1fb
😆 |
Oh yes indeed, sorry for taking so long to respond. But glad you figured it out yourself! The issue here is not necessarily getting local anisette to work, but rather packaging it so that people don't need a local D compiler. Unless your solution works outside of Docker as well? Edit: you could also use anisette-v3-server in a separate docker container if you're deploying FindMy.py in docker anyway; that way you can simply use Also also, if you have a functional API implementation, let me know because I'm also interested ;-) |
Ohhh I'm way behind you guys... hahahaha I just now how to follow steps and connect dots, I dont really understand Anisette or Findmy... hahahahah. The only reason I tried the local anisette is just to try... you see, I tried remote anisete with the anisette server in the same docker-compose, and it worked fine... but only after first login. Once I restart the server, for some reason, I needed to re-login. I was hoping that local anisette would solve this issue... |
Hey @JayFoxRox, I'd finally like to tackle this issue and I think your implementation is currently looking the most promising in terms of flexibility and ease of integration. My plan is to release a separate python package with a nice API to act as an anisette provider. Just checking in to see if that'd be OK with you as 80-90% of it will probably be consisting of your code (credit will be given, of course!) |
Sure, do whatever you want with it 👍 Consider it MIT licensed for now, but I'll happily add another license to suit your needs. |
Perfect, thanks! MIT is fine, I don't really care too much about the exact license specifics. Just want the package to be out there so it can be used :-) |
Hi @JayFoxRox , I noticed that |
It uses an "Allocator"-class which doesn't even have the option to free pages: https://github.com/JayFoxRox/pyprovision-uc/blob/70254670674c7e54d6e4a07483248ed124aa016f/src/pyprovision/__init__.py#L168 Note that this is a VM which runs Apples Android code (specifically a very small portion of it). However, I don't think restarting the VM would work yet, because https://github.com/JayFoxRox/pyprovision-uc/blob/70254670674c7e54d6e4a07483248ed124aa016f/src/pyprovision/__init__.py#L737 would only instantiate it once (so the malloc area would be shared by all VMs and it would be impossible to reset it). But yes, if you keep calling functions in the VM there'd be problems - it hasn't been designed to run more than a handful of calls. The allocator actually uses a fixed amount of space: https://github.com/JayFoxRox/pyprovision-uc/blob/70254670674c7e54d6e4a07483248ed124aa016f/src/pyprovision/__init__.py#L144 . So instead of leaking memory, you'd just run out of memory (if the functions you call in the VM actually do malloc on each call). I'm also not sure if it's enough to lose the reference to the ADI to actually free the unicorn-engine machine, so there might be an actual memory leak there (leaking the the unicorn-engine memory). |
Ta-daaa: https://github.com/malmeloo/Anisette.py It works, using basically the same code as @JayFoxRox wrote, but in a nice API. There are still a couple of things to fix and finish, but it appears to work perfectly so far. My intention is to also add a small command-line interface to this tool to quickly create and destroy provisioning sessions and save them to disk. Like anisette-v3-server, but without the server, and mostly suited for developers. And I think it would be nice to be able to quickly spin up a server as well. Also like anisette-v3-server, but without Docker :-). It could even work with None of the stability issues mentioned above have been fixed yet, except for the dangling malloc allocator. I'm curious to see how long a single instance of the VM will survive until it comes crashing down. |
A quick progress update: I managed to implement However, I can confirm that unicorn appears to release all system memory when the VM is garbage collected by Python. So I've configured my wrapper to simply destroy and recreate the VM once any memory region has been > 50% allocated, which might be a band-aid fix but is totally fine IMO considering how rarely it occurs. And we can always adjust the size of the memory region to tweak that frequency. I've been benchmarking it and am able to hit ~40 header requests per second on my laptop, with the entire process consuming roughly 75 MB of system memory. I think that's very respectable, so my next focus will probably be on actually publishing the library so it can be integrated into FindMy.py. I've also set up a Cloudflare worker to expose a URL that creates a bundle consisting of only the necessary libraries, which should make it very easy to get started. That bundle is only a few megabytes, which is tiny compared to the ~130 MB of the full Apple Music APK. |
Support local anisette header generation using pyprovision.
The text was updated successfully, but these errors were encountered: