Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[VB.NET] WriteProcessMemory

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
DaNemeziz
Master Cheater
Reputation: 0

Joined: 29 Sep 2007
Posts: 430

PostPosted: Wed Nov 26, 2008 11:25 am    Post subject: [VB.NET] WriteProcessMemory Reply with quote

Code:
Imports System.Runtime.InteropServices

Public Class Form1
    <DllImport("kernel32.dll")> _
    Public Shared Function WriteProcessMemory( _
    ByVal hProcess As IntPtr, _
    ByVal lpBaseAddress As IntPtr, _
    ByVal lpBuffer As Byte(), _
    ByVal nSize As UInt32, _
    ByRef lpNumberOfBytesWritten As UInt32 _
    ) As Boolean
    End Function

    Dim hProcess As Process() = Process.GetProcessesByName("winmine")

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WriteProcessMemory(hProcess(0).Handle, &H100579C, New Byte() {255}, 4, 0)
    End Sub
End Class

That is my current source, as you can see - if you understand it - I set the value of the timer to 255. But I can't set it higher than 255, is there a possibility to set it higher? Confused
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Wed Nov 26, 2008 11:27 am    Post subject: Reply with quote

You can use the BitConverter.GetBytes() method to convert another type to bytes, or simply declate the array and type the value reversed, for example for 65534 you could do:
new byte[] { 0xFE, 0xFF }
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Wed Nov 26, 2008 12:07 pm    Post subject: Reply with quote

Code:
New Byte() {255}

You're trying to set a byte to something higher than 255, and that's not possible. So put something like New Int() there.
Back to top
View user's profile Send private message
ElectroFusion
Grandmaster Cheater
Reputation: 0

Joined: 17 Dec 2006
Posts: 786

PostPosted: Wed Nov 26, 2008 12:24 pm    Post subject: Reply with quote

Tombana, you beat me to it. A byte can only go up to 255, so try using int instead, because i'm pretty sure it can go up to 3903284824284284207402057207507 and higher.
_________________
qwerty147 wrote:

ghostonline wrote:

what world are you in?

bera

but i live in NZ
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Nov 26, 2008 12:46 pm    Post subject: Reply with quote

Just be careful to take the Endianness into account when writing bytes like that.

ElectroFusion wrote:
Tombana, you beat me to it. A byte can only go up to 255, so try using int instead, because i'm pretty sure it can go up to 3903284824284284207402057207507 and higher.


and no.
Back to top
View user's profile Send private message
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Wed Nov 26, 2008 12:54 pm    Post subject: Reply with quote

ElectroFusion wrote:
Tombana, you beat me to it. A byte can only go up to 255, so try using int instead, because i'm pretty sure it can go up to 3903284824284284207402057207507 and higher.

lmao.

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
GMZorita
Grandmaster Cheater Supreme
Reputation: 0

Joined: 21 Mar 2007
Posts: 1361

PostPosted: Wed Nov 26, 2008 12:59 pm    Post subject: Reply with quote

ElectroFusion wrote:
Tombana, you beat me to it. A byte can only go up to 255, so try using int instead, because i'm pretty sure it can go up to 3903284824284284207402057207507 and higher.

UNSIGNED:
BYTE = 1 BYTE = 0xFF(MAX) = 255;
WORD = 2 BYTE's = 0xFFFF(MAX) = 65535;
DWORD = 4 BYTE's = 0xFFFFFFFF(MAX) = 4294967295;
QWORD = 8 BYTE's = 0xFFFFFFFFFFFFFFFF(MAX) = 18446744073709551615;

So NO it wont go to "3903284824284284207402057207507 and higher".

Well let me save you from getting "pwned" an int is the samething as an DWORD, it have just 4 BYTE's, remember 0xFFFFFFFF is the max it can reach.

_________________
Gone
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Wed Nov 26, 2008 2:03 pm    Post subject: Reply with quote

