elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Arreglado, de nuevo, el registro del warzone (wargame) de EHN


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  [RESUELTO] CopyMem Array VarTypes
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [RESUELTO] CopyMem Array VarTypes  (Leído 4,947 veces)
Miseryk

Desconectado Desconectado

Mensajes: 225


SI.NU.SA U.GU.DE (2NE1 - D-Unit)


Ver Perfil
[RESUELTO] CopyMem Array VarTypes
« en: 9 Mayo 2013, 21:45 pm »

Estaba tratando de mover memoria entre arrays.

Hice este ejemplo, tal vez puedan mejorarlo y/o ayudame con Variant :P

Código
  1. Modulo:
  2. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
  3.        (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
  4.  
  5. Form:
  6. Private Sub Form_Load()
  7. Dim ESI(3 To 6) As Variant
  8. Dim EDI(3 To 6) As Variant
  9.  
  10. ESI(3) = "asdasdasdasdsd12312331231asdasd" '255 '32767 '2147483647
  11. ESI(4) = ESI(3)
  12. ESI(5) = ESI(3)
  13. ESI(6) = ESI(3)
  14.  
  15. EDI(3) = 0
  16. EDI(4) = EDI(3)
  17. EDI(5) = EDI(3)
  18. EDI(6) = EDI(3)
  19.  
  20. CopyMemory EDI(LBound(EDI)), ESI(LBound(ESI)), GetSizeArray(ESI)
  21.  
  22. Dim i As Byte
  23.  
  24. For i = LBound(ESI) To UBound(ESI)
  25.    MsgBox i & ": " & (ESI(i) = EDI(i)) & vbCrLf & "&H" & Hex(VarPtr(ESI(i)))
  26. Next i
  27.  
  28. End
  29. End Sub
  30.  
  31. Private Function GetSizeArray(ByRef vArray)
  32. Dim BaseBytes As Byte
  33.  
  34. 'MsgBox TypeName(vArray)
  35.  
  36. Select Case TypeName(vArray)
  37.    Case "Byte()"
  38.        BaseBytes = 1
  39.    Case "Boolean()", "Integer()"
  40.        BaseBytes = 2
  41.    Case "Long()", "Single()"
  42.        BaseBytes = 4
  43.    Case "Double()", "Currency()", "Date()"
  44.        BaseBytes = 8
  45.    Case "Variant()"
  46.        BaseBytes = 0 'DUNNO
  47.    Case "String()"
  48.        BaseBytes = 4 'ReadMem del VarPtr está el Address al string con su len 4 bytes antes
  49. End Select
  50.  
  51. GetSizeArray = BaseBytes * (UBound(vArray) - LBound(vArray) + 1)
  52. End Function
  53.  

Edit:
Se podría tomar como un reto *-)


« Última modificación: 22 Junio 2013, 02:51 am por Miseryk » En línea

Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It’s never too late to change our luck
So, don’t let them steal your light
Don’t let them break your stride
There is light on the other side
And you’ll see all the raindrops falling behind
Make it out tonight
it’s a revolution

CL!!!
Psyke1
Wiki

Desconectado Desconectado

Mensajes: 1.089



Ver Perfil WWW
Re: [AYUDA] CopyMem Array VarTypes
« Respuesta #1 en: 8 Junio 2013, 19:19 pm »

Mírate esto:

Código:
http://msdn.microsoft.com/en-us/library/aa263420(v=vs.60).aspx

DoEvents! :P


En línea

Miseryk

Desconectado Desconectado

Mensajes: 225


SI.NU.SA U.GU.DE (2NE1 - D-Unit)


Ver Perfil
Re: [AYUDA] CopyMem Array VarTypes
« Respuesta #2 en: 18 Junio 2013, 11:46 am »

Ya la había visto esa página, pero no funciona como dice ahí, ya que el string son 4 bytes, porque hace referencia a un puntero y no a la longitud del mismo, con hacer mov eax, [strvar] está moviendo el puntero del str hacia eax, lo mismo que hace StrPtr supongo.
En línea

Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It’s never too late to change our luck
So, don’t let them steal your light
Don’t let them break your stride
There is light on the other side
And you’ll see all the raindrops falling behind
Make it out tonight
it’s a revolution

CL!!!
Danyfirex


Desconectado Desconectado

