IOS: Add ESFormats.{cpp,h}.
This library implements basic parsing support for some of the IOS ES formats we need to extract data from. Currently only implements TMD functions, but some ticket handling functions from DiscIO should likely be moved here in the future.
This commit is contained in:
parent
334ddf754e
commit
0a5cfd8946
|
@ -135,6 +135,7 @@ set(SRCS ActionReplay.cpp
|
|||
HW/WiimoteEmu/Speaker.cpp
|
||||
HW/WiimoteReal/WiimoteReal.cpp
|
||||
HW/WiiSaveCrypted.cpp
|
||||
IPC_HLE/ESFormats.cpp
|
||||
IPC_HLE/ICMPLin.cpp
|
||||
IPC_HLE/NWC24Config.cpp
|
||||
IPC_HLE/WII_IPC_HLE.cpp
|
||||
|
|
|
@ -167,6 +167,7 @@
|
|||
<ClCompile Include="HW\WiimoteReal\WiimoteReal.cpp" />
|
||||
<ClCompile Include="HW\WII_IPC.cpp" />
|
||||
<ClCompile Include="HW\WiiSaveCrypted.cpp" />
|
||||
<ClCompile Include="IPC_HLE\ESFormats.cpp" />
|
||||
<ClCompile Include="IPC_HLE\ICMPWin.cpp" />
|
||||
<ClCompile Include="IPC_HLE\NWC24Config.cpp" />
|
||||
<ClCompile Include="IPC_HLE\WiiMote_HID_Attr.cpp" />
|
||||
|
@ -392,6 +393,7 @@
|
|||
<ClInclude Include="HW\WiimoteReal\WiimoteRealBase.h" />
|
||||
<ClInclude Include="HW\WiiSaveCrypted.h" />
|
||||
<ClInclude Include="HW\WII_IPC.h" />
|
||||
<ClInclude Include="IPC_HLE\ESFormats.h" />
|
||||
<ClInclude Include="IPC_HLE\hci.h" />
|
||||
<ClInclude Include="IPC_HLE\ICMP.h" />
|
||||
<ClInclude Include="IPC_HLE\l2cap.h" />
|
||||
|
|
|
@ -565,6 +565,9 @@
|
|||
<ClCompile Include="DSP\LabelMap.cpp">
|
||||
<Filter>DSPCore</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="IPC_HLE\ESFormats.cpp">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\ES</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="IPC_HLE\WII_IPC_HLE.cpp">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29</Filter>
|
||||
</ClCompile>
|
||||
|
@ -1162,6 +1165,9 @@
|
|||
<ClInclude Include="DSP\LabelMap.h">
|
||||
<Filter>DSPCore</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="IPC_HLE\ESFormats.h">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\ES</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="IPC_HLE\WII_IPC_HLE.h">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/IPC_HLE/ESFormats.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/ChunkFile.h"
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
TMDReader::TMDReader(const std::vector<u8>& bytes) : m_bytes(bytes)
|
||||
{
|
||||
}
|
||||
|
||||
TMDReader::TMDReader(std::vector<u8>&& bytes) : m_bytes(std::move(bytes))
|
||||
{
|
||||
}
|
||||
|
||||
void TMDReader::SetBytes(const std::vector<u8>& bytes)
|
||||
{
|
||||
m_bytes = bytes;
|
||||
}
|
||||
|
||||
void TMDReader::SetBytes(std::vector<u8>&& bytes)
|
||||
{
|
||||
m_bytes = std::move(bytes);
|
||||
}
|
||||
|
||||
bool TMDReader::IsValid() const
|
||||
{
|
||||
if (m_bytes.size() < 0x1E4)
|
||||
{
|
||||
// TMD is too small to contain its base fields.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_bytes.size() < 0x1E4 + GetNumContents() * 36u)
|
||||
{
|
||||
// TMD is too small to contain all its expected content entries.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
u64 TMDReader::GetTitleId() const
|
||||
{
|
||||
return Common::swap64(m_bytes.data() + 0x18C);
|
||||
}
|
||||
|
||||
u16 TMDReader::GetNumContents() const
|
||||
{
|
||||
return Common::swap16(m_bytes.data() + 0x1DE);
|
||||
}
|
||||
|
||||
bool TMDReader::GetContent(u16 index, Content* content) const
|
||||
{
|
||||
if (index >= GetNumContents())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const u8* content_base = m_bytes.data() + 0x1E4 + index * 36;
|
||||
content->id = Common::swap32(content_base);
|
||||
content->index = Common::swap16(content_base + 4);
|
||||
content->type = Common::swap16(content_base + 6);
|
||||
content->size = Common::swap64(content_base + 8);
|
||||
std::copy(content_base + 16, content_base + 36, content->sha1.begin());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TMDReader::FindContentById(u32 id, Content* content) const
|
||||
{
|
||||
for (u16 index = 0; index < GetNumContents(); ++index)
|
||||
{
|
||||
if (!GetContent(index, content))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (content->id == id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TMDReader::DoState(PointerWrap& p)
|
||||
{
|
||||
p.Do(m_bytes);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
// Utilities to manipulate files and formats from the Wii's ES module: tickets,
|
||||
// TMD, and other title informations.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/ChunkFile.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
class TMDReader final
|
||||
{
|
||||
public:
|
||||
TMDReader() = default;
|
||||
explicit TMDReader(const std::vector<u8>& bytes);
|
||||
explicit TMDReader(std::vector<u8>&& bytes);
|
||||
|
||||
void SetBytes(const std::vector<u8>& bytes);
|
||||
void SetBytes(std::vector<u8>&& bytes);
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
u64 GetTitleId() const;
|
||||
|
||||
struct Content
|
||||
{
|
||||
u32 id;
|
||||
u16 index;
|
||||
u16 type;
|
||||
u64 size;
|
||||
std::array<u8, 20> sha1;
|
||||
};
|
||||
u16 GetNumContents() const;
|
||||
bool GetContent(u16 index, Content* content) const;
|
||||
bool FindContentById(u32 id, Content* content) const;
|
||||
|
||||
void DoState(PointerWrap& p);
|
||||
|
||||
private:
|
||||
std::vector<u8> m_bytes;
|
||||
};
|
Loading…
Reference in New Issue