求问这一小段 c 程序在 Java 里怎么写。。。

2017-05-13 12:39:25 +08:00
 kokutou

就是根据情况读取有 1 个、2 个、或者 3 个字节,做些操作,然后得到输出。
这个输出的意义是个数组长度。

这段是用 ida 静态分析一个 delphi 程序得到的 c 伪代码。。。
为啥存个数组长度要存成这样了???
还是说是某个算法,然后编译器优化成这样了?
还是说是我想多了,这玩意就是恶心人防破解的?

输入 0x3d,输出 0x7a
输入 0x70 0x01,输出 0xe0
输入 0x76 0xb8 0x21,输出 0x08 0x5c 0x6c

#include <stdio.h>

int main() {
    unsigned long long i = 0;
    unsigned long long out = 0;

    // read 1 bit to i;
    i = 0x76;
    out = i;
    if (i > 0x3f) {
        // read 1 bit to i;
        i = 0xb8;
        out += (i - 1) << 6;
        printf("%lld\n", (i - 1) << 6);
        if (i > 0x7f) {
            // read 1 bit to i;
            i = 0x21;
            out += (i - 1) << 13;
            printf("%lld\n", (i - 1) << 13);
        }
    }

    //output*2
    printf("%lld %llx", out * 2, out * 2);

    return 0;
}

下面是截图:

1498 次点击
所在节点    问与答
1 条回复
kokutou
2017-05-14 12:53:30 +08:00
java 没有 unsigned,这样搞一下就好了:

```
private static int uByte(byte signedByte) {
return ((int) signedByte) & 0xff;
}

```

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/361065

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX