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 


[Solved] What causes this memory read violation in CS:S?

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

Joined: 04 Mar 2008
Posts: 172

PostPosted: Fri Mar 21, 2008 6:29 am    Post subject: [Solved] What causes this memory read violation in CS:S? Reply with quote

Fixed. Cheers for the help - problem was that I wrote too many bytes to the memory address ... lol, I'm sorry for wasting people's time. I just finally noticed in the disassembler what was happening on the bytes after the one I was writing to. =\ I learned some useful code and gained a bit of knowledge figuring this out though (how to NOP with API's - which is how I found the error, the VPEx API, and a few other small things Very Happy)

So yeah, thanks again for the help. Laughing

Quote:
Hey, I was wondering if someone could help me out here.

I come upon this error every time I use my code to modify the sv_cheats variable in CS:S. (the error occurs when-ever I try to access the console or options, otherwise it's fine)

Error wrote:
The instruction at "0x0d86b423" referenced memory at "0x00000038". The memory could not be "read".


The address is dynamic in the error message, the address for the sv_cheats variable isn't.

I'm using this code to open, write and close the process (which generally work fine):
Code:
        [DllImport("kernel32.dll")]
        private static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, bool bInheritHandle, UInt32 dwProcessId);

        [DllImport("kernel32.dll")]
        private static extern Int32 CloseHandle(IntPtr hObject);

        [DllImport("kernel32.dll")]
        private static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);


This code writes to the memory (which also generally works fine):
Code:
            bBuff = BitConverter.GetBytes(data);
            return WriteProcessMemory(hProc, (IntPtr)address, bBuff, 4, out bytesRW);


Finally, I'm using All_Access (have tried write+operation) to open the process (tried both inheriting the handle and not inheriting).

Any help would be appreciated, if there's something I missed: please point it out.


Last edited by Estx on Sun Mar 23, 2008 6:10 am; edited 2 times in total
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Fri Mar 21, 2008 7:38 am    Post subject: Reply with quote

It might be that the pages are protected, or maybe you've just got the wrong address.

I forget which, but there's an API to change the property of a page; you should look for it on MSDN.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Estx
Expert Cheater
Reputation: 0

Joined: 04 Mar 2008
Posts: 172

PostPosted: Fri Mar 21, 2008 8:39 am    Post subject: Reply with quote

I've got the right address, I know that much.

Will check for the page properties or w/e it's called API on MSDN.

Thanks for the reply.

Edit: Oh, by the way. When I modify the address with Cheat Engine - access is fine. So I know I am definitely missing some API calls or have written something incorrect.
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Fri Mar 21, 2008 9:09 am    Post subject: Reply with quote

samuri25404 wrote:
It might be that the pages are protected, or maybe you've just got the wrong address.

I forget which, but there's an API to change the property of a page; you should look for it on MSDN.


VirtualProtectEx
Back to top
View user's profile Send private message MSN Messenger
Estx
Expert Cheater
Reputation: 0

Joined: 04 Mar 2008
Posts: 172

PostPosted: Fri Mar 21, 2008 10:17 am    Post subject: Reply with quote

I still fail, lol. It hasn't change anything, perhaps I'm making a mistake with the API call. (called after WriteProcessMemory)

Code:
        [DllImport("kernel32.dll")]
        static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);
        public bool RemoveProtection()
        {
            uint tUInt = 0;
            return VirtualProtectEx(hProc, (IntPtr)0x00000000, (UIntPtr)0xFFFFFFFF, 0x04, out tUInt);
        }


The code above returns false, I've tried 'PAGE_READWRITE' and 'PAGE_EXECUTE_READWRITE', both resulting in the former mentioned.

The address that most frequently appears referenced to is: 0x00000038, if it isn't that, then it's a random address with the same reference as that random address.
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Fri Mar 21, 2008 7:15 pm    Post subject: Reply with quote

