SlideShare a Scribd company logo
1 of 19
Download to read offline
binary
packaging
and distribution of your client apps
Multiplatform
WHO AM I?
AGENDA
Motivation
Process
Security
Efficiency
wHO AM I?
Julia S.Simon!
Software Engineer (in Test)!
@hithwen!
juliassimon

! ! Love:!
! ! ! - skiing - diving!
! ! ! - LARPS!
! ! ! - making ice cream!
! ! ! - baking bread!
! ! !
Motivation
Let’s move
to Python
but They’ll
copy our
code
Let me do
Some
research…
Motivation
• Python was not
designed

to be obfuscated

!
• That's against the
language's philosophy

!
• Everything in Python
is open
Python is
not the tool
you need
Even compiled programs
can be reverse-engineered
Obfuscation
is really
hard
Code
protection is
overrated
Having a
legal
requirement
is a good way
to go
They hack
windows all
the time
Quit your
job
Crazy,
Over the rainbow, I am crazy,
Bars in the window.
There must have been a door there in the wall
When I came in.
Crazy, over the rainbow, he is crazy.
ONE DOES NOT SIMPLY
OBFUSCATE PYTHON
Motivation
Process
How to
CYTHONIZE
Convert to .c Compile native
extensions
Create executable For different
platforms
1. 2. 3. 4.
SETUP PyInstall PAckage
9
Process
Cythonize
c_files = []
for dir_ in included_dirs:
for dirname, dirnames, filenames in os.walk(dir_):
if 'test' in dirnames:
dirnames.remove('test')
for filename in filenames:
file_ = os.path.join(dirname, filename)
stripped_name = os.path.relpath(file_, biicode_python_path)
file_name, extension = os.path.splitext(stripped_name)
if extension == '.py':
target_file = os.path.join(src_dir, file_name + '.c')
if filename not in ignored_files:
c_files.append(stripped_name.replace('.py', '.c'))
file_dir = os.path.dirname(target_file)
if not os.path.exists(file_dir):
os.makedirs(file_dir)
extension = cythonize(stripped_name,
force=force_compile,
build_dir=src_dir)
return c_files
10
Process
setup
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
modules = []
for c_file in abs_path_c_files:
relfile = os.path.relpath(c_file, src_dir)
filename = os.path.splitext(relfile)[0]
extName = filename.replace(os.path.sep, ".")
extension = Extension(extName,sources=[c_file],
define_macros=[('PYREX_WITHOUT_ASSERTIONS',None)])
modules.append(extension)
if platform.system() != 'Windows':
cflags = sysconfig.get_config_var('CFLAGS')
opt = sysconfig.get_config_var('OPT')
sysconfig._config_vars['CFLAGS'] = cflags.replace(' -g ', ' ')
sysconfig._config_vars['OPT'] = opt.replace(' -g ', ' ')
if platform.system() == 'Linux':
ldshared = sysconfig.get_config_var('LDSHARED')
sysconfig._config_vars['LDSHARED'] = ldshared.replace(' -g ', ' ')
elif platform.system() == 'Darwin':
for key in ['CONFIG_ARGS', 'LIBTOOL', 'PY_CFLAGS', 'CFLAGS']:
value = sysconfig.get_config_var(key)
if value:
sysconfig._config_vars[key] = value.replace('-mno-fused-madd', '')
sysconfig._config_vars[key] = value.replace('-DENABLE_DTRACE', '')
Process
setup
abs_path_c_files = [os.path.join(src_dir, c) for c in c_files]
setup(name="bii",
version=VERSION,
script_name='setup.py',
script_args=['build_ext'],
packages=['biicode'],
ext_modules=modules)
Process
PyInstall: Fake main
import biicode.client.shell.bii
import biicode.client
if False:
# Third party imports
biicode.client.shell.bii.main(sys.argv[1:])
Process
PyInstall: spec
a.datas += Tree('BII_SRC_PATH/biicode/client/setups/images',
prefix = 'images')
dict_tree = Tree('MIMER_PATH', prefix = 'mimer',
excludes=["*.pyc"])
# This package is a gittler non pypip dependency
# It contains dynamically loadable resources that are not
# automatically included by pyinstaller
a.datas += dict_tree
a.datas += Tree('CRYPTO_PATH', prefix='Crypto', excludes=["*.pyc"])
a.binaries += Tree('BII_COMPILED_PATH/biicode', prefix='biicode')
Security
Can they know it is python?
Yes as is not packaged as a simple executable
and you can see the all the files in there.
!
But even if it was (much slower) widely available
tools will tell you
Security
What can they see?
They can import your native extensions (even if you
packaged as single file), so they can reverse engineer
them.
!
They can see all method names and, if you din’t tell
Cython not to include them, your docstrings.
Time(s)
0s
3,333s
6,667s
10s
Number of processed files
54 422 459 2130
Native Python
Efficiency
Python vs native extensions
+32%
16
+7%
Read More
• Compiling your python application with Cython!
• Packaging a compiled app with PyInstaller!
• Automating DEB pkg generation!
• Automating MacOS pkg generation!
• How to do your own Windows Installer!
• C vs Python
Blog posts
Questions ?
Thanks

More Related Content

Recently uploaded

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSrknatarajan
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 

Recently uploaded (20)

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Multiplatform binary packaging of your python client apps

  • 1. binary packaging and distribution of your client apps Multiplatform
  • 3. wHO AM I? Julia S.Simon! Software Engineer (in Test)! @hithwen! juliassimon
 ! ! Love:! ! ! ! - skiing - diving! ! ! ! - LARPS! ! ! ! - making ice cream! ! ! ! - baking bread! ! ! !
  • 4. Motivation Let’s move to Python but They’ll copy our code Let me do Some research…
  • 5. Motivation • Python was not designed
 to be obfuscated
 ! • That's against the language's philosophy
 ! • Everything in Python is open Python is not the tool you need Even compiled programs can be reverse-engineered Obfuscation is really hard Code protection is overrated Having a legal requirement is a good way to go They hack windows all the time Quit your job
  • 6. Crazy, Over the rainbow, I am crazy, Bars in the window. There must have been a door there in the wall When I came in. Crazy, over the rainbow, he is crazy.
  • 7. ONE DOES NOT SIMPLY OBFUSCATE PYTHON Motivation
  • 8. Process How to CYTHONIZE Convert to .c Compile native extensions Create executable For different platforms 1. 2. 3. 4. SETUP PyInstall PAckage
  • 9. 9 Process Cythonize c_files = [] for dir_ in included_dirs: for dirname, dirnames, filenames in os.walk(dir_): if 'test' in dirnames: dirnames.remove('test') for filename in filenames: file_ = os.path.join(dirname, filename) stripped_name = os.path.relpath(file_, biicode_python_path) file_name, extension = os.path.splitext(stripped_name) if extension == '.py': target_file = os.path.join(src_dir, file_name + '.c') if filename not in ignored_files: c_files.append(stripped_name.replace('.py', '.c')) file_dir = os.path.dirname(target_file) if not os.path.exists(file_dir): os.makedirs(file_dir) extension = cythonize(stripped_name, force=force_compile, build_dir=src_dir) return c_files
  • 10. 10 Process setup Lorem ipsum dolor sit amet, consectetur adipiscing elit. modules = [] for c_file in abs_path_c_files: relfile = os.path.relpath(c_file, src_dir) filename = os.path.splitext(relfile)[0] extName = filename.replace(os.path.sep, ".") extension = Extension(extName,sources=[c_file], define_macros=[('PYREX_WITHOUT_ASSERTIONS',None)]) modules.append(extension) if platform.system() != 'Windows': cflags = sysconfig.get_config_var('CFLAGS') opt = sysconfig.get_config_var('OPT') sysconfig._config_vars['CFLAGS'] = cflags.replace(' -g ', ' ') sysconfig._config_vars['OPT'] = opt.replace(' -g ', ' ') if platform.system() == 'Linux': ldshared = sysconfig.get_config_var('LDSHARED') sysconfig._config_vars['LDSHARED'] = ldshared.replace(' -g ', ' ') elif platform.system() == 'Darwin': for key in ['CONFIG_ARGS', 'LIBTOOL', 'PY_CFLAGS', 'CFLAGS']: value = sysconfig.get_config_var(key) if value: sysconfig._config_vars[key] = value.replace('-mno-fused-madd', '') sysconfig._config_vars[key] = value.replace('-DENABLE_DTRACE', '')
  • 11. Process setup abs_path_c_files = [os.path.join(src_dir, c) for c in c_files] setup(name="bii", version=VERSION, script_name='setup.py', script_args=['build_ext'], packages=['biicode'], ext_modules=modules)
  • 12. Process PyInstall: Fake main import biicode.client.shell.bii import biicode.client if False: # Third party imports biicode.client.shell.bii.main(sys.argv[1:])
  • 13. Process PyInstall: spec a.datas += Tree('BII_SRC_PATH/biicode/client/setups/images', prefix = 'images') dict_tree = Tree('MIMER_PATH', prefix = 'mimer', excludes=["*.pyc"]) # This package is a gittler non pypip dependency # It contains dynamically loadable resources that are not # automatically included by pyinstaller a.datas += dict_tree a.datas += Tree('CRYPTO_PATH', prefix='Crypto', excludes=["*.pyc"]) a.binaries += Tree('BII_COMPILED_PATH/biicode', prefix='biicode')
  • 14. Security Can they know it is python? Yes as is not packaged as a simple executable and you can see the all the files in there. ! But even if it was (much slower) widely available tools will tell you
  • 15. Security What can they see? They can import your native extensions (even if you packaged as single file), so they can reverse engineer them. ! They can see all method names and, if you din’t tell Cython not to include them, your docstrings.
  • 16. Time(s) 0s 3,333s 6,667s 10s Number of processed files 54 422 459 2130 Native Python Efficiency Python vs native extensions +32% 16 +7%
  • 17. Read More • Compiling your python application with Cython! • Packaging a compiled app with PyInstaller! • Automating DEB pkg generation! • Automating MacOS pkg generation! • How to do your own Windows Installer! • C vs Python Blog posts