Jump to content


Photo

Requesting Wrapper For Existing Dll


  • Please log in to reply
14 replies to this topic

#1 tsa05

tsa05

    GMC Member

  • New Member
  • 713 posts
  • Version:GM:Studio

Posted 13 March 2009 - 01:20 AM

Hi there gmc,

Could somebody do a huge favor for me? I'm looking to have the P6CryptAES dll wrapped. It is a simple job to do...except for the unfortunate fact that I have not touched C or C++ in almost 8 years. :snitch:

The site for this Dll is here: http://www.wizardwrx...P6CryptAES.html
It has 10 encrypting functions, but only 4 that are needed for use with Game Maker (encrypt and decrypt for 65k string and for any length file). The problem is, these functions take in pointers to strings instead of strings, and GM does not create pointers. Could somebody assist? The source code for that Dll is provided on its site as well as the original dll, and it's so well documented that even I could almost make it work.

This would be a really nice addition to the community. The topic of encryption floats around here from time to time (passing secure network traffic, etc), and I have seen many techniques that do not yield strong encryption. This Dll provides current AES-strength encryption, which would definitively end the need for other algorithms. And, it's licensed under the lesser GPL, so it can be used and distributed freely for commercial works (I know that's an issue that comes up quite a bit).

Thank you thank you!
  • 0

#2 freaked

freaked

    freak up!

  • New Member
  • 890 posts

Posted 13 March 2009 - 06:00 AM

The problem is, these functions take in pointers to strings instead of strings, and GM does not create pointers.

Those functions take LPTSTR's.
Heres how to convert LPTSTR's(wchar_t) to char*
(MSDN)
wchar_t *orig = L"Hello, World!";
	wcout << orig << L" (wchar_t *)" << endl;

	// Convert to a char*
	size_t origsize = wcslen(orig) + 1;
	const size_t newsize = 100;
	size_t convertedChars = 0;
	char nstring[newsize];
	wcstombs_s(&convertedChars, nstring, origsize, orig, _TRUNCATE);
	strcat_s(nstring, " (char *)");
	cout << nstring << endl;

  • 0

#3 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 13 March 2009 - 08:29 AM

The problem is, these functions take in pointers to strings instead of strings, and GM does not create pointers.

I do not currently know if it has changed for v7.0 , but v6.x certainly did/does use pointers for its strings. Changing a provided string in a DLL will be visible in GM itself (I've used that "trick" once-or-twice myself).

Mind you, you cannot change its length, just its contents.
  • 0

#4 tsa05

tsa05

    GMC Member

  • New Member
  • 713 posts
  • Version:GM:Studio

Posted 13 March 2009 - 02:19 PM

I do not currently know if it has changed for v7.0 , but v6.x certainly did/does use pointers for its strings.

It does? :snitch: I didn't know that. How do I pass a pointer to a dll?? The only 2 parameter types it provides are real and string; is there some way to get a pointer for a string and pass it as a real? Or is do I just pass a variable name... Hm. Based on your input, I'll try fiddling with a bit more. But do feel free to clarify if I'm wandering astray!

@freaked:Ah--didn't realize that...maybe that's why this wasn't working for me...
  • 0

#5 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 14 March 2009 - 01:11 AM

How do I pass a pointer to a dll?? The only 2 parameter types it provides are real and string;

At least in v6.x the "ty_string" seems to be "by reference" (transferrring the pointer), while the "ty_real" seems to be "by value" (the contents).

In other words : you do not need to change anything, nor can you change anything to it. :lol: ^_^

Or is do I just pass a variable name...

You never do (pass the variable-name) (not in GM, nor in any other language I know of). If-and-when you pass a pointer-to data (string or variable) you "catch" that pointer into the arguments defined in the function (which can have a totally different name as the one origionally used for the string/value).

Compare it with how GMs functions work : you allways transfer contents, never variable/resource-names (and no, transferring a string which contains something resembling a variable/resource-name is not the same : you need a "variable_????_get(...)" to actually access the data, which is quite different from how a real variable gets accessed) )

Hope that clarifies it/helps.
  • 0

#6 SenJe0

SenJe0

    GMC Member

  • GMC Member
  • 733 posts

Posted 18 July 2012 - 02:45 PM

I need this badly!!!! :sad: :sad: :sad: :sad: :sad: :sad:
  • 0

#7 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 379 posts
  • Version:GM8

Posted 18 July 2012 - 08:12 PM

Using the (my) GM DLL extension you might be able to use this without having to write a wrapper dll - other than GM's dll functions it also allows passing int/long arguments which some of these functions seem to require.

Edited by Master Xilo, 18 July 2012 - 08:12 PM.

  • 0

#8 SenJe0

SenJe0

    GMC Member

  • GMC Member
  • 733 posts

Posted 19 July 2012 - 10:55 AM

its not working
  • 0

#9 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 379 posts
  • Version:GM8

Posted 19 July 2012 - 12:18 PM

Which commands did you try? How is it not working? Do you get an empty result? How are you using it? Maybe I can look into it.
  • 0

#10 SenJe0

SenJe0

    GMC Member

  • GMC Member
  • 733 posts

Posted 20 July 2012 - 01:02 PM

Which commands did you try? How is it not working? Do you get an empty result? How are you using it? Maybe I can look into it.

The file encryption fuction. I get only empty strings. In fact Im not gettin the head and tail of all this.
  • 0

#11 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 379 posts
  • Version:GM8

Posted 20 July 2012 - 05:30 PM

I just found a bug in GM DLL which prevented you from loading dlls in the current directory. Try again now (redownload and install the extension). Make sure dll_load and dll_define return non-null or non-negative (for the latter) values.

I will try too.

EDIT: Well first of all the documentation on the webpage is wrong, the header says the declaration is
LPTSTR APIENTRY EncryptString_P6C (	// One-call encryption function.
    LPCVOID plpstrPlaintext ,			// Pointer to invariant plaintext string .
    LPCTSTR plpszPassword ,				// Pointer to invariant password string
	unsigned int puintCTxtLen			// Length, in bytes, of data to which 
	                                    // plspstrCipherText points
)

But when calling this, I get different results every time I call it and the text cannot be decoded...

Edited by Master Xilo, 20 July 2012 - 06:31 PM.

  • 0

#12 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 379 posts
  • Version:GM8

Posted 20 July 2012 - 06:29 PM

I can get EncryptFile_P6C and DecryptFile_P6C to work like this:

var dll, func, s, rv;

dll = dll_load("P6CryptAES.dll");


////////////////////////////

func  = dll_define(dll, "EncryptFile_P6C", dll_stdcall, ty_dword);
dll_add_arg(func, ty_string);
dll_add_arg(func, ty_string);
dll_add_arg(func, ty_string);

rv = dll_call(func, "1.txt", "2.txt", "password");


show_message("EncryptFile_P6C retval = "+string(rv));



////////////////////////////

func  = dll_define(dll, "DecryptFile_P6C", dll_stdcall, 
ty_dword
//ty_string
);
dll_add_arg(func, ty_string);
dll_add_arg(func, ty_string);
dll_add_arg(func, ty_string);

rv = dll_call(func, "2.txt", "3.txt", "password");


show_message("DecryptFile_P6C retval = "+string(rv));

1.txt and 3.txt end up containing the same has intended.
However 2.txt seems to have different contents every time I run it (but it is still correctly decoded). Does this encryption result in multiple ways to encode the same thing? Well why not.

Edited by Master Xilo, 20 July 2012 - 06:32 PM.

  • 0

#13 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 379 posts
  • Version:GM8

Posted 20 July 2012 - 07:37 PM

Ah, ok, I get the problem with the encrypt and decypt string functions: It's because the Game Maker uses UTF-8 strings, and the things these functions return are heavily malformed when interpreted that way, which is especially bad when using e.g. string_length on them. I added functions to GM DLL to deal with real C style strings.

Still EncryptString_P6C is completely useless, I don't know what the writer of that library was thinking: Every once in a while, the encoded "string" (which is just an array of bytes) itself might contain a zero at any position - in that case, there's no way for us to know the real size of the encoded data and therefore decoding will fail. So we will need to use the _VB versions and decode the BSTR (struct BSTR { long length; WCHAR* str; } ) they return, then somehow store that data in a Game Maker string - or would you mind just getting a pointer that can later be passed to the decoding function?
  • 0

#14 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 379 posts
  • Version:GM8

Posted 21 July 2012 - 12:40 AM

Here we go:

http://gmc.yoyogames...howtopic=547799
  • 0

#15 SenJe0

SenJe0

    GMC Member

  • GMC Member
  • 733 posts

Posted 21 July 2012 - 07:47 PM

Thanks man. Will check and give feedback. I hope it works.
___________________________________________
EXECUTION ERROR in creation code of room room0
In script pc6_encrypt_file:
Error in code at line 2:
///pc6_encrypt_file(sourceFileName, encryptedTargetFileName, password) -> 0 on successreturn dll_call(global.EncryptFile_P6C_, argument0, argument1, argument2);
^
at position 24: Unknown variable EncryptFile_P6C_


for string encryption too I get an error. Or maybe I didn't do stuff right? I loaded the gml script and then added your gex, then added the dll to the same directory of the gm file but I still get errors for both? How do we correct this? did u even get it to work?

Edited by SenJe0, 21 July 2012 - 08:09 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users