Skip Menu |

This queue is for tickets about the Win32-Console-ANSI CPAN distribution.

Report information
The Basics
Id: 132827
Status: new
Priority: 0/
Queue: Win32-Console-ANSI

People
Owner: Nobody in particular
Requestors: jkahrman [...] mathworks.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: DLL injection broken with VS2015 (VC140) and up
None of the features of Win32-Console-ANSI work when built with VS2015. I think the problem is the refactoring and renaming of the C runtime DLLs that occurred with VC140. Not all the relevant DLLs start with "msvc" anymore and so aren't found by "HookAPIAllMod" and "SearchModFunc". Adding ucrtbase.dll and vcruntime*.dll to the search list appear to solve the issue.
Subject: Win32-Console-ANSI.VS2015.patch
--- a/ANSI.xs 2020-01-13 16:45:10.000000000 -0500 +++ b/ANSI.xs 2020-01-13 16:45:10.000000000 -0500 @@ -216,7 +216,7 @@ DWORD flOldProtect, flNewProtect, flDummy; MEMORY_BASIC_INFORMATION mbi; - DEBUGSTR("Found !\n"); + DEBUGSTR("Found: %s => %s\n", pszOldFunctionName, pszFunctionModule); // Get the current protection attributes VirtualQuery(&pThunk->u1.Function, &mbi, sizeof(mbi)); // Take the access protection flags @@ -287,7 +287,8 @@ // Walk the module list of the modules for (fOk = Module32First(hModuleSnap, &me); fOk; fOk = Module32Next(hModuleSnap, &me) ) { - if ( strstr(me.szModule, "MSVC") != NULL || strstr(me.szModule, "msvc") != NULL ) { + DEBUGSTR("Searching for %s in %s", pszOldFunctionName, me.szModule); + if ( isMSVC(me.szModule) ) { pDosHeader = (PIMAGE_DOS_HEADER) me.hModule; if ( pDosHeader->e_magic != IMAGE_DOS_SIGNATURE ) { DEBUGSTR("error: %s(%d)", __FILE__, __LINE__); @@ -330,7 +331,7 @@ // Function name found in the list... if ( strcmp(pImportByName->Name, pszOldFunctionName) == 0 ) { CloseHandle (hModuleSnap); - DEBUGSTR("Module found : %s", pszModName); + DEBUGSTR("Module import found: %s imports => %s", me.szModule, pszModName); return pszModName; // return the current module name } pThunk++; @@ -379,10 +380,12 @@ // Walk the module list of the modules for (fOk = Module32First(hModuleSnap, &me); fOk; fOk = Module32Next(hModuleSnap, &me) ) { + DEBUGSTR("Checking %s", me.szModule); + // Hooking into the C runtime library - if ( strstr(me.szModule, "MSVC") != NULL || strstr(me.szModule, "msvc") != NULL ) { + if ( isMSVC(me.szModule)) { // if ( me.hModule != hDllInstance ) { - DEBUGSTR("Hooking in %s", me.szModule); + DEBUGSTR("Hooking in %s: %s => %s", me.szModule, pszOldFunctionName, pszModName); // Hook this function in this module if (!HookAPIOneMod(me.hModule, pszModName, pszOldFunctionName, pfnNewFunction) ) { CloseHandle (hModuleSnap); @@ -395,6 +398,18 @@ return TRUE; } +BOOL isMSVC( + PSTR mod + ) +{ + PSTR module = tolower(mod); + // Visual Studio C runtime library DLLs + return ( strstr(module, "msvc") != NULL + || strstr(module, "ucrtbase") != NULL + || strstr(module, "vcruntime") != NULL + ); +} + // ========== Print Buffer functions #define BUFFER_SIZE 256 @@ -949,7 +964,7 @@ { DWORD i; char * s; - + dTHX; if (hDev != hCurrentDev) { hCurrentDev = hDev; @@ -1573,14 +1588,3 @@ srctWindow.Right = 79; srctWindow.Bottom = 24; SetConsoleWindowInfo(hConOut, TRUE, &srctWindow); - - - - - - - - - - -