Page 1 of 1

possible bug - thread crashing due to an unknown reason

Posted: Sun Jun 08, 2008 1:30 pm
by reijin
Hello!!
Im not new to PB and i already tried to fix this problem. And posted it in the german forum - without any result.

This code is part of a dll. It will be injected into a process.
What is should do:
Showing a messagerequester.
waiting for pushing the HOME-Key.
OPening a window.

Code: Select all

Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Text_0
  #val
  #Button_1
EndEnumeration

;- Fonts
Global FontID1
FontID1 = LoadFont(1, "Courier New", 10)

Procedure.l HexDec(h$)
  h$=UCase(h$)
  For r=1 To Len(h$)
    d<<4 : a$=Mid(h$,r,1)
    If Asc(a$)>60
      d+Asc(a$)-55
    Else
      d+Asc(a$)-48
    EndIf
  Next
  ProcedureReturn d
EndProcedure

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 289, 142, 188, 98, "IngameMenu - TEST",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_WindowCentered )
    If CreateGadgetList(WindowID(#Window_0))
      TextGadget(#Text_0, 10, 10, 90, 30, "Value at 0x004e8154:")
      SetGadgetFont(#Text_0, FontID1)
      StringGadget(#val, 100, 20, 80, 20, "", #PB_String_ReadOnly)
      SetGadgetFont(#val, FontID1)
      ButtonGadget(#Button_1, 10, 60, 170, 30, "Injection-Test")
     
    EndIf
  EndIf
EndProcedure

Procedure main(dummy)
Repeat 
Delay(100)
Until GetAsyncKeyState_(VK_INSERT) <> 0
Open_Window_0()

SetGadgetText(#val, Str(PeekL(HexDec("004e8154"))))


Repeat ; Start of the event loop
  
  Event = WaitWindowEvent() ; This line waits until an event is received from Windows
  
  WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
  
  GadgetID = EventGadget() ; Is it a gadget event?
  
  EventType = EventType() ; The event type
  
  ;You can place code here, and use the result as parameters for the procedures
  
  If Event = #PB_Event_Gadget
      
    If GadgetID = #Button_1
      MessageRequester("dont klick", ">_<")
    EndIf
    
  EndIf
  
Until Event = #PB_Event_CloseWindow ; End of the event loop
EndProcedure

MessageRequester("hackdll", "I have been injected!")
CreateThread(@main(), dummy)
What it does:
Showing a messagerequester.
Quitting.
By debugging i found out that the code keeps crashing, when it reaches the "delay".
Is this a bug? Thanks in advice.

greetings, reijin

Posted: Sun Jun 08, 2008 2:32 pm
by Trond
Have you compiled with the threadsafe option enabled?

Re: possible bug - thread crashing due to an unknown reason

Posted: Sun Jun 08, 2008 2:52 pm
by tinman
reijin wrote:

Code: Select all

MessageRequester("hackdll", "I have been injected!")
CreateThread(@main(), dummy)
What it does:
Showing a messagerequester.
Quitting.
By debugging i found out that the code keeps crashing, when it reaches the "delay".
Is this the code you are testing? Because you will create the thread but the main thread will come to the end of the program and exit (including destroying your thread).

It would appear to be caused by the delay() command because when your new thread calls delay execution would switch back to the main thread (which would be when the program would exit).

Posted: Sun Jun 08, 2008 5:15 pm
by IceSoft
Solved.

The # was missed on

Code: Select all

GetAsyncKeyState_(VK_INSERT)

Posted: Sun Jun 08, 2008 7:07 pm
by AND51
IceSoft wrote:Solved.

The # was missed on

Code: Select all

GetAsyncKeyState_(VK_INSERT)
You should use EnableExplicit; always!!

> Procedure.l HexDec(h$)
Äh... The function Val(), does also support Bin- and Hex-numbers since version 4.20!

P.S.:
if you're german, feel free to join the german PB-Forum: http://www.pure-board.de