Foros del Web » Programación para mayores de 30 ;) » .NET »

No puedo comprender el siguiente codigo

Estas en el tema de No puedo comprender el siguiente codigo en el foro de .NET en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 23/12/2017, 16:15
 
Fecha de Ingreso: febrero-2015
Mensajes: 404
Antigüedad: 9 años, 2 meses
Puntos: 3
No puedo comprender el siguiente codigo

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 C++:
Ver original
  1. public unsafe byte[] Decrypt(byte[] eData)
  2. {
  3.     byte[] buffer2;
  4.     byte[] buffer = Class41.smethod_0((int) Class37.smethod_0(eData));
  5.     if (((buffer2 = eData) != null) && (((int) Class37.smethod_0(buffer2)) != 0))
  6.     {
  7.         numRef2 = &(buffer2[Class4.smethod_0(0x114)]);
  8.     }
  9.     fixed (byte* numRef2 = ((byte*) Class4.smethod_0(0x110)))
  10.     {
  11.         if (((buffer2 = buffer) != null) && (((int) Class37.smethod_0(buffer2)) != 0))
  12.         {
  13.             numRef = &(buffer2[Class4.smethod_0(0x11c)]);
  14.         }
  15.         fixed (byte* numRef = ((byte*) Class4.smethod_0(280)))
  16.         {
  17.             int* numPtr = (int*) numRef2;
  18.             int* numPtr2 = (int*) numRef;
  19.             int num = Class4.smethod_0(0x120);
  20.             do
  21.             {
  22.                 numPtr += Class4.smethod_0(0x124);
  23.                 int num2 = numPtr[0].smethod_2();
  24.                 numPtr += Class4.smethod_0(0x128);
  25.                 int num3 = numPtr[0].smethod_2();
  26.                 this.ccfae92404b1d8caf890158f763ac579b(ref num2, ref num3);
  27.                 numPtr2 += Class4.smethod_0(300);
  28.                 numPtr2[0] = num2 = num2.smethod_2();
  29.                 numPtr2 += Class4.smethod_0(0x130);
  30.                 numPtr2[0] = num3 = num3.smethod_2();
  31.                 num += Class4.smethod_0(0x134);
  32.             }
  33.             while (num < (((int) Class37.smethod_0(eData)) >> Class4.smethod_0(0x138)));
  34.         }
  35.     }
  36.     return buffer;
  37. }
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?
Otra duda que tengo pero no aparece en este código es ¿Que diferencia hay entre usar IntPtr y int*?
  #2 (permalink)  
Antiguo 25/12/2017, 10:07
 
Fecha de Ingreso: febrero-2015
Mensajes: 404
Antigüedad: 9 años, 2 meses
Puntos: 3
Respuesta: No puedo comprender el siguiente codigo

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:
El botón que desencripta:
Código C++:
Ver original
  1. private void button_1_Click(object sender, EventArgs e)
  2. {
  3.     File.WriteAllBytes(this.string_0, new Form1.GClass1(this.byte_0).Decrypt(File.ReadAllBytes(this.string_0)));
  4.     int num = (int)MessageBox.Show(Class5.c39c0e0f1863ae92a6bb9f1c4d11eea98(80));
  5. }

