Jump to content
Sign in to follow this  
sandin

read any file's content (not only txt)

Recommended Posts

sandin

FileRead() can read content of a textual based files, but what I need is to read content of any file (.exe .jpg .mp3, etc...)

I found in help:

_WinAPI_ReadFile ()

and

_WinAPI_CreateFile ()

but in the help there aren't any examples, so I couldn't really understand them.

I also found some topics on this forum, but couldn't figure from them how to read file's content.

Can anyone give me a simple example of reading any file's content?

Share this post


Link to post
Share on other sites
ProgAndy

You can read all files with FileOPen, FileREad and FileClose, but only in binary mode.

Example:

$file = FileOPen("C:\test.exe",16)
$src = FileRead($file)
FileClose($file)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
sandin
ReaImDown

I tried, but I get first several characters of file, and not the entire file:

$file1 = FileOpenDialog("choose file", "", "ALL (*.*)")
$file = FileOPen($file1,16)
$src = BinaryToString(FileRead($file))
MsgBox(0, "wtf, is this?", $src)
FileClose($file)

edit: P.S. anyway, tnx for reply :)

90% of a file...is to automate the .exe... .mp3 or .mpeg etc... therefore you will not be able to read the biggest chunk of coding, but if theres 'english' in there, you will be able to read it :P

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

Share this post


Link to post
Share on other sites
dcer

Hmm... if you just want raw code/text out of it, you could try to use FileMove to rename the file to .txt and then read it

Share this post


Link to post
Share on other sites
ReaImDown

Hmm... if you just want raw code/text out of it, you could try to use FileMove to rename the file to .txt and then read it

just use HexEdit :)


[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

Share this post


Link to post
Share on other sites
d4rk

But then, what can we see from them ?

somethings like this :

}♂▐MÜ▌


[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites
dcer

just use HexEdit :)

HexEdit? Not recognized with my autoit :P, are you sure there's a function with that name? :P

EDIT: Doh... ofc you're talking about the program HexEdit... my bad xD

Edited by dcer

Share this post


Link to post
Share on other sites
d4rk

no, maybe it's mentioning about an external program


[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites
ProgAndy

I tried, but I get first several characters of file, and not the entire file:

$file1 = FileOpenDialog("choose file", "", "ALL (*.*)")
$file = FileOPen($file1,16)
$src = BinaryToString(FileRead($file))
MsgBox(0, "wtf, is this?", $src)
FileClose($file)

edit: P.S. anyway, tnx for reply :)

You mustn't convert it with BinaryToString. You CAN READ IT ONLY IN BINARY MODE ! Just remove BinaryToString and it works fine.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
sandin

You mustn't convert it with BinaryToString. You CAN READ IT ONLY IN BINARY MODE ! Just remove BinaryToString and it works fine.

I see.... so there is no way to get file's content like the one I get when I open any file in notepad, cause I can't convert binary to string anymore?

p.s. I tried hex:

$file1 = FileOpenDialog("choose file", "", "ALL (*.*)")
$file = FileOPen($file1,16)
$src = Hex(FileRead($file))
MsgBox(0, "wtf is this?", BinaryToString("0x" & $src))
FileClose($file)oÝ÷ Ù©Ýjëh×6#include <string.au3>
$file1 = FileOpenDialog("choose file", "", "ALL (*.*)")
$file = FileOPen($file1,16)
$src = _StringToHex(FileRead($file))
MsgBox(0, "wtf is this?", BinaryToString(_HexToString($src)))
FileClose($file)

and both giving me same results (only first part of the file), but if binaryToString is not working, then how can I convert read binary code into file I read in the first place?

Share this post


Link to post
Share on other sites
ProgAndy

What happens, if you open a file in Notepad, save it and close it again?

Right. the executable is changed and you can't run it anymore.

Why? I think Notepad changes all Chr(0) ( in Hex/Binary: 00 ) to Space. You could do that, too, but then you can't save the file anymore properly.

e.g.:

$file = FileOpen("C:\WINDOWS\Notepad.exe",16)
$str = FileRead($file)
FileClose($file)
$x = StringRegExpReplace($str,"((?:.{2})*?)00","$1.20"); Workaround, because $120 in replace doesn't work: $1.20
$x = StringReplace($x,".","")) ; remove the points from Workaround.
$x = BinaryToString($x)
MsgBox(0, '', $x)
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
sandin

oh... I see what you mean. :/ tnx, that was very informative.

I wanted to know if I can read file's content, so I can split a file into several smaller files, and then recreate the original file from those small files. I thought I can read file's content, then split it into smaller pieces, save each one in a different file, and eventually read those small file's parts, and recreate the original file again.

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
Sign in to follow this  

×