windows-process.cc
//
//   getModuleBase: (name: string) -> number
//
// Returns a memory offset to the base of the module loaded into
// process memory. This is useful if the memory address you wish
// to read from is a known offset into a module's memory space.
//
> number
Returns a memory offset to the base of the module loaded into
process memory. This is useful if the memory address you wish
to read from is a known offset into a module's memory space.
> number Returns a memory offset to the base of the module loaded into process memory . This is useful if the memory address you wish to read from is a known offset into a module ' s memory space .
NAN_METHOD(getModuleBase) {
    if (info.Length() < 1 || !info[0]->IsString()) {
        Nan::ThrowError("Must provide module name as an argument.");
        return;
    }
    Nan::Utf8String moduleName(info[0]);
    auto hProcess = (HANDLE)info.Data().As<v8::External>()->Value();
    HMODULE *hModules;
    TCHAR name[MAX_PATH];
    DWORD sizeD;
    if (EnumProcessModulesEx(hProcess, 0, 0, &sizeD, LIST_MODULES_ALL))
    {
        hModules = (HMODULE *)malloc(sizeD);
        if (hModules)
        {
            if (EnumProcessModulesEx(hProcess, hModules, sizeD, &sizeD, LIST_MODULES_ALL))
            {
                size_t count = sizeD / sizeof(HMODULE);
                for (int i = 0; i < count; i++)
                {
                    if (!GetModuleFileNameEx(hProcess, hModules[i], name, sizeof(name)))
                    {
                        continue;
                    }
                    ci_string searchString(name);
                    if (searchString.rfind(*moduleName) != ci_string::npos)
                    {
                        MODULEINFO modInfo;
                        if (GetModuleInformation(hProcess, hModules[i], &modInfo, sizeof(modInfo)))
                        {
                            auto ptr = reinterpret_cast<uintptr_t>(modInfo.lpBaseOfDll);
                             Return the module pointer as a number. This cast from LPVOID
                             to JavaScript number triggers a warning for a possible data
                             loss if the sizes don't match up.
                             A 64-bit JavaScript number should be suffice to hold any
                             32 or 64 bit memory address, which is all that is needed at
                             this time.
                            info.GetReturnValue().Set(Nan::New<v8::Number>(ptr));
                        }
                    }
                }
            }
            else
            {
                Nan::ThrowError("Can't enum modules");
            }
            free(hModules);
        }
        else
        {
            Nan::ThrowError("Can't callocate memory for modules");
        }
    }
}
NAN_METHOD ( getModuleBase ) { if ( info . Length ( ) < 1 || ! info [ 0 ] -> IsString ( ) ) { Nan :: ThrowError ( " " ) ; return ; } Nan :: Utf8String moduleName ( info [ 0 ] ) ; auto hProcess = ( HANDLE ) info . Data ( ) . As < v8 :: External > ( ) -> Value ( ) ; HMODULE * hModules ; TCHAR name [ MAX_PATH ] ; DWORD sizeD ; if ( EnumProcessModulesEx ( hProcess , 0 , 0 , & sizeD , LIST_MODULES_ALL ) ) { hModules = ( HMODULE * ) malloc ( sizeD ) ; if ( hModules ) { if ( EnumProcessModulesEx ( hProcess , hModules , sizeD , & sizeD , LIST_MODULES_ALL ) ) { size_t count = sizeD / sizeof ( HMODULE ) ; for ( int i = 0 ; i < count ; i ++ ) { if ( ! GetModuleFileNameEx ( hProcess , hModules [ i ] , name , sizeof ( name ) ) ) { continue ; } ci_string searchString ( name ) ; if ( searchString . rfind ( * moduleName ) != ci_string :: npos ) { MODULEINFO modInfo ; if ( GetModuleInformation ( hProcess , hModules [ i ] , & modInfo , sizeof ( modInfo ) ) ) { auto ptr = reinterpret_cast < uintptr_t > ( modInfo . lpBaseOfDll ) ; info . GetReturnValue ( ) . Set ( Nan :: New < v8 :: Number > ( ptr ) ) ; } } } } else { Nan :: ThrowError ( " " ) ; } free ( hModules ) ; } else { Nan :: ThrowError ( " " ) ; } } }
getModuleBase: (name: string) -> number
Returns a memory offset to the base of the module loaded into
process memory.
getModuleBase : ( name : string ) - > number Returns a memory offset to the base of the module loaded into process memory .
// Can't get module filename, just skip it // Search the end of the enumerated process name for the argument. // // Return the module pointer as a number. This cast from LPVOID // to JavaScript number triggers a warning for a possible data // loss if the sizes don't match up. // // A 64-bit JavaScript number should be suffice to hold any // 32 or 64 bit memory address, which is all that is needed at // this time. //