Skip to content

Commit 4c2320b

Browse files
authored
Merge pull request #990 from serpilliere/support_python2_python3
Support python2 python3
2 parents eab8099 + 26c1075 commit 4c2320b

File tree

343 files changed

+12074
-4670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

343 files changed

+12074
-4670
lines changed

.appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ environment:
1111
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
1212
PLATFORM_TOOLSET: v141
1313
PYTHON: c:\Python27
14+
PYTHON_VERSION: "2.7.x"
1415

1516
- platform: x64
1617
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
1718
PLATFORM_TOOLSET: v141
1819
PYTHON: c:\Python27-x64
20+
PYTHON_VERSION: "2.7.x"
1921

2022
# on_finish:
2123
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

.codespell_ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ uint
44
mye
55
iff
66
nto
7+
rela

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
sudo: false
22
language: python
3-
python: 2.7
3+
python:
4+
- 2.7
5+
- 3.6
46
addons:
57
apt:
68
sources: ['llvm-toolchain-trusty-6.0', 'ubuntu-toolchain-r-test']
@@ -29,4 +31,4 @@ before_script:
2931
# install
3032
- python setup.py build build_ext
3133
- python setup.py install
32-
script: cd test && python -W error test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard
34+
script: cd test && flags=""; python --version |& grep -q "Python 3" || flags="-W error"; python $flags test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard

Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This file is part of Miasm-Docker.
2+
# Copyright 2019 Camille Mougey <[email protected]>
3+
#
4+
# Miasm-Docker is free software: you can redistribute it and/or modify it
5+
# under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# Miasm-Docker is distributed in the hope that it will be useful, but WITHOUT
10+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
12+
# License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with Miasm-Docker. If not, see <http://www.gnu.org/licenses/>.
16+
17+
FROM debian:stretch
18+
MAINTAINER Camille Mougey <[email protected]>
19+
20+
# Download needed packages
21+
RUN apt-get -qq update && \
22+
apt-get -qqy install python python3 libpython-dev libpython3-dev python-pyparsing python3-pyparsing python-pip python3-pip && \
23+
apt-get -qqy install gcc g++ && \
24+
apt-get -qq clean
25+
26+
# Get miasm
27+
ADD . /opt/miasm
28+
RUN cd /opt/miasm && \
29+
pip install -r requirements.txt && \
30+
pip install -r optional_requirements.txt && \
31+
pip install . && \
32+
pip3 install -r requirements.txt && \
33+
pip3 install -r optional_requirements.txt && \
34+
pip3 install .
35+
36+
# Set user
37+
RUN useradd miasm && \
38+
chown -Rh miasm /opt/miasm
39+
USER miasm
40+
41+
# Default cmd
42+
WORKDIR /opt/miasm/test
43+
CMD ["/bin/bash", "-c", "for v in 2 3; do /usr/bin/python$v test_all.py -m; done"]

README.md

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Miasm is a free and open source (GPLv2) reverse engineering framework.
3030
Miasm aims to analyze / modify / generate binary programs. Here is
3131
a non exhaustive list of features:
3232

33-
* Opening / modifying / generating PE / ELF 32 / 64 LE / BE using Elfesteem
33+
* Opening / modifying / generating PE / ELF 32 / 64 LE / BE
3434
* Assembling / Disassembling X86 / ARM / MIPS / SH4 / MSP430
3535
* Representing assembly semantic using intermediate language
3636
* Emulating using JIT (dynamic code analysis, unpacking, ...)
@@ -47,8 +47,8 @@ Assembling / Disassembling
4747

4848
Import Miasm x86 architecture:
4949
```pycon
50-
>>> from miasm2.arch.x86.arch import mn_x86
51-
>>> from miasm2.core.locationdb import LocationDB
50+
>>> from miasm.arch.x86.arch import mn_x86
51+
>>> from miasm.core.locationdb import LocationDB
5252
```
5353
Get a location db:
5454

@@ -58,38 +58,38 @@ Get a location db:
5858
Assemble a line:
5959
```pycon
6060
>>> l = mn_x86.fromstring('XOR ECX, ECX', loc_db, 32)
61-
>>> print l
61+
>>> print(l)
6262
XOR ECX, ECX
6363
>>> mn_x86.asm(l)
6464
['1\xc9', '3\xc9', 'g1\xc9', 'g3\xc9']
6565
```
6666
Modify an operand:
6767
```pycon
6868
>>> l.args[0] = mn_x86.regs.EAX
69-
>>> print l
69+
>>> print(l)
7070
XOR EAX, ECX
7171
>>> a = mn_x86.asm(l)
72-
>>> print a
72+
>>> print(a)
7373
['1\xc8', '3\xc1', 'g1\xc8', 'g3\xc1']
7474
```
7575
Disassemble the result:
7676
```pycon
77-
>>> print mn_x86.dis(a[0], 32)
77+
>>> print(mn_x86.dis(a[0], 32))
7878
XOR EAX, ECX
7979
```
8080
Using `Machine` abstraction:
8181

8282
```pycon
83-
>>> from miasm2.analysis.machine import Machine
83+
>>> from miasm.analysis.machine import Machine
8484
>>> mn = Machine('x86_32').mn
85-
>>> print mn.dis('\x33\x30', 32)
85+
>>> print(mn.dis('\x33\x30', 32))
8686
XOR ESI, DWORD PTR [EAX]
8787
```
8888

8989
For Mips:
9090
```pycon
9191
>>> mn = Machine('mips32b').mn
92-
>>> print mn.dis('97A30020'.decode('hex'), "b")
92+
>>> print(mn.dis(b'\x97\xa3\x00 ', "b"))
9393
LHU V1, 0x20(SP)
9494
```
9595
Intermediate representation
@@ -99,8 +99,8 @@ Create an instruction:
9999

100100
```pycon
101101
>>> machine = Machine('arml')
102-
>>> instr = machine.mn.dis('002088e0'.decode('hex'), 'l')
103-
>>> print instr
102+
>>> instr = machine.mn.dis('\x00 \x88\xe0', 'l')
103+
>>> print(instr)
104104
ADD R2, R8, R0
105105
```
106106

@@ -120,7 +120,7 @@ Add instruction to the pool:
120120
Print current pool:
121121
```pycon
122122
>>> for lbl, irblock in ircfg.blocks.items():
123-
... print irblock.to_string(loc_db)
123+
... print(irblock.to_string(loc_db))
124124
loc_0:
125125
R2 = R8 + R0
126126

@@ -133,9 +133,9 @@ Working with IR, for instance by getting side effects:
133133
... for assignblk in irblock:
134134
... rw = assignblk.get_rw()
135135
... for dst, reads in rw.iteritems():
136-
... print 'read: ', [str(x) for x in reads]
137-
... print 'written:', dst
138-
... print
136+
... print('read: ', [str(x) for x in reads])
137+
... print('written:', dst)
138+
... print()
139139
...
140140
read: ['R8', 'R0']
141141
written: R2
@@ -164,21 +164,21 @@ Giving a shellcode:
164164
Import the shellcode thanks to the `Container` abstraction:
165165

166166
```pycon
167-
>>> from miasm2.analysis.binary import Container
167+
>>> from miasm.analysis.binary import Container
168168
>>> c = Container.from_string(s)
169169
>>> c
170-
<miasm2.analysis.binary.ContainerUnknown object at 0x7f34cefe6090>
170+
<miasm.analysis.binary.ContainerUnknown object at 0x7f34cefe6090>
171171
```
172172

173173
Disassembling the shellcode at address `0`:
174174

175175
```pycon
176-
>>> from miasm2.analysis.machine import Machine
176+
>>> from miasm.analysis.machine import Machine
177177
>>> machine = Machine('x86_32')
178178
>>> mdis = machine.dis_engine(c.bin_stream)
179179
>>> asmcfg = mdis.dis_multiblock(0)
180180
>>> for block in asmcfg.blocks:
181-
... print block.to_string(asmcfg.loc_db)
181+
... print(block.to_string(asmcfg.loc_db))
182182
...
183183
loc_0
184184
LEA ECX, DWORD PTR [ECX + 0x4]
@@ -208,7 +208,7 @@ Initializing the Jit engine with a stack:
208208
Add the shellcode in an arbitrary memory location:
209209
```pycon
210210
>>> run_addr = 0x40000000
211-
>>> from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
211+
>>> from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
212212
>>> jitter.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, s)
213213
```
214214

