-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Apply ((packed)) attribute to USB descriptor structures. #522
base: master
Are you sure you want to change the base?
Conversation
Useful for using sizeof(/* structure */) when setting bLength so that you don't accidentally put the wrong number and ensuring memory layouts follow the standard.
If I recall correctly, all structs are already packed under the eZ80 C ABI because the eZ80 is an 8-bit processor with no alignment requirements. So adding the packed attribute shouldn't change |
@commandblockguy That makes a lot more sense. I don't have any proof that the size is incorrect when using sizeof(), just that seeing visual studio code report the wrong size calculation when hovering over variables and such threw me off. For peace of mind I went in myself and added attribute((packed)) to not only get the right size but to satisfy my assumption that the ez80 wouldn't always handle those structures without any arbitrary byte alignment. I don't know why I thought that adding that to the header would make a difference, obviously the header isn't compiled in the final binary. I guess the only other reason to add that in would to be let people interested in learning about USB structures know that these structures must have no byte padding but there's plenty of information out there that definitely already says that so, eh. While I'm here, do you happen to know if I can code a libload library in C and how I would set that up using the toolchain? Any information I can find on a guide or some kind of template would be great. If I need to open up a discussion I definitely will. |
There's not currently an easy way to write a library in C. A few people have made C libraries by manually pasting the assembly code the compiler outputs (removing the linker directives) into an assembly file in-tree for the toolchain, but that's not a recommended or officially supported workflow. |
Ever since I started to understand how to use usbdrvce, I had an interest in seeing if I could communicate with iPhones in recovery/dfu/wtf/port dfu mode. The inspiration came from libimobiledevice, specifically libirecovery, in which I wanted to create a lightweight version of it and control some apple products from my calculator, because...why not?? I've also always been super interested in "hacking" iDevices; jailbreaks, pwndfu, downgrades, etc., so this was something that I thought would be really cool, to make my own little library for it. I don't know the slightest bit of assembly so I knew my only option would be to try to write it in C. I got it working pretty nicely. I followed the path of the actual library (which used libusb and IOKit) and just "translated" it to fit with what usbdrvce gave me and it worked. It could reboot my iPhone 3G, iPhone 4, iPhone SE, and my 16 Pro...just not the M1 Macs, probably since the power doesn't work that way for them, i dont know. Here's the video that I so professionally recorded showing it off. |
Useful for using sizeof(/* structure */) when setting bLength so that you don't accidentally put the wrong number and ensuring memory layouts follow the standard.