Estx wrote:
I still fail, lol. It hasn't change anything, perhaps I'm making a mistake with the API call. (called after WriteProcessMemory)

Code:
        [DllImport("kernel32.dll")]
        static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);
        public bool RemoveProtection()
        {
            uint tUInt = 0;
            return VirtualProtectEx(hProc, (IntPtr)0x00000000, (UIntPtr)0xFFFFFFFF, 0x04, out tUInt);
        }


The code above returns false, I've tried 'PAGE_READWRITE' and 'PAGE_EXECUTE_READWRITE', both resulting in the former mentioned.

The address that most frequently appears referenced to is: 0x00000038, if it isn't that, then it's a random address with the same reference as that random address.


It's been a while since I've used VPEX, but try just using your addy as the address.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Estx
Expert Cheater
Reputation: 0

Joined: 04 Mar 2008
Posts: 172

PostPosted: Sat Mar 22, 2008 4:31 am    Post subject: Reply with quote

VirtualProtectEx returns true when I allow read/write/exec to all the addresses involved.

Tried using several addresses (including the sv_cheats address) with multiple lengths, still to no avail.

The main error that occurs comes from this area of memory:
Code:
Error Signature
   Address: 0000b423
   Module: datacache.dll
      Image Base: 0x0d860000, size: 0x0


Which is where 0x0d86b423 comes from, this references 0x00000038. (assuming that's in the same module, the address returns 0x0)

I've googled around for ages as well, still having no luck. Spent about 3 hours on this (tonight alone lol), but I'm just not experienced enough with ASM & Memory editing to figure it out from that. I am teaching my self ASM at the moment, but I feel it will be some time before I completely understand what's happening here lol.

If there's anything else you guys can suggest, I would really appreciate it. Very Happy For now, I'll just keep trying different approaches. =\
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sat Mar 22, 2008 7:14 am    Post subject: Reply with quote

Try this:

Change your import signature to this:

Code:

[DllImport("whatever", SetLastError = True)]
...


Then, after you call, say VPEx, do this:

Code:

MessageBox.Show(Marshal.GetLastWin32Error.ToString());


You should get a MessageBox with a number in it. Go to Tools -> Error Lookup (assuming that you're using Visual Studio), and punch in that number. Click "Look up" and check out the error. See if you can resolve it from there.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Estx
Expert Cheater
Reputation: 0

Joined: 04 Mar 2008
Posts: 172

PostPosted: Sat Mar 22, 2008 7:48 am    Post subject: Reply with quote

Returns zero on all API calls that are made, which means there's no error via the calls.. man what a mission this is lol.

If it returned non-zero I would've been very happy lol (makes it a whole lot easier when you know what the problem is).

Added to your reputation for helping out this far. Cheers man.
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Sat Mar 22, 2008 11:06 am    Post subject: Reply with quote

You cant read/write memory that not exists(Not allocated).
So try Alloc the address before you read/write the memory.
Back to top
View user's profile Send private message
Estx
Expert Cheater
Reputation: 0

Joined: 04 Mar 2008
Posts: 172

PostPosted: Sat Mar 22, 2008 11:30 pm    Post subject: Reply with quote

I have no problems with reading / writing to the actual memory. I can modify all the variables easily (used cheat-engine / visual perception to determine that lol)

The addresses seem to be all already allocated, unless I need to use HeapAlloc or something? I did an API hook on C.E. and browsed through all of it's calls, but nothing stood out..

0x0da27e13 references: 0x00000038, but holds the bytes (used 64 for length just in case it isn't just 4 bytes that display the ASM):
Code:
FF 52 38 5E C2 04 00 CC
CC CC CC CC CC 56 8B 74
24 08 85 F6 7C 05 3B 71
08 7C 06 32 C0 5E C2 04
00 56 E8 A6 AF FF FF 3B
C6 0F 95 C0 5E C2 04 00
CC CC CC CC CC CC CC CC
CC CC CC CC CC 8B 44 24


That any help..?
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