| View previous topic :: View next topic |
| Author |
Message |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Sat Oct 06, 2007 12:53 pm Post subject: [Delphi] Problems with DB's 'Assemble' function.. |
|
|
Hey
I'm trying to make something, and I really need this function.. So I made this DLL, and I exported this functions, but everytime I try using it in C it just give me error..
Oh, and I defined it as stdcall in both the dll and the C application.
I also have another problem.. I made a DLL in C, but I have problems to use it in Delphi. The function requires 2 string parameters, and I tryed converting Delphi's 'string' type to 'PChar', and it still doesn't work...
Any idea?
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Oct 06, 2007 1:06 pm Post subject: |
|
|
Give us the source otherwise its very hard for us to help you.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Sat Oct 06, 2007 1:14 pm Post subject: |
|
|
| Code: |
uses
SysUtils,
Classes,
Assemblerunit in 'Assemblerunit.pas',
symbolhandler in 'symbolhandler.pas';
{$R *.res}
exports Assemble;
begin
end.
|
And I renamed DB's function to 'Assemble2', and then make this 'Assemble':
| Code: |
function Assemble(opcode:PChar; address: dword;var bytes: TAssemblerBytes): BYTE; stdcall;export;
begin
if Assemble2(opcode,address,bytes) then
result:=BYTE(length(bytes))
else
result:=0;
end; |
The C application that reads it is 100% fine.
BTW, I deleted everyting in DB's functions that is compiled if 'autoassemblerdll' is not declared.
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25821 Location: The netherlands
|
Posted: Sat Oct 06, 2007 2:08 pm Post subject: |
|
|
that is because you're using TAssemblerBytes as a parameter, which is a declared array, that gets reallocated during runtime
replace it with a pointer to a array of byte's and provide a maximum size it can be. And in your stub add some checks to make sure it isn't overwritten
| Code: |
function Assemble(opcode:PChar; address: dword; bytes: PByteArray; maxsize: integer): BYTE; stdcall;export;
var bytes2: tassemblerbytes;
begin
setlength(bytes2,0);
if Assemble2(opcode,address,bytes2) then
begin
if length(bytes2)>maxsize then
copymemory(bytes,bytes2,maxsize)
else
copymemory(bytes,bytes2,length(bytes2));
result:=BYTE(length(bytes2));
end
else
result:=0;
end;
|
_________________
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 |
|
 |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Sat Oct 06, 2007 11:58 pm Post subject: |
|
|
Thanks DB.. It works now
BTW, it's a really usefull function..
My other problem is using C function that looks like this:
| Code: | extern "C" DWORD __stdcall GetProcessIDFromWindowName(char* ClassName, char* WindowName)
{
HWND hWnd;
DWORD pID;
hWnd = FindWindow(ClassName, WindowName);
if(!hWnd)
return 0;
GetWindowThreadProcessId(hWnd, &pID);
return pID;
} |
in Delphi (threw a DLL). I've tryed doing something like:
| Code: | | Function GetProcessIDFromWindowName(ClassName, WindowName: PChar): DWORD; stdcall; external 'Injecting.dll'; |
And then using it like:
| Code: | pID:=GetProcessIDFromWindowName(PChar(Edit1.Text),PChar(Edit2.Text));
if(pID<>0) then
Label1.Caption:='Found!!!'
else
Label1.Caption:='Not Found...'; |
But it always returned 0, even when it was supposed to return the pID.
BTW: It works fine when I'm trying to use this function from a C application
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25821 Location: The netherlands
|
Posted: Sun Oct 07, 2007 6:41 am Post subject: |
|
|
might depend on your C-compiler, since FindWindow is not a real export. So it has to look at the defines it it calls FindWindowA or FindWindowW (Visual C++ 2005 or later usually prefer FindWindowW)
Delphi (or at least delphi7) has by default ascii instead of unicode, so try explicitly calling FindWindowA
_________________
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 |
|
 |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Sun Oct 07, 2007 7:55 am Post subject: |
|
|
I still have some problems with that... I tryed:
| Code: | hWindow:=FindWindowA(PChar(Edit1.Text),PChar(Edit2.Text));
if DWORD(hWindow)=0 then
raise exception.Create('DAMMIT!'); |
in delphi, but it always gives me the exception...
|
|
| Back to top |
|
 |
|