/// <summary> /// This method finds a 'Method' object. /// This method uses the 'Method_Find' procedure. /// </summary> /// <returns>A 'Method' object.</returns> /// </summary> public Method FindMethod(FindMethodStoredProcedure findMethodProc, DataConnector databaseConnector) { // Initial Value Method method = null; // Verify database connection is connected if ((databaseConnector != null) && (databaseConnector.Connected)) { // First Get Dataset DataSet methodDataSet = this.DataHelper.LoadDataSet(findMethodProc, databaseConnector); // Verify DataSet Exists if (methodDataSet != null) { // Get DataTable From DataSet DataRow row = this.DataHelper.ReturnFirstRow(methodDataSet); // if row exists if (row != null) { // Load Method method = MethodReader.Load(row); } } } // return value return(method); }
/// <summary> /// This method fetches a 'List<Method>' object. /// This method uses the 'Methods_FetchAll' procedure. /// </summary> /// <returns>A 'List<Method>'</returns> /// </summary> public List <Method> FetchAllMethods(FetchAllMethodsStoredProcedure fetchAllMethodsProc, DataConnector databaseConnector) { // Initial Value List <Method> methodCollection = null; // Verify database connection is connected if ((databaseConnector != null) && (databaseConnector.Connected)) { // First Get Dataset DataSet allMethodsDataSet = this.DataHelper.LoadDataSet(fetchAllMethodsProc, databaseConnector); // Verify DataSet Exists if (allMethodsDataSet != null) { // Get DataTable From DataSet DataTable table = this.DataHelper.ReturnFirstTable(allMethodsDataSet); // if table exists if (table != null) { // Load Collection methodCollection = MethodReader.LoadCollection(table); } } } // return value return(methodCollection); }
public void TestMethod1() { Span <byte> start = Convert.FromBase64String("AAkAAAHDDGNhcGFiaWxpdGllc0YAAADHEnB1Ymxpc2hlcl9jb25maXJtc3QBGmV4Y2hhbmdlX2V4Y2hhbmdlX2JpbmRpbmdzdAEKYmFzaWMubmFja3QBFmNvbnN1bWVyX2NhbmNlbF9ub3RpZnl0ARJjb25uZWN0aW9uLmJsb2NrZWR0ARNjb25zdW1lcl9wcmlvcml0aWVzdAEcYXV0aGVudGljYXRpb25fZmFpbHVyZV9jbG9zZXQBEHBlcl9jb25zdW1lcl9xb3N0AQ9kaXJlY3RfcmVwbHlfdG90AQxjbHVzdGVyX25hbWVTAAAAD3JhYmJpdEBBZG1pbi1IUAljb3B5cmlnaHRTAAAALkNvcHlyaWdodCAoQykgMjAwNy0yMDE5IFBpdm90YWwgU29mdHdhcmUsIEluYy4LaW5mb3JtYXRpb25TAAAANkxpY2Vuc2VkIHVuZGVyIHRoZSBNUEwuICBTZWUgaHR0cHM6Ly93d3cucmFiYml0bXEuY29tLwhwbGF0Zm9ybVMAAAAPRXJsYW5nL09UUCAyMi4wB3Byb2R1Y3RTAAAACFJhYmJpdE1RB3ZlcnNpb25TAAAABjMuNy4xNwAAAA5BTVFQTEFJTiBQTEFJTgAAAAVlbl9VUw=="); var res = MethodReader.ParseStart(start); Assert.AreEqual(9, res.VersionMajor); Assert.AreEqual(1, res.VersionMinor); }
/// <summary> /// Success /// </summary> protected override void OnExecutionSuccess() { Log.Instance.Debug("Record updated"); //See if there's a cache in the process. If so then we need to flush the cache. if (MethodReader.MethodHasAttribute(Request.method, "CacheFlush")) { cDTO = new CacheMetadata("CacheFlush", Request.method, DTO); foreach (Cas cas in cDTO.CasList) { MemCacheD.CasRepositoryFlush(cas.CasRepository + cas.Domain); } } }
/// <summary> /// On success /// </summary> protected override void OnExecutionSuccess() { Log.Instance.Debug("Record deleted"); //See if there's a cache in the process. If so then we need to flush the cache. if (MethodReader.MethodHasAttribute(Request.method, Utility.GetCustomConfig("APP_CACHE_FLUSH_ATTRIBUTE"))) { cDTO = new CacheMetadata(Utility.GetCustomConfig("APP_CACHE_FLUSH_ATTRIBUTE"), Request.method, DTO); foreach (Cas cas in cDTO.CasList) { MemCacheD.CasRepositoryFlush(cas.CasRepository + cas.Domain); } } }
bool RestoreMethod(MethodDef method) { int? methodId = GetMethodId(method); if (methodId == null) return false; var parameters = method.Parameters; var methodInfo = methodInfos[methodId.Value]; methodInfos.Remove(methodId.Value); var methodReader = new MethodReader(module, methodInfo.data, parameters); methodReader.Read(); RestoreMethod(method, methodReader); delegateTypes.Add(methodReader.DelegateType); return true; }
public PactSchemaService(PactOptions options) { this._options = options; this._jsonOptions = new JsonSerializerOptions { Converters = { new UnionConverterFactory() }, PropertyNamingPolicy = JsonNamingPolicy.CamelCase, IgnoreNullValues = true }; var typeProvider = this._options.TypeProvider ?? new TypeProvider(); var typeChecker = new TypeChecker(typeProvider); var distinctTypeQueue = new DistinctTypeQueue(); var typeReferenceReader = new TypeReferenceReader(typeChecker, distinctTypeQueue); var distinctTypeReader = new DistinctTypeReader(typeChecker, typeReferenceReader); var methodReader = new MethodReader(typeChecker, typeReferenceReader); var controllerReader = new ControllerReader(methodReader); this._schemaReader = new SchemaReader(distinctTypeQueue, distinctTypeReader, controllerReader, typeProvider); }
static void RestoreMethod(MethodDef method, MethodReader methodReader) { // body.MaxStackSize = <let dnlib calculate this> method.Body.InitLocals = methodReader.InitLocals; methodReader.RestoreMethod(method); }
/// <summary> /// Constructor /// </summary> /// <returns></returns> public BaseTemplate_Read <T, V> Read() { try { // first of all, we check if user has the right to perform this operation! if (HasUserToBeAuthenticated()) { if (!IsUserAuthenticated() || !HasUserPrivilege()) { return(this); } } //Run the parameters through the cleanse process dynamic cleansedParams = Cleanser.Cleanse(Request.parameters); try { DTO = GetDTO(cleansedParams); } catch { throw new InputFormatException(); } DTO = Sanitizer.Sanitize(DTO); DTOValidationResult = Validator.Validate(DTO); if (!DTOValidationResult.IsValid) { OnDTOValidationError(); return(this); } //Create the analytic data if required Security.Analytic_BSO_Create.Create(Ado, DTO, HttpContext.Current.Request, Request); //See if there's a cache in the process if (MethodReader.MethodHasAttribute(Request.method, "CacheRead")) { cDTO = new CacheMetadata("CacheRead", Request.method, DTO); MemCachedD_Value cache = MemCacheD.Get_BSO <dynamic>(cDTO.Namespace, cDTO.ApiName, cDTO.Method, DTO); if (cache.hasData) { Response.data = cache.data; return(this); } } // The Actual Read should happen here by the specific class! if (!Execute()) { OnExecutionError(); return(this); } OnExecutionSuccess(); return(this); } catch (UnmatchedParametersException unmatchException) { Log.Instance.Debug(unmatchException); OnDTOValidationError(); return(this); } catch (FormatException formatException) { //A FormatException error has been caught, log the error and return a message to the caller Log.Instance.Error(formatException); Response.error = Label.Get("error.schema"); return(this); } catch (Exception ex) { //An error has been caught, log the error and return a message to the caller Log.Instance.Error(ex); Response.error = Label.Get("error.exception"); return(this); } finally { Dispose(); } }
bool restoreMethod(MethodDef method) { int methodId = getMethodId(method); if (methodId == INVALID_METHOD_ID) return false; var parameters = method.Parameters; var methodInfo = methodInfos[methodId]; methodInfos.Remove(methodId); var methodReader = new MethodReader(module, methodInfo.data, parameters); methodReader.read(); restoreMethod(method, methodReader); delegateTypes.Add(methodReader.DelegateType); return true; }
/// <summary> /// Creates the analytic entry if one is deemed to be necessary /// This method relies on DeviceDetector.NET. Details at https://github.com/totpero/DeviceDetector.NET /// It is advisable to frequently check for updates, especially to the regexes folder (situated in the Resources folder of this project) /// </summary> /// <param name="Ado"></param> /// <param name="requestDTO"></param> /// <param name="hRequest"></param> /// <param name="request"></param> internal static void Create(ADO Ado, dynamic requestDTO, HttpRequest hRequest, JSONRPC_API request) { //If this method doesn't require analytic logging then exit the function here if (!MethodReader.MethodHasAttribute(request.method, "Analytic")) { return; } Analytic_DTO aDto = new Analytic_DTO(); if (hRequest.UserLanguages != null) { if (hRequest.UserLanguages.Count() > 0) { if (hRequest.UserLanguages[0].Length >= 2) { aDto.EnvironmentLngIsoCode = hRequest.UserLanguages[0].Substring(0, 2); } } } //Get a masked version of the ip address aDto.NltMaskedIp = getMaskedIp(request.ipAddress); //Get the matrix field from the calling DTO if (MethodReader.DynamicHasProperty(requestDTO, "jStatQueryExtension")) { aDto.matrix = requestDTO.jStatQueryExtension.extension.Matrix; } // Get the Referer aDto.NltReferer = hRequest.UrlReferrer == null || String.IsNullOrEmpty(hRequest.UrlReferrer.Host) ? null : hRequest.UrlReferrer.Host; //The m2m parameter will not be translated into a DTO property so we just read it from the request parameters if it exists if (MethodReader.DynamicHasProperty(requestDTO, "m2m")) { aDto.NltM2m = requestDTO.m2m; } else { aDto.NltM2m = true; } if (MethodReader.DynamicHasProperty(requestDTO, "widget")) { aDto.NltWidget = requestDTO.widget; } if (MethodReader.DynamicHasProperty(requestDTO, "user")) { aDto.NltUser = requestDTO.user; } // Get the DateTime aDto.NltDate = DateTime.Now; //Get Format information if (MethodReader.DynamicHasProperty(requestDTO, "jStatQueryExtension")) { if (MethodReader.DynamicHasProperty(requestDTO.jStatQueryExtension.extension.Format, "Type") && MethodReader.DynamicHasProperty(requestDTO.jStatQueryExtension.extension.Format, "Version")) { aDto.FrmType = requestDTO.jStatQueryExtension.extension.Format.Type; aDto.FrmVersion = requestDTO.jStatQueryExtension.extension.Format.Version; } } //Get the device detector and populate the dto attributes DeviceDetector deviceDetector = GetDeviceDetector(request.userAgent); aDto.NltBotFlag = deviceDetector.IsBot(); //If it's a bot, then that overrules everything else if (aDto.NltBotFlag) { aDto.NltM2m = false; aDto.NltUser = false; aDto.NltWidget = false; } if (deviceDetector.GetBrowserClient().Match != null) { aDto.NltBrowser = deviceDetector.GetBrowserClient().Match.Name; } if (deviceDetector.GetOs().Match != null) { aDto.NltOs = deviceDetector.GetOs().Match.Name; } var valids = new Analytic_VLD().Validate(aDto); //validate whatever has been returned if (!valids.IsValid) { foreach (var fail in valids.Errors) { Log.Instance.Debug("Analytic method failed validation:" + request.method + " :" + fail.ErrorMessage); } return; } //Create the analytic entry Analytic_ADO ado = new Analytic_ADO(Ado); if (ado.Create(aDto) == 0) { Log.Instance.Debug("Failed to create Analytic:" + request.method); return; } return; }
/// <summary> /// Constructor /// </summary> /// <returns></returns> public BaseTemplate_Read <T, V> Read() { try { // first of all, we check if user has the right to perform this operation! if (HasUserToBeAuthenticated()) { if (!IsUserAuthenticated() || !HasUserPrivilege()) { OnAuthenticationFailed(); return(this); } } //if we didn't attempt to authenticate and it's an external call then we still need to the the SamAccountName if (SamAccountName == null && Request.sessionCookie != null) { Log.Instance.Debug("Session cookie: " + Request.sessionCookie.Value); //Does the cookie correspond with a live token for a user? ADO_readerOutput user; using (Login_BSO lBso = new Login_BSO()) { user = lBso.ReadBySession(Request.sessionCookie.Value); if (user.hasData) { SamAccountName = user.data[0].CcnUsername; } } } //Run the parameters through the cleanse process dynamic cleansedParams; //If the API has the IndividualCleanseNoHtml attribute then parameters are cleansed individually //Any of these parameters whose corresponding DTO property contains the NoHtmlStrip attribute will not be cleansed of HTML tags if (Resources.MethodReader.MethodHasAttribute(Request.method, "IndividualCleanseNoHtml")) { dynamic dto = GetDTO(Request.parameters); cleansedParams = Cleanser.Cleanse(Request.parameters, dto); } else { cleansedParams = Cleanser.Cleanse(Request.parameters); } try { DTO = GetDTO(cleansedParams); } catch { throw new InputFormatException(); } DTO = Sanitizer.Sanitize(DTO); DTOValidationResult = Validator.Validate(DTO); if (!DTOValidationResult.IsValid) { OnDTOValidationError(); return(this); } ////Has the user hit a limit of how many queries are allowed? //if (Throttle_BSO.IsThrottled(Ado, HttpContext.Current.Request, Request, SamAccountName)) //{ // OnThrottle(); // return this; //} //Create the analytic data if required Security.Analytic_BSO_Create.Create(Ado, DTO, HttpContext.Current.Request, Request); //See if there's a cache in the process if (MethodReader.MethodHasAttribute(Request.method, "CacheRead")) { cDTO = new CacheMetadata("CacheRead", Request.method, DTO); MemCachedD_Value cache = MemCacheD.Get_BSO <dynamic>(cDTO.Namespace, cDTO.ApiName, cDTO.Method, DTO); if (cache.hasData) { Response.data = cache.data; return(this); } } // The Actual Read should happen here by the specific class! if (!Execute()) { OnExecutionError(); } else { OnExecutionSuccess(); } return(this); } catch (UnmatchedParametersException unmatchException) { Log.Instance.Debug(unmatchException); OnDTOValidationError(); return(this); } catch (FormatException formatException) { //A FormatException error has been caught, log the error and return a message to the caller Log.Instance.Error(formatException); Response.error = Label.Get("error.schema"); return(this); } catch (Exception ex) { //An error has been caught, log the error and return a message to the caller Log.Instance.Error(ex); Response.error = Label.Get("error.exception"); return(this); } finally { Dispose(); } }
public static bool HasSilverInTradeBeaconRangeMethod(MethodInfo method) { var instructions = MethodReader.GetInstructions(method); return(instructions.Any(instruction => instruction.opcode == OpCodes.Call && IsTradeBeaconMethod(instruction.operand as MethodInfo))); }
static void restoreMethod(MethodDefinition method, MethodReader methodReader) { var body = method.Body; // body.MaxStackSize = <let Mono.Cecil calculate this> body.InitLocals = methodReader.InitLocals; body.Variables.Clear(); if (methodReader.Locals != null) { foreach (var local in methodReader.Locals) body.Variables.Add(local); } body.Instructions.Clear(); if (methodReader.Instructions != null) { foreach (var instr in methodReader.Instructions) body.Instructions.Add(instr); } body.ExceptionHandlers.Clear(); if (methodReader.ExceptionHandlers != null) { foreach (var eh in methodReader.ExceptionHandlers) body.ExceptionHandlers.Add(eh); } }
public DelegateData Serialize(MethodInfo methodInfo) { var methodBody = methodInfo.GetMethodBody(); if (methodBody == null) { return(null); } var fieldsToLocals = new Dictionary <string, int>(); var result = new DelegateData(); result.ReturnType = typeInfoDataConverter.Build(methodInfo.ReturnType); result.ParametersType = methodInfo.GetParameters() .Select(info => typeInfoDataConverter.Build(info.ParameterType)) .ToArray(); result.ExceptionHandlingClauses = methodBody.ExceptionHandlingClauses .Select(c => exceptionHandlingClauseDataConverter.Build(c)) .ToArray(); result.LocalVariables = new List <LocalVariableInfoData>(); foreach (var localVariable in methodBody.LocalVariables) { result.LocalVariables.Add(localVariableInfoDataConverter.Build(localVariable)); } result.Instructions = new List <ILInstructionData>(); foreach (var instruction in MethodReader.Read(methodInfo)) { //Console.WriteLine(instruction); var operand = instruction.Operand; var code = (OpCodeValues)(instruction.Code.Value & 0xffff); var il = new ILInstructionData(); if (!methodInfo.IsStatic) { if (code == OpCodeValues.Ldarg_0) { throw new DelegateSerializationException("Method reference to this"); } if (code == OpCodeValues.Ldarg_1) { code = OpCodeValues.Ldarg_0; } else if (code == OpCodeValues.Ldarg_2) { code = OpCodeValues.Ldarg_1; } else if (code == OpCodeValues.Ldarg_3) { code = OpCodeValues.Ldarg_2; } else if (code == OpCodeValues.Ldarg_S && (byte)operand == 4) { code = OpCodeValues.Ldarg_3; operand = null; } else if (code == OpCodeValues.Ldarg_S && (byte)operand > 4) { operand = (byte)operand - 1; } } if (code == OpCodeValues.Ldftn) { il.OperandDelegateData = Serialize((MethodInfo)instruction.Operand); operand = null; } else if (operand is FieldInfo) { var field = (FieldInfo)operand; var fieldFullName = field.DeclaringType.FullName + "_" + field.Name; if (field.Name.StartsWith("CS$<>9__CachedAnonymousMethodDelegate") || field.Name.StartsWith("<>9")) { int local; if (!fieldsToLocals.TryGetValue(fieldFullName, out local) && field.FieldType.Name != "<>c") { result.LocalVariables.Add(localVariableInfoDataConverter.Build(field)); local = result.LocalVariables.Count - 1; fieldsToLocals.Add(fieldFullName, local); } if (code == OpCodeValues.Ldsfld) { if (field.FieldType.Name == "<>c") { code = OpCodeValues.Ldnull; operand = null; } else { code = OpCodeValues.Ldloc; operand = local; } } else if (code == OpCodeValues.Stsfld) { code = OpCodeValues.Stloc; operand = local; } else { throw new DelegateSerializationException("Unknown field operation"); } } else { throw new DelegateSerializationException(string.Format("Unknown field info {0}", fieldFullName)); } } else if (operand is ConstructorInfo) { il.OperandConstructor = constructorInfoDataConverter.Build((ConstructorInfo)operand); operand = null; } else if (operand is MethodInfo) { il.OperandMethod = methodInfoDataConverter.Build((MethodInfo)operand); operand = null; } il.Code = (uint)code; il.Offset = instruction.Offset; il.Operand = operand; result.Instructions.Add(il); } return(result); }
static void restoreMethod(MethodDefinition method, MethodReader methodReader) { // body.MaxStackSize = <let Mono.Cecil calculate this> method.Body.InitLocals = methodReader.InitLocals; methodReader.restoreMethod(method); }