151 lines
3.5 KiB
C
151 lines
3.5 KiB
C
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <sys/mman.h>
|
|
#include "lint.h"
|
|
|
|
void
|
|
cmd_new(struct hmt *hmt, int flag)
|
|
{
|
|
if (hmt->binsize < HMT_FLAGS1)
|
|
{
|
|
printf("File too small to patch.\n");
|
|
return;
|
|
}
|
|
|
|
if (flag)
|
|
hmt->bin[HMT_FLAGS1] &= ~HMT_FLAGS1_NEW;
|
|
else
|
|
hmt->bin[HMT_FLAGS1] |= HMT_FLAGS1_NEW;
|
|
}
|
|
|
|
void
|
|
cmd_lock(struct hmt *hmt, int flag)
|
|
{
|
|
if (hmt->binsize < HMT_FLAGS1)
|
|
{
|
|
printf("File too small to patch.\n");
|
|
return;
|
|
}
|
|
|
|
if (flag)
|
|
hmt->bin[HMT_FLAGS1] |= HMT_FLAGS1_LOCKED;
|
|
else
|
|
hmt->bin[HMT_FLAGS1] &= ~HMT_FLAGS1_LOCKED;
|
|
}
|
|
|
|
void
|
|
cmd_protect(struct hmt *hmt, int flag)
|
|
{
|
|
if (hmt->binsize < HMT_FLAGS1)
|
|
{
|
|
printf("File too small to patch.\n");
|
|
return;
|
|
}
|
|
|
|
if (flag)
|
|
hmt->bin[HMT_FLAGS1] |= HMT_FLAGS1_PROTECTED;
|
|
else
|
|
hmt->bin[HMT_FLAGS1] &= ~HMT_FLAGS1_PROTECTED;
|
|
}
|
|
|
|
void
|
|
patch_string(struct hmt *hmt, uint32_t offset, char *str, int ReportErrs)
|
|
{
|
|
int i;
|
|
|
|
if (hmt->binsize < offset + strlen(str))
|
|
{
|
|
if (ReportErrs==1) {
|
|
printf("File too small to patch.\n");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (offset != HMT_FILENAME) {
|
|
for (i=0; i<255; i++) {hmt->bin[offset+i] = 0x00;}
|
|
hmt->bin[offset] = 0x15;
|
|
strcpy((char *)(hmt->bin + offset+1), (const char *)str);
|
|
} else {
|
|
for (i=0; i<512; i++) {hmt->bin[offset+i] = 0x00;}
|
|
strcpy((char *)(hmt->bin + offset), (const char *)str);
|
|
}
|
|
}
|
|
|
|
void
|
|
cmd_getstring(struct hmt *hmt, uint32_t offset)
|
|
{
|
|
printf("%s\n", strip_string(hmt->bin + offset));
|
|
}
|
|
|
|
void
|
|
expand_hmt(struct hmt *hmt, uint32_t new_size)
|
|
{
|
|
/*void *new_bin = malloc(new_size);*/
|
|
|
|
if (debug)
|
|
printf("expand_hmt(0x%08X, %d) {\n", (void *)hmt, (int)new_size);
|
|
/*memset(new_bin, 0, new_size);*/
|
|
/*memcpy(new_bin, hmt->bin, hmt->binsize);*/
|
|
munmap((void *)hmt->bin, hmt->binsize);
|
|
hmt->binsize = new_size;
|
|
/* Will this work when size is larger than file? */
|
|
hmt->bin = (uint8_t *)mmap(NULL, hmt->binsize, PROT_READ|PROT_WRITE,
|
|
MAP_SHARED, hmt->fd, 0);
|
|
|
|
/*free(hmt->bin);*/
|
|
/*hmt->bin = new_bin;*/
|
|
hmt->epgstart = hmt->bin + 0x1004;
|
|
if (debug)
|
|
printf("expand_hmt(0x%08X, %d) }\n", (void *)hmt, (int)new_size);
|
|
}
|
|
|
|
void
|
|
init_hmt_epg_block(struct hmt *hmt)
|
|
{
|
|
uint32_t duration = 0;
|
|
|
|
if (debug)
|
|
printf("init_hmt_epg_block(0x%08X) {\n", (void *)hmt);
|
|
hmt->bin[HMT_BLOCK_LENGTH] = 0x1;
|
|
if (debug)
|
|
printf(
|
|
"Zeroing 0x%04X bytes from 0x%04X\n",
|
|
HMT_EPG_BLOCK_LENGTH + HMT_GUIDE_BLOCK_MIN_SIZE,
|
|
hmt->epgstart - hmt->bin
|
|
);
|
|
memset(hmt->epgstart, 0, HMT_EPG_BLOCK_LENGTH + HMT_GUIDE_BLOCK_MIN_SIZE);
|
|
if (debug)
|
|
printf(
|
|
"Copying 0x%04X bytes from 0x%04X to 0x%04X\n",
|
|
4, HMT_RECORDING_START, hmt->epgstart + HMT_SCHEDULED_START - hmt->bin
|
|
);
|
|
memcpy(hmt->epgstart + HMT_SCHEDULED_START, hmt->bin + HMT_RECORDING_START, 4);
|
|
if (debug)
|
|
printf("1\n");
|
|
duration =
|
|
*(uint32_t*)(hmt->bin + HMT_RECORDING_END) -
|
|
*(uint32_t*)(hmt->bin + HMT_RECORDING_START);
|
|
if (debug)
|
|
printf(
|
|
"Setting duration %d in 0x%04X\n",
|
|
duration, hmt->epgstart + HMT_SCHEDULED_DURATION - hmt->bin
|
|
);
|
|
memcpy(hmt->epgstart + HMT_SCHEDULED_DURATION, &duration, 4);
|
|
*(hmt->epgstart + 0x0c) = 0x04;
|
|
*(hmt->epgstart + 0x0e) = 0x01;
|
|
/**(hmt->epgstart + 0x14) = 0x15;*/
|
|
if (debug)
|
|
printf(
|
|
"Copying 0x%04X bytes from 0x%04X to 0x%04X\n",
|
|
0xff, HMT_TITLE, hmt->epgstart + 0x14 - hmt->bin
|
|
);
|
|
memcpy(hmt->epgstart + 0x14, hmt->bin + HMT_TITLE, 0xff /*53*/);
|
|
/* *(hmt->epgstart + 0x114) = 0x15; */
|
|
/* Synopsis, up to 255 bytes. */
|
|
/* No guide block. */
|
|
if (debug)
|
|
printf("init_hmt_epg_block(0x%08X) }\n", (void *)hmt);
|
|
}
|