资源简介
大家知道,win32窗口的内置滚动自绘是个非常棘手的问题,在写这篇文章之前首先感谢下CSDN的mynamelj,他写的那个SkinSB开源的时候我就开始使用来美化一般win32窗口的滚动条,很好用,但是最近有想把自己的应用迁移到x64平台的想法,所以必须把全部源码编译成64位的版本,以便能在win 64位下获得最佳性能,好了废话不多说,继续往下看。
改进SkinSB:
当时遇到两大难题,第一个是API钩子库detours在X64下用不了,第二个是skinsb自有源码小部分不适应64位。
对于第一个难题,当时到微软网站看了下其实detours 3.0版本有支持64位的,但是不是免费的,收费$9999一套,相当于7万RMB左右,这费用我等实在付不起,只好另找其他方法,经同事介绍mhook库,稍微看了下也是开源的,使用方法也很方便,就两个函数,一个Mhook_SetHook加载API钩子,一个Mhook_Unhook
代码片段和文件信息
// Copyright (C) 2003 Matt Conover (mconover@gmail.com)
#include “cpu.h“
#include
// NOTE: this assumes default scenarios (i.e. we assume CS/DS/ES/SS and flat
// and all have a base of 0 and limit of 0xffffffff we don‘t try to verify
// that in the GDT)
//
// TODO: use inline assembly to get selector for segment
// Segment = x86 segment register (SEG_ES = 0 SEG_CS = 1 ...)
BYTE *GetAbsoluteAddressFromSegment(BYTE Segment DWORD Offset)
{
switch (Segment)
{
// Windows uses a flat address space (except FS for x86 and GS for x64)
case 0: // SEG_ES
case 1: // SEG_CS
case 2: // SEG_SS
case 3: // SEG_DS
return (BYTE *)(DWORD_PTR)Offset;
case 4: // SEG_FS
case 5: // SEG_GS
return (BYTE *)(DWORD_PTR)Offset;
// Note: we‘re really supposed to do this but get_teb is not implemented
// in this bastardized version of the disassembler.
// return (BYTE *)get_teb() + Offset;
default:
assert(0);
return (BYTE *)(DWORD_PTR)Offset;
}
}
// This is an GDT/LDT selector (pGDT+Selector)
BYTE *GetAbsoluteAddressFromSelector(WORD Selector DWORD Offset)
{
DEscriptOR_ENTRY Entry;
GATE_ENTRY *Gate;
ULONG_PTR base;
assert(Selector < 0x10000);
if (!GetThreadSelectorEntry(GetCurrentThread() Selector (LDT_ENTRY *)&Entry)) return NULL;
if (!Entry.Present) return NULL;
if (Entry.System)
{
base = 0;
#ifdef _WIN64
base |= (ULONG_PTR)Entry.HighOffset64 << 32;
#endif
base |= Entry.baseHi << 24;
base |= Entry.baseMid << 16;
base |= Entry.baseLow;
}
else
{
switch (Entry.Type)
{
case 1: // 16-bit TSS (available)
case 2: // LDT
case 3: // 16-bit TSS (busy)
case 9: // 32-bit TSS (available)
case 11: // 32-bit TSS (busy)
base = 0;
#ifdef _WIN64
base |= (ULONG_PTR)Entry.HighOffset64 << 32;
#endif
base |= Entry.baseHi << 24;
base |= Entry.baseMid << 16;
base |= Entry.baseLow;
break;
case 4: // 16-bit call gate
case 5: // task gate
case 6: // 16-bit interrupt gate
case 7: // 16-bit task gate
case 12: // 32-bit call gate
case 14: // 32-bit interrupt gate
case 15: // 32-bit trap gate
Gate = (GATE_ENTRY *)&Entry;
#ifdef _WIN64
base = ((ULONG_PTR)Gate->HighOffset64 << 32) | (Gate->HighOffset << 16) | Gate->LowOffset;
#else
base = (Gate->HighOffset << 16) | Gate->LowOffset;
#endif
assert(!Offset); Offset = 0;
break;
default:
assert(0);
return NULL;
}
}
return (BYTE *)base + Offset;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2550 2007-07-09 12:59 SkinSB\disasm\cpu.c
文件 6796 2007-07-09 02:04 SkinSB\disasm\cpu.h
文件 4101 2007-07-09 01:33 SkinSB\disasm\disasm.c
文件 16194 2007-07-09 01:45 SkinSB\disasm\disasm.h
文件 6369 2012-08-10 21:39 SkinSB\disasm\disasm.vcproj
文件 150604 2007-07-08 19:58 SkinSB\disasm\disasm_x86.c
文件 21231 2007-07-08 19:39 SkinSB\disasm\disasm_x86.h
文件 264999 2007-05-29 00:09 SkinSB\disasm\disasm_x86_tables.h
文件 4667 2007-07-09 01:06 SkinSB\disasm\misc.c
文件 1366 2007-07-09 02:04 SkinSB\disasm\misc.h
文件 32692 2012-08-10 20:19 SkinSB\mhook\mhook.cpp
文件 1377 2008-06-26 03:35 SkinSB\mhook\mhook.h
文件 5938 2012-08-10 21:39 SkinSB\mhook\mhook.vcproj
文件 7607 2011-01-08 18:10 SkinSB\skinsb\internal.h
文件 49712 2012-08-10 10:59 SkinSB\skinsb\skinsb.cpp
文件 275 2009-09-23 13:42 SkinSB\skinsb\skinsb.def
文件 3583 2011-01-08 18:10 SkinSB\skinsb\skinsb.h
..A..H. 24064 2009-06-23 20:58 SkinSB\skinsb\skinsb.suo
..A..H. 9216 2008-06-25 10:21 SkinSB\skinsb\skinsb.suo.old
文件 11399 2012-08-10 22:54 SkinSB\skinsb\skinsb_2005.vcproj
文件 3670 2012-08-10 21:44 SkinSB\skinsb.sln
..A..H. 14336 2012-08-10 23:26 SkinSB\skinsb.suo
文件 36920 2012-08-02 14:52 SkinSB\SkinSBDemo\res\scroll.bmp
文件 71116 2009-09-22 19:05 SkinSB\SkinSBDemo\res\SCROLL.psd
文件 37110 2011-01-09 11:31 SkinSB\SkinSBDemo\res\scrollex.bmp
文件 46926 2011-01-09 11:31 SkinSB\SkinSBDemo\res\scrollx.bmp
文件 39270 2011-01-09 11:31 SkinSB\SkinSBDemo\res\scrollxx.bmp
文件 21630 2005-08-12 16:37 SkinSB\SkinSBDemo\res\SkinSBDemo.ico
文件 401 2009-02-15 20:59 SkinSB\SkinSBDemo\res\SkinSBDemo.rc2
文件 999 2011-01-09 11:31 SkinSB\SkinSBDemo\resource.h
............此处省略23个文件信息
评论
共有 条评论