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

View File

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