fopetesl

Mixed binary and ASCII file - want to read ASCII

12 posts in this topic

#1 ·  Posted (edited)

Need to read a small file which looks like

01 01 01 00 21 21 48 4F ����!HHO
(cut from hexedit)

First four are binary but don't show, last four are ascii "!HHO"

I have tried to split the file and look for the ascii string but not succeeded:

; Set the working directory ... or set PATH! ...
            FileChangeDir("C:\S3_GUI\ncat\")
        ;   Run(@ComSpec & " /k " & "C:\S3_GUI\ncat\Home.bat", "", @SW_HIDE);;comment: not over  write
            Local $hFileOpen = FileOpen("C:\S3_GUI\ncat\homerep", $FO_READ) ;; homerep
            Local $sFileRead = FileRead($hFileOpen)
            Local $Comp = StringInStr ($sFileRead,"!HHO",1,4)
            If( $Comp = 1) Then
               MsgBox($MB_OK, "Head is Home", "!HHO")
            Else
               MsgBox($MB_OK, "Head not Home!","!HHx")
            EndIf

Fails every time.

If I open it as binary then I lose the ascii?

I've been advised to include the whole file but it's getting big. You need to see it all?

Edited by fopetesl
Correct syntax

The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites



#2 ·  Posted

What does the file look like without the hexeditor?

 


Share this post


Link to post
Share on other sites

#3 ·  Posted

Hi,

StringInstr() returns the position of the substring, your parameter "4" returns the 4th occurrence of the substring....

You should better use MUCH more  of CTRL+SHIFT+D and ALT+D....

Share this post


Link to post
Share on other sites

#4 ·  Posted

Open the file using FileOpen with the $FO_BINARY option to read it as binary. FileOpen without that will stop at the first instance of the character 00 which delimits a text string, so reading it as text isn't going to work.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#5 ·  Posted

22 hours ago, JoHanatCent said:

What does the file look like without the hexeditor?

 

 !HHO

 


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

#6 ·  Posted

21 hours ago, BrewManNH said:

Open the file using FileOpen with the $FO_BINARY option to read it as binary. FileOpen without that will stop at the first instance of the character 00 which delimits a text string, so reading it as text isn't going to work.

OK, so I tried to read as binary:

Local $hFileOpen = FileOpen("C:\S3_GUI\ncat\homerep", BitOr($FO_READ,$FO_BINARY))
            Local $sFileRead = FileRead($hFileOpen)
;     Local $AscStr = BinaryToString($sFileRead,$SB_ANSI)
;    Local $bFile = StringLeft($sFileRead,20)  ; get 8 bytes from file
;    Local $bFbyte = StringMid($bFile,11,10)
;    Local $sConvtd = BinaryToString($bFbyte)
     MsgBox($MB_OK, "Bin2Asc", $sConvtd)

I tried all these combinations. No change :(


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

#7 ·  Posted

21 hours ago, AndyG said:

Hi,

StringInstr() returns the position of the substring, your parameter "4" returns the 4th occurrence of the substring....

You should better use MUCH more  of CTRL+SHIFT+D and ALT+D....

Hi, AndyG.  first I tried this

Local $hFileOpen = FileOpen("C:\S3_GUI\ncat\homerep", $FO_READ) ;; homerep
            Local $sFileRead = FileRead($hFileOpen)
            Local $Comp = StringInStr ($sFileRead,"!HHO",1,4)
            MsgBox($MB_OK, "Bin2Asc", $Comp)
            If( $Comp = 1) Then
               MsgBox($MB_OK, "Head is Home", "!HHO")
            Else
               MsgBox($MB_OK, "Head not Home!","!HHx")
            EndIf

returned a single '0'

 

Explain "CTRL+SHIFT+D and ALT+D", please. Alt+D gives a ping, Ctrl+Shift+D gives "EOT" in Scite editor.

 


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

#8 ·  Posted

fopetesl,

This seems to work:

#include <File.au3>

; ###################
; Only for example

; Required file content
$bBinary = "0x010101002121484F"

; Create file containing the data
$hFile = FileOpen("Test.fil", $FO_OVERWRITE + $FO_BINARY)
FileWrite($hFile, $bBinary)
FileClose($hFile)

Sleep(1000)

; ##################

; Define required search string
$sSearch = "2121484F"

; Or create it from ASCII
$sSearch = StringTrimLeft(StringToBinary("!!HO"), 2)

; Open file and read contents as binary
$hFile = FileOpen("Test.fil", $FO_BINARY)
$sContent = FileRead($hFile)
FileClose($hFile)

; Check for search string
 If StringInStr($sContent, $sSearch) Then
    MsgBox($MB_SYSTEMMODAL, "Head is Home", "!HHO")
Else
    MsgBox($MB_SYSTEMMODAL, "Head not Home!","!HHx")
EndIf

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#9 ·  Posted

M23 & guys, thank you.

Works a treat. So simple. When you know how.


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

#10 ·  Posted

On 15.3.2017 at 10:46 AM, fopetesl said:

Explain "CTRL+SHIFT+D and ALT+D", please. Alt+D gives a ping, Ctrl+Shift+D gives "EOT" in Scite editor.

Hi,

I do not know which Scite version you are using, In all Scite versions which i have used since 2008, the CTRL+SHIFT+D writes a line with a DEBUG-Msgbox whith the content of a variable or function the cursor stands on (or a marked funktion or anything else).

ALT+D writes a DEBUG-consolewrite.

In the "extras" Menu you will find some more very(!) helpful commands and shortcuts to debug your code within seconds. I think 80% of the "help me"-posts in every internet-(programming)-forum could be avoided with minimalistic usage of simplest debugging functions!

Share this post


Link to post
Share on other sites

#11 ·  Posted

AndyG,

Quote

I think 80% of the "help me"-posts in every internet-(programming)-forum could be avoided with minimalistic usage of simplest debugging functions!

So true!

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

45 minutes ago, AndyG said:

I do not know which Scite version you are using, In all Scite versions which i have used since 2008, the CTRL+SHIFT+D writes a line with a DEBUG-Msgbox whith the content of a variable or function the cursor stands on (or a marked funktion or anything else).

This is only the case for the full SciTE version that comes in the separate installer. The lite SciTE version included in the AutoIt3 installer doesn't have these debugging options.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • TheSaint
      By TheSaint
      I had a need, and so I developed.
      Before I did that though, I did a quick search of the forum, and found a few things, but none seemed to suit what I really wanted ... though to be honest, I did not investigate them deeply or search extensively. In any case, I am not very good at modifying the code of others, nor do I enjoy doing so, so in the end I decided it was best to start from scratch ... re-inventing the wheel perhaps, but a wheel I feel a certain degree of comfort with. I also thought about Maps, but don't know enough.
      _IniString Functions (was Ini_InMem)
      Ini in memory
      Settings INI - Read/Write once to the disk
      INI File Processing Functions
      ... sure to be others.
      As with all my stuff, feel free to use (no guarantees) or modify ... just give me credit where due.
      I always go for the quick & simple approach, as those who know me here, are well aware, so without a doubt, my code could be improved - sped up, RegExp used, etc. So feel free to do that, and convert into a proper UDF, if you want, following best practices etc, as I am sure others will appreciate it.
      Recently, I have come upon a need to extract data from an approximately 50 Mb downloaded Index file, just extracting the few elements I need, and storing them in an INI file. It is quite a time consuming process, especially on my underpowered Netbook, which is where I am using the program I built. I have been considering ways to speed up things. Two good sounding methods, out of several possibles, have come to mind - 1) RAM Disk and 2) Virtual INI processing. That last being a better option, when sharing code (program) with others.
      Another method, which I am currently using, that did give me some measurable benefit, was to download the almost 50 Mb Index file in Stages (i.e. 30 x 1.4 Mb roughly), extracting data from each in turn. I have also considered extracting to 10 (or 11) separate INI files, rather than the single large INI file (4~5 Mb), as things noticeably slow up as the INI file increases in size ... obviously due to writing time.
      I can't really speed up the extraction process, but that last method may speed up the writing stage.  However, it would require significant program changes, and perhaps not gain me much benefit. To complicate things, there are too many Section names (Index ID's) for the IniReadSectionNames command, so I have had to split them off into their own (read/write) line-by-line index file, and create code to deal with duplicates. When read, Index ID's and Titles populate a Listbox control in a user GUI.
      So at this point in time, it seems best to use the Virtual INI approach to gain a significant reduction in time taken. For my own specific use, with my slow Netbook, I may also use a RAM Disk.
      Due to the aforementioned INI issues, and lack of available specific data, probably because it is always  program concentric, I have created an ASCII Checker program, which I guess you can say, is AutoIt  concentric. Because others may also find it handy, I am providing it here. NOTE - As yet, I am only aware that Escape characters exist, but have not investigated or catered for them in any way.
      ASCII Checker.zip

      The Virtual_INI_UDF is still a work in progress, though I have done most of the functions now, with the working but incomplete _Ini_Test function, still requiring changes etc from the information gleaned by the ASCII Checker program.
      Here's something to play with meanwhile.
      Updated files (24th February 2017)
      Virtual_INI_UDF.au3  NEW
      Example.au3 (23rd February 2017)
      All pretty basic, but managed to load my 4 Mb INI file (seemingly ok, but took a few seconds) ... though I have only worked with much smaller testing ones so far.
      P.S. While I have done a fair amount of testing, it has been pretty basic, and mostly limited to the examples provided. Testing has definitely not been extensive.
       
    • wakillon
      By wakillon
      Bitmap2AscII use Lucida Console font with a size set to 8, so Windows 8/8.1 users need to change their notepad font and size for get a correct display.
      Image Rescale slider is only available when saving as image.
      A click on the "PreviewEdit" open AscII string in Notepad.
      You can save as Text, Html or Image (add the extension you want)
      Each setting change is immediately applied.
       
      Downloads available in the download section
       
      Hope you like it ! 
       
    • wakillon
      By wakillon
      Convert Images to AscII Art.
    • wakillon
      By wakillon
      I do not like Charmap, it's too small and you can't test a character with another font, you only get all chars for each font so it's not very handy.

      SpecialCharactersViewer permit with the Segoe UI Symbol font to display a maximum ( not all! ) of  Ascii and Unicode characters.
      Simple click on a char and the corresponding Chr or ChrW code is displayed. 
      Free to you to choose another font for see if the selected character can be used with.
      Windows XP do not have Segoe UI Symbol font, so it's more for Win7/Win8 users...
      Previous downloads : 100
      Source : SpecialCharactersViewer v1.0.1.0.au3
      Executable : SpecialCharactersViewer.exe.html
      (Once this html file downloaded, double click on it for start the download)
       
      Will be added to the next version of SciTE Hopper.
      Hope it can help ! 
    • Fr33b0w
      By Fr33b0w
      Hi. I am trying whole day yesterday and today to make script work. Code shouldnt be a problem but I just dont understand how some characters work. I will try to explain. I have a bunch of chars that I picked up from http://fsymbols.com/emoji/ and if you paste them in facebook page they work fine. But if you paste more then 20 or 40 (I am not sure anymore) they will not show well. Same thing happens in a script. When I had less then 20 everything worked fine. Now when I put much more it wont work. For example if code is "ΓÿÇ" then I need to get " ☀" when it goes trough code and that worked fine. When I put much more in a script it just wouldnt work. Same happens on facebook page. I have just checked it shows first 40 and then it wont decode others. Same happens in script. I even changed a bit way it works and instead that code is inside script i have put it in a .txt file so it will just load a line i need trough scrip (to make it work somehow) but it just doesnt work. Can anyone solve this ghost inside a script?
      #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> $hGUI = GUICreate("v3.00", 752, 418, -1, -1) ;GUICtrlSetStyle(-1, ) GUICtrlSetFont(-1, 8.5, 400, 0, "MS Shell Dlg", 5) $oIE = ObjCreate("Shell.Explorer.2") ;GUICtrlSetStyle(-1, ) $hPic = GUICtrlCreatePic("", 13, 33, 16, 16) GUICtrlSetImage(-1, "E:\0\autoit\2014-03-31 Facebook Spec Chars\img\01.bmp") $hPic2 = GUICtrlCreatePic("", 13, 51, 16, 16) GUICtrlSetImage(-1, "E:\0\autoit\2014-03-31 Facebook Spec Chars\img\02.bmp") $hButton = GUICtrlCreateButton("#", 37, 33, 16, 16) $hButton2 = GUICtrlCreateButton("#", 37, 51, 16, 16) $hButton3 = GUICtrlCreateButton("#", 37, 69, 16, 16) $hButton4 = GUICtrlCreateButton("#", 37, 87, 16, 16) $hButton5 = GUICtrlCreateButton("#", 37, 105, 16, 16) $hButton6 = GUICtrlCreateButton("#", 37, 123, 16, 16) $hButton7 = GUICtrlCreateButton("#", 37, 141, 16, 16) GUISetState() While 1 $hMsg = GUIGetMsg() Switch $hMsg Case $GUI_EVENT_CLOSE Exit EndSwitch Select Case $hMsg = $hButton ClipPut("ðŸ") ; those are chars that needs to be inserted in a facebook Case $hMsg = $hButton2 ClipPut("â˜") ; here also Case $hMsg = $hButton3 ClipPut("☔") Case $hMsg = $hButton4 ClipPut("⛄") Case $hMsg = $hButton5 ClipPut("âš¡") Case $hMsg = $hButton7 ClipPut("") EndSelect WEnd At the end I need to get "