Skip to content

Commit aa306b2

Browse files
committed
license and fmt and info
1 parent 1c5eca8 commit aa306b2

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ jobs:
88
steps:
99
- uses: actions/checkout@v4
1010
- uses: dtolnay/rust-toolchain@stable
11+
with:
12+
components: rustfmt
13+
- run: cargo fmt --check
1114
- run: cargo build --release

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
[package]
22
name = "utracy-redact"
3+
description = "Redact secret source locations from .utracy profiler files"
34
version = "1.0.0"
45
edition = "2024"
6+
authors = ["ZeWaka <zewakagamer@gmail.com>"]
7+
repository = "https://github.com/spacestation13/utracy-redact"
8+
license = "GPL-3.0"
59

610
[dependencies]
711
clap = { version = "4.5", features = ["derive"] }

LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
utracy-redact - redact secret source locations from .utracy profiler files
2+
Copyright (C) 2026 ZeWaka
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>.

src/main.rs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fs::{self, File};
22
use std::io::{BufReader, BufWriter, Read, Write};
33
use std::path::{Path, PathBuf};
44

5-
use anyhow::{bail, Context, Result};
5+
use anyhow::{Context, Result, bail};
66
use clap::Parser;
77

88
// .utracy file constants
@@ -52,15 +52,17 @@ struct Cli {
5252

5353
fn read_lenpfx_string<R: Read>(r: &mut R) -> Result<String> {
5454
let mut len_buf = [0u8; 4];
55-
r.read_exact(&mut len_buf).context("reading string length")?;
55+
r.read_exact(&mut len_buf)
56+
.context("reading string length")?;
5657
let len = u32::from_le_bytes(len_buf) as usize;
5758
let mut bytes = vec![0u8; len];
5859
r.read_exact(&mut bytes).context("reading string bytes")?;
5960
String::from_utf8(bytes).context("string is not valid UTF-8")
6061
}
6162

6263
fn write_lenpfx_string<W: Write>(w: &mut W, s: &str) -> Result<()> {
63-
w.write_all(&(s.len() as u32).to_le_bytes()).context("writing string length")?;
64+
w.write_all(&(s.len() as u32).to_le_bytes())
65+
.context("writing string length")?;
6466
w.write_all(s.as_bytes()).context("writing string bytes")
6567
}
6668

@@ -77,8 +79,7 @@ fn resolve_output(cli: &Cli) -> Result<Option<PathBuf>> {
7779
return Ok(None); // we'll use a temp file; handled separately
7880
}
7981

80-
let canonical_in = fs::canonicalize(&cli.input)
81-
.unwrap_or_else(|_| cli.input.clone());
82+
let canonical_in = fs::canonicalize(&cli.input).unwrap_or_else(|_| cli.input.clone());
8283

8384
if let Some(p) = &cli.output {
8485
let canonical_out = fs::canonicalize(p).unwrap_or_else(|_| p.clone());
@@ -126,9 +127,7 @@ fn process<R: Read, W: Write>(
126127
// Validate signature (u64 LE at offset 0)
127128
let sig = u64::from_le_bytes(header[SIG_OFFSET..SIG_OFFSET + 8].try_into().unwrap());
128129
if sig != FILE_SIGNATURE {
129-
bail!(
130-
"invalid .utracy signature: got 0x{sig:016X}, expected 0x{FILE_SIGNATURE:016X}"
131-
);
130+
bail!("invalid .utracy signature: got 0x{sig:016X}, expected 0x{FILE_SIGNATURE:016X}");
132131
}
133132

134133
// Validate version (u32 LE at offset 8)
@@ -155,7 +154,10 @@ fn process<R: Read, W: Write>(
155154
}
156155

157156
// -- Srcloc table --------------------------------------------------------
158-
let file_markers_lower: Vec<String> = file_markers.iter().map(|m| m.to_ascii_lowercase()).collect();
157+
let file_markers_lower: Vec<String> = file_markers
158+
.iter()
159+
.map(|m| m.to_ascii_lowercase())
160+
.collect();
159161
let fn_markers_lower: Vec<String> = fn_markers.iter().map(|m| m.to_ascii_lowercase()).collect();
160162
let mut redacted_fns = Vec::new();
161163

@@ -175,8 +177,12 @@ fn process<R: Read, W: Write>(
175177

176178
let file_lower = file.to_ascii_lowercase();
177179
let fn_lower = function.to_ascii_lowercase();
178-
let secret = file_markers_lower.iter().any(|m| file_lower.contains(m.as_str()))
179-
|| fn_markers_lower.iter().any(|m| fn_lower.contains(m.as_str()));
180+
let secret = file_markers_lower
181+
.iter()
182+
.any(|m| file_lower.contains(m.as_str()))
183+
|| fn_markers_lower
184+
.iter()
185+
.any(|m| fn_lower.contains(m.as_str()));
180186

181187
if secret {
182188
redacted_fns.push(function.clone());
@@ -192,7 +198,9 @@ fn process<R: Read, W: Write>(
192198
write_lenpfx_string(writer, out_fn).context("writing srcloc.function")?;
193199
write_lenpfx_string(writer, out_file).context("writing srcloc.file")?;
194200
writer.write_all(&line_buf).context("writing srcloc.line")?;
195-
writer.write_all(&color_buf).context("writing srcloc.color")?;
201+
writer
202+
.write_all(&color_buf)
203+
.context("writing srcloc.color")?;
196204
}
197205
}
198206

@@ -246,11 +254,17 @@ fn main() -> Result<()> {
246254
let redacted: Vec<String>;
247255

248256
if let Some(out) = effective_out {
249-
let out_file = File::create(out)
250-
.with_context(|| format!("creating output: {}", out.display()))?;
257+
let out_file =
258+
File::create(out).with_context(|| format!("creating output: {}", out.display()))?;
251259
let mut writer = BufWriter::with_capacity(BUF_SIZE, out_file);
252260

253-
redacted = process(&mut reader, &mut writer, false, &cli.file_markers, &cli.fn_markers)?;
261+
redacted = process(
262+
&mut reader,
263+
&mut writer,
264+
false,
265+
&cli.file_markers,
266+
&cli.fn_markers,
267+
)?;
254268

255269
writer.flush().context("flushing output")?;
256270
} else {

0 commit comments

Comments
 (0)