Jump to content

Uploading files containing 0x00


Recommended Posts

Hey

I have a funktion to upload a file. The PHP script can't work with the file then the "0x00" char is stripped from the file... And when the "0x00" char is included the file won't even be uploaded...

Here is the function:

$boundary = "------"&Chr(Random(Asc("A"), Asc("Z"), 3))&Chr(Random(Asc("a"), Asc("z"), 3))&Chr(Random(Asc("A"), Asc("Z"), 3))&Chr(Random(Asc("a"), Asc("z"), 3))&Random(1, 9, 1)&Random(1, 9, 1)&Random(1, 9, 1)
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("POST", "http://LINK REMOVED", False)
    $oHTTP.SetRequestHeader("User-Agent", "UploadProgram")
    $oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
    $oHTTP.SetRequestHeader("Accept-Encoding", "gzip, deflate")
    $oHTTP.SetRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
    $oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; boundary=" & $boundary)
    $fileopen = FileOpen($torrent,16)
    $fileread=''
    While 1
        $t = FileRead($fileopen, 1)
        If @error Then ExitLoop
        If $t <> 0x00 Then $fileread &= BinaryToString($t)
    WEnd
    FileClose($fileopen)

    $data= "--" & $boundary & @LF & 'Content-Disposition: form-data; name="torrent"; filename="' & $torrent & '"' & @LF & 'Content-Type: application/x-bittorrent' & @LF& @LF & $fileread & @LF & "--" & $boundary & "--"
    Dim $datasize = StringLen($data)
    $oHTTP.SetRequestHeader("Host", "HOST REMOVED")
    $oHTTP.SetRequestHeader("Content-Length", $datasize)
    $oHTTP.SetRequestHeader("Pragma", "no-cache")

    $oHTTP.Send($data); & @CRLF & $data2)
    $oReceived = $oHTTP.ResponseText

When i remove "If $t <> 0x00 Then" from the code, the file won't even be uploaded :P

I hope someone can help... Thanks in advance :mellow:

By the way... The PHP-script is working, just not with this program :party:

Link to comment
Share on other sites

Hey

I have a funktion to upload a file. The PHP script can't work with the file then the "0x00" char is stripped from the file... And when the "0x00" char is included the file won't even be uploaded...

Here is the function:

$boundary = "------"&Chr(Random(Asc("A"), Asc("Z"), 3))&Chr(Random(Asc("a"), Asc("z"), 3))&Chr(Random(Asc("A"), Asc("Z"), 3))&Chr(Random(Asc("a"), Asc("z"), 3))&Random(1, 9, 1)&Random(1, 9, 1)&Random(1, 9, 1)
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("POST", "http://LINK REMOVED", False)
    $oHTTP.SetRequestHeader("User-Agent", "UploadProgram")
    $oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
    $oHTTP.SetRequestHeader("Accept-Encoding", "gzip, deflate")
    $oHTTP.SetRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
    $oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; boundary=" & $boundary)
    $fileopen = FileOpen($torrent,16)
    $fileread=''
    While 1
        $t = FileRead($fileopen, 1)
        If @error Then ExitLoop
        If $t <> 0x00 Then $fileread &= BinaryToString($t)
    WEnd
    FileClose($fileopen)

    $data= "--" & $boundary & @LF & 'Content-Disposition: form-data; name="torrent"; filename="' & $torrent & '"' & @LF & 'Content-Type: application/x-bittorrent' & @LF& @LF & $fileread & @LF & "--" & $boundary & "--"
    Dim $datasize = StringLen($data)
    $oHTTP.SetRequestHeader("Host", "HOST REMOVED")
    $oHTTP.SetRequestHeader("Content-Length", $datasize)
    $oHTTP.SetRequestHeader("Pragma", "no-cache")

    $oHTTP.Send($data); & @CRLF & $data2)
    $oReceived = $oHTTP.ResponseText

When i remove "If $t <> 0x00 Then" from the code, the file won't even be uploaded :P

I hope someone can help... Thanks in advance :mellow:

By the way... The PHP-script is working, just not with this program :party:

I'm not familiar with the Http functions, but you shouldn't convert binary data which contains 0x0 to a string because 0x0 marks the end of a string. You need to send the data as binary data. That's my guess at least.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

For more about nulls embedded in strings, see the last few posts in this thread.

Anyway, Martin is right that you definitely should handle your binary data as ... binary data.

Disclaimer: I'm not used either with Http COM.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

When i convert the file content to Binary, the file isn't uploaded...

Even if i insert: Content-Transfer-Encoding: binary

in the $data line so it looks like this:

$data= "--" & $boundary & @LF & 'Content-Disposition: form-data; name="torrent"; filename="' & $torrent & '"' & @LF & 'Content-Type: application/x-bittorrent' & @LF& 'Content-Transfer-Encoding: binary' & @LF& @LF & $fileread & @LF & "--" & $boundary & "--"

It just won't work :S

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...