improve diff-dol-files
This commit is contained in:
@@ -5,10 +5,16 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
struct DiffEntry {
|
||||||
|
uint32_t address;
|
||||||
|
std::string a_data;
|
||||||
|
std::string b_data;
|
||||||
|
};
|
||||||
|
|
||||||
inline void run_address_translator(const std::string&, const std::string&, const std::string&) {
|
inline void run_address_translator(const std::string&, const std::string&, const std::string&) {
|
||||||
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
|
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::vector<std::pair<uint32_t, std::string>> diff_dol_files(const std::string&, const std::string&) {
|
inline std::vector<DiffEntry> diff_dol_files(const std::string&, const std::string&) {
|
||||||
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
|
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -253,8 +253,8 @@ public:
|
|||||||
phosg::StringReader src_r = this->src_mem->reader(src_section.first + src_offset - match_bytes_before, match_length);
|
phosg::StringReader src_r = this->src_mem->reader(src_section.first + src_offset - match_bytes_before, match_length);
|
||||||
for (const auto& dest_section : dest_mem->allocated_blocks()) {
|
for (const auto& dest_section : dest_mem->allocated_blocks()) {
|
||||||
for (size_t dest_match_offset = 0;
|
for (size_t dest_match_offset = 0;
|
||||||
dest_match_offset + match_length < dest_section.second;
|
dest_match_offset + match_length < dest_section.second;
|
||||||
dest_match_offset += (is_ppc ? 4 : 1)) {
|
dest_match_offset += (is_ppc ? 4 : 1)) {
|
||||||
src_r.go(0);
|
src_r.go(0);
|
||||||
phosg::StringReader dest_r = dest_mem->reader(dest_section.first + dest_match_offset, match_length);
|
phosg::StringReader dest_r = dest_mem->reader(dest_section.first + dest_match_offset, match_length);
|
||||||
size_t z;
|
size_t z;
|
||||||
@@ -468,8 +468,8 @@ public:
|
|||||||
phosg::StringReader src_r = this->src_mem->reader(src_addr, match_length);
|
phosg::StringReader src_r = this->src_mem->reader(src_addr, match_length);
|
||||||
for (const auto& dest_section : dest_mem->allocated_blocks()) {
|
for (const auto& dest_section : dest_mem->allocated_blocks()) {
|
||||||
for (size_t dest_match_offset = 0;
|
for (size_t dest_match_offset = 0;
|
||||||
dest_match_offset + match_length < dest_section.second;
|
dest_match_offset + match_length < dest_section.second;
|
||||||
dest_match_offset += 4) {
|
dest_match_offset += 4) {
|
||||||
src_r.go(0);
|
src_r.go(0);
|
||||||
phosg::StringReader dest_r = dest_mem->reader(dest_section.first + dest_match_offset, match_length);
|
phosg::StringReader dest_r = dest_mem->reader(dest_section.first + dest_match_offset, match_length);
|
||||||
size_t z;
|
size_t z;
|
||||||
@@ -623,7 +623,7 @@ void run_address_translator(const std::string& directory, const std::string& use
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<pair<uint32_t, string>> diff_dol_files(const string& a_filename, const string& b_filename) {
|
vector<DiffEntry> diff_dol_files(const string& a_filename, const string& b_filename) {
|
||||||
ResourceDASM::DOLFile a(a_filename.c_str());
|
ResourceDASM::DOLFile a(a_filename.c_str());
|
||||||
ResourceDASM::DOLFile b(b_filename.c_str());
|
ResourceDASM::DOLFile b(b_filename.c_str());
|
||||||
auto a_mem = make_shared<ResourceDASM::MemoryContext>();
|
auto a_mem = make_shared<ResourceDASM::MemoryContext>();
|
||||||
@@ -642,7 +642,7 @@ vector<pair<uint32_t, string>> diff_dol_files(const string& a_filename, const st
|
|||||||
max_addr = max<uint32_t>(max_addr, sec.address + sec.data.size());
|
max_addr = max<uint32_t>(max_addr, sec.address + sec.data.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<pair<uint32_t, string>> ret;
|
vector<DiffEntry> ret;
|
||||||
for (uint32_t addr = min_addr; addr < max_addr; addr += 4) {
|
for (uint32_t addr = min_addr; addr < max_addr; addr += 4) {
|
||||||
bool a_exists = a_mem->exists(addr, 4);
|
bool a_exists = a_mem->exists(addr, 4);
|
||||||
bool b_exists = b_mem->exists(addr, 4);
|
bool b_exists = b_mem->exists(addr, 4);
|
||||||
@@ -650,10 +650,11 @@ vector<pair<uint32_t, string>> diff_dol_files(const string& a_filename, const st
|
|||||||
string a_value = a_mem->read(addr, 4);
|
string a_value = a_mem->read(addr, 4);
|
||||||
string b_value = b_mem->read(addr, 4);
|
string b_value = b_mem->read(addr, 4);
|
||||||
if (a_value != b_value) {
|
if (a_value != b_value) {
|
||||||
if (!ret.empty() && (ret.back().first + ret.back().second.size() == addr)) {
|
if (!ret.empty() && (ret.back().address + ret.back().b_data.size() == addr)) {
|
||||||
ret.back().second += b_value;
|
ret.back().a_data += a_value;
|
||||||
|
ret.back().b_data += b_value;
|
||||||
} else {
|
} else {
|
||||||
ret.emplace_back(make_pair(addr, b_value));
|
ret.emplace_back(DiffEntry{.address = addr, .a_data = a_value, .b_data = b_value});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,11 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
struct DiffEntry {
|
||||||
|
uint32_t address;
|
||||||
|
std::string a_data;
|
||||||
|
std::string b_data;
|
||||||
|
};
|
||||||
|
|
||||||
void run_address_translator(const std::string& directory, const std::string& use_filename, const std::string& command);
|
void run_address_translator(const std::string& directory, const std::string& use_filename, const std::string& command);
|
||||||
std::vector<std::pair<uint32_t, std::string>> diff_dol_files(const std::string& a_filename, const std::string& b_filename);
|
std::vector<DiffEntry> diff_dol_files(const std::string& a_filename, const std::string& b_filename);
|
||||||
|
|||||||
+8
-2
@@ -2858,10 +2858,16 @@ Action a_diff_dol_files(
|
|||||||
"diff-dol-files", nullptr, +[](phosg::Arguments& args) {
|
"diff-dol-files", nullptr, +[](phosg::Arguments& args) {
|
||||||
const string& a_filename = args.get<string>(1);
|
const string& a_filename = args.get<string>(1);
|
||||||
const string& b_filename = args.get<string>(2);
|
const string& b_filename = args.get<string>(2);
|
||||||
|
bool show_pre = args.get<bool>("show-pre");
|
||||||
auto result = diff_dol_files(a_filename, b_filename);
|
auto result = diff_dol_files(a_filename, b_filename);
|
||||||
for (const auto& it : result) {
|
for (const auto& it : result) {
|
||||||
string data = phosg::format_data_string(it.second, nullptr, phosg::FormatDataFlags::HEX_ONLY);
|
string b_str = phosg::format_data_string(it.b_data, nullptr, phosg::FormatDataFlags::HEX_ONLY);
|
||||||
fprintf(stdout, "%08" PRIX32 " %s\n", it.first, data.c_str());
|
if (show_pre) {
|
||||||
|
string a_str = phosg::format_data_string(it.a_data, nullptr, phosg::FormatDataFlags::HEX_ONLY);
|
||||||
|
fprintf(stdout, "%08" PRIX32 ": %s => %s\n", it.address, a_str.c_str(), b_str.c_str());
|
||||||
|
} else {
|
||||||
|
fprintf(stdout, "%08" PRIX32 " %s\n", it.address, b_str.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user