1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ I have a feeling the shaders will proly be inside the app package.... \$\endgroup\$ Jan 24, 2017 at 1:17

1 Answer 1

3
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ "invalid bitcode signature" from LLVM Dis - sure there isn't an intermediary step? \$\endgroup\$ Jan 24, 2017 at 19:10
  • \$\begingroup\$ 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. \$\endgroup\$
    – user1430
    Jan 24, 2017 at 19:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .