如何解决缺少函数的参数

时间:2011-10-20 04:17:20

标签: php function

我的功能有问题。我似乎无法弄清楚它为什么会以某种方式工作而不是另一种方式。

当我在这里找到html源代码http://adcrun.ch/ZJzV并将javascript编码的字符串放入函数中时它很好地解码了字符串。

echo js_unpack('$(34).39(4(){$(\'29.37\').7($(34).7()-$(\'6.41\').7()-($(\'6.44\').7()*2))});$(\'29.37\').39(4(){3 1=-2;3 5=4(){9(1<0){$.26(\'15://25.22/21/24.20.19\',{14:\'46\',13:{16:18,17:23}},4(40){3 28=38(\'(\'+40+\')\');9(28.12&&1!=-2){45(31);3 8=$(\'<6 48="47"><27 36="#">49</27></6><!--43.42-->\');$(\'6.41 33#35\').57().60(\'59\',\'61\').30(8);8.62(4(){$.26(\'15://25.22/21/24.20.19\',{14:\'50\',13:{63:0,16:18,17:23,58:\'\'}},4(5){3 11=38(\'(\'+5+\')\');9(11.12&&1!=-2){52.51.36=11.12.53}});8.30(\'54...\')})}32{1=10}})}32{$(\'33#35\').56(1--)}};5();3 31=55(5,64)});',10,65,explode('|','|a0x1||var|function|rr|div|height|skip_ad|if||jj|message|args|opt|http|lid|oid|4106|php|fly|links|ch|188|ajax|adcrun|post|a|j|iframe|html|si|else|span|document|redirectin|href|fly_frame|eval|ready|r|fly_head|button|end|fly_head_bottom|clearInterval|check_log|continue_button|class|Continue|make_log|location|top|url|Loading|setInterval|text|parent|ref|margin|css|6px|click|aid|1000'));

但是,我这样使用它echo js_unpack($full_code);它失败并给我以下错误。

Warning: Missing argument 2 for js_unpack(),
Warning: Missing argument 3 for js_unpack(),
Warning: Missing argument 4 for js_unpack(),

这是我正在使用的PHP源代码。

//function to extract string between 2 delimiters
function extract_unit($string, $start, $end)
{
    $pos = stripos($string, $start);
    $str = substr($string, $pos);
    $str_two = substr($str, strlen($start));
    $second_pos = stripos($str_two, $end);
    $str_three = substr($str_two, 0, $second_pos);
    $unit = trim($str_three);
    return $unit;
}

//html source
$html = file_get_contents('http://adcrun.ch/ZJzV');
//extract everything beteen these two delimiters
$unit = extract_unit($html, 'return p}(\'', '.split');

//full encoded strning
$string = $unit;  
//the part here ne values ill be inserted
$expression = "',10,65,";  
//inserted value
$insertvalue = "explode('|',";  

//newly formatted encoded string
$full_code =  str_replace($expression,$expression.$insertvalue,$string).')';

//function to decode the previous string
function js_unpack($p,$a,$c,$k)
{
  while ($c--)
    if($k[$c]) $p = preg_replace('/\b'.base_convert($c, 10, $a).'\b/', $k[$c], $p);

  return $p;
}

//return decoded
echo js_unpack($full_code);

1 个答案:

答案 0 :(得分:2)

我没有完成您的所有代码,但前两个示例中存在根本区别。

此行将4个参数传递给js_unpack函数:

echo js_unpack( '$(......);', 10, 65, explode( '|', '|............' ) );

此行将1个参数传递给它:

echo js_unpack( $full_code );

我不知道这是否是你其他问题的根源,但是说“它是第一种方式而不是第二种方式”的比较差。警告正在告诉你你需要知道什么:你缺少参数。

修改
根据你的评论,我认为你不明白真正发生了什么。你说你“复制了字符串并将其放在函数中”。这是不正确的。你真正复制的是1个字符串,2个整数和1个数组。您将这4个参数放在函数中。

如果以这种方式格式化函数,也许会有所帮助:

echo js_unpack( 
    '$(......);',                     //  <-- Argument #1 (a long string)
    10,                               //  <-- Argument #2 (int)
    65,                               //  <-- Argument #3 (int)
    explode( '|', '|............' )   //  <-- Argument #4 (array)
);

将其与:

进行比较
echo js_unpack( 
    $full_code                        //  <-- Just 1 argument
);

这些签名根本就不一样。有些PHP函数有default argument values,但js_unpack不是这种情况,它会给你一个非常明确的警告,说明你没有正确调用它。