惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Spread Privacy
Spread Privacy
T
Tor Project blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Project Zero
Project Zero
C
Cyber Attacks, Cyber Crime and Cyber Security
SecWiki News
SecWiki News
雷峰网
雷峰网
O
OpenAI News
aimingoo的专栏
aimingoo的专栏
Hacker News: Ask HN
Hacker News: Ask HN
Jina AI
Jina AI
Help Net Security
Help Net Security
月光博客
月光博客
S
Secure Thoughts
L
LINUX DO - 热门话题
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
N
News | PayPal Newsroom
爱范儿
爱范儿
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Attack and Defense Labs
Attack and Defense Labs
F
Full Disclosure
The Register - Security
The Register - Security
NISL@THU
NISL@THU
H
Help Net Security
W
WeLiveSecurity
I
Intezer
Engineering at Meta
Engineering at Meta
Martin Fowler
Martin Fowler
F
Fortinet All Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Know Your Adversary
Know Your Adversary
G
GRAHAM CLULEY
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Announcements
Recent Announcements
K
Kaspersky official blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
云风的 BLOG
云风的 BLOG
S
Security @ Cisco Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
IT之家
IT之家
The GitHub Blog
The GitHub Blog
S
Securelist
博客园 - 【当耐特】
Last Week in AI
Last Week in AI
D
Docker
T
Tailwind CSS Blog

博客园 - Charles Chen

.Net Framework 4.x 程序到底运行在哪个 CLR 版本之上(ZT) C#常用工具类——Excel操作类(ZT) C#程序以管理员权限运行(ZT) why happen "WaitHandles must be less than or equal to 64" MS SQL执行大脚本文件时,提示“内存不足”的解决办法() OLDB读取excel的数据类型不匹配的解决方案(ZT) 加密配置文件(App.Config和Web.config)中connectionStrings通用方法 WinForm中使用XML文件存储用户配置及操作本地Config配置文件(zt) 理解DllImportAttribute中的属性 Winform中消息循环、异步操作、Control.Invoke&Control.BeginInvoke学习 Winform打包程序制作的快捷方式指向错误的位置(指向安装包文件) Reflector导出.NET工程项目的修复 存储过程返回值及输出参数笔记 使用本地系统帐户和域用户帐户两者区别(microsoft SQLServer2000)(ZT) SQL字符串的分组聚合(ZT) SQL中使用update inner join和delete inner join (ZT) C# ComboBox(DropDownList)数据绑定后,怎样再添加选项(ZT) 项目维护之WinXP IIS中HTTP500的来龙去脉 一次项目维护案例而对事务学习的笔记
fsn文件解析(C#)
Charles Chen · 2016-09-06 · via 博客园 - Charles Chen

  public class FsnBizNet

    {

        private static int count;

        public static int parseInt(IList<string> list)

        {

            int value = Convert.ToInt32(list[count + 1] + list[count], 2);

            count += 2;

            return value;

        }

        public static string parseString(IList<string> list)

        {

            string value = list[count + 3] + list[count + 2] + list[count + 1] + list[count];

            count += 4;

            return value;

        }

        public static List<string> readFileToBit(string filepath)

        {

            FileStream @in = new FileStream(filepath, FileMode.Open);

            List<string> list = new List<string>();

            long left = @in.Length;//文件大小

            byte[] buffer = new byte[1024];

            int start = 0;//读取位置

            int length = 0; //实际返回结果长度

            while (left > 0)

            {

                @in.Position = start;

                length = 0;

                if (left < buffer.Length)

                    length = @in.Read(buffer, 0, Convert.ToInt32(left));

                else

                    length = @in.Read(buffer, 0, buffer.Length);

                if (length == 0)

                {

                    break;

                }

                start = start + length;

                left = left - length;

                for (int i = 0; i < length; i++)

                {

                    string s = Convert.ToString(buffer[i] | 256, 2);

                    s = s.Substring(s.Length - 8);

                    list.Add(s);

                }

            }

            @in.Close();

            return list;

        }

        public static SnoHead getHead(IList<string> list)

        {

            count = 0;

            FsnBizNet f = new FsnBizNet();

            SnoHead sh = new FsnBizNet.SnoHead(f);

            int[] headStart = new int[4];

            for (int i = 0; i < 4; i++)

            {

                headStart[i] = parseInt(list);

            }

            sh.HeadStart = headStart;

            int[] headString = new int[6];

            for (int i = 0; i < 6; i++)

            {

                headString[i] = parseInt(list);

            }

            sh.HeadString = headString;

            long counter = parseInt(list) + (parseInt(list) << 8);

            sh.Counter = counter;

            int[] headEnd = new int[4];

            for (int i = 0; i < 4; i++)

            {

                headEnd[i] = parseInt(list);

            }

            sh.HeadEnd = headEnd;

            return sh;

        }

        public static IDictionary getSnoExpImg(IList<string> list)

        {

            count = 0;

            IDictionary map = new Hashtable();

            // 设置日期时间

            int data = parseInt(list);

            int time = parseInt(list);

            int y = data >> 9;

            int m = (data - (y << 9)) >> 5;

            int d = data - (y << 9) - (m << 5);

            int hh = time >> 11;

            int mm = (time - (hh << 11)) >> 5;

            int ss = (time - (hh << 11) - (mm << 5)) << 1;

            map["DateTime"] = y + 1980 + "-" + m + "-" + d + " " + hh + ":" + mm + ":" + ss;

            // 设置货币真、假、残和旧币标志

            map["TfFlag"] = parseInt(list);

            // 设置货币错误码(3个)

            string errorCode = "";

            for (int i = 0; i < 3; i++)

            {

                int code = parseInt(list);

                if (code < 13 && code > 0)

                {

                    errorCode += code + ",";

                }

            }

            if ("1".Equals(map["TfFlag"]))

            {

                errorCode = errorCode.Substring(0, errorCode.LastIndexOf(","));

            }

            else

            {

                errorCode = "0";

            }

            map["ErrorCode"] = errorCode;

            // 设置币种标志(4个)

            string moneyFlag = "";

            for (int i = 0; i < 4; i++)

            {

                int flag = parseInt(list);

                if (flag != 0)

                {

                    moneyFlag += (char)flag;

                }

            }

            map["MoneyFlag"] = moneyFlag;

            // 设置年版或版本号标志

            int ver = parseInt(list);

            if (ver == 0)

            {

                ver = 1990;

            }

            if (ver == 1)

            {

                ver = 1999;

            }

            if (ver == 2)

            {

                ver = 2005;

            }

            if (ver == 9999)

            {

                ver = 0;

            }

            map["Ver"] = ver;

            // 设置币值

            map["Valuta"] = parseInt(list);

            // 设置冠字号位数

            map["CharNum"] = parseInt(list);

            // 设置冠字号(12个)

            string no = "";

            for (int i = 0; i < 12; i++)

            {

                int No = parseInt(list);

                if (No != 0)

                {

                    no += (char)No;

                }

            }

            map["Sno"] = no;

            // 设置机具编号(24个)

            string machineSNo = "";

            for (int i = 0; i < 24; i++)

            {

                int Msno = parseInt(list);

                if (Msno != 0)

                {

                    machineSNo += (char)Msno;

                }

            }

            map["MachineSno"] = machineSNo;

            // 设置冠字号保留字

            map["Reserve1"] = parseInt(list);

            return map;

        }

        public static Bitmap getSnoImg(IList<string> list)

        {

            count = 0;

            int num = parseInt(list);

            int height = parseInt(list);

            int width = parseInt(list);

            int Reserve2 = parseInt(list);

            // 根据读取的信息创建图像缓冲区

            Brush bruch = Brushes.White;

            Bitmap image = new Bitmap(width * num, height, PixelFormat.Format32bppRgb);

            System.Drawing.Graphics g = Graphics.FromImage(image);

            g.FillRectangle(bruch, 0, 0, width * num, height);

            g.Dispose();

            int i = 0;

            while (list.Count - count > 0 && i < width * num)

            {

                string s = parseString(list);

                for (int j = 0; j < height && j < s.Length; j++)

                {

                    if (s[j] == '1')

                    {

                         int colorvalue =Convert.ToInt32(0x000000);

                         image.SetPixel(i, j, Color.FromArgb(colorvalue));

                    }

                }

                i++;

            }

            return image;

        }

        public static List<IDictionary> readFile(string path)

        {

            // bit-list

            List<string> listBit = readFileToBit(path);

            // 头文件

            SnoHead sh = getHead(listBit.GetRange(0, 32-0));

            // 冠字号信息条数

            long counter = sh.Counter;

            // 根据冠字号头文件判断是否存在图像,得出一条冠字号信息包含的byte数

            int size = sh.HeadString[2] != 0x2D ? 1644 : 100;

            if (counter * size + 32 == listBit.Count)

            {

                //string imagePath = Thread.CurrentThread.ContextClassLoader.getResource("").Path.Substring(1).Replace("%20", " ");

                string imagePath = AppDomain.CurrentDomain.BaseDirectory.Substring(0).Replace("%20", " ");

                imagePath = Path.Combine(imagePath,"image");

                List<IDictionary> list = new List<IDictionary>();

                for (int i = 0; i < counter; i++)

                {

                    //listBit.ToArray().

                    IDictionary map = getSnoExpImg(listBit.GetRange(i * size + 32, i * size + 132 - (i * size + 32)));

                    if (size != 100)

                    {

                        Bitmap imageSno = getSnoImg(listBit.GetRange(i * size + 132, (i + 1) * size - (i * size + 132)));

                        imageSno.Save(Path.Combine(imagePath,i + ".bmp"), ImageFormat.Bmp);

                        map["ImageSno"] = "image/" + i + ".bmp";

                    }

                    else

                    {

                        map["ImageSno"] = null;

                    }

                    list.Add(map);

                }

                return list;

            }

            return null;

        }

        public class SnoHead

        {

            private readonly FsnBizNet outerInstance;

            public SnoHead(FsnBizNet outerInstance)

            {

                this.outerInstance = outerInstance;

            }

            internal int[] headStart;

            internal int[] headString;

            internal long counter;

            internal int[] HeadEnd_Renamed;

            public virtual int[] HeadStart

            {

                get

                {

                    return headStart;

                }

                set

                {

                    this.headStart = value;

                }

            }

            public virtual int[] HeadString

            {

                get

                {

                    return headString;

                }

                set

                {

                    this.headString = value;

                }

            }

            public virtual long Counter

            {

                get

                {

                    return counter;

                }

                set

                {

                    this.counter = value;

                }

            }

            public virtual int[] HeadEnd

            {

                get

                {

                    return HeadEnd_Renamed;

                }

                set

                {

                    HeadEnd_Renamed = value;

                }

            }

        }

    }