Esempio n. 1
0
        /// <summary>
        /// This is available only on Windows 10 / Windows Server 2016 and up.
        /// It does not scan and returns a "no malware found" indication on earlier systems.
        /// </summary>
        public static bool IsMalware(string ConsumerAppName, byte[] input, string contentName)
        {
            IntPtr amsiContext;
            IntPtr session;
            var    result = AMSI_RESULT.AMSI_RESULT_NOT_DETECTED;
            int    returnValue;

            try
            {
                returnValue = AmsiInitialize(ConsumerAppName, out amsiContext);
                returnValue = AmsiOpenSession(amsiContext, out session);
                returnValue = AmsiScanBuffer(amsiContext, input, (ulong)input.LongLength, contentName, session, out result);
                AmsiCloseSession(amsiContext, session);
                AmsiUninitialize(amsiContext);
            }
            catch (DllNotFoundException dex)
            {
                Tracing.ErrorCore("AMSI malware detection: {0}", dex.ToString());

                /* for PEN test, when we do not have a real AMSI detector,
                 * then we just detect the eicar file by hand
                 * KEEP THIS SEPARATED so TFS and local developer computers don't choke on this very file!! */
                if (input != null && input.Length > 0)
                {
                    var part = new byte[Math.Min(input.Length, 255)];
                    for (var i = 0; i < part.Length; ++i)
                    {
                        part[i] = input[i];
                    }
                    if (System.Text.ASCIIEncoding.ASCII.GetString(part).Contains(@"X5O!P%@AP[4\PZX54(P^)7CC)7}$EI" + @"CAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                /* [dlatikay 20190316] MEA-2019-00154 for diagnostics */
                Tracing.ErrorSecurity("{0}: scanning \"{1}\" for malware: {2}", ConsumerAppName, contentName, ex.ToString());
            }
            return(result.HasFlag(AMSI_RESULT.AMSI_RESULT_DETECTED));
        }
Esempio n. 2
0
        /// <summary>
        /// The German Dienstwegeunfallfragebogen
        /// (test harness)
        /// </summary>
        public bool RenderRep0010(out MemoryStream chunk, out string mime, out string encoding, out string uri, BuiltinReportDescriptor data)
        {
            /* make a direct (synchronous) PDF off the rdlc */
            chunk    = new MemoryStream();
            mime     = sherm.core.formatting.mime.cstMIMEPDF;
            encoding = Encoding.UTF8.EncodingName;
            uri      = "Wegeunfallfragebogen.pdf";
            try
            {
                var dt                   = data.DataDescriptor.Data.Tables[ReportDatatableIdentifiers.REPORT_DATATABLE_HARDCOPY_ACCIDENTTRAVEL];
                var dr                   = dt.Rows[0];
                var repRepDate           = dr["fRepRepDate"].ToString();
                var repPersNr            = dr["PersNr"].ToString();
                var repRequestorname     = string.Format("{0}", dr["Requestorname"].ToString());
                var repRequestorPosition = string.Format("{0}", dr["RequestorPosition"].ToString());
                var repTravelOrder       = dr["TravelOrder"].ToString();
                var RepPersonInfo        = string.Format("{0} {1} geb. {2}", dr["Firstname"].ToString(), dr["Lastname"].ToString(), dr["fPersDoB"].ToString());

                var repAccidentInfo          = string.Format(" - Unfall vom {0} - ", dr["fEventDate"].ToString());
                var repTavelStartDatePlace   = InjectCommas(dr["TravelStartPlace"].ToString(), dr["fTravelStartdate"].ToString(), dr["fTravelStarttime"].ToString());
                var repReturnDateReturnPlace = InjectCommas(dr["ReturnPlace"].ToString(), dr["fReturnDate"].ToString(), dr["ReturnTime"].ToString());

                var repAccidentLocation = dr["AccidentLocation"].ToString();
                var repAccidentRoute    = dr["AccidentRoute"].ToString();

                var repRouteMatchesOrder = ToYesNoString(dr["RouteMatchesOrder"].ToString());
                var repsObjective        = dr["sObjective"].ToString();

                var repLastContactBeforeAcc = dr["LastContactBeforeAcc"].ToString();
                var repLastContactDate      = InjectCommas(dr["fLastContactEnddate"].ToString(), dr["fLastContactEndtime"].ToString());
                var repNextPlannedDest      = dr["NextPlannedDest"].ToString();
                int travelflags             = 0;
                int.TryParse(dr["Travelflags"].ToString(), out travelflags);

                bool isSetPrivateMatters = ((AccidentFlags)(travelflags)).HasFlag(AccidentFlags.PrivateMatters);
                bool isSetPolicereport   = ((AccidentFlags)(travelflags)).HasFlag(AccidentFlags.Policereport);

                var repPrivateMatters = ToYesNoString(isSetPrivateMatters); //dr["PrivateMatters"].ToString();
                var repPolicereport   = ToYesNoString(isSetPolicereport);   //["Policereport"].ToString();

                var isSetOpponent      = ToYesNoString(((AccidentFlags)(travelflags)).HasFlag(AccidentFlags.Opponent));
                var repOpponentName    = string.Format("{0}", dr["OpponentName"].ToString());
                var repOpponentAddress = string.Format("{0}", dr["OpponentAddress"].ToString());
                var repOpponentLicence = string.Format("{0}", dr["OpponentLicence"].ToString());


                var isSetLegal     = ToYesNoString(((AccidentFlags)(travelflags)).HasFlag(AccidentFlags.Legal));
                var isSetCompanion = ToYesNoString(((AccidentFlags)(travelflags)).HasFlag(AccidentFlags.Companion));
                var isSetReuptake  = ToYesNoString(((AccidentFlags)(travelflags)).HasFlag(AccidentFlags.Reuptake));

                var repLegalWho       = dr["LegalWho"].ToString();
                var repLegalReference = dr["LegalReference"].ToString();

                var repCompanionName    = dr["CompanionName"].ToString();
                var repCompanionAddress = dr["CompanionAddress"].ToString();

                var repReuptakeDate = dr["fReuptakeDate"].ToString();

                var rpt_format = "PDF";
                /* instantiate and render the rdlc */
                var rpt = new LocalReport()
                {
                    ReportEmbeddedResource = "sherm.rpt.msdbrpt.ReportHardcopyTravelQuestionnaire.rdlc",
                    EnableExternalImages   = true
                };
                rpt.SetParameters(new ReportParameter[]
                {
                    new ReportParameter("RepPersonInfo", RepPersonInfo),     // geb.
                    new ReportParameter("RepAccidentInfo", repAccidentInfo), // Datum in "Unfall vom 01.01.2018"
                    new ReportParameter("RepRepDate", repRepDate),           // report date used to display current date.

                    new ReportParameter("RepPersNr", repPersNr),             // PerNum

                    new ReportParameter("RepRequestorname", repRequestorname),
                    new ReportParameter("RepRequestorPosition", repRequestorPosition),

                    new ReportParameter("RepTravelOrder", repTravelOrder),

                    new ReportParameter("RepTavelStartDatePlace", repTavelStartDatePlace),
                    new ReportParameter("RepReturnDateReturnPlace", repReturnDateReturnPlace),

                    new ReportParameter("RepAccidentLocation", repAccidentLocation),
                    new ReportParameter("RepAccidentRoute", repAccidentRoute),
                    new ReportParameter("RepRouteMatchesOrder", repRouteMatchesOrder),

                    new ReportParameter("RepsObjective", repsObjective),

                    new ReportParameter("RepLastContactBeforeAcc", repLastContactBeforeAcc),
                    new ReportParameter("RepLastContactDate", repLastContactDate),
                    new ReportParameter("RepNextPlannedDest", repNextPlannedDest),

                    new ReportParameter("RepPrivateMatters", repPrivateMatters),
                    new ReportParameter("repPolicereport", repPolicereport),

                    new ReportParameter("Param_22", isSetOpponent),
                    new ReportParameter("RepOpponentName", repOpponentName),
                    new ReportParameter("RepOpponentAddress", repOpponentAddress),
                    new ReportParameter("RepOpponentLicence", repOpponentLicence),

                    new ReportParameter("Param_23", isSetLegal),
                    new ReportParameter("RepLegalWho", repLegalWho),
                    new ReportParameter("RepLegalReference", repLegalReference),

                    new ReportParameter("Param_24", isSetCompanion),
                    new ReportParameter("RepCompanionName", repCompanionName),
                    new ReportParameter("RepCompanionAddress", repCompanionAddress),
                    new ReportParameter("RepReuptakeDate", repReuptakeDate),

                    new ReportParameter("Param_25", isSetReuptake),
                });
                /* rendition - with annoying placeholder table to satisfy the rdlc's data binding */
                var table = new List <ReportHardcopyShim>();
                table.Add(new ReportHardcopyShim());
                var dsTable     = "dsRow";
                var dynDS_Table = new ReportDataSource(dsTable, table);
                rpt.DataSources.Add(dynDS_Table);
                rpt.Refresh();
                string[]  streams;
                Warning[] warnings;
                string    extension;
                string    devinfo = null;
                devinfo = String.Format("<DeviceInfo><DpiX>{0}</DpiX><DpiY>{0}</DpiY></DeviceInfo>", 300);
                var result = rpt.Render(rpt_format, devinfo, PageCountMode.Actual, out mime, out encoding, out extension, out streams, out warnings);
                foreach (var w in warnings)
                {
                    Tracing.WarningCore("Code: {0}, Message: {1}, Objectname: {2}, Objecttype: {3}, Severity: {4}",
                                        w.Code,
                                        w.Message,
                                        w.ObjectName,
                                        w.ObjectType,
                                        w.Severity.ToString()
                                        );
                }
                chunk = new MemoryStream(result);
                if (Debugger.IsAttached)
                {
                    File.WriteAllBytes(uri, result);
                }
                /* succeeded */
                return(true);
            }
            catch (Exception ex)
            {
                Tracing.ErrorCore("{0}", ex.ToString());
                return(false);
            }
        }
Esempio n. 3
0
        public bool RenderRep0000(string virtualbasepath, string printername, string jobname, bool dinA5, string footerinfoline, string participantname, string participationdatetime, string trainingtopic, string fexpires, out MemoryStream chunk, out string mime, out string encoding, out string uri)
        {
            /* make a direct (synchronous) PDF from training participation certificate data */
            chunk    = new MemoryStream();
            mime     = sherm.core.formatting.mime.cstMIMEPDF;
            encoding = System.Text.Encoding.UTF8.EncodingName;
            uri      = String.Format("Teilnahmezertifikat-{0}-{1}.pdf",
                                     trainingtopic.Replace(" ", "_"),
                                     participantname.Replace(" ", "_")
                                     );
            try
            {
                var rpt_format = "PDF";
                /* instantiate and render the rdlc */
                var rpt = new LocalReport()
                {
                    ReportEmbeddedResource = "sherm.rpt.msdbrpt.ReportHardcopyTrainingCert.rdlc",
                    EnableExternalImages   = true
                };
                if (dinA5)
                {
                    rpt.ReportEmbeddedResource = "sherm.rpt.msdbrpt.ReportHardcopyTrainingCertA5.rdlc";
                }
                /* data binding */
                var Logo = String.Format("{0}{1}",
                                         virtualbasepath,
                                         BuiltinReportDescriptor.MediaURL(sherm.core.formatting.mime.BINGET_NAMEDRESOURCE_CORPORATELOGO, null, null, new FileType[] { FileType.ft_png })
                                         );
                rpt.SetParameters(new ReportParameter[]
                {
                    new ReportParameter("LogoURL", Logo),
                    new ReportParameter("ParticipantName", participantname),
                    new ReportParameter("ParticipationTime", participationdatetime),
                    new ReportParameter("Topic", trainingtopic),
                    new ReportParameter("Expires", fexpires),
                    new ReportParameter("FooterInfoline", footerinfoline)
                });
                /* rendition - with [sic(k)] placeholder table to satisfy the rdlc's data binding */
                var table = new List <ReportHardcopyPSAPlanRow>();
                table.Add(new ReportHardcopyPSAPlanRow());
                var dsTable     = "dsRow";
                var dynDS_Table = new ReportDataSource(dsTable, table);
                rpt.DataSources.Add(dynDS_Table);
                rpt.Refresh();
                string[]  streams;
                Warning[] warnings;
                string    extension;

                /* [pkosec 20140521] set dpi for rdlc (MEA-2014-00207 initiative)
                 * [pkosec 20140506] use the default value (null), if DPI has not been set */
                string devinfo = null;
                devinfo = String.Format("<DeviceInfo><DpiX>{0}</DpiX><DpiY>{0}</DpiY></DeviceInfo>", 300);
                if (printername == null)
                {
                    /* [dlatikay 20180625] can now send directly */
                    var result = rpt.Render(rpt_format, devinfo, PageCountMode.Actual, out mime, out encoding, out extension, out streams, out warnings);
                    foreach (var w in warnings)
                    {
                        Tracing.WarningCore("Code: {0}, Message: {1}, Objectname: {2}, Objecttype: {3}, Severity: {4}",
                                            w.Code,
                                            w.Message,
                                            w.ObjectName,
                                            w.ObjectType,
                                            w.Severity.ToString()
                                            );
                    }
                    chunk = new MemoryStream(result);
                }
                else
                {
                    rpt.PrintToPrinter(printername, jobname);
                }
                /* succeeded */
                return(true);
            }
            catch (Exception ex)
            {
                Tracing.ErrorCore("{0}", ex.ToString());
                return(false);
            }
        }