rdramPatch.c 1.57 KB
#include <stdio.h>
#include <stdlib.h>

#include <verify.h>

#define LIST_ADDR   (VERIFY_INFO_PHYSADDR + RDPLIST_ADDR_OFFSET)
#define COUNT_ADDR  (VERIFY_INFO_PHYSADDR + RDPLISTSIZE_OFFSET)

main (int argc,  char *argv[])
{
    FILE *fp;
    unsigned int newCount[2], temp;
    int count;
    unsigned long long int lcount;
    int startaddr;
    
    if (argc != 2) {
	fprintf(stderr, "Usage: %s memory_file\n", argv[0]);
	exit(1);
    }
    
    if ( (fp = fopen(argv[1], "r+")) == NULL) {
	fprintf(stderr, "Could not open %s\n", argv[1]);
	exit(1);
    }

    fseek(fp, LIST_ADDR, SEEK_SET);
    fread(&startaddr, sizeof (startaddr), 1, fp);

    fseek(fp, COUNT_ADDR, SEEK_SET);
    fread(&lcount, sizeof (lcount), 1, fp);
    count = (int) lcount;
    
fprintf(stderr, "start 0x%x, original count 0x%x\n", startaddr, count);
    
    fseek(fp, COUNT_ADDR, SEEK_SET);
    fread(&newCount, sizeof (unsigned int), 2, fp);

fprintf(stderr, "\tnewCount[0] = 0x%x, newCount[1] = 0x%x\n", 
    newCount[0], newCount[1]);

    /*
     * Swap 'em.
     */
    temp = newCount[0];
    newCount[0] = newCount[1];
    newCount[1] = temp;

fprintf(stderr, "\tnewCount[0] now = 0x%x, newCount[1] now = 0x%x\n", 
    newCount[0], newCount[1]);
    
    fseek(fp, COUNT_ADDR, SEEK_SET);
    fwrite(&newCount, sizeof (unsigned int), 2, fp);

    fseek(fp, LIST_ADDR, SEEK_SET);
    fread(&startaddr, sizeof (startaddr), 1, fp);

    fseek(fp, COUNT_ADDR, SEEK_SET);
    fread(&lcount, sizeof (lcount), 1, fp);
    count = (int) lcount;
    
fprintf(stderr, "start 0x%x, patched count 0x%x\n\n", startaddr, count);
    

}