I recently moved from inline assembly to high level language (C++) where I want to set the result from a value^0x1A3C into a short type pointer (WORD PTR) but I am getting the following error:
A value of type int cannot be used to initialize an entity of type short*
I got the problem when passing an int type to a short*:
void PacketEncrypt(Packet* packet, int sizeofpacket)
{
char* pointer;
pointer = ((char*)packet+sizeofpacket) -2;
short *pointer = packet->PacketSize^0x1A3C;
packet->Type += 0x0FFF7;
}
What I want the compiler to make:
0041585E 8B45 0C MOV EAX,DWORD PTR SS:[EBP+C]
00415861 8B4D 08 MOV ECX,DWORD PTR SS:[EBP+8]
00415864 8D5401 FE LEA EDX,DWORD PTR DS:[ECX+EAX-2]
00415868 8955 F8 MOV DWORD PTR SS:[EBP-8],EDX
0041586B 8B45 08 MOV EAX,DWORD PTR SS:[EBP+8]
0041586E 0FBF08 MOVSX ECX,WORD PTR DS:[EAX]
00415871 81F1 3C1A0000 XOR ECX,1A3C
00415877 8B55 F8 MOV EDX,DWORD PTR SS:[EBP-8]
0041587A 880A MOV WORD PTR DS:[EDX],CX
Assuming you want to write the calculated value to the location that
pointerpoints to:reinterpret_castmeans “take an object of one type and force it into another type”, and is the cast used to convert between pointers to unrelated types; the value is assigned as ifpointerpointed toshort. Note that this might cause undefined behaviour if the pointer doesn’t have the correct alignment forshort. In general,reinterpret_castremoves compile-time type checks, leaving the onus on the programmer to make sure the result is used correctly.