mirror of https://github.com/encounter/nod-rs.git
clippy config & fixes; enable LTO
This commit is contained in:
parent
46fa0c59ff
commit
6b8d41b130
|
@ -13,13 +13,19 @@ jobs:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
|
profile: minimal
|
||||||
toolchain: ${{ matrix.toolchain }}
|
toolchain: ${{ matrix.toolchain }}
|
||||||
override: true
|
override: true
|
||||||
|
components: rustfmt, clippy
|
||||||
- uses: EmbarkStudios/cargo-deny-action@v1
|
- uses: EmbarkStudios/cargo-deny-action@v1
|
||||||
- uses: actions-rs/cargo@v1
|
- uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: check
|
command: check
|
||||||
args: --all-features
|
args: --all-features
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: clippy
|
||||||
|
args: --all-features
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
|
@ -33,12 +39,13 @@ jobs:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
|
profile: minimal
|
||||||
toolchain: ${{ matrix.toolchain }}
|
toolchain: ${{ matrix.toolchain }}
|
||||||
override: true
|
override: true
|
||||||
- uses: actions-rs/cargo@v1
|
- uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
args: --all-features
|
args: --release --all-features
|
||||||
- uses: actions-rs/cargo@v1
|
- uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: build
|
command: build
|
||||||
|
|
|
@ -12,11 +12,15 @@ Rust library and CLI tool for reading GameCube and Wii disc images.
|
||||||
"""
|
"""
|
||||||
keywords = ["gamecube", "wii", "iso", "nfs", "gcm"]
|
keywords = ["gamecube", "wii", "iso", "nfs", "gcm"]
|
||||||
categories = ["command-line-utilities", "parser-implementations"]
|
categories = ["command-line-utilities", "parser-implementations"]
|
||||||
|
rust-version = "1.51"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "nodtool"
|
name = "nodtool"
|
||||||
path = "src/bin.rs"
|
path = "src/bin.rs"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
aes = "0.7.5"
|
aes = "0.7.5"
|
||||||
anyhow = "1.0.53"
|
anyhow = "1.0.53"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
msrv = "1.51"
|
|
@ -5,7 +5,6 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use clap::{clap_app, AppSettings};
|
use clap::{clap_app, AppSettings};
|
||||||
use file_size;
|
|
||||||
use nod::{
|
use nod::{
|
||||||
disc::{new_disc_base, PartReadStream},
|
disc::{new_disc_base, PartReadStream},
|
||||||
fst::NodeType,
|
fst::NodeType,
|
||||||
|
|
|
@ -52,7 +52,7 @@ impl<'a> Read for GCPartReadStream<'a> {
|
||||||
|
|
||||||
while rem > 0 {
|
while rem > 0 {
|
||||||
if block != self.cur_block as usize {
|
if block != self.cur_block as usize {
|
||||||
self.stream.read(&mut self.buf)?;
|
self.stream.read_exact(&mut self.buf)?;
|
||||||
self.cur_block = block as u64;
|
self.cur_block = block as u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ struct Ticket {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, BinRead)]
|
#[derive(Debug, PartialEq, BinRead)]
|
||||||
struct TMDContent {
|
struct TmdContent {
|
||||||
id: u32,
|
id: u32,
|
||||||
index: u16,
|
index: u16,
|
||||||
content_type: u16,
|
content_type: u16,
|
||||||
|
@ -114,7 +114,7 @@ struct TMDContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, BinRead)]
|
#[derive(Debug, PartialEq, BinRead)]
|
||||||
struct TMD {
|
struct Tmd {
|
||||||
sig_type: SigType,
|
sig_type: SigType,
|
||||||
#[br(count = 256)]
|
#[br(count = 256)]
|
||||||
sig: Vec<u8>,
|
sig: Vec<u8>,
|
||||||
|
@ -137,7 +137,7 @@ struct TMD {
|
||||||
#[br(pad_after = 2)]
|
#[br(pad_after = 2)]
|
||||||
boot_idx: u16,
|
boot_idx: u16,
|
||||||
#[br(count = num_contents)]
|
#[br(count = num_contents)]
|
||||||
contents: Vec<TMDContent>,
|
contents: Vec<TmdContent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, BinRead)]
|
#[derive(Debug, PartialEq, BinRead)]
|
||||||
|
@ -176,7 +176,7 @@ struct WiiPartitionHeader {
|
||||||
data_size: u64,
|
data_size: u64,
|
||||||
|
|
||||||
#[br(seek_before = SeekFrom::Start(tmd_off))]
|
#[br(seek_before = SeekFrom::Start(tmd_off))]
|
||||||
tmd: TMD,
|
tmd: Tmd,
|
||||||
#[br(seek_before = SeekFrom::Start(cert_chain_off))]
|
#[br(seek_before = SeekFrom::Start(cert_chain_off))]
|
||||||
ca_cert: Certificate,
|
ca_cert: Certificate,
|
||||||
tmd_cert: Certificate,
|
tmd_cert: Certificate,
|
||||||
|
@ -226,7 +226,7 @@ impl DiscBase for DiscWii {
|
||||||
.parts
|
.parts
|
||||||
.iter()
|
.iter()
|
||||||
.find(|v| v.part_type == WiiPartType::Data)
|
.find(|v| v.part_type == WiiPartType::Data)
|
||||||
.ok_or(Error::DiscFormat("Failed to locate data partition".to_string()))?;
|
.ok_or_else(|| Error::DiscFormat("Failed to locate data partition".to_string()))?;
|
||||||
let data_off = part.part_header.data_off;
|
let data_off = part.part_header.data_off;
|
||||||
let has_crypto = disc_io.has_wii_crypto();
|
let has_crypto = disc_io.has_wii_crypto();
|
||||||
let result = Box::new(WiiPartReadStream {
|
let result = Box::new(WiiPartReadStream {
|
||||||
|
@ -276,7 +276,7 @@ impl<'a> PartReadStream for WiiPartReadStream<'a> {
|
||||||
fn as_digest(slice: &[u8; 20]) -> digest::Output<Sha1> { (*slice).into() }
|
fn as_digest(slice: &[u8; 20]) -> digest::Output<Sha1> { (*slice).into() }
|
||||||
|
|
||||||
fn decrypt_block(part: &mut WiiPartReadStream, cluster: usize) -> io::Result<()> {
|
fn decrypt_block(part: &mut WiiPartReadStream, cluster: usize) -> io::Result<()> {
|
||||||
part.stream.read(&mut part.buf)?;
|
part.stream.read_exact(&mut part.buf)?;
|
||||||
if part.crypto.is_some() {
|
if part.crypto.is_some() {
|
||||||
// Fetch IV before decrypting header
|
// Fetch IV before decrypting header
|
||||||
let iv = Block::from(*array_ref![part.buf, 0x3d0, 16]);
|
let iv = Block::from(*array_ref![part.buf, 0x3d0, 16]);
|
||||||
|
|
|
@ -37,18 +37,18 @@ pub trait DiscIO: Send + Sync {
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new_disc_io(filename: &Path) -> Result<Box<dyn DiscIO>> {
|
pub fn new_disc_io(filename: &Path) -> Result<Box<dyn DiscIO>> {
|
||||||
let path_result = fs::canonicalize(filename);
|
let path_result = fs::canonicalize(filename);
|
||||||
if path_result.is_err() {
|
if let Err(err) = path_result {
|
||||||
return Result::Err(Error::Io(
|
return Result::Err(Error::Io(
|
||||||
format!("Failed to open {}", filename.to_string_lossy()),
|
format!("Failed to open {}", filename.to_string_lossy()),
|
||||||
path_result.unwrap_err(),
|
err,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let path = path_result.as_ref().unwrap();
|
let path = path_result.as_ref().unwrap();
|
||||||
let meta = fs::metadata(path);
|
let meta = fs::metadata(path);
|
||||||
if meta.is_err() {
|
if let Err(err) = meta {
|
||||||
return Result::Err(Error::Io(
|
return Result::Err(Error::Io(
|
||||||
format!("Failed to open {}", filename.to_string_lossy()),
|
format!("Failed to open {}", filename.to_string_lossy()),
|
||||||
meta.unwrap_err(),
|
err,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if !meta.unwrap().is_file() {
|
if !meta.unwrap().is_file() {
|
||||||
|
|
|
@ -34,16 +34,16 @@ pub(crate) struct NFSHeader {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub(crate) struct FBO {
|
pub(crate) struct Fbo {
|
||||||
pub(crate) file: u32,
|
pub(crate) file: u32,
|
||||||
pub(crate) block: u32,
|
pub(crate) block: u32,
|
||||||
pub(crate) l_block: u32,
|
pub(crate) l_block: u32,
|
||||||
pub(crate) offset: u32,
|
pub(crate) offset: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for FBO {
|
impl Default for Fbo {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
FBO { file: u32::MAX, block: u32::MAX, l_block: u32::MAX, offset: u32::MAX }
|
Fbo { file: u32::MAX, block: u32::MAX, l_block: u32::MAX, offset: u32::MAX }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ impl NFSHeader {
|
||||||
(((total_block_count as u64) * 0x8000u64 + (0x200u64 + 0xF9FFFFFu64)) / 0xFA00000u64) as u32
|
(((total_block_count as u64) * 0x8000u64 + (0x200u64 + 0xF9FFFFFu64)) / 0xFA00000u64) as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn logical_to_fbo(&self, offset: u64) -> FBO {
|
pub(crate) fn logical_to_fbo(&self, offset: u64) -> Fbo {
|
||||||
let block_div = (offset / 0x8000) as u32;
|
let block_div = (offset / 0x8000) as u32;
|
||||||
let block_off = (offset % 0x8000) as u32;
|
let block_off = (offset % 0x8000) as u32;
|
||||||
let mut block = u32::MAX;
|
let mut block = u32::MAX;
|
||||||
|
@ -70,9 +70,9 @@ impl NFSHeader {
|
||||||
physical_block += range.num_blocks;
|
physical_block += range.num_blocks;
|
||||||
}
|
}
|
||||||
if block == u32::MAX {
|
if block == u32::MAX {
|
||||||
FBO::default()
|
Fbo::default()
|
||||||
} else {
|
} else {
|
||||||
FBO { file: block / 8000, block: block % 8000, l_block: block_div, offset: block_off }
|
Fbo { file: block / 8000, block: block % 8000, l_block: block_div, offset: block_off }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ pub(crate) struct NFSReadStream<'a> {
|
||||||
file: Option<File>,
|
file: Option<File>,
|
||||||
crypto: Aes128,
|
crypto: Aes128,
|
||||||
// Physical address - all UINT32_MAX indicates logical zero block
|
// Physical address - all UINT32_MAX indicates logical zero block
|
||||||
phys_addr: FBO,
|
phys_addr: Fbo,
|
||||||
// Logical address
|
// Logical address
|
||||||
offset: u64,
|
offset: u64,
|
||||||
// Active file stream and its offset as set in the system.
|
// Active file stream and its offset as set in the system.
|
||||||
|
@ -127,7 +127,7 @@ impl<'a> NFSReadStream<'a> {
|
||||||
io::Result::Ok(())
|
io::Result::Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_phys_addr(&mut self, phys_addr: FBO) -> Result<()> {
|
fn set_phys_addr(&mut self, phys_addr: Fbo) -> Result<()> {
|
||||||
// If we're just changing the offset, nothing else needs to be done
|
// If we're just changing the offset, nothing else needs to be done
|
||||||
if self.phys_addr.file == phys_addr.file && self.phys_addr.block == phys_addr.block {
|
if self.phys_addr.file == phys_addr.file && self.phys_addr.block == phys_addr.block {
|
||||||
self.phys_addr.offset = phys_addr.offset;
|
self.phys_addr.offset = phys_addr.offset;
|
||||||
|
@ -151,12 +151,12 @@ impl<'a> NFSReadStream<'a> {
|
||||||
|
|
||||||
// Read block, handling 0x200 overlap case
|
// Read block, handling 0x200 overlap case
|
||||||
if phys_addr.block == 7999 {
|
if phys_addr.block == 7999 {
|
||||||
self.file.as_ref().unwrap().read(&mut self.buf[..BUFFER_SIZE - 0x200])?;
|
self.file.as_ref().unwrap().read_exact(&mut self.buf[..BUFFER_SIZE - 0x200])?;
|
||||||
self.set_cur_file(self.cur_file + 1)?;
|
self.set_cur_file(self.cur_file + 1)?;
|
||||||
self.file.as_ref().unwrap().read(&mut self.buf[BUFFER_SIZE - 0x200..])?;
|
self.file.as_ref().unwrap().read_exact(&mut self.buf[BUFFER_SIZE - 0x200..])?;
|
||||||
self.cur_block = 0;
|
self.cur_block = 0;
|
||||||
} else {
|
} else {
|
||||||
self.file.as_ref().unwrap().read(&mut self.buf)?;
|
self.file.as_ref().unwrap().read_exact(&mut self.buf)?;
|
||||||
self.cur_block += 1;
|
self.cur_block += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ impl<'a> Read for NFSReadStream<'a> {
|
||||||
read_size = BUFFER_SIZE - block_offset
|
read_size = BUFFER_SIZE - block_offset
|
||||||
}
|
}
|
||||||
buf[read..read + read_size]
|
buf[read..read + read_size]
|
||||||
.copy_from_slice(&mut self.buf[block_offset..block_offset + read_size]);
|
.copy_from_slice(&self.buf[block_offset..block_offset + read_size]);
|
||||||
read += read_size;
|
read += read_size;
|
||||||
rem -= read_size;
|
rem -= read_size;
|
||||||
self.offset += read_size as u64;
|
self.offset += read_size as u64;
|
||||||
|
@ -233,7 +233,7 @@ impl DiscIO for DiscIONFS {
|
||||||
disc_io: self,
|
disc_io: self,
|
||||||
file: Option::None,
|
file: Option::None,
|
||||||
crypto: Aes128::new(&self.key.into()),
|
crypto: Aes128::new(&self.key.into()),
|
||||||
phys_addr: FBO::default(),
|
phys_addr: Fbo::default(),
|
||||||
offset,
|
offset,
|
||||||
cur_file: u32::MAX,
|
cur_file: u32::MAX,
|
||||||
cur_block: u32::MAX,
|
cur_block: u32::MAX,
|
||||||
|
|
|
@ -191,6 +191,7 @@ impl Read for ByteReadStream<'_> {
|
||||||
let total = self.bytes.len();
|
let total = self.bytes.len();
|
||||||
let pos = self.position as usize;
|
let pos = self.position as usize;
|
||||||
if len + pos > total {
|
if len + pos > total {
|
||||||
|
#[allow(clippy::comparison_chain)]
|
||||||
if pos > total {
|
if pos > total {
|
||||||
return Err(io::Error::from(io::ErrorKind::UnexpectedEof));
|
return Err(io::Error::from(io::ErrorKind::UnexpectedEof));
|
||||||
} else if pos == total {
|
} else if pos == total {
|
||||||
|
|
Loading…
Reference in New Issue