二进制文件每两个的字节位置交换
发表于:2025-12-01 作者:千家信息网编辑
千家信息网最后更新 2025年12月01日,(一).写作缘由:写这篇博客的目的是是为了方便下次使用或者帮助其他需要的人。在打CTF的时候,偶尔会遇到还原一些文件,笔者遇到的是分析数据流量的时候,提取出了一个未知文件,用二进制编辑器打开,搜所文件
千家信息网最后更新 2025年12月01日二进制文件每两个的字节位置交换
(一).写作缘由:
写这篇博客的目的是是为了方便下次使用或者帮助其他需要的人。在打CTF的时候,偶尔会遇到还原一些文件,笔者遇到的是分析数据流量的时候,提取出了一个未知文件,用二进制编辑器打开,搜所文件头,发现和某个文件头有点相似,但是每两个字节位置颠倒了,于是就想到把每两个字节交换位置,就像下面这种:


(二).演示及效果:
在命令行执行前后如下图:
(三).贴上代码:
代码是C写的,有点多不太美观,功能太单一, 也没弄啥模块化,编写环境是windows。
#include#include #include int main(int argc, const char** argv){ //The pointer of input file and output file FILE *fin; FILE* fout; //The file name of input file and output char* inFile; char* outFile; //The pointer of single and double byte type unsigned short* pDouble = NULL; unsigned char* pSingle = NULL; //The memery buffer of header and tail pointer about input file void* fBuffStart = NULL; void* fBuffEnd = NULL; //The size of input file (Byte) unsigned long fileSize = 0; //Judge the count of parameter and the file name limit if(argc != 3 || strlen(argv[1]) > 255 || strlen(argv[2]) > 255) { printf("\n[-]Usage: %s infile outfile\n", argv[0]); printf("[-]Filename limited: 255 Byte\n"); exit(-1); } inFile = argv[1]; outFile = argv[2]; //Exception handling if(!(fin = fopen(inFile, "rb"))) { printf("Error: open %s failed!\n", inFile); exit(-1); } //Obtain file size fseek(fin, 0, SEEK_END); fileSize = ftell(fin); fseek(fin, 0, SEEK_SET); //Alloc memery for input file and read its data to memery fBuffStart = (unsigned char*)malloc(fileSize); memset(fBuffStart, 0, fileSize); fread(fBuffStart, 1, fileSize, fin); fclose(fin); //The position of start and end input file memery fBuffEnd = (unsigned char*)fBuffStart + fileSize; pDouble = (unsigned short*)fBuffStart; //Exception handling if(!(fout = fopen(outFile,"wb"))) { printf("Error: open %s failed!\n", outFile); exit(-1); } //Exchange position of each two byte while(pDouble != fBuffEnd) { pSingle = pDouble; fwrite(pSingle+1, 1, 1, fout); fwrite(pSingle, 1, 1, fout); pDouble++; } fclose(fout); return 0;}
(四).若有不足之处,还请斧正。
文件
两个
位置
字节
时候
二进制
相似
美观
上代
代码
功能
博客
命令
效果
数据
模块
流量
环境
目的
笔者
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
微信小程序软件开发系统模板
数据库中的时间验证规则怎么做
管理服务器的部门
北京如何网络技术推广
网络如何手动设置代理服务器主机
天津网络安全招标
江苏超频服务器厂家直销
阿里云数据库和mysql
多媒体视频系统服务器
k3数据授权数据库表
云海超融合 浪潮服务器
芯片软件开发总监招聘
数据库一个表哪个是主键
读取html内容写到数据库
服务器和客户机地址配置
计算机网络技术网站设计方向
长沙软件开发招聘ios
数据库的删除数据语句
太仓电子网络技术收费
科技信息互联网
电厂网络安全存在缺陷
民航 杰普逊 数据库
信阳市网络安全委员会
网络安全 美国大学
工行信创服务器
网络安全最高职位
护苗网络安全志愿者活动
我的世界1.18的服务器
手机上传图片到服务器
专职网络安全任命