Scrambler issue
-
Good Morning,
We are meeting hard time with the scrambler. Ruby script works well and scrambled on recent Sketchup version as well but crashes or runs bug splat window on older version. We spent much and much time to preserve backward compatibility and now are unable to deliver good code on Sketchup old version due to that scrambler.Does anyone hold old version of the scrambler and send us?
Best Regards
-
I don't think the RBS scrambler has changed since it was first released.
But there has been some bugs where loading RBS would fail/crash because of too long lines in the source code. I'd start there - check the length of the lines in your RB files.
Some of the more recent version allowed for longer length's lines, but still have a max limit. (don't recall the exact numbers.) -
Hi thomthom,
Bad news! RBS scrambler won't serve our purpose because of line max limit.
I have now to find out a solution 'by myself' to obfuscate our ruby script but really don't know where to start.any help appreciated
have a good day
-
Why can't the lines be broken into smaller ones? You have to have some pretty long lines to trigger this bug - far beyond what is normal for source code. I have some times seem people embed HTML etc as one-liners, though this could easily be extracted as separate resources loaded at runtime.
What versions of SU are you looking to support? How far back are you going?
I'm not sure what to recommend as alternatives - depend on how far you feel the need to go. This could easily snowball - which is why I'd recommend looking into breaking up the long lines.
-
Reading your post I feel better as I know there are alternatives even time consuming
In fact there are so many long lines of code in our script which weights nearly 500k with comments I should add. We knew about some RBS scrambler limits but were far from what you have just told to me.
On the other hand code obfuscation is not an option but a need.
We take care to develop under Sketchup8 an test 2013, 14, 15, 16 make or pro version. From where we are now we can't go back. I am fully aware this could easily snowball but want to give a trial to any solution.
Anyway I don't see any other way right now -
@whydi said:
In fact there are so many long lines of code in our script which weights nearly 500k
Five hundred thousand character long lines? Did I read that correctly? How do you end up with lines that long? Auto-generated code?
Is is embedded resources (binary data)?If you cannot address the line lengths (I don't fully understand why this wouldn't be possible) then you'd have to find a way to scramble or encrypt your files yourself, have a proxy loader that reads your files and descrabmle/decrypt and then evaluate the code. You can do this as easily as base64 encoding it or as complicated as you want with true encryption etc. You can do the loading and decrypting in a Ruby C extension to hide the loading logic.
However, I really would recommend focusing on your source code line length. I struggle to see any reason for source code to be more than a couple of hundred characters long - none the less in the thousands!
Wait.... are you talking about number of lines? Because that'd make more sense. I was talking about number of characters per line.
-
You're right I'm talking about numbers of long lines, not a single line of five hundred thousand of chars. But why not? might be a way more to prevent code from being easily read.
Scramble or encrypt the script is not the issue and I fully understand your recommendation. I may end up with shortening lines length but would have liked to know more about the process you describe. My understanding is c++ reads and unscramble my data file then sends the result -which is a ruby script- straightforward to Sketchup. Am I right?
If so where can I find information about such process ? may you help me to go through? -
@whydi said:
If so where can I find information about such process ? may you help me to go through?
This would be a rare thing to do. I know of only one or two that do the base64 hashing, and one other developer that use their own. But none have fully described in detail the process.
I also have no specific encryption method to recommend because I've never had the need to do this.I did debug this issue at some point, and I ran a script on the extension source that basically went through line by line and counted the size. In the two cases I had there where at max 5 lines that exceeded the limit - and they where all due to embedding binary or HTML data. I'd urge you to first do this simple assessment of your source. If it's only a handful of lines then that's so much easier to fix than rolling your own obfuscating system.
Another caveat with rolling your own obfuscating system is that you'd make debugging a nightmare for yourself. -
Hi thomthom,
I agree with you but really meet hard time with that scrambler. have a look. The following code crashes on SU8 8.0.14346 but works well on 2016.
mainFile.rbrequire 'sketchup.rb' module Cie_qwerty module Ext_azerty #load "C;/Users/uName/SketchUp/Ruby/test.rb" Sketchup;;load "C;/Users/uName/SketchUp/Ruby/testSC" puts "------------------------------------------start" print_test() puts "------------------------------------------ready" end end
test.rb
require 'sketchup' module Cie_qwerty module Ext_azerty def self.print_test() puts "print test" end end end
then wScrambler.exe test.rb
then rename test.rbs testSC.rbs
Sketchup::load or Sketchup::require doesn't matter
testSC.rbs or testSC doesn't matterFIRST... load "C:/Users/NeW/SketchUp/Ruby/test.rb"
load SU8 : run correctly
load SU2016 : run correctlySECOND... Sketchup::load "C:/Users/NeW/SketchUp/Ruby/testSC"
Unload then reload SU8: crash
Unload then reload SU2016 : works wellRuby console results
SU8 one single line and crash. nothing more
------------------------------------------start
SU2016 all right
------------------------------------------start print test ------------------------------------------ready
So what is wrong in my code?
have a good day
-
Hm....
That is strange.
However, I do not see a crash in SU8. I get a Ruby error - but not crash.
require 'C;/Users/tthomas2/Desktop/scram/main.rb' ------------------------------------------start Error; #<NoMethodError; undefined method `print_test' for Cie_qwerty;;Ext_azerty;Module> (eval) (eval);0;in `require' (eval);0
However, I realize this is due to a bug in older SketchUp where
Sketchup.require
(Sketchup.load
is an alias) will evaluate the content of the file directly into the current namespace.So in your code you ended up with something like this:
module Cie_qwerty module Ext_azerty module Cie_qwerty module Ext_azerty def print_test
The workaround is to ensure that you do all require outside your namespace:
require 'sketchup.rb' Sketchup;;require "C;/Users/uName/SketchUp/Ruby/testSC" module Cie_qwerty module Ext_azerty puts "------------------------------------------start" print_test() puts "------------------------------------------ready" end end
This made the file load correctly for me.
Btw, I never saw a crash - did you mean Ruby errors? Quite a significant different - a crash is when the application terminate (with SketchUp you get a BugSplat dialog).
-
No crash your way and no error shown. the script stops and nothing. The bug splat window appears when I run the full script of our extension.
I modified the code but get the same result. what sub version of SU8 do you run?
-
@whydi said:
No crash your way and no error shown. the script stops and nothing.
When you load main.rb - do you use require or Sketchup.require. The former will yield an Ruby error. The latter will just return false.
@whydi said:
The bug splat window appears when I run the full script of our extension.
Have you submitted this crash? (If so entered any info?)
@whydi said:
I modified the code but get the same result. what sub version of SU8 do you run?
8.0.16846
Can you share the RBS you generated from that snippet above?
main.zip
Here's my test files. The path is hard coded to my machine so you'd have to update that to test. -
My version is the latest SU8 release - meaning Trimble branded.
Sketchup.require is the same as Sketchup::require. Just different Ruby syntax.
Please submit the bugsplat with some info that can be used to look it up. Like mention it is related to Sketchup.require. -
Your version is near mine. Does it come from Trimble or Google? Google I think.
I use Sketchup::require, not Sketchup.require
I haven't submitted the crash yet and don't think I do. It looks so strange!Edit...
from your code i modified this way the main filerequire 'sketchup.rb' Sketchup;;require "C;/Users/uName/SketchUp/Ruby/testSC" module Cie_qwerty module Ext_azerty puts "------------------------------------------start" print_test() puts "------------------------------------------ready" end end
This time it works!
Sketchup::require or Sketchup.require doesn't matter
keepgoing tests...Here are the files not modified
-
@whydi said:
Your version is near mine. Does it come from Trimble or Google? Google I think.
I use Sketchup::require, not Sketchup.require
I haven't submitted the crash yet and don't think I do. It looks so strange!Here are the files
I did not see a crash when loading your files.
But I did get a load error, you where still having theSketchup::require
statement within your module:
Move it to the global namespace, like so:
Then it loads fine.
-
I edited my previous post with result after reading your code. It works!
Sketchup::require needs to appear before any module.
I go ahead testing line length...
-
@whydi said:
Sketchup::require needs to appear before any module.
At least in SketchUp versions earlier than SU2014. From then on it was fixed.
-
I found information about line length here
https://groups.google.com/forum/#!topic/sketchupruby/EV5KDgh6C0M
where ChuckVali in the last post wrote :@unknownuser said:
...I noticed something else about the scrambler. If there are more than around 1000 characters in any line the resulting .rbs file can't be read by SU. Not a problem though: I just use shorter lines and concat them...
the longest line in our script is over 1500 chars and I won't be able to cut these lines under 503 chars due to if statement with and and and and and so forth.
Are 512 chars OK?in the same thread I read something that I don't clearly understand. Jim wrote :
@unknownuser said:
...This may be related to a bug when scrambling Ruby files. If you are
loading the .rbs from a SketchupExtension, the loaded files may be put
under the SketchupExtension namespace. Maybe there are conflicting
names if these other plugins are also loading scrambled files using
SketchupExtension...Is it what we have just done ? I believe but who knows
-
@whydi said:
...I won't be able to cut these lines under 503 chars due to if statement with and and and and and so forth....
the ruby 'style guide' recommends 70 chars per line, so 503 is a'little' longer than that...
you can break
**and, &&, or, ||**
in statements by escaping a newline...I leave a space so before the escape
\
as I find it easier to read...if (Sketchup.active_model.tools.active_tool_name == 'ScaleTool' || \ Sketchup.active_model.tools.active_tool_name == 'CameraOrbitTool' || \ Sketchup.active_model.tools.active_tool_name == 'MoveTool' || \ Sketchup.active_model.tools.active_tool_name == 'RotateTool' ) p "waiting for #{Sketchup.active_model.tools.active_tool_name}" else # whatever end
john
-
Hi driven
70 chars per line are very small but I'm making my best for reducing more an more. Fortunately we are speaking about Sketchup Scrambler not ruby. Using your way I think a might be able to decrease the numbers of characters per line down to 250 even 125 but no more.
Result in some hours...
Have a good day
Advertisement