0

Now I have only a DLL file which writen in C# and C++ mixed(C# code call the C++ natvie code inside) I know, I want to wrap this DLL file with Python(ctypes), using a refoctor(dnSpy) to reverse the DLL i found the function named s_set_server_public_key.

So my question is how to use Python to call this function? the DLL is attached, could you please give me some suggestion? Thanks very much!!! enter image description here

peterc
  • 9
  • 1
  • I wonder if you would have any specific errors? – UdonN00dle May 22 '20 at 09:37
  • What research have you done? There's a code example in [this](https://en.wikipedia.org/wiki/Dynamic-link_library) wikipedia article. And AFAIK it doesn't matter that much from what language the DLL was compiled. The general idea behind shared object files or DLLs in Microland is to have code parts which cooperate with each other. – nada May 22 '20 at 10:27
  • Thanks for quick answer nada! The situation is i have nothing to know about the DLL, don't know the import、export, no .h file no related source file, the DLL to me is a blackbox, only use reflactor(reverse engineering) to get the funciton info. Now i want to use python to wrap it, and to do something like list all the functions in the DLL for example, but i don't know how to do. From reflactor i can see the function "s_set_server_public_key" as the picture attached, now how can i call this function via python with the very little info i know. – peterc May 22 '20 at 11:02
  • I have put the DLL file to: https##pan.baidu.com/s/1ZO7QNHylu7pfnBMX55ABOQ(code:l9w7),could you please have a check and give me some suggestions? Thanks again. – peterc May 22 '20 at 11:02

1 Answers1

0

I think this answer is useful for you:

import ctypes

# Load DLL into memory.

hllDll = ctypes.WinDLL ("c:\\PComm\\ehlapi32.dll")

# Set up prototype and parameters for the desired function call.
# HLLAPI

hllApiProto = ctypes.WINFUNCTYPE (
    ctypes.c_int,      # Return type.
    ctypes.c_void_p,   # Parameters 1 ...
    ctypes.c_void_p,
    ctypes.c_void_p,
    ctypes.c_void_p)   # ... thru 4.
hllApiParams = (1, "p1", 0), (1, "p2", 0), (1, "p3",0), (1, "p4",0),

# Actually map the call ("HLLAPI(...)") to a Python name.

hllApi = hllApiProto (("HLLAPI", hllDll), hllApiParams)

# This is how you can actually call the DLL function.
# Set up the variables and call the Python name with them.

p1 = ctypes.c_int (1)
p2 = ctypes.c_char_p (sessionVar)
p3 = ctypes.c_int (1)
p4 = ctypes.c_int (0)
hllApi (ctypes.byref (p1), p2, ctypes.byref (p3), ctypes.byref (p4))

How can I use a DLL file from Python?

Peyman Majidi
  • 1,777
  • 2
  • 18
  • 31