Extract
Publicado por Enzo de Brito Ferber 08/06/2008
[ Hits: 4.788 ]
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; }
Pequeno simulador de Banco de Dados
MakeInt - gerador de wordlist numérica
Programa para inversão de colunas
Nenhum comentário foi encontrado.
tux-gpt - Assistente de IA para o Terminal
Instalação e configuração do Chrony
Programa IRPF - Guia de Instalação e Resolução de alguns Problemas
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
Copiar Layout do Teclado para aplicar em outra Distribuição (4)
QUERO USAR ABNT 2 NO LINUX MINT (1)
Alguém poderia me ajudar a escolher peças pra montar um desktop? (32)