Skip to content

Instantly share code, notes, and snippets.

@codewings
Last active January 4, 2016 04:59
Show Gist options
  • Save codewings/8572236 to your computer and use it in GitHub Desktop.
Save codewings/8572236 to your computer and use it in GitHub Desktop.
dump HLSL binary code
import sys
import os
import struct
#/Tvs_4_0 f:\default.vs
root = os.environ['DXSDK_DIR']
file = os.environ['TEMP'] + "output.bin"
expr = "\"" + root + "Utilities\\bin\\x86\\fxc.exe\" /Fo" + file
if len(sys.argv) >= 2:
for i in sys.argv[1:]:
expr = expr + ' ' + i
reval = os. popen(expr).read()
print reval
count = 16
if reval.index("compilation succeeded") != -1:
filelen = os.path.getsize(file)
bincode = open(file, 'rb')
hexlist = [0] * count
while filelen > 0:
for j in range(0, count):
filelen = filelen - 1
hexlist[j] = struct.unpack("B", bincode.read(1))[0]
if filelen <= 0:
break
if j + 1 == count:
for i in range(0, count):
sys.stdout.write("0x%02x," % hexlist[i])
sys.stdout.write(" // ")
for i in range(0, count):
if hexlist[i] >= 32 and hexlist[i] <= 126:
sys.stdout.write("%c" % hexlist[i])
else:
sys.stdout.write(".")
sys.stdout.write("\n")
if j + 1 != count:
for i in range(0, j+1):
if i != j:
sys.stdout.write("0x%02x," % hexlist[i])
else:
sys.stdout.write("0x%02x" % hexlist[i])
for i in range(j+1, count):
sys.stdout.write(" ")
sys.stdout.write(" //")
for i in range(0, j+1):
if hexlist[i] >= 32 and hexlist[i] <= 126:
sys.stdout.write("%c" % hexlist[i])
else:
sys.stdout.write(".")
bincode.close()
# os.remove(file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment