Jump to content

Recommended Posts

Posted

Seems way to much cumbersome to me. Wouldn't be easy doing as i asked here?

take a look

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Posted

  On 1/16/2011 at 1:13 AM, 'Newb said:

Seems way to much cumbersome to me. Wouldn't be easy doing as i asked here?

take a look

Well, that's your choice, that depends of what you feel more accustomed to. I replied to you in that other thread.

@trancexx: I think there may be a little bug in the internal function __WinHttpFinalizeCtrls : I wanted to preview a post where I filled the fields subject and message only, and set the preview button to True.

The problem is that the data that was being sent (it's an application/x-www-form-urlencoded form by the way) was this:

  Reveal hidden contents

subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=32104&s=&securitytoken=1295202737-c31b8cb3d41a8b148ce55a3b6d702722aaaaaaaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=EDITED&emailupdate=&polloptions=4&preview=Preview+Post

I debugged the value of $sAddData and in every part of the code the part with taglist was without value as it should (&taglist=) because the source code of the taglist is this:

<input type="text" class="bginput" name="taglist" id="tag_add_input" value="" size="40" tabindex="1" />

but when exiting __WinHttpFinalizeCtrls it changed to &taglist=32104 :x So I debugged the function by adding msgboxes and a consolewrite log. Here is the code:

  Reveal hidden contents

And this is the result of the console log (I highlighted in red and blue where &taglist changed):

  Reveal hidden contents

adddatafinalizectrls at $aRadio and $m = 0 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=&iconid=1&iconid=13&iconid=12&iconid=11&iconid=10&iconid=9&iconid=8&iconid=7&iconid=6&iconid=5&iconid=4&iconid=3&iconid=2&iconid=14&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 1 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=3210&iconid=9&iconid=8&iconid=7&iconid=6&iconid=5&iconid=4&iconid=3&iconid=24&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 2 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=3210&iconid=9&iconid=8&iconid=7&iconid=6&iconid=5&iconid=4&iconid=3&iconid=24&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 3 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=3210&iconid=9&iconid=8&iconid=7&iconid=6&iconid=5&iconid=4&iconid=3&iconid=24&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 4 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=3210&iconid=9&iconid=8&iconid=7&iconid=6&iconid=5&iconid=4&iconid=3&iconid=24&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 5 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=3210&iconid=9&iconid=8&iconid=7&iconid=6&iconid=5&iconid=4&iconid=3&iconid=24&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 6 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=3210&iconid=8&iconid=7&iconid=6&iconid=5&iconid=4&iconid=3&iconid=24&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 7 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=3210&iconid=7&iconid=6&iconid=5&iconid=4&iconid=3&iconid=24&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 8 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=3210&iconid=6&iconid=5&iconid=4&iconid=3&iconid=24&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 9 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=3210&iconid=5&iconid=4&iconid=3&iconid=24&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 10 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=3210&iconid=4&iconid=3&iconid=24&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 11 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=3210&iconid=3&iconid=24&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 12 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=3210&iconid=24&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 13 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=32104&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aRadio and $m = 14 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=32104&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&parseurl=1&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aCheckbox and $m = 0 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=32104&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&disablesmilies=1&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aCheckbox and $m = 1 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=32104&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&emailupdate=&postpoll=yes&polloptions=4&preview=Preview+Post

adddatafinalizectrls at $aCheckbox and $m = 2 :

&subject=Test77&message=Test77+of+previewing+a+post&wysiwyg=1&taglist=32104&s=&securitytoken=1295207273-81b1a22b1588682060384b6fe1ec2fede72faaaa&f=42&do=postthread&posthash=&poststarttime=&loggedinuser=22aaa&emailupdate=&polloptions=4&preview=Preview+Post

As you can see the changes happened when doing the $aRadio controls. That would explain why &taglist= is concatenated with numbers, because the values of radios are numbers

<input type="radio" name="iconid" value="6" id="rb_iconid_6" tabindex="1" onclick="swap_posticon('pi_6')"  />

. There may be some problem with the splits and replacements there...

Here you have the source of the form, and thanks in advance for your help!

  Reveal hidden contents

Posted (edited)

I found it, I found it! :x The problem was that as stringreplace replaces from left to right when it has to replace '&iconid=1' in this string for instance:

taglist=&iconid=0&iconid=1&iconid=13&iconid=12&iconid=11&iconid=10&iconid=9&iconid=8&iconid=7&iconid=6&iconid=5&iconid=4&iconid=3&iconid=2&iconid=14&s=

It will erase '&iconid=1' but also the substring '&iconid=1' of '&iconid=13' thus leaving the 3 hanging there. I think the solution would be to put the delimiter ( $sSep ) after $aRadio and check with @extended to see if you are trying to replace the last elem of the string.

$sAddData = StringReplace($sAddData,$aRadio[$m]&$sSep, "") ; delete
If @extended = 0 Then $sAddData = StringReplace($sAddData, $sSep & $aRadio[$m], ""); delete it in the case it is the last elem of the string

and then check if $sAddData has a '&' at the end. So the code would be this:

Func __WinHttpFinalizeCtrls($sSubmit, $sRadio, $sCheckBox, $sButton, ByRef $sAddData, $sSep = "")
    If $sSubmit Then ; If no submit is specified
        Local $aSubmit = StringSplit($sSubmit, "&", 2)
        For $m = 1 To UBound($aSubmit) - 1 ; skip the first (leave that one as default)
            $sAddData = StringReplace($sAddData, $aSubmit[$m] & $sSep, "") ; delete the rest
            If @extended = 0 Then $sAddData = StringReplace($sAddData, $sSep & $aSubmit[$m], "") ; delete it in the case it is the last elem of the string
        Next
    EndIf
    If $sRadio Then ; If no radio is specified
        Local $aRadio = StringSplit($sRadio, "&", 2)
        For $m = 0 To UBound($aRadio) - 1 ; for all "radio" controls
            $sAddData = StringReplace($sAddData, $aRadio[$m] & $sSep, "") ; delete
            If @extended = 0 Then $sAddData = StringReplace($sAddData, $sSep & $aRadio[$m], ""); delete it in the case it is the last elem of the string
        Next
    EndIf
    If $sCheckBox Then ; If no checkbox is specified
        Local $aCheckBox = StringSplit($sCheckBox, "&", 2)
        For $m = 0 To UBound($aCheckBox) - 1 ; for all left "checkbox" controls in $sCheckBox string (non-set)
            $sAddData = StringReplace($sAddData, $aCheckBox[$m] & $sSep, "") ; delete
            If @extended = 0 Then $sAddData = StringReplace($sAddData, $sSep & $aCheckBox[$m], ""); delete it in the case it is the last elem of the string
        Next
    EndIf
    If $sButton Then ; If no button is specified
        Local $aButton = StringSplit($sButton, "&", 2)
        For $m = 0 To UBound($aButton) - 1 ; for all left "button" controls in $sButton string (non-set)
            $sAddData = StringReplace($sAddData, $aButton[$m] & $sSep, "") ; delete
            If @extended = 0 Then $sAddData = StringReplace($sAddData, $sSep & $aButton[$m], ""); delete it in the case it is the last elem of the string
        Next
    EndIf
    If StringRight($sAddData, 1) = '&' Then StringTrimRight($sAddData, 1);just to be sure there's no '&' hanging at the end of the string
    If StringLeft($sAddData, 1) = '&' Then StringTrimLeft($sAddData, 1);just to be sure there's no '&' hanging at the beginning of the string also
EndFunc   ;==>__WinHttpFinalizeCtrls

And since I'm a little paranoid :P (or that I envision future problems if you prefer :shifty: ) I also checked if there's an '&' hanging at the beginning of the string.

...The other thing I thought would be to use string replace with $sSep before the 'name=value' and a count of 1 but that would function to remove for instance '&iconid=1' from '&iconid=1&iconid=13' but not from '&iconid=13&iconid=1' (it would leave 3&iconid=1 ) and I don't think we can expect radios or whatever to be alphanumerically ordered...

Edited by Mithrandir
Posted (edited)

Now that I think a bit more about it, the problem in general persists whether the delimiter is before or after (for instance if you want to erase '&iconid1' from 'iconid1&iiconid1&' and you use the string 'iconid1&' to search for replace it would leave 'i', it's a symmetric problem to the other one), so stringreplace should be used with both, and since we know at least one replacement should be done, if no replacements ocurred, check whether it's an element of the first or the last element of the string. Here is the code:

Func __WinHttpFinalizeCtrls($sSubmit, $sRadio, $sCheckBox, $sButton, ByRef $sAddData, $sSep = "")
    If $sSubmit Then ; If no submit is specified
        Local $aSubmit = StringSplit($sSubmit, "&", 2)
        For $m = 1 To UBound($aSubmit) - 1 ; skip the first (leave that one as default)
            $sAddData = StringReplace($sAddData, $sSep & $aSubmit[$m] & $sSep, $sSep) ; delete it in the case it's somewhere in the middle of the string
            If @extended = 0 Then
                $sAddData = StringReplace($sAddData, $sSep & $aSubmit[$m], "") ; delete it in the case it is the last elem of the string
                If @extended = 0 Then $sAddData = StringReplace($sAddData, $aSubmit[$m] & $sSep, ""); delete it in the case it is the first elem of the string
            EndIf
        Next
    EndIf
    If $sRadio Then ; If no radio is specified
        Local $aRadio = StringSplit($sRadio, "&", 2)
        For $m = 0 To UBound($aRadio) - 1 ; for all "radio" controls
            $sAddData = StringReplace($sAddData, $sSep & $aRadio[$m] & $sSep, $sSep) ; delete it in the case it's somewhere in the middle of the string
            If @extended = 0 Then
                $sAddData = StringReplace($sAddData, $sSep & $aRadio[$m], ""); delete it in the case it is the last elem of the string
                If @extended = 0 Then $sAddData = StringReplace($sAddData, $aRadio[$m] & $sSep, ""); delete it in the case it is the first elem of the string
            EndIf
        Next
    EndIf
    If $sCheckBox Then ; If no checkbox is specified
        Local $aCheckBox = StringSplit($sCheckBox, "&", 2)
        For $m = 0 To UBound($aCheckBox) - 1 ; for all left "checkbox" controls in $sCheckBox string (non-set)
            $sAddData = StringReplace($sAddData, $sSep & $aCheckBox[$m] & $sSep, $sSep) ; delete it in the case it's somewhere in the middle of the string
            If @extended = 0 Then
                $sAddData = StringReplace($sAddData, $sSep & $aCheckBox[$m], ""); delete it in the case it is the last elem of the string
                If @extended = 0 Then $sAddData = StringReplace($sAddData, $aCheckBox[$m] & $sSep, ""); delete it in the case it is the first elem of the string
            EndIf
        Next
    EndIf
    If $sButton Then ; If no button is specified
        Local $aButton = StringSplit($sButton, "&", 2)
        For $m = 0 To UBound($aButton) - 1 ; for all left "button" controls in $sButton string (non-set)
            $sAddData = StringReplace($sAddData, $sSep & $aButton[$m] & $sSep, $sSep) ; delete it in the case it's somewhere in the middle of the string
            If @extended = 0 Then
                $sAddData = StringReplace($sAddData, $sSep & $aButton[$m], ""); delete it in the case it is the last elem of the string
                If @extended = 0 Then $sAddData = StringReplace($sAddData, $aButton[$m] & $sSep, ""); delete it in the case it is the first elem of the string
            EndIf
        Next
    EndIf
    If StringRight($sAddData, 1) = '&' Then StringTrimRight($sAddData, 1);just to be sure there's no '&' hanging at the end of the string
    If StringLeft($sAddData, 1) = '&' Then StringTrimLeft($sAddData, 1);just to be sure there's no '&' hanging at the beginning of the string also
EndFunc   ;==>__WinHttpFinalizeCtrls

PS: I have been looking at the __WinHttpFinalizeCtrls of multipart form data and I think it doesn't screw that part :P In other case :x , well you can always have one function for each kind of form.

Edited by Mithrandir
Posted (edited)

Another problem, this time with this part of the code (but will happen the same in the stringreplace of .getelementbyid part):

$sAddData = StringRegExpReplace($sAddData, "(?i)\Q" & $aSplit[1] & "\E=.*?(&|\Z)", $aSplit[1] & "=" & $sPassedData & "$1")
$iNumRepl = @extended                       
If $iNumRepl > 1 Then ; remove duplicates
    $sAddData = StringRegExpReplace($sAddData, "(?i)\Q" & $aSplit[1] & "\E=.*?(&|\Z)", "", $iNumRepl - 1)
EndIf

Because I want to set a field whose name is 'passwr' but there's another one which is hidden whose name is 'hash_passwrd' and the regexp (as well as i think it will occur with stringreplace) is matching both fields as 'passwr' because 'passwr' is a substring of 'hash_passwr' and moreover since it's the last set it removes 'passwr' :shifty: I think the solution would be like the one of the post before, to use the '&' as delimiters, in this case I think it is enough to add one before $aSplit, I will make some tests but I don't completely understand the regexp you used there, I would like to know:

1)You used \Q in order to use the '&' in &$aSplit[1]& ? I think there '&' is used as the operator concatenation and not as part of the string. If not, what did you use \Q for?

2)When you use (&|\Z) are you telling the regexp to match a '&' before the end of the "pattern" string? I thought it was for matching before the end of the "test" string (StringRegExp ( "test", "pattern" [, flag ] [, offset ] ] ))

What's the use of the '|' in (&|\Z) ? I guess it matches '&' or 'nothing' before the end of the string but I don't understand

3)$1 is the value of what was captured in (&|\Z) (the backreference) ? ie if it matched a '&' it will concatenate a '&' ?

Thanks for your help!

PS: I tried a regexp with \A to match the first letter of 'passwrd' at the beginning of the "pattern" match so as to avoid matching 'passwr' as a substring of 'hash_passwr' and then I matched the rest of the string ('asswr') Here is the code:

Local $FirstChar = StringMid($aSplit[1],1,1)
Local $RestofString = StringMid($aSplit[1],2)
                        
$sAddData = StringRegExpReplace($sAddData, "(?i)\A"&$FirstChar&"\Q" & $RestofString & "\E=.*?(&|\Z)", $aSplit[1] & "=" & $sPassedData & "$1")
FileWriteLine(@ScriptDir&'/log2.txt',$sAddData)
$iNumRepl = @extended                       
If $iNumRepl > 1 Then ; remove duplicates
    $sAddData = StringRegExpReplace($sAddData, "(?i)\A"&$FirstChar&"\Q" & $RestofString & "\E=.*?(&|\Z)", "", $iNumRepl - 1)
EndIf

But this is what's being sent with that code: user=myusername&passwrd=True&cookielength=True&cookieneverexp=&hash_passwrd=TrueTrue

:nuke::x:P I don't understand why there are booleans in the string...Also with the original code cookielength was being sent as True...I'm pretty lost and I appreciate any help!

PS2: My bad, I was passing a submitbutton as Default and that caused all the mess with the booleans apparently. However, the problem with 'passwr' and 'hash_passwr' persists: It stills sends the later instead of 'passwr'

Edited by Mithrandir
Posted

Well, it's not like I know everything :x

But I know about the code I used...

1. \Q makes pair with \E because $aSplit[1] could have characters that need escaping.

2. (&|\Z) means match either & or the end of the string.

3. Yes

Thanks for the reports. I know what to do.

♡♡♡

.

eMyvnE

Posted (edited)

  On 1/17/2011 at 1:55 PM, 'trancexx said:

Well, it's not like I know everything :P

But I know about the code I used...

1. \Q makes pair with \E because $aSplit[1] could have characters that need escaping.

2. (&|\Z) means match either & or the end of the string.

3. Yes

Thanks for the reports. I know what to do.

:x You know almost everything. Concerning the problem of substrings being matched I now think that instead of using regexp you could use _StringExplode to store the fields in an array and then do the substitutions there and with _ArrayUnique remove the duplicates. I don't know if dealing with arrays instead of using regexp will add too much execution time though. Edited by Mithrandir
Posted

  On 1/17/2011 at 3:58 PM, 'Mithrandir said:

