<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>固件 :: 标签 :: yafeng 的博客</title><link>http://yafengabc.github.io/tags/%E5%9B%BA%E4%BB%B6/index.html</link><description/><generator>Hugo</generator><language>zh-cn</language><lastBuildDate>Sat, 19 Sep 2026 14:36:30 +0800</lastBuildDate><atom:link href="http://yafengabc.github.io/tags/%E5%9B%BA%E4%BB%B6/index.xml" rel="self" type="application/rss+xml"/><item><title>MicroPython入坑记（四）关于MicroPython的代码保护</title><link>http://yafengabc.github.io/cnblogs/p8682910/index.html</link><pubDate>Sat, 31 Mar 2018 16:47:00 +0800</pubDate><guid>http://yafengabc.github.io/cnblogs/p8682910/index.html</guid><description>脚本开发东西，可能面临的第一个问题就是：拷给别人，代码怎么写的他不就都知道了？不行，我要保住我的小秘密！&#10;先说下结果：没有攻不破的堡垒，即使你写成C语言，只要能拿到二进制结果，都可以反汇编逆向出你是怎么实现的，关键是值不值得&#10;另外，这跟逆向者对系统的了解程度有关，比如对方连代码都不会上传，那你即使把源文件放进去也他也无可奈何。&#10;好了，言归正传，我们知道普通python有个编译成字节码的功能，也就是源代码会在解释时先编译成一个类似java中间代码的结果，这是不可读的（但是这也不排除反编译的可能，毕竟JAVA的class文件是有反编译软件的）。&#10;micropython也有这个功能，不过这个文件的扩展名是mpy，也不能在运行时自动生成，需要一款软件：mpy-cross.exe，这是micropython官方提供的，可以用python pip直接安装，安装完成后，可以运行mpy-cross.exe pythonfile,py，就可以生成一个pythonfile.mpy的字节码文件，这文件使用跟py文件是等效的。把所有文件生成mpy，可以在一定程度上保护你的代码。&#10;更进一步的方式：把mpy文件藏到固件中去，这不光能保护代码，还能降低程序的内存占用，官方的描述如下：&#10;Cross-installing packages with freezing For the low-memory MicroPython ports, the process described in the previous section does not provide the most efficient resource usage,because the packages are installed in the source form, so need to be compiled to the bytecome on each import. This compilation requires RAM, and the resulting bytecode is also stored in RAM, reducing its amount available for storing application data. Moreover, the process above requires presence of the filesystem on a device, and the most resource-constrained devices may not even have it.</description></item><item><title>MicroPython入坑记（二）刷固件（ESP8266 ESP32）</title><link>http://yafengabc.github.io/cnblogs/p8681380/index.html</link><pubDate>Sat, 31 Mar 2018 11:13:00 +0800</pubDate><guid>http://yafengabc.github.io/cnblogs/p8681380/index.html</guid><description>先来个刷写过程：&#10;其实各种刷ESP8266/ESP32的软件都可以搞（比如刷NodeMCU的软件），不过我这还是出问题了：刷完后无限输出乱码。然后参照Micropython官方的教程，用esptool先清除所有的FLASH，然后重新刷入，正常运行：&#10;pip install esptool 安装esptool（当然，电脑上要先装好python） esptool.py --port /dev/ttyUSB0 erase_flash 擦除所有的flash，如果是windows系统，则改为具体的COM口，比如我的电脑是COM4： esptool.py --port COM4 erase_flash刷入固件这个命令比较长，可以不熟悉命令行的可以用其他GUI软件代替： esptool.py --port COM4 --baud 460800 write_flash --flash_size=detect 0 esp8266.bin（这个改为具体固件文件名） 刷完后，用putty连接板子会出现以下界面（如果没有显示就先按一下RST键）： 现在就可以执行Python代码了，支持命令补全哦列出所有的模块：继续探索：在ESP8266上，跟板子相关的代码主要在esp machine两个模块上： import esp&#10;import machine&#10;dir(esp)&#10;[’__class__’, ‘__name__’, ‘SLEEP_LIGHT’, ‘SLEEP_MODEM’, ‘SLEEP_NONE’, ‘apa102_write’, ‘check_fw’, ‘deepsleep’, ‘dht_readinto’, ’esf_free_bufs’, ‘flash_erase’, ‘flash_id’, ‘flash_read’, ‘flash_size’, ‘flash_user_start’, ‘flash_write’, ‘free’, ‘freemem’, ‘info’, ‘malloc’, ‘meminfo’, ’neopixel_write’, ‘osdebug’, ‘set_native_code_location’, ‘sleep_type’]&#10;dir(machine)&#10;[’__class__’, ‘__name__’, ‘ADC’, ‘DEEPSLEEP’, ‘DEEPSLEEP_RESET’, ‘HARD_RESET’, ‘I2C’, ‘PWM’, ‘PWRON_RESET’, ‘Pin’, ‘RTC’, ‘SOFT_RESET’, ‘SPI’, ‘Signal’, ‘Timer’, ‘UART’, ‘WDT’, ‘WDT_RESET’, ‘deepsleep’, ‘disable_irq’, ’enable_irq’, ‘freq’, ‘idle’, ‘mem16’, ‘mem32’, ‘mem8’, ‘reset’, ‘reset_cause’, ‘sleep’, ’time_pulse_us’, ‘unique_id’]</description></item></channel></rss>