| View previous topic :: View next topic |
| Author |
Message |
i__h4x Grandmaster Cheater Supreme
Reputation: 0
Joined: 09 Jun 2007 Posts: 1005 Location: i__<3's__wpe
|
Posted: Mon Jan 07, 2008 11:40 am Post subject: [VB .NET] Search Memory Methods... |
|
|
Ok, now i know that VB Net isnt a particuarlly liked program around these parts, but wth, ill ask anyway!
Im looking to create a program that can search a selected processes memory for a value, and was wondering what the best way to achieve this is.
Cheatengine and other programs can search huge numbers of addresses very quickly.
Currently Im just using a For address to endaddress statment:
| Code: |
For Value As Integer = &H1000000 To Max
Call ReadProcessMemory(myHandle, Value, buffer, 1, 0)
If buffer = SearchValue Then
Scanner.ReportProgress(100, Value)
End If
Next |
This is slow as it has to search every address one after another, and i was wondering how i could speed this up and if there was an efficent method of searching the memory.
_________________
Mes'a back!
 |
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Mon Jan 07, 2008 12:02 pm Post subject: |
|
|
| It will freeze your script. In vb6.0 you have to add DoEvents To preve3nt it from freezing.
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Mon Jan 07, 2008 12:03 pm Post subject: |
|
|
| Umm, a thread? Whats DoEvents?
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Mon Jan 07, 2008 12:12 pm Post subject: |
|
|
DoEvents is the thing used in vb6.0 DirectX Fast Loop to prevent it from freezing up.
Create a new project and try it.
Do while 1=1
Loop
Try this and your comp will freeze.
Do while 1=1
DoEvents
Loop
And it wont.
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Mon Jan 07, 2008 12:16 pm Post subject: |
|
|
Any idea how can I do it in C#?
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Mon Jan 07, 2008 12:21 pm Post subject: |
|
|
Application.DoEvents();
_________________
|
|
| Back to top |
|
 |
i__h4x Grandmaster Cheater Supreme
Reputation: 0
Joined: 09 Jun 2007 Posts: 1005 Location: i__<3's__wpe
|
Posted: Mon Jan 07, 2008 12:26 pm Post subject: |
|
|
No, its not that it dosnt work, it ist just too slow. I want it to search faster
_________________
Mes'a back!
 |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8585 Location: 127.0.0.1
|
Posted: Mon Jan 07, 2008 12:28 pm Post subject: |
|
|
| dnsi0 wrote: | DoEvents is the thing used in vb6.0 DirectX Fast Loop to prevent it from freezing up.
Create a new project and try it.
Do while 1=1
Loop
Try this and your comp will freeze.
Do while 1=1
DoEvents
Loop
And it wont. |
While DoEvents is used in DirectX applications that are developed with VB, that isn't the reason it was created. In your application when you process code, the process only handles 1 message from the queue at a time. The other messages wait until that message is done, then the next message is handled.
DoEvents tells the program to continue processing the event queue even while other events are still being handled. It's not something thats good to use unless you know your code wont conflict with itself while it is used. In that case, you should use it with care and only during certain occasions. If you feel you have to use it, look for other ways to write your program to prevent it from freezing.
_________________
- Retired. |
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Mon Jan 07, 2008 12:37 pm Post subject: |
|
|
Yeah, it's in .NET--that's the problem.
You'll have to write some kind of DLL in like C or something if you want it to go fast--you've optimized it about as much as you can.
_________________
|
|
| Back to top |
|
 |
i__h4x Grandmaster Cheater Supreme
Reputation: 0
Joined: 09 Jun 2007 Posts: 1005 Location: i__<3's__wpe
|
Posted: Mon Jan 07, 2008 12:42 pm Post subject: |
|
|
Hmmm ok, just a random idea that probablly isnt very good coding practice, but could i split the search up into multiple threads and then return them all the the main after each is finished?
_________________
Mes'a back!
 |
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Mon Jan 07, 2008 12:43 pm Post subject: |
|
|
| Eh, thanks, works fine but still, cheat engine gets all addresses from 0 to FFFFFFFF in 2 seconds, mine takes forever just for 5000...
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Mon Jan 07, 2008 12:53 pm Post subject: |
|
|
Look at ce's code for scanning
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Mon Jan 07, 2008 12:59 pm Post subject: |
|
|
| i__h4x wrote: | | Hmmm ok, just a random idea that probablly isnt very good coding practice, but could i split the search up into multiple threads and then return them all the the main after each is finished? |
A while back, I thought of that--it's not good practice at all--I forget where this comes from, but I think it's Coding Horror: "If you're questioning the limits of your system, chances are that you aren't doing it right."
There are only about 25 or so usable threads in a program (the thread pool), and you'd have to use one hell of a lot of threads to get it quickly.
~~
| Symbol wrote: | | Eh, thanks, works fine but still, cheat engine gets all addresses from 0 to FFFFFFFF in 2 seconds, mine takes forever just for 5000... |
As I said before, it's because you're doing it in .NET.
.NET is simply slower, especially when calling unmanged things, than unmanaged applications, such as Cheat Engine.
What I reccomend doing, if you want to continue in C#, is do a lot of speed tests (I'll give you a quick tut in a minute), to optimize it fully.
Or you could always do it in ASM.
~~~~~
DOING SPEED TESTS IN C#
Create a new Console App, name it whatever.
Put this code in your main method:
| Code: |
DateTime test_1_start;
DateTime test_1_end;
TimeSpan test_1_total;
DateTime test_2_start;
DateTime test_2_end;
TimeSpan test_2_total;
long l;
//Also, if you're gonna use other variables, declare them up here, it gives
//you the most accurate results
//~~~~~~~~~
//begin test 1
//~~~~~~~~~
Console.WriteLine("Beginning test 1... Press enter to start.");
Console.ReadLine();
test_1_start = DateTime.Now;
//Do test 1 here instead of for loop
for (l = 0; l < 1000000; l++)
{}
test_1_end = DateTime.Now;
test_1_total = test_1_end.Subtract(test_1_start);
Console.WriteLine("Test 1 : " + test_1_total.ToString());
Console.WriteLine();
Console.ReadLine();
Console.Clear();
//~~~~~~~~~
//begin test 2
//~~~~~~~~~
Console.WriteLine("Beginning test 2... Press enter to start.");
Console.ReadLine();
test_2_start = DateTime.Now;
//Do test 2 here, instead of the for loop
for (l = 0; l < 1000000; l = l + 1)
{}
test_2_end = DateTime.Now;
test_2_total = test_2_end.Subtract(test_2_start);
Console.WriteLine("Test 2: " + test_2_total.ToString());
Console.WriteLine("Press enter...");
Console.ReadLine();
Console.Clear();
//comparison
Console.WriteLine("Test 1: " + test_1_total.ToString());
Console.WriteLine("Test 2: " + test_2_total.ToString());
|
Edit:
| dnsi0 wrote: | Look at ce's code for scanning  |
I actually tried that. It, like most of CE's other code, is incredibly confusing.
_________________
|
|
| Back to top |
|
 |
i__h4x Grandmaster Cheater Supreme
Reputation: 0
Joined: 09 Jun 2007 Posts: 1005 Location: i__<3's__wpe
|
Posted: Mon Jan 07, 2008 1:06 pm Post subject: |
|
|
Ok, ive been talking to some other people about this.
They reccomended instead of reading the memory address by address, to store the memory in an array of bytes and then searching that.
Im going to test this in a few days to see if the speed is increased, if somebody else wants to give it a shot, let me know the results
_________________
Mes'a back!
 |
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Mon Jan 07, 2008 1:08 pm Post subject: |
|
|
Actually, that sounds good--that may be what CE does. I'll try that.
_________________
|
|
| Back to top |
|
 |
|