Jump to content

problem with reading a file send it by TCP and then save as new file. help


 Share

Recommended Posts

Look in my code:

#include <Misc.au3>
#include <string.au3>
$ppp2="0xFFD8FFE000104A46494600010101006400640000FFDB004300100B0C0E0C0A100E0D0E1211101318281A1816161831


23251D283A333D3C3933383740485C4E404457453738506D51575F626768673E4D71797064785C656763FFDB004301111212


1815182F1A1A2F63423842636363636363636363636363636363636363636363636363636363636363636363636363636363


6363636363636363636363FFC00011080028002803012200021101031101FFC4001900010101010101000000000000000000


00050004030601FFC400331000010303020208020B00000000000000010203040005110612213113415152617192D191B214


1522234344537282A2B1FFC400190101000301010000000000000000000000020103040005FFC40024110002020103020700


00000000000000000102000311121321619104051532415181FFDA000C03010002110311003F007AE372E964BACE32DB6ADB


B738C91CC9ACC97DBFD147A95EF464B776DDAE09CF290AA5A3DB336F54B94F7420A77207F99F3AAF2499B742AA827E675C61


90E98A90D9E4ACABDEA0E327F011EA57BD6871493A7582B56D49DB93D8335C66C00CB0244670BACE3278E481DB5C4985554F


07EF135C19894BCD323825C252139CE0E09E1F0AA8281312F6A186C23884294547C769E155243A84AEFAB6DB10D9A5275249


6D67095CAC1F224539ABDF5B6B8AC8E0D105581C89AF2D7F52937F9BB4E3EF49AF4F1A543D516C6E349743339BE47AF3DA3B


41EB154E73913D029A457611C01CF6872EF4E2ADA886B084B68C7DAEB38A5F4B48FA64296CA81E8527009F1073462745CD2F


615259D9DEE24FC29097261D92D86DD057BDF58216A072467993E3E1503503968EDD975DBA7924F6EB08D3AD045EE291DE50


FEA6AAED614E2ED17F71F94D54E8F6CC9E627377E4D5A874D392662E4C7495749C484E320F951234C4D073D1BBE81EF55548


D6A4E60AFC6DA8A1419A3EA7BBECD85C9851DDCF0F9ABE22C5311F9778FF0014FBD55546CAC7EA1774ED1BB159DD62426448


4140403B524F127964E3975D55554D5428C0992CB1AD6D4D3FFFD9"
$ppp=$ppp2
;$ppp=_HexToString($ppp)
$ppp=BinaryToString($ppp)
MsgBox(0,"",$ppp)

BinaryTostring read only untill 00 appears, if we erase all 00's, function will read all the string.

#include <Misc.au3>
#include <string.au3>

$ppp2="0xFFD8FFE0104A4649460101016464FFDB431B0C0E0C0A1E0D0E1211101318281A181616183123251D283A333D3C3933


383740485C4E404457453738506D51575F626768673E4D71797064785C656763FFDB43011112121815182F1A1A2F63423842


6363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363


FFC011082828030122021101031101FFC4190101010101010504030601FFC433110303020208020B01020304051106122131


13415152617192D191B2141522234344537282A2B1FFC41901010301010201030405FFC42411020201030207010203111213


21619104051532415181FFDA0C0301021103113F7AE372E964BACE32DB6ADBB738C91CC9ACC97DBFD147A95EF464B776DDAE


09CF290AA5A3DB336F54B94F7420A77207F99F3AAF2499B742AA827E675C6190E98A90D9E4ACABDEA0E327F011EA57BD6871


493A7582B56D49DB93D8335C66CCB0244670BACE3278E481DB5C4985554F07EF135C19894BCD323825C252139CE0E09E1F0A


A8281312F6A186C23884294547C769E155243A84AEFAB6DB10D9A52752496D67095CAC1F224539ABDF5B6B8AC8E0D105581C


89AF2D7F52937F9BB4E3EF49AF4F1A543D516C6E349743339BE47AF3DA3B41EB154E73913D029A457611C01CF6872EF4E2AD


A886B084B68C7DAEB38A5F4B48FA64296CA81E85279F1073462745CD2F615259D9DEE24FC29097261D92D86DD057BDF58216


A072467993E3E1503503968EDD975DBA7924F6EB08D3AD045EE291DE50FEA6AAED614E2ED17F71F94D54E8F6CC9E627377E4


D5A874D392662E4C7495749C484E320F951234C4D073D1BBE81EF55548D6A4E60AFC6DA8A1419A3EA7BBECD85C9851DDCF0F


9ABE22C5311F9778FF14FBD55546CAC7EA1774ED1BB159DD624264484140403B524F127964E3975D55554D5428C0992CB1AD


6D4D3FFFD9"
$ppp=$ppp2
;$ppp=_HexToString($ppp)
$ppp=BinaryToString($ppp)
MsgBox(0,"",$ppp)

But then it will be diffrent from start code. Can somebody help me with this ? Im fighting with this from two days already :)

I have tried already all flags in BinaryToString and with none resoult, im Using UTF-8 coding in SciTe. please help :)

Edited by Uriziel01
Link to comment
Share on other sites

Zero byte traditionally means end of string and is treated as such by pretty much all generic functions that take string as an input.

And this has nothing to do with BinaryToString at all, which by the way, reads and converts whole binary to string, despite what your assumption is. Which you could see yourself if you only bothered to apply some minor debugging to your code (for example, ConsoleWrite(StringLen($ppp) & @CRLF) after the BinaryToString() call).

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

Ok, thank you for reply, but how can i translate this binary to string again (it was some file source code before reading it like a binary) because when i look in the code and at you answer i dont have any ideas what to do :)

AND ! Why this code is running propertly ? Are my problem connected with TCP sending ?

#include <File.au3>
$file = FileOpen ( "C:\boot.jpg", 16 )
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$size=FileGetSize ("C:\boot.jpg")
MsgBox(0,"",$size)
    $chars = FileRead($file, $size)
MsgBox(0, "Char read:", $chars)
$tresc=$chars
FileClose($file)
_FileCreate( "C:\bootnowy.jpg")
Sleep(50)
$file2 = FileOpen ( "C:\bootnowy.jpg", 16 )
If $file2 = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
FileWrite("C:\bootnowy.jpg", $tresc)
  FileClose($file2)
Edited by Uriziel01
Link to comment
Share on other sites

That data is NOT a string, so why do you insist to treat it as such?

If you want to save it to file, open file in binary write mode (16+2); oh, and you don't need to use BinaryToString() at all.

Edited by Siao

"be smart, drink your wine"

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...