Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@apk
Created September 22, 2011 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apk/1235596 to your computer and use it in GitHub Desktop.
Save apk/1235596 to your computer and use it in GitHub Desktop.
Program that scrapes the big wav file from the damaged filesystem (FAT borked); throwaway code
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
int iszero (char *buf, int size) {
int i;
int z = 0;
for (i = 0; i < size; i ++) {
if (buf [i] == 0) z ++;
}
return z + 100 >= size;
}
int main () {
int fd = open ("/Volumes/Ext/8gb.dump", 0);
int i;
long long p = 101122048;
int lz = 0;
int z = 0;
int ofd = creat ("o1.wav", 644);
lseek (fd, p, 0);
for (i = 0; i <= 29100; i ++) {
char buf [32768];
int r = read (fd, buf, sizeof (buf));
if (r != sizeof (buf)) {
printf ("Hey!\n");
return 1;
}
if (iszero (buf, sizeof (buf))) {
printf ("Zero %d (%d)\n", i, i - lz);
lz = i;
z ++;
if (z > 20) {
printf ("Enough\n");
break;
}
continue;
}
z = 0;
r = write (ofd, buf, sizeof (buf));
if (r != sizeof (buf)) {
printf ("Yeh!\n");
return 1;
}
}
close (fd);
close (ofd);
}
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
static void dofile (char *fn) {
long long pos = 0;
int fd = open (fn, 0);
if (fd == -1) {
printf ("Can't open %s\n", fn);
return;
}
while (1) {
char buf [65536];
int i;
int r = read (fd, buf, sizeof (buf));
if (r != sizeof (buf)) {
printf ("Read only %d bytes at %llx\n", r, pos);
close (fd);
return;
}
for (i = 0; i < sizeof (buf); i += 512) {
if (buf [i] == 'R' &&
buf [i + 1] == 'I' &&
buf [i + 2] == 'F' &&
buf [i + 3] == 'F')
{
int k;
for (k = 0; k < 16; k ++) {
char c = buf [i + k];
printf ("%c",
c > ' ' && c <= '~' ? c : '.');
}
printf (" at %llx (%lld)\n",
pos + i,
pos + i);
}
}
pos += sizeof (buf);
}
close (fd);
}
int main (int argc, char **argv) {
int i;
for (i = 1; i < argc; i ++) {
dofile (argv [i]);
}
return 0;
}
@apk
Copy link
Author

apk commented Sep 22, 2011

riff finds the start of the wav files, the other thingie scrapes them from disk, assuming linear storage with a few blocks omitted (i have no idea why it did that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment