Luna updated for third-party TNS document generation

I’m pleased to announce the availability of Luna v0.2!

This version adds support for arbitrary TI-Nspire “problems” conversion from XML format to TI-Nspire TNS documents compatible with OS 3.0.2 and above. This could not easily be done on the latest OS versions before, because TI took the sad decision to protect its OS from interoperability with third-party user tools.

Suppose you now want to build a computer tool that generates TI-Nspire documents with Notepad widgets.

1) Build the problem template: on nspire_emu, create a new document with a Notepad widget (“Add notes”). Put a debugger breakpoint to export the document in XML form, before it is compressed and encrypted: on a non-CAS OS 3.0.1, you would use something like:
k 10032AA0 +x
c
[save the document here]
w problem.xml r1 400
[repeat if the problem is bigger than 1024 bytes to get each problem chunk]

Some alternative methods such as copying from TI-Nspire Software and exporting the content with Levak’s clipboard dumper may also be used instead, or as adriweb suggests for Mac users the “Clipboard Viewer” available with XCode in /developer/Applications/Utilities/.

You will get an XML document that looks like (the Notepad only contains a “Hello world” here, the TI-Nspire XML format is indeed quite verbose):

<?xml version="1.0" encoding="UTF-8" ?>
<prob xmlns="urn:TI.Problem" ver="1.0" pbname="">
<sym></sym><card clay="0" h1="10000" h2="10000" w1="10000" w2="10000"><isDummyCard>0</isDummyCard><flag>0</flag>
<wdgt xmlns:np="urn:TI.Notepad" type="TI.Notepad" ver="2.0"><np:mFlags>1024</np:mFlags><np:value>3</np:value>
<np:fmtxt>&lt;r2dtotree&gt;&lt;node name=&quot;1doc&quot;&gt;&lt;node name=&quot;1para&quot;&gt;&lt;node name=&quot;1rtline&quot;&gt;&lt;leaf name=&quot;1word&quot;&gt;hello &lt;/leaf&gt;&lt;leaf name=&quot;1word&quot;&gt;world&lt;cursor index=&quot;0&quot;/&gt;&lt;/leaf&gt;&lt;/node&gt;&lt;/node&gt;&lt;/node&gt;&lt;/r2dtotree&gt;</np:fmtxt></wdgt></card></prob>

2) Write your problem generator based on this template

3) Integrate Luna with your generator:
luna problem.xml outdoc.tns

Quite easy, isn’t it? :)

[update 2011/09/21] Levak tells me his Make3D program which features a Lua plugin system can now be built with Luna and its XML converter for compatibility with OS 3.0.2 and later! Minor encoding issues had to be worked around, we’re looking further into them.

Luna, here she is!

Luna is the first third-party Lua script converter for TI-Nspire compatible with OS 3.0.2. It defeats the useless compression and encryption layers described in earlier posts.

Long-time TI-Nspire users, you now won’t need to pay for a Computer Software licence to code in Lua.

Developers, you won’t click and click and click anymore to convert/test/run your programs as you have to with the official kit.

Linux users, here is a portable tool.

Hackers, this can be a good base to build (or rewrite) third-party TI-Nspire document generators.

Enthusiasts, support for C and ARM on OS 3.x might not be so far…

I like this sound of openness and happiness, don’t you too?

Luna

Lua to TNS converter – A little bit further

I finally could find a couple of hours to go further on the converter.

As you remember the OS 3.x TNS file format has 4 layers: 1) XML compression, 2) zlib compression, 3) triple-DES encryption and 4) zip wrapper. 4) and 3) are now supported by the converter, but it fails miserably on the inflate() call for 2) with a Z_DATA_ERROR… The deflated 512-byte block to inflate seems OK, and can be inflated on the computer side without problem.

What could be wrong?

[edit 2011/08/01] 2) (zlib compression) now passes! the zlib stream needs to be produced with a negative windowBits parameter, to avoid emitting a zlib header.

