Jump to content

Crash Reporter System


Recommended Posts

  • Bot

M2 Download Center

This is the hidden content, please
( Internal )

Client Binary Source -> Eterbase/error.cpp

#include "StdAfx.h"
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <time.h>
#include <imagehlp.h>
#include <ws2tcpip.h>
#include <winsock.h>
#pragma comment (lib, "wsock32.lib")

static const char *Website_Host = "www.mymetin2server.com";
static const char *Website_ScriptName = "/errorlog.php";
static const char *ErrorLog_FileName = "ErrorLog.txt";
static const std::string page_password = "Insert_Your_Website_Page_Password";
FILE * fException;
static char __msg[4000];
static int __idx;
typedef BOOL(CALLBACK *PENUMLOADED_MODULES_CALLBACK)(__in PCSTR ModuleName, __in ULONG ModuleBase, __in ULONG ModuleSize, __in_opt PVOID UserContext);

void Send_Request(const char* verb, const char* hostname, int port, const char* resource, const char* opt_urlencoded, std::string& response)
{
	WSADATA wsaData;
	if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) return;
	SOCKET Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	struct hostent *host;
	host = gethostbyname(hostname);
	SOCKADDR_IN SockAddr;
	SockAddr.sin_port = htons(port);
	SockAddr.sin_family = AF_INET;
	SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
	if (connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) != 0) return;
	std::string req = verb;
	req.append(" ");
	req.append(resource);
	req.append(" HTTP/1.1\r\n");
	req.append("Host: ");
	req.append(hostname);
	req.append(":");
	req.append(std::to_string(port));
	req.append("\r\n");
	if (strcmp(verb, "POST") == 0)
	{
		req.append("Cache-Control: no-cache\r\n");
		req.append("Content-length: ");
		req.append(std::to_string(strlen(opt_urlencoded)));
		req.append("\r\n");
		req.append("Content-Type: application/x-www-form-urlencoded\r\n\r\n");
		req.append(opt_urlencoded);
	}
	else
	{
		req.append("Cache-Control: no-cache\r\n");
		req.append("Connection: close\r\n\r\n");
	}
	send(Socket, req.c_str(), req.size(), 0);
	char buffer[1024];
	recv(Socket, buffer, 1024, 0);
	response += std::string(buffer);
	closesocket(Socket);
	WSACleanup();
}

std::string urlencode(std::string str){
	std::string new_str = "";
	char c;
	int ic;
	const char* chars = str.c_str();
	char bufHex[10];
	int len = strlen(chars);
	for (int i = 0; i<len; i++){
		c = chars[i];
		ic = c;
		if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') new_str += c;
		else {
			sprintf(bufHex, "%X", c);
			if (ic < 16)
				new_str += "%0";
			else
				new_str += "%";
			new_str += bufHex;
		}
	}
	return new_str;
}

bool send_errorlog(std::string msg)
{
	std::string data = "password=" + page_password + "&message=" + urlencode(msg);
	std::string response;
	Send_Request("POST", Website_Host, 80, Website_ScriptName, data.c_str(), response);
	if (strstr(response.c_str(), "OK_SENT")) return true; else return false;
}

#if _MSC_VER >= 1400
BOOL CALLBACK EnumerateLoadedModulesProc(PCSTR ModuleName, ULONG ModuleBase, ULONG ModuleSize, PVOID UserContext)
#else
BOOL CALLBACK EnumerateLoadedModulesProc(PSTR ModuleName, ULONG ModuleBase, ULONG ModuleSize, PVOID UserContext)
#endif
{
	DWORD offset = *((DWORD*)UserContext);
	
	if (offset >= ModuleBase && offset <= ModuleBase + ModuleSize)
	{
		fprintf(fException, "%s", ModuleName);
		__idx += sprintf(__msg+__idx, "%s", ModuleName);
		return FALSE;
	}
	else
		return TRUE;
}

