.tbc to .tcl file
Asked Answered
M

2

6

this is a strange question and i searched but couldn't find any satisfactory answer.

I have a compiled tcl file i.e. a .tbc file. So is there a way to convert this .tbc file back to .tcl file.

I read here and someone mentioned about ::tcl_traceCompile and said this could be used to disassemble the .tbc file. But being a novice tcl user i am not sure if this is possible, or to say more, how exactly to use it.

Though i know that tcl compiler doesn't compile all the statements and so these statements can be easily seen in .tbc file but can we get the whole tcl back from .tbc file.

Any comment would be great.

Mobley answered 31/1, 2013 at 18:58 Comment(1)
You are aware that the whole point of using the .tbc format is to stop conversion to a readable .tcl file. It's certainly not done for performance; it's actually faster to not use the .tbc format at all. (Weird, but true!)Margarettamargarette
M
5

No, or at least not without a lot of work; you're doing something that quite a bit of effort was put in to prevent (the TBC format is intended for protecting commercial code from prying eyes).


The TBC file format is an encoding of Tcl's bytecode, which is not normally saved at all; the TBC stands for Tcl ByteCode. The TBC format data is only produced by one tool, the commercial “Tcl Compiler” (originally written by either Sun or Scriptics; the tool dates from about the time of the transition), which really is a leveraging of the built-in compiler that every Tcl system has together with some serialization code. It also strips as much of the original source code away as possible. The encoding used is unpleasant; you want to avoid writing your own loader of it if you can, and instead use the tbcload extension to do the work.

You'll then need to use it with a custom build of Tcl that disables a few defensive checks so that you can disassemble the loaded code with the tcl::unsupported::disassemble command (which normally refuses to take apart anything coming from tbcload); that command exists from Tcl 8.5 onwards. After that, you'll have to piece together what the code is doing from the bytecodes; I'm not aware of any tools for doing that at all, but the bytecodes are mostly fairly high level so it's not too difficult for small pieces of code.

There's no manual page for disassemble; it's formally unsupported after all! However, that wiki page I linked to should cover most of the things you need to get started.

Margarettamargarette answered 31/1, 2013 at 22:34 Comment(1)
Also, tcl_traceCompile won't help very much as the code is already compiled, and there are checks in place even when that feature is enabled to prevent revealing the contents of TBC-defined code. (tcl_traceExec is slightly more relevant, but no more useful really.)Margarettamargarette
P
0

I can say partially "yes" and conditionaly too. That condition is if original tcl code is written in namespace and procs are defined within namespace curly braces. Then you source tbc file in tkcon/wish and see code using info procs and namespace command. Offcourse you need to know namespace name. However that also can be found.

Phage answered 19/11, 2015 at 9:14 Comment(1)
#10834261 shows how namespaces can be listed. Get the namespaces before loading the tcb module. Get them again after loading it, Then filter the previous from the current. Then use [info commands $namespace] to list out the available functions. Function prototypes are not copyright-able. Tangent: If you have to get what the source code is doing, I suggest using a two person system. Look into how reactos was legally developed.Forestay

© 2022 - 2024 — McMap. All rights reserved.