CBoot: Use vectors instead of raw pointers in ELF functions.
This commit is contained in:
parent
64b21a4812
commit
edd63c14a4
|
@ -15,11 +15,11 @@ bool CBoot::IsElfWii(const std::string& filename)
|
||||||
there is no need for another check, just read the file right away */
|
there is no need for another check, just read the file right away */
|
||||||
|
|
||||||
const u64 filesize = File::GetSize(filename);
|
const u64 filesize = File::GetSize(filename);
|
||||||
u8 *const mem = new u8[(size_t)filesize];
|
std::vector<u8> mem((size_t)filesize);
|
||||||
|
|
||||||
{
|
{
|
||||||
File::IOFile f(filename, "rb");
|
File::IOFile f(filename, "rb");
|
||||||
f.ReadBytes(mem, (size_t)filesize);
|
f.ReadBytes(mem.data(), (size_t)filesize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the same method as the DOL loader uses: search for mfspr from HID4,
|
// Use the same method as the DOL loader uses: search for mfspr from HID4,
|
||||||
|
@ -30,8 +30,7 @@ bool CBoot::IsElfWii(const std::string& filename)
|
||||||
|
|
||||||
u32 HID4_pattern = 0x7c13fba6;
|
u32 HID4_pattern = 0x7c13fba6;
|
||||||
u32 HID4_mask = 0xfc1fffff;
|
u32 HID4_mask = 0xfc1fffff;
|
||||||
ElfReader reader(mem);
|
ElfReader reader(mem.data());
|
||||||
bool isWii = false;
|
|
||||||
|
|
||||||
for (int i = 0; i < reader.GetNumSections(); ++i)
|
for (int i = 0; i < reader.GetNumSections(); ++i)
|
||||||
{
|
{
|
||||||
|
@ -42,29 +41,27 @@ bool CBoot::IsElfWii(const std::string& filename)
|
||||||
u32 word = Common::swap32(((u32*)reader.GetSectionDataPtr(i))[j]);
|
u32 word = Common::swap32(((u32*)reader.GetSectionDataPtr(i))[j]);
|
||||||
if ((word & HID4_mask) == HID4_pattern)
|
if ((word & HID4_mask) == HID4_pattern)
|
||||||
{
|
{
|
||||||
isWii = true;
|
return true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] mem;
|
return false;
|
||||||
return isWii;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CBoot::Boot_ELF(const std::string& filename)
|
bool CBoot::Boot_ELF(const std::string& filename)
|
||||||
{
|
{
|
||||||
const u64 filesize = File::GetSize(filename);
|
const u64 filesize = File::GetSize(filename);
|
||||||
u8 *mem = new u8[(size_t)filesize];
|
std::vector<u8> mem((size_t)filesize);
|
||||||
|
|
||||||
{
|
{
|
||||||
File::IOFile f(filename, "rb");
|
File::IOFile f(filename, "rb");
|
||||||
f.ReadBytes(mem, (size_t)filesize);
|
f.ReadBytes(mem.data(), (size_t)filesize);
|
||||||
}
|
}
|
||||||
|
|
||||||
ElfReader reader(mem);
|
ElfReader reader(mem.data());
|
||||||
reader.LoadInto(0x80000000);
|
reader.LoadInto(0x80000000);
|
||||||
if (!reader.LoadSymbols())
|
if (!reader.LoadSymbols())
|
||||||
{
|
{
|
||||||
|
@ -77,7 +74,6 @@ bool CBoot::Boot_ELF(const std::string& filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
PC = reader.GetEntryPoint();
|
PC = reader.GetEntryPoint();
|
||||||
delete[] mem;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue