C # port code in Java

Next problem: I have a C # program that does some decryption at a very low level. I used the tool to convert most of C # code to Java, which worked for most things, but when it comes to such low-level parts, the tool crashes. The following data structure is used internally:

[StructLayout(LayoutKind.Explicit)]
        private struct ByteUInt
        {
            [FieldOffset(0)]
            public byte Byte0;

            [FieldOffset(1)]
            public byte Byte1;

            [FieldOffset(2)]
            public byte Byte2;

            [FieldOffset(3)]
            public byte Byte3;

            [FieldOffset(0)]
            public uint FullUint;
        }

In the program, the bytes and uint inside this structure are changed several times separately, for example. for example, MyByteUint.Byte0 &= someByte;or MyMyteUint.FullUint = someByte & 0x0For some other bitwise operations. Since uint refers to the same memory as 4 bytes, if I change one of them, uint will also change and vice versa.

Java , , ​​ Java, . - , , uint/bytes ?

.

+4
1

, () byte int.

Java. :

  • byte , .
  • int - .
  • ; / C ++ JNI JNA Java.

IntBuffer ByteBuffer. (IMO) /, , NIO I/O ( I/O + / ), .


, . Java- , .... , .

+3
source

All Articles