Exemplo n.º 1
0
        public static PeBinary Load(string filename)
        {
            filename = filename.GetFullPath().ToLower();
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("Unable to find file", filename);
            }

            if (!PEInfo.Scan(filename).IsPEBinary)
            {
                throw new ClrPlusException("File {0} does not appear to be a PE Binary".format(filename));
            }

            PeBinary result = null;

            lock (_cache) {
                if (_cache.ContainsKey(filename))
                {
                    result = _cache[filename];
                }
                else
                {
                    // otherwise, let's load it
                    result = new PeBinary(filename);
                    _cache.Add(filename, result);
                }
            }
            // loads happen via a Task, so that no matter how we asked to get the assembly, only one copy will be ever loaded.
            try {
                result._loading.Wait();
            } catch (AggregateException ae) {
#if TODO
                Logger.Error(ae);
                Logger.Error(ae.InnerException);
#endif
                var inner = ae.Flatten().InnerException;
                Console.WriteLine("FAIL: {0} / {1}\r\n{2}", inner.GetType(), inner.Message, inner.StackTrace);
            }
            return(result);
        }
Exemplo n.º 2
0
        public static PeBinary Load(string filename) {
            filename = filename.GetFullPath().ToLower();
            if (!File.Exists(filename)) {
                throw new FileNotFoundException("Unable to find file", filename);
            }

            if (!PEInfo.Scan(filename).IsPEBinary) {
                throw new ClrPlusException("File {0} does not appear to be a PE Binary".format(filename));
            }

            PeBinary result = null;

            lock (_cache) {
                if (_cache.ContainsKey(filename)) {
                    result = _cache[filename];
                } else {
                    // otherwise, let's load it 
                    result = new PeBinary(filename);
                    _cache.Add(filename, result);
                }
            }
            // loads happen via a Task, so that no matter how we asked to get the assembly, only one copy will be ever loaded.
            try {
                result._loading.Wait();
            } catch (AggregateException ae) {
#if TODO
                Logger.Error(ae);
                Logger.Error(ae.InnerException);
#endif
                var inner = ae.Flatten().InnerException;
                Console.WriteLine("FAIL: {0} / {1}\r\n{2}", inner.GetType(), inner.Message, inner.StackTrace);
            }
            return result;
        }