myph-v2.git


myph-v2

~ rust shellcode loader with evasive capabilities
git clone https://github.com/djnnvx/myph-v2.git
log | files | refs | archive | README

helpers.rs (1292B)

      1 /// Format bytes as a hex array string
      2 pub fn format_bytes_as_hex(bytes: &[u8]) -> String {
      3     format!(
      4         "[{}]",
      5         bytes
      6             .iter()
      7             .map(|b| format!("0x{:02x}", b))
      8             .collect::<Vec<_>>()
      9             .join(", ")
     10     )
     11 }
     12 
     13 /// Convert snake_case to UpperCamelCase
     14 pub fn to_upper_camel_case(s: &str) -> String {
     15     s.split('_')
     16         .map(|word| {
     17             let mut chars = word.chars();
     18             match chars.next() {
     19                 None => String::new(),
     20                 Some(first) => first.to_uppercase().chain(chars).collect(),
     21             }
     22         })
     23         .collect::<String>()
     24         + "Fn"
     25 }
     26 
     27 #[cfg(test)]
     28 mod tests {
     29     use super::*;
     30 
     31     #[test]
     32     fn test_format_bytes_as_hex() {
     33         let bytes = [0x41, 0x42, 0x43];
     34         let result = format_bytes_as_hex(&bytes);
     35         assert_eq!(result, "[0x41, 0x42, 0x43]");
     36     }
     37 
     38     #[test]
     39     fn test_to_upper_camel_case() {
     40         assert_eq!(to_upper_camel_case("virtual_alloc"), "VirtualAllocFn");
     41         assert_eq!(
     42             to_upper_camel_case("create_remote_thread"),
     43             "CreateRemoteThreadFn"
     44         );
     45         assert_eq!(to_upper_camel_case("rtl_copy_memory"), "RtlCopyMemoryFn");
     46         assert_eq!(to_upper_camel_case("simple"), "SimpleFn");
     47     }
     48 }