@@ -284,15 +284,15 @@ Initializing the IR pool:
284284
Initializing the engine with default symbolic values:
285285

286286
```pycon
287-
>>> from miasm2.ir.symbexec import SymbolicExecutionEngine
287+
>>> from miasm.ir.symbexec import SymbolicExecutionEngine
288288
>>> sb = SymbolicExecutionEngine(ira)
289289
```
290290

291291
Launching the execution:
292292

293293
```pycon
294294
>>> symbolic_pc = sb.run_at(ircfg, 0)
295-
>>> print symbolic_pc
295+
>>> print(symbolic_pc)
296296
((ECX + 0x4)[0:8] + 0xFF)?(0xB,0x10)
297297
```
298298

@@ -355,7 +355,7 @@ ________________________________________________________________________________
355355
Retry execution with a concrete ECX. Here, the symbolic / concolic execution reach the shellcode's end:
356356

357357
```pycon
358-
>>> from miasm2.expression.expression import ExprInt
358+
>>> from miasm.expression.expression import ExprInt
359359
>>> sb.symbols[machine.mn.regs.ECX] = ExprInt(-3, 32)
360360
>>> symbolic_pc = sb.run_at(ircfg, 0, step=True)
361361
Instr LEA ECX, DWORD PTR [ECX + 0x4]
@@ -525,7 +525,6 @@ Miasm uses:
525525

526526
* python-pyparsing
527527
* python-dev
528-
* elfesteem from [Elfesteem](https://github.com/serpilliere/elfesteem.git)
529528
* optionally python-pycparser (version >= 2.17)
530529

531530
To enable code JIT, one of the following module is mandatory:
@@ -539,14 +538,6 @@ To enable code JIT, one of the following module is mandatory:
539538
Configuration
540539
-------------
541540

542-
* Install elfesteem
543-
```pycon
544-
git clone https://github.com/serpilliere/elfesteem.git elfesteem
545-
cd elfesteem
546-
python setup.py build
547-
sudo python setup.py install
548-
```
549-
550541
To use the jitter, GCC or LLVM is recommended
551542
* GCC (any version)
552543
* Clang (any version)
@@ -570,8 +561,8 @@ Windows & IDA
570561

571562
Most of Miasm's IDA plugins use a subset of Miasm functionality.
572563
A quick way to have them working is to add:
573-
* `elfesteem` directory and `pyparsing.py` to `C:\...\IDA\python\` or `pip install pyparsing elfesteem`
574-
* `miasm2/miasm2` directory to `C:\...\IDA\python\`
564+
* `pyparsing.py` to `C:\...\IDA\python\` or `pip install pyparsing`
565+
* `miasm/miasm` directory to `C:\...\IDA\python\`
575566

576567
All features excepting JITter related ones will be available. For a more complete installation, please refer to above paragraphs.
577568

@@ -598,7 +589,7 @@ Tools
598589
-----
599590

600591
* [Sibyl](https://github.com/cea-sec/Sibyl): A function divination too
601-
* [R2M2](https://github.com/guedou/r2m2): Use miasm2 as a radare2 plugin
592+
* [R2M2](https://github.com/guedou/r2m2): Use miasm as a radare2 plugin
602593
* [CGrex](https://github.com/mechaphish/cgrex) : Targeted patcher for CGC binaries
603594
* [ethRE](https://github.com/jbcayrou/ethRE) Reversing tool for Ethereum EVM (with corresponding Miasm2 architecture)
604595

0 commit comments

Comments
 (0)