Thread: S-Extract, Self Extractor w/ Source Code

  1. #1
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254

    S-Extract, Self Extractor w/ Source Code

    I wrote a little self extractor a while back, and thought that I would publish the source code.
    Its just one file, cross platform (just uses iostream, ifstream), and you can use it for whatever you want.

    After you compile it, stick a copy in the directory of files you want to archive, then do:
    "sextract.exe MyTarget.exe MyFirstFile MySecondFile MyThirdFile"

    Then, it will create an executable called MyTarget.exe.
    When you run this executable, the files MyFirstFile, mySecondFile, etc. will be extracted.
    This is a decent very minor overhead system for simple installers and the like.

    I thought I'd post it here, as it is a decent example of binary I/O, how to do it, and can be useful for some people.

    The source code is attached for your enjoyment.
    It compiles and runs under Windows and Linux, probably DOS too, but I haven't tested it under DOS.
    Programming Your Mom. http://www.dandongs.com/

  2. #2
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Why... when we already have NSIS?

    For one thing, I have [CENSORED] of an idea how it works, thanks to the excellent lack of comments. (One comment line for 77 code lines, folks.)

    For another thing, there is no license, and I might be doing something illegal by looking at it right now. Woe to my scruples!

    The else{} clause will also never execute... since argc will be at least 1 on any commonly-used platform.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Hmm, looks pretty neat. The only problem I can see is that a user could in theory take the archived form, and by doing a pack operation, make their own archive with the original archive inside it, and so on and so forth.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  4. #4
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254
    Sorry about the lack of comments. I didn't think these 77 lines were that confusing. Some time I'll comment it. Also, good catch on the else clause. I must've had that there originally and not intended to have the extractor and the archiver as one program, and let it remain somehow. Not exactly going to cause a problem, but good point.

    Use it however you want. I don't feel like going through the time of choosing a license, and I don't care how you use it.
    Programming Your Mom. http://www.dandongs.com/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seven Kingdoms I: Ancient Adversaries for Linux
    By MIH1406 in forum Projects and Job Recruitment
    Replies: 13
    Last Post: 01-17-2010, 05:03 PM
  2. How do you call another source code file?
    By nifear4 in forum C Programming
    Replies: 2
    Last Post: 10-28-2008, 12:16 PM
  3. starting linux's source code and kernel
    By sawer in forum Linux Programming
    Replies: 9
    Last Post: 08-01-2006, 07:46 AM
  4. DxEngine source code
    By Sang-drax in forum Game Programming
    Replies: 5
    Last Post: 06-26-2003, 05:50 PM
  5. Lines from Unix's source code have been copied into the heart of Linux????
    By zahid in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 05-19-2003, 03:50 PM