split debug (=dangerous) things from trezor.utils to trezor.debug

pull/25/head
Pavol Rusnak 8 years ago
parent 6402b3d232
commit fbfd9d4b61
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -0,0 +1,71 @@
/*
* Copyright (c) Pavol Rusnak, SatoshiLabs
*
* Licensed under TREZOR License
* see LICENSE file for details
*/
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "py/objstr.h"
#if MICROPY_PY_TREZORDEBUG
typedef struct _mp_obj_Debug_t {
mp_obj_base_t base;
} mp_obj_Debug_t;
STATIC mp_obj_t mod_TrezorDebug_Debug_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_Debug_t *o = m_new_obj(mp_obj_Debug_t);
o->base.type = type;
return MP_OBJ_FROM_PTR(o);
}
/// def trezor.utils.memaccess(address: int, length: int) -> bytes
/// '''
/// Creates a bytes object that can be used to access certain memory location.
/// '''
STATIC mp_obj_t mod_TrezorDebug_Debug_memaccess(mp_obj_t self, mp_obj_t address, mp_obj_t length) {
uint32_t addr = mp_obj_get_int(address);
uint32_t len = mp_obj_get_int(length);
mp_obj_str_t *o = m_new_obj(mp_obj_str_t);
o->base.type = &mp_type_bytes;
o->len = len;
o->hash = 0;
o->data = (byte *)(uintptr_t)addr;
return MP_OBJ_FROM_PTR(o);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorDebug_Debug_memaccess_obj, mod_TrezorDebug_Debug_memaccess);
STATIC const mp_rom_map_elem_t mod_TrezorDebug_Debug_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_memaccess), MP_ROM_PTR(&mod_TrezorDebug_Debug_memaccess_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorDebug_Debug_locals_dict, mod_TrezorDebug_Debug_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorDebug_Debug_type = {
{ &mp_type_type },
.name = MP_QSTR_Debug,
.make_new = mod_TrezorDebug_Debug_make_new,
.locals_dict = (void*)&mod_TrezorDebug_Debug_locals_dict,
};
STATIC const mp_rom_map_elem_t mp_module_TrezorDebug_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_TrezorDebug) },
{ MP_ROM_QSTR(MP_QSTR_Debug), MP_ROM_PTR(&mod_TrezorDebug_Debug_type) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_TrezorDebug_globals, mp_module_TrezorDebug_globals_table);
const mp_obj_module_t mp_module_TrezorDebug = {
.base = { &mp_type_module },
.name = MP_QSTR_TrezorDebug,
.globals = (mp_obj_dict_t*)&mp_module_TrezorDebug_globals,
};
#endif // MICROPY_PY_TREZORDEBUG

@ -1,71 +0,0 @@
/*
* Copyright (c) Pavol Rusnak, SatoshiLabs
*
* Licensed under TREZOR License
* see LICENSE file for details
*/
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "py/objstr.h"
#if MICROPY_PY_TREZORUTILS
typedef struct _mp_obj_Utils_t {
mp_obj_base_t base;
} mp_obj_Utils_t;
STATIC mp_obj_t mod_TrezorUtils_Utils_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_Utils_t *o = m_new_obj(mp_obj_Utils_t);
o->base.type = type;
return MP_OBJ_FROM_PTR(o);
}
/// def trezor.utils.memaccess(address: int, length: int) -> bytes
/// '''
/// Creates a bytes object that can be used to access certain memory location.
/// '''
STATIC mp_obj_t mod_TrezorUtils_Utils_memaccess(mp_obj_t self, mp_obj_t address, mp_obj_t length) {
uint32_t addr = mp_obj_get_int(address);
uint32_t len = mp_obj_get_int(length);
mp_obj_str_t *o = m_new_obj(mp_obj_str_t);
o->base.type = &mp_type_bytes;
o->len = len;
o->hash = 0;
o->data = (byte *)(uintptr_t)addr;
return MP_OBJ_FROM_PTR(o);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUtils_Utils_memaccess_obj, mod_TrezorUtils_Utils_memaccess);
STATIC const mp_rom_map_elem_t mod_TrezorUtils_Utils_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_memaccess), MP_ROM_PTR(&mod_TrezorUtils_Utils_memaccess_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorUtils_Utils_locals_dict, mod_TrezorUtils_Utils_locals_dict_table);
STATIC const mp_obj_type_t mod_TrezorUtils_Utils_type = {
{ &mp_type_type },
.name = MP_QSTR_Utils,
.make_new = mod_TrezorUtils_Utils_make_new,
.locals_dict = (void*)&mod_TrezorUtils_Utils_locals_dict,
};
STATIC const mp_rom_map_elem_t mp_module_TrezorUtils_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_TrezorUtils) },
{ MP_ROM_QSTR(MP_QSTR_Utils), MP_ROM_PTR(&mod_TrezorUtils_Utils_type) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_TrezorUtils_globals, mp_module_TrezorUtils_globals_table);
const mp_obj_module_t mp_module_TrezorUtils = {
.base = { &mp_type_module },
.name = MP_QSTR_TrezorUtils,
.globals = (mp_obj_dict_t*)&mp_module_TrezorUtils_globals,
};
#endif // MICROPY_PY_TREZORUTILS

@ -0,0 +1,9 @@
if not __debug__:
raise ImportError('This module can be loaded only in DEBUG mode')
from TrezorDebug import Debug
_utils = Debug()
def memaccess(address, length):
return _utils.memaccess(address, length)

@ -1,13 +1,7 @@
import sys
from TrezorUtils import Utils
_utils = Utils()
type_gen = type((lambda: (yield))())
def memaccess(address, length):
return _utils.memaccess(address, length)
def unimport_func(func):
def inner(*args, **kwargs):
mods = set(sys.modules)

@ -1 +1 @@
Subproject commit e1a7215201e2cc567a28b3ee12dddc9486747be4
Subproject commit 861b0136cd68b3fe4431010588cabee96b016d41
Loading…
Cancel
Save