title: Obfuscating python bytecode through interpreter mutation
body: <p>Actually, Dropbox made it very well, they were able to secure their desktop application made in python; I researched this a lot, but no good solution better than obfuscation, which is not very secure way to go, and you will end up seeing your code uploaded somewhere.</p>
  
  <p>I listened to a session made by <strong>Giovanni Bajo</strong> (the PyInstaller founder), he said Dropbox does this:</p>
  
  <ol>
  <li>Bytecode-scrambling by recompiling your CPython's interpreter, and
  by this, standard CPython interpreter will not be able to run it,
  only the recompiled cpython interpreter.</li>
  <li>All what you need to do is to shuffle the numbers below the <code>define
  loadup 8</code>.</li>
  </ol>
  
  <p>I've never gone through Python's source code, so, I will not claim that I fully understand the above words. </p>
  
  <p>I need to hear the voice of experts: How to do such a thing? And if after recompilation I will be able to package my application using the available tools like PyInstaller?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I made some research regarding how Dropbox does this type of obfuscation/mutation, and I found this:</p>
  
  <p>According to <a href="http://itooktheredpill.dyndns.org/" rel="noreferrer">Hagen Fritsch</a>, they do it in two stages:</p>
  
  <ol>
  <li><p>They use TEA cipher along with an RNG seeded by some values in the
  code object of each python module. They adjusted the interpreter
  accordingly so that it </p>
  
  <p>a) Decrypts the modules and</p>
  
  <p>b) Prevents access to the decrypted code-objects.</p>
  
  <p>This would have been the straightforward path just letting dropbox         decrypt everything and dump the modules using the builtin marshaller.</p></li>
  <li><p>Another trick used is the manual scrambling of the opcodes.
  Unfortunately this could only be fixed semiautomatically thus their
  monoalphabetic substitution cipher proved quite effective in terms
  of winning some time.</p></li>
  </ol>
  
  <p>I still want more insights on how this could be done, more over, I don't know how the decryption happens in this process... I want all the experts' voice here ... common guys where are you.</p>