Skip to content

Commit

Permalink
align memory regions; zero out before injecting code
Browse files Browse the repository at this point in the history
  • Loading branch information
sherman5 committed Feb 10, 2017
1 parent 694c456 commit d25558f
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
13 changes: 11 additions & 2 deletions src/ArgumentParsing/Arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@
#include <vector>
#include <string>
#include <utility>
#include <cmath>

/* 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;
Expand Down
16 changes: 16 additions & 0 deletions src/HighLevel/Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
3 changes: 3 additions & 0 deletions src/HighLevel/HighLevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion src/ISO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ void ISO::loadState(std::string fileName)
}

/* inject code into iso */
void ISO::injectCode(std::vector< std::pair<uint32_t, uint32_t> >& code)
void ISO::injectCode(const std::vector< std::pair<uint32_t, uint32_t> >&
code)
{
/* loop through code and write each (address, value) pair */
for (auto& line : code)
Expand Down
2 changes: 1 addition & 1 deletion src/ISO.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ISO
void loadState(std::string);

/* inject code into iso */
void injectCode(std::vector< std::pair<uint32_t, uint32_t> >&);
void injectCode(const std::vector< std::pair<uint32_t, uint32_t> >&);
};

#endif
4 changes: 2 additions & 2 deletions src/MainProgram/wiimake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d25558f

Please sign in to comment.