libscemu/emu/winapi32/
crypt32.rs

1use crate::emu;
2use crate::emu::winapi32::kernel32;
3/*
4use crate::emu::winapi32::helper;
5use crate::emu::context32;
6use crate::emu::constants;
7use crate::emu::console;
8*/
9
10pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String {
11    let api = kernel32::guess_api_name(emu, addr);
12    match api.as_str() {
13        "PkiInitializeCriticalSection" => PkiInitializeCriticalSection(emu),
14        "CryptStringToBinaryA" => CryptStringToBinaryA(emu),
15
16        _ => {
17            log::info!(
18                "calling unimplemented crypt32 API 0x{:x} {}",
19                addr, api
20            );
21            return api;
22        }
23    }
24
25    return String::new();
26}
27
28fn PkiInitializeCriticalSection(emu: &mut emu::Emu) {
29    let addr = emu
30        .maps
31        .read_dword(emu.regs.get_esp())
32        .expect("crypt32!PkiInitializeCriticalSection error getting flags param");
33    let flags = emu
34        .maps
35        .read_dword(emu.regs.get_esp() + 4)
36        .expect("crypt32!PkiInitializeCriticalSection error getting addr param");
37
38    log::info!(
39        "{}** {} crypt32!Pki_InitializeCriticalSection flags: {:x} addr: 0x{:x} {}",
40        emu.colors.light_red, emu.pos, flags, addr, emu.colors.nc
41    );
42
43    for _ in 0..2 {
44        emu.stack_pop32(false);
45    }
46    emu.regs.rax = 1;
47}
48
49fn CryptStringToBinaryA(emu: &mut emu::Emu) {
50    let string = emu
51        .maps
52        .read_dword(emu.regs.get_esp())
53        .expect("crypt32!CryptStringToBinaryA error getting flags param");
54    let num_chars = emu
55        .maps
56        .read_dword(emu.regs.get_esp() + 4)
57        .expect("crypt32!PCryptStringToBinaryA error getting addr param");
58    let flags = emu
59        .maps
60        .read_dword(emu.regs.get_esp() + 8)
61        .expect("crypt32!CryptStringToBinaryA error getting flags param");
62    let ptr = emu
63        .maps
64        .read_dword(emu.regs.get_esp() + 12)
65        .expect("crypt32!PCryptStringToBinaryA error getting addr param");
66    let inout_sz = emu
67        .maps
68        .read_dword(emu.regs.get_esp() + 16)
69        .expect("crypt32!CryptStringToBinaryA error getting flags param");
70    let skip = emu
71        .maps
72        .read_dword(emu.regs.get_esp() + 20)
73        .expect("crypt32!PCryptStringToBinaryA error getting addr param");
74    let out_flags = emu
75        .maps
76        .read_dword(emu.regs.get_esp() + 24)
77        .expect("crypt32!CryptStringToBinaryA error getting flags param");
78
79    let dflags = match flags {
80        0x00000000 => "CRYPT_STRING_BASE64HEADER",
81        0x00000001 => "CRYPT_STRING_BASE64",
82        0x00000002 => "CRYPT_STRING_BINARY",
83        0x00000003 => "CRYPT_STRING_BASE64REQUESTHEADER",
84        0x00000004 => "CRYPT_STRING_HEX",
85        0x00000005 => "CRYPT_STRING_HEXASCII",
86        0x00000006 => "CRYPT_STRING_BASE64_ANY",
87        0x00000007 => "CRYPT_STRING_ANY",
88        0x00000008 => "CRYPT_STRING_HEX_ANY",
89        0x00000009 => "CRYPT_STRING_BASE64X509CRLHEADER",
90        0x0000000a => "CRYPT_STRING_HEXADDR",
91        0x0000000b => "CRYPT_STRING_HEXASCIIADDR",
92        0x0000000c => "CRYPT_STRING_HEXRAW",
93        0x20000000 => "CRYPT_STRING_STRICT",
94        _ => "incorrect flag",
95    };
96
97    log::info!(
98        "{}** {} crypt32!CryptStringToBinaryA str: 0x{:x} len: {} ptr: {} len: {} {}{}",
99        emu.colors.light_red, emu.pos, string, num_chars, ptr, inout_sz, dflags, emu.colors.nc
100    );
101
102    for _ in 0..7 {
103        emu.stack_pop32(false);
104    }
105    emu.regs.rax = 1;
106}