char conversion [closed] - character-encoding

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I want to know what will be the best way for a char-char conversion.
I will create some data for the conversion for example teh letter "A" will be converted to "C" and so on.
Shall I use a MySQL DB or files or what?
Note: The application will be a web app and most likely be running ASP or PHP.
EDIT:
I want to create a website or a desktop app that will allow user who work on PCs that only support one language to be able to use any other language something like a translator, yet it is not a translator.
For example, arabic users cannot use the AR keyboard due to system restrictions, I want to help them write in the language without installing the language pack. I`m facing this problem myself, and can`t install language pack without admin access.
I can`t provide output at the moment as the PC I`m using doesn`t support AR.

I guess you mean character / keyboard mapping (or an Input Method Editor as Ignacio Vazquez-Abrams said)...
In this case, create static hash maps / associative arrays that map keys to characters or strings.
That said, however, I think there are some keyboard mapping tools out there that hook into the operating system and can be customized to one's needs.

What about JavaScript?
Here's a simple code for converting the infamous YZ keys to ZY (QWERTY <-> QWERTZ).
<textarea id="txt"></textarea>
<script language="JavaScript" type="text/JavaScript">
document.getElementById("txt").onkeydown = InputKeyDown;
function InputKeyDown(event) {
var shift = event.shiftKey;
var keyCode = (event.which == null) ? event.keyCode : event.which;
//alert(String.fromCharCode(keyCode) + "\\n" + keyCode); return false;
switch (keyCode) {
case 89 /* Y */: InsertAtCursor(event.target, shift ? 'Z' : 'z'); return false;
case 90 /* Z */: InsertAtCursor(event.target, shift ? 'Y' : 'y'); return false;
default: return true;
}
}
</script>
I think you could start something with this. You can also use the event.ctrlKey or event.altKey flags for more complex languages.

Related

Is it possible to deobfuscate this string of obfuscated Lua Code? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a(nother) string of lua code that's obfuscated. I'm wondering if it's possible to deobfuscate it, or to figure out how it was obfuscated, as I've never encountered anything like it before. This string of code is supposedly the main module for a malicious serverside script executor. Knowing what's inside will help us patch the exploit on our platform. I'm told that it would be easy to decipher by getting the constants, because it's VM based obfuscation, we just need a bit of help getting pointed in the right direction.
The code is rather large, so it's in this pastebin.
pastebin com/dtfzBPZk
Deobfuscating this one looks like it will be a slightly more manual process. As usual, the first things you should do are rename variables to have saner names, and add whitespace and indentation to the code. You can see a start to this at https://pastebin.com/eRTGAbTH. Once you do that, you'll see a pattern of functions like this:
(function(...)
local SynapseXen_116 = "hi xen doesn't work on sk8r please help"
local SynapseXen_092 = SynapseXen_100(38909278, 3932326132)
local SynapseXen_069 = {...}
for SynapseXen_109, SynapseXen_043 in pairs(
SynapseXen_069
) do
local SynapseXen_119
local SynapseXen_097 = type(SynapseXen_043)
if SynapseXen_097 == "number" then
SynapseXen_119 = SynapseXen_043
elseif SynapseXen_097 == "string" then
SynapseXen_119 = SynapseXen_043:len()
elseif SynapseXen_097 == "table" then
SynapseXen_119 = SynapseXen_100(4264903821, 30110892)
end
SynapseXen_092 = SynapseXen_092 + SynapseXen_119
end
SynapseXen_140[1171393165] =
SynapseXen_bit_bxor(
SynapseXen_bit_bxor(2179831066, SynapseXen_092),
SynapseXen_bit_bxor(2132161653, SynapseXen_082)
) -
string.len(SynapseXen_116) -
SynapseXen_139 -
#{
2716917292,
2960928816,
2092744992,
3945961999,
2156388474,
2523828292,
534526172
}
return SynapseXen_140[1171393165]
end)({}, {}, 14275, 107, "iIIllIIlIIilillilI", "i", 5327, 3211, 14382, 14643)
Now you can start to eliminate red herrings. For example, any time you see #{ a bunch of stuff in here }, you can just count the elements in the list, and replace the whole thing with the count. In this case, there's one of those near the end we can replace with the number 7. Next, look at SynapseXen_116. The only place it's used is for its length, so you can substitute that in as well. Now, After that, notice that this is declaring a function and then immediately invoking it, so you can substitute in its arguments. Continue going down that path until you uncover the heart of the Lua-in-Lua VM, and from there, it should be easy to plug in the Base64 at the end, and see what bytecode it decodes to.

Inserting CrossReference to word via Delphi XE5

Bonjour, Hello,
I'm making this delphi application that I use to create word documents. I'm done with basic word operations (create/save, text, tables..etc).
What I need to do is to insert Page Numbers of headings as Cross Reference in the text. Something like :
"... and the process works as explained on page 23..."
where page number is a hyperlink to a heading. When I recorded a Macros in word it looks like:
Selection.InsertCrossReference ReferenceType:="Heading", _
ReferenceKind:=wdPageNumber, ReferenceItem:="49", InsertAsHyperlink:=True _
, IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
What would be the equivalent in Delphi please?
Thanks in advance!
Arjun.
Even when you're using Late Binding you still need to provide all of the parameters in the same order as the original declaration.
expression.InsertCrossReference(ReferenceType, ReferenceKind, ReferenceItem,
InsertAsHyperlink, IncludePosition, SeparateNumbers, SeparatorString)
If you aren't using a parameter then you can replace it with EmptyParam.
So I think your code will be:
Selection.InsertCrossReference('Heading', 7, '49', True, False, False, ' ');
(I think that wdPageNumber's value is 7).

Fetching breeze metadata is slow in Chrome, fast in IE

It appears that fetching metadata for my model is extremely slow in Chrome, but fast in IE.
My dbcontext contains around 35 entities with lots of navigation properties and each entity I add adds to the delay. Currently the delay is around 20 seconds, starting AFTER the query has returned the raw metadata, and it's entirely CPU which is working heavily, memory usage stays stable. I've got an i7 processor and ample memory.
I know there are differences in how the javascript engine is geared in these two browsers, with the chrome javascript JIT compiler being optimised for floating point operations (which is why webgl graphics are a thousand times faster in chrome than IE) - could this be having an impact on the work which fetchMetaData has to do?
Has anyone else noticed this slowness? Could it be that my relationships are wrong? Once the delay is over everything works though, so i'm doubting that relationships could be a problem.
Found the problem and solution!
Thank you for taking the time to look at this, after your reply I decided to strip the whole project down to basics where I could reproduce the problem and look for any interference.
This was an older project in which I had implemented Breeze. The project used standard jquery post/get methods to get data from MVC, and since dates and times have always been a problem when posting and receiving json data from MVC I had this code in my startup script:
// Add datafilter to jQuery ajax calls to translate dates
$.ajaxSettings.dataFilter = function (data, type) {
//if (type === 'json') {
// convert things that look like Dates into a UTC Date string and completely replace them.
data = data.replace(/(.*?")(\\\/Date\([0-9\-]+\)\\\/)(")/g,
function (fullMatch, $1, $2, $3) {
try {
return $1 + new Date(parseInt($2.substr(7))) + $3;
}
catch (e) { }
// something miserable happened, just return the original string
return $1 + $2 + $3;
});
//}
return data;
};
After removing this code (since breeze does dates properly), everything works as normal. This type of code may be common in other older projects which had to deal properly with dates, I know I got the above snippet from WiredPrairie and i'm sure others will also run into this problem.
Dmitri,
I can't repro this, so I am wondering if there isn't something else involved. Have you tried Firefox as well?

Phonegap/Sencha Language Localization

The Problem:
I'm about to implement language localization to an already very large ipad application that was built using sencha touch wrapped in phonegap. I have the english and spanish translations in json files.
What I'm Planning on Doing:
I plan to load the json files into a sencha touch store, creating a global object. Then in each place where I call text that is displayed, i will replace the text with a call to the global object.
My question(s):
Is there an easier way to implement language localization with my
setup?
Will I run into issues with native sencha stuff (like datepickers)?
When loading/reloading language json files, will I have performance
issues (require a webview reload?, sencha object resizing issues,
etc)
edit 1 : Useful Related Info:
For those going down this road, it quickly becomes useful to write a simple phonegap plugin to get the ipad/iphone device's language setting into your javascript. This requires a plugin, which will look something like this:
Javascript :
part 1:
PhoneGap.exec("PixFileDownload.getSystemLanguage");
part 2(callback Function):
setLanguage(returnedLanguage)
{
GlobalVar.CurrentLanguage = returnedLanguage; //GloablVar.CurrentLanguage already defined
}
Objective C:
-(void)getSystemLanguage:(NSMutableArray*)paramArray withDict:(NSMutableDictionary*)options
{
/*Plugin Details
PhoneGap.exec("PixFileDownload.getSystemLanguage");
Returns Language Code
*/
NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defs objectForKey:#"AppleLanguages"];
NSString *language = [languages objectAtIndex:0];
NSLog(#"####### This is the language code%#",language);
NSString *jsCallBack;
jsCallBack = [NSString stringWithFormat:#"setLanguage('%#');",language];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
}
edit 2: character encoding
When adding additional language characters to a sencha project (or any webview phonegap project), ensure that you have the proper encoding specified in the index file. This is the tag i needed.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
I've finished this language localization plugin. It's not amazing, but it worked better than I originally speculated. Here are the short answers to each of the questions.
1- Is there an easier way to implement language localization with my
setup?
Not that i'm aware of. The comment by Stuart provided this link Sencha-touch localization. Use a store or a global JSON object? which had some good information on one way that you can use class overrides. I didn't like this approach, because it spread my language translations into different classes. But certainly, if you are doing something simple, or you want something that could be more powerful, perhaps you should investigate that.
2- Will I run into issues with native sencha stuff (like datepickers)?
I ended up specifically leaving "datepickers" in english for now. But everything else was really relatively easy to customize. Almost every graphical UI element can have it's text altered.
3- When loading/reloading language json files, will I have performance
issues (require a webview reload?, sencha object resizing issues,
etc).
The method that i employed (see below) worked exceptionally well in regards to performance. The one issue that you have is right when you switch the languages, you need that specific page to reload. Sencha handled resizing without any flaws, except where I had been foolish and statically set sizes.
Some of what I did was described in edits to the question. Here is a detailed overview of my solution. (warning, it's not the most elegant solution.)
Instead of using a pure JSON file, I ended up just using a javascript function. This isn't the greatest solution because it requires some minimal maintenance, but JSON parsing with phonegap/sencha isn't the best. (I get JSON files from translater's, and quickly paste into the javascript file. Takes around 2 minutes, see further explanation below).
Language.js
function setLanguage(language)
{
if(language == "en")
{
//console.log("inside if Language == en");
GlobalLanguage.CurrentLanguage = language;
GlobalLanguage.ID = {"glossary": [
{
//CONVERTED JSON
about : 'About',
checking_for_updates : 'Checking for updates...(This may take a few minutes.)'
//Any additional translations
}
]};
}
if (language == "es"){
//console.log("inside language == es");
GlobalLanguage.CurrentLanguage = language;
GlobalLanguage.ID = {"glossary": [
{
//CONVERTED JSON
about : 'Acerca de ',
checking_for_updates : 'Verificando actualizaciones... (Capas que demore algunos minutos).'
//Any additional translations
}]};
}
if (language == "pt"){
//console.log("inside language == pt");
GlobalLanguage.CurrentLanguage = language;
GlobalLanguage.ID = {"glossary": [
{
//CONVERTED JSON
about : 'Sobre',
checking_for_updates : 'Verificando se há atualizações... (pode demorar alguns minutos.)'
//Any additional translations
}]};
}
}
As you can see, this file allows for 3 languages (Portugese, English, and Spanish). After setting the language, you could access each localized string anywhere in your object. For example, if you need to access the word "about" simply use:
GlobalLanguage.ID.glossary[0]["about"]
This will access the GlobalLanguage object which will have whatever language loaded into the properties. So throughout your project, you could have these calls. However, I'd recommend taking it one step further
function langSay(languageIdentifier){
// console.log("inside langSay");
if(!GlobalLanguage.ID.glossary[0][languageIdentifier]){
return "[! LANGUAGE EXCEPTION !]";
}
else{
return GlobalLanguage.ID.glossary[0][languageIdentifier];
}
}
This protects you from having language exceptions and having your program crash without knowing where (you may have hundreds or thousands of properties being set in that language.js file). So now simply :
langSay("about")
One additional note about formatting from JSON. The format you want your language files in is:
languageIdentifier : 'Translation',
languageIdentifier : 'Translation',
languageIdentifier : 'Translation'
I used Excel for the formatting. Also the languageIdentifiers are unique identifiers without spaces. I recommend just using Excel to format first 3 to 4 words word1_word2_word3_word4 of the english translation.
word1_word2_word3 : 'word1 word2 word3'
Hope this helps you out! I'd be happy to respond to any questions

Parse arbitary user input [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I have a database full of messages from a bulletin board. The board uses BB codes as formatting style. I.e.:
I'm not formatted
This is [b]bold[/b] text
Tags can also [i][b]be[/b] nested[/i]
And the [b]nesting [i]can be[/b] rather[/i] ugly
My ultimate goal is to convert these messages to some well formed XML (no discussion here ;) ). I don't want to use regular expression, which will fail at some point (in fact: it does).
First step: parse a message into some kind of internal representation (a graph, a tree, etc.). And I'm stuck at this point. The actual extraction is not that big problem, but the storage is.
How do I represent this kind of markup into some meaningful structure. My problem seems to be similar (or almost identical) to a browser building a DOM from a HTML file. So I think there are some strategies to solve it. I know the solution will not be perfect but im willing to invest a vast amount of time to do build the best possible.
Question: Do you have any tips/hint/comments? Any articles or paper you can recommend? Or a book which discusses these topic? I'm grateful for any input.
And the [b]nesting [i]can be[/b] rather[/i] ugly
I've written a parser very similar to what you are looking to do except that it would throw an error on your fourth example. Something to the effect of "Unexpected end tag [/b] within [i]".
I think that what you want to do is very doable but internally you will want to create a tree as if your original text was:
"And the [b]nesting [i]can be[/i][/b][i] rather[/i] ugly". (I don't think this would be necessary if you didn't need to convert it to XML later. If there were no need to convert to XML you could keep a linked list of text sections where each section is marked with its format combination)
Two possible approaches to this problem come to mind (of course there could be better possibilities). 1) Preprocess and insert the missing end and begin tags where necessary. 2) Build your parse tree and where there are overlapping tags imply the missing ones based on the current context. I think approach number (2) would be simpler and cleaner.
You could model your tree based on a composite pattern where you have an AbstractElement class, a TextElement class that extends AbstractElement, and a Tag class that extends AbstractElement and contains a list of sub-elements of type AbstractElement.
You would start by creating a root Tag instance. You would then call rootTag.parse(text). You would need a scanner that could return 3 types of tokens: text, start-tags, and end-tags. The scanner would allow you to push tokens onto it, which it would return before any normal scanned token. This would allow you to push new start tag tokens on after encountering and dealing with the unexpected end tag. You would also have to know when you are done with input. I'll use a 4th token type for that.
/* methods within class Tag */
public void parse(String text) {
MyScanner scanner = new MyScanner(text);
parse(scanner);
}
/* returns next token */
private Token parse(MyScanner scanner) {
Token firstToken = scanner.getNextToken();
return parse(scanner,firstToken);
}
private Token parse(MyScanner scanner) {
Token firstToken = scanner.getNextToken();
return parse(scanner,firstToken);
}
private Token parse(MyScanner scanner, Token token) {
while (!token.isDone() && !token.isEndTag()) {
if (token.isStartTag()) {
Tag subTag = new Tag(token.getValue());
token = scanner.getNextToken();
token = subTag.parse(scanner,token);
addElement(subTag);
}
else {
TextElement text = new TextElement(token.getValue());
addElement(text);
token = scanner.getNextToken();
}
}
if (token.isEndTag()) {
if (!token.getValue().equals(getName()) {
scanner.push(new Token(Token.START_TAG,token.getValue()));
}
else {
token = scanner.getNextToken();
}
}
return token;
}
So if you were to parse "And the [b]nesting [i]can be[/b] rather[/i] ugly", The following should get created.
rootTag.parse should be adding:
TextElement: "And the "
Tag: "b"
TextElement: "nesting "
Tag: "i"
TextElement: "can be"
(... at this point the odd [/b] is encountered ...)
(... push "i" start tag on the scanner ...)
(... here the [/b] is encountered (again) ...)
Tag: "i" (this was scanned because it had been pushed to the scanner)
TextElement: " rather"
TextElement: " ugly"
Note: Coding within a text area does not lend itself well to testing and debugging. Accept this answer as a hint or a possibility, not as your definate answer.

Resources