diff --git a/CMakeLists.txt b/CMakeLists.txt index c3b64dc..b69e015 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ project (WiiMake) # project version set (WiiMake_VERSION_MAJOR 1) set (WiiMake_VERSION_MINOR 1) -set (WiiMake_VERSION_REVISION 2) +set (WiiMake_VERSION_REVISION 3) # create header for version number configure_file ( diff --git a/changelog.md b/changelog.md index f311a10..56a5adc 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,15 @@ # Change Log This documents all differences between versions of the program +## [1.1.3] - 2/10/17 +### Added + +- memory regions given in config file are aligned to + multiples of 0x4 +- memory regions are zereod out before code is injected + +### Changed + ## [1.1.2] - 2/5/17 ### Added diff --git a/src/ArgumentParsing/Arguments.h b/src/ArgumentParsing/Arguments.h index bd18479..e417fbf 100644 --- a/src/ArgumentParsing/Arguments.h +++ b/src/ArgumentParsing/Arguments.h @@ -5,17 +5,26 @@ #include #include #include +#include /* single region of memory (struct used for sorting) */ struct MemRegion { uint32_t start, end; - MemRegion(uint32_t a, uint32_t b) : start(a), end(b) {} + MemRegion(uint32_t a, uint32_t b) : start(a), end(b) + {align();} MemRegion(std::string a, std::string b) : - start(stoul(a, nullptr, 16)), end(stoul(b, nullptr, 16)) {} + start(stoul(a, nullptr, 16)), end(stoul(b, nullptr, 16)) + {align();} + void align() + { + start = 4 * floor((double) start / 4.0) + 4; + end = 4 * floor((double) end / 4.0) - 4; + } + bool operator<(const MemRegion& other) { return end - start < other.end - other.start; diff --git a/src/HighLevel/Builder.cpp b/src/HighLevel/Builder.cpp index 9cf7374..0b5dd44 100644 --- a/src/HighLevel/Builder.cpp +++ b/src/HighLevel/Builder.cpp @@ -108,6 +108,22 @@ SectionList& sections) } } +/* get regions of memory to zero out */ +ASMcode Builder::getZeroedMemory(Arguments& args) +{ + ASMcode zereodMem; + + for (auto& region : args.memRegions) + { + uint32_t address = region.start; + for (; address <= region.end; address += 0x04) + { + zereodMem.push_back(std::make_pair(address, 0)); + } + } + return zereodMem; +} + /* remove all temporary files created in the build process */ void Builder::cleanDirectory() { diff --git a/src/HighLevel/HighLevel.h b/src/HighLevel/HighLevel.h index 478b7b6..ca9e4f7 100644 --- a/src/HighLevel/HighLevel.h +++ b/src/HighLevel/HighLevel.h @@ -34,6 +34,9 @@ namespace Builder /* add original instruction, overwrite nop line in code */ void addOverwrittenASM(ASMcode&, Arguments&, SectionList&); + /* get regions of memory to zero out */ + ASMcode getZeroedMemory(Arguments&); + /* remove all temporary files created in the build process */ void cleanDirectory(); } diff --git a/src/ISO.cpp b/src/ISO.cpp index ede0447..dfa3090 100644 --- a/src/ISO.cpp +++ b/src/ISO.cpp @@ -177,7 +177,8 @@ void ISO::loadState(std::string fileName) } /* inject code into iso */ -void ISO::injectCode(std::vector< std::pair >& code) +void ISO::injectCode(const std::vector< std::pair >& +code) { /* loop through code and write each (address, value) pair */ for (auto& line : code) diff --git a/src/ISO.h b/src/ISO.h index 5b80c2d..57d7f41 100644 --- a/src/ISO.h +++ b/src/ISO.h @@ -64,7 +64,7 @@ class ISO void loadState(std::string); /* inject code into iso */ - void injectCode(std::vector< std::pair >&); + void injectCode(const std::vector< std::pair >&); }; #endif diff --git a/src/MainProgram/wiimake.cpp b/src/MainProgram/wiimake.cpp index 8b99b7a..d06ec4a 100644 --- a/src/MainProgram/wiimake.cpp +++ b/src/MainProgram/wiimake.cpp @@ -22,8 +22,8 @@ void run(TokenList& tokens) /* inject code into iso */ iso.injectCode(args.staticOverwrites); - auto code = Builder::getASM(args); - iso.injectCode(code); + iso.injectCode(Builder::getZeroedMemory(args)); + iso.injectCode(Builder::getASM(args)); } int main(int argc, const char** argv)