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;
|
|
|
|
|
2011-12-29 21:01:52 +08:00
|
|
|
CHAR g_charValue = -1;
|
|
|
|
SHORT g_shortValue = -2;
|
|
|
|
LONG g_longValue = -4;
|
|
|
|
LONGLONG g_longlongValue = -8;
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
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
|
|
|
|
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 };
|
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
|
|
|
|
};
|
|
|
|
|
2011-09-22 19:20:31 +08:00
|
|
|
class classChild : public classBase {
|
|
|
|
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
|
|
|
};
|
|
|
|
|
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 };
|
|
|
|
|
|
|
|
|
|
|
|
struct listStruct1;
|
|
|
|
|
|
|
|
static listStruct1 *g_listHead1 = NULL;
|
|
|
|
|
|
|
|
struct listStruct1 {
|
|
|
|
int num;
|
|
|
|
struct listStruct1 *next;
|
|
|
|
};
|
|
|
|
|
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 };
|
|
|
|
|
2011-12-29 20:45:16 +08:00
|
|
|
#pragma pack( pop )
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
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;
|
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];
|
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;
|
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;
|
2011-09-22 00:50:42 +08:00
|
|
|
}
|
|
|
|
|
2011-12-29 20:45:16 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2011-12-28 21:32:50 +08:00
|
|
|
|
|
|
|
BOOL CALLBACK EnumWindowsProc(
|
|
|
|
HWND hWindow,
|
|
|
|
LPARAM lParam
|
|
|
|
)
|
|
|
|
{
|
2011-12-29 20:45:16 +08:00
|
|
|
DWORD dwProccessId = 0;
|
2011-12-28 21:32:50 +08:00
|
|
|
if (hWindow)
|
|
|
|
std::cout << lParam;
|
|
|
|
{
|
2011-12-29 20:45:16 +08:00
|
|
|
DWORD dwThreadId = ::GetWindowThreadProcessId(hWindow, &dwProccessId);
|
|
|
|
std::cout << dwProccessId << dwThreadId;
|
2011-12-28 21:32:50 +08:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-06-07 00:48:10 +08:00
|
|
|
int _tmain(int argc, _TCHAR* argv[])
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
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 );
|
|
|
|
|
|
|
|
g_listHead1 = &g_listItem11;
|
|
|
|
g_listItem11.next = &g_listItem12;
|
|
|
|
g_listItem12.next = &g_listItem13;
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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);
|
2011-12-28 21:32:50 +08:00
|
|
|
|
|
|
|
EnumWindows(&::EnumWindowsProc, 6);
|
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
|
|
|
////////////////////////////////////////////////////////////////////////////////
|