What I know is ptr points at \xFF\xFF
. Let's say that the value of ptr is (e.g 0x004E0000
) which point at \xFF\xFF
, how can I make foo array contain "\x41\x42\x43\x00\x00\x4E\x00"
?
我所知道的是ptr点在\ xFF \ xFF。假设ptr的值是(例如0x004E0000),它指向\ xFF \ xFF,我怎么能让foo数组包含“\ x41 \ x42 \ x43 \ x00 \ x00 \ x4E \ x00”?
Code:
#include <string.h>
#include <iostream>
#include <Windows.h>
int main()
{
char foo[20];
char *alpha = "\x41\x42\x43";
char *test = "\xFF\xFF";
void *ptr = VirtualAlloc(NULL, strlen(test), 0x3000, 0x40);
RtlMoveMemory(lpvAddr, test, strlen(test));
}
I'm using visual studio 2017.
我正在使用2017年的视觉工作室。
2 个解决方案
#1
0
I assume that you just want to:
我假设你只想:
- copy the
alpha
string at the beginning offoo
- copy the address pointed to by
test
immediately after the string infoo
复制foo开头的alpha字符串
在foo中的字符串后立即复制test指向的地址
memcpy
is your friend when it comes to copy arbitrary objects, but it would be simpler to use an auxiliary pointer. Code could be:
在复制任意对象时,memcpy是你的朋友,但使用辅助指针会更简单。代码可以是:
char foo[20];
char *alpha = "\x41\x42\x43";
char *test = "\xFF\xFF";
char **pt = &test; // pt now points to the address where "\xFF\xFF" lies
memcpy(foo, alpha, strlen(alpha));
memcpy(foo + strlen(alpha), pt, sizeof(char *)); // copy the address
But beware: I've just answered your question, but I really cannot see a real use case for it. Just assuming that you are exploring address copy for learning purpose.
但要注意:我刚刚回答了你的问题,但我真的看不出真正的用例。假设您正在探索用于学习目的的地址副本。
#2
0
What does copying anything to foo have to do with the VirtualAlloc? You have an array of 20 chars, just copy the values you want to that memory. You never declare lpvAddr, did you mean that to be ptr?
将任何内容复制到foo与VirtualAlloc有什么关系?你有一个20个字符的数组,只需将你想要的值复制到该内存中。你永远不会声明lpvAddr,你的意思是ptr吗?
If you did mean (lpvAddrto to be ptr, it would be something like (although it seems entirely pointless to take the high 4 bytes of an 8-byte address in this way):
如果你的意思是(lpvAddrto是ptr,它会是这样的(虽然以这种方式取8字节地址的高4字节似乎完全没有意义):
memcpy(foo, test, 4);
*((PULONG)foo+1) = *((PULONG)&ptr+1);
#1
0
I assume that you just want to:
我假设你只想:
- copy the
alpha
string at the beginning offoo
- copy the address pointed to by
test
immediately after the string infoo
复制foo开头的alpha字符串
在foo中的字符串后立即复制test指向的地址
memcpy
is your friend when it comes to copy arbitrary objects, but it would be simpler to use an auxiliary pointer. Code could be:
在复制任意对象时,memcpy是你的朋友,但使用辅助指针会更简单。代码可以是:
char foo[20];
char *alpha = "\x41\x42\x43";
char *test = "\xFF\xFF";
char **pt = &test; // pt now points to the address where "\xFF\xFF" lies
memcpy(foo, alpha, strlen(alpha));
memcpy(foo + strlen(alpha), pt, sizeof(char *)); // copy the address
But beware: I've just answered your question, but I really cannot see a real use case for it. Just assuming that you are exploring address copy for learning purpose.
但要注意:我刚刚回答了你的问题,但我真的看不出真正的用例。假设您正在探索用于学习目的的地址副本。
#2
0
What does copying anything to foo have to do with the VirtualAlloc? You have an array of 20 chars, just copy the values you want to that memory. You never declare lpvAddr, did you mean that to be ptr?
将任何内容复制到foo与VirtualAlloc有什么关系?你有一个20个字符的数组,只需将你想要的值复制到该内存中。你永远不会声明lpvAddr,你的意思是ptr吗?
If you did mean (lpvAddrto to be ptr, it would be something like (although it seems entirely pointless to take the high 4 bytes of an 8-byte address in this way):
如果你的意思是(lpvAddrto是ptr,它会是这样的(虽然以这种方式取8字节地址的高4字节似乎完全没有意义):
memcpy(foo, test, 4);
*((PULONG)foo+1) = *((PULONG)&ptr+1);