What I know is ptr points at \\xFF\\xFF
. Let's say that the value of ptr is (eg 0x004E0000
) which point at \\xFF\\xFF
, how can I make foo array contain "\\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.
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?
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):
memcpy(foo, test, 4);
*((PULONG)foo+1) = *((PULONG)&ptr+1);
I assume that you just want to:
alpha
string at the beginning of foo
test
immediately after the string in foo
memcpy
is your friend when it comes to copy arbitrary objects, but it would be simpler to use an auxiliary pointer. Code could be:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.