From 2fcacc55d5466a7d17bdc0b3ce988772aa6d0653 Mon Sep 17 00:00:00 2001 From: KyleMiles Date: Thu, 21 Jan 2021 18:35:20 +0000 Subject: cargo fmt and all my changes --- rust/src/platform.rs | 89 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 24 deletions(-) (limited to 'rust/src/platform.rs') diff --git a/rust/src/platform.rs b/rust/src/platform.rs index 3343bece..0e0b98b9 100644 --- a/rust/src/platform.rs +++ b/rust/src/platform.rs @@ -1,12 +1,26 @@ +// Copyright 2021 Vector 35 Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use std::borrow::Borrow; use binaryninjacore_sys::*; use crate::architecture::{Architecture, CoreArchitecture}; use crate::callingconvention::CallingConvention; -use crate::types::QualifiedNameAndType; use crate::rc::*; use crate::string::*; +use crate::types::QualifiedNameAndType; #[derive(PartialEq, Eq, Hash)] pub struct Platform { @@ -35,13 +49,16 @@ macro_rules! cc_func { pub fn $set_name(&self, cc: &CallingConvention) { let arch = self.arch(); - assert!(cc.arch_handle.borrow().as_ref().0 == arch.0, "use of calling convention with non-matching Platform architecture!"); + assert!( + cc.arch_handle.borrow().as_ref().0 == arch.0, + "use of calling convention with non-matching Platform architecture!" + ); unsafe { $set_api(self.handle, cc.handle); } } - } + }; } impl Platform { @@ -93,20 +110,26 @@ impl Platform { } } - pub fn list_by_os_and_arch(name: S, arch: &CoreArchitecture) -> Array { + pub fn list_by_os_and_arch( + name: S, + arch: &CoreArchitecture, + ) -> Array { let raw_name = name.as_bytes_with_nul(); unsafe { let mut count = 0; - let handles = BNGetPlatformListByOSAndArchitecture(raw_name.as_ref().as_ptr() as *mut _, - arch.0, &mut count); + let handles = BNGetPlatformListByOSAndArchitecture( + raw_name.as_ref().as_ptr() as *mut _, + arch.0, + &mut count, + ); Array::new(handles, count, ()) } } pub fn list_available_os() -> Array { - unsafe { + unsafe { let mut count = 0; let list = BNGetPlatformOSList(&mut count); @@ -133,9 +156,7 @@ impl Platform { } pub fn arch(&self) -> CoreArchitecture { - unsafe { - CoreArchitecture::from_raw(BNGetPlatformArchitecture(self.handle)) - } + unsafe { CoreArchitecture::from_raw(BNGetPlatformArchitecture(self.handle)) } } pub fn register_os(&self, os: S) { @@ -146,20 +167,40 @@ impl Platform { } } - cc_func!(get_default_calling_convention, BNGetPlatformDefaultCallingConvention, - set_default_calling_convention, BNRegisterPlatformDefaultCallingConvention); - - cc_func!(get_cdecl_calling_convention, BNGetPlatformCdeclCallingConvention, - set_cdecl_calling_convention, BNRegisterPlatformCdeclCallingConvention); - - cc_func!(get_stdcall_calling_convention, BNGetPlatformStdcallCallingConvention, - set_stdcall_calling_convention, BNRegisterPlatformStdcallCallingConvention); - - cc_func!(get_fastcall_calling_convention, BNGetPlatformFastcallCallingConvention, - set_fastcall_calling_convention, BNRegisterPlatformFastcallCallingConvention); - - cc_func!(get_syscall_convention, BNGetPlatformSystemCallConvention, - set_syscall_convention, BNSetPlatformSystemCallConvention); + cc_func!( + get_default_calling_convention, + BNGetPlatformDefaultCallingConvention, + set_default_calling_convention, + BNRegisterPlatformDefaultCallingConvention + ); + + cc_func!( + get_cdecl_calling_convention, + BNGetPlatformCdeclCallingConvention, + set_cdecl_calling_convention, + BNRegisterPlatformCdeclCallingConvention + ); + + cc_func!( + get_stdcall_calling_convention, + BNGetPlatformStdcallCallingConvention, + set_stdcall_calling_convention, + BNRegisterPlatformStdcallCallingConvention + ); + + cc_func!( + get_fastcall_calling_convention, + BNGetPlatformFastcallCallingConvention, + set_fastcall_calling_convention, + BNRegisterPlatformFastcallCallingConvention + ); + + cc_func!( + get_syscall_convention, + BNGetPlatformSystemCallConvention, + set_syscall_convention, + BNSetPlatformSystemCallConvention + ); pub fn types(&self) -> Array { unsafe { -- cgit v1.3.1