ReactOS  0.4.14-dev-114-gc8cbd56
path.c File Reference
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "dbghelp_private.h"
#include "winnls.h"
#include "winternl.h"
#include "wine/debug.h"
Include dependency graph for path.c:

Go to the source code of this file.

Classes

struct  enum_dir_treeWA
 
struct  sffip
 
struct  module_find
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (dbghelp)
 
static BOOL is_sep (char ch)
 
static BOOL is_sepW (WCHAR ch)
 
static const charfile_name (const char *str)
 
static const WCHARfile_nameW (const WCHAR *str)
 
static void file_pathW (const WCHAR *srcFileNameW, WCHAR *dstFilePathW)
 
HANDLE WINAPI FindDebugInfoFile (PCSTR FileName, PCSTR SymbolPath, PSTR DebugFilePath)
 
HANDLE WINAPI FindDebugInfoFileEx (PCSTR FileName, PCSTR SymbolPath, PSTR DebugFilePath, PFIND_DEBUG_FILE_CALLBACK Callback, PVOID CallerData)
 
HANDLE WINAPI FindExecutableImageExW (PCWSTR FileName, PCWSTR SymbolPath, PWSTR ImageFilePath, PFIND_EXE_FILE_CALLBACKW Callback, PVOID user)
 
HANDLE WINAPI FindExecutableImageEx (PCSTR FileName, PCSTR SymbolPath, PSTR ImageFilePath, PFIND_EXE_FILE_CALLBACK Callback, PVOID user)
 
HANDLE WINAPI FindExecutableImage (PCSTR FileName, PCSTR SymbolPath, PSTR ImageFilePath)
 
BOOL WINAPI MakeSureDirectoryPathExists (PCSTR DirPath)
 
BOOL WINAPI SymMatchFileNameW (PCWSTR file, PCWSTR match, PWSTR *filestop, PWSTR *matchstop)
 
BOOL WINAPI SymMatchFileName (PCSTR file, PCSTR match, PSTR *filestop, PSTR *matchstop)
 
static BOOL do_searchW (PCWSTR file, PWSTR buffer, BOOL recurse, PENUMDIRTREE_CALLBACKW cb, PVOID user)
 
BOOL WINAPI SearchTreeForFileW (PCWSTR root, PCWSTR file, PWSTR buffer)
 
BOOL WINAPI SearchTreeForFile (PCSTR root, PCSTR file, PSTR buffer)
 
BOOL WINAPI EnumDirTreeW (HANDLE hProcess, PCWSTR root, PCWSTR file, PWSTR buffer, PENUMDIRTREE_CALLBACKW cb, PVOID user)
 
static BOOL CALLBACK enum_dir_treeWA (PCWSTR name, PVOID user)
 
BOOL WINAPI EnumDirTree (HANDLE hProcess, PCSTR root, PCSTR file, PSTR buffer, PENUMDIRTREE_CALLBACK cb, PVOID user)
 
static BOOL CALLBACK sffip_cb (PCWSTR buffer, PVOID user)
 
BOOL WINAPI SymFindFileInPathW (HANDLE hProcess, PCWSTR searchPath, PCWSTR full_path, PVOID id, DWORD two, DWORD three, DWORD flags, PWSTR buffer, PFINDFILEINPATHCALLBACKW cb, PVOID user)
 
BOOL WINAPI SymFindFileInPath (HANDLE hProcess, PCSTR searchPath, PCSTR full_path, PVOID id, DWORD two, DWORD three, DWORD flags, PSTR buffer, PFINDFILEINPATHCALLBACK cb, PVOID user)
 
static BOOL CALLBACK module_find_cb (PCWSTR buffer, PVOID user)
 
BOOL path_find_symbol_file (const struct process *pcs, const struct module *module, PCSTR full_path, const GUID *guid, DWORD dw1, DWORD dw2, PSTR buffer, BOOL *is_unmatched)
 

Function Documentation

◆ do_searchW()

static BOOL do_searchW ( PCWSTR  file,
PWSTR  buffer,
BOOL  recurse,
PENUMDIRTREE_CALLBACKW  cb,
PVOID  user 
)
static

Definition at line 222 of file path.c.

