mirror of
https://github.com/volatilityfoundation/volatility
synced 2026-06-08 18:04:46 +00:00
Page:
Style Guide
Pages
2.6 Win Profiles
Address Spaces
Android
Command Reference Gui
Command Reference Mal
Command Reference Registry Api
Command Reference Registry Api23
Command Reference
Compiling Binaries with Pyinstaller
Crash Address Space
EWF Address Space
Encrypted KDBG (Win 8 and later)
FAQ
Firewire Address Space
Hiber Address Space
Home
Hpak Address Space
Installation
Lime Address Space
Linux Command Reference
Linux
Mac Command Reference
Mac
MachO Address Space
Memory Samples
Style Guide
Unified Output
VMware Snapshot File
Virtual Box Core Dump
Volatility Documentation Project
Volatility Usage
_Header
Clone
6
Style Guide
gleeda edited this page 2014-06-11 15:51:42 -07:00
Table of Contents
Introduction
Here's a brief guide to coding styles for adding to volatility. They mostly follow PEP 8, and also pylint (although with certain rules ignored including C0111, C0103, C0301, W0511, R0201, R0903 and W0142). The reasoning behind each decision should be given after the guideline.
Please note, this is just a guideline, and if anyone feels like changing any of these, please do. If everyone's happy, then someone can remove this paragraph. If you have any additions you'd like to make, again please make them.
Volatility currently requires python-2.6 or greater.
Details
- Spacing: 4 space indents, no tabs.
- Consistency, PEP8
- Multiple statements on one line are discouraged.
- PEP8
- Always try to use
if x == Nonerather thanif x is None - The New Object model overrides equivalence, allowing NoneObjects to be equal to
None - Note that if you want to test for validity you should use
if x: ....This is because x might be an actual real object (i.e. not equivalent to None) but actually invalid. For example it might be an invalid pointer. - Importing specific objects or functions is discouraged.
- It pollutes the namespace and causes confusion. Previous versions of volatility allowed people to import functions from files they weren't defined in.
- "
from blah import *" is strongly discouraged. - Again, namespace pollution and inappropriate imports.
- Module names should be lower case, Class names should be CamelCase, function names should be lower_case_with_underscores).
- PEP8 using most historically common style (hence function names aren't mixedCase).
- Whitespace on either side of all operators, and a space after all commas.
- This includes the
=in method(arg = default). - PEP8, clarity.
- No whitespace at the end of a line
- clarity, easier diffs.
- No need for docstrings on
__init__, since they're implicit. - Pylint, obvious.
- Use
"{0:spec}".format(blah)over"%spec" % blah. - In preparation for python-3,
%is evil. - Use lowercase format specifier when outputting hex offsets (
"{0:08x}"or"{0:#010x}"). - Consistency, ease of reading (particularly
0x123vs0X123). - Avoid using super, call the superclass's function by name instead.
- This is primarily in regards to
__init__, because you need to pass the underlying__init__function's arguments, and you don't know which__init__you'll end up calling in the case of multiple inheritance. As such, that requires the entire codebase to ensure that all__init__s take**kwargs, and are co-operative to this coding style. Super's only really useful for multiple-inheritance, and even then it's easy to get wrong. - See http://fuhm.net/super-harmful/
- This is primarily in regards to
- Always try to catch the most specific exception you can.
- Never use "
except:" (see idioms and anti-idioms in Python) - Makes debugging far easier if you only catch what you're expecting.
- Never use "
Getting Started
- FAQ
- Installation
- Linux
- Mac
- Android
- Basic Usage
- 2.6 Win Profiles
- Encrypted KDBG
- Pyinstaller Builds
- Unified Output
Command References
Development
Miscellaneous
Physical Address Spaces
Volatility Foundation