小编tja*_*jac的帖子

在不知道.proto的情况下解析协议 - 缓冲区

我知道协议缓冲区是一种序列化格式,需要.proto中的消息格式才能正确读回.但我有一个文件,我不知道正确的消息格式,因为它没有发布.我想要做的是自己对数据进行逆向工程,以便我可以重建消息.要做到这一点,我需要读取原始文件,我可以在那里获取字段数字,类型和值.

有没有一个程序可以做到这一点(最好是在python中,但C/C++也很酷)?

parsing protocol-buffers

17
推荐指数
2
解决办法
2万
查看次数

从python中的二进制文件中提取字符串

我有一个项目,我给了一个文件,我需要从文件中提取字符串.基本上想到linux中的"strings"命令,但我在python中这样做.下一个条件是文件作为流(例如字符串)给我,所以使用其中一个子进程函数来运行字符串的明显答案也不是一个选项.

我写了这段代码:

def isStringChar(ch):
    if ord(ch) >= ord('a') and ord(ch) <= ord('z'): return True
    if ord(ch) >= ord('A') and ord(ch) <= ord('Z'): return True
    if ord(ch) >= ord('0') and ord(ch) <= ord('9'): return True

    if ch in ['/', '-', ':', '.', ',', '_', '$', '%', '\'', '(', ')', '[', ']', '<', '>', ' ']: return True

# default out
return False

def process(stream):
dwStreamLen = len(stream)
if dwStreamLen < 4: return None

dwIndex = 0;
strString = ''
for ch …
Run Code Online (Sandbox Code Playgroud)

python string-search

6
推荐指数
2
解决办法
1万
查看次数

Protobuf声明我显然没有丢失必填字段

我正在编写一个使用protobuf作为序列化系统的轻量级服务器-客户端系统。我在protobufs抱怨缺少必填字段时遇到问题,但是1)字段显然在数据流中; 2)错误消息无法识别出缺少的字段。

首先一点代码:

myMessages::DataRequest cData;  // this is declared outside of the function in the global
                                // so it can be reused each time to avoid unnecessary
                                // memory allocation. Per the documentation in protobufs
.
.
.

bool processStream(u_int8_t *pStream, u_int32_t dwLength)
{
try
{
    if (!cData.ParseFromArray(pStream, dwLength))
    {
        printf("Failed to parse data stream\n");
        hexdump(pStream, dwLength);
        return false;
    }
}
catch(exception e)
{
    printf("Exception in ParseFromArray: %s", e.what());
    hexdump(pStream, dwLength);
    return false;
}
Run Code Online (Sandbox Code Playgroud)

这是我获取完整数据流并尝试让protobufs对其进行解码的代码。在大多数情况下,这可以正常工作。但是通过此代码进行的如此多次迭代都会出现此错误:

[libprotobuf ERROR google/protobuf/message_lite.cc:123] Can't parse …
Run Code Online (Sandbox Code Playgroud)

c c++ protocol-buffers

0
推荐指数
1
解决办法
2341
查看次数

标签 统计

protocol-buffers ×2

c ×1

c++ ×1

parsing ×1

python ×1

string-search ×1