Recent

Author Topic: Pls assist, I am having errors.  (Read 7422 times)

shonay

  • Full Member
  • ***
  • Posts: 169
Pls assist, I am having errors.
« on: July 31, 2014, 11:10:37 pm »
Good evening,
I have a unit, I am trying to code, I get errors around here
Code: [Select]
nHook.pas(18,20) Error: Incompatible types: got "Byte" expected "Char" , I am still trying to learn as I am learning via Forums.
My source  code looks like this
Code: [Select]
unit nHook;

{$mode delphi}{$H+}

interface
   uses
     Windows , Classes, SysUtils;
function nHookCode(TargetProc, NewProc: pointer; var OldProc: pointer):Boolean;
implementation
function nHookCode(TargetProc, NewProc: pointer; var OldProc: pointer):Boolean;
var
oldProtect:DWORD;
i:integer;
nNops:integer;

begin
  VirtualProtect(OldProc,5 + nNops,PAGE_EXECUTE_READWRITE,@oldProtect);
  PChar(OldProc)^:=$E9;
  PDWord(DWORD(OldProc)+1)^:=DWORD(NewProc)-DWORD(OldProc)-5;
  for i:=0 to nNops -1 do begin PBYTE(DWORD(OldProc)+5+i)^:=$90 end;
  VirtualProtect(OldProc,5+nNops,OldProtect,@OldProtect);
end;
end.

I honestly do not have an idea of this kind of error, what could be wrong. Doesn't pop out any Message box to show hooked.
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Pls assist, I am having errors.
« Reply #1 on: July 31, 2014, 11:16:41 pm »
This means that the compiler has found a Byte instead of a Char, which should be the type, at the line and position showed on the message (18, 20).

shonay

  • Full Member
  • ***
  • Posts: 169
Re: Pls assist, I am having errors.
« Reply #2 on: July 31, 2014, 11:21:10 pm »
This means that the compiler has found a Byte instead of a Char, which should be the type, at the line and position showed on the message (18, 20).

Um, so anyways to correct it? Pls. I mean the error.
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Pls assist, I am having errors.
« Reply #3 on: July 31, 2014, 11:24:56 pm »
It is a puzzle for you, Shonay. Compare line 18 in this post with your other post. The answer is there.

"To save the batteries, he smashed the flash light!"

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Pls assist, I am having errors.
« Reply #4 on: July 31, 2014, 11:29:50 pm »
Could you point what is the line 18 in your code?

Note that caret is there on 18, 20 position. You simply need to look at it to know where is the error.
« Last Edit: July 31, 2014, 11:37:06 pm by typo »

shonay

  • Full Member
  • ***
  • Posts: 169
Re: Pls assist, I am having errors.
« Reply #5 on: July 31, 2014, 11:37:14 pm »
Could you point what is the line 18 in your code?

Note that caret is there on 18, 20 position. You simply need to look at it.

Code: [Select]
PChar(OldProc)^:=$E9;
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Pls assist, I am having errors.
« Reply #6 on: July 31, 2014, 11:41:14 pm »
Well done, Shonay. Now, this is line 18. What about character 20? What is it?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Pls assist, I am having errors.
« Reply #7 on: July 31, 2014, 11:42:29 pm »
Well, try this (at least it compiles, I don't know whether it makes sense):

Code: [Select]
PChar(OldProc)^ := Chr($E9);
« Last Edit: July 31, 2014, 11:46:01 pm by typo »

shonay

  • Full Member
  • ***
  • Posts: 169
Re: Pls assist, I am having errors.
« Reply #8 on: July 31, 2014, 11:51:23 pm »
Throws a new Error,

Project raised an exception class 'External : SIGSEGV'

In filenHook.pas at line 18 :
PChar(OldProc)^:=Char($E9);
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Pls assist, I am having errors.
« Reply #9 on: July 31, 2014, 11:57:05 pm »
But it does compile.

shonay

  • Full Member
  • ***
  • Posts: 169
Re: Pls assist, I am having errors.
« Reply #10 on: August 01, 2014, 12:04:56 am »
O yes it does. But when I run it, its suppose to hook a MessageBox() and show 'Hooked' on my screen. :( unfortunately, it doesn't.

Would u like to see the source code of the MessageBox Hook?
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Pls assist, I am having errors.
« Reply #11 on: August 01, 2014, 12:06:50 am »
But when I run it, its suppose to hook a MessageBox() and show 'Hooked' on my screen. :( unfortunately, it doesn't.
You did get that before, didn't you. Just go back to your older posts.

shonay

  • Full Member
  • ***
  • Posts: 169
Re: Pls assist, I am having errors.
« Reply #12 on: August 01, 2014, 12:09:02 am »
But when I run it, its suppose to hook a MessageBox() and show 'Hooked' on my screen. :( unfortunately, it doesn't.
You did get that before, didn't you. Just go back to your older posts.

Except, it wasn't fixed. So if it was, obbviously I wouldn't ask again :(
Just wondering what the issue is.
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Pls assist, I am having errors.
« Reply #13 on: August 01, 2014, 12:53:10 am »
You could try also:

Code: [Select]
PChar(OldProc) := PChar($E9);

or

Code: [Select]
PChar(OldProc)^ := PChar($E9)^;
« Last Edit: August 01, 2014, 01:01:27 am by typo »

shonay

  • Full Member
  • ***
  • Posts: 169
Re: Pls assist, I am having errors.
« Reply #14 on: August 01, 2014, 10:04:49 am »
You could try also:

Code: [Select]
PChar(OldProc) := PChar($E9);

or

Code: [Select]
PChar(OldProc)^ := PChar($E9)^;

Still throws the same errors.just checking what I can do.
When the power of love overcomes the love of power, the world would know Peace

- Jimi Hendrix.

 

TinyPortal © 2005-2018