/* (C) 2003-2007 Willem Jan Hengeveld * Web: http://www.xs4all.nl/~itsme/ * http://wiki.xda-developers.com/ * * $Id$ */ #include #include #include #include #include "debug.h" #include "args.h" #include "ptrutils.h" #include "itsutils.h" #include "dllversion.h" // todo: kill by handle does not seem to work. void ITTerminateProcess(DWORD dwProcessHandle, const std::string& szProcessName, bool bWait); void ITTerminateThread(DWORD dwThreadHandle); void usage() { printf("(C) 2003-2008 Willem jan Hengeveld itsme@xs4all.nl\n"); printf("Usage: pkill [-w] [-t HANDLE] [ {-h HANDLE } | { processname } ]...\n"); printf(" -w : wait until process has terminated\n"); } int main( int argc, char *argv[]) { DebugStdOut(); if (argc==1) { usage(); return 1; } CheckITSDll(); bool bWaitForProcess= false; for (int i=1 ; iwszProcessName+wprocname.size()+1) : PTR_DIFF(inbuf, inbuf->wszProcessName+1); inbuf= (TerminateProcessParams*)RapiAlloc(insize); DWORD outsize=0; inbuf->dwProcessHandle= dwProcessHandle; inbuf->bWait= bWait; if (!wprocname.empty()) { std::copy(wprocname.begin(), wprocname.end(), inbuf->wszProcessName); inbuf->wszProcessName[wprocname.size()]= 0; } else { inbuf->wszProcessName[0]= 0; } HRESULT res= ItsutilsInvoke("ITTerminateProcess", insize, (BYTE*)inbuf, &outsize, NULL); if (res) error(res, "killing %08lx | %s", dwProcessHandle, szProcessName.empty()?("-"):szProcessName.c_str()); else debug("%08lx | %s killed\n", dwProcessHandle, szProcessName.empty()?("-"):szProcessName.c_str()); } void ITTerminateThread(DWORD dwThreadHandle) { TerminateThreadParams inbuf; DWORD insize= sizeof(inbuf); DWORD outsize=0; inbuf.dwThreadHandle= dwThreadHandle; HRESULT res= ItsutilsInvoke("ITTerminateThread", insize, (BYTE*)&inbuf, &outsize, NULL); if (res) error(res, "killing thread %08lx", dwThreadHandle); else debug("thread %08lx killed\n", dwThreadHandle); }