ProtectedInteger

Struct ProtectedInteger 

Source
pub struct ProtectedInteger<T> { /* private fields */ }
Expand description

The protected integer

use protected_integer::ProtectedInteger;
let mut my_number = ProtectedInteger::new(114514); // initialize this variable
println!("{}", my_number.get().to_value());

Implementations§

Source§

impl<T: Integer + Copy + BitXor<Output = T>> ProtectedInteger<T>

Source

pub fn new(value: T) -> ProtectedInteger<T>

Create a new protected integer A random value will be generated for the verification key

Examples found in repository?
examples/hacking_test.rs (line 4)
3fn main() {
4    let mut money:ProtectedInteger<i16> = ProtectedInteger::new(123);
5    println!("The initial amount of money is {}", money.get().to_value());
6    println!("Press Enter to increment it by 1");
7    println!("Try searching and modifying this value with Cheat Engine");
8    println!("Input 'quit' to exit");
9    loop {
10        let mut input = String::new();
11        std::io::stdin().read_line(&mut input).unwrap();
12        let input = input.trim();
13        if input == "quit" {
14            println!("Exiting...");
15            break;
16        }
17        if !money.check() {
18            println!("Hacking detected!");
19        }
20        money.set(money.get().to_value() + 1);        
21        println!("The money is now {}", money.get().to_value());
22    }
23}
Source

pub fn get(&self) -> State<T>

Get the value of the protected integer and check if it is tampered

Examples found in repository?
examples/hacking_test.rs (line 5)
3fn main() {
4    let mut money:ProtectedInteger<i16> = ProtectedInteger::new(123);
5    println!("The initial amount of money is {}", money.get().to_value());
6    println!("Press Enter to increment it by 1");
7    println!("Try searching and modifying this value with Cheat Engine");
8    println!("Input 'quit' to exit");
9    loop {
10        let mut input = String::new();
11        std::io::stdin().read_line(&mut input).unwrap();
12        let input = input.trim();
13        if input == "quit" {
14            println!("Exiting...");
15            break;
16        }
17        if !money.check() {
18            println!("Hacking detected!");
19        }
20        money.set(money.get().to_value() + 1);        
21        println!("The money is now {}", money.get().to_value());
22    }
23}
Source

pub fn set(&mut self, value: T)

Set the value of the protected integer, and update the verification key

Examples found in repository?
examples/hacking_test.rs (line 20)
3fn main() {
4    let mut money:ProtectedInteger<i16> = ProtectedInteger::new(123);
5    println!("The initial amount of money is {}", money.get().to_value());
6    println!("Press Enter to increment it by 1");
7    println!("Try searching and modifying this value with Cheat Engine");
8    println!("Input 'quit' to exit");
9    loop {
10        let mut input = String::new();
11        std::io::stdin().read_line(&mut input).unwrap();
12        let input = input.trim();
13        if input == "quit" {
14            println!("Exiting...");
15            break;
16        }
17        if !money.check() {
18            println!("Hacking detected!");
19        }
20        money.set(money.get().to_value() + 1);        
21        println!("The money is now {}", money.get().to_value());
22    }
23}
Source

pub fn check(&self) -> bool

Check if the value is not tampered

Examples found in repository?
examples/hacking_test.rs (line 17)
3fn main() {
4    let mut money:ProtectedInteger<i16> = ProtectedInteger::new(123);
5    println!("The initial amount of money is {}", money.get().to_value());
6    println!("Press Enter to increment it by 1");
7    println!("Try searching and modifying this value with Cheat Engine");
8    println!("Input 'quit' to exit");
9    loop {
10        let mut input = String::new();
11        std::io::stdin().read_line(&mut input).unwrap();
12        let input = input.trim();
13        if input == "quit" {
14            println!("Exiting...");
15            break;
16        }
17        if !money.check() {
18            println!("Hacking detected!");
19        }
20        money.set(money.get().to_value() + 1);        
21        println!("The money is now {}", money.get().to_value());
22    }
23}

Auto Trait Implementations§

§

impl<T> Freeze for ProtectedInteger<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ProtectedInteger<T>
where T: RefUnwindSafe,

§

impl<T> Send for ProtectedInteger<T>
where T: Send,

§

impl<T> Sync for ProtectedInteger<T>
where T: Sync,

§

impl<T> Unpin for ProtectedInteger<T>
where T: Unpin,

§

impl<T> UnwindSafe for ProtectedInteger<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V