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

 

 


Tema destacado: Curso de javascript por TickTack


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


Desconectado Desconectado

Mensajes: 900


Ver Perfil
Re: leer archivo con api's
« Respuesta #10 en: 14 Julio 2008, 16:25 pm »

Código
  1. Const MOVEFILE_REPLACE_EXISTING = &H1
  2. Const FILE_ATTRIBUTE_TEMPORARY = &H100
  3. Const FILE_BEGIN = 0
  4. Const FILE_SHARE_READ = &H1
  5. Const FILE_SHARE_WRITE = &H2
  6. Const CREATE_NEW = 1
  7. Const OPEN_EXISTING = 3
  8. Const GENERIC_READ = &H80000000
  9. Const GENERIC_WRITE = &H40000000
  10. Private Declare Function SetVolumeLabel Lib "kernel32" Alias "SetVolumeLabelA" (ByVal lpRootPathName As String, ByVal lpVolumeName As String) As Long
  11. 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
  12. 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
  13. Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  14. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  15. Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
  16. Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
  17. Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
  18. Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
  19. Private Declare Function MoveFileEx Lib "kernel32" Alias "MoveFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal dwFlags As Long) As Long
  20. Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
  21. Private Sub Form_Load()
  22.    'KPD-Team 1998
  23.    'URL: http://www.allapi.net/
  24.    'E-Mail: KPDTeam@Allapi.net
  25.    Dim sSave As String, hOrgFile As Long, hNewFile As Long, bBytes() As Byte
  26.    Dim sTemp As String, nSize As Long, Ret As Long
  27.    'Ask for a new volume label
  28.    sSave = InputBox("Please enter a new volume label for drive C:\" + vbCrLf + " (if you don't want to change it, leave the textbox blank)")
  29.    If sSave <> "" Then
  30.        SetVolumeLabel "C:\", sSave
  31.    End If
  32.  
  33.    'Create a buffer
  34.    sTemp = String(260, 0)
  35.    'Get a temporary filename
  36.    GetTempFileName "C:\", "KPD", 0, sTemp
  37.    'Remove all the unnecessary chr$(0)'s
  38.    sTemp = Left$(sTemp, InStr(1, sTemp, Chr$(0)) - 1)
  39.    'Set the file attributes
  40.    SetFileAttributes sTemp, FILE_ATTRIBUTE_TEMPORARY
  41.    'Open the files
  42.    hNewFile = CreateFile(sTemp, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
  43.    hOrgFile = CreateFile("c:\config.sys", GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
  44.  
  45.    'Get the file size
  46.    nSize = GetFileSize(hOrgFile, 0)
  47.    'Set the file pointer
  48.    SetFilePointer hOrgFile, Int(nSize / 2), 0, FILE_BEGIN
  49.    'Create an array of bytes
  50.    ReDim bBytes(1 To nSize - Int(nSize / 2)) As Byte
  51.    'Read from the file
  52.    ReadFile hOrgFile, bBytes(1), UBound(bBytes), Ret, ByVal 0&
  53.    'Check for errors
  54.    If Ret <> UBound(bBytes) Then MsgBox "Error reading file ..."
  55.  
  56.    'Write to the file
  57.    WriteFile hNewFile, bBytes(1), UBound(bBytes), Ret, ByVal 0&
  58.    'Check for errors
  59.    If Ret <> UBound(bBytes) Then MsgBox "Error writing file ..."
  60.  
  61.    'Close the files
  62.    CloseHandle hOrgFile
  63.    CloseHandle hNewFile
  64.  
  65.    'Move the file
  66.    MoveFileEx sTemp, "C:\KPDTEST.TST", MOVEFILE_REPLACE_EXISTING
  67.    'Delete the file
  68.    DeleteFile "C:\KPDTEST.TST"
  69.    Unload Me
  70. End Sub


En línea

Mi blog
Bienvenido krackwar, actualmente tu puntuación es de 38 puntos y tu rango es Veteran.
El pollo número 1, es decir yo, (krackwar), adoro a Shaddy como a un dios.
cast0r

Desconectado Desconectado

Mensajes: 16


Ver Perfil
Re: leer archivo con api's
« Respuesta #11 en: 14 Julio 2008, 16:43 pm »

Krackwar por lo que veo en el codigo que posteaste lo que hace es una copia temporal de el archivo en ejecucion y luego abre la copia para obtener el handle y leerlo, no hay una manera con createfile que haga lo mismo que este codigo, o con alguna otra api.

Open app.path & "\" & app.exename for binary as #1

quiero hacerlo solo con apis para luego pasarlo a ASM


En línea

krackwar


Desconectado Desconectado

Mensajes: 900


Ver Perfil
Re: leer archivo con api's
« Respuesta #12 en: 14 Julio 2008, 17:00 pm »

Krackwar por lo que veo en el codigo que posteaste lo que hace es una copia temporal de el archivo en ejecucion y luego abre la copia para obtener el handle y leerlo, no hay una manera con createfile que haga lo mismo que este codigo, o con alguna otra api.

Open app.path & "\" & app.exename for binary as #1

quiero hacerlo solo con apis para luego pasarlo a ASM
Un code en asm para abrir archivos.
http://foro.eduhack.es/index.php?PHPSESSID=e92f7a2ac60d5e7ca408d96925b3793f&topic=659.msg1507#msg1507
Lo abred y obtiene su peso.
En línea

Mi blog
Bienvenido krackwar, actualmente tu puntuación es de 38 puntos y tu rango es Veteran.
El pollo número 1, es decir yo, (krackwar), adoro a Shaddy como a un dios.
Páginas: 1 [2] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ayuda con BAT leer Archivo « 1 2 3 4 »
Scripting
elecktra 30 24,251 Último mensaje 9 Octubre 2009, 05:27 am
por Aranguez
Leer Archivo en pascal
Programación General
¡Micronet! 6 8,275 Último mensaje 26 Enero 2011, 01:20 am
por ¡Micronet!
Leer archivo txt y pasarlo a un arreglo
Java
ZedGe 6 30,339 Último mensaje 11 Junio 2011, 15:14 pm
por barbieturico
Problema en C++ al leer archivo .txt « 1 2 »
Programación C/C++
javier_SL 10 12,590 Último mensaje 21 Junio 2011, 00:54 am
por Danyel_Casvill
leer cadena de archivo en c#
.NET (C#, VB.NET, ASP)
alan03 0 3,389 Último mensaje 22 Julio 2011, 20:01 pm
por alan03
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines