neo_decompiler/nef/
types.rs1use crate::util;
2
3use super::encoding::{encoded_method_tokens_size, varint_encoded_len};
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7#[non_exhaustive]
8pub struct NefHeader {
9 pub magic: [u8; 4],
11 pub compiler: String,
13 pub source: String,
15}
16
17#[derive(Debug, Clone, PartialEq, Eq)]
19#[non_exhaustive]
20pub struct MethodToken {
21 pub hash: [u8; 20],
23 pub method: String,
25 pub parameters_count: u16,
27 pub has_return_value: bool,
29 pub call_flags: u8,
31}
32
33#[derive(Debug, Clone, PartialEq, Eq)]
35#[non_exhaustive]
36pub struct NefFile {
37 pub header: NefHeader,
39 pub method_tokens: Vec<MethodToken>,
41 pub script: Vec<u8>,
43 pub checksum: u32,
45}
46
47impl NefFile {
48 #[must_use]
50 pub fn payload_len(&self) -> usize {
51 let fixed_header_len = super::FIXED_HEADER_SIZE; let source_bytes = self.header.source.as_bytes();
53 let source_len = varint_encoded_len(source_bytes.len() as u32) + source_bytes.len();
54 let tokens_len = encoded_method_tokens_size(&self.method_tokens);
55 let script_len = varint_encoded_len(self.script.len() as u32) + self.script.len();
56
57 fixed_header_len + source_len + 1 + tokens_len + 2 + script_len
58 }
59
60 #[must_use]
62 pub fn script_hash(&self) -> [u8; 20] {
63 util::hash160(&self.script)
64 }
65
66 #[must_use]
68 #[deprecated(
69 since = "0.5.1",
70 note = "use `script_hash()` instead, which is identical"
71 )]
72 pub fn script_hash_le(&self) -> [u8; 20] {
73 self.script_hash()
74 }
75
76 #[must_use]
78 pub fn script_hash_be(&self) -> [u8; 20] {
79 let mut hash = self.script_hash();
80 hash.reverse();
81 hash
82 }
83}