Update rres

This commit is contained in:
Milan Nikolic 2023-11-12 12:21:11 +01:00
parent 3c5dec7f24
commit f492eb5f2b
No known key found for this signature in database
GPG key ID: 9229D0EAA3AA4E75
3 changed files with 32 additions and 21 deletions

6
rres/cgo.go Normal file
View file

@ -0,0 +1,6 @@
package rres
/*
#cgo CFLAGS: -std=gnu99 -Wno-unused-result -Wno-implicit-function-declaration -Wno-deprecated-declarations
*/
import "C"

View file

@ -567,7 +567,7 @@ int UnpackResourceChunk(rresResourceChunk *chunk)
};
crypto_argon2_inputs inputs = {
.pass = (const uint8_t *)rresGetCipherPassword(), // User password
.pass_size = 16, // Password length
.pass_size = strlen(rresGetCipherPassword()), // Password length
.salt = salt, // Salt for the password
.salt_size = 16
};
@ -642,7 +642,7 @@ int UnpackResourceChunk(rresResourceChunk *chunk)
};
crypto_argon2_inputs inputs = {
.pass = (const uint8_t *)rresGetCipherPassword(), // User password
.pass_size = 16, // Password length
.pass_size = strlen(rresGetCipherPassword()), // Password length
.salt = salt, // Salt for the password
.salt_size = 16
};

View file

@ -136,6 +136,8 @@
#ifndef RRES_H
#define RRES_H
#include <stdio.h>
// Function specifiers in case library is build/used as a shared library (Windows)
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
#if defined(_WIN32)
@ -178,6 +180,8 @@
#define RRES_LOG(...)
#endif
// On Windows, MAX_PATH is limited to 256 by default,
// on Linux, it could go up to 4096
#define RRES_MAX_FILENAME_SIZE 1024
//----------------------------------------------------------------------------------
@ -891,7 +895,7 @@ rresCentralDir rresLoadCentralDirectory(const char *fileName)
RRES_LOG("RRES: CDIR: Central Directory file entries count: %i\n", dir.count);
unsigned char *ptr = chunkData.raw;
unsigned char *ptr = (unsigned char *)chunkData.raw;
dir.entries = (rresDirEntry *)RRES_CALLOC(dir.count, sizeof(rresDirEntry));
for (unsigned int i = 0; i < dir.count; i++)
@ -1054,7 +1058,7 @@ static rresResourceChunkData rresLoadResourceChunkData(rresResourceChunkInfo inf
rresResourceChunkData chunkData = { 0 };
// CRC32 data validation, verify packed data is not corrupted
unsigned int crc32 = rresComputeCRC32(data, info.packedSize);
unsigned int crc32 = rresComputeCRC32((unsigned char *)data, info.packedSize);
if ((rresGetDataType(info.type) != RRES_DATA_NULL) && (crc32 == info.crc32)) // Make sure chunk contains data and data is not corrupted
{
@ -1070,8 +1074,9 @@ static rresResourceChunkData rresLoadResourceChunkData(rresResourceChunkInfo inf
for (unsigned int i = 0; i < chunkData.propCount; i++) chunkData.props[i] = ((unsigned int *)data)[i + 1];
}
chunkData.raw = RRES_MALLOC(info.baseSize);
memcpy(chunkData.raw, ((unsigned char *)data) + sizeof(int) + (chunkData.propCount*sizeof(int)), info.baseSize);
int rawSize = info.baseSize - sizeof(int) - (chunkData.propCount*sizeof(int));
chunkData.raw = RRES_MALLOC(rawSize);
memcpy(chunkData.raw, ((unsigned char *)data) + sizeof(int) + (chunkData.propCount*sizeof(int)), rawSize);
}
else
{