2

我运行一些脚本,出现以下错误:

TypeError: 62 的类型为 < type 'int' >,但应为以下之一:( < type 'str' >, < type 'unicode' >)

错误的原因尚不清楚。从终端运行脚本 - 发出此错误。在 proto 文件中,为值 62 请求的字段是必需的 uint32。问题可能出在哪里?

我应用全屏输出:

在此处输入图像描述

这里有这样的功能:

def get_patch_info(self):
        if self.mode == "manual":
            pi = patch_symbol.resolve(self.bf_old.elf, self.bf_new.elf)
        elif self.mode == "auto":
            raise Exception("Not implemented")
        else:
            print "Unknown patch mode: \"%s\"" % self.mode

        if not pi.func_jumps:
            raise Exception("No functions to patch")

        for fj in pi.func_jumps:
            if fj.func_size < MIN_FUNC_SIZE:
                raise Exception("Function '%s' size less than minimal: %d < %d" %
                            fj.name, fj.func_size, MIN_FUNC_SIZE)

        print "\n*************************************************"
        print "***************** Patch info ********************"
        print "*************************************************\n"

        pi.old_bid = get_build_id(self.bf_old.elf)
        pi.new_bid = get_build_id(self.bf_new.elf)

        pi.new_arch_type = ENUM_E_MACHINE[self.bf_new.elf.header.e_machine]


        print "Header:"
        print "  Target BuildId: %s" % pi.old_bid
        print "  Patch BuildId : %s" % pi.new_bid
        print "  Architecture on which patch is built : %u" % pi.new_arch_type

        if self.patchfile:
            pi.new_path = self.bf_new.filename
            print "  Patch path    : %s" % pi.new_path

        self.pi = pi

有这样一个proto文件:

import "funcjump.proto";
import "markedsym.proto";
import "staticsym.proto";

message BinPatch {
    required string     old_bid     = 1;
    required string     new_bid     = 2;
    optional string     new_path    = 3;
    repeated FuncJump   func_jumps  = 4;
    repeated MarkedSym  manual_symbols  = 5;
    repeated StaticSym  static_symbols  = 6;
    repeated MarkedSym  global_symbols  = 7;
    required uint32     new_arch_type   = 8;
}

因此,错误发生在该行:

pi.new_arch_type = ENUM_E_MACHINE[self.bf_new.elf.header.e_machine]

如果我用一些修改重写代码一切正常。为此,我必须遵循以下修改: 1)我必须在 proto中替换required uint32 new_arch_type = 8;on ;required string new_arch_type = 8;2)我必须在功能pi.new_arch_type = ENUM_E_MACHINE [self.bf_new.elf.header.e_machine]上更换 所以一切正常。但这适用于字符串。我需要使用枚举处理数字。但是,如果我根据上述情况(使用枚举处理数字)工作,则会出现上述错误。pi.new_arch_type = self.bf_new.elf.header.e_machineget_patch_info(self);

4

0 回答 0