Bug 8271 - pyobfuscate does not handle comprehensions correctly
Summary: pyobfuscate does not handle comprehensions correctly
Status: NEW
Alias: None
Product: ThinLinc
Classification: Unclassified
Component: Build system (show other bugs)
Version: trunk
Hardware: PC Unknown
: P2 Normal
Target Milestone: LowPrio
Assignee: Bugzilla mail exporter
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-12-13 10:47 CET by Alexander Zeijlon
Modified: 2023-12-19 13:15 CET (History)
0 users

See Also:
Acceptance Criteria:


Attachments
Non-obfuscated code for the example. (505 bytes, text/x-python)
2023-12-13 10:47 CET, Alexander Zeijlon
Details

Description Alexander Zeijlon cendio 2023-12-13 10:47:10 CET
Created attachment 1174 [details]
Non-obfuscated code for the example.

It does not work, specifically, if the comprehension statement is put in a function (outside functions it works just fine).

Example:
> input_lst = ['This', 'sentence', 'is', 'false']
> 
> def capitalize_str(string):
>     return string.capitalize()
> 
> def do_stuff(lst):
>     _lst = [capitalize_str(elem) for elem in lst]
>     _set = {capitalize_str(elem) for elem in lst}
>     _dict = {elem: capitalize_str(elem) for elem in lst}
>     return _lst, _set, _dict
> 
> res = do_stuff(input_lst)
> 
> _lst = [capitalize_str(elem) for elem in input_lst]
> _set = {capitalize_str(elem) for elem in input_lst}
> _dict = {elem: capitalize_str(elem) for elem in input_lst}

Is obfuscated to:
> iIiii1i111i1I = [ 'This' , 'sentence' , 'is' , 'false' ]
> if 5 - 5: i11i1
> def II1Ii ( string ) :
>  return string . capitalize ( )
>  if 98 - 98: OooOoo * oO0Oo0O
> def I1I ( lst ) :
>  ooo0oOoooOOO0 = [ capitalize_str ( elem ) for elem in lst ]
>  oOo0O00 = { capitalize_str ( elem ) for elem in lst }
>  i1iiIII111 = { elem : capitalize_str ( elem ) for elem in lst }
>  return ooo0oOoooOOO0 , oOo0O00 , i1iiIII111
>  if 29 - 29: iI + o00Oo - OOoOoo000O00 * Oo0Oo - ii1I1iII1I1I . i1I1IiIIiIi1
> oo0O000ooO = I1I ( iIiii1i111i1I )
> if 98 - 98: IiiIIiii1 % iIi1ii1I1iI11
> ooo0oOoooOOO0 = [ II1Ii ( elem ) for elem in iIiii1i111i1I ]
> oOo0O00 = { II1Ii ( elem ) for elem in iIiii1i111i1I }
> i1iiIII111 = { elem : II1Ii ( elem ) for elem in iIiii1i111i1I }
> # dd678faae9ac167bc83abf78e5cb2f3f0688d3a3


Where you can see that the function capitalize_str() has not been replaced in comprehensions in side the function.
Comment 1 Pierre Ossman cendio 2023-12-19 13:15:48 CET
Also note that the name of the iterator variable ("elem") should also be obfuscated.

Note You need to log in before you can comment on or make changes to this bug.