mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-04 03:46:42 +01:00
Ensure comment strings in CBannerLoaderWii::SWiiBanner are null-terminated. Fixes issue 5012.
Signed-off-by: Shawn Hoffman <godisgovernment@gmail.com>
This commit is contained in:
parent
79ca43226c
commit
bef3d7229e
@ -144,43 +144,57 @@ bool CBannerLoaderWii::GetBanner(u32* _pBannerImage)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBannerLoaderWii::GetName(std::string* _rName)
|
bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::string& s)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
if (IsValid())
|
||||||
|
{
|
||||||
|
// find Banner type
|
||||||
|
SWiiBanner *pBanner = (SWiiBanner*)m_pBannerFile;
|
||||||
|
|
||||||
|
// Ensure the string is null-terminating, since the banner format
|
||||||
|
// doesn't require it
|
||||||
|
u16 *src = new u16[COMMENT_SIZE + 1];
|
||||||
|
memcpy(src, &pBanner->m_Comment[index], COMMENT_SIZE * sizeof(u16));
|
||||||
|
src[COMMENT_SIZE] = 0;
|
||||||
|
|
||||||
|
ret = CopyBeUnicodeToString(s, src, COMMENT_SIZE + 1);
|
||||||
|
|
||||||
|
delete [] src;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::wstring& s)
|
||||||
{
|
{
|
||||||
if (IsValid())
|
if (IsValid())
|
||||||
{
|
{
|
||||||
// find Banner type
|
// find Banner type
|
||||||
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
||||||
|
|
||||||
std::string name;
|
std::wstring description;
|
||||||
if (CopyBeUnicodeToString(name, pBanner->m_Comment[0], WII_BANNER_COMMENT_SIZE))
|
for (int i = 0; i < COMMENT_SIZE; ++i)
|
||||||
{
|
description.push_back(Common::swap16(pBanner->m_Comment[index][i]));
|
||||||
for (int i = 0; i < 6; i++)
|
|
||||||
{
|
s = description;
|
||||||
_rName[i] = name;
|
return true;
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CBannerLoaderWii::GetName(std::string* _rName)
|
||||||
|
{
|
||||||
|
return GetStringFromComments(NAME_IDX, *_rName);
|
||||||
|
}
|
||||||
|
|
||||||
bool CBannerLoaderWii::GetName(std::vector<std::wstring>& _rNames)
|
bool CBannerLoaderWii::GetName(std::vector<std::wstring>& _rNames)
|
||||||
{
|
{
|
||||||
if (IsValid())
|
std::wstring temp;
|
||||||
{
|
bool ret = GetStringFromComments(NAME_IDX, temp);
|
||||||
// find Banner type
|
_rNames.push_back(temp);
|
||||||
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
return ret;
|
||||||
|
|
||||||
std::wstring temp;
|
|
||||||
for (int i = 0; i < WII_BANNER_COMMENT_SIZE; ++i)
|
|
||||||
{
|
|
||||||
temp.push_back(Common::swap16(pBanner->m_Comment[0][i]));
|
|
||||||
}
|
|
||||||
_rNames.push_back(temp);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBannerLoaderWii::GetCompany(std::string& _rCompany)
|
bool CBannerLoaderWii::GetCompany(std::string& _rCompany)
|
||||||
@ -191,39 +205,12 @@ bool CBannerLoaderWii::GetCompany(std::string& _rCompany)
|
|||||||
|
|
||||||
bool CBannerLoaderWii::GetDescription(std::string* _rDescription)
|
bool CBannerLoaderWii::GetDescription(std::string* _rDescription)
|
||||||
{
|
{
|
||||||
if (IsValid())
|
return GetStringFromComments(DESC_IDX, *_rDescription);
|
||||||
{
|
|
||||||
// find Banner type
|
|
||||||
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
|
||||||
|
|
||||||
std::string description;
|
|
||||||
if (CopyBeUnicodeToString(description, pBanner->m_Comment[1], WII_BANNER_COMMENT_SIZE))
|
|
||||||
{
|
|
||||||
for (int i = 0; i< 6; i++)
|
|
||||||
{
|
|
||||||
_rDescription[i] = description;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBannerLoaderWii::GetDescription(std::wstring& _rDescription)
|
bool CBannerLoaderWii::GetDescription(std::wstring& _rDescription)
|
||||||
{
|
{
|
||||||
if (IsValid())
|
return GetStringFromComments(DESC_IDX, _rDescription);
|
||||||
{
|
|
||||||
// find Banner type
|
|
||||||
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
|
||||||
|
|
||||||
std::wstring description;
|
|
||||||
for (int i = 0; i < WII_BANNER_COMMENT_SIZE; ++i)
|
|
||||||
description.push_back(Common::swap16(pBanner->m_Comment[1][i]));
|
|
||||||
|
|
||||||
_rDescription = description;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height)
|
void CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height)
|
||||||
|
@ -47,9 +47,18 @@ class CBannerLoaderWii
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
#define WII_BANNER_TEXTURE_SIZE (192 * 64 * 2)
|
enum
|
||||||
#define WII_BANNER_ICON_SIZE ( 48 * 48 * 2)
|
{
|
||||||
#define WII_BANNER_COMMENT_SIZE 32
|
TEXTURE_SIZE = 192 * 64 * 2,
|
||||||
|
ICON_SIZE = 48 * 48 * 2,
|
||||||
|
COMMENT_SIZE = 32
|
||||||
|
};
|
||||||
|
|
||||||
|
enum CommentIndex
|
||||||
|
{
|
||||||
|
NAME_IDX,
|
||||||
|
DESC_IDX
|
||||||
|
};
|
||||||
|
|
||||||
struct SWiiBanner
|
struct SWiiBanner
|
||||||
{
|
{
|
||||||
@ -59,9 +68,10 @@ class CBannerLoaderWii
|
|||||||
u16 m_Speed;
|
u16 m_Speed;
|
||||||
u8 m_Unknown[22];
|
u8 m_Unknown[22];
|
||||||
|
|
||||||
u16 m_Comment[2][WII_BANNER_COMMENT_SIZE];
|
// Not null terminated!
|
||||||
u8 m_BannerTexture[WII_BANNER_TEXTURE_SIZE];
|
u16 m_Comment[2][COMMENT_SIZE];
|
||||||
u8 m_IconTexture[8][WII_BANNER_ICON_SIZE];
|
u8 m_BannerTexture[TEXTURE_SIZE];
|
||||||
|
u8 m_IconTexture[8][ICON_SIZE];
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
u8* m_pBannerFile;
|
u8* m_pBannerFile;
|
||||||
@ -69,6 +79,9 @@ class CBannerLoaderWii
|
|||||||
bool m_IsValid;
|
bool m_IsValid;
|
||||||
|
|
||||||
void decode5A3image(u32* dst, u16* src, int width, int height);
|
void decode5A3image(u32* dst, u16* src, int width, int height);
|
||||||
|
|
||||||
|
bool GetStringFromComments(const CommentIndex index, std::string& s);
|
||||||
|
bool GetStringFromComments(const CommentIndex index, std::wstring& s);
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user