Created
January 25, 2020 00:40
-
-
Save vklachkov/ee8f3e8cc23745deeee744d430411a2b to your computer and use it in GitHub Desktop.
Generates an entry from the RunList and outputs it in byte order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* INCLUDES *******************************************************************/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
/* TYPES **********************************************************************/ | |
#define BYTE unsigned char | |
#define PBYTE BYTE* | |
#define ULONG unsigned int | |
#define PULONG ULONG* | |
/* BYTES OPERATIONS ***********************************************************/ | |
#define GET_BYTE(val, n) (((val) >> (8*(n))) & 0xFF) | |
#define GET_BYTE_FROM_END(val, n) (((val) >> (8*(sizeof((val)) - 1 - (n)))) & 0xFF) | |
#define BSWAP16(val) \ | |
( (((val) >> 8) & 0x00FF) | (((val) << 8) & 0xFF00) ) | |
#define BSWAP32(val) \ | |
( (((val) >> 24) & 0x000000FF) | (((val) >> 8) & 0x0000FF00) | \ | |
(((val) << 8) & 0x00FF0000) | (((val) << 24) & 0xFF000000) ) | |
#define BSWAP64(val) \ | |
( (((val) >> 56) & 0x00000000000000FF) | (((val) >> 40) & 0x000000000000FF00) | \ | |
(((val) >> 24) & 0x0000000000FF0000) | (((val) >> 8) & 0x00000000FF000000) | \ | |
(((val) << 8) & 0x000000FF00000000) | (((val) << 24) & 0x0000FF0000000000) | \ | |
(((val) << 40) & 0x00FF000000000000) | (((val) << 56) & 0xFF00000000000000) ) | |
/* CONSTS *********************************************************************/ | |
#define ENTRY_SIZE 8 | |
/* FUNCTIONS ******************************************************************/ | |
int main() | |
{ | |
// Hardcoded values from reality | |
ULONG LCN = BSWAP32(0xC0000); | |
BYTE LCNCutSize = 3; | |
ULONG Clusters = BSWAP32(0x6340); | |
BYTE ClustersCutSize = 2; | |
// Run list entry | |
PBYTE Entry; | |
BYTE EntryOffset = 0; | |
BYTE ClustersOffset = 1; | |
BYTE LCNOffset = ClustersOffset + ClustersCutSize; | |
// Allocate memory | |
Entry = malloc(ENTRY_SIZE); | |
if (!Entry) | |
{ | |
printf("Can't allocate memory for entry\n"); | |
return 1; | |
} | |
// Fill structure | |
// Setup header | |
Entry[0] = (LCNCutSize << 4) | ClustersCutSize; | |
// Copy clusters count | |
for (EntryOffset = ClustersOffset; EntryOffset < ClustersOffset + ClustersCutSize; EntryOffset++) | |
{ | |
Entry[EntryOffset] = GET_BYTE_FROM_END(Clusters, EntryOffset - ClustersOffset); | |
} | |
// Copy LCN | |
for (EntryOffset = LCNOffset; EntryOffset < LCNOffset + LCNCutSize; EntryOffset++) | |
{ | |
Entry[EntryOffset] = GET_BYTE_FROM_END(LCN, EntryOffset - LCNOffset); | |
} | |
// Print entry | |
printf("Run List Entry:\n"); | |
for (EntryOffset = 0; EntryOffset < ENTRY_SIZE; EntryOffset++) | |
{ | |
printf("0x%02hhX ", *(Entry + EntryOffset)); | |
} | |
// Free memory | |
free(Entry); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment