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 write a NOP like in Cheat Engine ?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
silentus
How do I cheat?
Reputation: 0

Joined: 07 Feb 2013
Posts: 9

PostPosted: Tue Mar 19, 2013 8:47 am    Post subject: VB.NET write a NOP like in Cheat Engine ? Reply with quote

Hi !
I need your help, i need to write a NOP to game speed address in SA:MP game.When i write something to this address (0xB7CB64 - [float] Game speed in percent) its automatically changed to its default value (1)
when i make it "Active" in CE, its pretty working however i see that moments when it switchs back to 1, when i find what writes to this address and then change it to code that does nothing (NOP) then it works, but i need to make it in VB.NET, and i kinda have no idea how to make something like this, i know how to use pointers in vb.net etc, but a NOP ? I found some memory module that had write nop function, but it was doing the same as normal write memory..it still was changing to 1
Help please Very Happy
Back to top
View user's profile Send private message
TsTg
Master Cheater
Reputation: 5

Joined: 12 Dec 2012
Posts: 340
Location: Somewhere....

PostPosted: Tue Mar 19, 2013 11:42 am    Post subject: Reply with quote

If you mean how to write a NOP in the dot NET assembly(MSIL), the op code byte is 0x00, while is normal assembly it's 0x90
Back to top
View user's profile Send private message
silentus
How do I cheat?
Reputation: 0

Joined: 07 Feb 2013
Posts: 9

PostPosted: Tue Mar 19, 2013 12:47 pm    Post subject: Reply with quote

ok but how do i use it to lock the value so the game wotn change it ?

EDIT
After tracking what writes to this address, i got this
Quote:

00401190 - C7 05 64CBB700 0000803F - mov [gta_sa.exe+77CB64],3F800000



00401190 - C7 05 64CBB700 0000803F - mov [gta_sa.exe+77CB64],3F800000 <<



EAX=00B7CD98
EBX=00000000
ECX=02CD7800
EDX=00000000
ESI=02CD78D0
EDI=00000000
ESP=0022FC00
EBP=0022FCD0
EIP=0040119A




After double clicking the instruction i got this
Quote:

>> 00401190 - mov [gta_sa.exe+77CB64],3F800000

copy memory
The value of the pointer needed to find this address is probably 0077CB64


EAX=00B7CD98 EDX=00000000 EBP=0022FCD0
EBX=00000000 ESI=02CD78D0 ESP=0022FC00
ECX=02CD7800 EDI=00000000 EIP=0040119A


Could someone help ? i dont understand this cheat engine
Back to top
View user's profile Send private message
SteveAndrew
Master Cheater
Reputation: 30

Joined: 02 Sep 2012
Posts: 323

PostPosted: Tue Mar 19, 2013 6:16 pm    Post subject: Reply with quote

Well if nopping it has the effect you want, you're going to need to NOP all bytes of that instruction...

There are 10 bytes which make up that instruction:

Code:

C7 05 64CBB700 0000803F


C7 05 64 CB B7 00 00 00 80 3F

I don't know how to do that in VB.NET (I don't use that / have never)

but in C/C++ it's this easy:
Code:

memset((void*)0x401190, 0x90, 10);


Or if not inside the process(an injected .dll) and outside instead (an .exe)

Code:

ULONG BytesWritten;
char TenNops[10] = {0};
memset(&TenNops, 0x90, 10);
WriteProcessMemory(GTAHandle, (void*)0x401190, &TenNops, 10, &BytesWritten);


Of course GTAHandle would have to be a valid open handle to the game (from OpenProcess) Wink And the BytesWritten parameter is required for it to work, even if you don't care to check if it did successfully write all 10 bytes afterwards, you still need it.

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

Joined: 12 Dec 2012
Posts: 340
Location: Somewhere....

PostPosted: Tue Mar 19, 2013 7:36 pm    Post subject: Reply with quote

silentus wrote:
ok but how do i use it to lock the value so the game wotn change it ?

EDIT
After tracking what writes to this address, i got this
Quote:

00401190 - C7 05 64CBB700 0000803F - mov [gta_sa.exe+77CB64],3F800000





well, if you want to write the nop of that command by your own program then do as SteveAndrew said, if you want just to nop it from Cheat Enigne memory view window, then right click on the 00401190 - mov [gta_sa.exe+77CB64],3F800000 line then choose 'Replace with code that does nothing' , also if you would like to change the float value of 1 (which is the 0x3F800000) , press enter on the same line and edit the instruction to be something like:
00401190 - mov [gta_sa.exe+77CB64],00000000 (will set it to zero)
Back to top
View user's profile Send private message
foxfire9
Advanced Cheater
Reputation: 0

Joined: 23 Mar 2012
Posts: 57

PostPosted: Wed Mar 20, 2013 9:02 am    Post subject: Reply with quote

You need to know how much NOP's you need. And how will it affect to the system. And also tell the difference that's afffect to that instruction.

I forgot what thread it was.


Last edited by foxfire9 on Wed Mar 20, 2013 8:57 pm; edited 1 time in total
Back to top
View user's profile Send private message
silentus
How do I cheat?
Reputation: 0

Joined: 07 Feb 2013
Posts: 9

PostPosted: Wed Mar 20, 2013 11:25 am    Post subject: Reply with quote

I kinda cant understand how can i write to these bytes ? In what address are they located ?
In CE when i try to add a address 00401190 with a type of byte array, it doesnt give a value, just "???"
When i try to add the same address with a pointer, then it kinda gets the value but reversed and some zeros are missing.
Could just someone explain me what i have to do ? Without any code, because if you tell me what i need to do then i will understand this and code it without any problems.I just have no idea how to write &H90 to those bytes, as i dont know how to find them oO
Back to top
View user's profile Send private message
TsTg
Master Cheater
Reputation: 5

Joined: 12 Dec 2012
Posts: 340
Location: Somewhere....

PostPosted: Wed Mar 20, 2013 1:00 pm    Post subject: Reply with quote

ok let's say you want to NOP the command at
00401190 - C7 05 64CBB700 0000803F - mov[gta_sa.exe+77CB64],3F800000 , right ?

as you see here the: C7 05 64CBB700 0000803F are the bytes you are looking for(in fact every byte consist of two charachters, so this should be: C7 05 64 CB B7 00 00 00 80 3F)

in order to NOP an assembly instruction you have to set all the bytes of it(here we have,...C7 is a one byte, 05 is another byte, so total is 10 bytes), by replacing all the bytes with 90, so it will be: 90 90 90 90 90 90 90 90 90 90).

TAKE IMPORTANT NOTE: that the address 401190 and all the bytes mentioned (including the 90) are all HEXADECIMAL values, so in some programs or developer applications, you will need to add the characters 0x just before the value,(so 90 is 0x90, C7 is 0xC7, the address 401190 is 0x401190, and so on).

If you want to write the values using WriteProcessMemory, you enter the bytes in a reverse order, let's say i will edit 4 bytes starting from
401190 to 401193, this should be:

1)For nopping: use DataToWrite = 0x90909090 <--Four nops
Address = 0x401190 <--as a DWORD or integer value
DataLength = 4 <--Four bytes to edit

2)For restoring original code: use DataToWrite = 0xCB6405C7 <-- the reverse order of the C7 05 64 CB bytes

Now Call: WriteProcessMemory(Process_Handle,Address,DataToWrite,DataLength,RealLength_as_output)

-Now for the next four bytes (out of 10), set Address to (0x401190+4 = 0x401194), and so on.


Last edited by TsTg on Wed Mar 20, 2013 1:06 pm; edited 3 times in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25788
Location: The netherlands

PostPosted: Wed Mar 20, 2013 1:02 pm    Post subject: Reply with quote

Sometimes you may need to use VirtualProtectEx to make the memory writable first
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
silentus
How do I cheat?
Reputation: 0

Joined: 07 Feb 2013
Posts: 9

PostPosted: Wed Mar 20, 2013 2:35 pm    Post subject: Reply with quote

Hmm
i read the value of &H4011190 and it gave me all the bytes that i found in CE, however they were reversed (i needed to convert it to string)
So i thought i will write 90909090909090909090 to this address (of course write as a hex, with &H at start (in VB.NET you use &H for hex))
however this gives me 10 opcodes in game, and crashes:
(i cant post images so i will just copy the text here)
Quote:

Warning(opcode 0x52C): Exception 0xC0000005 at 0x0

and its shown 10 times then game crashes

I used this code (Visual Basic .NET)
Code:

Dim nopped As String = "&H90909090909090909090"
            Try
                WriteMemory(&H401190, nopped)
            Catch
            End Try


If i have to make it like you showed, with 4 bytes and then next 4 bytes then why do i need to add 4 to the address ? when i added 4 to the address it shows different bytes, and i cant make it with 4 bytes all the time because 4 + 4 = 8 and 8 + 4 = 12, not 10
Back to top
View user's profile Send private message
TsTg
Master Cheater
Reputation: 5

Joined: 12 Dec 2012
Posts: 340
Location: Somewhere....

PostPosted: Wed Mar 20, 2013 4:32 pm    Post subject: Reply with quote

Well, i don't write programs in VB.NET language, but here's a sample of using WriteProcessMemory api that i found:

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 p As Process() = Process.GetProcessesByName("ProcessName") <----or just give the handle the way you want
    Dim en1 As Byte() = {&HB8, &HFF, &HFF, &H0, &H0} 'Bytes for a MOV EAX,0FFFF command


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
Try
        WriteProcessMemory(p(0).Handle, &H4972A7, en1, en1.Length, 0) 'the address to write here is 0x4972A7
Catch ex as Exception
MsgBox(ex.ToString)
End Try
            End Sub
End Class


So for your case, i guess you should edit the line:
Code:
    Dim en1 As Byte() = {&HB8, &HFF, &HFF, &H0, &H0}

to be:
Code:
    Dim en1 As Byte() = {&H90, &H90, &H90, &H90, &H90, &H90, &H90, &H90, &H90, &H90}



silentus wrote:

if i have to make it like you showed, with 4 bytes and then next 4 bytes then why do i need to add 4 to the address ?


because if you don't add them to the address, you will only modify the first four bytes from 401190 to 401193, while leaving the remainig 6 bytes unmodified(and that is what crashed your game for sure).

silentus wrote:

when i added 4 to the address it shows different bytes, and i cant make it with 4 bytes all the time because 4 + 4 = 8 and 8 + 4 = 12, not 10


This is just to divide the operation of memory editing(if you want), so you just divide them the way you like:

-write them in one shot(no division)
-or write 10 bytes one by one(means 10 WriteProcessMemory calls)
-or write 4 bytes, then next 4, then the remainig two(3 calls)
-or whatever, it up to you

In the sample above it's written in one call only
Back to top
View user's profile Send private message
silentus
How do I cheat?
Reputation: 0

Joined: 07 Feb 2013
Posts: 9

PostPosted: Thu Mar 21, 2013 8:54 am    Post subject: Reply with quote

Oh thank you for this code, it probably wasnt written in any IDE but just on some forum, i needed to edit it because it had errors like missing commas etc
It works perfectly Smile
Anyways, can i be sure that this address will be static (401190) for all computers if its static on mine ? Always when i find what writes to the speed address i find this address, but i dont have any other computers with gta to test, will it always be the same ?
Back to top
View user's profile Send private message
TsTg
Master Cheater
Reputation: 5

Joined: 12 Dec 2012
Posts: 340
Location: Somewhere....

PostPosted: Thu Mar 21, 2013 12:33 pm    Post subject: Reply with quote

Well you can not always assume the image base will be same on all computers (assuming here it's 400000), so to reach your address you will add the offset 1190 to the base address to be 401190, you can get the image base of the process executable by calling the functions:

-CreateToolhelp32Snapshot
-Module32First
-Module32Next
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684218

Or if you are injecting a dll inside the game to patch it, you can use GetModuleHandle instead
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683199
Back to top
View user's profile Send private message
silentus
How do I cheat?
Reputation: 0

Joined: 07 Feb 2013
Posts: 9

PostPosted: Thu Mar 21, 2013 12:57 pm    Post subject: Reply with quote

Well its very weird, this address wasnt changing for like a week, and after i nopped it in VB.NET and restarted my PC, its completely different.And before it changed, in CE disassembler in "address" there was
"gta_sa.exe + 1190" but now its "gta_sa.exe + 20CD41"

If it changes like this, how can i get this address every time ? I also thought i have to add 1190 to that gta_sa.exe pointer, but it changed from 1190 to 20CD41 ?
Now the proper address with those bytes is 60CD41
It says "The value of pointer needed to find this address is probably 0077CB64" thats the only thing that didnt changed
Back to top
View user's profile Send private message
TsTg
Master Cheater
Reputation: 5

Joined: 12 Dec 2012
Posts: 340
Location: Somewhere....

PostPosted: Thu Mar 21, 2013 2:37 pm    Post subject: Reply with quote

silentus wrote:
there was
"gta_sa.exe + 1190" but now its "gta_sa.exe + 20CD41"


Have you tried looking in 401190 address again?, i guess you will find it has the same bytes of 60CD41, it's just that your value is changed by more than one instruction addresses, go check it out.
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 Gamehacking All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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