首页 > 其他分享 >protobuf js逆向

protobuf js逆向

时间:2023-11-19 21:47:41浏览次数:32  
标签:逆向 protobuf buffer age js let AwesomeMessage name

1.proto

syntax = "proto3";
message Person{
  string name = 1;// name标识 1顺序
  int32 age = 2 ; // age标识 2顺序
}

2.protobufjs

let protobuf = require("protobufjs");   //npm install -g protobufjs
protobuf.load("1.proto", function (err, root) {
    if (err) {
        throw err
    }
    ;
    let AwesomeMessage = root.lookupType("Person");
    let payload = {"name": "zhiyuan", "age": 18};
    // 10,7,122,184,185,121,117,97,110,16,18
    let message = AwesomeMessage.create(payload);
    debugger;
    let buffer_finish = AwesomeMessage.encode(message);
    let buffer = buffer_finish.finish();
    let test = AwesomeMessage.decode(buffer);
    debugger;
    console.log(buffer)
    console.log(test)
});


// (function anonymous(Writer, types, util
// ) {
//     return function Person$encode(m, w) {
//         if (!w)
//             w = Writer.create()
//         if (m.name != null && Object.hasOwnProperty.call(m, "name"))
//             w.uint32(10).string(m.name)
//         if (m.age != null && Object.hasOwnProperty.call(m, "age"))
//             w.uint32(16).int32(m.age)
//         return w
//     }
// })

  

 

标签:逆向,protobuf,buffer,age,js,let,AwesomeMessage,name
From: https://www.cnblogs.com/yoyo1216/p/17842717.html

相关文章