Results 1 to 2 of 2

Thread: mprotect regions made with dlopen

  1. #1
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts

    mprotect regions made with dlopen

    [20:53] php: do u know how to mprotect regions made with dlopen
    PHP Code:
    int unprotect_lib(char *libname)
    {
        
    char buf[512];
        
    char flags[4];
        
    void *low, *high;
        
    FILE *fp;
        
    fp fopen("/proc/self/maps""r");
        if ( ! 
    fp)
            return 
    0;
        while (
    fgets(bufsizeof(buf), fp))
        {
            if ( ! 
    strstr(buflibname))
                continue;
            if (
    sscanf (buf"%p-%p %4c", &low, &highflags) != 3)
                continue;
            
    //printf(buf);
            //printf("%08x %08x diff:%.8p\n", low, high, (int)high-(int)low);
            
    mprotect((void *)low, (int)high-(int)lowPROT_READ PROT_WRITE PROT_EXEC);
        }
        
    fclose(fp);
        return 
    1;

    For dlopen("bla") it should be unprotect_lib("bla");

    You can look in /proc/self/maps or /proc/$pid/maps for the actual loaded maps at runtime.
    timescale 0.01

  2. The Following User Says Thank You to kung foo man For This Useful Post:

    php (23rd February 2014)

  3. #2
    Private First Class php's Avatar
    Join Date
    Nov 2012
    Posts
    142
    Thanks
    28
    Thanked 116 Times in 59 Posts
    Thanks for this, maybe it'll help someone else too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •