Skip to content

Instantly share code, notes, and snippets.

View JohnScience's full-sized avatar

Dmitrii - Demenev JohnScience

View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;

Examples of using cargo test

cargo test - run all tests, which are not ignored. Their stdout is not shown/printed.

cargo test --help - see the documentation of cargo test. Note that it does not display the [test options].

cargo test top_level_mod::tests::test_fn_name -- --exact - run a single test [^1]. The --exact argument ensures that similar test names won't be executed [^2]. Note that the path does not include the crate name.

Also see

@JohnScience
JohnScience / direct_test.rs
Last active August 3, 2024 07:12
An example of a test that behaves differently depending on whether it is called directly or indirectly.
// I work in VS Code. It has a Run Test button above every test.
// I have a test that renders an HTML page with Handlebars.
// I'd like to open the page in the browser if the test is called directly.
// If the test is called indirectly (but rather as a result of `cargo test`), I don't want the test to open the browser.
// The code below demonstrates how it can be achieved.
#[cfg(test)]
mod tests {
#[test]
fn direct_test() {
@JohnScience
JohnScience / reflective_pe_loader.rs
Created April 4, 2024 06:33
An implementation of a reflective PE loader with a bit of hardcode for an example dll. It is meant to be librarified soon
use core::panic;
use core::ptr;
use goblin::pe::data_directories::DataDirectory;
use goblin::pe::section_table::{IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE};
use goblin::pe::PE;
use winapi::ctypes::c_void;
use winapi::shared::minwindef::HINSTANCE;
use winapi::um::memoryapi::VirtualAlloc;
use winapi::um::winnt::{
DLL_THREAD_ATTACH, MEM_COMMIT, MEM_RESERVE, PAGE_EXECUTE, PAGE_EXECUTE_READ,
pub struct VSRegKey(registry::RegKey);
impl VSRegKey {
pub fn open() -> Result<Self, registry::key::Error> {
let regkey = registry::Hive::LocalMachine.open(
r"SOFTWARE\WOW6432Node\Microsoft\VisualStudio",
registry::Security::Read,
)?;
Ok(Self(regkey))
}
@JohnScience
JohnScience / gist:12a28cb57c0c6e791ba3741dceeef584
Created August 26, 2023 08:17
My setup for Rust development (Chrome OS)
sudo apt update
# install essential build tools, notably cc linker
sudo apt install build-essential -y
# install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# configure the current shell, suggested by the installation script
source "$HOME/.cargo/env"
# install dependencies
sudo apt install software-properties-common apt-transport-https wget -y
# Import the GPG key provided by Microsoft to verify the package integrity.