Clase:
Código
'--------------------------------------------------------------------------------------- ' Module : cEditSvr ' DateTime : 19/09/2008 13:23 ' Author : Cobein ' Mail : cobein27@hotmail.com ' WebPage : http://www.advancevb.com.ar ' Purpose : Read Write data at EOF ' Usage : At your own risk ' Requirements: None ' Distribution: You can freely use this code in your own ' applications, but you may not reproduce ' or publish this code on any web site, ' online service, or distribute as source ' on any media without express permission. ' ' History : 19/09/2008 First Cut.................................................... '--------------------------------------------------------------------------------------- Option Explicit Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long) Private c_pBag As New PropertyBag Private c_sFile As String Private c_lEOF As Long Public c_bHasData As Boolean '--------------------------------------------------------------------------------------- ' Procedure : GetEOF ' Author : E0N ' Purpose : Calculate EOF '--------------------------------------------------------------------------------------- Private Function GetEOF(sPath As String) As Long Dim vbData() As Byte Dim PE As Long, NumberOfSections As Integer Dim BeginLastSection As Long Dim RawSize As Long, RawOffset As Long Open sPath For Binary As #1 ReDim vbData(LOF(1) - 1) Get #1, , vbData Close #1 Call CopyMemory(PE, vbData(&H3C), 4) Call CopyMemory(NumberOfSections, vbData(PE + &H6), 2) BeginLastSection = PE + &HF8 + ((NumberOfSections - 1) * &H28) Call CopyMemory(RawSize, vbData(BeginLastSection + 16), 4) Call CopyMemory(RawOffset, vbData(BeginLastSection + 20), 4) GetEOF = RawSize + RawOffset End Function Public Function ExeFile(sPath As String) As Boolean c_sFile = sPath c_lEOF = GetEOF(c_sFile) If Not FileLen(c_sFile) = c_lEOF Then c_bHasData = True Dim vbData() As Byte Open c_sFile For Binary As #1 ReDim vbData(LOF(1) - c_lEOF - 1) Seek #1, c_lEOF + 1 Get #1, , vbData Close #1 '+++++++++++++++++++++++++++++++++++++++++++++++++++++ 'At this point you can Decrypt the byte array [vbData] '+++++++++++++++++++++++++++++++++++++++++++++++++++++ Set c_pBag = New PropertyBag c_pBag.Contents = vbData End If End Function Public Sub WriteProp(sName As String, vVal As Variant) c_pBag.WriteProperty sName, vVal End Sub Public Function ReadProp(sName As String) As Variant ReadProp = c_pBag.ReadProperty(sName) End Function Public Function WriteData(sDstFile As String) As Boolean Dim vbData() As Byte Open c_sFile For Binary Access Read As #1 ReDim vbData(LOF(1) - 1) Get #1, , vbData Close #1 Open sDstFile For Binary Access Write As #1 Put #1, , vbData vbData = c_pBag.Contents '+++++++++++++++++++++++++++++++++++++++++++++++++++++ 'At this point you can Encrypt the byte array [vbData] '+++++++++++++++++++++++++++++++++++++++++++++++++++++ Put #1, , vbData Close #1 End Function
Como llamarlo
Código
Option Explicit Private Sub Form_Load() Dim c As New cEditSvr c.ExeFile "c:\proyecto1.exe" c.WriteProp "IP", "123.123.123.123" c.WriteProp "Port", 1234 c.WriteData "c:\test.exe" Set c = New cEditSvr c.ExeFile "c:\test.exe" Debug.Print c.ReadProp("IP") Debug.Print c.ReadProp("Port") End Sub