Skip to main content

SniParInject

It is the abbreviation of these three word: Sniffer, Parser and Inject. Intercept and read the network packets to find information about the game, but it could be useful for any network sniffer purpose. The injection is coming soon.

This project is work in progress. Reefer to the To-Do's list to check what is done and what is coming.

Run it

Locally

For more information go to the package's page in PyPi.

Install the package.

python3 -m pip install sniparinject

As a developer

The only two special Python's packages that you need are scapy and PyYAML, the suggested version of Python is >= 3.11. Follow the commands to set up and install this package.

git clone https://github.com/airvzxf/sniparinject.git
cd sniparinject || exit 123
./script/setup-dev.bash

After this setup, it could be easy to activate the vEnv and start to work.

# Inside of the GitHub cloned directory.
source ./venv/bin/activate
cd src/sniparinject || exit 123
# Make modification to the source code files.
# Run your changes.
# Finally deactivate the vEnv.
deactivate

Usage

The most basic setup is creating one Python file, and the settings file.

main.py

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
The most basic example of SniParInject.
"""
from sniparinject.network_sniffer import NetworkSniffer

if __name__ == '__main__':
    SETTINGS_PATH = 'settings.yml'
    NetworkSniffer(SETTINGS_PATH).start()

settings.yml

%YAML 1.1
---
Network:
  interface: enp4s0

Server:
  ip: 52.174.196.146
  port: 5122

Game:
  node:
    actions:
      0x7d:
        title: Scenario change
      0x85:
        title: Player move to
        display_message: Yes
        structs:
          - type: chars
            size: 3
            output:
              type: hex
  host:
    actions:
      0x78:
        title: NPC Info
        structs:
          - name: ID
            type: unsigned int
            output:
              type: hex
              auto_zero_fill: Yes
          - type: chars
            size: 1
            output:
              type: hex
          - name: HP
            type: unsigned short
          - name: Max HP
            type: unsigned short

The settings, needs to set the network interface which could get by the command ip addr or ls -1 /sys/class/net. The next two are the host IP and its port, in our case we will use the game IP and port. You could use this command lsof -i to show all the process which has connection to the network, check the column NAME to review the connection manaplus 5563 wolf ... MSIGT73EVR7RF:55238->52.174.196.146:5122 (ESTABLISHED). Also, another command is sudo netstat -nap | grep -i NAME_OF_GAME_PROCESS.

Execute the application:

# Execute with root permissions the main script.
sudo python3 main.py

Example

This example is for the game Mana Plus.

asciicast

Settings

This software does not need to modify any file in the source code. Create a settings.yml file which is able to add, modify or remove any parse rules.

Examples

The required fields for the Server information are ip, port or both.

Network:
  interface: enp4s0

Server:
  ip: 52.174.196.146
  port: 5122

The default protocol is TCP but you can assign the UDP.

Network:
  interface: enp4s0

Server:
  protocol: UDP
  port: 6666

Read the packets from a capture file (pcap or pcapng) instead of the network interface with offline. A relative path is relative to the settings file. It does not need root permissions, and only the packets to or from the Server ip and port are parsed.

Network:
  offline: capture.pcapng

Server:
  ip: 52.174.196.146
  port: 5122

For example, record the game with tshark, which also does not need root when your user is in the wireshark group.

tshark -i enp4s0 -f 'tcp port 5122' -w capture.pcapng

This is the basic structure without any rule.

Game:
  node:
  host:

Example for node, which is the raw data send from your computer to the server.

Here will capture all the packets which start with the id 0x7d equal to the raw data \x00\x7d. It will print in your console: --> Scenario change | every time your computer send to the server this packet.

The action 0x85 equal to the raw data \x00\x85. It will print in your console: --> Player move to | a07f18 |. Means the player communicate to the server that it is moving to this position.

Game:
  node:
    actions:
      0x7d:
        title: Scenario change
      0x85:
        title: Player move to
        structs:
          - type: chars
            size: 3
            output:
              type: hex

Same example as above, but we do not want to print the action Player move to. Add display_message: No in the action which want to avoid the print.

Game:
  node:
    actions:
      0x7d:
        title: Scenario change
      0x85:
        title: Player move to
        display_message: No
        structs:
          - type: chars
            size: 3
            output:
              type: hex

Same example as above, but we do not want to print any node action, it means the actions sent by you computer to the server. It will print only the host's actions. The default value for the node/host or actions is always display_message: Yes, it does need to set explicitly.

Game:
  node:
    display_message: No
    actions:
      0x7d:
        title: Scenario change
  host:
    actions:
      0xad:
        title: Scenario change

What are the structs? It is the way that it will parse the data. Basically, split the raw data based on the Python Structs which are C Types. They are well-known as an integer, char, long, float, etc. You will find information in the official web page Python Structs. In the game the function which contains this map is STRUCT_TYPES in ./core/structs.py.

# 'ID': ('Python struct symbol', Size in bytes)
STRUCT_TYPES = {
    'char': ('c', 1),
    'signed char': ('b', 1),
    'unsigned char': ('B', 1),
    'bool': ('?', 1),
    'short': ('h', 2),
    'unsigned short': ('H', 2),
    'int': ('i', 4),
    'unsigned int': ('I', 4),
    'long': ('q', 8),
    'unsigned long': ('Q', 8),
    'half precision': ('e', 2),
    'float': ('f', 4),
    'double': ('d', 8),
    'chars': ('s', 1),
}

The sniffer checks the settings file when it starts. A missing Server or Game section, an unknown struct type, a size that is not a number, or an action id that is not a number ('0x7e' in quotes is text) stops it with a list of every problem found.


The option size returns the number of repeats of this struct. One example is if the setting's action has type: int and size: 8, it will returns 4i and it is exactly the same to write iiii. The example below will return 5s.

structs:
  - type: chars
    size: 5

In this example it will take the raw data and split in two. The first is an unsigned int with 4 bytes of size and the char with 1 byte of size. The raw data could be \x00\x80 \x0f\x00\x00\x00 \xf8, I split intentional with spaces to be more clear. The rule in the example take the first unsigned short value as an action ID (\x00\x80 equal to 0x80), then extract as a unsigned int the monster ID, and the last byte as an unknown. The output will be ---> NPC Monster Check | ID 0x0000000f | 0xf8 |. Note in the monster ID that the raw data, and the output is different: \x0f\x00\x00\x00 vs 0x0000000f. It is because the network data is coming in big-endian and the human / machine-readable for numbers is in little-endian.

Game:
  node:
    actions:
      0x80:
        title: NPC Monster Check
        structs:
          - name: ID
            type: unsigned int
            output:
              type: hex
              auto_zero_fill: Yes
          - type: chars
            size: 1
            output:
              type: hex

In every struct there is an option to add the name which will display before the value. In the follow example the first struct does not have the name, and the second has the name id. The output will be ---> NPC Monster Check | 56 | ID 78 |.

Game:
  node:
    actions:
      0x80:
        title: NPC Monster Check
        structs:
          - type: unsigned int
          - name: ID
            type: unsigned int

What happen if I do not use the output as an hex? It will show the raw data: ---> NPC Monster Check | ID b'\x00\x00\x00\x0f' |

Game:
  node:
    actions:
      0x80:
        title: NPC Monster Check
        structs:
          - name: ID
            type: chars
            size: 4

Names and messages are usually chars padded with zeros. The output type text decodes them as UTF-8 and stops at the first zero byte. Given the raw data \x95\x00 \x12\x9f\x8e\x06 Bob\x00..., the output will be <-- Being name | ID 0x068e9f12 | Name Bob |.

Game:
  host:
    actions:
      0x95:
        title: Being name
        structs:
          - name: ID
            type: unsigned int
            output:
              type: hex
              auto_zero_fill: Yes
          - name: Name
            type: chars
            size: 24
            output:
              type: text

Some packets have a variable length: the two bytes after the ID are the total length of the packet, including the ID and the length. Set variable_length: Yes in the action: the structs parse the body of the packet, the bytes left in the body are displayed as Data in hex, and the parse continues with the next packet in the same network packet.

Given the raw data \x00\x80 \x04\x00, the output will be <-- Header only | Length 4 |.

Game:
  host:
    actions:
      0x8000:
        title: Header only
        variable_length: Yes

With the TCP protocol, one game packet can be split across two or more TCP segments, and one segment can hold several game packets. The sniffer joins the segments of each direction in sequence order, skips the retransmitted bytes, and parses only the complete packets: the size of a packet is its ID plus its structs, or the length after the ID with variable_length: Yes. The bytes of an incomplete packet wait for the next segment. An unknown ID takes all the data left, because its size is not known, so define the actions of the packets that come before the ones you study. After a lost segment the stream starts again from the next one.


Take a little break for output and check the reference option. In the middle time that you are parsing the data, some findings will be discovered for example the ID types of the shop options. It is possible to map this information and display as a text in the output. Adding reference: *node_shop_options to your settings, it will take the section referring with the ID shop_options: &node_shop_options. If the value is not in the map, it will print as usual.

Given the raw data \x00\xc5 \x00, the output will be ---> Shop store | ID Buy |.

Given the raw data \x00\xc5 \x01, the output will be ---> Shop store | ID Sell |.

Given the raw data \x00\xc5 \x5a, the output will be ---> Shop store | ID 0x5a |.

Game:
  node:
    references:
      shop_options: &node_shop_options
        0x0: 'Buy'
        0x1: 'Sell'
    actions:
      0xc5:
        title: Shop store
        structs:
          - name: ID
            type: unsigned char
            reference: *node_shop_options
            output:
              type: hex
              auto_zero_fill: Yes

Formatting the output is possible with these options zero_fill, auto_zero_fill, fill and fill_left.

  • zero_fill - Add zeros to the left until the value has this width. For a hex value the zeros go after the 0x prefix: if the output is 0x12 and the property is set to 8, it will display 0x000012.
  • auto_zero_fill - Add zeros to the left taking the type of the structure. For example if you have an integer with byte size of 4, but the value is 5. The output without this option will be 0x05, then if your next value is 123456789 the output will be 0x75bcd15. Keep aligned the output and using the property auto_zero_fill: Yes it will display both numbers as 0x00000005 and 0x075bcd15 because the integer is 4 bytes equal to 00 00 00 00 plus the pre-fix 0x, it means 10 characters.
  • fill - Same as zero_fill but add blank spaces to the right of the value.
  • fill_left - Same as the previous option but add blank spaces to the left of the value.
Game:
  node:
    actions:
      0x146:
        title: NPC Dialog close
        structs:
          - type: unsigned int
            output:
              type: hex
              zero_fill: 20
          - type: unsigned int
            output:
              type: hex
              auto_zero_fill: Yes
          - type: unsigned int
            output:
              type: hex
              fill: 9
          - type: unsigned int
            output:
              type: hex
              fill_left: 17

Endian

All the data coming from the network or server usually is big-endian, to read this as the game interpretation needs to convert to little-endian. In this example if you receive a raw data ff 00 ab 14 36 f0 1f. The parse should be:

  • ID Action package: ff 00 = 0x00ff = 255.
  • ID Monster: ab 14 36 f0 = 0xf03614ab.
  • Unknown: 1f = 0x1f = 31.

Enjoy!

Metadata

Release files for sniparinject 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sniparinject 1.1.0
File Size Uploaded Provenance Actions
sniparinject-1.1.0.tar.gz 23.3 kB With provenance Details for sniparinject-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sniparinject 1.1.0
File Interpreter ABI Platform Actions
sniparinject-1.1.0-py3-none-any.whl Python 3 none any Details for sniparinject-1.1.0-py3-none-any.whl

Total release size: 44.2 kB

Release files / sniparinject-1.1.0.tar.gz

Download URL sniparinject-1.1.0.tar.gz
Size 23.3 kB
Tags Source
SHA-256 checksum
How to use checksums
739e6aa819fba1e29488889d840b38b20055a5a5f2e019ce2da7e207b3789779
BLAKE2b-256 checksum
How to use checksums
5fe0efd6cd12c181232c1e0b69b3fc28aba9ab43be2b0f0cdde6169a6e271ff1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / sniparinject-1.1.0-py3-none-any.whl

Download URL sniparinject-1.1.0-py3-none-any.whl
Size 20.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00658fda017e5f9bef7872b28b6ef939c78d03990019d016200ce2c766f25513
BLAKE2b-256 checksum
How to use checksums
e45a60cecd4fe48437639c464d16c44f9bc108f917a9c4f3019a034683735534
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Security for sniparinject 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sniparinject-1.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page