#include <stdio.h>#include<malloc.h>#include<sys/stat.h>typedefint(*pfunc) (int,int); typedefstruct{ intPosition; intLength;} Fun;typedefstruct{ intnum; Fun*Pfun;} Lib;intMain () {intFileSize =0; CharFilename[] ="Code.obj"; FILE* FileHandle = fopen (FileName,"RB"); if(filehandle!=NULL) {Lib lib; Fread (&lib.num,sizeof(Char),4, FileHandle); //determine how many functions are in the fileLib.pfun = (fun*)malloc(sizeof(Fun) *lib.num); Fread (Lib.pfun,sizeof(fun), lib.num,filehandle); //read the information of the first function in the file (in the file) address and length Char*instruction= (Char*)malloc(sizeof(Char) *lib.pfun->Length); //allocating space for functions in memory based on functionsFseek (Filehandle,lib.pfun->position,0); //move to function address, in bytes, 0 for the first byte of the fileFread (instruction,sizeof(Char),lib.pfun->length,filehandle); //read function instruction to reserved memoryPFUNC PFUNC =(PFUNC) instruction; printf ("%d \ n", Pfunc (3,4)); //Execute function }}/*Description: 1) There is no function type information, if the function type information is supported, then it can be said that this is DLL file 2) read the file can be imagined as a char a[m], a char pointer to the array, and in this array moved back and forth, the initial point to a[0], We always copy a certain byte from the address pointed to by this pointer to another array, assuming the pointer is pointing to a[0], we want to read 10 bytes, after reading, the pointer is positioned to A[10], of course, we can also use fseek arbitrary move pointer size_t fread (void * buffer,size_t size,size_t count,file *stream) {int i=0; while (Stream->ptr!=null && i<count) {buffer = stream->ptr; (stream->ptr) + +; } return i;} imaginary function code int fseek (FILE *stream,long offset,int origin) {stream->ptr = Offset + origin}*/
CODE. Obj
0C xx, 2B, XX, 8B EC 81
EC C0 (XX) 8D BD-FF FF FF B9 30
XX B8 cc cc cc F3 AB 8B 0C
5F 5E 5B 8B E5 5D C3
Simulating DLL loading