#include #include // must be included before cenk.h / cearm.h #include #include "debug.h" #include "kernelmisc.h" #include "cever_deps.h" #include "vectorutils.h" #include "stringutils.h" #include typedef DWORD (*dllvarproc_t)(...); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { KernelMode _km; DebugSetLogfile("loaddll.log"); StringList args; if (!SplitString(ToString(lpCmdLine), args, false)) { error("Error in commandline"); return false; } std::string dllname; std::string procname; std::string paramspec; StringList params; bool kernelLib= false; bool sleepafterload= false; bool kernelmode= false; for (StringList::iterator i= args.begin() ; i!=args.end() ; ++i) { std::string& arg= *i; if (arg[0]=='-') switch(arg[1]) { case 'k': kernelLib=true; break; case 's': sleepafterload=true; break; case 'm': kernelmode=true; break; } else if (dllname.empty()) dllname= arg; else if (procname.empty()) procname= arg; else if (paramspec.empty()) paramspec= arg; else params.push_back(arg); } typedef boost::shared_ptr km_ptr; km_ptr km; if (kernelmode) { km= km_ptr(new KernelMode()); debug("switched to kmode\n"); } if (kernelLib) { HANDLE hLib= LoadKernelLibrary(ToTString(dllname).c_str()); if (hLib==NULL) { error("LoadkernelLib"); return 1; } while (sleepafterload) Sleep(100000); return 0; } HMODULE hLib= LoadLibrary(ToTString(dllname).c_str()); if (hLib==NULL) { error("LoadLib"); return 1; } dllvarproc_t proc= (dllvarproc_t)GetProcAddress(hLib, ToTString(procname).c_str()); if (proc==NULL) { error("getproc"); return 1; } DwordVector v; for (unsigned i=0 ; i(pstr->c_str())); break; } case 'S': { std::Wstring *pstr= new std::Wstring(ToWString(params[i])); v.push_back(reinterpret_cast(pstr->c_str())); break; } case 'i': v.push_back(strtoul(params[i].c_str(), 0, 0)); break; } } v.resize(16); DWORD res= proc(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15]); debug("result: %08lx\n", res); while (sleepafterload) Sleep(100000); return 0; }