diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2020-05-26 14:22:17 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2020-05-26 14:22:17 -0400 |
commit | afbc33d68cd773c273bfbf744c7485d427f03e2e (patch) | |
tree | 4eec6a0d7003d29a27413248848543351796ee7f | |
parent | 7a89e3397b920c7ba78a02c310e87d1acf6b203e (diff) |
Bikeshedding update of calcrom.cpp; sign calcrom.cpp
-rw-r--r-- | .travis/calcrom/calcrom.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/.travis/calcrom/calcrom.cpp b/.travis/calcrom/calcrom.cpp index 3f48511b..8b43e010 100644 --- a/.travis/calcrom/calcrom.cpp +++ b/.travis/calcrom/calcrom.cpp @@ -1,3 +1,19 @@ +/* + * CALCROM.CPP + * © PikalaxALT 2020 + * + * Simple C++ executable to measure the completion rate of Pokémon Diamond + * reverse engineering (decompilation). + * + * Requirements: + * - Must have C++11 compliant compiler. + * - MacOS X: Must provide elf.h on the include (-I) path. + * - Must be placed in ".travis/calcrom/". + * + * Changelog: + * - 1.0 (26 May 2020): Initial implementation + */ + #include <iostream> #include <fstream> #include <sstream> @@ -13,10 +29,10 @@ struct Glob : public vector<char const *> { glob_t glob_result; public: Glob(string const & pattern) { - int result = ::glob(pattern.c_str(), GLOB_TILDE | GLOB_BRACE, NULL, &glob_result); + int result = glob(pattern.c_str(), GLOB_TILDE | GLOB_BRACE, NULL, &glob_result); if (result) { stringstream ss; - ss << "Glob::glob(" << pattern << ") failed with error " << result << endl; + ss << "Glob(" << pattern << ") failed with error " << result << endl; throw runtime_error(ss.str()); } assign(glob_result.gl_pathv, glob_result.gl_pathv + glob_result.gl_pathc); @@ -30,8 +46,7 @@ int main() { fstream elf; Elf32_Ehdr ehdr; - Elf32_Shdr shdr_buf; - vector<Elf32_Shdr> shdr(0); + vector<Elf32_Shdr> shdr; // Accumulate sizes // src asm @@ -59,6 +74,7 @@ int main() elf.seekg(ehdr.e_shoff); shdr.resize(ehdr.e_shnum); elf.read((char *)shdr.data(), ehdr.e_shnum * ehdr.e_shentsize); + // Read .shstrtab if (shstrsz < shdr[ehdr.e_shstrndx].sh_size) { shstrtab = (char *)realloc(shstrtab, shdr[ehdr.e_shstrndx].sh_size); @@ -67,6 +83,8 @@ int main() elf.seekg(shdr[ehdr.e_shstrndx].sh_offset); elf.read(shstrtab, shdr[ehdr.e_shstrndx].sh_size); elf.close(); + + // Analyze sections for (Elf32_Shdr & hdr : shdr) { string shname = shstrtab + hdr.sh_name; bool is_text = (shname == ".text" || shname == ".init"); |