c++ - using pointer to function to asm file? -
I am reading a book, where a program is written in C so that the shell code can be executed. I copied it, but it did not work, so I tried to fix it. I found that I should use the mmap func to assign memory mobility, and also get the proper permissions, but it also does not work. Here is an example of an asm file:
test.asm: xor eax, eax mov eax, 1
Then I call it "nasm -o test test." Compiled with
Then to call the ASM module, implement the following code in Book C:
void * code; Zero (* func) (zero); // point to function code = Malloc (funcLen); // funcLen, ASM file size compiled file * * fp = fopen ("test", "rb"); Fread (code, 1, funcLen, fp); Func = (zero (*) (zero)) code; (* Fptr) ();
But when I run it, I put a "Segmentation error (code dump)" error Function, and the code ends:
Zero * code; Zero (* func) (zero); // indicator code = mAMAP (faucet, function, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_AONYMOUS, -1, 0); // funcLen, compile size of the ash file file FILE * fp = fopen ("test", "rb"); Fread (code, 1, funcLen, fp); Func = (zero (*) () zero)) code; (* Fptr) ();
And that still does not work, how can I have asign memory with execution permissions? Thanks
Comments
Post a Comment