Skip to content

Commit

Permalink
huge refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Jun 12, 2023
1 parent 314b1a2 commit eeabb3f
Show file tree
Hide file tree
Showing 5,960 changed files with 647 additions and 457 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 2 additions & 2 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ jobs:

- name: Build Packages
run: |
for f in fw-extract elf-verify ipk-verify; do
cargo deb -p "$f" || exit 1
for f in packages/*; do
cargo deb -p $(basename "$f") || exit 1
done
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:

- name: Build Packages
run: |
for f in fw-extract elf-verify ipk-verify; do
cargo deb -p "$f" || exit 1
for f in packages/*; do
cargo deb -p $(basename "$f") || exit 1
done
- name: Create Release (Ubuntu)
Expand Down
70 changes: 57 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[workspace]
members = [
"common",
"elf-verify",
"ipk-verify",
"fw-extract"
"common/fw",
"common/bin",
"common/ipk",
"common/verify",
"packages/elf-verify",
"packages/ipk-verify",
"packages/fw-extract",
"packages/gen-manifest",
]
7 changes: 0 additions & 7 deletions common/Cargo.lock

This file was deleted.

2 changes: 1 addition & 1 deletion common/Cargo.toml → common/bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "common"
name = "bin-lib"
version = "0.1.0"
edition = "2021"

Expand Down
74 changes: 5 additions & 69 deletions common/src/binary.rs → common/bin/src/binary.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::fs::File;
use std::io::{Error, ErrorKind};
use std::path::Path;

use elf::dynamic::Dyn;
use elf::endian::AnyEndian;
use elf::symbol::Symbol;
use elf::{abi, ElfStream};
use std::collections::HashSet;
use std::fs::File;
use std::io::{Error, ErrorKind};
use std::path::Path;

use crate::{BinVerifyResult, BinaryInfo, Firmware, LibraryInfo, VerifyResult, VerifyWithFirmware};
use crate::{BinaryInfo, LibraryInfo};

impl BinaryInfo {
pub fn find_library(&self, name: &str) -> Option<LibraryInfo> {
Expand Down Expand Up @@ -96,70 +96,6 @@ impl BinaryInfo {
}
}

impl VerifyWithFirmware<BinVerifyResult> for BinaryInfo {
fn verify(&self, firmware: &Firmware) -> BinVerifyResult {
let mut result = BinVerifyResult::new(self.name.clone());
result.undefined_sym.extend(self.undefined.clone());
let mut visited_libs: HashSet<String> = Default::default();

let find_library = |name: &str| -> Option<LibraryInfo> {
return firmware
.find_library(name)
.or_else(|| self.find_library(name));
};

fn resolve_symbols<F>(
lib: &LibraryInfo,
undefined: &mut Vec<String>,
visited: &mut HashSet<String>,
lib_resolver: &F,
) where
F: Fn(&str) -> Option<LibraryInfo>,
{
undefined.retain(|symbol| !lib.has_symbol(symbol));
for needed in &lib.needed {
if visited.contains(needed) {
continue;
}
visited.insert(needed.clone());
if let Some(needed) = lib_resolver(needed) {
resolve_symbols(&needed, undefined, visited, lib_resolver);
}
}
}

for needed in &self.needed {
if let Some(lib) = find_library(needed) {
resolve_symbols(
&lib,
&mut result.undefined_sym,
&mut visited_libs,
&find_library,
);
} else {
result.missing_lib.push(needed.clone());
}
}
return result;
}
}

impl BinVerifyResult {
pub fn new(name: String) -> Self {
return Self {
name,
missing_lib: Default::default(),
undefined_sym: Default::default(),
};
}
}

impl VerifyResult for BinVerifyResult {
fn is_good(&self) -> bool {
return self.missing_lib.is_empty() && self.undefined_sym.is_empty();
}
}

#[cfg(test)]
mod tests {
use std::io::Cursor;
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions common/bin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use serde::{Deserialize, Serialize};

pub mod binary;
pub mod library;

#[derive(Debug, Serialize, Deserialize)]
pub struct BinaryInfo {
pub name: String,
pub rpath: Vec<String>,
pub needed: Vec<String>,
pub undefined: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct LibraryInfo {
pub name: String,
pub needed: Vec<String>,
pub symbols: Vec<String>,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub names: Vec<String>,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub undefined: Vec<String>,
}
File renamed without changes.
Loading

0 comments on commit eeabb3f

Please sign in to comment.