@anonymous/

DimpledNumbCharacters

C

No description

fork
loading
Files
  • main.c

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.9367862966506488","path":"main.c","file":{"path":"main.c","content":{"asEncoding":{"base64":"I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxpbnR0eXBlcy5oPgojaW5jbHVkZSA8c3RyaW5nLmg+CgovLyAjZGVmaW5lIFVTRV9TSE9SVF9QT0lOVEVSCiNpZmRlZiBVU0VfU0hPUlRfUE9JTlRFUgogIHR5cGVkZWYgdWludDE2X3Qgc2hvcnRQdHI7CiNlbHNlCiAgdHlwZWRlZiB1aW50cHRyX3Qgc2hvcnRQdHI7CiNlbmRpZgoKdHlwZWRlZiBzdHJ1Y3QgX21tYXAgewogIHVpbnQ4X3QgdXBkYXRlWzB4NUMwMF07CiAgdWludDhfdCB1cGRhdGVfZnVuY1sweDA0MDBdOwogIHVpbnQ4X3QgcHJvZ3JhbVsweDVCODBdOwogIHVpbnQ4X3QgaXZbMHgwMDgwXTsKfSBtbWFwX3Q7Cgp2b2xhdGlsZSBzdGF0aWMgbW1hcF90IG1lbTsKCnZvbGF0aWxlIHZvaWQqIG1lbXNldF92b2xhdGlsZSh2b2xhdGlsZSB2b2lkKiBwX21lbSwgaW50IGMsIHNpemVfdCBsZW4pIHsKICAgIHZvbGF0aWxlIGNoYXIqIHAgPSBwX21lbTsKICAgIHdoaWxlIChsZW4tLSA+IDApIHsKICAgICAgICAqcCsrID0gYzsKICAgIH0KICAgIHJldHVybiBwX21lbTsKfQoKCmludCBtYWluKHZvaWQpIHsKICBwcmludGYoIiVwLCAlcCwgJXAsICVwXG4iLAogICAgICZtZW0udXBkYXRlLCAmbWVtLnVwZGF0ZV9mdW5jLCAmbWVtLnByb2dyYW0sICZtZW0uaXYpOwoKICBwcmludGYoInNpemVvZiB1cGRhdGU6ICV6ZCwgdXBkYXRlX2Z1bmM6ICV6ZCwgcHJvZ3JhbTogJXpkLCBpdjogJ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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <inttypes.h>
#include <string.h>

// #define USE_SHORT_POINTER
#ifdef USE_SHORT_POINTER
  typedef uint16_t shortPtr;
#else
  typedef uintptr_t shortPtr;
#endif

typedef struct _mmap {
  uint8_t update[0x5C00];
  uint8_t update_func[0x0400];
  uint8_t program[0x5B80];
  uint8_t iv[0x0080];
} mmap_t;

volatile static mmap_t mem;

volatile void* memset_volatile(volatile void* p_mem, int c, size_t len) {
    volatile char* p = p_mem;
    while (len-- > 0) {
        *p++ = c;
    }
    return p_mem;
}


int main(void) {
  printf("%p, %p, %p, %p\n",
     &mem.update, &mem.update_func, &mem.program, &mem.iv);

  printf("sizeof update: %zd, update_func: %zd, program: %zd, iv: %zd\n",
    sizeof(mem.update), sizeof(mem.update_func), sizeof(mem.program), sizeof(mem.iv));

  memset_volatile(mem.update, 0x00, sizeof(mem.update));
  memset_volatile(mem.update_func, 0x01, sizeof(mem.update_func));
  memset_volatile(mem.program, 0x02, sizeof(mem.program));
  memset_volatile(mem.iv, 0x03, sizeof(mem.iv));

  printf("[0] update: %x, %x, program: %x, iv:%x\n",
     mem.update[0], mem.update_func[0], mem.program[0], mem.iv[0]);

  shortPtr updateSectionPtr;
  shortPtr programSectionPtr;
	uint16_t tempData;

  shortPtr update_start = (shortPtr)mem.update;
  shortPtr update_end = (shortPtr)mem.update + (sizeof(mem.update) - 1);

  shortPtr update_func_start = (shortPtr)mem.update_func;
  shortPtr update_func_end = (shortPtr)mem.update_func + (sizeof(mem.update_func) - 1);
  
  shortPtr program_start = (shortPtr)mem.program;
  shortPtr program_end = (shortPtr)mem.program + (sizeof(mem.program) - 1);

  shortPtr iv_start = (shortPtr)&mem.iv;
  shortPtr iv_end = (shortPtr)&mem.iv + (sizeof(mem.iv) - 1);

  shortPtr section_gap = program_start - update_start;

#ifdef USE_SHORT_POINTER
  printf("update_start: %x, update_end: %x, update_func_start: %x, update_func_end: %x\r\n",
    update_start,  update_end,  update_func_start, update_func_end);
#else
  printf("update_start: %p, update_end: %p, update_func_start: %p, update_func_end: %p\r\n",
    update_start,  update_end,  update_func_start, update_func_end);
#endif

  printf("program_start: %p, program_end: %p, iv_start: %p, iv_end: %p\r\n",
     program_start, program_end,  iv_start,  iv_end);

  printf("section_gap: %p\n", section_gap);

	for (updateSectionPtr = update_start; updateSectionPtr <= update_end; updateSectionPtr += 2) {
		programSectionPtr = updateSectionPtr + section_gap;
    // printf("updateSectionPtr: %p, programSectionPtr: %p\r\n",
    //   (uint64_t) updateSectionPtr, (uint64_t) programSectionPtr);
		tempData = *(uint16_t*)programSectionPtr; // store old word on stack
		// *programSectionPtr = *updateSectionPtr; // copy word from update to program
		// *updateSectionPtr  = tempData; // save old word into update
	}

  printf("[0] update: %x, update_func: %x, program: %x, iv: %x\r\n",
   mem.update[0],  mem.update_func[0],  mem.program[0],  mem.iv[0]);

  return 0;
}