Skip to content

Commit

Permalink
Merge pull request #4 from gabrielesvelto/system-symbols-mac-merged
Browse files Browse the repository at this point in the history
Merged changes required by the macOS system symbols scraper
  • Loading branch information
glandium committed Apr 19, 2022
2 parents a745334 + 9874ad1 commit afebe24
Show file tree
Hide file tree
Showing 28 changed files with 1,809 additions and 503 deletions.
2 changes: 1 addition & 1 deletion common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_library(common abstractfile.c ../includes/abstractfile.h ../includes/common.h)
add_library(common abstractfile.c base64.c ../includes/abstractfile.h ../includes/common.h)

1 change: 1 addition & 0 deletions common/abstractfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ size_t memFileWrite(AbstractFile* file, const void* data, size_t len) {
}

if((info->offset + (size_t)len) > (*(info->bufferSize))) {
memset(((uint8_t*)(*(info->buffer))) + *(info->bufferSize), 0, (info->offset + (size_t)len) - *(info->bufferSize));
*(info->bufferSize) = info->offset + (size_t)len;
}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion dmg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ link_directories(${BZIP2_LIBRARIES})

link_directories(${PROJECT_BINARY_DIR}/common ${PROJECT_BINARY_DIR}/hfs)

add_library(dmg adc.c base64.c checksum.c dmgfile.c dmglib.c filevault.c io.c partition.c resources.c udif.c ../includes/dmg/adc.h ../includes/dmg/dmg.h ../includes/dmg/dmgfile.h ../includes/dmg/dmglib.h ../includes/dmg/filevault.h)
add_library(dmg adc.c checksum.c dmgfile.c dmglib.c filevault.c io.c partition.c resources.c udif.c ../includes/dmg/adc.h ../includes/dmg/dmg.h ../includes/dmg/dmgfile.h ../includes/dmg/dmglib.h ../includes/dmg/filevault.h)

IF(OPENSSL_FOUND)
add_definitions(-DHAVE_CRYPT)
Expand Down
2 changes: 1 addition & 1 deletion dmg/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <dmg/dmg.h>
#include <dmg/adc.h>

int adc_decompress(int in_size, unsigned char *input, int avail_size, unsigned char *output, size_t *bytes_written)
size_t adc_decompress(size_t in_size, unsigned char *input, size_t avail_size, unsigned char *output, size_t *bytes_written)
{
if (in_size == 0)
return 0;
Expand Down
64 changes: 33 additions & 31 deletions dmg/checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,17 @@ A million repetitions of "a"
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/

#define SHA1HANDSOFF * Copies data before messing with it.
#define SHA1HANDSOFF

void SHA1Transform(uint32_t state[5], const uint8_t buffer[64]);

#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))

/* blk0() and blk() perform the initial expand. */
/* I got the idea of expanding during the round function from SSLeay */

/* FIXME: can we do this in an endian-proof way? */
#define blk0(i) ((endianness == IS_LITTLE_ENDIAN) ? (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
|(rol(block->l[i],8)&0x00FF00FF)) : block->l[i])

|(rol(block->l[i],8)&0x00FF00FF)) : block->l[i])
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
^block->l[(i+2)&15]^block->l[i&15],1))

Expand All @@ -228,30 +229,31 @@ A million repetitions of "a"
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);


/* Hash a single 512-bit block. This is the core of the algorithm. */

void SHA1Transform(unsigned long state[5], const unsigned char buffer[64])
void SHA1Transform(uint32_t state[5], const uint8_t buffer[64])
{
unsigned long a, b, c, d, e;
typedef union {
unsigned char c[64];
unsigned long l[16];
} CHAR64LONG16;
CHAR64LONG16* block;
uint32_t a, b, c, d, e;
typedef union {
uint8_t c[64];
uint32_t l[16];
} CHAR64LONG16;
CHAR64LONG16* block;

#ifdef SHA1HANDSOFF
static unsigned char workspace[64];
static uint8_t workspace[64];
block = (CHAR64LONG16*)workspace;
memcpy(block, buffer, 64);
#else
block = (CHAR64LONG16*)buffer;
#endif

/* Copy context->state[] to working vars */
a = state[0];
b = state[1];
c = state[2];
d = state[3];
e = state[4];

/* 4 rounds of 20 operations each. Loop unrolled. */
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
Expand All @@ -273,19 +275,20 @@ static unsigned char workspace[64];
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);

