diff --git a/CMakeLists.txt b/CMakeLists.txt index 56153bd..3016ffe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 3.13) -if (NOT CMAKE_BUILD_TYPE) +if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING - "Build type options: Debug Release RelWithDebInfo MinSizeRel" FORCE) -endif () + "Build type options: Debug Release RelWithDebInfo MinSizeRel" FORCE) +endif() project(wibo LANGUAGES CXX) @@ -25,10 +25,11 @@ add_executable(wibo dll/user32.cpp dll/vcruntime.cpp dll/version.cpp + dll/msvcrt.cpp files.cpp handles.cpp loader.cpp main.cpp - ) +) target_link_libraries(wibo PRIVATE std::filesystem) install(TARGETS wibo DESTINATION bin) diff --git a/dll/msvcrt.cpp b/dll/msvcrt.cpp new file mode 100644 index 0000000..729a73f --- /dev/null +++ b/dll/msvcrt.cpp @@ -0,0 +1,36 @@ +#include "common.h" + +namespace msvcrt { + int _commode; + int _fmode; + + // Stub because we're only ever a console application + void WIN_FUNC __set_app_type(int at) { + } + + int* WIN_FUNC __p__fmode() { + return &_fmode; + } + + int* WIN_FUNC __p__commode() { + return &_commode; + } +} + + +static void *resolveByName(const char *name) { + if (strcmp(name, "__set_app_type") == 0) return (void *) msvcrt::__set_app_type; + if (strcmp(name, "__p__fmode") == 0) return (void *) msvcrt::__p__fmode; + if (strcmp(name, "__p__commode") == 0) return (void *) msvcrt::__p__commode; + return nullptr; +} + +wibo::Module lib_msvcrt = { + (const char *[]){ + "msvcrt40", + "msvcrt40.dll", + nullptr, + }, + resolveByName, + nullptr, +}; diff --git a/main.cpp b/main.cpp index 5a63bbc..50b0d5d 100644 --- a/main.cpp +++ b/main.cpp @@ -77,6 +77,7 @@ extern const wibo::Module lib_bcrypt; extern const wibo::Module lib_crt; extern const wibo::Module lib_kernel32; extern const wibo::Module lib_lmgr; +extern const wibo::Module lib_msvcrt; extern const wibo::Module lib_ntdll; extern const wibo::Module lib_ole32; extern const wibo::Module lib_user32; @@ -88,6 +89,7 @@ const wibo::Module * wibo::modules[] = { &lib_crt, &lib_kernel32, &lib_lmgr, + &lib_msvcrt, &lib_ntdll, &lib_ole32, &lib_user32,