The other day I was watching some stuff on a video stream site. It was a knockoff of the all popular youtube, but this one took extra steps to make sure you could not download their videos.
The easiest method for me to download videos from sites like this is to just check the temp internet folder and copy the file from there. This site was different. The file was in use by firefox the entire time (IE as well) and could not be copied or opened or written to without getting the classic ‘access denied’ message. Windows as we all know wont let you delete files that are in use including DLL’s and temp files (as we’ve all seen with malware). I believe it used a method similar to this:
http://msdn.microsoft.com/en-us/library/aa365203%28v=vs.85%29.aspx
LockFileEx Function
BOOL WINAPI LockFileEx( __in HANDLE hFile, __in DWORD dwFlags, __reserved DWORD dwReserved, __in DWORD nNumberOfBytesToLockLow, __in DWORD nNumberOfBytesToLockHigh, __inout LPOVERLAPPED lpOverlapped );
CreateHardLink
BOOL WINAPI CreateHardLink( __in LPCTSTR lpFileName, __in LPCTSTR lpExistingFileName, __reserved LPSECURITY_ATTRIBUTES lpSecurityAttributes );
Seems self explanatory. Funny enough the security attributes param is supposed to be null since they never implemented it (yay).
So what do we do? C to the rescue:
#include <windows.h> #include <stdio.h> int main(int argc, char **argv[]) { if(argc < 2) { printf("usage is %s path + file to locked file\r\n",argv[0]); return 0; } else { char *lockedfilename = argv[1]; char *newfilename = argv[2]; if(CreateHardLink(newfilename,lockedfilename,NULL)) { printf("Hard Link created between %s and %s\r\n",lockedfilename,newfilename); system("pause"); return 1; } else { printf("something went wrong, you prolly specified a bad file or something\r\n"); return 0; } } } }
If there’s a syntax error in this code, I’m sorry. I wrote the C off the top of my head. My little program allows you to save locked files to a new location. Further modifications to the code would be to call DeleteFile() or something like that after the link is created. Oh well.
Woh I your blog posts, bookmarked ! .
Good write-up, I’m regular visitor of one’s blog, maintain up the excellent operate, and It’s going to be a regular visitor for a lengthy time.