模拟exe文件的拉伸

// .cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"
#include <stdlib.h>

void pula()
{
	short* pe1;
	int* pe;
	FILE *fp;
	FILE *fp1;
	//判断是否打开文件
	if ( (fp = fopen("C:\\WINDOWS\\system32\\notepad.exe", "rb")) == NULL )
	{
		puts("Fail to open file!");
		return;
	}
	//或者文件大小
	fseek(fp,0,2);
	int z = ftell(fp);
	//申请内存空间
	char* date = (char*)malloc(z);
	if(date == NULL)
		puts("申请失败");
	//让指针回到开头位置
	fseek(fp,0,0);
	//写入内存中
	for(int i = 0; i<z;i++)
	{
		fscanf(fp, "%c", (date+i));
	
	}
	//申请内存空间
	int Number=*(pe=(int *)(date+*(pe=(int *)(date+60))+80));
	char* date1 = (char*)calloc(Number,sizeof(char));
	if(date1 == NULL)
		puts("申请失败");
	//拉伸数据
	//头
	int aa=*(pe=(int *)(date+*(pe=(int *)(date+60))+84));

	for(i=0; i<aa;i++)
	{
		*(date1+i) = *(date+i);
	}
	//数据段
	aa = *(pe1=(short *)(date+*(pe=(int *)(date+60))+6));
	int oo=0;
	int pp=0;
	int yy;
	for(i=0; i<aa;i++)
	{	
		pp=i*40;
		int uu=*(pe=(int *)(date+*(pe=(int *)(date+60))+22+0xe2+pp+8));
		printf("%x",*(pe=(int *)(date+*(pe=(int *)(date+60))+22+0xe2+pp+8)));
		oo=*(pe=(int *)(date+*(pe=(int *)(date+60))+22+0xe2+pp+20));
		int ww=*(pe=(int *)(date+*(pe=(int *)(date+60))+22+0xe2+pp+12));
		for(yy=0; yy<uu; yy++)
		{
			*(date1+ww+yy) = *(date+oo+yy);
		}

	}

	//拉伸回去
	//申请内存空间
	Number=*(pe=(int *)(date1+*(pe=(int *)(date1+60))+84));
	pp=0;
	for(i=0; i<aa; i++)
	{
		pp=i*40;
		Number=(*(pe=(int *)(date1+*(pe=(int *)(date1+60))+22+0xe2+pp+16)))+Number;
	}
	char* date2 = (char*)calloc(Number,sizeof(char));
	if(date2 == NULL)
		puts("申请失败");
	
	//收缩数据
	//头
	aa=*(pe=(int *)(date1+*(pe=(int *)(date1+60))+84));

	for(i=0; i<aa;i++)
	{
		*(date2+i)=*(date1+i);
	}
	//数据段
	aa = *(pe1=(short *)(date1+*(pe=(int *)(date1+60))+6));
	oo=*(pe=(int *)(date1+*(pe=(int *)(date1+60))+84));
	pp=0;
	for(i=0; i<aa;i++)
	{	
		pp=i*40;
		int uu=*(pe=(int *)(date1+*(pe=(int *)(date1+60))+22+0xe2+pp+8));
		printf("%x",*(pe=(int *)(date1+*(pe=(int *)(date1+60))+22+0xe2+pp+8)));
		oo=*(pe=(int *)(date1+*(pe=(int *)(date1+60))+22+0xe2+pp+20));
		int ww=*(pe=(int *)(date1+*(pe=(int *)(date1+60))+22+0xe2+pp+12));
		for(int yy=0; yy<uu; yy++)
		{
			*(date2+oo+yy) = *(date1+ww+yy);
		}

	}

	//判断打开文件如果文件不存在就创建一个叫1111.exe的文件

	if ( (fp1 = fopen("c:\\1111.exe", "wb")) == NULL )
	{
		puts("Fail to open file!");
		return;
	}
	//写入数据
	for(i=0;i<Number;i++)
	{
		fprintf(fp1,"%c",*(date2+i));
		printf("写入文件成功\n");

	}
	



	free(date);//释放内存空间
	free(date1);
	free(date2);
	fclose(fp1);//操作结束后关闭文件
	fclose(fp);//操作结束后关闭文件
}


int main()
{
	pula();

	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值