any body can help me in merge/extract two files?

thefalcon79

Member
Joined
Mar 27, 2010
Messages
8
Programming Experience
Beginner
hi all

i found this code to merge two two files and i'm trying to do the reverse of it. kindly, any one can help me to do the reverse of this function:
VB.NET:
strDest("f1.exe")
strSource("f2.jpg")

 
Private Sub AppendFile(ByVal strSource As String, ByVal strDest As String)
Const intBUFFER_SIZE = 4096 '4KB buffer

Dim stmReader As System.IO.FileStream = System.IO.File.OpenRead(strSource)
Dim stmWriter As System.IO.FileStream = System.IO.File.OpenWrite(strDest)
Dim abytBuffer(0 To intBUFFER_SIZE - 1) As Byte
Dim intBufferSize As Integer

stmWriter.Seek(0, IO.SeekOrigin.End) 'Seek to end of file to append

Do

intBufferSize = stmReader.Read(abytBuffer, 0, intBUFFER_SIZE) 'Read
If intBufferSize = 0 Then Exit Do 'End of file
stmWriter.Write(abytBuffer, 0, intBufferSize) 'Write 

Loop

stmReader.Close()
stmReader.Dispose()
stmWriter.Close()
stmWriter.Dispose()

what i'm trying to do is to hide the image file in exe file, and extract the image again. this function working 100% and do not damage the exe file after merge. but i'm confused in how to extract the image?!!!

hope i'll find some help here

thank you in forward :)
 
Last edited:
You would open a FileStream, read the data for the first file and write to another file, then read the data fro the second file and write it to another file. The thing is, you have to know exactly how long the first file is in order to know where to break between the two. If all you've got is a series of Bytes then that isn't going to tell you, so you have to know ahead of time. The alternative would be to store that information inside the file somewhere, e.g. when you join the two files, add a 64-bit value at the end that contains the length of the first part of the file. You can then read that value first in order to know how to split it up again.
 
hi

thanks Sir for your respond

i tried to read and store the two files into two array's of bytes + one array for the password.
i could write/merge these three array's of bytes but the result file is nothing/corrupted. i need the first file (*.exe) to run as it's before merging.

can you please provide me a sample of code about what u suggested?

thank you again
 
thanks Sir for your respond

i tried to read and store the two files into two array's of bytes + one array for the password.
i could write/merge these three array's of bytes but the result file is nothing/corrupted. i need the first file (*.exe) to run as it's before merging.

can you please provide me a sample of code about what u suggested?

thank you again

How about you show us what you tried and we can help you fix that?
 
Dear jmcilhinney

hi again

i could merge two files successfully :)
and extracted the exe (first file) successfully too, but still trying to extract the second file properly!!!


VB.NET:
Imports System
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography


Public Class Form1

    Dim fsDestinationEncryptFile As System.IO.FileStream
    Dim fsDestinationDecryptFile As System.IO.FileStream
    Dim fsDestinationDecryptFile2 As System.IO.FileStream
    Dim InputFileContent() As Byte
    Dim fsexeFile As System.IO.FileStream
    Dim file2 As System.IO.FileStream
    Dim exeFilePath0 As String
    Dim filePath0 As String = ""


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim DestinationEncryptPath As String
        Dim fsDestinationEncryptFile As System.IO.FileStream

        exeFilePath0 = "C:\myfile.exe"
        DestinationEncryptPath = "C:\newmyfile.exe"

        fsexeFile = New System.IO.FileStream(exeFilePath0, FileMode.Open, FileAccess.Read)
        fsDestinationEncryptFile = New System.IO.FileStream(DestinationEncryptPath, FileMode.OpenOrCreate, FileAccess.Write)
        fsDestinationEncryptFile.SetLength(0) 'make sure fsDestination is empty

        'Read The Content of exe File and write it in the output file
        Dim InputFileContent(fsexeFile.Length - 1) As Byte
        fsexeFile.Read(InputFileContent, 0, fsexeFile.Length)
        fsDestinationEncryptFile.Write(InputFileContent, 0, InputFileContent.Length)

        'read 2nd file and write it to new exe file
        filePath0 = "C:\mydata.mdb"
        file2 = New System.IO.FileStream(filePath0, FileMode.Open, FileAccess.Read)
        'Read The Content of exe File and write it in the output file
        Dim InputFileContent2(file2.Length - 1) As Byte
        file2.Read(InputFileContent2, 0, file2.Length)
        fsDestinationEncryptFile.Write(InputFileContent2, 0, InputFileContent2.Length)

        fsexeFile.Close()
        fsDestinationEncryptFile.Close()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim fsexeFile As System.IO.FileStream
        Dim extractfile2 As System.IO.FileStream
        Dim exeFilePath As String
        Dim DestinationDecryptPath As String
        Dim DestinationDecryptPath2 As String
        Dim fsDestinationDecryptFile2 As System.IO.FileStream

        exeFilePath = "C:\newmyfile.exe"
        DestinationDecryptPath = "C:\restoredExe.exe"

        fsexeFile = New System.IO.FileStream(exeFilePath0, FileMode.Open, FileAccess.Read)
        fsDestinationDecryptFile = New System.IO.FileStream(DestinationDecryptPath, FileMode.OpenOrCreate, FileAccess.Write)
        fsDestinationDecryptFile.SetLength(0) 'make sure fsDestination is empty

        'Read The Content of new exe File and write exe file (exe restore)
        ReDim InputFileContent(fsexeFile.Length - 1) 
        fsexeFile.Read(InputFileContent, 0, fsexeFile.Length)
        fsDestinationDecryptFile.Write(InputFileContent, 0, InputFileContent.Length)


        'write 2nd file
'what i can do here???
'............


        fsexeFile.Close()
        fsDestinationDecryptFile.Close()
    End Sub
End Class
 
Last edited:
Dear jmcilhinney

Dear jmcilhinney

i tried using this way, but the result file is corrupted !!!


VB.NET:
        'write 2nd file
        DestinationDecryptPath2 = "C:\extractedmydata.mdb"
        fsDestinationDecryptFile2 = New System.IO.FileStream(DestinationDecryptPath2, FileMode.OpenOrCreate, FileAccess.Write)
        fsDestinationDecryptFile2.SetLength(0) 'make sure fsDestination is empty

        extractfile2 = New System.IO.FileStream(filePath0, FileMode.Open, FileAccess.Read)
        FileToExtractStartPosition = FileToExtractStartPosition
        fsexeFile.Seek(FileToExtractStartPosition, SeekOrigin.Begin)

        'Read The Content of exe File and write it in the 2nd output file
        Dim InputFileContent2(extractfile2.Length - 1) As Byte
        file2.Read(InputFileContent, 0, extractfile2.Length)
        fsDestinationDecryptFile2.Write(InputFileContent, 0, extractfile2.Length)

any mistakes/errors in my code? did i miss something?
suggestions plz?
 
Back
Top