Jump to content

[SOLVED] _HexToString or BinaryToString ?


Recommended Posts

There is a way to have a clean string value without any SOH STX etc... Values

 

#include <FileConstants.au3>
#include <String.au3>
#include <WinAPI.au3>
#include <Array.au3>
#include <File.au3>

$file = _FileListToArrayRec(@ScriptDir,"*.otf",1,1,0,2)

For $x = 1 to UBound($file)-1
    ;ConsoleWrite(_ReadOffSet($ISO[$x],0x000000,12))
    ConsoleWrite(_HexToString(StringStripWS(_ReadOffSet($file[$x],0x000000,16), 8))&@CRLF)
    $String = StringReplace(BinaryToString(_ReadOffSet($file[$x],0x000000,16)), Chr(0), "")
    FileWrite(@ScriptDir&"\file.txt",$String&@CRLF)
    FileWrite(@ScriptDir&"\file2.txt",_HexToString(StringStripWS(_ReadOffSet($file[$x],0x000000,16), 8))&@CRLF)
Next


Func _ReadOffSet($sFilePath,$iOffset,$iLen=1)
    Local $sRet=""
    Local $hFile=FileOpen($sFilePath,$FO_BINARY)
    FileSetPos($hFile,$iOffset,$FILE_BEGIN)
    $sRet=FileRead($hFile,$iLen)
    FileClose($hFile)
    Return $sRet
EndFunc

 

Edited by rootx
Link to comment
Share on other sites

Your question is vague at best. What are those .OTF files, are they OTF fonts? If yes, lookup he OTF file format to see that your blind reading of 16 bytes at head of file is off the mark.

Else post an example of your OTF file and tell us which string you want to read. Hint: use a hex file editor to inspect it.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Please answer first all the points raised.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

You can do that (quick'n dirty):

Local $hOTF = FileOpen("SourceCodePro-Regular.otf", 16)
Local $bOTF = FileRead($hOTF)
FileClose($hOTF)
Local $sOTF = StringRegExpReplace(BinaryToString($bOTF), "[[:cntrl:]]", "")
ConsoleWrite($sOTF)

but it doesn't make you any good.

  • First, there are pure binary areas containing offsets, adresses, flags, binary data, some of which will get interpreted as printable characters.
  • Second, there are portions of text encoded in UTF16; depending on the language used you can as well read garbage there.
  • Lastly, this brute-forcing read of everything in [0x20, 0x7E] U [0x80, 0xFF] completely ignores the file structure, having headers, optional areas, glyph tables as compressed Postscript and other zones.

If you want to retrieve significant information properly, you need to dissect the file format according to OTF specifications, in order to read just the valid area(s) of interest under the correct format and encoding. Anything else is just plain wrong.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
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
 Share

×
×
  • Create New...