Skip to content

Commit

Permalink
Add BuildIndex endpoint to generate the index file (#14)
Browse files Browse the repository at this point in the history
* Add BuildIndex endpoint to ttd_types

* Generate idx file during engine init

* Remove useless parameters
  • Loading branch information
atxr authored Jun 16, 2023
1 parent b095779 commit d3a863b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
2 changes: 2 additions & 0 deletions libyarattd/include/libyarattd_ttd.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ char* base64_encode(
size_t input_length,
size_t* output_length);

void build_index_from_engine(TTD_Replay_ReplayEngine* engine);

static unsigned char VERSION_GUID[] = {
0xA5, 0x20, 0x34, 0x4D, 0xEF, 0x37, 0x14, 0x41, 0xAE, 0x91, 0x63, 0xD0,
0x37, 0x8C, 0x84, 0xA9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Expand Down
10 changes: 5 additions & 5 deletions libyarattd/include/libyarattd_ttd_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ typedef struct TTD_Replay_ExceptionEvent
TTD_Replay_Exception* info;
} TTD_Replay_ExceptionEvent;

typedef enum TTD_Replay_IndexStatus TTD_Replay_IndexStatus;
typedef enum TTD_Replay_IndexBuildFlags TTD_Replay_IndexBuildFlags;

typedef struct TTD_Replay_IReplayEngine_vftable
{
// const void* (__fastcall*
Expand Down Expand Up @@ -227,11 +230,8 @@ typedef struct TTD_Replay_IReplayEngine_vftable
struct TTD_Replay_ICursor*(__fastcall* NewCursor)(
TTD_Replay_ReplayEngine* self,
const unsigned char* guid);
// enum TTD::Replay::IndexStatus(__stdcall __high*
//_BuildIndex_ReplayEngine_Replay_TTD__UEAA_AW4IndexStatus_23_P6AXPEBXPEBUIndexBuildProgressType_23__Z0W4IndexBuildFlags_23__Z)(void(__stdcall
//__high*)(const void*, const struct TTD::Replay::IndexBuildProgressType*),
// const void*, enum TTD::Replay::IndexBuildFlags);
void* unk44;
TTD_Replay_IndexStatus(
__stdcall* BuildIndex)(TTD_Replay_ReplayEngine* self, void* callback);
// enum TTD::Replay::IndexStatus(__high*
//_GetIndexStatus_ReplayEngine_Replay_TTD__UEBA_AW4IndexStatus_23_XZ)(void);
void* unk45;
Expand Down
19 changes: 15 additions & 4 deletions libyarattd/src/libyarattd_ttd.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,18 @@ int init_ttd_engine(TTD_Replay_ReplayEngine** engine, wchar_t* filename)
result = CreateReplayEngineWithHandshake(tmp, &instance, VERSION_GUID);
*engine = (TTD_Replay_ReplayEngine*) instance;

if ((*engine)->IReplayEngine->Initialize((*engine), filename) == TRUE)
if ((*engine)->IReplayEngine->Initialize((*engine), filename) != TRUE)
{
return ERROR_SUCCESS;
fwprintf(stdout, L"Failed to initialize ReplayEngine\n");
return ERROR_INTERNAL_FATAL_ERROR;
}
else

// Generate if needed the idx file of the trace file. This file is needed by
// TTDReplay.dll to call some API endpoints like GetCrossPlatformContext
build_index_from_engine(*engine);
if (check_idx_file(filename) != ERROR_SUCCESS)
{
fwprintf(stdout, L"Failed to initialize ReplayEngine\n");
fwprintf(stderr, L"Failed to generate index file\n");
return ERROR_INTERNAL_FATAL_ERROR;
}
}
Expand Down Expand Up @@ -99,3 +104,9 @@ char* base64_encode(

return encoded_data;
}

void dummy_callback() {}
void build_index_from_engine(TTD_Replay_ReplayEngine* engine)
{
engine->IReplayEngine->BuildIndex(engine, &dummy_callback);
}
15 changes: 0 additions & 15 deletions libyarattd/src/libyarattd_virtual_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,6 @@ int build_virtual_alloc_map_from_cache(

int build_virtual_alloc_map(YR_TTD_SCHEDULER* scheduler)
{
// Check that the idx file exists in the same path as the trace file
// This file is needed by TTDReplay.dll to use
// ICursor.GetCrossPlatformContext
if (check_idx_file(scheduler->path) != ERROR_SUCCESS)
{
fwprintf(
stderr,
L"Error: idx file not found\nTo use the Virtual Alloc mode, you need "
L"to have the idx file alongside the run file recored by TTD.\nIf "
L"you "
L"don't have this file, you can generate it automatically by "
L"openning the .run file with WinDbg.\n");
return ERROR_INTERNAL_FATAL_ERROR;
}

// Save current cursor position
Position* last = scheduler->engine->IReplayEngine->GetLastPosition(
scheduler->engine);
Expand Down

0 comments on commit d3a863b

Please sign in to comment.