The code you are writing "c3" is actually a xor gs:[something] command which dies because [something] isn't a valid pointer.
Main Topics
Browse All TopicsI'm trying to write a program that generates some opcodes and then executes them.
I can't seem to get it to work what is wrong?
it dies saying the address at the memory location pointed to by p could not be read
Here is what I've got:
#include <stdio.h>
#include <windows.h>
void (*func)();
int main()
{
void *p;
char *pc;
printf("hello\n");
// allocate the memory
p = VirtualAlloc(NULL,1024,MEM
if (p == NULL)
printf("virtual alloc failed");
else
{
// write the opcodes to the memory
pc = p;
// ret = c3 ?? right ??
(*pc) = 12; // c
pc++;
(*pc) = 3; // 3
pc++;
// call the function
func = p;
func();
// all done
printf("done\n");
}
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
One at a time:
yes I should do a 0xc3 as a single byte
I use a ret to return from the function.
basically what I'm tyring to do is to create a function in machine code execute it and have it return. later it will do more complicated stuff
I'm still new at translating assembly code to machine code but I thought ret was 0xc3 if not then is there where do you recommed I look for the proper value? I got c3 from the intel docs (.pdf) but I may have misread them.
Business Accounts
Answer for Membership
by: WxWPosted on 2003-07-08 at 14:27:11ID: 8880663
obvious error
ret = 0xc3 , not "c3"
*pc = 0xc3 is what you need.
But why issuing a ret command there ?