Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >正在填充WASAPI提供的音频端点缓冲区,无法播放声音

正在填充WASAPI提供的音频端点缓冲区,无法播放声音
EN

Stack Overflow用户
提问于 2020-12-13 15:36:16
回答 1查看 507关注 0票数 1

我尝试使用WASPAI接口通过默认的音频端点渲染器播放噪波。我正在尝试使用微软在这个页面上提供的代码:https://docs.microsoft.com/en-us/windows/win32/coreaudio/rendering-a-stream。我想写一个可以为这个代码样本生成噪声的类。

我尝试将有符号整数值和无符号整数值写入默认音频端点渲染器的缓冲区,并看到值正在写入缓冲区,但没有声音播放。

首先,我使用所需的方法和随机数生成器创建了一个头文件。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#pragma once

// RNG
#include <random>

template <typename T>
class Random {
public:
    Random(T low, T high) : mLow(low), mHigh(high), function(std::mt19937_64(__rdtsc())) {};

    T operator()() { 
        signed __int64 f =  function();

        return ((f  % ((signed __int64) mHigh + (signed __int64) mLow)) + (signed __int64) mLow); }

private:
    T mLow;
    T mHigh;
    std::mt19937_64 function;
};

class Noise_Gen {

public:

    Noise_Gen() : nChannels(NULL), nSamplesPerSec(NULL), nAvgBytesPerSec(NULL), nByteAlign(NULL), wBitsPerSample(NULL), 
        wValidBitsPerSample(NULL), wSamplesPerBlock(NULL), dwChannelMask(NULL), rd(NULL) {};

    ~Noise_Gen() {
        if(rd != NULL) {
            delete rd;
        }
    };

    HRESULT SetFormat(WAVEFORMATEX*);

    HRESULT LoadData(UINT32 bufferFrameCount, BYTE* pData, DWORD* flags);

private:
    void* rd;

    // WAVEFORMATEX
    WORD nChannels;
    DWORD nSamplesPerSec;
    DWORD nAvgBytesPerSec;
    WORD nByteAlign;
    WORD wBitsPerSample;

    // WAVEFORMATEXTENSIBLE
    WORD wValidBitsPerSample;
    WORD wSamplesPerBlock;
    DWORD dwChannelMask;
};

然后我添加了定义:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
// WASAPI
#include <Audiopolicy.h>
#include <Audioclient.h>

#include <time.h>

#include "Noise_Gen.h"

HRESULT Noise_Gen::SetFormat(WAVEFORMATEX* format) {
    nChannels = format->nChannels;
    nSamplesPerSec = format->nSamplesPerSec;
    nAvgBytesPerSec = format->nAvgBytesPerSec;
    nByteAlign = format->nBlockAlign;
    wBitsPerSample = format->wBitsPerSample;
    WORD  wFormatTag = format->wFormatTag;
    if(wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
        WAVEFORMATEXTENSIBLE* pWFE = reinterpret_cast<WAVEFORMATEXTENSIBLE*>(format);
        wValidBitsPerSample = pWFE->Samples.wValidBitsPerSample;
        wSamplesPerBlock = pWFE->Samples.wSamplesPerBlock;
        dwChannelMask = pWFE->dwChannelMask;
    } else {
        wValidBitsPerSample = wBitsPerSample;
    }
    double amplitude = std::pow(2.0, wValidBitsPerSample) - 1;
    switch(wBitsPerSample / 8) {
    case(1):
        rd = new Random<unsigned __int8>(0.0, amplitude);
        break;
    case(2): 
        rd = new Random<unsigned __int16>(0.0, amplitude);
        break;
    case(3):
        rd = new Random<unsigned __int32>(0.0, amplitude);
        break;
    case(4): 
        rd = new Random<signed __int32>(-amplitude, amplitude);
        break;
    case(5): 
        rd = new Random<unsigned __int64>(0.0, amplitude);
        break;
    case(6):
        rd = new Random<unsigned __int64>(0.0, amplitude);
        break;
    case(7): 
        rd = new Random<unsigned __int64>(0.0, amplitude);
        break;
    case(8):
        rd = new Random<unsigned __int64>(0.0, amplitude);
        break;
    default:
        return E_NOTIMPL;
    }
    return S_OK;
}

