8.用C语言与音符播放钢琴曲梦中的婚礼
[toc]
用C语言与音符播放钢琴曲梦中的婚礼1.使用MDI函数播放钢琴曲卡农1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#include <stdio.h>#include <windows.h>#pragma comment(lib, "winmm.lib")enum Scale { Rest = 0, C8 = 108, B7 = 107, A7s = 106, A7 = 105, G7s = 104, G7 = 103, F7s = 102, F7 = 101, E7 = 100, D7s = 99, D7 = 98, C7s = 97, C7 = 96, B6 = 95, A6s = 94, A6 = 93, G6s = 92, G6 = 91, F6s = 90, F6 = 89, E6 = 88, D6s = 87, D6 = 86, C6s = 8 ...
6.使用C语言将PCM文件编码成WAV文件
[toc]
C语言将PCM编码成WAV文件
准备一个pcm文件
编写代码并编译main.exe
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdint.h>#include <assert.h>#include <sys/stat.h>#pragma warning(disable:4996)size_t getFileSize(const char* filename) { struct stat st; if (stat(f ...
使用C语言在Windows中录制一个PCM音频文件
[toc]
使用C语言在Windows中录制一个PCM音频文件12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879#define _CRT_SECURE_NO_WARNINGS#include <windows.h>#include <mmsystem.h>#include <stdio.h>#pragma comment(lib, "winmm.lib")#define BUFFER_SIZE 44100 // 1 second of audio at 44.1kHz#define SAMPLE_RATE 44100#define NUM_CHANNELS 1#define BITS_PER_SAMPLE 16typedef struct { WAVEHDR head ...
3.使用C语言在Windows中创建PCM格式的音频文件
[toc]
使用C语言在Windows中创建PCM格式的音频文件PCM文件里面存储的是经过数模转换后存储的二进制文件,需要支持的播放器才能播放。
1.保存do re mi fa so la ti do到PCM文件中12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdint.h>#include <stdlib.h>#include <math.h>// 定义 M_PI#ifndef M_PI#define M_PI 3.14159265358979323846#endif#define SAMPLE_RATE 44100#define NUM_CHANNELS 1#define BITS_PER_SAMPLE 16#define DURATION 0.25 // 每 ...
3.使用C语言在Windows中创建WAV格式的音频文件
[toc]
使用C语言在Windows中创建WAV格式的音频文件1. 创建WAV格式的音频文件12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <math.h>#include <stdint.h>#include <string.h>#include <stdlib.h>#define SAMPLE_RATE 44100#define DURATION 0.1 // 每个音符的持续时间(秒)#define AMPLITUDE 32767 // 最大振幅(16位音频)// 定义 M_PI#ifndef M_PI#define M_ ...
2.C语言在Windows中播放特定频率的声音
[toc]
C语言在Windows中播放特定频率的声音1.C语言在Windows中使用Beep播放特定频率的声音12345678910111213141516171819#include <windows.h>#include <stdio.h>int main() { // 播放432Hz的声音,持续0.5秒 Beep(432, 500); // 播放440Hz的声音,持续0.5秒 Beep(440, 500); // 播放1000Hz的声音,持续0.5秒 Beep(1000, 500); // 播放2000Hz的声音,持续0.5秒 Beep(2000, 500); return 0;}
2.C语言在Windows中使用waveOut播放特定频率的声音1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 ...
2.3.C语言在Windows中播放do_ re _mi_fa_so_la _ti_do
[toc]
C语言在Windows中播放乐谱1.C语言在Windows中通过音符相关函数播放一秒432HZ的声音123456789101112131415161718192021222324252627282930#include <stdio.h>#include <windows.h>#include <math.h>#pragma comment(lib, "winmm.lib")void PlayTone(double frequency, int duration) { HMIDIOUT handle; midiOutOpen(&handle, 0, 0, 0, CALLBACK_NULL); int volume = 0x7f; // 最大音量 int sleep = duration; // 每个音符的持续时间 // 计算432Hz对应的MIDI音符 int midiNote = (int)(69 + 12 * log2(frequency / 440.0)) ...
33.在x86_64中不用call指令修改返回地址调用函数
在x86_64中不用call指令修改返回地址调用函数修改返回地址调用函数hello
准备环境vs2022。
start.asm
123456789101112131415161718192021222324252627282930313233343536373839404142434445;assembly.asmextrn hello : PROC.codefunnormal PROC; 正常调用函数 ; shadow space 32 bytes sub rsp, 40 ; 保持16字节对齐 + 预留 shadow space mov ecx, 123 ; RCX = 第一个参数(Windows x64 ABI) call hello ; 正常调用函数 add rsp, 40 xor eax, eax ; return 0 retfunnormal ENDPvulnerable PROC;修改返回地址调用函数 push rbp mov rbp, rsp ; retu ...
32.设置断点与无痕Hook的原理
无痕Hook的原理1.C语言使用VirtualAlloc分配内存后写入指令调用12345678910111213141516171819202122232425262728293031323334353637383940#include <stdio.h>#include <windows.h>void test(){ // 使用 VirtualAlloc 分配内存,确保内存页面可执行 SIZE_T size = 1; // 1 字节的内存 unsigned char* arry = (unsigned char*)VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); if (arry == NULL) { printf("Memory allocation failed.\n"); return; } // 将内存填充为 RET 指令 ar ...
31.C语言在windows中捕获异常
Windows捕获会引起程序崩溃的异常1.给空指针赋值引起的异常(__try __except)访问冲突(Access Violation):
这通常发生在尝试访问无效或不可访问的内存地址时,例如空指针解引用或访问已释放的内存。
示例:int* ptr = NULL; *ptr = 5; 或 free(ptr); ptr = NULL; *ptr = 10;
123456789101112131415161718192021#include <windows.h>#include <stdio.h>void test() { __try { // 这里执行可能会抛出异常的代码 int* ptr = NULL; *ptr = 42; // 这会触发访问冲突异常 } __except (EXCEPTION_EXECUTE_HANDLER) { // 捕获异常并处理 printf("An exception occurred! ...
