__init__.py 958 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from __future__ import absolute_import
  2. import sys
  3. from . import ws2_32
  4. from . import oleaut32
  5. """
  6. A small module for keeping a database of ordinal to symbol
  7. mappings for DLLs which frequently get linked without symbolic
  8. infoz.
  9. """
  10. ords = {
  11. b"ws2_32.dll": ws2_32.ord_names,
  12. b"wsock32.dll": ws2_32.ord_names,
  13. b"oleaut32.dll": oleaut32.ord_names,
  14. }
  15. PY3 = sys.version_info > (3,)
  16. if PY3:
  17. def formatOrdString(ord_val):
  18. return "ord{}".format(ord_val).encode()
  19. else:
  20. def formatOrdString(ord_val):
  21. return b"ord%d" % ord_val
  22. def ordLookup(libname, ord_val, make_name=False):
  23. """
  24. Lookup a name for the given ordinal if it's in our
  25. database.
  26. """
  27. names = ords.get(libname.lower())
  28. if names is None:
  29. if make_name is True:
  30. return formatOrdString(ord_val)
  31. return None
  32. name = names.get(ord_val)
  33. if name is None:
  34. return formatOrdString(ord_val)
  35. return name