title: How to dereference a memory location from python ctypes?
body: <p>I want to replicate the following c code in python ctypes:</p>
  
  <pre><code>main() {
    long *ptr = (long *)0x7fff96000000;
    printf("%lx",*ptr);
  }
  </code></pre>
  
  <p>I can figure out how to call this memory location as a function pointer but not just do a normal dereference:</p>
  
  <pre><code>from ctypes import *
  """
  &gt;&gt;&gt; fptr = CFUNCTYPE(None, None)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/lib/python2.6/ctypes/__init__.py", line 104, in CFUNCTYPE
      class CFunctionType(_CFuncPtr):
  TypeError: Error when calling the metaclass bases
      item 1 in _argtypes_ has no from_param method
  """
  fptr = CFUNCTYPE(None, c_void_p) #add c_void_p since you have to have an arg
  fptr2 = fptr(0x7fff96000000)
  fptr2(c_void_p(0))
  #python: segfault at 7fff96000000 ip 00007fff96000000
  </code></pre>
  
  <p>Since there it is a segfault with the instruction pointer pointing to this memory location it is successfully calling it.  However I can't get it to just read the memory location:</p>
  
  <pre><code>ptr = POINTER(c_long)
  ptr2 = ptr(c_long(0x7fff96000000))
  #&gt;&gt;&gt; ptr2[0]
  #140735709970432
  #&gt;&gt;&gt; hex(ptr2[0])
  #'0x7fff96000000'
  #&gt;&gt;&gt; ptr2.contents
  #c_long(140735709970432)
  </code></pre>