Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 
Cleanup implants lib and refactor dependencies (#215)
  • Loading branch information
hulto authored Jun 22, 2023
1 parent 860f4a4 commit a5d5202
Show file tree
Hide file tree
Showing 68 changed files with 158 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/target/
tests/create_file_dll/target/
tests/create_file_dll/Cargo.lock
cmd/implants/eldritch/target/
cmd/implants/lib/eldritch/target/
cmd/implants/target/
cmd/implants/Cargo.lock

Expand Down
4 changes: 2 additions & 2 deletions docs/_docs/dev-guide/eldritch.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The <b>module.function</b> describe your function and edge cases.

```
#### Eldritch definition
`implants/Eldritch/src/module.rs`
`implants/lib/eldritch/src/module.rs`
Add a function definition here, where `module.rs` is the name of the module you selected above. This is how the Eldritch language is made aware that your function exists.

Add the import for your functions implementation at the top, try to keep these in alphabetical order for readability.
Expand All @@ -76,7 +76,7 @@ You may notice that some functions follow the pattern:
This pattern is only used for none type returns since we're returning Starlark None. Returning like this in the module file is more streamlined than having each module return a special starlark type.

### Eldritch Implementation
`implants/Eldritch/src/module/function_impl.rs`
`implants/lib/eldritch/src/module/function_impl.rs`
Add your function implementation here, where `/module/` is the name of the module you selected above and `/function_impl.rs` is the name of your function with `_impl.rs` appended after it. This should match what's been put in the module file.
This file will contain the actual implementation, helper functions, and unit tests for your function.

Expand Down
49 changes: 47 additions & 2 deletions implants/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,56 @@
[workspace]
members = [
"imix",
"eldritch",
"golem",
"pkg/tavern",
"lib/eldritch",
"lib/tavern",
]

[workspace.dependencies]
allocative = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" }
allocative_derive = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" }
anyhow = "1.0.65"
assert_cmd = "2.0.6"
async-recursion = "1.0.0"
async-trait = "0.1.68"
chrono = "0.4.24"
clap = "3.2.23"
default-net = "0.13.1"
derive_more = "0.99.17"
eldritch = { path = "./lib/eldritch" }
eval = "0.4.3"
flate2 = "1.0.24"
gazebo = "0.8.1"
graphql_client = "0.12.0"
httptest = "0.15.4"
itertools = "0.10"
lsp-types = "0.93.0"
nix = "0.26.1"
openssl = "0.10"
predicates = "2.1"
rand = "0.8.5"
regex = "1.5.5"
reqwest = "0.11.4"
rust-embed = "6.6.0"
serde = "1.0"
serde_json = "1.0.87"
sha256 = "1.0.3"
starlark = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" }
structopt = "0.3.23"
sys-info = "0.9.1"
sysinfo = "0.28.4"
tar = "0.4.38"
tavern = { path = "./lib/tavern" }
tempfile = "3.3.0"
tera = "1.17.1"
thiserror = "1.0.30"
tokio = "1.19.1"
tokio-stream = "0.1.9"
tokio-test = "*"
uuid = "1.3.0"
whoami = "1.3.0"
windows-sys = "0.45.0"

[profile.release]
strip = true # Automatically strip symbols from the binary.
opt-level = "z" # Optimize for size.
Expand Down
40 changes: 0 additions & 40 deletions implants/eldritch/Cargo.toml

This file was deleted.

2 changes: 0 additions & 2 deletions implants/eldritch/rust-toolchain

This file was deleted.

32 changes: 16 additions & 16 deletions implants/golem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ version = "0.1.0"
edition = "2021"

[dependencies]
eldritch = { path = "../eldritch" }
tokio = { version = "1.19.1" , features = ["macros"] }
clap = { version = "3.2.23" }
starlark = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" }
anyhow = "1.0.65"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.87"
structopt = "0.3.23"
gazebo = "0.8.1"
itertools = "0.10"
thiserror = "1.0.30"
lsp-types = "0.93.0"
rust-embed = { version = "6.6.0" }
eldritch = { workspace = true }
tokio = { workspace = true, features = ["macros"] }
clap = { workspace = true }
starlark = { workspace = true }
anyhow = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
structopt = { workspace = true }
gazebo = { workspace = true }
itertools = { workspace = true }
thiserror = { workspace = true }
lsp-types = { workspace = true }
rust-embed = { workspace = true }

[dev-dependencies]
assert_cmd = "2.0.6"
predicates = "2.1"
tempfile = "3.3.0"
assert_cmd = { workspace = true }
predicates = { workspace = true}
tempfile = { workspace = true }
2 changes: 0 additions & 2 deletions implants/golem/rust-toolchain

This file was deleted.

34 changes: 17 additions & 17 deletions implants/imix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ version = "0.1.0"
edition = "2021"

[dependencies]
eldritch = { path = "../eldritch" }
clap = { version = "3.0" }
rand = "0.8.5"
openssl = { version = "0.10", features = ["vendored"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.11.4" , features = ["blocking", "stream", "json"] }
tokio = { version = "1", features = ["full"] }
anyhow = "1.0.65"
chrono = { version = "0.4.23" , features = ["serde"] }
whoami = "1.3.0"
uuid = { version = "1.3.0", features = ["v4","fast-rng"] }
default-net = "0.13.1"
sys-info = "0.9.1"
tavern = { path = "../pkg/tavern" }
anyhow = { workspace = true }
chrono = { workspace = true , features = ["serde"] }
clap = { workspace = true }
default-net = { workspace = true }
eldritch = { workspace = true }
openssl = { workspace = true, features = ["vendored"] }
rand = {workspace = true}
reqwest = { workspace = true, features = ["blocking", "stream", "json"] }
serde = { workspace = true, features = ["derive"] }
serde_json = {workspace = true}
sys-info = { workspace = true }
tavern = { workspace = true }
tokio = { workspace = true, features = ["full"] }
uuid = { workspace = true, features = ["v4","fast-rng"] }
whoami = { workspace = true }

[dev-dependencies]
httptest = "0.15.4"
tempfile = "3.3.0"
httptest = { workspace = true }
tempfile = { workspace = true }
2 changes: 0 additions & 2 deletions implants/imix/rust-toolchain

This file was deleted.

3 changes: 3 additions & 0 deletions implants/lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Overview

Code shared by multiple implants can be defined in the `lib` folder.
File renamed without changes.
39 changes: 39 additions & 0 deletions implants/lib/eldritch/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "eldritch"
version = "0.1.0"
edition = "2021"

[dependencies]
allocative = { workspace = true }
allocative_derive = { workspace = true }
anyhow = { workspace = true }
async-recursion = { workspace = true }
derive_more = { workspace = true }
eval = { workspace = true }
flate2 = { workspace = true }
gazebo = { workspace = true }
nix = { workspace = true }
regex = { workspace = true }
reqwest = { workspace = true , features = ["blocking", "stream"] }
rust-embed = { workspace = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = { workspace = true }
sha256 = { workspace = true }
starlark = { workspace = true }
sysinfo = { workspace = true }
tar = { workspace = true }
tempfile = { workspace = true }
tera = { workspace = true }
tokio = { workspace = true , features = ["macros", "rt-multi-thread"] }
tokio-stream = { workspace = true }
windows-sys = { workspace = true, features = [
"Win32_Foundation",
"Win32_System_LibraryLoader",
"Win32_System_Threading",
"Win32_System_Memory",
"Win32_System_Diagnostics_Debug",
"Win32_Security",
]}

[dev-dependencies]
httptest = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Build
```
cd ./implants/eldritch/
cd ./implants/lib/eldritch/
cargo build
```
# Test
```
cd ./implants/eldritch/
cd ./implants/lib/eldritch/
cargo test
```
4 changes: 2 additions & 2 deletions implants/eldritch/build.rs → implants/lib/eldritch/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn build_tests_create_file_dll(){

// Get the path of the create_file_dll workspace member
let cargo_root = env!("CARGO_MANIFEST_DIR");
let relative_path_to_test_dll = "..\\..\\tests\\create_file_dll\\";
let relative_path_to_test_dll = "..\\..\\..\\tests\\create_file_dll\\";
let test_dll_path = Path::new(cargo_root).join(relative_path_to_test_dll);
assert!(test_dll_path.is_dir());

Expand All @@ -25,7 +25,7 @@ fn build_tests_create_file_dll(){
.filter_map(|line| line.ok())
.for_each(|line| println!("cargo dll build: {}", line));

let relative_path_to_test_dll_file = "..\\..\\tests\\create_file_dll\\target\\debug\\create_file_dll.dll";
let relative_path_to_test_dll_file = "..\\..\\..\\tests\\create_file_dll\\target\\debug\\create_file_dll.dll";
let test_dll_path = Path::new(cargo_root).join(relative_path_to_test_dll_file);
assert!(test_dll_path.is_file());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ use rust_embed::RustEmbed;

#[cfg(debug_assertions)]
#[derive(RustEmbed)]
#[folder = "../../tests/embedded_files_test"]
#[folder = "../../../tests/embedded_files_test"]
pub struct Asset;

#[cfg(not(debug_assertions))]
#[derive(RustEmbed)]
#[folder = "../../implants/golem/embed_files_golem_prod"]
#[folder = "../../../implants/golem/embed_files_golem_prod"]
pub struct Asset;


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ mod tests {

// Get the path to our test dll file.
let cargo_root = env!("CARGO_MANIFEST_DIR");
let relative_path_to_test_dll = "..\\..\\tests\\create_file_dll\\target\\debug\\create_file_dll.dll";
let relative_path_to_test_dll = "..\\..\\..\\tests\\create_file_dll\\target\\debug\\create_file_dll.dll";
let test_dll_path = Path::new(cargo_root).join(relative_path_to_test_dll);
assert!(test_dll_path.is_file());

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions implants/lib/tavern/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "tavern"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["http"]
http = ["dep:reqwest"]

[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
chrono = { workspace = true, features = ["serde"] }
graphql_client = { workspace = true }
reqwest = { workspace = true, optional = true, features = ["blocking", "stream", "json"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["full"] }

[dev-dependencies]
httptest = { workspace = true }
tokio-test = { workspace = true }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions implants/pkg/README.md

This file was deleted.

24 changes: 0 additions & 24 deletions implants/pkg/tavern/Cargo.toml

This file was deleted.

4 changes: 2 additions & 2 deletions tavern/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ package main
//go:generate /bin/sh -c "cd ./graphql && go run -mod=mod github.com/99designs/gqlgen"

//go:generate /bin/sh -c "cat ./graphql/schema/* > ./graphql/schema.graphql"
//go:generate /bin/sh -c "cp ./graphql/schema.graphql ../implants/pkg/tavern/graphql/schema.graphql"
//go:generate /bin/sh -c "cd ../implants/pkg/tavern && ./codegen.sh"
//go:generate /bin/sh -c "cp ./graphql/schema.graphql ../implants/lib/tavern/graphql/schema.graphql"
//go:generate /bin/sh -c "cd ../implants/lib/tavern && ./codegen.sh"

0 comments on commit a5d5202

Please sign in to comment.