Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions panda/plugins/textprinter/textprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ PANDAENDCOMMENT */
#include <set>
#include <iostream>
#include <fstream>
#include <unordered_set>

#include "panda/plugin.h"

Expand All @@ -53,33 +54,38 @@ void write_mem_callback(CPUState *env, target_ulong pc, target_ulong addr, size_
uint64_t mem_counter;

std::set<prog_point> tap_points;
std::unordered_set<target_ulong> tap_pc;
gzFile read_tap_buffers;
gzFile write_tap_buffers;

void mem_callback(CPUState *env, target_ulong pc, target_ulong addr,
size_t size, uint8_t *buf, gzFile f) {
mem_counter++;
if (tap_pc.find(pc) == tap_pc.end()) {
return;
}
prog_point p = {};
get_prog_point(env, &p);

if (tap_points.find(p) != tap_points.end()) {
target_ulong callers[16] = {0};
int nret = get_callers(callers, 16, env);
unsigned char *buf_uc = static_cast<unsigned char *>(buf);
for (unsigned int i = 0; i < size; i++) {
for (int j = nret-1; j > 0; j--) {
gzprintf(f, TARGET_FMT_lx " ", callers[j]);
}
gzprintf(f,
TARGET_FMT_lx " " TARGET_FMT_lx " %d " TARGET_FMT_lx
" " TARGET_FMT_lx " %s " TARGET_FMT_lx
" %ld %02x\n",
p.caller, p.pc, p.stackKind, p.sidFirst, p.sidSecond,
p.isKernelMode ? "kernel" : "user", addr + i, mem_counter,
buf_uc[i]);
if (tap_points.find(p) == tap_points.end()) {
return;
}

target_ulong callers[16] = {0};
int nret = get_callers(callers, 16, env);
unsigned char *buf_uc = static_cast<unsigned char *>(buf);
for (unsigned int i = 0; i < size; i++) {
for (int j = nret-1; j > 0; j--) {
gzprintf(f, TARGET_FMT_lx " ", callers[j]);
}
gzprintf(f,
TARGET_FMT_lx " " TARGET_FMT_lx " %d " TARGET_FMT_lx
" " TARGET_FMT_lx " %s " TARGET_FMT_lx
" %ld %02x\n",
p.caller, p.pc, p.stackKind, p.sidFirst, p.sidSecond,
p.isKernelMode ? "kernel" : "user", addr + i, mem_counter,
buf_uc[i]);
}
mem_counter++;


return;
}

Expand Down Expand Up @@ -142,6 +148,7 @@ bool init_plugin(void *self) {
printf("Adding tap point (" TARGET_FMT_lx "," TARGET_FMT_lx ", %s)\n",
p.caller, p.pc, sid_string);
tap_points.insert(p);
tap_pc.insert(p.pc);
g_free(sid_string);
}
taps.close();
Expand Down