Skip to content

Instantly share code, notes, and snippets.

@soda92
Created April 27, 2022 05:28
Show Gist options
  • Save soda92/00241e62b287ed40f0049869ac002311 to your computer and use it in GitHub Desktop.
Save soda92/00241e62b287ed40f0049869ac002311 to your computer and use it in GitHub Desktop.
python ctype pointer cast
#include <stdio.h>
#include <stdbool.h>
int main()
{
int t = 0xaabbccdd;
bool * p = (bool *)&t;
printf("%x\n", *p);
printf("%x\n", *(p+1));
printf("%x\n", *(p+2));
printf("%x\n", *(p+3));
}
from ctypes import *
t = c_int(0x10)
pt = pointer(t)
pt_casted = cast(pt, POINTER(c_byte))
pt_casted[0] = 0x10
pt_casted[1] = 0x11
print(t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment