Beispiel #1
0
        public static void CompactEXE(ref byte[] exefile)
        {
            if (ByteConverter.ToUInt16(exefile, 0) != 0x5A4D)
            {
                return;
            }
            int ptr = ByteConverter.ToInt32(exefile, 0x3c);

            if (ByteConverter.ToInt32(exefile, (int)ptr) != 0x4550)             //PE\0\0
            {
                return;
            }
            ptr += 4;
            UInt16 numsects = ByteConverter.ToUInt16(exefile, (int)ptr + 2);

            ptr += 0x14;
            int  PEHead    = ptr;
            uint imageBase = ByteConverter.ToUInt32(exefile, ptr + 28);

            byte[] result = new byte[ByteConverter.ToInt32(exefile, ptr + 0xe0 + ((int)SectOffs.Size * (numsects - 1)) + (int)SectOffs.FAddr) + ByteConverter.ToInt32(exefile, ptr + 0xe0 + ((int)SectOffs.Size * (numsects - 1)) + (int)SectOffs.FSize)];
            Array.Copy(exefile, result, ByteConverter.ToUInt32(exefile, ptr + 60));
            ptr += 0xe0;
            for (int i = 0; i < numsects; i++)
            {
                Array.Copy(exefile, ByteConverter.ToInt32(exefile, ptr + (int)SectOffs.VAddr), result, ByteConverter.ToInt32(exefile, ptr + (int)SectOffs.FAddr), ByteConverter.ToInt32(exefile, ptr + (int)SectOffs.FSize));
                ptr += (int)SectOffs.Size;
            }
            exefile = result;
        }
Beispiel #2
0
 public override int ReadInt32()
 {
     return(ByteConverter.ToInt32(ReadBytes(sizeof(int)), 0));
 }