Jump to content

[C] Stopping Wine emulation


Recommended Posts

This is a snippet from my anti-cheat system, MetinGuard.

Wine is commonly used in reverse engineering as you can run PE (Windows executables) in an emulated environment, ntdll.dll on Wine will export the functions below listed in lpBadFunctions - we can try and get the address in the export table by using GetProcAddress and seeing if it succeeds.

This is just a small part of MetinGuard's anti reverse engineering module.

#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
BOOL bCheckWine()
{
	LPCSTR lpBadFunctions[] = {
		"wine_get_unix_file_name", "wine_get_version",
		"wine_nt_to_unix_file_name", "wine_server_call",
		"wine_server_handle_to_fd", "wine_server_release_fd",
		"__wine_init_codepages"
	};

	HANDLE hNtLib = LoadLibraryA("ntdll.dll");
	if (hNtLib == NULL)
	{
		return FALSE;
	}

	LPVOID lpNtFunc = NULL;
	for (SIZE_T i = 0; i < ARRAY_SIZE(lpBadFunctions); i++)
	{
		lpNtFunc = GetProcAddress(hNtLib, lpBadFunctions[i]);
		if (lpNtFunc != NULL)
		{
			FreeLibrary(hNtLib);
			return TRUE;
		}
	}
	FreeLibrary(hNtLib);
	return FALSE;
}

 

  • Love 3
Link to comment
Share on other sites

4 minutes ago, tierrilopes said:

Not sure what the goal was, but to me it only gave me reasons to dont buy it.

__

But a release is a release and im sure it may help someone.

Good luck on your service.

The goal it to detect Wine which is an emulation environment on Linux, which allows you to run Windows executables. Its usually used when reverse engineering, this will simply detect that environment.

55 minutes ago, Koray said:

FreeLibrary(lpNtFunc);

wat?

Yeah I actually posted an old version which had been quickly mashed together, got my Git branches mucked up, updated the OP.

  • Love 1
Link to comment
Share on other sites

  • Active Member
16 minutes ago, MetinGuard said:

Yeah I actually posted an old version which had been quickly mashed together, got my Git branches mucked up, updated the OP.

 

You don't need create new define macro (#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))) Because there is already have a another one (_countof).

LoadLibrary API don't return as HANDLE so you should convert to HMODULE or similar memory pointer.

LoadLibrary API don't give INVALID_HANDLE_VALUE aka. -1 value if is failed you will get null pointer.

You should free ntdll module not export's pointer.

  • Love 1
Link to comment
Share on other sites

A macro is a macro, they do the same things, ARRAY_SIZE looks a lot cleaner to me. But yeah, they both serve the same prupose.

No, HMODULE is a typedef of HINSTANCE which is a typedef of HANDLE.

Wow, that was a stupid mistake.

24 minutes ago, Koray said:

 

You don't need create new define macro (#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))) Because there is already have a another one (_countof).

LoadLibrary API don't return as HANDLE so you should convert to HMODULE or similar memory pointer.

LoadLibrary API don't give INVALID_HANDLE_VALUE aka. -1 value if is failed you will get null pointer.

You should free ntdll module not export's pointer.

 

  • Love 2
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



  • Similar Content

  • Activity

    1. 0

      Quest 6/7 Problem

    2. 5

      Effect weapons

    3. 3

      Crystal Metinstone

    4. 3

      Feeding game source to LLM

    5. 113

      Ulthar SF V2 (TMP4 Base)

    6. 3

      Feeding game source to LLM

    7. 0

      Target Information System

    8. 3

      Feeding game source to LLM

  • Recently Browsing

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.