Created
April 27, 2022 05:28
-
-
Save soda92/00241e62b287ed40f0049869ac002311 to your computer and use it in GitHub Desktop.
python ctype pointer cast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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