/*
Hints to follow:
1. Copy function load_imports from the project pe_self_load
2. Copy the functions from the shellcodes exercise, that are responsible for loading imports by PEB lookup:
+ get_module_by_name
+ get_func_by_name
(and their dependencies)
3. Refactor the function load_imports so that it will not use the original functions directly:
+ LoadLibraryA
+ GetProcAddress
but fetch them via PEB.
Remember that no imports will be filled at this stage, so if we want to use any, we need to fetch them via PEB.

4. Fill the exported function SelfLoadImports in such a way, that it will be fetching its own NT header, and calling the function load_imports with relevant parameters.
*/

#include <windows.h>
#include <iostream>

#define MYEXPORTS
#include "dll_main.h"

bool MYAPI SelfLoadImports(LPVOID currentImageBase)
{
    // Fill this function in such a way, that it will be loading its own imports. The Image Base of the current module will be given as a parameter.
    return false;
}

void MYAPI SayHello()
{
    // this function should be called from the injector, after the imports got successfully loaded:
    MessageBoxA(0, "Hello!", "Success! Imports loaded", MB_OK);
}

BOOL WINAPI DllMain(HANDLE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        MessageBoxA(0, "Hello!", "Hello from DLL Entry Point", MB_OK);
        break;
    }
    return TRUE;
}
