1

Here is the example code:

import ctypes.util
from ctypes import CDLL

path = ctypes.util.find_library('crypto')
lib = CDLL(path)
hasattr(lib, 'EVP_get_cipherbyname') #only run this line or getattr, 
#the print(lib.__dict__) show the EVP_get_cipherbyname

print(lib.__dict__)
print(vars(lib))

The result is:

{'EVP_get_cipherbyname': <_FuncPtr object at 0x7f1b30835048>, '_handle': 21221024, '_name': 'libcrypto.so.1.0.0', '_FuncPtr': <class 'ctypes.CDLL.__init__.<locals>._FuncPtr'>}

I found if the code without the line

hasattr(lib, 'EVP_get_cipherbyname')

the print result is below which doesn't include the 'EVP_get_cipherbyname'

{'_name': 'libcrypto.so.1.0.0', '_handle': 24407408, '_FuncPtr': <class 'ctypes.CDLL.__init__.<locals>._FuncPtr'>}

Could someone explain why?

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
Edwin
  • 71
  • 1
  • 1
  • 3

0 Answers0