-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
379 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#[repr(C)] | ||
#[derive(Default)] | ||
pub struct METADATA_HEADER { | ||
pub signature: u32, | ||
pub major_version: u16, | ||
pub minor_version: u16, | ||
pub reserved: u32, | ||
pub length: u32, | ||
pub version: [u8; 20], | ||
pub flags: u16, | ||
pub streams: u16, | ||
} | ||
|
||
pub const METADATA_SIGNATURE: u32 = 0x424A_5342; | ||
|
||
extern "C" { | ||
pub fn strlen(cs: *const u8) -> usize; | ||
} | ||
|
||
pub fn composite_index_size(tables: &[usize]) -> usize { | ||
fn small(row_count: usize, bits: u8) -> bool { | ||
(row_count as u64) < (1u64 << (16 - bits)) | ||
} | ||
|
||
fn bits_needed(value: usize) -> u8 { | ||
let mut value = value - 1; | ||
let mut bits: u8 = 1; | ||
loop { | ||
value >>= 1; | ||
if value == 0 { | ||
break; | ||
} | ||
bits += 1; | ||
} | ||
bits | ||
} | ||
|
||
let bits_needed = bits_needed(tables.len()); | ||
|
||
if tables.iter().all(|table| small(*table, bits_needed)) { | ||
2 | ||
} else { | ||
4 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,13 @@ | ||
#![allow(dead_code)] | ||
|
||
use std::collections::*; | ||
mod flags; | ||
mod imp; | ||
pub mod reader; | ||
pub mod writer; | ||
|
||
pub use flags::*; | ||
use imp::*; | ||
use std::io::*; | ||
use std::mem::*; | ||
use std::ptr::*; | ||
|
||
#[repr(C)] | ||
#[derive(Default)] | ||
struct METADATA_HEADER { | ||
signature: u32, | ||
major_version: u16, | ||
minor_version: u16, | ||
reserved: u32, | ||
length: u32, | ||
version: [u8; 20], | ||
flags: u16, | ||
streams: u16, | ||
} | ||
|
||
const METADATA_SIGNATURE: u32 = 0x424A_5342; | ||
|
||
extern "C" { | ||
fn strlen(cs: *const u8) -> usize; | ||
} | ||
|
||
fn composite_index_size(tables: &[usize]) -> usize { | ||
fn small(row_count: usize, bits: u8) -> bool { | ||
(row_count as u64) < (1u64 << (16 - bits)) | ||
} | ||
|
||
fn bits_needed(value: usize) -> u8 { | ||
let mut value = value - 1; | ||
let mut bits: u8 = 1; | ||
loop { | ||
value >>= 1; | ||
if value == 0 { | ||
break; | ||
} | ||
bits += 1; | ||
} | ||
bits | ||
} | ||
|
||
let bits_needed = bits_needed(tables.len()); | ||
|
||
if tables.iter().all(|table| small(*table, bits_needed)) { | ||
2 | ||
} else { | ||
4 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#[derive(Clone, Copy)] | ||
pub enum ResolutionScope { | ||
None, | ||
Module(usize), | ||
ModuleRef(usize), | ||
AssemblyRef(usize), | ||
TypeRef(usize), | ||
} | ||
|
||
impl ResolutionScope { | ||
pub fn encode(&self) -> usize { | ||
match self { | ||
Self::Module(row) => ((row + 1) << 2), | ||
Self::ModuleRef(row) => ((row + 1) << 2) + 1, | ||
Self::AssemblyRef(row) => ((row + 1) << 2) + 2, | ||
Self::TypeRef(row) => ((row + 1) << 2) + 3, | ||
_ => unimplemented!(), | ||
} | ||
} | ||
} | ||
|
||
impl Default for ResolutionScope { | ||
fn default() -> Self { | ||
Self::None | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy)] | ||
pub enum TypeDefOrRef { | ||
None, | ||
TypeDef(usize), | ||
TypeRef(usize), | ||
TypeSpec(usize), | ||
} | ||
|
||
impl TypeDefOrRef { | ||
pub fn encode(&self) -> usize { | ||
match self { | ||
Self::TypeDef(row) => ((row + 1) << 2), | ||
Self::TypeRef(row) => ((row + 1) << 2) + 1, | ||
Self::TypeSpec(row) => ((row + 1) << 2) + 2, | ||
_ => 0, | ||
} | ||
} | ||
} | ||
|
||
impl Default for TypeDefOrRef { | ||
fn default() -> Self { | ||
Self::None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,17 @@ | ||
mod blobs; | ||
mod codes; | ||
mod gen; | ||
mod helpers; | ||
mod pe; | ||
pub mod pe; | ||
mod strings; | ||
mod tables; | ||
use blobs::*; | ||
mod type_name; | ||
|
||
use super::*; | ||
use blobs::*; | ||
use codes::*; | ||
pub use gen::*; | ||
use helpers::*; | ||
pub use helpers::*; | ||
use strings::*; | ||
use tables::*; | ||
|
||
pub fn test() { | ||
let mut tables = Tables::new(); | ||
tables.module.push(Module::new("test.winmd")); | ||
tables.type_def.push(TypeDef::module()); | ||
|
||
let mut stringable = TypeDef::winrt_interface("IStringable", "Windows.Foundation"); | ||
stringable.method_list.push(MethodDef::new("ToString")); | ||
tables.type_def.push(stringable); | ||
|
||
let mut closable = TypeDef::winrt_interface("IClosable", "Windows.Foundation"); | ||
closable.method_list.push(MethodDef::new("Close")); | ||
tables.type_def.push(closable); | ||
|
||
pe::write("/git/test.winmd", tables); | ||
} | ||
pub use tables::*; | ||
pub use type_name::*; |
Oops, something went wrong.