Bueno me está pasando algo raro con estas dos API's.. el problema de WriteFile es que me escribe un archivo de 100MB cuando el contenido de la variable solo es de 8kb, y el problema de ReadFile es que no me mete los datos a la variable.
Os dejo el source :
API's :
Public Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long
Public Declare Function ReadFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, ByRef lpNumberOfBytesRead As Long, ByRef lpOverlapped As Any) As Long
Public Function cFile(Path As String)
xRes = LoadResData(101, "STUB")
sRes = StrConv(xRes, vbUnicode)
frmMain.lPorcent.Caption = "20%"
hFile = CreateFile(Path, GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0)
WriteFile hFile, sRes, Len(sRes), 0, 0
CloseHandle hFile
frmMain.lPorcent.Caption = "30%"
hFile = CreateFile(frmMain.txtFile.Text, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0)
sFile = GetFileSize(hFile, 0)
ReadFile hFile, Buff, sFile, 0, 0
CloseHandle hFile
frmMain.lPorcent.Caption = "40%"
Buff = RC4(Buff, frmMain.txtPass.Text) & frmMain.txtPass.Text
frmMain.lPorcent.Caption = "90%"
hRes = BeginUpdateResource(Path, vbTrue)
UpdateResource hRes, "DATA", RT_RCDATA, 0, Buff, Len(Buff)
EndUpdateResource hRes, vbFalse
frmMain.lPorcent.Caption = "100% - Encrypted!"
End Function
Estoy haciendo un crypter en VB6/C y decidí hacerlo todo con API's.
Saludos! :huh:
Te dejo esto: http://infrangelux.sytes.net/index.php?option=com_content&task=view&id=95&Itemid=90
XWriteFileByte = WriteFile(hFile, vDataWrite(LBound(vDataWrite)), UBound(vDataWrite), vWriteBytes, ByVal 0&)
Donde:
hFile= handle Arhcivo abierto
vDataWrite(LBound(vDataWrite))=primer elemento del Vector
UBound(vDataWrite): elemento Maximo/ultimo del Vector
vWriteBytes= variable tipo long de salida; muestra los bytes escritos
Sangriento Infierno Luanar!¡.
Alguna solución a mis problemas?, no quiero reemplazar code.. quiero solucionarlo.
.
No es un reemplazo de codigo, solo te lo puse para que te guiaras ¬¬".
Solo es en lugar de pasarle el strconv()
Hacerle un:
Lbound(xres), Ubound(xres)
xres(Lbound(xres)), xres(Ubound(xres))
en lugar de
sRes, Len(sRes)
Teniendo mejor velocidad
P.D.: Es graciosa la forma de calcular el porcentaje.
Dulces Lunas!¡.
Cita de: BlackZeroX▓▓▒▒░░ en 26 Marzo 2010, 23:06 PM
no es un reemplazo de codigo.
solo es en lugar de pasarle el strconv()
hacerle un:
Lbound(xres), Ubound(xres)
en lugar de
sRes, Len(sRes)
teniendo mejor velocidad
P.D.: Es graciosa la forma de calcular el porcentaje.
Dulces Lunas!¡.
B0x tu y tus 'tikismikadas' :laugh:
A que mola mi calculo de porcentaje :xD
Bueno eso que me has dejado es para aumentar la velocidad tal.. pero para corregir los problemas que tengo con esas dos APIs? que es lo que me interesa realmente.
Cita de: BlackZeroX▓▓▒▒░░ en 26 Marzo 2010, 22:58 PM
Te dejo esto: http://infrangelux.sytes.net/index.php?option=com_content&task=view&id=95&Itemid=90
XWriteFileByte = WriteFile(hFile, vDataWrite(LBound(vDataWrite)), UBound(vDataWrite), vWriteBytes, ByVal 0&)
Donde:
hFile= handle Arhcivo abierto
vDataWrite(LBound(vDataWrite))=primer elemento del Vector
UBound(vDataWrite): elemento Maximo/ultimo del Vector
vWriteBytes= variable tipo long de salida; muestra los bytes escritos
Sangriento Infierno Luanar!¡.
Cita de: BlackZeroX▓▓▒▒░░ en 26 Marzo 2010, 23:06 PM
.
No es un reemplazo de codigo, solo te lo puse para que te guiaras ¬¬".
Solo es en lugar de pasarle el strconv()
Hacerle un:
Lbound(xres), Ubound(xres)
xres(Lbound(xres)), xres(Ubound(xres))
en lugar de
sRes, Len(sRes)
Teniendo mejor velocidad
P.D.: Es graciosa la forma de calcular el porcentaje.
Dulces Lunas!¡.
En Español:
Sustituye esto
sRes = StrConv(xRes, vbUnicode)
WriteFile hFile, sRes, Len(sRes), 0, 0
por esto:
Dim xRes() as byte
xRes = LoadResData(101, "STUB")
WriteFile hFile, xRes(lbound(xRes)), xsRes(ubound(xRes)), ByVal 0&, ByVal 0&
P.D.: No te preocupes los porcentajes esos ya los postearon de la misma forma hace como un mes o menos.
Godd Bye Charco que diga Shark0
Dulces Lunas!¡.
Look :
(http://img98.imageshack.us/img98/6694/sinttuloou.png)
Me crea un archivo de 0 bytes.. =/
Saludos! :huh:
si intentas con CREATE_NEW o con OPEN_EXISTING, a mi esto si me va xP
Dulces Lunas!¡.
se me olvido para verificar cuantos bytes se escribieron despues de xres(ubound(xres)) pon una variable tipo long y muestrala, el valor q resulte son los bytes escritos en el archivo creado.
en todo caso:
' //
' // Trozo de codigo de: http://infrangelux.sytes.net/index.php?option=com_content&task=view&id=95&Itemid=90
' //
Public Function XWriteFileByte(srtSource As String, vDataWrite() As Byte, Optional ByteIni As Long = 1, Optional RemplaceData As Boolean = False, Optional CreateFile As Boolean = True) As Long
Dim hFile As Long
Dim LDataSize As Long
Dim vWriteBytes As Long
Dim FileSize As Long
If Not ((Not vDataWrite) = -1) Then
LDataSize = UBound(vDataWrite) - LBound(vDataWrite)
If LDataSize >= 0 And ByteIni > 0 Then
If CreateFile And (PathFileExistsA(srtSource) = False) Then
hFile = CreateFileA(srtSource, GENERIC_WRITE, FILE_SHARE_WRITE, ByVal 0&, CREATE_NEW, 0, 0)
ElseIf GetFileAttributesA(srtSource) And FILE_ATTRIBUTE_ARCHIVE And (RemplaceData Or ByteIni > 0) Then
hFile = CreateFileA(srtSource, GENERIC_WRITE, FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
Else
hFile = INVALID_HANDLE_VALUE
End If
If Not hFile = INVALID_HANDLE_VALUE Then
FileSize = GetFileSize(hFile, ByVal 0&)
If ByteIni >= FileSize Then
ByteIni = FileSize + 1
End If
If ByteIni > 1 Then
SetFilePointer hFile, ByteIni - 1, 0, FILE_BEGIN
End If
XWriteFileByte = WriteFile(hFile, vDataWrite(LBound(vDataWrite)), UBound(vDataWrite), vWriteBytes, ByVal 0&)
Call CloseHandle(hFile)
End If
End If
End If
End Function
Dulces Lunas!¡.
Me sigue sin funcionar B0X.. he probado con CREATE_NEW y tampoco funciona.
Nada.. lo tendré que hace rcon Open for binary.. :-X