Skip to content

Commit 462abe2

Browse files
committed
Format the host with cargo fmt
1 parent 1fd02ea commit 462abe2

10 files changed

Lines changed: 291 additions & 142 deletions

File tree

‎build.rs‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,18 @@ fn pinned(manifest: &Path, path: &str) -> String {
8989
entries
9090
.as_array()
9191
.and_then(|list| {
92-
list.iter().find(|entry| entry["path"] == path).and_then(|entry| {
93-
entry["version"].as_str().map(str::to_string)
94-
})
92+
list.iter()
93+
.find(|entry| entry["path"] == path)
94+
.and_then(|entry| entry["version"].as_str().map(str::to_string))
9595
})
9696
.unwrap_or_else(|| panic!("No version is pinned for {path} in dependencies.json"))
9797
}
9898

9999
/// Downloads and unpacks `agent.zip` from a public release. No token: needing
100100
/// one to build the host would defeat the point of the download path.
101101
fn fetch(version: &str, into: &Path) {
102-
let url = format!(
103-
"https://github.com/ancaria-dev/coderpack/releases/download/v{version}/agent.zip"
104-
);
102+
let url =
103+
format!("https://github.com/ancaria-dev/coderpack/releases/download/v{version}/agent.zip");
105104
let holder = into.parent().unwrap_or(into).to_path_buf();
106105
let zip = holder.join(format!("agent-{version}.zip"));
107106
fs::create_dir_all(&holder).ok();
@@ -142,9 +141,7 @@ fn fetch(version: &str, into: &Path) {
142141
vec![
143142
"-NoProfile",
144143
"-Command",
145-
&format!(
146-
"Expand-Archive -Path '{target}' -DestinationPath '{folder}' -Force"
147-
),
144+
&format!("Expand-Archive -Path '{target}' -DestinationPath '{folder}' -Force"),
148145
],
149146
),
150147
]);
@@ -178,8 +175,7 @@ fn embed(dir: &Path, origin: &str, out: &Path) {
178175

179176
let addr = dir.join("gen/addr.js");
180177
println!("cargo:rerun-if-changed={}", addr.display());
181-
fs::write(staged.join("addr.js"), js::compact(&read(&addr)))
182-
.expect("could not stage addr.js");
178+
fs::write(staged.join("addr.js"), js::compact(&read(&addr))).expect("could not stage addr.js");
183179

184180
let mut modules: Vec<PathBuf> = fs::read_dir(dir)
185181
.unwrap_or_else(|err| panic!("Could not read {}: {err}", dir.display()))
@@ -190,9 +186,8 @@ fn embed(dir: &Path, origin: &str, out: &Path) {
190186
// are for: every module shares one scope and later definitions win.
191187
modules.sort();
192188

193-
let mut table = String::from(
194-
"// Generated by build.rs. The agent, minified, one entry per module.\n",
195-
);
189+
let mut table =
190+
String::from("// Generated by build.rs. The agent, minified, one entry per module.\n");
196191
table.push_str(&format!("pub static ORIGIN: &str = {:?};\n", origin));
197192
table.push_str(
198193
"pub static ADDR: &str = include_str!(concat!(env!(\"OUT_DIR\"), \"/agent/addr.js\"));\n",

‎examples/message_check.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! cargo run --example message_check
99
1010
use std::process::{Child, Command};
11-
use std::sync::mpsc::{channel, Sender};
11+
use std::sync::mpsc::{Sender, channel};
1212
use std::time::Duration;
1313

1414
use frida::{DeviceManager, Frida, Message, ScriptHandler, ScriptOption};
@@ -18,7 +18,9 @@ struct Collector(Sender<String>);
1818
impl ScriptHandler for Collector {
1919
fn on_message(&mut self, message: Message, _data: Option<Vec<u8>>) {
2020
if let Message::Send(send) = message {
21-
let _ = self.0.send(format!("{} {}", send.payload.r#type, send.payload.result));
21+
let _ = self
22+
.0
23+
.send(format!("{} {}", send.payload.r#type, send.payload.result));
2224
}
2325
}
2426
}

‎src/agent.rs‎

Lines changed: 76 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,28 @@ type Module = (String, String);
3535
/// `core` and `bus` always load, since everything else depends on them.
3636
/// Bisecting a crash otherwise means an edit and a rebuild per attempt, and
3737
/// every attempt costs a game restart.
38-
pub fn bundle(dir: Option<&Path>, skip: &[String], only: &[String],
39-
ask: bool, no_hook: &[String], trace: bool) -> Result<String> {
38+
pub fn bundle(
39+
dir: Option<&Path>,
40+
skip: &[String],
41+
only: &[String],
42+
ask: bool,
43+
no_hook: &[String],
44+
trace: bool,
45+
) -> Result<String> {
4046
let (mut out, sources) = read(dir)?;
4147

4248
// Individual sites the agent must not attach to, read by core's hook().
4349
let names: Vec<String> = no_hook.iter().map(|n| format!("\"{n}\"")).collect();
44-
out.push_str(&format!("
50+
out.push_str(&format!(
51+
"
4552
var NO_HOOK = [{}];
46-
", names.join(", ")));
47-
out.push_str(&format!("var HOOK_TRACE = {trace};
48-
"));
53+
",
54+
names.join(", ")
55+
));
56+
out.push_str(&format!(
57+
"var HOOK_TRACE = {trace};
58+
"
59+
));
4960

5061
for (name, source) in sources {
5162
let module = module(&name);
@@ -67,10 +78,12 @@ var NO_HOOK = [{}];
6778
if !ask {
6879
// Separates "the hook is installed" from "the hook stops the game
6980
// thread waiting for a verdict". One game restart answers which.
70-
out.push_str("
81+
out.push_str(
82+
"
7183
// --no-ask
7284
askEnabled = false;
73-
");
85+
",
86+
);
7487
}
7588
Ok(out)
7689
}
@@ -127,7 +140,11 @@ fn read(dir: Option<&Path>) -> Result<(String, Vec<Module>)> {
127140

128141
let mut modules = Vec::with_capacity(paths.len());
129142
for path in paths {
130-
let name = path.file_name().unwrap_or_default().to_string_lossy().to_string();
143+
let name = path
144+
.file_name()
145+
.unwrap_or_default()
146+
.to_string_lossy()
147+
.to_string();
131148
modules.push((name, std::fs::read_to_string(&path)?));
132149
}
133150
Ok((addr, modules))
@@ -155,20 +172,36 @@ mod tests {
155172

156173
#[test]
157174
fn disabled_sites_reach_the_agent() {
158-
let bundle = super::bundle(Some(&agent_dir()), &[], &[], true,
159-
&["goldEpilogue".to_string()], false)
160-
.expect("bundles");
161-
assert!(bundle.contains("var NO_HOOK = [\"goldEpilogue\"];"),
162-
"the agent must be told which sites to leave alone");
163-
assert!(bundle.find("var NO_HOOK").unwrap()
164-
< bundle.find("function hook(").unwrap(),
165-
"NO_HOOK has to be declared before core reads it");
175+
let bundle = super::bundle(
176+
Some(&agent_dir()),
177+
&[],
178+
&[],
179+
true,
180+
&["goldEpilogue".to_string()],
181+
false,
182+
)
183+
.expect("bundles");
184+
assert!(
185+
bundle.contains("var NO_HOOK = [\"goldEpilogue\"];"),
186+
"the agent must be told which sites to leave alone"
187+
);
188+
assert!(
189+
bundle.find("var NO_HOOK").unwrap() < bundle.find("function hook(").unwrap(),
190+
"NO_HOOK has to be declared before core reads it"
191+
);
166192
}
167193

168194
#[test]
169195
fn only_keeps_the_runtime_modules() {
170-
let bundle = super::bundle(Some(&agent_dir()), &[], &["gold".to_string()],
171-
true, &[], false).expect("bundles");
196+
let bundle = super::bundle(
197+
Some(&agent_dir()),
198+
&[],
199+
&["gold".to_string()],
200+
true,
201+
&[],
202+
false,
203+
)
204+
.expect("bundles");
172205
assert!(bundle.contains("60-gold.js"));
173206
assert!(bundle.contains("10-core.js"), "core is not optional");
174207
assert!(!bundle.contains("50-health.js"));
@@ -183,9 +216,10 @@ mod tests {
183216
let bundle = super::bundle(None, &[], &[], true, &[], false).expect("bundles");
184217
assert!(bundle.contains("var RVA"), "the address table comes first");
185218
assert!(bundle.find("var RVA").unwrap() < bundle.find("var NO_HOOK").unwrap());
186-
assert!(bundle.find("var NO_HOOK").unwrap()
187-
< bundle.find("// ---- 10-core.js ----").unwrap(),
188-
"core reads NO_HOOK, so it is declared before core");
219+
assert!(
220+
bundle.find("var NO_HOOK").unwrap() < bundle.find("// ---- 10-core.js ----").unwrap(),
221+
"core reads NO_HOOK, so it is declared before core"
222+
);
189223
}
190224

191225
/// Minification is comments and layout, and nothing else. Whole lines of
@@ -196,7 +230,10 @@ mod tests {
196230
.iter()
197231
.flat_map(|(_, source)| source.lines())
198232
.any(|line| line.starts_with("//") || line.starts_with(" "));
199-
assert!(!commented, "the embedded modules keep comments or indentation");
233+
assert!(
234+
!commented,
235+
"the embedded modules keep comments or indentation"
236+
);
200237
}
201238

202239
/// Every module the real agent has is still a module, and the ones the
@@ -208,7 +245,10 @@ mod tests {
208245
.map(|(name, _)| super::module(name))
209246
.collect();
210247
for required in ["core", "bus", "names"] {
211-
assert!(names.contains(&required), "{required} is missing from the bundle");
248+
assert!(
249+
names.contains(&required),
250+
"{required} is missing from the bundle"
251+
);
212252
}
213253
}
214254

@@ -218,11 +258,19 @@ mod tests {
218258
let manifest = super::manifest(None).expect("manifest");
219259
let groups: serde_json::Value = serde_json::from_str(&manifest).expect("json");
220260
let groups = groups.as_array().expect("an array of groups");
221-
assert!(!groups.is_empty(), "no hook sites were read out of the agent");
261+
assert!(
262+
!groups.is_empty(),
263+
"no hook sites were read out of the agent"
264+
);
222265
assert!(groups.iter().any(|group| group["module"] == "core"));
223-
assert!(groups.iter().all(|group| {
224-
group["hooks"].as_array().is_some_and(|hooks| !hooks.is_empty())
225-
}), "a module with no sites has no row");
266+
assert!(
267+
groups.iter().all(|group| {
268+
group["hooks"]
269+
.as_array()
270+
.is_some_and(|hooks| !hooks.is_empty())
271+
}),
272+
"a module with no sites has no row"
273+
);
226274
}
227275

228276
/// The same list, read out of a folder: what `--agent` gets.

‎src/codec.rs‎

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ impl Frame {
7373
_ => {}
7474
}
7575
}
76-
Some(Frame { verb, seq, name, fields })
76+
Some(Frame {
77+
verb,
78+
seq,
79+
name,
80+
fields,
81+
})
7782
}
7883
}
7984

@@ -101,7 +106,9 @@ mod tests {
101106
#[test]
102107
fn round_trips_through_encode() {
103108
let mut frame = Frame::new("EVT", 9, "item.pickup");
104-
frame.fields.push(("name".into(), "Lesser Healing Potion".into()));
109+
frame
110+
.fields
111+
.push(("name".into(), "Lesser Healing Potion".into()));
105112
let back = Frame::decode(&frame.encode()).expect("parses");
106113
assert_eq!(back.name, "item.pickup");
107114
assert_eq!(back.field("name"), Some("Lesser Healing Potion"));
@@ -170,13 +177,20 @@ mod endtoend {
170177
/// boundary is another repository's build.
171178
fn jars() -> Option<(PathBuf, PathBuf)> {
172179
let newest = |dir: PathBuf, part: &str| -> Option<PathBuf> {
173-
std::fs::read_dir(dir).ok()?.flatten()
180+
std::fs::read_dir(dir)
181+
.ok()?
182+
.flatten()
174183
.map(|e| e.path())
175184
.filter(|p| {
176-
let name = p.file_name().unwrap_or_default()
177-
.to_string_lossy().to_string();
178-
name.starts_with(part) && name.ends_with(".jar")
179-
&& !name.contains("-sources") && !name.contains("-javadoc")
185+
let name = p
186+
.file_name()
187+
.unwrap_or_default()
188+
.to_string_lossy()
189+
.to_string();
190+
name.starts_with(part)
191+
&& name.ends_with(".jar")
192+
&& !name.contains("-sources")
193+
&& !name.contains("-javadoc")
180194
})
181195
// By when it was built, not by what it is called. As text
182196
// "zygote-0.99.0" sorts above "zygote-0.100.0", so a folder
@@ -185,11 +199,18 @@ mod endtoend {
185199
.max_by_key(|path| path.metadata().and_then(|m| m.modified()).ok())
186200
};
187201
let sibling = |part: &str| {
188-
newest(PathBuf::from("../coderpack").join(part).join("build/libs"), part)
202+
newest(
203+
PathBuf::from("../coderpack").join(part).join("build/libs"),
204+
part,
205+
)
189206
};
190207
let m2 = |part: &str| {
191-
let base = home()?.join(".m2/repository/dev/ancaria/coderpack").join(part);
192-
std::fs::read_dir(base).ok()?.flatten()
208+
let base = home()?
209+
.join(".m2/repository/dev/ancaria/coderpack")
210+
.join(part);
211+
std::fs::read_dir(base)
212+
.ok()?
213+
.flatten()
193214
.map(|e| e.path())
194215
.filter(|p| p.is_dir())
195216
.filter_map(|version| newest(version, part))
@@ -221,10 +242,12 @@ mod endtoend {
221242
// No name, and the decision in the fields. A verdict that parsed
222243
// as a *named* frame is how the fields used to get eaten.
223244
assert!(verdict.name.is_empty(), "END frames carry no name");
224-
assert!(verdict.field("ok").is_some()
225-
|| verdict.field("cancel").is_some()
226-
|| !verdict.rewrites().is_empty(),
227-
"ask {seq} came back with no decision in it");
245+
assert!(
246+
verdict.field("ok").is_some()
247+
|| verdict.field("cancel").is_some()
248+
|| !verdict.rewrites().is_empty(),
249+
"ask {seq} came back with no decision in it"
250+
);
228251
}
229252
}
230253

@@ -242,8 +265,12 @@ mod endtoend {
242265
};
243266
let classpath = format!("{};{}", api.display(), zygote.display());
244267
let mut zygote = Command::new("java")
245-
.args(["-cp", &classpath, "dev.ancaria.coderpack.zygote.Main",
246-
"--mods"])
268+
.args([
269+
"-cp",
270+
&classpath,
271+
"dev.ancaria.coderpack.zygote.Main",
272+
"--mods",
273+
])
247274
.arg("no-mods-here")
248275
.stdin(Stdio::piped())
249276
.stdout(Stdio::piped())
@@ -305,9 +332,7 @@ mod endtoend {
305332
// Ends on its own: BYE stops the JVM, that closes the pipe, and the
306333
// host's reader thread drops the sender on its way out.
307334
let mut collected = Vec::new();
308-
while let Ok(frame) =
309-
replies.recv_timeout(std::time::Duration::from_secs(30))
310-
{
335+
while let Ok(frame) = replies.recv_timeout(std::time::Duration::from_secs(30)) {
311336
collected.push(frame);
312337
}
313338
answered(&collected);

‎src/job.rs‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ mod imp {
1111

1212
use windows_sys::Win32::Foundation::HANDLE;
1313
use windows_sys::Win32::System::JobObjects::{
14-
AssignProcessToJobObject, CreateJobObjectW, SetInformationJobObject,
15-
JobObjectExtendedLimitInformation, JOBOBJECT_EXTENDED_LIMIT_INFORMATION,
16-
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE,
14+
AssignProcessToJobObject, CreateJobObjectW, JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE,
15+
JOBOBJECT_EXTENDED_LIMIT_INFORMATION, JobObjectExtendedLimitInformation,
16+
SetInformationJobObject,
1717
};
1818

1919
pub struct Job(HANDLE);
@@ -29,10 +29,8 @@ mod imp {
2929
if handle.is_null() {
3030
return None;
3131
}
32-
let mut info: JOBOBJECT_EXTENDED_LIMIT_INFORMATION =
33-
std::mem::zeroed();
34-
info.BasicLimitInformation.LimitFlags =
35-
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
32+
let mut info: JOBOBJECT_EXTENDED_LIMIT_INFORMATION = std::mem::zeroed();
33+
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
3634
let ok = SetInformationJobObject(
3735
handle,
3836
JobObjectExtendedLimitInformation,

0 commit comments

Comments
 (0)