• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 472
  • Last Modified:

Reassemble binary file

Please assist me.
How do I reassemble a file that I red in Binary ?
0
HESUS
Asked:
HESUS
  • 4
  • 4
  • 3
  • +3
1 Solution
 
BahnassCommented:

In Dos Mode
Debug was to read in assembly
is that what U mean
also there is DEBUGGERS to read assembly
0
 
wsh2Commented:
How did you DISassemble it? Please provide us with more information and/or Program code.. <smile>
0
 
andyclapCommented:
Disassembly is pretty easy, as Bahnass said, DEBUG in dos has a disassembler - eg
DEBUG c:\windows\mplayer.exe
-u
gives you a very readable disassembly of the first few bytes of the file:

19A8:0000 0E            PUSH    CS
19A8:0001 1F            POP     DS
19A8:0002 BA0E00        MOV     DX,000E
19A8:0005 B409          MOV     AH,09
19A8:0007 CD21          INT     21
19A8:0009 B8014C        MOV     AX,4C01
19A8:000C CD21          INT     21
19A8:000E 54            PUSH    SP
19A8:000F 68            DB      68
19A8:0010 69            DB      69
19A8:0011 7320          JNB     0033
19A8:0013 7072          JO      0087
19A8:0015 6F            DB      6F
19A8:0016 67            DB      67
19A8:0017 7261          JB      007A
19A8:0019 6D            DB      6D
19A8:001A 206361        AND     [BP+DI+61],AH
19A8:001D 6E            DB      6E
19A8:001E 6E            DB      6E
19A8:001F 6F            DB      6F


If you want to get back to the VB source code, then I'm afraid you just can't do this in VB4/5/6. No way. Nada. Never. Not on your nelly. But in VB.NET you can ;)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Richie_SimonettiIT OperationsCommented:
i think that HESUS is talking about "restoring".
If you have saved that binary data in an array of byte, do some like this:

Open "c:\yourchoice.???" for binary as #1
    put #1,1,YourByteArray()
close #1
0
 
HESUSAuthor Commented:
Thank you all for responding.
I did not explain myself correctly.
The procedure is as follows:
 
  Open 'File' For Binary As #1
 
  Open 'File2' For Binary As #2
   
  THE_LOF = LOF(1)
 
  While Not EOF(1)
    If (THE_LOF  Mod 100) = 0 Then
      N = 100
     Else
      N = (THE_LOF  Mod 100)
    End If
    cr = Input(N, #1)
    Put #2, N, cr
  Wend
 
  Close (1)
  Close (2)

What I get in File2 is a corrupted file.
0
 
andyclapCommented:
Oh, that's better, we all got the wrong end of the stick!

Still not sure what you're trying to do (a patcher?) - your code is definitely a bit strange.

What you're doing is getting chunks of file1 (based on the file length mod 100, so for a 156 byte file you're processing 56 character chunks). You're then writing the each chunk to the same position in the second file (eg at byte 56 onwards). I guess this isn't what you want!

try the following:


