Exemple #1
0
function _BF_ADD32($x, $y)
{
    $x = $x & 0xffffffff;
    $y = $y & 0xffffffff;
    $total = 0;
    $carry = 0;
    for ($i = 0; $i < 4; $i++) {
        $byte_x = _BF_GETBYTE($x, $i);
        $byte_y = _BF_GETBYTE($y, $i);
        $sum = $byte_x + $byte_y;
        $result = $sum & 0xff;
        $carryforward = _BF_SHR32($sum, 8);
        $sum = $result + $carry;
        $result = $sum & 0xff;
        $carry = $carryforward + _BF_SHR32($sum, 8);
        $total = _BF_OR32(_BF_SHL32($result, $i * 8), $total);
    }
    return $total;
}
 private function unpack_ftp_file($ftp_contents)
 {
     $bitmask = array(0, 1, 3, 7, 0xf, 0x1f, 0x3f, 0x7f, 0xff, 0x1ff, 0x3ff, 0x7ff, 0xfff, 0x1fff, 0x3fff, 0x7fff);
     $source_file_len = strlen($ftp_contents) - 4;
     $source_buffer = $ftp_contents;
     $unpacked_len = data_int32(substr($source_buffer, 0, 4));
     $source_buffer = substr($ftp_contents, 4) . chr(0) . chr(0) . chr(0) . chr(0);
     $first_flag = true;
     $output_buffer = '';
     $bitmask_sum = 0;
     $bitmask_pos = 0;
     $bitmask_max = 0;
     $v23 = 0;
     $v22 = 0;
     $input_char_copy1 = 0;
     $input_char_copy0 = 0;
     $unpack_buffer_offset = 0;
     $unpack_buffer = array_fill(0, 32768, 0);
     $byte_shadow_table = array_fill(0, 32768, 0);
     $word_shadow_table = array_fill(0, 32770, 0);
     $unpacked_len2 = $unpacked_len;
     if ($unpacked_len > 0) {
         do {
             if (0 >= $unpack_buffer_offset) {
                 if ($first_flag) {
                     $first_flag = false;
                     $input_char = 0x100;
                 } else {
                     if ($bitmask_sum > $bitmask_max) {
                         break;
                     }
                     $input_char = $bitmask[$bitmask_pos] & _BF_SHR32(data_int32(substr($source_buffer, $bitmask_sum >> 3, 4)), $bitmask_sum & 7);
                     $bitmask_sum = $bitmask_sum + $bitmask_pos;
                 }
                 if ($input_char == 0x100) {
                     $bitmask_pos = 9;
                     $bitmask_max = 8 * $source_file_len - 9;
                     $v23 = 0x100 + 2;
                     $v22 = 2 * 0x100;
                     do {
                         if ($bitmask_sum > $bitmask_max) {
                             break;
                         }
                         $input_char = $bitmask[$bitmask_pos] & _BF_SHR32(data_int32(substr($source_buffer, $bitmask_sum >> 3, 4)), $bitmask_sum & 7);
                         $bitmask_sum = $bitmask_sum + $bitmask_pos;
                     } while ($input_char == 0x100);
                     $input_char_copy1 = $input_char;
                     $input_char_copy0 = $input_char;
                 } else {
                     if ($input_char == 0x101) {
                         break;
                     }
                     $input_char_copy2 = $input_char;
                     if ($input_char >= $v23) {
                         $unpack_buffer[$unpack_buffer_offset++] = $input_char_copy1;
                         $input_char = $input_char_copy0;
                     }
                     while ($input_char >= 0x100) {
                         $unpack_buffer[$unpack_buffer_offset++] = $byte_shadow_table[$input_char];
                         $input_char = $word_shadow_table[$input_char];
                     }
                     $input_char_copy1 = $input_char;
                     if ($v23 <= 32767) {
                         $word_shadow_table[$v23] = $input_char_copy0 & 0xffff;
                         $byte_shadow_table[$v23] = $input_char_copy1 & 0xff;
                         $v23++;
                         if ($v23 >= $v22) {
                             if ($v22 < 32767) {
                                 $v22 = $v22 * 2;
                                 $bitmask_pos++;
                                 $bitmask_max--;
                             }
                         }
                     }
                     $input_char_copy0 = $input_char_copy2;
                 }
             } else {
                 $unpack_buffer_offset--;
                 $input_char = $unpack_buffer[$unpack_buffer_offset];
             }
             $output_buffer .= chr($input_char);
             $unpacked_len2--;
         } while ($unpacked_len2 > 0);
     }
     return $output_buffer;
 }