Mensajes: 493


My Dear Mizuho


Ver Perfil
Re: [AYUDA] CopyMem Array VarTypes
« Respuesta #3 en: 18 Junio 2013, 16:01 pm »

Mira esto http://www.codeguru.com/vb/gen/vb_misc/algorithms/article.php/c7495/How-Visual-Basic-6-Stores-Data.htm

saludos
En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [AYUDA] CopyMem Array VarTypes
« Respuesta #4 en: 19 Junio 2013, 05:07 am »

Los VARIANT siguen esta estructura:
Código:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms221627(v=vs.85).aspx

Las cadenas son BSTR:
Código:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms221069(v=vs.85).aspx
Y para obtener el puntero a su estructura real debes usar StrPtr().

Los tipos que utiliza VB6 en memoria se conocen como OLETypes. Internamente VB6 hace uso de funciones de OLEAUT32 para trabajar con ellos. Aquí tienes más información sobre éstos:
Código:
http://www.roblocher.com/whitepapers/oletypes.aspx

Saludos
En línea

Miseryk

Desconectado Desconectado

Mensajes: 225


SI.NU.SA U.GU.DE (2NE1 - D-Unit)


Ver Perfil
Re: [RESUELTO] CopyMem Array VarTypes
« Respuesta #5 en: 22 Junio 2013, 02:51 am »

Gracias por su ayuda, creo que así está bien:

Modulo:
Código
  1. Option Explicit
  2.  
  3. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
  4. Public Declare Function VirtualProtect Lib "kernel32" (lpAddress As Any, ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long
  5.  
  6. Public Const PAGE_EXECUTE_READWRITE As Long = &H40&
  7.  
  8. Public Function GetMem(ByVal lpAddr As Long, ByVal pData As Long, ByVal dlen As Long) As Boolean
  9. Dim lngOldProtect   As Long
  10.  
  11. If 0 = VirtualProtect(ByVal lpAddr, dlen, PAGE_EXECUTE_READWRITE, lngOldProtect) Then
  12.    Exit Function
  13. End If
  14.  
  15. CopyMemory ByVal pData, ByVal lpAddr, dlen
  16. VirtualProtect ByVal lpAddr, dlen, lngOldProtect, lngOldProtect
  17.  
  18. GetMem = True
  19. End Function
  20.  
  21. Public Function PutMem(ByVal lpAddr As Long, ByVal pData As Long, ByVal dlen As Long) As Boolean
  22. Dim lngOldProtect   As Long
  23.  
  24. If 0 = VirtualProtect(ByVal lpAddr, dlen, PAGE_EXECUTE_READWRITE, lngOldProtect) Then
  25.    Exit Function
  26. End If
  27.  
  28. CopyMemory ByVal lpAddr, ByVal pData, dlen
  29. VirtualProtect ByVal lpAddr, dlen, lngOldProtect, lngOldProtect
  30.  
  31. PutMem = True
  32. End Function
  33.  

Código
  1. Option Explicit
  2.  
  3. 'http://msdn.microsoft.com/en-us/library/aa263420(v=vs.60).aspx
  4.  
  5. 'http://www.codeguru.com/vb/gen/vb_misc/algorithms/article.php/c7495/How-Visual-Basic-6-Stores-Data.htm
  6.  
  7. 'http://msdn.microsoft.com/en-us/library/windows/desktop/ms221627(v=vs.85).aspx
  8. 'http://msdn.microsoft.com/en-us/library/windows/desktop/ms221069(v=vs.85).aspx
  9. 'http://www.roblocher.com/whitepapers/oletypes.aspx
  10.  
  11. Private Sub Form_Load()
  12. Dim ESI(3 To 6) As Variant
  13. Dim EDI(3 To 6) As Variant
  14.  
  15. Dim i As Byte
  16.  
  17. ESI(3) = "2NE1" '255 '32767 '2147483647
  18. ESI(4) = "CL"
  19. ESI(5) = "THE BADDEST FEMALE"
  20. ESI(6) = "This is for all my bad girls around the world, Not bad meaning bad but bad meaning good u know, Let’s light it up and let it burn like we don’t care, Let em know how it feels damn good to be bad"
  21.  
  22. 'For i = LBound(ESI) To UBound(ESI)
  23. '    MsgBox i & ": " & (ESI(i) = EDI(i)) & vbCrLf & ESI(i) & " = " & EDI(i) & vbCrLf & "ESI: &H" & Hex(VarPtr(ESI(i))) & vbCrLf & "EDI: &H" & Hex(VarPtr(EDI(i)))
  24. 'Next i
  25. 'Stop
  26.  
  27. 'Call PutMem(VarPtr(EDI(LBound(EDI))), VarPtr(ESI(LBound(ESI))), GetSizeArray(ESI))
  28. Call PutMem(VarPtr(EDI(LBound(EDI))), VarPtr(ESI(LBound(ESI))), GetSizeArray(ESI)) '60 tmb
  29.  
  30. For i = LBound(ESI) To UBound(ESI)
  31.    MsgBox i & ": " & (ESI(i) = EDI(i)) & vbCrLf & ESI(i) & " = " & EDI(i) & vbCrLf & "ESI: &H" & Hex(VarPtr(ESI(i))) & vbCrLf & "EDI: &H" & Hex(VarPtr(EDI(i)))
  32. Next i
  33. End
  34. End Sub
  35.  
  36. Private Function GetSizeArray(ByRef vArray)
  37. Dim BaseBytes As Byte
  38.  
  39. 'MsgBox TypeName(vArray)
  40.  
  41. Select Case TypeName(vArray)
  42.    Case "Byte()"
  43.        BaseBytes = 1
  44.    Case "Boolean()", "Integer()"
  45.        BaseBytes = 2
  46.    Case "Long()", "Single()"
  47.        BaseBytes = 4
  48.    Case "Double()", "Currency()", "Date()"
  49.        BaseBytes = 8
  50.    Case "Variant()"
  51.        'The variant is 16 bytes large.
  52.        'It has 2 bytes to describe the type of data it is storing, 6 reserved bytes, and 8 bytes to store the data (each block represents a byte).
  53.        BaseBytes = 16
  54.    Case "String()"
  55.        BaseBytes = 4 'ReadMem del VarPtr está el Address al string con su len 4 bytes antes
  56. End Select
  57.  
  58. GetSizeArray = BaseBytes * (UBound(vArray) - LBound(vArray) + 1)
  59. End Function
  60.  
« Última modificación: 22 Junio 2013, 02:53 am por Miseryk » En línea

Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It’s never too late to change our luck
So, don’t let them steal your light
Don’t let them break your stride
There is light on the other side
And you’ll see all the raindrops falling behind
Make it out tonight
it’s a revolution

CL!!!
Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [RESUELTO] CopyMem Array VarTypes
« Respuesta #6 en: 22 Junio 2013, 23:29 pm »

No he podido probarlo porque estoy lejos del IDE, pero una recomendación es que uses VarType() en lugar de TypeName() para trabajar con constantes en lugar de cadenas :)
En línea

