将二进制文件转换为原始文件

2024-09-29 07:29:52 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我想找到二进制文件的.proto结构

因此,我将该文件添加到站点--https://protogen.marcgravell.com/decode/

收到

enter image description here

我创建了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"
}

Tags: 文件httpsiorestringpng二进制sq
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模式进行反向工程

如果您无法获得模式,那么这主要是基于试错的。但是,我可以告诉您,这里的根对象看起来不像一个列表(repeated)——这是真的

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

因此,您的根对象有如下内容:

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

相关问题 更多 >