c - 我如何将'0xA5'的值设置为我的字符串“Now the Message is:”的前5个字节?
问题描述
目前我的输出如下所示:
但我想替换字符串“The end is near!”的前 5 个字节。在我的 x_memset 函数末尾加上“A5”,紧跟在语句“现在消息是:”之后。
#include <stdio.h>
#include <string.h>
#include <Windows.h>
void printBytes(char *data, int length)
{
int x;
for (x = 0; x < length; x++)
{
if ((x & 0xF) == 0) printf("\n");
printf("%02X ", (unsigned char)data[x]);
}
printf("\n\n");
return;
} // printBytes
void x_memset(void *destination, unsigned char value, int nCount,char *str) {
__asm {
mov eax, 16; push the length
push eax
mov eax, 0x41; push the value
push eax
lea eax, str; push the address of string
push eax
call inline_memset
add esp, 12
jmp EXIT
inline_memset :
mov ecx, [nCount]
mov edi, [destination]
mov al, [value]
mov ebx, ecx
// shr ecx, 2
// and ebx, 3
// rep stosd
// mov ecx, ebx
// rep stosb
EXIT:
}
printf("\nNow the message is : %s\n", str);
printBytes(str, strlen(str));
return;
} // end function
int main()
{
char string[] = "The end is near!"; // this is 16 bytes + null
printf("The message is : %s\n", string);
printBytes(string,strlen(string));
x_memset(0x1000,0xA5,5,string);
//puts(string);
//fflush(stdin);
getchar();
return 0;
}
我非常感谢您提供的任何帮助!
解决方案
推荐阅读
- python - 合并两个深度学习模型 VGG16 和 ResNet50 后出错
- jquery - wordpress:AppMe 主题在 macOS 中不播放背景视频
- c++ - 我可以存储指向转发声明的类/结构的指针吗?
- mongodb - MongoDB中的聚合总和
- fortran - gfortran -fopenmp 导致分段错误
- html - CSS按钮滑动过渡效果问题
- architecture - Xcode 12 Apple M1 arm64 - 可设计错误:“错误的架构”
- excel - 当我已经在变量中设置文件名和路径时如何关闭工作簿
- python - Tensorflow:梯度在训练过程中突然变成了 NaN
- xml - 如何删除 PostgreSQL 中的 XML 属性?