:x You know almost everything. Concerning the problem of substrings being matched I now think that instead of using regexp you could use _StringExplode to store the fields in an array and then do the substitutions there and with _ArrayUnique remove the duplicates. I don't know if dealing with arrays instead of using regexp will add too much execution time though.

Surely would. I've made some changes. Could you try it now, I've run only the most basic tests.

♡♡♡

.

eMyvnE

Posted (edited)

  On 1/17/2011 at 10:57 PM, 'trancexx said:

84 actually.

edit:

like that movie

'Big Brother is watching you' :x I read the book and watch the film :P

On topic: There's an error with the regexp in the Else of ; like .getElementsByName, it is removing an '&', here you have the code part with the consolewrite I used to debug:

ConsoleWrite('$aSplit[1] = '&$aSplit[1]&@CRLF&@CRLF&'adddata in .getelembyname loop before regexp replace: '&@CRLF&@CRLF&$sAddData&@CRLF&@CRLF)
$sAddData = StringRegExpReplace($sAddData, "(?i)\Q" & $aSplit[1] & "\E=.*?(&|\Z)", $aSplit[1] & "=" & $sPassedData & "$1")
$iNumRepl = @extended
If $iNumRepl > 1 Then ; remove duplicates
   $sAddData = StringRegExpReplace($sAddData, "(?i)(&|\A)\Q" & $aSplit[1] & "\E=.*?(&|\Z)", "", $iNumRepl - 1)
