@@ -1169,12 +1169,16 @@ bool valapifromstring(const char* name, uint* value, int* value_size, bool print
1169
1169
if (!value or !DbgIsDebugging ())
1170
1170
return false ;
1171
1171
// explicit API handling
1172
- const char * apiname = strstr (name, " : " ); // the ':' character cannot be in a path: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions
1172
+ const char * apiname = strchr (name, ' : ' ); // the ':' character cannot be in a path: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions
1173
1173
bool noexports = false ;
1174
- if (!apiname)
1174
+ if (!apiname) // not found
1175
1175
{
1176
- apiname = strstr (name, " ?" ); // the '?' character cannot be in a path either
1177
- noexports = true ;
1176
+ apiname = strrchr (name, ' .' ); // kernel32.GetProcAddress support
1177
+ if (!apiname) // not found
1178
+ {
1179
+ apiname = strchr (name, ' ?' ); // the '?' character cannot be in a path either
1180
+ noexports = true ;
1181
+ }
1178
1182
}
1179
1183
if (apiname)
1180
1184
{
@@ -1204,71 +1208,73 @@ bool valapifromstring(const char* name, uint* value, int* value_size, bool print
1204
1208
}
1205
1209
else
1206
1210
{
1207
- wchar_t * szBaseName = wcschr (szModName, L ' \\ ' );
1208
- if (szBaseName )
1211
+ HMODULE mod = LoadLibraryExW (szModName, 0 , DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE );
1212
+ if (!mod )
1209
1213
{
1210
- szBaseName++;
1211
- HMODULE mod = LoadLibraryExW (szModName, 0 , DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
1212
- if (!mod)
1213
- {
1214
- if (!silent)
1215
- dprintf (" unable to load library %s\n " , szBaseName);
1216
- }
1217
- else
1214
+ if (!silent)
1215
+ dprintf (" unable to load library %s\n " , szModName);
1216
+ }
1217
+ else
1218
+ {
1219
+ uint addr = noexports ? 0 : (uint)GetProcAddress (mod, apiname);
1220
+ if (addr) // found exported function
1221
+ addr = modbase + (addr - (uint)mod); // correct for loaded base
1222
+ else // not found
1218
1223
{
1219
- uint addr = noexports ? 0 : (uint)GetProcAddress (mod, apiname);
1220
- if (addr) // found exported function
1221
- addr = modbase + (addr - (uint)mod); // correct for loaded base
1222
- else // not found
1224
+ if (scmp (apiname, " base" ) or scmp (apiname, " imagebase" ) or scmp (apiname, " header" )) // get loaded base
1225
+ addr = modbase;
1226
+ else if (scmp (apiname, " entry" ) or scmp (apiname, " oep" ) or scmp (apiname, " ep" )) // get entry point
1227
+ addr = modbase + GetPE32DataW (szModName, 0 , UE_OEP);
1228
+ else if (*apiname == ' $' ) // RVA
1223
1229
{
1224
- if (scmp (apiname, " base" ) or scmp (apiname, " imagebase" ) or scmp (apiname, " header" )) // get loaded base
1225
- addr = modbase;
1226
- else if (scmp (apiname, " entry" ) or scmp (apiname, " oep" ) or scmp (apiname, " ep" )) // get entry point
1227
- addr = modbase + GetPE32DataW (szModName, 0 , UE_OEP);
1228
- else if (*apiname == ' $' ) // RVA
1229
- {
1230
- uint rva;
1231
- if (valfromstring (apiname + 1 , &rva))
1232
- addr = modbase + rva;
1233
- }
1234
- else if (*apiname == ' #' ) // File Offset
1230
+ uint rva;
1231
+ if (valfromstring (apiname + 1 , &rva))
1232
+ addr = modbase + rva;
1233
+ }
1234
+ else if (*apiname == ' #' ) // File Offset
1235
+ {
1236
+ uint offset;
1237
+ if (valfromstring (apiname + 1 , &offset))
1238
+ addr = valfileoffsettova (modname, offset);
1239
+ }
1240
+ else
1241
+ {
1242
+ if (noexports) // get the exported functions with the '?' delimiter
1235
1243
{
1236
- uint offset ;
1237
- if (valfromstring (apiname + 1 , &offset))
1238
- addr = valfileoffsettova (modname, offset);
1244
+ addr = ( uint) GetProcAddress (mod, apiname) ;
1245
+ if (addr) // found exported function
1246
+ addr = modbase + (addr - (uint)mod); // correct for loaded base
1239
1247
}
1240
1248
else
1241
1249
{
1242
1250
uint ordinal;
1243
1251
if (valfromstring (apiname, &ordinal))
1244
1252
{
1245
- addr = noexports ? 0 : (uint)GetProcAddress (mod, (LPCSTR)(ordinal & 0xFFFF ));
1253
+ addr = (uint)GetProcAddress (mod, (LPCSTR)(ordinal & 0xFFFF ));
1246
1254
if (addr) // found exported function
1247
1255
addr = modbase + (addr - (uint)mod); // correct for loaded base
1248
1256
else if (!ordinal) // support for getting the image base using <modname>:0
1249
1257
addr = modbase;
1250
1258
}
1251
1259
}
1252
1260
}
1253
- FreeLibrary (mod);
1254
- if (addr) // found!
1255
- {
1256
- if (value_size)
1257
- *value_size = sizeof (uint);
1258
- if (hexonly)
1259
- * hexonly = true ;
1260
- *value = addr ;
1261
- return true ;
1262
- }
1261
+ }
1262
+ FreeLibrary (mod);
1263
+ if (addr) // found!
1264
+ {
1265
+ if (value_size)
1266
+ *value_size = sizeof (uint);
1267
+ if ( hexonly)
1268
+ *hexonly = true ;
1269
+ *value = addr ;
1270
+ return true ;
1263
1271
}
1264
1272
}
1265
- else if (!silent)
1266
- dputs (" unknown error" );
1267
1273
}
1268
1274
return false ;
1269
1275
}
1270
1276
int found = 0 ;
1271
- int kernelbase = -1 ;
1277
+ int kernel32 = -1 ;
1272
1278
DWORD cbNeeded = 0 ;
1273
1279
Memory<uint*> addrfound;
1274
1280
if (EnumProcessModules (fdProcessInfo->hProcess , 0 , 0 , &cbNeeded))
@@ -1282,7 +1288,7 @@ bool valapifromstring(const char* name, uint* value, int* value_size, bool print
1282
1288
wchar_t szModuleName[MAX_PATH] = L" " ;
1283
1289
if (GetModuleFileNameExW (fdProcessInfo->hProcess , hMods[i], szModuleName, MAX_PATH))
1284
1290
{
1285
- wchar_t * szBaseName = wcschr (szModuleName, L' \\ ' );
1291
+ wchar_t * szBaseName = wcsrchr (szModuleName, L' \\ ' );
1286
1292
if (szBaseName)
1287
1293
{
1288
1294
szBaseName++;
@@ -1292,8 +1298,8 @@ bool valapifromstring(const char* name, uint* value, int* value_size, bool print
1292
1298
ULONG_PTR funcAddress = (ULONG_PTR)GetProcAddress (hModule, name);
1293
1299
if (funcAddress)
1294
1300
{
1295
- if (!_wcsicmp (szBaseName, L" kernelbase .dll" ))
1296
- kernelbase = found;
1301
+ if (!_wcsicmp (szBaseName, L" kernel32 .dll" ))
1302
+ kernel32 = found;
1297
1303
uint rva = funcAddress - (uint)hModule;
1298
1304
addrfound[found] = (uint)hMods[i] + rva;
1299
1305
found++;
@@ -1311,13 +1317,13 @@ bool valapifromstring(const char* name, uint* value, int* value_size, bool print
1311
1317
*value_size = sizeof (uint);
1312
1318
if (hexonly)
1313
1319
*hexonly = true ;
1314
- if (kernelbase != -1 )
1320
+ if (kernel32 != -1 ) // prioritize kernel32 exports
1315
1321
{
1316
- *value = addrfound[kernelbase ];
1322
+ *value = addrfound[kernel32 ];
1317
1323
if (!printall or silent)
1318
1324
return true ;
1319
1325
for (int i = 0 ; i < found; i++)
1320
- if (i != kernelbase )
1326
+ if (i != kernel32 )
1321
1327
dprintf (fhex" \n " , addrfound[i]);
1322
1328
}
1323
1329
else
0 commit comments