AutoIt: Конвертиране на файл до Bynary и обратно

Публикувано: 06.01.14, 01:49:05 | Автор: ArMeN | Видяна: 458 | Редактирано: 19.07.16, 21:08:37

Конвертиране на файл до Bynary
$var = "$bynary"

$hfile = FileOpen(@ScriptDir & "\body-bg.png", 16)
$hfile2 = FileOpen(@ScriptDir & "\body-bg.au3", 2)
FileWrite($hfile2, $var&'="0x"' & @CRLF)

While 1
$data = FileRead($hfile, 45)
If @error Then ExitLoop
FileWrite($hfile2, $var & ' &="' & StringTrimLeft($data,2) & '"' & @CRLF)
WEnd
MsgBox(0, 'Finish', 'Finish')

Конвертиране на Bynary до файл
$bynary="0x"
$bynary &="89504E470D0A1A0A0000000D494844520000000E000001ED0802000000A68DD81E0000000373424954080808DB"
$bynary &="E14FE0000000097048597300000B1200000B1201D2DD7EFC0000001F74455874536F667477617265004D616372"
$bynary &="6F6D656469612046697265776F726B732038B568D27800000016744558744372656174696F6E2054696D650030"
$bynary &="362F32382F3038CCA221E7000000A649444154789CEDD0B90DC0400C03417F2DBAFF52EC162E39101446B102EE"
$bynary &="9CEFB17AD7F2E7D4D7E70B0F88BF12182A30348B00010204083465356D95252BBE950001020408102040A069AB"
$bynary &="2C59F1ADB2081020408000010243059AB6CA9215DF2A8B00010204081020202BBE5596ACF85659040810204080"
$bynary &="000159F1ADB29AB29AB6122040800001020408C89265AB2C020408EC79BDCFF080A657589B5CD30386BE3AB7E7"
$bynary &="7E7CDF55692259A8660000000049454E44AE426082"

$File = FileOpen(@ScriptDir & "\body-bg2.png", 2)
FileWrite($File, Binary($bynary))
FileClose($File)

Конвертиране на файл до Bynary
$file = FileOpenDialog('Open the image file', @ScriptDir, 'image (*.mp3;*.jpg;*.bmp;*gif;*.png;*.txt;*.au3;*.exe)', 1)

$file2 = FileSaveDialog('Save the file', @ScriptDir, 'script (*.au3)')

_CheckExt($file2, 'au3')

$var = InputBox('Name variable', 'Prompt the name variable used', '$pic')

_CheckCapital($var, '$')

$hfile = FileOpen($file, 16)
$hfile2 = FileOpen($file2, 2)

FileWrite($hfile2, $var&'="0x"' & @CRLF)

While 1
$data = FileRead($hfile, 45)
If @error Then ExitLoop
FileWrite($hfile2, $var&'&="' & StringTrimLeft($data,2) & '"' & @CRLF)
WEnd

MsgBox(0, 'Done!!', 'Done by Fabry!!!')

Func _CheckExt(ByRef $s_file, $s_ext)
If StringRight($s_file, StringLen($s_ext)) <> $s_ext Then $s_file &= '.' & $s_ext
EndFunc

Func _CheckCapital(ByRef $s_file, $s_cap)
If StringLeft($s_file, StringLen($s_cap)) <> $s_cap Then $s_file = $s_cap & $s_file
EndFunc

Източник
Прочитане на файл и запазване
$hfile = FileOpen(@ScriptDir & "\body-bg.png", 16)
$data = FileRead($hfile)
$File = FileOpen(@ScriptDir & "\body-bg2.png", 2)
FileWrite($File, Binary($data))
FileClose($File)

Не сте влезли в акаунта си за да коментирате.


 

Няма коментари.