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

📄 type.h

📁 数据加密算法
💻 H
字号:
#pragma once

#define ID 0
#define NUM 1
#define POINTER 2
#define COMMA 3
#define LB 4
#define RB 5
#define LS 6
#define RS 7
#define SEMICOLON 8
#define EQ 9
#define UNKNOWN -1

typedef BOOL ( CALLBACK* LPPROC_DECODE_ROUTINE ) 
( LPVOID lpAddress , CHAR* lpBuf ) ;

typedef void ( CALLBACK* LPPROC_REGISTER_DECODER )
( HANDLE hControl , LPCSTR lpTypeName , LPPROC_DECODE_ROUTINE lpDecodeRoutine ) ; 

typedef BYTE ( CALLBACK* LPPROC_READ_BYTE )
( HANDLE hControl , LPVOID lpAddress ) ;

typedef WORD ( CALLBACK* LPPROC_READ_WORD )
( HANDLE hControl , LPVOID lpAddress ) ;

typedef DWORD ( CALLBACK* LPPROC_READ_DWORD )
( HANDLE hControl , LPVOID lpAddress ) ;

typedef DWORD ( CALLBACK* LPPROC_READ_STRING )
( HANDLE hControl , LPVOID lpAddress , LPVOID lpBuf ) ;

typedef DWORD ( CALLBACK* LPPROC_READ_STRINGW )
( HANDLE hControl , LPVOID lpAddress , LPVOID lpBuf ) ;

typedef BOOL ( CALLBACK* LPPROC_READ_BLOCK )
( HANDLE hControl , LPVOID lpAddress , LPVOID lpBuf , DWORD dwSize ) ;

typedef void ( CALLBACK* LPPROC_OUTPUT_STRING )
( HANDLE hControl , LPCSTR pString ) ;

// for type-decoder
struct RoutineEntry
{
	HANDLE m_hControl ;

	LPPROC_REGISTER_DECODER m_pfnRegisterDecoder ;
	LPPROC_OUTPUT_STRING m_pfnOutputString ;
	
	LPPROC_READ_BYTE m_pfnReadByte ;
	LPPROC_READ_WORD m_pfnReadWord ;
	LPPROC_READ_DWORD m_pfnReadDWord ;
	LPPROC_READ_STRING m_pfnReadString ; 
	LPPROC_READ_STRINGW m_pfnReadStringW ; 
	LPPROC_READ_BLOCK m_pfnReadBlock ;
} ;

typedef void ( CALLBACK* LPPROC_LOAD_ROUTINE )
( RoutineEntry* pRoutineEntry ) ;

typedef void ( CALLBACK* LPPROC_UNLOAD_ROUTINE )
( VOID ) ;

struct Type ;

// describe a type used for parameter
struct ParamType
{
	Type* m_pType ; // base type
	DWORD m_dwPointerDepth ; // pointer depth
} ;

struct ParamBlock ;
struct Thread ;
class CDebugControl ;

// describe a type
struct Type
{
	CString m_strName ; // type name
	
	DWORD m_dwLength ; // type size ( in byte )
	BOOL m_bFunction ; // is a function name
	BOOL m_bStruct ; // is a structure name

	CArray < ParamType , ParamType > m_arParam ; // sub fields

	LPPROC_DECODE_ROUTINE m_pfnUserDecoder ; // function pointer for user-defined decoder

public :
	Type ( ) ;
	~Type ( ) ;
	void Present ( CString& str ) ;
	int GetLength ( ) ;
	ParamBlock* Construct ( CDebugControl* pDebugControl , LPVOID lpAddress , DWORD dwPointer ) ;
	Type& operator= ( Type& rh )
	{
		m_strName = rh.m_strName ;
		m_dwLength = rh.m_dwLength ;
		m_bFunction = rh.m_bFunction ;
		m_bStruct = rh.m_bStruct ;
		m_pfnUserDecoder = rh.m_pfnUserDecoder ;
		m_arParam.RemoveAll ( ) ;

		int i , n = rh.m_arParam.GetSize ( ) ;
		for ( i = 0 ; i < n ; i++ )
		{
			m_arParam.Add ( rh.m_arParam [ i ] ) ;
		}
		return *this ;
	}
} ;

// type collection for a certain dll
struct TypeSet
{
	CString m_strPathName ; // dll name
	CMapStringToPtr m_mapType ; // mapping type name to type structure

	CPtrArray m_arType ;

public :
	TypeSet ( ) ;
	~TypeSet ( ) ;

	void Dispose ( ) ;
	Type* Query ( const CString& strName ) ;
	void GetAllLength ( ) ;
	void Append ( TypeSet* pTypeSet ) ; // insert an existing type set to this one

#ifdef _DEBUG // used for debugging
	void Dump ( ) 
	{
		FILE* fp = fopen ( "d:\\type.txt" , "w" ) ;
		int i , n = m_arType.GetSize ( ) ;
		for ( i = 0 ; i < n ; i++ )
		{
			Type* p = ( Type* ) m_arType [ i ] ;

			CString msg ;
			p->Present ( msg ) ;
			fprintf ( fp , "%s\n" , msg ) ;
		}
		fclose ( fp ) ;
	}
#endif
} ;

// token for gammar file parsing
struct Token 
{
	DWORD m_dwType ;
	
	CString m_strName ;
	DWORD m_dwNum ;
} ;

class CDebugControl ;

// manager for all type sets
class CTypeManager
{
	friend class CDebugControl ;

	CPtrArray m_arTypeSet ;
	CMapStringToPtr m_mapTypeSet ;
	CDebugControl* m_pDebugControl ;
	CPtrArray m_arDecoder ;
	CStringArray m_arModName ;

public :
	CTypeManager ( ) ;
	~CTypeManager ( ) ;

	void LoadType ( CPtrArray& ar ) ;
	void LoadCommonType ( CPtrArray& ar ) ;
	void LoadDecoder ( ) ;
	void LoadDecoder ( const CString& strPathName ) ;
	void UnloadDecoder ( ) ;
	void Dispose ( ) ;

	void AttachTo ( CDebugControl* pDebugControl ) ;
	
	void LoadType ( TypeSet* pTypeSet ) ;
	BOOL GetToken ( char* buf , int& p , Token& t ) ;
	void RemoveComment ( char* buf ) ;
	int Parse ( TypeSet* pTypeSet , char* buf ) ;

	static BOOL IsWhitespace ( int c ) ;
	static BOOL IsNondigit ( int c ) ;
} ;

⌨️ 快捷键说明

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