code stringlengths 1 1.72M | language stringclasses 1
value |
|---|---|
"""
structures.py: core classes Vector and Direction.
"""
from __future__ import division
from math import hypot
class Vector(object):
"""
A point identified on a cartesian plane.
"""
def __init__(self, x, y):
self.__dict__['x'] = x
self.__dict__['y'] = y
def __setattr__(self, n... | Python |
# -*- coding: utf-8 -*-
"""
foxgame/: root directory: contains Tests, UI, Controllers, and Game Logic.
"""
__author__ = 'Michele Orrù'
__mail__ = 'maker.py@gmail.com'
__license__ = 'GPLv2'
__contributors__ = ['Ezio Melotti',
'Davide Rizzo',
'Edmund_Ogban']
| Python |
import shelve
from collections import deque
from foxgame.structures import Direction
from foxgame.controller import PostFilter
from foxgame.options import FoxgameOption
class Inverted(PostFilter):
"""
A simple postfilter which invertes the direction given.
"""
def update(self, direction, time):
... | Python |
# -*- coding: utf-8 -*-
"""
./controllers/example.py: an example of controller.
"""
# import libraries useful for our Brains
from random import choice as randomchoice
# import basics foxgame modules
from foxgame.controller import Brain, PostFilter
from foxgame.structures import Direction
from foxgame.options import F... | Python |
"""
void.py: Brains useful for testing.
"""
from foxgame.controller import Brain
from foxgame.structures import Direction
class FoxBrain(Brain):
def update(self, time):
"""
Always return Direction.NULL.
"""
return Direction(Direction.NULL)
class HareBrain(Brain):
# threshol... | Python |
# -*- coding: utf-8 -*-
"""
fuzzy/ : Simple backpropagation, one hidden-layer Neural Network..
"""
__authors__ = 'Daniele Iamartino and Michele Orrù'
__date__ = '03/4/2010'
__contributors__ = []
| Python |
# -*- coding: utf-8 -*-
"""
neuralnet/nn.py: Back-Propagation module for Neural Networks.
"""
from __future__ import division
from os.path import exists
import shelve
import anydbm
import tfuncts
from logging import getLogger
log = getLogger('[libs-neuralnetwork]')
try:
import psyco
psyco.full()
except Im... | Python |
"""
neuralnet/tfuncts.py: some of the most common transfer functions
for neuralnetworks.
"""
from __future__ import division
from math import e, tanh
#HYPERBOLIC TANGENT
def tanh_function(x):
"""
Hyperbolic tangent - transfer function
"""
return tanh(x)
def tanh_derived(y):
... | Python |
from __future__ import division
from functools import partial
from itertools import product
PRECISION = 0.5
def operator(op):
"""
Operators relate two sets according to the standard
fuzzy logic conventions.
"""
def operate(*parents):
return partial(op, *parents)
return operate
def ar... | Python |
"""
fuzzy/hedges.py: collection of hedges.
"""
from functools import wraps
from math import sqrt
from fuzzy import Set
def hedge(modifier):
"""
Hedges are devices commonly used to weaken or strengthen
the impact of a statement.
"""
@wraps(hedge)
def modify(set):
return Set(set.parent... | Python |
# -*- coding: utf-8 -*-
from __future__ import division
from operator import sub
from math import sqrt
from operator import or_
from collections import defaultdict
from itertools import product
import operators
from mfuncts import functions
EPSILON = 1e-5
class Set(object):
"""
A Fuzzy set is a set whose va... | Python |
"""
fuzzy/mfuncts.py: some of the most common membership funtions for fuzzy sets.
"""
from __future__ import division
def singleton(self, x):
xa, = self._lims
return 1 if x == xa else 0
def triangular(self, x):
xl, xa, xr = self._lims
if xl < x <= xa:
return (x - xl) / (xa - xl)
if xa ... | Python |
# -*- coding: utf-8 -*-
"""
fuzzy/ : Simple Fuzzy controller.
"""
__authors__ = 'Michele Orrù'
__date__ = '17/4/2010'
__contributors__ = []
| Python |
# -*- coding: utf-8 -*-
"""
./controlles/libs/test: Tests for FoxGame's controller libraries.
"""
__license__ = 'GPLv2'
| Python |
# -*- coding: utf-8 -*-
"""
./controllers/libs/: Libraries needed from controllers.
"""
__author__ = 'Michele Orrù'
__mail__ = 'maker.py@gmail.com'
__license__ = 'GPLv2'
__contributors__ = ['Daniele Iamartino']
| Python |
"""
rl.py: Reinforcement learning implementation
of Hare brain
"""
from __future__ import division
from random import random, randint
from math import hypot, exp, log as logn
from os.path import join as osjoin
from foxgame.controller import Brain
from foxgame.structures import Vector, Direction
from foxgame.opt... | Python |
from sys import stdout
from foxgame.structures import Direction
from foxgame.options import FoxgameOption
from foxgame.controller import PostFilter
@staticmethod
def simple_print(dst, data):
"""
Print data 'as it is'.
"""
print >> dst, '\n'.join(data.values())
@staticmethod
def core_print(dst, data)... | Python |
"""
"""
from __future__ import division
from foxgame.controller import Brain
from foxgame.structures import Vector, Direction
from libs.fuzzy import fuzzy, operators
operators.PRECISION = 0.25
import logging
log = logging.getLogger(__name__)
class HareBrain(Brain):
"""
A simple controller witch uses traditi... | Python |
# -*- coding: utf-8 -*-
"""
./controlles/: Brains and Postfilters for foxgame.
"""
__author__ = 'Michele Orrù'
__mail__ = 'maker.py@gmail.com'
__license__ = 'GPLv2'
| Python |
"""
nn.py: Brains which provide a neural network
to move foxes/hare.
"""
from __future__ import division
from os.path import join as osjoin
from os.path import exists
from os import remove
from glob import glob
from math import sqrt
from foxgame.options import FoxgameOption, task
from foxgame.controller import... | Python |
import os
import os.path
from glob import glob
from foxgame.controller import PostFilter
from foxgame.options import FoxgameOption
import logging
log = logging.getLogger(__name__)
class CSV(PostFilter):
"""
A simple postfilter which outputs sequential game data to CSV file.
"""
logfile = 'game.csv'... | Python |
"""
traditional.py: Brains which provide a simple algorithm
to move foxes/hare using traditional programming.
"""
from foxgame.controller import Brain
from foxgame.structures import Vector, Direction
import logging
log = logging.getLogger(__name__)
class FoxBrain(Brain):
"""
A simple controll... | Python |
#!/usr/bin/python -O
# -*- coding: utf-8 -*-
"""
main: the main game.
"""
#
# Copyright 2010 <Michele Orrù>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 dated June, 199... | Python |
#!/usr/bin/python -O
# -*- coding: utf-8 -*-
"""
task: execute tasks for controllers.
"""
#
# Copyright 2010 <Michele Orrù>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2... | Python |
#
# Expression simplification regression tests #
#
from pdb import pm
from miasm2.expression.expression import *
from miasm2.expression.simplifications import expr_simp
# Define example objects
a = ExprId('a')
b = ExprId('b')
c = ExprId('c')
d = ExprId('d')
e = ExprId('e')
m = ExprMem(a)
s = a[:8]
i1 = ExprInt(uint... | Python |
from miasm2.expression.modint import *
a = uint8(0x42)
b = uint8(0xFF)
c = uint8(0x4)
d = uint1(0)
e = uint1(1)
f = uint8(0x1)
print a, b, c
print a + b, a + c, b + c
print a == a, a == b, a == 0x42, a == 0x78
print a != b, a != a
print d, e
print d + e, d + d, e + e, e + e + e, e + 0x11
assert(f == 1)
assert(f +... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import unittest
class TestIrIr2STP(unittest.TestCase):
def test_ExprOp_strcst(self):
from miasm2.expression.expression import ExprInt32, ExprOp
import miasm2.expression.stp # /!\ REALLY DIRTY HACK
args = [ExprInt32(i) for i in xrange(9)]
... | Python |
import os
import time
from sys import stderr
from miasm2.arch.sh4.arch import *
filename = os.environ.get('PYTHONSTARTUP')
if filename and os.path.isfile(filename):
execfile(filename)
def h2i(s):
return s.replace(' ', '').decode('hex')
reg_tests_sh4 = [
# vxworks
("c80022f2 MOV 0x10, R6",
... | Python |
import os
import time
from miasm2.arch.x86.arch import *
filename = os.environ.get('PYTHONSTARTUP')
if filename and os.path.isfile(filename):
execfile(filename)
for s in ["[EAX]",
"[0x10]",
"[EBX + 0x10]",
"[EBX + ECX*0x10]",
"[EBX + ECX*0x10 + 0x1337]"]:
(e, a, b) = der... | Python |
import os
import time
from miasm2.arch.arm.arch import *
filename = os.environ.get('PYTHONSTARTUP')
if filename and os.path.isfile(filename):
execfile(filename)
if 0:
a = bs('00')
b = bs('01')
c = bs(l=2)
d = bs(l=4, fname='rd')
e = bs_name(l=1, name={'ADD': 0, 'SUB': 1})
assert(isinstance... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import unittest
import logging
from miasm2.ir.symbexec import symbexec
from miasm2.arch.arm.arch import mn_arm as mn, mode_arm as mode
from miasm2.arch.arm.sem import ir_arm as ir
from miasm2.arch.arm.regs import *
from miasm2.expression.expression import *
logging.getLogg... | Python |
import os
import time
from miasm2.arch.msp430.arch import *
filename = os.environ.get('PYTHONSTARTUP')
if filename and os.path.isfile(filename):
execfile(filename)
def h2i(s):
return s.replace(' ', '').decode('hex')
def u16swap(i):
return struct.unpack('<H', struct.pack('>H', i))[0]
reg_tests_msp = ... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import unittest
import logging
from miasm2.ir.symbexec import symbexec
from miasm2.arch.msp430.arch import mn_msp430 as mn, mode_msp430 as mode
from miasm2.arch.msp430.sem import ir_msp430 as ir
from miasm2.arch.msp430.regs import *
from miasm2.expression.expression import ... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import unittest
class TestSymbExec(unittest.TestCase):
def test_ClassDef(self):
from miasm2.expression.expression import ExprInt32, ExprId, ExprMem, ExprCompose
from miasm2.arch.x86.arch import mn_x86
from miasm2.ir.symbexec import symbexec
... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import unittest
class TestIrIr2C(unittest.TestCase):
def test_ExprOp_toC(self):
from miasm2.expression.expression import ExprInt32, ExprOp
import miasm2.ir.ir2C # /!\ REALLY DIRTY HACK
args = [ExprInt32(i) for i in xrange(9)]
# Unary... | Python |
from miasm2.core.graph import *
g = DiGraph()
g.add_node('a')
g.add_node('b')
g.add_edge('a', 'b')
g.add_edge('a', 'c')
g.add_edge('a', 'c')
g.add_edge('c', 'c')
print g
print [x for x in g.successors('a')]
print [x for x in g.predecessors('a')]
print [x for x in g.predecessors('b')]
print [x for x in g.predecessor... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from miasm2.core.interval import *
from random import randint
from pdb import pm
i1 = interval([(1, 3)])
i2 = interval([(2, 5)])
i3 = interval([(3, 5)])
i4 = interval([(5, 8)])
i5 = interval([(1, 5)])
i6 = interval([(1, 3), (5, 8)])
i7 = interval([(2, 8)])
i8 = interval([(... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import unittest
class TestParseAsm(unittest.TestCase):
def test_ParseTxt(self):
from miasm2.arch.x86.arch import mn_x86
from miasm2.core.parse_asm import parse_txt
ASM0 = '''
;
.LFB0:
.LA:
.text
.data
... | Python |
#
# Simplification methods library #
#
from miasm2.expression.expression import *
from miasm2.expression.expression_helper import *
# Common passes
# -------------
def simp_cst_propagation(e_s, e):
"""This passe includes:
- Constant folding
- Common logical identities
- ... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
class moduint(object):
def __init__(self, arg):
if isinstance(arg, moduint):
arg = arg.arg
self.arg = arg % self.__class__.limit
assert(self.arg >= 0 and self.arg < self.__class__.limit)
def __repr__(self):
return self.__... | Python |
#!/usr/bin/env python
#
# Copyright (C) 2011 EADS France, Fabrice Desclaux <fabrice.desclaux@eads.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at... | Python |
#
# Copyright (C) 2011 EADS France, Fabrice Desclaux <fabrice.desclaux@eads.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any late... | Python |
from miasm2.expression.expression import *
"""
Quick implementation of miasm traduction to stp langage
TODO XXX: finish
"""
def ExprInt_strcst(self):
b = bin(int(self.arg))[2::][::-1]
b += "0" * self.size
b = b[:self.size][::-1]
return "0bin" + b
def ExprId_strcst(self):
return self.name
def... | Python |
#
# Copyright (C) 2011 EADS France, Fabrice Desclaux <fabrice.desclaux@eads.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any late... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os
from miasm2.ir.ir2C import irblocs2C
from subprocess import Popen, PIPE
import jitcore
from distutils.sysconfig import get_python_inc
import Jittcc
def jit_tcc_compil(func_name, func_code):
global Jittcc
c = Jittcc.tcc_compil(func_name, func_code)
ret... | Python |
#!/usr/bin/env python
import os
from miasm2.core import asmbloc
from collections import defaultdict
import struct
from elfesteem import pe
from elfesteem import cstruct
from elfesteem import *
from vm_mngr import *
from vm_mngr import VmMngr
from csts import *
from miasm2.core.utils import *
from jitcore_tcc import J... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#
# Copyright (C) 2011 EADS France, Fabrice Desclaux <fabrice.desclaux@eads.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 o... | Python |
#
# Copyright (C) 2011 EADS France, Fabrice Desclaux <fabrice.desclaux@eads.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any late... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from sys import stdout
from string import printable
def xxx_isprint(jitter):
'''
#include <ctype.h>
int isprint(int c);
checks for any printable character including space.
'''
c, = jitter.func_args_fastcall(1)
ret = chr(c & 0xFF) in printable ... | Python |
#
# Copyright (C) 2011 EADS France, Fabrice Desclaux <fabrice.desclaux@eads.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any late... | Python |
#
#
# Miasm2 Extension: #
# - Miasm2 IR to LLVM IR #
# - JiT #
#
# Requires: ... | Python |
import os
import importlib
import hashlib
try:
from llvmconvert import *
except ImportError:
pass
import jitcore
import Jitllvm
class JitCore_LLVM(jitcore.JitCore):
"JiT management, using LLVM as backend"
# Architecture dependant libraries
arch_dependent_libs = {"x86": "arch/JitCore_x86.so"}
... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
# VM Mngr Exceptions
EXCEPT_DO_NOT_UPDATE_PC = 1 << 25
EXCEPT_CODE_AUTOMOD = (1 << 0)
EXCEPT_SOFT_BP = (1 << 1)
EXCEPT_INT_XX = (1 << 2)
EXCEPT_BREAKPOINT_INTERN = (1 << 10)
EXCEPT_ACCESS_VIOL = ((1 << 14) | EXCEPT_DO_NOT_UPDATE_PC)
# VM Mngr constants
PAGE_READ = 1
PAGE... | Python |
from miasm2.expression.expression import *
from miasm2.core.cpu import reg_info, gen_reg
# GP
gpregs_str = ['R%d' % r for r in xrange(0x10)]
gpregs_expr = [ExprId(x, 32) for x in gpregs_str]
gpregs = reg_info(gpregs_str, gpregs_expr)
bgpregs_str = ['R%d_BANK' % r for r in xrange(0x8)]
bgpregs_expr = [ExprId(x, 32) fo... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os
from pyparsing import *
from miasm2.core.cpu import *
from miasm2.expression.expression import *
from collections import defaultdict
from regs import *
jra = ExprId('jra')
jrb = ExprId('jrb')
jrc = ExprId('jrc')
# parser helper ###########
PLUS = Suppress("+")
... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from miasm2.expression.expression import *
from miasm2.core.graph import DiGraph
from miasm2.ir.ir import ir, irbloc
from miasm2.ir.analysis import ira
from miasm2.arch.x86.sem import ir_x86_16, ir_x86_32, ir_x86_64
class ir_a_x86_16(ir_x86_16, ira):
def __init__(self... | Python |
from miasm2.expression.expression import *
from miasm2.core.cpu import reg_info
IP = ExprId('IP', 16)
EIP = ExprId('EIP', 32)
RIP = ExprId('RIP', 64)
exception_flags = ExprId('exception_flags', 32)
# GP
regs08_str = ["AL", "CL", "DL", "BL", "AH", "CH", "DH", "BH"] + \
["R%dB" % (i + 8) for i in xrange(8)]
regs... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import re
from miasm2.expression.expression import *
from pyparsing import *
from miasm2.core.cpu import *
from collections import defaultdict
import regs as regs_module
from regs import *
from miasm2.ir.ir import *
log = logging.getLogger("x86_arch")
console_handler = logg... | Python |
from miasm2.core.asmbloc import asm_constraint, asm_label, disasmEngine
from miasm2.expression.expression import ExprId
from arch import mn_x86
def cb_x86_callpop(mn, attrib, pool_bin, cur_bloc, offsets_to_dis, symbol_pool):
"""
1000: call 1005
1005: pop
"""
if len(cur_bloc.lines) < 1:
ret... | Python |
__all__ = ["arch", "disasm", "regs", "sem"]
| Python |
#
# Copyright (C) 2011 EADS France, Fabrice Desclaux <fabrice.desclaux@eads.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any late... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from miasm2.expression.expression import *
from miasm2.ir.ir import ir, irbloc
from miasm2.ir.analysis import ira
from miasm2.arch.arm.sem import ir_arm, ir_armt
from miasm2.arch.arm.regs import *
# from miasm2.core.graph import DiGraph
class ir_a_arm_base(ir_arm, ira):
... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from miasm2.expression.expression import *
# GP
regs32_str = ["R%d" % i for i in xrange(13)] + ["SP", "LR", "PC"]
regs32_expr = [ExprId(x, 32) for x in regs32_str]
R0 = regs32_expr[0]
R1 = regs32_expr[1]
R2 = regs32_expr[2]
R3 = regs32_expr[3]
R4 = regs32_expr[4]
R5 = r... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import logging
from pyparsing import *
from miasm2.expression.expression import *
from miasm2.core.cpu import *
from collections import defaultdict
from miasm2.core.bin_stream import bin_stream
import regs as regs_module
from regs import *
# A1 encoding
log = logging.getLo... | Python |
from miasm2.core.asmbloc import asm_constraint, disasmEngine
from arch import mn_arm, mn_armt
def cb_arm_fix_call(
mn, attrib, pool_bin, cur_bloc, offsets_to_dis, symbol_pool):
"""
for arm:
MOV LR, PC
LDR PC, [R5, 0x14]
* is a subcall *
"""
if len(cur_bloc.lines) < 2:
... | Python |
__all__ = ["arch", "disasm", "regs", "sem"]
| Python |
from miasm2.expression.expression import *
from miasm2.ir.ir import ir, irbloc
from miasm2.arch.arm.arch import mn_arm, mn_armt
# liris.cnrs.fr/~mmrissa/lib/exe/fetch.php?media=armv7-a-r-manual.pdf
EXCEPT_PRIV_INSN = (1 << 17)
# CPSR: N Z C V
reg_r0 = 'R0'
reg_r1 = 'R1'
reg_r2 = 'R2'
reg_r3 = 'R3'
reg_r4 = 'R4'
reg... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from miasm2.expression.expression import *
from miasm2.ir.ir import ir, irbloc
from miasm2.ir.analysis import ira
from miasm2.arch.msp430.sem import ir_msp430
from miasm2.arch.msp430.regs import *
# from miasm2.core.graph import DiGraph
class ir_a_msp430_base(ir_msp430, ir... | Python |
from miasm2.expression.expression import *
from miasm2.core.cpu import reg_info
# GP
regs16_str = ["PC", "SP", "SR"] + ["R%d" % i for i in xrange(3, 16)]
regs16_expr = [ExprId(x, 16) for x in regs16_str]
gpregs = reg_info(regs16_str, regs16_expr)
PC = regs16_expr[0]
SP = regs16_expr[1]
SR = regs16_expr[2]
R3 = re... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import logging
from pyparsing import *
from miasm2.expression.expression import *
from miasm2.core.cpu import *
from collections import defaultdict
from miasm2.core.bin_stream import bin_stream
import regs as regs_module
from regs import *
log = logging.getLogger("armdis")
... | Python |
from miasm2.core.asmbloc import disasmEngine
from arch import mn_msp430
class dis_msp430(disasmEngine):
def __init__(self, bs=None, **kwargs):
super(dis_msp430, self).__init__(mn_msp430, None, bs, **kwargs)
| Python |
__all__ = ["arch", "disasm", "regs", "sem"]
| Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from miasm2.expression.expression import *
from miasm2.arch.msp430.regs import *
from miasm2.arch.msp430.arch import mn_msp430
from miasm2.ir.ir import ir
from regs import *
# Utils
def hex2bcd(val):
"Return val as BCD"
try:
return int("%x" % val, 10)
e... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from miasm2.ir.symbexec import symbexec
from miasm2.core.graph import DiGraph
from miasm2.expression.expression import *
class ira:
def sort_dst(self, todo, done):
out = set()
while todo:
dst = todo.pop()
if self.ExprIsLabel(dst... | Python |
from miasm2.expression.expression import *
from miasm2.expression.simplifications import expr_simp
from miasm2.core import asmbloc
import logging
log = logging.getLogger("symbexec")
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter("%(levelname)-5s: %(message)s"))
log.addHandler... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#
# Copyright (C) 2013 Fabrice Desclaux
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any ... | Python |
from miasm2.expression.expression import *
from miasm2.expression.simplifications import expr_simp
from miasm2.core import asmbloc
import logging
log_to_c_h = logging.getLogger("ir_helper")
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter("%(levelname)-5s: %(message)s"))
log_to... | Python |
import struct
upck8 = lambda x: struct.unpack('B', x)[0]
upck16 = lambda x: struct.unpack('H', x)[0]
upck32 = lambda x: struct.unpack('I', x)[0]
upck64 = lambda x: struct.unpack('Q', x)[0]
pck16 = lambda x: struct.pack('H', x)
pck32 = lambda x: struct.pack('I', x)
pck64 = lambda x: struct.pack('Q', x)
class Disasm_E... | Python |
class DiGraph:
def __init__(self):
self._nodes = set()
self._edges = []
self._nodes_to = {}
self._nodes_from = {}
def __repr__(self):
out = []
for n in self._nodes:
out.append(str(n))
for a, b in self._edges:
out.append("%s -> %s"... | Python |
INT_EQ = 0
INT_B_IN_A = 1
INT_A_IN_B = -1
INT_DISJOIN = 2
INT_JOIN = 3
INT_JOIN_AB = 4
INT_JOIN_BA = 5
# 0 => eq
# 1 => b in a
# -1 => a in b
# 2 => disjoin
# 3 => join
# 4 => join a,b touch
# 5 => join b,a touch
def cmp_interval(a, b):
if a == b:
return INT_EQ
a1, a2 = a
b1, b2 = b
if ... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import re
import struct
import miasm2.expression.expression as m2_expr
from miasm2.core.asmbloc import *
declarator = {'byte': 'B',
'word': 'H',
'dword': 'I',
'qword': 'Q',
'long': 'I', 'zero': 'I',
}
d... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import re
import struct
import logging
from pyparsing import *
from miasm2.expression.expression import *
from miasm2.core import asmbloc
from collections import defaultdict
from bin_stream import bin_stream, bin_stream_str
from utils import Disasm_Exception
from miasm2.expr... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import logging
import miasm2.expression.expression as m2_expr
from miasm2.expression.modint import moduint, modint
from miasm2.core.graph import DiGraph
from utils import Disasm_Exception
from miasm2.core.graph import DiGraph
import inspect
log_asmbloc = logging.getLogger("... | Python |
#
# Copyright (C) 2011 EADS France, Fabrice Desclaux <fabrice.desclaux@eads.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any late... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from miasm2.expression.expression import *
from miasm2.expression.simplifications import expr_simp
from miasm2.core.asmbloc import *
from miasm2.core.utils import *
# from miasm2.core.graph import DiGraph
def get_ira(mnemo, attrib):
arch = mnemo.name, attrib
if arc... | Python |
import cmd
from miasm2.core.utils import hexdump
import miasm2.jitter.csts as csts
from miasm2.jitter.jitload import ExceptionHandle
class DebugBreakpoint:
"Debug Breakpoint parent class"
pass
class DebugBreakpointSoft(DebugBreakpoint):
"Stand for software breakpoint"
def __init__(self, addr):
... | Python |
from miasm2.expression.expression import *
from miasm2.ir.symbexec import symbexec
def get_node_name(label, i, n):
# n_name = "%s_%d_%s"%(label.name, i, n)
n_name = (label, i, n)
return n_name
def intra_bloc_flow_raw(my_ir, flow_graph, irb):
"""
Create data flow for an irbloc using raw IR expres... | Python |
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import socket
import struct
import time
import logging
from StringIO import StringIO
import miasm2.analysis.debugging as debugging
from miasm2.jitter.jitload import ExceptionHandle
class GdbServer(object):
"Debugguer binding for GDBServer protocol"
general_regist... | Python |
#! /usr/bin/env python
from distutils.core import setup, Extension
from distutils.util import get_platform
import shutil
import os, sys
def buil_all():
packages=['miasm2',
'miasm2/arch',
'miasm2/arch/x86',
'miasm2/arch/arm',
'miasm2/arch/msp430',
... | Python |
from miasm2.expression.expression import *
from miasm2.expression.simplifications import expr_simp
print """
Simple expression simplification demo
"""
a = ExprId('eax')
b = ExprId('ebx')
exprs = [a + b - a,
ExprInt32(0x12) + ExprInt32(0x30) - a,
ExprCompose([(a[:8], 0, 8),
(a... | Python |
from miasm2.core.cpu import parse_ast, ast_id2expr
from miasm2.arch.x86.arch import mn_x86, base_expr
from miasm2.core import parse_asm
from miasm2.expression.expression import *
from miasm2.core import asmbloc
from miasm2.arch.x86.ira import ir_a_x86_32
from pdb import pm
def my_ast_int2expr(a):
return ExprInt32... | Python |
from miasm2.core.graph import DiGraph
from miasm2.expression.expression import *
print "Simple Expression grapher demo"
a = ExprId("A")
b = ExprId("B")
c = ExprId("C")
d = ExprId("D")
m = ExprMem(a + b + c + a)
e1 = ExprCompose([(a + b - (c * a) / m | b, 0, 32), (a + m, 32, 64)])
e2 = ExprInt64(15)
e = ExprCond(d, e... | Python |
from miasm2.arch.x86.arch import mn_x86
from miasm2.expression.expression import get_rw
from miasm2.arch.x86.ira import ir_a_x86_32
print """
Simple expression manipulation demo.
Get read/written registers for a given instruction
"""
arch = mn_x86
my_ir = ir_a_x86_32()
l = arch.fromstring('LODSB', 32)
l.offset, l.l =... | Python |
import os
import sys
from miasm2.expression.expression import *
from miasm2.expression.simplifications import expr_simp
from miasm2.arch.x86.ira import ir_a_x86_32
from miasm2.arch.x86.arch import mn_x86
from miasm2.core import asmbloc
from miasm2.core.bin_stream import bin_stream_str
from elfesteem import pe_init
from... | Python |
from miasm2.expression.expression import *
from miasm2.expression.simplifications import expr_simp
from pdb import pm
import os
filename = os.environ.get('PYTHONSTARTUP')
if filename and os.path.isfile(filename):
execfile(filename)
print """
Expression simplification demo.
(and regression test)
"""
a = ExprId('... | Python |
from miasm2.expression.expression import *
print """
Simple expression manipulation demo
"""
# define 2 ID
a = ExprId('eax', 32)
b = ExprId('ebx', 32)
print a, b
# eax ebx
# add those ID
c = ExprOp('+', a, b)
print c
# (eax + ebx)
# + automaticaly generates ExprOp('+', a, b)
c = a + b
print c
# (eax + ebx)
# ax is... | Python |
import os
import sys
from miasm2.arch.x86.arch import *
from miasm2.arch.x86.regs import *
from miasm2.arch.x86.sem import *
from miasm2.core.bin_stream import bin_stream_str
from miasm2.core import asmbloc
from miasm2.expression.expression import get_rw
from miasm2.ir.symbexec import symbexec
from miasm2.expression.si... | Python |
#! /usr/bin/env python
from miasm2.core.cpu import parse_ast
from miasm2.arch.arm.arch import mn_arm, base_expr, variable
from miasm2.core.bin_stream import bin_stream
from miasm2.core import parse_asm
from miasm2.expression.expression import *
from elfesteem.strpatchwork import StrPatchwork
from pdb import pm
from m... | Python |
import sys
import struct
from elfesteem import *
import os
import sys
# example for extracting all pe ressources
def extract_res(res, name_o="", num=0, lvl=-1):
lvl += 1
if not res:
return num
for x in res.resentries:
print "\t" * lvl, repr(x)
num += 1
if x.name_s:
... | Python |
import sys
import os
from argparse import ArgumentParser
from miasm2.arch.x86.arch import mn_x86
from miasm2.jitter.jitload import jitter_x86_32, vm_load_pe, preload_pe, libimp
from miasm2.jitter.jitload import bin_stream_vm
from miasm2.jitter.csts import *
from miasm2.jitter.os_dep import win_api_x86_32
from miasm2.an... | Python |
Subsets and Splits
SQL Console for ajibawa-2023/Python-Code-Large
Provides a useful breakdown of language distribution in the training data, showing which languages have the most samples and helping identify potential imbalances across different language groups.