Miseryk

Desconectado Desconectado

Mensajes: 225


SI.NU.SA U.GU.DE (2NE1 - D-Unit)


Ver Perfil
Re: [RESUELTO] CopyMem Array VarTypes
« Respuesta #7 en: 29 Junio 2013, 07:55 am »

Sí, es mejor VarType, no lo hice así porque tenía pereza de crear constantes y asignarles ese número :D :D :D
En línea

Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It’s never too late to change our luck
So, don’t let them steal your light
Don’t let them break your stride
There is light on the other side
And you’ll see all the raindrops falling behind
Make it out tonight
it’s a revolution

CL!!!
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ayuda con array... (Resuelto)
Programación C/C++
miketru 6 6,832 Último mensaje 9 Septiembre 2010, 01:35 am
por miketru
[Bash] Problema con array [resuelto]
Scripting
hervasiop12345 8 7,874 Último mensaje 21 Julio 2011, 10:15 am
por hervasiop12345
[Resuelto] Allegro 5 - Array de BITMAPS
Programación C/C++
NOIS 0 1,632 Último mensaje 14 Noviembre 2014, 10:06 am
por NOIS
[Resuelto] incrementar clave de un array ()
PHP
Crarmon 3 1,904 Último mensaje 20 Enero 2015, 01:54 am
por T. Collins
[Resuelto] Problemas con un Array
PHP
DeXon18 2 1,753 Último mensaje 3 Junio 2015, 20:22 pm
por DeXon18
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines