Thread: How To Incorporate input_byte In For Loop Query ?

  1. #16
    Registered User
    Join Date
    Jan 2023
    Posts
    39
    Hi Salem,

    Here attached to this post, is a zip file with some of the Greyscale .bmp Files, that I got when I ran the Code, on the other Game Graphics Files.

    The Program is guessing, rather than using exact dimensions of the Graphics, it's a custom Run Length Encoding compression. I know brute forcing combinations isn't the best method, to get results, but is it possible with this code ?

    How could it be done, with what I have said so far ?

    How could this part of the Code, being initialised, be repeated with a for loop ?

    To try out all the Hex Value combinations, bar the ones I would like excluded ? :-

    Code:
                if(input_byte == 0xFF) {                    //==============
                        // Fin de chunk
                        //==============
                        Save();
                        current_output_index++;
    
    
                        RLE_sumador            = 0;
                        line_min_length        = int.MaxValue;
                        line_max_length        = 0;
                        width_current        = 0;
                        image_height        = 0;
    
    
                    } else if(input_byte == 0xFE) {
                        //=================
                        // Siguiente linea
                        //=================
                        if(width_current < line_min_length) line_min_length = width_current;
                        if(width_current > line_max_length) line_max_length = width_current;
    
    
                        if(forced_image_width!=null) {
                            count = forced_image_width.Value - width_current;
                            if(count > 0) {
                                for(n=0; n<count; n++) {
                                    output_buffer.Add(0);
                                }
                            }
                        }
    
    
                        image_height++;
                        width_current = 0;
    
    
                    } else if(input_byte == 0xFD) {
                        count = (int) (input_data[current_input_position]) + 1;
                        current_input_position++;
    
    
                        b = input_data[current_input_position];
                        current_input_position++;
    
    
                        for(n=0; n<count; n++) {
                            output_buffer.Add(b);
                        }
    
    
                        width_current += count;
    
    
                    } else if(input_byte == 0xFC) {
                        b = input_data[current_input_position];
                        current_input_position++;
    
    
                        b2 = (byte)(b + 1);
    
    
                        count = (int) (input_data[current_input_position]) + 1;
                        current_input_position++;
    
    
                        RLE_FC_swap = false;
                        for(n=0; n<count; n++) {
                            output_buffer.Add(
                                RLE_FC_swap ? b2 : b
                            );
                            RLE_FC_swap = !RLE_FC_swap;
                        }
    
    
                        width_current += count;
    
    
                    } else if(input_byte == 0xFB) {
                        RLE_sumador = input_data[current_input_position];
                        current_input_position++;
    
    
                    } else {
                        b = (byte)(input_byte >> 2);
                        b += RLE_sumador;
                        count = (input_byte & 3) + 1;
    
    
                        for(n=0; n<count; n++) {
                            output_buffer.Add(b);
                        }
    
    
                        width_current += count;
                    }
                }
    
    
                Save();
            }
    I can't think of a way.
    Attached Files Attached Files
    Last edited by eddywinch82; 01-14-2023 at 09:37 AM.

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,669
    What about the input files you're trying to pick apart?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #18
    Registered User
    Join Date
    Jan 2023
    Posts
    39
    Hi Salem,

    I have attached on of those .PAC Files I have been experimenting with just one.
    Attached Files Attached Files

  4. #19
    Registered User
    Join Date
    Dec 2017
    Posts
    1,652
    Are you saying that 110DASH.PAC (15969 bytes) expands into one of those bmps (61238 bytes, 320x188pixels) ?
    If that's the case it would be most useful to have a PAC and it's associated bmp.
    And that's the world in a nutshell, an appropriate receptacle.

  5. #20
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,669
    I'm somewhat confused.

    The PAC file contains only codes FD, FE and a single FF right at the end - so far, so good.
    But it doesn't tell us anything about whether your FC or FB handling code is right or not.

    Throwing the PAC file into a hex editor, and marking out the bytes of interest gets us this.How To Incorporate input_byte In For Loop Query ?-pac_hexdump-png

    So according to your code, the first 6 bytes of "fd 2e 03 fd 6d 00" should result in
    - a run of 46(0x2e) bytes of 0x03
    - a run of 109(0x6d) bytes of 0x00

    None of the BMP files in the previous zip file contain anything like that.

    The first break in the pattern is what to do with "39 42 39".
    Are these just copied to the output until you get to the next 0xF? byte?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #21
    Registered User
    Join Date
    Jan 2023
    Posts
    39
    Hi Salem and john.c,

    I have attached two .PNL Files and the output .bmp Files as separate .zip Files. Even though, they are not .PAC Files Files, it still worked, from the Game where these extracted to .bmps. The 110DASH.PAC File, is from the latest game I am trying the Code on, with no success so far, the File is not from the Game, where the .PNL Files are from. Dash I would assume is the Dashboard image, like with the latest Files I have uploaded.
    Attached Files Attached Files
    Last edited by eddywinch82; 01-14-2023 at 12:04 PM.

  7. #22
    Registered User
    Join Date
    Dec 2017
    Posts
    1,652
    I was able to decode the PAC file to this ragged image:
    How To Incorporate input_byte In For Loop Query ?-img-png

    How exactly do you plan to brute force this into the correct image?

    I used this C program to create the image. Maybe I output the binary PGM file incorrectly? (I uploaded it above as a PNG.)
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdbool.h>
    #include <limits.h>
     
    char output_buffer[250000];
    int bufsize = 0;
     
    void Save() {
        printf("P5\n320 192\n255\n");
        for (int i = 0; i < bufsize; ++i)
            putchar(output_buffer[i]);
    }
     
    void Add(int byte) {
        output_buffer[bufsize++] = byte;
    }
     
    int main() {
        int current_output_index = 0;
        int RLE_sumador = 0;
        int line_min_length = INT_MAX, line_max_length = 0;
        int width_current = 0, image_height = 0;
        int count = 0, n = 0;
        int forced_image_width = 320;
        int b, b2;
        bool RLE_FC_swap = false;
     
        for (int input_byte; (input_byte = getchar()) != EOF; ) {
            if (input_byte == 0xFF) {
                // Finish chunk
                fprintf(stderr, "line_min_length: %d\n", line_min_length);
                fprintf(stderr, "line_max_length: %d\n", line_max_length);
                Save();
                current_output_index++;
                RLE_sumador     = 0;
                line_min_length = INT_MAX;
                line_max_length = 0;
                width_current   = 0;
                image_height    = 0;
      
            } else if (input_byte == 0xFE) {
                // Next line
                if (width_current < line_min_length)
                    line_min_length = width_current;
                if (width_current > line_max_length)
                    line_max_length = width_current;
                if (forced_image_width) {
                    count = forced_image_width - width_current;
                    if (count > 0)
                        for (n = 0; n < count; n++)
                            output_buffer[bufsize++] = 0;
                }
                image_height++;
                fprintf(stderr, "%d %d\n", image_height, width_current);
                width_current = 0;
      
            } else if (input_byte == 0xFD) {
                count = getchar() + 1;
                b = getchar();
                for (n = 0; n < count; n++)
                    output_buffer[bufsize++] = b;
                width_current += count;
      
            } else if (input_byte == 0xFC) {
                b = getchar() + 1;
                b2 = b + 1;
                count = getchar() + 1;
                RLE_FC_swap = false;
                for (n = 0; n < count; n++) {
                    output_buffer[bufsize++] = RLE_FC_swap ? b2 : b;
                    RLE_FC_swap = !RLE_FC_swap;
                }
                width_current += count;
      
            } else if (input_byte == 0xFB) {
                RLE_sumador = getchar();
      
            } else {
                b = input_byte >> 2;
                b += RLE_sumador;
                count = (input_byte & 3) + 1;
                for (n = 0; n < count; n++)
                    output_buffer[bufsize++] = b;
                width_current += count;
            }
        }
     
        Save();
     
        return 0;
    }
    BTW, there are no 0xFB or 0xFC in the PAC file.
    Last edited by john.c; 01-14-2023 at 12:45 PM.
    And that's the world in a nutshell, an appropriate receptacle.

  8. #23
    Registered User
    Join Date
    Jan 2023
    Posts
    39
    How did you do that john.c ? thats fantastic I see a Dashboard in there. I am very impressed you're amazing, did you adapt a C Code, or write that from scratch ? ))
    Last edited by eddywinch82; 01-14-2023 at 12:57 PM.

  9. #24
    Registered User
    Join Date
    Jan 2023
    Posts
    39
    Hi john.c

    Here below I have posted the other Code that make up the unpac c# Program it's called Bitmap.cs.

    I am not sure how to get the text in the correct layout, as it was in Visual Studio, could someone alter the text, in the code I have posted ? if that is okay ? :-

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    
    
    
    namespace Unpac {
        public static class Bitmap {
    
    
            private static byte[]            Header;
            private readonly static byte[]    Paleta;
    
    
            static Bitmap() {
                Header = new byte[0x436];
                Header[0] = 0x42;
                Header[1] = 0x4D;
                Header[0xA] = 0x36;
                Header[0xB] = 0x04;
                Header[0xE] = 0x28;
                Header[0x1A] = 1;
                Header[0x1C] = 8;
                Header[0x26] = 0x12;
                Header[0x27] = 0x0B;
                Header[0x2A] = 0x12;
                Header[0x2B] = 0x0B;
    
    
                
                // Grayscale palette
                int    dst_pos = 0x36;
                int color;
                for(color=0; color<0x100; color++) {
                    Header[dst_pos++] = (byte) (color << 2);
                    Header[dst_pos++] = (byte) (color << 2);
                    Header[dst_pos++] = (byte) (color << 2);
                    dst_pos++;
                }
    
    
                
                /*Paleta = new byte[] {
                    0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x05, 0x05, 0x05, 0x08, 0x08, 0x08, 0x0A, 0x0A, 0x0A, 0x0D,
                    0x0D, 0x0D, 0x10, 0x10, 0x10, 0x13, 0x13, 0x13, 0x16, 0x16, 0x16, 0x19, 0x19, 0x19, 0x1C, 0x1C,
                    0x1C, 0x1F, 0x1F, 0x1F, 0x22, 0x22, 0x22, 0x25, 0x25, 0x25, 0x27, 0x27, 0x27, 0x2A, 0x2A, 0x2A,
                    0x2D, 0x2D, 0x2D, 0x30, 0x30, 0x30, 0x33, 0x33, 0x33, 0x36, 0x36, 0x36, 0x39, 0x39, 0x39, 0x3C,
                    0x3C, 0x3C, 0x3F, 0x3F, 0x3F, 0x19, 0x3F, 0x19, 0x0F, 0x32, 0x0F, 0x08, 0x25, 0x08, 0x03, 0x19,
                    0x03, 0x39, 0x0C, 0x0C, 0x2E, 0x06, 0x06, 0x23, 0x01, 0x01, 0x18, 0x00, 0x00, 0x15, 0x3F, 0x3F,
                    0x00, 0x00, 0x00, 0x3F, 0x3F, 0x3F, 0x2C, 0x00, 0x00, 0x00, 0x17, 0x00, 0x3F, 0x38, 0x1F, 0x3C,
                    0x34, 0x1A, 0x39, 0x30, 0x16, 0x36, 0x2C, 0x12, 0x33, 0x28, 0x0E, 0x31, 0x24, 0x0B, 0x2E, 0x20,
                    0x08, 0x2B, 0x1D, 0x05, 0x28, 0x19, 0x03, 0x25, 0x16, 0x01, 0x23, 0x13, 0x00, 0x19, 0x27, 0x2E,
                    0x18, 0x18, 0x18, 0x1E, 0x1E, 0x1E, 0x0B, 0x0B, 0x0B, 0x2A, 0x00, 0x2A, 0x2A, 0x00, 0x2A, 0x2A,
                    0x00, 0x2A, 0x2A, 0x00, 0x2A, 0x2A, 0x00, 0x2A, 0x2A, 0x00, 0x2A, 0x2A, 0x00, 0x2A, 0x2A, 0x00,
                    0x2A, 0x2A, 0x00, 0x2A, 0x2A, 0x00, 0x2A, 0x2A, 0x00, 0x2A, 0x2A, 0x00, 0x2A, 0x2A, 0x00, 0x2A,
                    0x1E, 0x20, 0x20, 0x12, 0x12, 0x12, 0x10, 0x10, 0x10, 0x0F, 0x0F, 0x0F, 0x0E, 0x0E, 0x0E, 0x0D,
                    0x0D, 0x0D, 0x0C, 0x0C, 0x0C, 0x0B, 0x0B, 0x0B, 0x00, 0x0C, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x08,
                    0x00, 0x00, 0x06, 0x00, 0x0B, 0x0C, 0x06, 0x0A, 0x0B, 0x06, 0x09, 0x0A, 0x06, 0x06, 0x06, 0x00,
                    0x09, 0x0A, 0x0A, 0x0D, 0x0D, 0x0D, 0x12, 0x12, 0x12, 0x19, 0x19, 0x19, 0x2B, 0x02, 0x00, 0x33,
                    0x1A, 0x06, 0x39, 0x2B, 0x0C, 0x3C, 0x33, 0x0F, 0x02, 0x11, 0x03, 0x07, 0x16, 0x06, 0x0F, 0x1B,
                    0x0D, 0x2F, 0x19, 0x12, 0x31, 0x31, 0x31, 0x35, 0x35, 0x35, 0x3A, 0x3A, 0x3A, 0x3F, 0x3F, 0x3F,
                    0x31, 0x3D, 0x3D, 0x2E, 0x3D, 0x3D, 0x2B, 0x3D, 0x3D, 0x28, 0x3D, 0x3D, 0x22, 0x3D, 0x3D, 0x1A,
                    0x3D, 0x3D, 0x17, 0x3B, 0x3D, 0x17, 0x39, 0x3D, 0x16, 0x38, 0x3D, 0x15, 0x37, 0x3D, 0x14, 0x36,
                    0x3D, 0x12, 0x34, 0x3D, 0x14, 0x28, 0x12, 0x00, 0x22, 0x0A, 0x00, 0x20, 0x09, 0x00, 0x1F, 0x08,
                    0x00, 0x1E, 0x07, 0x00, 0x1D, 0x06, 0x00, 0x1C, 0x05, 0x00, 0x1B, 0x04, 0x0E, 0x18, 0x2D, 0x00,
                    0x12, 0x22, 0x00, 0x11, 0x21, 0x00, 0x10, 0x20, 0x00, 0x0F, 0x1F, 0x00, 0x0E, 0x1E, 0x00, 0x0D,
                    0x1D, 0x00, 0x0C, 0x1C, 0x0F, 0x23, 0x0E, 0x01, 0x1A, 0x05, 0x00, 0x19, 0x04, 0x00, 0x18, 0x03,
                    0x00, 0x17, 0x02, 0x00, 0x16, 0x01, 0x00, 0x15, 0x00, 0x00, 0x14, 0x00, 0x13, 0x27, 0x15, 0x00,
                    0x1F, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x1D, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x1A,
                    0x00, 0x00, 0x19, 0x00, 0x22, 0x22, 0x22, 0x18, 0x18, 0x17, 0x16, 0x16, 0x16, 0x15, 0x15, 0x15,
                    0x14, 0x14, 0x14, 0x13, 0x13, 0x13, 0x12, 0x12, 0x12, 0x11, 0x11, 0x11, 0x11, 0x25, 0x13, 0x00,
                    0x1D, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x1A, 0x00, 0x00, 0x19, 0x00, 0x00, 0x18,
                    0x00, 0x00, 0x17, 0x00, 0x0A, 0x06, 0x00, 0x0E, 0x09, 0x00, 0x0F, 0x0C, 0x00, 0x13, 0x0F, 0x00,
                    0x19, 0x14, 0x00, 0x1A, 0x16, 0x00, 0x22, 0x1C, 0x12, 0x26, 0x22, 0x18, 0x2A, 0x2B, 0x1D, 0x20,
                    0x21, 0x0A, 0x1E, 0x1F, 0x08, 0x1D, 0x1E, 0x07, 0x1C, 0x1D, 0x06, 0x1B, 0x1C, 0x06, 0x1A, 0x1B,
                    0x06, 0x19, 0x1A, 0x06, 0x1B, 0x00, 0x00, 0x15, 0x00, 0x00, 0x20, 0x0A, 0x00, 0x1C, 0x08, 0x00,
                    0x04, 0x16, 0x09, 0x06, 0x1A, 0x0B, 0x09, 0x1C, 0x0D, 0x0A, 0x21, 0x2D, 0x06, 0x1C, 0x2E, 0x2B,
                    0x29, 0x35, 0x26, 0x25, 0x34, 0x2F, 0x2D, 0x36, 0x00, 0x12, 0x09, 0x38, 0x38, 0x38, 0x00, 0x0E,
                    0x08, 0x0A, 0x21, 0x22, 0x06, 0x1C, 0x1C, 0x2B, 0x29, 0x35, 0x26, 0x25, 0x34, 0x2F, 0x2D, 0x36,
                    0x00, 0x0E, 0x00, 0x04, 0x15, 0x04, 0x00, 0x18, 0x00, 0x08, 0x1D, 0x08, 0x1E, 0x20, 0x32, 0x2B,
                    0x29, 0x35, 0x3F, 0x15, 0x3F, 0x32, 0x00, 0x32, 0x08, 0x0E, 0x00, 0x0A, 0x11, 0x04, 0x11, 0x13,
                    0x00, 0x16, 0x18, 0x00, 0x23, 0x23, 0x1D, 0x2A, 0x29, 0x24, 0x3F, 0x15, 0x3F, 0x32, 0x00, 0x32,
                    0x03, 0x13, 0x07, 0x05, 0x17, 0x0A, 0x08, 0x1A, 0x0C, 0x0A, 0x1D, 0x0E, 0x1A, 0x2C, 0x3F, 0x14,
                    0x28, 0x3F, 0x00, 0x26, 0x3F, 0x3F, 0x15, 0x3F, 0x05, 0x0B, 0x05, 0x00, 0x0A, 0x00, 0x00, 0x12,
                    0x00, 0x00, 0x15, 0x00, 0x1D, 0x23, 0x23, 0x1A, 0x1F, 0x1F, 0x16, 0x1A, 0x19, 0x3F, 0x15, 0x3F,
                    0x10, 0x14, 0x00, 0x12, 0x18, 0x00, 0x0F, 0x11, 0x00, 0x25, 0x25, 0x2A, 0x21, 0x21, 0x27, 0x21,
                    0x21, 0x26, 0x06, 0x0D, 0x00, 0x0B, 0x0F, 0x00, 0x30, 0x30, 0x36, 0x2A, 0x2C, 0x30, 0x27, 0x2A,
                    0x2D, 0x29, 0x29, 0x2E, 0x25, 0x25, 0x2B, 0x26, 0x26, 0x2B, 0x30, 0x32, 0x3C, 0x34, 0x35, 0x3F,
                    0x00, 0x00, 0x00, 0x00, 0x0C, 0x20, 0x00, 0x20, 0x00, 0x0E, 0x0E, 0x0E, 0x28, 0x00, 0x00, 0x10,
                    0x14, 0x00, 0x0A, 0x0A, 0x0A, 0x29, 0x29, 0x29, 0x0F, 0x0F, 0x0F, 0x00, 0x22, 0x2E, 0x00, 0x2C,
                    0x00, 0x00, 0x39, 0x39, 0x39, 0x00, 0x00, 0x38, 0x28, 0x00, 0x3F, 0x34, 0x00, 0x3F, 0x3F, 0x3F
                };
    
    
                
                int    src_pos = 0;
                int    dst_pos = 0x36;
                int color;
                for(color=0; color<0x100; color++) {
                    Header[dst_pos++] = (byte) (Paleta[src_pos++] << 2);
                    Header[dst_pos++] = (byte) (Paleta[src_pos++] << 2);
                    Header[dst_pos++] = (byte) (Paleta[src_pos++] << 2);
                    dst_pos++;
                }*/
    
    
                /*Paleta2 = new byte[] {
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03,
                    0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08,
                    0x09, 0x09, 0x09, 0x0A, 0x0A, 0x0A, 0x0B, 0x0B, 0x0B, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0E,
                    0x0E, 0x0E, 0x0F, 0x0E, 0x0E, 0x10, 0x0F, 0x0F, 0x11, 0x10, 0x10, 0x12, 0x11, 0x11, 0x13, 0x12,
                    0x12, 0x14, 0x13, 0x13, 0x15, 0x14, 0x14, 0x16, 0x15, 0x15, 0x17, 0x16, 0x16, 0x18, 0x17, 0x17,
                    0x19, 0x18, 0x18, 0x1A, 0x18, 0x18, 0x1B, 0x19, 0x19, 0x1C, 0x1A, 0x1A, 0x1D, 0x1B, 0x1B, 0x1E,
                    0x1C, 0x1C, 0x1F, 0x1D, 0x1D, 0x20, 0x1E, 0x1E, 0x21, 0x1F, 0x1F, 0x22, 0x20, 0x20, 0x23, 0x21,
                    0x21, 0x24, 0x22, 0x22, 0x25, 0x23, 0x23, 0x26, 0x24, 0x24, 0x27, 0x24, 0x24, 0x28, 0x25, 0x25,
                    0x29, 0x26, 0x26, 0x2A, 0x27, 0x27, 0x2B, 0x28, 0x28, 0x2C, 0x29, 0x29, 0x2D, 0x2A, 0x2A, 0x2E,
                    0x2B, 0x2B, 0x2F, 0x2C, 0x2C, 0x30, 0x2D, 0x2D, 0x31, 0x2E, 0x2E, 0x32, 0x2E, 0x2E, 0x33, 0x30,
                    0x30, 0x35, 0x30, 0x30, 0x36, 0x31, 0x31, 0x37, 0x32, 0x32, 0x38, 0x33, 0x33, 0x39, 0x34, 0x34,
                    0x3A, 0x35, 0x35, 0x3B, 0x36, 0x36, 0x3C, 0x37, 0x37, 0x3D, 0x38, 0x38, 0x3E, 0x39, 0x39, 0x3F
                };
    
    
                src_pos = 0;
                dst_pos = 0x36;
                for(color=0; color<64; color++) {
                    Header[dst_pos++] = (byte) (Paleta2[src_pos++] << 2);
                    Header[dst_pos++] = (byte) (Paleta2[src_pos++] << 2);
                    Header[dst_pos++] = (byte) (Paleta2[src_pos++] << 2);
                    dst_pos++;
                }*/
            }
    
    
            public static bool Save(string filename, byte[] image_data, int width, int height) {
                
                byte[]    output_array;
                int        image_length;
                int        file_size;
                int        width_dword_align_padding;
                int        width_virtual;
                bool    fix_alignment;
                int        n;
                int        pos_src, pos_dst;
                
    
    
                width_dword_align_padding = 4 - (width & 3);
                width_virtual = width;
                if(width_dword_align_padding != 4) width_virtual += width_dword_align_padding;
                fix_alignment = width != width_virtual;
    
    
                try {
                    image_length    = width_virtual * height;
                    file_size        = 0x436 + image_length;
                    output_array    = new byte[file_size];
                
                    // Header
                    System.Buffer.BlockCopy(Header, 0, output_array, 0, 0x436);
                    // Header File size
                    System.Buffer.BlockCopy(BitConverter.GetBytes(file_size), 0, output_array, 2, 4);
                    // Header image width
                    System.Buffer.BlockCopy(BitConverter.GetBytes(width), 0, output_array, 0x12, 4);
                    // Header image height
                    System.Buffer.BlockCopy(BitConverter.GetBytes(0 - height), 0, output_array, 0x16, 4);
    
    
                    if(fix_alignment) {
                        pos_src = 0;
                        pos_dst = 0x436;
                        for(n=0; n<height; n++) {
                            System.Buffer.BlockCopy(image_data, pos_src, output_array, pos_dst, width);
                            pos_src += width;
                            pos_dst += width_virtual;
                        }
    
    
                    } else {
                        System.Buffer.BlockCopy(image_data, 0, output_array, 0x436, image_length);
                    }
    
    
                    System.IO.File.WriteAllBytes(filename, output_array);
                } catch {
                    return false;
                }
    
    
                return true;
            }
    
    
        }
    }

  10. #25
    Registered User
    Join Date
    Dec 2017
    Posts
    1,652
    So what exactly were you trying to brute force?
    Why bytes only with letters in their hex representations?
    And that's the world in a nutshell, an appropriate receptacle.

  11. #26
    Registered User
    Join Date
    Dec 2017
    Posts
    1,652
    Are these just copied to the output until you get to the next 0xF? byte?
    The default byte handling is in the else clause:
    Code:
                b = input_byte >> 2;
                b += RLE_sumador;
                count = (input_byte & 3) + 1;
                for (n = 0; n < count; n++)
                    output_buffer[bufsize++] = b;
                width_current += count;
    So the value is in the top 6 bits while the count (less one) is stored in the low 2 bits.
    This means the values are limited to 0 to 63.
    However, the bmp palette apparently translates these over 2 bits.
    It strangely creates 4 copies of a grayscale color map, each using 1/4 of the palette.
    Code:
                for (color = 0; color < 0x100; color++) {
                    Header[dst_pos++] = (byte) (color << 2);
                    Header[dst_pos++] = (byte) (color << 2);
                    Header[dst_pos++] = (byte) (color << 2);
                    dst_pos++;
                }
    And that's the world in a nutshell, an appropriate receptacle.

  12. #27
    Registered User
    Join Date
    Jan 2023
    Posts
    39
    Hi John,

    I knew for certain that all input_byte == as numbers only Hex Values, would not yield any outputted bitmap Files. And I was hoping, by brute forcing as many hex value combinations, I may get some useful ones. Working backwards from 0xFF as I felt it more likely, those higher combinations would get a result, so if I got something useful, I would end the process.

  13. #28
    Registered User
    Join Date
    Dec 2017
    Posts
    1,652
    Your description of what you are trying to do is unintelligible.

    by brute forcing as many hex value combinations
    "Brute forcing" how? In what way are you thinking of using them?
    Last edited by john.c; 01-14-2023 at 02:11 PM.
    And that's the world in a nutshell, an appropriate receptacle.

  14. #29
    Registered User
    Join Date
    Jan 2023
    Posts
    39
    Quote Originally Posted by john.c View Post
    Your description of what you are trying to do is unintelligible.


    "Brute forcing" how? In what way are you thinking of using them?
    Hi John,

    I should have said from the outset, but this program was written for me by someone I found on Freelancer.com, the persons first language wasn't English, and he said to explain the RLE Algorithm, would take too long.

    So apart from what you have established, of how parts of the Code work and mean, I don't know exactly how the Program.cs code works. So I don't exactly know how, the Hex Values are used, in the Code. But your insights are helping me understand more.
    Last edited by eddywinch82; 01-14-2023 at 02:40 PM.

  15. #30
    Registered User
    Join Date
    Jan 2023
    Posts
    39
    Hi John,

    Have you made any progress, with the codes, you were working on yesterday ?

    Eddie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. While Loop Query - code displayed
    By darren78 in forum C Programming
    Replies: 13
    Last Post: 02-17-2009, 10:44 AM
  2. first look incorporate assembly?
    By stabu in forum C Programming
    Replies: 8
    Last Post: 09-25-2008, 08:53 AM
  3. Loop Query
    By (TNT) in forum C# Programming
    Replies: 5
    Last Post: 02-13-2006, 06:16 PM
  4. How can I incorporate this code into a web page?
    By MisterRob in forum C Programming
    Replies: 6
    Last Post: 11-02-2005, 05:43 PM
  5. Best way to incorporate upgrades
    By Shadow12345 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-26-2002, 07:41 AM

Tags for this Thread