views:

638

answers:

3

I had a previous post on how to make memorystream play in wmp activex and got a reply with a link to boxedapp sdk. It's not a freeware so I studied the process and I figured out that it is using a virtual file for the stream to be saved and that its filename is used as the URL. So, my question is how to create a virtual file that returns a handle which should be then be accessed by a THandleStream. I am using Delphi 7. Thanks.

Desired Process on how to make memorystream play in wmp activex or any player:

  1. Create a virtual file and return a HANDLE; (This is my question)
  2. This HANDLE is then accessed by a THandleStream;
  3. THandleStream copies the content of the MemoryStream to be played;
  4. The player(wmp activex in my case) accesses the filename.
  5. The player plays it.
A: 

Boxedapp intercepts all IO calls and in if the file was create using their API (I.E. BoxedAppSDK_CreateVirtualFile) they will handle the call them self. Its not an easy task, you can take a look at detours which is an intercepation framework, but as for intercepting all the IO calls good luck with that.

Why do you need that? why can't you save the memory stream into the temp folder and play the file from there? do you need to clean the file upon completion?

Shay Erlichmen
But then again, BoxedApp is not free(no budget as in $0). Do you some free stuffs similar? The reason I don't want to save this to a temp folder is because I don't want to expose the content of the file. Let's just say my program is very strict. I can't really tell you its nature.
junmats
How do you know that boxed app is not saving the file into the temp folder also (or other location)? I don't know how they impl their virtual file. If you don't want the content to be expose the only way of doing so is to use DRM.
Shay Erlichmen
+1  A: 

I believe you use the pipe function (from msvcrt.dll):

function _pipe(phandles : pointer; psize : uint; textmode : integer) : integer; cdecl; external 'msvcrt.dll' name '_pipe';

some pseudocode:

var
 _handles : array[0..1] of THandle;
begin
  if _pipe(@_handles, size, 0) = -1 then
   Exit;

  FReadHandle := _handles[0];
  FWriteHandle  := _handles[1];

  _write(FVirtualWriteHandle, Buffer, size);

  close(FWriteHandle);
  close(FReadHandle);

end;
jcinacio
Better to use CreatePipe; the _pipe function is a C function, but he's not using C. Use the API instead. Too bad it won't really solve his problem, though, because accomplishing step 1 doesn't mean step 4 will work, and that's his real problem.
Rob Kennedy
+2  A: 

If you're trying to create content that's hidden from the user, as implied in one of your comments, you may as well forget all about it right now. It's impossible. Never has worked and never will. You can make it more difficult, but at the end of the day if the computer is able to read it, a clever enough hacker can read your code and duplicate your tricks. Even strongly-encrypted DRM schemes only tend to last about a month at best before being broken, and you're not even trying to go that far.

Mason Wheeler
no.. hackers don't have anything to do with this. The users who will be using this program are students. That's why I don't want the contents to be exposed so that they can't cheat.
junmats