kernel32: Moved GetModuleBaseName[AW] implementation to kernel32.
This commit is contained in:
parent
8379893f96
commit
e6dd213d52
|
@ -772,6 +772,8 @@
|
||||||
@ stdcall K32GetProcessImageFileNameW(long ptr long)
|
@ stdcall K32GetProcessImageFileNameW(long ptr long)
|
||||||
@ stdcall K32EnumProcessModules(long ptr long ptr)
|
@ stdcall K32EnumProcessModules(long ptr long ptr)
|
||||||
@ stdcall K32EnumProcesses(ptr long ptr)
|
@ stdcall K32EnumProcesses(ptr long ptr)
|
||||||
|
@ stdcall K32GetModuleBaseNameA(long long ptr long)
|
||||||
|
@ stdcall K32GetModuleBaseNameW(long long ptr long)
|
||||||
@ stdcall K32GetProcessMemoryInfo(long ptr long)
|
@ stdcall K32GetProcessMemoryInfo(long ptr long)
|
||||||
@ stdcall K32QueryWorkingSet(long ptr long)
|
@ stdcall K32QueryWorkingSet(long ptr long)
|
||||||
@ stdcall K32QueryWorkingSetEx(long ptr long)
|
@ stdcall K32QueryWorkingSetEx(long ptr long)
|
||||||
|
|
|
@ -1125,6 +1125,29 @@ static int module_iterator_next(MODULE_ITERATOR *iter)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL get_ldr_module(HANDLE process, HMODULE module, LDR_MODULE *ldr_module)
|
||||||
|
{
|
||||||
|
MODULE_ITERATOR iter;
|
||||||
|
INT ret;
|
||||||
|
|
||||||
|
if (!init_module_iterator(&iter, process))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
while ((ret = module_iterator_next(&iter)) > 0)
|
||||||
|
/* When hModule is NULL we return the process image - which will be
|
||||||
|
* the first module since our iterator uses InLoadOrderModuleList */
|
||||||
|
if (!module || module == iter.ldr_module.BaseAddress)
|
||||||
|
{
|
||||||
|
*ldr_module = iter.ldr_module;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret == 0)
|
||||||
|
SetLastError(ERROR_INVALID_HANDLE);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* K32EnumProcessModules (KERNEL32.@)
|
* K32EnumProcessModules (KERNEL32.@)
|
||||||
*
|
*
|
||||||
|
@ -1155,6 +1178,55 @@ BOOL WINAPI K32EnumProcessModules(HANDLE process, HMODULE *lphModule,
|
||||||
return ret == 0;
|
return ret == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* K32GetModuleBaseNameW (KERNEL32.@)
|
||||||
|
*/
|
||||||
|
DWORD WINAPI K32GetModuleBaseNameW(HANDLE process, HMODULE module,
|
||||||
|
LPWSTR base_name, DWORD size)
|
||||||
|
{
|
||||||
|
LDR_MODULE ldr_module;
|
||||||
|
|
||||||
|
if (!get_ldr_module(process, module, &ldr_module))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
size = min(ldr_module.BaseDllName.Length / sizeof(WCHAR), size);
|
||||||
|
if (!ReadProcessMemory(process, ldr_module.BaseDllName.Buffer,
|
||||||
|
base_name, size * sizeof(WCHAR), NULL))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
base_name[size] = 0;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* K32GetModuleBaseNameA (KERNEL32.@)
|
||||||
|
*/
|
||||||
|
DWORD WINAPI K32GetModuleBaseNameA(HANDLE process, HMODULE module,
|
||||||
|
LPSTR base_name, DWORD size)
|
||||||
|
{
|
||||||
|
WCHAR *base_name_w;
|
||||||
|
DWORD len, ret = 0;
|
||||||
|
|
||||||
|
if(!base_name || !size) {
|
||||||
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
base_name_w = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * size);
|
||||||
|
if(!base_name_w)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
len = K32GetModuleBaseNameW(process, module, base_name_w, size);
|
||||||
|
TRACE("%d, %s\n", len, debugstr_w(base_name_w));
|
||||||
|
if (len)
|
||||||
|
{
|
||||||
|
ret = WideCharToMultiByte(CP_ACP, 0, base_name_w, len,
|
||||||
|
base_name, size, NULL, NULL);
|
||||||
|
if (ret < size) base_name[ret] = 0;
|
||||||
|
}
|
||||||
|
HeapFree(GetProcessHeap(), 0, base_name_w);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __i386__
|
#ifdef __i386__
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
@ stdcall GetDeviceDriverFileNameW(ptr ptr long)
|
@ stdcall GetDeviceDriverFileNameW(ptr ptr long)
|
||||||
@ stdcall GetMappedFileNameA(long ptr ptr long)
|
@ stdcall GetMappedFileNameA(long ptr ptr long)
|
||||||
@ stdcall GetMappedFileNameW(long ptr ptr long)
|
@ stdcall GetMappedFileNameW(long ptr ptr long)
|
||||||
@ stdcall GetModuleBaseNameA(long long ptr long)
|
@ stdcall GetModuleBaseNameA(long long ptr long) kernel32.K32GetModuleBaseNameA
|
||||||
@ stdcall GetModuleBaseNameW(long long ptr long)
|
@ stdcall GetModuleBaseNameW(long long ptr long) kernel32.K32GetModuleBaseNameW
|
||||||
@ stdcall GetModuleFileNameExA(long long ptr long)
|
@ stdcall GetModuleFileNameExA(long long ptr long)
|
||||||
@ stdcall GetModuleFileNameExW(long long ptr long)
|
@ stdcall GetModuleFileNameExW(long long ptr long)
|
||||||
@ stdcall GetModuleInformation(long long ptr long)
|
@ stdcall GetModuleInformation(long long ptr long)
|
||||||
|
|
|
@ -262,52 +262,6 @@ DWORD WINAPI GetMappedFileNameW(HANDLE hProcess, LPVOID lpv, LPWSTR lpFilename,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* GetModuleBaseNameA (PSAPI.@)
|
|
||||||
*/
|
|
||||||
DWORD WINAPI GetModuleBaseNameA(HANDLE hProcess, HMODULE hModule,
|
|
||||||
LPSTR lpBaseName, DWORD nSize)
|
|
||||||
{
|
|
||||||
WCHAR *lpBaseNameW;
|
|
||||||
DWORD buflenW, ret = 0;
|
|
||||||
|
|
||||||
if(!lpBaseName || !nSize) {
|
|
||||||
SetLastError(ERROR_INVALID_PARAMETER);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
lpBaseNameW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * nSize);
|
|
||||||
buflenW = GetModuleBaseNameW(hProcess, hModule, lpBaseNameW, nSize);
|
|
||||||
TRACE("%d, %s\n", buflenW, debugstr_w(lpBaseNameW));
|
|
||||||
if (buflenW)
|
|
||||||
{
|
|
||||||
ret = WideCharToMultiByte(CP_ACP, 0, lpBaseNameW, buflenW,
|
|
||||||
lpBaseName, nSize, NULL, NULL);
|
|
||||||
if (ret < nSize) lpBaseName[ret] = 0;
|
|
||||||
}
|
|
||||||
HeapFree(GetProcessHeap(), 0, lpBaseNameW);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* GetModuleBaseNameW (PSAPI.@)
|
|
||||||
*/
|
|
||||||
DWORD WINAPI GetModuleBaseNameW(HANDLE hProcess, HMODULE hModule,
|
|
||||||
LPWSTR lpBaseName, DWORD nSize)
|
|
||||||
{
|
|
||||||
LDR_MODULE LdrModule;
|
|
||||||
|
|
||||||
if (!PSAPI_GetLdrModule(hProcess, hModule, &LdrModule))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
nSize = min(LdrModule.BaseDllName.Length / sizeof(WCHAR), nSize);
|
|
||||||
if (!ReadProcessMemory(hProcess, LdrModule.BaseDllName.Buffer,
|
|
||||||
lpBaseName, nSize * sizeof(WCHAR), NULL))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
lpBaseName[nSize] = 0;
|
|
||||||
return nSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* GetModuleFileNameExA (PSAPI.@)
|
* GetModuleFileNameExA (PSAPI.@)
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue