Open guedou opened 6 years ago
Yes! That's interesting. I will see with @commial some details on the way to implement this: In some Miasm parts, we used an "AbstractMethod" raising in order to enforce the sub class implementations, something like:
raise NotImplementedError("Abstract")
I can implement it if you tell what to do =)
Hi @guedou,
Two things here:
x86*
or arm*
takes more than 1 sec. So, this code has been done to avoid a 3/4 seconds delay on Miasm launch, even if the architecture aren't all needed.Machine
object is not yet well designed to be extended, and this is probably a fault of mine. A dynamic registration could be done with an association "architecture name" -> callback setting IR, jit, ... attributes
. We could then imagine having either a Machine
class with a dictionary as class attribute representing this aforementioned association, or an initial empty object and further registration. Something like:
def set_x86_16(machine): from ... import ... machine._ir = ...
class Machine(object): architectures = {"x86_16": set_x86_16, "x86_32": set_x86_32, ... }
def __init__(self, arch_name):
cb = self.architectures.get(arch_name, None)
if cb is None:
raise ValueError("...")
cb(self)
Machine.architectures["my_awesome_arch"] = set_my_awesome_arch
or
```Python
class Machine(object):
@classmethod
def register(arch, callback):
...
Machine.register("x86_16", ...)
Machine.register("x86_32", ...)
# Further add of a new arch
Machine.register("my_awesome_arch", set_my_awesome_arch)
Is that what you requested?
This is exactly what I meant =)
The main use case will be to add an architecture by adding files into miasm2/arch/NEW_ARCH
without modifying anything else. Moreover, it will also be possible to maintain an architecture as an independent Python module, without including the whole miasm source.
Your second use case is what I had in mind while writing comments above. Regarding the first use case, we may consider that if an arch is landing in Miasm, you can also modify a few other part. You'll also probably need to modify sandbox, jitter,... In addition, you'll probably end with a weird import tree: Machine from the new arch to add the callback, the architecture from the callback, others architectures from the Machine module.
That being said, a clean separation between architecture specifics and the rest is still a good objective. But some prior work should be done before and is probably not related with this PR
I would like to dynamically add a new architecture into
Machine
, and found this comment while reading the source code.Do you think that dynamic registration can be implemented, or that's a dead end due to performance issues ?