voiceroid_readonly_sdic.zip/main.cpp
#include <cstdio>
#include <iostream>
#include <string>
struct IUnknown;
#include <Windows.h>
#include <boost/version.hpp>
#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/shared_ptr.hpp>
#include <org/click3/dll_hack_lib.h>
boost::filesystem::path getTempPath() {
wchar_t buf[MAX_PATH];
::GetTempPathW(_countof(buf), buf);
return boost::filesystem::path(buf) / L"user.sdic";
}
HANDLE __stdcall dummyCreateFileA(
LPCSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile)
{
boost::filesystem::path path(lpFileName);
if (path.extension() == ".sdic") {
::printf("%s\n", path.string().c_str());
path = getTempPath();
}
return ::CreateFileW(path.wstring().c_str(), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
}
HANDLE __stdcall dummyCreateFileW(
LPCWSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile)
{
boost::filesystem::path path(lpFileName);
if (path.extension() == ".sdic" && dwCreationDisposition == CREATE_ALWAYS) {
//::printf("%s\n", path.string().c_str());
path = getTempPath();
}
return ::CreateFileA(path.string().c_str(), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
}
void main() {
//org::click3::DllHackLib::SetupConsole();
const unsigned int createFileW = reinterpret_cast<unsigned int>(::GetProcAddress(::GetModuleHandleA("Kernel32.dll"), "CreateFileW"));
unsigned char code[] = {
0xB8, 0x00, 0x00, 0x00, 0x00, // mov EAX, 0x00000000
0xFF, 0xE0, // jmp EAX
};
*reinterpret_cast<unsigned int*>(&code[1]) = reinterpret_cast<unsigned int>(&dummyCreateFileW);
org::click3::DllHackLib::WriteCode(nullptr, createFileW, code, sizeof(code));
}