this is not finding any strings #pragma once
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX

#include "windows.h"
#include "tlhelp32.h"
#include "stdio.h"
#include "string"
#include "vector"
#include "algorithm"
#include "ctype.h"

using namespace std;

void log_message(FILE* log_file, const char* format, ...) {
    va_list args;
    va_start(args, format);
    vprintf(format, args);
    if (log_file != NULL) {
        vfprintf(log_file, format, args);
        fflush(log_file);
    }
    va_end(args);
}

DWORD get_process_id_by_name(const char* process_name) {
    PROCESSENTRY32 pe32;
    pe32.dwSize = sizeof(PROCESSENTRY32);

    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hSnapshot == INVALID_HANDLE_VALUE) {
        return 0;
    }

    if (!Process32First(hSnapshot, &pe32)) {
        CloseHandle(hSnapshot);
        return 0;
    }

    do {
        char exeFile[MAX_PATH];
        size_t converted_chars = 0;
        wcstombs_s(&converted_chars, exeFile, sizeof(exeFile), pe32.szExeFile, _TRUNCATE);
        if (_stricmp(exeFile, process_name) == 0) {
            CloseHandle(hSnapshot);
            return pe32.th32ProcessID;
        }
    } while (Process32Next(hSnapshot, &pe32));

    CloseHandle(hSnapshot);
    return 0;
}

UINT_PTR get_base_address(DWORD pid) {
    MODULEENTRY32 me32;
    me32.dwSize = sizeof(MODULEENTRY32);

    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid);
    if (hSnapshot == INVALID_HANDLE_VALUE) {
        return 0;
    }

    if (Module32First(hSnapshot, &me32)) {
        CloseHandle(hSnapshot);
        return (UINT_PTR)me32.modBaseAddr;
    }

    CloseHandle(hSnapshot);
    return 0;
}

bool get_section_limits(HANDLE hProcess, UINT_PTR base_addr, const char* section_name,
    UINT_PTR& section_start, UINT_PTR& section_end, UINT_PTR& image_base_in_pe) {
    IMAGE_DOS_HEADER dos_header;
    if (!ReadProcessMemory(hProcess, (LPCVOID)base_addr, &dos_header,
        sizeof(dos_header), NULL)) {
        return false;
    }

    if (dos_header.e_magic != IMAGE_DOS_SIGNATURE) {
        return false;
    }

    IMAGE_NT_HEADERS nt_headers;
    if (!ReadProcessMemory(hProcess, (LPCVOID)(base_addr + dos_header.e_lfanew),
        &nt_headers, sizeof(nt_headers), NULL)) {
        return false;
    }

    if (nt_headers.Signature != IMAGE_NT_SIGNATURE) {
        return false;
    }

    image_base_in_pe = nt_headers.OptionalHeader.ImageBase;

    vector<IMAGE_SECTION_HEADER> section_headers(nt_headers.FileHeader.NumberOfSections);
    if (!ReadProcessMemory(hProcess,
        (LPCVOID)(base_addr + dos_header.e_lfanew + sizeof(nt_headers)),
        &section_headers[0],
        sizeof(IMAGE_SECTION_HEADER) * nt_headers.FileHeader.NumberOfSections,
        NULL)) {
        return false;
    }

    for (const auto& section : section_headers) {
        if (strncmp((const char*)section.Name, section_name, IMAGE_SIZEOF_SHORT_NAME) == 0) {
            section_start = base_addr + section.VirtualAddress;
            SIZE_T section_size = max(section.Misc.VirtualSize, section.SizeOfRawData);
            section_end = section_start + section_size;
            return true;
        }
    }
    return false;
}

vector<pair<string, UINT_PTR>> find_strings_in_section(HANDLE hProcess,
    UINT_PTR section_start,
    UINT_PTR section_end,
    size_t min_length) {
    vector<pair<string, UINT_PTR>> strings;
    UINT_PTR addr = section_start;
    vector<char> buffer(4096);

    while (addr < section_end) {
        MEMORY_BASIC_INFORMATION mbi;
        if (!VirtualQueryEx(hProcess, (LPCVOID)addr, &mbi, sizeof(mbi))) {
            break;
        }

        if (mbi.State == MEM_COMMIT &&
            (mbi.Protect == PAGE_READONLY || mbi.Protect == PAGE_READWRITE ||
                mbi.Protect == PAGE_EXECUTE_READ || mbi.Protect == PAGE_EXECUTE_READWRITE)) {

            SIZE_T bytes_to_read = min((SIZE_T)(section_end - addr), mbi.RegionSize);
            buffer.resize(bytes_to_read);

            SIZE_T bytes_read;
            if (ReadProcessMemory(hProcess, (LPCVOID)addr, &buffer[0],
                bytes_to_read, &bytes_read) && bytes_read > 0) {

                for (SIZE_T i = 0; i < bytes_read;) {
                    if (i + min_length <= bytes_read) {
                        bool is_printable = true;
                        for (SIZE_T k = 0; k < min_length; k++) {
                            if (!isprint((unsigned char)buffer[i + k])) {
                                is_printable = false;
                                break;
                            }
                        }

                        if (is_printable) {
                            string str;
                            SIZE_T j = i;
                            while (j < bytes_read && isprint((unsigned char)buffer[j])) {
                                str += buffer[j];
                                j++;
                            }

                            if (str.length() >= min_length) {
                                strings.push_back(make_pair(str, addr + i));
                            }
                            i = j;
                            continue;
                        }
                    }
                    i++;
                }
            }
        }
        addr += mbi.RegionSize;
    }
    return strings;
}