La función desencriptadora:
Código C++:
Ver original
  1. public unsafe byte[] Decrypt(byte[] eData)
  2. {
  3.     byte[] numArray = Class41.smethod_0((int) Class37.smethod_0(eData));
  4.     byte[] byte_0_1;
  5.     // ISSUE: cast to a reference type
  6.     // ISSUE: explicit reference operation
  7.     // ISSUE: explicit reference operation
  8.     fixed (byte* numPtr1 = &^((byte_0_1 = eData) == null || (int) Class37.smethod_0(byte_0_1) == 0 ? (byte&) Class4.smethod_0(272) : @byte_0_1[Class4.smethod_0(276)]))
  9.     {
  10.         byte[] byte_0_2;
  11.         // ISSUE: cast to a reference type
  12.         // ISSUE: explicit reference operation
  13.         // ISSUE: explicit reference operation
  14.         fixed (byte* numPtr2 = &^((byte_0_2 = numArray) == null || (int) Class37.smethod_0(byte_0_2) == 0 ? (byte&) Class4.smethod_0(280) : @byte_0_2[Class4.smethod_0(284)]))
  15.         {
  16.             int* numPtr3 = (int*) numPtr1;
  17.             int* numPtr4 = (int*) numPtr2;
  18.             int num1 = Class4.smethod_0(288);
  19.             while (num1 < (int) Class37.smethod_0(eData) >> Class4.smethod_0(312))
  20.             {
  21.                 int* numPtr5 = numPtr3;
  22.                 IntPtr num2 = (IntPtr) Class4.smethod_0(292);
  23.                 int* numPtr6 = (int*) ((IntPtr) numPtr5 + num2);
  24.                 int int_2 = GClass0.smethod_2(*numPtr5);
  25.                 int* numPtr7 = numPtr6;
  26.                 IntPtr num3 = (IntPtr) Class4.smethod_0(296);
  27.                 numPtr3 = (int*) ((IntPtr) numPtr7 + num3);
  28.                 int int_3 = GClass0.smethod_2(*numPtr7);
  29.                 this.ccfae92404b1d8caf890158f763ac579b(ref int_2, ref int_3);
  30.                 int* numPtr8 = numPtr4;
  31.                 IntPtr num4 = (IntPtr) Class4.smethod_0(300);
  32.                 int* numPtr9 = (int*) ((IntPtr) numPtr8 + num4);
  33.                 int num5;
  34.                 int num6 = num5 = GClass0.smethod_2(int_2);
  35.                 *numPtr8 = num5;
  36.                 int* numPtr10 = numPtr9;
  37.                 IntPtr num7 = (IntPtr) Class4.smethod_0(304);
  38.                 numPtr4 = (int*) ((IntPtr) numPtr10 + num7);
  39.                 int num8;
  40.                 int_3 = num8 = GClass0.smethod_2(int_3);
  41.                 *numPtr10 = num8;
  42.                 num1 += Class4.smethod_0(308);
  43.             }
  44.             // ISSUE: cast to a reference type
  45.             // ISSUE: variable of a reference type
  46.             byte& local1 = (byte&) Class4.smethod_0(316);
  47.             // ISSUE: cast to a reference type
  48.             // ISSUE: variable of a reference type
  49.             byte& local2 = (byte&) Class4.smethod_0(320);
  50.             return numArray;
  51.         }
  52.     }
  53. }

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 C++:
Ver original
  1. private void ccfae92404b1d8caf890158f763ac579b(ref int int_2, ref int int_3)
  2. {
  3.      Class4.smethod_0(376);
  4.      int num1 = Class4.smethod_0(380);
  5.      int num2;
  6.      do
  7.      {
  8.          num2 = this.int_0[Class4.smethod_0(384) - num1] ^ int_2;
  9.          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) (byte) num2] ^ int_3;
  10.          int_3 = num2;
  11.          num1 += Class4.smethod_0(416);
  12.      }
  13.      while (num1 < Class4.smethod_0(420));
  14.      int_3 = this.int_0[Class4.smethod_0(424)] ^ int_2;
  15.      int_2 = this.int_0[Class4.smethod_0(428)] ^ num2;
  16. }

La función Class41.smethod_0:
Código C++:
Ver original
  1. internal static byte[] smethod_0(int int_0)
  2. {
  3.     return new byte[int_0];
  4. }

la función Class37.smethod_0:
Código C++:
Ver original
  1. internal static UIntPtr smethod_0(byte[] byte_0)
  2. {
  3.     return (UIntPtr) byte_0.Length;
  4. }

La función Class4.smethod_0:
Código C++:
Ver original
  1. internal static int smethod_0(int int_1)
  2. {
  3.     return BitConverter.ToInt32(Class4.byte_0, int_1);
  4. }

