2016-11-01 03:36:32 -07:00
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "app-helpers.h"
|
|
|
|
#include "nt-stuff.h"
|
|
|
|
|
|
|
|
WINADVAPI WINAPI ConvertSidToStringSidW(PSID sid, LPWSTR *str);
|
|
|
|
|
|
|
|
bool is_app(HANDLE process)
|
|
|
|
{
|
|
|
|
DWORD size_ret;
|
|
|
|
DWORD ret = 0;
|
|
|
|
HANDLE token;
|
|
|
|
|
|
|
|
if (OpenProcessToken(process, TOKEN_QUERY, &token)) {
|
|
|
|
BOOL success = GetTokenInformation(token, TokenIsAppContainer,
|
2019-06-22 22:13:45 -07:00
|
|
|
&ret, sizeof(ret),
|
|
|
|
&size_ret);
|
2016-11-01 03:36:32 -07:00
|
|
|
if (!success) {
|
|
|
|
DWORD error = GetLastError();
|
|
|
|
int test = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(token);
|
|
|
|
}
|
|
|
|
return !!ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
wchar_t *get_app_sid(HANDLE process)
|
|
|
|
{
|
|
|
|
wchar_t *ret = NULL;
|
|
|
|
DWORD size_ret;
|
|
|
|
BOOL success;
|
|
|
|
HANDLE token;
|
|
|
|
|
|
|
|
if (OpenProcessToken(process, TOKEN_QUERY, &token)) {
|
|
|
|
DWORD info_len = GetSidLengthRequired(12) +
|
2019-06-22 22:13:45 -07:00
|
|
|
sizeof(TOKEN_APPCONTAINER_INFORMATION);
|
2016-11-01 03:36:32 -07:00
|
|
|
|
|
|
|
PTOKEN_APPCONTAINER_INFORMATION info = malloc(info_len);
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
success = GetTokenInformation(token, TokenAppContainerSid, info,
|
|
|
|
info_len, &size_ret);
|
2016-11-01 03:36:32 -07:00
|
|
|
if (success)
|
|
|
|
ConvertSidToStringSidW(info->TokenAppContainer, &ret);
|
|
|
|
|
|
|
|
free(info);
|
|
|
|
CloseHandle(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const wchar_t *path_format =
|
|
|
|
L"\\Sessions\\%lu\\AppContainerNamedObjects\\%s\\%s";
|
|
|
|
|
|
|
|
HANDLE open_app_mutex(const wchar_t *sid, const wchar_t *name)
|
|
|
|
{
|
|
|
|
wchar_t path[MAX_PATH];
|
|
|
|
DWORD session_id = WTSGetActiveConsoleSessionId();
|
|
|
|
_snwprintf(path, MAX_PATH, path_format, session_id, sid, name);
|
|
|
|
return nt_open_mutex(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE open_app_event(const wchar_t *sid, const wchar_t *name)
|
|
|
|
{
|
|
|
|
wchar_t path[MAX_PATH];
|
|
|
|
DWORD session_id = WTSGetActiveConsoleSessionId();
|
|
|
|
_snwprintf(path, MAX_PATH, path_format, session_id, sid, name);
|
|
|
|
return nt_open_event(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE open_app_map(const wchar_t *sid, const wchar_t *name)
|
|
|
|
{
|
|
|
|
wchar_t path[MAX_PATH];
|
|
|
|
DWORD session_id = WTSGetActiveConsoleSessionId();
|
|
|
|
_snwprintf(path, MAX_PATH, path_format, session_id, sid, name);
|
|
|
|
return nt_open_map(path);
|
|
|
|
}
|