Page 3 of 4

Re: TextEdit

Posted: 22 Dec 2010, 05:35
by mattallen37
You are right, I did forget the ";". I haven't compiled it, I just copied and heavily modified preexisting code. What is a "STACKOVERFLOW"? I have used that method of mine, and it seems to work actually really well for me.

Re: TextEdit

Posted: 22 Dec 2010, 05:38
by nxtboyiii
mattallen37 wrote:
nxtboyiii wrote:I have enhanced FW 1.21...
I don't think there is such a thing as enhanced firmware 1.21.
Oops. :oops: I meant to say 1.31.

Re: TextEdit

Posted: 22 Dec 2010, 23:37
by dudmaster
Mattallen, can you modify your program to output to the variable "Sen" (not an array)

Re: TextEdit

Posted: 23 Dec 2010, 00:44
by mattallen37
dudmaster wrote:Mattallen, can you modify your program to output to the variable "Sen" (not an array)

Code: Select all

if(OpenFileRead("File.txt", size, handle) == NO_ERR)
{
  until (Sdone == true)  // read the text file till the end
  {
    if(ReadLnString(handle,message) != NO_ERR) Sdone = true;
    //You need to grab the message and write it to another string(or whatever you need to do) all right here.
    //Base it on an increasing variable, like the following lines.
    Sen[i]=message;
    i++
  }
}
There, like that? I know you don't want it to be an array, but it must be, or you will only get the last line of the file. If you really do only want the last line, then just take out the i++ and the . I suggest though that you just stick to the original.

How about this?

Code: Select all

if(OpenFileRead("File.txt", size, handle) == NO_ERR)
{
  until (Sdone == true)  // read the text file till the end
  {
    if(ReadLnString(handle,message) != NO_ERR) Sdone = true;
    //You need to grab the message and write it to another string(or whatever you need to do) all right here.
    //Base it on an increasing variable, like the following lines.
    TotalMessage[i]=message;
    i++
  }
  Sen=TotalMessage[Line];//Line being a variable or constant in the range of 0-(number of lines-1)
}
Using that UNTESTED code, you can read a multiple line text file (or what-have-you), and it stores each line into the TotalMessage array. To extract a specific line, use this part.

Code: Select all

Sen=TotalMessage[Line];
where Line is the line you want to extract (starting with 0).

Re: TextEdit

Posted: 23 Dec 2010, 03:19
by dudmaster
The program is great. Thanks, maybe i can add all lines together, and i can use the variable i to find out how many lines, correct?

Re: TextEdit

Posted: 23 Dec 2010, 04:19
by dudmaster
Well, i can't get the code to compile.

I got muntoo's code to compile but when i use it i get a -5 error.

Here is the code:

It takes the array and adds all the lines into one variable.

Code: Select all

void ReadLines(string &out[], string filename)
{
byte handle;
int fsize = 300;
ArrayInit(out, "", 0);
if(OpenFileRead(filename, fsize, handle) == LDR_SUCCESS)
{
for(string szBuf; (ReadLnString(handle, szBuf) == LDR_SUCCESS); ArrayBuild(out, out, szBuf));
CloseFile(handle);
}
}
task main() {
bool Sdone;
int size = 300, i, n;
byte handle;
string message, Full;
string Sen[100000000];
ReadLines(Sen, "Test3.txt");
int ArrLen = ArrayLen(Sen);
while (n < ArrLen)
{
string Dude = Sen[n];
Full = Full + Dude;
}
int TextWrap = 0;
while (0 == ButtonCount(BTNCENTER, true))
{
if (ButtonCount(BTNLEFT, true) && TextWrap > 0)
{
  TextWrap = TextWrap - 100;
}
if (ButtonCount(BTNRIGHT, true) && TextWrap < StrLen(Full) - 99)
{
  TextWrap = TextWrap + 100;
}
TextOut(0, LCD_LINE1, SubStr(Full, TextWrap, 18), true);
TextOut(0, LCD_LINE2, SubStr(Full, TextWrap + 16, 18));
TextOut(0, LCD_LINE3, SubStr(Full, TextWrap + 32, 18));
TextOut(0, LCD_LINE4, SubStr(Full, TextWrap + 48, 18));
TextOut(0, LCD_LINE5, SubStr(Full, TextWrap + 64, 18));
TextOut(0, LCD_LINE6, SubStr(Full, TextWrap + 80, 18));
TextOut(0, LCD_LINE7, SubStr(Full, TextWrap + 96, 18));
TextOut(0, LCD_LINE8, SubStr(Full, TextWrap + 112, 18));
if (ButtonCount(BTNEXIT, true))
{
  Stop(true);
}
Wait(50);
}
}
}

Re: TextEdit

Posted: 23 Dec 2010, 04:53
by muntoo
Paint.NET "Caligraphy Toolbox" Plugin SDK
Chrome Extension Development/Themes.

@Matt
Technically, I believe it would be called a buffer overflow, but StackOverflow cooler. :D
Buffer overflows are one of the oldest hacking techniques used to execute arbitary code. I don't understand the details, but here's a simple explaination:

Code: Select all

byte badCode[] = {0x10, 0x20, 0x30, 0x42, 0x2A, 0x10, 0x10, 0x10}; // Instructions in machine language
byte temp[3];
temp[0] = 0x10;
temp[1] = 0x20;
temp[2] = 0x30;
temp = badCode;
//temp[3] == 0x42!!!
I'll add more to this later...

Dud, look here:
https://sourceforge.net/apps/phpbb/mind ... 2865#p2865

Re: TextEdit

Posted: 23 Dec 2010, 05:57
by mattallen37
muntoo wrote:@Matt
Technically, I believe it would be called a buffer overflow, but StackOverflow cooler. :D
Buffer overflows are one of the oldest hacking techniques used to execute arbitary code. I don't understand the details, but here's a simple explaination:

Code: Select all

byte badCode[] = {0x10, 0x20, 0x30, 0x42, 0x2A, 0x10, 0x10, 0x10}; // Instructions in machine language
byte temp[3];
temp[0] = 0x10;
temp[1] = 0x20;
temp[2] = 0x30;
temp = badCode;
//temp[3] == 0x42!!!
I'll add more to this later...
Ok, but that looks legit to me. Why shouldn't temp[3] = 0x42?

Re: TextEdit

Posted: 23 Dec 2010, 08:49
by muntoo
mattallen37 wrote:Ok, but that looks legit to me. Why shouldn't temp[3] = 0x42?
It will. BUT temp was only initialized for 3 elements (temp[0-2]). temp[3-7] have been written to. Oh oh.
On your NXT, this would probably give you a File Error, if you gave it random data. But if you gave it legitimate machine instructions, something would happen... Depends on the instructions.

I'm probably bringing about a new hacker into this world by explaining all this. ;)

Re: TextEdit

Posted: 23 Dec 2010, 15:59
by mattallen37
Ok, well, it does NOT get program errors when running, so it must be somewhat decent.