Java 无符号字符数组

发布于 2024-07-14 15:32:27 字数 230 浏览 12 评论 0原文

我正在开发一个模糊媒体播放器的项目。 我用Java编写了文件生成器,并从用C编写的原始压缩代码转换了CRC生成器。我可以使用DataOutputStream很好地编写数据,但我不知道如何在java中将数据作为无符号字符数组发送。 在 C 语言中,这是一个非常简单的过程。 我已经非常彻底地搜索了解决方案,我找到的最佳解决方案是将数据发送到 C 并让 C 返回 CRC。 我可能没有正确搜索,因为我对这些东西很不熟悉。 非常感谢您的帮助。

I'm working on a project fuzzing a media player. I wrote the file generator in Java and converted the CRC generator from the original compression code written in C. I can write data fine with DataOutputStream, but I can't figure out how to send the data as an unsigned character array in java. In C this is a very straightforward process. I have searched for a solution pretty thoroughly, and the best solution I've found is to just send the data to C and let C return a CRC. I may just not be searching correctly as I'm pretty unfamiliar with this stuff. Thank you very much for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉城凉梦凉人心 2024-07-21 15:32:27

你肯定想要一个字节[]。 “byte”相当于 C 中的signed char。Java 的“char”是一个 16 位 unicode 值,实际上根本不等价。

如果是用于模糊测试,除非您使用的 CRC 函数有特殊之处,否则我想您可以简单地使用:

import java.util.Random;
Random randgen = new Random();

byte[] fuzzbytes = new byte[numbytes];
randgen.nextBytes(fuzzbytes);
outstream.write(fuzzbytes, 0, numbytes);

You definitely want a byte[]. A 'byte' is equivalent to a signed char in C. Java's "char" is a 16-bit unicode value and not really equivalent at all.

If it's for fuzzing, unless there's something special about the CRC function you're using, I imagine you could simply use:

import java.util.Random;
Random randgen = new Random();

byte[] fuzzbytes = new byte[numbytes];
randgen.nextBytes(fuzzbytes);
outstream.write(fuzzbytes, 0, numbytes);
奈何桥上唱咆哮 2024-07-21 15:32:27

我怀疑你想对角色做任何事情。 我在您的描述中看不到任何暗示文本操作的内容,这就是您对字符所做的操作。

您想使用字节数组。 在 Java 中对字节进行签名有点麻烦,但字节数组就是您所拥有的 - 只需使用位模式而不是将它们视为实际数字,并仔细检查每个操作。

I doubt that you want to do anything with characters. I can't see anything in your description which suggests text manipulation, which is what you'd do with characters.

You want to use a byte array. It's a bit of a pain that bytes are signed in Java, but a byte array is what you've got - just work with the bit patterns rather than thinking of them as actual numbers, and check each operation carefully.

思慕 2024-07-21 15:32:27

大多数 CRC 运算符主要使用按位移位和 XOR。 这些在 Java 上应该可以正常工作,因为 Java 不支持无符号整数原语。 如果您需要其他算术才能正常工作,您可以尝试转换为short

Most CRC operators use mostly bitwise shifts and XORs. These should work fine on Java, which does not support unsigned integer primitives. If you need other arithmetic to work properly, you could try casting to a short.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文