static void setDisassembly(PDWriter* writer, int start, int instCount) { char temp[65536]; disassembleToBuffer(temp, &start, &instCount); PDWrite_eventBegin(writer, PDEventType_setDisassembly); PDWrite_u16(writer, "address_start", (uint16_t)start); PDWrite_u16(writer, "instruction_count", (uint16_t)instCount); PDWrite_string(writer, "string_buffer", temp); PDWrite_eventEnd(writer); }
static void setExceptionLocation(PDWriter* writer) { PDWrite_eventBegin(writer,PDEventType_setExceptionLocation); PDWrite_u16(writer, "address", pc); PDWrite_u8(writer, "address_size", 2); PDWrite_eventEnd(writer); }
static void parseForCallstack(PDWriter* writer, const char* data, int length) { uint16_t callStackEntries[256 * 2]; int callStackCount = 0; memcpy(s_tempBuffer, data, length); s_tempBuffer[length] = 0; char* pch = strtok(s_tempBuffer, "\n"); while (pch) { // expected format of each line: // xxx.. .C:080e A9 22 LDA #$22 if (pch[0] == '(' && pch[1] != 'C') { uint32_t offset = (uint32_t)atoi(&pch[2]); char* endOffset = strstr(&pch[2], ") "); if (endOffset) { endOffset += 2; uint16_t address = (uint16_t)strtol(endOffset, 0, 16); callStackEntries[(callStackCount * 2) + 0] = address; callStackEntries[(callStackCount * 2) + 1] = (uint16_t)offset; callStackCount++; } } pch = strtok(0, "\n"); } if (callStackCount == 0) return; PDWrite_eventBegin(writer, PDEventType_setCallstack); PDWrite_arrayBegin(writer, "callstack"); for (int i = 0; i < callStackCount; ++i) { PDWrite_arrayEntryBegin(writer); PDWrite_u16(writer, "address", callStackEntries[(i * 2) + 0] + callStackEntries[(i * 2) + 1]); PDWrite_arrayEntryEnd(writer); } PDWrite_arrayEnd(writer); PDWrite_eventEnd(writer); }
static void writeRegister(PDWriter* writer, const char* name, uint8_t size, uint16_t reg, uint8_t readOnly) { PDWrite_arrayEntryBegin(writer); PDWrite_string(writer, "name", name); PDWrite_u8(writer, "size", size); if (readOnly) PDWrite_u8(writer, "read_only", 1); if (size == 2) PDWrite_u16(writer, "register", reg); else PDWrite_u8(writer, "register", (uint8_t)reg); PDWrite_arrayEntryEnd(writer); }
static bool parse_for_callstack(PluginData* data, const char* res, int length, PDReader* reader, PDWriter* writer) { uint16_t callstack_entries[256]; int callstack_count = 0; (void)data; (void)reader; memcpy(TEMP_BUFFER, res, length); TEMP_BUFFER[length] = 0; char* pch = strtok(TEMP_BUFFER, "\n"); while (pch) { const char* startText; const char* endText; if (!find_parentheses(pch, &startText, &endText)) break; // startText points at (xx) // endText points at ) xxxx uint16_t offset = (uint16_t)atoi(startText + 1); uint16_t address = (uint16_t)strtol(endText + 2, 0, 16); callstack_entries[callstack_count++] = address + offset; pch = strtok(0, "\n"); } if (callstack_count == 0) return false; PDWrite_event_begin(writer, PDEventType_SetCallstack); PDWrite_array_begin(writer, "callstack"); for (int i = 0; i < callstack_count; ++i) { PDWrite_array_entry_begin(writer); PDWrite_u16(writer, "address", callstack_entries[i]); PDWrite_entry_end(writer); } PDWrite_array_end(writer); PDWrite_event_end(writer); return true; }
bool parse_disassassembly_call(PluginData* plugin, const char* res, int len, PDReader* reader, PDWriter* writer) { memcpy(TEMP_BUFFER, res, len); TEMP_BUFFER[len] = 0; (void)plugin; (void)reader; // parse the buffer char* pch = strtok(TEMP_BUFFER, "\n"); PDWrite_event_begin(writer, PDEventType_SetDisassembly); PDWrite_array_begin(writer, "disassembly"); bool hasAllDisasembly = false; while (pch) { // expected format of each line: // xxx.. .C:080e A9 22 LDA #$22 char* endOfStream = strstr(pch, "(C:"); char* line = strstr(pch, ".C"); if (endOfStream) { hasAllDisasembly = true; break; } if (!line) break; uint16_t address = (uint16_t)strtol(&line[3], 0, 16); PDWrite_array_entry_begin(writer); PDWrite_u16(writer, "address", address); PDWrite_string(writer, "line", parse_disassembly_line(&line[9])); PDWrite_entry_end(writer); pch = strtok(0, "\n"); } PDWrite_array_end(writer); PDWrite_event_end(writer); return hasAllDisasembly; }
static void write_register(PDWriter* writer, const char* name, uint8_t size, uint16_t reg, uint8_t read_only) { PDWrite_array_entry_begin(writer); PDWrite_string(writer, "name", name); PDWrite_u8(writer, "size", size); if (read_only) { PDWrite_u8(writer, "read_only", 1); } if (size == 2) { PDWrite_u16(writer, "register", reg); } else { PDWrite_u8(writer, "register", (uint8_t)reg); } PDWrite_entry_end(writer); }
static void parseDisassembly(PDWriter* writer, const char* data, int length) { memcpy(s_tempBuffer, data, length); s_tempBuffer[length] = 0; // parse the buffer char* pch = strtok(s_tempBuffer, "\n"); PDWrite_eventBegin(writer, PDEventType_setDisassembly); PDWrite_arrayBegin(writer, "disassembly"); while (pch) { // expected format of each line: // xxx.. .C:080e A9 22 LDA #$22 char* line = strstr(pch, ".C"); if (!line) break; uint16_t address = (uint16_t)strtol(&line[3], 0, 16); PDWrite_arrayEntryBegin(writer); PDWrite_u16(writer, "address", address); PDWrite_string(writer, "line", parseDisassemblyLine(&line[9])); PDWrite_arrayEntryEnd(writer); pch = strtok(0, "\n"); } PDWrite_arrayEnd(writer); PDWrite_eventEnd(writer); }