Example #1
0
        /// <summary>
        /// Get one char's font data by given bitmap
        /// </summary>
        /// <param name="bmp"></param>
        /// <param name="colorMode"></param>
        /// <param name="scanMode"></param>
        /// <returns></returns>
        public static List <byte> getCharFontData(Bitmap bmp, COLOR_MODE colorMode, SCAN_MODE scanMode)
        {
            List <byte>  bytes = new List <byte>();
            List <Color> colors = new List <Color>();
            int          outsideInitValue, insideInitValue;
            int          outsideStopValue, insideStopValue;
            int          outsideStep, insideStep;
            bool         loopOutsideIsX = true;

            switch (scanMode)
            {
            case SCAN_MODE.ROW_SCAN:
                outsideInitValue = 0;
                outsideStopValue = bmp.Height;
                outsideStep      = 1;
                insideInitValue  = 0;
                insideStopValue  = bmp.Width;
                insideStep       = 1;
                break;

            case SCAN_MODE.COLUMN_SCAN:
                outsideInitValue = 0;
                outsideStopValue = bmp.Width;
                outsideStep      = 1;
                insideInitValue  = 0;
                insideStopValue  = bmp.Height;
                insideStep       = 1;
                break;

            default:
                throw new ArgumentException(Properties.Resources.Err_invalidateScanMode);
            }

            // scan font bitmap
            for (int i = outsideInitValue; i != outsideStopValue; i += outsideStep)
            {
                for (int j = insideInitValue; j != insideStopValue; j += insideStep)
                {
                    if (loopOutsideIsX)
                    {
                        colors.Add(bmp.GetPixel(i, j));
                    }
                    else
                    {
                        colors.Add(bmp.GetPixel(j, i));
                    }
                    j++;
                }
                // convert to byte every row or column
                bytes.AddRange(color2byte(colors, colorMode));
                colors.Clear();
                i++;
            }

            return(bytes);
        }
Example #2
0
        private void UpdateVariables()
        {
            // 扫描模式
            SCAN_MODE mode = rbtnGalv.Checked ? SCAN_MODE.GALVANOMETER : SCAN_MODE.RESONANT;

            m_config.SetScanMode(mode);
            // 扫描策略
            SCAN_STRATEGY strategy = ((KeyValuePair <SCAN_STRATEGY, string>)cbxScanStrategy.SelectedItem).Key;

            m_config.SetScanStartegy(strategy);
            // 振镜系统
            SCAN_MIRROR_NUM mirrorNum = rbtnThree.Checked ? SCAN_MIRROR_NUM.THREEE : SCAN_MIRROR_NUM.TWO;

            m_config.SetScanMirrorNum(mirrorNum);
            // 采集模式 & 采集数量
            SCAN_ACQUISITION_MODE acquisitionMode = ((KeyValuePair <SCAN_ACQUISITION_MODE, string>)cbxAcquisitionMode.SelectedItem).Key;

            m_config.SetScanAcquisitionMode(acquisitionMode);
            // 采集模式数量
            int acquisitionModeNum = (int)cbxAcquisitionModeNum.SelectedItem;

            m_config.SetScanAcquisitionModeNum(acquisitionModeNum);
            // Dwell Time
            m_config.SetScanDwellTime(double.Parse(cbxDwellTime.SelectedItem.ToString()));
            // 扫描像素
            int scanPixels = ((KeyValuePair <int, string>)cbxScanPixels.SelectedItem).Key;

            m_config.SetScanXPoints(scanPixels);
            m_config.SetScanYPoints(scanPixels);
            // 激光[通道]开关状态
            LASER_CHAN_SWITCH status = chbx405.Checked ? LASER_CHAN_SWITCH.ON : LASER_CHAN_SWITCH.OFF;

            m_config.SetLaserSwitch(CHAN_ID.WAVELENGTH_405_NM, status);
            status = chbx488.Checked ? LASER_CHAN_SWITCH.ON : LASER_CHAN_SWITCH.OFF;
            m_config.SetLaserSwitch(CHAN_ID.WAVELENGTH_488_NM, status);
            status = chbx561.Checked ? LASER_CHAN_SWITCH.ON : LASER_CHAN_SWITCH.OFF;
            m_config.SetLaserSwitch(CHAN_ID.WAVELENGTH_561_NM, status);
            status = chbx640.Checked ? LASER_CHAN_SWITCH.ON : LASER_CHAN_SWITCH.OFF;
            m_config.SetLaserSwitch(CHAN_ID.WAVELENGTH_640_NM, status);

            m_params.Calculate();
        }
Example #3
0
        /// <summary>
        /// Get one char's font data by given bitmap
        /// </summary>
        /// <param name="bmp"></param>
        /// <param name="colorMode"></param>
        /// <param name="scanMode"></param>
        /// <returns></returns>
        public static List<byte> getCharFontData(Bitmap bmp, COLOR_MODE colorMode, SCAN_MODE scanMode)
        {
            List<byte> bytes = new List<byte>();
            List<Color> colors = new List<Color>();
            int outsideInitValue, insideInitValue;
            int outsideStopValue, insideStopValue;
            int outsideStep, insideStep;
            bool loopOutsideIsX = true;

            switch (scanMode)
            {
                case SCAN_MODE.ROW_SCAN:
                    outsideInitValue = 0;
                    outsideStopValue = bmp.Height;
                    outsideStep = 1;
                    insideInitValue = 0;
                    insideStopValue = bmp.Width;
                    insideStep = 1;
                    break;
                case SCAN_MODE.COLUMN_SCAN:
                    outsideInitValue = 0;
                    outsideStopValue = bmp.Width;
                    outsideStep = 1;
                    insideInitValue = 0;
                    insideStopValue = bmp.Height;
                    insideStep = 1;
                    break;
                default:
                    throw new ArgumentException(Properties.Resources.Err_invalidateScanMode);
            }

            // scan font bitmap
            for(int i=outsideInitValue; i!=outsideStopValue; i+=outsideStep)
            {
                for(int j=insideInitValue; j!=insideStopValue; j+=insideStep)
                {
                    if (loopOutsideIsX)
                    {
                        colors.Add(bmp.GetPixel(i, j));
                    }
                    else
                    {
                        colors.Add(bmp.GetPixel(j, i));
                    }
                    j++;
                }
                // convert to byte every row or column
                bytes.AddRange(color2byte(colors, colorMode));
                colors.Clear();
                i++;
            }

            return bytes;
        }
Example #4
0
        public static void ScanForAnomalies(Process targetProcess, SCAN_MODE mode)
        {
            Log.LogGeneral($"Scanning {targetProcess.ProcessName}/{targetProcess.Id}");

            var scanList = new List <NT.MEMORY_BASIC_INFORMATION>();

            foreach (ProcessThread thread in targetProcess.Threads)
            {
                var startAddress = thread.GetRealStartAddress();
                var query        = targetProcess.VirtualQuery(startAddress);

                if (query.AllocationBase > 0 && !scanList.Exists(x => x.AllocationBase == query.AllocationBase))
                {
                    scanList.Add(query);
                }

                // GET THREAD INSTRUCTION POINTERS
                // TO PREVENT BYPASSING BY UNMAPPING
                // ALLOCATION BASE AFTER JUMPING TO
                // SOMEWHERE ELSE
                var instructionPointer = thread.GetInstructionPointer(targetProcess.IsWow64());
                var threadQuery        = targetProcess.VirtualQuery(instructionPointer);

                if (threadQuery.AllocationBase > 0 && !scanList.Exists(x => x.AllocationBase == threadQuery.AllocationBase))
                {
                    scanList.Add(threadQuery);
                }
            }

            // GET ALL MODULES VIA EnumProcessModulesEx
            g_linkedModules = targetProcess.GetModules();

            Log.LogInfo($"Finished iterating threads - Scanning {scanList.Count} address(es)", 1);
            scanList.ForEach(scanData =>
            {
                var result = ValidateImage(targetProcess, scanData);

                if (result != PE_SECTION_INFO.Valid)
                {
                    Log.LogWarning($"{scanData.AllocationBase.ToString("x2")} -> {result}", true, 2);
                }
            });

            // DO A DEEPER SCAN BY WALKING THE VIRTUAL ADDRESSES, LOOKING FOR
            // INDEPENDENT EXECUTABLE VIRTUAL PAGES

            Log.LogInfo($"Iterating virtual pages", 1);
            if (mode == SCAN_MODE.DEEP)
            {
                var query = new NT.MEMORY_BASIC_INFORMATION();

                do
                {
                    query = targetProcess.VirtualQuery(query.BaseAddress + query.RegionSize);

                    if (query.State == NT.PAGE_STATE.MEM_FREE)
                    {
                        continue;
                    }

                    if (query.Protect != NT.MemoryProtection.ExecuteReadWrite &&
                        query.Protect != NT.MemoryProtection.ExecuteWriteCopy)
                    {
                        continue;
                    }

                    // TEST IF ADDRESS IS WITHIN ANY LINKED MODULE
                    if (!g_linkedModules.Any(module => IsAddressInsideModule(module, query.BaseAddress)))
                    {
                        Log.LogWarning($"{query.BaseAddress.ToString("x2")} - {query.RegionSize / 1000}kb", query.Type == NT.PAGE_TYPE.MEM_IMAGE, 2);

                        if (query.RegionSize > 400000) // 40kb
                        {
                            var buffer  = targetProcess.ReadMemory(query.BaseAddress, query.RegionSize);
                            var pattern = FindPattern(buffer, "73 6E 78 68 6B 36 34 2E 64 6C 6C");
                        }

                        //if (query.Type == NT.PAGE_TYPE.MEM_IMAGE)
                        //{
                        //    var buffer = targetProcess.ReadMemory(query.BaseAddress, query.RegionSize);
                        //    File.WriteAllBytes(query.BaseAddress.ToString("x2"), buffer);
                        //}
                    }
                } while (query.RegionSize > 0);
            }

            bool IsAddressInsideModule(NT.ModuleInfo module, ulong address) =>
            module.ModuleHandle <= address && (module.ModuleHandle + module.ModuleSize) > address;
        }
Example #5
0
        /// <summary>
        /// Export Font Data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonSave_Click(object sender, EventArgs e)
        {
            // check output settings
            COLOR_MODE colorMode = radioButton8.Checked ? COLOR_MODE.MONO :
                                   radioButton9.Checked ? COLOR_MODE.GRAY4BITS :
                                   radioButton10.Checked ? COLOR_MODE.RGB565 :
                                   radioButton11.Checked ? COLOR_MODE.RGB565P :
                                   COLOR_MODE.UNKONOWN;

            if (colorMode == COLOR_MODE.UNKONOWN)
            {
                Misc.MsgInf(Properties.Resources.Inf_colorMode_required);
                return;
            }
            SCAN_MODE scanMode = radioButtonRow1.Checked ? SCAN_MODE.ROW_SCAN :
                                 radioButtonColumn1.Checked ? SCAN_MODE.COLUMN_SCAN :
                                 SCAN_MODE.UNKOWN;

            if (scanMode == SCAN_MODE.UNKOWN)
            {
                Misc.MsgInf(Properties.Resources.Inf_scanMode_required);
                return;
            }
            string arrayName = textBoxArrayName.Text;

            if (arrayName.Length == 0)
            {
                Misc.MsgInf(Properties.Resources.Inf_arrayName_required);
                return;
            }

            // if content never showed, check input parameters, and show it
            if (fontSettings == null)
            {
                this.toolStripButtonView_Click(null, null);
                if (fontSettings == null)
                {
                    return;
                }
            }

            // user canceled
            if (this.saveFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            if (radioButton13.Checked)
            {
                saveAsBitmap(saveFileDialog1.FileName);
                return;
            }

            // get stream for write font data
            List <byte>   bytes;
            int           iNewLinePosition = Properties.Settings.Default.NewLinePositionOfExport;
            int           pos  = 1;
            Size          size = new Size();
            StringBuilder sb   = new StringBuilder();

            using (Stream ss = this.saveFileDialog1.OpenFile())
            {
                using (StreamWriter sw = new System.IO.StreamWriter(ss))
                {
                    if (!fontSettings.AutoFixWidth)
                    {
                        sw.WriteLine(string.Format(@"const unsigned char {0} = {{", arrayName));
                    }
                    using (Bitmap bmp = new Bitmap(fontSettings.BlockWidth, fontSettings.BlockHeight))
                    {
                        using (Graphics g = Graphics.FromImage(bmp))
                        {
                            // output chars data one by one
                            foreach (char c in fontSettings.Chars)
                            {
                                FontDrawExtend.DrawChar(g, fontSettings, c);
                                bytes = FontDrawExtend.getCharFontData(bmp, colorMode, scanMode, fontSettings, out size);

                                if (fontSettings.AutoFixWidth)
                                {
                                    sw.WriteLine(@"

// char ""{0}""
const unsigned char {1}_{2:X2}_dat[] = {{", c, arrayName, (int)c);
                                    pos = 1;
                                }
                                foreach (byte b in bytes)
                                {
                                    sw.Write("0x{0:X2},", b);
                                    if (iNewLinePosition > 0 && pos == iNewLinePosition)
                                    {
                                        sw.Write(Environment.NewLine);
                                        pos = 0;
                                    }
                                    pos++;
                                }
                                if (fontSettings.AutoFixWidth)
                                {
                                    sw.WriteLine("};");
                                    sw.WriteLine(@"mos_font_data_t {0}_{1:X2} = {{
{2},{3},
&{4}_{5:X2}_dat[0]}};", arrayName, (int)c, size.Width, size.Height, arrayName, (int)c);
                                    sb.Append(String.Format("&{0}_{1:X2},", arrayName, (int)c));
                                }
                            }
                        }
                    }
                    if (fontSettings.AutoFixWidth)
                    {
                        sw.WriteLine(@"


// data list
mos_font_data_t* {0}[] = {{{1}}};", arrayName, sb.ToString());
                    }
                    else
                    {
                        sw.WriteLine("}");
                    }
                }
            }

            // ask for open export file
            if (MessageBox.Show(Properties.Resources.Inf_openFileConfirm,
                                Properties.Resources.Caption_exportMsg,
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Process.Start(this.saveFileDialog1.FileName);
            }
        }
Example #6
0
 public API_RETURN_CODE SetScanMode(SCAN_MODE mode)
 {
     Logger.Info(string.Format("set scan mode: [{0}].", mode));
     m_scan.Mode = mode;
     return(API_RETURN_CODE.API_SUCCESS);
 }
Example #7
0
        /// <summary>
        /// Get one char's font data by given bitmap
        /// </summary>
        /// <param name="bmp"></param>
        /// <param name="colorMode"></param>
        /// <param name="scanMode"></param>
        /// <returns></returns>
        public static List <byte> getCharFontData(Bitmap bmp, COLOR_MODE colorMode, SCAN_MODE scanMode, FontSettings settings, out Size size)
        {
            List <byte>   bytes = new List <byte>();
            StringBuilder sb = new StringBuilder();
            List <Color>  colors = new List <Color>();
            int           outsideInitValue, insideInitValue;
            int           outsideStopValue, insideStopValue;
            int           outsideStep, insideStep;
            bool          loopOutsideIsX = true;
            Rectangle     rect           = new Rectangle(0, 0, settings.BlockWidth, settings.BlockHeight);

            if (settings.AutoFixWidth)
            {
                rect = GetFixedWidthRect(bmp, rect, settings.MinWidth, settings.BackColor);
                size = new Size(rect.Width, rect.Height);
            }
            else
            {
                size = new Size();
            }

            switch (scanMode)
            {
            case SCAN_MODE.ROW_SCAN:
                outsideInitValue = rect.Top;
                outsideStopValue = rect.Bottom;
                outsideStep      = 1;
                insideInitValue  = rect.Left;
                insideStopValue  = rect.Right;
                insideStep       = 1;
                loopOutsideIsX   = false;
                break;

            case SCAN_MODE.COLUMN_SCAN:
                outsideInitValue = rect.Left;
                outsideStopValue = rect.Right;
                outsideStep      = 1;
                insideInitValue  = rect.Top;
                insideStopValue  = rect.Bottom;
                insideStep       = 1;
                loopOutsideIsX   = true;
                break;

            default:
                throw new ArgumentException(Properties.Resources.Err_invalidateScanMode);
            }

            // scan font bitmap
            for (int i = outsideInitValue; i != outsideStopValue; i += outsideStep)
            {
                for (int j = insideInitValue; j != insideStopValue; j += insideStep)
                {
                    if (loopOutsideIsX)
                    {
                        colors.Add(bmp.GetPixel(i, j));
                    }
                    else
                    {
                        colors.Add(bmp.GetPixel(j, i));
                    }
                }
            }

            bytes.AddRange(color2byte(colors, colorMode));

            return(bytes);
        }