Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   .NET (https://www.clubdelphi.com/foros/forumdisplay.php?f=17)
-   -   No entiendo esta función (https://www.clubdelphi.com/foros/showthread.php?t=92668)

aguml 24-12-2017 00:11:31

No entiendo esta función
 
Hola amigos, tengo un código que estoy intentando entender pero en visual studio c# no compila. La parte que quiero entender por ahora y donde da los errores es esta:
Código PHP:

public unsafe byte[] Decrypt(byte[] eData)
{
    
byte[] buffer2;
    
byte[] buffer Class41.smethod_0((int) Class37.smethod_0(eData));
    if (((
buffer2 eData) != null) && (((int) Class37.smethod_0(buffer2)) != 0))
    {
        
numRef2 = &(buffer2[Class4.smethod_0(0x114)]);
    }
    
fixed (bytenumRef2 = ((byte*) Class4.smethod_0(0x110)))
    {
        if (((
buffer2 buffer) != null) && (((int) Class37.smethod_0(buffer2)) != 0))
        {
            
numRef = &(buffer2[Class4.smethod_0(0x11c)]);
        }
        
fixed (bytenumRef = ((byte*) Class4.smethod_0(280)))
        {
            
intnumPtr = (int*) numRef2;
            
intnumPtr2 = (int*) numRef;
            
int num Class4.smethod_0(0x120);
            do
            {
                
numPtr += Class4.smethod_0(0x124);
                
int num2 numPtr[0].smethod_2();
                
numPtr += Class4.smethod_0(0x128);
                
int num3 numPtr[0].smethod_2();
                
this.ccfae92404b1d8caf890158f763ac579b(ref num2ref num3);
                
numPtr2 += Class4.smethod_0(300);
                
numPtr2[0] = num2 num2.smethod_2();
                
numPtr2 += Class4.smethod_0(0x130);
                
numPtr2[0] = num3 num3.smethod_2();
                
num += Class4.smethod_0(0x134);
            }
            while (
num < (((int) Class37.smethod_0(eData)) >> Class4.smethod_0(0x138)));
        }
    }
    return 
buffer;


Los errores los da en las líneas con fixed.
¿Alguien puede corregir el código y comentarlo para entender que hace en cada línea?

mamcx 24-12-2017 02:05:33

Si estas tratando de hacer encriptacion, .NET ya tiene incluido librerias de calidad para esos casos. No inventes tu propia encriptacion.

aguml 24-12-2017 02:18:24

No es eso, el caso es que es un código para desencriptar un archivo en concreto y quiero saber qué encriptacion usa para ello y de paso aprendo c#.

mamcx 24-12-2017 19:31:01

Igual no has dicho que error.

Y no tienes el nombre del algoritmo?

aguml 24-12-2017 22:57:18

El error no lo puedo ver hasta el martes pero es por el fixed y decía algo como que no se puede modificar una variable dentro del fixed o algo así. Por supuesto no se el nombre del algoritmo pero sé que va encriptando/desencriptando bloques de 8 bytes y que si el bloque a encriptar es:
00 00 00 00 00 00 00 00
Queda como:
0D 88 78 F9 51 E0 19 41
Y si el bloque es:
00 00 00 01 00 00 00 00
Queda como:
72 92 D7 6D 67 D8 3C 93
Aún no analicé más el código porque no entiendo está parte y no quiero correr antes de caminar.
Sé que usa una key o algo así para realizar los cálculos porque si no al ser todos 00 no serían valores diferentes para cada byte pero no sé más.

aguml 25-12-2017 18:05:54

Aqui os pongo todas las funciones que creo que son las que estan involucradas por si podeis echarme un cable:
El botón que desencripta:
Código PHP:

private void button_1_Click(object senderEventArgs e)
{
    
File.WriteAllBytes(this.string_0, new Form1.GClass1(this.byte_0).Decrypt(File.ReadAllBytes(this.string_0)));
    
int num = (int)MessageBox.Show(Class5.c39c0e0f1863ae92a6bb9f1c4d11eea98(80));


La función desencriptadora:
Código PHP:

public unsafe byte[] Decrypt(byte[] eData)
{
    
byte[] numArray Class41.smethod_0((int) Class37.smethod_0(eData));
    
byte[] byte_0_1;
    
// ISSUE: cast to a reference type
    // ISSUE: explicit reference operation
    // ISSUE: explicit reference operation
    
fixed (bytenumPtr1 = &^((byte_0_1 eData) == null || (int) Class37.smethod_0(byte_0_1) == ? (byte&) Class4.smethod_0(272) : @byte_0_1[Class4.smethod_0(276)]))
    {
        
byte[] byte_0_2;
        
// ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        // ISSUE: explicit reference operation
        
fixed (bytenumPtr2 = &^((byte_0_2 numArray) == null || (int) Class37.smethod_0(byte_0_2) == ? (byte&) Class4.smethod_0(280) : @byte_0_2[Class4.smethod_0(284)]))
        {
            
intnumPtr3 = (int*) numPtr1;
            
intnumPtr4 = (int*) numPtr2;
            
int num1 Class4.smethod_0(288);
            while (
num1 < (int) Class37.smethod_0(eData) >> Class4.smethod_0(312))
            {
                
intnumPtr5 numPtr3;
                
IntPtr num2 = (IntPtrClass4.smethod_0(292);
                
intnumPtr6 = (int*) ((IntPtrnumPtr5 num2);
                
int int_2 GClass0.smethod_2(*numPtr5);
                
intnumPtr7 numPtr6;
                
IntPtr num3 = (IntPtrClass4.smethod_0(296);
                
numPtr3 = (int*) ((IntPtrnumPtr7 num3);
                
int int_3 GClass0.smethod_2(*numPtr7);
                
this.ccfae92404b1d8caf890158f763ac579b(ref int_2ref int_3);
                
intnumPtr8 numPtr4;
                
IntPtr num4 = (IntPtrClass4.smethod_0(300);
                
intnumPtr9 = (int*) ((IntPtrnumPtr8 num4);
                
int num5;
                
int num6 num5 GClass0.smethod_2(int_2);
                *
numPtr8 num5;
                
intnumPtr10 numPtr9;
                
IntPtr num7 = (IntPtrClass4.smethod_0(304);
                
numPtr4 = (int*) ((IntPtrnumPtr10 num7);
                
int num8;
                
int_3 num8 GClass0.smethod_2(int_3);
                *
numPtr10 num8;
                
num1 += Class4.smethod_0(308);
            }
            
// ISSUE: cast to a reference type
            // ISSUE: variable of a reference type
            
bytelocal1 = (byte&) Class4.smethod_0(316);
            
// ISSUE: cast to a reference type
            // ISSUE: variable of a reference type
            
bytelocal2 = (byte&) Class4.smethod_0(320);
            return 
numArray;
        }
    }


Esta función creo que es la que realmente desencripta usando dos valores enteros (supongo que uno será el que está en el archivo y el otro el que se usa para desencriptar):
Código PHP:

private void ccfae92404b1d8caf890158f763ac579b(ref int int_2ref int int_3)
{
     
Class4.smethod_0(376);
     
int num1 Class4.smethod_0(380);
     
int num2;
     do
     {
         
num2 this.int_0[Class4.smethod_0(384) - num1] ^ int_2;
         
int_2 = (this.int_1[Class4.smethod_0(388), (int) (byte) (num2 >> Class4.smethod_0(392))] + this.int_1[Class4.smethod_0(396), (int) (byte) (num2 >> Class4.smethod_0(400))] ^ this.int_1[Class4.smethod_0(404), (int) (byte) (num2 >> Class4.smethod_0(408))]) + this.int_1[Class4.smethod_0(412), (int) (bytenum2] ^ int_3;
         
int_3 num2;
         
num1 += Class4.smethod_0(416);
     }
     while (
num1 Class4.smethod_0(420));
     
int_3 this.int_0[Class4.smethod_0(424)] ^ int_2;
     
int_2 this.int_0[Class4.smethod_0(428)] ^ num2;


La función Class41.smethod_0:
Código PHP:

internal static byte[] smethod_0(int int_0)
{
    return new 
byte[int_0];


la función Class37.smethod_0:
Código PHP:

internal static UIntPtr smethod_0(byte[] byte_0)
{
    return (
UIntPtrbyte_0.Length;


La función Class4.smethod_0:
Código PHP:

internal static int smethod_0(int int_1)
{
    return 
BitConverter.ToInt32(Class4.byte_0int_1);


La parte donde se define Class4.byte_0:
Código PHP:

internal sealed class Class4
{
    
internal static readonly byte[] byte_0;
    
internal readonly int int_0;

    static 
Class4()
    {
        if (
Class4.byte_0 != null)
            return;
        
byte[] bytes Convert.FromBase64String("UmVzaWRlbnQgRXZpbCBSZXZlbGF0aW9ucyAyIERlY3J5cHRlciU=");
        
Class4.byte_0 Class6.smethod_1(97LAssembly.GetExecutingAssembly().GetManifestResourceStream(Encoding.UTF8.GetString(bytes0bytes.Length)));
    }
    ... 

El botón donde se encripta:
Código PHP:

private void button_2_Click(object senderEventArgs e)
{
    
File.WriteAllBytes(this.string_0, new Form1.GClass1(this.byte_0).Encrypt(File.ReadAllBytes(this.string_0)));
    
int num = (int)MessageBox.Show(Class5.c39c0e0f1863ae92a6bb9f1c4d11eea98(95));


Para la funcion encriptadora:
Código PHP:

public unsafe byte[] Encrypt(byte[] uData)
{
    
byte[] numArray Class41.smethod_0((int) Class37.smethod_0(uData));
    
byte[] byte_0_1;
    
// ISSUE: cast to a reference type
    // ISSUE: explicit reference operation
    // ISSUE: explicit reference operation
    
fixed (bytenumPtr1 = &^((byte_0_1 uData) == null || (int) Class37.smethod_0(byte_0_1) == ? (byte&) Class4.smethod_0(220) : @byte_0_1[Class4.smethod_0(224)]))
    {
        
byte[] byte_0_2;
        
// ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        // ISSUE: explicit reference operation
        
fixed (bytenumPtr2 = &^((byte_0_2 numArray) == null || (int) Class37.smethod_0(byte_0_2) == ? (byte&) Class4.smethod_0(228) : @byte_0_2[Class4.smethod_0(232)]))
        {
            
intnumPtr3 = (int*) numPtr2;
            
intnumPtr4 = (int*) numPtr1;
            
int num1 Class4.smethod_0(236);
            while (
num1 < (int) Class37.smethod_0(uData) >> Class4.smethod_0(260))
            {
                
intnumPtr5 numPtr4;
                
IntPtr num2 = (IntPtrClass4.smethod_0(240);
                
intnumPtr6 = (int*) ((IntPtrnumPtr5 num2);
                
int int_2 GClass0.smethod_2(*numPtr5);
                
intnumPtr7 numPtr6;
                
IntPtr num3 = (IntPtrClass4.smethod_0(244);
                
numPtr4 = (int*) ((IntPtrnumPtr7 num3);
                
int int_3 GClass0.smethod_2(*numPtr7);
                
this.c0c1ef294051644e1e4a229a2e6a0ee04(ref int_2ref int_3);
                
intnumPtr8 numPtr3;
                
IntPtr num4 = (IntPtrClass4.smethod_0(248);
                
intnumPtr9 = (int*) ((IntPtrnumPtr8 num4);
                
int num5;
                
int num6 num5 GClass0.smethod_2(int_2);
                *
numPtr8 num5;
                
intnumPtr10 numPtr9;
                
IntPtr num7 = (IntPtrClass4.smethod_0(252);
                
numPtr3 = (int*) ((IntPtrnumPtr10 num7);
                
int num8;
                
int_3 num8 GClass0.smethod_2(int_3);
                *
numPtr10 num8;
                
num1 += Class4.smethod_0(256);
            }
            
// ISSUE: cast to a reference type
            // ISSUE: variable of a reference type
            
bytelocal1 = (byte&) Class4.smethod_0(264);
            
// ISSUE: cast to a reference type
            // ISSUE: variable of a reference type
            
bytelocal2 = (byte&) Class4.smethod_0(268);
            return 
numArray;
        }
    }


Esta función creo que es la que realmente encripta usando dos valores enteros (supongo que uno será el que está en el archivo y el otro el que se usa para encriptar):
Código PHP:

private void c0c1ef294051644e1e4a229a2e6a0ee04(ref int int_2ref int int_3)
{
    
Class4.smethod_0(324);
    
int index Class4.smethod_0(328);
    
int num;
    do
    {
        
num this.int_0[index] ^ int_2;
        
int_2 = (this.int_1[Class4.smethod_0(332), (int) (byte) (num >> Class4.smethod_0(336))] + this.int_1[Class4.smethod_0(340), (int) (byte) (num >> Class4.smethod_0(344))] ^ this.int_1[Class4.smethod_0(348), (int) (byte) (num >> Class4.smethod_0(352))]) + this.int_1[Class4.smethod_0(356), (int) (bytenum] ^ int_3;
        
int_3 num;
        
index += Class4.smethod_0(360);
    }
    while (
index Class4.smethod_0(364));
    
int_3 this.int_0[Class4.smethod_0(368)] ^ int_2;
    
int_2 this.int_0[Class4.smethod_0(372)] ^ num;




La franja horaria es GMT +2. Ahora son las 21:44:33.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi