2011-06-07 00:48:10 +08:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
#include <intrin.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
2011-09-22 16:25:42 +08:00
|
|
|
#include <string>
|
2011-06-07 00:48:10 +08:00
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
2011-12-29 20:45:16 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-10-04 15:00:54 +08:00
|
|
|
#pragma pack( push, 4 )
|
|
|
|
|
2011-09-22 16:25:42 +08:00
|
|
|
const ULONG g_constNumValue = 0x5555;
|
2012-01-05 04:06:50 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// kd> x targetapp!g_constBoolValue
|
|
|
|
// *** nothing ***
|
|
|
|
//
|
|
|
|
// kd> > u 01331995
|
|
|
|
// targetapp!FuncWithName0+0x75 [c:\projects\pykd\branch\0.1.x\test\targetapp\targetapp.cpp @ 198]:
|
|
|
|
// 01331995 8bf4 mov esi,esp
|
|
|
|
// 01331997 6a01 push 1 ; << g_constBoolValue
|
|
|
|
// 01331999 8b0d84043401 mov ecx,dword ptr [targetapp!_imp_?coutstd (01340484)]
|
|
|
|
// 0133199f ff1578043401 call dword ptr [targetapp!_imp_??6?$basic_ostreamDU?$char_traitsDstdstdQAEAAV01_NZ (01340478)]
|
2011-09-22 16:25:42 +08:00
|
|
|
const bool g_constBoolValue = true;
|
|
|
|
|
|
|
|
UCHAR g_ucharValue = 1;
|
|
|
|
USHORT g_ushortValue = 2;
|
|
|
|
ULONG g_ulongValue = 4;
|
|
|
|
ULONGLONG g_ulonglongValue = 8;
|
2012-11-23 00:00:06 +08:00
|
|
|
ULONGLONG *g_pUlonglongValue = &g_ulonglongValue;
|
2011-09-22 16:25:42 +08:00
|
|
|
|
2011-12-29 21:01:52 +08:00
|
|
|
CHAR g_charValue = -1;
|
|
|
|
SHORT g_shortValue = -2;
|
|
|
|
LONG g_longValue = -4;
|
|
|
|
LONGLONG g_longlongValue = -8;
|
|
|
|
|
2013-01-17 14:50:35 +08:00
|
|
|
float g_float = 5.123456f;
|
|
|
|
double g_double = 5.1234567891;
|
|
|
|
|
2011-09-22 16:25:42 +08:00
|
|
|
std::string g_string;
|
|
|
|
|
2011-09-22 18:05:56 +08:00
|
|
|
struct structWithBits {
|
|
|
|
ULONG m_bit0_4 : 5;
|
|
|
|
ULONG m_bit5 : 1;
|
|
|
|
ULONG m_bit6_7 : 2;
|
|
|
|
};
|
|
|
|
|
2011-12-13 15:52:04 +08:00
|
|
|
|
2011-09-22 19:20:31 +08:00
|
|
|
union unionTest {
|
|
|
|
ULONG m_value;
|
2011-12-27 16:32:50 +08:00
|
|
|
double m_doubleValue;
|
2011-09-22 19:20:31 +08:00
|
|
|
structWithBits m_bits;
|
|
|
|
};
|
|
|
|
|
|
|
|
class classBase {
|
|
|
|
public:
|
|
|
|
int m_baseField;
|
|
|
|
void baseMethod() const {}
|
|
|
|
virtual void virtFunc() = 0;
|
|
|
|
virtual void virtFunc2() = 0;
|
2012-05-15 22:47:22 +08:00
|
|
|
|
|
|
|
classBase() :
|
|
|
|
m_baseField( -100 )
|
|
|
|
{}
|
2011-09-22 19:20:31 +08:00
|
|
|
};
|
|
|
|
|
2012-04-18 15:39:33 +08:00
|
|
|
class anotherBase {
|
|
|
|
static std::string m_stdstr;
|
|
|
|
ULONG m_count;
|
2012-05-15 22:47:22 +08:00
|
|
|
int m_baseField;
|
2012-04-18 15:39:33 +08:00
|
|
|
public:
|
2012-05-15 22:47:22 +08:00
|
|
|
anotherBase() :
|
|
|
|
m_count( 1234 ),
|
|
|
|
m_baseField( 100 )
|
|
|
|
{}
|
2012-04-18 15:39:33 +08:00
|
|
|
};
|
|
|
|
std::string anotherBase::m_stdstr = "hello";
|
|
|
|
|
|
|
|
|
2011-09-22 19:20:31 +08:00
|
|
|
struct structTest {
|
|
|
|
ULONG m_field0;
|
|
|
|
ULONGLONG m_field1;
|
|
|
|
bool m_field2;
|
|
|
|
USHORT m_field3;
|
2011-11-07 14:46:53 +08:00
|
|
|
structTest* m_field4;
|
2011-09-22 19:20:31 +08:00
|
|
|
};
|
|
|
|
|
2012-12-06 14:28:59 +08:00
|
|
|
struct structNullSize {
|
|
|
|
};
|
|
|
|
|
|
|
|
structNullSize* g_nullSizeArray = 0;
|
|
|
|
|
|
|
|
struct structAbstract;
|
|
|
|
typedef struct structAbstract *pstructAbstract;
|
|
|
|
|
|
|
|
pstructAbstract g_structAbstract = 0;
|
|
|
|
|
2011-12-13 15:52:04 +08:00
|
|
|
structWithBits g_structWithBits = { 4, 1, 3};
|
2011-11-08 18:53:07 +08:00
|
|
|
|
2011-11-07 14:46:53 +08:00
|
|
|
structTest g_structTest = { 0, 500, true, 1, NULL };
|
|
|
|
structTest g_structTest1 = { 0, 500, true, 1, &g_structTest };
|
2011-10-19 16:13:02 +08:00
|
|
|
|
|
|
|
structTest g_testArray[2] = { { 0, 500, true, 1 }, { 2, 1500, false, 1 } };
|
|
|
|
|
|
|
|
structTest *g_structTestPtr = &g_structTest;
|
|
|
|
structTest **g_structTestPtrPtr = &g_structTestPtr;
|
2011-10-06 14:26:25 +08:00
|
|
|
|
2012-02-17 18:16:54 +08:00
|
|
|
|
2011-10-21 15:13:31 +08:00
|
|
|
char helloStr[] = "Hello";
|
|
|
|
wchar_t helloWStr[] = L"Hello";
|
|
|
|
|
2011-10-26 14:49:57 +08:00
|
|
|
unsigned char ucharArray[] = {0, 10, 0x78, 128, 0xFF };
|
2011-11-07 17:13:22 +08:00
|
|
|
unsigned short ushortArray[] = {0, 10, 0xFF, 0x8000, 0xFFFF };
|
|
|
|
unsigned long ulongArray[] = {0, 0xFF, 0x8000, 0x80000000, 0xFFFFFFFF };
|
2011-11-19 01:20:23 +08:00
|
|
|
long longArray[] = {0, -10, -2000, -100000, 0xFFFFFFFF };
|
2011-11-07 17:13:22 +08:00
|
|
|
unsigned __int64 ulonglongArray[] = {0, 0xFF, 0xFFFFFFFF, 0x8000000000000000, 0xFFFFFFFFFFFFFFFF };
|
2011-11-21 20:05:38 +08:00
|
|
|
long long longlongArray[] = {0, -10, -2000, -100000, -10000000000 };
|
2013-01-17 14:50:35 +08:00
|
|
|
float floatArray[] = { 1.0f, 2.001f, -3.0004f };
|
|
|
|
double doubleArray[] = { 1.0, 2.0000001, -3.0000004 };
|
2011-10-26 14:49:57 +08:00
|
|
|
|
2011-11-16 14:42:00 +08:00
|
|
|
int intMatrix[2][3] = { { 0, 1, 2}, { 3, 4, 5 } };
|
2011-11-18 04:36:11 +08:00
|
|
|
int intMatrix2[2][3] = { { 0, 1, 2}, { 3, 4, 5 } };
|
|
|
|
int intMatrix3[2][3] = { { 0, 1, 2}, { 3, 4, 5 } };
|
|
|
|
int intMatrix4[2][3] = { { 0, 1, 2}, { 3, 4, 5 } };
|
2011-11-16 18:30:50 +08:00
|
|
|
char* strArray[] = { "Hello", "Bye" };
|
2011-11-16 14:42:00 +08:00
|
|
|
int (*ptrIntMatrix)[2][3] = &intMatrix;
|
2011-11-18 04:36:11 +08:00
|
|
|
|
|
|
|
// kd> x targetapp!arrIntMatrixPtrs
|
|
|
|
// xxxxxxxx targetapp!arrIntMatrixPtrs = int (*[4])[2][3]
|
|
|
|
int (* arrIntMatrixPtrs[4])[2][3] = {
|
|
|
|
&intMatrix, &intMatrix2, &intMatrix3, &intMatrix4
|
|
|
|
};
|
|
|
|
|
2011-12-09 14:45:12 +08:00
|
|
|
int ((*ptrIntMatrix1))[2][3] = &intMatrix;
|
|
|
|
|
2011-11-16 14:42:00 +08:00
|
|
|
char *(*ptrStrArray)[2] = &strArray;
|
|
|
|
|
2011-12-27 16:32:50 +08:00
|
|
|
enum enumType {
|
|
|
|
|
|
|
|
ONE = 1,
|
|
|
|
TWO = 2,
|
|
|
|
THREE = 3
|
|
|
|
};
|
|
|
|
|
2012-03-10 00:30:07 +08:00
|
|
|
const enumType g_constEnumThree = THREE;
|
|
|
|
|
2012-03-10 00:47:12 +08:00
|
|
|
const ULONG g_constUlong = 0xffffff;
|
|
|
|
const ULONGLONG g_constUlonglong = 0xffffff000000;
|
|
|
|
|
2012-04-18 15:39:33 +08:00
|
|
|
class classChild : public classBase, public anotherBase {
|
2012-04-11 16:51:16 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-04-18 15:39:33 +08:00
|
|
|
static const int m_staticConst = 100;
|
|
|
|
|
|
|
|
static int m_staticField;
|
2012-04-11 16:51:16 +08:00
|
|
|
|
2011-09-22 19:20:31 +08:00
|
|
|
public:
|
|
|
|
int m_childField;
|
|
|
|
int m_childField2;
|
2011-10-04 15:00:54 +08:00
|
|
|
structTest m_childField3;
|
2011-12-27 16:32:50 +08:00
|
|
|
enumType m_enumField;
|
2011-09-22 19:20:31 +08:00
|
|
|
void childMethod() const {}
|
|
|
|
virtual void virtFunc() {}
|
|
|
|
virtual void virtFunc2() {}
|
2011-12-27 16:32:50 +08:00
|
|
|
|
|
|
|
classChild() :
|
|
|
|
m_enumField( THREE )
|
|
|
|
{}
|
2011-09-22 19:20:31 +08:00
|
|
|
};
|
|
|
|
|
2012-04-18 15:39:33 +08:00
|
|
|
int classChild::m_staticField = 200;
|
|
|
|
|
2011-12-27 16:32:50 +08:00
|
|
|
classChild g_classChild;
|
|
|
|
|
2011-09-22 22:38:42 +08:00
|
|
|
struct struct2 {
|
|
|
|
structTest m_struct;
|
|
|
|
unionTest m_union;
|
|
|
|
int m_field;
|
|
|
|
};
|
|
|
|
|
2011-11-19 00:00:25 +08:00
|
|
|
struct struct3 {
|
|
|
|
int m_arrayField[2];
|
|
|
|
int m_noArrayField;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct3 g_struct3 = { { 0, 2 }, 3 };
|
|
|
|
|
2011-11-16 15:36:21 +08:00
|
|
|
__int64 g_bigValue = 0x8080808080808080;
|
|
|
|
|
2011-12-15 18:34:03 +08:00
|
|
|
|
|
|
|
static LIST_ENTRY g_listHead;
|
|
|
|
|
|
|
|
struct listStruct {
|
|
|
|
int num;
|
|
|
|
LIST_ENTRY listEntry;
|
|
|
|
};
|
|
|
|
|
|
|
|
listStruct g_listItem1 = { 1 };
|
|
|
|
listStruct g_listItem2 = { 2 };
|
|
|
|
listStruct g_listItem3 = { 3 };
|
|
|
|
|
2012-12-08 22:13:03 +08:00
|
|
|
LIST_ENTRY entry1;
|
|
|
|
LIST_ENTRY entry2;
|
2011-12-15 18:34:03 +08:00
|
|
|
|
|
|
|
struct listStruct1;
|
|
|
|
|
|
|
|
static listStruct1 *g_listHead1 = NULL;
|
|
|
|
|
2012-02-18 01:22:34 +08:00
|
|
|
listStruct1* g_arrOfListStruct1[] = {
|
|
|
|
g_listHead1, g_listHead1
|
|
|
|
};
|
|
|
|
|
2012-02-17 18:16:54 +08:00
|
|
|
void* g_voidPtr = g_listHead1;
|
|
|
|
|
2012-02-18 01:22:34 +08:00
|
|
|
void *g_arrOfVoidPtr[] = {
|
|
|
|
g_voidPtr, g_voidPtr, g_voidPtr
|
|
|
|
};
|
|
|
|
|
2012-02-21 03:42:19 +08:00
|
|
|
// kd> x targetapp!g_arrOfPtrToFunc
|
|
|
|
// xxxxxxxx`xxxxxxxx targetapp!g_arrOfPtrToFunc = <function> *[4]
|
|
|
|
WNDPROC g_arrOfPtrToFunc[] = {
|
|
|
|
NULL, NULL, NULL, NULL
|
|
|
|
};
|
|
|
|
|
2011-12-15 18:34:03 +08:00
|
|
|
struct listStruct1 {
|
|
|
|
int num;
|
|
|
|
struct listStruct1 *next;
|
|
|
|
};
|
|
|
|
|
2012-01-19 00:17:11 +08:00
|
|
|
|
|
|
|
struct SomeBaseClassWithFields {
|
|
|
|
int m_someBaseFiled1;
|
|
|
|
int m_someBaseFiled2;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BaseEntryStruct {
|
|
|
|
BaseEntryStruct *m_next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ChildEntryTest : SomeBaseClassWithFields, BaseEntryStruct {
|
|
|
|
int m_childFiled1;
|
|
|
|
};
|
|
|
|
|
|
|
|
BaseEntryStruct *g_childListHead = NULL;
|
|
|
|
ChildEntryTest g_childListEntry1;
|
|
|
|
ChildEntryTest g_childListEntry2;
|
|
|
|
ChildEntryTest g_childListEntry3;
|
|
|
|
|
2011-12-28 21:32:50 +08:00
|
|
|
class classWithDestructor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
classWithDestructor(DWORD errCode) : m_errCode(errCode) {}
|
|
|
|
virtual ~classWithDestructor() {::SetLastError(m_errCode);}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DWORD m_errCode;
|
|
|
|
};
|
|
|
|
|
2011-12-15 18:34:03 +08:00
|
|
|
listStruct1 g_listItem11 = { 100 };
|
|
|
|
listStruct1 g_listItem12 = { 200 };
|
|
|
|
listStruct1 g_listItem13 = { 300 };
|
|
|
|
|
2012-01-19 03:14:46 +08:00
|
|
|
struct {
|
|
|
|
struct {
|
|
|
|
int m_fieldNestedStruct;
|
|
|
|
};
|
|
|
|
int m_fieldOfUnNamed;
|
|
|
|
}g_unNamedStruct;
|
|
|
|
|
2012-01-19 18:16:07 +08:00
|
|
|
struct StructWithNested {
|
|
|
|
struct Nested {
|
|
|
|
int m_nestedFiled;
|
|
|
|
};
|
|
|
|
int m_field;
|
2013-04-17 17:22:57 +08:00
|
|
|
|
|
|
|
struct {
|
|
|
|
int m_field2;
|
|
|
|
};
|
2012-01-19 18:16:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
StructWithNested g_structWithNested;
|
|
|
|
StructWithNested::Nested g_structNested;
|
|
|
|
|
2012-05-15 23:17:26 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
struct baseStruct1
|
|
|
|
{
|
|
|
|
int m_field;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct intermediateStruct : baseStruct1
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
struct baseStruct2
|
|
|
|
{
|
|
|
|
char m_field;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fieldSameNameStruct : intermediateStruct
|
|
|
|
, baseStruct2
|
|
|
|
{
|
|
|
|
char *m_field;
|
|
|
|
};
|
|
|
|
fieldSameNameStruct g_fieldSameNameStruct;
|
|
|
|
|
|
|
|
// kd> ?? g_fieldSameNameStruct
|
|
|
|
// struct fieldSameNameStruct
|
|
|
|
// +0x000 m_field : 0x400
|
|
|
|
// +0x004 m_field : 12 ''
|
|
|
|
// +0x008 m_field : 0x00000001`3f7bc928 "toaster"
|
|
|
|
|
|
|
|
// kd> dt fieldSameNameStruct @@C++(&g_fieldSameNameStruct)
|
|
|
|
// targetapp!fieldSameNameStruct
|
|
|
|
// +0x000 m_field : 0x400
|
|
|
|
// +0x004 m_field : 12 ''
|
|
|
|
// +0x008 m_field : 0x00000001`3f7bc928 "toaster"
|
|
|
|
|
|
|
|
// kd> dt fieldSameNameStruct
|
|
|
|
// targetapp!fieldSameNameStruct
|
|
|
|
// +0x000 m_field : Int4B
|
|
|
|
// +0x004 m_field : Char
|
|
|
|
// +0x008 m_field : Ptr64 Char
|
|
|
|
|
|
|
|
// kd> ?? g_fieldSameNameStruct.m_field
|
|
|
|
// char * 0x00000001`3f04c928
|
|
|
|
// "toaster"
|
|
|
|
// kd> ?? g_fieldSameNameStruct.intermediateStruct::baseStruct1::m_field
|
|
|
|
// Type does not have given member error at 'intermediateStruct::baseStruct1::m_field'
|
|
|
|
// kd> g_fieldSameNameStruct.baseStruct2::m_field
|
|
|
|
// Type does not have given member error at 'baseStruct2::m_field'
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-16 21:27:47 +08:00
|
|
|
class VirtualBaseClass1 : public virtual classBase
|
|
|
|
{
|
|
|
|
int m_member;
|
|
|
|
|
|
|
|
public:
|
|
|
|
VirtualBaseClass1() : m_member(123){}
|
|
|
|
|
|
|
|
virtual void virtFunc() {}
|
|
|
|
virtual void virtFunc2() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class VirtualBaseClass2 : public virtual classBase
|
|
|
|
{
|
|
|
|
int m_member;
|
|
|
|
|
|
|
|
public:
|
|
|
|
VirtualBaseClass2() : m_member(345){}
|
|
|
|
|
|
|
|
virtual void virtFunc() {}
|
|
|
|
virtual void virtFunc2() {}
|
|
|
|
};
|
|
|
|
|
2012-05-22 16:50:21 +08:00
|
|
|
class VirtualChildClass : public VirtualBaseClass1, public VirtualBaseClass2
|
2012-05-16 21:27:47 +08:00
|
|
|
{
|
|
|
|
void virtFunc() {}
|
|
|
|
void virtFunc2() {}
|
2012-05-22 16:50:21 +08:00
|
|
|
|
|
|
|
void virtual virtFunc3() {}
|
2012-05-16 21:27:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
VirtualChildClass g_virtChild;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-25 15:29:53 +08:00
|
|
|
char* bigCStr = NULL;
|
|
|
|
wchar_t* bigWStr = NULL;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-01-19 21:29:01 +08:00
|
|
|
WNDENUMPROC g_ptrToFunction;
|
2012-03-11 22:54:03 +08:00
|
|
|
void *g_unTypedPtrToFunction = g_ptrToFunction;
|
2011-12-29 20:45:16 +08:00
|
|
|
#pragma pack( pop )
|
|
|
|
|
2012-04-11 00:48:51 +08:00
|
|
|
typedef struct structTest structTestTypeDef;
|
|
|
|
|
|
|
|
structTestTypeDef g_structTypeDef = { 0 };
|
|
|
|
|
2011-12-29 20:45:16 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-12-15 18:34:03 +08:00
|
|
|
#define InitializeListHead(ListHead) (\
|
|
|
|
(ListHead)->Flink = (ListHead)->Blink = (ListHead))
|
|
|
|
|
|
|
|
#define InsertTailList(ListHead,Entry) {\
|
|
|
|
PLIST_ENTRY _EX_Blink;\
|
|
|
|
PLIST_ENTRY _EX_ListHead;\
|
|
|
|
_EX_ListHead = (ListHead);\
|
|
|
|
_EX_Blink = _EX_ListHead->Blink;\
|
|
|
|
(Entry)->Flink = _EX_ListHead;\
|
|
|
|
(Entry)->Blink = _EX_Blink;\
|
|
|
|
_EX_Blink->Flink = (Entry);\
|
|
|
|
_EX_ListHead->Blink = (Entry);\
|
|
|
|
}
|
|
|
|
|
2011-12-29 20:45:16 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-09-22 00:50:42 +08:00
|
|
|
void FuncWithName0()
|
|
|
|
{
|
2011-09-22 19:20:31 +08:00
|
|
|
classChild _classChild;
|
|
|
|
_classChild.baseMethod();
|
|
|
|
|
|
|
|
reinterpret_cast<classChild *>(&_classChild)->virtFunc2();
|
2011-09-23 22:26:55 +08:00
|
|
|
std::cout << _classChild.m_childField2;
|
|
|
|
std::cout << g_constNumValue;
|
|
|
|
std::cout << g_constBoolValue;
|
|
|
|
std::cout << g_ucharValue;
|
|
|
|
std::cout << g_ushortValue;
|
|
|
|
std::cout << g_ulongValue;
|
|
|
|
std::cout << g_ulonglongValue;
|
2012-11-23 00:00:06 +08:00
|
|
|
std::cout << *g_pUlonglongValue;
|
2011-12-29 21:01:52 +08:00
|
|
|
std::cout << g_charValue;
|
|
|
|
std::cout << g_shortValue;
|
|
|
|
std::cout << g_longValue;
|
|
|
|
std::cout << g_longlongValue;
|
2011-10-06 14:26:25 +08:00
|
|
|
|
|
|
|
std::cout << g_structTest.m_field0;
|
2011-10-19 16:13:02 +08:00
|
|
|
std::cout << g_testArray[1].m_field3;
|
|
|
|
std::cout << g_structTestPtr->m_field3;
|
|
|
|
std::cout << (*g_structTestPtrPtr)->m_field3;
|
2011-10-21 15:13:31 +08:00
|
|
|
|
|
|
|
std::cout << helloStr;
|
|
|
|
std::wcout << helloWStr;
|
2011-10-26 14:49:57 +08:00
|
|
|
std::cout << ucharArray[2];
|
|
|
|
std::cout << ushortArray[2];
|
|
|
|
std::cout << ulongArray[2];
|
|
|
|
std::cout << ulonglongArray[2];
|
2013-01-17 14:50:35 +08:00
|
|
|
std::cout << floatArray[2];
|
|
|
|
std::cout << doubleArray[2];
|
2011-11-16 14:42:00 +08:00
|
|
|
|
|
|
|
std::cout << intMatrix[1][1];
|
|
|
|
std::cout << strArray[0];
|
|
|
|
std::cout << (*ptrIntMatrix)[0][1];
|
2011-11-19 00:00:25 +08:00
|
|
|
std::cout << g_struct3.m_noArrayField;
|
2011-12-15 22:20:28 +08:00
|
|
|
std::cout << g_structWithBits.m_bit5;
|
|
|
|
std::cout << ptrStrArray;
|
|
|
|
std::cout << g_structTest1.m_field2;
|
|
|
|
std::cout << ptrIntMatrix1;
|
|
|
|
std::cout << g_bigValue;
|
2011-12-27 16:32:50 +08:00
|
|
|
std::cout << g_classChild.m_enumField;
|
2012-04-18 15:39:33 +08:00
|
|
|
std::cout << g_classChild.m_staticConst;
|
2012-03-10 00:30:07 +08:00
|
|
|
std::cout << g_constEnumThree;
|
2012-03-10 00:47:12 +08:00
|
|
|
std::cout << g_constUlong;
|
|
|
|
std::cout << g_constUlonglong;
|
2012-01-19 03:14:46 +08:00
|
|
|
std::cout << g_unNamedStruct.m_fieldNestedStruct;
|
2012-01-19 18:16:07 +08:00
|
|
|
std::cout << g_structNested.m_nestedFiled;
|
2012-01-19 21:29:01 +08:00
|
|
|
std::cout << g_unTypedPtrToFunction;
|
2012-04-11 00:48:51 +08:00
|
|
|
|
2012-05-15 23:17:26 +08:00
|
|
|
std::cout << g_fieldSameNameStruct.m_field;
|
|
|
|
std::cout << g_fieldSameNameStruct.intermediateStruct::baseStruct1::m_field;
|
|
|
|
std::cout << g_fieldSameNameStruct.intermediateStruct::m_field;
|
|
|
|
std::cout << g_fieldSameNameStruct.baseStruct2::m_field;
|
|
|
|
|
2012-04-11 00:48:51 +08:00
|
|
|
std::cout << g_structTypeDef.m_field0;
|
2012-05-16 21:27:47 +08:00
|
|
|
|
2012-12-06 14:28:59 +08:00
|
|
|
std::cout << g_nullSizeArray;
|
|
|
|
std::cout << g_structAbstract;
|
|
|
|
|
2013-01-17 14:50:35 +08:00
|
|
|
std::cout << g_float;
|
|
|
|
std::cout << g_double;
|
|
|
|
|
2012-05-22 16:50:21 +08:00
|
|
|
//std::cout << g_virtChild.VirtualBaseClass1::m_baseField;
|
2011-09-22 00:50:42 +08:00
|
|
|
}
|
|
|
|
|
2011-12-29 20:45:16 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-09-23 05:54:27 +08:00
|
|
|
void FuncWithName1(int a)
|
2011-09-22 00:50:42 +08:00
|
|
|
{
|
2011-09-23 22:26:55 +08:00
|
|
|
unionTest _unionTest[2] = {0};
|
2011-09-23 22:16:29 +08:00
|
|
|
_unionTest[1].m_value = 0;
|
2011-09-22 19:20:31 +08:00
|
|
|
structTest _structTest;
|
2011-09-23 05:54:27 +08:00
|
|
|
_structTest.m_field1 = a;
|
2011-09-22 22:38:42 +08:00
|
|
|
struct2 _struct2;
|
|
|
|
RtlZeroMemory(&_struct2, sizeof(_struct2));
|
2011-09-23 22:26:55 +08:00
|
|
|
|
|
|
|
std::cout << _unionTest[0].m_value;
|
|
|
|
std::cout << _structTest.m_field1;
|
|
|
|
std::cout << _struct2.m_struct.m_field1;
|
|
|
|
std::cout << g_string;
|
2012-01-19 03:14:46 +08:00
|
|
|
std::cout << g_unNamedStruct.m_fieldOfUnNamed;
|
2012-01-19 18:16:07 +08:00
|
|
|
std::cout << g_structWithNested.m_field;
|
2012-01-19 21:29:01 +08:00
|
|
|
std::cout << g_ptrToFunction;
|
2012-02-21 03:42:19 +08:00
|
|
|
|
|
|
|
std::cout << g_ptrToFunction;
|
|
|
|
std::cout << g_arrOfPtrToFunc[1];
|
2011-09-22 00:50:42 +08:00
|
|
|
}
|
|
|
|
|
2012-10-16 16:15:20 +08:00
|
|
|
#pragma optimize("g", off)
|
|
|
|
|
2012-09-25 14:15:50 +08:00
|
|
|
static
|
|
|
|
void _FuncWithName2(int a)
|
|
|
|
{
|
|
|
|
std::cout << a;
|
|
|
|
}
|
|
|
|
|
2011-12-29 20:45:16 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-10-16 16:15:20 +08:00
|
|
|
|
2012-01-25 19:57:47 +08:00
|
|
|
VOID functionCalledFromEnumWindowsProc1(DWORD dwProcessId)
|
|
|
|
{
|
|
|
|
DWORD dwCurrentProcessId = GetCurrentProcessId();
|
|
|
|
if (dwCurrentProcessId != dwProcessId)
|
|
|
|
std::cout << dwCurrentProcessId << dwProcessId;
|
|
|
|
__debugbreak();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-01-13 05:51:57 +08:00
|
|
|
BOOL CALLBACK EnumWindowsProc1(
|
2011-12-28 21:32:50 +08:00
|
|
|
HWND hWindow,
|
2012-01-12 06:23:29 +08:00
|
|
|
const LPARAM lParam
|
2011-12-28 21:32:50 +08:00
|
|
|
)
|
|
|
|
{
|
2011-12-29 20:45:16 +08:00
|
|
|
DWORD dwProccessId = 0;
|
2011-12-28 21:32:50 +08:00
|
|
|
if (hWindow)
|
|
|
|
std::cout << lParam;
|
2012-01-12 06:23:29 +08:00
|
|
|
|
|
|
|
if (hWindow)
|
2011-12-28 21:32:50 +08:00
|
|
|
{
|
2012-01-12 06:23:29 +08:00
|
|
|
static ULONGLONG staticVar = 0;
|
2011-12-29 20:45:16 +08:00
|
|
|
DWORD dwThreadId = ::GetWindowThreadProcessId(hWindow, &dwProccessId);
|
2012-01-12 21:41:01 +08:00
|
|
|
staticVar = dwProccessId + 1;
|
2012-01-12 06:23:29 +08:00
|
|
|
__debugbreak();
|
2012-01-25 19:57:47 +08:00
|
|
|
functionCalledFromEnumWindowsProc1(dwProccessId);
|
2012-01-12 06:23:29 +08:00
|
|
|
std::cout << dwProccessId << dwThreadId << staticVar;
|
2011-12-28 21:32:50 +08:00
|
|
|
}
|
2012-01-12 06:23:29 +08:00
|
|
|
return hWindow ? FALSE : TRUE;
|
2011-12-28 21:32:50 +08:00
|
|
|
}
|
2012-01-13 05:51:57 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
BOOL CALLBACK EnumWindowsProc2(HWND, LPARAM)
|
|
|
|
{
|
|
|
|
__debugbreak();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-01-12 21:41:01 +08:00
|
|
|
#pragma optimize("g", on)
|
2011-12-06 02:48:26 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int doLoadUnload()
|
|
|
|
{
|
2011-12-06 17:26:58 +08:00
|
|
|
__debugbreak();
|
2011-12-06 02:48:26 +08:00
|
|
|
HMODULE hmod = ::LoadLibrary( _T("iphlpapi.dll") );
|
|
|
|
if (hmod)
|
|
|
|
::FreeLibrary(hmod);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-12-19 00:28:04 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int doAccessViolation()
|
|
|
|
{
|
|
|
|
char *p = (char *)6;
|
|
|
|
*p = 12;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-25 01:26:08 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int g_valueForAccessTesting1 = 4;
|
|
|
|
int g_valueForAccessTesting2 = 5;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma optimize("g", off)
|
|
|
|
void changeValueForAccessTesting()
|
|
|
|
{
|
|
|
|
g_valueForAccessTesting1 = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void readValueForAccessTesting()
|
|
|
|
{
|
|
|
|
std::cout << g_valueForAccessTesting1 << g_valueForAccessTesting2;
|
|
|
|
}
|
|
|
|
#pragma optimize("g", on)
|
2012-01-19 03:14:46 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int doExeptions()
|
|
|
|
{
|
2012-01-25 04:40:07 +08:00
|
|
|
__debugbreak();
|
|
|
|
|
2012-01-25 01:26:08 +08:00
|
|
|
changeValueForAccessTesting();
|
|
|
|
|
|
|
|
readValueForAccessTesting();
|
|
|
|
|
2012-01-19 03:14:46 +08:00
|
|
|
__debugbreak();
|
|
|
|
|
|
|
|
PUCHAR _ptr = reinterpret_cast<UCHAR *>(2);
|
|
|
|
__try {
|
|
|
|
*_ptr = 5;
|
|
|
|
} __except(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
}
|
|
|
|
|
|
|
|
++_ptr;
|
|
|
|
*_ptr = 6;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-12-06 02:48:26 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-03-12 15:08:01 +08:00
|
|
|
int doChangeStatus()
|
|
|
|
{
|
|
|
|
__debugbreak();
|
|
|
|
__debugbreak();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-20 14:40:21 +08:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
std::map<int, bool> g_map;
|
|
|
|
|
2011-06-07 00:48:10 +08:00
|
|
|
int _tmain(int argc, _TCHAR* argv[])
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2012-05-20 14:40:21 +08:00
|
|
|
g_map.insert(std::pair<int, bool>(100, true));
|
|
|
|
|
2011-12-15 18:34:03 +08:00
|
|
|
InitializeListHead( &g_listHead );
|
|
|
|
InsertTailList( &g_listHead, &g_listItem1.listEntry );
|
|
|
|
InsertTailList( &g_listHead, &g_listItem2.listEntry );
|
|
|
|
InsertTailList( &g_listHead, &g_listItem3.listEntry );
|
|
|
|
|
2012-12-08 22:13:03 +08:00
|
|
|
entry1.Flink = &entry2;
|
|
|
|
entry2.Flink = &entry1;
|
|
|
|
|
2011-12-15 18:34:03 +08:00
|
|
|
g_listHead1 = &g_listItem11;
|
|
|
|
g_listItem11.next = &g_listItem12;
|
|
|
|
g_listItem12.next = &g_listItem13;
|
|
|
|
|
2012-01-19 00:17:11 +08:00
|
|
|
g_childListEntry1.m_someBaseFiled2 = 1000;
|
|
|
|
g_childListEntry1.m_childFiled1 = 1001;
|
|
|
|
|
|
|
|
g_childListEntry2.m_someBaseFiled2 = 2000;
|
|
|
|
g_childListEntry2.m_childFiled1 = 2001;
|
|
|
|
|
|
|
|
g_childListEntry3.m_someBaseFiled2 = 3000;
|
|
|
|
g_childListEntry3.m_childFiled1 = 3001;
|
|
|
|
|
|
|
|
g_childListHead = &g_childListEntry1;
|
|
|
|
g_childListEntry1.m_next = &g_childListEntry2;
|
|
|
|
g_childListEntry2.m_next = &g_childListEntry3;
|
|
|
|
g_childListEntry3.m_next = NULL;
|
|
|
|
|
2012-01-19 03:14:46 +08:00
|
|
|
g_unNamedStruct.m_fieldNestedStruct = 4;
|
|
|
|
g_unNamedStruct.m_fieldOfUnNamed = 5;
|
|
|
|
|
2012-01-19 18:16:07 +08:00
|
|
|
g_structWithNested.m_field = 34;
|
|
|
|
g_structNested.m_nestedFiled = 46;
|
|
|
|
|
2012-05-15 23:17:26 +08:00
|
|
|
g_fieldSameNameStruct.m_field = "toaster";
|
|
|
|
g_fieldSameNameStruct.intermediateStruct::baseStruct1::m_field = 1024;
|
|
|
|
g_fieldSameNameStruct.baseStruct2::m_field = 0xc;
|
|
|
|
|
2012-01-19 21:29:01 +08:00
|
|
|
g_ptrToFunction = &EnumWindowsProc2;
|
|
|
|
g_unTypedPtrToFunction = &EnumWindowsProc2;
|
|
|
|
|
2012-05-25 15:29:53 +08:00
|
|
|
bigCStr = new char[0x2000 + 1];
|
|
|
|
memset( bigCStr, 'a', 0x2000 );
|
|
|
|
bigCStr[0x2000] = 0;
|
|
|
|
|
|
|
|
bigWStr = new wchar_t[0x2000 + 1];
|
|
|
|
wmemset( bigWStr, L'a', 0x2000 );
|
|
|
|
bigWStr[0x2000] = 0;
|
|
|
|
|
2011-12-06 17:26:58 +08:00
|
|
|
// Let test scripts to execute
|
|
|
|
__debugbreak();
|
|
|
|
|
2011-12-06 02:48:26 +08:00
|
|
|
if (2 == argc)
|
|
|
|
{
|
|
|
|
// run with parameters
|
|
|
|
if ( !_tcsicmp(argv[1], _T("-testLoadUnload")) )
|
|
|
|
return doLoadUnload();
|
2012-01-12 06:23:29 +08:00
|
|
|
|
2012-12-19 00:28:04 +08:00
|
|
|
if ( !_tcsicmp(argv[1], _T("-testAccessViolation")) )
|
|
|
|
return doAccessViolation();
|
|
|
|
|
2012-01-12 06:23:29 +08:00
|
|
|
if ( !_tcsicmp(argv[1], _T("-testEnumWindows")) )
|
2012-01-12 21:41:01 +08:00
|
|
|
{
|
2012-01-13 05:51:57 +08:00
|
|
|
::EnumWindows(&EnumWindowsProc1, 6);
|
|
|
|
::EnumWindows(&EnumWindowsProc2, 7);
|
2012-01-12 21:41:01 +08:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2012-01-19 03:14:46 +08:00
|
|
|
|
|
|
|
if ( !_tcsicmp(argv[1], _T("-testExceptions")) )
|
|
|
|
return doExeptions();
|
2013-03-12 15:08:01 +08:00
|
|
|
|
|
|
|
if ( !_tcsicmp(argv[1], _T("-testChangeStatus")) )
|
|
|
|
return doChangeStatus();
|
2011-12-06 02:48:26 +08:00
|
|
|
}
|
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
__debugbreak();
|
|
|
|
__debugbreak();
|
|
|
|
__debugbreak();
|
2011-09-22 00:50:42 +08:00
|
|
|
FuncWithName0();
|
2011-09-23 05:54:27 +08:00
|
|
|
FuncWithName1(2);
|
2012-09-25 14:15:50 +08:00
|
|
|
_FuncWithName2(3);
|
2011-06-07 00:48:10 +08:00
|
|
|
}
|
|
|
|
catch(std::exception & ex)
|
|
|
|
{
|
|
|
|
std::cout << ex.what() << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
std::cout << "Unknown error" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-29 20:45:16 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|