MCPcopy Create free account
hub / github.com/acl-dev/acl / AllocExeHelper

Function AllocExeHelper

lib_fiber/cpp/src/detours/creatwth.cpp:1222–1324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1220}
1221
1222static
1223BOOL WINAPI AllocExeHelper(_Out_ PDETOUR_EXE_HELPER *pHelper,
1224 _In_ DWORD dwTargetPid,
1225 _In_ DWORD nDlls,
1226 _In_reads_(nDlls) LPCSTR *rlpDlls)
1227{
1228 PDETOUR_EXE_HELPER Helper = NULL;
1229 BOOL Result = FALSE;
1230 _Field_range_(0, cSize - 4) DWORD cOffset = 0;
1231 DWORD cSize = 4;
1232
1233 if (pHelper == NULL) {
1234 goto Cleanup;
1235 }
1236 *pHelper = NULL;
1237
1238 if (nDlls < 1 || nDlls > 4096) {
1239 SetLastError(ERROR_INVALID_PARAMETER);
1240 goto Cleanup;
1241 }
1242
1243 for (DWORD n = 0; n < nDlls; n++) {
1244 HRESULT hr;
1245 size_t cchDest = 0;
1246
1247 hr = StringCchLengthA(rlpDlls[n], 4096, &cchDest);
1248 if (!SUCCEEDED(hr)) {
1249 goto Cleanup;
1250 }
1251
1252 cSize += (DWORD)cchDest + 1;
1253 }
1254
1255 Helper = (PDETOUR_EXE_HELPER) new NOTHROW BYTE[sizeof(DETOUR_EXE_HELPER) + cSize];
1256 if (Helper == NULL) {
1257 goto Cleanup;
1258 }
1259
1260 Helper->cb = sizeof(DETOUR_EXE_HELPER) + cSize;
1261 Helper->pid = dwTargetPid;
1262 Helper->nDlls = nDlls;
1263
1264 for (DWORD n = 0; n < nDlls; n++) {
1265 HRESULT hr;
1266 size_t cchDest = 0;
1267
1268 if (cOffset > 0x10000 || cSize > 0x10000 || cOffset + 2 >= cSize) {
1269 goto Cleanup;
1270 }
1271
1272 if (cOffset + 2 >= cSize || cOffset + 65536 < cSize) {
1273 goto Cleanup;
1274 }
1275
1276 _Analysis_assume_(cOffset + 1 < cSize);
1277 _Analysis_assume_(cOffset < 0x10000);
1278 _Analysis_assume_(cSize < 0x10000);
1279

Callers 2

Calls 1

StringCchCopyAFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…