Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Is it possible to decompile a .xnb file? I've lost my shader code, but only have my .xnb file left.

share|improve this question
    
I'd be very surprised if you get back anything like the orignal source as shaders are heavily optimised during compilation (not just compressed into XNB format. I'd re-write it. That said, here's the XNB file format –  George Duckett Feb 20 '12 at 11:12
add comment

3 Answers

up vote 0 down vote accepted

It's unlikely you'll be able to retrieve the source from the xnb file as it has undergone compilation into a binary format during the XNA pipeline stages. While it's theoretically not impossible, in my opinion you'd probably be much better off rewriting the shader..

share|improve this answer
add comment

The best you can get is a disassembly, which may help you recreate the source code. (Unless someone can point you to an actual HLSL decompiler. I've never seen one.)

If you happen to be using XNA 3.1 you could simply load it into an Effect object via the content system and then call Effect.Disassemble on it.

XNA 4.0 removes this - so it will be much harder:

First of all you need the actual effect data. Probably the easiest way to get it would be to use reflection to get access to the private Effect.pCachedEffectData member which (I think) contains it.

Once you have the binary data, you'll want to disassemble it. I can't figure out a way to use fxc.exe to disassemble the data directly. But perhaps you can install XNA 3.1 and use that. Or use Direct3D and D3DDisassemble - which is, I suspect, what XNA 3.1 uses internally.

share|improve this answer
    
Can you show me how to write the code to use Disassemble? I've tried but it complains that it can't find the file. –  Neil Knight Feb 20 '12 at 19:24
    
@NeilKnight Not really. But perhaps ask in a fresh question and provide more details. –  Andrew Russell Feb 22 '12 at 1:07
add comment

http://mirror.dataorb.net/XNB_Exporter.zip - Maybe this can help you.

share|improve this answer
3  
You should write, what it is. At least some short description. –  zacharmarz Feb 20 '12 at 9:39
    
Ah.. Its xnb exporter. I found it in popular topic of Terraria forum.. :p –  ChaosDev Feb 20 '12 at 9:42
    
I'm after Shader files, not converting image files. –  Neil Knight Feb 20 '12 at 9:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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