LONG __stdcall EterExceptionFilter(_EXCEPTION_POINTERS* pExceptionInfo)
{
	HANDLE		hProcess	= GetCurrentProcess();
	HANDLE		hThread		= GetCurrentThread();
	fException = fopen(ErrorLog_FileName, "wt");
	if (fException)
	{
		char module_name[256];
		time_t module_time;
		HMODULE hModule = GetModuleHandle(NULL);
		GetModuleFileName(hModule, module_name, sizeof(module_name));
		module_time = (time_t)GetTimestampForLoadedLibrary(hModule);
		fprintf(fException, "Module Name: %s\n", module_name);
		fprintf(fException, "Time Stamp: 0x%08x - %s\n", module_time, ctime(&module_time));
		fprintf(fException, "\n");
		fprintf(fException, "Exception Type: 0x%08x\n", pExceptionInfo->ExceptionRecord->ExceptionCode);
		fprintf(fException, "\n");

		{
			__idx+=sprintf(__msg+__idx,"Module Name: %s\n", module_name);
			__idx+=sprintf(__msg+__idx, "Time Stamp: 0x%08x - %s\n", module_time, ctime(&module_time));
			__idx+=sprintf(__msg+__idx, "\n");
			__idx+=sprintf(__msg+__idx, "Exception Type: 0x%08x\n", pExceptionInfo->ExceptionRecord->ExceptionCode);
			__idx+=sprintf(__msg+__idx, "\n");
		}
		
		CONTEXT&	context		= *pExceptionInfo->ContextRecord;
		
		fprintf(fException, "eax: 0x%08x\tebx: 0x%08x\n", context.Eax, context.Ebx);
		fprintf(fException, "ecx: 0x%08x\tedx: 0x%08x\n", context.Ecx, context.Edx);
		fprintf(fException, "esi: 0x%08x\tedi: 0x%08x\n", context.Esi, context.Edi);
		fprintf(fException, "ebp: 0x%08x\tesp: 0x%08x\n", context.Ebp, context.Esp);
		fprintf(fException, "\n");

		{
			__idx+=sprintf(__msg+__idx, "eax: 0x%08x\tebx: 0x%08x\n", context.Eax, context.Ebx);
			__idx+=sprintf(__msg+__idx, "ecx: 0x%08x\tedx: 0x%08x\n", context.Ecx, context.Edx);
			__idx+=sprintf(__msg+__idx, "esi: 0x%08x\tedi: 0x%08x\n", context.Esi, context.Edi);
			__idx+=sprintf(__msg+__idx, "ebp: 0x%08x\tesp: 0x%08x\n", context.Ebp, context.Esp);
			__idx+=sprintf(__msg+__idx, "\n");
		}
		
		STACKFRAME stackFrame = {0,};
		stackFrame.AddrPC.Offset	= context.Eip;
		stackFrame.AddrPC.Mode		= AddrModeFlat;
		stackFrame.AddrStack.Offset	= context.Esp;
		stackFrame.AddrStack.Mode	= AddrModeFlat;
		stackFrame.AddrFrame.Offset	= context.Ebp;
		stackFrame.AddrFrame.Mode	= AddrModeFlat;
		
		for (int i=0; i < 512 && stackFrame.AddrPC.Offset; ++i)
		{
			if (StackWalk(IMAGE_FILE_MACHINE_I386, hProcess, hThread, &stackFrame, &context, NULL, NULL, NULL, NULL) != FALSE)
			{
				fprintf(fException, "0x%08x\t", stackFrame.AddrPC.Offset);
				__idx+=sprintf(__msg+__idx, "0x%08x\t", stackFrame.AddrPC.Offset);
				EnumerateLoadedModules(hProcess, (PENUMLOADED_MODULES_CALLBACK) EnumerateLoadedModulesProc, &stackFrame.AddrPC.Offset);
				fprintf(fException, "\n");
				__idx+=sprintf(__msg+__idx,  "\n");
			}
			else
			{
				break;
			}
		} 
		
		fprintf(fException, "\n");
		__idx+=sprintf(__msg+__idx, "\n");
		BYTE* stack = (BYTE*)(context.Esp);
		fprintf(fException, "stack %08x - %08x\n", context.Esp, context.Esp+1024);
		__idx+=sprintf(__msg+__idx, "stack %08x - %08x\n", context.Esp, context.Esp+1024);
		
		for(int i=0; i<16; ++i)
		{
			fprintf(fException, "%08X : ", context.Esp+i*16);
			__idx+=sprintf(__msg+__idx, "%08X : ", context.Esp+i*16);
			for(int j=0; j<16; ++j)
			{
				fprintf(fException, "%02X ", stack[i*16+j]);
				__idx+=sprintf(__msg+__idx, "%02X ", stack[i*16+j]);
			}
			fprintf(fException, "\n");
			__idx+=sprintf(__msg+__idx, "\n");
		}
		fprintf(fException, "\n");
		__idx+=sprintf(__msg+__idx, "\n");
		fflush(fException);
		fclose(fException);
		fException = NULL;
		if (send_errorlog(__msg)) {
			FILE *f = fopen("syserr.txt", "w");
			fputs("We found an exception that kill the client process.\nWe have sent your ErrorLog to our data center.\nWe will solve your problem soon.", f);
			fclose(f);
		}else{
			FILE *f = fopen("syserr.txt", "w");
			fputs("We found an exception that kill the client process.\nWe tried to send your ErrorLog to our data center.\nBut the operation was failed.", f);
			fclose(f);
		}
	}
	return EXCEPTION_EXECUTE_HANDLER;
}

void SetEterExceptionHandler()
{
	SetUnhandledExceptionFilter(EterExceptionFilter);
}

On your website: create errorlog.php

<?php

if (isset($_REQUEST["password"])) {

	if ($_REQUEST["password"] == "Insert_Your_Website_Page_Password") {

		if (strlen($_REQUEST["message"]) > 0) {
			$file=fopen("ErrorLogs_Player.txt", "a");
			fwrite($file, $_REQUEST["message"]);
			fclose($file);
			echo "OK_SENT";
		}else{

			echo "ERROR";			

		}

	}else{
		header("Location: index.php");
	}

}else{
	header("Location: index.php");
}

?>

 

  • Metin2 Dev 6
  • Good 2
  • Love 3

english_banner.gif

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Announcements



×
×
  • 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.