Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

FIOC

Name: Anonymous 2008-12-05 18:08

So I was thinking about picking up some toy-language some day. I'm used to the real stuff (think C and friends), and the non-practical stuff (like LISP/SICP, although I'm certainly no expert on that - hard to become one, since you can't do anything useful), but I can see how these scripting-language-in-asteroids things can be attractive.

So, since Python 3 was released recently, I took a look.

What the fuck, man? This isn't "revolutionary" at all, it's a 10-times-slower C with a arguably prettier syntax.

It's missing CRITICAL features like coroutines (when you have a fork called "stackless Python", you know you're in trouble). Threading is pure shit - the GLOBAL INTERPRETER LOCK literally ruins any of the language's future prospects.

They first think I take a look at, basic types, starts showing serious trouble. And I quote:

     Floating point numbers are implemented using double
     in C—all bets on their precision are off unless you
     happen to know the machine you are working with.


That's great. An interpreted non-deterministic language. And even though it doesn't offer anything resembling a guarantee about the results of a FP computation, it goes ahead and picks up the slow type, just in case it ran too fast otherwise.

Immediately below I see:

     pow(x, y)   x to the power y
     x ** y      x to the power y


Oh, I see. This must be a great example of that "there should be one—and preferably only one—obvious way to do it ".

The sad thing is that I'm starting to fear it's amongst the best toy-but-remotely-useful languages.

Name: Anonymous 2008-12-07 15:40

typedef struct {
    u32     key;
    u8      *host;
    u16     port;
#ifdef V3HPROXY
    u8      handshake_key[64];
    u8      handshake[16];
    int     ok;
#endif
} ventrilo3_auth_t;

static ventrilo3_auth_t ventrilo3_auth[] = {
    { 0x48332e1f, "72.51.46.31",   6100 V3HPROXY_PARS },
    { 0x4022b2b2, "64.34.178.178", 6100 V3HPROXY_PARS },
    { 0x3dc24a36, "74.54.61.194",  6100 V3HPROXY_PARS },
    { 0x46556ef2, "70.85.110.242", 6100 V3HPROXY_PARS },
    { 0,          NULL,            0    V3HPROXY_PARS }
};



int ventrilo3_hdr_udp(int type, u8 *buff, u8 *pck);
int ventrilo3_send_udp(int sd, u32 key, u32 ip, u16 port, u8 *data, int len);
int ventrilo3_recv_udp(int sd, ventrilo3_auth_t *vauth, u8 *data, int maxsz, int *handshake_num);
int getbe(u8 *data, u32 *ret, int bits);
int putbe(u8 *data, u32 num, int bits);
int v3timeout(int sock, int secs);



void ventrilo3_algo_scramble(ventrilo_key_ctx *ctx, u8 *v3key) {
    int     i,
            keylen;
    u8      *key;

    key = ctx->key;
    keylen = ctx->size;
    for(i = 64; i < keylen; i++) {
        v3key[i] = i + keylen;
    }
    for(i = 0; i < keylen; i++) {
        key[i] += v3key[i];
        if(!key[i]) key[i] = i + 36;
    }
    ctx->pos = 0;
}



int ventrilo3_handshake(u32 ip, u16 port, u8 *handshake, int *handshake_num, u8 *handshake_key) {
    struct  linger  ling = {1,1};
    int     sd;
    int     i,
            len;
    u8      sbuff[V3HBUFFSZ],
            rbuff[V3HBUFFSZ];

    sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if(sd < 0) return(-1);
    setsockopt(sd, SOL_SOCKET, SO_LINGER, (char *)&ling, sizeof(ling));

    memset(rbuff, 0, 200);
    ventrilo3_hdr_udp(4, sbuff, rbuff);
    putbe(sbuff + 0xc,  2,         8);
    putbe(sbuff + 0x10, 1,         16); // useless
    putbe(sbuff + 0x12, time(NULL),16); // rand useless number

    ventrilo3_send_udp(sd, 0, ip, port, sbuff, 200);
    len = ventrilo3_recv_udp(sd, NULL, rbuff, V3HBUFFSZ, handshake_num);
    if(len < 0) goto quit;

    for(i = 0; ventrilo3_auth[i].key; i++) {
        len = ventrilo3_hdr_udp(5, sbuff, rbuff);
        ventrilo3_send_udp(sd, ventrilo3_auth[i].key, inet_addr(ventrilo3_auth[i].host), ventrilo3_auth[i].port, sbuff, len);
    }

    for(;;) {
        len = ventrilo3_recv_udp(sd, (void *)&ventrilo3_auth, rbuff, V3HBUFFSZ, handshake_num);
        if(len < 0) break;
        if(!len) continue;
        if(len < (0x5c + 16)) continue;
#ifdef V3HPROXY
        memcpy(ventrilo3_auth[*handshake_num].handshake_key, rbuff + 0x1c, 64);
        memcpy(ventrilo3_auth[*handshake_num].handshake,     rbuff + 0x5c, 16);
        ventrilo3_auth[*handshake_num].ok = 1;
#else
        memcpy(handshake_key, rbuff + 0x1c, 64);
        memcpy(handshake,     rbuff + 0x5c, 16);
        close(sd);
        return(0);
#endif
    }

quit:
    close(sd);
#ifdef V3HPROXY
    return(0);
#else
    return(-1);
#endif
}



