Thanks Thanks:  5
Likes Likes:  2
Dislikes Dislikes:  0
Results 1 to 4 of 4
  1. #1
    3D Printer Noob
    Join Date
    Mar 2017
    Post Thanks / Like

    .cube3 file decoder

    I have never been able to get the cube-decoder on github to work so I sat down with a friend last night and rewrote the code a bit. So here is the compiled program. We will post the source later this month once it has been cleaned up a bit. *note* I don't think this will work with .cubepro files but it should work all .cube3 files. If you do have issues, please post your .cube3 for me to look at. To run the program just drag your .cube3 onto the decoder and it should output a .bfb in the same directory as your input.


    Edit: My friend is doing more work on the program to make it function closer to what the OP wanted. He said he is going to upload it to github once he is done adding options for the cubex, cubepro < V2.0, and image prefix detection. I will add his link/credit once its posted. In the mean time I wanted to go ahead and post the code for this program (solution for just .cube3 files)The blowfish includes can be found here on the OP's original page:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <assert.h>
    #include "blowfish.h"
    long int fsize(FILE *f) {
    long int original, size;
    original = ftell(f);
    fseek(f, 0, SEEK_END);
    size = ftell(f);
    fseek(f, original, SEEK_SET);
    return size;
    struct file_struct {
    size_t size;
    BYTE *data;
    struct file_struct *create_file_struct(size_t size, BYTE *data);
    struct file_struct *read_file(char *name);
    struct file_struct *truncate_padding(struct file_struct *data);
    void load_data(BYTE *data, size_t infilesize, FILE *infile);
    void decrypt(struct file_struct *data, char *userkey);
    void write_file(FILE *outfile, struct file_struct *data);
    void save_output_file(char *name, struct file_struct *f);
    BYTE *allocate_data(size_t size);
    FILE *get_file(char *infilename);
    FILE *get_output_file(char *name);
    size_t get_file_size(FILE *infile);
    size_t get_model_data_offset(BYTE *data, size_t size);
    int main(int argc, char **argv) {
    char cubepro_key[] = "221BBakerMycroft";
    char bfb[] = ".bfb";
    char *infilename;
    char *outfilename;
    if (argc < 2) {
    return -1;
    infilename = argv[1]; //assign argument
    struct file_struct *f = truncate_padding(read_file(infilename)); //read input file and remove prefix
    decrypt(f, cubepro_key); //run data through blowfish
        outfilename = strcat(infilename, bfb); //make outfile name
    save_output_file(outfilename, f); //save output file
    return 0;
    FILE *get_file(char *infilename) {
    FILE *infile = fopen(infilename, "rb");
    if (infile == NULL) {
    perror("Unable to open input file");
    return infile;
    size_t get_file_size(FILE *infile) {
    size_t infilesize = fsize(infile);
    if (infilesize < 0) {
    perror("Unable to determine size of input file");
    return 3;
    return infilesize;
    BYTE *allocate_data(size_t size) {
    BYTE *data = malloc(size); 
    if (data == NULL) {
    perror("Unable to allocate memory for input file");
    return data;
    void load_data(BYTE *data, size_t infilesize, FILE *infile) {
    size_t readcount = fread(data, 1, infilesize, infile);
    if (readcount != infilesize) {
    printf("Unable to read the whole input file: %zd != %zd\n", readcount, infilesize);
    struct file_struct *create_file_struct(size_t size, BYTE *data) {
    struct file_struct *f = malloc(sizeof(struct file_struct));
    f->size = size;
    f->data = data;
    return f;
    struct file_struct *read_file(char *name) {
    FILE *infile = get_file(name);
    size_t size = get_file_size(infile);
    BYTE *data = allocate_data(size);
    load_data(data, size, infile);
    return create_file_struct(size, data);
    size_t get_model_data_offset(BYTE *data, size_t size) {
        int i;
    for (i=0; i < size; i++) {
    if (data[i] == 0xc8) {
    return i;
    struct file_struct *truncate_padding(struct file_struct *data) {
    size_t offset = get_model_data_offset(data->data, data->size);
    size_t truncated_size = data->size - offset;
    BYTE *truncated_data = malloc(truncated_size);
    memcpy(truncated_data, data->data+offset, truncated_size );
    return create_file_struct(truncated_size, truncated_data);
    void decrypt(struct file_struct *data, char *userkey) {
    blowfish_key_setup((BYTE*) userkey, &key, strlen(userkey));
    int i;
    for (i = 0; i < data->size; i += 8) {
    blowfish_decrypt(&data->data[i], &data->data[i], &key, 1);
    FILE *get_output_file(char *name) {
    FILE *outfile = fopen(name, "wb");
    if (outfile == NULL) {
    perror("Unable to open output file");
    return outfile;
    void write_file(FILE *outfile, struct file_struct *data) {
    size_t writecount = fwrite(data->data, 1, data->size, outfile);
    if (writecount != data->size) {
    printf("Unable to write the whole output file: %zd != %zd\n", writecount, data->size);
    void save_output_file(char *name, struct file_struct *f) {
    FILE *outfile = get_output_file(name);
    write_file(outfile, f);
    Last edited by swwinterry; 10-10-2017 at 12:32 AM.

  2. Thanks bolsoncerrado, TommyDee, ztoddman1, AdamKempenich thanked for this post
    Likes bolsoncerrado, garufa liked this post
  3. #2
    Administrator bolsoncerrado's Avatar
    Join Date
    Nov 2014
    Post Thanks / Like
    THanks for sharing!

  4. #3
    3D Printer Noob
    Join Date
    Mar 2017
    Post Thanks / Like
    If anyone has any ideas for dealing with the .cubepro files I'm all ears. This program works by reading in the file, searching for 0xC8 (the char where the gcode starts), chopping off the prefix then running it through the blowfish algorithm. I can't seem to figure out how the .cubepro files are formatted. When I cut off the prefix (or what I think is the prefix) on the .cubepro files and run it through blowfish I get these 25 lines then encrypted nonsense after that.
    ^Time: 139
    - - - - - - - - - -

    The source is now posted at the top. Feel free to let me know if you have any questions.
    Last edited by swwinterry; 09-22-2017 at 08:20 PM.

  5. Thanks garufa thanked for this post
  6. #4
    3D Printer God(dess)
    Join Date
    Nov 2016
    Post Thanks / Like
    How did I overlook this.
    This is the 1st decoder I got working.


    Much thanks!

    - - - - - - - - - -

    Yep, BFB files can be used for reverse engineering.
    I've been wondering about that.
    Not easy but possible.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts