Пример #1
0
bool tTVPApplication::StartApplication( int argc, char* argv[] ) {
	_set_se_translator(se_translator_function);

	ArgC = argc;
	ArgV = argv;
	for( int i = 0; i < argc; i++ ) {
		if(!strcmp(argv[i], "-@processohmlog")) {
			has_map_report_process_ = true;
		}
	}
	TVPTerminateCode = 0;

	CheckConsole();

	// try starting the program!
	bool engine_init = false;
	try {
		if(TVPCheckProcessLog()) return true; // sub-process for processing object hash map log

		TVPInitScriptEngine();
		engine_init = true;

		// banner
		TVPAddImportantLog( TVPFormatMessage(TVPProgramStartedOn, TVPGetOSName(), TVPGetPlatformName()) );

		// TVPInitializeBaseSystems
		TVPInitializeBaseSystems();

		Initialize();

		if(TVPCheckPrintDataPath()) return true;
		if(TVPExecuteUserConfig()) return true;
		
		image_load_thread_ = new tTVPAsyncImageLoader();

		TVPSystemInit();

		if(TVPCheckAbout()) return true; // version information dialog box;

		SetTitle( std::wstring(TVPKirikiri) );
		TVPSystemControl = new tTVPSystemControl();
#ifndef TVP_IGNORE_LOAD_TPM_PLUGIN
		TVPLoadPluigins(); // load plugin module *.tpm
#endif
		// Check digitizer
		CheckDigitizer();

		// start image load thread
		image_load_thread_->Resume();

		if(TVPProjectDirSelected) TVPInitializeStartupScript();

		Run();

		try {
			// image_load_thread_->ExitRequest();
			delete image_load_thread_;
			image_load_thread_ = NULL;
		} catch(...) {
			// ignore errors
		}
		try {
			TVPSystemUninit();
		} catch(...) {
			// ignore errors
		}
	} catch( const EAbort & ) {
		// nothing to do
	} catch( const Exception &exception ) {
		TVPOnError();
		if(!TVPSystemUninitCalled)
			ShowException(exception.what());
	} catch( const TJS::eTJSScriptError &e ) {
		TVPOnError();
		if(!TVPSystemUninitCalled)
			ShowException( e.GetMessage().c_str() );
	} catch( const TJS::eTJS &e) {
		TVPOnError();
		if(!TVPSystemUninitCalled)
			ShowException( e.GetMessage().c_str() );
	} catch( const std::exception &e ) {
		ShowException( ttstr(e.what()).c_str() );
	} catch( const char* e ) {
		ShowException( ttstr(e).c_str() );
	} catch( const wchar_t* e ) {
		ShowException( e );
	} catch( const SEHException& e ) {
		PEXCEPTION_RECORD rec = e.ExceptionPointers->ExceptionRecord;
		std::wstring text(SECodeToMessage(e.Code));
		ttstr result = TJSGetStackTraceString( 10 );
		PrintConsole( result.c_str(), result.length(), true );

		TVPDumpHWException();
		ShowException( text.c_str() );
	} catch(...) {
		ShowException( (const tjs_char*)TVPUnknownError );
	}

	if(engine_init) TVPUninitScriptEngine();

	if(TVPSystemControl) delete TVPSystemControl;
	TVPSystemControl = NULL;

	CloseConsole();

	return false;
}
Пример #2
0
USEFORM("..\..\..\..\tools\win32\krdevui\ConfMainFrameUnit.cpp", ConfMainFrame); /* TFrame: File Type */
//---------------------------------------------------------------------------
#ifdef TVP_SUPPORT_ERI
#	pragma link "../../../../Lib/liberina.lib"
#endif
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	// try starting the program!
	bool engine_init = false;
	try
	{
		if(TVPCheckProcessLog()) return 0; // sub-process for processing object hash map log


		TVPInitScriptEngine();
		engine_init = true;

		// banner
		TVPAddImportantLog(TJS_W("Program started on ") + TVPGetOSName() +
			TJS_W(" (") + TVPGetPlatformName() + TJS_W(")"));

		// TVPInitializeBaseSystems
		TVPInitializeBaseSystems();

		Application->Initialize();

		if(TVPCheckPrintDataPath()) return 0;
		if(TVPCheckCmdDescription()) return 0;
		if(TVPExecuteUserConfig()) return 0; // userconf

		TVPSystemInit();

		if(TVPCheckAbout()) return 0; // version information dialog box;

		Application->Title = "‹g—¢‹g—¢";
		Application->CreateForm(__classid(TTVPMainForm), &TVPMainForm);
		TVPLoadPluigins(); // load plugin module *.tpm
		if(TVPProjectDirSelected) TVPInitializeStartupScript();

		Application->Run();

		try
		{
			TVPSystemUninit();
		}
		catch(...)
		{
			// ignore errors
		}
	}
	catch (EAbort &e)
	{
		// nothing to do
	}
	catch (Exception &exception)
	{
		TVPOnError();
		if(!TVPSystemUninitCalled)
			Application->ShowException(&exception);
	}
	catch (eTJSScriptError &e)
	{
		TVPOnError();
		if(!TVPSystemUninitCalled)
			Application->ShowException(&Exception(e.GetMessage().AsAnsiString()));
	}
	catch (eTJS &e)
	{
		TVPOnError();
		if(!TVPSystemUninitCalled)
			Application->ShowException(&Exception(e.GetMessage().AsAnsiString()));
	}
	catch(...)
	{
		Application->ShowException(&Exception("Unknown error!"));
	}

	if(engine_init) TVPUninitScriptEngine();