EndIf
ConsoleWrite('adddata in .getelembyname loop after regexp replace: '&@CRLF&@CRLF,$sAddData&@CRLF&@CRLF& _
                        '--------------------------------------------------------------------------------------------------------------------------------------------------------------'&@CRLF&@CRLF)

Here is the log of the errors, I highlighted in red where the '&' is removed:

  Reveal hidden contents

$aSplit[1] = vb_login_username

adddata in .getelembyname loop before regexp replace:

s=bb3794fca900bcf9fc507beb1e10674bAAA&do=login&vb_login_password=&vb_login_md5password=&vb_login_md5password_utf=&vb_login_username=&cookieuser=1&vb_login_password=

adddata in .getelembyname loop after regexp replace:

s=bb3794fca900bcf9fc507beb1e10674bAAA&do=login&vb_login_password=&vb_login_md5password=&vb_login_md5password_utf=&vb_login_username=MYUSERNAME&cookieuser=1&vb_login_password=

--------------------------------------------------------------------------------------------------------------------------------------------------------

$aSplit[1] = vb_login_password

adddata in .getelembyname loop before regexp replace:

s=bb3794fca900bcf9fc507beb1e10674bAAA&do=login&vb_login_password=&vb_login_md5password=&vb_login_md5password_utf=&vb_login_username=MYUSERNAME&cookieuser=1&vb_login_password=

adddata in .getelembyname loop after regexp replace:

s=bb3794fca900bcf9fc507beb1e10674bAAA&do=loginvb_login_md5password=&vb_login_md5password_utf=&vb_login_username=MYUSERNAME&cookieuser=1&vb_login_password=MYPASSWORD

--------------------------------------------------------------------------------------------------------------------------------------------------------

$aSplit[1] = vb_login_md5password

adddata in .getelembyname loop before regexp replace:

s=bb3794fca900bcf9fc507beb1e10674bAAA&do=loginvb_login_md5password=&vb_login_md5password_utf=&vb_login_username=MYUSERNAME&cookieuser=1&vb_login_password=MYPASSWORD

adddata in .getelembyname loop after regexp replace:

s=bb3794fca900bcf9fc507beb1e10674bAAA&do=loginvb_login_md5password=e50a187a5967361541265aefccaaaaaaaAA&vb_login_md5password_utf=&vb_login_username=MYUSERNAME&cookieuser=1&vb_login_password=MYPASSWORD

--------------------------------------------------------------------------------------------------------------------------------------------------------

I saw you introduced $sGrSep = Chr(29) as separator but you didn't use it in this part of the code, maybe using it may help? As I said previously, I'd rather go with string split and don't complicate myself with regexp. I may code it and make a test comparing the two alternatives (regexp or stringsplit/_stringexplode) using TimerDiff or _Timer_Diff to research if the difference of time is considerable. The problem is that in other tests they showed contradictory results so I asked which is more precise.

Edited by Mithrandir
Posted

Objective speed tests in AutoIt are very hard to do. It's very important to create the same "environmental" conditions for every tested sequence of code. It's kinda hard to explain without examples so I won't :x You'll figure it out your self.