224 {
225  HANDLE h;
227  unsigned pos;
228  BOOL found = FALSE;
229  static const WCHAR S_AllW[] = {'*','.','*','\0'};
230  static const WCHAR S_DotW[] = {'.','\0'};
231  static const WCHAR S_DotDotW[] = {'.','.','\0'};
232 
233  pos = strlenW(buffer);
234  if (buffer[pos - 1] != '\\') buffer[pos++] = '\\';
235  strcpyW(buffer + pos, S_AllW);
237  return FALSE;
238  /* doc doesn't specify how the tree is enumerated...
239  * doing a depth first based on, but may be wrong
240  */
241  do
242  {
243  if (!strcmpW(fd.cFileName, S_DotW) || !strcmpW(fd.cFileName, S_DotDotW)) continue;
244 
245  strcpyW(buffer + pos, fd.cFileName);
246  if (recurse && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
247  found = do_searchW(file, buffer, TRUE, cb, user);
248  else if (SymMatchFileNameW(buffer, file, NULL, NULL))
249  {
250  if (!cb || cb(buffer, user)) found = TRUE;
251  }
252  } while (!found && FindNextFileW(h, &fd));
253  if (!found) buffer[--pos] = '\0';
254  FindClose(h);
255 
256  return found;
257 }
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
#define TRUE
Definition: types.h:120
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
GLuint buffer
Definition: glext.h:5915
static int fd
Definition: io.c:51
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
BOOL WINAPI SymMatchFileNameW(PCWSTR file, PCWSTR match, PWSTR *filestop, PWSTR *matchstop)
Definition: path.c:171
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
__wchar_t WCHAR
Definition: xmlstorage.h:180
static DWORD cb
Definition: integrity.c:41
static BOOL do_searchW(PCWSTR file, PWSTR buffer, BOOL recurse, PENUMDIRTREE_CALLBACKW cb, PVOID user)
Definition: path.c:222
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
WINE_UNICODE_INLINE int strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: unicode.h:229
void user(int argc, const char *argv[])
Definition: cmds.c:1350
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
Definition: fci.c:126
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

Referenced by EnumDirTreeW(), path_find_symbol_file(), SearchTreeForFileW(), and SymFindFileInPathW().

◆ enum_dir_treeWA()

static BOOL CALLBACK enum_dir_treeWA ( PCWSTR  name,
PVOID  user 
)
static

Definition at line 315 of file path.c.

316 {
317  struct enum_dir_treeWA* edt = user;
318 
320  return edt->cb(edt->name, edt->user);
321 }
char name[MAX_PATH]
Definition: path.c:312
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
void * user
Definition: path.c:311
smooth NULL
Definition: ftsmooth.c:416
#define MAX_PATH
Definition: compat.h:26
Definition: name.c:36
PENUMDIRTREE_CALLBACK cb
Definition: path.c:310
void user(int argc, const char *argv[])
Definition: cmds.c:1350

◆ EnumDirTree()

BOOL WINAPI EnumDirTree ( HANDLE  hProcess,
PCSTR  root,
PCSTR  file,
PSTR  buffer,
PENUMDIRTREE_CALLBACK  cb,
PVOID  user 
)

Definition at line 323 of file path.c.

325 {
328  WCHAR bufferW[MAX_PATH];
329  struct enum_dir_treeWA edt;
330  BOOL ret;
331 
332  edt.cb = cb;
333  edt.user = user;
336  if ((ret = EnumDirTreeW(hProcess, rootW, fileW, bufferW, enum_dir_treeWA, &edt)))
337  WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL);
338  return ret;
339 }
#define WideCharToMultiByte
Definition: compat.h:101
static const WCHAR rootW[]
Definition: chain.c:69
#define CP_ACP
Definition: compat.h:99
GLuint buffer
Definition: glext.h:5915
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
DWORD ret
Definition: path.c:47
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI EnumDirTreeW(HANDLE hProcess, PCWSTR root, PCWSTR file, PWSTR buffer, PENUMDIRTREE_CALLBACKW cb, PVOID user)
Definition: path.c:293
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
static DWORD cb
Definition: integrity.c:41
#define MultiByteToWideChar
Definition: compat.h:100
static const WCHAR fileW[]
Definition: url.c:111
void user(int argc, const char *argv[])
Definition: cmds.c:1350
Definition: fci.c:126

◆ EnumDirTreeW()

BOOL WINAPI EnumDirTreeW ( HANDLE  hProcess,
PCWSTR  root,
PCWSTR  file,
PWSTR  buffer,
PENUMDIRTREE_CALLBACKW  cb,
PVOID  user 
)

Definition at line 293 of file path.c.

