📄 dcdtable.cpp
字号:
public:
KDecodeDC(HDC hDC, unsigned * addr)
{
m_hDC = hDC;
m_addr = addr;
}
void Save(void)
{
memcpy(buffer, m_addr, sizeof(buffer));
}
void Comp(TCHAR * mess);
void DeviceCap(const TCHAR * name, int id);
};
void KDecodeDC::DeviceCap(const TCHAR *name, int id)
{
unsigned rslt = GetDeviceCaps(m_hDC, id);
OutputDebugString("GetDeviceCaps(");
OutputDebugString(name);
TCHAR temp[64];
wsprintf(temp, "%x", rslt);
OutputDebugString(" returns ");
OutputDebugString(temp);
for (int i=0; i<sizeof(DCAttr)/sizeof(unsigned); i++)
if (m_addr[i] == rslt )
{
wsprintf(temp, "offset %d", i);
OutputDebugString(temp);
break;
}
OutputDebugString("\n");
}
void KDecodeDC::Comp(TCHAR *mess)
{
int changes = 0;
TCHAR temp[128];
for (int i=0; i<sizeof(DCAttr)/sizeof(unsigned); i++)
if (buffer[i] != m_addr[i])
{
wsprintf(temp, "%s changes offse 0x%x (%08x -> %08x) \n", mess, i*4,
buffer[i], m_addr[i]);
OutputDebugString(temp);
changes ++;
}
if (changes == 0)
{
wsprintf(temp, "%s changes nothing\n", mess);
OutputDebugString(temp);
}
}
#include <math.h>
// convert FLOATOBJ back to double
double FLOATOBJ2Double(const FLOATOBJ & f)
{
double rslt = (double) f.ul1 * pow(2, (double)f.ul2-32);
char temp[48];
sprintf(temp, "%08lx %08lx %10.8f", f.ul2, f.ul1, rslt);
OutputDebugString(temp);
return rslt;
}
void DecodeDC(HDC hDC, unsigned * addr)
{
KDecodeDC dc(hDC, addr);
DCAttr * p = (DCAttr *) addr;
int j = sizeof(DCAttr);
#if (_WIN32_WINNT >= 0x0500)
assert (j==0x1c8);
#else
assert (j==0x190);
#endif
POINT Org; GetDCOrgEx(hDC, & Org);
dc.Save();
HBITMAP hDDB = CreateBitmap(15, 15, 1, 1, NULL);
SelectObject(hDC, hDDB);
dc.Comp("SelectBitmap");
HRGN hRgn = CreateRectRgn(1, 2, 3, 4);
SelectObject(hDC, hRgn);
for (int i=0; i<sizeof(DCAttr)/sizeof(unsigned); i++)
if ( GetObjectType((HGDIOBJ) addr[i]) )
{
TCHAR Temp[48];
wsprintf(Temp, "offset %x objtype %d\n", i*4, GetObjectType((HGDIOBJ) addr[i]));
OutputDebugString(Temp);
}
dc.Save();
BeginPath(hDC); dc.Comp("BeginPath");
Rectangle(hDC, 1, 2, 3, 4);
dc.Save();
EndPath(hDC);
dc.Comp("EndPath");
int s = SaveDC(hDC); dc.Save();
RestoreDC(hDC, s); dc.Comp("SaveDC");
SetBrushOrgEx(hDC, 1, 2, NULL); dc.Save();
SetBrushOrgEx(hDC, 3, 4, NULL); dc.Comp("SetBrushOrgEx");
SetGraphicsMode(hDC, GM_COMPATIBLE); dc.Save();
SetGraphicsMode(hDC, GM_ADVANCED); dc.Comp("SetGraphicsMode");
XFORM xform = { 1, 0, 0, 1, 5, 5.5 };
SetWorldTransform(hDC, & xform); dc.Save();
XFORM xform1= { 1, 0, 0, 2, 5, (float)5.49 };
SetWorldTransform(hDC, & xform1); dc.Comp("SetWorldTransform");
// FLOATOBJ2Double(p->XFORM_eDx);
dc.Save();
XFORM xform2= { 1.1111f, 0xFF02, 0xFF03, 0xFF04, 0xFF05, 0xFF06 };
SetWorldTransform(hDC, & xform2); dc.Comp("SetWorldTransform 1");
// FLOATOBJ2Double(p->XFORM_eM11);
dc.Save();
XFORM xform3= { 1.1111f, 2.2222f, 0xFF03, 0xFF04, 0xFF05, 0xFF06 };
SetWorldTransform(hDC, & xform3); dc.Comp("SetWorldTransform 2");
dc.Save();
XFORM xform4= { 1.1111f, 2.2222f, 3.333f, 0xFF04, 0xFF05, 0xFF06 };
SetWorldTransform(hDC, & xform4); dc.Comp("SetWorldTransform 3");
dc.Save();
XFORM xform5= { 1.1111f, -2.2222f, 3.333f, 4.4444f, 0xFF05, 0xFF06 };
SetWorldTransform(hDC, & xform5); dc.Comp("SetWorldTransform 4");
dc.Save();
XFORM xform6= { 1.1111f, 2.2222f, 3.333f, 4.4444f, 5.5555f, 0xFF06 };
SetWorldTransform(hDC, & xform6); dc.Comp("SetWorldTransform 5");
dc.Save();
XFORM xform7= { 1.1111f, 2.2222f, 3.333f, 4.4444f, 5.5555f, 6.6666f };
SetWorldTransform(hDC, & xform7); dc.Comp("SetWorldTransform 6");
SetMiterLimit(hDC, 0.5, NULL); dc.Save();
SetMiterLimit(hDC, 1.1f, NULL); dc.Comp("SetMiterLimit");
SetArcDirection(hDC, AD_COUNTERCLOCKWISE ); dc.Save();
SetArcDirection(hDC, AD_CLOCKWISE); dc.Comp("SetArcDirection");
RECT rect = { 1961, 1962, 1963, 1964 }; dc.Save();
SetBoundsRect(hDC, & rect, DCB_ENABLE); dc.Comp("SetBoundsRect");
SelectObject(hDC, GetStockObject(BLACK_BRUSH)); dc.Save();
SelectObject(hDC, GetStockObject(WHITE_BRUSH)); dc.Comp("SelectBrush");
SelectObject(hDC, GetStockObject(BLACK_PEN)); dc.Save();
SelectObject(hDC, GetStockObject(WHITE_PEN)); dc.Comp("SelectPen");
SelectObject(hDC, GetStockObject(ANSI_FIXED_FONT)); dc.Save();
SelectObject(hDC, GetStockObject(ANSI_VAR_FONT)); dc.Comp("SelectFont");
SelectObject(hDC, GetStockObject(DEFAULT_PALETTE)); dc.Save();
SelectObject(hDC, CreateHalftonePalette(hDC)); dc.Comp("SelectPalette");
MoveToEx(hDC, 1, 2, NULL); dc.Save();
MoveToEx(hDC, 100, 200, NULL); dc.Comp("MoveToEx");
SetBkColor(hDC, RGB(1, 0, 0)); dc.Save();
SetBkColor(hDC, RGB(2, 0, 0)); dc.Comp("SetBkColor");
SetBkMode(hDC, OPAQUE); dc.Save();
SetBkMode(hDC, TRANSPARENT); dc.Comp("SetBkMode");
SetPolyFillMode(hDC, ALTERNATE); dc.Save();
SetPolyFillMode(hDC, WINDING); dc.Comp("SetPolyFillMode");
SetROP2(hDC, R2_BLACK); dc.Save();
SetROP2(hDC, R2_WHITE); dc.Comp("SetRop2");
SetStretchBltMode(hDC, BLACKONWHITE); dc.Save();
SetStretchBltMode(hDC, COLORONCOLOR); dc.Comp("SetStretchBltMode");
SetTextColor(hDC, RGB(3, 0, 0)); dc.Save();
SetTextColor(hDC, RGB(4, 0, 0)); dc.Comp("SetTextColor");
SetMapMode(hDC, MM_TEXT); dc.Save();
SetMapMode(hDC, MM_ANISOTROPIC); dc.Comp("SetMapMode");
SetViewportOrgEx(hDC, 1, 2, NULL); dc.Save();
SetViewportOrgEx(hDC, 3, 4, NULL); dc.Comp("SetViewportOrgEx");
SetViewportExtEx(hDC, 100, 200, NULL); dc.Save();
SetViewportExtEx(hDC, 300, 400, NULL); dc.Comp("SetViewportExtEx");
SetWindowOrgEx(hDC, 1, 3, NULL); dc.Save();
SetWindowOrgEx(hDC, 2, 4, NULL); dc.Comp("SetWindowOrgEx");
SetWindowExtEx(hDC, 100, 50, NULL); dc.Save();
SetWindowExtEx(hDC, 50, 100, NULL); dc.Comp("SetWindowExtEx");
SetTextAlign(hDC, TA_BASELINE); dc.Save();
SetTextAlign(hDC, TA_BOTTOM); dc.Comp("SetTextAlign");
SetTextJustification(hDC, 1, 2); dc.Save();
SetTextJustification(hDC, 3, 4); dc.Comp("SetTextJustification");
SetTextCharacterExtra(hDC, 5); dc.Save();
SetTextCharacterExtra(hDC, 0); dc.Comp("SetTextCharacterExtra");
SetMapperFlags(hDC, 1); dc.Save();
SetMapperFlags(hDC, 0); dc.Comp("SetMapperFlags");
TEXTMETRIC tm;
GetTextMetrics(hDC, &tm);
GetClipBox(hDC, & rect);
i=1;
dc.Cap(DRIVERVERSION);
dc.Cap(TECHNOLOGY);
dc.Cap(HORZSIZE);
dc.Cap(VERTSIZE);
dc.Cap(HORZRES);
dc.Cap(VERTRES);
dc.Cap(BITSPIXEL);
dc.Cap(PLANES);
dc.Cap(NUMBRUSHES);
dc.Cap(NUMPENS);
dc.Cap(NUMMARKERS);
dc.Cap(NUMFONTS);
dc.Cap(NUMCOLORS);
dc.Cap(PDEVICESIZE);
dc.Cap(CURVECAPS);
dc.Cap(LINECAPS);
dc.Cap(POLYGONALCAPS);
dc.Cap(TEXTCAPS);
dc.Cap(CLIPCAPS);
dc.Cap(RASTERCAPS);
dc.Cap(ASPECTX);
dc.Cap(ASPECTY);
dc.Cap(ASPECTXY);
// dc.Cap(SHADEBLENDCAPS);
dc.Cap(LOGPIXELSX);
dc.Cap(LOGPIXELSY);
dc.Cap(SIZEPALETTE);
dc.Cap(NUMRESERVED);
dc.Cap(COLORRES);
dc.Cap(PHYSICALWIDTH);
dc.Cap(PHYSICALHEIGHT);
dc.Cap(PHYSICALOFFSETX);
dc.Cap(PHYSICALOFFSETY);
dc.Cap(SCALINGFACTORX);
dc.Cap(SCALINGFACTORY);
dc.Cap(VREFRESH);
dc.Cap(DESKTOPVERTRES);
dc.Cap(DESKTOPHORZRES);
dc.Cap(BLTALIGNMENT);
}
class KEditDC : public KDialog
{
public:
unsigned * addr;
BOOL DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int i;
switch (uMsg)
{
case WM_INITDIALOG:
m_hWnd = hWnd;
for (i=0; i<sizeof(DCProperty)/sizeof(DCProperty[0]); i++)
{
SendDlgItemMessage(hWnd, IDC_OPERATIONS, LB_ADDSTRING, 0,
(LPARAM) DCProperty[i]);
}
for (i=0; i<(sizeof(DCAttr)/4); i++)
{
TCHAR temp[64];
wsprintf(temp, "%03x = %08x", i*4, addr[i]);
SendDlgItemMessage(hWnd, IDC_CONTEXT, LB_ADDSTRING, 0,
(LPARAM) temp);
}
return TRUE;
case WM_COMMAND:
switch ( LOWORD(wParam) )
{
case IDOK:
EndDialog(hWnd, TRUE);
return TRUE;
}
}
return FALSE;
}
};
void KDecodeTablePage::Modify(unsigned nIndex)
{
GDITableCell Obj = m_GDITable[nIndex];
HGDIOBJ hObj = (HGDIOBJ) (Obj.nUpper << 16 | nIndex);
switch ( GetObjectType(hObj) )
{
case OBJ_MEMDC:
case OBJ_DC:
{
KEditDC editdc;
DecodeDC((HDC) hObj, (unsigned *) m_GDITable[nIndex].pUser);
editdc.addr = (unsigned *) m_GDITable[nIndex].pUser;
editdc.Dialogbox(m_hInst, MAKEINTRESOURCE(IDD_EDITDC));
}
break;
}
}
void KDecodeTablePage::ShowDetails(unsigned nIndex)
{
KString<1024> message;
GDITableCell Obj = m_GDITable[nIndex];
int * pInt;
HGDIOBJ hObj = (HGDIOBJ) (Obj.nUpper << 16 | nIndex);
message.Append("Index: %x, ", nIndex);
message.Append("Handle: %x, ", (unsigned) hObj);
message.Append("Type: "); message.Append(GetObjectTypeName(hObj));
message.Append("\r\n");
for (int o = obj_BLACK_BRUSH; o<=obj_DEFAULT_PALETTE; o++)
if ( hObj == CreateObject(o) )
{
message.Append(Commands[o]);
message.Append("\r\n");
break;
}
switch ( GetObjectType(hObj) )
{
case OBJ_BRUSH:
if ( Obj.pUser )
{
assert (! IsBadReadPtr( Obj.pUser, 0x18 ) );
pInt = (int *) Obj.pUser;
LOGBRUSH * pBrush = (LOGBRUSH *) Obj.pUser;
message.Append("LOGBRUSH { %d, ", pBrush->lbStyle);
message.Append("0x%06x, ", pBrush->lbColor);
message.Append("%d }", pBrush->lbHatch);
message.Append("%d, ", pInt[3]);
message.Append("%d, ", pInt[4]);
message.Append("%d ", pInt[5]);
}
break;
case OBJ_REGION:
if ( Obj.pUser )
{
assert (! IsBadReadPtr( Obj.pUser, 0x18 ) );
pInt = (int *) Obj.pUser;
message.Append("{ %d, ", pInt[0]);
message.Append("%d, ", pInt[1]);
message.Append("%d, ", pInt[2]);
message.Append("%d, ", pInt[3]);
message.Append("%d, ", pInt[4]);
message.Append("%d }", pInt[5]);
}
break;
case OBJ_FONT:
if ( Obj.pUser )
{
assert (Obj.pUser );
assert (! IsBadReadPtr( & Obj, 8 ) );
pInt = (int *) Obj.pUser;
message.Append("{ 0x%x, ", pInt[0]);
message.Append("0x%x }", pInt[1]);
LOGFONT logfont;
GetObject(hObj, sizeof(LOGFONT), &logfont);
message.Append(logfont.lfFaceName);
// Figuring out pInt[1]
/*
if ( pInt[1] )
{
HDC hDC = GetDC(NULL);
HGDIOBJ hOld = SelectObject(hDC, hObj);
TEXTMETRIC tm;
GetTextMetrics(hDC, & tm);
int width[256];
GetCharWidth(hDC, tm.tmFirstChar, tm.tmLastChar, width);
SelectObject(hDC, hOld);
ReleaseDC(NULL, hDC);
}
*/
}
break;
case OBJ_DC:
assert (Obj.pUser);
assert (! IsBadReadPtr(Obj.pUser, 0x190) );
break;
}
// big enough to get the whole object
int buffer[200];
int size = GetObjectW(hObj, sizeof(buffer), buffer);
if ( size )
{
message.Append("\r\n%d bytes: ", size);
size = (size+3)/4;
for (int i=0; i<size; i++)
message.Append("%x ", buffer[i]);
}
SetDlgItemText(m_hWnd, IDC_DETAIL, message);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -