Browse Source

more debugging

master
Olaf Rempel 13 years ago
parent
commit
b8f40b506f
4 changed files with 22 additions and 11 deletions
  1. +4
    -1
      cfgpatch.c
  2. +9
    -2
      configdata.c
  3. +6
    -3
      lzsc.c
  4. +3
    -5
      lzsd.c

+ 4
- 1
cfgpatch.c View File

@@ -27,7 +27,10 @@ int main(int argc, char *argv[])
config_patch(config->data, CFG_PORTNAME_MASK + 1, "PORT-001");
config_patch(config->data, CFG_PORTNAME_MASK + 2, "PORT-002");

put_filedata(argv[2], config);
char outname[64];
strncpy(outname, argv[1], sizeof(outname));
strcat(outname, ".patched");
put_filedata(outname, config);

free(config);
return 0;


+ 9
- 2
configdata.c View File

@@ -48,6 +48,13 @@ static int patch_ip(void *config, struct cfg_patch *patch, int code, const char
return (inet_pton(AF_INET, parameter, config + patch->offset) <= 0) ? -1 : 0;
}

static int patch_defaultgw(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
/* metric? */
*((uint8_t *)(config + 0x110d)) = 0x02;
return patch_ip(config, patch, code, parameter);
}

static int patch_portname(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
int num = code - patch->code;
@@ -75,7 +82,7 @@ static struct cfg_patch patcharr[] = {{
.size = 0x1d,
}, {
.code = CFG_DEFAULTGW,
.patch = patch_ip,
.patch = patch_defaultgw,
.offset = 0x10fc,
}, {
.code = CFG_IPADDRESS,
@@ -100,7 +107,7 @@ static struct cfg_patch patcharr[] = {{
.mask = 0xFFFFFFE0,
.patch = patch_portname,
.offset = 0x336c,
.size = 8,
.size = 9,
.min = 1, .max = 26,
}};



+ 6
- 3
lzsc.c View File

@@ -49,17 +49,17 @@ static int put_bits(struct lzs_state *state, uint32_t bits, uint32_t len)
/* TODO: check dstsize */
static int put_literal_byte(struct lzs_state *state, uint8_t byte)
{
printf(" put_literal_byte: 0x%02x\n", byte);
printf(" put_literal_byte: 0x%02x\n", byte);
return put_bits(state, (0 << 8) | byte, 1+8);
}

/* TODO: check dstsize */
static int put_compressed_string(struct lzs_state *state, uint32_t offset, uint32_t len)
{
printf(" put_compressed_string: offset=0x%03x len=0x%03x\n", offset, len);
printf(" put_compressed_string: offset=0x%03x len=0x%03x\n", offset, len);

if (offset > 0x7ff || len > 0x800)
printf(" ERROR\n");
printf(" ERROR\n");

if (offset < 128)
put_bits(state, (1 << 8) | (1 << 7) | offset, 1+1+7);
@@ -249,6 +249,8 @@ int lzs_pack(uint8_t *srcbuf, int srcsize, uint8_t *dstbuf, int dstsize)

/* get length of match (min. 2, 0 if collision) */
int matchlen = getMatchLen(search->pos, state.src, maxlen);
printf(" testing pos=0x%03x has 0x%02x matching bytes\n", (state.src - search->pos), matchlen);

if (matchlen > bestmatchlen) {
bestmatchlen = matchlen;
bestmatch = search;
@@ -257,6 +259,7 @@ int lzs_pack(uint8_t *srcbuf, int srcsize, uint8_t *dstbuf, int dstsize)

/* found something? */
if (bestmatch != NULL) {
printf(" selected pos=0x%03x with 0x%02x matching bytes\n", (state.src - bestmatch->pos), bestmatchlen);
put_compressed_string(&state, state.src - bestmatch->pos, bestmatchlen);
/* add bytes to history hash */
while (bestmatchlen--)


+ 3
- 5
lzsd.c View File

@@ -99,12 +99,10 @@ uint32_t lzs_unpack(uint8_t *srcbuf, uint32_t srcsize, uint8_t *dstbuf, uint32_t
/* end condition (7bit offset == 0x00) */
if (tag == 1 && offset == 0) {
/* align src to next byte */
if (state.bitcnt > 7)
printf("ERROR: alignment?\n");
uint32_t cnt = state.bitcnt;
uint32_t tmp = get_bits(&state, cnt);

state.bitcnt = 0;

printf("=== BLOCK END === \n");
printf("=== BLOCK END (align=%d bits=0x%x) === \n", cnt, tmp);
get_zyxel_header(&state);
state.srcblkstart = state.src;
state.dstblkstart = state.dst;


Loading…
Cancel
Save