威尼斯人线上娱乐

闲来无事探讨一下酷狗缓存文件kgtemp的加密方法,闲来无事kgtemp

18 5月 , 2019  

此贴为自己原创,转发请注解出处

闲来无事讨论一下酷狗缓存文件kgtemp的加密方法,闲来无事kgtemp

展现图片

今日更新了被打入冷宫很久的酷狗,等进入之后就感到黄花一紧————试 听 居 然 都 要 开 通 音 乐
包(高品和无毒)
才行了,WTF!

那代表在此之前缓存的都听不了了,本着好马不吃回头草的尺码,不筹划去降级了,下载PJ版的又忧郁被植入恶意代码,心好累╮(╯▽╰)╭

用作一个技师,岂能被您那小阴招就制伏,定要给你点颜色看看!

此贴为作者原创,转发请申明出处

main.c

探索

先是相比了1晃缓存文件和下载好的mp叁文书,开采缓存文件多了十二十五个字节,而且相比较了多少个缓存文件,前十二陆个字节都一样,看来使了个障眼法,去掉这拾2四个字节应该正是原版的节奏数据了。

然后下图是加密前后的冲突统1:

威尼斯人线上娱乐 1威尼斯人线上娱乐 2

会发觉加密前的一批0x5伍 加密后改成 0xA玖 0xE玖 0xDA
0x5二循环往复了,表明是用了四字节的循环加密,然后切换来二进制钻探

加密前 0x55 0x55 0x55 0x55   01010101 01010101 01010101 01010101

加密后 0xA9 0xE9 0xDA 0x52   10101001 11101001 11011010 01010010

对称逐字节加密的演算也就循环移位只怕异或固定的数或许取反,但地方的几组数循环移位和取反都不太像,就先如若是异或固定的数A
B C D,接下去做填空题:

0x55 0x55 0x55 0x55   01010101 01010101 01010101 01010101

A       B      C      D        11111100 10111100 10001111 00000111

0xA9 0xE9 0xDA 0x52   10101001 11101001 11011010 01010010

搜查缉获:A B C D分别为0xFC 0xBC 0x八F 0x0七 ,然后取开头的数目证实:

加密前 0x49 0x44 0x33 0x03   01001001 01000100 00110011 00000011

xor     0x3C 0xAC 0xEF 0x67   00111100 10101100 11101111 01100111

加密后 0x75 0xE8 0xDC 0x64   01110101 11101000 11011100 01100100

这次的A B C D分别为0x3C 0xAC 0xEF 0x67

纳尼?不是牢固的?WTF! 

两组A B C D低2位的数字都以 C C F 柒

如上所述最后结出真的是xor总括来的,只是高多少人的数值要复杂一些。

依靠0 xor X =X的性质,小编找了1组全0的加密内外的比较,

加密前 0x00 0x00 0x00 0x00   00000000 00000000 00000000 00000000

加密后 0xAC 0xEC 0xDF 0x57   10101100 11101100 11011111 01010111

那A B C D高4人就对应 0xA 0xE 0xD 0x五

再用起来的多寡表达:

加密前 0x49 0x44 0x33 0x03   01001001 01000100 00110011 00000011

xor     0xAC 0xEC 0xDF 0x57  10101100 11101100 11011111 01010111

加密后 0xE5 0xA8 0xEC 0x54 11100101 10101000 11101100 01010100

依旧不对,而且开采一些:只要加密前的数的高四人=低三个人,加密后的高几个人都固定为0xA
0xE 0xD 0x伍

这不就是xor 中的两个数的高2位吗,由(0 xor X=X)和(X xor
X=0)可见,高3个人的算法应该是如此的:

分级取输入数的高三位和低四个人H,L, 然后取xor的高几人I 结果Y= H xor L xor I

教导后面包车型客车三组数据验算,都对了^_^

前日更新了被打入冷宫很久的酷狗,等跻身之后就以为金蕊一紧————试 听 居
然 都 要 开 通 音 乐 包(高品和无毒)
才行了,WTF!

那意味以前缓存的都听不了了,本着好马不吃回头草的标准,不筹算去降级了,下载PJ版的又忧虑被植入恶意代码,心好累╮(╯▽╰)╭

用作四个程序员,岂能被你那小阴招就制服,定要给您点颜色看看!

#include<reg51.h>
#include”st7565.h”
//—存四个图片–//
unsigned char code pic[]={
/*– 宽度x高度=128×64 –*/
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,
0x57,0x53,0x57,0x07,0xFF,0x0F,0xE3,0x0F,0xEF,0xFF,0xEF,0xEF,0xEF,0x03,0xEF,0xEF,
0xEF,0x0F,0xE3,0x0F,0xEF,0xFF,0x77,0x77,0x17,0x57,0x57,0x53,0x57,0x57,0x17,0x77,
0x77,0xFF,0xFB,0x8B,0xAB,0x83,0xAB,0x83,0xAB,0x8B,0xFF,0x37,0xDB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0xB7,0x6C,0x6C,0x6F,0x6F,0xB6,0xB6,
0xDB,0xCB,0xD5,0xAA,0x2F,0x37,0x7B,0xFC,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFC,0xF9,0xF3,0xF7,0xFB,0xFD,0xFE,0xFF,
0xFF,0xFF,0xFE,0xFC,0xF9,0xF3,0xF7,0xFB,0xFD,0xFE,0xFF,0xDF,0xDF,0xC1,0xC8,0xDC,
0xFF,0xF8,0xF7,0xEF,0xDF,0xF8,0xF2,0xF2,0xF8,0xFC,0xFE,0xFC,0xFC,0xFE,0xFC,0xF8,
0xF2,0xD2,0xE8,0xF7,0xF8,0xFF,0xDC,0xC8,0xC1,0xC3,0xC7,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFC,0xF9,0xF3,0xF7,0xFB,0xFD,0xFE,0xFF,
0xFF,0xFF,0xFE,0xFC,0xF9,0xF3,0xF7,0xFB,0xFD,0xFE,0xFF,0xDF,0xDF,0xC1,0xC8,0xDC,
0xFF,0xF8,0xF7,0xEF,0xDF,0xF8,0xF2,0xF2,0xF8,0xFC,0xFE,0xFC,0xFC,0xFE,0xFC,0xF8,
0xF2,0xD2,0xE8,0xF7,0xF8,0xFF,0xDC,0xC8,0xC1,0xC3,0xC7,0xFF,0xFF,0xFF,0xFF,0xFF,
};

撸码

既是加密算法已经猜出来了,就撸码验证一下,看解密后的文书的MD5与缓存文件名是不是等于:

class Program
    {
        static void Main(string[] args)
        {

            byte[] key={0xAC,0xEC,0xDF,0x57};
            using (var input = new FileStream(@"E:\KuGou\Temp\236909b6016c6e98365e5225f488dd7a.kgtemp", FileMode.Open, FileAccess.Read))
            {
                var output = File.OpenWrite(@"d:\test.mp3");//输出文件
                input.Seek(1024, SeekOrigin.Begin);//跳过1024字节的包头
                byte[] buffer = new byte[key.Length];
                int length;
                while((length=input.Read(buffer,0,buffer.Length))>0)
                {
                    for(int i=0;i<length;i++)
                    {
                        var k = key[i];
                        var kh = k >> 4;
                        var kl = k & 0xf;
                        var b = buffer[i];
                        var low = b & 0xf ^ kl;//解密后的低4位
                        var high = (b >> 4) ^ kh ^ low & 0xf;//解密后的高4位
                        buffer[i] = (byte)(high << 4 | low);
                    }
                    output.Write(buffer, 0, length);
                }
                output.Close();
            }
            Console.WriteLine("按任意键退出...");
            Console.ReadKey();
        }
    }

 

 

结果:输出文件的MD五与缓存文件名同样,水到渠成

