I'm writing a CGI application in C++ using cgicc, running on an embedded device. Now I came to the point where it is required to upload a large file to the device (the firmware package for updating). Now I realize 2 problems:
1.) The web server (currently lighttpd) stores the file in an temporary file before starting the CGI application.
2.) cgicc tries to load the complete data into an allocated memory before continuing.
Point 1.) is another problem, more importand for now is point 2.). Is there a way to tell cgicc to read the file piece by piece instead at once? Otherwise I run into OOM trouble.
Any other suggestion which can help are welcome!
Thanx, Andi
Related
First I want to ask whether is it possible for an application to update itself at runtime on same address space?
If yes, what's the best way to implement the logic?
Usecase : My application is running on a board which is connected to network. At runtime if it detects a new version of same application, then how to update the application on same memory address, where previous one is stored.
As per my understanding first we should take the backup of update and at the time of boot load, main application should be updated with backup and then launch the application normally. Am I right?
Usually you can replace the file containing the executable while it's running without problems.
After you update the file, you can start the application like always, and close your running instance.
If you however want to do it at runtime (i.e. without forking or starting new process), I don't think it's possible without extremely weird hacks:
if you plan to "rebase" your program memory with new executable's code, you'd need to figure the stack, memory and instruction pointers for each thread. You'd need to become a disassembler.
if you plan to call a stub in your program after loading it into auxilliary memory segment, that's fine, but you need to figure where the target function is, and what happens if it's gone in your next update. Plus it's totally platform-specific.
if you plan to standardize the above approach by using shared libraries that are dynamically loaded and unloaded, I see no problem - it's very similar to the approach where you restart entire process.
I'd go with replacing just the executable, or the third option if I have a very good reason for this. The last option is nice since it lets you update your application's components separately (but at the same time this might cause you maintenance headaches later on.)
What you need is something akin to a bootloader. In this case: you will have two programs on the device, hereafter referred to as the Loader and the App.
On your initial install of the system: write the App to the beginning of memory and the Loader somewhere further down to give space if the App grows in size in the future. (Keep note of the beginning memory address of the Loader)
The App will run normally as if it was the only program, periodically checking for updates to itself. If it finds an update on the network, use a GOTO to go to the first memory location of your Loader, which will then begin running and can write over the original App with the new App found on the network. At the end of your Loader, GOTO back to the (new) App.
See this Stack Overflow question for ideas on how to GOTO to specific memory addresses. Goto a specific Address in C
i am trying to open and edit a file that contains some type of custom protection.
file game :gameguard.des
its from lineage2/interlude/system file.
this is not the original version though, it has been modified to block some packets sent to the server.
i've used VS2010 to open it and it shows me the memory and the contents in hex, like viewing computer memory.
here is the file attached. http://www20.zippyshare.com/v/88173717/file.html
so my question is, how can i open it viewing the code in a higher level and edit it? what tools i need to use to do that?
regards, George
This is a Win32 program. You can try to disassemble it, but it's itself a binary file and what the VS2010 is showing you is correct, because it's showing it most probably in HEX format to you.
You need to first figure out which compiler was used to compile this application, then maybe it helps you to refactor the executable.
The fact that you can not directly run this application might be just the extension, maybe if you change the extension to .exe, it runs under windows. I don't recommend it though.
I've data in MP4 format which needs to be copied to DVD on Linux platform. Now I am creating MP4 file on hard disk and then burning that file to DVD using growisofs command.
It would be more efficient if I didn't have to write the MP4 data to hard disk before they are burned to DVD. Please let me know if there is a way to write in memory data to DVD using C program.
By reimplementing the tasks growisofs performs. DVDs are different to randomly accessible storage. First the data to be burnt onto the blank medium must be prepared into in a certain format, namely ISO9660, this includes a certain error correction scheme. The result of this is a complete Track. In the ISO9660 scheme it's not possible to record single files, only whole file systems. Once you got the FS you must implement the whole program for controlling the recording process.
This is what growisofs does. Now you could take the source of growisofs and replace the code it uses to read the files with code to read from some shared memory. But then you must make sure, that your program can deliver the data continously, without falling into pauses. Once started, the recording process should not be interrupted.
Anyway: If you're under Linux your program could provide the filesystem structure through FUSE.
In C following this article (http://blogs.msdn.com/oldnewthing/archive/2006/12/21/1340571.aspx), we have succesfully been able to grab the file version information out of windows files however there are some files that seem to have a different mechanism for storing the version information that is not addressed in the article and was wondering if anyone had any ideas here.
One example of a file would be system32/oledlg.dll. Going through the file byte by byte we come to a chunk where the version information SHOULD be stored:
F^#i^#l^#e^#V^#e^#r^#s^#i^#o^#n^#^#^#^#^1.0 (x^#p^#s^#p^#.^#0^#8^#0^#4^#1^#3
^#-^#2^#1^#0^#8^#)^#^#^#^#^#.^#^G^#^A^#I^#n^#t^#e^#r^#n^#a^#l^#N^#a^#m^#e
That we can see is 1.0. However, when you look at the file information in windows the version is actually 5.1.2600.5512. The method in the article works for most files but there are a few instances I have come across where I am running into the above problem. Anyone have any experience with this? I only have access to standard C.
Based on the follow up article posted in the comment, does that mean there is no way to grab the actual file version from a file with a corrupted file info block?
I should also add that I am grabbing the files from a windows box, and then examining them on linux with a C program to grab the file info.
IT turns out the wrong peice of info for that file was being used to get the version, didn't actually need the File Version block but the "VS_VERSION_INFO" block.
I have a program written in C that allows the user to scroll through a display of about a zillion small files. Each file needs to undergo a certain amount of processing (read only) before it's displayed to the user. I've implemented a buffer that preprocesses the files in a certain radius around the user's position, so if they're working linearly through them, there's not much delay. For various reasons, I can only actually run my processing algorithm on one file at a time (though I can have multiple files open, and I can read from them) so my buffer loads sequentially.
My processing algorithms are as optimized as they're going to get, but I'm running into I/O problems. At first, my loading process is slow, but when the files have been accessed a few times, it speeds up by about 5x. Therefore I strongly suspect that what's slowing me down is waiting for the Windows page cache to pull my files into memory. I know very little about that sort of thing. If I could ensure my files were in the cache before my processing algorithm needed them, I'd be in business.
My question is: is there a way to persuade/cajole/trick/intimidate Windows into loading my files into the page cache before I actually get around to reading/processing them?
There's only one way to get a file into the file system cache: reading it. That's a chicken-and-egg problem. You can get the egg first by using a helper thread that reads files. It would have to have some kind of smarts about what file is likely to be next. And not read too much.
On a POSIX system, you'd use posix_fadvise:
POSIX_FADV_WILLNEED
Specifies that the application expects to access the specified data in the near future.
However, that doesn't seem to exist on Windows. What is fadvise/madvise equivalent on windows ? - Stack Overflow has some alternatives.