file_rename() and file_rename_unicode() new prototype
This commit is contained in:
parent
46de1359fd
commit
3d99713d6a
6 changed files with 88 additions and 56 deletions
|
@ -78,5 +78,5 @@ static void file_rename_d2s(const char *old_filename)
|
|||
return;
|
||||
buffer_size=fread(buffer, 1, sizeof(buffer), file);
|
||||
fclose(file);
|
||||
file_rename(old_filename, buffer, buffer_size, 0x14);
|
||||
file_rename(old_filename, buffer, buffer_size, 0x14, NULL, 1);
|
||||
}
|
||||
|
|
|
@ -313,7 +313,7 @@ static void PEVersion(FILE *file, const unsigned int offset, const unsigned int
|
|||
{
|
||||
if(do_rename)
|
||||
{
|
||||
file_rename_unicode(old_filename, buffer, end, pt, 0);
|
||||
file_rename_unicode(old_filename, buffer, end, pt, NULL, 0);
|
||||
free(buffer);
|
||||
return ;
|
||||
}
|
||||
|
|
|
@ -231,7 +231,7 @@ static void file_rename_gz(const char *old_filename)
|
|||
}
|
||||
if((flags&GZ_FNAME)!=0)
|
||||
{
|
||||
file_rename(old_filename, buffer, buffer_size, off);
|
||||
file_rename(old_filename, buffer, buffer_size, off, NULL, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include <ctype.h>
|
||||
#include "types.h"
|
||||
#include "filegen.h"
|
||||
#include "log.h"
|
||||
|
||||
static void register_header_check_r3d(file_stat_t *file_stat);
|
||||
static int header_check_r3d(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
|
||||
|
@ -82,9 +81,8 @@ static void file_rename_r3d(const char *old_filename)
|
|||
return;
|
||||
for(i=0x43; i< buffer_size && buffer[i]!=0 && buffer[i]!='.'; i++)
|
||||
{
|
||||
log_info("%c", buffer[i]);
|
||||
if(!isalnum(buffer[i]) && buffer[i]!='_')
|
||||
return ;
|
||||
}
|
||||
file_rename(old_filename, buffer, i, 0x43);
|
||||
file_rename(old_filename, buffer, i, 0x43, NULL, 1);
|
||||
}
|
||||
|
|
130
src/filegen.c
130
src/filegen.c
|
@ -341,7 +341,7 @@ file_stat_t * init_file_stats(file_enable_t *files_enable)
|
|||
}
|
||||
|
||||
/* The original filename begins at offset in buffer and is null terminated */
|
||||
void file_rename(const char *old_filename, const unsigned char *buffer, const int buffer_size, const int offset)
|
||||
void file_rename(const char *old_filename, const unsigned char *buffer, const int buffer_size, const int offset, const char *new_ext, const int force_ext)
|
||||
{
|
||||
/* new_filename is large enough to avoid a buffer overflow */
|
||||
char new_filename[2048];
|
||||
|
@ -350,8 +350,6 @@ void file_rename(const char *old_filename, const unsigned char *buffer, const in
|
|||
char *dst=&new_filename[0];
|
||||
char *directory_sep=&new_filename[0];
|
||||
int off=offset;
|
||||
if(buffer_size <= offset)
|
||||
return ;
|
||||
*dst='\0';
|
||||
while(*src!='\0')
|
||||
{
|
||||
|
@ -364,60 +362,96 @@ void file_rename(const char *old_filename, const unsigned char *buffer, const in
|
|||
dst=directory_sep;
|
||||
while(*dst!='.' && *dst!='\0')
|
||||
dst++;
|
||||
*dst++ = '_';
|
||||
/* Add original filename */
|
||||
while(off<buffer_size && buffer[off]!='\0')
|
||||
if(offset < buffer_size && buffer!=NULL)
|
||||
{
|
||||
switch(buffer[off])
|
||||
*dst++ = '_';
|
||||
for(;off<buffer_size && buffer[off]!='\0'; off++)
|
||||
{
|
||||
case '/':
|
||||
case '\\':
|
||||
*dst++ = '_';
|
||||
break;
|
||||
default:
|
||||
*dst++ = buffer[off];
|
||||
break;
|
||||
switch(buffer[off])
|
||||
{
|
||||
case '/':
|
||||
case '\\':
|
||||
case ':':
|
||||
*dst++ = '_';
|
||||
break;
|
||||
default:
|
||||
if(isprint(buffer[off]) && !isspace(buffer[off]))
|
||||
*dst++ = buffer[off];
|
||||
else
|
||||
*dst++ = '_';
|
||||
break;
|
||||
}
|
||||
}
|
||||
off++;
|
||||
}
|
||||
/* Add extension */
|
||||
while(*ext!='\0')
|
||||
*dst++ = *ext++;
|
||||
*dst='\0';
|
||||
rename(old_filename, new_filename);
|
||||
}
|
||||
|
||||
/* The original filename begins at offset in buffer and is null terminated */
|
||||
void file_rename_unicode(const char *old_filename, const unsigned char *buffer, const int buffer_size, const int offset, const int force_ext)
|
||||
{
|
||||
/* new_filename is large enough to avoid a buffer overflow */
|
||||
char new_filename[2048];
|
||||
const char *src=old_filename;
|
||||
const char *ext=src;
|
||||
char *dst=&new_filename[0];
|
||||
char *directory_sep=&new_filename[0];
|
||||
int off=offset;
|
||||
if(buffer_size <= offset)
|
||||
return ;
|
||||
*dst='\0';
|
||||
while(*src!='\0')
|
||||
if(new_ext!=NULL)
|
||||
{
|
||||
if(*src=='/')
|
||||
directory_sep=dst;
|
||||
if(*src=='.')
|
||||
ext=src;
|
||||
*dst++ = *src++;
|
||||
*dst++ = '.';
|
||||
while(*new_ext!='\0')
|
||||
*dst++ = *new_ext++;
|
||||
}
|
||||
dst=directory_sep;
|
||||
while(*dst!='.' && *dst!='\0')
|
||||
dst++;
|
||||
*dst++ = '_';
|
||||
/* Add original filename */
|
||||
for(;off<buffer_size && buffer[off]!='\0'; off+=2)
|
||||
*dst++ = buffer[off];
|
||||
if(force_ext)
|
||||
else if(force_ext>0)
|
||||
{
|
||||
while(*ext!='\0')
|
||||
*dst++ = *ext++;
|
||||
}
|
||||
*dst='\0';
|
||||
rename(old_filename, new_filename);
|
||||
}
|
||||
|
||||
/* The original filename begins at offset in buffer and is null terminated */
|
||||
void file_rename_unicode(const char *old_filename, const unsigned char *buffer, const int buffer_size, const int offset, const char *new_ext, const int force_ext)
|
||||
{
|
||||
/* new_filename is large enough to avoid a buffer overflow */
|
||||
char new_filename[2048];
|
||||
const char *src=old_filename;
|
||||
const char *ext=src;
|
||||
char *dst=&new_filename[0];
|
||||
char *directory_sep=&new_filename[0];
|
||||
int off=offset;
|
||||
*dst='\0';
|
||||
while(*src!='\0')
|
||||
{
|
||||
if(*src=='/')
|
||||
directory_sep=dst;
|
||||
if(*src=='.')
|
||||
ext=src;
|
||||
*dst++ = *src++;
|
||||
}
|
||||
dst=directory_sep;
|
||||
while(*dst!='.' && *dst!='\0')
|
||||
dst++;
|
||||
/* Add original filename */
|
||||
if(offset < buffer_size && buffer!=NULL)
|
||||
{
|
||||
*dst++ = '_';
|
||||
for(;off<buffer_size && buffer[off]!='\0'; off+=2)
|
||||
{
|
||||
switch(buffer[off])
|
||||
{
|
||||
case '/':
|
||||
case '\\':
|
||||
case ':':
|
||||
*dst++ = '_';
|
||||
break;
|
||||
default:
|
||||
if(isprint(buffer[off]) && !isspace(buffer[off]))
|
||||
*dst++ = buffer[off];
|
||||
else
|
||||
*dst++ = '_';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Add extension */
|
||||
if(new_ext!=NULL)
|
||||
{
|
||||
while(*new_ext!='\0')
|
||||
*dst++ = *new_ext++;
|
||||
}
|
||||
else if(force_ext>0)
|
||||
{
|
||||
/* Add extension */
|
||||
while(*ext!='\0')
|
||||
*dst++ = *ext++;
|
||||
}
|
||||
|
|
|
@ -130,8 +130,8 @@ void register_header_check(const unsigned int offset, const unsigned char *value
|
|||
const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new),
|
||||
file_stat_t *file_stat);
|
||||
file_stat_t * init_file_stats(file_enable_t *files_enable);
|
||||
void file_rename(const char *old_filename, const unsigned char *buffer, const int buffer_size, const int offset);
|
||||
void file_rename_unicode(const char *old_filename, const unsigned char *buffer, const int buffer_size, const int offset, const int force_ext);
|
||||
void file_rename(const char *old_filename, const unsigned char *buffer, const int buffer_size, const int offset, const char *new_ext, const int force_ext);
|
||||
void file_rename_unicode(const char *old_filename, const unsigned char *buffer, const int buffer_size, const int offset, const char *new_ext, const int force_ext);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* closing brace for extern "C" */
|
||||
|
|
Loading…
Reference in a new issue