All in all there shouldn't be doubt that lesser code is faster, particularly in this case.

I think I got that "&" correct now.

♡♡♡

.

eMyvnE

Posted (edited)

  On 1/18/2011 at 6:55 AM, 'trancexx said:

Objective speed tests in AutoIt are very hard to do. It's very important to create the same "environmental" conditions for every tested sequence of code. It's kinda hard to explain without examples so I won't :x You'll figure it out your self.

All in all there shouldn't be doubt that lesser code is faster, particularly in this case.

I think I got that "&" correct now.

Yeah I agree but If it isn't considerable the difference I wouldn't complicate myself :P . I'm going to test rev 85 but I see that you didn't change this part of the Else ; like .getElementsByName from the Case "", "application/x-www-form-urlencoded" :

$sAddData = StringRegExpReplace($sAddData, "(?i)\Q" & $aSplit[1] & "\E=.*?(&|\Z)", $aSplit[1] & "=" & $sPassedData & "$1")

If you have one field whose name is 'myname' and I set its value to 'Mithrandir' and another whose name is 'name' and I set its value to 'trancexx' and $sAddData = 'name=&myname=' then wouldn't that regexp replace 'name' with 'name=trancexx' AND 'myname' with 'myname=trancexx' (which is wrong)?

so $sAddData would end up 'name=trancexx&myname=trancexx' and after replacing the duplicates from left to right it would end up 'name=trancexx&' (which after __WinHttpTrimBounds($sAddData, "&") would end up as name=trancexx so your code would not sent 'myname' field with its data but that's not what I expect it to do.

By the way, I experimented that problem (the 'passwr' and 'hash_passwr' problem)

I think the problem of regular expressions matching fields names and substrings of field names can't be avoided. I think a way would be to make some 'cheat' changing this part:

If $aInputIds[1][$i] Then ; if there is 'name' field then add it
                        $sAddData &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & "&"
                        If $aInputIds[3][$i] = "submit" Then $sSubmit &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "submit" string
                        If $aInputIds[3][$i] = "radio" Then $sRadio &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "radio" string
                        If $aInputIds[3][$i] = "checkbox" Then $sCheckBox &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "checkbox" string
                        If $aInputIds[3][$i] = "button" Then $sButton &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "button" string
                    EndIf

by:

If $aInputIds[1][$i] Then ; if there is 'name' field then add it
                        $sAddData &= $sGrSep&$aInputIds[1][$i]&$sGrSep & "=" & $aInputIds[2][$i] & "&"
                        If $aInputIds[3][$i] = "submit" Then $sSubmit &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "submit" string
                        If $aInputIds[3][$i] = "radio" Then $sRadio &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "radio" string
                        If $aInputIds[3][$i] = "checkbox" Then $sCheckBox &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "checkbox" string
                        If $aInputIds[3][$i] = "button" Then $sButton &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "button" string
                    EndIf

and then this:

$sAddData = StringRegExpReplace($sAddData, "(?i)\Q" & $aSplit[1] & "\E=.*?(&|\Z)", $aSplit[1] & "=" & $sPassedData & "$1")
                        $iNumRepl = @extended
                        If $iNumRepl > 1 Then ; remove duplicates
                            $sAddData = StringRegExpReplace($sAddData, "(?i)(?:&|\A)\Q" & $aSplit[1] & "\E=.*?(?:&|\Z)", "&", $iNumRepl - 1)
                        EndIf
                        __WinHttpTrimBounds($sAddData, "&")

by this:

$sAddData = StringRegExpReplace($sAddData, "(?i)\Q" $sGrSep& $aSplit[1]& $sGrSep & "\E=.*?(&|\Z)", $sGrSep& $aSplit[1] & $sGrSep "=" & $sPassedData & "$1")
                        $iNumRepl = @extended
                        If $iNumRepl > 1 Then ; remove duplicates
                            $sAddData = StringRegExpReplace($sAddData, "(?i)(?:&|\A)\Q" $sGrSep& $aSplit[1] & $sGrSep& "\E=.*?(?:&|\Z)", "&", $iNumRepl - 1)
                        EndIf
                        __WinHttpTrimBounds($sAddData, "&")

and before __WinHttpFinalizeCtrls at this part:

__WinHttpFinalizeCtrls($sSubmit, $sRadio, $sCheckBox, $sButton, $sAddData, $sGrSep, "&")
                If $sMethod = "GET" Then
                    $sAction &= "?" & $sAddData
                    $sAddData = "" ; not to send as addition to the request (this is GET)
                EndIf
                ExitLoop

remove the $sGrSep from it. The same would be needed for the multipart form as well as with getelementsbyid part of both. What do you think?

Edit: Now I see you used $sGrSep for other things, so use it other ascii char that is less than 30.

Edited by Mithrandir
Posted (edited)

  On 1/18/2011 at 11:55 PM, 'trancexx said:

So, what are we gonna do when that function becomes perfect?

I felt a great disturbance in the force when submitted rev86.

...no, I'm lying.

Hehe, 'may the force be with you' (even though it would be strange to see Gandalf with a lightsaber). Well, if this function becomes 'perfect' we can search for other problems to solve :x What I did was to use a new variable $sBlSep = Chr(30) to 'surround' input ids and names so that there's no way a substring is matched (ie chr(30)namechr(30) is not a substring of chr(30)mynamechr(30) ) and then I -here I have to correct what I posted before- removed the $sBlSep from $sAddData after __WinHttpFinalizeCtrls.

I finished all my tests, and everything is ok.

Edited by Mithrandir
Posted

New version of this UDF is available for those who would be interested. All the adjustments from the above for _WinHttpSimpleFormFill are included. That function is much better now. Special thanks to Mithrandir. His help is very much appreciated.

_WinHttpSimpleFormFill can also take form as variable with this version. In that case you should provide session handle as second parameter. Form variable goes in byref. On successful return it will be changed to connection handle of the created connection. "Action" for this type of forms must be full (not relative) address.

♡♡♡

.

eMyvnE

  • 4 weeks later...
Posted

How to Use SetOption to set a Proxy?

by using this code,I receive ERROR_INVALID_PARAMETER, what's wrong with it?

#include <winhttp.au3>

$MyOpen=_WinHttpOpen()

    $tWINHTTP_PROXY_INFO = DllStructCreate("DWORD dwAccessType[2];wchar lpszProxy[18];wchar lpszProxyBypass[7]")
    DllStructSetData($tWINHTTP_PROXY_INFO,1,$WINHTTP_ACCESS_TYPE_NAMED_PROXY)
    DllStructSetData($tWINHTTP_PROXY_INFO,2,"119.40.187.49:8080")
    DllStructSetData($tWINHTTP_PROXY_INFO,3,"<local>")
    $pWINHTTP_PROXY_INFO=DllStructGetPtr($tWINHTTP_PROXY_INFO)
    If @error Then MsgBox(0,"1",@error)
    
    _WinHttpSetOption($MyOpen,$WINHTTP_OPTION_PROXY,$pWINHTTP_PROXY_INFO,DllStructGetSize($tWINHTTP_PROXY_INFO))
    If @error Then MsgBox(0,@error,_GetLastError_Winhttp())

_WinHttpCloseHandle($MyOpen) 

Func _GetLastError_Winhttp()
    Local $lastError = DllCall ( "kernel32.dll", "dword", "GetLastError" )
    Return $lastError[0]
EndFunc
Posted

The DLLStruct is incorrect. This is a working version:

#include<WinHTTP.au3>
Global Const $tagWINHTTP_PROXY_INFO = "DWORD  dwAccessType;ptr lpszProxy;ptr lpszProxyBypass;"

Func _WinHttpProxyInfoCreate($dwAccessType, $sProxy, $sProxyBypass)
    Local $tWINHTTP_PROXY_INFO[2] = [DllStructCreate($tagWINHTTP_PROXY_INFO), DllStructCreate('wchar proxychars[' & StringLen($sProxy)+1 & ']; wchar proxybypasschars[' & StringLen($sProxyBypass)+1 & ']')]
    DllStructSetData($tWINHTTP_PROXY_INFO[0], "dwAccessType", $dwAccessType)
    If StringLen($sProxy) Then DllStructSetData($tWINHTTP_PROXY_INFO[0], "lpszProxy", DllStructGetPtr($tWINHTTP_PROXY_INFO[1], 'proxychars'))
    If StringLen($sProxyByPass) Then DllStructSetData($tWINHTTP_PROXY_INFO[0], "lpszProxyBypass", DllStructGetPtr($tWINHTTP_PROXY_INFO[1], 'proxybypasschars'))
    DllStructSetData($tWINHTTP_PROXY_INFO[1], "proxychars", $sProxy)
    DllStructSetData($tWINHTTP_PROXY_INFO[1], "proxybypasschars", $sProxyBypass)
    Return $tWINHTTP_PROXY_INFO
EndFunc

$hInternet = _WinHttpOpen()

$hConnect = _WinHttpConnect($hInternet, "api.hostip.info")
$standard = _WinHttpSimpleRequest($hConnect, "GET", "/get_html.php")
_WinHttpCloseHandle($hConnect)


$tProxyInfo = _WinHttpProxyInfoCreate($WINHTTP_ACCESS_TYPE_NAMED_PROXY, "122.146.153.125:80", "localhost")
_WinHttpSetOption($hInternet, $WINHTTP_OPTION_PROXY, $tProxyInfo[0])

$hConnect = _WinHttpConnect($hInternet, "api.hostip.info")
$mit_proxy = _WinHttpSimpleRequest($hConnect, "GET", "/get_html.php")
_WinHttpCloseHandle($hConnect)

MsgBox(0, 'Proxyinfo', "Before setting proxy" & @CRLF & $standard & @CRLF & @CRLF & "After setting proxy: " & @CRLF & $mit_proxy)

_WinHttpCloseHandle($hInternet)

*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

Posted

It works very well, Thank you!~~~

  On 2/18/2011 at 11:24 AM, 'ProgAndy said:

The DLLStruct is incorrect. This is a working version:

#include<WinHTTP.au3>
Global Const $tagWINHTTP_PROXY_INFO = "DWORD  dwAccessType;ptr lpszProxy;ptr lpszProxyBypass;"

Func _WinHttpProxyInfoCreate($dwAccessType, $sProxy, $sProxyBypass)
    Local $tWINHTTP_PROXY_INFO[2] = [DllStructCreate($tagWINHTTP_PROXY_INFO), DllStructCreate('wchar proxychars[' & StringLen($sProxy)+1 & ']; wchar proxybypasschars[' & StringLen($sProxyBypass)+1 & ']')]
    DllStructSetData($tWINHTTP_PROXY_INFO[0], "dwAccessType", $dwAccessType)
    If StringLen($sProxy) Then DllStructSetData($tWINHTTP_PROXY_INFO[0], "lpszProxy", DllStructGetPtr($tWINHTTP_PROXY_INFO[1], 'proxychars'))
    If StringLen($sProxyByPass) Then DllStructSetData($tWINHTTP_PROXY_INFO[0], "lpszProxyBypass", DllStructGetPtr($tWINHTTP_PROXY_INFO[1], 'proxybypasschars'))
    DllStructSetData($tWINHTTP_PROXY_INFO[1], "proxychars", $sProxy)
    DllStructSetData($tWINHTTP_PROXY_INFO[1], "proxybypasschars", $sProxyBypass)
    Return $tWINHTTP_PROXY_INFO
EndFunc

$hInternet = _WinHttpOpen()

$hConnect = _WinHttpConnect($hInternet, "api.hostip.info")
$standard = _WinHttpSimpleRequest($hConnect, "GET", "/get_html.php")
_WinHttpCloseHandle($hConnect)


$tProxyInfo = _WinHttpProxyInfoCreate($WINHTTP_ACCESS_TYPE_NAMED_PROXY, "122.146.153.125:80", "localhost")
_WinHttpSetOption($hInternet, $WINHTTP_OPTION_PROXY, $tProxyInfo[0])

$hConnect = _WinHttpConnect($hInternet, "api.hostip.info")
$mit_proxy = _WinHttpSimpleRequest($hConnect, "GET", "/get_html.php")
_WinHttpCloseHandle($hConnect)

MsgBox(0, 'Proxyinfo', "Before setting proxy" & @CRLF & $standard & @CRLF & @CRLF & "After setting proxy: " & @CRLF & $mit_proxy)

_WinHttpCloseHandle($hInternet)

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
  • Recently Browsing   0 members

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