[参考]字节码倒序工具

要将一个文件从头到尾全部倒转,可以采用以下代码:

#include<iostream>
#include "defs.h"

int main(int argc, char** argv)
{
	if (argc != 2 || argv[1] == "")
	{
		printf("Usage: revfile [filename]");
		return -1;
	}
	const char * fname = argv[1];
	char* buffer = nullptr;
	// input binary data
	FILE* fprb;
	if (fopen_s(&fprb, fname, "rb") != 0)  //> fname is path of file by const char* type
	{
		printf("can't open file\n");
		return false;
	}
	fseek(fprb, 0, SEEK_END);
	long size = ftell(fprb);
	fseek(fprb, 0, SEEK_SET);
	buffer = (char*)malloc(sizeof(char) * size);
	if (buffer == nullptr)return -2;
	fread(buffer, sizeof(char) * size, 1, fprb);  //> Con is a container to contain the input data
	fclose(fprb);
	
	char* savname = nullptr;
	savname = (char*)malloc(strlen(fname) * sizeof(char) + 8);
	if (savname == nullptr)return -2;
	memset(savname, 0, strlen(fname) * sizeof(char) + 8);
	strcpy(savname, fname);
	strcat(savname, ".r_");

	// output binary data
	if (fopen_s(&fprb, savname, "wb") != 0)  //> fname is path of file by const char* type
	{
		printf("can't write file\n");
		return false;
	}
	for (long i = size -1 ; i >= 0; i--)
	{
		fwrite(&buffer[i],sizeof(buffer[i]), 1, fprb);
	}
	fclose(fprb);
	return 0;
}

可执行文件请查看Release #RELEASE 20220216 · Holit/revfile (github.com)

image

posted @ 2022-02-16 22:34  二氢茉莉酮酸甲酯  阅读(88)  评论(0编辑  收藏  举报