C BIN加密
#include <stdio.h>
#include <string.h>
#include <stdlib.h> #ifndef DWORD
#define DWORD unsigned int
#endif #ifndef BYTE
#define BYTE unsigned char
#endif #ifndef bool
#define bool unsigned int
#endif #define FLASH_HW_KEY 0x08825252
#define FLASH_HW_KEY_0 ((FLASH_HW_KEY <<(32-11)) |(FLASH_HW_KEY>>11))
#define FLASH_HW_KEY_1 ((FLASH_HW_KEY <<(32-20)) |(FLASH_HW_KEY>>20))
#define FLASH_HW_KEY_2 ((FLASH_HW_KEY <<(32-26)) |(FLASH_HW_KEY>>26))
#define FLASH_HW_KEY_3 ((FLASH_HW_KEY <<(32-7)) |(FLASH_HW_KEY>>7)) DWORD cmN_BytesToDWORD(char* bytes)
{
int i;
DWORD value;
value = ;
char* tmpByte;
//printf("cmN_BytesToDWORD %p\n", bytes);
for(i=;i<;i++)
{
tmpByte = &bytes[i];
if(tmpByte)
{
value |= (*tmpByte & 0xFF) <<(*i);
//printf("%x\t ", value);
}
}
return value;
} void cmN_DWORDToBytes(char* bytes, DWORD value)
{
int i;
char* tmpbyte; for(i=;i<;i++)
{
tmpbyte = &bytes[i];
*tmpbyte = (BYTE)(value >> (*i)) & 0xFF;
}
} bool cmN_GetBitFromDword(DWORD data, BYTE i)
{
if( (data>>i)& )
return ;
else
return ;
} DWORD Mix_0(DWORD data)
{
return ( (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<) );
} DWORD Mix_1(DWORD data)
{
return ( (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<) );
} DWORD Mix_2(DWORD data)
{
return ( (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<) );
} DWORD Mix_3(DWORD data)
{
return ( (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<) );
} DWORD unMix_0(DWORD data)
{
return ( (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<) );
}
DWORD unMix_1(DWORD data)
{
return ( (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<) );
} DWORD unMix_2(DWORD data)
{
return ( (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<) );
}
DWORD unMix_3(DWORD data)
{
return ( (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<)
| (cmN_GetBitFromDword(data, )<<) );
} void hwEncodeRawDataForFlash(char * pChar, DWORD length, DWORD ref_address)
{
DWORD tmplength=;
DWORD in_data, data_add, pre_xor_data, out_data;
BYTE type; //to handle for each DWORD
while( tmplength < length)
{
//printf("tmplength %d\n", tmplength);
in_data = cmN_BytesToDWORD(pChar);
data_add = in_data + FLASH_HW_KEY;
type = (BYTE)(ref_address>>) & 0x03; if(type==)
{
pre_xor_data = Mix_0(data_add);
out_data = pre_xor_data^FLASH_HW_KEY_0;
cmN_DWORDToBytes(pChar, out_data); }
else if(type==)
{
pre_xor_data = Mix_1(data_add);
out_data = pre_xor_data^FLASH_HW_KEY_1;
cmN_DWORDToBytes(pChar, out_data);
}
else if(type==)
{
pre_xor_data = Mix_2(data_add);
out_data = pre_xor_data^FLASH_HW_KEY_2;
cmN_DWORDToBytes(pChar, out_data);
}
else if(type==)
{
pre_xor_data = Mix_3(data_add);
out_data = pre_xor_data^FLASH_HW_KEY_3;
cmN_DWORDToBytes(pChar, out_data);
} ref_address += ;
pChar += ;
tmplength += ;
} pChar -= tmplength;
} void hwDecodeRawDataForFlash(char * pChar, DWORD length, DWORD ref_address)
{
DWORD tmplength=;
DWORD in_data, pre_xor_data, out_data;
BYTE type; while( tmplength < length)
{
in_data = cmN_BytesToDWORD(pChar);
type = (BYTE)(ref_address>>) & 0x03;
if(type==)
{
in_data = in_data^FLASH_HW_KEY_0;
pre_xor_data = unMix_0(in_data);
out_data = pre_xor_data - FLASH_HW_KEY;
cmN_DWORDToBytes(pChar, out_data); }
else if(type==)
{
in_data = in_data^FLASH_HW_KEY_1;
pre_xor_data = unMix_1(in_data);
out_data = pre_xor_data - FLASH_HW_KEY;
cmN_DWORDToBytes(pChar, out_data);
}
else if(type==)
{
in_data = in_data^FLASH_HW_KEY_2;
pre_xor_data = unMix_2(in_data);
out_data = pre_xor_data - FLASH_HW_KEY;
cmN_DWORDToBytes(pChar, out_data);
}
else if(type==)
{
in_data = in_data^FLASH_HW_KEY_3;
pre_xor_data = unMix_3(in_data);
out_data = pre_xor_data - FLASH_HW_KEY;
cmN_DWORDToBytes(pChar, out_data);
} ref_address += ;
pChar += ;
tmplength += ;
} pChar -= tmplength;
} #define BUF_SIZE 128 main(int argc,char *argv[])
{
char buf[BUF_SIZE];
char outFile[]; FILE *filein = fopen( argv[], "rb" );
if(filein == NULL) {
printf("open %s fail\n", argv[] );
return ;
}
memset(outFile,,);
sprintf(outFile,"decrypt_%s",argv[]+);
//printf("--->%s\n",outFile);
FILE *fileout=fopen(outFile, "wb" );
if(fileout == NULL) {
printf("open outfile fail\n" );
return ;
} while()
{
int ret = fread(buf, , BUF_SIZE, filein);
if(ret <=)
{
break;
}
hwDecodeRawDataForFlash( &buf[], BUF_SIZE, );
fwrite(buf, , BUF_SIZE, fileout);
}
fclose(filein);
fclose(fileout);
return ; }
C BIN加密的更多相关文章
- AM335X的应用程序自启动流程以及U盘更新应用程序记录
在AM335X的SD卡更新系统学习记录中最后更新完系统后,以后运行应用程序都会从EMMC中取出Linux系统运行.接着介绍Linux系统是怎么自己启动我们编写的应用程序的. 1.在AM335X的SD卡 ...
- Encrypting bootloader (程序BIN文件加密及在线升级)
了解更多关于bootloader 的C语言实现,请加我QQ: 1273623966 (验证信息请填 bootloader),欢迎咨询或定制bootloader(在线升级程序). 在上一个博客随笔,我介 ...
- Encrypted bootloader (程序BIN文件加密及在线升级)
了解更多关于bootloader 的C语言实现,请加我QQ: 1273623966 (验证信息请填 bootloader),欢迎咨询或定制bootloader(在线升级程序). 在上一个博客随笔,我介 ...
- PHP的学习--RSA加密解密
PHP服务端与客户端交互或者提供开放API时,通常需要对敏感的数据进行加密,这时候rsa非对称加密就能派上用处了. 举个通俗易懂的例子,假设我们再登录一个网站,发送账号和密码,请求被拦截了. 密码没加 ...
- 如何使用DotfuscatorPro_4.9对软件进行加密
DotfuscatorPro_4.9可以防止你的.NET软件被反编译,可以在一定程度上防止你的软件被反编译.现在很多软件都有被反编译的现象,虽然不能做到百分百的防范,但是你至少可以先做些技术上的处理, ...
- node.js下使用RSA加密事例(windows)
1.安装openss 直接下载window下的安装包 http://houjixin.blog.163.com/blog/static/3562841020144143494875/ 以我发博文现在的 ...
- php rsa加密解密实例
1.加密解密的第一步是生成公钥.私钥对,私钥加密的内容能通过公钥解密(反过来亦可以) 下载开源RSA密钥生成工具openssl(通常Linux系统都自带该程序),解压缩至独立的文件夹,进入其中的bin ...
- MySQL的SSL加密连接与性能开销
本文转载自:http://www.innomysql.net/article/23959.html(只作转载, 不代表本站和博主同意文中观点或证实文中信息) Contents [hide] 1 前言 ...
- windows下OpenSSL加密证书安装步骤与使用方法
OpenSSL加密证书一般用于签名认证,含私钥和公钥.在Linux系统中,OpenSSL一般是已经安装好了,可以直接使用.而在Windows系统中,是需要安装使用的. 最近在使用支付平台时,用到了Op ...
随机推荐
- [bug report] 当springboot报错 找不到类 javax.xml.bind.JAXBException
<!--以下四个依赖均是javax.xml.bind.JAXBException的依赖 在java6/7/8默认支持,java9不再支持--> <dependency> < ...
- python 字典获取最大和最小的value
my_dict = {, , } key_max = max(my_dict.keys(), key=(lambda k: my_dict[k])) key_min = min(my_dict.key ...
- Android ViewGroup等容器控件的使用
在Android中,可以自定义类,继承ViewGroup等容器类,以实现自己需要的布局显示.如果你在ViewGroup中增加了控件,却无法显示出 来,那么下面这个例子,就可以用来参考了.(主要是要实现 ...
- Spring Boot安装
Spring引导依赖项groupId使用org.springframework.boot. 通常Maven POM文件将继承自spring-boot-starter-parent项目,并将依赖性声明为 ...
- 80端口未被占用,无法启动wamp的解决方法(原创)
起床之后想要弄弄侧边栏的东西,打开wamp居然无法启动apache服务,上网查了之后才知道是需要启动httpd.exe这个程序,测试了很久,80端口也没有被占用,点击启动apache服务的时候弹出co ...
- freemarker多个checkbox一个被选中示例
前端真的不难!!!!! 前端真的不难!!!!! 前端真的不难!!!!! 前端真的不难!!!!! 前端真的不难!!!!! 前端真的不难!!!!! 前端真的不难!!!!! 前端真的不难!!!!! 前端真的 ...
- JavaScript学习总结(二十二)——JavaScript屏蔽Backspace键
今天在IE浏览器下发现,当把使用readonly="readonly"属性将文本框设置成只读<input type="text" readonly=&qu ...
- Laravel框架中Validor中错误信息$error的输出
@if (count($errors) > 0) <div class="alert alert-danger"> <ul> @foreach ($e ...
- 监听器的使用例子 ServletContextListener
之前一直对监听知识有个概念,最近业务需要用到了才真正有点了解了监听器的好处. web项目的监听事件与监听器: ServletAPI中的6个事件类: ServletContextEvent:该类表示上下 ...
- java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout
java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()L ...