Giter Site home page Giter Site logo

python-unpacky's Introduction

python-unpacky

Easily unpack binary data into a dict.

Example

Pattern that allows you to unpack HL2 server info...

>>> pattern = (
...         "{byte:header}{byte_int:protocol}{string:name}{string:map}{string:folder}{string:game}"
...         "{short:id}{byte_int:players}{byte_int:max_players}{byte_int:bots}"
...         "{byte:server_type}{byte:environment}"
...         "{byte_int:visibility}{byte_bool:vac}"
... )

Full Example

>>> import unpacky
>>> import binascii
>>> hex_data = (
...         "4911010101010101687474703a2f2f7777772e536169676e732e6465202833292052554e4f464"
...         "600646d5f72756e6f666600686c326d70005465616d2044656174686d6174636800400119200c64770001333"
...         "0393435343200b0996907984c8df6174001736169676e732c5f726567697374657265642c73746174732c696"
...         "e637265617365645f6d6178706c617965727300"
...     )
>>> data = binascii.unhexlify(hex_data)
>>> pattern = (
...         "{byte:header}{byte_int:protocol}{string:name}{string:map}{string:folder}{string:game}"
...         "{short:id}{byte_int:players}{byte_int:max_players}{byte_int:bots}"
...         "{byte:server_type}{byte:environment}"
...         "{byte_int:visibility}{byte_bool:vac}"
... )
>>> unpacked = unpacky.Unpacky(pattern, data).data
>>> unpacked
{'map': 'dm_runoff', 'protocol': 17, 'name': '\x01\x01\x01\x01\x01\x01http://www.Saigns.de (3) RUNOFF', 'players': 25, 'max_players': 32, 'vac': True, 'server_type': 'd', 'visibility': 0, 'environment': 'w', 'header': 'I', 'game': 'Team Deathmatch', 'bots': 12, 'folder': 'hl2mp', 'id': 320}
>>> 

python-unpacky's People

Contributors

daniellawrence avatar

Watchers

James Cloos 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.