;TailRW.au3 ; based on "APIRW.au3"" ; ------------------------------------------------------------------------------ ; AutoIt Version: 3.0 ; Language: English ; Description: Functions that assist with reading binary files./ writing to tail by line number fast/ writing to any line ;Author : Write tail etc by Randallc; original binary by Larry, Zedna [binary wites by EriFash?] ; ------------------------------------------------------------------------------ #include-once #include #include #include Func _BinRead($sFile) ;############################## ; _BinRead( ) ; ; Reads any file into a string in hex format. ; ; Return - file contents in hex ;############################## Local $GENERIC_READ = 0x80000000, $OPEN_ALWAYS = 4, $FILE_ATTRIBUTE_NORMAL = 0x00000080, $hDLL = DllOpen("kernel32.dll"), $iBytes = FileGetSize($sFile), $AFR_ret = "", $hFile = DllCall($hDLL, "hwnd", "CreateFile", "str", $sFile, "long", $GENERIC_READ, "long", 0, "ptr", 0, "long", $OPEN_ALWAYS, "long", $FILE_ATTRIBUTE_NORMAL, "long", 0), $AFR_ptr = DllStructCreate("byte[" & $iBytes & "]"), $AFR_r = DllCall($hDLL, "int", "ReadFile", "hwnd", $hFile[0], "ptr", DllStructGetPtr($AFR_ptr), "long", $iBytes, "long_ptr", 0, "ptr", 0) For $i = 1 To $AFR_r[4] $AFR_ret = $AFR_ret & Hex(DllStructGetData($AFR_ptr, 1, $i), 2) Next $AFR_ptr = "";DllStructDelete($AFR_ptr) DllCall($hDLL, "int", "CloseHandle", "hwnd", $hFile[0]) DllClose($hDLL) Return $AFR_ret EndFunc ;==>_BinRead Func _BinWrite($sFile, $sHex) ;############################## ; _BinWrite( , ) ; ; Writes a hex formatted string to a file. ; ; Return - idk... ;############################## Local $GENERIC_WRITE = 0x40000000, $OPEN_ALWAYS = 4, $FILE_ATTRIBUTE_NORMAL = 0x00000080, $c = -1, $hDLL = DllOpen("kernel32.dll"), $iBytes = StringLen($sHex) / 2, $hFile = DllCall($hDLL, "hwnd", "CreateFile", "str", $sFile, "long", $GENERIC_WRITE, "long", 0, "ptr", 0, "long", $OPEN_ALWAYS, "long", $FILE_ATTRIBUTE_NORMAL, "long", 0), $AFW_ptr = DllStructCreate("byte[" & $iBytes & "]") For $i = 1 To $iBytes $c = $c + 2 DllStructSetData($AFW_ptr, 1, Dec(StringMid($sHex, $c, 2)), $i) Next Local $AFW_r = DllCall($hDLL, "int", "WriteFile", "hwnd", $hFile[0], "ptr", DllStructGetPtr($AFW_ptr), "long", $iBytes, "long_ptr", 0, "ptr", 0) $AFR_ptr = "";DllStructDelete($AFR_ptr) DllCall($hDLL, "int", "CloseHandle", "hwnd", $hFile[0]) DllClose($hDLL) SetError($AFW_r[0]) Return $AFW_r[4] EndFunc ;==>_BinWrite Func _LastErr($hDLL = "kernel32.dll") ;############################## ; _LastErr( [ ] ) ; ; Gets the last api error. ; ; Return - value from GetLastError api ;############################## Local $err = DllCall($hDLL, "int", "GetLastError") Return $err[0] EndFunc ;==>_LastErr Func _APIFileOpen($sFile) ;############################## ; _APIFileOpen( ) ; ; Creates a "REAL" file handle for reading and writing. ; ; Return - value from CreateFile api ;############################## Local $GENERIC_READ = 0x80000000, $GENERIC_WRITE = 0x40000000, $OPEN_ALWAYS = 4, $FILE_ATTRIBUTE_NORMAL = 0x00000080 Local $AFO_h ,$FILE_SHARE_READ = 0x00000001,$OPEN_EXISTING = 3,$FILE_READ_DATA = 1 $AFO_h = DllCall("kernel32.dll", "hwnd", "CreateFile", "str", $sFile, "long", $GENERIC_READ, "long", 7, "ptr", 0, "long", $OPEN_EXISTING, "long", $FILE_ATTRIBUTE_NORMAL, "long", 0) Return $AFO_h[0] EndFunc ;==>_APIFileOpen Func _APIFileClose($hFile) ;############################## ; _APIFileClose( ) ; ; Return - value from CloseHandle api ;############################## Local $AFC_r $AFC_r = DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return $AFC_r[0] EndFunc ;==>_APIFileClose Func _APIFileSetPos($hFile, $nPos) ;############################## ; _APIFileSetPos( , ) ; ; Return - value from SetFilePointer api ;############################## Local $FILE_BEGIN = 0 Local $AFSP_r = DllCall("kernel32.dll", "long", "SetFilePointer", "hwnd", $hFile, "long", $nPos, "long_ptr", 0, "long", $FILE_BEGIN) Return $AFSP_r[0] EndFunc ;==>_APIFileSetPos Func _APIFileRead($hFile, $nBytes, $Option = 0) ;############################## ; _APIFileRead( , , [