I am interested in analyzing existing shaders implemented using Apple's Metal framework. From my previous experience on other platforms with OpenGL, I have found that applications sometimes bundle shader code more or less in plaintext within the application binary. I have not found this to be the case with iOS.

  • Is there a special final format that Metal shaders are compiled into?

  • Can they be disassembled?

  • Where should one normally look for shader code in iOS applications?

Please let me know if this isn't posted on the right SE before downvoting. I was torn on whether this should go on Graphics SE or GamesDev SE. I do not think this should go on ReverseEngineering, or Security SE, as I fear those communities have very little experience with shader formats and likely wont be much help.

Is there a special final format that Metal shaders are compiled into?

Yes. They're compiled into a proprietary format (LLVM-based, device-agnostic intermediate language) that is not publicly documented. This happens as part of the build process, by default; the Xcode toolchain has a build rule to take Metal source files, compile them, and shove the output .metallib into your application's bundle someplace. Apple's documentation covers this in more detail.

Can they be disassembled?

You should be able to use llvm-dis to do so, although I've never actually tried. You may not be able to use it directly on the .metallib.

Where should one normally look for shader code in iOS applications?

In the "Resources" directory of the application's bundle. That would be a good place to start at least. A developer could choose to put them elsewhere.

  • "invalid bitcode signature" from LLVM Dis - sure there isn't an intermediary step? – baordog Jan 24 '17 at 19:10
  • Almost certainly, as based on the linked Apple docs the bitcode is bundled up into the metallib archive, so you'd have to reverse that last step somewhere. Maybe the man pages for the build or archive tool will be helpful. – Josh Jan 24 '17 at 19:18

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.