[MPlayer-dev-eng] [PATCH] loader/win32.c cleanup of CreateFile should fix vp6vfw 2nd pass encoding on linux
Gianluigi Tiesi
mplayer at netfarm.it
Sun Sep 16 02:25:37 CEST 2007
By looking at this patch:
http://d.hatena.ne.jp/nazodane/20070307/1173271025
I've decided to rewrite CreateFile from scratch.
S_IRWXU seams to be needed anyway it's not really a problem,
I'm not 100% sure about flags conversion.
also think about security concerns,
it should be safe since /\: are converted to _
the attached patch should also fix vp6 2nd pass encoding
Please test
Regards
--
Gianluigi Tiesi <sherpya at netfarm.it>
EDP Project Leader
Netfarm S.r.l. - http://www.netfarm.it/
Free Software: http://oss.netfarm.it/
-------------- next part --------------
Index: loader/win32.c
===================================================================
--- loader/win32.c (revision 24540)
+++ loader/win32.c (working copy)
@@ -64,6 +64,7 @@
#include <dirent.h>
#include <sys/time.h>
#include <sys/timeb.h>
+#include <sys/stat.h>
#ifdef HAVE_KSTAT
#include <kstat.h>
#endif
@@ -3486,102 +3487,43 @@
// They try to open APmpeg4v1.apl with it.
// DLL will close opened file with CloseHandle().
//
-static HANDLE WINAPI expCreateFileA(LPCSTR cs1,DWORD i1,DWORD i2,
- LPSECURITY_ATTRIBUTES p1, DWORD i3,DWORD i4,HANDLE i5)
+// refer to http://msdn2.microsoft.com/en-us/library/aa363858.aspx
+// for CreateFile flags
+static HANDLE WINAPI expCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess,
+ DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
+ DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
+ HANDLE hTemplateFile)
{
- dbgprintf("CreateFileA(0x%x='%s', %d, %d, 0x%x, %d, %d, 0x%x)\n", cs1, cs1, i1,
- i2, p1, i3, i4, i5);
- if((!cs1) || (strlen(cs1)<2))return -1;
+ char dest[MAX_PATH + 1] = "/tmp/";
+ char *p = dest + 4;
+ int flags = 0;
-#ifdef QTX
- if(strstr(cs1, "QuickTime.qts"))
- {
- int result;
- char* tmp=malloc(strlen(def_path)+50);
- strcpy(tmp, def_path);
- strcat(tmp, "/");
- strcat(tmp, "QuickTime.qts");
- result=open(tmp, O_RDONLY);
- free(tmp);
- return result;
- }
- if(strstr(cs1, ".qtx"))
- {
- int result;
- char* tmp=malloc(strlen(def_path)+250);
- char* x=strrchr(cs1,'\\');
- sprintf(tmp,"%s/%s",def_path,x?(x+1):cs1);
-// printf("### Open: %s -> %s\n",cs1,tmp);
- result=open(tmp, O_RDONLY);
- free(tmp);
- return result;
- }
-#endif
+ if ((!lpFileName) || (strlen(lpFileName) < 2)) return -1;
- if(strncmp(cs1, "AP", 2) == 0)
- {
- int result;
- char* tmp=malloc(strlen(def_path)+50);
- strcpy(tmp, def_path);
- strcat(tmp, "/");
- strcat(tmp, "APmpg4v1.apl");
- result=open(tmp, O_RDONLY);
- free(tmp);
- return result;
- }
- if (strstr(cs1, "vp3"))
- {
- int r;
- int flg = 0;
- char* tmp=malloc(20 + strlen(cs1));
- strcpy(tmp, "/tmp/");
- strcat(tmp, cs1);
- r = 4;
- while (tmp[r])
- {
- if (tmp[r] == ':' || tmp[r] == '\\')
- tmp[r] = '_';
- r++;
- }
- if (GENERIC_READ & i1)
- flg |= O_RDONLY;
- else if (GENERIC_WRITE & i1)
- {
- flg |= O_WRONLY;
- printf("Warning: openning filename %s %d (flags; 0x%x) for write\n", tmp, r, flg);
- }
- r=open(tmp, flg);
- free(tmp);
- return r;
- }
+ dest[MAX_PATH] = 0;
+ strncat(dest, lpFileName, MAX_PATH);
+ while (*p)
+ if ((*p == '/') || (*p == '\\') || (*p == ':'))
+ *p = '_';
- // Needed by wnvplay1.dll
- if (strstr(cs1, "WINNOV.bmp"))
- {
- int r;
- r=open("/dev/null", 0);
- return r;
- }
+ /* Desidered Access */
+ if ((dwDesiredAccess & GENERIC_READ) &&
+ (dwDesiredAccess & GENERIC_WRITE))
+ flags |= O_RDWR;
-#if 0
- /* we need this for some virtualdub filters */
- {
- int r;
- int flg = 0;
- if (GENERIC_READ & i1)
- flg |= O_RDONLY;
- else if (GENERIC_WRITE & i1)
- {
- flg |= O_WRONLY;
- printf("Warning: openning filename %s %d (flags; 0x%x) for write\n", cs1, r, flg);
- }
- r=open(cs1, flg);
- return r;
- }
-#endif
+ if (dwDesiredAccess & GENERIC_READ) flags |= O_RDONLY;
+ if (dwDesiredAccess & GENERIC_WRITE) flags |= O_WRONLY;
- return atoi(cs1+2);
+ /* Creation Disposition */
+ if (dwCreationDisposition & CREATE_ALWAYS) flags |= O_CREAT | O_TRUNC;
+ if (dwCreationDisposition & CREATE_NEW) flags |= O_CREAT | O_EXCL;
+ if (dwCreationDisposition & OPEN_ALWAYS) flags |= O_CREAT;
+ if (dwCreationDisposition & OPEN_EXISTING) flags |= O_CREAT;
+ if (dwCreationDisposition & TRUNCATE_EXISTING) flags |= O_TRUNC;
+
+ return open(dest, flags, S_IRWXU);
}
+
static UINT WINAPI expGetSystemDirectoryA(
char* lpBuffer, // address of buffer for system directory
UINT uSize // size of directory buffer
More information about the MPlayer-dev-eng
mailing list