Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define GSH_BLOCK_MAGIC 0x424C4B7B // BLK{
- #define BLOCK_TYPE_VERTEX_SHADER_STRUCT 3
- #define BLOCK_TYPE_VERTEX_SHADER_PROGRAM 5
- #define BLOCK_TYPE_PIXEL_SHADER_STRUCT 6
- #define BLOCK_TYPE_PIXEL_SHADER_PROGRAM 7
- typedef unsigned int u32;
- static inline u32 be32(u32 a)
- {
- return ((a & 0xFF) << 24) | (((a >> 8) & 0xFF) << 16) | (((a >> 16) & 0xFF) << 8) | (((a >> 24) & 0xFF) << 0);
- }
- typedef struct _gsh_header_t
- {
- u32 magic;
- u32 header_size;
- u32 unk[6];
- } __attribute__((packed)) gsh_header_t;
- typedef struct _gsh_blk_header_t
- {
- u32 magic;
- u32 header_size;
- u32 unk[2];
- u32 block_type;
- u32 block_data_size;
- u32 unk2[2];
- } __attribute__((packed)) gsh_blk_header_t;
- int main(int argc, char *argv[])
- {
- if(argc < 2)
- return 1;
- FILE *f = fopen(argv[1], "rb");
- if(!f)
- return 0;
- fseek(f, 0, SEEK_END);
- unsigned int size = ftell(f);
- fseek(f, 0, SEEK_SET);
- unsigned char *gshBuffer = (unsigned char *)malloc(size);
- fread(gshBuffer, 1, size, f);
- fclose(f);
- gsh_header_t *header = (gsh_header_t *)gshBuffer;
- unsigned char *ptr = gshBuffer + be32(header->header_size);
- gsh_blk_header_t *block = (gsh_blk_header_t*) ptr;
- while(be32(block->magic) == GSH_BLOCK_MAGIC)
- {
- ptr = (unsigned char *)(ptr + be32(block->header_size));
- switch(be32(block->block_type))
- {
- case BLOCK_TYPE_VERTEX_SHADER_STRUCT:
- printf("BLOCK_TYPE_VERTEX_SHADER_STRUCT\n");
- break;
- case BLOCK_TYPE_PIXEL_SHADER_STRUCT:
- printf("BLOCK_TYPE_PIXEL_SHADER_STRUCT\n");
- break;
- case BLOCK_TYPE_VERTEX_SHADER_PROGRAM:
- printf("BLOCK_TYPE_VERTEX_SHADER_PROGRAM\n");
- break;
- case BLOCK_TYPE_PIXEL_SHADER_PROGRAM:
- printf("BLOCK_TYPE_PIXEL_SHADER_PROGRAM\n");
- break;
- default:
- printf("Unknown block type %i\n", be32(block->block_type));
- break;
- }
- for(int i = 0; i < be32(block->block_data_size); i++)
- {
- if(i % 16 == 0)
- printf("\n");
- printf("0x%02X, ", ptr[i]);
- }
- printf("\n\n");
- ptr = (unsigned char *)(ptr + be32(block->block_data_size));
- block = (gsh_blk_header_t*) ptr;
- }
- free(gshBuffer);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement