west@turing.toronto.edu (Tom West) (11/07/90)
I have a program that acts upon data currently stored in a file. I would like to somehow be able to combine the program with the data, so that a separate data file would not be necessary. (i.e. spreadsheet data with a viewer builtin.) Is there any way that one can do this? Actually, of course it can be done. Programs that build self-extracting archives must do exactly this. i.e. they have a uncompressing part and a data part. Could anyone either provide a few hints as to how this is done, or point me towards some magazine articles describing this? Thanks in advance. Tom West west@turing.toronto.edu or tomwest@gpu.utcs.utoronto.ca
fisher@sc2a.unige.ch (Markus Fischer) (11/09/90)
In article <1990Nov6.133618.23396@jarvis.csri.toronto.edu>, west@turing.toronto.edu (Tom West) writes: > I have a program that acts upon data currently stored in a file. I would > like to somehow be able to combine the program with the data, so that a > separate data file would not be necessary. (i.e. spreadsheet data with a > viewer builtin.) Is there any way that one can do this? > [...] Hello, Isn't this exactly what you do when you say `printf("Hello world!\n")'? i.e. a compilable code referencing static data? (note: examples are in (Turbo)C) A quick-and-dirty solution would be to create a program module like ] static char data[] = ] "here comes your text-file, remember to \"escape\" quotes, new lines\ ] and the like...\n"; If your data is in binary format, you can dump it as in ] static char data[] = { ] 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, ] 0x74, 0x21, ... /* or do you prefer octal notation? */ ] }; The program to generate such a listing for any file seems easy to write... Of course, a hacker might provide us a program creating directly the object module, without having to recompile it, but the above solution is more portable. After this step, compile the module, modify the file-io of your program into direct memory read, and link the whole thing. Hope this helps Markus Fischer, Dpt of Anthropology, Geneva.
dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (11/09/90)
In article <290@sc2a.unige.ch> fisher@sc2a.unige.ch (Markus Fischer) writes: >In article <1990Nov6.133618.23396@jarvis.csri.toronto.edu>, west@turing.toronto.edu (Tom West) writes: >> I have a program that acts upon data currently stored in a file. I would >> like to somehow be able to combine the program with the data, so that a >> separate data file would not be necessary. (i.e. spreadsheet data with a >> viewer builtin.) Is there any way that one can do this? >> [...] > >Of course, a hacker might provide us a program creating directly the object >module, without having to recompile it, but the above solution is more >portable. After this step, compile the module, modify the file-io of your >program into direct memory read, and link the whole thing. I don't know about Turbo C, but Borland supplies this program with Turbo Pascal: it's called BINOBJ, and converts any file into an object file, with an external of some sort pointing to the start of the data. (I think it's set up as an entry point, but I'm not sure; in any case, you reference it using the "address of" operator @.) Duncan Murdoch