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 


how could i use dbk32.dll in my own peocess

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Source
View previous topic :: View next topic  
Author Message
lailei009
How do I cheat?
Reputation: 0

Joined: 05 Feb 2009
Posts: 9

PostPosted: Thu Mar 26, 2009 7:44 am    Post subject: how could i use dbk32.dll in my own peocess Reply with quote

Code:
it want to  jmp  00873236  to 00873243 so i change the eip

this is my source:
//////////////////////////////////////////////////////
///////////////////////////////////////////////////////

typedef   bool   (__stdcall *TChangeRegOnBP)(DWORD Processid,DWORD address,int debugreg,bool changeEAX,bool changeEBX,bool changeECX,bool changeEDX,bool changeESI,bool changeEDI,bool changeEBP,bool changeESP,bool changeEIP,bool changeCF,bool changePF,bool changeAF,bool changeZF,bool changeSF,bool changeOF,DWORD newEAX,DWORD newEBX,DWORD newECX,DWORD newEDX,DWORD newESI,DWORD newEDI,DWORD newEBP,DWORD newESP,DWORD newEIP, bool newCF,bool newPF,bool newAF,bool newZF,bool newSF,bool newOF);

typedef   bool   (__stdcall *TDebugProcess)(DWORD processid,DWORD address, byte size,byte debugtype);
/////////////////////////////////////////////////////////////////
TDebugProcess       DebugProcess;

TChangeRegOnBP        ChangeRegOnBP;

//////////////////////////////////////////////////////////////////
HMODULE  mydll= LoadLibrary("dbk32.dll");

DebugProcess=(TDebugProcess)GetProcAddress(mydll,"DebugProcess");

ChangeRegOnBP=(TChangeRegOnBP)GetProcAddress(mydll,"ChangeRegOnBP");
///////////////////////////////////////////////////////////////
HWND hwnd=FindWindow(NULL,"TTen");

DWORD proid=0;

GetWindowThreadProcessId(hwnd,&proid);

DebugProcess(proid,0x00873236,1,3);

ChangeRegOnBP(proid,0x00873236,0,false,false,false,false,false,false,false,false,true,false,false,false,false,false,false,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0x00873243, false,false,false,false,false,false);

but it doesn't work who konw thy?
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: Thu Mar 26, 2009 8:02 am    Post subject: Reply with quote

DebugProcess is for "Find what accesses and find what writes"
The only one you need is ChangeRegOnBp

As for why it's not working, that's because you have to manually set the debug registers in the threads of the target process.
ChangeRegOnBP just sets a watch in the kernel, for when such a breakpoint occurs on what to do

so,
enumerate all threads in the target process (createtoolhelp32snapshot, thread32first/thread32next)
and set the debug registers to break on execution of 00873236 (openthread,suspendthread,get/setthreadcontext, resumethread)

_________________
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
lailei009
How do I cheat?
Reputation: 0

Joined: 05 Feb 2009
Posts: 9

PostPosted: Thu Mar 26, 2009 10:09 am    Post subject: Reply with quote

thanks,could i sets breakpoint to all thread or find the call thread and set breakpoint?
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: Thu Mar 26, 2009 10:21 am    Post subject: Reply with quote

It's easiest to set it on all threads, then you can be pretty sure that the thread that executes that particular piece of code is captured when it executes it

Of course, it will usually always be the same thread, but probloem would be pinpointing it, so thats why I just pick all

_________________
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
lailei009
How do I cheat?
Reputation: 0

Joined: 05 Feb 2009
Posts: 9

PostPosted: Thu Mar 26, 2009 10:43 am    Post subject: Reply with quote

oh that's right . let me try it .
finnally,you mean the Processid:dword is a thread id??
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: Thu Mar 26, 2009 12:00 pm    Post subject: Reply with quote

no, that processid is the processid of the process
It's used by the kernelroutine to check if the generated breakpoint belongs to the process being debugged.

You just have to set the debug registers to an execute bp at the specified eip on every thread of that particular process, the kernel routine will do the rest (dr0=eip, dr7=3)

_________________
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
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Thu Mar 26, 2009 12:16 pm    Post subject: Reply with quote

Dark Byte wrote:
no, that processid is the processid of the process
It's used by the kernelroutine to check if the generated breakpoint belongs to the process being debugged.

You just have to set the debug registers to an execute bp at the specified eip on every thread of that particular process, the kernel routine will do the rest (dr0=eip, dr7=3)


Isn't it FF to enable all the registers?

Does anyone know why my program crashes when I try to use DR2 and DR3. It works fine with DR0 and DR1.

~Halp T.T
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: Thu Mar 26, 2009 3:51 pm    Post subject: Reply with quote

FF only when DR 1, dr2 and dr3 are used

FF=11111111= 11 11 11 11

Meaning enable g0,g1,g2,g3 and l0,l1,l2,l3
So, if you only use dr0 and don't fill in dr1 to 3 then any access to 0 will generate a breakpoint. (e.g a access check by using a try/except instead of checking if something is really 0)

as for dr2 and dr3 not working properly, not really sure. It does work in ce ? (setting more then 2 change reg on bp, something I never tested since max I ever needed was 2 )
Or perhaps you're not filling in the proper debug registers
Or perhaps the game itself is using dr2 or dr3 (e.g ce's standalone trainer with protect on makes use of a debug register to jump over useless code)

_________________
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
lailei009
How do I cheat?
Reputation: 0

Joined: 05 Feb 2009
Posts: 9

PostPosted: Fri Mar 27, 2009 4:38 am    Post subject: Reply with quote

I also found some mistake, I set a breakpoints and breakpoints should be work but the application is automatically exit ?why

here is my source:
Code:

THREADENTRY32 te;
   HANDLE  threads;
   DWORD  proid=FindGameProcess("TTen.exe");
   HANDLE ths=CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,proid);
   te.dwSize=sizeof(te);
   CONTEXT debugreg;
   debugreg.ContextFlags=CONTEXT_DEBUG_REGISTERS;
   debugreg.Dr7=0x3; //|0xc|0x30|0xc0
   debugreg.Dr0=0x008732EC;

   if(Thread32First(ths,&te))
   {
      while(Thread32Next(ths,&te))
      {
      if(te.th32OwnerProcessID==proid)
      {
                  threads=OpenThread(STANDARD_RIGHTS_REQUIRED| SYNCHRONIZE | 0x3ff,true,te.th32ThreadID);
     }
                  }
   SuspendThread(threads);
   SetThreadContext(threads,&debugreg)
   
   ResumeThread(threads);

ChangeRegOnBP(proid,0x008732EC,0,false,false,false,false,false,false,false,false,false/*eip*/,false,false,false,false,false,false,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, false,false,false,false,false,false)

               
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: Fri Mar 27, 2009 6:19 am    Post subject: Reply with quote

I recommend calling ChangeRegOnBP before setting the debug context. If a breakpoint fires and it's not handled and just passed on to the game, most of the times it will then terminate because an unhandled exception occurred. (And that can happen thanks to taskswitching and multicore cpu's)

Also, your thread enumeration is broken, you're not setting the breakpoint on the first thread (you skip the result of Thread32first)

Actually, you're only doing it on the last thread. (The suspendthread-SetThreadContext-ResumeThread code is outside the whole loop)


Also, make sure dbk32.sys is in the same location as the dll
You might want to use dbgview to make sure everything is being set as expected. Just noticed that if the driver failed to load, ChangeRegOnBP can randomly return true or false

_________________
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
lailei009
How do I cheat?
Reputation: 0

Joined: 05 Feb 2009
Posts: 9

PostPosted: Fri Mar 27, 2009 8:07 pm    Post subject: Reply with quote

i tryed what you said ,but it alway auto exit.

when I call setthreadcontext the application is aoto exit whether I calling ChangeRigsterOnBP

Whether I call RetivedebugData?

how changerigsteronbp work?

can you give me a sample?
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: Sat Mar 28, 2009 6:34 am    Post subject: Reply with quote

First make sure you're not using some uce's driver (they tend to strip out the debugging part completly)

Also, get dbgview, so you know it's working or not

Retrievedebugdata is only needed when using the option to fuind out what accesses an address

changerigsteronbp will first hook interrupt 1 in the idt and then tell the driver to watch for interrupts that happen in the specified process on the given eip address.
Then when such a breakpoint occurs it will handle it itself, instead of telling windows that the interrupt occured. (If it doesn't handle it and just tells windows about it, 99% chance the game will terminate on such a breakpoint)

And with application terminating you mean tyhe target app right? Not your own

and agin, get dbgview from sysinternals. It'll tell you if the driver loaded, what it's going to do, and when an interrupt got fired and if it got handled or not, including the register states in some cases

_________________
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
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Sat Mar 28, 2009 1:52 pm    Post subject: Reply with quote

It works perfect with cheatengine. And Im using my own program to test the registers.
Back to top
View user's profile Send private message
lailei009
How do I cheat?
Reputation: 0

Joined: 05 Feb 2009
Posts: 9

PostPosted: Sun Mar 29, 2009 6:36 am    Post subject: Reply with quote

I know the reasons for the error

The application has np and hooked KiResumeThread and KiSuspendThread

could I use dbkResumeThread and dbkSuspendThread to instead?
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: Sun Mar 29, 2009 1:57 pm    Post subject: Reply with quote

It could work, but it's hardly tested

But what you are describing sounds a lot that you're actually setting the debug registers just fine (I don't know if the suspend is really needed for setting the debugregs alone) and that the game is crashing because of the unhandled breakpoint.

Whats more likely going on here is that the IDT is being unhooked by nprotect.(Game crashes after setting the debug registers) Also, since you say the game is running nprotect, and you're not getting a hack detect message, means you either made your own driver undetected but didn't put in a working bypass for the interrupt 1 unhook by nprotect. Or you reused another driver, e.g moon light engine's driver, which I know has stripped the interrupt1 handler

If you made it yourself, try booting up with dbvm. The driver will then use dbvm for interrupt hooking. (Check if your system supports it by opening ce and rightclick on the ce logo)



But, if you intend on thinking it's the setting of debug registers and not the unhooking of int1(again, I really really doubt it), then fix the global debug routine where it keeps on setting the breakpoint as a read/write breakpoint of a 4 byte length to an execute breakpoint.
Then enable the globaldebug flag and go threadsurfing. The globaldebug method will break on EVERY thread, allowing you to set the debug register you like if you enter in a thread owned by the target process

_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Source 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