Range - signed = -(2^(nBits-1))~2^(nBits-1)-1
Range - unsigned = 0~2^nBits-1

For example:
signed 32-bit: -(2^31)~2^(31)-1 = -2147483648~2147483647
unsigned 32-bit: 0~2^32-1 = 4294967296-1 = 4294967295
Back to top
View user's profile Send private message
ElJEffro
Grandmaster Cheater Supreme
Reputation: 0

Joined: 15 Apr 2007
Posts: 1881
Location: La Tierra

PostPosted: Fri Nov 28, 2008 2:07 am    Post subject: Reply with quote

GMZorita wrote:
ElectroFusion wrote:
Tombana, you beat me to it. A byte can only go up to 255, so try using int instead, because i'm pretty sure it can go up to 3903284824284284207402057207507 and higher.

UNSIGNED:
BYTE = 1 BYTE = 0xFF(MAX) = 255;
WORD = 2 BYTE's = 0xFFFF(MAX) = 65535;
DWORD = 4 BYTE's = 0xFFFFFFFF(MAX) = 4294967295;
QWORD = 8 BYTE's = 0xFFFFFFFFFFFFFFFF(MAX) = 18446744073709551615;

So NO it wont go to "3903284824284284207402057207507 and higher".

Well let me save you from getting "pwned" an int is the samething as an DWORD, it have just 4 BYTE's, remember 0xFFFFFFFF is the max it can reach.


In some processor types int is 16 bit (word)
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Fri Nov 28, 2008 10:48 am    Post subject: Reply with quote

ElJEffro wrote:
In some processor types int is 16 bit (word)

Yes I was thinking about that some time ago:
'long' is 32-bit (dword), 'short' is 16-bit (word), but 'int' can be both. When is an int 16-bit and when is it 32-bit? And what about 64-bits. Does 'long' automatically become 64-bit on a 64-bit system?
Back to top
View user's profile Send private message
arigity
Advanced Cheater
Reputation: 0

Joined: 03 Jul 2008
Posts: 65
Location: middle of nowhere.

PostPosted: Fri Nov 28, 2008 2:14 pm    Post subject: Reply with quote

2 problems here.

<DllImport("kernel32.dll")> _
Public Shared Function WriteProcessMemory( _
ByVal hProcess As IntPtr, _
ByVal lpBaseAddress As IntPtr, _
ByVal lpBuffer As Byte(), _
ByVal nSize As UInt32, _
ByRef lpNumberOfBytesWritten As UInt32 _
) As Boolean
End Function


1. your buffer is not just a byte, but a byte array.


WriteProcessMemory(hProcess(0).Handle, &H100579C, New Byte() {255}, 4, 0)

2. your byte array of 1 is writing 4 bytes. where are the other 3 coming from?

if you wanna write a specific amount of bytes to memory try lopping off the array part (ByVal lpBuffer As Byte) designate an array of bytes (dim mybytes() as byte) and then write them (WriteProcessMemory(Handle, address, mybytes(0), amountofbytes, 0))

if you want to write 436434 to memory change the buffer to an int or something (ByVal lpBuffer As integer) (dim hax as integer = 436434 ) (WriteProcessMemory(Handle, address, hax, 4 , 0))

you write 4 bytes the second time because an int is 4 bytes (in most cases. definitely yours.)


*note* if anything is incorrect or doesn't work, do note that i wrote it in the browser. you may need to change some stuff.

_________________
Back to top
View user's profile Send private message
hacksign23
Master Cheater
Reputation: 0

Joined: 26 Nov 2006
Posts: 404

PostPosted: Fri Nov 28, 2008 5:43 pm    Post subject: Reply with quote

or you could use two writeprocessmemory s and... yea.
_________________
Back to top
View user's profile Send private message AIM Address
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Nov 28, 2008 6:04 pm    Post subject: Reply with quote

Just use the BitConverter class, it has a method that will convert whatever to a byte array.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites