--- a\np2src\src\Helpers.c Wed Apr 09 18:00:00 2008 +++ b\np2src\src\Helpers.c Sat Jul 05 12:12:01 2008 @@ -939,16 +939,43 @@ BOOL ExtractFirstArgument(LPCSTR lpArgs, if (lpArg2) TrimString(lpArg2); return TRUE; } +//============================================================================= +// +// IsNotepadPath() +// +BOOL IsNotepadPath(LPSTR lpPath) +{ + LPSTR lpa, lpb; + + // special case: invoked without the .exe, e.g.: "notepad file.txt" + // cases like "\path\notepad file.txt" will not be considered because, without + // the .exe, there is a higher risk of false positives, so it's best to limit + // the range of possible cases; besides, it is rare for someone to specify the + // path without the extension + if (lstrcmpi(lpPath, "notepad") == 0) + return(TRUE); + + // general case: invoked normally or from file association + // the .exe extension is present, and usually, the path as well + // also, both slashes are technically legal as path delimiters in Windows + lpa = strrchr(lpPath, '\\'); + lpb = strrchr(lpPath, '/'); + if (lpb > lpa) lpa = lpb; + if (lpa >= lpPath) lpPath = lpa + 1; + return(lstrcmpi(lpPath, "notepad.exe") == 0); +} + + //============================================================================= // // PrepareFilterStr() // void PrepareFilterStr(LPSTR lpFilter) { LPSTR psz = StrEnd(lpFilter); while (psz != lpFilter) --- a\np2src\src\Helpers.h Wed Apr 09 18:00:00 2008 +++ b\np2src\src\Helpers.h Sat Jul 05 12:12:26 2008 @@ -106,16 +106,17 @@ BOOL PathIsLnkFile(LPCSTR); BOOL PathGetLnkPath(LPCSTR,LPSTR,int); BOOL PathIsLnkToDirectory(LPCSTR,LPSTR,int); BOOL PathCreateDeskLnk(LPCSTR); BOOL PathCreateFavLnk(LPCSTR,LPCSTR,LPCSTR); BOOL TrimString(LPSTR); BOOL ExtractFirstArgument(LPCSTR, LPSTR, LPSTR); +BOOL IsNotepadPath(LPSTR); void PrepareFilterStr(LPSTR); void StrTab2Space(LPSTR); void ExpandEnvironmentStringsEx(LPSTR,DWORD); void PathCanonicalizeEx(LPSTR); --- a\np2src\src\Notepad2.c Wed Apr 09 18:00:00 2008 +++ b\np2src\src\Notepad2.c Sat Jul 05 12:52:23 2008 @@ -4314,31 +4355,34 @@ void SaveSettings(BOOL bSaveSettingsNow) // ParseCommandLine() // // void ParseCommandLine(LPSTR lpCmdLine) { LPSTR lp1,lp2,lp3; BOOL bContinue = TRUE; + BOOL bFirstArg = TRUE; if (lstrlen(lpCmdLine) == 0) return; // Good old console can also send args separated by Tabs StrTab2Space(lpCmdLine); lp1 = LocalAlloc(LPTR,lstrlen(lpCmdLine) + 1); lp2 = LocalAlloc(LPTR,lstrlen(lpCmdLine) + 1); lp3 = LocalAlloc(LPTR,lstrlen(lpCmdLine) + 1); lstrcpy(lp3,lpCmdLine); while (bContinue && ExtractFirstArgument(lp3,lp1,lp2)) { + // discard notepad.exe from the image hijack + if (bFirstArg && IsNotepadPath(lp1)) { } else // options if ((*lp1 == '/') || (*lp1 == '-')) { switch (*CharUpper(lp1+1)) { @@ -4453,16 +4497,17 @@ void ParseCommandLine(LPSTR lpCmdLine) bContinue = FALSE; } // Continue with next argument if (bContinue) lstrcpy(lp3,lp2); + bFirstArg = FALSE; } LocalFree(lp1); LocalFree(lp2); LocalFree(lp3); }