Make a self extractor
OK, I want o make a self extractor(C++)(CLI).
I know how to use binary fstream but dont know how to put a file in the EXE or how to use it once its in. Can anyone help? MinGW Compiler |
A simple, straightforward way of doing that would be storing the data in a variable:
Code:
unsigned char file[FILE_SIZE] = {0x01, 0x02, 0x03, ...}; Alternatively, you may try a more sophisticated aproach. You may also find this interesting. |
HOw would I write a program to do it for me? (it sounds awesome!)
|
Quote:
Code:
(echo "const unsigned char binary_data[] = {"; od -txC -v myfile.bin | sed -e "s/^[0-9]*//" -e s"/ \([0-9a-f][0-9a-f]\)/0x\1,/g" -e"\$d" | sed -e"\$s/,$/};/") Code:
#include <stdio.h> There are probably as many ways of doing this as there are programming languages. You can also try exporting the file as C source from a hex editor or something. |
I tried that with a rather large file and the output was only 3 bytes (Supposed to be 501 kilos) (the text hexadecimal output thing was fine the actual binary file wasn't)
I know (took a half hour for the precompiler to get done) but any help? |
Quote:
Quote:
|
Um... Mr.SigTerm I AM NOT DENNIS RITCHIE!!!!! Could you please explain that more clearly? I have no idea how to do almost any of that!
How do I append the file!?!? How do I get the executable's size!?!? ECT!?!? |
7zip is an opensource archiver and it has self-extractor module. You could try to see how it works - source code should be available.
Quote:
When resulting exe launches, it should skip to the beginning of data, and read from it. To do that you need to find file that corresponds to current module and read from it (GetModuleFilename on windows platform), or get a pointer to module as it is loaded into memory (in some versions of windows you could cast GetModuleHandle() result into pointer, but I'm not sure if this is even documented functionality). The trick is to determine offset of data. You can try to do that by:
|
I have looked at 7zip but I can't find the command line version of it and I just got to diologs In GUI programing. So how would I use the size of the program to determine what to extract? How would I make the program write this data? Is there a easy way to get my IDE (Code::Blocks) to do this for me (as in add file to executable)? Am I hopeless? I loved the first hexadecimal thing (could you give me an outline of what it is doing? I want to port it to C++) but the file I want to try it on is ~500 Kilobytes.
|
Hi.
Suppose you want to incorporate string "123" (3 bytes length) to the executable file "a.out". For simplicity I assume that "a.out", when run, just prints to stdout its payload (that is the string 123). It is not a problem to append "123" to a.out. For example, on linux: Code:
echo -n "123" >> a.out Your program should first open its own binary, then seek to 3 bytes back from its end and print contents of the file to the end. To do that your program have to know that its payload is 3 bytes length. This may be specified at compile time. Here is an example. Code:
// file self-extract.c Code:
$ gcc -D N=3 self-extract.c Of course your program can do more complicated things with payload than just printing it. The code may require some modification to compile on Windows. Hope this helps. PS. If you don't know how to append to the file, follow SigTerm's suggestion -- use `copy' utility or write your own. |
How would I seek throughthe file? Would this be easyer in Perl? I know perl but i thought scripted languiges had a weekness in storing binary files in them. (if the file was outside of that then it would be easy.)
I also know minute ammounts of python and ruby (weekest being ruby) but ruby wont start on my computer... So, how do i seek through the file, and would this be easyer in Perl? I love Perl...... |
Hi.
The situation is different for compiled languages (like C) and for interpreted languages (like Perl). 1. In C you write your program in a text file, say `prog.c', then you compile it to binary file, on linux just `prog', and then run it: `./prog' on linux. Executable file is different from program source. In this situation your program (self-extractor) should open its own binary file and locate the payload inside. You need some kind of `seek' function for this. And in C you already have one, it is called `lseek' (in linux you can run `man 2 lseek' for details or see here and this example). In my previous post I use lseek to go to specified number of bytes back from the end of file. 2. There are no such thing as executable (binary) file for interpreted languages. So you don't need to load it and then find something there. Instead you just put the information you want straight to the script, for example using here document and do what you want with it. This approach is very similar to putting the data to C-array (see first post), but much simpler and standard for such languages. In fact, some time ago this approach was used to make self-extracting shell archives (shar) -- see here and here. Example in perl: Code:
print << 'END' Note also that you will need an interpreter (correctly installed perl executable in your case) in order to extract your data automatically. Hope this helps. |
This pice of info might also chage some things:
The file is a non OS/2\Windows specific DLL. I wrote it and have the endure source (der). Would it be possible to place the code inside of a variable or something and when it's comPiled it gets turned into binary data. I acctualy have both strawberrie and ActiveState perl on my computer (the Linux side doesnt have one because I dont have Internet nor the time to to download all dependicys). Still deciding which one get in the regishtry and path... They both have ups n downs. Thanks! |
All times are GMT -5. The time now is 12:01 PM. |