Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python3-字节读取未返回预期值_Python_Python 3.x - Fatal编程技术网

Python3-字节读取未返回预期值

Python3-字节读取未返回预期值,python,python-3.x,Python,Python 3.x,我当前正在读取一个文件,并试图将字节值与测试变量进行比较。我的比较总是错误的,因为我没有返回预期值 我的代码: def grey(self, varexec): offsets = [0x388e93] write = b'\x02' test1 = b'\x02' test2 = b'\x30' test3 = b'\x10' test4 = b'\x00' for offset in offsets: with open(varexec, 'rb') as offsetwrite

我当前正在读取一个文件,并试图将字节值与测试变量进行比较。我的比较总是错误的,因为我没有返回预期值

我的代码:

def grey(self, varexec):
offsets = [0x388e93]
write = b'\x02'

test1 = b'\x02'
test2 = b'\x30'
test3 = b'\x10'
test4 = b'\x00'

for offset in offsets:
    with open(varexec, 'rb') as offsetwriter:
        offsetwriter.seek(offset)
        offsetwriter.seek(6,1)
        print(offsetwriter.read(2))
我希望打印(offsetwriter.read(2))返回 b'\x14' 根据下面的说明,但不是这样。没有这个,我不能使用if语句,因为它总是返回false,从而导致else

CPU Disasm
Address   Hex dump          Command                                  Comments
00788E93  |.  6A 01         PUSH 1                                   ; |Arg8 = 1
00788E95  |.  6A 0C         PUSH 0C                                  ; |Arg7 = 0C
00788E97  |.  51            PUSH ECX                                 ; |Arg6
00788E98  |.  8D50 14       LEA EDX,[EAX+14]                         ; |
00788E9B  |.  6A 30         PUSH 30                                  ; |Arg5 = 30
00788E9D  |.  52            PUSH EDX                                 ; |Arg4
00788E9E  |.  68 0C030000   PUSH 30C                                 ; |Arg3 = 30C
00788EA3  |.  50            PUSH EAX                                 ; |Arg2 => [LOCAL.1455]
00788EA4  |.  68 8F020000   PUSH 28F                                 ; |Arg1 = 28F
当我运行脚本时,我得到:

b'P\x14'
“p”是“\x50”。你差一点就走了。此外,“\x14”是1字节,您正在读取2