Simulating DLL loading

Source: Internet
Author: User
Tags fread

#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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.