Skip to content

Instantly share code, notes, and snippets.

@rhelmer
Created August 28, 2018 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhelmer/f788252f64d75a3844964496b861431b to your computer and use it in GitHub Desktop.
Save rhelmer/f788252f64d75a3844964496b861431b to your computer and use it in GitHub Desktop.
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
const ENABLE_PROB = 0.01;
const ADDON_ID = "...";
XPCOMUtils.defineLazyServiceGetters(this, {
uuidGen: ["@mozilla.org/uuid-generator;1", "nsIUUIDGenerator"],
});
async function generateVariate(seed, label) {
const hasher = crypto.subtle;
const hash = await hasher.digest("SHA-256", new TextEncoder("utf-8").encode(seed + label));
let view = new DataView(hash);
return view.getUint32(0) / 0xffffffff;
}
(function loop() {
uuid = uuidGen.generateUUID().number;
uuid = uuid.substring(1, uuid.length - 1);
generateVariate(uuid, ADDON_ID).then(a => {
if (a < ENABLE_PROB) {
console.log(`Found one: ${uuid}`);
} else {
loop();
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment