Beispiel #1
0
/**
 * Parses an line from /proc/<pid>/maps
 */
void px_maps_region(const char *line)
{
	uintptr_t start, end;
	char perms[5], filename[PATH_MAX];
	int offset, dmajor, dminor, inode;
	const size_t n = ENV(nregions);

	if (sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %s %x %x:%x %u %s",
		&start, &end, perms, &offset, &dmajor, &dminor, &inode, filename) < 6 ||
		(end - start) == 0) {
		return;
	}

	if (ENV(maps) == NULL || n % 5 == 0) {
		ENV(maps) = (px_maps*) realloc(ENV(maps), sizeof(px_maps) * (n + 5));

		if (ENV(maps) == NULL) {
			px_error("Failed to realloc!\n");
			return;
		}
	}

	ENV(maps)[n].start = start;
	ENV(maps)[n].end = end;
	memcpy(ENV(maps)[n].filename, filename, sizeof(filename));
	memcpy(ENV(maps)[n].perms, perms, sizeof(perms));

	/* Sets the base address where we will read ELF data */
	if (n == 0) {
		ELF(header) = ENV(maps)[0].start;
	}

	++ENV(nregions);
}
Beispiel #2
0
bool DManager::secure(const DManager::secured_file_info &sfi) {
  // check file type
  QFile in(sfi.get_file_name());
  if(!in.open(QFile::ReadOnly)) {
      LOG_ERROR(QString("Could not open specified file: %s").arg(sfi.get_file_name()));
      return false;
  }

  // read whole file content
  QByteArray data = in.readAll(); // is passed as parameter to avoid race condition

  // TODO: change and save file
  bool s;
  // check if ELF / PE type
  if (ELF(data).is_valid()) {
    s = __secure_elf(data, sfi);
    if (!s) {
      LOG_WARN("Secure failed");
      return false;
    }

    return s;
  }
  if (PEFile(data).is_valid())
    return __secure_pe(data, sfi);

  LOG_ERROR(QString("Specified file %s is non-ELF neither non-PE").arg(sfi.get_file_name()));
  return false;
}