Embroidermodder / libembroidery

Library for reading/writing/manipulating machine and design embroidery files
https://www.libembroidery.org
zlib License
45 stars 13 forks source link

Deobfuscation #66

Closed robin-swift closed 2 years ago

robin-swift commented 2 years ago

@JoshVarga Do you know where this originally comes from?

Deobfuscating this mess should be a priority, but since the code already doesn't work right (try ./embroider test01.csv test01.hus && ./embroider test01.hus test01_processed.csv && cat test*.csv, it doesn't encode/decode properly).

Perhaps it's safer to strip this out entirely and do more research into the format, rather than attempt to correct broken code that's heavily obfuscated? I'd even put in the labour to manually work out the encoding based on some hus source files if we can just pull this code out.

robin-swift commented 2 years ago

So the format is documented here. Quoting:

The section is compressed using the proprietary ArchiveLib compression library made by Greenleaf Software (http://www.greenleafsoft.com). This library supports several different compression schemes, but the one used in this case is called AL_GREENLEAF_LEVEL_4. Once decompressed, the data should be exactly NumberOfStitches bytes in length with each byte sequentially representing one stitch of the pattern.

Which is repeated for stitch x then stitch y giving 3 sections in the same encryption.

Chasing this further the specifics have already been hashed out by the pyembroidery dev so we can translate that back into C for our more embedded systems friendly library and give a attribution at the top of the file to the specific file we translated (which is under the compatible MIT license).

Cheers,

Robin

robin-swift commented 2 years ago

I'm working on that translation, here's the attribution I'd use:

/*
    Thanks to Jason Weiler for describing the binary formats of the HUS and
    VIP formats at:

    http://www.jasonweiler.com/HUSandVIPFileFormatInfo.html

    Further thanks to github user tatarize for solving the mystery of the
    compression in:

    https://github.com/EmbroidePy/pyembroidery

    with a description of that work here:

    https://stackoverflow.com/questions/7852670/greenleaf-archive-library

    This is based on their work.
*/
JoshVarga commented 2 years ago

This has worked, I will review what has changed. Originally I found that the greenleaf software was being used, but no longer exists. I was able to mimic what the original code was doing, but never spent the time to fully understand it. Tatarize took the original functioning code and ported it. I am not sure who deobfuscated the code. We may be able to port the deobfuscated code back.