// Test.cpp: Implementation of the ctest class.////
#include "stdafx.h" #include "test.h"
//// construction / destruction //
#define class_member_function_support_callback (thispointerAddress) / __ASM MOV EAX, (thispointerAddress) / __asm mov [EBP-4], EAX
Ctest :: ctest () {typedef void (int); pf p = & ctest :: testfunction; m_itHeadId = 0x99; m_itheadid1 = 0x12; m_schar = 'a'; ulong * pTID = & this-> m_itHeadID ;
__ASM {Push PTID PUSH 0 PUSH THIS PUSH P Push 0 Push 0 // Eax is the return value of the function, so the change does not matter MOV Eax, CreateThread Call Eax}}
CTEST :: ~ ctest () {
}
Void ctest :: TestFunction (int thispointer) {class_member_function_support_callback (thispointer) int x = 1000;
// The following to analyze the program to walk to the structure of the stack: // // [EBP 8] -> thispointer's value, because it is a pass value // [EBP 4] -> ctest :: testfunction (int a) function Call [ctest :: testfunction] The address of this statement is 4 // [EBP] -> As the boundary line of local variables and external transmission variables, the original value of EBP is // [EBP-4] -> Point to the THIS pointer of the class, which is added to the code by the compiler. If the function is not a member function, // This address points to the first allocated local variable, and the this pointer is passed through ECX, // That is to say The nature of member functions and global functions is the same (they are the same as the number of parameters inside the stack), // is only the compiler will have some additional work on the member function when the compiler is analyzed, // If it is a member When the function is functional, the THIS pointer is allocated by: MOV [EBP-4], ECX before the function's '{' //, and the non-local variable // quantity and non-transmission variables will be [EBP-4). ] Solid memory // [eBp-8] -> points to the local variable x address // // esp -> always point to the top of the stack, when the function exits, all local parties will be used in MOV ESP, EBP Variable disappears Printf ("Hello World! I am Inside a class, and caled By OS / N"); Printf ("M_ITHEADID1: 0x% x / T% C / N", m_itHeadID1, M_Schar);}
// Test.h: interface for the ctest class.////
#if! defined (AFX_TEST_H__F30756C2_DE72_48F2_BBA2_A416B7ED3E28__INCLUDED _) # define AFX_TEST_H__F30756C2_DE72_48F2_BBA2_A416B7ED3E28__INCLUDED_ # if _MSC_VER> 1000 # pragma once # endif // _MSC_VER> 1000
Class ctest {public: void testfunction (int A); ctest (); ~ ctest ();
PRIVATE: ULONG M_ITHEADID1; ULONG M_ITHEADID; CHAR M_SCHAR;
#ndif //! Defined (AFX_TEST_H__F30756C2_DE72_48F2_BBA2_A416B7ED3E28__INCLUDED_)
// TestmemberFunction.cpp: Defines the entry point for the console application.//
#include "stdafx.h" #include "test.h"
INT Main (int Argc, char * argv []) {ctest testObject; Sleep (100); return 0;}
The above is the code of the entire implementation, there are comments, look slowly!