Block images VPN - Android

43 Views Asked by At

I want to create a self vpn to block nsfw photos using nsfw js

I tried to write a simple empty vpn unsuccessfully When I open a website the loading take forever. and I don't know how to block the images this what I got:

    private fun startVpn() {
        val builder = Builder()
        builder.setSession("SafeSurfVPN")
        builder.addAddress(VPN_IP_ADDRESS, VPN_IP_PREFIX_LENGTH)
        builder.addRoute(ALL_ROUTES, 0)
        builder.setMtu(1500)
        mInterface = builder.establish()

        // Start a thread for handling the VPN traffic
        Thread {
            try {
                handleTraffic()
            } catch (e: IOException) {
                Log.e(TAG, "Error handling traffic: ${e.message}")
            }
        }.start()
    }

    private fun handleTraffic() {
        val buffer = ByteArray(1024)
        val fileDescriptor = mInterface!!.fileDescriptor

        try {
            val inputChannel = FileInputStream(fileDescriptor).channel
            val outputChannel = FileOutputStream(fileDescriptor).channel

            while (true) {
                val bytesRead = inputChannel.read(ByteBuffer.wrap(buffer))
                if (bytesRead > 0) {
                    // Process and modify the traffic as needed
                    // Implement image blocking logic here

                    // Write the modified data back to the VPN interface
                    outputChannel.write(ByteBuffer.wrap(buffer, 0, bytesRead))
                }
            }
        } catch (e: IOException) {
            Log.e(TAG, "Error handling traffic: ${e.message}")
        }
    }

I tried to use the code from httptoolkit

0

There are 0 best solutions below