0

I made 2 memory dump files with iOS, and I want to see the difference between these files. I made them with gdb (idk if this is important or not). I read a tutorial to do these dumps, and he said this: "7. Compare your 2 dumps (tons of tutorials online on how to compare dumps, Sketch will probably write one.)" I spent three hours to find nothing about this "Sketch" but I only found a mac "paint app" called Sketch. I want to do it all without pc (I have windows and ubuntu), if possible, but if not than ok, no problem. I tried cmp dump1.dmp dump2.dmp and cmp -l dump1.dmp dump2.dmp nothing happened. It will be important if you can help for me :) Thanks for any help :)

Robin Vekety
  • 89
  • 3
  • 9

1 Answers1

0

I think you want the difference between two binary files. Here is something you can get started with.

It counts the number of different 8 byte blocks in two files, but you can modify it to suit your needs.

#include <string>
#include <fstream>
#include <iostream>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
using namespace std;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
uint64_t filebytes( ifstream & f ) {
    f.seekg( 0, f.end );
    const uint64_t l = f.tellg();
    f.seekg( 0, f.beg );

    return l;
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
int main( int argc, char ** argv ) {

    assert( argc == 3 );

    ifstream file0( argv[1], ifstream::binary );
    ifstream file1( argv[2], ifstream::binary );

    assert( file0.is_open() );
    assert( file1.is_open() );
    assert( file0.good() );
    assert( file1.good() );

    const uint64_t f0bytes = filebytes( file0 );
    const uint64_t f1bytes = filebytes( file1 );
    assert( f0bytes == f1bytes );
    assert( f0bytes % sizeof( uint64_t ) == 0ULL );

    const uint64_t numWords = f0bytes / sizeof( uint64_t );

    uint64_t word0;
    uint64_t word1;
    uint64_t numDiffs = 0ULL;
    char * p0 = (char*) &word0;
    char * p1 = (char*) &word1;

    for( uint64_t wordIdx = 0ULL; wordIdx < numWords; wordIdx++ ) {

        file0.read( p0, sizeof( uint64_t ) );
        file1.read( p1, sizeof( uint64_t ) );

        if( word0 != word1 ) {
            numDiffs++;
        }

        assert( !file0.eof() );
        assert( !file1.eof() );
    }
    cout << "numWords = " << numWords << endl;
    cout << "numDiffs = " << numDiffs << endl;
    cout << "fraction = " << double( numDiffs ) / double( numWords ) << endl;

    return 0;
}
etep
  • 93
  • 5