MCPcopy Create free account
hub / github.com/DFHack/dfhack / main

Function main

library/binpatch.cpp:234–315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232}
233
234int main (int argc, char *argv[])
235{
236 if (argc <= 3)
237 {
238 cerr << "Usage: binpatch check|apply|remove <exe> <patch>" << endl;
239 return 2;
240 }
241
242 std::string cmd = argv[1];
243
244 if (cmd != "check" && cmd != "apply" && cmd != "remove")
245 {
246 cerr << "Invalid command: " << cmd << endl;
247 return 2;
248 }
249
250 std::string exe_file = argv[2];
251 std::vector<patch_byte> bindata;
252 if (!load_file(&bindata, exe_file))
253 return 2;
254
255 BinaryPatch patch;
256 if (!patch.loadDIF(argv[3]))
257 return 2;
258
259 BinaryPatch::State state = patch.checkState(bindata.data(), bindata.size());
260 if (state == BinaryPatch::Conflict)
261 return 1;
262
263 if (cmd == "check")
264 {
265 switch (state)
266 {
267 case BinaryPatch::Unapplied:
268 cout << "Currently not applied." << endl;
269 break;
270 case BinaryPatch::Applied:
271 cout << "Currently applied." << endl;
272 break;
273 case BinaryPatch::Partial:
274 cout << "Currently partially applied." << endl;
275 break;
276 default:
277 break;
278 }
279
280 return 0;
281 }
282 else if (cmd == "apply")
283 {
284 if (state == BinaryPatch::Applied)
285 {
286 cout << "Already applied." << endl;
287 return 0;
288 }
289
290 patch.apply(bindata.data(), bindata.size(), true);
291 }

Callers

nothing calls this directly

Calls 8

compute_hashFunction · 0.85
loadDIFMethod · 0.80
checkStateMethod · 0.80
load_fileFunction · 0.70
save_fileFunction · 0.70
dataMethod · 0.45
sizeMethod · 0.45
applyMethod · 0.45

Tested by

no test coverage detected