Skip to content

Commit

Permalink
Merge pull request #4 from Modorganizer2/Develop
Browse files Browse the repository at this point in the history
Release 0.3.1.0
  • Loading branch information
LePresidente authored Apr 13, 2018
2 parents dc22de5 + ff1e376 commit 8a22297
Show file tree
Hide file tree
Showing 163 changed files with 14,705 additions and 1,667 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
/lib
/test/bin

# local overides
/vsbuild/external_dependencies_local.props

# build intermediates:
/vsbuild/Release
/vsbuild/Debug
Expand Down
22 changes: 22 additions & 0 deletions include/usvfs_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#define USVFS_VERSION_MAJOR 0
#define USVFS_VERSION_MINOR 3
#define USVFS_VERSION_BUILD 1
#define USVFS_VERSION_REVISION 0

#define USVFS_BUILD_STRING "-beta5"
#define USVFS_BUILD_WSTRING L"-beta5"

#ifndef USVFS_STRINGIFY
# define USVFS_STRINGIFY(x) USVFS_STRINGIFY_HELPER(x)
# define USVFS_STRINGIFY_HELPER(x) #x
#endif

#ifndef USVFS_STRINGIFYW
# define USVFS_STRINGIFYW(x) USVFS_STRINGIFYW_HELPER(x)
# define USVFS_STRINGIFYW_HELPER(x) L ## #x
#endif

#define USVFS_VERSION_STRING USVFS_STRINGIFY(USVFS_VERSION_MAJOR) "." USVFS_STRINGIFY(USVFS_VERSION_MINOR) "." USVFS_STRINGIFY(USVFS_VERSION_BUILD) "." USVFS_STRINGIFY(USVFS_VERSION_REVISION) USVFS_BUILD_STRING
#define USVFS_VERSION_WSTRING USVFS_STRINGIFYW(USVFS_VERSION_MAJOR) L"." USVFS_STRINGIFYW(USVFS_VERSION_MINOR) L"." USVFS_STRINGIFYW(USVFS_VERSION_BUILD) L"." USVFS_STRINGIFYW(USVFS_VERSION_REVISION) USVFS_BUILD_WSTRING
38 changes: 38 additions & 0 deletions src/shared/loghelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ along with usvfs. If not, see <http://www.gnu.org/licenses/>.

namespace ush = usvfs::shared;

std::ostream &usvfs::log::operator<<(std::ostream &os, const Wrap<DWORD> &value)
{
ush::FormatGuard guard(os);
os << std::hex << value.data();
return os;
}

std::ostream &usvfs::log::operator<<(std::ostream &os, const Wrap<NTSTATUS> &status)
{
Expand Down Expand Up @@ -68,6 +74,15 @@ std::ostream &usvfs::log::operator<<(std::ostream &os, const Wrap<PUNICODE_STRIN
return os;
}

static void writeToStream(std::ostream &os, LPCSTR str)
{
if (str == nullptr) {
os << "<null>";
}
else {
os << str;
}
}

static void writeToStream(std::ostream &os, LPCWSTR str)
{
Expand All @@ -78,6 +93,29 @@ static void writeToStream(std::ostream &os, LPCWSTR str)
}
}

std::ostream &usvfs::log::operator<<(std::ostream &os, const Wrap<LPSTR> &str)
{
try {
writeToStream(os, str.data());
}
catch (const std::exception &e) {
os << e.what();
}

return os;
}

std::ostream &usvfs::log::operator<<(std::ostream &os, const Wrap<LPCSTR> &str)
{
try {
writeToStream(os, str.data());
}
catch (const std::exception &e) {
os << e.what();
}

return os;
}

