Refactor help (winreg)


can someone check my code GitHub - SmuSmu/OpAgent: Agent Software

My Problem is the following. I need to know what kind of RegValue (string, int, ...) a regkey is in order to correctly get the value. Or better have a generic function which works with all correctly.

I am very new to Rust and typesafe programming. So I expect I should use a kind of match? Or how should I handle this kind of Problem.

Thanks for your hints

If you're talking about this code?

Your thevalue is a "stringified" representation of the registry value, so numbers will be written in decimal. If you actually want to get at the type, use a "raw value" instead.

use winreg::enums::RegType::*;
            match subkey.get_raw_value(regvalue) {
                Ok(raw_value) => {
                    match raw_value.vtype {
                        REG_NONE => println!("None"),
                        REG_SZ => println!("null-teminated string"),
                        REG_EXPAND_SZ => println!("null-teminated string with variables"),
                        REG_BINARY => println!("blob"),
                        REG_DWORD => println!("64-bit number"),
                        REG_DWORD_BIG_ENDIAN => println!("64-bit number"),
                        REG_LINK => println!("null-terminated path"),
                        REG_MULTI_SZ => println!("null-terminated, null-separated, list of strings"),
                        REG_RESOURCE_LIST => println!("list of resources"),
                        REG_FULL_RESOURCE_DESCRIPTOR => println!("resource"),
                        REG_RESOURCE_REQUIREMENTS_LIST => println!("dependencies"),
                        REG_QWORD => println!("128-bit number"),
                Err(_) => unimplemented!(),

Yeah that helped a lot. Now it looks even more crappy but hey it works. Tanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.