mirror of
https://github.com/lcdr/utils.git
synced 2024-08-30 17:32:16 +00:00
bitstream now uses struct instead of ctypes for type conversion.
This commit is contained in:
parent
3a1c0a73e0
commit
9419e656b5
@ -5,12 +5,11 @@ import tkinter.filedialog as filedialog
|
||||
import xml.etree.ElementTree as ET
|
||||
import zipfile
|
||||
from collections import OrderedDict
|
||||
from ctypes import c_float, c_int, c_int64, c_ubyte, c_uint, c_ushort
|
||||
from tkinter import BooleanVar, END, Menu
|
||||
|
||||
import viewer
|
||||
import structparser
|
||||
from pyraknet.bitstream import BitStream, c_bit
|
||||
from pyraknet.bitstream import BitStream, c_bit, c_float, c_int, c_int64, c_ubyte, c_uint, c_ushort
|
||||
|
||||
with open("packetdefinitions/replica/creation_header.structs", encoding="utf-8") as file:
|
||||
creation_header_parser = structparser.StructParser(file.read())
|
||||
@ -422,7 +421,7 @@ class CaptureViewer(viewer.Viewer):
|
||||
traceback.print_exc()
|
||||
values = ("likely not "+msg_name, "Error while parsing, likely not this message!\n"+str(e)+"\nlen: "+str(len(packet)-10)+"\n"+"\n".join(["%s = %s" % (a, b) for a, b in attr_values.items()]))
|
||||
tags = ["error"]
|
||||
except ValueError as e:
|
||||
except Exception as e:
|
||||
values = ("likely not "+msg_name, "Error while parsing, likely not this message!\n"+str(e)+"\nlen: "+str(len(packet)-10))
|
||||
tags = ["error"]
|
||||
else:
|
||||
|
@ -1,13 +1,12 @@
|
||||
import configparser
|
||||
import os.path
|
||||
import sqlite3
|
||||
from ctypes import c_float, c_int64, c_ubyte, c_uint, c_uint64, c_ushort
|
||||
|
||||
import tkinter.filedialog as filedialog
|
||||
from tkinter import END, Menu
|
||||
|
||||
import viewer
|
||||
from pyraknet.bitstream import BitStream
|
||||
from pyraknet.bitstream import BitStream, c_float, c_int64, c_ubyte, c_uint, c_uint64, c_ushort
|
||||
|
||||
class LUZViewer(viewer.Viewer):
|
||||
def __init__(self):
|
||||
|
@ -2,16 +2,15 @@
|
||||
Module for parsing binary data into structs.
|
||||
"""
|
||||
import argparse
|
||||
import ctypes
|
||||
import re
|
||||
from collections import namedtuple
|
||||
|
||||
from pyraknet.bitstream import BitStream, c_bit
|
||||
from pyraknet.bitstream import BitStream, c_bit, c_float, c_double, c_int8, c_uint8, c_int16, c_uint16, c_int32, c_uint32, c_int64, c_uint64
|
||||
|
||||
VAR_CHARS = r"[^ \t\[\]]+"
|
||||
BIT = r"(BIT[0-7])?"
|
||||
TYPES = "bytes", "string", "wstring", "char", "wchar", "float", "double", "s8", "u8", "s16", "u16", "s32", "u32", "s64", "u64"
|
||||
TYPES_RE = "("+"|".join(TYPES)+")"
|
||||
BITSTREAM_TYPES = {"bytes": bytes, "string": (str, 1), "wstring": (str, 2), "float": c_float, "double": c_double, "s8": c_int8, "u8": c_uint8, "s16": c_int16, "u16": c_uint16, "s32": c_int32, "u32": c_uint32, "s64": c_int64, "u64": c_uint64}
|
||||
TYPES_RE = "("+"|".join(BITSTREAM_TYPES.keys())+")"
|
||||
|
||||
DEFINITION_SYNTAX = re.compile(r"""^
|
||||
(?P<indent>\t*) # Indentation
|
||||
@ -134,31 +133,19 @@ class StructParser:
|
||||
else:
|
||||
eval_ = None
|
||||
if def_["type"] is not None:
|
||||
if def_["type"] == "bytes":
|
||||
type_ = bytes
|
||||
elif def_["type"] == "string":
|
||||
type_ = str, 1
|
||||
elif def_["type"] == "wstring":
|
||||
type_ = str, 2
|
||||
elif def_["type"] in ("char", "wchar", "float", "double"):
|
||||
type_ = vars(ctypes)["c_"+def_["type"]]
|
||||
# the rest of types are in the format (s|u)<bitlength>
|
||||
elif def_["type"].startswith("s"):
|
||||
type_ = vars(ctypes)["c_int"+def_["type"][1:]]
|
||||
elif def_["type"].startswith("u"):
|
||||
type_ = vars(ctypes)["c_uint"+def_["type"][1:]]
|
||||
type_ = BITSTREAM_TYPES[def_["type"]]
|
||||
else:
|
||||
# try to find a type based on the length
|
||||
if length_bits == 1:
|
||||
type_ = c_bit
|
||||
elif length_bits == 8:
|
||||
type_ = ctypes.c_byte
|
||||
type_ = c_int8
|
||||
elif length_bits == 16:
|
||||
type_ = ctypes.c_short
|
||||
type_ = c_int16
|
||||
elif length_bits == 32:
|
||||
type_ = ctypes.c_int
|
||||
type_ = c_int32
|
||||
elif length_bits == 64:
|
||||
type_ = ctypes.c_int64
|
||||
type_ = c_int64
|
||||
else:
|
||||
if length_bits % 8 == 0:
|
||||
type_ = bytes
|
||||
|
Loading…
Reference in New Issue
Block a user