Extract
Publicado por Enzo de Brito Ferber 08/06/2008
[ Hits: 4.791 ]
Homepage: http://www.maximasonorizacao.com.br
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é?!
/* * 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; }
Compactando arquivos de log *.txt
Exemplo de manipulação de arquivos
Agenda eletrônica completa em C
Nenhum comentário foi encontrado.
Resolver problemas de Internet
Como compartilhar a tela do Ubuntu com uma Smart TV (LG, Samsung, etc.)
Descritores de Arquivos e Swappiness
Como instalar no Linux Jogos da Steam só para Windows
Instalando o Team Viewer no Debian Trixie - problema no Policykit
O Que Fazer Após Instalar Ubuntu 25.04
O que você está ouvindo agora? [2] (176)
Erro ao executar o comando para dar um get email (1)
Problema ao iniciar o Opensuse Tumbleweed (2)