mirror of
https://github.com/Noratrieb/portability.git
synced 2026-01-14 15:55:04 +01:00
pdb
This commit is contained in:
parent
559186088f
commit
b7afada251
4 changed files with 54 additions and 42 deletions
|
|
@ -1,4 +1,5 @@
|
|||
mod emulated;
|
||||
mod pdb;
|
||||
mod sys;
|
||||
|
||||
use std::{
|
||||
|
|
@ -276,6 +277,13 @@ const IMAGE_FILE_MACHINE_AMD64: u16 = 0x8664;
|
|||
const IMAGE_FILE_MACHINE_ARM64: u16 = 0xaa64;
|
||||
|
||||
pub fn execute(pe: &[u8], executable_path: &Path) {
|
||||
let pdb_path = executable_path.with_extension("pdb");
|
||||
let pdb_file = std::fs::File::open(&pdb_path).unwrap();
|
||||
let map = unsafe { memmap2::Mmap::map(&pdb_file).unwrap() };
|
||||
let pdb = pdb::Pdb::new(&map);
|
||||
pdb.dump();
|
||||
return;
|
||||
|
||||
let mut main_tls_slots = [ptr::null_mut(); 64];
|
||||
|
||||
let mut main_teb = ThreadEnvironmentBlock {
|
||||
|
|
|
|||
45
src/pdb.rs
Normal file
45
src/pdb.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
//! <https://llvm.org/docs/PDB/index.html>
|
||||
|
||||
pub(crate) struct Pdb<'a> {
|
||||
data: &'a [u8],
|
||||
}
|
||||
|
||||
/// <https://llvm.org/docs/PDB/MsfFile.html>
|
||||
mod msf {
|
||||
use bytemuck::{AnyBitPattern, Zeroable};
|
||||
|
||||
const MAGIC: [u8; 32] = *b"Microsoft C/C++ MSF 7.00\r\n\x1A\x44\x53\x00\x00\x00";
|
||||
pub(super) const BLOCK_SIZE: usize = 4096;
|
||||
|
||||
#[derive(Debug, Clone, Copy, AnyBitPattern)]
|
||||
pub(super) struct SuperBlock {
|
||||
pub(super) magic: [u8; MAGIC.len()],
|
||||
pub(super) block_size: u32,
|
||||
pub(super) free_block_map_block: u32,
|
||||
pub(super) num_blocks: u32,
|
||||
pub(super) num_directory_bytes: u32,
|
||||
pub(super) unknown: u32,
|
||||
pub(super) block_map_addr: u32,
|
||||
}
|
||||
|
||||
pub(super) struct StreamDirectory {
|
||||
pub(super) num_streams: u32,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Pdb<'a> {
|
||||
pub(crate) fn new(data: &'a [u8]) -> Self {
|
||||
Self { data }
|
||||
}
|
||||
|
||||
pub(crate) fn dump(&self) {
|
||||
let superblock = bytemuck::cast_slice::<_, msf::SuperBlock>(
|
||||
&self.data[0..][..size_of::<msf::SuperBlock>()],
|
||||
)[0];
|
||||
dbg!(superblock);
|
||||
|
||||
assert_eq!(superblock.block_size, 4096);
|
||||
let free_block_map_1 = &self.data[msf::BLOCK_SIZE..][..msf::BLOCK_SIZE];
|
||||
let free_block_map_2 = &self.data[msf::BLOCK_SIZE * 2..][..msf::BLOCK_SIZE];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,8 @@
|
|||
SHELL = bash
|
||||
RUSTC = rustc --target x86_64-pc-windows-msvc -Copt-level=3 -Cpanic=abort -Clinker=lld-link -Clink-arg=/NODEFAULTLIB -Clink-arg=/debug:none -Cdebuginfo=0
|
||||
RUSTC = rustc --target x86_64-pc-windows-msvc -Copt-level=3 -Cpanic=abort -Clinker=lld-link -Clink-arg=/NODEFAULTLIB
|
||||
|
||||
build: empty_exe.exe one_dll.exe two_dll.exe tls_exe.exe
|
||||
|
||||
tls_exe.exe: tls_exe.rs
|
||||
$(RUSTC) tls_exe.rs
|
||||
|
||||
empty_exe.exe: empty_exe.rs
|
||||
$(RUSTC) empty_exe.rs
|
||||
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
#![feature(thread_local)]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![windows_subsystem = "console"]
|
||||
|
||||
#[panic_handler]
|
||||
fn handle_panic(_: &core::panic::PanicInfo<'_>) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[thread_local]
|
||||
static mut A_THREAD_LOCAL: u32 = 50;
|
||||
#[thread_local]
|
||||
static mut ANOTHER_THREAD_LOCAL: u32 = 55;
|
||||
|
||||
#[inline(never)]
|
||||
fn set_tls(value: u32) {
|
||||
unsafe { A_THREAD_LOCAL = value; }
|
||||
unsafe { ANOTHER_THREAD_LOCAL = value; }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "stdcall" fn mainCRTStartup() -> u32 {
|
||||
// Use some indirection to actually force TLS to happen
|
||||
set_tls(14);
|
||||
unsafe { A_THREAD_LOCAL + ANOTHER_THREAD_LOCAL }
|
||||
}
|
||||
|
||||
/*
|
||||
!!!!!!!!!!!!!!!
|
||||
THIS IS WRONG. WE ARE NOT CREATING THE TLS DIRECTORY. THAT WOULD BE OUR JOB.
|
||||
!!!!!!!!!!!!!!
|
||||
*/
|
||||
|
||||
|
||||
extern "stdcall" {
|
||||
static _tls_index: usize;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue