Skip to content

Commit 41fc5c8

Browse files
authored
Update detours vcpkg to use prior version (microsoft#5601)
## Change Starting with the time that the UndockedRegFreeWinRT change was introduced and working backward through commits, I found the equivalent one (only whitespace changes are present, probably due to auto-formatting). This change uses the existing overlay infrastructure to update the detours port to that commit.
1 parent c84f06c commit 41fc5c8

File tree

7 files changed

+132
-5
lines changed

7 files changed

+132
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ settings.json
2020
[Rr]eleases/
2121
x64/
2222
x86/
23+
arm64/
2324
AnyCPU/
2425
Fuzzing/
2526
bld/

src/VcpkgPortOverlay/CreatePortOverlay.ps1

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,44 @@ function Add-PatchToPortFile
208208
$modifiedPortFile | Out-File $portFilePath
209209
}
210210

211+
# Removes all patches from portfile.cmake
212+
function Remove-PortPatches
213+
{
214+
param(
215+
[Parameter(Mandatory)]
216+
[string]$Port
217+
)
218+
219+
# Look for the line that says "PATCHES"
220+
221+
$portFilePath = Join-Path $OverlayRoot $Port "portfile.cmake"
222+
$originalPortFile = Get-Content $portFilePath
223+
224+
$modifiedPortFile = @()
225+
foreach ($line in $originalPortFile)
226+
{
227+
if ($line.TrimEnd().EndsWith("PATCHES"))
228+
{
229+
$foundPatches = $true
230+
}
231+
elseif ($line -eq ")")
232+
{
233+
$foundParen = $true
234+
$modifiedPortFile += $line
235+
}
236+
elseif ($foundPatches -and -not $foundParen)
237+
{
238+
# Drop line
239+
}
240+
else
241+
{
242+
$modifiedPortFile += $line
243+
}
244+
}
245+
246+
$modifiedPortFile | Out-File $portFilePath
247+
}
248+
211249
# Adds a patch to a port
212250
function Add-PatchToPort
213251
{
@@ -275,13 +313,12 @@ function Update-PortSource
275313
[Parameter(Mandatory)]
276314
[string]$Commit,
277315
[Parameter(Mandatory)]
278-
[string]$SourceHash
316+
[string]$SourceHash,
317+
[string]$RefPattern = '[0-9a-f]{40}( #.*)?$'
279318
)
280319

281-
$portDir = Join-Path $OverlayRoot $Port
282-
283320
# For the REF, we also delete any comments after it that may say the wrong version
284-
Set-ParameterInPortFile $Port -ParameterName 'REF' -CurrentValuePattern '[0-9a-f]{40}( #.*)?$' -NewValue "$Commit # Unreleased"
321+
Set-ParameterInPortFile $Port -ParameterName 'REF' -CurrentValuePattern $RefPattern -NewValue "$Commit # Unreleased"
285322
Set-ParameterInPortFile $Port -ParameterName 'SHA512' -CurrentValuePattern '[0-9a-f]{128}' -NewValue $SourceHash
286323
}
287324

@@ -302,6 +339,10 @@ function Update-PortVersion
302339
New-PortOverlay cpprestsdk -Version 2.10.18 -PortVersion 4
303340
Add-PatchToPort cpprestsdk -PatchRepo 'microsoft/winget-cli' -PatchCommit '888b4ed8f4f7d25cb05a47210e083fe29348163b' -PatchName 'add-server-certificate-validation.patch' -PatchRoot 'src/cpprestsdk/cpprestsdk'
304341

342+
New-PortOverlay detours -Version 4.0.1 -PortVersion 8
343+
Update-PortSource detours -RefPattern 'v4.0.1' -Commit '404c153ff390cb14f1787c7feeb4908c6d79b0ab' -SourceHash '1f3f26657927fa153116dce13dbfa3319ea368e6c9017f4999b6ec24d6356c335b3d5326718d3ec707b92832763ffea092088df52596f016d7ca9b8127f7033d'
344+
Remove-PortPatches detours
345+
305346
New-PortOverlay libyaml -Version 0.2.5 -PortVersion 5
306347
Update-PortSource libyaml -Commit '840b65c40675e2d06bf40405ad3f12dec7f35923' -SourceHash 'de85560312d53a007a2ddf1fe403676bbd34620480b1ba446b8c16bb366524ba7a6ed08f6316dd783bf980d9e26603a9efc82f134eb0235917b3be1d3eb4b302'
307348
Update-PortVersion libyaml

src/VcpkgPortOverlay/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@ Note that we use v2.10.18, which is not the latest.
1212

1313
Changes:
1414
* Add patch file: `add-server-certificate-validation.patch`
15-
Patch source: https://github.com/microsoft/winget-cli/commit/888b4ed8f4f7d25cb05a47210e083fe29348163b
15+
* Patch source: https://github.com/microsoft/winget-cli/commit/888b4ed8f4f7d25cb05a47210e083fe29348163b
16+
17+
## detours
18+
19+
We use the version used by UndockedRegFreeWinRT (https://github.com/microsoft/winget-cli/tree/release-v1.10/src/Xlang/UndockedRegFreeWinRT/src/UndockedRegFreeWinRT/detours).
20+
The only official release of detours (4.0.1) does not include complete support for ARM64.
21+
While the exact version that we pulled from UndockedRegFreeWinRT is unclear (https://github.com/microsoft/xlang/pull/644), through manually comparing versions it is equivalent to
22+
https://github.com/microsoft/Detours/commit/404c153ff390cb14f1787c7feeb4908c6d79b0ab (only some whitespace changes are present).
23+
24+
Changes:
25+
* New source commit: https://github.com/microsoft/Detours/commit/404c153ff390cb14f1787c7feeb4908c6d79b0ab
26+
* Remove the patch on the official port as it is already present in the newer commit
1627

1728
## libyaml
1829

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/src/detours.cpp b/src/detours.cpp
2+
index 8345c4d..3cd0e9d 100644
3+
--- a/src/detours.cpp
4+
+++ b/src/detours.cpp
5+
@@ -974,6 +974,19 @@ inline PBYTE detour_skip_jmp(PBYTE pbCode, PVOID *ppGlobals)
6+
return pbCode;
7+
}
8+
9+
+inline void detour_find_jmp_bounds(PBYTE pbCode,
10+
+ PDETOUR_TRAMPOLINE *ppLower,
11+
+ PDETOUR_TRAMPOLINE *ppUpper)
12+
+{
13+
+ // We have to place trampolines within +/- 2GB of code.
14+
+ ULONG_PTR lo = detour_2gb_below((ULONG_PTR)pbCode);
15+
+ ULONG_PTR hi = detour_2gb_above((ULONG_PTR)pbCode);
16+
+ DETOUR_TRACE(("[%p..%p..%p]\n", lo, pbCode, hi));
17+
+
18+
+ *ppLower = (PDETOUR_TRAMPOLINE)lo;
19+
+ *ppUpper = (PDETOUR_TRAMPOLINE)hi;
20+
+}
21+
+
22+
inline BOOL detour_does_code_end_function(PBYTE pbCode)
23+
{
24+
ULONG Opcode = fetch_opcode(pbCode);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
2+
3+
vcpkg_from_github(
4+
OUT_SOURCE_PATH SOURCE_PATH
5+
REPO microsoft/Detours
6+
REF 404c153ff390cb14f1787c7feeb4908c6d79b0ab # Unreleased
7+
SHA512 1f3f26657927fa153116dce13dbfa3319ea368e6c9017f4999b6ec24d6356c335b3d5326718d3ec707b92832763ffea092088df52596f016d7ca9b8127f7033d
8+
HEAD_REF master
9+
)
10+
11+
vcpkg_build_nmake(
12+
SOURCE_PATH "${SOURCE_PATH}"
13+
PROJECT_SUBPATH "src"
14+
PROJECT_NAME "Makefile"
15+
OPTIONS "PROCESSOR_ARCHITECTURE=${VCPKG_TARGET_ARCHITECTURE}"
16+
OPTIONS_RELEASE "DETOURS_CONFIG=Release"
17+
OPTIONS_DEBUG "DETOURS_CONFIG=Debug"
18+
)
19+
20+
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
21+
file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/lib.${VCPKG_TARGET_ARCHITECTURE}Release/" DESTINATION "${CURRENT_PACKAGES_DIR}/lib")
22+
endif()
23+
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
24+
file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/lib.${VCPKG_TARGET_ARCHITECTURE}Debug/" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib")
25+
endif()
26+
27+
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
28+
file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/include/" DESTINATION "${CURRENT_PACKAGES_DIR}/include" RENAME detours)
29+
else()
30+
file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/include/" DESTINATION "${CURRENT_PACKAGES_DIR}/include" RENAME detours)
31+
endif()
32+
33+
file(INSTALL "${SOURCE_PATH}/LICENSE.md" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
34+
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")

src/VcpkgPortOverlay/detours/usage

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
detours can be used from CMake via:
2+
3+
find_path(DETOURS_INCLUDE_DIRS "detours/detours.h")
4+
find_library(DETOURS_LIBRARY detours REQUIRED)
5+
6+
target_include_directories(main PRIVATE ${DETOURS_INCLUDE_DIRS})
7+
target_link_libraries(main PRIVATE ${DETOURS_LIBRARY})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "detours",
3+
"version": "4.0.1",
4+
"port-version": 8,
5+
"description": "Detours is a software package for monitoring and instrumenting API calls on Windows.",
6+
"homepage": "https://github.com/microsoft/Detours",
7+
"license": "MIT",
8+
"supports": "windows & !uwp"
9+
}

0 commit comments

Comments
 (0)