110 lines
2.6 KiB
Text
110 lines
2.6 KiB
Text
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# Flash target\n",
|
||
|
"\n",
|
||
|
"import chipwhisperer as cw\n",
|
||
|
"\n",
|
||
|
"PLATFORM='CWNANO'\n",
|
||
|
"\n",
|
||
|
"try:\n",
|
||
|
" %run \"scripts/Setup_Generic.ipynb\"\n",
|
||
|
"except:\n",
|
||
|
" %run \"../scripts/Setup_Generic.ipynb\"\n",
|
||
|
"scope.adc.samples = 1000\n",
|
||
|
"\n",
|
||
|
"programmer = cw.programmers.STM32FProgrammer\n",
|
||
|
"try:\n",
|
||
|
" fw_path = 'hex/basic-passwdcheck-CWNANO.hex'\n",
|
||
|
" cw.program_target(scope, programmer, fw_path)\n",
|
||
|
"except FileNotFoundError:\n",
|
||
|
" fw_path = '../hex/basic-passwdcheck-CWNANO.hex'\n",
|
||
|
" cw.program_target(scope, programmer, fw_path)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def serial_read():\n",
|
||
|
" res = ''\n",
|
||
|
" num_char = target.in_waiting()\n",
|
||
|
" while num_char > 0:\n",
|
||
|
" res += target.read(num_char, 10)\n",
|
||
|
" time.sleep(0.01)\n",
|
||
|
" num_char = target.in_waiting()\n",
|
||
|
" return res"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {
|
||
|
"scrolled": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def cap_pass_trace(password):\n",
|
||
|
" if not password.endswith('\\n'):\n",
|
||
|
" password += '\\n'\n",
|
||
|
" reset_target(scope)\n",
|
||
|
" ret = serial_read()\n",
|
||
|
" scope.arm()\n",
|
||
|
" target.flush()\n",
|
||
|
" target.write(password)\n",
|
||
|
" ret = scope.capture()\n",
|
||
|
" if ret:\n",
|
||
|
" print('Timeout happened during acquisition') \n",
|
||
|
" trace = scope.get_last_trace()\n",
|
||
|
" return trace"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def pass_response(password):\n",
|
||
|
" if not password.endswith('\\n'):\n",
|
||
|
" password += '\\n'\n",
|
||
|
" reset_target(scope)\n",
|
||
|
" ret = serial_read()\n",
|
||
|
" target.flush()\n",
|
||
|
" target.write(password)\n",
|
||
|
" time.sleep(0.1)\n",
|
||
|
" res = serial_read()\n",
|
||
|
" return res"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
},
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"nbconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": "3.9.2"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 2
|
||
|
}
|