/* Add the working vars back into context.state[] */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;

/* Wipe variables */
a = b = c = d = e = 0;
}


/* SHA1Init - Initialize new context */

void SHA1Init(SHA1_CTX* context)
{
/* SHA1 initialization constants */
Expand All @@ -299,10 +302,9 @@ void SHA1Init(SHA1_CTX* context)


/* Run your data through this. */

void SHA1Update(SHA1_CTX* context, const unsigned char* data, unsigned int len)
void SHA1Update(SHA1_CTX* context, const uint8_t* data, const size_t len)
{
unsigned int i, j;
size_t i, j;

j = (context->count[0] >> 3) & 63;
if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++;
Expand All @@ -311,7 +313,7 @@ unsigned int i, j;
memcpy(&context->buffer[j], data, (i = 64-j));
SHA1Transform(context->state, context->buffer);
for ( ; i + 63 < len; i += 64) {
SHA1Transform(context->state, &data[i]);
SHA1Transform(context->state, data + i);
}
j = 0;
}
Expand All @@ -321,33 +323,33 @@ unsigned int i, j;


/* Add padding and return the message digest. */

void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
void SHA1Final(uint8_t digest[SHA1_DIGEST_SIZE], SHA1_CTX* context)
{
unsigned long i, j;
unsigned char finalcount[8];
uint32_t i;
uint8_t finalcount[8];

for (i = 0; i < 8; i++) {
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
}
SHA1Update(context, (unsigned char *)"\200", 1);
SHA1Update(context, (uint8_t *)"\200", 1);
while ((context->count[0] & 504) != 448) {
SHA1Update(context, (unsigned char *)"\0", 1);
SHA1Update(context, (uint8_t *)"\0", 1);
}
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
for (i = 0; i < 20; i++) {
digest[i] = (unsigned char)
for (i = 0; i < SHA1_DIGEST_SIZE; i++) {
digest[i] = (uint8_t)
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
}

/* Wipe variables */
i = j = 0;
i = 0;
memset(context->buffer, 0, 64);
memset(context->state, 0, 20);
memset(context->count, 0, 8);
memset(&finalcount, 0, 8);
#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */
memset(finalcount, 0, 8); /* SWR */

#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite its own static vars */
SHA1Transform(context->state, context->buffer);
#endif
}

8 changes: 6 additions & 2 deletions dmg/dmg.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main(int argc, char* argv[]) {
TestByteOrder();

if(argc < 4) {
printf("usage: %s [extract|build|iso|dmg] <in> <out> (-k <key>) (partition)\n", argv[0]);
printf("usage: %s [extract|build|build2048|res|iso|dmg] <in> <out> (-k <key>) (partition)\n", argv[0]);
return 0;
}

Expand Down Expand Up @@ -72,7 +72,11 @@ int main(int argc, char* argv[]) {
}
extractDmg(in, out, partNum);
} else if(strcmp(argv[1], "build") == 0) {
buildDmg(in, out);
buildDmg(in, out, SECTOR_SIZE);
} else if(strcmp(argv[1], "build2048") == 0) {
buildDmg(in, out, 2048);
} else if(strcmp(argv[1], "res") == 0) {
outResources(in, out);
} else if(strcmp(argv[1], "iso") == 0) {
convertToISO(in, out);
} else if(strcmp(argv[1], "dmg") == 0) {
Expand Down

0 comments on commit afebe24

Please sign in to comment.