Skip to content

how to change data in pagein hooked function #6

@sdhzdmzzl

Description

@sdhzdmzzl

Hi,slavaim:
I used this code to modify some data , read write rename truncate all works.
but I don't know how to modify data in pagein and pageout procedure.
my code like belows:
`int
FltVnopPageinHook(
__in struct vnop_pagein_args *ap
)

{
int (origVnop)(struct vnop_pagein_args ap);
origVnop = (int (
)(struct vnop_pagein_args
))FltGetOriginalVnodeOp( ap->a_vp, FltVopEnum_pagein );
assert( origVnop );

char procname[1024] ={0};
proc_selfname( procname, 1024);
int ret = origVnop( ap );
if(0 == strcmp("test", procname))
{
    char path[1024] = {0};
    int len = 1024;
    vn_getpath(ap->a_vp, path, &len);
    int flags =UPL_RET_ONLY_DIRTY;
    vm_offset_t map = NULL;
    vm_offset_t map1 = NULL;
    upl_t upl = NULL;
    upl_page_info_t* uplpageinfo = NULL;
    if(ap->a_flags&UPL_MSYNC)
    {
        flags = flags | UPL_UBC_MSYNC;
    }
    else{
        flags = flags | UPL_UBC_PAGEIN;
    }
    //ubc_create_upl(ap->a_vp, ap->a_f_offset, ap->a_size, &upl, &uplpageinfo, UPL_UBC_PAGEIN|UPL_RET_ONLY_ABSENT);
    ubc_create_upl(ap->a_vp, ap->a_f_offset, ap->a_size, &upl, &uplpageinfo, UPL_UBC_PAGEIN|UPL_FLAGS_NONE);
    //ubc_upl_map(ap->a_pl, &map);
    ubc_upl_map(upl, &map1);
    char *p = (char*)map1;
    *p = '5';
    if(map1)
    {
        ubc_upl_unmap(upl);
    }
    if(upl)
    {
        ubc_upl_commit(upl);
        //ubc_upl_abort_range(upl,  ap->a_f_offset, ap->a_size, UPL_ABORT_FREE_ON_EMPTY);
    }
}
return ret;

}
`
for example, If a text file which content is "aaaa", after hook pagein function, I want the user who view it to see its content as "5aaa",but above codes don't work.
thanks for your reply.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions