【问题标题】:Convert binary file to proto file将二进制文件转换为 proto 文件
【发布时间】:2021-04-02 20:12:48
【问题描述】:

服务器返回给我二进制文件 -- https://pastebin.com/E4jxdF0W

我要查找二进制文件的 .proto 结构

所以,我将文件添加到网站 -- https://protogen.marcgravell.com/decode/

收到

我创建了 proto 文件(但没有收到有效文本)

我应该对我的原型结构进行哪些更改?

syntax = "proto2";

    message Cities {
      repeated City city = 1;
    }
    
    message City {
      optional string name = 2;
      optional string name2 = 3;
      optional string name3 = 4;
      optional string name4 = 5;
      optional string name5 = 6;
      optional string name6 = 7;
      optional int32 name7 = 8;
      optional int32 name8 = 9;
      optional int32 name9 = 10;
      optional string name10 = 11;
    }

更新 1 我用过

protoc --decode_raw < binary_file.protobuf

并收到结果

1 {
  1: "U\222\017\352c\021\021\346\204\237RT\000\020\266\010"
  2: "\320\241\320\260\320\275\320\272\321\202-\320\237\320\265\321\202\320\265\321\200\320\261\321\203\321\200\320\263"
  4 {
    1: 0x426fc1a3
    2: 0x41f286ea
  }
  5: "\320\241\320\260\320\275\320\272\321\202-\320\237\320\265\321\202\320\265\321\200\320\261\321\203\321\200\320\263"
  5: "\320\241\320\260\320\275\320\272\321\202-\320\237\320\265\321\202\320\265\321\200\320\261\321\203\321\200\320\263\320\260"
  5: "\320\241\320\260\320\275\320\272\321\202-\320\237\320\265\321\202\320\265\321\200\320\261\321\203\321\200\320\263\321\203"
  5: "\320\241\320\260\320\275\320\272\321\202-\320\237\320\265\321\202\320\265\321\200\320\261\321\203\321\200\320\263"
  5: "\320\241\320\260\320\275\320\272\321\202-\320\237\320\265\321\202\320\265\321\200\320\261\321\203\321\200\320\263\320\276\320\274"
  5: "\320\241\320\260\320\275\320\272\321\202-\320\237\320\265\321\202\320\265\321\200\320\261\321\203\321\200\320\263\320\265"
  5: "\320\241\320\260\320\275\320\272\321\202-\320\237\320\265\321\202\320\265\321\200\320\261\321\203\321\200\320\263\320\265"
  6: "sankt-peterburg"
  7: 2
}
2 {
  1: "\224\331\203\202B\303\021\346\224\031RT\000\020\266\010"
  2: "\260\336\t\360I\026I\006\217\232t\2021T\030B"
  3: "\320\237\321\217\321\202\321\221\321\200\320\276\321\207\320\272\320\260"
  4: "https://leonardo.edadeal.io/dyn/re/retailers/images/icons/sq/85cd6908f8a34aefbe66dd1948cc3d39.png"
  5: "https://leonardo.edadeal.io/dyn/re/retailers/images/logos/sq/992af68cffaa47de9ff23079648074ad.png"
  6: "eb2316"
  7: 733
  8: 55
  9: 425
  10: "5ka"
}
2 {
  1: "\224\331\205\336B\303\021\346\224\031RT\000\020\266\010"
  2: "\260\336\t\360I\026I\006\217\232t\2021T\030B"
  3: "\320\224\320\270\320\272\321\201\320\270"
  4: "https://leonardo.edadeal.io/dyn/re/retailers/images/icons/sq/146db05ebc81464cbf4872675cb2e761.png"
  5: "https://leonardo.edadeal.io/dyn/re/retailers/images/logos/sq/9c2b2c291f134929949fa4daab88252f.png"
  6: "FF8A38"
  7: 691
  8: 61
  9: 276
  10: "dixy"
}

【问题讨论】:

标签: python protocol-buffers


【解决方案1】:

如果您无法获得架构,这在很大程度上是基于反复试验的。但是,我可以告诉你,这里的根对象看起来不像一个列表 (repeated) - 这是真的

  1. 每个子项都有相同的字段编号(它们没有,1 对 2)
  2. 每个子项都具有相同的形状(它们没有,请参阅字段 4,文本与子对象)

所以你的根对象有这样的东西:

optional Foo foo = 1;
optional Bar bar = 2;

【讨论】:

  • @swor 我不能告诉你名字 - 二进制内容不包括 - 我只知道它们是不同的。您需要分别对有效负载进行逆向工程。大概其中之一就是您称为City 的类型。另一个是不同的形状,所以它是别的东西。我不会说俄语,也不知道上下文是什么,所以...
  • @swor 与网站截图内容基本相同。这里的实际问题是什么?我无法告诉您这些字段是什么或意味着什么。有一些明显的文本字段和一些整数字段(虽然我不能告诉你它们是否有符号)。几个字段(第一个消息类型中的字段 1,以及第二个消息类型中的字段 1 和 2)可能是 bytes,但我不能告诉你字节代表什么。
  • @swor btw 第一条消息中的字段 4 可能是“持续时间”或“时间戳”(可能是“时间戳” - 2005 年 4 月 27 日有什么意义吗?)
  • @swor 也是,16 字节表示“guid”/“uuid”,但我不能告诉你哪种字节序/布局(使用多种约定)
  • @swor 定义“消除”。对我来说,没有一条消息看起来“不好”。如果你不关心数据,当然:你可以忽略它。
【解决方案2】:

对不起,如果这已经过时了,但是如果您查看在该页面上运行的 js,就会有一些用于解码这些对象的代码:

  t.id && t.hasOwnProperty("id") && e.uint32(10).bytes(t.id),
                                null != t.description && t.hasOwnProperty("description") && e.uint32(18).string(t.description),
                                null != t.imageUrl && t.hasOwnProperty("imageUrl") && e.uint32(26).string(t.imageUrl),
                                null != t.priceOld && t.hasOwnProperty("priceOld") && e.uint32(37).float(t.priceOld),
                                null != t.priceNew && t.hasOwnProperty("priceNew") && e.uint32(45).float(t.priceNew),
                                null != t.priceIsFrom && t.hasOwnProperty("priceIsFrom") && e.uint32(48).bool(t.priceIsFrom),
                                t.segmentId && t.hasOwnProperty("segmentId") && e.uint32(58).bytes(t.segmentId),
                                null != t.quantity && t.hasOwnProperty("quantity") && e.uint32(69).float(t.quantity),
                                null != t.quantityUnit && t.hasOwnProperty("quantityUnit") && e.uint32(74).string(t.quantityUnit),
                                null != t.discount && t.hasOwnProperty("discount") && e.uint32(85).float(t.discount),
                                null != t.discountUnit && t.hasOwnProperty("discountUnit") && e.uint32(90).string(t.discountUnit),
                                null != t.discountLabel && t.hasOwnProperty("discountLabel") && e.uint32(98).string(t.discountLabel),
                                null != t.discountPercent && t.hasOwnProperty("discountPercent") && e.uint32(104).uint32(t.discountPercent),
                                null != t.country && t.hasOwnProperty("country") && e.uint32(114).string(t.country),
                                null != t.dateStart && t.hasOwnProperty("dateStart") && e.uint32(122).string(t.dateStart),
                                null != t.dateEnd && t.hasOwnProperty("dateEnd") && e.uint32(130).string(t.dateEnd),
                                t.metaId && t.hasOwnProperty("metaId") && e.uint32(138).bytes(t.metaId),
                                t.compilationIds && t.compilationIds.length)
                                    for (var r = 0; r < t.compilationIds.length; ++r)
                                        e.uint32(146).bytes(t.compilationIds[r]);
                                if (t.brandIds && t.brandIds.length)
                                    for (r = 0; r < t.brandIds.length; ++r)
                                        e.uint32(154).bytes(t.brandIds[r]);

也许这样更容易对 protobuf 架构进行逆向工程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    • 2021-03-17
    • 2011-10-08
    • 1970-01-01
    相关资源
    最近更新 更多