matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: [Request] Minimize to tray on focus contact window with a hotkey
js code: function embedCode(hWnd){
if(!subClassProcAddr){
var hCurrentProcess = Interop.call("kernel32.dll", "GetCurrentProcess");
subClassProcAddr = Interop.Call("kernel32.dll", "VirtualAlloc", null, CODE_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
var code = Interop.Allocate(CODE_SIZE);
var pos = 0;
code.SetAt(pos++, 0x55); // push ebp
code.SetAt(pos++, 0x8b); // mov ebp, esp
code.SetAt(pos++, 0xec);
code.SetAt(pos++, 0x81); // cmp dword ptr [ebp+12], WM_NCDESTROY
code.SetAt(pos++, 0x7d);
code.SetAt(pos++, 0x0c);
code.SetAt(pos++, 0x82);
code.SetAt(pos++, 0x00);
code.SetAt(pos++, 0x00);
code.SetAt(pos++, 0x00);
code.SetAt(pos++, 0x74); // je remove
code.SetAt(pos++, 0x31);
code.SetAt(pos++, 0x81); // cmp dword ptr [ebp+12], WM_CHAR
code.SetAt(pos++, 0x7d);
code.SetAt(pos++, 0x0c);
code.SetAt(pos++, 0x02);
code.SetAt(pos++, 0x01);
code.SetAt(pos++, 0x00);
code.SetAt(pos++, 0x00);
code.SetAt(pos++, 0x75); // jne exit
code.SetAt(pos++, 0x3a);
code.SetAt(pos++, 0x83); // cmp dword ptr [ebp+16], 23
code.SetAt(pos++, 0x7d);
code.SetAt(pos++, 0x10);
>>> code.SetAt(pos++, 0x17); /* Maybe 0x1B for the Escape key? */<<<
code.SetAt(pos++, 0x75); // jne exit
code.SetAt(pos++, 0x34);
code.SetAt(pos++, 0x6a); // push 0
code.SetAt(pos++, 0x00);
code.SetAt(pos++, 0x6a); // push 0
code.SetAt(pos++, 0x00);
code.SetAt(pos++, 0x6a); // push WM_CLOSE
code.SetAt(pos++, 0x10);
code.SetAt(pos++, 0xff); // push [ebp+8]
code.SetAt(pos++, 0x75);
code.SetAt(pos++, 0x08);
code.SetAt(pos++, 0xb9); // mov ecx, &GetParent
code.WriteDWORD(pos, getLibraryProcAddress("user32.dll", "GetParent"));
pos += 4;
code.SetAt(pos++, 0xff); // call ecx
code.SetAt(pos++, 0xd1);
if(Messenger.Version >= 9){
code.SetAt(pos++, 0x50); // push eax
code.SetAt(pos++, 0xb9); // mov ecx, &GetParent
code.WriteDWORD(pos, getLibraryProcAddress("user32.dll", "GetParent"));
pos += 4;
code.SetAt(pos++, 0xff); // call ecx
code.SetAt(pos++, 0xd1);
}else if(Messenger.Version >= 8){
code.WriteDWORD(pos, 0x00841f0f); // nop dword ptr [eax + eax*1 + 00000000h]
pos += 4;
code.WriteDWORD(pos, 0x00000000);
pos += 4;
}
code.SetAt(pos++, 0x50); // push eax
code.SetAt(pos++, 0xb9); // mov ecx, &PostMessageW
code.WriteDWORD(pos, getLibraryProcAddress("user32.dll", "PostMessageW"));
pos += 4;
code.SetAt(pos++, 0xff); // call ecx
code.SetAt(pos++, 0xd1);
code.SetAt(pos++, 0xeb); // jmp exit
code.SetAt(pos++, 0x12);
// remove:
code.SetAt(pos++, 0xff); // push [ebp+24]
code.SetAt(pos++, 0x75);
code.SetAt(pos++, 0x18);
code.SetAt(pos++, 0x68); // push &subClassProcAddr
code.WriteDWORD(pos, subClassProcAddr);
pos += 4;
code.SetAt(pos++, 0xff); // push [ebp+8]
code.SetAt(pos++, 0x75);
code.SetAt(pos++, 0x08);
code.SetAt(pos++, 0xb9); // mov ecx, &RemoveWindowSubclass
code.WriteDWORD(pos, getLibraryProcAddress("comctl32.dll", "RemoveWindowSubclass"));
pos += 4;
code.SetAt(pos++, 0xff); // call ecx
code.SetAt(pos++, 0xd1);
// exit:
code.SetAt(pos++, 0xff); // push [ebp+20]
code.SetAt(pos++, 0x75);
code.SetAt(pos++, 0x14);
code.SetAt(pos++, 0xff); // push [ebp+16]
code.SetAt(pos++, 0x75);
code.SetAt(pos++, 0x10);
code.SetAt(pos++, 0xff); // push [ebp+12]
code.SetAt(pos++, 0x75);
code.SetAt(pos++, 0x0c);
code.SetAt(pos++, 0xff); // push [ebp+8]
code.SetAt(pos++, 0x75);
code.SetAt(pos++, 0x08);
code.SetAt(pos++, 0xb9); // mov, ecx, &DefSubclassProc
code.WriteDWORD(pos, getLibraryProcAddress("comctl32.dll", "DefSubclassProc"));
pos += 4;
code.SetAt(pos++, 0xff); // call ecx
code.SetAt(pos++, 0xd1);
code.SetAt(pos++, 0xc9); // leave
code.SetAt(pos++, 0xc2); // retn 24
code.SetAt(pos++, 0x18);
code.SetAt(pos++, 0x00);
ASSERT(pos == CODE_SIZE, "Code insertion complete");
Interop.Call("kernel32.dll", "WriteProcessMemory", hCurrentProcess, subClassProcAddr, code.DataPtr, CODE_SIZE, null);
}
if(subClassProcAddr){
Interop.Call("comctl32.dll", "SetWindowSubclass", hWnd, subClassProcAddr, 0, 0);
}
}
This post was edited on 05-20-2009 at 06:10 PM by matty.
|
|