| 151 | } |
| 152 | |
| 153 | BinaryPatch::State BinaryPatch::checkState(const patch_byte *ptr, size_t len) |
| 154 | { |
| 155 | int state = 0; |
| 156 | |
| 157 | for (size_t i = 0; i < entries.size(); i++) |
| 158 | { |
| 159 | Byte &bv = entries[i]; |
| 160 | |
| 161 | if (bv.offset >= len) |
| 162 | { |
| 163 | cerr << "Offset out of range: 0x" << std::hex << bv.offset << std::dec << endl; |
| 164 | return Conflict; |
| 165 | } |
| 166 | |
| 167 | patch_byte cv = ptr[bv.offset]; |
| 168 | if (bv.old_val == cv) |
| 169 | state |= Unapplied; |
| 170 | else if (bv.new_val == cv) |
| 171 | state |= Applied; |
| 172 | else |
| 173 | { |
| 174 | cerr << std::hex << bv.offset << ": " |
| 175 | << unsigned(bv.old_val) << " " << unsigned(bv.new_val) |
| 176 | << ", but currently " << unsigned(cv) << std::dec << endl; |
| 177 | return Conflict; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | return State(state); |
| 182 | } |
| 183 | |
| 184 | void BinaryPatch::apply(patch_byte *ptr, size_t len, bool newv) |
| 185 | { |