⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 数据加密算法
💻 CPP
字号:
#include "pch.h"
#include "main.h"
#include "frame.h"
#include "doc.h"
#include "about.h"
#include "page.h"
#include "debug.h"

BEGIN_MESSAGE_MAP ( CMainApp , CWinApp )
	ON_COMMAND ( IDM_FILE_OPEN , OnFileOpen )
	ON_COMMAND ( IDM_FILE_EXIT , OnAppExit )
	ON_COMMAND ( IDM_HELP_CONTENT , OnHelpContent )
	ON_COMMAND ( IDM_HELP_ABOUT , OnHelpAbout )
	ON_COMMAND ( IDM_EDIT_OPTION , OnEditOption )
END_MESSAGE_MAP ( )

CMainApp theApp ;

CMainApp::CMainApp ( )
{
	// reset attribute
	m_appOption.m_bCheckDebugger = TRUE ;
	m_appOption.m_bHookExplicit = TRUE ;

	m_appOption.m_bRecordDebugMsg = TRUE ;
	m_appOption.m_bRecordExtraMsg = TRUE ;
	m_appOption.m_bNotify = FALSE ;
	m_appOption.m_bDumpFile = FALSE ;

	m_appOption.m_bDisplay = TRUE ;
	m_appOption.m_bDisplaySync = TRUE ;

	m_appOption.m_dwMaxDisplay = 1000 ;
}

CMainApp::~CMainApp ( )
{
}

BOOL CMainApp::InitInstance ( )
{
	// add document template
	CMultiDocTemplate* p = new CMultiDocTemplate (
		IDR_DANCER_FRAME ,
		RUNTIME_CLASS ( CDancerDoc ) ,
		RUNTIME_CLASS ( CDancerFrame ) ,
		NULL ) ;
	AddDocTemplate ( p ) ;

	// get from registry
	SetRegistryKey ( _T("Mirager") ) ;
	LoadStdProfileSettings ( ) ;

	CHAR sec [ ] = "Settings" ;

	// all settings
	m_appOption.m_bCheckDebugger = GetProfileInt ( sec , "Hide Debugger" , TRUE ) ;
	m_appOption.m_bDisplay = GetProfileInt ( sec , "Display" , TRUE ) ;
	m_appOption.m_bDisplaySync = GetProfileInt ( sec , "Display Sync" , TRUE ) ;
	m_appOption.m_bDumpFile = GetProfileInt ( sec , "Dump To File" , FALSE ) ;
	m_appOption.m_bHookExplicit = GetProfileInt ( sec , "Explicit" , TRUE ) ;
	m_appOption.m_bGetRegister = GetProfileInt ( sec , "Get Register" , TRUE ) ;
	m_appOption.m_bNotify = GetProfileInt ( sec , "Notify" , FALSE ) ;
	m_appOption.m_bRecordDebugMsg = GetProfileInt ( sec , "Record Debug" , TRUE ) ;
	m_appOption.m_bRecordExtraMsg = GetProfileInt ( sec , "Record Extra" , TRUE ) ;
	m_appOption.m_dwMaxDisplay = GetProfileInt ( sec , "Max Display" , 10000 ) ;
	m_appOption.m_bViewAll = GetProfileInt ( sec , "View All Functions" , TRUE ) ;
	m_appOption.m_bUndecorate = GetProfileInt ( sec , "Undecorate C++ Functions" , TRUE ) ;

	int i ;
	CString key , tmp1 , tmp2 , str ;

	// user-decoders
	for ( i = 0 , key = "Decoder" ; ; i++ )
	{
		tmp1 = key ;
		tmp2.Format ( "%d" , i ) ;
		tmp1 += tmp2 ;
		
		str = GetProfileString ( sec , tmp1 , NULL ) ;
		if ( str.IsEmpty ( ) ) break ;

		m_appOption.m_arDecoder.Add ( str ) ;
	}

	// type-describing file
	for ( i = 0 , key = "Type" ; ; i++ )
	{
		tmp1 = key ;
		tmp2.Format ( "%d" , i ) ;
		tmp1 += tmp2 ;
		
		str = GetProfileString ( sec , tmp1 , NULL ) ;
		if ( str.IsEmpty ( ) ) break ;

		m_appOption.m_arTypeFile.Add ( str ) ;
	}

	// create main window
	m_pMainWnd = new CMainFrame ;

	CCommandLineInfo cmdInfo ;
	ParseCommandLine ( cmdInfo ) ;

	if ( cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew )
	{
		cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing ;
	}
	if ( ProcessShellCommand ( cmdInfo ) == FALSE )
		return FALSE ;

	m_pMainWnd->DragAcceptFiles ( ) ;

	m_pMainWnd->ShowWindow ( m_nCmdShow );
	m_pMainWnd->UpdateWindow ( ) ;
	
	return TRUE ;
} 

BOOL CMainApp::ExitInstance ( )
{
	CHAR sec [ ] = "Settings" ;

	HKEY h ;
	RegOpenKey ( HKEY_CURRENT_USER , "Software\\Mirager\\Mirager\\Settings" , &h ) ;

	int i , n ;
	CString key , tmp1 , tmp2 ;

	// delete previous keys

	for ( i = 0 , key = "Type" ; ; i++ )
	{
		tmp1 = key ;
		tmp2.Format ( "%d" , i ) ;
		tmp1 += tmp2 ;
        if ( ERROR_SUCCESS != RegDeleteValue ( h , tmp1 ) )
			break ;
	}

	for ( i = 0 , key = "Decoder" ; ; i++ )
	{
		tmp1 = key ;
		tmp2.Format ( "%d" , i ) ;
		tmp1 += tmp2 ;
        if ( ERROR_SUCCESS != RegDeleteValue ( h , tmp1 ) )
			break ;
	}

	// save current keys

	WriteProfileInt ( sec , "Hide Debugger" , m_appOption.m_bCheckDebugger ) ;
	WriteProfileInt ( sec , "Display" , m_appOption.m_bDisplay ) ;
	WriteProfileInt ( sec , "Display Sync" , m_appOption.m_bDisplaySync ) ;
	WriteProfileInt ( sec , "Dump To File" , m_appOption.m_bDumpFile ) ;
	WriteProfileInt ( sec , "Explicit" , m_appOption.m_bHookExplicit ) ;
	WriteProfileInt ( sec , "Get Register" , m_appOption.m_bGetRegister ) ;
	WriteProfileInt ( sec , "Notify" , m_appOption.m_bNotify ) ;
	WriteProfileInt ( sec , "Record Debug" , m_appOption.m_bRecordDebugMsg ) ;
	WriteProfileInt ( sec , "Record Extra" , m_appOption.m_bRecordExtraMsg ) ;
	WriteProfileInt ( sec , "Max Display" , m_appOption.m_dwMaxDisplay ) ;
	WriteProfileInt ( sec , "View All Functions" , m_appOption.m_bViewAll ) ;
	WriteProfileInt ( sec , "Undecorate C++ Functions" , m_appOption.m_bUndecorate ) ;

	n = m_appOption.m_arDecoder.GetSize ( ) ;
	for ( i = 0 , key = "Decoder" ; i < n ; i++ )
	{
		tmp1 = key ;
		tmp2.Format ( "%d" , i ) ;
		tmp1 += tmp2 ;
		
		WriteProfileString ( sec , tmp1 , m_appOption.m_arDecoder [ i ]  ) ;
	}

	n = m_appOption.m_arTypeFile.GetSize ( ) ;
	for ( i = 0 , key = "Type" ; i < n ; i++ )
	{
		tmp1 = key ;
		tmp2.Format ( "%d" , i ) ;
		tmp1 += tmp2 ;
		
		WriteProfileString ( sec , tmp1 , m_appOption.m_arTypeFile [ i ]  ) ;
	}

	RegCloseKey ( h ) ;

	return CWinApp::ExitInstance ( ) ;
}

BOOL CMainApp::InitApplication ( )
{
	if ( CWinApp::InitApplication ( ) == FALSE ) 
		return FALSE ;

	// intialize bitmap resource

	m_imgTree.Create ( IDB_TREE , 26 , 0 , RGB ( 255 , 0 , 255 ) ) ;
	m_imgList.Create ( IDB_LIST , 16 , 0 , RGB ( 255 , 0 , 255 ) ) ;
	m_imgMog.Create ( IDB_MOG , 46 , 0 , RGB ( 255 , 0 , 255 ) ) ;
	m_imgMessage.Create ( IDB_MESSAGE , 16 , 0 , RGB ( 255 , 0 , 255 ) ) ;
	m_imgType.Create ( IDB_TYPE , 26 , 0 , RGB ( 255 , 255 , 255 ) ) ;

	// get some procedure pointer

	m_pfnGetProcAddress = GetProcAddress (
		GetModuleHandle ( "KERNEL32.dll" ) ,
		"GetProcAddress" ) ;

	m_pfnLoadLibraryExW = GetProcAddress (
		GetModuleHandle ( "KERNEL32.dll" ) ,
		"LoadLibraryExW" ) ;

	m_pfnIsDebuggerPresent = GetProcAddress (
		GetModuleHandle ( "KERNEL32.dll" ) ,
		"IsDebuggerPresent" ) ;
	
	return TRUE ;
}

void CMainApp::OnHelpAbout ( )
{
	CAboutDialog* p = new CAboutDialog ;
	p->DoModal ( ) ;
	delete p ;
}

