| | |
Files extraction program
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2009
Posts: 7
Reputation:
Solved Threads: 0
I am trying to make a file extraction program in C and I can't get it to work. It compiles ok, but it has a run-time error. I hope you can figure out what I am trying to do here. I don't know if there is a standard way to do this. I am going to make a table with length of files later. Is there a way to determine EOF without having a table of lengths?
Here is the layout of the file:
1. extraction program
2. 4 bytes for number of files in archive
3. table of files (each 16 bytes long)
4. length of each files in table (not implemented)
Here is the layout of the file:
1. extraction program
2. 4 bytes for number of files in archive
3. table of files (each 16 bytes long)
4. length of each files in table (not implemented)
C Syntax (Toggle Plain Text)
#include "stdio.h" int main(int argc, char* argv[]) { //Declair vars FILE *self; int fcount = 0; int i; //Size of this program (the stub) const int F_SIZE = 6143; //Open self, set pointer to the end of the stub self = fopen(argv[0], "rb"); fseek(self, F_SIZE, SEEK_SET); //Read integer for number of files in archive fread(&fcount, 4, 1, self); char filenames[fcount][16]; //Loop through the file names for(i = F_SIZE + 4; i < F_SIZE + 4 + (fcount * 16); i+=16) { fseek(self, i, SEEK_SET); fread(&filenames[i][16], 16, 1, self); } fclose(self); for(i = 0; i < fcount; i++) { self = fopen(&filenames[i][16], "w"); //This part is just to test if it can make the files fprintf(self, "%c", 144); fclose(self); } return 0; }
Last edited by John A; Aug 31st, 2009 at 11:27 pm. Reason: added code tags
C Syntax (Toggle Plain Text)
char filenames[fcount][16];
C Syntax (Toggle Plain Text)
char filenames[MAX_FCOUNT][16];
Also:
C Syntax (Toggle Plain Text)
//Loop through the file names for(i = F_SIZE + 4; i < F_SIZE + 4 + (fcount * 16); i+=16) { fseek(self, i, SEEK_SET); fread(&filenames[i][16], 16, 1, self); }
•
•
•
•
Is there a way to determine EOF without having a table of lengths?
How are you generating this executable? Because you'll have to add some stuff onto the end to make it work.
I should mention that in doing so, you may mess up the executable format. I'm not very familiar with the windows executable format, but it may require some data at the end of the file (and by adding onto the end of the file, you may be messing it up). A quick way to test this would be to add random junk onto the end of an existing, working program, and see if that crashes it.
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
•
•
Join Date: Jun 2009
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
You're declaring a variable-length array here. It's not standard C89 to do that. If I were you I'd just declare the array as
•
•
•
•
All that seeking is unnecessary. The filenames are all contiguous in the file, so just read the first, then the second, and so on. After reading one filename, your file pointer will already be in the correct position to read the next.
•
•
•
•
How are you generating this executable? Because you'll have to add some stuff onto the end to make it work.
•
•
•
•
I should mention that in doing so, you may mess up the executable format.
Last edited by Joe Shmoe; Aug 31st, 2009 at 11:19 pm.
![]() |
Similar Threads
- How to read pdf files with VB.net program- pls help me. (VB.NET)
- Mp3 Files Searching program inside a drive (Windows NT / 2000 / XP)
- Reading data into files (C++)
- Modem keeps dialling when i open files (Viruses, Spyware and other Nasties)
- Unable to open any DOS program and IE shows DNS error (Web Browsers)
- PLease help me to make my program run (C++)
- Another Program Launching mine (C++)
- Delete files on restart (Windows NT / 2000 / XP)
- How to develop a new program (C++)
- Default program to open *.pdf (Mac Software)
Other Threads in the C Forum
- Previous Thread: comparing string in array
- Next Thread: implicit declaration?
| Thread Tools | Search this Thread |
Tag cloud for C
#include adobe ansi array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic fflush file fork forloop framework getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware histogram homework inches include incrementoperators input iso kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix problem probleminc process program programming radix recursion recv research reversing scanf scripting segmentationfault sequential shape socket socketprograming spoonfeeding standard string strings structures student systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi





