Search the Community
Showing results for tags 'binary'.
-
I have wrote a lot of binary code library for AutoIt before. I also discover many ways to generate binary code for AutoIt in the past. However, all of them have limitation or need some extra effort. Recently, I think I found the best and easiest way to generate the binary code. So I wrote this UDF, may be my last one about binary code. The Features:Both AutoIt x86 and x64 version are supported.Windows API and static variables can be use (code relocation supported).Decompression at run-time with smallest footprint LZMA decoder.Allocated memory blocks are released automatically.Most C source code works without modification.Two step or one step script generation, very easy to use.How It Works: The C source code must be compiled by MinGW GCC with "-S -masm=intel" option. Output is GAS syntax assembly file.BinaryCall Tool is able to convert the GAS syntax assembly file (*.s) to FASM syntax (*.asm). During the conversion, global symbols will be stored as "Symbol Jump Table" at the head of the file. The output file should be able to be assembled to binary file under command line by FASM.EXE. This syntax conversion is step 1.The step 2 is to assemble the file. BinaryCall Tool will use the embedded FASM to assemble every file twice to generate the relocation table. "BinaryCall.inc" will be included automatically before assembling to detect the Windows API and generate the "API Jump table". All the results will be compressed and converted to AutoIt script output.There are two major functions in the output script. _BinaryCall_Create() function allocates memorys, decompress the binary, relocates the address in memory, and fills the "API Jump Table"._BinaryCall_SymbolList() converts the "Symbol Jump Table" to memory addresses, and then store them as pointers in a DllStruct variable.Finally, we can use DllCallAddress() to call the memory address stored in the DllStruct.Step by Step Tutorial: Write C source code:#include <windows.h> void main() { MessageBox(0, "Hello", "Welcome Message", 1); }Use GCC MinGW 32/64 to compile the source code: gcc -S -masm=intel -m32 MessageBox.cUse BinaryCall Tool "GAS2AU3 Converter", select "MessageBox.s": If Not @AutoItX64 Then Local $Code = '...' Local $Reloc = '...' Local $Symbol[] = ["main"] Local $CodeBase = _BinaryCall_Create($Code, $Reloc) If @Error Then Exit Local $SymbolList = _BinaryCall_SymbolList($CodeBase, $Symbol) If @Error Then Exit EndIfPaste the output script, call the main() in AutoIt: #Include "BinaryCall.au3" ; Paste output here DllCallAddress("none:cdecl", DllStructGetData($SymbolList, "main"))Try to run it! Change Log:v1.0Initial release.v1.1A lot of improvement for GAS2ASM converter and FASM header file.Add many C Run-Time library as inline asm subroutines.Add command-line to argc/argv parser for easy calling main() function.Add ability to redirect stdio.More C source code can work without modification in this version. Following open source projects are tested. And Yes, they can run as binary code library in AutoIt now. SQLite 3.8.5 TCC 0.9.26 PuTTY beta 0.63 v1.2Dynamic-link library (DLL) calling is supported now. If the C program requires a DLL file to run, just put it together with the source file. BinaryCall Tool will searches *.dll and exports all the symbols in these DLL files automatically. Of course, you need these DLL files when run the output script. However, it also works if you loaded them by last version of MemoryDll UDF.To add more Windows API library easily by editing the ini file.Better error handling and more error messages in output script.Add zero padding to avoid short jumps that crash the relocation table.BinaryCall Tool accepts drag and drop files now.Some small bug fixed. BinaryCall 1.0.zip BinaryCall 1.1.zip BinaryCall 1.2.zip
- 33 replies
-
- binary
- machine code
-
(and 1 more)
Tagged with:
-
Func _Binary($Int) ;Uncomment To Only Accept Integers #cs If IsInt($Int) = 0 Then Return 0 EndIf #ce If $Int < 0 Then ;Negative Numbers Will Break The Function Return 0000 EndIf Local $Integer = $Int Dim $Bin[1] = [Mod($Integer, 2)] Local $Counter = 1 Do $Integer = Floor($Integer / 2) _ArrayAdd($Bin, Mod($Integer, 2)) Until $Integer = 0 _ArrayReverse($Bin) ;Reverses The Array Because As Is, The Product Is Backwards ;A Loop To Remove Any Preceding 0's or Add 0's To Keep At Least Four Digits Select Case $Int <= 1 $Integer = "00" & _ArrayToString($Bin, "") Case $Int = 2 Or $Int = 3 $Integer = "0" & _ArrayToString($Bin, "") Case $Int >= 8 $Integer = StringTrimLeft(_ArrayToString($Bin, ""), 1) Case Else $Integer = _ArrayToString($Bin, "") EndSelect ;You Can Comment It Out Without Anything Else Having A Problem Return $Integer EndFunc I made this because I was writing something that I could use to play with Bitwise Operations and using Binary() by itself wasn't helping. It's very basic and will only take positive integers because that's all I needed but I'm sure with a little tweaking you could make it fit with negative and float types. It returns a string essentially but doesn't pose a problem when just changing numbers into binary digits. Example: If you were to do _Binary(5) you would get "0101" and _Binary(8) would return "1000" Between this last sentence and here I've changed this about a half dozen times to refine it a bit because without it checking if your number is < 0 it would break if a negative number was inserted and it wouldn't even have a problem if you put in Float Values, Regular or Special Characters but that negative value will do the trick lol. Anyway, I hope someone finds some use of this and thank you for reading! -Pick
-
Hi AutoIt Programmers, i wanna figure out how to use Binary functions in C# like: BinaryMid BinaryLen IsBinary and other basic ones were too ez, but those two were hard to noob like me. I appreciate for your helps/hints.
-
BinaryToAu3Kompressor v1.0.5.4 It's now possible to see the best compression ratio using LZMA, LZNT and Base64 compressions with differents combinations. Nothing too complicate, you drag'n drop a file on the picture and script Test all compression types and return the ratios. ( Test duration depends of file size, slowest compression is LZNT, but all decompressions are fast ) Free to you after, to choose the compression(s) you want... Yes, LZMA needs a dll ( embedded & compressed in script ) but brings a powerfull compression. It opens scite with your file compressed to an au3 script with or without decompression function as you want. Hold Left Shift key when clicking button for just copy script to clipboard. Use the 3 compressions at a time works but doesn't give a good ratio, that's why i don't display it. Usefull for little files you want include in your scripts ! No externals files needed, they are already in script. Previous downloads : 1103 Source and Executable BinaryToAu3Kompressor will be added to the next version of >SciTEHopper Thanks to Ward for his >Base64.au3 and LZMA.au3, and trancexx for his >LZNT functions and his >Base64Decode function.
-
(Edited from original. Please note that I AM NOT AN AUTOIT EXPERT. I write code using Autoit frequently but I am no expert, especially when it comes to I/O. So any remarks that start with "Why did you..." can be answered by referring to the first sentence. This project was done in Autoit because of an interface I built to display the data.) Attached is a program and ascii input file I wrote to read stock price data, convert it to binary and then read it back into the program in binary. The goal was to show increased performance for reading the files in binary and provide a demo on how to read/write binary for int32, int64, double and strings for anyone who might find it helpful. The results on my PC show the following: Time to read ascii file only: 456.981951167202 Ascii read & process time: 6061.83075631701 Binary write file time: 14787.9184635239 Time just to read binary file: 42.418867292311 Binary read and process time: 4515.16129830537 A couple things to note: 1) The 32 MB ascii file took 10x longer to read than the 15 MB binary file. Not entirely sure why. Both were read into a buffer. 2) The Binary write takes a long time but I made no effort to optimize this because the plan was to write this file one time only so I don't mind if it takes longer to write this file. I care much more about how long it takes to read the file because I will be reading it many times. 3) There was a modest gain in converting the ascii file to binary in terms of file size and reading speed. So big picture... not sure it's worth the effort to convert the files to binary even though most of the data is numerical data in the binary file. That was actually surprising as I expected there would be more of a difference. Any ideas on how to get the binary data to read at a faster rate would be great. binary.au3 2019_02_08.zip
-
When I am trying to compile the autoit files with aut2exe. I am getting below error. There is no issue in code as the same code is getting compiled on different machine. I tried reinstalling the AUtoIT, but the issue replicates. Any suggestions?
- 10 replies
-
- binary
- binary integrity
-
(and 1 more)
Tagged with:
-
Hello, I'm trying to read a binary file to an array but couln't get it to work. Also I coul not find any help in the forum around this subject whish was helpfull. Is there any way it could be done? I tried a lot of ways but maybe somebody know's the right way? #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <File.au3> #include <Array.au3> #include <AutoItConstants.au3> Local $in=FileOpen("TEST_labels.idx1-ubyte",16) ; 16+0=Read binary Local $data = FileRead($in) Local $FileArray = BinaryToString($data,4) ;~ $FileArray = StringSplit($BinarydData, @CRLF, 1+2) ;~ Local $FileArray = StringRegExp($BinarydData, "[^\r\n]+", 3) FileClose($in) _ArrayDisplay($FileArray,"$FileArray","",32) MsgBox($MB_SYSTEMMODAL, "", "$FileArray = " & $FileArray ) TEST_labels.idx1-ubyte
-
How can I perform binary operations?
Dragonfighter posted a topic in AutoIt General Help and Support
I'm searching a way to do xor and shift and if possible also other operations. Thanks in advance for the replies. -
Hello. I'm too stupid to see my mistake: To investigate the internal "dictionary" of TIFF files I'd like to read in the files in binary mode and to check, if there are more than one pages "in" this TIFF. Notepad++, "View as Hex" is presenting the first bytes as "49 49 2a 20 08 20 20 20 12" for the TIF attached to this posting The "TIFF Header Format" is easy: Offset 00h, 2 Byte = Byte Order, "II"=intel, "MM"=motorola. (I = 0x49) --> II Offset 02h, 2 Byte = Version Nr. Offset 04h, 4 Byte = pointer to first IFD entry Description of TIFF header: https://www.awaresystems.be/imaging/tiff/faq.html#q3 Howto read and analyse the binary content correctly? This is my messy, not operational code: $sampleTiff="H:\daten\tif\11\11\111111.TIF" $h=FileOpen($sampleTiff,16) $content=FileRead($h) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console FileClose($h) $type=VarGetType($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $type = ' & $type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $ToString=BinaryToString($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ToString = ' & $ToString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & @CRLF) $content=StringTrimLeft($content,2) ; cut off the leading "0x" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console for $i = 1 to 8 step 8 $next=StringMid($content,$i,2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $next = ' & $next & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $Chr=BinaryToString($next) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Chr = ' & $Chr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & "---" & @CRLF) Next Regards, Rudi. 111111.TIF
-
Hello , Here are three stepts that I would like to speed up - if possible: STEP 1: I am generating an array, containing binary numbers up to a certain amount of digits. My script adds leading zeros, so that each number has equal amount of digits. Example: 14 digit Binary array: I am using the code For $i = 0 to 2^$bit-1 ; $bit amount of digits. for example: 14 $binary = ( Dec2Bin($i) ) ; Check length of binary string $adig = $bit - StringLen($binary) ; Determine how many leading 0 have to be added $zeros = "" For $j = 1 To $adig ; add leading "0"s $zeros = $zeros & "0" Next $BinArray[$i] = $zeros & $binary ;Write binary-number to file, leading "0" Next Func Dec2Bin($D) Return (BitShift($D, 1) ? Dec2Bin(BitShift($D, 1)) : "") & BitAnd($D, 1) EndFunc ;==> Dec2Bin() AutoIt v3.3.12.0 to generate the binary number. STEP 2: I reduce the array to unique values. In my application, the binary-numbers do not have a start-bit or end-bit. This means, that are actually the same numbers, and only one of them is to remain in the array. All alterations aren't unique and shall be removed. Here is my code: For $i = 0 to Ubound($BinArray)-1 ; shift through all rows For $j = 1 to $bit ; shift through all the bits If $i = Ubound($BinArray) Then ; exit before exceeding the arrays boundries ExitLoop 2 EndIf $BinArray[$i] = StringRight ( $BinArray[$i], 1 ) & StringLeft ( $BinArray[$i], $bit-1 ) $BinArray = _ArrayUnique($BinArray, 0, 0, 0, 0, $ARRAYUNIQUE_AUTO) If @error <> 0 Then Msgbox(0, "Error in _ArrayUnique", "The Error Code is " & @error & " Abort.") Exit EndIf Next Next STEP 3: Finally, I write the remaining array into a text-file. For $i = 0 to Ubound($BinArray)-1 FileWrite($hFileOpen, $i & @TAB & $BinArray[$i] & @CRLF) Next So my question is: any idea how to speed up this procedure? There certainly is a way to do this smarter. Btw.: Step 2 is optional. Thanks for helping, dejhost
-
New release. 19 June 2013 (1.0.0.4) There is a relation with this topic SQLite ListView and BLOB demo but I decided to start a completely new Topic because the approach is considerably different from the two previous examples which were only kick-offs to this demo. This example shows how binary objects can be recognized natively in a database BLOB field without having to link to other fields that may contain information of the data object. In the demo I used 2 approaches for native recognition 1. For multi-type binary objects, the file name is added in the header of the BLOB Multi-type object can be images or any other kind of file. Because of the object header data, there is no need to identify the object in the binary code 2. Objects without header data, this works only for images, an algorithm will identify the type of image. The demo shows what happens whit objects which are not identifiable, see example 5. Credits to: 1. trancexx: GIFAnimation.au3 '?do=embed' frameborder='0' data-embedContent>> 2. smashly: _ImageResize() Resizes and converts different graphicformats 3. rover: Customize Draw of Listview rows Optimizations of WS_NOTIFY I also thank rover for giving a second method to resolve the image space issue. I implemented the one proposed by KaFu, because very simple to implement 4. KaFu: Solved the Listview issue with image space in Columns one. 5. jchd: For some hints and background info on SQLite 6. Yashied: WinAPIEx.au3 '?do=embed' frameborder='0' data-embedContent>> new release. Version 1.0.0.4 What's new: - added fully generic Add, Edit, Add/Copy, Delete and Find buttons. With fully generic I mean, you don't have to bother about the table content, GUI field inputs will populate accoring to the table definition. - Added Field validation, also according to how the columns were defined in the table. (see GUI dynamic input validation for more information) tested a thousand times... on W7 and WXP 32/64 For a working example you have to download 2 files (see links in between the horizontal lines: SQLite GreenCan_demo BLOB in Listview 1.0.0.4.zip GreenCan_demo2.zip (if you already did, don't mind downloading it again) Note: For the Edit GUI, you will notice that sometimes one field is not editable, marked as (*PK) in the description. The field is a 'Primary Key autoincrement'. When appending the row, the PK will automatically increment, therefore it is not allowed to edit the field. Other fields mared (*) cannot be empty, you can only save the row if these fields contain data. In the case (*PK) is editable, you have to put unique data for the Primary key. If you do a copy/add without changing the field content, you will get a not unique Error. Special case: I don't allow empty primary key (NULL), while SQLite does, but it's pretty useless anyhow because you can only have 1 NULL in a Primary key. I have also included a very small non BLOB database, for example 0, to show that the generic edit/add works also here. SQLite GreenCan_demo BLOB in Listview 1.0.0.4.zip and don't forget to download this zip file to complete the required files for the demo http://users.telenet.be/GreenCan/AutoIt/GreenCan_demo2.zip I let you explore the demo and please give me feedback. GreenCan
-
Hi, I have a binary string that I want to convert to octal, The string I want to convert is, 10001001010100000100111001000111000011010000101000011010 The String is read from a .txt file Once its converted it should read this, 4 2 2 5 0 1 1 6 2 1 6 0 6 4 1 2 0 6 10 which I want written to the .txt file to overwrite the original binary string. The 10 at the end should be ignored as there are not 3 digits to convert. I'm thinking it should read the string from left to right to get the next 3 digits before converting them to its oct value. would this be the best way to do this or is there a better way? If i'm on the right track can anyone give me an example of how to write this script please? I've looked at the StringLeft function & StringReplace but I'm not sure how to use them the correct way to accomplish what I'm trying to do. Thanks
-
I was just working on a project that involved decoding a stream of binary data from a serial port in AutoIt. It took me a few hours to figure out how to process the data efficiently in AutoIt and I did not find any helpful examples on how to do so, so I thought I would share my core example and maybe save someone else some time. There may be a more efficient way to do this, but this works well for me. #cs Author: ToasterKing This is an example of a way to parse streaming binary data that follows a strict format with a header and footer. In this example, each frame is 5 bytes with a 2-byte header of 0xD5AA and a 1-byte footer of 0xAD. The _BinaryParse() function accumulates incoming data in a buffer. Once a footer is found, it searches backward for the header, and if it is in the right position, it extracts the remaining 2 bytes in the middle, then moves on to looking for the next frame. #ce ; The data source might be something asynchronous like serial or TCP, but since this is just an example, I'm just putting the data in a variable. Local $fSomeData $fSomeData = Binary("0xD5AA24B1") ; Binary data constituting almost a complete frame. _BinaryParse($fSomeData) ; Call the function with the received data. It isn't a complete frame, so it is just stored in the buffer until more data is received. $fSomeData = Binary("0xAD62D5AA92E7AD") ; Remainder of the previous frame, one garbage byte (0x62) which should be skipped, and a complete additional frame. _BinaryParse($fSomeData) ; The function should be able to parse both frames now. Func _BinaryParse($fNewData) Local Static $fBinaryReceived = Binary("") ; Buffer for received data ConsoleWrite("Hey, the function is called!" & @CRLF) ; Add new data to the buffer. ; This ridiculous monstrosity is the only way I could find to append binary data to binary data in AutoIt. It must be converted to strings first. ; Both, one, or no substrings will begin with "0x" depending on whether they contained binary data. To be converted back to binary properly, only one instance ; of "0x" must exist at the beginning of the string. $fBinaryReceived = Binary("0x" & StringReplace(String($fBinaryReceived) & String($fNewData),"0x","")) ConsoleWrite("Data in the buffer: " & String($fBinaryReceived) & @CRLF) Local $iLength = BinaryLen($fBinaryReceived) ; Count the bytes in the data If $iLength > 0 Then Local $fBinaryReceivedTemp = $fBinaryReceived ; Create temporary copy to work on Local $fByte1,$fByte2 For $i = 1 To $iLength If BinaryMid($fBinaryReceivedTemp,$i,1) = 0xAD Then ; If the 1-byte footer found ConsoleWrite("Footer found at end of " & $i & " of " & $iLength & " bytes!" & @CRLF) If BinaryMid($fBinaryReceivedTemp,$i - 4,1) = 0xD5 And BinaryMid($fBinaryReceivedTemp,$i - 3,1) = 0xAA Then ; and the 2-byte header is found 4 bytes before that ConsoleWrite("Header found before the footer!" & @CRLF) $fByte1 = BinaryMid($fBinaryReceivedTemp,$i - 2,1) ; Get 1st byte in the body (between header and footer) $fByte2 = BinaryMid($fBinaryReceivedTemp,$i - 1,1) ; Get 2nd byte in the body (between header and footer) ConsoleWrite("Here is the critical data: " & String($fByte1) & " " & String($fByte2) & @CRLF) ; Just display the 2 bytes for demonstration purposes. Normally, you'd do something more useful with it here. EndIf $fBinaryReceived = BinaryMid($fBinaryReceivedTemp,$i + 1) ; Truncate the original data to remove all of the bytes just processed, then continue processing $fBinaryReceivedTemp EndIf Next EndIf EndFunc
-
I want to take a binary data from any source (string,number,files,etc..) and iterate over each X bits of it in a loop, say take bits 1-5, then 6-10, etc.. Then I want to convert these bits to their corresponding decimal value. but all the binary functions I found in autoit only work with full bytes, and do not let me get smaller sections of bits, like "BinaryMid()" that "Extracts a number of bytes from a binary variant" Can anyone tell me if this is possible to do and how? and also if there is a function to convert those bits to/from decimals? I'm not that familiar with dealing directly with binary, so any help or tips will be very appreciated Context: I'm trying to make a function to encode/decode any given binary data into/from a given array of characters. just like Base64 but using different bases then [a-z A-Z 0-9 +/= ]. My approach currently is to figure out how many bits of binary I can encode with each character, read those bits and convert them to a decimal number, then I will use that number as an index and take the character at that index from the character array and add it to the result string. I'm aware that there may be some padding needed.
-
This code is a subset of an AutoIt tool I wrote for the classic DOS word-processor XyWrite. The tool allows 7-bit Ascii encoding of XyWrite Programming Language programs, with "readability aids" that mimic the way this code looks natively on the DOS screen. This is a special 7-bit encoding that we've used for many years in the XyWrite community to discuss XPL code on the XyWrite Mailing List. But that's neither here nor there. The present subset consists of three utilities, which I offer here for what they're worth. The first, DVIEW.AU3, takes a binary file and displays it in the default Windows text editor, displaying only Ascii chars 32-127, the other chars being represented by ".". The command-line usage is: DVIEW.AU3 <file_in><Enter> The second, DREAD.AU3 (that's "Dee-Read", not "dread" ), provides a similar display, except that characters outside the Ascii 32-127 range are represented by "{nnn}", where "nnn" is the 3-digit decimal Ascii number. (The initial "D" in these utilities' names stands for "decimal".) The output from DREAD.AU3 can be edited to make simple patches to binary files. The output file is named DREAD.TXT. The usage is: DREAD.AU3 <file_in><Enter> The third utility, DWRITE.AU3, takes DREAD output and writes it back to disk as a binary file. So, once you edit the output from DREAD, you write it to disk with: DWRITE.AU3 <file_in><Enter> The default file_in is DREAD.TXT -- i.e., the output of DREAD.AU3. The output file is named DWRITE.BIN, which can be renamed as desired. You'll see that each of these scripts processes the input file character by character. If there's a faster way of doing this, for example by manipulating bit patterns, I'd be pleased to hear about it. Here are the three scripts. Enjoy. ; DVIEW.AU3 -- AutoIt v3 [CarlD rev.9/27/15] ; Display a decimal view of a binary file ; ; Usage: ; DREAD.AU3 file_in ProgressOn(@ScriptName,"Working") Global $iLnLen = 0; Line length meter Local $sTmp = ""; Temp string var Local $sInFile = @ScriptDir & "\DVIEW.IN" If $CmdLine[0] > 0 Then $sInFile = $CmdLine[1] If Not FileExists($sInFile) Then ProgressOff() MsgBox(16, @Scriptname, $sInFile & " does not exist!", 3) Exit EndIf Local $sTmpFile = @ScriptDir & "\DVIEW.TMP" Local $sOutFile = @ScriptDir & "\DVIEW.TXT" If FileExists($sTmpFile) Then FileDelete($sTmpFile) If FileExists($sOutFile) Then FileDelete($sOutFile) Local $hWrIn = FileOpen($sInFile, 16); Handle for source file Local $sToEncode = FileRead($hWrIn); Binary (hex) string to encode FileClose($hWrIn) Global $sEncoded = ""; Encoded output (string) Local $aEncoded = HexToDec($sToEncode); Binary (hex) to decimal array Local $iAsc = ""; Decimal Ascii number of current char ; Loop through each byte of input string For $i = 1 To UBound($aEncoded) - 1 $iAsc = StringFormat("%03u", $aEncoded[$i]) $sTmp = "" If $iAsc > 31 And $iAsc < 128 Then $sTmp = Chr($aEncoded[$i]) Else $sTmp = "." EndIf $sTmp = AddCrLf($sTmp) If $iLnLen = 0 And $sTmp = "." Then $sTmp = "{046}" If $iLnLen = 0 And $sTmp = ">" Then $sTmp = "{062}" $sEncoded &= $sTmp Next ; Trim double CrLf to one; change trailing space to "{032}" If StringRight($sEncoded, 2) = @CRLF Then _ $sEncoded = StringTrimRight($sEncoded, 2) If StringRight($sEncoded, 1) = " " Then _ $sEncoded = StringTrimRight($sEncoded, 1) & "{032}" ; Add header and footer Local $sHeader = "DVIEW v1.0" & @CRLF $sEncoded = $sHeader & "b-gin [" & $sInFile & "]" & @CRLF & _ $sEncoded & @CRLF & "-nd DVIEW" & @CRLF ; Write output file Local $hWrOut = FileOpen($sTmpFile, 2) FileWrite($sTmpFile, $sEncoded) FileClose($hWrOut) FileMove($sTmpFile, $sOutFile, 1) ProgressSet(100, "Done") Sleep(2000) ProgressOff() ShellExecute($sOutFile) ; --------- Function DeFinitions --------- Func HexToDec($sHexIn); Convert hex string to decimal array $aHexChars = StringSplit($sHexIn, "") Local $aHexIn[UBound($aHexChars) / 2] Local $j = 0 For $i = 1 To UBound($aHexChars) Step 2 If $i + 1 <= UBound($aHexChars) Then $aHexIn[$j] = $aHexChars[$i] & $aHexChars[$i + 1] $j += 1 Else ExitLoop EndIf Next Local $aDecOut[UBound($aHexIn)] For $i = 0 To UBound($aHexIn) - 1 $aDecOut[$i] = Dec($aHexIn[$i]) Next Return $aDecOut EndFunc ;==>HexToDec Func AddCrLf($sIn); Add line breaks to output $iLnLen += StringLen($sIn) If $iLnLen > 74 Then $sIn &= @CRLF $iLnLen = 0 EndIf Return $sIn EndFunc ;==>AddCrLf ; DREAD.AU3 -- AutoIt v3 [CarlD rev.9/27/15] ; Display a decimal view of a binary file ; ; Usage: ; DREAD.AU3 file_in ProgressOn(@ScriptName,"Working") Global $iLnLen = 0; Line length meter Local $sTmp = ""; Temp string var Local $sInFile = @ScriptDir & "\DREAD.IN" If $CmdLine[0] > 0 Then $sInFile = $CmdLine[1] If Not FileExists($sInFile) Then ProgressOff() MsgBox(16, @Scriptname, $sInFile & " does not exist!", 3) Exit EndIf Local $sTmpFile = @ScriptDir & "\DREAD.TMP" Local $sOutFile = @ScriptDir & "\DREAD.TXT" If FileExists($sTmpFile) Then FileDelete($sTmpFile) If FileExists($sOutFile) Then FileDelete($sOutFile) Local $hWrIn = FileOpen($sInFile, 16); Handle for source file Local $sToEncode = FileRead($hWrIn); Binary (hex) string to encode FileClose($hWrIn) Global $sEncoded = ""; Encoded output (string) Local $aEncoded = HexToDec($sToEncode); Binary (hex) to decimal array Local $iAsc = ""; Decimal Ascii number of current char ; Loop through each byte of input string For $i = 1 To UBound($aEncoded) - 1 $iAsc = StringFormat("%03u", $aEncoded[$i]) $sTmp = "" If $iAsc > 31 And $iAsc < 128 Then $sTmp = Chr($aEncoded[$i]) Else $sTmp = "{" & $iAsc & "}" EndIf $sTmp = AddCrLf($sTmp) If $iLnLen = 0 And $sTmp = "." Then $sTmp = "{046}" If $iLnLen = 0 And $sTmp = ">" Then $sTmp = "{062}" $sEncoded &= $sTmp Next ; Trim double CrLf to one; change trailing space to "{032}" If StringRight($sEncoded, 2) = @CRLF Then _ $sEncoded = StringTrimRight($sEncoded, 2) If StringRight($sEncoded, 1) = " " Then _ $sEncoded = StringTrimRight($sEncoded, 1) & "{032}" ; Add header and footer Local $sHeader = "DeeREAD v1.0" & @CRLF $sEncoded = $sHeader & "b-gin [" & $sInFile & "]" & @CRLF & _ $sEncoded & @CRLF & "-nd DeeREAD" & @CRLF ; Write output file Local $hWrOut = FileOpen($sTmpFile, 2) FileWrite($sTmpFile, $sEncoded) FileClose($hWrOut) FileMove($sTmpFile, $sOutFile, 1) ProgressSet(100, "Done") Sleep(2000) ProgressOff() ShellExecute($sOutFile) ; --------- Function DeFinitions --------- Func HexToDec($sHexIn); Convert hex string to decimal array $aHexChars = StringSplit($sHexIn, "") Local $aHexIn[UBound($aHexChars) / 2] Local $j = 0 For $i = 1 To UBound($aHexChars) Step 2 If $i + 1 <= UBound($aHexChars) Then $aHexIn[$j] = $aHexChars[$i] & $aHexChars[$i + 1] $j += 1 Else ExitLoop EndIf Next Local $aDecOut[UBound($aHexIn)] For $i = 0 To UBound($aHexIn) - 1 $aDecOut[$i] = Dec($aHexIn[$i]) Next Return $aDecOut EndFunc ;==>HexToDec Func AddCrLf($sIn); Add line breaks to output $iLnLen += StringLen($sIn) If $iLnLen > 74 Then If $sIn = " " Then $sIn = "{032}" $sIn &= @CRLF $iLnLen = 0 EndIf Return $sIn EndFunc ;==>AddCrLf ; DWRITE.AU3 -- AutoIt v3 [CarlD rev.9/27/15] ; Write DVIEW encoding as binary file ; ; Usage: ; DWRITE.AU3 file_in ; Output is sent to @ScriptDir & "DWRITE.BIN" ProgressOn(@ScriptName,"Working") Local $sInFile = @ScriptDir & "\DREAD.TXT" If $CmdLine[0] > 0 Then $sInFile = $CmdLine[1] If Not FileExists($sInFile) Then ProgressOff() MsgBox(16, @Scriptname, $sInFile & " does not exist!", 3) Exit EndIf Local $sTmpFile = @ScriptDir & "\DWRITE.TMP" Local $sOutFile = @ScriptDir & "\DWRITE.BIN" Local $hWrIn = FileOpen($sInFile); Handle for source file Local $sMaster = FileRead($hWrIn); Master string to decode FileClose($hWrIn) Local $sToDecode = "" Local $aTmp = "" ; Remove header|footer If StringLeft($sMaster, 9) = "DeeREAD v" Then _ $sMaster = StringTrimLeft($sMaster, StringInStr($sMaster, "]")) If StringRight($sMaster, 13) = "-nd DeeREAD" & @CRLF Then _ $sMaster = StringTrimRight($sMaster, 13) Local $sFinished = "" Local $iChunkSz = 512 Local $iAdd = 0 ; - - - - - - Main Loop - - - - - - While $sMaster If StringLen($sMaster) > $iChunkSz Then $sToDecode = StringLeft($sMaster, $iChunkSz) $sMaster = StringTrimLeft($sMaster, $iChunkSz) If StringRight($sToDecode, 2) <> @CRLF Then $iAdd = 1 + StringInStr($sMaster, @CRLF) $sToDecode &= StringLeft($sMaster, $iAdd) $sMaster = StringTrimLeft($sMaster, $iAdd) EndIf Else $sToDecode = $sMaster $sMaster = "" EndIf ; Strip CrLfs $sToDecode = StringReplace($sToDecode, @CRLF, "") ; "{nnn}" ==> 1-byte Ascii char; Local $aTmp = StringSplit($sToDecode, "{") Local $iAsc = -1 For $i = 1 To UBound($aTmp) - 1 $iAsc = StringLeft($aTmp[$i], 3) If StringInStr($aTmp[$i], "}") = 4 And _ StringIsDigit($iAsc) Then If $iAsc > -1 And $iAsc < 256 Then $sToDecode = StringReplace($sToDecode, "{" & _ StringLeft($aTmp[$i], 4), Chr($iAsc)) EndIf EndIf Next $sFinished &= $sToDecode $sToDecode = "" WEnd ; - - - - - End Main Loop - - - - - ; Write output file Local $hWrOut = FileOpen($sTmpFile, 2) FileWrite($sTmpFile, $sFinished) FileClose($hWrOut) FileMove($sTmpFile, $sOutFile, 1) ProgressOff() MsgBox(0, @ScriptName, "Output in " & $sOutFile, 5) ; Done
-
Here is my code. Adopted from a post UEZ made. _GenerateUID() Func _GenerateUID() Local $lReturn, $lDriveSerial,$lRandomSeed = "" Local $lChr[2] For $N = 1 To 32 $lChr[0] = Chr(Random(65, 90, 1)) ;A-Z $lChr[1] = Chr(Random(48, 57, 1)) ;0-9 $lRandomSeed &= $lChr[Random(0, 1, 1)] Next $lDriveSerial = DriveGetSerial(StringLeft(@WindowsDir, 3)) $lReturn = StringToBinary($lRandomSeed & $lDriveSerial) ConsoleWrite($lReturn) ;<--- Is printed as a String. ConsoleWrite(@CRLF & $lReturn & @CRLF) ;<--- Printed properly as Binary? Return $lReturn EndFunc ;==>_GenerateUIDOutput: --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop V9P03Y144OZW38YC80IW1IJXWH4003501486415223 0x5639503033593134344F5A57333859433830495731494A58574834303033353031343836343135323233 +>10:40:52 AutoIt3.exe ended.rc:0 +>10:40:52 AutoIt3Wrapper Finished. >Exit code: 0 Time: 0.544 Whenever ConsoleWrite is fed pure binary, it will output it as a string. Whenever a string is mixed with the binary, it outputs the binary as binary. I found this especially confusing when I consulted the Help Documents for an answer... I'm sure I'm missing something, as usual. As always, thanks for your time!
- 8 replies
-
- consolewrite
- binary
-
(and 1 more)
Tagged with:
-
Hello everyone, Again here with my new question. I do have a value what is "text" string, what i read from memory adress, but i do not understand when i convert it, why i geting only the first 4 letter from the word... I was reading how does it storeing in memory, but i am not 100% sure, i did understand right. Anyone can explain how does it work? Or why i get only the first 4 letter only? Ps.: Useing Nomadmemory. BinaryToString($MemRead, 1), 0, 0 The valuse is correct, if i do not convert it at all, but the valuse includeing only numbers. I tried different convert way, but nothing.
-
Hey, Just needed for some projects a side by side control, on the left the binary data on the rigth the string. Nothing more to say here, take a look for yourself. HexControl UDF is licensed under a Creative Commons Attribution 4.0 International License. http://creativecommons.org/licenses/by/4.0/ Greetz, Spider Hex Control.zip
-
I'm trying to replace all occurrences of one string in a binary file with another string (e.g. all "C:\" with "D:\"), but StringReplace() does nothing. I opened my files in Binary mode and set the data read in to binary(), but nothing works. My test script reads a compiled version of the script, does the replacements, then writes the results to an output file. Prior to calling StringReplace(), I call StringInStr() to see if my 'from' string is found. The StringInStr() reports that it found the string, but the StringReplace() reports 0 replacements. Just to be sure, I did a binary compare (BeyondCompare) and the input and output files were exactly the same. Here is my test code: #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 Opt('MustDeclareVars', 1) _Main() Func _Main() Local $infn, $infh, $outfn, $outfh, $cnt, $str_from, $str_to Local $buffer, $offset = 0, $bufsize, $mcnt, $matches = 0, $ret $infn = StringTrimRight(@ScriptName, 4) & ".exe" $outfn = "test2_out.exe" $infh = FileOpen($infn, 16 + 0) If ($infh <= 0) Then Exit (1) $outfh = FileOpen($outfn, 16 + 2) ; 2 = Write mode (erase previous contents) If ($infh <= 0) Then Exit (1) $str_from = "D:\" $str_to = "C:\" $bufsize = 2000 While (1) FileSetPos($infh, $offset, 0) $buffer = FileRead($infh, $bufsize) If (@error == -1) Then ExitLoop $cnt = @extended $buffer = Binary($buffer) $ret = StringInStr($buffer, $str_from) If ($ret >= 0) Then ConsoleWrite("+++: 1 or more strings are in the buffer" & @CRLF) $buffer = StringReplace( _ $buffer, _ $str_from, _ $str_to _ ) $mcnt = @extended $matches += $mcnt ConsoleWrite("+++: " & $mcnt & " replacement(s) made" & @CRLF) FileWrite($outfh, $buffer) $offset += $cnt WEnd FileClose($infh) FileClose($outfh) ConsoleWrite("+++: matches: " & $matches & @CRLF) ConsoleWrite("+++: processed " & $offset & " bytes." & @CRLF) EndFunc ;==>_Main
-
I have been looking at sending/receiving bytes down a serial interface and I got rather confused when using the Binary() command. I did a quick search of the forums without finding any further detail and then thrashed around experimenting, until I think I understand. In the hope that this might help someone else starting down the same road, here is a trivial bit of code: $a = Binary(0x12345678) $b = Binary("ABCDEF") $c = Binary("0x123456789") $d = Binary("0x12345678") MsgBox(0, Default, _ 'Binary(0x12345678) gives ' & $a & ", a little-endian integer" & @CRLF & _ 'Binary("ABCDEF") gives ' & $b & ", because it's a string. So" & @CRLF & _ 'Binary("0x123456789") gives ' & $c & ", also a string, but" & @CRLF & _ 'Binary("0x12345678") gives ' & $d & ". Syntax is the same, but now it's treated as Hex." & @CRLF & _ "The rule seems to be that if it can be treated as Hex, it will be!") With hindsight, it is quite logical and has enough flexibility to cover the most useful cases.
-
Peers: (binary model), the peers value may be a string consisting of multiples of 6 bytes. First 4 bytes are the IP address and last 2 bytes are the port number. All in network (big endian) notation. The list of peers is length 50 by default. How can I convert the attached? http://en.wikipedia.org/wiki/Endianness#Big-endian I've tried BinaryToString with no luck. Thanks in advance. Peers.txt
-
The goal here is to get the Internet History for endpoints and users in the enterprise to find what business use websites use Java. When opening index.dat in Notepad, I can see all the data I need. Unfortunatly, trying to read that data in AutoIT is proving diffucult. I've tried : Func _ParseIndexdat($indexdatpath) ; Parse index.dat file for useable info ; The tools I've seen don't grab all the info I want :( $Bindexdat = FileOpen($indexdatpath,16) $indexdat = FileRead($Bindexdat) $strIndexdat = BinaryToString($indexdat,2) MsgBox(0,"String from Binary",$strIndexdat) $FileArray = StringSplit($strIndexdat,@CRLF) ;This may get complex... Dim $r = 1 ; to count the records Dim $e = 0; to count the entries ; Start reading from line 1 For $line In $FileArray $content = StringStripWS($line,7) Select Case StringInStr($line,"REDR") ; this is the start of a record MsgBox(0,"REDR",$content) Case StringInStr($line,"URL") ; this may be the start of a record MsgBox(0,"URL",$content) Case StringInStr($line,"LEAK") ; this is the start of an error record ; I will likely ignore it. MsgBox(0,"LEAK",$content) Case StringInStr($line,"http://") ; this is the line with a couple entries MsgBox(0,"http",$content) Case StringInStr($line,"Content-Type:") ; this is an entry I want MsgBox(0,"Content-Type",$content) Case StringInStr($line,"X-Powered-By:") ; this is an entry I want MsgBox(0,"Powered-By",$content) Case StringInStr($line,"~U:") ; this is an entry I want and it marks the end of a record MsgBox(0,"~U",$content) Case Else ; do nothing with the line EndSelect Next EndFunc That doesn't get the info... That code doesn't return anything. Using $Bindexdat = FileOpen($indexdatpath,16) $indexdat = FileRead($Bindexdat) $strIndexdat = BinaryToString($indexdat,1) MsgBox(0,"String from Binary",$strIndexdat) the "string from binary" msg box shows a LOT of data... but URL and http case are both blank or gibberish. BinaryToString($indexdat,2) and ,3 return Nothing in the cases - 4 does the same as 1. Using : $Bindexdat = FileOpen($indexdatpath, 16) $indexdat = FileRead($Bindexdat);$indexdatpath) MsgBox(0,"Index dat",$indexdat) $strIndexdat = BinaryToString($indexdat,1) MsgBox(0,"String from Binary",$indexdat);$strIndexdat & @CRLF & @error) $FileArray = StringSplit($strIndexdat,@CRLF) Shows that $indexdat and $strIndexdat are effectively the same. Using : ; Parse index.dat file for useable info ; The tools I've seen don't grab all the info I want :( ;$Bindexdat = FileOpen($indexdatpath,16) $indexdat = FileRead($indexdatpath);$Bindexdat) ;$strIndexdat = BinaryToString($indexdat,4) MsgBox(0,"String from Binary",$indexdat);$strIndexdat & @CRLF & @error) $FileArray = StringSplit($indexdat,@CRLF) It reads a lot more info... Content-Type is fine. ~U: is fine. URL is mostly blank. Case http:// it will pop up the msg box, but $content is blank. So the data is there... I just can't figure out how to get it into a string. Using : $Bindexdat = FileOpen($indexdatpath,256) $indexdat = FileRead($Bindexdat);$indexdatpath) MsgBox(0,"Index dat",$indexdat) $strIndexdat = BinaryToString($indexdat,1) MsgBox(0,"String from Binary",$indexdat);$strIndexdat & @CRLF & @error) $FileArray = StringSplit($strIndexdat,@CRLF) Returns data, but URL and Http:// pop up as blank... $Bindexdat = FileOpen($indexdatpath,48) - URL and Http are blank. I've found a VBScript that is supposed to read the files... so far no luck on Win7 - it can't find index.dat file... lol! On remote XP machines, it can't find a history folder. So I don't know if it DOES read index.dat files. I've attached it. Any ideas or code help is greatly appreciated!! IE_Network - Copy.txt
- 3 replies
-
- Internet Explorer
- History
-
(and 1 more)
Tagged with:
-
Hi guys, i don't now if it possible, but i have to copy the contenent of a binary file to a txt. Noiw i'm using a hex editor and save everytime to a txt I have try to do: $input=FileOpen("input",16) $output=FileOpen("output",17) $data=FileRead($input) FileWrite($output,$data) With no success, some advice? Thanks for support EDIT: For now seems work, if i have problem i'll post in this thread