Comments (2)
Hello and thanks for taking interest!
A windows binary (PE file) contains more than just code instructions, you cannot simply start at some point and iterate until the end. This very simple length disassembler will stop when it encounters an instruction it does not understand.
You may try to extract the 'code' section of the PE file, using eg. pelite whose job it is to parse the PE file structures (disclaimer: I am the author of pelite). You can use that library to extract the code section (assuming x64):
use pelite::pe64::{Pe, PeFile};
let map = pelite::FileMap::open("demo/Demo64.dll").unwrap();
let file = PeFile::from_bytes(&map).unwrap();
let code_section = file.section_headers().iter().find(|sect| §.Name == b".text\0\0\0").unwrap();
let code_bytes = file.get_section_bytes(code_section).unwrap();
for (opcode, va) in lde::X64.iter(code_bytes, code_section.VirtualAddress as u64) {
println!("{:#x}: {}", va, opcode);
}
However even this isn't guaranteed to only contain executable code! jump tables for switch statements will put their tables in the code section as well as you can easily write source code in C++ or Rust which puts arbitrary data in the code section.
How to work around this issue depends on what your goal is. Here is an example where I'm looking for a particular bit of code which I know ahead of time what its structure is going to be, then I run through it with lde to find specific instructions which reveal the underlying data structures of the source code which generated that code.
I haven't found much time to work on this library in particular, I'd love to put more work into it (eg. supporting the new v
-style sse instructions) but it should keep working for 32-bit and older x64 based instructions.
from lde.
If I understand correctly, using pelite won't work either because there is no guarantee there will be only executable code.
What you suggest is, for example, to look for a particular piece of code and then run lde from there, am I correct?
I think that's what I have done so I will keep my approach to the problem as it is now then. I guess I was looking for a wrong abstraction. (The code is here if you want to check.)
from lde.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lde.