Reputation: 1
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"
?
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.
Upvotes: 0
Views: 1301
Reputation: 148880
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.
Upvotes: 1
Reputation: 15164
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);
Upvotes: 0