使用Theos打包报错,怎么解决?


#1

今天根据书中所说,尝试编译一个Tweak,在编译的时候,先是出现这个错误:

bogon:iostest jimmy$ make
/Users/jimmy/Code/iostest/theos/makefiles/targets/Darwin/iPhone.mk:21: *** first argument to `word’ function must be greater than 0. Stop.

网上一查:

回到跟目录下,然后
输入如下命令:sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/

之后再执行make就能编译通过了。

此方法是从github上找到的,原文链接:https://github.com/DHowett/theos/issues/18

然后真的可以编译通过了,也生成了书中所说的Obj文件夹和那两个重要的文件。

接着下一步:make package

结果显示如下错误:

bogon:iostest jimmy$ make package
/Applications/Xcode-beta.app/Contents/Developer/usr/bin/make package requires dpkg-deb.
make: *** [internal-package-check] Error 1

难道还是XCode7的原因,还是第一步就不要改变路径,尝试改回路径也改不了。希望大牛指定迷津,谢谢!


#2

这个地方书上写了吧?


#3

如果说这个错误提示,书上肯定没有提及,或者告诉我哪一页,我买的是第二版。

然后我感觉是不是makefile的设置内容不全,所有导致无法打包,我的makefile内容如下:

ARCHS = armv7 arm64
TARGET = iPhone:latest:8.0

include theos/makefiles/common.mk

TWEAK_NAME = IOSTest
IOSTest_FILES = Tweak.xm

include $(THEOS_MAKE_PATH)/tweak.mk

after-install::
install.exec “killall -9 SpringBoard”

书中提及了几个元素,包括“指定处理器架构”,“指定SDK版本”,“导入framework”, 链接Match-O对象。但是最终还是没有总结最后的makefile应该是怎样的,包括后面举的例子。

我想作为一本逆向入门书籍,至少让新手能轻松编译打包安装吧?希望能得到进一步的指导,谢谢!


#4

Theos部分的配置dpkg-deb
看书还可以再认真一点


#5

这个我肯定看了,已经替换了,第30页上部分,怎么可能漏了这里。

今天再次编译,结果换了一个错误信息:

make: *** [internal-package] Error 126

然后网上查了一下,说另外建新项目,结果这次新项目又显示其它错误,我真的晕了:

bogon:iostest2 jimmy$ make
Making all for tweak IOSTest2…
Warning! No files to link. Please check your Makefile! Make sure you set IOSTest2_FILES (or similar variables)
Linking tweak IOSTest2…
fatal error: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can’t create temporary output file: obj/IOSTest2.dylib.4182ea4e.unsigned.lipo (No such file or directory)
clang: error: lipo command failed with exit code 1 (use -v to see invocation)
make[2]: *** [obj/IOSTest2.dylib.4182ea4e.unsigned] Error 1
make[1]: *** [internal-library-all_] Error 2
make: *** [IOSTest2.all.tweak.variables] Error 2

是Xcode7-beta的问题,还是啥情况?


#6

make messages=yes这个命令,然后把所有打印的信息po出来;
另外,你的makefile内容,也截个屏发出来看看


#7

make是可以通过,没问题。现在是无法打包。可能你平时太忙,对于这些小问题无暇顾及,我再理清思路给你:

第一个make的时候:(前提当然都是按书上说的,包括你提及的 dpkg-deb.)

然后出现了如下的错误:

bogon:iostest jimmy$ make
/Users/jimmy/Code/iostest/theos/makefiles/targets/Darwin/iPhone.mk:21: *** first argument to `word’ function must be greater than 0. Stop.

