Skip to content

Instantly share code, notes, and snippets.

@jzlka
Last active June 25, 2020 10:08
Show Gist options
  • Save jzlka/4dd39604af294f67d9ec9e78fc078b14 to your computer and use it in GitHub Desktop.
Save jzlka/4dd39604af294f67d9ec9e78fc078b14 to your computer and use it in GitHub Desktop.
USBApp build script
#!/bin/bash
# WARNING: still does not match against the usb. Needs to be further debugged with other pojects to find out what is wrong
VENDOR_ID_HEX=0xB27
VENDOR_ID_DEC=2855
PRODUCT_ID_HEX=0x603
PRODUCT_ID_DEC=1539
# Find your device IDs
#ioreg -p IOUSB -l -b | grep -E "@|idVendor|idProduct|bcdDevice"
# Log the messages
#log show --predicate 'sender == "sysextd" or sender CONTAINS "sc.knight"' --info --debug --last 1h # from Stuart Lynne
# Clone the project
git clone https://github.com/knightsc/USBApp
# Delete entitlements file from the project config
perl -pi -e 's/(CODE_SIGN_ENTITLEMENTS = ).*/$1"";/' USBApp/USBApp.xcodeproj/project.pbxproj
# Set ad-hoc certificate and manual code sign
perl -pi -e 's/(CODE_SIGN_STYLE = ).*/CODE_SIGN_IDENTITY = "-";\n\t\t\t\t$1Manual;/' USBApp/USBApp.xcodeproj/project.pbxproj
# Set empty provisioning profile
perl -pi -e 's/(SDKROOT = .*)/PROVISIONING_PROFILE_SPECIFIER = "";\n\t\t\t\t$1/' USBApp/USBApp.xcodeproj/project.pbxproj
# Change Vendor ID
#perl -i -0pse 's|(idVendor.*\n.*<integer>)0x[0-9]*|$1$id|g' -- -id=$VENDOR_ID_HEX USBApp/MyUserUSBInterfaceDriver/Info.plist
/usr/libexec/PlistBuddy -c "Set :IOKitPersonalities:MyUserUSBInterfaceDriver:idProduct $VENDOR_ID_DEC" USBApp/MyUserUSBInterfaceDriver/Info.plist
# Change Product ID
#perl -i -0pse 's|(idProduct.*\n.*<integer>)0x[0-9]*|$1$id|g' -- -id=$PRODUCT_ID_HEX USBApp/MyUserUSBInterfaceDriver/Info.plist
/usr/libexec/PlistBuddy -c "Set :IOKitPersonalities:MyUserUSBInterfaceDriver:idVendor $PRODUCT_ID_DEC" USBApp/MyUserUSBInterfaceDriver/Info.plist
# Fix entitlementis file
/usr/libexec/PlistBuddy -c "Delete :com.apple.developer.driverkit.transport.usb" \
-c "Add :com.apple.developer.driverkit.transport.usb array" \
-c "Add :com.apple.developer.driverkit.transport.usb:0 dict" \
-c "Add :com.apple.developer.driverkit.transport.usb:0:idProduct integer $PRODUCT_ID_DEC" \
-c "Add :com.apple.developer.driverkit.transport.usb:0:idVendor integer $VENDOR_ID_DEC" \
USBApp/MyUserUSBInterfaceDriver/MyUserUSBInterfaceDriver.entitlements
# Build the project into build folder in the current folder
pushd USBApp && xcodebuild -scheme USBApp build SYMROOT="$PWD/build" && popd
# Sign the bundle and the driver extension
codesign --force -vvvv --entitlements USBApp/USBApp/USBApp.entitlements -s - USBApp/build/Debug/USBApp.app
codesign --force -vvvv --entitlements USBApp/MyUserUSBInterfaceDriver/MyUserUSBInterfaceDriver.entitlements -s - USBApp/build/Debug/USBApp.app/Contents/Library/SystemExtensions/sc.knight.MyUserUSBInterfaceDriver.dext
# Copy the application
#cp -r USBApp/build/Debug/USBApp.app /Applications/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment