Skip to content

Instantly share code, notes, and snippets.

@thewh1teagle
Created January 10, 2024 17:03
Show Gist options
  • Select an option

  • Save thewh1teagle/f71ef8816cbebc23ddcf8487274ecf39 to your computer and use it in GitHub Desktop.

Select an option

Save thewh1teagle/f71ef8816cbebc23ddcf8487274ecf39 to your computer and use it in GitHub Desktop.
Dumb init

here's the dumb way to do it :D,

const uint8_t dll_data[] = { /* dump the raw dll file data here */ };

typedef int (*SquareFn)(int);

int main()
{
    // create a dll file from the above dll_data
    HANDLE hFile = CreateFileA("a.dll", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

    DWORD written;
    BOOL writeResult = WriteFile(hFile, dll_data, sizeof(dll_data), &written, NULL);
    CloseHandle(hFile);

    HMODULE hModule = LoadLibraryA("a.dll");
    SquareFn square = (SquareFn)GetProcAddress(hModule, "square");


    int result = square(5);

    FreeLibrary(hModule);
    DeleteFileA("a.dll"); // Delete the temp file

    printf("Function result: %d\n", result);
    return 0;
}
 the fun.c file which i create a dll out of, 
__declspec(dllexport) int square(int num)
{
    return num * num;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment