D
D
dominy2021-08-15 22:46:12
C++ / C#
dominy, 2021-08-15 22:46:12

How to read array of dynamic length data?

Hello, I have a read function in my library

template <typename type>
  static type readMemory(uintptr_t offset) {
    type value;
    isLastSuccessful = ReadProcessMemory(targetHandle, (LPVOID)offset, &value, sizeof(type), 0);
    return value;
  }

I need to use it only once to read an array of dynamic length data, that is, I
need to do
wchar_t* readWcharArray(uintptr_t adrArray, int length) {
  wchar_t* str = new wchar_t[length];
  for (int i = 0; i < length; i++) {
    str[i] = readMemory<wchar_t>(adrArray + sizeof(wchar_t) * i); 
  }
  return str;
}
but without the loop, is it possible without changing the library itself...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-08-15
@dominy

You will have to rewrite the function readMemoryto accept lengthand read length*sizeof(type). Or call ReadProcessMemory directly in your function.
The current implementation doesn't suit your purpose at all. The template type must be known at compile time. And you want to somehow transfer the dynamic length in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question