Coder Social home page Coder Social logo

pypiss's Introduction

PyPISS (v0.1)

Python Packet parser generator In Simple Structured format


Intro

PyPISS is a simple packet parser generator framework inspired by P4 Lang If you tired about making every packet formats or, If you want to make your own packet format (such as researching, game socket io, etc...) This framework may be helpful for creating packet builder/parser.


Specification

  • Support bit,byte,short,int,string,list and so on ...
  • Declare packet's structure and setting each fields default value or action easily (such as CRC, Flag)
  • Creating packet by declared packet's structure
  • Automatic validity check from packet's structure
  • Creating new packet structure by compositing another packet's structure

Supporting types

1. primitives

name c-style type name size(bytes) note
bool bool (not same size) 1bit True / False
char signed char 1
byte unsigned char 1
short signed short 2
u_short unsigned short 2
int signed long int 4
u_int unsigned long int 4
long signed long long int 8
u_long unsigned long long int 8
float float 4
double double 8

2. iteratives

name c-style type name size(bytes) note
str(size) char[] vary return in python string
bytes(size) unsigned char[] vary return in byte array
arr(size) array of type vary return in list, must use with type

3. structures

name c-style type name size(bytes) note
ipv4 byte[4] 4 return in IPv4 python class
ipv6 short[8] 16 return in IPv6 python class
hmac byte[6] 6 return in HMAC python class

Supporting operators

  • {typename}(bits=0) : set field's type, if bits is 0 then using default bit size.
  • val(val) : set default value for {val} when build
  • val(lambda) : set default value by lambda function when build
  • check(lambda) : check value by lambda function when parse

Installation

  • Python 2.x : pip install pypiss
  • Python 3.x : pip3 install pypiss

Example

IPv4 with Custom Packets

import enum.Enum
from pypiss.PacketStructure import *
from pypiss.PacketUtil import CRC32

class EtherType(Enum):
    IPV4 = 0x0800,
    ARP = 0x0806

class EthernetFrame(PacketHeader):
    _field = [
        field("dst").hmac(),
        field("src").hmac(),
        field("ether_type").u_short().enum(EtherType),
        field("payload").bytes(),   # if skip to define size, auto calculated from rest bytes
        field("crc").int().val(CRC32.make(['payload'])).check() # if skip to define check function, use same logic from make
    ]
    
class IPv4Frame(PacketHeader):
    _field = [
        field("src").ipv4(),
        field("dst").ipv4(),
        ...,
        field("len").u_short(),
        ...,
        field("payload").bytes()
    ]
    
    def parse(self, data):
        self.
        # In this function, all fields except payload should be assigned
    
class PingPongFrame(PacketHeader):
    _field = [
        field(type).byte(bits=3),
        payload()
    ]
    

Roadmap

See in 'Issues'

  1. make converter p4 lang to piss python structure

Contribution

I always need your helps. don't be shy, don't hesitate, just fork & pull request thx!

If you have any suggestion (feature request, etc...), feel free to contact me!

pypiss's People

Contributors

betas avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.