Paste: openssl dll test in C
Author: | erg |
Mode: | c |
Date: | Sat, 22 Apr 2023 02:07:07 |
Plain Text |
#include <stdio.h>
#include <windows.h>
typedef void* (*DLL_FUNC_T1)();
typedef void* (*DLL_FUNC_CTX_NEW)(DLL_FUNC_T1);
typedef void* (*DLL_FUNC_CTX_FREE)(DLL_FUNC_T1);
typedef void* (*DLL_FUNC_SSL_NEW)(void*);
typedef void* (*DLL_FUNC_SSL_FREE)(void*);
typedef char* (*DLL_FUNC_SSL_STRING)(void*);
typedef int (*DLL_FUNC_SSL_WANT)(void*);
int main() {
HINSTANCE hinstLib = LoadLibrary(TEXT("libssl-3-x64.dll"));
if (hinstLib == NULL) {
printf("Failed to load DLL\n");
return 1;
}
DLL_FUNC_T1 fnT1 = (DLL_FUNC_T1)GetProcAddress(hinstLib, "TLSv1_client_method");
if (fnT1 == NULL) { printf("Failed to get function from DLL\n"); return 1; }
DLL_FUNC_CTX_NEW fnCTXNew = (DLL_FUNC_CTX_NEW)GetProcAddress(hinstLib, "SSL_CTX_new");
if (fnCTXNew == NULL) { printf("Failed to get function from DLL\n"); return 2; }
DLL_FUNC_SSL_NEW fnSSLNew = (DLL_FUNC_SSL_NEW)GetProcAddress(hinstLib, "SSL_new");
if (fnSSLNew == NULL) { printf("Failed to get function from DLL\n"); return 4; }
DLL_FUNC_SSL_STRING fnSSLString = (DLL_FUNC_SSL_STRING)GetProcAddress(hinstLib, "SSL_rstate_string_long");
if (fnSSLString == NULL) { printf("Failed to get function from DLL\n"); return 6; }
DLL_FUNC_SSL_WANT fnSSLWant = (DLL_FUNC_SSL_WANT)GetProcAddress(hinstLib, "SSL_want");
if (fnSSLWant == NULL) { printf("Failed to get function from DLL\n"); return 6; }
printf("ssl state 1\n");
void *method = fnT1();
printf("ssl state 1.1\n");
void *ptr1 = fnCTXNew(method);
printf("ssl state 2\n");
void *ptr2 = fnSSLNew(ptr1);
printf("ssl state 3\n");
void *ctx = printf("ssl state %s\n", fnSSLString(ptr2));
printf("ssl state %d\n", fnSSLWant(ptr2));
FreeLibrary(hinstLib);
return 0;
}
New Annotation