cake
/
libg1m
Archived
1
0
Fork 0

Fixed crash (was a memset).

This commit is contained in:
Thomas Touhey 2017-03-18 08:16:14 +01:00
parent 43c58008fa
commit a527c64591
9 changed files with 34 additions and 20 deletions

View File

@ -92,7 +92,7 @@ endif
# - Specific linker flags
LDFLAGS_Windows := -lws2_32 -Wl,--out-implib,lib$(NAME).dll.a
LDFLAGS_Linux := $(if $(STATIC),,-Wl,-soname,$(SONAME) \
-e __lib$(NAME)_version \
-e __lib$(NAME)_version \
-Wl,-z,relro -Wl,-z,combreloc -Wl,-z,defs)
# - Linker flags
LDFLAGS := $(if $(STATIC),,-shared) \

View File

@ -92,6 +92,7 @@ struct standard_subheader {
uint32_t checksum;
/* file type:
* - 0x00: picture;
* - 0x01: add-in;
* - 0x02: function keys;
* - 0x04: language files; */
@ -103,7 +104,10 @@ struct standard_subheader {
uint8_t platform;
/* unknown */
uint8_t _unknown0[8];
uint8_t _unknown0[4];
/* size of the data + footer? */
uint32_t df_size;
/* control:
* - for a G3A: filesize - 0x7000 - 4

View File

@ -57,11 +57,14 @@ struct g1l_subheader {
* have this language header: */
struct g3l_lang_header {
/* sequence: '4C 59 37 35 35 00 00 00 02' (LY755 ) */
uint8_t sequence[9];
/* sequence: '4C 59 37 35 35 00 00 00' (LY755 ) */
uint8_t sequence[8];
/* unknown: 0x02 */
uint8_t _unknown;
/* unused byte. */
uint8_t unused;
uint8_t _unused;
/* number of messages ("possibly 0 base indexed") */
uint32_t num;

View File

@ -37,12 +37,18 @@ enum g3p_colorsize {
/* So, after the header, here is the G3P subheader: */
struct g3p_subheader {
/* some magic sequence: "CP0100Ly755"
* "CP" is check by a syscall */
uint8_t magic[11];
/* some magic sequence: "CP0100"
* "CP" is checked by a syscall */
uint8_t type[6];
/* some magic sequence: '4C 59 37 35 35 00 00 00' (LY755 ) */
uint8_t magic[8];
/* unknown: 0x02 */
uint8_t _unknown;
/* unused */
uint8_t unused[5];
uint8_t _unused;
/* size of the file after standard header */
uint32_t g3p_size;

View File

@ -93,13 +93,10 @@ static int lookup_extension(const char *path, g1m_type_t types,
int g1m_decode(g1m_t **handle, const char *path, g1m_buffer_t *buffer,
g1m_type_t expected_types)
{
/* initialize the handle */
memset(handle, 0, sizeof(g1m_t));
/* match using extension */
decode_func decode;
int err = lookup_extension(path, expected_types, &decode);
if (err == g1m_error_wrong_type) return (g1m_error_wrong_type);
if (err == g1m_error_wrong_type) return (err);
else if (!err) return ((*decode)(handle, buffer));
/* identify a CAS file */

View File

@ -71,7 +71,6 @@ static int find_decode_function(g1m_platform_t platform, g1m_type_t type,
{
/* get the function */
struct corresp *c = parsing_functions - 1;
log_info("Type is %04X, platform is %04X", type, platform);
while ((++c)->decode) {
if (c->type != type)
continue;

View File

@ -140,17 +140,17 @@ int g1m_decode_std_cg_fkey(g1m_t **h, g1m_buffer_t *buffer,
struct standard_header *std, struct standard_subheader *sub,
struct _prizm_subheader *prizm, uint32_t *check)
{
int err;
int err = g1m_error_alloc; uint8_t *data = NULL;
/* read the subheader */
DREAD(lhd, g3l_lang_header)
*check = g1m_checksum32(&lhd, sizeof(struct g3l_lang_header), *check);
/* read the data */
size_t data_size = sub->filesize - sizeof(struct standard_header)
size_t data_size = be32toh(sub->filesize) - sizeof(struct standard_header)
- sizeof(struct standard_subheader) - sizeof(struct _prizm_subheader)
- sizeof(struct g3l_lang_header) - 4;
uint8_t data[data_size];
if (!(data = malloc(data_size))) goto fail;
READ(data, data_size)
*check = g1m_checksum32(data, data_size, *check);
@ -183,9 +183,11 @@ int g1m_decode_std_cg_fkey(g1m_t **h, g1m_buffer_t *buffer,
}
/* done */
free(data);
return (0);
fail:
free(data);
g1m_free(*h); *h = NULL;
return (err);
}

View File

@ -105,17 +105,17 @@ int g1m_decode_std_cg_lang(g1m_t **h, g1m_buffer_t *buffer,
struct standard_header *std, struct standard_subheader *sub,
struct _prizm_subheader *prizm, uint32_t *check)
{
int err;
int err = g1m_error_alloc; uint8_t *data = NULL;
/* read the subheader */
DREAD(lhd, g3l_lang_header)
*check = g1m_checksum32(&lhd, sizeof(struct g3l_lang_header), *check);
/* read the data */
size_t data_size = sub->filesize - sizeof(struct standard_header)
size_t data_size = be32toh(sub->filesize) - sizeof(struct standard_header)
- sizeof(struct standard_subheader) - sizeof(struct _prizm_subheader)
- sizeof(struct g3l_lang_header) - 4;
uint8_t data[data_size];
if (!(data = malloc(data_size))) goto fail;
READ(data, data_size)
*check = g1m_checksum32(data, data_size, *check);
@ -148,9 +148,11 @@ int g1m_decode_std_cg_lang(g1m_t **h, g1m_buffer_t *buffer,
}
/* done */
free(data);
return (0);
fail:
free(data);
g1m_free(*h); *h = NULL;
return (err);
}

View File

@ -194,6 +194,7 @@ int g1m_make_addin(g1m_t **h, g1m_platform_t platform,
memset(handle, 0, sizeof(g1m_t));
/* set basic options */
handle->type = g1m_type_addin;
handle->platform = platform;
handle->version = *version;
handle->creation_date = *created;