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

 

 


Tema destacado: Tutorial básico de Quickjs


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

Desconectado Desconectado

Mensajes: 272


El testamento Maya...


Ver Perfil
comprimir archivo
« en: 23 Noviembre 2008, 18:43 pm »

Wenas, digamos q creamos un archivo desde nuestro exe (un txt por ejemplo) y una vez creado ¿se podria 'meter' a un rar o zip desde vb?

un saludo ;)


En línea

En mi cabeza existe una barrera espacio-tiempo de 4cm³. ¿Alguien sabe como eliminarla?.
                                                                                                                                                                                                                            
ricardovinzo

Desconectado Desconectado

Mensajes: 135


P.T.C


Ver Perfil
Re: comprimir archivo
« Respuesta #1 en: 23 Noviembre 2008, 20:32 pm »

Si se puede, obviamente no con el VB puro.. necesitas APIs o algo asi.. tambien puedes hacerlo mediante el mismo WinRar o Winzip..
Aqui te dejo un modulo para que lo veas y veas como lo hace.. ( no creado por mi )

mCompressFile para comprimir archivos


En línea

3# Convocacion de Moderadores en Code Makers, entra!
WestOn

Desconectado Desconectado

Mensajes: 272


El testamento Maya...


Ver Perfil
Re: comprimir archivo
« Respuesta #2 en: 23 Noviembre 2008, 22:23 pm »

Grax voy a mirarlo, tiene buena pinta :P

un saludo
En línea

En mi cabeza existe una barrera espacio-tiempo de 4cm³. ¿Alguien sabe como eliminarla?.
                                                                                                                                                                                                                            
XcryptOR

Desconectado Desconectado

Mensajes: 228



Ver Perfil
Re: comprimir archivo
« Respuesta #3 en: 24 Noviembre 2008, 01:56 am »

esta funcion la incorpora el win xp y el vista, a mi siempre me funciona, pueda que tengas problemas en algunos windows desatendidos.

Citar
Si se puede, obviamente no con el VB puro.. necesitas APIs o algo asi.. tambien puedes hacerlo mediante el mismo WinRar o Winzip..
Aqui te dejo un modulo para que lo veas y veas como lo hace.. ( no creado por mi )

mCompressFile para comprimir archivos

el code anterior: mCompressFile es efectivo pues casi todos los pcs incluyen el winrar, winzip o los tienen instalados eso lo utilizo en un worm machinedramon hace unos años ya es viejito pero funciona.
Código
  1.  
  2. Sub Zipea(ByVal sZIPFileName, ByVal sFileName)
  3. Dim oShell As Object
  4. Dim oZip As Object
  5. Open sZIPFileName For Output As #1
  6. Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
  7. Close #1
  8. ' copia el arcivo en la carpeta comprimida
  9. Set oShell = CreateObject("Shell.Application")
  10. Set oZip = oShell.Namespace(sZIPFileName)
  11. oZip.CopyHere sFileName
  12. ' bucle que controla hasta que la compresion se haya realizado
  13. Do Until oZip.Items.Count = 1
  14. DoEvents
  15. Loop
  16. Set oZip = Nothing
  17. Set oShell = Nothing
  18. End Sub
  19.  
  20. Private Sub Form_Load()
  21. Zipea "C:\myfile.zip", "C:\cualquierfile"
  22. End Sub
  23.  
  24.  
« Última modificación: 24 Noviembre 2008, 01:58 am por XcryptOR » En línea



XcryptOR

Desconectado Desconectado

Mensajes: 228



Ver Perfil
Re: comprimir archivo
« Respuesta #4 en: 24 Noviembre 2008, 02:03 am »

Igualmente este code basado en el zipstore del MyDoom puede servirte eso si solo funciona en tiempo de ejecucion compilado presenta error, si alguien puede decirme porque pasa o quizas donde radica el error pues la verdad ni controlando los errores funciona al compilar y ejecutar

form:
Código
  1. Call Zipea("archivo_a_comprimir", "nombre_del_zip", "nombre_del_archivo_dentro_del_Zip")
  2.  

modulo:
Código
  1. 'Codigo para Zipear Basado en zipstore.c del worm Mydoom
  2. 'y Small ZIP Component de www.positronvx.cjb.net en DELPHI
  3.  
  4. Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  5. Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Long) As Long
  6. Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As Long) As Long
  7. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  8. Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
  9. Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
  10. Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
  11. Private Declare Sub ZeroMemory Lib "kernel32" Alias "RtlZeroMemory" (dest As Any, ByVal numbytes As Long)
  12. Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
  13. Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
  14. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  15.  
  16. Private Const FILE_BEGIN = 0
  17. Private Const GENERIC_READ = &H80000000
  18. Private Const GENERIC_WRITE = &H40000000
  19. Private Const FILE_SHARE_READ = &H1
  20. Private Const CREATE_ALWAYS = 2
  21. Private Const OPEN_EXISTING = 3
  22. Private Const INVALID_HANDLE_VALUE = -1
  23. Private Const GMEM_FIXED = &H0
  24. Private Const GMEM_ZEROINIT = &H40
  25. Private Const GPTR = (GMEM_FIXED Or GMEM_ZEROINIT)
  26.  
  27. Private Type LOCAL_FILE_HEADER
  28. signature As Long          'Firma &H04034b50
  29. ver_needed As Integer      'Version minima de software necesaria para extraer el archivo
  30. flags As Integer           'Opciones
  31. method As Integer          'Metodo de compresion
  32. lastmod_time As Integer    'Tiempo de ultima modificacion
  33. lastmod_date As Integer    'Fecha de ultima modificacion
  34. crcLO As Integer                'CRC del file
  35. crcHI As Integer
  36. compressed_sizeLO As Integer    'Tamaño de file comprimido
  37. compressed_sizeHI As Integer
  38. uncompressed_sizeLO As Integer  'Tamaño del file sin comprimir
  39. uncompressed_sizeHI As Integer
  40. filename_length As Integer 'Longitud del nombre del Archivo
  41. extra_length As Integer    'Longitud de "InFormacion Adicional" ¿?
  42. End Type
  43.  
  44. Private Type CENTRAL_DIRECTORY_STRUCTURE
  45. signature As Long          'FIRMA &H02014b50
  46. made_by As Integer         'Indica SO y version de software donde se comprimio el file
  47. ver_needed As Integer      'Version minima de software necesaria para extraer el archivo
  48. flags As Integer           'Opciones
  49. method As Integer          'Metodo de compresion
  50. lastmod_time As Integer    'Tiempo de ultima modificacion
  51. lastmod_date As Integer    'Fecha de ultima modificacion
  52. crc As Long                'CRC del file
  53. compressed_size As Long    'Tamaño de file comprimido
  54. uncompressed_size As Long  'Tamaño del file sin comprimir
  55. filename_length As Integer 'Longitud del nombre del Archivo
  56. extra_length As Integer    'Longitud de "InFormacion Adicional" ¿?
  57. comment_length As Integer  'Longitud de los comentarios
  58. disk_nums As Integer       'El número del disco por el cual este archivo comienza ¿?
  59. internal_attr As Integer   'Opciones entre ellas: Si el file tiene datos ASCII(texto) o Binarios
  60. external_attrLO As Integer 'Opciones entre ellas: Tipo de Sistema de Archivos
  61. external_attrHI As Integer '
  62. local_offs As Long         'N° de Byte donde comienza el correspondiente
  63.                            'LOCAL_FILE_HEADER de esta struct CENTRAL_DIRECTORY_STRUCTURE
  64. End Type
  65.  
  66. Private Type END_CENTRAL_DIR
  67. signature As Long           'FIrma &H06054b50
  68. disk_nums As Integer        '"El número de este disco, que contiene el expediente de extremo central del directorio" ¿?
  69. disk_dirstart As Integer    '"El número del disco en el cual el directorio central comienza" ¿?
  70. disk_dir_entries As Integer 'El número de entradas en el central directory en este disco
  71. dir_entries As Integer      'El número total de archivos en el zipfile
  72. dir_size As Long            'El tamaño (en bytes) de la o las CENTRAL_DIRECTORY_STRUCTURE que contenga el zip
  73. dir_offs As Long            'N° de Byte donde comienza la CENTRAL_DIRECTORY_STRUCTURE o la primera CENTRAL_DIRECTORY_STRUCTURE
  74.                             'si es que hay más de una
  75. comment_length As Integer   'Longitud de los Comentarios
  76. End Type
  77.  
  78. Private Type SYSTEMTIME
  79. wYear As Integer
  80. wMonth As Integer
  81. wDayOfWeek As Integer
  82. wDay As Integer
  83. wHour As Integer
  84. wMinute As Integer
  85. wSecond As Integer
  86. wMilliseconds As Integer
  87. End Type
  88.  
  89. Private Type HL_DWORD
  90. LOWORD As Integer
  91. HIWORD As Integer
  92. End Type
  93.  
  94. Private CRCTable(256) As Long
  95.  
  96. Private Sub SetCRCTable()
  97. 'Code CRC32 de www.vbaccelerator.com
  98. On Error Resume Next
  99. Dim dwPolynomial As Long, dwCrc As Long, i As Integer, j As Integer
  100. dwPolynomial = &HEDB88320
  101.  
  102. For i = 0 To 255
  103.  dwCrc = i
  104.  For j = 8 To 1 Step -1
  105.   If (dwCrc And 1) Then
  106.   dwCrc = ((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF
  107.   dwCrc = dwCrc Xor dwPolynomial
  108.   Else
  109.   dwCrc = ((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF
  110.   End If
  111.  Next
  112.  CRCTable(i) = dwCrc
  113. Next
  114. End Sub
  115.  
  116. Private Function GetCRC32(Buffer As String) As Long
  117. 'Code CRC32 de www.vbaccelerator.com
  118. On Error Resume Next
  119. Dim crc As Long, i As Long, iLookup As Integer
  120.  
  121. crc = &HFFFFFFFF
  122.  
  123. For i = 1 To Len(Buffer)
  124. iLookup = (crc And &HFF) Xor Asc(Mid(Buffer, i, 1))
  125. crc = ((crc And &HFFFFFF00) \ &H100) And 16777215
  126. crc = crc Xor CRCTable(iLookup)
  127. Next
  128.  
  129. GetCRC32 = Not (crc)
  130. End Function
  131.  
  132. Public Function Zipea(ffile As String, fzip As String, fname As String) As Boolean
  133. On Error Resume Next
  134. Dim lfh As LOCAL_FILE_HEADER
  135. Dim cds As CENTRAL_DIRECTORY_STRUCTURE
  136. Dim ecd As END_CENTRAL_DIR
  137. Dim st As SYSTEMTIME
  138. Dim File As String, FPtr As Long
  139. Dim sz As Long, dw As Long, o As Long
  140. Dim hFile As Long, hZip As Long
  141. Dim HL As HL_DWORD
  142. Dim CRC32 As Long
  143.  
  144. o = 0
  145.  
  146. hFile = CreateFile(ffile, GENERIC_READ, FILE_SHARE_READ, ByVal 0&, OPEN_EXISTING, 0, 0)
  147. If (hFile = INVALID_HANDLE_VALUE) Then Zipea = False: Exit Function
  148.  
  149. hZip = CreateFile(fzip, GENERIC_WRITE, FILE_SHARE_READ, ByVal 0&, CREATE_ALWAYS, 0, 0)
  150. If (hZip = INVALID_HANDLE_VALUE) Then CloseHandle (hFile): Zipea = False: Exit Function
  151.  
  152. ZeroMemory ByVal lfh, Len(lfh)
  153. ZeroMemory ByVal cds, Len(cds)
  154. ZeroMemory ByVal ecd, Len(ecd)
  155.  
  156. Call GetSystemTime(st)
  157. If (st.wHour > 12) Then st.wHour = st.wHour - 12
  158.  
  159. sz = GetFileSize(hFile, 0)
  160.  
  161. lfh.signature = &H4034B50
  162. lfh.ver_needed = 10
  163. lfh.flags = 0
  164. lfh.method = 0
  165. lfh.lastmod_time = (st.wHour) * (2 ^ 11) Or (st.wMinute * (2 ^ 5)) Or (st.wSecond / 2)
  166. lfh.lastmod_date = ((st.wYear - 1980) * (2 ^ 9)) Or (st.wMonth * (2 ^ 5)) Or (st.wDay)
  167. CopyMemory ByVal HL, sz, 4
  168. lfh.uncompressed_sizeHI = HL.HIWORD And &HFFFF
  169. lfh.uncompressed_sizeLO = HL.LOWORD And &HFFFF
  170. lfh.compressed_sizeHI = HL.HIWORD And &HFFFF
  171. lfh.compressed_sizeLO = HL.LOWORD And &HFFFF
  172. lfh.filename_length = Len(fname)
  173. lfh.extra_length = 0
  174.  
  175. cds.signature = &H2014B50
  176. cds.made_by = 20           'MSDOS=0, PKZIP 2.0 =20
  177. cds.ver_needed = 10
  178. cds.flags = 0
  179. cds.method = 0
  180. cds.lastmod_time = (st.wHour) * (2 ^ 11) Or (st.wMinute * (2 ^ 5)) Or (st.wSecond / 2)
  181. cds.lastmod_date = ((st.wYear - 1980) * (2 ^ 9)) Or (st.wMonth * (2 ^ 5)) Or (st.wDay)
  182. cds.compressed_size = sz
  183. cds.uncompressed_size = sz
  184. cds.filename_length = Len(fname)
  185. cds.extra_length = 0
  186. cds.comment_length = 0
  187. cds.disk_nums = 0
  188. cds.local_offs = 0
  189. cds.internal_attr = 0      'Datos Binarios
  190. cds.external_attrLO = &H20 'FAT_32 (&H20=32)
  191. cds.external_attrHI = &H0
  192.  
  193. Call SetFilePointer(hFile, 0, 0, FILE_BEGIN)
  194. FPtr = GlobalAlloc(GPTR, sz)
  195. If (FPtr = 0) Then Zipea = False: GoTo Cierra
  196.  
  197.  Call ReadFile(hFile, ByVal FPtr, sz, dw, ByVal 0)
  198.  If (dw = 0) Then Zipea = False: GoTo Cierra
  199.  
  200.  File = Space$(dw)
  201.  CopyMemory ByVal File, ByVal FPtr, dw
  202.  
  203. Call SetCRCTable
  204.  
  205. CRC32 = GetCRC32(File)
  206.  
  207. CopyMemory ByVal HL, CRC32, 4
  208. lfh.crcLO = HL.LOWORD And &HFFFF
  209. lfh.crcHI = HL.HIWORD And &HFFFF
  210.  
  211. cds.crc = CRC32
  212.  
  213. Call WriteFile(hZip, ByVal lfh, Len(lfh), dw, ByVal 0&)
  214. Call WriteFile(hZip, ByVal fname, Len(fname), dw, ByVal 0&)
  215. Call WriteFile(hZip, ByVal File, sz, dw, ByVal 0&)
  216.  
  217. GlobalFree (FPtr)
  218. o = o + (Len(lfh) + Len(fname) + sz)
  219.  
  220. ecd.dir_offs = o
  221.  
  222. Call WriteFile(hZip, ByVal cds, Len(cds), dw, ByVal 0&)
  223. Call WriteFile(hZip, ByVal fname, Len(fname), dw, ByVal 0&)
  224. o = o + (Len(cds) + Len(fname))
  225.  
  226. ecd.signature = &H6054B50
  227. ecd.disk_nums = 0
  228. ecd.disk_dirstart = 0
  229. ecd.disk_dir_entries = 1
  230. ecd.dir_entries = 1
  231. ecd.dir_size = o - ecd.dir_offs
  232. ecd.comment_length = 0
  233. Call WriteFile(hZip, ByVal ecd, Len(ecd), dw, ByVal 0&)
  234.  
  235. Zipea = True
  236. Cierra:
  237. CloseHandle (hFile): CloseHandle (hZip)
  238. End Function
  239.  


En línea



WestOn

Desconectado Desconectado

Mensajes: 272


El testamento Maya...


Ver Perfil
Re: comprimir archivo
« Respuesta #5 en: 24 Noviembre 2008, 02:14 am »

Wenas, el primer ejemplo q pusiste es bastante intuitivo, ademas es pequeño el code :P
En el segundo aun no lo he probado, pero si averiguo porq da error sin compilar ya lo posteo  ;)

un saludo

PD:No tengo ni dea de porq da error :huh:
« Última modificación: 24 Noviembre 2008, 02:23 am por WestOn » En línea

En mi cabeza existe una barrera espacio-tiempo de 4cm³. ¿Alguien sabe como eliminarla?.
                                                                                                                                                                                                                            
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
comprimir archivo msi
Software
ratadigital 2 2,058 Último mensaje 22 Noviembre 2011, 12:36 pm
por ratadigital
Comprimir un archivo de video .mpg
Multimedia
Pox1 1 4,521 Último mensaje 7 Enero 2012, 21:11 pm
por Songoku
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines