【文章标题】: 打造记事本置顶功能
【文章作者】: wxxw
【软件名称】: 系统自带
【保护方式】: 无壳
【编写语言】: Microsoft Visual C++ 7.0 Method2
【使用工具】: PEID 0.95 Olldbg1.10 resscope lordpe
【操作平台】: XP sp3
【软件介绍】: 不用介绍了吧
【作者声明】: 只是感兴趣,没有其他目的。失误之处敬请诸位大侠赐教!
--------------------------------------------------------------------------------
【详细过程】
早有前人实现了该功能,虽说是别人嚼过的馍,可我还是想自己动手试试
首先先设想下做成什么样?我们想在菜单里添加一项“置顶”,选择后完成置顶功能,取消后恢复原状,类似菜单“格式”下的“自动换行”,设想好了,开始动工
因为有系统文件还原保护,所以先将notepad.exe复制为notepad1.exe,然后在资源管理器--“工具”--“文件夹选项”--“文件类型”将txt文件更改为notepad1.exe打开,前备工作做完了,现在开始正式修改了,首先用资源工具(如rescope,exescope)修改菜单资源,比如我在“查看”下添加一菜单项“置顶”,ID自己随便写,如这里写为28,然后用LORDPE在输入表里添加user32.dll里函数SetWindowPos(完成置顶及释放置顶)还需要函数GetMenu,CheckMenuItem(完成菜单项前面的选择标记和取消),这两个函数源程序里已经有了,用OD载入程序notepad1.exe,F9运行,然后在77d1870c(这个地址由来详见http://bbs.pediy.com/showthread.php?t=98274)下条件断点[esp+c]==WM_COMMAND && [esp+14]==0 ,这里[esp+c]是消息码,[esp+10]是消息wparam,[esp+14]是消息lparam,因为菜单的lparam是0,所以加上[esp+14]==0条件,如果不加,一切换到notepad1,就会中断了,这是因为notepad的edit控件发出了WM_COMMAND,好了,选择“置顶”菜单,断下来,来到窗口回调函数01003429,F7单步,来到处理WM_COMMAND消息代码01002b87,继续单步来到如下代码
01002BBE . 83FF 40 CMP EDI,40 ; Switch (cases 1..303)
01002BC1 . 8995 F0FDFFFF MOV DWORD PTR SS:[EBP-210],EDX
01002BC7 . 0F8F F9060000 JG notepad1.010032C6
01002BCD . 0F84 DB060000 JE notepad1.010032AE
01002BD3 . 83FF 15 CMP EDI,15
01002BD6 . 0F8F CE020000 JG notepad1.01002EAA
01002BDC . 0F84 EC030000 JE notepad1.01002FCE
01002BE2 . 83FF 05 CMP EDI,5
01002BE5 . 0F8F 74020000 JG notepad1.01002E5F
01002BEB . 0F84 0B020000 JE notepad1.01002DFC
01002BF1 . 4F DEC EDI
01002BF2 . 0F84 F8010000 JE notepad1.01002DF0
01002BF8 . 4F DEC EDI
01002BF9 . 0F84 0E010000 JE notepad1.01002D0D
01002BFF . 4F DEC EDI
01002C00 . 74 0A JE SHORT notepad1.01002C0C
01002C02 . 4F DEC EDI
01002C03 . 74 32 JE SHORT notepad1.01002C37
01002C05 > 33C0 XOR EAX,EAX ; Default case of switch 01003024
01002C07 . E9 5E070000 JMP notepad1.0100336A
......
01002EAA > \83FF 1A CMP EDI,1A
01002EAD . 0F8F 95580000 JG notepad1.01003019
01002EB3 . 0F84 55010000 JE notepad1.0100300E
01002EB9 . 83EF 16 SUB EDI,16
01002EBC . 0F84 F4000000 JE notepad1.01002FB6
01002EC2 . 4F DEC EDI
01002EC3 . 0F84 93000000 JE notepad1.01002F5C
01002EC9 . 4F DEC EDI
01002ECA . 74 5E JE SHORT notepad1.01002F2A
01002ECC . 4F DEC EDI
01002ECD .^ 0F85 32FDFFFF JNZ notepad1.01002C05
01008748 > \6A 1C PUSH 1C
0100874A . 5B POP EBX
0100874B . 3BFB CMP EDI,EBX
0100874D .^ 0F85 C6A8FFFF JNZ notepad1.01003019
01008753 . 803D 47870001>CMP BYTE PTR DS:[1008747],1 ; Case 1C of switch 01002BBE
0100875A . 74 35 JE SHORT notepad1.01008791
0100875C . C605 47870001>MOV BYTE PTR DS:[1008747],1
01008763 . 60 PUSHAD
01008764 . 6A 03 PUSH 3 ; /Flags = SWP_NOSIZE|SWP_NOMOVE
01008766 . 6A 00 PUSH 0 ; |Height = 0
01008768 . 6A 00 PUSH 0 ; |Width = 0
0100876A . 6A 00 PUSH 0 ; |Y = 0
0100876C . 6A 00 PUSH 0 ; |X = 0
0100876E . 6A FF PUSH -1 ; |InsertAfter = HWND_TOPMOST
01008770 . 52 PUSH EDX ; |hWnd
01008771 . FF15 1A300101 CALL DWORD PTR DS:[<&USER32.SetWindowPos>; \SetWindowPos
01008777 . 61 POPAD
01008778 . 60 PUSHAD
01008779 . 52 PUSH EDX ; /hWnd
0100877A . FF15 64120001 CALL DWORD PTR DS:[<&USER32.GetMenu>] ; \GetMenu
01008780 . 6A 08 PUSH 8 ; /Flags = MF_BYCOMMAND|MF_ENABLED|MF_CHECKED|MF_STRING
01008782 . 6A 1C PUSH 1C ; |ItemId = 1C (28.)
01008784 . 50 PUSH EAX ; |hMenu
01008785 . FF15 48120001 CALL DWORD PTR DS:[<&USER32.CheckMenuIte>; \CheckMenuItem
0100878B . 61 POPAD
0100878C .^ E9 88A8FFFF JMP notepad1.01003019
01008791 > C605 47870001>MOV BYTE PTR DS:[1008747],0
01008798 . 60 PUSHAD
01008799 . 6A 03 PUSH 3 ; /Flags = SWP_NOSIZE|SWP_NOMOVE
0100879B . 6A 00 PUSH 0 ; |Height = 0
0100879D . 6A 00 PUSH 0 ; |Width = 0
0100879F . 6A 00 PUSH 0 ; |Y = 0
010087A1 . 6A 00 PUSH 0 ; |X = 0
010087A3 . 6A FE PUSH -2 ; |InsertAfter = HWND_NOTOPMOST
010087A5 . 52 PUSH EDX ; |hWnd
010087A6 . FF15 1A300101 CALL DWORD PTR DS:[<&USER32.SetWindowPos>; \SetWindowPos
010087AC . 61 POPAD
010087AD . 60 PUSHAD
010087AE . 52 PUSH EDX ; /hWnd
010087AF . FF15 64120001 CALL DWORD PTR DS:[<&USER32.GetMenu>] ; \GetMenu
010087B5 . 6A 00 PUSH 0 ; /Flags = MF_BYCOMMAND|MF_ENABLED|MF_STRING
010087B7 . 6A 1C PUSH 1C ; |ItemId = 1C (28.)
010087B9 . 50 PUSH EAX ; |hMenu
010087BA . FF15 48120001 CALL DWORD PTR DS:[<&USER32.CheckMenuIte>; \CheckMenuItem
010087C0 . 61 POPAD
010087C1 .^ E9 53A8FFFF JMP notepad1.01003019
010034C5 > \8B45 10 MOV EAX,DWORD PTR SS:[EBP+10] ; EAX里为WM_SIZE的wparam,最小化时为1
010034C8 . 33F6 XOR ESI,ESI
010034CA . 2BC6 SUB EAX,ESI
010034CC . 74 06 JE SHORT notepad7.010034D4
010034CE . 48 DEC EAX ; Switch (cases 1..2)
010034CF . 74 49 JE SHORT notepad7.0100351A ;这里就是跳到处理最小化的消息 0100351A
010087C6 > \60 PUSHAD
010087C7 . 6A 00 PUSH 0 ; /ShowState = SW_HIDE
010087C9 . FF75 08 PUSH DWORD PTR SS:[EBP+8] ; |hWnd
010087CC . FF15 B0110001 CALL DWORD PTR DS:[<&USER32.ShowWindow>] ; \ShowWindow
010087D2 . 6A 02 PUSH 2 ; /RsrcName = 2.
010087D4 . 68 00000001 PUSH notepad7.01000000 ; |hInst = 01000000
010087D9 . FF15 EC110001 CALL DWORD PTR DS:[<&USER32.LoadIconW>] ; \LoadIconW
010087DF .- E9 1CB80000 JMP notepad7.01014000 ;01014000是我新加的代码节
...............
01014000 A3 14410101 MOV DWORD PTR DS:[1014114],EAX ;我将NOTIFYICONDATA结构数据预先放在01014100处,这里写入hicon
01014005 8B45 08 MOV EAX,DWORD PTR SS:[EBP+8]
01014008 A3 04410101 MOV DWORD PTR DS:[1014104],EAX ;这里写入hwnd
0101400D 68 00410101 PUSH notepad7.01014100
01014012 6A 00 PUSH 0
01014014 FF15 41300101 CALL DWORD PTR DS:[<&shell32.Shell_Notif>; shell32.Shell_NotifyIconA
0101401A 61 POPAD
0101401B 8BE5 MOV ESP,EBP
0101401D 5D POP EBP
0101401E C3 RETN
0100343B .- 0F87 DE0B0100 JA notepad7.0101401F
......
0101401F 81FE 05040000 CMP ESI,405
01014025 - 0F85 57F6FEFF JNZ notepad7.01003682
0101402B 837D 10 00 CMP DWORD PTR SS:[EBP+10],0
0101402F - 0F85 4DF6FEFF JNZ notepad7.01003682
01014035 817D 14 0102000>CMP DWORD PTR SS:[EBP+14],201
0101403C 75 6A JNZ SHORT notepad7.010140A8
0101403E 60 PUSHAD
0101403F 6A 09 PUSH 9
01014041 FF75 08 PUSH DWORD PTR SS:[EBP+8]
01014044 FF15 B0110001 CALL DWORD PTR DS:[<&USER32.ShowWindow>] ; user32.ShowWindow
0101404A FF75 08 PUSH DWORD PTR SS:[EBP+8]
0101404D FF15 BC300101 CALL DWORD PTR DS:[<&USER32.SetForegroun>; user32.SetForegroundWindow
01014053 68 00410101 PUSH notepad7.01014100
01014058 6A 02 PUSH 2
0101405A FF15 41300101 CALL DWORD PTR DS:[<&shell32.Shell_Notif>; shell32.Shell_NotifyIconA
01014060 61 POPAD
01014061 8BE5 MOV ESP,EBP
01014063 5D POP EBP
01014064 C3 RETN
01003434 .- E9 2F0C0100 JMP notepad7.01014068
.......
01014068 83FE 01 CMP ESI,1
0101406B 0F85 81000000 JNZ notepad7.010140F2
01014071 60 PUSHAD
01014072 FF15 C0300101 CALL DWORD PTR DS:[<&USER32.CreatePopupM>; user32.CreatePopupMenu
01014078 A3 00420101 MOV DWORD PTR DS:[1014200],EAX ;保存菜单句柄备后用
0101407D 68 10420101 PUSH notepad7.01014210 ; ASCII "restore" 自己先写好的菜单字符串
01014082 6A 1D PUSH 1D
01014084 6A 00 PUSH 0
01014086 50 PUSH EAX
01014087 FF15 C8300101 CALL DWORD PTR DS:[<&USER32.AppendMenuA>>; user32.AppendMenuA
0101408D 68 20420101 PUSH notepad7.01014220 ; ASCII "exit" 自己先写好的菜单字符串
01014092 6A 1E PUSH 1E
01014094 6A 00 PUSH 0
01014096 FF35 00420101 PUSH DWORD PTR DS:[1014200]
0101409C FF15 C8300101 CALL DWORD PTR DS:[<&USER32.AppendMenuA>>; user32.AppendMenuA
010140A2 61 POPAD
010140A3 EB 4D JMP SHORT notepad7.010140F2
......
010140F2 83FE 1C CMP ESI,1C ;这里是恢复原来01003434的代码,返回执行
010140F5 57 PUSH EDI
010140F6 6A 08 PUSH 8
010140F8 5A POP EDX
010140F9 - E9 3DF3FEFF JMP notepad7.0100343B
010140A8 817D 14 0502000>CMP DWORD PTR SS:[EBP+14],205
010140AF - 0F85 CDF5FEFF JNZ notepad7.01003682
010140B5 60 PUSHAD
010140B6 68 00430101 PUSH notepad7.01014300
010140BB FF15 38120001 CALL DWORD PTR DS:[<&USER32.GetCursorPos>; user32.GetCursorPos
010140C1 FF75 08 PUSH DWORD PTR SS:[EBP+8]
010140C4 FF15 BC300101 CALL DWORD PTR DS:[<&USER32.SetForegroun>; user32.SetForegroundWindow
010140CA 6A 00 PUSH 0
010140CC FF75 08 PUSH DWORD PTR SS:[EBP+8]
010140CF 6A 00 PUSH 0
010140D1 FF35 04430101 PUSH DWORD PTR DS:[1014304]
010140D7 90 NOP
010140D8 FF35 00430101 PUSH DWORD PTR DS:[1014300]
010140DE 90 NOP
010140DF 6A 08 PUSH 8
010140E1 FF35 00420101 PUSH DWORD PTR DS:[1014200]
010140E7 FF15 C4300101 CALL DWORD PTR DS:[<&USER32.TrackPopupMe>; user32.TrackPopupMenu
010140ED 61 POPAD
010140EE 8BE5 MOV ESP,EBP
010140F0 5D POP EBP
010140F1 C3 RETN
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
上传的附件: