Passing memory content as paramater?

Hi

What I want to do is read the content of a binary file to memory... edit the content.. and pass it to an external program as a parameter.

Basically I have an app that should read a file, but I want to modify the content of this file first and then pass it directly to the app without writing it to a file again.

Modifying the content will include encrypting/decrypting.

So I read my file to memory, modified it.. now how do I export it directly?
I need something like std:system("myexternalapp") << memory content

any ideas?

thank you,
Matthew

Unless the app can take its input from stdin, it won't be easy (or possible maybe).
Typically you'd do this by passing the data as a command line parameter:

1
2
3
4
WhateverFunction( "theotherprogram passed_information" );

// system would work for 'WhateverFunction' but you might be better off with ShellExecute
//   or something similar. 


'passed_information' would wind up in the argv[] of the other program.

If the program doesn't use argv, then you're used and the only option would be to modify whatever file that program uses.
If you own the code of both programs, you could set up interprocess communication between the executables. I know the Windows ones: pipes, shared memory, WM_COPYDATA, the clipboard, and external file, and a few others I'm probably forgetting.

sockets or rpc (if two applications are on different system).
Actually I'm thinking of going a completely different way now...

The point of my program is mainly encryption.
Originally I was thinking of modifying the external app but since it's going to constantly get updated and changed by someone else I need to make my solution as dynamic/modular as possible.

So I don't want to modify the external app and as it only accepts input from a file I'm thinking of creating another file, which will act as a sort of encrypted data storage unit. And save the external file, which I want to encrypt, into my file, decrypting it inside the program and passing it's location to the external app just like it was normally located on the disk...

or something along these lines.. but I have no idea how to actually pull this off...

any ideas :)?
You haven't said what your trying to do, you've only described how you want to do it. So it's tricky trying to help out with ideas.
yeah, correct kbw.
I know, and I'm sorry.

I don't fully understand what it is exactly that I'm looking for at this point. I have no experience here.

I am looking into Embedded File System (EFS), or something similar maybe.. that would allow me to encrypt a file and access it on-the-fly somehow from within my program so I can give only the external app access to the data.

I suppose this isn't a topic for these forums anymore. However, if anyone has any pointers as to which projects/libs I should be looking at... I would be extremely grateful!

This should be straight I guess.. Just use any encryption algo, read the file in buffer, encrypt the file with the algo and use the encrypted data.

An algo for encryption can be found here:
http://www.schneier.com/blowfish.html
http://en.wikipedia.org/wiki/Blowfish_%28cipher%29


You want to see how to use it, I have posted a full code here:
http://www.codeproject.com/KB/install/Qt_SelfExtractor.aspx

thank you for all the info!

I managed to pass the file to the external app using stdin(modifying the external app)
But I do have one more question now. Would it be possible to load both - the external app and the file to memory - modify the data in memory as it needs to be and then execute the app from memory(so load the app and the file and execute the app from memory)?

this would probably be platform specific right? Any hints :)?


I somehow didn't understand.. what do you mean by loading the application and file into the memory.
closed account (zb0S216C)
tenn wrote:
Would it be possible to load both - the external app and the file to memory

Both are loaded into memory anyway. Everything that the CPU processes, is stored into memory.
Topic archived. No new replies allowed.