#ifndef _DEBUG
	// delete application and exit forcely
	// this prevents ugly exception message on exit

	delete Application;
	ExitProcess(TVPTerminateCode);
#endif
	return TVPTerminateCode;
}
Пример #3
0
//---------------------------------------------------------------------------
void TVPDumpHWException()
{
	// dump latest hardware exception if it exists

	if(!TVPHWExcRaised) return;
	TVPHWExcRaised = false;

	TVPOnError();

	tjs_char buf[256];
	tTVPHWExceptionData * d = &TVPLastHWExceptionData;

	TVPAddLog(ttstr(TVPHardwareExceptionRaised));

	ttstr line;

	line = TJS_W("Exception : ");

	tjs_char *p = NULL;
	switch(d->Code)
	{
	case  3:	p = TJS_W("Divide By Zero"); break;
	case  4:	p = TJS_W("Range Error"); break;
	case  5:	p = TJS_W("Integer Overflow"); break;
	case  6:	p = TJS_W("Invalid Operation"); break;
	case  7:	p = TJS_W("Zero Divide"); break;
	case  8:	p = TJS_W("Overflow"); break;
	case  9:	p = TJS_W("Underflow"); break;
	case 10:	p = TJS_W("Invalid Cast"); break;
	case 11:	p = TJS_W("Access Violation"); break;
	case 12:	p = TJS_W("Privilege Violation"); break;
	case 13:	p = TJS_W("Control C"); break;
	case 14:	p = TJS_W("Stack Overflow"); break;
	}

	if(p) line += p;

	if(d->Code == 11)
	{
		// EAccessViolation
		const tjs_char *mode = TJS_W("unknown");
		if(d->AccessFlag == 0)
			mode = TJS_W("read");
		else if(d->AccessFlag == 1)
			mode = TJS_W("write");
		else if(d->AccessFlag == 8)
			mode = TJS_W("execute");
		TJS_sprintf(buf, TJS_W("(%ls access to 0x%p)"), mode, d->AccessTarget);
		line += buf;
	}

	TJS_sprintf(buf, TJS_W("  at  EIP = 0x%p   ESP = 0x%p"), d->EIP, d->ESP);
	line += buf;
	if(d->Module[0])
	{
		line += TJS_W("   in ") + ttstr(d->Module);
	}

	TVPAddLog(line);

	// dump OS context
	TVPDumpOSContext(d->Context);

	// dump codes at EIP
	line = TJS_W("Codes at EIP : ");
	for(tjs_int i = 0; i<d->CodesAtEIPLen; i++)
	{
		TJS_sprintf(buf, TJS_W("0x%02X "), d->CodesAtEIP[i]);
		line += buf;
	}
	TVPAddLog(line);

	TVPAddLog(TJS_W("Stack data and data pointed by each stack data :"));

	// dump stack and data
	for(tjs_int s = 0; s<d->StackAtESPLen; s++)
	{
		TJS_sprintf(buf, TJS_W("0x%p (ESP+%3d) : 0x%p : "),
			(DWORD)d->ESP + s*sizeof(tjs_uint32),
			s*sizeof(tjs_uint32), d->StackAtESP[s]);
		line = buf;

		for(tjs_int i = 0; i<d->StackDumpsLen[s]; i++)
		{
			TJS_sprintf(buf, TJS_W("0x%02X "), d->StackDumps[s][i]);
			line += buf;
		}
		TVPAddLog(line);
	}

	// dump call trace
	TVPAddLog(TJS_W("Call Trace :"));
	for(tjs_int s = 0; s<d->CallTraceLen; s++)
	{
		TJS_sprintf(buf, TJS_W("0x%p : "),
			d->CallTrace[s]);
		line = buf;

		for(tjs_int i = 0; i<d->CallTraceDumpsLen[s]; i++)
		{
			TJS_sprintf(buf, TJS_W("0x%02X "), d->CallTraceDumps[s][i]);
			line += buf;
		}
		MEMORY_BASIC_INFORMATION mbi;
		VirtualQuery((void*)d->CallTrace[s], &mbi, sizeof(mbi));
		if(mbi.State == MEM_COMMIT)
		{
			char module[MAX_PATH];
			if(GetModuleFileName((HMODULE)mbi.AllocationBase, module,
				MAX_PATH))
			{
				line += ttstr(ExtractFileName(module).c_str());
				TJS_sprintf(buf, TJS_W(" base 0x%p"), mbi.AllocationBase);
				line += buf;
			}
		}
		TVPAddLog(line);
	}
}