Jump to content


Photo

Development Thread For Xboxdumper2


  • Please log in to reply
1 reply to this topic

#1 ldotsfan

ldotsfan

    X-S Messiah

  • Dev/Contributor
  • PipPipPipPipPipPipPip
  • 3,100 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 10 April 2010 - 08:01 AM

1. Reused partition.cpp, partition.h and a small portion of PartInfo.cpp from NghtShd's xbpartitioner codebase.
2. Used typedefs and minor edits to get rid of C++ style code and renamed to .c
partition.h
CODE

typedef int bool;
typedef u_int64_t ULONG;
typedef u_int32_t USHORT;

#define false 0
#define true 1

#define PARTITION_MODE_F_CAPPED 0
#define PARTITION_MODE_F_ALL 1
#define PARTITION_MODE_G_REST 2
#define PARTITION_MODE_FG_EVEN 3


3. Fixed the Makefile.
CODE

OBJS=main.o util.o fatx.o dir.o partition.o
MKFS=mkfs.o util.o fatx.o dir.o partition.o


Headers in xboxdumper.c
CODE

#include "partition.h


Change to writeBRFR
CODE

int writeBRFR(char *szDrive,int partition_mode) {

    FILE *fp;
    int fd,i;
    int error = 0;
    FATXPartition* partition = NULL;
    u_int64_t start,size,totalsize,totalsectors;
    char szBuffer[512];
    XboxPartitionTable *BackupPartTbl;
    XboxPartitionTable *PartTbl;

XboxPartitionTable DefaultPartTbl =
{
    { '*', '*', '*', '*', 'P', 'A', 'R', 'T', 'I', 'N', 'F', 'O', '*', '*', '*', '*' },
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    {
        { { 'X', 'B', 'O', 'X', ' ', 'S', 'H', 'E', 'L', 'L', ' ', ' ', ' ', ' ', ' ', ' '}, PE_PARTFLAGS_IN_USE, XBOX_MUSICPART_LBA_START, XBOX_MUSICPART_LBA_SIZE, 0 },
        { { 'X', 'B', 'O', 'X', ' ', 'D', 'A', 'T', 'A', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, PE_PARTFLAGS_IN_USE, XBOX_SYSPART_LBA_START, XBOX_SYSPART_LBA_SIZE, 0 },
        { { 'X', 'B', 'O', 'X', ' ', 'G', 'A', 'M', 'E', ' ', 'S', 'W', 'A', 'P', ' ', '1'}, PE_PARTFLAGS_IN_USE, XBOX_SWAPPART1_LBA_START, XBOX_SWAPPART_LBA_SIZE, 0 },
        { { 'X', 'B', 'O', 'X', ' ', 'G', 'A', 'M', 'E', ' ', 'S', 'W', 'A', 'P', ' ', '2'}, PE_PARTFLAGS_IN_USE, XBOX_SWAPPART2_LBA_START, XBOX_SWAPPART_LBA_SIZE, 0 },
        { { 'X', 'B', 'O', 'X', ' ', 'G', 'A', 'M', 'E', ' ', 'S', 'W', 'A', 'P', ' ', '3'}, PE_PARTFLAGS_IN_USE, XBOX_SWAPPART3_LBA_START, XBOX_SWAPPART_LBA_SIZE, 0 },
        { { 'X', 'B', 'O', 'X', ' ', 'F', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, XBOX_PART6_LBA_START, 0, 0 },
        { { 'X', 'B', 'O', 'X', ' ', 'G', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, XBOX_PART6_LBA_START + 0, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
    }
};


    fp = fopen (szDrive, "r+b");
    if(!fp) {
        printf("Error opening %s\n",szDrive);
        return 0;
    }
    
    memset(szBuffer,0,256);

    fseeko (fp,0L,SEEK_END);
    totalsize = ftello(fp);
    totalsectors = totalsize/SECTOR_SIZE;

    fseeko(fp,0x600,SEEK_SET);
    fread(szBuffer,4,1,fp);
    
    printf("Readed  -> %c%c%c%c\n",szBuffer[0],szBuffer[1],szBuffer[2],szBuffer[3]);

    memset(szBuffer,0,512);
            
    fseeko(fp,0L,SEEK_SET);
    for(i = XBOX_SECTOR_CONFIG;i < XBOX_SECTORS_CONFIG;i++)
        fwrite(szBuffer,512,1,fp);

    fseeko(fp,0x600,SEEK_SET);
    sprintf(szBuffer,"BRFR");
    fwrite(szBuffer,4,1,fp);

    memset(szBuffer,0,256);

    fseeko(fp,0x600,SEEK_SET);
    fread(szBuffer,4,1,fp);
    
    printf("Written -> %c%c%c%c\n",szBuffer[0],szBuffer[1],szBuffer[2],szBuffer[3]);

    PartTbl = (XboxPartitionTable*) malloc(sizeof(XboxPartitionTable));
    BackupPartTbl = (XboxPartitionTable*) malloc(sizeof(XboxPartitionTable));

    memcpy (BackupPartTbl,&DefaultPartTbl,sizeof(XboxPartitionTable));
    
    part_setup_standard_partitions (PartTbl,BackupPartTbl,totalsectors,partition_mode);

    fseeko(fp,0L,SEEK_SET);
    fwrite(PartTbl, sizeof(XboxPartitionTable), 1, fp);
    
    fclose(fp);

    sprintf(szBuffer,"part50");
    start = XBOX_SECTOR_STORE * 512UL;
    size = XBOX_SECTORS_STORE * 512ULL;
    printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
    
    partition = createPartition(szDrive, start,size, 0);
    if(partition == NULL) {
        printf("Error creating -> %s\n",szBuffer);
        return 0;
    }
    closePartition(partition);

    sprintf(szBuffer,"part51");
    start = XBOX_SECTOR_SYSTEM * 512UL;
    size = XBOX_SECTORS_SYSTEM * 512UL;
    printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
    
    partition = createPartition(szDrive, start,size, 0);
    if(partition == NULL) {
        printf("Error creating -> %s\n",szBuffer);
        return 0;
    }
    closePartition(partition);

    sprintf(szBuffer,"part52");
    start = XBOX_SECTOR_CACHE1 * 512UL;
    size = XBOX_SECTORS_CACHE1 * 512UL;
    printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
    
    partition = createPartition(szDrive, start,size, 0);
    if(partition == NULL) {
        printf("Error creating -> %s\n",szBuffer);
        return 0;
    }
    closePartition(partition);

    sprintf(szBuffer,"part53");
    start = XBOX_SECTOR_CACHE2 * 512UL;
    size = XBOX_SECTORS_CACHE2 * 512UL;
    printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
    
    partition = createPartition(szDrive, start,size, 0);
    if(partition == NULL) {
        printf("Error creating -> %s\n",szBuffer);
        return 0;
    }
    closePartition(partition);

    sprintf(szBuffer,"part54");
    start = XBOX_SECTOR_CACHE3 * 512UL;
    size = XBOX_SECTORS_CACHE3 * 512UL;
    printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
    
    partition = createPartition(szDrive, start,size, 0);
    if(partition == NULL) {
        printf("Error creating -> %s\n",szBuffer);
        return 0;
    }
    closePartition(partition);
    
    for (i=5;i<14;i++)
    {
        if (PartTbl->TableEntries[i].Flags & PE_PARTFLAGS_IN_USE)
        {
            printf("Creating -> start %lld size %lld\n", PartTbl->TableEntries[i].LBAStart,PartTbl->TableEntries[i].LBASize);
            partition = createPartition(szDrive, PartTbl->TableEntries[i].LBAStart,PartTbl->TableEntries[i].LBASize,0);
            closePartition (partition);
        }
    }
        printf("Calling ioctl() to re-read partition table.\n");
        sync();
    sleep(2);
    
    return 1;
}

Edited by ldotsfan, 10 April 2010 - 08:06 AM.


#2 ldotsfan

ldotsfan

    X-S Messiah

  • Dev/Contributor
  • PipPipPipPipPipPipPip
  • 3,100 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 13 May 2010 - 03:33 AM

Bug fixes for variable sizes:
CODE

typedef u_int32_t ULONG;
typedef struct
{
    unsigned char Name[16];
    u_int32_t Flags;
    u_int32_t LBAStart;
    u_int32_t LBASize;
    u_int32_t Reserved;
} XboxPartitionTableEntry;


Actual method:
CODE

int writeBRFR(char *szDrive,int partition_mode) {

    FILE *fp;
    int fd,i;
    int error = 0;
    FATXPartition* partition = NULL;
    u_int64_t start,size,totalsize,totalsectors;
    char szBuffer[512];
    XboxPartitionTable *BackupPartTbl;
    XboxPartitionTable *PartTbl;
    XboxPartitionTable DefaultPartTbl =
{
    { '*', '*', '*', '*', 'P', 'A', 'R', 'T', 'I', 'N', 'F', 'O', '*', '*', '*', '*' },
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    {
        { { 'X', 'B', 'O', 'X', ' ', 'S', 'H', 'E', 'L', 'L', ' ', ' ', ' ', ' ', ' ', ' '}, PE_PARTFLAGS_IN_USE, XBOX_SECTOR_STORE, XBOX_SECTORS_STORE, 0 },
        { { 'X', 'B', 'O', 'X', ' ', 'D', 'A', 'T', 'A', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, PE_PARTFLAGS_IN_USE, XBOX_SECTOR_SYSTEM, XBOX_SECTORS_SYSTEM, 0 },
        { { 'X', 'B', 'O', 'X', ' ', 'G', 'A', 'M', 'E', ' ', 'S', 'W', 'A', 'P', ' ', '1'}, PE_PARTFLAGS_IN_USE, XBOX_SECTOR_CACHE1, XBOX_SECTORS_CACHE1, 0 },
        { { 'X', 'B', 'O', 'X', ' ', 'G', 'A', 'M', 'E', ' ', 'S', 'W', 'A', 'P', ' ', '2'}, PE_PARTFLAGS_IN_USE, XBOX_SECTOR_CACHE2, XBOX_SECTORS_CACHE2, 0 },
        { { 'X', 'B', 'O', 'X', ' ', 'G', 'A', 'M', 'E', ' ', 'S', 'W', 'A', 'P', ' ', '3'}, PE_PARTFLAGS_IN_USE, XBOX_SECTOR_CACHE3, XBOX_SECTORS_CACHE3, 0 },
        { { 'X', 'B', 'O', 'X', ' ', 'F', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, XBOX_PART6_LBA_START, 0, 0 },
        { { 'X', 'B', 'O', 'X', ' ', 'G', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, XBOX_PART6_LBA_START, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
        { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
    }
};

    fp = fopen (szDrive, "r+b");
    if(!fp) {
        printf("Error opening %s\n",szDrive);
        return 0;
    }
    
    memset(szBuffer,0,256);
    fseeko (fp,0L,SEEK_END);
    totalsize = ftello(fp);
    totalsectors = totalsize/512ULL;
    
    printf("Total Sectors  -> %lld\n",totalsectors);
    fseeko(fp,0x600,SEEK_SET);
    fread(szBuffer,4,1,fp);
    
    printf("Readed  -> %c%c%c%c\n",szBuffer[0],szBuffer[1],szBuffer[2],szBuffer[3]);

    memset(szBuffer,0,512);
            
    fseeko(fp,0L,SEEK_SET);
    for(i = XBOX_SECTOR_CONFIG;i < XBOX_SECTORS_CONFIG;i++)
        fwrite(szBuffer,512,1,fp);

    fseeko(fp,0x600,SEEK_SET);
    sprintf(szBuffer,"BRFR");
    fwrite(szBuffer,4,1,fp);

    memset(szBuffer,0,256);

    fseeko(fp,0x600,SEEK_SET);
    fread(szBuffer,4,1,fp);
    
    printf("Written -> %c%c%c%c\n",szBuffer[0],szBuffer[1],szBuffer[2],szBuffer[3]);
    PartTbl = (XboxPartitionTable*) malloc(sizeof(XboxPartitionTable));
    BackupPartTbl = (XboxPartitionTable*) malloc(sizeof(XboxPartitionTable));

    memcpy (BackupPartTbl,&DefaultPartTbl,sizeof(XboxPartitionTable));

    part_setup_standard_partitions (PartTbl,BackupPartTbl,totalsectors,partition_mode);

    fseeko(fp,0L,SEEK_SET);
    fwrite(PartTbl, sizeof(XboxPartitionTable), 1, fp);
    
    fclose(fp);

    sprintf(szBuffer,"part50");
    start = XBOX_SECTOR_STORE * 512ULL;
    size = XBOX_SECTORS_STORE * 512ULL;
    printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
    
    partition = createPartition(szDrive, start,size, 0);
    if(partition == NULL) {
        printf("Error creating -> %s\n",szBuffer);
        return 0;
    }
    closePartition(partition);

    sprintf(szBuffer,"part51");
    start = XBOX_SECTOR_SYSTEM * 512ULL;
    size = XBOX_SECTORS_SYSTEM * 512ULL;
    printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
    
    partition = createPartition(szDrive, start,size, 0);
    if(partition == NULL) {
        printf("Error creating -> %s\n",szBuffer);
        return 0;
    }
    closePartition(partition);

    sprintf(szBuffer,"part52");
    start = XBOX_SECTOR_CACHE1 * 512ULL;
    size = XBOX_SECTORS_CACHE1 * 512ULL;
    printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
    
    partition = createPartition(szDrive, start,size, 0);
    if(partition == NULL) {
        printf("Error creating -> %s\n",szBuffer);
        return 0;
    }
    closePartition(partition);

    sprintf(szBuffer,"part53");
    start = XBOX_SECTOR_CACHE2 * 512ULL;
    size = XBOX_SECTORS_CACHE2 * 512ULL;
    printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
    
    partition = createPartition(szDrive, start,size, 0);
    if(partition == NULL) {
        printf("Error creating -> %s\n",szBuffer);
        return 0;
    }
    closePartition(partition);

    sprintf(szBuffer,"part54");
    start = XBOX_SECTOR_CACHE3 * 512ULL;
    size = XBOX_SECTORS_CACHE3 * 512ULL;
    printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
    
    partition = createPartition(szDrive, start,size, 0);
    if(partition == NULL) {
        printf("Error creating -> %s\n",szBuffer);
        return 0;
    }
    closePartition(partition);
    
    for (i=5;i<14;i++)
    {
        if (PartTbl->TableEntries[i].Flags & PE_PARTFLAGS_IN_USE)
        {
            printf("Creating -> start %lld size %lld\n", PartTbl->TableEntries[i].LBAStart*512ULL,PartTbl->TableEntries[i].LBASize*512ULL);
            partition = createPartition(szDrive, PartTbl->TableEntries[i].LBAStart*512ULL,PartTbl->TableEntries[i].LBASize*512ULL,0);
            closePartition (partition);
        }
    }
        printf("Calling ioctl() to re-read partition table.\n");
    for (i=0;i<14;i++)
    {
        if (PartTbl->TableEntries[i].Flags & PE_PARTFLAGS_IN_USE)
        {
            printf("partition %d start %lld size %lld\n", i,PartTbl->TableEntries[i].LBAStart*512ULL,PartTbl->TableEntries[i].LBASize*512ULL);
        }
    }
        sync();
    sleep(2);
    
    fd = open(szDrive,O_RDONLY);
        if ((i = ioctl(fd, BLKRRPART)) != 0) {
        error = errno;
    } else {
                sync();
                sleep(2);
        if ((i = ioctl(fd, BLKRRPART)) != 0)
            error = errno;
    }
    
    close(fd);
    
    return 1;
}

Edited by ldotsfan, 13 May 2010 - 03:35 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users