Example #1
0
  /** Interrogate the IFileEx. */
  private void addExtendedInfo(FileObject fObj, IFileEx extended, FileItem item)
      throws IOException {
    if (extended instanceof IWindowsFileInfo) {
      EntityItemFileTypeType typeType = Factories.sc.windows.createEntityItemFileTypeType();
      switch (((IWindowsFileInfo) extended).getWindowsFileType()) {
        case IWindowsFileInfo.FILE_ATTRIBUTE_DIRECTORY:
          typeType.setValue("FILE_ATTRIBUTE_DIRECTORY");
          break;
        case IWindowsFileInfo.FILE_TYPE_DISK:
          typeType.setValue("FILE_TYPE_DISK");
          break;
        case IWindowsFileInfo.FILE_TYPE_REMOTE:
          typeType.setValue("FILE_TYPE_REMOTE");
          break;
        case IWindowsFileInfo.FILE_TYPE_PIPE:
          typeType.setValue("FILE_TYPE_PIPE");
          break;
        case IWindowsFileInfo.FILE_TYPE_CHAR:
          typeType.setValue("FILE_TYPE_CHAR");
          break;
        default:
          typeType.setValue("FILE_TYPE_UNKNOWN");
          break;
      }
      item.setType(typeType);

      EntityItemStringType ownerType = Factories.sc.core.createEntityItemStringType();
      ownerType.setValue(((IWindowsFileInfo) extended).getOwner().getNetbiosName());
      item.setOwner(ownerType);
    } else if (extended instanceof IUnixFileInfo) {
      EntityItemFileTypeType typeType = Factories.sc.windows.createEntityItemFileTypeType();
      String type = ((IUnixFileInfo) extended).getUnixFileType();
      if (IUnixFileInfo.FILE_TYPE_DIR.equals(type)) {
        typeType.setValue("FILE_ATTRIBUTE_DIRECTORY");
      } else if (IUnixFileInfo.FILE_TYPE_REGULAR.equals(type)) {
        typeType.setValue("FILE_TYPE_DISK");
      } else if (IUnixFileInfo.FILE_TYPE_FIFO.equals(type)) {
        typeType.setValue("FILE_TYPE_PIPE");
      } else if (IUnixFileInfo.FILE_TYPE_CHAR.equals(type)) {
        typeType.setValue("FILE_TYPE_CHAR");
      } else {
        typeType.setValue("FILE_TYPE_UNKNOWN");
      }
      item.setType(typeType);
    }
  }
Example #2
0
  /**
   * Read the Portable Execution format header information from the IFileEx, or directly from the
   * file itself, and convey it to the item.
   */
  private void addHeaderInfo(FileObject fObj, IFile file, FileItem item) throws IOException {
    session.getLogger().trace(JOVALMsg.STATUS_PE_READ, file.toString());
    IFileEx extended = file.getExtended();
    Map<String, String> peHeaders = null;
    if (file.isFile() && file.length() == 0) {
      MessageType msg = Factories.common.createMessageType();
      msg.setLevel(MessageLevelEnumeration.INFO);
      msg.setValue(JOVALMsg.getMessage(JOVALMsg.STATUS_PE_EMPTY));
      item.getMessage().add(msg);
    } else if (extended instanceof IWindowsFileInfo) {
      peHeaders = ((IWindowsFileInfo) extended).getPEHeaders();
    } else if (file.isFile()) {
      try {
        Header header = new Header(file);
        peHeaders = new HashMap<String, String>();
        String cs = Integer.toString(header.getNTHeader().getImageOptionalHeader().getChecksum());
        peHeaders.put(IWindowsFileInfo.PE_MS_CHECKSUM, cs);
        String key = VsVersionInfo.LANGID_KEY;
        VsVersionInfo versionInfo = header.getVersionInfo();
        VsFixedFileInfo value = null;
        if (versionInfo != null) {
          value = versionInfo.getValue();
          key = versionInfo.getDefaultTranslation();
        }
        if (value != null) {
          String version = versionInfo.getValue().getFileVersion().toString();
          peHeaders.put(IWindowsFileInfo.PE_VERSION, version);
          StringTokenizer tok = new StringTokenizer(version, ".");
          if (tok.countTokens() == 4) {
            peHeaders.put(IWindowsFileInfo.PE_VERSION_MAJOR_PART, tok.nextToken());
            peHeaders.put(IWindowsFileInfo.PE_VERSION_MINOR_PART, tok.nextToken());
            peHeaders.put(IWindowsFileInfo.PE_VERSION_BUILD_PART, tok.nextToken());
            peHeaders.put(IWindowsFileInfo.PE_VERSION_PRIVATE_PART, tok.nextToken());
          }
          String locale = LanguageConstants.getLocaleString(key);
          if (locale != null) {
            peHeaders.put(IWindowsFileInfo.PE_LANGUAGE, LanguageConstants.getLocaleString(key));
          }
          Map<String, String> stringTable = versionInfo.getStringTable(key);
          if (stringTable.containsKey("CompanyName")) {
            peHeaders.put(IWindowsFileInfo.PE_COMPANY_NAME, stringTable.get("CompanyName"));
          }
          if (stringTable.containsKey("InternalName")) {
            peHeaders.put(IWindowsFileInfo.PE_INTERNAL_NAME, stringTable.get("InternalName"));
          }
          if (stringTable.containsKey("ProductName")) {
            peHeaders.put(IWindowsFileInfo.PE_PRODUCT_NAME, stringTable.get("ProductName"));
          }
          if (stringTable.containsKey("OriginalFilename")) {
            peHeaders.put(IWindowsFileInfo.PE_ORIGINAL_NAME, stringTable.get("OriginalFilename"));
          }
          if (stringTable.containsKey("ProductVersion")) {
            peHeaders.put(IWindowsFileInfo.PE_PRODUCT_VERSION, stringTable.get("ProductVersion"));
          }
        }
      } catch (IllegalArgumentException e) {
        MessageType msg = Factories.common.createMessageType();
        msg.setLevel(MessageLevelEnumeration.ERROR);
        msg.setValue(e.getMessage());
        item.getMessage().add(msg);
      }
    }

    EntityItemStringType msChecksumType = Factories.sc.core.createEntityItemStringType();
    if (peHeaders != null && peHeaders.containsKey(IWindowsFileInfo.PE_MS_CHECKSUM)) {
      msChecksumType.setValue(peHeaders.get(IWindowsFileInfo.PE_MS_CHECKSUM));
    } else {
      msChecksumType.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setMsChecksum(msChecksumType);

    EntityItemStringType languageType = Factories.sc.core.createEntityItemStringType();
    if (peHeaders != null && peHeaders.containsKey(IWindowsFileInfo.PE_LANGUAGE)) {
      languageType.setValue(peHeaders.get(IWindowsFileInfo.PE_LANGUAGE));
    } else {
      languageType.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setLanguage(languageType);

    EntityItemVersionType versionType = Factories.sc.core.createEntityItemVersionType();
    versionType.setDatatype(SimpleDatatypeEnumeration.VERSION.value());
    if (peHeaders != null && peHeaders.containsKey(IWindowsFileInfo.PE_VERSION_MAJOR_PART)) {
      int major = Integer.parseInt(peHeaders.get(IWindowsFileInfo.PE_VERSION_MAJOR_PART));
      int minor = 0, build = 0, priv = 0;
      if (peHeaders.containsKey(IWindowsFileInfo.PE_VERSION_MINOR_PART)) {
        minor = Integer.parseInt(peHeaders.get(IWindowsFileInfo.PE_VERSION_MINOR_PART));
      }
      if (peHeaders.containsKey(IWindowsFileInfo.PE_VERSION_BUILD_PART)) {
        build = Integer.parseInt(peHeaders.get(IWindowsFileInfo.PE_VERSION_BUILD_PART));
      }
      if (peHeaders.containsKey(IWindowsFileInfo.PE_VERSION_PRIVATE_PART)) {
        priv = Integer.parseInt(peHeaders.get(IWindowsFileInfo.PE_VERSION_PRIVATE_PART));
      }
      if (major == 0 && minor == 0 && build == 0 && priv == 0) {
        versionType.setStatus(StatusEnumeration.DOES_NOT_EXIST);
      } else {
        versionType.setValue(new Version(major, minor, build, priv).toString());
      }
    } else {
      versionType.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setFileVersion(versionType);

    EntityItemStringType companyType = Factories.sc.core.createEntityItemStringType();
    if (peHeaders != null && peHeaders.containsKey(IWindowsFileInfo.PE_COMPANY_NAME)) {
      companyType.setValue(peHeaders.get(IWindowsFileInfo.PE_COMPANY_NAME));
    } else {
      companyType.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setCompany(companyType);

    EntityItemStringType internalNameType = Factories.sc.core.createEntityItemStringType();
    if (peHeaders != null && peHeaders.containsKey(IWindowsFileInfo.PE_INTERNAL_NAME)) {
      internalNameType.setValue(peHeaders.get(IWindowsFileInfo.PE_INTERNAL_NAME));
    } else {
      internalNameType.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setInternalName(internalNameType);

    EntityItemStringType productNameType = Factories.sc.core.createEntityItemStringType();
    if (peHeaders != null && peHeaders.containsKey(IWindowsFileInfo.PE_PRODUCT_NAME)) {
      productNameType.setValue(peHeaders.get(IWindowsFileInfo.PE_PRODUCT_NAME));
    } else {
      productNameType.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setProductName(productNameType);

    EntityItemStringType originalFilenameType = Factories.sc.core.createEntityItemStringType();
    if (peHeaders != null && peHeaders.containsKey(IWindowsFileInfo.PE_ORIGINAL_NAME)) {
      originalFilenameType.setValue(peHeaders.get(IWindowsFileInfo.PE_ORIGINAL_NAME));
    } else {
      originalFilenameType.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setOriginalFilename(originalFilenameType);

    EntityItemVersionType productVersionType = Factories.sc.core.createEntityItemVersionType();
    productVersionType.setDatatype(SimpleDatatypeEnumeration.VERSION.value());
    if (peHeaders != null && peHeaders.containsKey(IWindowsFileInfo.PE_PRODUCT_VERSION)) {
      productVersionType.setValue(peHeaders.get(IWindowsFileInfo.PE_PRODUCT_VERSION));
    } else {
      productVersionType.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setProductVersion(productVersionType);

    EntityItemStringType developmentClassType = Factories.sc.core.createEntityItemStringType();
    if (peHeaders != null && peHeaders.containsKey(IWindowsFileInfo.PE_VERSION)) {
      try {
        developmentClassType.setValue(
            getDevelopmentClass(peHeaders.get(IWindowsFileInfo.PE_VERSION)));
      } catch (IllegalArgumentException e) {
        MessageType msg = Factories.common.createMessageType();
        msg.setLevel(MessageLevelEnumeration.INFO);
        msg.setValue(JOVALMsg.getMessage(JOVALMsg.STATUS_PE_DEVCLASS, e.getMessage()));
        item.getMessage().add(msg);
        developmentClassType.setStatus(StatusEnumeration.DOES_NOT_EXIST);
      }
    } else {
      developmentClassType.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setDevelopmentClass(developmentClassType);
  }
Example #3
0
  private XinetdItem makeItem(Service service) {
    XinetdItem item = Factories.sc.unix.createXinetdItem();

    EntityItemStringType serviceName = Factories.sc.core.createEntityItemStringType();
    serviceName.setValue(service.getName());
    item.setServiceName(serviceName);

    EntityItemBoolType disabled = Factories.sc.core.createEntityItemBoolType();
    disabled.setDatatype(SimpleDatatypeEnumeration.BOOLEAN.value());
    try {
      disabled.setValue(service.getString(Property.DISABLE).equals("yes") ? "1" : "0");
    } catch (NoSuchElementException e) {
      disabled.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setDisabled(disabled);

    try {
      for (String flag : service.get(Property.FLAGS)) {
        EntityItemStringType value = Factories.sc.core.createEntityItemStringType();
        value.setValue(flag);
        item.getFlags().add(value);
      }
    } catch (NoSuchElementException e) {
    }

    try {
      for (String deny : service.get(Property.NO_ACCESS)) {
        EntityItemStringType value = Factories.sc.core.createEntityItemStringType();
        value.setValue(deny);
        item.getNoAccess().add(value);
      }
    } catch (NoSuchElementException e) {
    }

    try {
      for (String allow : service.get(Property.ONLY_FROM)) {
        EntityItemIPAddressStringType value =
            Factories.sc.core.createEntityItemIPAddressStringType();
        value.setValue(allow);
        item.getOnlyFrom().add(value);
      }
    } catch (NoSuchElementException e) {
    }

    EntityItemIntType port = Factories.sc.core.createEntityItemIntType();
    port.setDatatype(SimpleDatatypeEnumeration.INT.value());
    try {
      port.setValue(service.getString(Property.PORT));
    } catch (NoSuchElementException e) {
      port.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setPort(port);

    EntityItemStringType protocol = Factories.sc.core.createEntityItemStringType();
    try {
      protocol.setValue(service.getString(Property.PROTOCOL));
    } catch (NoSuchElementException e) {
      protocol.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setProtocol(protocol);

    EntityItemStringType server = Factories.sc.core.createEntityItemStringType();
    try {
      server.setValue(service.getString(Property.SERVER));
    } catch (NoSuchElementException e) {
      server.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setServer(server);

    EntityItemStringType serverArguments = Factories.sc.core.createEntityItemStringType();
    try {
      serverArguments.setValue(service.getString(Property.SERVER_ARGUMENTS));
    } catch (NoSuchElementException e) {
      serverArguments.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setServerArguments(serverArguments);

    EntityItemStringType socketType = Factories.sc.core.createEntityItemStringType();
    try {
      socketType.setValue(service.getString(Property.SOCKET_TYPE));
    } catch (NoSuchElementException e) {
      socketType.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setSocketType(socketType);

    EntityItemXinetdTypeStatusType type = Factories.sc.unix.createEntityItemXinetdTypeStatusType();
    try {
      type.setValue(service.getString(Property.TYPE));
    } catch (NoSuchElementException e) {
      type.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setType(type);

    EntityItemStringType user = Factories.sc.core.createEntityItemStringType();
    try {
      user.setValue(service.getString(Property.USER));
    } catch (NoSuchElementException e) {
      user.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setUser(user);

    EntityItemBoolType wait = Factories.sc.core.createEntityItemBoolType();
    wait.setDatatype(SimpleDatatypeEnumeration.BOOLEAN.value());
    try {
      wait.setValue(service.getString(Property.WAIT).equals("wait") ? "1" : "0");
    } catch (NoSuchElementException e) {
      wait.setStatus(StatusEnumeration.DOES_NOT_EXIST);
    }
    item.setWait(wait);

    item.setStatus(StatusEnumeration.EXISTS);
    return item;
  }