Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

security - How can I call an assembly file that contains a simple function from a C program function?

I want to write a simple C program example that calls a file in .asm format and executes his code.
PSEUDO-CODE ;)

    call(functionwithasmcode.asm);
question from:https://stackoverflow.com/questions/65944544/how-can-i-call-an-assembly-file-that-contains-a-simple-function-from-a-c-program

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, you can::

call("functionwithasmcode.asm");

This function will have to:

  1. Invoke the assembler and linker - create the dynamic link library.
  2. Depending on the system you need to load this library (for example in Linux by calling the dlopen function, in Windows LoadLibrary).
  3. Find your function in the library, assign to function pointer (it is also OS dependant for example in Linux dlsym, windows GetProcAddress)
  4. call the function using the function pointer from the point 3.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...