std::ostream &usvfs::log::operator<<(std::ostream &os, const Wrap<LPWSTR> &str)
{
Expand Down
3 changes: 3 additions & 0 deletions src/shared/loghelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ template <typename T>
Wrap<T> wrap(const T &data) { return Wrap<T>(data); }


std::ostream &operator<<(std::ostream &os, const Wrap<LPSTR> &str);
std::ostream &operator<<(std::ostream &os, const Wrap<LPWSTR> &str);
std::ostream &operator<<(std::ostream &os, const Wrap<LPCSTR> &str);
std::ostream &operator<<(std::ostream &os, const Wrap<LPCWSTR> &str);
std::ostream &operator<<(std::ostream &os, const Wrap<std::wstring> &str);

std::ostream &operator<<(std::ostream &os, const Wrap<PUNICODE_STRING> &str);
std::ostream &operator<<(std::ostream &os, const Wrap<NTSTATUS> &status);
std::ostream &operator<<(std::ostream &os, const Wrap<DWORD> &value);


spdlog::level::level_enum ConvertLogLevel(LogLevel level);
Expand Down
47 changes: 26 additions & 21 deletions src/shared/ntdll_declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,43 @@ along with usvfs. If not, see <http://www.gnu.org/licenses/>.
#define LOAD_EXT(mod, name) name = reinterpret_cast<name ## _type>(::GetProcAddress(mod, #name)); assert(name != nullptr)

NtQueryDirectoryFile_type NtQueryDirectoryFile;
NtQueryDirectoryFileEx_type NtQueryDirectoryFileEx;
NtQueryFullAttributesFile_type NtQueryFullAttributesFile;
NtQueryAttributesFile_type NtQueryAttributesFile;
NtOpenFile_type NtOpenFile;
NtCreateFile_type NtCreateFile;
NtClose_type NtClose;
RtlDoesFileExists_U_type RtlDoesFileExists_U;
RtlDosPathNameToRelativeNtPathName_U_WithStatus_type RtlDosPathNameToRelativeNtPathName_U_WithStatus;
RtlReleaseRelativeName_type RtlReleaseRelativeName;
RtlGetVersion_type RtlGetVersion;
NtTerminateProcess_type NtTerminateProcess;

static bool ntdll_initialized;

static struct __Initializer {
HMODULE m_NtDLLMod;
__Initializer() {
m_NtDLLMod = ::LoadLibrary(TEXT("ntdll.dll"));

if (m_NtDLLMod == nullptr) {
TerminateProcess(GetCurrentProcess(), 1);
return;
}
LOAD_EXT(m_NtDLLMod, NtQueryDirectoryFile);
LOAD_EXT(m_NtDLLMod, NtQueryFullAttributesFile);
LOAD_EXT(m_NtDLLMod, NtQueryAttributesFile);
LOAD_EXT(m_NtDLLMod, NtCreateFile);
LOAD_EXT(m_NtDLLMod, NtOpenFile);
LOAD_EXT(m_NtDLLMod, NtClose);
LOAD_EXT(m_NtDLLMod, RtlDoesFileExists_U);
LOAD_EXT(m_NtDLLMod, RtlGetVersion);
LOAD_EXT(m_NtDLLMod, NtTerminateProcess);
void ntdll_declarations_init() {
if (!ntdll_initialized) {
HMODULE ntDLLMod = GetModuleHandleW(L"ntdll.dll");

LOAD_EXT(ntDLLMod, NtQueryDirectoryFile);
LOAD_EXT(ntDLLMod, NtQueryDirectoryFileEx);
LOAD_EXT(ntDLLMod, NtQueryFullAttributesFile);
LOAD_EXT(ntDLLMod, NtQueryAttributesFile);
LOAD_EXT(ntDLLMod, NtCreateFile);
LOAD_EXT(ntDLLMod, NtOpenFile);
LOAD_EXT(ntDLLMod, NtClose);
LOAD_EXT(ntDLLMod, RtlDoesFileExists_U);
LOAD_EXT(ntDLLMod, RtlDosPathNameToRelativeNtPathName_U_WithStatus);
LOAD_EXT(ntDLLMod, RtlReleaseRelativeName);
LOAD_EXT(ntDLLMod, RtlGetVersion);
LOAD_EXT(ntDLLMod, NtTerminateProcess);

ntdll_initialized = true;
}
}

~__Initializer() {
// all hooks should be disabled by now. If not, this won't end well...
FreeLibrary(m_NtDLLMod);
static struct __Initializer {
__Initializer() {
ntdll_declarations_init();
}
} __initializer;
28 changes: 28 additions & 0 deletions src/shared/ntdll_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ typedef struct _FILE_REPARSE_POINT_INFORMATION {
#define STATUS_NO_MORE_FILES ((NTSTATUS)0x80000006L)
#define STATUS_NO_SUCH_FILE ((NTSTATUS)0xC000000FL)

#define SL_RESTART_SCAN 0x01
#define SL_RETURN_SINGLE_ENTRY 0x02
#define SL_INDEX_SPECIFIED 0x04
#define SL_RETURN_ON_DISK_ENTRIES_ONLY 0x08

#define SL_QUERY_DIRECTORY_MASK 0x0b

typedef enum _FILE_INFORMATION_CLASS {
FileDirectoryInformation = 1,
FileFullDirectoryInformation = 2,
Expand Down Expand Up @@ -245,6 +252,12 @@ typedef struct _OBJECT_HANDLE_INFORMATION {
ACCESS_MASK GrantedAccess;
} OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;

typedef struct _RTL_RELATIVE_NAME {
UNICODE_STRING RelativeName;
HANDLE ContainingDirectory;
void* CurDirRef;
} RTL_RELATIVE_NAME, *PRTL_RELATIVE_NAME;

typedef struct _FILE_NETWORK_OPEN_INFORMATION {
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
Expand All @@ -270,6 +283,10 @@ typedef NTSTATUS(WINAPI *NtQueryDirectoryFile_type)(
HANDLE, HANDLE, PIO_APC_ROUTINE, PVOID, PIO_STATUS_BLOCK, PVOID, ULONG,
FILE_INFORMATION_CLASS, BOOLEAN, PUNICODE_STRING, BOOLEAN);

typedef NTSTATUS(WINAPI *NtQueryDirectoryFileEx_type)(
HANDLE, HANDLE, PIO_APC_ROUTINE, PVOID, PIO_STATUS_BLOCK, PVOID, ULONG,
FILE_INFORMATION_CLASS, ULONG, PUNICODE_STRING);

typedef NTSTATUS(WINAPI *NtQueryFullAttributesFile_type)(
POBJECT_ATTRIBUTES, PFILE_NETWORK_OPEN_INFORMATION);

Expand All @@ -290,17 +307,25 @@ typedef NTSTATUS(WINAPI *NtClose_type)(HANDLE);

typedef NTSYSAPI BOOLEAN(NTAPI *RtlDoesFileExists_U_type)(PCWSTR);

typedef NTSTATUS(NTAPI *RtlDosPathNameToRelativeNtPathName_U_WithStatus_type)(
PCWSTR DosFileName, PUNICODE_STRING NtFileName, PWSTR* FilePath, PRTL_RELATIVE_NAME RelativeName);

typedef void (NTAPI *RtlReleaseRelativeName_type)(PRTL_RELATIVE_NAME RelativeName);

typedef NTSTATUS (NTAPI *RtlGetVersion_type)(PRTL_OSVERSIONINFOW);

typedef NTSTATUS(WINAPI *NtTerminateProcess_type)(HANDLE ProcessHandle, NTSTATUS ExitStatus);

extern NtQueryDirectoryFile_type NtQueryDirectoryFile;
extern NtQueryDirectoryFileEx_type NtQueryDirectoryFileEx;
extern NtQueryFullAttributesFile_type NtQueryFullAttributesFile;
extern NtQueryAttributesFile_type NtQueryAttributesFile;
extern NtOpenFile_type NtOpenFile;
extern NtCreateFile_type NtCreateFile;
extern NtClose_type NtClose;
extern RtlDoesFileExists_U_type RtlDoesFileExists_U;
extern RtlDosPathNameToRelativeNtPathName_U_WithStatus_type RtlDosPathNameToRelativeNtPathName_U_WithStatus;
extern RtlReleaseRelativeName_type RtlReleaseRelativeName;
extern RtlGetVersion_type RtlGetVersion;
extern NtTerminateProcess_type NtTerminateProcess;

Expand All @@ -311,4 +336,7 @@ extern ObDereferenceObject_type ObDereferenceObject;
extern RtlInitUnicodeString_type RtlInitUnicodeString;
*/

// ensures ntdll functions have been initialized (only needed during static objects initialization)
void ntdll_declarations_init();

#pragma warning(pop)
2 changes: 1 addition & 1 deletion src/shared/shmlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void SHMLogger::get(char *buffer, size_t bufferSize)
}

spdlog::sinks::shm_sink::shm_sink(const char *queueName)
: m_LogQueue(open_only, (std::string("__shm_sink_") + queueName).c_str())
: m_LogQueue(open_only, (std::string("__shm_sink_") + queueName).c_str()), m_DroppedMessages(0)
{
}

Expand Down
Loading

0 comments on commit 8a22297

Please sign in to comment.