然后通过网上查询,DHowett提供的方法:(https://github.com/DHowett/theos/issues/18)

输入如下命令:sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/

之后再执行make就能编译通过了。

然后打包出现了问题:

bogon:iostest jimmy$ make package
/Applications/Xcode-beta.app/Contents/Developer/usr/bin/make package requires dpkg-deb.
make: *** [internal-package-check] Error 1

我想,应该是sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/改变了文件搜索路径,他是去到/Applications/Xcode-beta.app/Contents/Developer/usr/bin/这个目录下执行make的。

结果到了第二天,我再次尝试make package(当然是关机了再开机),结果出现了另外一个错误:

make: *** [internal-package] Error 126

然后我新建了项目iostest2,且不说连make都报错,可能我没处理好。我后来又新建了项目iostest3,结果这次make成功了,但是依然是这个错误:

make: *** [internal-package] Error 126

我依然感觉是不是DHowett提供的方法: sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/,影响了整个Theos。

我的make文件一直是如下的内容:

ARCHS = armv7 arm64
TARGET = iPhone:latest:8.0

include theos/makefiles/common.mk

TWEAK_NAME = IOSTest
IOSTest_FILES = Tweak.xm

include $(THEOS_MAKE_PATH)/tweak.mk

after-install::
install.exec “killall -9 SpringBoard”

希望作者既然开这个论坛为本书解惑,希望你真的可以帮我们这些新手读者解决问题,而不是几句话就应付过去,而且真的如我所说,你在描述theos的时候,的确没有提供一个完整的makefile文件给大家,让大家不清楚makefile文件到底需要哪些内容。

希望你不要嫌我说话太直,也希望你的这本书越来越完善,越来越受欢迎。谢谢了!


#8

dpkg没安装吧?


#9
  1. 你的Theos目录是什么?
  2. 运行make package messages=yes,把完整的输出贴出来

#10
  1. Theos目录是/opt/Theos/

  2. 输出很简单,就这些,编译没问题,现在是打包报错。
    bogon:iostest3 jimmy$ make message=yes
    Making all for tweak iostest3…
    Preprocessing Tweak.xm…
    Compiling Tweak.xm…
    Linking tweak iostest3…
    Stripping iostest3…
    Signing iostest3…


#11

我新建一个项目,一样是这些内容:

bogon:Code jimmy$ /opt/theos/bin/nic.pl
NIC 2.0 - New Instance Creator

[1.] iphone/application
[2.] iphone/cydget
[3.] iphone/framework
[4.] iphone/library
[5.] iphone/notification_center_widget
[6.] iphone/preference_bundle
[7.] iphone/sbsettingstoggle
[8.] iphone/tool
[9.] iphone/tweak
[10.] iphone/xpc_service
Choose a Template (required): 9
Project Name (required): iostest4
Package Name [com.yourcompany.iostest4]: com.s4ku.iostest4
Author/Maintainer Name [jimmy]: jimmy
[iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]: com.apple.springboard
[iphone/tweak] List of applications to terminate upon installation (space-separated, ‘-’ for none) [SpringBoard]: SpringBoard
Instantiating iphone/tweak in iostest4/…
Done.
bogon:Code jimmy$ ls
iostest iostest2 iostest3 iostest4
bogon:Code jimmy$ cd iostest4
bogon:iostest4 jimmy$ make message=yes
Making all for tweak iostest4…
Preprocessing Tweak.xm…
Compiling Tweak.xm…
Linking tweak iostest4…
Stripping iostest4…
Signing iostest4…


#12

然后还是打包报错

bogon:iostest4 jimmy$ make package
Making all for tweak iostest4…
make[2]: Nothing to be done for `internal-library-compile’.
Making stage for tweak iostest4…
make: *** [internal-package] Error 126


#13
  1. ls -l /opt/Theos/bin,输出贴上来;
  2. make package messages=yes,输出贴上来(注意看我的命令,跟你的不一样)

#14
bogon:~ jimmy$ ls -l /opt/Theos/bin
total 496
-rwxr-xr-x  1 root  wheel    5516 10 19 16:19 bootstrap.sh
-rwxr-xr-x  1 root  wheel     491 10 19 16:19 deb_build_num.sh
-rwxr-xr-x  1 root  wheel    1022 10 19 16:19 denicify.pl
-rwxrwxrwx  1 root  wheel    5533 10 21 16:45 dpkg-deb
-rwxr-xr-x  1 root  wheel     892 10 19 16:19 fakeroot.sh
-rwxr-xr-x  1 root  wheel     134 10 19 16:19 install.copyFile
-rwxr-xr-x  1 root  wheel     139 10 19 16:19 install.exec
-rwxr-xr-x  1 root  wheel     213 10 19 16:19 install.mergeDir
-rwxrwxrwx  1 root  wheel  154728 10 20 03:12 ldid
drwxr-xr-x  6 root  wheel     204 10 19 16:19 lib
-rwxr-xr-x  1 root  wheel    2120 10 19 16:19 logify.pl
-rwxr-xr-x  1 root  wheel   24407 10 19 16:19 logos.pl
-rwxr-xr-x  1 root  wheel    8874 10 19 16:19 nic.pl
-rwxr-xr-x  1 root  wheel    3616 10 19 16:19 nicify.pl
-rwxr-xr-x  1 root  wheel     980 10 19 16:19 package_version.sh
-rwxr-xr-x  1 root  wheel     437 10 19 16:19 target.pl
-rwxr-xr-x  1 root  wheel     552 10 19 16:19 vercmp.pl
bogon:~ jimmy$ pwd
/Users/jimmy
bogon:~ jimmy$ cd code
bogon:code jimmy$ ls
iostest		iostest2	iostest3	iostest4
bogon:code jimmy$ cd iostest4
bogon:iostest4 jimmy$ make package messages=yes
Making all for tweak iostest4...
/Applications/Xcode-beta.app/Contents/Developer/usr/bin/make -f Makefile --no-print-directory --no-keep-going \
		internal-library-compile \
		_THEOS_CURRENT_TYPE=tweak THEOS_CURRENT_INSTANCE=iostest4 _THEOS_CURRENT_OPERATION=compile \
		THEOS_BUILD_DIR="." _THEOS_MAKE_PARALLEL=yes
/Users/jimmy/code/iostest4/theos/bin/logos.pl -c warnings=error    Tweak.xm > ./obj/Tweak.xm.mm
xcrun -sdk iphoneos g++ -x objective-c++ -c -I"/Users/jimmy/code/iostest4" -DTARGET_IPHONE=1 -O2 -I/Users/jimmy/code/iostest4/theos/include -include /Users/jimmy/code/iostest4/theos/Prefix.pch -Wall -Werror  -isysroot "/Applications/Xcode-beta.app/Contents/Developer//Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.1.sdk" -arch armv7 -arch arm64 -D__IPHONE_OS_VERSION_MIN_REQUIRED=__IPHONE_8_0 -miphoneos-version-min=8.0                 -include "logos/logos.h" ./obj/Tweak.xm.mm -o obj/Tweak.xm.26e2cae0.o
rm ./obj/Tweak.xm.mm
xcrun -sdk iphoneos g++ -L/Users/jimmy/code/iostest4/theos/lib -lobjc -framework Foundation -framework CoreFoundation -ObjC++ -fobjc-exceptions -fobjc-call-cxx-cdtors       -lsubstrate -dynamiclib -install_name "/Library/MobileSubstrate/DynamicLibraries/iostest4.dylib"  -isysroot "/Applications/Xcode-beta.app/Contents/Developer//Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.1.sdk" -arch armv7 -arch arm64 -D__IPHONE_OS_VERSION_MIN_REQUIRED=__IPHONE_8_0 -miphoneos-version-min=8.0 -multiply_defined suppress   -o "obj/iostest4.dylib.4182ea4e.unsigned" obj/Tweak.xm.26e2cae0.o
xcrun -sdk iphoneos strip -x "obj/iostest4.dylib.4182ea4e.unsigned"
CODESIGN_ALLOCATE="/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate" ldid -S "obj/iostest4.dylib.4182ea4e.unsigned"; mv "obj/iostest4.dylib.4182ea4e.unsigned" "obj/iostest4.dylib"
rm -rf "/Users/jimmy/code/iostest4/_"
/Users/jimmy/code/iostest4/theos/bin/fakeroot.sh -p "/Users/jimmy/code/iostest4/.theos/fakeroot" -c
mkdir -p "/Users/jimmy/code/iostest4/_"
[ -d layout ] && rsync -a "layout/" "/Users/jimmy/code/iostest4/_" --exclude "DEBIAN" --exclude "_MTN" --exclude ".git" --exclude ".svn" --exclude ".DS_Store" --exclude "._*" || true
Making stage for tweak iostest4...
mkdir -p "/Users/jimmy/code/iostest4/_/Library/MobileSubstrate/DynamicLibraries/"
cp ./obj/iostest4.dylib "/Users/jimmy/code/iostest4/_/Library/MobileSubstrate/DynamicLibraries/"
if [ -f iostest4.plist ]; then cp iostest4.plist "/Users/jimmy/code/iostest4/_/Library/MobileSubstrate/DynamicLibraries/"; fi
mkdir -p "/Users/jimmy/code/iostest4/_/DEBIAN"
sed -e '/^[Vv]ersion:/d' "/Users/jimmy/code/iostest4/control" > "/Users/jimmy/code/iostest4/_/DEBIAN/control"
echo "Version: 0.0.1-2" >> "/Users/jimmy/code/iostest4/_/DEBIAN/control"
echo "Installed-Size: 104" >> "/Users/jimmy/code/iostest4/_/DEBIAN/control"
COPYFILE_DISABLE=1 /Users/jimmy/code/iostest4/theos/bin/fakeroot.sh -p "/Users/jimmy/code/iostest4/.theos/fakeroot" -r dpkg-deb -b "/Users/jimmy/code/iostest4/_" "./com.s4ku.iostest4_0.0.1-2_iphoneos-arm.deb" 
/Users/jimmy/code/iostest4/theos/bin/fakeroot.sh: /Users/jimmy/code/iostest4/theos/bin/dpkg-deb: /usr/bin/perl^M: bad interpreter: No such file or directory
make: *** [internal-package] Error 126

相信你能找到答案了,我今天喝了点酒,不想仔细看,等你指点迷津

谢谢!


#15

运行一下
perl -i -pe 'y|\r||d' /Users/jimmy/code/iostest4/theos/bin/dpkg-deb
然后再
make package messages=yes
把输出贴出来


#16

第一个命令就报错了。

Last login: Tue Oct 27 14:09:26 on console
bogon:~ jimmy$ perl -i -pe ‘y|\r||d’ /Users/jimmy/code/iostest4/theos/bin/dpkg-deb
Can’t remove /Users/jimmy/code/iostest4/theos/bin/dpkg-deb: Permission denied, skipping file.
bogon:~ jimmy$ make package messages=yes
make: *** No rule to make target package'. Stop. bogon:~ jimmy$ cd code bogon:code jimmy$ cd iostest4 bogon:iostest4 jimmy$ perl -i -pe 'y|\r||d' /Users/jimmy/code/iostest4/theos/bin/dpkg-deb Can't remove /Users/jimmy/code/iostest4/theos/bin/dpkg-deb: Permission denied, skipping file. bogon:iostest4 jimmy$ make package messages=yes Making all for tweak iostest4... /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make -f Makefile --no-print-directory --no-keep-going \ internal-library-compile \ _THEOS_CURRENT_TYPE=tweak THEOS_CURRENT_INSTANCE=iostest4 _THEOS_CURRENT_OPERATION=compile \ THEOS_BUILD_DIR="." _THEOS_MAKE_PARALLEL=yes make[2]: Nothing to be done forinternal-library-compile’.
rm -rf “/Users/jimmy/code/iostest4/"
/Users/jimmy/code/iostest4/theos/bin/fakeroot.sh -p “/Users/jimmy/code/iostest4/.theos/fakeroot” -c
mkdir -p "/Users/jimmy/code/iostest4/

[ -d layout ] && rsync -a “layout/” “/Users/jimmy/code/iostest4/" --exclude “DEBIAN” --exclude “MTN" --exclude “.git” --exclude “.svn” --exclude “.DS_Store” --exclude ".*” || true
Making stage for tweak iostest4…
mkdir -p "/Users/jimmy/code/iostest4/
/Library/MobileSubstrate/DynamicLibraries/”
cp ./obj/iostest4.dylib “/Users/jimmy/code/iostest4//Library/MobileSubstrate/DynamicLibraries/"
if [ -f iostest4.plist ]; then cp iostest4.plist "/Users/jimmy/code/iostest4/
/Library/MobileSubstrate/DynamicLibraries/”; fi
mkdir -p “/Users/jimmy/code/iostest4//DEBIAN"
sed -e ‘/^[Vv]ersion:/d’ “/Users/jimmy/code/iostest4/control” > "/Users/jimmy/code/iostest4/
/DEBIAN/control”
echo “Version: 0.0.1-3” >> “/Users/jimmy/code/iostest4//DEBIAN/control"
echo “Installed-Size: 104” >> "/Users/jimmy/code/iostest4/
/DEBIAN/control”
COPYFILE_DISABLE=1 /Users/jimmy/code/iostest4/theos/bin/fakeroot.sh -p “/Users/jimmy/code/iostest4/.theos/fakeroot” -r dpkg-deb -b “/Users/jimmy/code/iostest4/_” “./com.s4ku.iostest4_0.0.1-3_iphoneos-arm.deb”
/Users/jimmy/code/iostest4/theos/bin/fakeroot.sh: /Users/jimmy/code/iostest4/theos/bin/dpkg-deb: /usr/bin/perl^M: bad interpreter: No such file or directory
make: *** [internal-package] Error 126
bogon:iostest4 jimmy$


#17

第1条命令改成:

sudo perl -i -pe 'y|\r||d' /Users/jimmy/code/iostest4/theos/bin/dpkg-deb

试试?
你是不是从没用过命令行?根据出错信息google一下,类似的问题可以搜到一大堆


#18

哈,终于成功了,非常感谢!


#19

@snakeninny 谢谢你告诉我使用 make messages=yes,看日志得知问题是因为大写问题, 我在运行 make package install时遇到上面基本一样的错误,
但是通过打印运行log信息来看,make package install messages=yes,遇到错误是:包名的字符不是小写。如下所示,而且当前项目的包名是:com.victor.iOSScreenShotTest
随即,我删掉,重新创建一个项目,包名是: com.victor.iosscreenshottest

ERROR: package name has characters that aren't lowercase alphanums or '-+.'.
make: *** [internal-package] Error 255

然后就运行正常了,再次感谢~~ :smile:


#20

其实并不需要。直接修改control就好了啊