And now probably the last step: 1) (the XML compression) fails at the 13th 512-byte block of the Lua sample program I use, in the TNS decryption loop…

Lua, Ndless, What’s up?

Sorry for not having posted more frequent updates on the current work in progress.

The Lua to TNS converter compatible with OS 3.0.2 was entirely written a few weeks ago, but doesn’t yet produce valid TNS files. I had missed a few steps in the initial description of the conversion algorithm.

The constant Triple-DES keys embedded in the OS are actually used to encrypt a header, which itself includes other Triple-DES keys and an initialization vector, all uniquely generated for each TNS file created. The use of the initialization vector is quite differently than in common block cipher modes of operation. The vector is actually incremented for each 8-byte encryption/decryption step, and xor-ed with the encrypted/decrypted block.

Apparently something is still wrong or missing, but the tool is probably not far from working.

Wait, TI publicly released a month ago (or maybe was forced to release after the leak) a set of converters and documentation for Lua development. So why should we care about another converter? The official tools aren’t command-line based and require cumbersome manual steps for each code&test cycle that any developer would obviously fear. They depend on TI-Nspire Computer Software which requires a license. Many developers who bought the old Clickpad model didn’t get this license now sold with the Touchpads TI-Nspires. And most importantly Ndless 3.0 may depend on such a user tool.

Work on the awaited Ndless 3.0 is frozen as long as I cannot get the Lua converter running. I have recently quite seriously thought about making the maintenance of Ndless and related tools a full-time job, to combine free time and passion and push the project even further. Unfortunately I couldn’t find any realistic revenue model and I’m now resigned to give up on this idea…

D-method encryption and Lua hopes for OS 3.0.2

So a TNS file entry compressed with the unknown “D” method is:

  1. XML-compressed by the OS with a custom binary XML method
  2. deflated with zlib
  3. Encrypted

I was curious about 1) and 3).

I first checked that XML-compressing a Lua script from a skeleton (similarly to what the current third-party Lua converters for OS 3.0.1 do) is quite easy without needing to implemented the patented algorithm, thus avoiding any legal issues. This is good news.

I also had a closer look at the encryption algorithm. It is actually an OpenSSL-based Triple-DES encryption in ECB mode (thanks Google Code Search for making ARM code so much clearer). The 3 keys are probably embedded in the OS although I didn’t bother to look where exactly. Computer-side encryption tests confirm that the 3 keys I found are the good ones.

Integrating this into to a new Lua converter compatible with OS 3.0.2  should now be easy :)

Tweaking OS 3.0

Considering the release of TI-Nspire OS 3.0.2 I have both good and bad news:

  • The upcoming Ndless v3.0, compatible with OS 3.0, is under development, and I was hoping to share an alpha version soon
  • TI sadly took with OS 3.0.2 the decision  to block third-party Lua development, preferring to force developers to wait for an official release of their SDK. Fortunately Lua scripts can still be saved on OS 3.0.1 and transferred back to OS 3.0.2 to run them.
  • Some of the most active contributors to the unofficial Lua runtime documentation unfortunately accepted to beta-test the upcoming TI SDK, probably under NDA, and now may have difficulties to contribute on both sides
  • The forthcoming v3.0 of Ndless depends on Lua for its installation

The “D” compression method of TNS documents introduced in the latest OS versions that prevents third-party tools to TNS files was by-passed by LUA2TNS and the other (now blocked) Lua converters. I have looked a bit closer at it this morning, and it appears that an XML file  (document or problem) included in a TNS file this way is first XML-compressed with a patented methodinflated with zlib, then probably encrypted.

So what does this mean for us? Implementing a third-party converter which includes the XML compression required by OS 3.0.2 is impossible without being exposed to legal action. Compressing XML is surely a bright idea to optimize storage space, but there were many open binary XML encoding methods available that did not require TI to invest (probably specifically for the TI-Nspire) in a new one. Unless they want to wrap the device with fiddle-proof legal tape.

I’m now considering extending Ncubate, the enhanced nspire_emu, with a Lua script conversion feature.