21 if (strcmp(
desc->plugin->name,
"dmp")) {
22 RZ_LOG_ERROR(
"Open a file with dmp:// to use the 'dmp' debug plugin\n");
27 RZ_LOG_ERROR(
"Open a Windows kernel dump file with dmp:// to use the 'dmp' debug plugin\n");
40 ctx->context_sz = ret;
43 ut32 MachineImageType = 0;
44 ut32 MinorVersion = 0;
45 ut32 ServicePackBuild = 0;
46 ut32 ProcessOffset = 0;
47 ut32 ThreadOffset = 0;
48 ut32 CallStackOffset = 0;
49 ut32 SizeOfCallStack = 0;
51 ut32 NumberProcessors = 0;
85 switch (MachineImageType) {
87 ctx->windctx.is_arm =
true;
88 ctx->windctx.is_64bit =
true;
89 ctx->windctx.is_pae =
true;
92 ctx->windctx.is_arm =
true;
93 ctx->windctx.is_pae =
true;
96 ctx->windctx.is_64bit =
true;
97 ctx->windctx.is_pae =
true;
111 rz_list_foreach (obj->
drivers, it, driver) {
122 ctx->windctx.target = kernel;
131 ctx->windctx.target.uniqueid = 0;
133 char *kernel_pdb =
NULL;
138 char *pdbpath, *exepath;
145 if (!
ctx->windctx.profile) {
147 if (
ctx->windctx.profile) {
148 ctx->windctx.profile->build = MinorVersion;
149 ctx->windctx.profile->sp = ServicePackBuild;
153 RZ_LOG_WARN(
"Failed to download ntoskrnl.pdb, many things won't work.\n");
157 if (!
ctx->windctx.profile) {
159 ctx->windctx.is_arm ?
"ARM" :
"x86",
dbg->
bits * 8, MinorVersion, ServicePackBuild);
165 if (
ctx->windctx.is_arm) {
172 kpb_flag_name =
rz_str_newf(
"pdb.%s.KiProcessorBlock", kernel_pdb);
175 kpb_flag_name =
strdup(
"0");
180 for (
i = 0;
i < NumberProcessors;
i++) {
181 ut64 address = KiProcessorBlock +
i * (
ctx->windctx.is_64bit ? 8 : 4);
191 const ut64 address = 0x1000;
193 map->name =
strdup(
"kernel.target.ethread");
196 ctx->windctx.target_thread.ethread = address;
197 const ut64 current_thread_offset =
ctx->windctx.is_64bit ? 8 : 4;
206 map->name =
strdup(
"kernel.target.eprocess");
209 ctx->windctx.target_thread = *thread;
227 dbg->
tid =
ctx->windctx.target_thread.uniqueid;
230 const ut64 current_thread_offset =
ctx->windctx.is_64bit ? 8 : 4;
246 ctx->windctx.target_thread = *thread;
253 dbg->
tid =
ctx->windctx.target_thread.uniqueid;
254 return ctx->windctx.target.uniqueid;
265 const ut64 current_thread_offset =
ctx->windctx.is_64bit ? 8 : 4;
277 rz_list_foreach (pids, it,
p) {
286 newpid->
pid =
p->uniqueid;
305 if (
pid !=
ctx->windctx.target.uniqueid || tid !=
ctx->windctx.target_thread.uniqueid) {
306 RZ_LOG_ERROR(
"Cannot select other targets on a triage dump\n");
309 dbg->
tid =
ctx->windctx.target_thread.uniqueid;
310 return ctx->windctx.target_thread.uniqueid;
319 dbg->
tid =
ctx->windctx.target_thread.uniqueid;
320 return ctx->windctx.target_thread.uniqueid;
325 if (!
ctx->read_at_kernel_virtual(
ctx->user, at, ptr_buf,
ctx->is_64bit ? 8 : 4)) {
337 const ut64 current_thread_offset =
ctx->is_64bit ? 8 : 4;
341 if (current_thread ==
ctx->target_thread.ethread) {
343 if (current_context) {
344 return ctx->read_at_kernel_virtual(
ctx->user, current_context,
buf,
size);
346 RZ_LOG_WARN(
"Failed to get KPRCB Context pointer at 0x%" PFMT64x "\n", current_context);
353 const int kernel_stack_offset =
ctx->is_64bit ? 0x58 : 0x48;
361 struct context_type_arm *
regs = (
struct context_type_arm *)
buf;
370 struct context_type_i386 *
regs = (
struct context_type_i386 *)
buf;
382 if (
ctx->windctx.is_arm) {
383 if (
ctx->windctx.is_64bit) {
388 if (
ctx->windctx.is_64bit) {
404 rz_list_foreach (
threads, it, t) {
431 rz_list_foreach (obj->
drivers, it, driver) {
438 mod->size = driver->size;
439 mod->addr = driver->base;
440 mod->timestamp = driver->timestamp;
466 mod->addr_end =
m->addr +
m->size;
483 rz_list_foreach (
maps, it,
m) {
494 map->size =
m->end -
m->start;
495 map->addr =
m->start;
496 map->addr_end =
m->end;
520 if (!
ctx->windctx.is_arm &&
ctx->windctx.is_64bit) {
539 char *exepath, *pdbpath;
543 RzBinOptions opts = { 0 };
544 opts.obj_opts.baseaddr =
module->addr;
582 #ifndef RZ_PLUGIN_INCORE
RZ_API RzBinFile * rz_bin_open(RzBin *bin, const char *file, RzBinOptions *opt)
static RzList * maps(RzBinFile *bf)
RzBinInfo * info(RzBinFile *bf)
void winkd_build_profile(WindCtx *ctx, RzTypeDB *db)
bool winkd_download_module_and_pdb(WindModule *module, const char *symserver, const char *symstore, char **exepath, char **pdbpath)
static RzList * dmp_get_modules(DmpCtx *ctx)
static bool is_kernel_address_present(WindCtx *ctx, ut64 at)
RzDebugPlugin rz_debug_plugin_dmp
static int rz_debug_dmp_reg_read(RzDebug *dbg, int type, ut8 *buf, int size)
static bool rz_debug_dmp_kill(RzDebug *dbg, int pid, int tid, int sig)
static int rz_debug_dmp_select(RzDebug *dbg, int pid, int tid)
static RzList * rz_debug_dmp_maps(RzDebug *dbg)
RzList * rz_debug_dmp_frames(RzDebug *dbg, ut64 at)
static bool rz_debug_dmp_init(RzDebug *dbg, void **user)
static RzList * rz_debug_dmp_modules(RzDebug *dbg)
RZ_API RzLibStruct rizin_plugin
static int is_pc_inside_windmodule(const void *value, const void *list_data)
static char * rz_debug_dmp_reg_profile(RzDebug *dbg)
static RzList * rz_debug_dmp_pids(RzDebug *dbg, int pid)
static int rz_debug_dmp_attach(RzDebug *dbg, int pid)
static RzList * rz_debug_dmp_threads(RzDebug *dbg, int pid)
RZ_API void rz_debug_map_free(RzDebugMap *map)
#define DMP_DUMPTYPE_TRIAGE
size_t map(int syms, int left, int len)
static RzList * backtrace_generic(RZ_BORROW RZ_NONNULL RzDebug *dbg)
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
RZ_API RZ_BORROW RzListIter * rz_list_find(RZ_NONNULL const RzList *list, const void *p, RZ_NONNULL RzListComparator cmp)
Returns RzListIter element which matches via the RzListComparator.
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API void * rz_list_iter_get_data(RzListIter *list)
returns the value stored in the list element
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
void * malloc(size_t size)
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
#define PE_IMAGE_FILE_MACHINE_ARMNT
#define PE_IMAGE_FILE_MACHINE_AMD64
#define PE_IMAGE_FILE_MACHINE_ARM64
RZ_API RzDebugPid * rz_debug_pid_free(RzDebugPid *pid)
#define rz_buf_read_le32_at(b, addr, result)
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_io(RZ_NONNULL void *iob)
Creates a new buffer wrapping the memory map exposed by RzIOBind.
#define rz_buf_read_le64_at(b, addr, result)
RZ_API const char * rz_file_basename(const char *path)
RZ_API const char * rz_file_dos_basename(RZ_BORROW RZ_NONNULL const char *path)
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
RZ_API bool rz_io_map_del(RzIO *io, ut32 id)
RZ_API RzIOMap * rz_io_map_get(RzIO *io, ut64 addr)
RZ_API bool rz_io_map_remap(RzIO *io, ut32 id, ut64 addr)
RZ_API RzIOMap * rz_io_map_new(RzIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size)
void(* RzListFree)(void *ptr)
#define RZ_LOG_WARN(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
RZ_API bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case sensitive)
#define RZ_PTR_MOVE(d, s)
#define rz_offsetof(type, member)
RZ_API void * rz_vector_push(RzVector *vec, void *x)
#define rz_vector_foreach(vec, it)
RZ_API void rz_vector_fini(RzVector *vec)
#define rz_vector_foreach_prev(vec, it)
RZ_API void rz_vector_init(RzVector *vec, size_t elem_size, RzVectorFree free, void *free_user)
RzVector KiProcessorBlock
ut32 kprcb_context_offset
ut32 kthread_switch_frame_offset
ut64 baseaddr
where the linker maps the binary in memory
XX curplugin == o->plugin.
RzBinObjectLoadOptions opts
RZ_DEPRECATE RzBinFile * cur
never use this in new code! Get a file from the binfiles list or track it yourself.
RzCoreBinApplyInfo applyBinInfo
struct rz_io_desc_t * desc
static uv_thread_t * threads
RZ_API ut64 rz_type_db_struct_member_offset(RZ_NONNULL const RzTypeDB *typedb, RZ_NONNULL const char *name, RZ_NONNULL const char *member)
Returns the offset in bytes of the structure member if there is a match.
static bool backtrace_windows_x64(RZ_IN RzDebug *dbg, RZ_INOUT RzList **out_frames, RZ_INOUT struct context_type_amd64 *context)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
WindThread * winkd_get_thread_at(RZ_BORROW RZ_NONNULL WindCtx *ctx, ut64 address)
Profile * winkd_get_profile(int bits, int build, int sp)
RzList * winkd_list_threads(RZ_BORROW RZ_NONNULL WindCtx *ctx)
RzList * winkd_list_maps(RZ_BORROW RZ_NONNULL WindCtx *ctx)
int winkd_get_sp(RZ_BORROW RZ_NONNULL WindCtx *ctx)
void winkd_windmodule_free(void *ptr)
RzList * winkd_list_modules(RZ_BORROW RZ_NONNULL WindCtx *ctx)
bool winkd_set_target(RZ_BORROW RZ_NONNULL WindCtx *ctx, ut32 pid, ut32 tid)
WindProc * winkd_get_process_at(RZ_BORROW RZ_NONNULL WindCtx *ctx, ut64 address)
RzList * winkd_list_process(RZ_BORROW RZ_NONNULL WindCtx *ctx)
static ut64 winkd_read_ptr_at(RZ_BORROW RZ_NONNULL WindCtx *ctx, RZ_BORROW RZ_NONNULL WindReadAt *read_at_func, ut64 at)
static zip_compression_status_t process(void *ud, zip_uint8_t *data, zip_uint64_t *length)