Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: Belial & Grimoire en 1 Febrero 2014, 05:41 am



Título: podrian decirme si la conversion de VB.net a C lo hice bien?
Publicado por: Belial & Grimoire en 1 Febrero 2014, 05:41 am
hola

Estoy tratado de pasar un codigo de VB.NET a C, pero hay unas cosas que no logro enteder, entre ellas una funcion llamada Bitconverter, me podrian ayudar analizando los codigos y decirme si lo estoy haciendo bien?

segun MSDN Bitconverter.ToInt sirve para avanzar a cierto offset y tomar bytes, por ejemplo

bitconverter.ToInt32(buffer, 11)

aqui supuestamente avanzaria al offset 0xB, toma 4 bytes desde el offset 0xB, los cambia a big-endian y lo devuelve en un array de bytes

tampoco se si estoy haciendo bien lo de BitConverter.GetBytes

Esto es lo que hay en la multiplicacion

MFTCluster * SectperCluster * BytesPerSect = 322122547

Código
  1. SetReadFileOffset(NO, MFTCluster * SectperCluster * BytesPerSect)
  2.  
  3. Private Sub SetReadFileOffset(ByRef NO As System.Threading.NativeOverlapped, ByRef curBig As Int64)
  4.        Dim lowoffset() As Byte = BitConverter.GetBytes(curBig)
  5.        Dim highoffset As Int32 = BitConverter.ToInt32(lowoffset, 0)
  6.        Dim high As Int32
  7.        Dim lastbytes(3) As Byte
  8.        Array.Copy(lowoffset, 4, lastbytes, 0, 4)
  9.        high = BitConverter.ToInt32(lastbytes, 0)
  10.        NO.OffsetLow = highoffset
  11.        NO.OffsetHigh = high
  12.    End Sub

Y este es el codigo que yo hice, endianhextodec lo hice para simular lo que haria Bitconverter.ToInt32


Código
  1. long endianhextodec(BYTE *buffers, int offs){
  2.  
  3.    BYTE tmp[1] = {0};
  4.  
  5.       if(offs == 0){
  6.  
  7.        tmp[0] = buffers[0];
  8.        tmp[1] = buffers[1];
  9.        tmp[2] = buffers[2];
  10.        tmp[3] = buffers[3];
  11.  
  12.        return tmp[3] << 24;
  13.    }
  14. }
  15.  
  16.  
  17. setreadfileoffset(overlapped, (sectperclusters * (bytespercluster * MFTCluster)));
  18.  
  19.  
  20. void setreadfileoffset(OVERLAPPED overlap, INT64 crbig ){
  21.  
  22. BYTE *lowoffset = (BYTE*)malloc(sizeof(crbig));
  23. INT32 higoffset = endianhextodec(lowoffset, 0);
  24. INT32 high;
  25. BYTE lastbytes[3];
  26.  
  27. for(int i = 0; i < 4; i++){
  28. for(int n = 4; n > 0; n--){
  29.  
  30. lastbytes[i] = lowoffset[n];
  31. }
  32. }
  33.  
  34. high = endianhextodec(lastbytes, 0);
  35. overlap.Offset = higoffset;
  36. overlap.OffsetHigh = high;
  37. }

espero puedan decirme si lo encuentran bien o estoy totalmente equivocado

salu2


Título: Re: podrian decirme si la conversion de VB.net a C lo hice bien?
Publicado por: raul338 en 2 Febrero 2014, 01:46 am
Te lo muevo a .Net donde te podrán ayudar mejor