From 39be9e1ed51fb04eae10fd701cb99d5590da3102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Lindstr=C3=B6m?= Date: Sun, 4 Oct 2020 22:30:28 +0200 Subject: [PATCH 1/2] Fix ilasm path parsing on *nix. ILAsm did not properly parse paths on *nix systems, which notably broke the inclusion of managed resources in an assembly. This commit enables ILAsm to support both types of directory separators by relying on the DIRECTORY_SEPARATOR_CHAR_A macro where relevant. --- src/ilasm/asmman.cpp | 2 +- src/ilasm/grammar_after.cpp | 2 +- src/ilasm/main.cpp | 2 +- src/ilasm/writer.cpp | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ilasm/asmman.cpp b/src/ilasm/asmman.cpp index 47dc6eb5c573..6ba0db7c845b 100644 --- a/src/ilasm/asmman.cpp +++ b/src/ilasm/asmman.cpp @@ -965,7 +965,7 @@ HRESULT AsmMan::EmitManifest() for(j=0; (hFile == INVALID_HANDLE_VALUE)&&(pwzInputFiles[j] != NULL); j++) { wcscpy_s(wzFileName,2048,pwzInputFiles[j]); - pwz = wcsrchr(wzFileName,'\\'); + pwz = wcsrchr(wzFileName,DIRECTORY_SEPARATOR_CHAR_A); if(pwz == NULL) pwz = wcsrchr(wzFileName,':'); if(pwz == NULL) pwz = &wzFileName[0]; else pwz++; diff --git a/src/ilasm/grammar_after.cpp b/src/ilasm/grammar_after.cpp index 7764c8d63ef7..41c9f044fb62 100644 --- a/src/ilasm/grammar_after.cpp +++ b/src/ilasm/grammar_after.cpp @@ -845,7 +845,7 @@ int yylex() if(wzFile != NULL) { if((parser->wzIncludePath != NULL) - &&(wcschr(wzFile,'\\')==NULL)&&(wcschr(wzFile,':')==NULL)) + &&(wcschr(wzFile,DIRECTORY_SEPARATOR_CHAR_A)==NULL)&&(wcschr(wzFile,':')==NULL)) { PathString wzFullName; diff --git a/src/ilasm/main.cpp b/src/ilasm/main.cpp index 447d02107ed2..80158cd4ec96 100644 --- a/src/ilasm/main.cpp +++ b/src/ilasm/main.cpp @@ -67,7 +67,7 @@ void MakeProperSourceFileName(__in __nullterminated WCHAR* wzOrigName, { j--; if(wzProperName[j] == '.') break; - if((wzProperName[j] == '\\')||(j == 0)) + if((wzProperName[j] == DIRECTORY_SEPARATOR_CHAR_A)||(j == 0)) { wcscat_s(wzProperName,MAX_FILENAME_LENGTH,W(".il")); break; diff --git a/src/ilasm/writer.cpp b/src/ilasm/writer.cpp index 0958f027218a..258ce0a647d1 100644 --- a/src/ilasm/writer.cpp +++ b/src/ilasm/writer.cpp @@ -332,7 +332,7 @@ HRESULT Assembler::CreateExportDirectory() char* szOutputFileName = new char[Ldllname]; memset(szOutputFileName,0,wcslen(m_wzOutputFileName)*3+3); WszWideCharToMultiByte(CP_ACP,0,m_wzOutputFileName,-1,szOutputFileName,Ldllname,NULL,NULL); - pszDllName = strrchr(szOutputFileName,'\\'); + pszDllName = strrchr(szOutputFileName,DIRECTORY_SEPARATOR_CHAR_A); if(pszDllName == NULL) pszDllName = strrchr(szOutputFileName,':'); if(pszDllName == NULL) pszDllName = szOutputFileName; Ldllname = (unsigned)strlen(pszDllName)+1; @@ -1100,7 +1100,7 @@ HRESULT Assembler::CreatePEFile(__in __nullterminated WCHAR *pwzOutputFilename) else { WCHAR* pwc; - if ((pwc = wcsrchr(m_wzOutputFileName, '\\')) != NULL) pwc++; + if ((pwc = wcsrchr(m_wzOutputFileName, DIRECTORY_SEPARATOR_CHAR_A)) != NULL) pwc++; else if ((pwc = wcsrchr(m_wzOutputFileName, ':')) != NULL) pwc++; else pwc = m_wzOutputFileName; From 5beca66fe77d6cc5cdb1287379acc8b2194fbd79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Lindstr=C3=B6m?= Date: Sun, 4 Oct 2020 22:59:20 +0200 Subject: [PATCH 2/2] Only consider colon as a special path character on Windows. We rely on the FEATURE_PAL macro to determine whether we are targeting a *nix platform. --- src/ilasm/asmman.cpp | 2 ++ src/ilasm/grammar_after.cpp | 6 +++++- src/ilasm/writer.cpp | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ilasm/asmman.cpp b/src/ilasm/asmman.cpp index 6ba0db7c845b..87456e5e3fba 100644 --- a/src/ilasm/asmman.cpp +++ b/src/ilasm/asmman.cpp @@ -966,7 +966,9 @@ HRESULT AsmMan::EmitManifest() { wcscpy_s(wzFileName,2048,pwzInputFiles[j]); pwz = wcsrchr(wzFileName,DIRECTORY_SEPARATOR_CHAR_A); +#ifndef FEATURE_PAL if(pwz == NULL) pwz = wcsrchr(wzFileName,':'); +#endif if(pwz == NULL) pwz = &wzFileName[0]; else pwz++; wcscpy_s(pwz,2048-(pwz-wzFileName),wzUniBuf); diff --git a/src/ilasm/grammar_after.cpp b/src/ilasm/grammar_after.cpp index 41c9f044fb62..14181208004d 100644 --- a/src/ilasm/grammar_after.cpp +++ b/src/ilasm/grammar_after.cpp @@ -845,7 +845,11 @@ int yylex() if(wzFile != NULL) { if((parser->wzIncludePath != NULL) - &&(wcschr(wzFile,DIRECTORY_SEPARATOR_CHAR_A)==NULL)&&(wcschr(wzFile,':')==NULL)) + &&(wcschr(wzFile,DIRECTORY_SEPARATOR_CHAR_A)==NULL) +#ifndef FEATURE_PAL + &&(wcschr(wzFile,':')==NULL) +#endif + ) { PathString wzFullName; diff --git a/src/ilasm/writer.cpp b/src/ilasm/writer.cpp index 258ce0a647d1..c9787f783c4d 100644 --- a/src/ilasm/writer.cpp +++ b/src/ilasm/writer.cpp @@ -333,7 +333,9 @@ HRESULT Assembler::CreateExportDirectory() memset(szOutputFileName,0,wcslen(m_wzOutputFileName)*3+3); WszWideCharToMultiByte(CP_ACP,0,m_wzOutputFileName,-1,szOutputFileName,Ldllname,NULL,NULL); pszDllName = strrchr(szOutputFileName,DIRECTORY_SEPARATOR_CHAR_A); +#ifndef FEATURE_PAL if(pszDllName == NULL) pszDllName = strrchr(szOutputFileName,':'); +#endif if(pszDllName == NULL) pszDllName = szOutputFileName; Ldllname = (unsigned)strlen(pszDllName)+1; @@ -1101,7 +1103,9 @@ HRESULT Assembler::CreatePEFile(__in __nullterminated WCHAR *pwzOutputFilename) { WCHAR* pwc; if ((pwc = wcsrchr(m_wzOutputFileName, DIRECTORY_SEPARATOR_CHAR_A)) != NULL) pwc++; +#ifndef FEATURE_PAL else if ((pwc = wcsrchr(m_wzOutputFileName, ':')) != NULL) pwc++; +#endif else pwc = m_wzOutputFileName; wcsncpy_s(wzScopeName, MAX_SCOPE_LENGTH, pwc, _TRUNCATE);