send
Grupo de Telegram
play_arrow
Este sitio utiliza cookies propias y de terceros. Si continúa navegando consideramos que acepta el uso de cookies. OK Más Información.

Extractor de strings de binarios

  • 0 Respuestas
  • 1573 Vistas

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Jhonjhon_123

  • *
  • Underc0der
  • Mensajes: 150
  • Actividad:
    0%
  • Reputación 0
    • Ver Perfil
    • Jhonjhon_123's Software In Developed
« en: Febrero 23, 2010, 05:59:06 pm »
Muestra o guarda en un archivo los strings de un binario

Código: C
  1. // By Codr_joe
  2. // Bajo la licencia GPLv3
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. // Cambiar lo que hay entre parentesis para cambiar los caracteres que se buscaran por defecto
  8. #define default_chars "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789 \n!?\0" // El \0 hace falta para indicar el fin del string
  9.  
  10. // Cambiar para distinto numero minimo de caracteres
  11. #define default_chnum 4
  12.  
  13. int chnum;              // Numero de caracteres necesarios para considerarlo un string
  14.  
  15. void rmv_jmp(char *str);
  16. void rmv_strs(char *str,char * tgt);
  17. void add_strs(char *str,char * tgt);
  18. long f_getsize(char *fname);
  19. int exist(char *fname);
  20. void string_find(char * selected);
  21. int es_char(char ch,char* str);
  22.  
  23.  
  24. main(int argc,char* argv[]){
  25.  
  26. chnum=default_chnum;
  27.  
  28. char selected_chars[256]; // 255 Caracteres + 1 para el \0 (vamos, digo yo que ese no
  29.                           // va a ser parte de un string, no?)
  30. char opt;
  31.  
  32. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(selected_chars,default_chars);
  33. while (1){
  34.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\n\n\t\tString Finder\n\n");
  35.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Selecciona una opcion:\n");
  36.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\ta) Cambiar caracteres a buscar\n");
  37.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\tb) Mostrar caracteres a buscar\n");
  38.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\tc) Cambiar numero caracteres a buscar (%i)\n",chnum);
  39.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\td) Iniciar busqueda\n");
  40.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\tx) Salir\n");
  41.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("->");   You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(stdout);
  42.         opt=You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();
  43.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();                      // Uno para recojer la variable y otro para sacar el [Enter] del medio
  44.         switch (opt){
  45.                 case ('a'):
  46.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\n\nSelecciona una opcion:\n");
  47.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\ta) Añadir a la lista\n");
  48.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\tb) Eliminar de la lista\n");
  49.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("La lista es:\n%s\n",selected_chars);
  50.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("->");   You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(stdout);
  51.                         opt=You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();  You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();
  52.                         if ((opt=='a') || (opt=='b')){
  53.                                 char new_str[256];
  54.                                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Introduce el/los caracteres: "); You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(stdout);
  55.                                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(new_str,256,stdin);
  56.                                 rmv_jmp(new_str);
  57.                                 if (opt=='a')
  58.                                         add_strs(new_str,selected_chars);              
  59.                                 else
  60.                                         rmv_strs(new_str,selected_chars);              
  61.                         }
  62.                         else {
  63.                                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Opcion no valida\n");
  64.                                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Pulsa [enter] para continuar");You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(stdout);
  65.                                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();
  66.                                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\n");
  67.                         }
  68.                         break;
  69.                 case ('b'):
  70.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Caracteres:%s\n",selected_chars);
  71.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Pulsa [enter] para continuar");You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(stdout);
  72.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();
  73.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\n");
  74.                         break;
  75.                 case ('c'):
  76.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Introduce el nuevo numero: ");
  77.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("%i",&chnum);
  78.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();
  79.                         break;
  80.                 case ('d'):
  81.                         string_find(selected_chars);
  82.                         break;
  83.                 case ('x'):
  84.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(0);
  85.                         break;
  86.                 default:
  87.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Opcion [%c] no valida.\n",opt);
  88.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Pulsa [enter] para continuar");You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(stdout);
  89.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();
  90.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\n");
  91.         }
  92.  }
  93. }
  94.  
  95. void string_find(char * selected_chars){
  96.         char new_char;
  97.  
  98.         char in_fname [256];
  99.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(in_fname,'\0',256);
  100.         FILE * fin;
  101.  
  102.         char out_fname [256];
  103.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(out_fname,'\0',256);
  104.         FILE * fout;
  105.  
  106.         while (1){
  107.                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Introduce un archivo donde buscar: ");You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(stdout);
  108.                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(in_fname,256,stdin);
  109.                 rmv_jmp(in_fname);
  110.                 if (exist(in_fname))
  111.                         break;
  112.                 else
  113.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("El archivo no existe o no tienes permisos de lectura\n");
  114.         }
  115.  
  116.         fin=You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(in_fname,"rb");
  117.         if (fin==NULL)
  118.                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(1);               
  119.         while (1){
  120.                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Introduce un archivo donde guardar los resultados (o stdout para mostrar por pantalla): ");You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(stdout);
  121.                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(out_fname,256,stdin);
  122.                 rmv_jmp(out_fname);
  123.                 if ((You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(out_fname,"stdout")==0) || (!exist(out_fname)))
  124.                         break;
  125.                 else{
  126.                         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("El archivo ya existe, los resultados se añadiran al final (S/n)\n");
  127.                         new_char=You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();     You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();
  128.                         if (new_char!='n')
  129.                                 break;
  130.                 }
  131.         }
  132.         if (You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(out_fname,"stdout")==0)
  133.                 fout=stdout;
  134.         else
  135.                 fout=You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(out_fname,"ab");
  136.         if (fout==NULL)
  137.                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(1);
  138.        
  139.         char chars[256];
  140.         int i=0;
  141.         int es_ch;
  142.         long str_start;
  143.         long count=0;
  144.         long e=count;
  145.         long fsize=f_getsize(in_fname);
  146.         long refresh_rate=fsize/100;
  147.        
  148.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\n");
  149.         while (!You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(fin)){
  150.  
  151.                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(fin,"%c",&new_char);
  152.                 es_ch=es_char(new_char,selected_chars);
  153.  
  154.                 if (es_ch){
  155.                         if (i==0)
  156.                                 str_start=You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(fin);
  157.                         chars[i]=new_char;
  158.                         i++;
  159.                 }
  160.  
  161.                 if ((!es_ch && i>=chnum) || i>=255){
  162.                                 chars[i]='\0';
  163.                                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(fout,"%li--> %s\n",str_start,chars);
  164.                                 i=0;
  165.                 }
  166.  
  167.                 count++;
  168.                 if (e<count-refresh_rate){
  169.                         if (fout!=stdout){
  170.                                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\r");
  171.                                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("%li / %li",count,fsize);
  172.                                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(stdout);
  173.                         }
  174.                         e=count;
  175.                 }
  176.  
  177.         }
  178.         if (fout!=stdout){
  179.                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("\r");
  180.                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("%li / %li\n",fsize,fsize);
  181.                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(stdout);
  182.                 close(fout);
  183.         }
  184.         close(fin);
  185. }
  186.  
  187. int es_char(char ch,char* lista){
  188.         int es_char=0;
  189.         int i;
  190.         for (i=0;i<You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(lista);i++){
  191.                
  192.                 if (lista[i]==ch){
  193.                         es_char=1;
  194.                         break;
  195.                 }
  196.         }
  197.         return es_char;
  198. }
  199.  
  200. void rmv_strs(char *str,char * tgt){
  201.         int len=You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(tgt);
  202.         int i,j;
  203.         for (i=0;i<You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(str);i++){
  204.                 for (j=0;j<len;j++){
  205.                         if (tgt[j]==str[i]){
  206.                                 tgt[j]=0;
  207.                                 break;                         
  208.                         }
  209.                 }
  210.         }
  211.         int clean=0;
  212.         while (clean==0){
  213.                 clean=1;
  214.                 for (i=0;i<len;i++){
  215.                         if (tgt[i]=='\0'){
  216.                                 for (j=i+1;j<len;j++){
  217.                                         if (tgt[j]!='\0'){
  218.                                                 clean=0;
  219.                                                 tgt[j-1]=tgt[j];
  220.                                                 tgt[j]='\0';
  221.                                                 break;
  222.                                         }
  223.                                 }
  224.                         }
  225.                 }
  226.         }
  227. }
  228.  
  229. void add_strs(char *str,char * tgt){
  230.         int len=You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(tgt);
  231.         int i,j;
  232.         for (i=0;i<You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(str);i++){
  233.                 for (j=0;j<len;j++){
  234.                         if (tgt[j]==str[i]){
  235.                                 break;                         
  236.                         }
  237.                 }
  238.                 if ((tgt[j]!=str[i]) && (len<255)){
  239.                         tgt[len]=str[i];
  240.                         len++;
  241.                         tgt[len]='\0';
  242.                 }
  243.         }
  244. }
  245.  
  246.  
  247.  
  248. void rmv_jmp(char *str){                //Limpia los saltos de linea que puede dejar el fgets
  249.         int i;
  250.         for (i=0;i<You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(str);i++){
  251.                 if (str[i]=='\n')
  252.                         str[i]='\0';
  253.                 else if (str[i]!='\0')
  254.                         continue;
  255.                 break;
  256.         }
  257. }
  258.  
  259. long f_getsize(char *fname){            //Devuelve el tamaño de un archivo
  260.         FILE *f;
  261.         long size;
  262.         f=You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(fname,"rb");
  263.         if (f!=NULL){
  264.                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(f,0,SEEK_END);    // Vamos al final
  265.                 size=You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(f);          // Y guardamos la posicion
  266.                 close(f);
  267.         }
  268.         else
  269.                 size=-1;
  270.         return size;
  271. }
  272.  
  273. int exist(char *fname){                 //Devuelve 0 si un archivo no existe (o no se puede leer)
  274.         FILE *f;                        // o 1 si existe
  275.         int exist;
  276.         f=You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(fname,"rb");    // Ya se que el metodo no es muy preciso
  277.         if (f!=NULL){           // pero si no se puede leer para que seguir?
  278.                 exist=1;
  279.                 close(f);
  280.         }
  281.         else
  282.                 exist=0;
  283.         return exist;
  284. }
  285.  
  286.  
« Última modificación: Febrero 08, 2014, 06:14:05 pm por Expermicid »
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

 

¿Te gustó el post? COMPARTILO!