Walk and parse the delay import directory.
552416
def parse_delay_import_directory(self, rva, size):
        """"""
        
        import_descs =  []
        while True:
            try:
                # If the RVA is invalid all would blow up. Some PEs seem to be
                # specially nasty and have an invalid RVA.
                data = self.get_data( rva, Structure(self.__IMAGE_DELAY_IMPORT_DESCRIPTOR_format__).sizeof() )
            except PEFormatError, e:
                self.__warnings.append(
                    'Error parsing the Delay import directory at RVA: 0x%x' % ( rva ) )
                break
            
            import_desc =  self.__unpack_data__(
                self.__IMAGE_DELAY_IMPORT_DESCRIPTOR_format__,
                data, file_offset = self.get_offset_from_rva(rva) )
            
            
            # If the structure is all zeroes, we reached the end of the list
            if not import_desc or import_desc.all_zeroes():
                break
            
            
            rva += import_desc.sizeof()
            
            try:
                import_data =  self.parse_imports(
                    import_desc.pINT,
                    import_desc.pIAT,
                    None)
            except PEFormatError, e:
                self.__warnings.append(
                    'Error parsing the Delay import directory. ' +
                    'Invalid import data at RVA: 0x%x' % ( rva ) )
                break
            
            if not import_data:
                continue
            
            
            dll = self.get_string_at_rva(import_desc.szName)
            if not is_valid_dos_filename(dll):
                dll = '*invalid*'

            if dll:
                import_descs.append(
                    ImportDescData(
                        struct = import_desc,
                        imports = import_data,
                        dll = dll))
        
        return import_descs
553129
def examine(self):
        """"""
        if self._changes:
            return self._changes.pop()

        # clean filepath
        self.filepath = None
        delays = set([0])
        for path in self._tasks:
            item = self._tasks[path]
            if self.is_changed(path, item['ignore']):
                func = item['func']
                func and func()
                delay = item['delay']
                if delay:
                    delays.add(delay)

        if 'forever' in delays:
            delay = 'forever'
        else:
            delay = max(delays)
        return self.filepath, delay
1081107
function importFor(node) {
      self.pendingImports++;

      if (isSync) {
        // Sync import:
        var file = self.importer.resolveSync(node.uri, self);
        _.mapNodeToFile(node, file.parse());
        _.mapIncludedFiles(self, file);
        self.resolvedImports++;
        return;
      }

      // Async import:
      self.importer.resolve(node.uri, self, function(err, file) {
        if (err) return finish(err);

        file.parse(function(err, file) {
          if (err) return finish(err);

          _.mapNodeToFile(node, file);
          _.mapIncludedFiles(self, file);
          self.resolvedImports++;
          finish(null);
        });
      });
    }
409282
async function importEnvironmentVariablesFromJSFile(from) {
	const object = await import(path.resolve(from));

	return importEnvironmentVariablesFromObject(object);
}
771697
def resolve_import(import_path, from_module):
    '''
    '''
    if not import_path or not import_path.startswith('.'):
        return import_path

    from_module = from_module.split('.')
    dots = 0
    for c in import_path:
        if c == '.':
            dots += 1
        else:
            break

    if dots:
        from_module = from_module[:-dots]
        import_path = import_path[dots:]

    if import_path:
        from_module.append(import_path)

    return '.'.join(from_module)
59176
@SuppressWarnings("unchecked")
    public Optional<DelayLoadSection> maybeLoadDelayLoadSection()
            throws IOException {
        return (Optional<DelayLoadSection>) maybeLoadSpecialSection(DataDirectoryKey.DELAY_IMPORT_DESCRIPTOR);
    }
99460
def extract_imports(script):
    """"""
    if not os.path.isfile(script):
        raise ValueError('Not a file: %s' % script)
    parse_tree = parse_python(script)
    result = find_imports(parse_tree)
    result.path = script
    return result
291483
private void parseImport() {
        tokenizer.consumeExpectedKeyword(KEYWORD_IMPORT);
        if (!tokenizer.current().isString()) {
            tokenizer.addError(tokenizer.current(),
                               "Unexpected token: '"
                               + tokenizer.current().getSource()
                               + "'. Expected a string constant naming an import file.");
        } else {
            result.addImport(tokenizer.consume().getContents());
        }
        tokenizer.consumeExpectedSymbol(";");
    }
1324798
def parsePathname(self, pathname):
        
        if os.path.isdir(pathname):
            for root, dirs, files in os.walk(pathname):
                dirs.sort()
                files.sort()
                for fn in files:
                    # ignore emacsish junk
                    if fn.endswith('.py') and not fn.startswith('.#'):
                        self.parseFile(os.path.join(root, fn))
        elif pathname.endswith('.importcache'):
            self.readCache(pathname)
        else:
            self.parseFile(pathname)
421138
def parse_import_directory(self, rva, size, dllnames_only=False):
        """"""

        import_descs =  []
        error_count = 0
        while True:
            try:
                # If the RVA is invalid all would blow up. Some EXEs seem to be
                # specially nasty and have an invalid RVA.
                data = self.get_data(rva, Structure(
                        self.__IMAGE_IMPORT_DESCRIPTOR_format__).sizeof() )
            except PEFormatError as e:
                self.__warnings.append(
                    'Error parsing the import directory at RVA: 0x%x' % ( rva ) )
                break

            file_offset = self.get_offset_from_rva(rva)
            import_desc =  self.__unpack_data__(
                self.__IMAGE_IMPORT_DESCRIPTOR_format__,
                data, file_offset = file_offset )

            # If the structure is all zeros, we reached the end of the list
            if not import_desc or import_desc.all_zeroes():
                break

            rva += import_desc.sizeof()

            # If the array of thunks is somewhere earlier than the import
            # descriptor we can set a maximum length for the array. Otherwise
            # just set a maximum length of the size of the file
            max_len = len(self.__data__) - file_offset
            if rva > import_desc.OriginalFirstThunk or rva > import_desc.FirstThunk:
                max_len = max(rva-import_desc.OriginalFirstThunk, rva-import_desc.FirstThunk)

            import_data = []
            if not dllnames_only:
                try:
                    import_data = self.parse_imports(
                        import_desc.OriginalFirstThunk,
                        import_desc.FirstThunk,
                        import_desc.ForwarderChain,
                        max_length = max_len)
                except PEFormatError as e:
                    self.__warnings.append(
                        'Error parsing the import directory. '
                        'Invalid Import data at RVA: 0x{0:x} ({1})'.format(
                            rva, e.value))

                if error_count > 5:
                    self.__warnings.append(
                        'Too may errors parsing the import directory. '
                        'Invalid import data at RVA: 0x{0:x}'.format(rva) )
                    break

                if not import_data:
                    error_count += 1
                    # TODO: do not continue here
                    continue

            dll = self.get_string_at_rva(import_desc.Name, MAX_DLL_LENGTH)
            if not is_valid_dos_filename(dll):
                dll = b('*invalid*')

            if dll:
                for symbol in import_data:
                    if symbol.name is None:
                        funcname = ordlookup.ordLookup(dll.lower(), symbol.ordinal)
                        if funcname:
                            symbol.name = funcname
                import_descs.append(
                    ImportDescData(
                        struct = import_desc,
                        imports = import_data,
                        dll = dll))

        if not dllnames_only:
            suspicious_imports = set([ u'LoadLibrary', u'GetProcAddress' ])
            suspicious_imports_count = 0
            total_symbols = 0
            for imp_dll in import_descs:
                for symbol in imp_dll.imports:
                    for suspicious_symbol in suspicious_imports:
                        if not symbol or not symbol.name:
                            continue
                        name = symbol.name
                        if type(symbol.name) == bytes:
                            name = symbol.name.decode('utf-8')
                        if name.startswith(suspicious_symbol):
                            suspicious_imports_count += 1
                            break
                    total_symbols += 1
            if suspicious_imports_count == len(suspicious_imports) and total_symbols < 20:
                self.__warnings.append(
                    'Imported symbols contain entries typical of packed executables.' )

        return import_descs
70355
protected function slowScan()
    {
        if ($this->haveSlowResults) {
            return;
        }

        // copy trie object add CopyInto() method
        $excl = $this->dirsExcluded;
        $notIncl = $this->dirsNotIncluded;

        for ($i = 0, $_i = count($excl); $i < $_i; $i++) {
            if (!$this->couldHoldIncluded($excl[$i])) {
                $this->scandir($this->basedir . $excl[$i], $excl[$i] . DIRECTORY_SEPARATOR, false);
            }
        }

        for ($i = 0, $_i = count($notIncl); $i < $_i; $i++) {
            if (!$this->couldHoldIncluded($notIncl[$i])) {
                $this->scandir($this->basedir . $notIncl[$i], $notIncl[$i] . DIRECTORY_SEPARATOR, false);
            }
        }

        $this->haveSlowResults = true;
    }