Open "File" For Binary As #1
 
 Open "File2" For Binary As #2

 'Strict typing Please!
 dim N as long
 dim THE_LOF as long
 dim lOffset as long
 THE_LOF = LOF(1)
 
 lOffset=1
 'can't use EOF when using input
 While lOffset<=THE_LOF
   'if there's more than 100 bytes to the end, copy 100 bytes
   If (lOffset <= THE_LOF - 100) = 0 Then
     N = 100
    Else
     'copy remaining bytes
     N = THE_LOF - lOffset + 1
   End If
   'get the bytes (this will increase the file pointer)
   cr = Input(N, #1)
   'put the bytes at the current offset
   Put #2, lOffset, cr
   lOffset=lOffset+N
 Wend
 
 Close (1)
 Close (2)


Note this is untested, but should give you some pointers.
I personally wouldn't use input (use GET), and I'd use a byte array as the intermediary rather than a string to save problems with double-byte character sets in NT. I'd also use freefile with variables rather than hardcoding file numbers.
0
 
PaulHewsCommented:
Use this:
cr = InputB(N, #1)

instead of this:
cr = Input(N, #1)

0
 
HESUSAuthor Commented:
To andyclap thank you veru much.
The file that I am trying to copy is a .MDB file.
I am using your code,and when I am trying to read the file in Access, I get error message that the file is not an MDB
file.
0
 
Richie_SimonettiIT OperationsCommented:
HESUS, please, explain if it comes from a modem connection from other question of you. So, Experts could figure out entire picture.
0
 
PaulHewsCommented:
The main problem I think is the use of input instead of inputb which will cause translation problems with certain binaray characters. By the way, why do you not just use FileCopy?
0
 
HESUSAuthor Commented:
Richie Simonetti is right.
I am transferring the file between two PCs by using a
modem connection.That is why I can not use FileCopy.
0
 
wsh2Commented:
Using CHUNKS to process through the file (Chunks are very efficient when dealing with VERY large files 1mb+)

<----- Code Begin ----->

   Const CHUNK_SIZE = 1000 ' Size of chunks to process
   
   Dim lngFileGet As Long: lngFileGet = FreeFile
   Dim strFileGet As String: strFileGet = "c:\MyFileINPUT.mdb" ' <-- CHANGE
   Dim lngFilePut As Long: lngFilePut = FreeFile
   Dim strFilePut As String: strFilePut = "c:\MyFileOUTPUT.mdb" ' <-- CHANGE
   
'  Open Input File
   Open strFileGet For Binary As #lngFileGet
   
'  Open Output File
   If Not Dir(strFileGet) = "" Then
      Kill strFileGet
   End If
   Open strFilePut For Binary As #lngFilePut
   
'  Copy File in CHUNK_SIZE bites
   Dim lngBuffer As Long
   Dim strBuffer As String
   Dim lngFileLOF As Long: lngFileLOF = LOF(1)
   Dim lngFilePOS As Long: lngFilePOS = 1
   Do Until lngFilePOS > lngFileLOF
      If (lngFilePOS + CHUNK_SIZE) > lngFileLOF Then
         lngBuffer = lngFileLOF - lngFilePOS + 1
      Else
         lngBuffer = CHUNK_SIZE
      End If
      strBuffer = Space$(lngBuffer)
      Get #lngFileGet, lngFilePOS, strBuffer
      Put #lngFilePut, lngFilePOS, strBuffer
      lngFilePOS = lngFilePOS + lngBuffer
   Loop
 
'  Close Files
   Close (lngFileGet)
   Close (lngFilePut)

<----- Code End ----->

====================================
For smaller files.. all you need is:
====================================

<----- Code Begin ----->

   Dim lngFileGet As Long: lngFileGet = FreeFile
   Dim strFileGet As String: strFileGet = "c:\MyFileINPUT.mdb" ' <-- CHANGE
   Dim lngFilePut As Long: lngFilePut = FreeFile
   Dim strFilePut As String: strFilePut = "c:\MyFileOUTPUT.mdb" ' <-- CHANGE
   
'  Open Input File
   Open strFileGet For Binary As #lngFileGet
   
'  Open Output File
   If Not Dir(strFileGet) = "" Then
      Kill strFileGet
   End If
   Open strFilePut For Binary As #lngFilePut

'  Copy File
   Dim strBuffer As String: strBuffer = Space$(LOF(lngFileGet))
   Get #lngFileGet, , strBuffer
   Put #lngFilePut, , strBuffer
 
'  Close Files
   Close (lngFileGet)
   Close (lngFilePut)

<----- Code End ----->

0
 
PaulHewsCommented:
All binary methods, fixed and tested:

Public Sub sCopyFileByByte(strFileIn As String, strFileOut As String)

    Const ChunkSize = 4096
    Dim lngNumChunks As Long
    Dim bytbuffer() As Byte
    Dim hFileIn As Integer
    Dim hFileOut As Integer
    Dim lngLOF As Long
    Dim i As Long
   
    ReDim bytbuffer(1 To ChunkSize) As Byte
   
    hFileIn = FreeFile
    Open strFileIn For Binary As #hFileIn
    hFileOut = FreeFile
    Open strFileOut For Binary As #hFileOut
   
   
    lngLOF = LOF(hFileIn)
   
    For i = 1 To lngLOF \ ChunkSize + IIf(lngLOF Mod ChunkSize, 1, 0)
        If i = lngLOF \ ChunkSize + 1 Then
            ReDim bytbuffer(1 To lngLOF Mod ChunkSize)
        End If
        Get #hFileIn, , bytbuffer
        Put #hFileOut, , bytbuffer

    Next i
    Close hFileIn, hFileOut
   
End Sub
0
 
wsh2Commented:
Oooops... corrected:

====================================
For Larger files
====================================

<----- Code Begin ----->

  Const CHUNK_SIZE = 1000 ' Size of chunks to process
 
  Dim lngFileGet As Long: lngFileGet = FreeFile
  Dim strFileGet As String: strFileGet = "c:\MyFileINPUT.mdb" ' <-- CHANGE
  Dim lngFilePut As Long: lngFilePut = FreeFile
  Dim strFilePut As String: strFilePut = "c:\MyFileOUTPUT.mdb" ' <-- CHANGE
 
'  Open Input File
  Open strFileGet For Binary As #lngFileGet
 
'  Open Output File
  If Not Dir(strFilePut) = "" Then ' <-- Corrected
     Kill strFilePut ' <-- Corrected
  End If
  Open strFilePut For Binary As #lngFilePut
 
'  Copy File in CHUNK_SIZE bites
  Dim lngBuffer As Long
  Dim strBuffer As String
  Dim lngFileLOF As Long: lngFileLOF = LOF(1)
  Dim lngFilePOS As Long: lngFilePOS = 1
  Do Until lngFilePOS > lngFileLOF
     If (lngFilePOS + CHUNK_SIZE) > lngFileLOF Then
        lngBuffer = lngFileLOF - lngFilePOS + 1
     Else
        lngBuffer = CHUNK_SIZE
     End If
     strBuffer = Space$(lngBuffer)
     Get #lngFileGet, lngFilePOS, strBuffer
     Put #lngFilePut, lngFilePOS, strBuffer
     lngFilePOS = lngFilePOS + lngBuffer
  Loop

'  Close Files
  Close (lngFileGet)
  Close (lngFilePut)

<----- Code End ----->

====================================
For smaller files.. all you need is:
====================================

<----- Code Begin ----->

  Dim lngFileGet As Long: lngFileGet = FreeFile
  Dim strFileGet As String: strFileGet = "c:\MyFileINPUT.mdb" ' <-- CHANGE
  Dim lngFilePut As Long: lngFilePut = FreeFile
  Dim strFilePut As String: strFilePut = "c:\MyFileOUTPUT.mdb" ' <-- CHANGE
 
'  Open Input File
  Open strFileGet For Binary As #lngFileGet
 
'  Open Output File
  If Not Dir(strFilePut) = "" Then ' <-- Corrected
     Kill strFilePut ' <-- Corrected
  End If
  Open strFilePut For Binary As #lngFilePut

'  Copy File
  Dim strBuffer As String: strBuffer = Space$(LOF(lngFileGet))
  Get #lngFileGet, , strBuffer
  Put #lngFilePut, , strBuffer

'  Close Files
  Close (lngFileGet)
  Close (lngFilePut)

<----- Code End ----->

0
 
Richie_SimonettiIT OperationsCommented:
HESUS, try this:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=26185
it could be useful to not break your head reading binaries.
0
 
HESUSAuthor Commented:
To all the experts,thank you very much for your help,and please accept my apologies for the delay.
I will accept PaulHews answer because it is the first one
I tested and it is doing the work.However,my problem is not completed ,because I need to transfare the file through
a Modem. But I will open a new question for that.(It is about time to pay somebody for his trouble,isn't it ?)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now