Update address for __C_specific_handler

This commit is contained in:
Sajid 2024-09-18 13:29:08 +06:00
parent 35560a0cd0
commit 6057ffe167
2 changed files with 126 additions and 121 deletions

View File

@ -198,147 +198,147 @@ int main()
//auto op = PPC_OP(insn.instruction);
//auto xop = PPC_XOP(insn.instruction);
auto printTable = [&](const SwitchTable& table)
{
println("[[switch]]");
println("base = 0x{:X}", table.base);
println("r = {}", table.r);
println("default = 0x{:X}", table.defaultLabel);
println("labels = [");
for (const auto& label : table.labels)
{
println(" 0x{:X},", label);
}
//auto printTable = [&](const SwitchTable& table)
// {
// println("[[switch]]");
// println("base = 0x{:X}", table.base);
// println("r = {}", table.r);
// println("default = 0x{:X}", table.defaultLabel);
// println("labels = [");
// for (const auto& label : table.labels)
// {
// println(" 0x{:X},", label);
// }
println("]");
println("");
};
// println("]");
// println("");
// };
std::vector<SwitchTable> switches{};
//std::vector<SwitchTable> switches{};
auto insertTable = [&](size_t base, size_t defaultLabel, size_t r, size_t nLabels, uint32_t type)
{
auto& sw = switches.emplace_back();
sw.base = base;
sw.defaultLabel = defaultLabel;
sw.r = r;
sw.labels.resize(nLabels);
sw.type = type;
};
//auto insertTable = [&](size_t base, size_t defaultLabel, size_t r, size_t nLabels, uint32_t type)
// {
// auto& sw = switches.emplace_back();
// sw.base = base;
// sw.defaultLabel = defaultLabel;
// sw.r = r;
// sw.labels.resize(nLabels);
// sw.type = type;
// };
println("# Generated by PowerAnalyse");
insertTable(0x830ADAD8, 0x830ADB28, 11, 0x1B, SWITCH_COMPUTED);
insertTable(0x830AE1B0, 0x830AE21C, 11, 0x1B, SWITCH_BYTEOFFSET);
insertTable(0x82CFE120, 0x82CFDE68, 11, 0x10, SWITCH_SHORTOFFSET);
//println("# Generated by PowerAnalyse");
//insertTable(0x830ADAD8, 0x830ADB28, 11, 0x1B, SWITCH_COMPUTED);
//insertTable(0x830AE1B0, 0x830AE21C, 11, 0x1B, SWITCH_BYTEOFFSET);
//insertTable(0x82CFE120, 0x82CFDE68, 11, 0x10, SWITCH_SHORTOFFSET);
println("# ---- MANUAL JUMPTABLE ----");
for (auto& table : switches)
{
ReadTable(image, table);
printTable(table);
}
//println("# ---- MANUAL JUMPTABLE ----");
//for (auto& table : switches)
//{
// ReadTable(image, table);
// printTable(table);
//}
auto scanPattern = [&](uint32_t* pattern, size_t count, size_t type)
{
for (const auto& section : image.sections)
{
if (!(section.flags & SectionFlags_Code))
{
continue;
}
//auto scanPattern = [&](uint32_t* pattern, size_t count, size_t type)
// {
// for (const auto& section : image.sections)
// {
// if (!(section.flags & SectionFlags_Code))
// {
// continue;
// }
size_t base = section.base;
uint8_t* data = section.data;
uint8_t* dataStart = section.data;
uint8_t* dataEnd = section.data + section.size;
while (data < dataEnd && data != nullptr)
{
data = (uint8_t*)SearchMask(data, pattern, count, dataEnd - data);
// size_t base = section.base;
// uint8_t* data = section.data;
// uint8_t* dataStart = section.data;
// uint8_t* dataEnd = section.data + section.size;
// while (data < dataEnd && data != nullptr)
// {
// data = (uint8_t*)SearchMask(data, pattern, count, dataEnd - data);
if (data != nullptr)
{
SwitchTable table{};
table.type = type;
ScanTable((uint32_t*)data, base + (data - dataStart), table);
// if (data != nullptr)
// {
// SwitchTable table{};
// table.type = type;
// ScanTable((uint32_t*)data, base + (data - dataStart), table);
// std::println("{:X} ; jmptable - {}", base + (data - dataStart), table.labels.size());
if (table.base != 0)
{
ReadTable(image, table);
printTable(table);
switches.emplace_back(std::move(table));
}
// // std::println("{:X} ; jmptable - {}", base + (data - dataStart), table.labels.size());
// if (table.base != 0)
// {
// ReadTable(image, table);
// printTable(table);
// switches.emplace_back(std::move(table));
// }
data += 4;
}
continue;
}
}
};
// data += 4;
// }
// continue;
// }
// }
// };
uint32_t absoluteSwitch[] =
{
PPC_INST_LIS,
PPC_INST_ADDI,
PPC_INST_RLWINM,
PPC_INST_LWZX,
PPC_INST_MTCTR,
PPC_INST_BCTR,
};
//uint32_t absoluteSwitch[] =
//{
// PPC_INST_LIS,
// PPC_INST_ADDI,
// PPC_INST_RLWINM,
// PPC_INST_LWZX,
// PPC_INST_MTCTR,
// PPC_INST_BCTR,
//};
uint32_t computedSwitch[] =
{
PPC_INST_LIS,
PPC_INST_ADDI,
PPC_INST_LBZX,
PPC_INST_RLWINM,
PPC_INST_LIS,
PPC_INST_ADDI,
PPC_INST_ADD,
PPC_INST_MTCTR,
};
//uint32_t computedSwitch[] =
//{
// PPC_INST_LIS,
// PPC_INST_ADDI,
// PPC_INST_LBZX,
// PPC_INST_RLWINM,
// PPC_INST_LIS,
// PPC_INST_ADDI,
// PPC_INST_ADD,
// PPC_INST_MTCTR,
//};
uint32_t offsetSwitch[] =
{
PPC_INST_LIS,
PPC_INST_ADDI,
PPC_INST_LBZX,
PPC_INST_LIS,
PPC_INST_ADDI,
PPC_INST_ADD,
PPC_INST_MTCTR,
};
//uint32_t offsetSwitch[] =
//{
// PPC_INST_LIS,
// PPC_INST_ADDI,
// PPC_INST_LBZX,
// PPC_INST_LIS,
// PPC_INST_ADDI,
// PPC_INST_ADD,
// PPC_INST_MTCTR,
//};
uint32_t wordOffsetSwitch[] =
{
PPC_INST_LIS,
PPC_INST_ADDI,
PPC_INST_RLWINM,
PPC_INST_LHZX,
PPC_INST_LIS,
PPC_INST_ADDI,
PPC_INST_ADD,
PPC_INST_MTCTR,
};
//uint32_t wordOffsetSwitch[] =
//{
// PPC_INST_LIS,
// PPC_INST_ADDI,
// PPC_INST_RLWINM,
// PPC_INST_LHZX,
// PPC_INST_LIS,
// PPC_INST_ADDI,
// PPC_INST_ADD,
// PPC_INST_MTCTR,
//};
println("# ---- ABSOLUTE JUMPTABLE ----");
scanPattern(absoluteSwitch, std::size(absoluteSwitch), SWITCH_ABSOLUTE);
//println("# ---- ABSOLUTE JUMPTABLE ----");
//scanPattern(absoluteSwitch, std::size(absoluteSwitch), SWITCH_ABSOLUTE);
println("# ---- COMPUTED JUMPTABLE ----");
scanPattern(computedSwitch, std::size(computedSwitch), SWITCH_COMPUTED);
//println("# ---- COMPUTED JUMPTABLE ----");
//scanPattern(computedSwitch, std::size(computedSwitch), SWITCH_COMPUTED);
println("# ---- OFFSETED JUMPTABLE ----");
scanPattern(offsetSwitch, std::size(offsetSwitch), SWITCH_BYTEOFFSET);
scanPattern(wordOffsetSwitch, std::size(wordOffsetSwitch), SWITCH_SHORTOFFSET);
//println("# ---- OFFSETED JUMPTABLE ----");
//scanPattern(offsetSwitch, std::size(offsetSwitch), SWITCH_BYTEOFFSET);
//scanPattern(wordOffsetSwitch, std::size(wordOffsetSwitch), SWITCH_SHORTOFFSET);
FILE* f = fopen("out/switches.toml", "w");
fwrite(out.data(), 1, out.size(), f);
fclose(f);
//FILE* f = fopen("out/switches.toml", "w");
//fwrite(out.data(), 1, out.size(), f);
//fclose(f);
uint32_t cxxFrameHandler = std::byteswap(0x831B1C90);
uint32_t cSpecificFrameHandler = std::byteswap(0x8324B3BC);
image.symbols.emplace("__CxxFrameHandler", 0x831B1C90, 0x38, Symbol_Function);
image.symbols.emplace("__C_specific_handler", 0x82BD7780, 0x38, Symbol_Function);
image.symbols.emplace("__C_specific_handler", 0x8324B3BC, 0x38, Symbol_Function);
image.symbols.emplace("memcpy", 0x831B0ED0, 0x488, Symbol_Function);
image.symbols.emplace("memset", 0x831B0BA0, 0xA0, Symbol_Function);
image.symbols.emplace("blkmov", 0x831B1358, 0xA8, Symbol_Function);
@ -361,10 +361,15 @@ int main()
f.base = fn.BeginAddress;
f.size = fn.FunctionLength * 4;
if (f.base == 0x82BD7420)
{
__debugbreak();
}
image.symbols.emplace(std::format("sub_{:X}", f.base), f.base, f.size, Symbol_Function);
}
auto sym = image.symbols.find(0x82C40D58);
auto sym = image.symbols.find(0x82BD7420);
std::vector<Function> missingFunctions;
for (const auto& section : image.sections)

View File

@ -28,7 +28,7 @@ int main()
uint32_t cxxFrameHandler = std::byteswap(0x831B1C90);
uint32_t cSpecificFrameHandler = std::byteswap(0x8324B3BC);
image.symbols.emplace("__CxxFrameHandler", 0x831B1C90, 0x38, Symbol_Function);
image.symbols.emplace("__C_specific_handler", 0x82BD7780, 0x38, Symbol_Function);
image.symbols.emplace("__C_specific_handler", 0x8324B3BC, 0x38, Symbol_Function);
image.symbols.emplace("__memcpy", 0x831B0ED0, 0x488, Symbol_Function);
image.symbols.emplace("__memset", 0x831B0BA0, 0xA0, Symbol_Function);
image.symbols.emplace("__blkmov", 0x831B1358, 0xA8, Symbol_Function);