Last active
January 4, 2016 04:59
-
-
Save codewings/8572236 to your computer and use it in GitHub Desktop.
dump HLSL binary code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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