Skip to content

Instantly share code, notes, and snippets.

@bluerise bluerise/swizzle.c
Created Jul 19, 2017

Embed
What would you like to do?
Swizzle extraction toolkit
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
int check(uint8_t *);
void print(uint8_t *);
int
main(int argv, char **argc)
{
int fd = open("bios.rom", O_RDONLY);
if (fd < 0)
return 1;
struct stat st;
if (fstat(fd, &st) < 0)
return 2;
uint8_t *buf = malloc(st.st_size);
if (buf == NULL)
return 3;
if (read(fd, buf, st.st_size) != st.st_size)
return 4;
for (int off = 0; off < st.st_size - 32; off++)
if (check(buf+off)) {
printf("match at offset 0x%x:\n", off);
print(buf+off);
}
return 0;
}
int
check(uint8_t *buf)
{
uint32_t bits = 0;
for (int i = 0; i < 32; i++)
bits |= (1ULL << buf[i]);
if (bits == 0xffffffff)
return 1;
return 0;
}
void
print(uint8_t *buf)
{
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 8; j++)
printf("0x%02x, ", buf[i*8+j]);
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.