mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-28 08:20:54 +01:00
Open key using streamFile, needed to allow user-defined callbacks
This commit is contained in:
parent
088fb4a480
commit
f5e8e8ad8e
@ -496,11 +496,9 @@ static int find_key(STREAMFILE *file, uint8_t type, uint16_t *xor_start, uint16_
|
||||
|
||||
/* try to find key in external file first */
|
||||
{
|
||||
char filename[PATH_LIMIT];
|
||||
uint8_t keybuf[6];
|
||||
|
||||
file->get_name(file,filename,sizeof(filename));
|
||||
if ( read_key_file(keybuf, 6, filename) ) {
|
||||
if ( read_key_file(keybuf, 6, file) ) {
|
||||
*xor_start = get_16bitBE(keybuf+0);
|
||||
*xor_mult = get_16bitBE(keybuf+2);
|
||||
*xor_add = get_16bitBE(keybuf+4);
|
||||
|
@ -275,57 +275,60 @@ size_t get_streamfile_dos_line(int dst_length, char * dst, off_t offset,
|
||||
|
||||
/**
|
||||
* open file containing decryption keys and copy to buffer
|
||||
* tries combinations of keynames based on the original songname
|
||||
* tries combinations of keynames based on the original filename
|
||||
*
|
||||
* returns true if found and copied
|
||||
*/
|
||||
int read_key_file(uint8_t * buf, size_t bufsize, const char * songname) {
|
||||
int read_key_file(uint8_t * buf, size_t bufsize, STREAMFILE *streamFile) {
|
||||
char keyname[PATH_LIMIT];
|
||||
char filename[PATH_LIMIT];
|
||||
const char *path, *ext;
|
||||
STREAMFILE * streamFileKey = NULL;
|
||||
|
||||
if (strlen(songname)+4 > sizeof(keyname)) goto fail;
|
||||
streamFile->get_name(streamFile,filename,sizeof(filename));
|
||||
|
||||
if (strlen(filename)+4 > sizeof(keyname)) goto fail;
|
||||
|
||||
/* try to open a keyfile using variations:
|
||||
* "(name.ext)key" (per song), "(.ext)key" (per folder) */
|
||||
{
|
||||
ext = strrchr(songname,'.');
|
||||
ext = strrchr(filename,'.');
|
||||
if (ext!=NULL) ext = ext+1;
|
||||
|
||||
path = strrchr(songname,DIR_SEPARATOR);
|
||||
path = strrchr(filename,DIR_SEPARATOR);
|
||||
if (path!=NULL) path = path+1;
|
||||
|
||||
/* "(name.ext)key" */
|
||||
strcpy(keyname, songname);
|
||||
strcpy(keyname, filename);
|
||||
strcat(keyname, "key");
|
||||
streamFileKey = open_stdio_streamfile(keyname);
|
||||
streamFileKey = streamFile->open(streamFile,keyname,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
if (streamFileKey) goto found;
|
||||
|
||||
/* "(name.ext)KEY" */
|
||||
/*
|
||||
strcpy(keyname+strlen(keyname)-3,"KEY");
|
||||
streamFileKey = open_stdio_streamfile(keyname);
|
||||
streamFileKey = streamFile->open(streamFile,keyname,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
if (streamFileKey) goto found;
|
||||
*/
|
||||
|
||||
|
||||
/* "(.ext)key" */
|
||||
if (path) {
|
||||
strcpy(keyname, songname);
|
||||
keyname[path-songname] = '\0';
|
||||
strcpy(keyname, filename);
|
||||
keyname[path-filename] = '\0';
|
||||
strcat(keyname, ".");
|
||||
} else {
|
||||
strcpy(keyname, ".");
|
||||
}
|
||||
if (ext) strcat(keyname, ext);
|
||||
strcat(keyname, "key");
|
||||
streamFileKey = open_stdio_streamfile(keyname);
|
||||
streamFileKey = streamFile->open(streamFile,keyname,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
if (streamFileKey) goto found;
|
||||
|
||||
/* "(.ext)KEY" */
|
||||
/*
|
||||
strcpy(keyname+strlen(keyname)-3,"KEY");
|
||||
streamFileKey = open_stdio_streamfile(keyname);
|
||||
streamFileKey = streamFile->open(streamFile,keyname,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
if (streamFileKey) goto found;
|
||||
*/
|
||||
|
||||
|
@ -149,7 +149,7 @@ static inline STREAMFILE * open_stdio_streamfile(const char * const filename) {
|
||||
size_t get_streamfile_dos_line(int dst_length, char * dst, off_t offset,
|
||||
STREAMFILE * infile, int *line_done_ptr);
|
||||
|
||||
int read_key_file(uint8_t * buf, size_t bufsize, const char * filename);
|
||||
int read_key_file(uint8_t * buf, size_t bufsize, STREAMFILE *streamFile);
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user