首页 > 解决方案 > 我如何将'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;
}

我非常感谢您提供的任何帮助!

标签: cwindowsassembly32-bitmemset

解决方案


推荐阅读