mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-30 03:47:30 +01:00
Update read_key_file for variable-sized keys
This commit is contained in:
parent
e5f52135db
commit
ae2ba1bc29
@ -249,7 +249,7 @@ static int find_key(STREAMFILE *file, uint8_t type, uint16_t *xor_start, uint16_
|
||||
{
|
||||
uint8_t keybuf[6];
|
||||
|
||||
if ( read_key_file(keybuf, 6, file) ) {
|
||||
if (read_key_file(keybuf, 6, file) == 6) {
|
||||
*xor_start = get_16bitBE(keybuf+0);
|
||||
*xor_mult = get_16bitBE(keybuf+2);
|
||||
*xor_add = get_16bitBE(keybuf+4);
|
||||
|
@ -56,7 +56,7 @@ VGMSTREAM * init_vgmstream_ahx(STREAMFILE *streamFile) {
|
||||
|
||||
if (cfg.encryption) {
|
||||
uint8_t keybuf[6];
|
||||
if (read_key_file(keybuf, 6, streamFile)) {
|
||||
if (read_key_file(keybuf, 6, streamFile) == 6) {
|
||||
cfg.cri_key1 = get_16bitBE(keybuf+0);
|
||||
cfg.cri_key2 = get_16bitBE(keybuf+2);
|
||||
cfg.cri_key3 = get_16bitBE(keybuf+4);
|
||||
|
@ -54,7 +54,7 @@ VGMSTREAM * init_vgmstream_hca(STREAMFILE *streamFile) {
|
||||
/* find decryption key in external file or preloaded list */
|
||||
{
|
||||
uint8_t keybuf[8];
|
||||
if ( read_key_file(keybuf, 8, streamFile) ) {
|
||||
if (read_key_file(keybuf, 8, streamFile) == 8) {
|
||||
ciphKey2 = get_32bitBE(keybuf+0);
|
||||
ciphKey1 = get_32bitBE(keybuf+4);
|
||||
} else {
|
||||
|
@ -546,17 +546,15 @@ STREAMFILE * open_stream_name(STREAMFILE *streamFile, const char * name) {
|
||||
return streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* open file containing decryption keys and copy to buffer
|
||||
* 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, STREAMFILE *streamFile) {
|
||||
/* Opens a file containing decryption keys and copies to buffer.
|
||||
* Tries combinations of keynames based on the original filename.
|
||||
* returns size of key if found and copied */
|
||||
size_t 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;
|
||||
size_t keysize;
|
||||
|
||||
streamFile->get_name(streamFile,filename,sizeof(filename));
|
||||
|
||||
@ -609,17 +607,17 @@ int read_key_file(uint8_t * buf, size_t bufsize, STREAMFILE *streamFile) {
|
||||
}
|
||||
|
||||
found:
|
||||
if (get_streamfile_size(streamFileKey) != bufsize) goto fail;
|
||||
keysize = get_streamfile_size(streamFileKey);
|
||||
if (keysize > bufsize) goto fail;
|
||||
|
||||
if (read_streamfile(buf, 0, bufsize, streamFileKey)!=bufsize) goto fail;
|
||||
if (read_streamfile(buf, 0, keysize, streamFileKey) != keysize)
|
||||
goto fail;
|
||||
|
||||
close_streamfile(streamFileKey);
|
||||
|
||||
return 1;
|
||||
return keysize;
|
||||
|
||||
fail:
|
||||
if (streamFileKey) close_streamfile(streamFileKey);
|
||||
|
||||
close_streamfile(streamFileKey);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ STREAMFILE * open_stream_name(STREAMFILE *streamFile, const char * ext);
|
||||
|
||||
int read_string(char * buf, size_t bufsize, off_t offset, STREAMFILE *streamFile);
|
||||
|
||||
int read_key_file(uint8_t * buf, size_t bufsize, STREAMFILE *streamFile);
|
||||
size_t read_key_file(uint8_t * buf, size_t bufsize, STREAMFILE *streamFile);
|
||||
int read_pos_file(uint8_t * buf, size_t bufsize, STREAMFILE *streamFile);
|
||||
|
||||
int check_extensions(STREAMFILE *streamFile, const char * cmp_exts);
|
||||
|
Loading…
x
Reference in New Issue
Block a user