实现过程
1.main函数中加入setuid(0);
2.新建脚本,修改脚本中的Root_Password为电脑登录密码。
3.需要build或profile两次,打包成deb,拷贝到手机安装(即可以root方式启动)【PS:因为xxx.app文件还没完全生成就会被拷贝过来了,所以需要build或profile两次,顺便问一下有什么好的解决方案没】
4.脚本实现了从xxx.app文件打包为deb;安装到手机后修改.app和可执行文件所有权为root.wheel,可执行文件设置提权标志位,设置6755权限。
Xcode脚本
- #main函数中加入setuid(0);
- #打包成deb,安装到/Applications/目录下
- #修改.app和可执行文件所有权为root.wheel,可执行文件设置提权标志位,设置6755权限。即可以root方式启动
- #需要build两次才能打出正确的包(因为.app文件还没完全生成就被拷贝过来了)
- #设置sudo密码
- Root_Password="xxx"
- Package_Path=${BUILT_PRODUCTS_DIR}/RunAsRootPackage
- #清理
- rm -f -r "${Package_Path}"
- rm -f -r "${Package_Path}.deb"
- #新建
- mkdir "${Package_Path}"
- mkdir "${Package_Path}/Applications"
- mkdir "${Package_Path}/DEBIAN"
- cp -R "${BUILT_PRODUCTS_DIR}/${PROJECT_NAME}.app" "${Package_Path}/Applications/"
- touch "${Package_Path}/DEBIAN/control"
- touch "${Package_Path}/DEBIAN/postinst"
- #获取BundleID
- PRODUCT_BUNDLE_IDENTIFIER=sed -n '/PRODUCT_BUNDLE_IDENTIFIER/{s/PRODUCT_BUNDLE_IDENTIFIER = //;s/;//;s/^[[:space:]]*//;p;q;}' ./${PROJECT_NAME}.xcodeproj/project.pbxproj
- # 覆盖内容
- echo "Package: ${PRODUCT_BUNDLE_IDENTIFIER}
- Name: ${PROJECT_NAME}
- Version: 0.0.1
- Architecture: iphoneos-arm
- Description: An awesome application!
- Maintainer:
- Author:
- Section: Utilities
- " > "${Package_Path}/DEBIAN/control"
- echo "chown root.wheel /Applications/${PROJECT_NAME}.app
- #chmod +s /Applications/${PROJECT_NAME}.app
- #chmod 6755 /Applications/${PROJECT_NAME}.app
- chown root.wheel /Applications/${PROJECT_NAME}.app/${PRODUCT_NAME}
- chmod +s /Applications/${PROJECT_NAME}.app/${PRODUCT_NAME}
- chmod 6755 /Applications/${PROJECT_NAME}.app/${PRODUCT_NAME}
- su mobile -c uicache
- killall "${PROJECT_NAME}" || true
- " > "${Package_Path}/DEBIAN/postinst"
- #echo "$Root_Password" | sudo -S chmod +s "${Package_Path}"
- echo "$Root_Password" | sudo -S chmod -R 0755 "${Package_Path}"
- echo "$Root_Password" | sudo -S chmod -R 0755 "${Package_Path}/DEBIAN"
- echo "$Root_Password" | sudo -S chmod -R 0755 "${Package_Path}/Applications"
- echo "$Root_Password" | sudo -S chmod -R 0755 "${Package_Path}/Applications/${PROJECT_NAME}.app"
- #echo "$Root_Password" | sudo -S chmod +s "${Package_Path}/Applications/${PROJECT_NAME}.app/${PROJECT_NAME}"
- #echo "$Root_Password" | sudo -S chmod 6755 "${Package_Path}/Applications/${PROJECT_NAME}.app/${PROJECT_NAME}"
- echo "$Root_Password" | sudo -S dpkg-deb -b "${Package_Path}"
- open ${BUILT_PRODUCTS_DIR}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。