135696
def parse_import_directory(self, rva, size):
        """"""
        
        import_descs =  []
        while True:
            try:
                # If the RVA is invalid all would blow up. Some EXEs seem to be
                # specially nasty and have an invalid RVA.
                data = self.get_data(rva, Structure(self.__IMAGE_IMPORT_DESCRIPTOR_format__).sizeof() )
            except PEFormatError, e:
                self.__warnings.append(
                    'Error parsing the import directory at RVA: 0x%x' % ( rva ) )
                break
            
            import_desc =  self.__unpack_data__(
                self.__IMAGE_IMPORT_DESCRIPTOR_format__,
                data, file_offset = self.get_offset_from_rva(rva) )
            
            # If the structure is all zeroes, we reached the end of the list
            if not import_desc or import_desc.all_zeroes():
                break
            
            rva += import_desc.sizeof()
            
            try:
                import_data =  self.parse_imports(
                    import_desc.OriginalFirstThunk,
                    import_desc.FirstThunk,
                    import_desc.ForwarderChain)
            except PEFormatError, excp:
                self.__warnings.append(
                    'Error parsing the import directory. ' +
                    'Invalid Import data at RVA: 0x%x (%s)' % ( rva, str(excp) ) )
                break
                #raise excp
            
            if not import_data:
                continue
            
            dll = self.get_string_at_rva(import_desc.Name)
            if not is_valid_dos_filename(dll):
                dll = '*invalid*'
                
            if dll:
                import_descs.append(
                    ImportDescData(
                        struct = import_desc,
                        imports = import_data,
                        dll = dll))
        
        suspicious_imports = set([ 'LoadLibrary', 'GetProcAddress' ])
        suspicious_imports_count = 0
        total_symbols = 0
        for imp_dll in import_descs:
            for symbol in imp_dll.imports:
                for suspicious_symbol in suspicious_imports:
                    if symbol and symbol.name and symbol.name.startswith( suspicious_symbol ):
                        suspicious_imports_count += 1
                        break
                total_symbols += 1
        if suspicious_imports_count == len(suspicious_imports) and total_symbols < 20:
            self.__warnings.append(
                'Imported symbols contain entries typical of packed executables.' )
            
            
        
        return import_descs
554416
def follow(self, delay=1.0):
        
        trailing = True

        while 1:
            where = self.file.tell()
            line = self.file.readline()
            if line:
                if trailing and line in self.line_terminators:
                    # This is just the line terminator added to the end of the file
                    # before a new line, ignore.
                    trailing = False
                    continue

                if line[-1] in self.line_terminators:
                    line = line[:-1]
                    if line[-1:] == '\r\n' and '\r\n' in self.line_terminators:
                        # found crlf
                        line = line[:-1]

                trailing = False
                yield line
            else:
                trailing = True
                self.seek(where)
                time.sleep(delay)
150990
def at_line(context, file, line)
      return if file && TRACE_IGNORE_FILES.include?(File.expand_path(file))

      # If stopped for a breakpoint or catchpoint, can't play any delayed steps
      # as they'll move away from the interruption point. (Unsure if scenario is
      # possible, but just keeping assertions in check.)
      @delayed = Hash.new(0) unless :step == context.stop_reason

      if @delayed[:next] > 1     # If any delayed nexts/steps, do 'em.
        step_over @delayed[:next] - 1
        @delayed = Hash.new(0)

      elsif @delayed[:step] > 1
        step @delayed[:step] - 1
        @delayed = Hash.new(0)

      elsif @delayed[:finish] > 0
        finish
        @delayed = Hash.new(0)

      else  # Otherwise, resume the pry session at the stopped line.
        resume_pry context
      end
    end
952754
def _walk(self):
        """"""

        self._base_len = len(self.base)

        for base, dirs, files in os.walk(self.base, followlinks=self.follow_links):
            # Remove child folders based on exclude rules
            for name in dirs[:]:
                try:
                    if not self._valid_folder(base, name):
                        dirs.remove(name)
                except Exception:
                    dirs.remove(name)
                    value = self.on_error(base, name)
                    if value is not None:  # pragma: no cover
                        yield value

                if self._abort:
                    break

            # Search files if they were found
            if len(files):
                # Only search files that are in the include rules
                for name in files:
                    try:
                        valid = self._valid_file(base, name)
                    except Exception:
                        valid = False
                        value = self.on_error(base, name)
                        if value is not None:
                            yield value

                    if valid:
                        yield self.on_match(base, name)
                    else:
                        self._skipped += 1
                        value = self.on_skip(base, name)
                        if value is not None:
                            yield value

                    if self._abort:
                        break

            if self._abort:
                break
1305129
def scandir(self, relpath):
    """"""
    if self.isignored(relpath, directory=True):
      self._raise_access_ignored(relpath)

    return self._filter_ignored(self._scandir_raw(relpath), selector=lambda e: e.path)
538611
def examine(self):
        """"""
        if self._changes:
            return self._changes.pop()

        # clean filepath
        self.filepath = None
        delays = set()
        for path in self._tasks:
            item = self._tasks[path]
            if self.is_changed(path, item['ignore']):
                func = item['func']
                delay = item['delay']
                if delay and isinstance(delay, float):
                    delays.add(delay)
                if func:
                    name = getattr(func, 'name', None)
                    if not name:
                        name = getattr(func, '__name__', 'anonymous')
                    logger.info(
                        "Running task: {} (delay: {})".format(name, delay))
                    func()

        if delays:
            delay = max(delays)
        else:
            delay = None
        return self.filepath, delay