Skip to content

Commit

Permalink
segfault fix test 5
Browse files Browse the repository at this point in the history
  • Loading branch information
kernelwernel committed Dec 25, 2023
1 parent 08de52a commit 240d87e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 30 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD_REQUIRED ON)

# CTest stuff
include(CTest)
#find_package(Python REQUIRED)
find_package(Python REQUIRED)
enable_testing()
add_test(executable, "${CMAKE_SOURCE_DIR}/bin/${TARGET}")
#if(NOT MSVC)
#add_test(
# checks
# ${Python_EXECUTABLE} "${CMAKE_SOURCE_DIR}/cmake/ctest_checks.py"
#)
#endif()
if(NOT MSVC)
add_test(
checks
${Python_EXECUTABLE} "${CMAKE_SOURCE_DIR}/cmake/ctest_checks.py"
)
endif()


# release stuff
Expand Down
Binary file removed resources/attacks_on_VMs.pdf
Binary file not shown.
58 changes: 35 additions & 23 deletions src/vmaware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,14 +792,6 @@ struct VM {
return (!(flags & p_flag));
}

// same as above but for checking enabled flags
#if (LINUX && __has_cpp_attribute(gnu::pure))
[[gnu::pure]]
#endif
[[nodiscard]] static inline bool enabled(const u64 p_flag) noexcept {
return (flags & p_flag);
}

// easier way to check if the result is memoized
[[nodiscard]] static inline bool is_memoized() noexcept {
return (
Expand Down Expand Up @@ -3102,16 +3094,45 @@ struct VM {
return false;
}

return false;

/*
#if (!MSVC)
return false;
#else
auto check_wmic_presence = []() -> bool {
FILE* pipe = _popen("wmic /?", "r");

if (pipe) {
char buffer[128];
while (!feof(pipe)) {
if (fgets(buffer, 128, pipe) != nullptr)
return true;
}
_pclose(pipe);
} else {
return false;
}
};

if (check_wmic_presence() == false) {
#ifdef __VMAWARE_DEBUG__
debug("BIOS_SERIAL: ", "wmic isn't found, returned false");
#endif
return false;
}

std::unique_ptr<std::string> bios = sys_result("wmic bios get serialnumber");

const std::size_t nl_pos = bios->find('\n');
std::string extract = bios->substr(nl_pos + 1);
const std::string str = std::move(*bios);
const std::size_t nl_pos = str.find('\n');

if (nl_pos == std::string::npos) {
return false;
}

#ifdef __VMAWARE_DEBUG__
debug("BIOS_SERIAL: ", str);
#endif

const std::string extract = str.substr(nl_pos + 1);

const bool all_digits = std::all_of(extract.cbegin(), extract.cend(), [](const char c) {
return std::isdigit(c);
Expand All @@ -3125,7 +3146,6 @@ struct VM {

return false;
#endif
*/
} catch (...) {
#ifdef __VMAWARE_DEBUG__
debug("BIOS_SERIAL: catched error, returned false");
Expand Down Expand Up @@ -3642,10 +3662,7 @@ struct VM {
if (disabled(HYPERV_WMI)) {
return false;
}

return false; // TEMPORARY

/*
#if (!MSVC)
return false;
#else
Expand Down Expand Up @@ -3677,7 +3694,6 @@ struct VM {
return false;
}

// Connect to WMI
IWbemLocator *pLoc = NULL;
hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc);

Expand Down Expand Up @@ -3782,7 +3798,6 @@ struct VM {

return is_vm;
#endif
*/
} catch (...) {
#ifdef __VMAWARE_DEBUG__
debug("HYPERV_WMI: ", "catched error, returned false");
Expand All @@ -3802,8 +3817,6 @@ struct VM {
return false;
}

return false; // TEMPORARY
/*
#if (!MSVC)
return false;
#else
Expand Down Expand Up @@ -3853,7 +3866,6 @@ struct VM {

return is_vm;
#endif
*/
} catch (...) {
#ifdef __VMAWARE_DEBUG__
debug("HYPERV_WMI: ", "catched error, returned false");
Expand Down Expand Up @@ -3988,7 +4000,7 @@ struct VM {

bool result = false;

if (enabled(EXTREME)) {
if (disabled(EXTREME)) {
result = (points > 0);
} else {
result = (points >= 100);
Expand Down

0 comments on commit 240d87e

Please sign in to comment.