/*VLC's libqt4_plugin.dll patcherThis program can patch VLC's libqt4_plugin.dll to solve the volume control problem.Suggested usage:cd path_to_VLC's_direcotry\pluginsmv libqt4_plugin.dll libqt4_plugin.dll.backuppath_to_this_program.exe libtq4_plugin.dll.backup libqt4_plugin.dllNote: strings in this program don't use '\0' as terminate character.Original python code (http://forum.videolan.org/viewtopic.php?f=14&t=79258&sid=d587667b82edc613b75b6d9e24dbbb13&start=20#p272045):PATH_SRC = r'c:\program files\videolan\vlc\plugins\libqt4_plugin.dll'PATH_DST = r'libqt4_plugin.dll'src = open(PATH_SRC, 'rb')data = src.read()src.close()s = 'unknown APPCOMMAND = %d\x00'pos = data.index(s) + len(s)if pos % 4 > 0: pos += 4 - pos % 4t = data[pos + 32 : pos + 36]data = data[:pos] + t * 3 + data[pos + 12:]dst = open(PATH_DST, 'wb')dst.write(data)dst.close()*/#include <fcntl.h>#include <io.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>/*function to get a substring's position in a string, where strings have not terminate at \0returns the substring's position in the string, or -1 if the substring not found*/int mystrstr(char *a,int na,char *b,int nb){ int j; for(int i=0;i<na;i++) { for(j=0;j<nb;j++) { if(a[i+j]!=b[j]) { break; } } if(j==nb) { return i; } } return -1;}int main(int argc,char *argv[]){ if(argc!=3) //check arguments { printf("Parameters required: source destination\n"); return 255; } int file=open(argv[1],O_RDONLY|O_BINARY); //open original file for reading if(file==-1) { printf("Cannot open file for reading: \"%s\"\n",argv[1]); return 1; } struct stat filestat; fstat(file,&filestat); //get filestats including filesize into filestat struct char *content=(char *)malloc(filestat.st_size); //allocate memory to the file's contents if(content==NULL) { printf("Cannot allocate %d bytes of memory.\n",filestat.st_size); return 1; } read(file,content,filestat.st_size); //read the whole file to content close(file); //close the file int pos=mystrstr(content,filestat.st_size,"unknown APPCOMMAND = %d\x00",24)+24; //get "magic string"'s position, 24 is the size of "unknown APPCOMMAND = %d\x00" if(pos==-1) { printf("The \"magic string\" not found.\n"); return 1; } if(pos%4>0) //pos have to be divisible by 4 { pos+=4-(pos%4); } char *temp=(char *)malloc(4); //allocate 4 bytes for temp string if(temp==NULL) { printf("Cannot allocate 4 bytes of memory.\n"); return 1; } memcpy(temp,content+pos+32,4); //get string into temp file=open(argv[2],O_WRONLY|O_BINARY|O_CREAT,S_IWRITE); //open new file for writing if(file==-1) { printf("Cannot open file for writing: \"%s\"\n",argv[2]); return 1; } write(file,content,pos); //writing out the first part for(int i=0;i<4;i++) //writing out temp for 4 times { write(file,temp,4); } write(file,content+pos+16,filestat.st_size-pos-16); //writing out the last part close(file); //close file free(temp); //freeing variables free(content); printf("Everything OK, file \"%s\" created from \"%s\" successfully.\n",argv[2],argv[1]); return 0;}