python错误地编码字节码到字节中
我一直在研究一个项目,该项目比较了从用户输入生成的字节码与服务器上字节码。目前,前端是用Python编写的CLI。该应用程序只需在用户的本地计算机上打开字节码文件,然后将其与来自服务器的字节码进行比较。这就是某些代码的样子:
correct_data = requests.get(api endpoint).content
usr_data = open(bytecode file).read().encode('UTF-8')
if correct_data == usr_data:
print("Good!")
由于文件以字符串格式读取,因此我将字符串编码为UTF-8,以将其与服务器中的内容进行比较。服务器字节码看起来像这样:
10 0 6 1 2 6 1 3 6 1 4 6 1 5 6 1 6 6 1 7 6 1 8 6 1 9 6 1 10 6 1 11 6 1 12 6 1 13 6 1 14 6 1 15 1 2 4 0 8 3
此字节码是正确的。但是,当我尝试打开并从本地计算机编码相同的字节码文件时...
10 0 6 1 2 6 1 3 6 1 4 6 1 5 6 1 6 6 1 7 6 1 8 6 1 9 6 1 10 6 1 11 6 1 12 6 1 10 6 1 14 6 1 15 1 2 4 0 8 3
此字节码有一个非常有趣的更改。应该是6 1 13变成6 1 10,我似乎无法弄清楚原因。我确保以相同方式生成的确切文件相同。这是一个始终显示的问题。任何帮助都会很棒!
I've been working on a project which compares bytecode generated from user input to bytecode on a server. Currently, the front-end is a CLI, written in python. The application simply opens the bytecode file on the user's local machine and compares it against bytecode coming from a server. This is what some of the code looks like:
correct_data = requests.get(api endpoint).content
usr_data = open(bytecode file).read().encode('UTF-8')
if correct_data == usr_data:
print("Good!")
Since the file reads in a string format, I encode the string into UTF-8 to compare it against the contents from the server. The server bytecode looks something like this:
10
0
6
1
2
6
1
3
6
1
4
6
1
5
6
1
6
6
1
7
6
1
8
6
1
9
6
1
10
6
1
11
6
1
12
6
1
13
6
1
14
6
1
15
1
2
4
0
8
3
This bytecode is correct. But, when I try to open and encode the same bytecode file from the local machine...
10
0
6
1
2
6
1
3
6
1
4
6
1
5
6
1
6
6
1
7
6
1
8
6
1
9
6
1
10
6
1
11
6
1
12
6
1
10
6
1
14
6
1
15
1
2
4
0
8
3
There is one very interesting change in this bytecode. What was supposed to be 6 1 13 becomes 6 1 10 and I can't seem to figure out why. I've made sure that these are the same exact files generated in the same way. This is an issue that consistently shows up. Any help would be amazing!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论