결정적이다. 당신이 그들을 사용하는 반사에 의해 그것을 감지 할 수 있습니까? 또는 일리노이 코드를 봐야합니까?이 C#을 Assemby를 확인 특정 클래스와 같은 <em>임의</em> 또는 <em>날짜 시간</em>, 또는 응용 프로그램 도메인에서 <em>플로트</em>의 사용을 제한 할 수
플러그인 시스템을 만들고 싶지만 실행 된 코드가 결정적인지 확인해야합니다. 그것을 다루는 방법에 대한 다른 아이디어?
감사합니다.
결정적이다. 당신이 그들을 사용하는 반사에 의해 그것을 감지 할 수 있습니까? 또는 일리노이 코드를 봐야합니까?이 C#을 Assemby를 확인 특정 클래스와 같은 <em>임의</em> 또는 <em>날짜 시간</em>, 또는 응용 프로그램 도메인에서 <em>플로트</em>의 사용을 제한 할 수
플러그인 시스템을 만들고 싶지만 실행 된 코드가 결정적인지 확인해야합니다. 그것을 다루는 방법에 대한 다른 아이디어?
감사합니다.
내가 INT localInt = 0``작성하는 경우,
readonly static List<string> WhiteList = new List<string>()
{
#region Basics
typeof(Boolean).FullName,
typeof(Char).FullName,
typeof(String).FullName,
typeof(Byte).FullName,
typeof(SByte).FullName,
typeof(UInt16).FullName,
typeof(Int16).FullName,
typeof(UInt32).FullName,
typeof(Int32).FullName,
typeof(UInt64).FullName,
typeof(Int64).FullName,
typeof(Decimal).FullName,
typeof(Double).FullName,
typeof(Single).FullName,
typeof(TimeSpan).FullName,
typeof(Array).FullName,
typeof(Enum).FullName,
#endregion
#region Exceptions
typeof(Exception).FullName,
typeof(NotImplementedException).FullName,
typeof(IOException).FullName,
#endregion
#region Delegates
typeof(Delegate).FullName,
#endregion
#region Parallel
typeof(Parallel).FullName,
#endregion
#region Conversions
typeof(Convert).FullName,
typeof(BitConverter).FullName,
#endregion
#region Streams
typeof(Stream).FullName,
typeof(MemoryStream).FullName,
typeof(BinaryReader).FullName,
typeof(BinaryWriter).FullName,
#endregion
#region Interfaces
typeof(IDisposable).FullName,
typeof(IComparable).FullName,
typeof(IConvertible).FullName,
typeof(IFormatProvider).FullName,
typeof(IFormattable).FullName,
typeof(IOrderedQueryable).FullName,
#endregion
#region Attributes
typeof(Attribute).FullName,
// Compilation JIT
typeof(CompilationRelaxationsAttribute).FullName,
typeof(RuntimeCompatibilityAttribute).FullName,
typeof(CompilerGeneratedAttribute).FullName,
#endregion
#region Generic Types
typeof(IDictionary<object,object>).Namespace+"."+typeof(IDictionary<object,object>).Name,
typeof(Dictionary<object,object>).Namespace+"."+typeof(Dictionary<object,object>).Name,
typeof(List<object>).Namespace+"."+typeof(List<object>).Name,
typeof(IList<object>).Namespace+"."+typeof(IList<object>).Name,
typeof(IEnumerable<object>).Namespace+"."+typeof(IEnumerable<object>).Name,
typeof(IEnumerator<object>).Namespace+"."+typeof(IEnumerator<object>).Name,
typeof(IOrderedEnumerable<object>).Namespace+"."+typeof(IOrderedEnumerable<object>).Name,
typeof(IOrderedQueryable<object>).Namespace+"."+typeof(IOrderedQueryable<object>).Name,
typeof(ICollection<object>).Namespace+"."+typeof(ICollection<object>).Name,
typeof(IComparable<object>).Namespace+"."+typeof(IComparable<object>).Name,
typeof(IEquatable<object>).Namespace+"."+typeof(IEquatable<object>).Name,
typeof(IObservable<object>).Namespace+"."+typeof(IObservable<object>).Name,
#endregion
};
const string WhiteListedNamespace = "XX.XXXXXXXXXX.";
/// <summary>
/// Check white list
/// </summary>
/// <param name="binary">Binary</param>
public static void CheckWhiteList(byte[] binary)
{
using (MemoryStream ms = new MemoryStream(binary))
{
AssemblyDefinition def = AssemblyDefinition.ReadAssembly(ms, new ReaderParameters(ReadingMode.Immediate));
List<string> ls = new List<string>();
foreach (ModuleDefinition mdef in def.Modules)
foreach (TypeReference tdef in mdef.GetTypeReferences())
{
if (!WhiteList.Contains(tdef.FullName) &&
!tdef.FullName.StartsWith(WhiteListedNamespace, StringComparison.InvariantCulture))
ls.Add(tdef.FullName);
}
if (ls.Count > 0)
throw (new TypeNotAllowedException(ls.ToArray()));
}
}
Cecil [*]과 같이 IL을 볼 수 있습니다. 그러나 다시 한번, 반사를 통해 그러한 것들에 접근 할 수 있습니다.
[*] : 어느 정도 시간이 걸리므로 결과를 캐시하라는 메시지가 나타납니다. 이는 공격자가 캐시에서 유효한 항목을 모방하는 취약점을 유발합니다.
반면에 sandboxwithout Reflection을 사용할 수 있습니다. 위의 방법과 함께 사용해야합니다.
다음은 설명하는 동작을 모방하는 방법이 있습니다. 예를 들어 자신 만의 Random Number Generator (완전히 결정적 인 것)을 만들고 현재 시간이나 다른 소스로 시드 할 수 있습니다 entropy (파일 시스템 및 네트워크에 대한 액세스를 거부하고 주변 장치 및 기타 시스템 상태에 대해서도 거부하려는 경우가 있습니다. 예를 들어 스크립트는 포인터 위치에 따라 다른 결과를 나타낼 수 있습니다.
따라서 blacklist 대신 whitelist이 표시되고 Damien_The_Unbeliever suggests으로 제안됩니다. 유형 화이트리스트를 작성
그래서 일을하는 것이 가능하다''어딘가에 내 코드에서, 당신은 당신이하고자 INT의 사용을 "제한" '미안하지만 ints는 허락하지 않는다 '라고 말하고 싶습니까? –
결정 성을 보장하기 위해 필요한 제한 수는 C#에서 시작하여 일을 멀리하는 것이 잘못된 접근이라고 생각할 정도로 높습니다. 비 결정론을 성취하기 위해 활용 될 수있는 mscorlib과 System.Core 내부의 많은 것들이 엄청납니다. –
@Damien_The_Unbeliever를 따라 결정 론적 스크립팅 언어를 찾거나 개발하는 것이 가능할 수도 있습니다. 그러나 파일 액세스 (비 결정적 내용), 사용자 상호 작용 (비 결정적 입력) 및 훨씬 더 많은 것을 허용하지 않는 플러그인 시스템은 나에게 매우 흥미롭지 않습니다. – grek40