探索

率先比较了弹指间缓存文件和下载好的mp三文件,开采缓存文件多了十二五个字节,而且比较了多少个缓存文件,前拾二五个字节都1律,看来使了个障眼法,去掉这10二多少个字节应该正是原版的节拍数据了。

下一场下图是加密内外的自己检查自纠:

威尼斯人线上娱乐 3

会发掘加密前的一群0x55 加密后形成 0xA玖 0xE九 0xDA
0x52巡回了,表明是用了4字节的巡回加密,然后切换到二进制研讨

加密前 0x55 0x55 0x55 0x55   01010101 01010101 01010101 01010101

加密后 0xA9 0xE9 0xDA 0x52   10101001 11101001 11011010 01010010

对称逐字节加密的运算也就循环移位可能异或固定的数或许取反,但地点的几组数循环移位和取反都不太像,就先假使是异或固定的数A
B C D,接下去做填空题:

0x55 0x55 0x55 0x55   01010101 01010101 01010101 01010101

A       B      C      D        11111100 10111100 10001111 00000111

0xA9 0xE9 0xDA 0x52   10101001 11101001 11011010 01010010

得出:A B C D分别为0xFC 0xBC 0x捌F 0x0七 ,然后取起先的多少表达:

加密前 0x49 0x44 0x33 0x03   01001001 01000100 00110011 00000011

xor     0x3C 0xAC 0xEF 0x67   00111100 10101100 11101111 01100111

加密后 0x75 0xE8 0xDC 0x64   01110101 11101000 11011100 01100100

这次的A B C D分别为0x3C 0xAC 0xEF 0x67

纳尼?不是永世的?WTF! 

两组A B C D低二人的数字都以 C A F 七

如上所述最终结出真的是xor总括来的,只是高四个人的数值要复杂一些。

听新闻说0 xor X =X的品质,作者找了一组全0的加密上下的自己检查自纠,

加密前 0x00 0x00 0x00 0x00   00000000 00000000 00000000 00000000

加密后 0xAC 0xEC 0xDF 0x57   10101100 11101100 11011111 01010111

那A B C D高二位就对应 0xA 0xE 0xD 0x五

再用起来的数目证实:

加密前 0x49 0x44 0x33 0x03   01001001 01000100 00110011 00000011

xor     0xAC 0xEC 0xDF 0x57  10101100 11101100 11011111 01010111

加密后 0xE5 0xA8 0xEC 0x54 11100101 10101000 11101100 01010100

恐怕不对,而且发掘某个:只要加密前的数的高二个人=低二个人,加密后的高四位都稳固为0xA
0xE 0xD 0x五

那不就是xor 中的五个数的高四位呢,由(0 xor X=X)和(X xor
X=0)可见,高几个人的算法应该是那样的:

取分别取输入数的高3个人和低三个人H,L, 然后取xor的高几位I 结果Y= H xor L xor I

带走前边的3组数据验算,都对了^_^

/*******************************************************************************
* 函 数 名 : main
* 函数成效 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/

总结

确定地点要异或的key={0xAC,0xEC,0xDF,0x57}

加密艺术如下:

1.设输入的数为x,输出结果为y,循环变量为i;

2.分别取x的高4位和低4位h,l;  h=x >> 4 ; l=x & 0xf;

3.分别取key[i]的高4位和低4位kh,kl;kh=key[i] >> 4;kl=key[i] &
0xf;

4.y=h ^ l ^ kh;

5.y=y<< 4 | (l ^ kl);

解密格局如下:

1.设输入的数为x,输出结果为y,循环变量为i;

2.分别取x的高4位和低4位h,l;h=x >> 4 ; l=x & 0xf;

3.分别取key[i]的高4位和低4位kh,kl;kh=key[i] >> 4;kl=key[i] &
0xf;

4.y=l ^ kl;

5.y=(h ^ kh ^ y)<<4 | y;

撸码

既然加密算法已经猜出来了,就撸码验证一下,看解密后的文本的MD伍与缓存文件名是还是不是等于:

class Program
    {
        static void Main(string[] args)
        {

            byte[] key={0xC,0xC,0xF,0x7};
            byte[] xor = { 0xA, 0xE, 0xD, 0x5 };
            using (var input = new FileStream(@"E:\KuGou\Temp\236909b6016c6e98365e5225f488dd7a.kgtemp", FileMode.Open, FileAccess.Read))
            {
                var output = File.OpenWrite(@"d:\test.mp3");//输出文件
                input.Seek(1024, SeekOrigin.Begin);//跳过1024字节的包头
                byte[] buffer = new byte[key.Length];
                int length;
                while((length=input.Read(buffer,0,buffer.Length))>0)
                {
                    for(int i=0;i<length;i++)
                    {
                        var b = buffer[i];
                        var low = b & 0xf ^ key[i];//解密后的低4位
                        var high = (b >> 4) ^ xor[i] ^ low & 0xf;//解密后的高4位
                        buffer[i] = (byte)(high << 4 | low);
                    }
                    output.Write(buffer, 0, length);
                }
                output.Close();
            }
            Console.WriteLine("按任意键退出...");
            Console.ReadKey();
        }
    }

 

结果:输出文件的MD5与缓存文件名一样,大功告成

此贴为本身原创,转发请注脚出处 序
前些天更新了被打入冷宫很久的酷狗…

void main(void)
{
uchar i , j;
uint n;
Lcd12864_Init(); //初始化
Lcd12864_ClearScreen(); //清屏

for (i=0;i<8;i++)
{
威尼斯人线上娱乐 ,//–设置开始突显初阶地方–//
LcdSt7565_WriteCmd(0x40);

//–设置Y坐标–//
LcdSt7565_WriteCmd(0xB0+i);

//–设置X坐标–//
LcdSt7565_WriteCmd(0x10);
LcdSt7565_WriteCmd(0x04);
for(j=0; j<128; j++)
{
LcdSt7565_WriteData(~pic[n]);
n=n+1;
}
}
while (1)
{
}
}

 

st7565.c

#include”st7565.h”

/*******************************************************************************
* 函 数 名 : LCD12864_WriteCmd
* 函数功用 : 写入多个命令到1286四
* 输 入 : cmd
* 输 出 : 无
*******************************************************************************/

void LcdSt7565_WriteCmd(cmd)
{
LCD12864_CS = 0; //chip select,打开片选
LCD12864_RD = 1; //disable read,读失能
LCD12864_奥迪Q7S = 0; //select command,选用命令
LCD12864_中华VW = 0; //select write,选取写格局
_nop_();
_nop_();

DATA_PORT = cmd; //put command,放置命令
_nop_();
_nop_();

LCD12864_MuranoW = 壹; //command writing ,写入命令
}

/*******************************************************************************
* 函 数 名 : LcdSt7565_WriteData
* 函数功效 : 写入3个数目到1286四
* 输 入 : dat
* 输 出 : 无
*******************************************************************************/

void LcdSt7565_WriteData(dat)
{
LCD12864_CS = 0; //chip select,打开片选
LCD12864_RD = 1; //disable read,读失能
LCD12864_奥迪Q3S = 一; //select data,选拔数据
LCD12864_HighlanderW = 0; //select write,选用写方式
_nop_();
_nop_();

DATA_PORT = dat; //put data,放置数据
_nop_();
_nop_();

LCD12864_RW = 1; //data writing,写数据
}
/*******************************************************************************
* 函 数 名 : LCD12864_Init
* 函数成效 : 先导化1286四
* 输 入 : 无
* 输 出 : 无
* 说 明 : LCD1286四的指令指令能够查看例程文件夹下的《ST75六5p数据手册》
* * 的第陆一页的岗位。
*******************************************************************************/

void Lcd12864_Init()
{
uchar i;
LCD12864_RSET = 0;
for (i=0; i<100; i++);
LCD12864_CS = 0;
LCD12864_RSET = 1;

//—————-Star Initial Sequence——-//
//——程序初叶化设置,具体命令能够看文件夹下—//

//–软件开始化–//
LcdSt7565_WriteCmd(0xE2); //reset
for (i=0; i<100; i++); //延时转手

//–表格第几个指令,0xA0段(左右)方向选取正规方向(0xA一为反方向)–//
LcdSt7565_WriteCmd(0xA1); //ADC select segment direction

//–表格第3多少个指令,0xC捌常备(上下)方向选用采纳反向,0xC0为正规方向–//
LcdSt7565_WriteCmd(0xC8); //Common direction

//–表格第七个指令,0xA陆为设置字体为深红,背景为宝石蓝—//
//–0xA七为设置字体为樱草黄,背景为中灰—//
LcdSt7565_WriteCmd(0xA6); //reverse display

//–表格第玖个指令,0x西玛像素符合规律展现,0xA5像素全开–//
LcdSt7565_WriteCmd(0xA4); //normal display

//–表格第11个命令,0xA3偏压为1/7,0xA2偏压为1/9–//
LcdSt7565_WriteCmd(0xA2); //bias set 1/9

//–表格第2柒个指令,那么些是个双字节的下令,0xF800挑选增压为4X;–//
//–0xF80一,采用增压为五X,其实际效果果大约–//
LcdSt7565_WriteCmd(0xF8); //Boost ratio set
LcdSt7565_WriteCmd(0x01); //x4

//–表格第二7个指令,这一个是个双字节命令,高字节为0X八一,低字节可以–//
//–接纳从0x00到0X三F。用来安装背景光相比度。—/
LcdSt7565_WriteCmd(0x81); //V0 a set
LcdSt7565_WriteCmd(0x23);

//–表格第叁玖个指令,选用调解电阻率–//
LcdSt7565_WriteCmd(0x25); //Ra/Rb set

//–表格第二多少个指令,电源设置。–//
LcdSt7565_WriteCmd(0x2F);
for (i=0; i<100; i++);

//–表格第三个指令,设置展现开端地点–//
LcdSt7565_WriteCmd(0x40); //start line

//–表格第三个指令,开启突显–//
LcdSt7565_WriteCmd(0xAF); // display on
for (i=0; i<100; i++);

}

/*******************************************************************************
* 函 数 名 : LCD12864_ClearScreen
* 函数功效 : 清屏1286四
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/

void Lcd12864_ClearScreen(void)
{
uchar i, j;

for(i=0; i<8; i++)
{
//–表格第3个命令,设置Y的坐标–//
//–Y轴有六十八个,五个坐标五个人,也正是有九个坐标–//
//所以一般大家采用的也便是从0xB0到0x07,就够了–//
LcdSt7565_WriteCmd(0xB0+i);

//–表格第4个命令,设置X坐标–//
//–当您的段初叶化为0xA1时,X坐标从0x十,0x0肆到0x1捌,0x0肆,1共1二十七人–//
//–当您的段开首化为0xA0时,X坐标从0x10,0x00到0x18,0x00,1共1二十六个人–//
//–在写入数据今后X坐标的坐标是会自动加一的,大家早先化使用0xA0所以–//
//–我们的X坐标从0x10,0x00开始—//
LcdSt7565_WriteCmd(0x10);
LcdSt7565_WriteCmd(0x04);

//–X轴有1二十七位,就一同刷135遍,X坐标会自动加一,所以我们绝不再设置坐标–//
for(j=0; j<128; j++)
{
LcdSt7565_WriteData(0x00); //即使设置背景为葡萄紫时,清屏选取0XFF
}
}
}

/*******************************************************************************
* 函 数 名 : LCD12864_Write16CnCHAR
* 函数功用 : 在1286四方面书写1陆X1六的汉字
* 输 入 : x, y, cn
* 输 出 : 无
* 说 明 : 该函数能够一贯书写字符串,不过书写是从右到左,所以输入的时
* * 侯注意输入。汉字的取模方式请观望文件夹下的《汉字取模软件的
* * 使用验证》
*******************************************************************************/

#ifdef CHAR_CODE

#include”charcode.h”

uchar Lcd12864_Write16CnCHAR(uchar x, uchar y, uchar *cn)
{
uchar j, x1, x2, wordNum;

//–Y的坐标只可以从0到七,大于则间接回到–//
if(y > 7)
{
return 0;
}

//–X的坐标只可以从0到128,大于则一直再次来到–//
if(x > 128)
{
return 0;
}
y += 0xB0; //求取Y坐标的值
//–设置Y坐标–//
LcdSt7565_WriteCmd(y);
while ( *cn != ‘\0’) //在C语言中字符串截至以‘\0’结尾
{

//–设置Y坐标–//
LcdSt7565_WriteCmd(y);

x壹 = (x >> 四) & 0x0F;
//由于X坐标要两句发号施令,分高低三人,所以那边先收取高4位
x二 = x & 0x0F; //去低四人
//–设置X坐标–//
LcdSt7565_WriteCmd(0x10 + x1); //高4位
LcdSt7565_WriteCmd(0x04 + x2); //低4位

for (wordNum=0; wordNum<50; wordNum++)
{
//–查询要写的字在字库中的地方–//
if ((CN16CHAR[wordNum].Index[0] == *cn)
&&(CN16CHAR[wordNum].Index[1] == *(cn+1)))
{
for (j=0; j<3二; j++) //写3个字
{
if (j == 1陆) //由于16X1陆用到多个Y坐标,当不仅仅等于16时,切换坐标
{
//–设置Y坐标–//
LcdSt7565_WriteCmd(y + 1);

//–设置X坐标–//
LcdSt7565_WriteCmd(0x10 + x1); //高4位
LcdSt7565_WriteCmd(0x04 + x2); //低4位
}
LcdSt7565_WriteData(CN16CHAR[wordNum].Msk[j]);
}
x += 16;
}//if查到字说尽
} //for查字截至
cn += 2;
} //while结束
return 1;
}

#endif

 st7565.h

//—重定义关键词—//
#ifndef uchar
#define uchar unsigned char
#endif

#ifndef uint
#define uint unsigned int
#endif

//–定期选择的IO口–//
#define DATA_PORT P0
sbit LCD12864_CS = P3^2;
sbit LCD12864_RSET = P3^3;
sbit LCD12864_RS = P2^6;
sbit LCD12864_RW = P2^7;
sbit LCD12864_RD = P2^5;

//–定义全局函数–//
void LcdSt7565_WriteCmd(cmd);
void LcdSt7565_WriteData(dat);
void Lcd12864_Init();
void Lcd12864_ClearScreen(void);
uchar Lcd12864_Write16CnCHAR(uchar x, uchar y, uchar *cn);

#endif

 

 

展现汉字

main.c

#include<reg51.h>
#include”st7565.h”

//—声美素佳儿(Friso)个全局变量—//
void Delay10ms(unsigned int c);

/*******************************************************************************
* 函 数 名 : main
* 函数效率 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/

void main()
{
uchar i = 128;
Lcd12864_Init();
Lcd12864_ClearScreen();

while (1)
{
for (i=0; i<8; i += 2)
{
Lcd12864_ClearScreen();

//–由于这些函数字突显示方向正好相反–//
Lcd12864_Write1陆CnCHA哈弗(0, i, “司公限有技科中普”);
Delay10ms(100);
}

}
}

/*******************************************************************************
* 函 数 名 : Delay10ms
* 函数功用 : 延时函数,延时十ms
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/

void Delay10ms(unsigned int c) //误差 0us
{
unsigned char a,b;
for(;c>0;c–)
for(b=38;b>0;b–)
for(a=130;a>0;a–);
}

 

CHARCODE.H

#ifndef __CHARCODE_H
#define __CHARCODE_H

#ifdef CHAR_CODE

// —————— 汉字字模的数据结构定义 ————————
//
struct Cn1陆CharTypeDef // 汉字字模数据结构
{
unsigned char Index[2]; // 汉字内码索引,1在这之中华人民共和国字占七个字节
unsigned char Msk[32]; // 点阵码数据(1六*16有32个数据)
};

struct Cn16CharTypeDef code CN16CHAR[]=
{
/*– 文字: 普 –*/
/*– 宋体1二; 此字体下相应的点阵为:宽x高=16×1陆 –*/
“普”,0x00,0x40,0x44,0x54,0x64,0x45,0x7E,0x44,0x44,0x44,0x7E,0x45,0x64,0x54,0x44,0x40,
0x00,0x00,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,

/*– 文字: 中 –*/
/*– 金鼎文1二; 此字体下相应的点阵为:宽x高=1陆x16 –*/
“中”,0x00,0x00,0xFC,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0xFC,0x08,0x00,0x00,
0x00,0x00,0x07,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x07,0x00,0x00,0x00,
/*– 文字: 科 –*/
/*– 大篆1贰; 此字体下相应的点阵为:宽x高=1陆x1陆 –*/
“科”,0x00,0x00,0x00,0xFF,0x00,0x00,0xCC,0x22,0x00,0x91,0x51,0xFE,0x72,0x92,0x12,0x10,
0x00,0x01,0x01,0xFF,0x02,0x02,0x02,0x04,0x04,0x04,0x00,0xFF,0x00,0x01,0x02,0x04,
/*– 文字: 技 –*/
/*– 燕书12; 此字体下相应的点阵为:宽x高=16×1六 –*/
“技”,0x00,0x08,0x48,0xC8,0x48,0x7F,0x48,0x48,0xC8,0x00,0x28,0x48,0xFF,0x88,0x08,0x08,
0x00,0x20,0x60,0x21,0x12,0x0C,0x0C,0x13,0x20,0x40,0x40,0x00,0x7F,0x80,0x41,0x01,
/*– 文字: 有 –*/
/*– 黑体1二; 此字体下相应的点阵为:宽x高=16×1陆 –*/
“有”,0x00,0x04,0x04,0x04,0xE4,0x24,0x24,0x24,0x27,0x2C,0x34,0xE4,0x44,0x84,0x04,0x00,
0x00,0x00,0x00,0x00,0x7F,0xC9,0x49,0x29,0x09,0x09,0x09,0xFF,0x00,0x00,0x01,0x02,

/*– 文字: 限 –*/
/*– 行书12; 此字体下相应的点阵为:宽x高=16×1陆 –*/
“限”,0x00,0x00,0x00,0x7E,0x4A,0x4A,0x4A,0xCA,0x4A,0xFE,0x00,0x82,0x4E,0x32,0x02,0xFE,
0x00,0x20,0x60,0x21,0x12,0x0C,0x03,0x20,0x40,0xFF,0x00,0x03,0x04,0x02,0x00,0xFF,

/*– 文字: 公 –*/
/*– 大篆12; 此字体下相应的点阵为:宽x高=1六x1陆 –*/
“公”,0x00,0x80,0x80,0xC0,0x60,0x10,0x0E,0x00,0x00,0x84,0x0E,0x30,0x40,0x80,0x00,0x00,
0x00,0x00,0x01,0x30,0x78,0x14,0x10,0x10,0x31,0x23,0x24,0x28,0x70,0x20,0x01,0x00,

/*– 文字: 司 –*/
/*– 黑体1二; 此字体下相应的点阵为:宽x高=16×16 –*/
“司”,0x00,0x00,0xFE,0x02,0x02,0x12,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x10,0x00,
0x00,0x00,0x3F,0x40,0x20,0x00,0x0F,0x04,0x04,0x04,0x04,0x04,0x04,0x1F,0x00,0x00,

};

#endif //end of CHAR_CODE

#endif


相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图