Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- static FILE *f;
- void doczytaj(unsigned char *p, int len) {
- if (fread(p, 1, len, f)!=len) {
- fprintf(stderr, "File too short\n");
- fclose(f);
- exit(1);
- }
- }
- unsigned long long getle(unsigned char *p, int bytes) {
- unsigned long long res=0;
- while (bytes--) {
- res|= p[bytes]<<(8*bytes);
- }
- return res;
- }
- unsigned long long getvl() {
- unsigned char b[8];
- doczytaj(b, 1);
- switch (*b) {
- case 0xfd:
- doczytaj(b, 2);
- return getle(b, 2);
- case 0xfe:
- doczytaj(b, 4);
- return getle(b, 4);
- case 0xff:
- doczytaj(b, 8);
- return getle(b, 8);
- }
- return *b;
- }
- void prhash(unsigned char *p, unsigned int l) {
- while (l--) printf("%02x", p[l]);
- }
- int main(int argc, char * argv[]) {
- static unsigned char buf[0x10000];
- unsigned long long i, sl, txcnt, v;
- if (argc!=2) {
- printf("Specify the filename of the transaction file (.btd)\n");
- return 1;
- }
- f = fopen(argv[1], "rb");
- if (!f) {
- fprintf(stderr, "File %s not found\n", argv[1]);
- return 1;
- }
- doczytaj(buf, 4);
- printf("Version: %llu\n", getle(buf, 4));
- txcnt = getvl();
- printf("TX IN cnt: %llu\n", txcnt);
- for (i=0; i<txcnt; i++) {
- doczytaj(buf, 36);
- sl = getvl();
- printf(" %lld) : ", i);
- prhash(buf, 32);
- printf(" Idx=%2lld sl=%lld", getle(buf+32, 4), sl);
- doczytaj(buf, sl);
- doczytaj(buf, 4);
- printf(" seq=%x\n", (unsigned)getle(buf, 4));
- }
- txcnt = getvl();
- printf("TX OUT cnt: %llu\n", txcnt);
- for (i=0; i<txcnt; i++) {
- doczytaj(buf, 8);
- sl = getvl();
- v = getle(buf, 8);
- printf(" %lld) : %lld.%8lld BTC sl=%lld\n", i, v/100000000, v%100000000, sl);
- doczytaj(buf, sl);
- }
- doczytaj(buf, 4);
- printf("Lock Time: %llu\n", getle(buf, 4));
- fclose(f);
- return 0;
- }
Add Comment
Please, Sign In to add comment