Extract
Publicado por Enzo de Brito Ferber 08/06/2008
[ Hits: 4.830 ]
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; }
Transformando uma sequencia de binário em executável
Fwn - Formatador de arquivos .txt
Controle de Funcionários (Básico)
Nenhum coment�rio foi encontrado.
Atualizando o Passado: Linux no Lenovo G460 em 2025
aaPanel - Um Painel de Hospedagem Gratuito e Poderoso
O macete do Warsaw no Linux Mint e cia
Visualizar arquivos em formato markdown (ex.: README.md) pelo terminal
Dando - teoricamente - um gás no Gnome-Shell do Arch Linux
Como instalar o Google Cloud CLI no Ubuntu/Debian
Mantenha seu Sistema Leve e Rápido com a Limpeza do APT!
Procurando vídeos de YouTube pelo terminal e assistindo via mpv (2025)
Pastas da raiz foram para a área de trabalho [RESOLVIDO] (10)
Será que eu deveria apreender C/C++ para desenvolver para Linux? (4)