broke jvm

This commit is contained in:
2026-05-24 22:47:29 +03:00
parent 07a1fbe692
commit 269f23198f
13 changed files with 4045 additions and 40 deletions

View File

@ -1,5 +1,4 @@
package su.sonoma
import kotlinx.coroutines.*
import java.io.DataInputStream
import java.net.Socket
@ -18,7 +17,6 @@ fun startClient() = runBlocking {
launch {
val buffer = ByteArray(32768)
// TUN → SERVER
while (true) {
val len = tun.input.read(buffer)
@ -34,7 +32,6 @@ fun startClient() = runBlocking {
launch {
val buffer = ByteArray(32768)
// SERVER → TUN
while (true) {
val hi = input.read()
val lo = input.read()

View File

@ -38,7 +38,6 @@ suspend fun handle(socket: Socket) {
val packet = buffer.copyOf(len)
// 🌍 forward to internet
val response = forwardPacket(packet)
output.write(response.size shr 8)
@ -49,8 +48,6 @@ suspend fun handle(socket: Socket) {
}
fun forwardPacket(packet: ByteArray): ByteArray {
// ⚠️ simplified: we assume HTTP (not real VPN parsing yet)
val host = "example.com"
val port = 80

View File

@ -6,31 +6,45 @@ import java.io.FileOutputStream
import java.io.RandomAccessFile
class TunDevice(
private val name: String = "tun0"
private val name: String = "tun0",
private val ip: String = "10.1.0.1"
) {
companion object {
init {
System.load(
"${System.getProperty("user.dir")}/build/native/libtun.so"
)
}
}
val input: FileInputStream
val output: FileOutputStream
init {
val fd = openTun(name)
val fd = openTun(name, ip)
input = FileInputStream(fd)
output = FileOutputStream(fd)
}
private fun openTun(name: String): FileDescriptor {
val fd = FileDescriptor()
private fun openTun(name: String, ip: String): FileDescriptor {
val tun = RandomAccessFile("/dev/net/tun", "rw")
val field = tun.javaClass.getDeclaredField("fd")
field.isAccessible = true
val flags = 0x0001 or 0x1000
val ioctl = ioctlTun(tun.fd, name, flags)
if (ioctl < 0) error("Cannot open TUN")
val result = ioctlTun(tun.fd, name, ip, flags)
if (result < 0) {
error("Cannot open TUN")
}
return tun.fd
}
private external fun ioctlTun(fd: FileDescriptor?, name: String, flags: Int): Int
private external fun ioctlTun(
fd: FileDescriptor,
name: String,
ip: String,
flags: Int
): Int
}