use crate::nativepointer::NativePointer;
use crate::plumbing;
use crate::range::RangeDetails;
use wasm_bindgen::{JsCast, JsValue};
pub fn get_base_address(name: &str) -> Option<NativePointer> {
let ret = plumbing::module::get_base_address(name);
if ret.is_null() {
return None;
}
Some(ret)
}
pub fn get_export(export_name: &str) -> Option<NativePointer> {
let ret = plumbing::module::get_export(JsValue::NULL, export_name);
if ret.is_null() {
return None;
}
Some(ret)
}
pub struct Module {
pub name: String,
pub base: NativePointer,
pub size: usize,
pub path: String,
_ref: plumbing::module::Module,
}
impl From<plumbing::module::Module> for Module {
fn from(m: plumbing::module::Module) -> Self {
Module {
name: m.name(),
base: m.base(),
size: m.size(),
path: m.path(),
_ref: m,
}
}
}
impl Module {
pub fn enumerate_exports(&self) -> Vec<ExportDetails> {
let mut export_details = Vec::new();
let m: plumbing::module::Module = self._ref.clone().unchecked_into();
let exports = m.enumerate_exports();
for export in exports.iter() {
let i = ExportDetails::from(plumbing::module::ExportDetails::from(export));
export_details.push(i);
}
export_details
}
pub fn enumerate_imports(&self) -> Vec<ImportDetails> {
let mut import_details = Vec::new();
let m: plumbing::module::Module = self._ref.clone().unchecked_into();
let imports = m.enumerate_imports();
for import in imports.iter() {
let i = ImportDetails::from(plumbing::module::ImportDetails::from(import));
import_details.push(i);
}
import_details
}
pub fn enumerate_symbols(&self) -> Vec<SymbolDetails> {
let mut symbol_details = Vec::new();
let m: plumbing::module::Module = self._ref.clone().unchecked_into();
let symbols = m.enumerate_symbols();
for symbol in symbols.iter() {
let i = SymbolDetails::from(plumbing::module::SymbolDetails::from(symbol));
symbol_details.push(i);
}
symbol_details
}
pub fn enumerate_ranges(&self, protection: &str) -> Vec<RangeDetails> {
let mut range_details = Vec::new();
let m: plumbing::module::Module = self._ref.clone().unchecked_into();
let ranges = m.enumerate_ranges(protection);
for range in ranges.iter() {
let i = RangeDetails::from(plumbing::range::RangeDetails::from(range));
range_details.push(i);
}
range_details
}
}
pub struct ExportDetails {
pub export_type: String, pub name: String,
pub address: NativePointer,
}
impl From<plumbing::module::ExportDetails> for ExportDetails {
fn from(m: plumbing::module::ExportDetails) -> Self {
ExportDetails {
export_type: m.export_type(),
name: m.name(),
address: m.address(),
}
}
}
pub struct ImportDetails {
pub import_type: Option<String>, pub name: String,
pub module: Option<String>,
pub address: Option<NativePointer>,
pub slot: Option<NativePointer>,
}
impl From<plumbing::module::ImportDetails> for ImportDetails {
fn from(m: plumbing::module::ImportDetails) -> Self {
ImportDetails {
import_type: m.import_type(),
name: m.name(),
module: m.module(),
address: m.address(),
slot: m.slot(),
}
}
}
pub struct SymbolDetails {
pub is_global: bool,
pub symbol_type: String, pub section: Option<SymbolSectionDetails>,
pub name: String,
pub address: NativePointer,
pub size: Option<usize>,
}
impl From<plumbing::module::SymbolDetails> for SymbolDetails {
fn from(m: plumbing::module::SymbolDetails) -> Self {
SymbolDetails {
is_global: m.is_global(),
symbol_type: m.symbol_type(),
section: m.section().map(|s| SymbolSectionDetails::from(s)),
name: m.name(),
address: m.address(),
size: m.size(),
}
}
}
pub struct SymbolSectionDetails {
pub id: String,
pub protection: String,
}
impl From<plumbing::module::SymbolSectionDetails> for SymbolSectionDetails {
fn from(m: plumbing::module::SymbolSectionDetails) -> Self {
SymbolSectionDetails {
id: m.id(),
protection: m.protection(),
}
}
}