#include "patch.h" namespace patch { type identify(const file& patch) { byte head[16]; size_t len = patch.read(arrayview(head)); return identify(arrayview(head, len)); } type identify(arrayview patch) { if (patch.size()>=5 && !memcmp(patch.ptr(), "PATCH", 5)) return ty_ips; if (patch.size()>=4 && !memcmp(patch.ptr(), "UPS1", 4)) return ty_ups; if (patch.size()>=4 && !memcmp(patch.ptr(), "BPS1", 4)) return ty_bps; return ty_unknown; } type identify_ext(cstring path) { if (path.endswith(".ips")) return ty_ips; if (path.endswith(".ups")) return ty_ups; if (path.endswith(".bps")) return ty_bps; return ty_unknown; } bool memstream::bpsnum(size_t* out) { //similar to uleb128, but bpsnum adds another 1<::lslov(next^0x80, shift, &tmp)) return false; if (safeint::addov(ret, tmp, &ret)) return false; if (next&0x80) break; shift+=7; } *out = ret; return true; } }