jtool inconsistent architecture support

Used for discussing the various tools in the book as well as encouraging members to share tools

jtool inconsistent architecture support

Postby 0xdead10cc » Thu Oct 04, 2018 12:34 pm

I use Caffeine.app from http://lightheadsw.com/caffeine/ for illustration purposes here because it contains lots of slices for lots of architectures.

---
jtool return 0 (Success) if no architecture was provided and no useful information is output.

Code: Select all
$ jtool -h /Applications/Caffeine.app/Contents/MacOS/Caffeine
Fat binary, big-endian,  4 architectures: i386, ppc7400, ppc64, x86_64
Specify one of these architectures with -arch switch, or export the ARCH environment variable
$ echo $?
0


Would it be possible to return a different return code here? While no error per se occurred, the result is not what one would expect and can not directly be distinguished from a useful result (useful as if a valid architecture had been provided).

---
Jtool reports success if the requested architecture could not be found in the input file

Code: Select all
# Caffeine.thinner obtained using lipo command
$ jtool -h Caffeine.thinner
Fat binary, big-endian,  3 architectures: i386, ppc7400, ppc64
Specify one of these architectures with -arch switch, or export the ARCH environment variable
# First issue, imho this should not return 0
$ echo $?
0
# This works
$ jtool -h -arch i386 Caffeine.thinner
Magic:   32-bit Mach-O
Type:   executable
CPU:   i386
Cmds:   19
Size:   2756 bytes
Flags:   0x85
# This should not return 0 imho
$ jtool -h -arch x86_64 Caffeine.thinner

Requested architecture not found in file
$ echo $?
0


Similar to the first issue mentioned, scriptability of jtool could be improved by returning a non-zero return code here. Supplying an architecture that is not contained in the file is clearly an error (and, through the ARCH environment variable, it is quite easy to hit this edge case!)

It would also be awesome to be able to supply a list of architectures to consider via the ARCH environment variable:
Say I specify
Code: Select all
export ARCH="x86_64 i386"
jtool -h /path/to/bin


jtool could then treat the ARCH environment variable as a list of my preferences: If available, return results for the x86_64 slice. If not, fall back to the i386 slice. If that is also not available, display an error message (and hopefully do not return 0 ;))

---
The
Code: Select all
-arch
flag only works with some architectures, despite jtool itself reporting all architectures for fat binaries, suggesting that "one of these architectures" should be provided in future calls.

Code: Select all
$ jtool -h /Applications/Caffeine.app/Contents/MacOS/Caffeine
Fat binary, big-endian,  4 architectures: i386, ppc7400, ppc64, x86_64
Specify one of these architectures with -arch switch, or export the ARCH environment variable
$ jtool -arch ppc64 -h /Applications/Caffeine.app/Contents/MacOS/Caffeine
Unrecognized architecture: ppc64
$ jtool -arch ppc7400 -h /Applications/Caffeine.app/Contents/MacOS/Caffeine
Unrecognized architecture: ppc7400
$ echo $?
2


Even if jtool does not support ppc, then the documentation should be updated to reflect that the user cannot specify any one of these architectures.
Note that this is also applies to jtool2.
0xdead10cc
 
Posts: 5
Joined: Fri Jan 05, 2018 12:00 am

Re: jtool inconsistent architecture support

Postby morpheus » Wed Nov 21, 2018 9:02 pm

Wow. ppc7400?! That's oooooold. Can you send me the Caffeine binary?

I'll add support for parsing ARCH like PATH.. That's a nifty idea. jtool2 only uses the environment variable now.
morpheus
Site Admin
 
Posts: 715
Joined: Thu Apr 11, 2013 6:24 pm


Return to Tools

Who is online

Users browsing this forum: No registered users and 7 guests

cron