Extract

Publicado por Enzo de Brito Ferber 08/06/2008

[ Hits: 4.600 ]

Homepage: http://www.maximasonorizacao.com.br

Download extract.c




Estava eu sem nada pra fazer hoje, então resolvi fazer um programa para retirar códigos fontes de arquivos txt.

<++> diretorio/arquivo.tipo
....
<-->

O <++> é o incio do arquivo, e o <--> é o fim.

Vale dizer que essa idéia de como definir o inicio e fim do arquivo nãoo foi minha, ela já é usada na zine phrack, que tem um programa extract também, mas o que me impede de fazer o meu né?!

  



Esconder código-fonte

/*
 * Programa: Retirar codigos de arquivo
 * Arquivo : extract.c
 * Autor   : Enzo Ferber (enzo@veloxmail.com.br)
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>

#define CODE_START      "<++>"
#define CODE_END        "<-->" 

FILE *createFile (char *);
void getFile (FILE *, int);
void search_code (FILE *, int);

FILE *createFile (char *path)
{
   FILE *nfile;
   FILE *log;
       char dir[50];
       struct stat file;
       register int i = 0;
   
       if (path[0] == ' ') path = path + 1;

       while (path[i] != '\r') i++;
       path[i] = '{FONTE}';

       i = 0;
       while (path[i] != 47) {
           dir[i] = path[i];
      i++;
       }
       dir[i] = '{FONTE}';
       if (stat(dir, &file) == -1) {
      printf("Novo Diretorio: %s\n", dir);
      mkdir (dir, 16877);
   }
   
   printf("Novo Arquivo: %s\n", path);

       nfile = fopen(path, "w");
   if (!nfile)
   {
      printf("Erro ao abrir %s\n", path);
      exit(0);
   }
       return nfile;
}   

void getFile (FILE *fp, int pos)
{
       FILE *nfile;
       char buffer[50];
       char info[5];
    
       fseek(fp, pos, SEEK_SET);
    
       fgets(buffer, 50, fp);
       nfile = createFile(buffer);

       while (1)
       {
          if (feof(fp)) break;
          fgets(buffer, 5, fp);
          if (strcmp(buffer, CODE_END) == 0) break;
          fputs(buffer, nfile);
       }


       fclose(nfile);
       search_code(fp, ftell(fp));
}

void search_code (FILE *fp, int pos)
{
       register int i;
       char buffer[5];
    
       fseek(fp, pos, SEEK_SET);

       while (1)
       {
           if (feof(fp)) break;
        
           fgets(buffer, 5, fp);
           if (!strcmp (buffer , CODE_START)) getFile(fp, ftell(fp));
       }
}

int main (int argc, char **argv)
{
       FILE *fp;
    
       if (argc < 2)
       {
           printf("Uso: %s <arquivo> \n", argv[0]);
           return 0;
       }
    
       fp = fopen (argv[1], "r");
       if (!fp)
       {
           perror("fopen()");
           return 0;
       }
    
       search_code (fp, 0);
    
       return 0;
}

Scripts recomendados

buildtgz

Cadastor de Produtos em C e metodos ordenação

Transformando uma sequencia de binário em executável

read_pg_conf

Pilhas C/C++ - Pares e ímpares


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts