Altering incoming text - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Forum: Plug-Ins (/forumdisplay.php?fid=28)
+------ Thread: Altering incoming text (/showthread.php?tid=24106)
Altering incoming text by RooJ on 04-23-2004 at 02:41 PM
Hey, ive just started coding a plugin in vb but im not sure on one thing.
I want it so if my plugin gets a certain notifycode it will alter the incoming text in a certain way such as adding the time to the end of it and then place it in the chat window as normal.. a simple example:
if the notify code is "atest" then i want it to alter the incoming message so it has "test" at the front and the end.
From what ive seen the ReceiveNotify function's sText parameter allows me to get the text sent to me.. i can then say sumthing like mystring = "test " & sText & " test", but how do i get it to add mystring to the conversation window instead of the actual message they sent. Is this actually possible?
Thanks for any help
RooJ
RE: Altering incoming text by Choli on 04-23-2004 at 03:49 PM
No, sorry, you can't do that. In ReceiveNotify you can (as you've said) send a message in response of the incomming one, but you can't modifiy in any way the received message. I know that would be great, however that isn't possible.
RE: Altering incoming text by eXXon on 04-23-2004 at 04:19 PM
Plus, it will be in the next Plus! (ahem)
I hope Patchou'll release a new API to let us mess more with incoming text
RE: RE: Altering incoming text by optimism_ on 04-23-2004 at 04:37 PM
quote: Originally posted by eXXon
Plus, it will be in the next Plus! (ahem)
How do you know this?
RE: Altering incoming text by Choli on 04-23-2004 at 04:44 PM
quote: Originally posted by eXXon
I hope Patchou'll release a new API to let us mess more with incoming text
mmm.... i'm not sure if he'll do that... in the beta version it's not possible (i think)
RE: Altering incoming text by eXXon on 04-23-2004 at 04:49 PM
quote: Originally posted by optimism_
How do you know this?
http://shoutbox.menthix.net/showthread.php?tid=21785
Well, kinda..
there will be a feature to replace incoming words.
BUT, that proofs that Patchou is able to modify incoming text, so I really hope he will let us use that in plugins in the future
RE: Altering incoming text by Choli on 04-23-2004 at 04:52 PM
quote: Originally posted by eXXon
BUT, that proofs that Patchou is able to modify incoming text, so I really hope he will let us use that in plugins in the future
that's not the first proof of patchou beign able to modify incomming texts, also with the color codes, text formatting, /ping command, etc... However there's a limitation: the modified text can't be longer than the original.
RE: Altering incoming text by optimism_ on 04-23-2004 at 04:59 PM
Oh yes it is possible to modify the incoming text, thats not in question
What will probably not happen, is that we wont be given access to modify the incoming text in our plugins. It is a security risk, and its why we dont already hav this ability
RE: Altering incoming text by RooJ on 04-23-2004 at 05:14 PM
Damn thats annoying.. at the moment im bringing the altered text up in a msgbox to the other user, but it can really bug you when your typing alot of messages with it.
RE: Altering incoming text by RooJ on 04-23-2004 at 11:46 PM
Optimism, I dont get why you think it would be a security risk, care to explain? as i see it its not like u can fake a connection to yourself from them or something such as a file transfer, the text is already there, mess has processed it, and your just modifying it before its displayed.
Whats the prob?
RooJ
RE: Altering incoming text by optimism_ on 04-23-2004 at 11:50 PM
you may not be thinking of the same defnition of he word secure as i am in this context
If a plugin had access to the incoming text, a dodgy plugin could phone home with all of a users conversations, or something like personaly information/password harvesting, or, alter incoming text for equalliy malicious reasons.
not everyone is completely ethical, even tho, those are some of the more extreme examples.
RE: Altering incoming text by RooJ on 04-24-2004 at 12:18 AM
But plugins already have access to incoming text:
* sText: the rest of the received message. You can use it to get more information about the action you want to perform.
so it could still gather info and phone home with it now.. the only malicious thing i can think of would be to alter an incoming message in such a way as to make the user recieving it give out some kind of personal info.. But i doubt someone would give out there password/credit card number to someone on there mess list etc.. and with functions such as:
sTextToSend:this parameter is optional. You can use it if you want to ask Messenger Plus! to send a new message after this one has been displayed. This WON'T modify the message associated with the notify code, this will simply send a new one.
Isnt that already insecure? You could have a plugin that opens a backdoor or sends out an ip when a particular message is recieved. I agree that not everyone is completely ethical about stuff like this but i really dont see how this would make much difference to security.
RooJ
RE: Altering incoming text by optimism_ on 04-24-2004 at 12:23 AM
yes but these are only outgoing commands and tags, and incoming notifications. This is NOT access to every single message that goes through messenger
RE: Altering incoming text by RooJ on 04-24-2004 at 12:38 AM
Adding the altering text function wouldnt give people access to all text going through messenger either..
it would only kick in when a certain notifycode was recieved. Just like most other plugins do.. the only difference is the plugin can alter the text sent to it if its got a certain notifycode.. and all this can do is display something different in the messenger conversation window than what was sent. No more or less secure than some of plus's other features.
Or am i just missing something obvious?
RooJ
RE: Altering incoming text by Mike on 04-24-2004 at 05:03 AM
quote: Originally posted by RooJ
Damn thats annoying.. at the moment im bringing the altered text up in a msgbox to the other user, but it can really bug you when your typing alot of messages with it.
Hmmm i tried that time ago but it didnt work...
RE: Altering incoming text by RooJ on 04-24-2004 at 12:25 PM
Hey Mike, im using this in ReceiveNotify function:
============
If (StrComp(sNotifyCode, "tcode", vbTextCompare) = 0) Then
;insert code to alter sText (there text) here
sText = "new( " & sText & " )"
MsgBox sText
===========
the rest is just from Patchou example and i have a small encryption routine as a test after the if statement.
Oh you can also use a boolean or whatever you prefer to stop the plugin answering your own text.
If you dont know how to do this id be glad to help.
RooJ
RE: Altering incoming text by optimism_ on 04-24-2004 at 12:31 PM
reading the documentation helps tbh
code: //////////////////////////////////////////////////////////////////////
// //
// Purpose: Allow special actions when a plugin text is received //
// //
// Definition: //
// This function is called everytime Messenger Plus! detects a //
// plugin text ID in a message received from a user. This ID is //
// generally placed at the beginning of a text by a plugin //
// command to perform an action on the destination computers. //
// This can be used, for example, to play a sound. See the //
// control characters section for more information. //
// //
// Parameters: //
// * sNotifyCode: this 5 character string is the notify code that //
// was sent next to the plugin ID control character. Use it to //
// identify what action to perform. //
// * sText: the rest of the received message. You can use it to //
// get more information about the action you want to perform. //
// However, you MUST NOT use this parameter to determine if an //
// action is supported by your plugin. Use sNotifyCode instead. //
// * pParam: additional information sent by Messenger Plus!. For //
// more information, read the documentation of the PLUGIN_PARAM //
// structure. iConversationWnd and sContactName are used. //
// * sTextToSend: this parameter is optional. You can use it if //
// you want to ask Messenger Plus! to send a new message after //
// this one has been displayed. This WON'T modify the message //
// associated with the notify code, this will simply send a new //
// one. Important: the size of this buffer is 4096 characters //
// and it is YOUR responsability to verify that you don't write //
// more characters to avoid memory faults.
// * return value: if you recognized the notify code return TRUE, //
// else, return FALSE. //
// //
// Advanced: if the plugin version returned by Initialize() is 2 or //
// above, you can specify more than one message or command in //
// sTextToSend. Simply create new lines with # as first character //
// (use '\n' to create new lines in your string). Up to 20 actions //
// can be specified, each being executed at a 0.5 second interval. //
// A different delay can even be entered for each action. After the //
// first #, just put a digit between 1 and 9 and another #. //
// Example: sTextToSend = "#First message\n#5#Second message" //
// //
// Important: keep in mind that several plugins can be installed //
// and that a lot of text is received. If you don't support the //
// notify code passed in parameter, you must return as fast as //
// possible and without doing anything else. //
// //
//////////////////////////////////////////////////////////////////////
MPPLUGIN_RETURN_BOOL ReceiveNotify(/*[in]*/ const char* sNotifyCode,
/*[in]*/ const char* sText,
/*[in]*/ PLUGIN_PARAM* pParam,
/*[out]*/ char* sTextToSend);
sText is an incomming/read only variable. You cannot chnage it (yes i know this is the c++ code but the vb code is the same).
Yes you can read what the user typed, eg
[]mcodeThis is My Message
sText contains "This is My Message"
but you CANNOT change it
RE: Altering incoming text by Choli on 04-24-2004 at 12:48 PM
quote: Originally posted by optimism_
but you CANNOT change it
for C codes:
yes, you can change it, because it's a char *, however plus discards the changes (well i've never tested to change it in C, but you can. (and if not, just remove the const keyword))
for VB ones:
yes, you can change it, because it's a local parameter, however it's declared as ByVal, that means plus won't (or shouldn't) notice you've changed it.
In any case: Anyway, in case you acomplish to change the text, plus won't use it to be displayed in teh chat window,
RE: Altering incoming text by optimism_ on 04-24-2004 at 12:54 PM
In both cases you will be getting a copy of the original. Presumable for c, patchou copies it into a new variable before passing it into the function or whatever. In VB it is defined as a copy
hence you CANNOT change the original text
and anyways, the original text gets dumped into msgplus independantly from the notification plugin call. The first 6 chars are stripped and then the sText gets dumped to messenger and separately the notifcation code is executed. (the order is irrelevant)
ps, choli
Actually is a const char*
this means the compiler wont let you change it unless you cast it to (char*) and if you do a cast, it will cause a runtime error, so no, you cannot change it in c at all
(so it doent have to be copied at all actually, cos theres no write access to it)
RE: Altering incoming text by Mike on 04-24-2004 at 01:14 PM
This is what i was doing....
If (StrComp(sNotifyCode, "msgbx", vbTextCompare) = 0) Then
Dim mymsgbox As String
mymsgbox = sText
MsgBox (mymsgbox)
ReceiveNotify = True
Exit Function
End If
I was trying several things with the msgbox but none of them did work...
RE: Altering incoming text by RooJ on 04-24-2004 at 01:32 PM
Why not just:
If (StrComp(sNotifyCode, "msgbx", vbTextCompare) = 0) Then
MsgBox sText
ReceiveNotify = True
Exit Function
End If
Also if u cant get it to work you might want to look at the notifycode and check if ur recieving it ok.
RE: Altering incoming text by Mike on 04-24-2004 at 01:34 PM
Yep I also did that but i was trying dif. things...
RE: Altering incoming text by Choli on 04-24-2004 at 01:55 PM
quote: Originally posted by optimism_
In both cases you will be getting a copy of the original. Presumable for c, patchou copies it into a new variable before passing it into the function or whatever. In VB it is defined as a copy
yes, plus makes a copy before calling the dll function. About VB, the ByVal in Strings is just a formalism... I bet you can change the decaration to ByVal bla as Long and you can cheat a bit with Windows APIs and modify the copy Plus makes.
quote: Originally posted by optimism_
hence you CANNOT change the original text
not the original, of course, but yes the copy
quote: Originally posted by optimism_
ps, choli
Actually is a const char*
this means the compiler wont let you change it unless you cast it to (char*) and if you do a cast, it will cause a runtime error, so no, you cannot change it in c at all
(so it doent have to be copied at all actually, cos theres no write access to it)
the const keyword is only used by the compiler to not let you change it (ie make something like sText[0]=mychar; ) however the internal (read assembler) implementation of it it's the same as if you don't put const. That's why I said you can remove the const keyword and all will work the same, just that now you'd be able to modify it.
about the cast, i don't think it'll do a runtime error... Anyway, you can also make
int dummy_ptr; //assume sizeof(int)=4
dummy_ptr=(int)sText; /*that's dodgy, i know, if you don't like it you can use void* instead of int too (dodgy too)*/
and then use dummy_ptr in an API like CopyMemory (or what ever it's called)....
Sumarizing, you can modify the string plus passes as parameter to the function (and plus won't use it once your function finishes)
RE: Altering incoming text by RooJ on 04-24-2004 at 02:07 PM
Well i changed the text:
RooJ says:
Ping? [request]
motion - [blahblah] says:
Pong! [00sec]
RooJ says:
Ping? [request]
motion - [blahblah] says:
Porn! [01sec]
Just i dont think i intercepted the message so therefore things like the logfile will have the origional (Pong! [01sec]) in it i think.
There will be ways to intercept and modify the copy Plus makes but it would be easier to add a function to the plugins to allow us to change it .
Choli any idea which dll makes the copy? MsgPlusH1.dll maybe?
RooJ
RE: Altering incoming text by Mike on 04-24-2004 at 02:09 PM
Cool how did you do it?
Might you add me at msn if you want?(look at my profile)
RE: Altering incoming text by optimism_ on 04-24-2004 at 02:21 PM
choli
code: const char* szMyString = "Hello World";
strcpy(szMyString, "hi"); //Compiler error
strcpy((char*)szMyString. "hi ho"); //Runtime error
but you are right... change the definition of sText and you could write to the string. Not sure what would happen in plus itself tho if you were to do that
RE: Altering incoming text by RooJ on 04-24-2004 at 02:35 PM
Just used a debugger to break on GetForegroundWindow which i think is called when someone messages you to check if the window is in the foreground, otherwise it will play a sound and flash. From there i found a huge string which contained the entire chat session, anything could be edited including names, it would then change on the chat window aswell.
Obviously this is impractical though, and finding the location of the copy plus makes (if it does) would be a better find. Shouldnt be too hard with a little debugging.
RooJ
RE: Altering incoming text by Choli on 04-24-2004 at 02:47 PM
quote: Originally posted by RooJ
Well i changed the text:
Porn! [01sec]
porn?
what dody thing did you do?
quote: Originally posted by RooJ
There will be ways to intercept and modify the copy Plus makes but it would be easier to add a function to the plugins to allow us to change it
the best way it's do the same plus does, ie use the messenger apis and/or hooking techniques
or maybe you can use the messenger objects plus sends...?
quote: Originally posted by RooJ
Choli any idea which dll makes the copy? MsgPlusH1.dll maybe?
I have no idea, but what do you want to do?? hack it?
inside a plugin you don't know the address where plus stores the original string, only the address of the copy, which, btw, its useless for these pourposes.
quote: Originally posted by optimism_
choli
code: const char* szMyString = "Hello World";
strcpy(szMyString, "hi"); //Compiler error
strcpy((char*)szMyString. "hi ho"); //Runtime error
but you are right... change the definition of sText and you could write to the string. Not sure what would happen in plus itself tho if you were to do that
that's because the compiler creates the string in a readonly zone of teh memory because you said you won't modify it (you said const)....
make this test:
make a dll that exports this function:
code: /*if strlen(str) > 0, this function replaces the first character by a X */
void f(cont char * str) {
char * str2 = (char*)str;
if(*str2)
*str2='X';
}
and now, make a program that calls that dll, something like:
code: char mystring[6];
/*let's fill the string this way so we assure the string is not read only
we could have declared it as
char * mystring = "Hello";
however, the following way makes sure no compiler will put the string in a read only zone of the memory*/
mystring[0]='H';
mystring[1]='e';
mystring[2]='l';
mystring[3]='l';
mystring[4]='o';
mystring[5]=0;
/* now display the string, you can do a MessageBox, or a printf*/
printf("%s\n",mystring); // Hello is printed
//call the dll
f(mystring);
/*display the string again*/
printf("%s\n",mystring); // Xello is printed
note the diference?
in a function you can declare a cont pointer to tell the compiler not let you modiy where it points to, but it is still a ponter, ie you can use it to access the memory and modify it.
note: about the line
char * str2 = (char*)str;
maybe the compiler doesn't let you compile that, i dunno, but there are ways to get rid of that restriction, sure (using another function, using casts to void *, etc..)
Edit:
quote: Originally posted by optimism_
but you are right... change the definition of sText and you could write to the string. Not sure what would happen in plus itself tho if you were to do that
i've read again your post. Nothing happens if you modify the copy that plus makes. Plus just ignores it and makes another copy for the next plugin.
quote: Originally posted by RooJ
Obviously this is impractical though, and finding the location of the copy plus makes (if it does) would be a better find. Shouldnt be too hard with a little debugging.
the copy is where sText points to.
RE: Altering incoming text by RooJ on 04-24-2004 at 03:04 PM
Choli: what dody thing did you do?
I dont understand dody?
Choli: the best way it's do the same plus does, ie use the messenger apis and/or hooking techniques
or maybe you can use the messenger objects plus sends...?
Wow, maybe i could hook his hook lol.
Choli: I have no idea, but what do you want to do?? hack it?
Nah not at the moment, just if worse comes to worse i could use code injection to pass control to me and steal/alter the copy plus is gonna use to put in the chat window.
RooJ
RE: Altering incoming text by Choli on 04-24-2004 at 03:21 PM
quote: Originally posted by RooJ
I dont understand dody?
dodgy, sorry
quote: Originally posted by RooJ
Nah not at the moment, just if worse comes to worse i could use code injection to pass control to me and steal/alter the copy plus is gonna use to put in the chat window.
that sound weird , i think it's better to use the messenger apis (as plus does)
RE: RE: Altering incoming text by optimism_ on 04-24-2004 at 09:37 PM
quote: Originally posted by RooJ
From there i found a huge string which contained the entire chat session, anything could be edited including names, it would then change on the chat window aswell.
presumably then this is where windows is storing the text for the rich edit control on the plus! window; as opposed to something in plus!?
RE: Altering incoming text by RooJ on 04-24-2004 at 11:06 PM
Choli: what dodgy thing did you do?
Heh, just altered the text via the debugger.
optimism_: presumably then this is where windows is storing the text for the rich edit control on the plus! window; as opposed to something in plus!?
Yeah its not in plus, Sadly the window text is a different address each break aswell so as i said before.. completely impractical to rely on it.
Choli: that sound weird , i think it's better to use the messenger apis (as plus does)
To be honest Choli i dont know much about the messenger api. Might have to read up on it.
RE: Altering incoming text by optimism_ on 04-25-2004 at 03:51 PM
Rooj: yes the location of the text will change all the time, however
There will always be a pointer to this memory address (a 4byte integer in ram which contains the numeric index of the first character of the string)
And this pointer is likely to be in a fixed position RELATIVE to something else, *such as* the window handle
RE: Altering incoming text by RooJ on 04-26-2004 at 01:09 AM
Yeah agreed.. might not need that though, i just altered text before it reached the window, infact before plus had even had chance to take the special chars out and the notifycode. I altered it and then it was placed in the chat window no problem. This could be useful when people keep sending plus sounds and stuff to annoy you.. i used it to edit a ping that was sent so that i didnt auto reply.. it worked. I know you can probebly turn the ping thing off but i dont care lol.
Depending on whether the plugins called before the text is sent to the main window, in theory you could add code to a plugin that would alter the real text just before it was sent to the chat window. If you wanted to edit it before plus does you would have to do it before that id imagine.
This would be ideal for an encryption plugin, not having to use msgbox's.
RooJ
|