home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / zines / phrack2 / phrack51.017 < prev    next >
Encoding:
Text File  |  2003-06-11  |  2.5 KB  |  112 lines

  1.  
  2. ---[  Phrack Magazine   Volume 7, Issue 51 September 01, 1997, article 17 of 17
  3.  
  4.  
  5. -------------------------[  Phrack Magzine Extraction Utility
  6.  
  7.  
  8. --------[  Phrack Staff
  9.  
  10.     This time around, you have the option of using the C version of extract,
  11. or the PERL version, contributed by Daos.
  12.  
  13.  
  14. ---------------------8<------------CUT-HERE----------->8---------------------
  15.  
  16. /*  extract.c by Phrack Staff and sirsyko
  17.  *
  18.  *  (c) Phrack Magazine, 1997
  19.  *
  20.  *  Extracts textfiles from a specially tagged flatfile into a hierarchical
  21.  *  directory strcuture. Use to extract source code from any of the articles
  22.  *  in Phrack Magazine (first appeared in Phrack 50).
  23.  *
  24.  *  gcc -o extract extract.c
  25.  *
  26.  *  ./extract filename
  27.  */
  28.  
  29.  
  30. #include <stdio.h>
  31. #include <sys/stat.h>
  32. #include <string.h>
  33.  
  34. int main(int argc, char **argv){
  35.  
  36.     char *s="<++> ",*e="<-->",b[256],*bp;
  37.     FILE *f,*o = NULL;
  38.     int l, n, i=0;
  39.  
  40.     l = strlen(s);
  41.     n = strlen(e);
  42.  
  43.     if(argc<2) {
  44.         printf("Usage: %s <inputfile>\n",argv[0]);
  45.         exit(1);
  46.     }
  47.  
  48.     if(! (f=fopen(argv[1], "r"))) {
  49.         printf("Could not open input file.\n");
  50.     exit(1);
  51.     }
  52.  
  53.     while(fgets(b, 256, f)){
  54.  
  55.         if(!strncmp (b, s, l)){
  56.         b[strlen(b)-1] = '\0';
  57.  
  58.         if((bp=strchr(b+l+1,'/')))
  59.             while (bp){
  60.             *bp='\0';
  61.             mkdir(b+l, 0700);
  62.             *bp='/';
  63.             bp=strchr(bp+1,'/');
  64.         }
  65.         if((o = fopen(b+l, "w")))
  66.             printf("- Extracting %s\n",b+l);
  67.         else {
  68.         printf("Could not extract '%s'\n",b+l);
  69.         exit(1);
  70.         }
  71.     }
  72.         else if(!strncmp (b, e, n)){
  73.         if(o) fclose(o);
  74.         else {
  75.             printf("Error closing file.\n");
  76.         exit(1);
  77.         }
  78.         }
  79.         else if(o) {
  80.             fputs(b, o);
  81.             i++;
  82.         }
  83.     }
  84.     if(!i) printf("No extraction tags found.\n");
  85.     return(0);
  86. }
  87.  
  88. ---------------------8<------------CUT-HERE----------->8---------------------
  89.  
  90. # Daos <daos@nym.alias.net>
  91.  
  92. <++> extract.pl
  93. #!/bin/sh -- # -*- perl -*- -n
  94. eval 'exec perl $0 -S ${1+"$@"}' if 0;
  95.  
  96. $opening=0;
  97.  
  98. if (/^\<\+\+\>/) {$curfile = substr($_ , 5); $opening=1;};
  99. if (/^\<\-\-\>/) {close ct_ex; $opened=0;};
  100. if ($opening) {
  101.         chop $curfile;
  102.         $sex_dir= substr( $curfile, 0, ((rindex($curfile,'/'))) ) if ($curfile =~ m/\//);
  103.         eval {mkdir $sex_dir, "0777";};
  104.         open(ct_ex,">$curfile");
  105.         print "Attempting extraction of $curfile\n";
  106.         $opened=1;
  107. }
  108. if ($opened && !$opening) {print ct_ex $_};
  109. <-->
  110.  
  111. ----[  EOF
  112.