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

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


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

Desconectado Desconectado

Mensajes: 194


Programmer


Ver Perfil WWW
FiletoString Function [VB6]
« en: 8 Abril 2010, 22:29 pm »

Código:
Option Explicit
'--------------------------------------------------------------------------------------------
' Function : FiletoString
' Coder     : The Swash
' References And Constans : API-Guide
' DateTime : 08/04/2010
'--------------------------------------------------------------------------------------------

'Shlwapi.dll
 Private Declare Function PathFileExistsA Lib "shlwapi.dll" (ByVal pszPath As String) As Long

'Kernel32.dll
 Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long
 Private Declare Function CreateFileA Lib "kernel32" (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
 Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long
 Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
 Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long

'Constants
 Const FILE_SHARE_READ = &H1
 Const OPEN_EXISTING = 3
 Const GENERIC_READ = &H80000000
 Const FILE_SHARE_WRITE = &H2
 
Public Function FiletoString(sFile As String) As String
Dim hFile    As Long
Dim hFSize   As Long
Dim bvBuff() As Byte
Dim hBytes   As Long
Dim hRead    As Long

 If PathFileExistsA(sFile) > 0 Then
  hFile = CreateFileA(sFile, GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
  If hFile > 0 Then
   hFSize = GetFileSize(hFile, 0)
   ReDim bvBuff(1 To hFSize)
   hRead = ReadFile(hFile, bvBuff(1), UBound(bvBuff), hBytes, 0&)
   If hRead > 0 Then
    FiletoString = StrConv(bvBuff, vbUnicode)
   End If
  End If
 End If
 
 Call CloseHandle(hFile)
 
End Function

Call:
Código:
Dim sFile As String
 sFile = FiletoString(File path)

Disculpen por la descripcion xD, esta funcion permite obtener las strings de un ejecutable, usado mucho en el mundo del malware pero tambien se puede usar para muchas otras cosas :D



« Última modificación: 8 Abril 2010, 22:45 pm por The Swash » En línea

Shell Root
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.723


<3


Ver Perfil WWW
Re: FiletoString Function [VB6]
« Respuesta #1 en: 8 Abril 2010, 22:29 pm »

Descripción?


En línea

Por eso no duermo, por si tras mi ventana hay un cuervo. Cuelgo de hilos sueltos sabiendo que hay veneno en el aire.
The Swash

Desconectado Desconectado

Mensajes: 194


Programmer


Ver Perfil WWW
Re: FiletoString Function [VB6]
« Respuesta #2 en: 8 Abril 2010, 22:49 pm »

Descripcion puesta en el post prinicipal, siendo exactos esto permite obtener todas las strings del archivo, hay muchos uso que se les puede dar como inyectar en memoria(uso de RunPE), Encryptar, editar, usar para escribir otro archivo, etc..
En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: FiletoString Function [VB6]
« Respuesta #3 en: 8 Abril 2010, 23:13 pm »

No obtiene las cadenas de un ejecutable... sino que obtiene un fichero en forma de cadena... no es muy buena idea... si el fichero pesa mas de 64KB no cabra en un String.
Código:
http://support.microsoft.com/kb/104554/es

De todas formas es mucho codigo, se puede hacer sin APIs, simplemente con las sentencias de VB... Open etc...
Otra cosa, no es necesario que compruebes si existe el fichero, porque si usas CreateFile() con OPEN_EXISTING y no existe el fichero devolverá -1 (INVALID_HANDLE_VALUE), y en err.LastDllError sera igual a 2 (ERROR_FILE_NOT_FOUND)...
En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: FiletoString Function [VB6]
« Respuesta #4 en: 9 Abril 2010, 06:55 am »


Call CloseHandle(hFile)

debe ir despues de ReadFile(), aun ta mal. faltan toques jeje

Dulces Lunas!¡.
En línea

The Dark Shadow is my passion.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[C] PEFileSize function
Programación C/C++
The Swash 4 2,768 Último mensaje 27 Enero 2011, 01:16 am
por The Swash
[Delphi] PEFileSize function
Programación General
Khronos14 1 1,959 Último mensaje 25 Enero 2011, 17:53 pm
por The Swash
API TerminateProcess function « 1 2 »
Programación C/C++
Dark Invader 12 6,479 Último mensaje 11 Octubre 2011, 05:51 am
por Karman
Function Driver y FDO
Análisis y Diseño de Malware
wachi 0 1,632 Último mensaje 9 Abril 2012, 22:20 pm
por wachi
template en function [codigo]
Programación C/C++
bash 1 1,204 Último mensaje 13 Febrero 2016, 14:15 pm
por Stakewinner00
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines