How to assign string value to phkey?

0

I'm working on an utility to hook various bits of the Windows API used by different applications. The aim of the project is, at the moment to make any application portable by redirecting filesystem and registry calls to custom locations using easyhook. The complexity of the Windows API, however, has stretched my limited programming skills to the limit.

Below is a function from the registry emulation part of my project. It is called when the program calls RegCreateKeyExA and recieves all it's parameters. When it is called, it creates an empty entry in the json file that I use as a sort of virtual registry. Normally, when a new registry key is created, the kernel assigns it a handle. This handle is assigned to phkResult (or rather the address that it is pointing to).

I have set up my own handle system (basically the count of the items in the "DICTIONARY" object of the json minus the default entries (HKEY_LOCAL_MACHINE and so on (hence the - 10)). I, however, have trouble converting my handle to whatever type can be assigned to phkResult. The value that has to be assigned to it is ss.str() but converted to the appropriate type which I can't seem to get right.

LSTATUS WINAPI myRegCreateKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD Reserved, LPSTR lpClass, DWORD dwOptions, REGSAM samDesired, const LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition)
{
    std::cout << "Function: RegCreateKeyExA" << "\n";
    std::cout << "lpSubKey: " << lpSubKey << "\n";
    std::cout << "hKey: " << hKey << "\n";

    boost::property_tree::ptree VirtualRegistry;
    boost::property_tree::read_json("VirtualRegistry.json", VirtualRegistry);
    std::string RegPath(GetHiveA(hKey) + "\\" + lpSubKey);
    VirtualRegistry.put(boost::property_tree::ptree::path_type(RegPath, '\\'), NULL);
    std::stringstream ss;
    ss << std::setfill('0') << std::hex << std::setw(8) << VirtualRegistry.get_child("DICTIONARY").size() - 10;
    VirtualRegistry.get_child("DICTIONARY").put(ss.str(), RegPath);
    *phkResult = ((HKEY)(ULONG_PTR)((LONG)0x8000ffff)); //REPLACE 0x8000ffff with ss.str() somehow!!
    boost::property_tree::write_json("VirtualRegistry.json", VirtualRegistry);

    return ERROR_SUCCESS;
}

Also I need to specify that I am using boost for the json and property tree operations. Thank you.

c++
winapi
easyhook
asked on Stack Overflow Nov 21, 2020 by enzeinzen

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0