title: ImportError: Ill-formed bytecode file error when decompiling .pyc file using uncompyle6
body: <p>I am using pyi-archive_viewer to extract the main .pyc file from my ELF executable compiled with pyinstaller. The executbale is called 'mal', I save the output as mal.pyc.</p>
  
  <p>I've corrected the magic numbers of the mal.pyc output file from pyi-archive_viewer 
      to '03 F3 0D 0A'.</p>
  
  <pre><code>00000000: 03f3 0d0a 0000 0000 0002 0000 0040 0000  .............@..
  00000010: 0073 2b01 0000 6400 0064 0100 6c00 006d  .s+...d..d..l..m
  00000020: 0100 5a01 0001 6400 0064 0200 6c02 0054  ..Z...d..d..l..T
  00000030: 6400 0064 0300 6c03 006d 0400 5a04 006d  d..d..l..m..Z..m
  00000040: 0500 5a05 0001 6400 0064 0400 6c06 005a  ..Z...d..d..l..Z
  00000050: 0600 6400 0064 0400 6c07 005a 0700 6400  ..d..d..l..Z..d.
  00000060: 0064 0400 6c08 005a 0800 6400 0064 0400  .d..l..Z..d..d..
  00000070: 6c09 005a 0900 6400 0064 0400 6c0a 005a  l..Z..d..d..l..Z
  00000080: 0a00 6400 0064 0400 6c0b 005a 0b00 6400  ..d..d..l..Z..d.
  00000090: 0064 0400 6c0c 005a 0c00 6400 0064 0400  .d..l..Z..d..d..
  </code></pre>
  
  <p>I've ran the command 'uncompyle6 -o . mal.pyc' and I recieve the following error.</p>
  
  <pre><code>Traceback (most recent call last):
    File "/usr/local/lib/python2.7/dist-packages/xdis/load.py", line 150, in load_module
  co = marshal.loads(bytecode)
  ValueError: bad marshal data (unknown type code)
  Traceback (most recent call last):
    File "/usr/local/bin/uncompyle6", line 10, in &lt;module&gt;
  sys.exit(main_bin())
    File "/usr/local/lib/python2.7/dist-   packages/uncompyle6/bin/uncompile.py", line 163, in main_bin
  **options)
    File "/usr/local/lib/python2.7/dist-packages/uncompyle6/main.py", line 146, in main
  decompile_file(infile, outstream, showasm, showast, showgrammar)
    File "/usr/local/lib/python2.7/dist-packages/uncompyle6/main.py", line 63, in decompile_file
  source_size) = load_module(filename, code_objects)
    File "/usr/local/lib/python2.7/dist-packages/xdis/load.py", line 163, in load_module
  % (filename, kind, msg))
  ImportError: Ill-formed bytecode file mal.pyc
  &lt;type 'exceptions.ValueError'&gt;; bad marshal data (unknown type code)
  </code></pre>
  
  <p>I presume this is due to the .pyc being corrupt? Can anyone suggest where im going wrong?</p>
  
  <p>UPDATE:
  The issue lies in me fixing the magic numbers.</p>
  
  <p>Ive used script python_exe_unpack.py <a href="https://github.com/countercept/python-exe-unpacker" rel="nofollow noreferrer">https://github.com/countercept/python-exe-unpacker</a> and it has a -p option that auto appends the magic number for you EXACTLY like I did it manually.</p>
  
  <p>Here is the function from the python_exe_unpack script</p>
  
  <pre><code>if is_prepend_magic:
      magic = b'\x03\xf3\x0d\x0a' # Default magic for python 2.7
      with edited_pyc as prepend_pyc:
          pyc_data = open(main_pyc, 'rb')
          prepend_pyc.write(magic) # Magic bytes
          prepend_pyc.write(b'\0' * 4) # Time stamp
          prepend_pyc.write(pyc_data.read())
          pyc_data.close()
  </code></pre>
  
  <p>So all its doing it prepending ' 03f3 0d0a '</p>
  
  <p>The function is successfull and spits out the .py file in clear text.</p>
  
  <p>Where could I be going wrong with doing this manually, Ive tried a different hex editor but same result. As you can see by my previous file header output the magic numbers match up? All im doing is replace the first 8bytes, save and exit.</p>