Esempio n. 1
0
FString GetModuleDirPrefix()
{
  FString s;
  if (MyGetModuleFileName(s))
  {
    int pos = s.ReverseFind_PathSepar();
    if (pos >= 0)
      s.DeleteFrom(pos + 1);
  }
  if (s.IsEmpty())
    s = "." STRING_PATH_SEPARATOR;
  return s;
}
Esempio n. 2
0
FString GetModuleDirPrefix()
{
  FString s;
  if (MyGetModuleFileName(s))
  {
    int pos = s.ReverseFind(FCHAR_PATH_SEPARATOR);
    if (pos >= 0)
    {
      s.DeleteFrom(pos + 1);
      return s;
    }
  }
  return FTEXT(".") FSTRING_PATH_SEPARATOR;
}
Esempio n. 3
0
void KLabDbgTraceW(const char *pszFileName, int nLine, BOOL bAssert, const WCHAR *pszFormat, ...)
{
	MyGetModuleFileName();

	const int nCount = 1024;
	WCHAR szBuf[nCount] = {'\0'};
	int nLen = 0;

	nLen += _snwprintf(szBuf + nLen, nCount - nLen, L"%s:%S:%d(%x) %s ", s_strModuleName, pszFileName, nLine, 
		GetCurrentThreadId(), bAssert ? L"-assert failed-" : L"");

	va_list ptr; 
	va_start(ptr, pszFormat);
	nLen += _vsnwprintf(szBuf + nLen, nCount - nLen, pszFormat, ptr);
	va_end(ptr);

	lstrcpynW(szBuf + nLen, L"\n", min(2, nCount - nLen));

	OutputDebugStringW(szBuf);
}
Esempio n. 4
0
bool MyGetModuleFileName(HMODULE hModule, UString &result)
{
  result.Empty();
  if (g_IsNT)
  {
    wchar_t fullPath[MAX_PATH + 2];
    DWORD size = ::GetModuleFileNameW(hModule, fullPath, MAX_PATH + 1);
    if (size <= MAX_PATH && size != 0)
    {
      result = fullPath;
      return true;
    }
    return false;
  }
  CSysString resultSys;
  if (!MyGetModuleFileName(hModule, resultSys))
    return false;
  result = MultiByteToUnicodeString(resultSys, GetCurrentCodePage());
  return true;
}
Esempio n. 5
0
File: delself.c Progetto: jaykrell/j
int wmain()
{
    WCHAR* MyPath = { 0 };
    WCHAR* AnotherPath = { 0 };
    BOOL Success = { 0 };
    DWORD Error = { 0 };
    UUID Uuid = { 0 };
    HMODULE MyDllHandle = { 0 };
    ULONG MyPathLength = { 0 };
    HANDLE FileHandle = INVALID_HANDLE_VALUE;
    ULONG AnotherPathLength = { 0 };
    STARTUPINFOW StartupInfo = { sizeof(StartupInfo) };
    PROCESS_INFORMATION ProcessInfo = { 0 };
    WCHAR* Dot = { 0 };

    MyDllHandle = GetModuleHandleW(NULL);
    wprintf(L"MyDllHandle is %x\n", MyDllHandle);

    UnmapViewOfFile(MyDllHandle);

    MyPath = MyGetModuleFileName(MyDllHandle);

    Dot = wcschr(MyPath, L'.');
    if (Dot != NULL)
    {
        if (_wcsicmp(Dot, L".exe") != 0)
        {
            *Dot = 0;
            while (!DeleteFileW(MyPath) && (GetLastError() == ERROR_ACCESS_DENIED))
            {
                Sleep(1);
            }
        }
    }
    else
    {
        MyPathLength = (1 + wcslen(MyPath));

        AnotherPathLength = (MyPathLength + 1 + (sizeof(UUID) * 8 / 4));
        AnotherPath = (WCHAR*) calloc(sizeof(WCHAR), AnotherPathLength);
        UuidCreate(&Uuid);
        CopyMemory(AnotherPath, MyPath, (MyPathLength * sizeof(WCHAR)));
        ToHex((AnotherPath + MyPathLength - 1), ((BYTE*) &Uuid), sizeof(Uuid));

        Success = CopyFileW(MyPath, AnotherPath, FALSE);
        wprintf(L"CopyFileW(%ls,%ls):%x,%x\n", MyPath, AnotherPath, Success, Error);

        FileHandle = CreateFileW(AnotherPath, (DELETE | GENERIC_READ | SYNCHRONIZE),
                (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE), NULL,
                CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);
        Error = GetLastError();        
        wprintf(L"CreateFile(%ls, delete-on-close):%x,%x\n", AnotherPath, (FileHandle != INVALID_HANDLE_VALUE), Error);

        //Success = MoveFileW(MyPath, AnotherPath);
        //wprintf(L"MoveFile(%ls,%ls):%x,%x\n", MyPath, AnotherPath, Success, Error);

        CreateProcessW(AnotherPath, AnotherPath, NULL, NULL, FALSE, 0, NULL, NULL, &StartupInfo, &ProcessInfo);
    }


    free(MyPath);
    free(AnotherPath);
    if (FileHandle != INVALID_HANDLE_VALUE)
        CloseHandle(FileHandle);
    return 0;
}