Skip to content

Instantly share code, notes, and snippets.

@jl2012
Last active November 23, 2018 22:10
Show Gist options
  • Select an option

  • Save jl2012/9315ee59290fd48db7c8a416444aa6fb to your computer and use it in GitHub Desktop.

Select an option

Save jl2012/9315ee59290fd48db7c8a416444aa6fb to your computer and use it in GitHub Desktop.
int FindAndMask(CScript& script)
{
int masked = 0;
bool skip_next = false;
CScript result;
CScript::const_iterator pc = script.begin(), pc2 = script.begin();
opcodetype opcode;
while (script.GetOp(pc, opcode)) {
if (opcode == OP_MASK) {
result.insert(result.end(), pc2, pc);
skip_next = true;
pc2 = pc;
}
else if (skip_next == true) {
result.insert(result.end(), (unsigned char)OP_VERIF);
skip_next = false;
pc2 = pc;
++masked;
}
}
if (skip_next == true) {
script = CScript();
return -1;
}
if (masked > 0) {
result.insert(result.end(), pc2, static_cast<CScript::const_iterator>(script.end()));
script = std::move(result);
}
return masked;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment