Bennu Game Development

Foros en Español => Mesa de Ayuda => Topic started by: josebita on August 04, 2009, 02:06:21 PM

Title: Splinter, ¡te reclaman!
Post by: josebita on August 04, 2009, 02:06:21 PM
En el foro inglés:

http://www.bennugd.co.uk/viewtopic.php?pid=243#p243
Title: Re: Splinter, ¡te reclaman!
Post by: splinter_work on August 04, 2009, 03:22:36 PM
No puedo responder ahi, porque no me acuerdo, ni la password ni el mail que use para registrarme.

El error esta en que cuando hace decrypt en vez de guardar "((l/8) + 1) * 8" bytes, guarda "strlen((string) out)".


//    fwrite( out, strlen( (string) out), f );
    fwrite( out, ( ( l / 8 ) + 1 ) * 8, f );


Igualmente yo no usaria ese metodo, si sucede algun problema como ser apagado de la pc justo cuando desencripto el archivo, este quedara desencriptado y no servira para la proxima corrida.

yo haria desencripcion en memoria y lo usaria de esa forma, asi:


import "mod_crypt"
import "mod_mem"
import "mod_file"
import "mod_string"
import "mod_say"

Global
    // sizeof of this struct must be aligned to 8
    struct test;
        int var1;           // 4 bytes
        int var2;           // 4 bytes
        int var3;           // 4 bytes
        char text[20];      // 20 bytes
    End                     // Total: 32 bytes = 4 blocks of 8 bytes
    // string type in struct isn't valid for encription
End

Process Main()
Begin
    if(fexists("struct.dat"))
        load("struct.dat", test);
        decrypt(&test, (sizeof(test)/8));
    End

    say ("Var 1:  " + test.var1);
    say ("Var 2:  " + test.var2);
    say ("Var 3:  " + test.var3);
    say ("Var 4: [" + test.text + "]");

    test.var1 += 10;
    test.var2 += 100;
    test.var3 += 1000;
    test.text = "total = " + ( test.var1 + test.var2 + test.var3 );

    encrypt(&test, (sizeof(test)/8));
    save("struct.dat", test);
End

Process encrypt( char * in, int l )
Private
    #include "key.inc"
    char *out;
Begin
    out = calloc( l, 8 );
    crypt_encrypt(CRYPT_3DES, &key, in, out, l);
    memmove( in, out, l * 8 );
    free( out );
End

Process decrypt( char * in, int l )
Private
    #include "key.inc"
    char *out;
Begin
    out = calloc( l, 8 );
    crypt_decrypt(CRYPT_3DES, &key, in, out, l);
    memmove( in, out, l * 8 );
    free( out );
End


Agradeceria si podes transmitir mi respuesta a ese post... gracias.

Adicionalmente, avisar que si uno hace calloc o alguna funcion de alocacion de memoria, hay que hacer el free.
Title: Re: Splinter, ¡te reclaman!
Post by: Prg on August 04, 2009, 03:56:47 PM
QuoteAdicionalmente, avisar que si uno hace calloc o alguna funcion de alocacion de memoria, hay que hacer el free.

disculpa, ¿y si no hiciéramos free y saliéramos del juego la memoria seguiría ocupada?
Title: Re: Splinter, ¡te reclaman!
Post by: DCelso on August 04, 2009, 09:26:42 PM
depende del S.O. En windows y los linux actuales sí.
Title: Re: Splinter, ¡te reclaman!
Post by: Prg on August 04, 2009, 10:34:30 PM
ya veo. gracias :)
Title: Re: Splinter, ¡te reclaman!
Post by: SplinterGU on August 05, 2009, 02:58:08 AM
no me refiero a la salida, me refiero a funciones, que se supone que al ser funciones pueden usarse reiteradas veces... con lo que se harian muchos allocs sin liberar