Is there a way to extract the compiled Lua code (.lc file) from the LFS (Lua Flash Store) image? - esp8266

I've had my laptop stolen from me a day after writing a very large and boring piece of Lua code. I did not commit this code to git, so I no longer have the .lua files :( However I still do have the debug esp8266 module where this code has been uploaded after compiling it into Lua File Store (LFS) image with luac.cross from nodemcu-firmware.
I was able to extract the LFS image from esp8266 back to my PC. Now I'd love to give luadec a try to decompile that code, but to do so I need to extract the compiled Lua files (.lc) from that LFS image. Is there any reasonable way to do so?

Related

Reverse engineering a ELF binary containing LUA bytecode

I have to reverse engineer a ELF binary file that also contains LUA bytecode, what would be the best approach for extracting the LUA bytecode to decompile it with luadec or similar tools ?
Currently I loaded the binary in Ghidra, mostly understood the functionality and how the lua code is loaded but I'am not very experienced in such things.
The binary uses luaL_readbuffer() to load the scripts, those scripts seems to be embedded in the binary files as variables.
Thanks!

How to unpack a single EXE file produced by Electron pack?

I have an EXE file which is packed and run by Electron. Now I want to unpack the single EXE file (not asar) to study the source code of this app. But how?
I have tried to unpack this web desktop app (EXE file packed by Electron) by change the extension of this file from exe to zip, 7z and tar. But all failed and indicates that this file is in "PE" format.
Could you please show some ways to unpack this Electron app in a single exe file? Thank you.
You don't unpack an executable file, you decompile it.
AFAIK, you won't get the source code from executable, all you get is machine code that is assembly instructions. There are tools out there which can help you to convert this assembly instructions to readable C code, for example, IDA Pro can do this.
There are lot many other decompilers and debuggers which can help you in this scenario. Like x64 debugger or Olly Debugger.
Trust me, you need a lot many hours to get proficient with these tools before you can actually make sense out of the raw assembly instructions, getting the source code out is a long way ahead.
And out of curiosity, why you wanted the source code of electron executable? All the real implementations for electron app should be inside ASAR packed file (which can be decompressed and then you have all the JavaScript source code). Electron executable is just like a wrapper which runs the JavaScript.
You can check out the electron implementation here.
Hi you can use exeinfope software. This is best ever software you can check programming languages easily

What is the file size limit? (NodeMCU, Esplorer)

I recently tried to host a little web interface from my ESP8266. But something kept failing until I realized that a bigger file (around 10kb) was corrupt. Well, not really corrupt, but simply incomplete. And no matter how I changed it, the file was always cut off after a certain amount of characters.
My compiled NodeMCU firmware is about 649kb in size, so there should easily be enough space. I mean my board has at least 4MB of storage (32m), so that should be plenty to store my lua, html and css files!
I used Esplorer to upload the files btw.
So what exactly is the limit here?
Is it a memory issue? A flash storage issue? An issue related to Esplorer?
Is it somehow possible to get bigger files onto my board?
edit:
I should mention that uploading the init.lua file always worked even if it was around 10kb. Maybe the uploading mechanism is different for the init.lua file?
Alright, here's the long form of my comment above. My best guess is (was) that this be an issue with ESPlorer. Whenever I look at its source code I'm actually surprized how well it usually works.
At https://frightanic.com/iot/tools-ides-nodemcu/ I compiled a list of tools and IDEs for NodeMCU. I suggest you pick a different uploader and try again. The NodeMCU-Tool for example is solid and it's definitely a lot better maintained than ESPlorer is.

ESP8266 - Is it possible to just run Lua from C (not the full NodeMCU environment)?

I'm working with ESP8266 and I don't want to use Lua for the whole project, I just want to run a few snippets of Lua code, received from wifi/sd card. I'd need to start a Lua environment and run the scripts, which would then eventually call some native functions for low level tasks. In other words, I just want to use Lua as simple scripting language (as it's intended to be) to implement some dynamic behavior. Is it possible? Is there any build of lualib for arduino?
Thanks in advance!
You can simply embed Lua in a extlibs/ folder for example and link to it when compiling your program.
There is existing Lua binaries but building it yourself is easy and better (as it's multiplatform).
OK, I know both answers told me I can just embed the code into my project, however, I found out I need to make some small changes. I made an example working project available here and the following list of changes had to be made:
The flags LUA_32BITS and LUA_USE_LONGJMP (C exception handling) were enabled
The following libraries were excluded: io, os, package, coroutine
The following functions were removed from C API: luaL_fileresult, luaL_execresult, luaL_loadfile, luaL_loadfilex, luaL_dofile, luaB_loadfile, luaB_dofile
Lua output messages are redirected to the Serial interface, check tinylua.h, tinylua.cpp and lauxlib.h to change this behavior
Hope this helps!
The ESP8266 has up to 4MB of program storage. Theoretically you can get up to 16MB as the datasheet specifies.
As I remember, compiling an amalgamated version of Lua (all sources in one file), occupies less than 100kb.
So, you can compile the Lua library and use it as needed on esp8266, even using Arduino IDE.
But you will get NAKED Lua if you do so... No nifty libraries to control Wifi, serial, SD, ports... You would have to provide that in C, or use NodeMCU code as you need.
You can try LuaJIT and access C code directly from Lua, cutting out the need for writing libraries. I have no idea of how you would compile it to Esp8266, or if anyone have tried this before, but you can do it "for science" and tell us how it turned out.

Using ZLib unit to compress files vs using ZipForge

There are many questions on zipping in Delphi, anyway this is not a duplicate.
I am using ZipForge for zip/unzip capability in my application.
Currently I use 2 features of ZipForge:
1) zip and unzip (!)
2) password protect the archives
Now I am removing the password from all the archives so I need only to zip and unzip files. I zip them just for minimizing bandwith when uploading/downloading files from the server. So my idea is to process all files once for unzipping them (with password) and rezipping them without password.
I have nothing against ZipForge, anyway it is an extra component, every time I upgrade to a newest Delphi version I have to wait for the new IDE support and moreover the more components the more problems during the installation (I don't mention the cost since it is very low, and replacing a component with some other thing costs time, so it is not a cost issue).
So since what I do is very simple I'd like to replace ZipForge with 2 simple functions using the ZLib unit.
I found (and tested) the functions here on Torry's.
What do you think of using Zlib unit? Do you see any potential problem that I would not have with ZipForge? Can you comment on speed?
Well, ZLib out-of-the-box is not ZIP and if you need to create ZIP files which should be unpacked by third-party software, you will have to write extra code to actually ZIP files. If you use your own code to perform both compression and decompression, you can go with ZLib. But still you will be reinventing the wheel by creating your own convention of passing file names etc. And you still need to use a third-party library.

Resources