/* (C) 2003 XDA Developers itsme@xs4all.nl * * $Header$ */ #include #include #include "debug.h" #include "stringutils.h" #include "itsutils.h" #include "tffsreader.h" typedef HRESULT (STDAPICALLTYPE *rapifn)( DWORD cbInput, void *pbInput, DWORD *pcbOutput, void **ppbOutput, void *pStream); bool tstapiver(HINSTANCE hLib) { // test api version rapifn getver= (rapifn )GetProcAddress(hLib, L"ITGetVersion"); if (getver==NULL) { error("GetProcAddress(ITGetVersion)"); return false; } debug("ITGetVersion= %08lx\n", getver); DWORD dwSize=0; BYTE *buf=NULL; HRESULT res= getver(0, NULL, &dwSize, (void**)&buf, NULL); debug("itsutils api version=%d\n", res); return true; } bool tstgetctx(HINSTANCE hLib) { // test get context rapifn getctx= (rapifn )GetProcAddress(hLib, L"ITGetContext"); if (getctx==NULL) { error("GetProcAddress(ITGetContext)"); return false; } debug("ITGetContext= %08lx\n", getctx); DWORD dwSize=0; BYTE *buf=NULL; HRESULT res= getctx(0, NULL, &dwSize, (void**)&buf, NULL); if (dwSize && buf) { debug("answer: %hs\n", hexdump(buf, dwSize).c_str()); LocalFree(buf); } return true; } bool tstgetphandle(HINSTANCE hLib) { // test get process handle rapifn getph= (rapifn )GetProcAddress(hLib, L"ITGetProcessHandle"); if (getph==NULL) { error("GetProcAddress(ITGetProcessHandle)"); return false; } debug("ITGetProcessHandle= %08lx\n", getph); WCHAR *szProcname= L"device.exe"; DWORD dwSize=0; BYTE *buf=NULL; HRESULT res= getph((wcslen(szProcname)+1)*sizeof(WCHAR), (BYTE*)szProcname, &dwSize, (void**)&buf, NULL); if (dwSize && buf) { debug("answer: %hs\n", hexdump(buf, dwSize).c_str()); LocalFree(buf); } return true; } bool tstgetplist(HINSTANCE hLib) { // test get context rapifn getplist= (rapifn )GetProcAddress(hLib, L"ITGetProcessList"); if (getplist==NULL) { error("GetProcAddress(ITGetProcessList)"); return false; } debug("ITGetProcessList= %08lx\n", getplist); bool bParam= false; DWORD dwSize=0; BYTE *buf=NULL; HRESULT res= getplist(sizeof(bool), (BYTE*)&bParam, &dwSize, (void**)&buf, NULL); if (dwSize && buf) { if (dwSize>64) { debug("truncating %d to 64 bytes\n", dwSize); dwSize= 64; } debug("answer: %hs\n", hexdump(buf, dwSize).c_str()); LocalFree(buf); } return true; } bool tstgettlist(HINSTANCE hLib) { // test get context rapifn gettlist= (rapifn )GetProcAddress(hLib, L"ITGetThreadUsageList"); if (gettlist==NULL) { error("GetProcAddress(ITGetThreadUsageList)"); return false; } debug("ITGetThreadUsageList= %08lx\n", gettlist); DWORD dwSize=0; BYTE *buf=NULL; bool bresolve= true; HRESULT res= gettlist(sizeof(bool), &bresolve, &dwSize, (void**)&buf, NULL); if (dwSize && buf) { if (dwSize>64) { debug("truncating %d to 64 bytes\n", dwSize); dwSize= 64; } debug("answer: %hs\n", hexdump(buf, dwSize).c_str()); LocalFree(buf); } return true; } bool tstlogdisk(HINSTANCE hLib) { // test get context rapifn logdisk= (rapifn )GetProcAddress(hLib, L"ITLogDiskInfo"); if (logdisk==NULL) { error("GetProcAddress(ITLogDiskInfo)"); return false; } debug("ITLogDiskInfo= %08lx\n", logdisk); LogDiskInfoParams disk; memset(&disk, 0, sizeof(disk)); wcscpy(disk.szDeviceName, L"TrueFFS"); wcscpy(disk.szPartitionName, L"Part00"); disk.dwBinaryPartitionNr= BP_TFFSSECTOR; DWORD dwSize=0; BYTE *buf=NULL; HRESULT res= logdisk(sizeof(disk), &disk, &dwSize, (void**)&buf, NULL); if (dwSize && buf) { if (dwSize>64) { debug("truncating %d to 64 bytes\n", dwSize); dwSize= 64; } debug("answer: %hs\n", hexdump(buf, dwSize).c_str()); LocalFree(buf); } return true; } bool tstgetmlist(HINSTANCE hLib) { // test get context rapifn getmlist= (rapifn )GetProcAddress(hLib, L"ITGetModuleList"); if (getmlist==NULL) { error("GetProcAddress(ITGetModuleList)"); return false; } debug("ITGetModuleList= %08lx\n", getmlist); bool bDirect= true; DWORD dwSize=0; BYTE *buf=NULL; HRESULT res= getmlist(sizeof(bool), &bDirect, &dwSize, (void**)&buf, NULL); if (dwSize && buf) { if (dwSize>64) { debug("truncating %d to 64 bytes\n", dwSize); dwSize= 64; } debug("answer: %hs\n", hexdump(buf, dwSize).c_str()); LocalFree(buf); } return true; } bool tstgetfgnd(HINSTANCE hLib) { rapifn getfgnd= (rapifn )GetProcAddress(hLib, L"ITGetForegroundWindow"); if (getfgnd==NULL) { error("GetProcAddress(ITGetForegroundWindow)"); return false; } debug("ITGetForegroundWindow= %08lx\n", getfgnd); DWORD dwSize=0; BYTE *buf=NULL; HRESULT res= getfgnd(0, NULL, &dwSize, (void**)&buf, NULL); if (dwSize && buf) { if (dwSize>64) { debug("truncating %d to 64 bytes\n", dwSize); dwSize= 64; } debug("answer: %hs\n", hexdump(buf, dwSize).c_str()); LocalFree(buf); } return true; } bool tstgetwlist(HINSTANCE hLib) { rapifn getwlist= (rapifn )GetProcAddress(hLib, L"ITGetWindowList"); if (getwlist==NULL) { error("GetProcAddress(ITGetWindowList)"); return false; } debug("ITGetWindowList= %08lx\n", getwlist); DWORD dwSize=0; BYTE *buf=NULL; HRESULT res= getwlist(0, NULL, &dwSize, (void**)&buf, NULL); if (dwSize && buf) { if (dwSize>64) { debug("truncating %d to 64 bytes\n", dwSize); dwSize= 64; } debug("answer: %hs\n", hexdump(buf, dwSize).c_str()); LocalFree(buf); } return true; } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { DebugSetLogfile("tstits.log"); if (lpCmdLine==NULL || lpCmdLine[0]==0) lpCmdLine= L"itsutils.dll"; HINSTANCE hLib= LoadLibrary(lpCmdLine); if (hLib==NULL || hLib==INVALID_HANDLE_VALUE) { error("LoadLibrary(%ls)", lpCmdLine); return 1; } debug("loaded %ls: hLib= %08lx\n", lpCmdLine, hLib); tstapiver(hLib); tstgetctx(hLib); tstgetphandle(hLib); tstgetplist(hLib); tstgetmlist(hLib); tstgettlist(hLib); tstlogdisk(hLib); tstgetfgnd(hLib); tstgetwlist(hLib); FreeLibrary(hLib); debug("done testing itsutils\n"); return 0; }