Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Here is how you figure out how to de-obfuscate this subroutine.</h3> <p><em>Sorry for the length</em></p> <p>First let's tidy up the code, and add useful comments.</p> <pre><code>sub foo { [ ( # ($#{$_[1]}) $#{ $_[ ! ( $| | $| ) # $OUTPUT_AUTOFLUSH === $| # $| is usually 0 # ! ( $| | $| ) # ! ( 0 | 0 ) # ! ( 0 ) # 1 ] } * # @{$_[1]} @{ $_[ !!$_ ^ !$_ # !! 1 ^ ! 1 # ! 0 ^ 0 # 1 ^ 0 # 1 # !! 0 ^ ! 0 # ! 1 ^ 1 # 0 ^ 1 # 1 ] } ) ? # @{$_[1]} @{ $_[ !$. . !!$. # $INPUT_LINE_NUMBER === $. # $. starts at 1 # !$. . !!$. # ! 1 . !! 1 # 0 . ! 0 # 0 . 1 # 01 ] } [ # $_[0] $_[ # @LAST_MATCH_START - @LAST_MATCH_END # 0 @- - @+ ] % # @{$_[1]} @{ $_[ $= =~ /(?=)/ / !$` #( fix highlighting )`/ # $= is usually 60 # /(?=)/ will match, returns 1 # $` will be '' # 1 / ! '' # 1 / ! 0 # 1 / 1 # 1 ] } .. # $#{$_[1]} $#{ $_[ $? ? !!$? : !$? # $CHILD_ERROR === $? # $? ? !!$? : !$? # 0 ? !! 0 : ! 0 # 0 ? 0 : 1 # 1 # 1 ? !! 1 : ! 1 # 1 ? 1 : 0 # 1 ] } , # ( 0 ) ( $) ? !$) : !!$) # $EFFECTIVE_GROUP_ID === $) # $) ? !$) : !!$) # 0 ? ! 0 : !! 0 # 0 ? 1 : 0 # 0 # 1 ? ! 1 : !! 1 # 1 ? 0 : 1 # 0 ) .. # $_[0] $_[ $- - $- # 0 # $LAST_PAREN_MATCH = $- # 1 - 1 == 0 # 5 - 5 == 0 ] % # @{$_[1]} @{ $_[ $] / $] # $] === The version + patchlevel / 1000 of the Perl interpreter. # 1 / 1 == 1 # 5 / 5 == 1 ] } - # ( 1 ) ( !!$+ + !$+ # !! 1 + ! 1 # ! 0 + 0 # 1 + 0 # 1 ) ] : # @{$_[1]} @{ $_[ !!$^^ ^ !$^^ # !! 1 ^ ! 1 # ! 0 ^ 0 # 1 ^ 0 # 1 # !! 0 ^ ! 0 # ! 1 ^ 1 # 0 ^ 1 # 1 ] } ] } </code></pre> <p>Now let's remove some of the obfuscation.</p> <pre><code>sub foo{ [ ( $#{$_[1]} * @{$_[1]} ) ? @{$_[1]}[ ( $_[0] % @{$_[1]} ) .. $#{$_[1]} , 0 .. ( $_[0] % @{$_[1]} - 1 ) ] : @{$_[1]} ] } </code></pre> <p>Now that we have some idea of what is going on, let's name the variables.</p> <pre><code>sub foo{ my( $item_0, $arr_1 ) = @_; my $len_1 = @$arr_1; [ # This essentially just checks that the length of $arr_1 is greater than 1 ( ( $len_1 -1 ) * $len_1 ) # ( ( $len_1 -1 ) * $len_1 ) # ( ( 5 -1 ) * 5 ) # 4 * 5 # 20 # 20 ? 1 : 0 == 1 # ( ( $len_1 -1 ) * $len_1 ) # ( ( 2 -1 ) * 2 ) # 1 * 2 # 2 # 2 ? 1 : 0 == 1 # ( ( $len_1 -1 ) * $len_1 ) # ( ( 1 -1 ) * 1 ) # 0 * 1 # 0 # 0 ? 1 : 0 == 0 # ( ( $len_1 -1 ) * $len_1 ) # ( ( 0 -1 ) * 0 ) # -1 * 0 # 0 # 0 ? 1 : 0 == 0 ? @{$arr_1}[ ( $item_0 % $len_1 ) .. ( $len_1 -1 ), 0 .. ( $item_0 % $len_1 - 1 ) ] : # If we get here, @$arr_1 is either empty or has only one element @$arr_1 ] } </code></pre> <p>Let's refactor the code to make it a little bit more readable.</p> <pre><code>sub foo{ my( $item_0, $arr_1 ) = @_; my $len_1 = @$arr_1; if( $len_1 &gt; 1 ){ return [ @{$arr_1}[ ( $item_0 % $len_1 ) .. ( $len_1 -1 ), 0 .. ( $item_0 % $len_1 - 1 ) ] ]; }elsif( $len_1 ){ return [ @$arr_1 ]; }else{ return []; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload