Skip to content

Commit

Permalink
sort usings in gscd
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Nov 24, 2024
1 parent 82e12a0 commit 4c90872
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/acts/tools/gsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ bool GscInfoOption::Compute(const char** args, INT startIndex, INT endIndex) {
else if (!_strcmpi("--path-output", arg)) {
m_usePathOutput = true;
}
else if (!_strcmpi("--no-usings-sort", arg)) {
m_noUsingsSort = true;
}
else if (!strcmp("-s", arg) || !_strcmpi("--skip-data", arg)) {
m_dumpSkipData = true;
}
Expand Down Expand Up @@ -371,6 +374,7 @@ void GscInfoOption::PrintHelp() {
LOG_DEBUG("--internalnames : Print asm nodes internal names");
LOG_DEBUG("--rawhash : Add raw hashes to export dump");
LOG_DEBUG("--no-path : No path extraction");
LOG_DEBUG("--no-usings-sort : No usings sort");
LOG_DEBUG("--ignore-dbg-plt : ignore debug platform info");
LOG_DEBUG("-A --sync [mode] : Sync mode: async or sync");
LOG_DEBUG("--vtable : Do not hide and decompile vtable functions");
Expand Down Expand Up @@ -1702,8 +1706,9 @@ int GscInfoHandleData(byte* data, size_t size, std::filesystem::path fsPath, Gsc
}
}

if (opt.m_includes && scriptfile->GetIncludesOffset()) {
if (opt.m_includes && scriptfile->GetIncludesOffset() && scriptfile->GetIncludesCount()) {
uint32_t includeOffset = scriptfile->GetIncludesOffset();
std::vector<std::string> usingsList{};
if (scriptfile->HasFlag(GOHF_STRING_NAMES)) {
if (includeOffset + scriptfile->GetIncludesCount() * sizeof(uint32_t) > scriptfile->GetFileSize()) {
LOG_ERROR("Invalid include offset 0x{:x} > 0x{:x}", includeOffset, scriptfile->GetFileSize());
Expand All @@ -1716,10 +1721,8 @@ int GscInfoHandleData(byte* data, size_t size, std::filesystem::path fsPath, Gsc
LOG_ERROR("Invalid include string offset 0x{:x} > 0x{:x}", includes[i], scriptfile->GetFileSize());
return tool::BASIC_ERROR;
}
asmout << "#using " << scriptfile->Ptr<char>(includes[i]) << ";\n";
}
if (scriptfile->GetIncludesCount()) {
asmout << "\n";
//asmout << "#using " << scriptfile->Ptr<char>(includes[i]) << ";\n";
usingsList.emplace_back(scriptfile->Ptr<char>(includes[i]));
}
}
else {
Expand All @@ -1744,23 +1747,31 @@ int GscInfoHandleData(byte* data, size_t size, std::filesystem::path fsPath, Gsc
}
}

asmout << "#using " << usingName << ";\n";
usingsList.emplace_back(usingName);
//asmout << "#using " << usingName << ";\n";

if (opt.m_debugHashes) {
const char* incExt{ hashutils::ExtractPtr(includes[i]) };
if (incExt) {
uint64_t hashPath{ ctx.m_vmInfo->HashPath(incExt) };

if (hashPath != includes[i] && gdctx.WarningType(GDGCW_BAD_HASH_PATH_INCLUDE)) {
LOG_WARNING("Invalid hash alogithm for extracted include 0x{:x} != 0x{:x} for {}", includes[i], hashPath, incExt);
LOG_WARNING("Invalid hash algorithm for extracted include 0x{:x} != 0x{:x} for {}", includes[i], hashPath, incExt);
}
}
}
}
if (scriptfile->GetIncludesCount()) {
asmout << "\n";
}
}
// better rendering, but not really good for debug
if (!opt.m_noUsingsSort) {
std::sort(usingsList.begin(), usingsList.end());
}

for (const std::string& usingName : usingsList) {
asmout << "#using " << usingName << ";\n";
}

asmout << "\n";
}

asmout
Expand Down
1 change: 1 addition & 0 deletions src/acts/tools/gsc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ namespace tool::gsc {
bool m_debugHashes{};
bool m_usePathOutput{};
bool m_dumpSkipData{};
bool m_noUsingsSort{};
const char* vtable_dump{};
uint32_t m_stepskip{};
opcode::Platform m_platform{ opcode::Platform::PLATFORM_PC };
Expand Down

0 comments on commit 4c90872

Please sign in to comment.