KAPITALSIN

JUEGOS/SOFTWARE/HARDWARE => SOFTWARE => Mensaje iniciado por: Fl0ppy en 15 de Febrero de 2021, 07:46:54 pm

Título: PEDORRO extracts a block from a file
Publicado por: Fl0ppy en 15 de Febrero de 2021, 07:46:54 pm
PEDORRO es una utilidad del 2007 creada por KPS para tratar el tamaño de ficheros, por ejemplo si queremos eliminar ciertos bytes del principio de un fichero o del final o de ambos sentidos, un ejemplo práctico lo teneis con el juego    
Silent hill 2 director's cut *MULTI 5* *RiP LOSSY* (https://www.kapitalsin.com/forum/index.php?topic=2279.0)

He creado una versión compilada con GCC para Windows 32 y para Linux 64 (estática, no necesita GLibc concretas ni nada), previamente estaba compilada con Cygwin que da problemas con Wine

Se liberó el código fuente bajo licéncia de DOMINIO PÚBLICO

CODIGO FUENTE
Código: [Seleccionar]
/* LICENSE: PUBLIC DOMAIN */
/* Pedorro: extracts a block from a file */
/* CODE KPS 2007 */

#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64

#include <stdio.h>
#include <stdlib.h>

#if WIN32
#define fseeko _fseeki64
#define ftello _ftelli64
typedef __int64 off_t;
int fseeko(FILE *stream, off_t offset, int whence);
off_t ftello(FILE *stream);
#endif


void usage(void)
{
  printf("KAPITALSIN 2007 PRESENTA\n");
  printf("\n");
  printf("Pedorro: extracts a block from a file\n");
  printf("Usage: pedorro.exe in_file [-]start_pos [-][end_pos]\n");
  printf("\n");
  printf("in_file: Input file\n");
  printf("start_pos: offset of the beginning of the block in bytes\n");
  printf("           If positive, offset is from start of the file\n");
  printf("           If negative, offset is from end   of the file\n");
  printf("           If zero, is start of file\n");
  printf("end_pos:   offset of the end of the block in bytes\n");
  printf("           If positive, offset is from start of the file\n");
  printf("           If negative, offset is from end   of the file\n");
  printf("           If zero, is end of file\n");
  printf("\n");
  printf("Example: pedorro.exe infile.bin 4 -8 >outfile.bin\n");
  printf("         Removes the four first and the eight last bytes\n");
  printf("         of the input file\n");
  printf("\n");
}


int main(int argc, char *argv[])
{
  FILE *in_file;
  int data;
  off_t start_pos;
  off_t end_pos;
  off_t counter;
  off_t in_file_size;

  if(argc < 4)
  {
    usage();
    return 1;
  }

  in_file=fopen(argv[1], "rb");
  if(in_file == NULL)
  {
    printf("Error in input file\n");
    return 2;
  }
  fseeko(in_file, 0, SEEK_END);
  in_file_size = ftello(in_file);

  start_pos = atoi(argv[2]);
  if(argc < 4)
  {
    end_pos = 0;
  }
  else
  {
    end_pos = atoi(argv[3]);
  }

  if(start_pos < 0) start_pos += in_file_size - 1;
  if(end_pos == 0) end_pos = in_file_size - 1;
  if(end_pos < 0) end_pos += in_file_size - 1;
 
  fseeko(in_file, start_pos, SEEK_SET);
  counter = end_pos - start_pos + 1;
  while(counter-- > 0)
  {
    data = fgetc(in_file);
    fputc(data, stdout);
  }

  fclose(in_file);
  return 0;
}

Como compilarlo bajo windows (previamente tienes de tener el GCC instalado y los path del GCC)
Código: [Seleccionar]
gcc  pedorro.c  -o pedorro.exe
strip pedorro.exe

Bajo Linux
Código: [Seleccionar]
gcc -static pedorro.c  -o pedorro.bin
strip pedorro.bin

Si tienes el upx (es recomendable pues
Código: [Seleccionar]
upx --ultra-brute pedorro.*
Igualmente lo podeis descargar en el adjunto al igual que los binarios compilados para Windows (32 bits) y GNU/Linux (64 bits)
Título: Re:PEDORRO extracts a block from a file
Publicado por: Fl0ppy en 25 de Febrero de 2022, 07:16:10 pm
Creada versión nueva compilada y ahora ocupa unos 240 KB MENOS  :muahaha:
Título: Re:PEDORRO extracts a block from a file
Publicado por: Fl0ppy en 27 de Febrero de 2022, 03:36:40 am
Creada versión nueva compilada con TCC (https://bellard.org/tcc/) y ahora ocupa unos 250 KB MENOS  :muahaha: , originalmente son 252  kb, PERO no es 100% estático, es decir, no os funcionará en un "unix" que no use glibc, se ha testado con una glibc 2.17/kernel 3.8.0 y funciona perfectamente