I am writing a self-modifying program; already got it working. I found these two functions, but not sure what EXACTLY they do and I like to comment my code proper.
pagesize is got using getpagesize
/*
* Defining variables:
* func - function in memory I'm using mprotect on
* offset - the offset in memory
* ptr - the pointer to the memory
*/
unsigned int offset = (unsigned int)( ((long)func) & (pagesize-1) );
unsigned char * ptr = (unsigned char *) ((long)func & (~(pagesize-1) ) );
I have found offset's function being used for memory alignment checks. I know vaguely what they do, but not the difference?
Thanks.