295 {
296  TRACE("(%p %s %s %p %p %p)\n",
298 
299  strcpyW(buffer, root);
300  return do_searchW(file, buffer, TRUE, cb, user);
301 }
#define TRUE
Definition: types.h:120
GLuint buffer
Definition: glext.h:5915
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
static DWORD cb
Definition: integrity.c:41
static BOOL do_searchW(PCWSTR file, PWSTR buffer, BOOL recurse, PENUMDIRTREE_CALLBACKW cb, PVOID user)
Definition: path.c:222
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
void user(int argc, const char *argv[])
Definition: cmds.c:1350
Definition: fci.c:126

Referenced by EnumDirTree().

◆ file_name()

static const char* file_name ( const char str)
inlinestatic

Definition at line 36 of file path.c.

37 {
38  const char* p;
39 
40  for (p = str + strlen(str) - 1; p >= str && !is_sep(*p); p--);
41  return p + 1;
42 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
const WCHAR * str
static BOOL is_sep(char ch)
Definition: path.c:33
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by FindDebugInfoFile().

◆ file_nameW()

static const WCHAR* file_nameW ( const WCHAR str)
inlinestatic

Definition at line 44 of file path.c.

45 {
46  const WCHAR* p;
47 
48  for (p = str + strlenW(str) - 1; p >= str && !is_sepW(*p); p--);
49  return p + 1;
50 }
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
const WCHAR * str
__wchar_t WCHAR
Definition: xmlstorage.h:180
static BOOL is_sepW(WCHAR ch)
Definition: path.c:34
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by path_find_symbol_file(), SymFindFileInPathW(), and URLDownloadToFileA().

◆ file_pathW()

static void file_pathW ( const WCHAR srcFileNameW,
WCHAR dstFilePathW 
)
inlinestatic

Definition at line 52 of file path.c.

54 {
55  int len;
56 
57  for (len = strlenW(srcFileNameW) - 1; (len > 0) && (!is_sepW(srcFileNameW[len])); len--);
58 
59  strncpyW(dstFilePathW, srcFileNameW, len);
60  dstFilePathW[len] = L'\0';
61 }
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
#define strncpyW(d, s, n)
Definition: unicode.h:227
static BOOL is_sepW(WCHAR ch)
Definition: path.c:34
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722

Referenced by path_find_symbol_file().

◆ FindDebugInfoFile()

HANDLE WINAPI FindDebugInfoFile ( PCSTR  FileName,
PCSTR  SymbolPath,
PSTR  DebugFilePath 
)

Definition at line 67 of file path.c.

68 {
69  HANDLE h;
70 
73  if (h == INVALID_HANDLE_VALUE)
74  {
75  if (!SearchPathA(SymbolPath, file_name(FileName), NULL, MAX_PATH, DebugFilePath, NULL))
76  return NULL;
77  h = CreateFileA(DebugFilePath, GENERIC_READ, FILE_SHARE_READ, NULL,
79  }
80  return (h == INVALID_HANDLE_VALUE) ? NULL : h;
81 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FILE_SHARE_READ
Definition: compat.h:125
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
static const char const char const char * SymbolPath
Definition: image.c:34
DWORD WINAPI SearchPathA(IN LPCSTR lpPath OPTIONAL, IN LPCSTR lpFileName, IN LPCSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPSTR lpBuffer, OUT LPSTR *lpFilePart OPTIONAL)
Definition: path.c:1122
smooth NULL
Definition: ftsmooth.c:416
static const char * file_name(const char *str)
Definition: path.c:36
#define OPEN_EXISTING
Definition: compat.h:426
#define MAX_PATH
Definition: compat.h:26
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define GENERIC_READ
Definition: compat.h:124
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399

◆ FindDebugInfoFileEx()

HANDLE WINAPI FindDebugInfoFileEx ( PCSTR  FileName,
PCSTR  SymbolPath,
PSTR  DebugFilePath,
PFIND_DEBUG_FILE_CALLBACK  Callback,
PVOID  CallerData 
)

Definition at line 87 of file path.c.

91 {
92  FIXME("(%s %s %s %p %p): stub\n", debugstr_a(FileName), debugstr_a(SymbolPath),
93  debugstr_a(DebugFilePath), Callback, CallerData);
94  return NULL;
95 }
static const char const char const char * SymbolPath
Definition: image.c:34
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
#define debugstr_a
Definition: kernel32.h:31
LPFNPSPCALLBACK Callback
Definition: desk.c:111

◆ FindExecutableImage()

HANDLE WINAPI FindExecutableImage ( PCSTR  FileName,
PCSTR  SymbolPath,
PSTR  ImageFilePath 
)

Definition at line 135 of file path.c.

136 {
137  return FindExecutableImageEx(FileName, SymbolPath, ImageFilePath, NULL, NULL);
138 }
HANDLE WINAPI FindExecutableImageEx(PCSTR FileName, PCSTR SymbolPath, PSTR ImageFilePath, PFIND_EXE_FILE_CALLBACK Callback, PVOID user)
Definition: path.c:118
static const char const char const char * SymbolPath
Definition: image.c:34
smooth NULL
Definition: ftsmooth.c:416

◆ FindExecutableImageEx()

HANDLE WINAPI FindExecutableImageEx ( PCSTR  FileName,
PCSTR  SymbolPath,
PSTR  ImageFilePath,
PFIND_EXE_FILE_CALLBACK  Callback,
PVOID  user 
)

Definition at line 118 of file path.c.

120 {
121  HANDLE h;
122 
123  if (Callback) FIXME("Unsupported callback yet\n");
124  if (!SearchPathA(SymbolPath, FileName, NULL, MAX_PATH, ImageFilePath, NULL))
125  return NULL;
126  h = CreateFileA(ImageFilePath, GENERIC_READ, FILE_SHARE_READ, NULL,
128  return (h == INVALID_HANDLE_VALUE) ? NULL : h;
129 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FILE_SHARE_READ
Definition: compat.h:125
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
static const char const char const char * SymbolPath
Definition: image.c:34
DWORD WINAPI SearchPathA(IN LPCSTR lpPath OPTIONAL, IN LPCSTR lpFileName, IN LPCSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPSTR lpBuffer, OUT LPSTR *lpFilePart OPTIONAL)
Definition: path.c:1122
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
#define MAX_PATH
Definition: compat.h:26
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define GENERIC_READ
Definition: compat.h:124
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
LPFNPSPCALLBACK Callback
Definition: desk.c:111

Referenced by FindExecutableImage().

◆ FindExecutableImageExW()

HANDLE WINAPI FindExecutableImageExW ( PCWSTR  FileName,
PCWSTR  SymbolPath,
PWSTR  ImageFilePath,
PFIND_EXE_FILE_CALLBACKW  Callback,
PVOID  user 
)

Definition at line 101 of file path.c.

103 {
104  HANDLE h;
105 
106  if (Callback) FIXME("Unsupported callback yet\n");
107  if (!SearchPathW(SymbolPath, FileName, NULL, MAX_PATH, ImageFilePath, NULL))
108  return NULL;
109  h = CreateFileW(ImageFilePath, GENERIC_READ, FILE_SHARE_READ, NULL,
111  return (h == INVALID_HANDLE_VALUE) ? NULL : h;
112 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FILE_SHARE_READ
Definition: compat.h:125
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
static const char const char const char * SymbolPath
Definition: image.c:34
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
#define MAX_PATH
Definition: compat.h:26
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define GENERIC_READ
Definition: compat.h:124
DWORD WINAPI SearchPathW(IN LPCWSTR lpPath OPTIONAL, IN LPCWSTR lpFileName, IN LPCWSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart OPTIONAL)
Definition: path.c:1297
#define CreateFileW
Definition: compat.h:400
LPFNPSPCALLBACK Callback
Definition: desk.c:111

◆ is_sep()

static BOOL is_sep ( char  ch)
inlinestatic

Definition at line 33 of file path.c.

33 {return ch == '/' || ch == '\\';}

Referenced by file_name(), and SymMatchFileName().

◆ is_sepW()

static BOOL is_sepW ( WCHAR  ch)
inlinestatic

Definition at line 34 of file path.c.

34 {return ch == '/' || ch == '\\';}

Referenced by file_nameW(), file_pathW(), and SymMatchFileNameW().

◆ MakeSureDirectoryPathExists()

BOOL WINAPI MakeSureDirectoryPathExists ( PCSTR  DirPath)

Definition at line 143 of file path.c.

144 {
145  char path[MAX_PATH];
146  const char *p = DirPath;
147  int n;
148 
149  if (p[0] && p[1] == ':') p += 2;
150  while (*p == '\\') p++; /* skip drive root */
151  while ((p = strchr(p, '\\')) != NULL)
152  {
153  n = p - DirPath + 1;
154  memcpy(path, DirPath, n);
155  path[n] = '\0';
156  if( !CreateDirectoryA(path, NULL) &&
158  return FALSE;
159  p++;
160  }
163 
164  return TRUE;
165 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
GLdouble n
Definition: glext.h:7729
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI CreateDirectoryA(IN LPCSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:37
smooth NULL
Definition: ftsmooth.c:416
#define MAX_PATH
Definition: compat.h:26
#define SetLastError(x)
Definition: compat.h:409
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: services.c:325
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
GLfloat GLfloat p
Definition: glext.h:8902

◆ module_find_cb()

static BOOL CALLBACK module_find_cb ( PCWSTR  buffer,
PVOID  user 
)
static

Definition at line 473 of file path.c.

474 {
475  struct module_find* mf = user;
477  unsigned matched = 0;
478 
479  /* the matching weights:
480  * +1 if a file with same name is found and is a decent file of expected type
481  * +1 if first parameter and second parameter match
482  */
483 
484  /* FIXME: should check that id/two match the file pointed
485  * by buffer
486  */
487  switch (mf->kind)
488  {
489  case DMT_PE:
490  {
491  HANDLE hFile, hMap;
492  void* mapping;
493 
494  timestamp = ~mf->dw1;
495  size = ~mf->dw2;
498  if (hFile == INVALID_HANDLE_VALUE) return FALSE;
499  if ((hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != NULL)
500  {
501  if ((mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL)
502  {
504  if (!nth)
505  {
507  CloseHandle(hMap);
509  return FALSE;
510  }
511  matched++;
515  }
516  CloseHandle(hMap);
517  }
519  if (timestamp != mf->dw1)
520  WARN("Found %s, but wrong timestamp\n", debugstr_w(buffer));
521  if (size != mf->dw2)
522  WARN("Found %s, but wrong size\n", debugstr_w(buffer));
523  if (timestamp == mf->dw1 && size == mf->dw2) matched++;
524  }
525  break;
526  case DMT_ELF:
528  {
529  matched++;
530  if (checksum == mf->dw1) matched++;
531  else
532  WARN("Found %s, but wrong checksums: %08x %08x\n",
533  debugstr_w(buffer), checksum, mf->dw1);
534  }
535  else
536  {
537  WARN("Couldn't read %s\n", debugstr_w(buffer));
538  return FALSE;
539  }
540  break;
541  case DMT_MACHO:
543  {
544  matched++;
545  if (checksum == mf->dw1) matched++;
546  else
547  WARN("Found %s, but wrong checksums: %08x %08x\n",
548  debugstr_w(buffer), checksum, mf->dw1);
549  }
550  else
551  {
552  WARN("Couldn't read %s\n", debugstr_w(buffer));
553  return FALSE;
554  }
555  break;
556  case DMT_PDB:
557  {
558  struct pdb_lookup pdb_lookup;
559  char fn[MAX_PATH];
560 
563 
564  if (mf->guid)
565  {
567  pdb_lookup.timestamp = 0;
568  pdb_lookup.guid = *mf->guid;
569  }
570  else
571  {
573  pdb_lookup.timestamp = mf->dw1;
574  /* pdb_loopkup.guid = */
575  }
576  pdb_lookup.age = mf->dw2;
577 
578  if (!pdb_fetch_file_info(&pdb_lookup, &matched)) return FALSE;
579  }
580  break;
581  case DMT_DBG:
582  {
583  HANDLE hFile, hMap;
584  void* mapping;
585 
586  timestamp = ~mf->dw1;
589  if (hFile == INVALID_HANDLE_VALUE) return FALSE;
590  if ((hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != NULL)
591  {
592  if ((mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL)
593  {
595  hdr = mapping;
596 
597  if (hdr->Signature == IMAGE_SEPARATE_DEBUG_SIGNATURE)
598  {
599  matched++;
600  timestamp = hdr->TimeDateStamp;
601  }
603  }
604  CloseHandle(hMap);
605  }
607  if (timestamp == mf->dw1) matched++;
608  else WARN("Found %s, but wrong timestamp\n", debugstr_w(buffer));
609  }
610  break;
611  default:
612  FIXME("What the heck??\n");
613  return FALSE;
614  }
615  if (matched > mf->matched)
616  {
617  strcpyW(mf->filename, buffer);
618  mf->matched = matched;
619  }
620  /* yes, EnumDirTree/do_search and SymFindFileInPath callbacks use the opposite
621  * convention to stop/continue enumeration. sigh.
622  */
623  return mf->matched == 2;
624 }
#define CloseHandle
Definition: compat.h:398
char hdr[14]
Definition: iptest.cpp:33
#define MapViewOfFile
Definition: compat.h:402
#define WideCharToMultiByte
Definition: compat.h:101
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159
#define CP_ACP
Definition: compat.h:99
#define WARN(fmt,...)
Definition: debug.h:111
BOOL macho_fetch_file_info(HANDLE process, const WCHAR *name, unsigned long load_addr, DWORD_PTR *base, DWORD *size, DWORD *checksum) DECLSPEC_HIDDEN
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
GLuint buffer
Definition: glext.h:5915
enum module_type kind
Definition: path.c:453
#define IMAGE_SEPARATE_DEBUG_SIGNATURE
Definition: compat.h:143
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
BOOL pdb_fetch_file_info(const struct pdb_lookup *pdb_lookup, unsigned *matched) DECLSPEC_HIDDEN
Definition: msc.c:2915
#define FILE_SHARE_READ
Definition: compat.h:125
enum pdb_kind kind
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
unsigned matched
Definition: path.c:465
smooth NULL
Definition: ftsmooth.c:416
#define FILE_MAP_READ
Definition: compat.h:427
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
#define OPEN_EXISTING
Definition: compat.h:426
GLsizeiptr size
Definition: glext.h:5919
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:401
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
WCHAR filename[MAX_PATH]
Definition: path.c:464
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define GENERIC_READ
Definition: compat.h:124
static cab_ULONG checksum(const cab_UBYTE *data, cab_UWORD bytes, cab_ULONG csum)
Definition: fdi.c:353
_In_ HANDLE hFile
Definition: mswsock.h:90
const GUID * guid
Definition: path.c:461
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
#define PAGE_READONLY
Definition: compat.h:127
#define RtlImageNtHeader
Definition: compat.h:457
#define CreateFileW
Definition: compat.h:400
DWORD dw1
Definition: path.c:462
BOOL elf_fetch_file_info(const WCHAR *name, DWORD_PTR *base, DWORD *size, DWORD *checksum) DECLSPEC_HIDDEN
Definition: elf_module.c:1814
#define UnmapViewOfFile
Definition: compat.h:403
const char * filename
void user(int argc, const char *argv[])
Definition: cmds.c:1350
DWORD dw2
Definition: path.c:463

Referenced by path_find_symbol_file().

◆ path_find_symbol_file()

BOOL path_find_symbol_file ( const struct process pcs,
const struct module module,
PCSTR  full_path,
const GUID guid,
DWORD  dw1,
DWORD  dw2,
PSTR  buffer,
BOOL is_unmatched 
)

Definition at line 626 of file path.c.

629 {
630  struct module_find mf;
631  WCHAR full_pathW[MAX_PATH];
632  WCHAR tmp[MAX_PATH];
633  WCHAR* ptr;
634  const WCHAR* filename;
635  WCHAR* searchPath = pcs->search_path;
636 
637  TRACE("(pcs = %p, full_path = %s, guid = %s, dw1 = 0x%08x, dw2 = 0x%08x, buffer = %p)\n",
638  pcs, debugstr_a(full_path), debugstr_guid(guid), dw1, dw2, buffer);
639 
640  mf.guid = guid;
641  mf.dw1 = dw1;
642  mf.dw2 = dw2;
643  mf.matched = 0;
644 
645  MultiByteToWideChar(CP_ACP, 0, full_path, -1, full_pathW, MAX_PATH);
646  filename = file_nameW(full_pathW);
648  *is_unmatched = FALSE;
649 
650  /* first check full path to file */
651  if (module_find_cb(full_pathW, &mf))
652  {
653  WideCharToMultiByte(CP_ACP, 0, full_pathW, -1, buffer, MAX_PATH, NULL, NULL);
654  return TRUE;
655  }
656 
657  /* FIXME: Use Environment-Variables (see MS docs)
658  _NT_SYMBOL_PATH and _NT_ALT_SYMBOL_PATH
659  FIXME: Implement "Standard Path Elements" (Path) ... (see MS docs)
660  do a search for (every?) path-element like this ...
661  <path>
662  <path>\dll
663  <path>\symbols\dll
664  (dll may be exe, or sys depending on the file extension) */
665 
666  /* 2. check module-path */
668  if (do_searchW(filename, tmp, FALSE, module_find_cb, &mf))
669  {
671  return TRUE;
672  }
673 
674  /* 3. check search-path */
675  while (searchPath)
676  {
677  ptr = strchrW(searchPath, ';');
678  if (ptr)
679  {
680  memcpy(tmp, searchPath, (ptr - searchPath) * sizeof(WCHAR));
681  tmp[ptr - searchPath] = '\0';
682  searchPath = ptr + 1;
683  }
684  else
685  {
686  strcpyW(tmp, searchPath);
687  searchPath = NULL;
688  }
689  if (do_searchW(filename, tmp, FALSE, module_find_cb, &mf))
690  {
691  /* return first fully matched file */
693  return TRUE;
694  }
695  }
696  /* if no fully matching file is found, return the best matching file if any */
697  if ((dbghelp_options & SYMOPT_LOAD_ANYTHING) && mf.matched)
698  {
699  WideCharToMultiByte(CP_ACP, 0, mf.filename, -1, buffer, MAX_PATH, NULL, NULL);
700  *is_unmatched = TRUE;
701  return TRUE;
702  }
703  return FALSE;
704 }
WCHAR * search_path
#define TRUE
Definition: types.h:120
#define WideCharToMultiByte
Definition: compat.h:101
WINE_UNICODE_INLINE WCHAR * strchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:248
#define CP_ACP
Definition: compat.h:99
static BOOL CALLBACK module_find_cb(PCWSTR buffer, PVOID user)
Definition: path.c:473
enum module_type module_get_type_by_name(const WCHAR *name) DECLSPEC_HIDDEN
Definition: module.c:465
GLuint buffer
Definition: glext.h:5915
const char * filename
Definition: ioapi.h:135
static void file_pathW(const WCHAR *srcFileNameW, WCHAR *dstFilePathW)
Definition: path.c:52
static const WCHAR * file_nameW(const WCHAR *str)
Definition: path.c:44
WCHAR LoadedImageName[256]
Definition: compat.h:727
const GUID * guid
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
#define debugstr_guid
Definition: kernel32.h:35
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define debugstr_a
Definition: kernel32.h:31
#define MAX_PATH
Definition: compat.h:26
unsigned dbghelp_options
Definition: dbghelp.c:72
static BOOL do_searchW(PCWSTR file, PWSTR buffer, BOOL recurse, PENUMDIRTREE_CALLBACKW cb, PVOID user)
Definition: path.c:222
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define SYMOPT_LOAD_ANYTHING
Definition: compat.h:640
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
#define MultiByteToWideChar
Definition: compat.h:100
DWORD dw1
Definition: path.c:462
IMAGEHLP_MODULEW64 module
DWORD dw2
Definition: path.c:463

Referenced by map_pdb_file(), and pe_load_dbg_file().

◆ SearchTreeForFile()

BOOL WINAPI SearchTreeForFile ( PCSTR  root,
PCSTR  file,
PSTR  buffer 
)

Definition at line 273 of file path.c.

274 {
277  WCHAR bufferW[MAX_PATH];
278  BOOL ret;
279 
282  ret = SearchTreeForFileW(rootW, fileW, bufferW);
283  if (ret)
284  WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL);
285  return ret;
286 }
#define WideCharToMultiByte
Definition: compat.h:101
static const WCHAR rootW[]
Definition: chain.c:69
#define CP_ACP
Definition: compat.h:99
GLuint buffer
Definition: glext.h:5915
DWORD ret
Definition: path.c:47
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
#define MultiByteToWideChar
Definition: compat.h:100
static const WCHAR fileW[]
Definition: url.c:111
BOOL WINAPI SearchTreeForFileW(PCWSTR root, PCWSTR file, PWSTR buffer)
Definition: path.c:262
Definition: fci.c:126

◆ SearchTreeForFileW()

BOOL WINAPI SearchTreeForFileW ( PCWSTR  root,
PCWSTR  file,
PWSTR  buffer 
)

Definition at line 262 of file path.c.

263 {
264  TRACE("(%s, %s, %p)\n",
266  strcpyW(buffer, root);
267  return do_searchW(file, buffer, TRUE, NULL, NULL);
268 }
#define TRUE
Definition: types.h:120
GLuint buffer
Definition: glext.h:5915
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
static BOOL do_searchW(PCWSTR file, PWSTR buffer, BOOL recurse, PENUMDIRTREE_CALLBACKW cb, PVOID user)
Definition: path.c:222
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
Definition: fci.c:126

Referenced by SearchTreeForFile().

◆ sffip_cb()

static BOOL CALLBACK sffip_cb ( PCWSTR  buffer,
PVOID  user 
)
static

Definition at line 352 of file path.c.

353 {
354  struct sffip* s = user;
355 
356  if (!s->cb) return TRUE;
357  /* yes, EnumDirTree/do_search and SymFindFileInPath callbacks use the opposite
358  * convention to stop/continue enumeration. sigh.
359  */
360  return !(s->cb)(buffer, s->user);
361 }
#define TRUE
Definition: types.h:120
GLuint buffer
Definition: glext.h:5915
GLdouble s
Definition: gl.h:2039
Definition: path.c:341
void user(int argc, const char *argv[])
Definition: cmds.c:1350

Referenced by SymFindFileInPathW().

◆ SymFindFileInPath()

BOOL WINAPI SymFindFileInPath ( HANDLE  hProcess,
PCSTR  searchPath,
PCSTR  full_path,
PVOID  id,
DWORD  two,
DWORD  three,
DWORD  flags,
PSTR  buffer,
PFINDFILEINPATHCALLBACK  cb,
PVOID  user 
)

Definition at line 424 of file path.c.

428 {
429  WCHAR searchPathW[MAX_PATH];
430  WCHAR full_pathW[MAX_PATH];
431  WCHAR bufferW[MAX_PATH];
432  struct enum_dir_treeWA edt;
433  BOOL ret;
434 
435  /* a PFINDFILEINPATHCALLBACK and a PENUMDIRTREE_CALLBACK have actually the
436  * same signature & semantics, hence we can reuse the EnumDirTree W->A
437  * conversion helper
438  */
439  edt.cb = cb;
440  edt.user = user;
441  if (searchPath)
442  MultiByteToWideChar(CP_ACP, 0, searchPath, -1, searchPathW, MAX_PATH);
443  MultiByteToWideChar(CP_ACP, 0, full_path, -1, full_pathW, MAX_PATH);
444  if ((ret = SymFindFileInPathW(hProcess, searchPath ? searchPathW : NULL, full_pathW,
445  id, two, three, flags,
446  bufferW, enum_dir_treeWA, &edt)))
447  WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL);
448  return ret;
449 }
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
GLuint buffer
Definition: glext.h:5915
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
DWORD ret
Definition: path.c:47
unsigned int BOOL
Definition: ntddk_ex.h:94
static double two
Definition: jn_yn.c:52
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI SymFindFileInPathW(HANDLE hProcess, PCWSTR searchPath, PCWSTR full_path, PVOID id, DWORD two, DWORD three, DWORD flags, PWSTR buffer, PFINDFILEINPATHCALLBACKW cb, PVOID user)
Definition: path.c:367
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
static DWORD cb
Definition: integrity.c:41
GLbitfield flags
Definition: glext.h:7161
#define MultiByteToWideChar
Definition: compat.h:100
void user(int argc, const char *argv[])
Definition: cmds.c:1350

◆ SymFindFileInPathW()

BOOL WINAPI SymFindFileInPathW ( HANDLE  hProcess,
PCWSTR  searchPath,
PCWSTR  full_path,
PVOID  id,
DWORD  two,
DWORD  three,
DWORD  flags,
PWSTR  buffer,
PFINDFILEINPATHCALLBACKW  cb,
PVOID  user 
)

Definition at line 367 of file path.c.

371 {
372  struct sffip s;
373  struct process* pcs = process_find_by_handle(hProcess);
374  WCHAR tmp[MAX_PATH];
375  WCHAR* ptr;
376  const WCHAR* filename;
377 
378  TRACE("(hProcess = %p, searchPath = %s, full_path = %s, id = %p, two = 0x%08x, three = 0x%08x, flags = 0x%08x, buffer = %p, cb = %p, user = %p)\n",
379  hProcess, debugstr_w(searchPath), debugstr_w(full_path),
380  id, two, three, flags, buffer, cb, user);
381 
382  if (!pcs) return FALSE;
383  if (!searchPath) searchPath = pcs->search_path;
384 
385  s.cb = cb;
386  s.user = user;
387 
388  filename = file_nameW(full_path);
389 
390  /* first check full path to file */
391  if (sffip_cb(full_path, &s))
392  {
393  strcpyW(buffer, full_path);
394  return TRUE;
395  }
396 
397  while (searchPath)
398  {
399  ptr = strchrW(searchPath, ';');
400  if (ptr)
401  {
402  memcpy(tmp, searchPath, (ptr - searchPath) * sizeof(WCHAR));
403  tmp[ptr - searchPath] = 0;
404  searchPath = ptr + 1;
405  }
406  else
407  {
408  strcpyW(tmp, searchPath);
409  searchPath = NULL;
410  }
411  if (do_searchW(filename, tmp, FALSE, sffip_cb, &s))
412  {
413  strcpyW(buffer, tmp);
414  return TRUE;
415  }
416  }
417  return FALSE;
418 }
WCHAR * search_path
#define TRUE
Definition: types.h:120
struct process * process_find_by_handle(HANDLE hProcess)
Definition: dbghelp.c:80
WINE_UNICODE_INLINE WCHAR * strchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:248
GLuint buffer
Definition: glext.h:5915
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
const char * filename
Definition: ioapi.h:135
static const WCHAR * file_nameW(const WCHAR *str)
Definition: path.c:44
static double two
Definition: jn_yn.c:52
#define debugstr_w
Definition: kernel32.h:32
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
static BOOL CALLBACK sffip_cb(PCWSTR buffer, PVOID user)
Definition: path.c:352
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
static DWORD cb
Definition: integrity.c:41
GLbitfield flags
Definition: glext.h:7161
static BOOL do_searchW(PCWSTR file, PWSTR buffer, BOOL recurse, PENUMDIRTREE_CALLBACKW cb, PVOID user)
Definition: path.c:222
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLdouble s
Definition: gl.h:2039
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
Definition: path.c:341
void user(int argc, const char *argv[])
Definition: cmds.c:1350

Referenced by SymFindFileInPath().

◆ SymMatchFileName()

BOOL WINAPI SymMatchFileName ( PCSTR  file,
PCSTR  match,
PSTR filestop,
PSTR matchstop 
)

Definition at line 199 of file path.c.

201 {
202  PCSTR fptr;
203  PCSTR mptr;
204 
205  TRACE("(%s %s %p %p)\n", debugstr_a(file), debugstr_a(match), filestop, matchstop);
206 
207  fptr = file + strlen(file) - 1;
208  mptr = match + strlen(match) - 1;
209 
210  while (fptr >= file && mptr >= match)
211  {
212  if (toupper(*fptr) != toupper(*mptr) && !(is_sep(*fptr) && is_sep(*mptr)))
213  break;
214  fptr--; mptr--;
215  }
216  if (filestop) *filestop = (PSTR)fptr;
217  if (matchstop) *matchstop = (PSTR)mptr;
218 
219  return mptr == match - 1;
220 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
Definition: match.c:28
static BOOL is_sep(char ch)
Definition: path.c:33
int toupper(int c)
Definition: utclib.c:881
#define TRACE(s)
Definition: solgame.cpp:4
#define debugstr_a
Definition: kernel32.h:31
signed char * PSTR
Definition: retypes.h:7
const char * PCSTR
Definition: typedefs.h:51
Definition: fci.c:126

◆ SymMatchFileNameW()

BOOL WINAPI SymMatchFileNameW ( PCWSTR  file,
PCWSTR  match,
PWSTR filestop,
PWSTR matchstop 
)

Definition at line 171 of file path.c.

173 {
174  PCWSTR fptr;
175  PCWSTR mptr;
176 
177  TRACE("(%s %s %p %p)\n",
178  debugstr_w(file), debugstr_w(match), filestop, matchstop);
179 
180  fptr = file + strlenW(file) - 1;
181  mptr = match + strlenW(match) - 1;
182 
183  while (fptr >= file && mptr >= match)
184  {
185  if (toupperW(*fptr) != toupperW(*mptr) && !(is_sepW(*fptr) && is_sepW(*mptr)))
186  break;
187  fptr--; mptr--;
188  }
189  if (filestop) *filestop = (PWSTR)fptr;
190  if (matchstop) *matchstop = (PWSTR)mptr;
191 
192  return mptr == match - 1;
193 }
const uint16_t * PCWSTR
Definition: typedefs.h:55
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
Definition: match.c:28
uint16_t * PWSTR
Definition: typedefs.h:54
#define debugstr_w
Definition: kernel32.h:32
WINE_UNICODE_INLINE WCHAR toupperW(WCHAR ch)
Definition: unicode.h:141
#define TRACE(s)
Definition: solgame.cpp:4
static BOOL is_sepW(WCHAR ch)
Definition: path.c:34
Definition: fci.c:126

Referenced by do_searchW().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( dbghelp  )