La parte donde se define Class4.byte_0:
Código C++:
Ver original
  1. internal sealed class Class4
  2. {
  3.     internal static readonly byte[] byte_0;
  4.     internal readonly int int_0;
  5.  
  6.     static Class4()
  7.     {
  8.         if (Class4.byte_0 != null)
  9.             return;
  10.         byte[] bytes = Convert.FromBase64String("UmVzaWRlbnQgRXZpbCBSZXZlbGF0aW9ucyAyIERlY3J5cHRlciU=");
  11.         Class4.byte_0 = Class6.smethod_1(97L, Assembly.GetExecutingAssembly().GetManifestResourceStream(Encoding.UTF8.GetString(bytes, 0, bytes.Length)));
  12.     }
  13.     ...

El botón donde se encripta:
Código C++:
Ver original
  1. private void button_2_Click(object sender, EventArgs e)
  2. {
  3.     File.WriteAllBytes(this.string_0, new Form1.GClass1(this.byte_0).Encrypt(File.ReadAllBytes(this.string_0)));
  4.     int num = (int)MessageBox.Show(Class5.c39c0e0f1863ae92a6bb9f1c4d11eea98(95));
  5. }

Para la funcion encriptadora:
Código C++:
Ver original
  1. public unsafe byte[] Encrypt(byte[] uData)
  2. {
  3.     byte[] numArray = Class41.smethod_0((int) Class37.smethod_0(uData));
  4.     byte[] byte_0_1;
  5.     // ISSUE: cast to a reference type
  6.     // ISSUE: explicit reference operation
  7.     // ISSUE: explicit reference operation
  8.     fixed (byte* numPtr1 = &^((byte_0_1 = uData) == null || (int) Class37.smethod_0(byte_0_1) == 0 ? (byte&) Class4.smethod_0(220) : @byte_0_1[Class4.smethod_0(224)]))
  9.     {
  10.         byte[] byte_0_2;
  11.         // ISSUE: cast to a reference type
  12.         // ISSUE: explicit reference operation
  13.         // ISSUE: explicit reference operation
  14.         fixed (byte* numPtr2 = &^((byte_0_2 = numArray) == null || (int) Class37.smethod_0(byte_0_2) == 0 ? (byte&) Class4.smethod_0(228) : @byte_0_2[Class4.smethod_0(232)]))
  15.         {
  16.             int* numPtr3 = (int*) numPtr2;
  17.             int* numPtr4 = (int*) numPtr1;
  18.             int num1 = Class4.smethod_0(236);
  19.             while (num1 < (int) Class37.smethod_0(uData) >> Class4.smethod_0(260))
  20.             {
  21.                 int* numPtr5 = numPtr4;
  22.                 IntPtr num2 = (IntPtr) Class4.smethod_0(240);
  23.                 int* numPtr6 = (int*) ((IntPtr) numPtr5 + num2);
  24.                 int int_2 = GClass0.smethod_2(*numPtr5);
  25.                 int* numPtr7 = numPtr6;
  26.                 IntPtr num3 = (IntPtr) Class4.smethod_0(244);
  27.                 numPtr4 = (int*) ((IntPtr) numPtr7 + num3);
  28.                 int int_3 = GClass0.smethod_2(*numPtr7);
  29.                 this.c0c1ef294051644e1e4a229a2e6a0ee04(ref int_2, ref int_3);
  30.                 int* numPtr8 = numPtr3;
  31.                 IntPtr num4 = (IntPtr) Class4.smethod_0(248);
  32.                 int* numPtr9 = (int*) ((IntPtr) numPtr8 + num4);
  33.                 int num5;
  34.                 int num6 = num5 = GClass0.smethod_2(int_2);
  35.                 *numPtr8 = num5;
  36.                 int* numPtr10 = numPtr9;
  37.                 IntPtr num7 = (IntPtr) Class4.smethod_0(252);
  38.                 numPtr3 = (int*) ((IntPtr) numPtr10 + num7);
  39.                 int num8;
  40.                 int_3 = num8 = GClass0.smethod_2(int_3);
  41.                 *numPtr10 = num8;
  42.                 num1 += Class4.smethod_0(256);
  43.             }
  44.             // ISSUE: cast to a reference type
  45.             // ISSUE: variable of a reference type
  46.             byte& local1 = (byte&) Class4.smethod_0(264);
  47.             // ISSUE: cast to a reference type
  48.             // ISSUE: variable of a reference type
  49.             byte& local2 = (byte&) Class4.smethod_0(268);
  50.             return numArray;
  51.         }
  52.     }
  53. }

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 C++:
Ver original
  1. private void c0c1ef294051644e1e4a229a2e6a0ee04(ref int int_2, ref int int_3)
  2. {
  3.     Class4.smethod_0(324);
  4.     int index = Class4.smethod_0(328);
  5.     int num;
  6.     do
  7.     {
  8.         num = this.int_0[index] ^ int_2;
  9.         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) (byte) num] ^ int_3;
  10.         int_3 = num;
  11.         index += Class4.smethod_0(360);
  12.     }
  13.     while (index < Class4.smethod_0(364));
  14.     int_3 = this.int_0[Class4.smethod_0(368)] ^ int_2;
  15.     int_2 = this.int_0[Class4.smethod_0(372)] ^ num;
  16. }
  #3 (permalink)  
Antiguo 27/12/2017, 08:31
Avatar de Malenko
Moderador
 
Fecha de Ingreso: enero-2008
Mensajes: 5.323
Antigüedad: 16 años, 3 meses
Puntos: 606
Respuesta: No puedo comprender el siguiente codigo

Esto tiene toda la pinta de que se trata de obtención de un código fuente mediante ingeniería inversa, lo cual no suele ser muy legal.
__________________
Aviso: No se resuelven dudas por MP!
  #4 (permalink)  
Antiguo 28/12/2017, 20:01
 
Fecha de Ingreso: febrero-2015
Mensajes: 404
Antigüedad: 9 años, 2 meses
Puntos: 3
Respuesta: No puedo comprender el siguiente codigo

Pues si pero lo único que quiero es saber que encriptacion usa para poder hacer lo mismo en otro lenguaje. No me voy a lucrar con ello ni lo hago para hacer daño a nadie, solo quiero aprender y tengo un archivo encriptado que este programa lo desencripta pero que no corre en mi máquina porque usa net 4.5 y no lo puedo instalar en XP con lo que no puedo usarlo. El programa es gratuito así que tampoco es tema de piratear nada, solo necesito saber que encriptación usa para desencriptar y encriptar mi archivo. Es para desencriptar los save data de un juego de PS3 y así poder poner cosas como vida infinita, munición infinita...

Etiquetas: errores, siguiente, visual
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:24.