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

Executable

Every release has a stand-alone ELF64 executable for Linux x86-64, sniparinject-<version>-linux-x86_64, with its SHA-256 checksum. It doesn't need Python. It is built on the latest Ubuntu, so it needs a glibc at least as new as that one.

sha256sum --check sniparinject-1.5.0-linux-x86_64.sha256
chmod +x sniparinject-1.5.0-linux-x86_64
./sniparinject-1.5.0-linux-x86_64 --version

To build it from the source, run ./script/executable-build.bash: it writes dist/executable/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 the settings file and the command sniparinject (also python3 -m sniparinject), or one Python file that uses the package.

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 command, or the main script.
sudo sniparinject settings.yml
sudo python3 main.py

Reading a capture file (Network.offline) does not need root. The command returns 1 and prints the error when the settings are wrong, and 130 when you stop it with Ctrl+C.

Proxy

With a Proxy section in the settings, SniParInject doesn't sniff: the game connects to it, it forwards every connection to Server.ip and Server.port, and it prints the packets that pass through, both ways.

Server:
  ip: 52.174.196.146
  port: 5122

Proxy:
  listen: 127.0.0.1:15122

When the game takes the server address from another server (for example after its login), redirect the connections of your user to the proxy, and run the proxy as root so its own connection reaches the real server:

sudo iptables -t nat -A OUTPUT -p tcp -d 52.174.196.146 --dport 5122 \
     -m owner --uid-owner "${USER}" -j REDIRECT --to-ports 15122
sudo sniparinject settings.yml
# Remove the rule when you finish: the same command with -D instead of -A.

Inject

With an Inject section, a key combination sends a packet through the proxy: node to the server as if the game sent it, host to the game as if the server sent it. Build it from an action of Game.<side>.actions with packet and values, or give the bytes with raw. The keys are read from /dev/input (root or the input group), so they work while the game has the focus and the game still gets them: use keys the game ignores.

Inject:
  keys:
    rightctrl+1:
      side: node
      packet: 0x89
      values: [0x0f, 7]
    rightctrl+2:
      side: node
      raw: 7d 00

A packet is sent between two game packets, never in the middle of one.

Example

This example is for the game Mana Plus.

asciicast

Settings

The man page sniparinject-settings(5) describes every key of the settings file. It is installed with the package: man sniparinject-settings, or man -l src/man/sniparinject-settings.5 in the cloned repository.

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

Choose which lines are printed with Display. The patterns are Python regular expressions that match anywhere in the line, without its colors: include prints only the lines that match one of them, and exclude hides the lines that match any of them. log_file appends every line, also the hidden ones, to a file (relative to the settings file), so you can search it later with grep. Each line starts with the local date and time in milliseconds, and the proxy also writes there the packets it injects. Like the rest of the settings, it is read again when the file changes.

Display:
  include: '^<-- '
  exclude: [Tick, Ping]
  log_file: packets.log

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 \x7d\x00. 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 \x85\x00. 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 8i and it is exactly the same to write iiiiiiii. The example below will return 5s.

structs:
  - type: chars
    size: 5

In a variable_length action the last struct can be a chars with size: rest. It takes the bytes of the body that the structs before it leave, so a message of any length is printed as text:

0xb4:
  title: NPC message
  variable_length: Yes
  structs:
    - name: NPC
      type: unsigned int
    - name: Text
      type: chars
      size: rest
      output:
        type: text

A list that fills the rest of the body, for example the items of a shop, is a last struct with type: repeat and size: rest. Its own structs are one item, and the items repeat until the body has fewer bytes than one item. The output prints the name and the number of items, then each item after #1, #2, and so on: <-- NPC buy list | Length 16 | Items 2 | #1 Price 10 | Item id 501 | #2 Price 20 | Item id 502 |. The bytes left after the last item are printed as Data.

0xc6:
  title: NPC buy list
  variable_length: Yes
  structs:
    - name: Items
      type: repeat
      size: rest
      structs:
        - name: Price
          type: unsigned int
        - name: Item id
          type: unsigned short

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 \x80\x00 \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 (\x80\x00 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 numbers are read in little-endian: the first byte is the least significant one, and the output writes the most significant digits first.

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'\x0f\x00\x00\x00' |

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 \xc5\x00 \x00, the output will be ---> Shop store | ID Buy |.

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

Given the raw data \xc5\x00 \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

The numbers are read in little-endian, the byte order of the game: the first byte is the least significant one. The action ID, the variable_length length and every number struct follow this order. 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.5.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.5.0
File Size Uploaded Provenance Actions
sniparinject-1.5.0.tar.gz 42.3 kB With provenance Details for sniparinject-1.5.0.tar.gz

Built distribution (wheel)

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

Total release size: 84.7 kB

Release files / sniparinject-1.5.0.tar.gz

Download URL sniparinject-1.5.0.tar.gz
Size 42.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e14c6414451a4d77f7911c461a07093c1392f1dcd8e49afcc4c63bf490681e80
BLAKE2b-256 checksum
How to use checksums
f4f6af47ab4d0edc664cc5e3a73f997671e6187b30a2c8fa9c3f8c8633d257ef
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 30, 2026.

Transparency log

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

Download URL sniparinject-1.5.0-py3-none-any.whl
Size 42.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e3fe0ebe79bcb14fdb6ed113d21265c81ad6b6b5c28caff94bea3d8603550f4
BLAKE2b-256 checksum
How to use checksums
d2f44ea6c89f455618669505a54c5b351d2c2866447eb41a8a0fbc673bf2c418
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 30, 2026.

Transparency log

Security for sniparinject 1.5.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.5.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 30, 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