inital commit
This commit is contained in:
commit
a60b1b13b2
78 files changed
+13166
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
import pefile
|
||||
|
||||
|
||||
def main(dll_path: str, def_path: str) -> None:
|
||||
pe = pefile.PE(dll_path, fast_load=True)
|
||||
pe.parse_data_directories(
|
||||
directories=[pefile.DIRECTORY_ENTRY["IMAGE_DIRECTORY_ENTRY_EXPORT"]]
|
||||
)
|
||||
symbols = []
|
||||
for entry in pe.DIRECTORY_ENTRY_EXPORT.symbols:
|
||||
if not entry.name:
|
||||
continue
|
||||
name = entry.name.decode("ascii", "ignore")
|
||||
# Only plain C symbols; mangled C++ names need quoting and are not used.
|
||||
if re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", name):
|
||||
symbols.append(name)
|
||||
|
||||
with open(def_path, "w", encoding="ascii", newline="\r\n") as f:
|
||||
f.write("LIBRARY " + dll_path.replace("\\", "/").rsplit("/", 1)[-1] + "\n")
|
||||
f.write("EXPORTS\n")
|
||||
for name in sorted(set(symbols)):
|
||||
f.write(" " + name + "\n")
|
||||
|
||||
print(f"{def_path}: {len(symbols)} symbols")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1], sys.argv[2])
|
||||
Reference in new issue
Block a user