File indexing completed on 2023-10-01 07:35:55
0001 import subprocess 0002 import os 0003 import sys 0004 0005 # Generate a .lib file for a given .dll 0006 # This assumed dumpbin and lib to be in the path, which they should be, when compiling with MSVC (and that's what this is needed for) 0007 # 0008 # Usage: python3 GenLibFile.py XYZ.dll output_directory architecture 0009 0010 dllfile = sys.argv[1] 0011 workdir = sys.argv[2] 0012 arch = sys.argv[3] 0013 base = os.path.basename(dllfile).replace(".dll", "") 0014 deffile = base + ".def" 0015 libfile = base + ".lib" 0016 0017 dump = subprocess.check_output(["dumpbin", "/exports", dllfile]).decode("latin1").splitlines() 0018 exports = [] 0019 for line in dump: 0020 fields = line.split() 0021 if len(fields) != 4: 0022 continue 0023 exports.append(fields[3]) 0024 os.chdir(workdir) 0025 with open(os.path.join(workdir, deffile), "wt+") as outdef: 0026 outdef.write("EXPORTS\n") 0027 outdef.write("\n".join(exports)) 0028 subprocess.call(["lib", f"/def:{deffile}", f"/out:{libfile}", f"/machine:{arch}"])