int ventrilo3_hdr_udp(int type, u8 *buff, u8 *pck) {
    u8      ecx;

    memset(buff, 0, 0x200); // no, I'm not mad, this is EXACTLY what Ventrilo does

    switch(type - 1) {
        case 0: ecx = 0xb4; break;
        case 1: ecx = 0x70; break;
        case 2: ecx = 0x24; break;
        case 3: ecx = 0xb8; break;
        case 4: ecx = 0x74; break;
        case 5: ecx = 0x5c; break;
        case 6: ecx = 0xd0; break;
        case 7: ecx = 0x08; break;
        case 8: ecx = 0x50; break;
        default: ecx = 0;   break;
    }
    ecx += 0x10;

    putbe(buff + 8,  type,   16);
    putbe(buff + 10, ecx,    16);
    buff[4] = 'U';
    buff[5] = 'D';
    buff[6] = 'C';
    buff[7] = 'L';
    buff[0xc] = 1;
    putbe(buff + 0x10, 0xb401, 32);         // x[seq], recheck
    putbe(buff + 0x14, getbe(pck + 0x14, NULL, 32), 32);
    putbe(buff + 0x18, getbe(pck + 0x18, NULL, 32), 32);
    putbe(buff + 0x1c, getbe(pck + 0x1c, NULL, 32), 32);
    putbe(buff + 0x20, getbe(pck + 0x20, NULL, 32), 32);
    putbe(buff + 0x24, getbe(pck + 0x28, NULL, 32), 32);
    buff[0x28] = pck[0x30];
    buff[0x29] = 0;
    buff[0x2a] = 0;
    buff[0x2b] = 0;
    putbe(buff + 0x2c, getbe(pck + 0x24, NULL, 16), 16);
    putbe(buff + 0x2e, 0, 16);
    putbe(buff + 0x30, getbe(pck + 0x14, NULL, 16), 16);
    memcpy(buff + 0x34, pck + 0x38, 16);    // hash
    memcpy(buff + 0x44, pck + 0x88, 32);    // WIN32
    buff[0x63] = 0;
    memcpy(buff + 0x64, pck + 0xa8, 32);    // version
    buff[0x83] = 0;
    return(132);
}



int ventrilo3_send_udp(int sd, u32 key, u32 ip, u16 port, u8 *data, int len) {
    struct  sockaddr_in peer;
    int     i;
    u8      tmp[4];

    tmp[0] = key >> 24;
    tmp[1] = key >> 16;
    tmp[2] = key >> 8;
    tmp[3] = key;
    for(i = 16; i < len; i++) {
        data[i] += tmp[i & 3];
    }

    peer.sin_addr.s_addr = ip;
    peer.sin_port        = htons(port);
    peer.sin_family      = AF_INET;

    printf(". %s:%hu\n", inet_ntoa(peer.sin_addr), ntohs(peer.sin_port));
    sendto(sd, data, len, 0, (struct sockaddr *)&peer, sizeof(struct sockaddr_in));
    return(0);
}



int ventrilo3_recv_udp(int sd, ventrilo3_auth_t *vauth, u8 *data, int maxsz, int *handshake_num) {
    struct  sockaddr_in peer;
    u32     key;
    int     len,
            i,
            psz;
    u8      tmp[4];

    if(v3timeout(sd, 2) < 0) return(-1);
    psz = sizeof(struct sockaddr_in);
    len = recvfrom(sd, data, maxsz, 0, (struct sockaddr *)&peer, &psz);
    if(len < 0) return(-1);
    if(!vauth) return(len);

    key = 0;
    for(i = 0; vauth[i].key; i++) {
        if(inet_addr(vauth[i].host) == peer.sin_addr.s_addr) {
            key = vauth[i].key;
            break;
        }
    }
    if(!key) return(0);

    *handshake_num = i;
    tmp[0] = key >> 24;
    tmp[1] = key >> 16;
    tmp[2] = key >> 8;
    tmp[3] = key;
    for(i = 16; i < len; i++) {
        data[i] -= tmp[i & 3];
    }
    return(len);
}



int getbe(u8 *data, u32 *ret, int bits) {
    u32     num;
    int     i,
            bytes;

    bytes = bits >> 3;
    for(num = i = 0; i < bytes; i++) {
        num |= (data[i] << ((bytes - 1 - i) << 3));
    }
    if(!ret) return(num);
    *ret = num;
    return(bytes);
}



int putbe(u8 *data, u32 num, int bits) {
    int     i,
            bytes;

    bytes = bits >> 3;
    for(i = 0; i < bytes; i++) {
        data[i] = (num >> ((bytes - 1 - i) << 3)) & 0xff;
    }
    return(bytes);
}



int v3timeout(int sock, int secs) {
    struct  timeval tout;
    fd_set  fd_read;

    tout.tv_sec  = secs;
    tout.tv_usec = 0;
    FD_ZERO(&fd_read);
    FD_SET(sock, &fd_read);
    if(select(sock + 1, &fd_read, NULL, NULL, &tout)
      <= 0) return(-1);
    return(0);
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List