void CMainApp::OnHelpContent ( )
{
	DWORD dwRet = ( DWORD ) ShellExecute ( NULL , NULL , "help\\index.htm" , NULL , NULL , SW_SHOW ) ;
	if ( dwRet < 32 ) 
		AfxMessageBox ( "Help files are lost." , MB_OK | MB_ICONERROR ) ;
}

void CMainApp::OnEditOption ( )
{
	// show option dialog

	CPropertySheet* p = new CPropertySheet ( IDS_OPTION ) ;
	CGenericPage* p1 = new CGenericPage ;
	CDebugPage* p2 = new CDebugPage ;
	CExtensionPage* p3 = new CExtensionPage ;

	p->AddPage ( p1 ) ;
	p->AddPage ( p2 ) ;
	p->AddPage ( p3 ) ;

	p->DoModal ( ) ;

	delete p1 ;
	delete p2 ;
	delete p3 ;
	delete p ;
}

BEGIN_MESSAGE_MAP ( CMainFrame , CMDIFrameWnd )
	ON_WM_CREATE ( )
	ON_WM_CLOSE ( )
	ON_WM_DESTROY ( )
END_MESSAGE_MAP ( )

CMainFrame::CMainFrame ( )
{
	LoadFrame ( IDR_MAIN_FRAME ) ;
}

CMainFrame::~CMainFrame ( )
{
}

int CMainFrame::OnCreate ( LPCREATESTRUCT lpCreateStruct )
{
	if ( CMDIFrameWnd::OnCreate ( lpCreateStruct ) == -1 ) 
		return -1 ;

	// create toolbar
	if ( m_wndToolBar.Create ( this , WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS ) == FALSE ||
		 m_wndToolBar.LoadToolBar ( IDR_MAIN_FRAME ) == FALSE )
		 return -1 ;
	m_wndToolBar.SetWindowText ( "Toolbar" ) ;
	m_wndToolBar.EnableDocking ( CBRS_ALIGN_ANY ) ;
	EnableDocking ( CBRS_ALIGN_ANY ) ;
	DockControlBar ( &m_wndToolBar ) ;

	// create status bar

	UINT ids [ ] = { ID_SEPARATOR } ;

	if ( m_wndStatusBar.Create ( this ) == FALSE ||
		 m_wndStatusBar.SetIndicators ( ids , 1 ) == FALSE )
		 return -1 ;

	return 0 ;
}

void CMainFrame::OnClose ( )
{
	if ( IsDebuggeeRunning ( ) ) AfxMessageBox ( IDS_INFO_DEBUGGING , MB_OK | MB_ICONINFORMATION ) ;
	else CMDIFrameWnd::OnClose ( ) ;
}

void CMainFrame::OnDestroy ( )
{
}

BOOL CMainFrame::QueryAllDocument ( )
{
	// prepare for closing all documents

	CMainApp* p = ( CMainApp* ) AfxGetApp ( ) ;

	POSITION pos = p->GetFirstDocTemplatePosition ( ) ;
	CMultiDocTemplate* pt = ( CMultiDocTemplate* ) 
		p->GetNextDocTemplate ( pos ) ;

	POSITION pos2 = pt->GetFirstDocPosition ( ) ;
	while ( pos2 != NULL )
	{
		CDancerDoc* pd = ( CDancerDoc* )
			pt->GetNextDoc ( pos2 ) ;

		if ( pd->CanCloseFrame ( ) == FALSE )
			return FALSE ;
	}

	return TRUE ;
}

void CMainFrame::CloseAllDocument ( )
{
	CMainApp* p = ( CMainApp* ) AfxGetApp ( ) ;

	POSITION pos = p->GetFirstDocTemplatePosition ( ) ;
	CMultiDocTemplate* pt = ( CMultiDocTemplate* ) 
		p->GetNextDocTemplate ( pos ) ;

	POSITION pos2 = pt->GetFirstDocPosition ( ) ;
	while ( pos2 != NULL )
	{
		CDancerDoc* pd = ( CDancerDoc* )
			pt->GetNextDoc ( pos2 ) ;

		pd->m_pDebugControl->Stop ( ) ;
		pd->m_pFrame->SendMessage ( WM_CLOSE ) ;
	}
}

BOOL CMainFrame::IsDebuggeeRunning ( )
{
	CMainApp* p = ( CMainApp* ) AfxGetApp ( ) ;

	POSITION pos = p->GetFirstDocTemplatePosition ( ) ;
	CMultiDocTemplate* pt = ( CMultiDocTemplate* ) 
		p->GetNextDocTemplate ( pos ) ;

	POSITION pos2 = pt->GetFirstDocPosition ( ) ;
	while ( pos2 != NULL )
	{
		CDancerDoc* pd = ( CDancerDoc* )
			pt->GetNextDoc ( pos2 ) ;
		if ( pd->m_pDebugControl->IsDebugging ( ) )
			return TRUE ;
	}
	return FALSE ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -