-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test specifically covering #17 (WIP)
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
target | ||
*.iml | ||
.idea | ||
|
||
fixtures/symbol_server/* |
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,6 @@ | ||
# `fixtures/symbol_server/` | ||
|
||
Microsoft operates a [public symbol server](https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/microsoft-public-symbols). | ||
This allows `tests/` to download PDBs at runtime instead of including them in this repository. | ||
|
||
As an optimization, `tests/` that download PDBs will cache them in this folder. |
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,67 @@ | ||
extern crate pdb; | ||
extern crate uuid; | ||
|
||
use std::str::FromStr; | ||
use std::sync::{Once, ONCE_INIT}; | ||
use pdb::FallibleIterator; | ||
|
||
// This test is intended to cover OMAP address translation: | ||
// https://github.com/willglynn/pdb/issues/17 | ||
|
||
static DOWNLOADED: Once = ONCE_INIT; | ||
fn open_file() -> std::fs::File { | ||
DOWNLOADED.call_once(|| { | ||
// TODO: download | ||
// https://msdl.microsoft.com/download/symbols/ntkrnlmp.pdb/3844dbb920174967be7aa4a2c20430fa2/ntkrnlmp.pdb | ||
// to the path we try to open | ||
}); | ||
|
||
std::fs::File::open("fixtures/symbol_server/3844dbb920174967be7aa4a2c20430fa2-ntkrnlmp.pdb") | ||
.expect("opening file") | ||
} | ||
|
||
#[test] | ||
fn verify_pdb_identity() { | ||
// make sure this is the right PDB | ||
let mut pdb = pdb::PDB::open(open_file()).expect("opening pdb"); | ||
|
||
let pdb_info = pdb.pdb_information().expect("pdb information"); | ||
assert_eq!(pdb_info.guid, uuid::Uuid::from_str("3844DBB9-2017-4967-BE7A-A4A2C20430FA").unwrap()); | ||
assert_eq!(pdb_info.age, 5); | ||
assert_eq!(pdb_info.signature, 1290245416); | ||
} | ||
|
||
#[test] | ||
fn test_omap() { | ||
let mut pdb = pdb::PDB::open(open_file()).expect("opening pdb"); | ||
|
||
let global_symbols = pdb.global_symbols().expect("global_symbols"); | ||
|
||
// find the target symbol | ||
let target_symbol = { | ||
let target_name = pdb::RawString::from("NtWaitForSingleObject"); | ||
let mut iter = global_symbols.iter(); | ||
iter.filter(|sym| sym.name().expect("symbol name") == target_name).next() | ||
.expect("iterate symbols") | ||
.expect("find target symbol") | ||
}; | ||
|
||
// extract the PublicSymbol data | ||
let pubsym = match target_symbol.parse().expect("parse symbol") { | ||
pdb::SymbolData::PublicSymbol(pubsym) => pubsym, | ||
_ => panic!("expected public symbol") | ||
}; | ||
|
||
// ensure the symbol has the correct location | ||
assert_eq!(pubsym.segment, 0x000c); | ||
assert_eq!(pubsym.offset, 0x0004aeb0); | ||
|
||
// great, good to go | ||
// find the debug information | ||
pdb.debug_information().expect("debug_information"); | ||
|
||
// TODO: | ||
// build an address translator | ||
// translate the segment+offset | ||
// assert_eq!(rva, 0x003768c0) | ||
} |