How does this obfuscated Perl code work?

How does this code work in general?

#!/usr/bin/perl $i=4;$|=@f=map{("!"x$i++)."K$_^\x{0e}"} "BQI!\\","BQI\\","BQI","BQ","B","";push @f,reverse@f[1..5];@f=map{join"",undef, map{chr(ord()-1)}split""}@f;{;$f=shift@ f;print$f;push@f,$f;select undef,undef, undef,.25;redo;last;exit;print or die;} 
+7
perl obfuscation
source share
3 answers

Let's put it first through perltidy

 $i = 5; $| = @f = map { ("!" x $i++) . "9$_*\x{0e}" } ">>>E!)", ">>>E)", ">>>E", ">>>", ">>", ">", ""; push @f, reverse @f[ 1..5 ]; @f = map { join "", map { chr(ord() - 1) } split // } @f; { $f = shift @f; print $f; push @f, $f; select undef, undef, undef, .25; redo; last; exit; print or die; } 

The first line is obvious.

The second line makes a list of ">>>E!)", ">>>E)", ">>>E", ">>>", ">>", ">", "" and places them equally long and adds an asterisk and "Shift Out" (character after carriage return).

The third line adds items from 5 to 1 (in this order) to this list, so there will be ">>>E!)", ">>>E)", ">>>E", ">>>", ">>", ">", "", ">", ">>", ">>>", ">>>E" .

The map reduces all characters by one, thus creating elements such as 8===D () .

The second loop simply prints the items in the list in a loop every 0.25 seconds. Carriage return forces them to overwrite each other to see the animation. The last couple of lines are never reached and therefore fictitious.

+16
source share

The data from the file is loaded into a program called the Perl interpreter. The interpreter analyzes the code and converts it into a series of "operation codes" - the bytecode language, which is halfway between the Perl code and the machine language in which the code runs. If there were no errors (called "compilation") during the conversion, the code is executed by another part of the Perl interpreter. At run time, a program can change various machine states, such as allocating, freeing, reading and writing to memory, or using I / O and other system functions.

(CW are more hardcore hackers than I can fix any errors or misconceptions and add more information)

+14
source share

There is no magic, just obfuscation. Take a high level view. The first thing to notice is that in the future, each character in the lines is interpreted as if it were the previous character:

 [1] map{chr(ord()-1)} ... 

Thus, a string like “6qD” will result in “5rC” (characters before “6”, “q” and “D” respectively). Of primary interest is the array of strings at the beginning:

 [2] ">>>E!)",">>>E)",">>>E",">>>",">>",">","" 

This defines the sequence of the “mask”, which we will replace later, with this line:

 [3] "9$_*\x{0e}" 

They will be inserted at the point $_ . The string \x{0e} represents the hexadecimal control character; that \x{0d} , the character before it, is a carriage return. This will be replaced by [3] when we do [1].

Before assembly [3] is assembled, we will add a number ! equal to i to each element in [2]. Each subsequent element gets one more ! than the item in front of it. Please note that the character whose value is immediately before ! is space .

The rest of the script iterates over each of the collected elements of the array, which now look more like this:

 [4] "!!!!!9>>>E!)\x{0e}", ---> " 8===D (" "!!!!!!9>>>E)\x{0e}", ---> " 8===D(" "!!!!!!!9>>>E\x{0e}", ---> " 8===D" "!!!!!!!!9>>>\x{0e}", ---> " 8===" "!!!!!!!!!9>>\x{0e}", ---> " 8==" "!!!!!!!!!!9>\x{0e}", ---> " 8=" "!!!!!!!!!!!9\x{0e}", ---> " 8" 

The reverse operation then adds the same elements in reverse order, creating a loop.

At this point, you can see the template that creates the animation. Now it's just a matter of going through each step in the animation and vice versa, which is executed by the rest of the script. The time delay of each step is determined by the select statement:

 [5] select undef, undef, undef, 0.25 

which tells us to wait 250 milliseconds between each iteration. You can change this if you want it to accelerate or decelerate.

+8
source share

All Articles