// (The size of an audio frame = nChannels * wBitsPerSample)
HRESULT Noise_Gen::LoadData(UINT32 bufferFrameCount, BYTE* pData, DWORD* flags) {
    for(UINT32 i = 0; i < nChannels *bufferFrameCount; i++) {
        switch(wBitsPerSample / 8) {
        case(1):
            pData[i] = (((Random<unsigned __int8>*)rd)->operator()());
            break;
        case(2):{
            unsigned __int16* pData2 = (unsigned __int16*) pData;
            pData2[i] = (((Random<unsigned __int16>*)rd)->operator()());
            break;
        }
        case(3): {
            __int32 data = ((Random<unsigned __int32>*)rd)->operator()();
            unsigned char* cp = (unsigned char*) (&data);
            pData[(3 * i)] = cp[0];
            pData[1 + (3 * i)] = cp[1];
            pData[2 + (3 * i)] = cp[2];
            break;
        }
        case(4):{
            signed __int32* pData2 = (signed __int32*) pData;
            pData2[i] = (((Random<signed __int32>*)rd)->operator()());
            break;
        }
        case(5): {
            __int64 data = ((Random<unsigned __int64>*)rd)->operator()();
            unsigned char* cp = (unsigned char*) &data;
            pData[(5 * i)] = cp[0];
            pData[1 + (5 * i)] = cp[1];
            pData[2 + (5 * i)] = cp[2];
            pData[3 + (5 * i)] = cp[3];
            pData[4 + (5 * i)] = cp[4];
            break;
        }
        case(6): {
            __int64 data = ((Random<unsigned __int64>*)rd)->operator()();
            unsigned char* cp = (unsigned char*) &data;
            pData[(6 * i)] = cp[0];
            pData[1 + (6 * i)] = cp[1];
            pData[2 + (6 * i)] = cp[2];
            pData[3 + (6 * i)] = cp[3];
            pData[4 + (6 * i)] = cp[4];
            pData[5 + (6 * i)] = cp[5];
            break;
        }
        case(7): {
            __int64 data = ((Random<unsigned __int64>*)rd)->operator()();
            unsigned char* cp = (unsigned char*) &data;
            pData[(7 * i)] = cp[0];
            pData[1 + (7 * i)] = cp[1];
            pData[2 + (7 * i)] = cp[2];
            pData[3 + (7 * i)] = cp[3];
            pData[4 + (7 * i)] = cp[4];
            pData[5 + (7 * i)] = cp[5];
            pData[6 + (7 * i)] = cp[6];
            break;
        }
        case(8): {
            unsigned __int64* pData2 = (unsigned __int64*) pData;
            pData2[i] = (((Random<unsigned __int64>*)rd)->operator()());
            break;
        }
        default:
            // For stopping playback
            (*flags) = AUDCLNT_BUFFERFLAGS_SILENT;
            return E_NOTIMPL;
        }
    }
    return S_OK;
}

然后,我将我的类添加到Microsoft提供的模板中,并将默认的音频端点渲染器打印到控制台。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <InitGuid.h>
#include <iostream>
#include <Windows.h>
#include <dshow.h>

// Windows multimedia device
#include <Mmdeviceapi.h>
#include <Functiondiscoverykeys_devpkey.h>

// WASAPI
#include <Audiopolicy.h>
#include <Audioclient.h>

#include "Noise_Gen.h"

//-----------------------------------------------------------
// Play an audio stream on the default audio rendering
// device. The PlayAudioStream function allocates a shared
// buffer big enough to hold one second of PCM audio data.
// The function uses this buffer to stream data to the
// rendering device. The inner loop runs every 1/2 second.
//-----------------------------------------------------------

// REFERENCE_TIME time units per second and per millisecond
#define REFTIMES_PER_SEC  10000000
#define REFTIMES_PER_MILLISEC  10000

#define EXIT_ON_ERROR(hres)  \
              if (FAILED(hres)) { goto Exit; }
#define SAFE_RELEASE(punk)  \
              if ((punk) != NULL)  \
                { (punk)->Release(); (punk) = NULL; }

const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
const IID IID_IAudioClient = __uuidof(IAudioClient);
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);

HRESULT PlayAudioStream(Noise_Gen* pMySource) {
    HRESULT hr;
    REFERENCE_TIME hnsRequestedDuration = REFTIMES_PER_SEC;
    REFERENCE_TIME hnsActualDuration;
    IMMDeviceEnumerator* pEnumerator = NULL;
    IMMDevice* pDevice = NULL;
    IAudioClient* pAudioClient = NULL;
    IAudioRenderClient* pRenderClient = NULL;
    WAVEFORMATEX* pwfx = NULL;
    UINT32 bufferFrameCount;
    UINT32 numFramesAvailable;
    UINT32 numFramesPadding;
    BYTE* pData;
    DWORD flags = 0;
    IPropertyStore* pPropertyStore = NULL;
    PROPVARIANT name;

    hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL,
                          CLSCTX_ALL, IID_IMMDeviceEnumerator,
                          (void**) &pEnumerator);
    EXIT_ON_ERROR(hr);
    hr = pEnumerator->GetDefaultAudioEndpoint(
        eRender, eConsole, &pDevice);

    hr = pDevice->OpenPropertyStore(STGM_READ, &pPropertyStore);
    PropVariantInit(&name);
    hr = pPropertyStore->GetValue(PKEY_Device_FriendlyName, &name);
    printf("%S", name.pwszVal);
    printf("\n");
    EXIT_ON_ERROR(hr);
    hr = pDevice->Activate(IID_IAudioClient, CLSCTX_ALL,
                           NULL, (void**) &pAudioClient);
    EXIT_ON_ERROR(hr);
    hr = pAudioClient->GetMixFormat(&pwfx);
    EXIT_ON_ERROR(hr);
    hr = pAudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED,
                                  0, hnsRequestedDuration,
                                  0, pwfx, NULL);
    EXIT_ON_ERROR(hr);
    // Tell the audio source which format to use.
    hr = pMySource->SetFormat(pwfx);
    EXIT_ON_ERROR(hr);
    // Get the actual size of the allocated buffer.
    hr = pAudioClient->GetBufferSize(&bufferFrameCount);
    EXIT_ON_ERROR(hr);
    hr = pAudioClient->GetService(IID_IAudioRenderClient,
                                  (void**) &pRenderClient);
    EXIT_ON_ERROR(hr);
    // Grab the entire buffer for the initial fill operation.
    hr = pRenderClient->GetBuffer(bufferFrameCount, &pData);
    EXIT_ON_ERROR(hr);
    // Load the initial data into the shared buffer.
    hr = pMySource->LoadData(bufferFrameCount, pData, &flags);
    EXIT_ON_ERROR(hr);
    hr = pRenderClient->ReleaseBuffer(bufferFrameCount, flags);
    EXIT_ON_ERROR(hr);
    // Calculate the actual duration of the allocated buffer.
    hnsActualDuration = (double) REFTIMES_PER_SEC * bufferFrameCount / pwfx->nSamplesPerSec;
    hr = pAudioClient->Start();  // Start playing.
    EXIT_ON_ERROR(hr);
    // Each loop fills about half of the shared buffer.
    while(flags != AUDCLNT_BUFFERFLAGS_SILENT) {
        // Sleep for half the buffer duration.
        Sleep((DWORD) (hnsActualDuration / REFTIMES_PER_MILLISEC / 2));
        // See how much buffer space is available.
        hr = pAudioClient->GetCurrentPadding(&numFramesPadding);
        EXIT_ON_ERROR(hr);
        numFramesAvailable = bufferFrameCount - numFramesPadding;
        // Grab all the available space in the shared buffer.
        hr = pRenderClient->GetBuffer(numFramesAvailable, &pData);
        EXIT_ON_ERROR(hr);
        // Get next 1/2-second of data from the audio source.
        hr = pMySource->LoadData(numFramesAvailable, pData, &flags);
        EXIT_ON_ERROR(hr);
        hr = pRenderClient->ReleaseBuffer(numFramesAvailable, flags);
        EXIT_ON_ERROR(hr);
    }
    // Wait for last data in buffer to play before stopping.
    Sleep((DWORD) (hnsActualDuration / REFTIMES_PER_MILLISEC / 2));
    hr = pAudioClient->Stop();  // Stop playing.
    EXIT_ON_ERROR(hr);
Exit:
    CoTaskMemFree(pwfx);
    SAFE_RELEASE(pEnumerator);
    SAFE_RELEASE(pDevice);
    SAFE_RELEASE(pAudioClient);
    SAFE_RELEASE(pRenderClient);
    return hr;
}

int main() {
    HRESULT hr = CoInitialize(nullptr);
    if(FAILED(hr)) { return hr; }
    Noise_Gen* ng = new Noise_Gen();
    PlayAudioStream(ng);
    delete ng;
    CoUninitialize();
}

我的系统上的默认音频端点渲染器使用32位值,因此代码从将无符号32位值写入缓冲区开始。然后,我尝试使用带符号的值,这可以在上面的代码中看到。在这两种情况下都没有播放声音。我在调试时检查了缓冲区的内容,它们确实发生了变化。我将默认的音频端点渲染器打印到控制台,它是我系统的扬声器。Windows甚至在音量混音器中显示我的应用程序,但即使在音量一直调高的情况下也没有声音显示。然后,我检查了休眠时间,以确保它处于休眠状态,以便系统可以访问缓冲区,并且在写入缓冲区之间休眠500ms。

更新:我发现我正在使用KSDATAFORMAT_SUBTYPE_IEEE_FLOAT子格式,并尝试在-amplitude到幅度范围、0到幅度范围、-1到1范围和0到1范围中输入缓冲区浮点。

我遗漏了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-18 10:59:13

你的随机数分布代码对浮点格式不能正常工作(据我所知,这基本上总是共享模式下的混合格式)。

即使对于整数也是错误的。我猜你是想写

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
((f  % ((signed __int64) mHigh - (signed __int64) mLow)) + (signed __int64) mLow); 

(请注意减号),但无论如何都不应该使用原始模数,因为它略有偏差。

对于浮点格式,您始终使用-1到1的范围。

我已经修改了你的代码以使用std::uniform_real_distribution,并且我的扬声器上有噪音播放。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <cstdio>
#include <Windows.h>

// Windows multimedia device
#include <Mmdeviceapi.h>
#include <Functiondiscoverykeys_devpkey.h>

// WASAPI
#include <Audiopolicy.h>
#include <Audioclient.h>

#include <random>


class Noise_Gen {
public:
    Noise_Gen() : format(), engine(__rdtsc()), float_dist(-1.f, 1.f) {};

    void SetFormat(WAVEFORMATEX* wfex) {
        if(wfex->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
            format = *reinterpret_cast<WAVEFORMATEXTENSIBLE*>(wfex);
        } else {
            format.Format = *wfex;
            format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
            INIT_WAVEFORMATEX_GUID(&format.SubFormat, wfex->wFormatTag);
            format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
            format.dwChannelMask = 0;
        }
    }

    // (The size of an audio frame = nChannels * wBitsPerSample)
    void FillBuffer(UINT32 bufferFrameCount, BYTE* pData, DWORD* flags) {
        const UINT16 formatTag = EXTRACT_WAVEFORMATEX_ID(&format.SubFormat);
        if(formatTag == WAVE_FORMAT_IEEE_FLOAT) {
            float* fData = (float*)pData;
            for(UINT32 i = 0; i < format.Format.nChannels * bufferFrameCount; i++) {
                fData[i] = float_dist(engine);
            }
        } else if(formatTag == WAVE_FORMAT_PCM) {
            using rndT = decltype(engine)::result_type;
            UINT32 iterations = format.Format.nBlockAlign * bufferFrameCount / sizeof(rndT);
            UINT32 leftoverBytes = format.Format.nBlockAlign * bufferFrameCount % sizeof(rndT);
            rndT* iData = (rndT*)pData;
            UINT32 i = 0;
            for(; i < iterations; i++) {
                iData[i] = engine();
            }
            if(leftoverBytes != 0) {
                rndT lastRnd = engine();
                BYTE* pLastBytes = pData + i * sizeof(rndT);
                for(UINT32 j = 0; j < leftoverBytes; ++j) {
                    pLastBytes[j] = lastRnd >> (j * 8) & 0xFF;
                }
            }
        } else {
            //memset(pData, 0, wfex.Format.nBlockAlign * bufferFrameCount);
            *flags = AUDCLNT_BUFFERFLAGS_SILENT;
        }
    }

private:
    WAVEFORMATEXTENSIBLE format;

    std::mt19937_64 engine;
    std::uniform_real_distribution<float> float_dist;
};

// REFERENCE_TIME time units per second and per millisecond
#define REFTIMES_PER_SEC  10000000ll
#define REFTIMES_PER_MILLISEC  10000

#define EXIT_ON_ERROR(hres)  \
              if (FAILED(hres)) { goto Exit; }
#define SAFE_RELEASE(punk)  \
              if ((punk) != NULL)  \
                { (punk)->Release(); (punk) = NULL; }

HRESULT PlayAudioStream(Noise_Gen* pMySource) {
    HRESULT hr;
    REFERENCE_TIME hnsRequestedDuration = REFTIMES_PER_SEC;
    REFERENCE_TIME hnsActualDuration;
    IMMDeviceEnumerator* pEnumerator = NULL;
    IPropertyStore* pPropertyStore = NULL;
    IMMDevice* pDevice = NULL;
    IAudioClient* pAudioClient = NULL;
    IAudioRenderClient* pRenderClient = NULL;
    WAVEFORMATEX* pwfx = NULL;
    UINT32 bufferFrameCount;
    BYTE* pData;
    DWORD flags = 0;
    PROPVARIANT name;

    hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL,
        CLSCTX_ALL, IID_PPV_ARGS(&pEnumerator));
    EXIT_ON_ERROR(hr);
    hr = pEnumerator->GetDefaultAudioEndpoint(
        eRender, eConsole, &pDevice);
    EXIT_ON_ERROR(hr);

    hr = pDevice->OpenPropertyStore(STGM_READ, &pPropertyStore);
    EXIT_ON_ERROR(hr);
    PropVariantInit(&name);
    hr = pPropertyStore->GetValue(PKEY_Device_FriendlyName, &name);
    EXIT_ON_ERROR(hr);
    printf("%S", name.pwszVal);
    printf("\n");
    hr = pDevice->Activate(__uuidof(pAudioClient), CLSCTX_ALL,
        NULL, (void**) &pAudioClient);
    EXIT_ON_ERROR(hr);
    hr = pAudioClient->GetMixFormat(&pwfx);
    EXIT_ON_ERROR(hr);

    hr = pAudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED,
        0, hnsRequestedDuration,
        0, pwfx, NULL);
    EXIT_ON_ERROR(hr);
    // Tell the audio source which format to use.
    pMySource->SetFormat(pwfx);
    // Get the actual size of the allocated buffer.
    hr = pAudioClient->GetBufferSize(&bufferFrameCount);
    EXIT_ON_ERROR(hr);
    hr = pAudioClient->GetService(IID_PPV_ARGS(&pRenderClient));
    EXIT_ON_ERROR(hr);
    // Grab the entire buffer for the initial fill operation.
    hr = pRenderClient->GetBuffer(bufferFrameCount, &pData);
    EXIT_ON_ERROR(hr);

    // Load the initial data into the shared buffer.
    pMySource->FillBuffer(bufferFrameCount, pData, &flags);    

    hr = pRenderClient->ReleaseBuffer(bufferFrameCount, flags);
    EXIT_ON_ERROR(hr);
    // Calculate the actual duration of the allocated buffer.
    hnsActualDuration = REFTIMES_PER_SEC * bufferFrameCount / pwfx->nSamplesPerSec;
    hr = pAudioClient->Start();  // Start playing.
    EXIT_ON_ERROR(hr);
    // Each loop fills about half of the shared buffer.
    DWORD sleepTime;
    while(flags != AUDCLNT_BUFFERFLAGS_SILENT) {
        // Sleep for half the buffer duration.
        sleepTime = (DWORD) (hnsActualDuration / REFTIMES_PER_MILLISEC / 2);
        if(sleepTime != 0)
            Sleep(sleepTime);
        // See how much buffer space is available.
        UINT32 numFramesPadding;
        hr = pAudioClient->GetCurrentPadding(&numFramesPadding);
        EXIT_ON_ERROR(hr);

        UINT32 numFramesAvailable = bufferFrameCount - numFramesPadding;
        // Grab all the available space in the shared buffer.
        hr = pRenderClient->GetBuffer(numFramesAvailable, &pData);
        EXIT_ON_ERROR(hr);

        // Get next 1/2-second of data from the audio source.
        pMySource->FillBuffer(numFramesAvailable, pData, &flags);

        hr = pRenderClient->ReleaseBuffer(numFramesAvailable, flags);
        EXIT_ON_ERROR(hr);
    }
    // Wait for last data in buffer to play before stopping.
    sleepTime = (DWORD) (hnsActualDuration / REFTIMES_PER_MILLISEC / 2);
    if(sleepTime != 0)
        Sleep(sleepTime);
    hr = pAudioClient->Stop();  // Stop playing.
    EXIT_ON_ERROR(hr);

Exit:
    CoTaskMemFree(pwfx);
    SAFE_RELEASE(pRenderClient);
    SAFE_RELEASE(pAudioClient);
    SAFE_RELEASE(pDevice);
    SAFE_RELEASE(pPropertyStore); // you forgot to free the property store
    SAFE_RELEASE(pEnumerator);
    return hr;
}

int main() {
    HRESULT hr = CoInitialize(nullptr);
    if(FAILED(hr)) { return hr; }

    Noise_Gen ng;
    PlayAudioStream(&ng);
    
    CoUninitialize();
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65277385

复制
相关文章
Firefox内容安全策略中的“Strict-Dynamic”限制
在本文中,我们将重点分析如何绕过Firefox内容安全策略中的“Strict-Dynamic”限制。该漏洞详情请参考: https://www.mozilla.org/en-US/security/advisories/mfsa2018-11/#CVE-2018-5175 。该漏洞将绕过内容安全策略(CSP)的保护机制,而在该机制中包含一个“严格动态限制”的Script-src策略。如果目标网站中存在HTTP注入漏洞,攻击者可以将一个引用注入到require.js库的一个副本中,这个库位于Firefox开发人员工具之中,攻击者随后便可以使用已知技术,利用该库绕过CSP限制,从而执行注入脚本。
西门呀在吹雪
2022/09/05
2.1K0
Firefox内容安全策略中的“Strict-Dynamic”限制
内容安全策略( CSP )
内容安全策略 (CSP) 是一个额外的安全层,用于检测并削弱某些特定类型的攻击,包括跨站脚本 (XSS) 和数据注入攻击等。无论是数据盗取、网站内容污染还是散发恶意软件,这些攻击都是主要的手段。
黑伞安全
2020/08/10
3.3K0
内容安全策略( CSP )
绕过内容安全策略总结
今年的 0CTF 预选赛 6 道 web 题,其中三道都涉及 CSP 的知识点,简直可怕。。。这次趁着空闲时间就稍稍总结一下 CSP 绕过方面的知识,无论是对以后 CTF 比赛还是工作都很有帮助。
信安之路
2018/08/08
2.1K0
绕过内容安全策略总结
Spring Security配置内容安全策略
在IDEA里集成阿里的https://start.aliyun.com,创建一个Spring Initializr项目:
SmileNicky
2022/05/13
1.7K0
Spring Security配置内容安全策略
CSP(Content Security Policy 内容安全策略)
正式加入生产环境前可以先仅收集一段时间的不匹配规则日志,观察一段时间没有问题再上生产环境。或者仅仅作为监控异常行为来使用也可以!
零式的天空
2022/03/16
2.3K0
绕过Edge、Chrome和Safari的内容安全策略
概述 ---- Web应用中有许多基本的安全机制,其中一个是同源(same-origin)策略机制,该机制规定了应用程序代码可以访问的资源范围。同源策略的基本思想是,源自于某台服务器上的代码只能访问同一台服务器上的web资源。 比如,在Web浏览器上下文中执行的某个脚本,如果其来源服务器为good.example.com,那么它就可以访问同一台服务器上的数据资源。另一方面,根据同源策略的思想,来自evil.example.com的另一个脚本不能访问good.example.com上的任何数据。
奶糖味的代言
2018/04/16
2.6K0
Kubernetes 中的 Pod 安全策略
很多人分不清 SecurityContext 和 PodSecurityPolicy 这两个关键字的差别,其实很简单:
崔秀龙
2020/05/07
1.5K0
防XSS的利器,什么是内容安全策略(CSP)?
内容安全策略(CSP),是一种安全策略,其原理是当浏览器请求某一个网站时,告诉该浏览器申明文件可以执行,什么不可以执行。CSP是专门解决XSS攻击而生的神器。 CSP的引入会使得我们的引入扩展程序更加安全,并且可以由开发者指定可以加载扩展程序的类型,避免恶意的脚本在浏览器中执行,造成信息泄露问题。
房东的狗丶
2023/02/17
2.2K0
Nginx内容缓存
介绍 当启用缓存时,NGINX Plus将响应保存在磁盘缓存中,并使用它们来响应客户端,而不必每次都为同一内容代理请求。 启用响应缓存 要启用缓存,请在顶层的HTTP上下文中包含proxy_c
用户1263954
2018/01/30
1.9K0
Nginx内容缓存
字符串处理中的通配符
通配符,从名称上我们也能大概猜到,这种特殊的符号是有通用匹配功能的,也就是可以匹配所有的符号。
xyj
2020/07/28
2.2K0
字符串处理中的通配符
如何使用cspparse评估内容安全策略CSP的有效性
 关于cspparse  cspparse是一款针对内容安全策略的升级工具,在该工具的帮助下,广大研究人员可以针对自己所实施的内容安全策略CSP进行安全审计和评估。 该工具使用了Google的API来获取CSP Header,并将获取到的信息以ReconJSON格式返回给研究人员。除此之外,该工具还能够解析目标站点的HTML,并检索HTML代码中<meta>标签包含的内容安全策略CSP规则。  ReconJSON  ReconJSON是一种基于Recon数据标准的JSON格式,ReconJSON这种数据格式
FB客服
2023/03/30
4490
如何使用cspparse评估内容安全策略CSP的有效性
Kubernetes中的Pod安全策略以及示例
上述示例中,Pod安全策略禁止容器使用特权访问权限和特权升级,要求容器以非特权用户运行,并放弃了一些特定能力。同时,允许容器使用任何组ID、SELinux用户标签和辅助组ID。支持的卷类型包括configMap、emptyDir、secret、downwardAPI和persistentVolumeClaim。
一凡sir
2023/09/07
4100
Kubernetes中的Pod安全策略以及示例
跟我一起探索HTTP-内容安全策略(CSP)
内容安全策略(CSP)是一个额外的安全层,用于检测并削弱某些特定类型的Attack,包括跨站脚本(XSS)和数据注入Attack等。无论是数据盗取、网站内容污染还是恶意软件分发,这些Attack都是主要的手段。
用户1418987
2023/10/16
4510
跟我一起探索HTTP-内容安全策略(CSP)
linux通配符的用法_linux中rmdir命令
注意:linux通配符和三剑客(grep,awk,sed)正则表达式是不一样的,因此,代表的意义也是有较大区别的。
全栈程序员站长
2022/09/28
3K0
模糊查询中输入通配符的问题
比如说在搜索框中输入'%'、'_'、'/'时会出错,因为这些特殊符号在sql语句查询的时候是有他特定的意义的,所有这里要对前台传过来的keyword搜索内容进行排除通配符处理,我是在工具类中写了一个方法代码如下:
小勇DW3
2019/07/22
1.6K0
通配符和通配符掩码
  在路由器的配置中,经常出现通配符。和子网掩码一样,都是以“0”或“1”表示,不过与子网掩码所表示的意思却不一样。
全栈程序员站长
2022/09/15
1.7K0
【说站】java方法参数中通配符的使用
2、Generic<Fruit>对象和Generic<Food>对象可以作为参数传递给print2。但是Generic<Apple>对象不能作为参数传入,因为 Apple是Fruit的子类,超出了泛型规定的下界。
很酷的站长
2022/11/23
9970
【说站】java方法参数中通配符的使用
Linux通配符详解_Linux 通配符
前提条件: 有file.jpg,file1.jpg,file2.jpg…file14.jpg共15个文件
全栈程序员站长
2022/11/04
14.2K0
Linux通配符详解_Linux 通配符
mysql通配符_mysql通配符使用
在mysql查询中,经常会用到通配符,而且mysql的通配符和pgsql是有所不同的,甚至mysql中还可以使用正则表达式。本文就为大家带来mysql查询中通配符的使用。
全栈程序员站长
2022/09/07
1.6K0
Java中类型参数“<T>”和无界通配符“<?>”的区别
List<T>最应该出现的地方,应该是定义一个泛型List容器 但List是库里自带的容器,看看ArrayList的源码头一行:
JavaEdge
2018/10/11
2.8K0
Java中类型参数“<T>”和无界通配符“<?>”的区别

相似问题

内容安全策略通配符?

119

在Nginx中添加内容安全策略

127

内容安全策略通配符似乎被忽略

46

NGINX解析和重载失败的内容安全策略

12

NGINX位置通配符

12
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文