Connecting Tech Pros Worldwide Help | Site Map

Using a string array

Member
 
Join Date: Jul 2007
Posts: 58
#1: Aug 6 '09
Hi,

I have a read process memory function, which is in a Do ... Loop.

Expand|Select|Wrap|Line Numbers
  1.         Do
  2.             On Error Resume Next
  3.             ReadProcessMemory(pHandle, (&H8723E9 + current_byte), Data, 1, 0&)
  4.             Text = Text + Chr(Data)
  5.             current_byte = current_byte + 1
  6.         Loop Until current_byte = 17
  7.         CloseHandle(pHandle)
  8.  
  9.         TextBox1.Text = Text
  10.  
It is currently reading a string saying: test-test-test-test-test
What I want is to keep the current character it reads, and add the new one after it. "Text = Text + Chr(Data)".

When I take this out and say "Text = Chr(Data)", then have Text display as MsgBox(Text), it works fine, I see character after character appear, but when I use the above code, then TextBox1.Text is left empty.

What I thought of using was a string/character array, but I have no idea how to use that with my code. I did do an attempt:

Expand|Select|Wrap|Line Numbers
  1. Dim Text() as String = Nothing
  2. ReDim Text(0 to 17)
  3.  
  4.         Do
  5.             On Error Resume Next
  6.             ReadProcessMemory(pHandle, (&H8723E9 + current_byte), Data, 1, 0&)
  7.             Text(1) = Text(1) + Chr(Data)
  8.             current_byte = current_byte + 1
  9.             Text(1) = Text(+1)
  10.         Loop Until current_byte = 17
  11.         CloseHandle(pHandle)
  12.  
  13.         TextBox1.Text = Text
  14.  
But this didnt work either. I also tried using a global variable instead of a local one, but no result either.

Another small problem Im having is that the readprocessmemory skips the very first character, always.


Anyone know how to solve these issues?
Any help appreciated.

Evolution445
MrMancunian's Avatar
Expert
 
Join Date: Jul 2008
Location: Utrecht, The Netherlands
Posts: 274
#2: Aug 6 '09

re: Using a string array


I think you should use & (ampersand) instead of + to concatenate strings. So Text = Text & Chr(Data).

Steven
Member
 
Join Date: Jul 2007
Posts: 58
#3: Aug 6 '09

re: Using a string array


Hi MrMancunian,


Thanks for your reply, but this did not seem to work.
This time 'Text' was left empty the whole time.

What I did notice was that if I used:

Text = Chr(Data) + Text

The whole string came out fine, except that it was flipped the wrong way around.
Member
 
Join Date: Jul 2007
Posts: 58
#4: Aug 6 '09

re: Using a string array


Think I found a way around this now, using:

Expand|Select|Wrap|Line Numbers
  1.             Text = TextBox1.Text + Chr(Data)
  2.             TextBox1.Text = Text
  3.  
Now it displays the string correctly in the textbox, but still the very first character is left out.

It should read: "This is a test", but instead it comes up in the textbox as "his is a test"

Is there a way to solve that?

Evolution445
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,743
#5: Aug 6 '09

re: Using a string array


Quote:
Another small problem Im having is that the readprocessmemory skips the very first character, always.
Current_byte must have been initialized someplace before the code you posted. I'm guessing you set it to 1 instead of zero. Most everything in our world is zero indexed meaning the first element of an array is item 0, second element is item 1 and so on.
Member
 
Join Date: Jul 2007
Posts: 58
#6: Aug 6 '09

re: Using a string array


I have looked into that several times, even tried changing the offset address from 8723E9 to H8723E8 or H8723E7, but it had no effect, neither did changing current_byte from 0 to -2 or any other value, except upwards. Whatever I do, the first character after Data returns 0, is left out.

Expand|Select|Wrap|Line Numbers
  1. Dim current_byte As Integer = 0
  2.  
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#7: Aug 6 '09

re: Using a string array


Have you tried using the Update method to refresh the TextBox.

Say you had your TextBox within a panel called "ResultSection"...you would have something like

Expand|Select|Wrap|Line Numbers
  1. Do
  2.             On Error Resume Next
  3.             ReadProcessMemory(pHandle, (&H8723E9 + current_byte), Data, 1, 0&)
  4.              TextBox1.Text += Chr(Data)
  5.              ResultSection.Update()     
  6.             current_byte = current_byte + 1
  7. Loop Until current_byte = 17
  8.  
  9. CloseHandle(pHandle)
  10.  
Member
 
Join Date: Jul 2007
Posts: 58
#8: Aug 6 '09

re: Using a string array


Hi Frinavale,

I have just tried this using TextBox1.Update(), but the result is still the same, also when I put the textbox inside a panel.

What I did was put a breakpoint on the readprocessmemory, and Chr(Data), when I pause it just after readprocessmemory, the first time, Data returns 0. While this seems kinda odd as it does run through the ReadProcessMemory. Whatever I try, it just skips the first character that comes after Data = 0.

Instead of making it stop when current_byte is 30, I made that 250 so that it picked up other things aswell. Somewhere down the line there was "nter Message:". Suppose it was missing the "E" there aswell.

I cant really explain the problem but I hope someone understands.

Thanks in advance,

Evolution445
Member
 
Join Date: Jul 2007
Posts: 58
#9: Aug 8 '09

re: Using a string array


Could it have something to do with the way I read memory? As in, one byte at a time. Could it solve the problem if I read e.g 20/30 bytes at once? How would I do this with an array, and properly converting whatever comes in Data to normal characters?
Reply