-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDXBC.bt
More file actions
173 lines (155 loc) · 4.71 KB
/
Copy pathDXBC.bt
File metadata and controls
173 lines (155 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//------------------------------------------------
// File: DXBC.bt
// Authors: Zee
// Version: 1.0
// Purpose: Reversing DirectX Shader Byte code
// Category: General
//------------------------------------------------
#include "Lib/Common.bt"
local int i;
struct Header
{
char DXBC[4]; // Always the string “DXBC”
byte checksum[16]; // Checksum; the HLSL compiler uses a private algorithm to compute this
int one; // Always the number “1” - I don’t know why this exists, perhaps as a sanity check
int totalSize; // Total size, in bytes, of the compiled shader, including the header
int chunkCount; // Chunk Count
int chunkOffsets[chunkCount];
};
struct Element(int start)
{
int offset;
local int save = FTell();
FSeek(start + offset);
string name;
FSeek(save);
int semanticIndex;
int systemValueType;
int componentType; // 3 = float
int register;
byte mask; // Mask. “7” means XYZ, which means this is a 3-component vector.
byte readWriteMask; // This is the same as the mask, but it is also possible for not all components to actually be used by the shader.
byte pad[2];
};
struct ISGN
{
// ISGN chunks define the input signature for a shader.
CHUNK chunk;
local int start = FTell();
int elementCount;
int unk; // 8
Element elements(start)[elementCount]<optimize=false>;
};
struct OSGN
{
// OSGN chunks define the output signature for a shader.
CHUNK chunk;
local int start = FTell();
int elementCount;
int unk; // 8
Element elements(start)[elementCount]<optimize=false>;
};
struct Instruction
{
BitfieldDisablePadding();
int Type : 10;
int pad : 14;
int Length : 6;
int Extended : 1;
BitfieldEnablePadding();
};
struct SHDR
{
// Shader SM4/PS_04
CHUNK chunk;
byte version;
FSkip(1);
short programType; // 1 = vertex shader
int dwordCount;
Instruction instructions[dwordCount]<optimize=false>;
};
struct VariableType
{
int class; // D3D10_SHADER_VARIABLE_CLASS.
int type; // D3D10_SHADER_VARIABLE_TYPE.
//int rows; // only for matrix vars
//int columns; // only for matrix vars
//int elements; // only for array type
//int members; // only for structure type
int offsetToFirstMember;
};
struct ConstantVariable(int start)
{
int nameOffset;
int constantBufferStartOffset;
int variableSize;
int flags; // https://docs.microsoft.com/en-us/windows/desktop/api/d3dcommon/ne-d3dcommon-_d3d_shader_variable_flags?redirectedfrom=MSDN
int variableTypeOffset;
int defaultValueOffset;
local int save = FTell();
FSeek(start + nameOffset);
string name;
FSeek(start + variableTypeOffset);
VariableType variableType;
FSeek(save);
};
struct ConstantBuffer(int start)
{
int nameOffset;
int variableCount;
int variableOffset;
int size;
int flags; // https://docs.microsoft.com/en-us/windows/win32/api/d3dcommon/ne-d3dcommon-d3d_shader_cbuffer_flags?redirectedfrom=MSDN
int type; // https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ff476097(v=vs.85)?redirectedfrom=MSDN
local int save = FTell();
FSeek(start + nameOffset);
string name;
FSeek(start + variableOffset);
ConstantVariable variables(start)[variableCount]<optimize=false>;
FSeek(save);
};
struct ResourceBinding(int start)
{
int nameOffset;
int inputType;
int returnType;
int viewDimension;
int sampleCount;
int bindPoint;
int bindCount;
int shaderInputFlags;
local int save = FTell();
FSeek(start + nameOffset);
string name;
FSeek(save);
};
struct RDEF
{
CHUNK chunk;
local int start = FTell();
int constantBufferCount;
int constantBufferOffset;
int resourceBindingCount;
int resourceBindingOffset;
byte minorVersion;
byte majorVersion;
short programType; // 0xFFFE = vertex shader
int flags;
int stringOffset;
FSeek(start + constantBufferOffset);
ConstantBuffer constantBuffer(start)[constantBufferCount];
FSeek(start + resourceBindingOffset);
ResourceBinding resourceBinding(start)[resourceBindingCount];
FSeek(start + stringOffset);
string creator;
};
Header header;
for(i = 0; i < header.chunkCount; i++)
{
FSeek(header.chunkOffsets[i]);
if ( matchr( "ISGN" ) ) ISGN inputSignature<bgcolor=cYellow>;
else if( matchr( "OSGN" ) ) OSGN outputSignature<bgcolor=cGreen>;
else if( matchr( "SHDR" ) ) SHDR shader<bgcolor=cLtPurple>;
else if( matchr( "RDEF" ) ) RDEF resourceDefinitions<bgcolor=cRed>;
else SKIPCHUNK unk;
}