Inventory Database With Pictures - General Topics

Hello,
I've got an Inventory of 1,000 parts and I would like to have this list available online via a web page. I need to include Part Number, Manufacturer, Description, and Notes. I also plan to take up to 10 photos of each part to include with the description.
The idea is to make this available to the Technicians in the field so that they have a control part to reference while on site trying to assess damages.
Over course I can't make 1 long page of parts, so I'm going to have to build a database.
I'm open to suggestions and direction. I'm assuming either an SQL DB or something using ASP, but I'm drawing a blank as to where to begin.
Thanks for your help,
Mike

I'd say SQL, get something like mySQL (super easy) then setup the proper tables and fields. I'm not sure if you can include actual image data in the tables or not (I don't think you can) but you can include references to the images (the links to them) and parse those through whatever reader you're using. If you make a webpage that pulls the data it would be simple enough to include the images of the specific part.
Code:
SELECT * FROM parts WHERE partnumber = "insert number here"
That should get you all the info from the "parts" DB for the part with whatever number, just parse the data and display.

Yes I was hoping to use the DB to reference the stored images and display them as thumbnails or something like that.

Then that should be easy, just make sure the images are uploaded to the same site so you can use relative paths instead of absolute. I'm sure if you need some help the other members here would be more than happy and feel free to PM me about this for more detail if you want to.

Thanks dbzfanatic. You know I got Web Skillz, but this is over my head a tad. Actually I'm probably making it more complicated than it is.
I need a page that they can go to:
Part # _________
Manufacturer ________
Description _______
[Search]
Then I just need it to show all matchs and possibly links to the photos
-- OR --
List all matches and when they select a match it opens to a "Details" page with the full description and extra Notes. Pics would also be on this page.
I seriously feel like canibalizing a freebie E-Commerce tool

It really wouldn't be hard, you probably are making this harder than it needs to be . I've done that before too >.>
Will they already know the part number or will it be something they usually get from the info in the DB? That will play a role probably, or at least it would the way I'm thinking. I'd say make it so you have a dropdown menu of part numbers and the search button, then use that number in your SQL query, then pull up the "details" page which should show pictures. You could also do it so that you have a page with all the parts of a certain type displayed and have it setup like
[ ] [ ] [ ] [ ]
# # # #
[ ] being picture and # being (obviously) part number. Then have the picture be a link to the main "details" page. If you use that format i'd suggest only using the first picture in your list for each part, that way they get a good idea and you also save some room, plus if it isn't the part they wanted there's always the back button .

I'll give you more when I get home tonight,but under normal circumstances they would know either the part number or the manufacturer. The parts usually reside in a unit has the manufacturer on it somewhere. The part number is normally on the part if we installed it, but sometimes it comes off or is damaged. (Bar Coded sticky label)

Alright that makes things easier and gives you the option of using both methods. If they know the part number just search for it in the DB and if they only know the manufacturer have a list page by manufacturer. Easy enough right? The hardest part will be getting the DB populated (trust me it's cumbersome...doing some DB pop myself -_-)

dbzfanatic said:
You could also do it so that you have a page with all the parts of a certain type displayed and have it setup like
[ ] [ ] [ ] [ ]
# # # #
[ ] being picture and # being (obviously) part number. Then have the picture be a link to the main "details" page. If you use that format i'd suggest only using the first picture in your list for each part, that way they get a good idea and you also save some room, plus if it isn't the part they wanted there's always the back button .
Click to expand...
Click to collapse
I like this idea, but this is mostly for the techs and they will be accessing it from a smartphone. For now those are HTC Snaps and Samsung Intrepids running Windows Mobile 6.0 or 6.5. The screens are very small so left to right scrolling would probably be a bad idea.
I would either build it in a Column like:
[_]
#
[_]
#
[_]
#
[_]
#
Or
# [_]
# [_]
# [_]
# [_]
I think the 2nd option would take less vertical space. We have some vendors with 200 parts.
Building it in a vertical/column style would help them to be able to scroll through the photos faster.
I would only consider the Row style interface for office employees.
I have my inventory data, less the photos, already compiled in Excel. I was hoping to be able to cheat death & time buy importing the information.

I'm not sure how to import excel info into a DB but there's bound to be a way, if your employees have a decent touchscreen they should be able to scroll left/right as well but yes the vertical layout would be better. If you need help with fine details don't hesitate to ask and good luck with this ^_^.

dbzfanatic said:
I'm not sure how to import excel info into a DB but there's bound to be a way, if your employees have a decent touchscreen they should be able to scroll left/right as well but yes the vertical layout would be better. If you need help with fine details don't hesitate to ask and good luck with this ^_^.
Click to expand...
Click to collapse
I thought I was asking I guess I'm doing it wrong.
The trouble with the phones is they're not all touchscreens plus there's a number of techs that have their own Blackberries. I think it's best to build a simple page with no left and right.
So I was thinking about it today and I don't think I need to much to get this done.
1 database with 1 table (Parts)
1 index.php to use for seraching
1 results.php to show results (Might even be able to put the results in the index)
I'd eventually like to have 2 versions/views, one for the phones and one for the warehouse.

Yeah sorry I took some time and did a lil search for you which might help. I'm assuming you're using MySQL, if so go here http://blog.tjitjing.com/index.php/2008/02/import-excel-data-into-mysql-in-5-easy.html and read how to import your parts list. Then it's just a matter of doing some coding of the php pages. My suggestion would be to have the image references already as html in the DB to make things easier. That way when you call
Code:
SELECT * FROM Parts WHERE ID=*number*
you can just display the information directly. If you "echo" the result and it's like this:
Code:
<img src=/parts/images/56.jpg><br /><img src=/parts/images/58.jpg>
it will automatically display as if you'd type it into the html (if you didn't already know that ). It's also handy to do it this way since you don't need to know how many pictures you have of the part, it's just parsed and added automatically. I'd say your DB should look something like this:
Code:
ID Manufactuerer Description Images
56 HTC "Small" <img src=/parts/images/56.jpg><br /><img src=/parts/images/58.jpg><br /><img src=/parts/images/56.jpg><br /><img src=/parts/images/56-2.jpg>
and your php page look like
HTML:
<title>Parts</title>
<?php
$query = "SELECT * FROM Parts WHERE ID=" . $_POST['ID'];
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
?>Part Number: <?php echo $row["ID"];?>
Manufacturer: <?php echo $row["Manufacturer"];?>
Description: <?php echo $row["Description"[;?>
Images: <?php echo $row["Images"];
}?>
Something like that should work fine , at least for the "results" page.

dbzfanatic said:
I'd say your DB should look something like this:
ID
Click to expand...
Click to collapse
Nothing displayed?

Yeah sorry hit "post" instead of "go advanced" >.>;; post above edited

Ok I got the DB made and some test data imported from Excel. Not Photos yet, but hopefully tomorrow I'll have some test photos.

You should test pulling some data and gettint the setup right, once u got that working the rest is cake (no cake is not a lie)
Sent from my T-Mobile myTouch 3G Slide using XDA App

How do I tell the PHP what DB to look at?
My DB name is minfinge_cdcparts
I had to assign it a user and a password. Is that important to use in the php file?
Got an error in Line 11 at the moment.
http://www.mikeinfinger.com/demos/cdc/parts/

Yeah your error is because you're trying to connect to the DB without the password.
Code:
$dbuser="username";
$dbpass="password";
$dbname="minfinge_cdcparts"; //the name of the database
$chandle = mysql_connect("localhost", $dbuser, $dbpass)
or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser);
$mainsection="Parts"; //The name of the table
is how you connect to a password protected DB (I pulled it off the net so I didn't have to type ), of course replacing appropriate info. So it'd look something like this
Code:
[COLOR=#000080]<title>[/COLOR]Parts[COLOR=#000080]</title>[/COLOR]
[COLOR=#000080]<?php
[/COLOR]$dbuser="username";
$dbpass="password";
$dbname="minfinge_cdcparts"; //the name of the database
$chandle = mysql_connect("localhost", $dbuser, $dbpass)
or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser);
$mainsection="Parts";
[COLOR=#000080]$query = "SELECT * FROM " . $mainsection . " WHERE ID=" . $_POST['ID'];
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
?>[/COLOR]Part Number: [COLOR=#000080]<?php echo $row["ID"];?>[/COLOR]
Manufacturer: [COLOR=#000080]<?php echo $row["Manufacturer"];?>[/COLOR]
Description: [COLOR=#000080]<?php echo $row["Description"[;?>[/COLOR]
Images: [COLOR=#000080]<?php echo $row["Images"];
}?>
That should help/do the trick.
[/COLOR]

Failure Line 14
Code:
while($row = mysql_fetch_array($result)){
Here's the whole file
Code:
<title>Parts</title>
<?php
$dbuser="dbusert";
$dbpass="dbpass";
$dbname="minfinge_cdcparts"; //the name of the database
$chandle = mysql_connect("localhost", $dbuser, $dbpass)
or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser);
$mainsection="parts"; //The name of the table
$query = "SELECT * FROM " . $mainsection . " WHERE ID=" . $_POST['ID'];
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
?>Part Number: <?php echo $row["ID"];?>
Vendor: <?php echo $row["Vendor"];?>
Vendor Number: <?php echo $row["Vendor_Number"];?>
Description: <?php echo $row["Description"];?>
Images: <?php echo $row["Images"];
}?>

You might wanna edit that file so people on the net can't use the usr/pass for your DB. Also try changing it to this.
Code:
<title>Parts</title>
<?php
$dbuser="*user*";
$dbpass="*pass*";
$dbname="minfinge_cdcparts"; //the name of the database
$chandle = mysql_connect("localhost", $dbuser, $dbpass)
or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser);
$mainsection="parts"; //The name of the table
$query = "SELECT * FROM '" . $mainsection . "' WHERE 'ID'='" . $_POST['ID'] ."'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
?>Part Number: <?php echo $row["ID"];?>
Vendor: <?php echo $row["Vendor"];?>
Vendor Number: <?php echo $row["Vendor_Number"];?>
Description: <?php echo $row["Description"];?>
Images: <?php echo $row["Images"];
}?>

Related

Force numeric input on VB.net

i ported a small app that does some djing related calculations on smartphone and ppc using vb.net...
i ve seen some apps on my smartphone (strtrk) that force numeric input only for inputing serials etc, do you have any idea how to do this on vb.net?
im not a developer, i just want to port my app!
For Smartphone.
Just Use.
Code:
InputModeEditor.SetInputMode(<TextBoxName>,
InputMode.Numeric)
When The Form Loads.
Regards,
OllieD
OllieD said:
Just Use.
Code:
InputModeEditor.SetInputMode(<TextBoxName>,
InputMode.Numeric)
When The Form Loads.
Regards,
OllieD
Click to expand...
Click to collapse
Thanks for the reply, but i get 2 errors:
Code:
Error 1 Name 'InputModeEditor' is not declared. E:\pitchCalcSP\PitchCalcSP\mainFrm.vb 36 9 PitchCalcSP
Error 2 Name 'InputMode' is not declared. E:\pitchCalcSP\PitchCalcSP\mainFrm.vb 36 47 PitchCalcSP
Im not really into coding but ive inserted what you told me in this section: (current is the textbox name)
Code:
Private Sub mainFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InputModeEditor.SetInputMode(current, InputMode.Numeric)
End Sub
Sorry I Was Rushing.
Add A Reference To "Microsoft.WindowsCE.Forms"
Then Add
Code:
Imports Microsoft.WindowsCE.Forms
To The Top Of The Forms Code In The Declarations Section.
Should Sort It Out.
this works perfectly. thanks a lot.
sorry for exploiting your knowledge, but i have noone else to ask
my textboxes are 3 digit numbers, what should i do if i want them to have 4 digits (1 decimal)? for example 100.5.
with the code u gave me i can only input numbers, * and #.
the only thing remaining is to use the * or # to input the decimal separator.
i ll sure mention u in the about box

Chapters Of C Programing

Plz do not comment on this thread.
This thread is just for posting my chapters of C programing in http://forum.xda-developers.com/showthread.php?p=32778306 this thread.
if you wanna comment or ask doubt comment here : http://forum.xda-developers.com/showthread.php?p=32756564
Chapter 1​
Lets Talk about programs:​
So all of us have heard about the words like programming, programs , code , decode, etc etc ..
but we don't know the meaning of it.. so here it goes..
♣What is a program and programming?
-> For computer to work , we need to give some instructions. This instruction is know as CODE. Where in Each line of code instructs the computer to do something. Set of lines of these codes is commonly known as an program. (this was in common words)
As the definition of program says:
->A computer is designed to accept input, process it and generate output. A set of instructions to perform a task is known as a program. Simmilarly, A set of programs together form an Application.
-> Coding The codes above is known as Programming.
Ohk . Cool . Now lets start learning About flowcharts​
♣What is FlowChart? Why use it?
->Flow chart is a graphical representation of a program. It is useful when you are working in a team. Lets say you and me are building a project in C language n you want to show me what u are thinking about the program. you would write in C n compile the program and would show me . But i may not understand how the program worked , in other words i may not understand THE FLOW OF THE PROGRAM you made. So for that reason you make a flow chart of your program on a piece of paper, and then i would understand what you made.
AND flowchart is just like a representation of your program, it is nothing to do with programing.. you cannot put the flowchart in some file in pc n compile n run it . its not possible ..
-> Flow charts are help full in developing complex programs . You will realize it as we go further with the tutorial . I bet you will make a flow chart when you are thinking of a program but you wouldnt know how to put that into set of codes. That is when you would need flow charts.
Chapter 2
FlowCharts​
Theory​
As Flow Chart is a graphical representation of programs, we need symbols which will help us to graphically represent it. so here they are:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Input:
The Input symbol is used when the user has to input something , in other words it denotes that user will input at this point of program.
eg: the program is about multiplying the two numbers, so the program will ask the user to input two numbers to multiply in this box, 2 and 4
Processing:
The Processing symbol is used to show that there will be some processing in the program now.
eg: after the two numbers are accepted, the process of multiplication is shown in this box. 2 * 4
Output:
The result after processing is done, ie after the two numbers are multiplied , the output is given to the user by this symbol.
eg: 2 * 4 = 8
Decision:
Some times , its essential for the program to make decisions, this can be achieved with the use of this symbol
eg: If you want the user to input two numbers two multiply, but both the numbers should be less then 5, here u can check if the user has given input as per that , if yes then the program will execute(do the work) the way u code for yes, if no then you have to code a different set of code or re run the program.
Subroutine:
This is usefull when you have a big program , you can make different flow charts and then add them together.
Flow Lines:
These are the Lines That will decide where your program will go .
Terminator::
It is like a start for each flowchart, and also the end of flowchart. Also known as Entry point of flow chart and Exit point of flochart.
On page connector:
When your program has the decision boxes, and different conditions satisfy in a different way and end up in a place is where you would use On page connector.
Off page connector:
When your program exceeds the page, and you continue it on some other page then we use Off page connector.
Annotation:
It is a type of comments, which you write for other developers if the part/logic of the part of your program is hard.
================================================== ================================================== ================================================== ==================================================
Practical​Lets take an example, that a friend of your asks u to make a program on how to make a tea.
n u say ya ok bro, i will make a flow chart n will send it to you.
so here is the flow chart that you would make
So heres the first flow chart .
lets discuss it in detail (remember the red numbers are just so that you know what i am talking about, u need not write it while drawing flowcharts).
1. It is the terminator. It denotes that your program has started
2. It is the annotation, it is just for the reference of the reader. it is as good as an comment.
3. It is an input box, asks the user to input water, sugar , tea leaves and milk
4. It is an processing box, in this box processes takes place, in this case it is boiling the milk.
5. It is an output box, it tells that the tea is prepared.
6. It is an terminator. It denotes that your program has ended.
================================================== ==================================================*
Lets Take another example:
Suppose i ask you to make a flow chart of how do users register them self at Xda-developers.com.
How would u make it?
Something like this:
So , as you can see,
The terminal is starting the program, then the user inputs his details that are neccesary for signing up(in input box). then those details are stored in the xda developers database(in processing box) , and then the output box shows that you are registered sucessfully..
================================================== ==================================================*
So after seeing two flowcharts i guess you got a better understanding of what flowchart is all about..
So the flowcharts start with a start terminal. and ends with stop terminal. And then there are input boxes for taking inputs and processing boxes for processing the input and there is an output box for output.
So far we learned how to use:
1) Terminator
2) Input Box
3) Processing Box
4) Output Box..
Lets Give you guys an Exercise... At the end of this Post i will put it up.
Now before we move on to use the Decision Box i would like to Show you one more simple flow chart (and if you dont understand it , then i guess i am going too fast in my teaching.. lemme know if you dont get it , pm me or mail me )[/I]
================================================== ==================================================
Decision Box​
So while in a program sometimes you have to make decisions.
Decisions like if the user input is right or wrong, username is less than 16 character, password is atleast 6 character etc etc.
This is when you use Decision Box in flow chart.
It is used as follows
When the user is signing up in xda-forum . this is the decision box used after the password is accepted.
It checks , "Is the password greater than 6 characters?, if yes then run so and so codes, if no then run so and so codes" The flow line of Yes have different set of codes. The flow line of No have different set of codes.
For eg:
as you can see , in the decision box, if the Username is greater than 16 characters it shows an error and then runs the program again from where the flow line indicates. If the user name is not greadter than 16 characters then it runs the program normally
Exercise::
Draw FlowCharts For the following programs:
1) To Add two numbers.
2) To multiply the numbers
3) Add two numbers which are single digit only and show appropriate error if user inputs a two digit number
(Hint: Use the decision box to check "is number1 < 10" as if the number will be less than 10 then it will be a single digit number , (we exclude the posibility of negative numbers for sake of simplicity , though will teach you to tackle it in the next chapter))​4) Add the two numbers and subtract the addition with their product (eg if the user inputs 2 and 3 , then in processing box write (2*3)-(2+3) )
This Fourth one is important , plz do not skip it as we will discuss on it in next chapter.
Do it on a paper or in book.
mail me at [email protected] your scaned copy or a photo of your flowchart if you want to .. i will see each of them
Or Check From The answers Below.
Answers:
1) Answer
2) Answer
3) Answer
4) Answer
Chapter 3
FlowCharts(...Continued)​I hope you have done the exercises and have checked the answers and rectified yourself if you were wrong.
Still i would like to discuss the 4th Problem of the Exercise as i Had some purpose for giving that sum.
So when you were doing the flow chart , you would have encountered a problem.
Lets not go to flow chart directly, lets talk on it as if it were a math problem .
Add the two numbers and subtract the addition with their product: (considering the two numbers are 2 and 3)
Code:
Let the two numbers be a and b.
a=2
b=3
a + b = 5
a x b = 6
(a x b) - (a + b) = 1
NOTE:
You know there are variables in maths?? like x = 2 or x= 7 or y = 10 etc etc..
Ever thought why they are called variables??
It is because their values keep on changing in other words "The value of x VARIATE"
Just Keep it in mind, i would ask you to recollect it after done with this 4th Flowchart Problem
​
Doesnt it seem too long and boring to write(m talking about (a x b) - (a + b) )?
That's where the flowcharts and all the computer programming languages have a plus point . You will realize it in a minute..
See the flow chart:
See the names underlined with red ink. Sum , Product and Answer.
(referring the flowchart with the above mathematical representation)
Here, when a+b is calculated , the answer is stored in "Sum"
ie:
Code:
Sum= a + b
Similarly, when a x b is calculated , the answer is stored in "Product"
ie:
Code:
Product = a x b
When Product(ie a x b) is subtracted to Sum(ie a+b) it is stored in "Answer"
ie:
Code:
Answer = Product - Sum
Recollect the note above, about the variables and read bellow.
What is a Variable?
-> Variable is a vessel that holds a Value . Where as this value is known as constant.
Eg: x , y , z , a , b , c etc etc
What is Constant?
-> Constant is that value that is stored in a Variable.
Eg, 1 , 2 , 3 , 4 , 5 , 6 etc etc
In all the flow chart above,
These were the variables you used:
Number 1
Number 2
Sum
Product
Answer
You can use the Variable Number 1 again and the value of Number 1 in a different flow chart would be different . Hence it is a variable.
But in any flow chart the value of "1" will remain "1" only.. it wont ever be like 1 = 2.
Hope you are getting my point.
This variable is not just for Flow Chart. Learn Any programing , the knowledge of what is variable and constants is necessary , its like the most basic thing .
So to Sum up and give a summary of variables and constants,
A variable is something like a vessel , a vessel that holds the constants. Constants are the values that are stored in vessel which is nothing but a Variable.
We will talk on this later again when we start the c programming.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
As in maths , Constants are limited to numbers. For eg , X = 10 , Y = 15 etc etc
But this is not the case with flowchart , In flowchart you can even write a word or a sentence in a variable.
Eg,
Day = " Wednesday"
Month = " October"
Name = " Mihir"
Birthdate = "1st January 0000"
Mobile no = " 123456789"
Pi = "3.148"
Etc etc...
So as you can widely distinguish , variables in FlowCharts are of 2 Types,
1) Character Variable, Eg, Name = "XDA"
2) Numeric Variable(also known as Integer variables , as Integer contains all the numbers ) , Eg, Num = " 12345"
So when you make flow chart you have to Define all the variables you use if they are number? or they are Character?
See the flow chart below to understand how.
As you can see everything is new in this flowchart.
This is the way we represent a program in a better way in flowchart.
Let me explain to you all of its components.
All of which is written in green above, is like a system command sort of a thing.
And all the red color text are variables.
And all of the blue color things are Operators ( mean + , - , x , = etc, we will talk all about operators in next chapter)
System:
START starts the program
NUMERIC defines that the following variables are Integers/numbers and is written always in processing box. (this process is called DECLARATION we will talk about it in a while).
ACCEPT Accepts constants from the user and stores it in the Variable, always written in input box.
DISPLAY Displays the constants stored in the variable.
STOP Stop/terminates the flowchart/program
Meaning of Declaration!
=> When you want to use a variable, lets suppose u want a variable Num1 , Then you first have to tell the computer that:
"Hey bro, i am using a variable named Num1 in my program which is a numeric variable"
which in flowchart is written as :
Code:
[COLOR="SeaGreen"][B]NUMERIC[/B][/COLOR] [B][COLOR="Red"]nNum1[/COLOR][/B]
As you can see that we are talking to the computer and telling that we are using the variable of this name , it is AS good AS a process?
Hence, it is written in a Processing Box.
As you can see i am prefixing all the numeric variables with n , and you might be wondering , what is this crazy guy talking ?
Basically,
All the variables are prefixed to show what type of variable it is when we use them .
meaning, when we use a numeric variable , we prefix it with n, when we use a character variable we prefix it with c
You can name the variable what ever you like , a, b ,c sum , interest , principle,Name, blah blah etc etc.. anything you like cuz when you will write it in flow chart it will be like nSum, nInterest, nPrinciple , cName. So u will know that Sum ,interest & Principle are numeric variables and Name is a Character variable. Hope now you understand whats the use of prefixing n and c in variable name.
Lets talk about the above flow chart step wise now(referring the numbers in the image above):
After the program starts,
1. There is a Process box. As you know it declares (recollect, declaration means to tell computer that you are using this variable) the variable, hence it is in the process box. In this box the Variables are declared as Numeric and hence are prefixed with n .
2. There is a Input box. What do we do in input box? we take input , and hence there is a proper word defined for it . Accept , and we then write all the variables that we want the values of , from the user.
3. There is a processing box, It adds the two numbers and then stores the value in the Variable Sum which is numeric ( nSum) (it will be clear when i teach you operators in next chapter)
4. There is a Output box, its purpose is to DISPLAY , hence we write Display and then we write all the variables in the Output box that we want to display.
and the program terminates..
======================================================================
Dont give up, let the things sink in. It will take time , you will learn! Trust your self
======================================================================
I would like to advice you to read this again. As you will get a better understanding of it now. And i have added some things in it so dont skip it.
======================================================================
Input:
The Input symbol is used when the user has to input something , in other words it denotes that user will input at this point of program.
eg: the program is about multiplying the two numbers, so the program will ask the user to input two numbers to multiply in this box, 2 and 4
When you want to accept the values from user , you write it in an Input Box. lets suppose you want to Add two numbers , for that you need Three Variables, One variable for storing The first number, second variable for storing the second number , third variable for storing the value of the addition of two variables. And lets name these variables now, nNum1,nNum2 and nSum. So how will you write it in input box?
This way
"Accept nNum1 and nNum2"
Processing:
The Processing symbol is used to show that there will be some processing in the program now.
eg: after the two numbers are accepted, the process of multiplication is shown in this box. 2 * 4
Two things that can be in processes :
The first process box is above, it is used to declare variable with its type,
lets consider the same above example , then u wud write it
"Numeric nNum1, nNum2 and nNum3"
And then you need to add those numbers? correct so you would add it in another processing box like this:
"nSum = nNum1 + nNum2 "
Output:
The result after processing is done, ie after the two numbers are multiplied , the output is given to the user by this symbol.
eg: 2 * 4 = 8
The main purpose of Output box is to show the output.
See the pic below
As we want to display , so we write "Display" in this box. Suppose you want to display Sum calculated above, you would do it this way:
"Display nSum".
We can also write what ever we want in double inverted comas.
Eg
Code:
Display "Hie this is Mihir"
You can even append a variable after it, the constant stored in that variable will be displayed,
Lets suppose there is a variable nNum , in which the Mobile number of a user is saved and the number is 123456789, then you can display it this way:
Code:
Display "Your Mobile number is" nNum
This will display , Your Mobile number is 123456789
Decision:
Some times , its essential for the program to make decisions, this can be achieved with the use of this symbol
eg: If you want the user to input two numbers two multiply, but both the numbers should be less then 5, here u can check if the user has given input as per that , if yes then the program will execute(do the work) the way u code for yes, if no then you have to code a different set of code or re run the program.
Here checking statement means to check something. Eg nSum < 10 or nSum > 10 , nNum <100 etc etc (as of now it consists only of Single Check statement , like you can just see if its a variable is less that 100 and similar things . You cant compare it with two things like a variable is greater than 50 but is less than 100. As of now i cant. We first have to understand operators, after done with operators , we will come back here and talk about it.)
If you were to check if the nSum is less than 100 you would write:
"Is nSum<100 ?"
======================================================================================
Plz read the output box again i have added something. This is for the users who have read the post yest. And i have edited it just now.
======================================================================================
A flow chart for registration.
i guess you can now understand this flowchart above , and i need not explain it to you.
======================================================================================
Chapter 4​
Operators​
===================================================================
Hope the above image , clears your mind about what is variable and constants.. If you still have any confusion about variables and constants then mail me at helpline mail : [email protected] or PM me..
I devote this chapter to Operators..
Operators: The symbols used to make the computer do an operation is know as an operator .
There are various various types of operators:
1)Arithmetical Operators
2)Conditional Operators
3)Relational Operators
1)Arithmetical Operators :
-> Operators used for doing mathematical operations is know as arithmetical operators. This includes the following :
=
+
-
*
/
%
you may be familiar with all the mathematical expressions above, rather than this, one %.
This is not a percentage , its a modulor division operator. Its name is Modulus.
The division operator yields the Quotient as an answer, where as Modulus yields the Remainder as an Answer.
as you can see above,
when you write an expression as 13/2 it will yield an ans 6 . Therefore, 13/2 is 6 or may be 6.5 (calculation in flowchart is not so precise as it is just to understand the flow of the program and not for calculations)
when you write an expression as 13%2 it will yield an ans 1. Therefore, 13%2 is 1.
====================
2)Conditional Operators
Operators that define conditions are known as conditional operators.
They include these
|
&
This | is "OR" operator. It is used when you want to define any conditions like : a<10|a>15. This means either a is less than 10 OR it is greater than 15 , then its yes . (refering to the decision box, cuz thats the only place where you want to put up conditions right?) Only one of the two conditions must be satisfied , in order to make it a YES
If not even one condition is satisfied then it is a NO , n it will run different set of codes .
Image below will help you understand it.
==============================
The second operator is & "AND" operator. This is used when you want conditions like : a>100&a<200. in this , a should be greater than 100 AND a should also be less than 200 , if both the conditions satisfy then only it is a yes, if either of the condition is not satisfied, then its a no.
=======================================================================
3)Relational operators:
->Operators used for relating two variables are known as Relational Operators
They are as follows:
==
<
>
<=
>=
!=
Note: '=' is used to assign the value, eg , a=4, this means a is equal to 4, where as , a==4 , is a relational operator, it checks , IS a is equal to 4?
The two operators == and != are new to you, i explained the first one above,
the second one != is "not equal to", it is used to check , eg , Is a!=4?,if a is not equal to 4 thn its a yes, if a is equal to 4 then its a no.
========================================================================
A flow chart to check whether the number input by the user is positive or negative?
Try this on your own , n then see the answer below,
You would notice , there is a circle after the processing box..
It is an on page conector. When more than one flow lines are conected to something , then this is used, (i havent used it in any of the above eg of flowcharts, just to teach you bit by bit.)
This is what i used before:
this is what is to be used :
====================================================================
This was it Small Chapter 4. On operators..
If you have done this much ,then be proud of your self, cuz u have learned half of the basics of C programming
Next chapter it about Subroutine and off page conector. And then we will commence out voyage in C programming
Chapter 5
Subroutines And Off-Page-Connector​​
==================================================================
So as you have seen many flow charts above, u have came to an end of learning the flow chart, are are soon going to learn about C programming.
==================================================================
So lets talk about Subroutine:
What is Subroutine?
-> It is a symbol used in Flow charts to represent the programs clearly.
You will understand it after you see the flow chart bellow.
Lets suppose you were to make a program to add the numbers (we did it before in Chapter 3) , but using subroutine makes it tidy graphical Representation , and also it is easy to understand while reading it. :
As you can see above , the function of adding the two numbers is separated from the flowchart for better representation , this is known as an Modular Approach of Programming.
(not talking just about FlowCharts , i Am talking of C programming language .)
Modular Approach of programming is , to keep the main code in a file , and then the operating codes in a separate file , as you can see above, the main code is separated from the code that adds the numbers.
It is not of a great help when such a small flowchart, but when u have a full calculator in which you would add , subtract , multiply , divide etc etc , this approach would be the best . :good:
NOTE:at the end of the subroutine , we use a terminator with "RETURN" , and not "STOP"
==================================================================
Lets take another Example.:
You wanted to make a flowchart of a program , a program that adds and subtracts both .
Then it would be represented this way :
(all the three images is one FlowChart Only)
Each image above is like a different page in a book.
So if your flow chart ever exceeds the page in a book or page in any document, then you use the off page Connector.
Lets first talk about subroutine.
As u can see above, the Subroutines add and subtract are separated from the flowchart , you can write it on any page as long as those pages are kept together .
When the page comes to an end, we use a Off-Page-Connector, and then name it what ever we like, and in a new page we make a new Off-Page-Connector with the same name, as you can see a connector with name "A" is on the both page, so the connector "A" on the first page , conects with the conector "A" on the second page , Same way with the connectors named "B"
====================================================================
One more eg and we are done With Flowcharts
A flowchart , to show a program .
The program takes the marks of the students who gave an entrance exam for College, Subjects are Math,English and French. If in each subject a student scores atleast 35 marks and the average of the 3 subject is atleast 50 marks , Then a selection letter from the college is sent , if not , then a rejection letter is sent. Also count the number of selection letters and rejection letters sent.
Note:I wont explain this flow chart. If you can understand it on your own then you are good to go further with C programming , if you cant then please read the chapters again and try understanding it again and then proceed with programming.
The only new thing in this is :
nSelect = nSelect + 1
Lets suppose nSelect is a variable with a value 0 in it , then you can say
nSelect = nSelect + 1 which means , nSelect = 0 + 1
And then suppose nSelect is 1 then
nSelect = nSelect + 1 means nSelect = 1+1 which comes to two.
You can use such type of statements in programing .
Remember ,
The Right Hand Side of an equation is calculated and then stored in the variable Left Hand Side,
NSelect + 1 is calculated and the ans is stored in nSelect on the Left Hand Side. It works as an counter.
And yeah!! you are done with flowcharts.. We will start with Programming ASAP ..
C Programming Begins!!!​
So today we would have started with C programming ,but according to me and my fellow developer friend with whom i discussed of how to teach it to you and decided that we will teach you some extra things. As we are secondarily studying this for learning Android stuff though not only for android , we will try to teach everything about C but we will also try to teach you some extra things that will be helpful while you start with your android development .
So the main things are :
What is Computer?
What is an Operating System?
Where is C usefull in all this?
What is android?
==========================================
What is computer?
-> The definition of computer have changed as it has got many changes in it. Years before when computer wasnt invented , the person who used to do calculations was referred as a Computer as he used compute the Mathematical problems. But as the machine was invented to do the calculation , The machine was then named as "Computer".
==========================================
What is a Operating System?
=> Years Ago when computer was first invented,
it had a monitor of small size, one full room of chips and stuff (today it fits into a small box and we call it CPU) the name of the room was Central Processing Unit , (the room was the core of the computer , and as you know a room is also called as a Unit) . That room used to get commands from other room where the input from user was taken , and then processed and sent back to the same room for displaying it on Monitor. Hence it was a processing room too. So the room with chips used to Process things , it was the Core thing and hence it is named as Central Processing Unit(CPU).
(If you are interested in all the things I said above, then you must study Computer Architecture , as study of all these stuff is known as Computer Architecture .)
When this Computer was invented , it was just for the sake of calculation , you can say it was a 2 room huge calculator. And when you start the computer , You just see a black screen , and then you had to write the whole calculator program in a programming language you like (idk what language was used at that time ) and then do the work. The calculator program was very huge and it was very tiring job of writing it everytime you turn on the computer. So then someone invented "something" that stored the things in it. This "something" was named as Memory. As it stored the calculator program, it was kind of a Memory for the Brain(CPU) of the computer, Hence named as Memory. (This memory was very small it wasnt even 1kb ) And then the Calculator Program was written again and then stored to the memory . So everytime you turn on the Computer you dont have to Write the whole calculator program you just have to write some set of codes to go to memory and run that calculator program. Eventually when the need of computers increased from just calculation to many other Office work , like Storing the customer information, making the list of expenses and profits of an company many such applications were made . But still to run any of these application , some set of codes were neccesary and hence it was useless till some extent for normal people. So a new era was started, The era of operating systems. It was like you will have applications for using APPLICATIONS, eg if you want to use calculator in windows operating system, you will go to Start menu and then accesories and then select calculator. This is called GUI, meaning Graphical User Interface. Today we can make a folder by right clicking and selecting "New Folder" this wasnt the scenerio at that point of time , they had some set of commands to create a folder.(even today you can make a folder with this command in Command Prompt "mkdir NewFolder" mkdir meaning make directory , and then "NewFolder" is the name of the folder. If we want to see what folders we have in c drive, we just go to MyComputer and then go to c drive, this wasnt the case at that time, they had to write set of commands to navigate till that directory , and then had another command to List all the files and folders in that place. So everything was based on Commands Given by the User. So an need of Operating System was essential , where in commands were given by user interface(eg right clicking and making a folder is as good as opening command prompt, navigating to the location and then giving commands to make a new folder .) So when all these things are put together and then the need of Commands is decrease for day to day work , this package of software is known as Operating System.
There are different companies making Operating Systems depending upon the hardware capabilities of a Computer. eg, Windows, Linux and Mac(apple).
Note: The Definition of an Operating System is way too big than i explained above, but this is what you should know as of now.
==============================================================
Where is C usefull in all this?
=> The whole operating System is made in C language. It is a fact that, Windows consists of 13,000 lines of codes where in only 800 lines are not writen in C launguage . Now you can see what is the value of C . (will be writing C rather than C language ) C is widely used in making Operating Systems , Games and Kernels in other electronic Devices.
==============================================================
What is kernel?
=> A set of codes writen in C language that lets the Software and the Hardware communicate is known as kernel. For eg , if you press the volume Down button (hardware) how does android phone knows that the volume down button was pressed and the he has to lower the volume by a level in the phone?
See the image below:
The Hardware says the kernel that the user wants to lower the volume , the kernel comunicates with Operating System(OS) and tells to lower the volume by one level , and then it displays that the volume is decreased .
===================================================
Why C in everything?
=> C is widely used in everything because it is very fast as it is in direct contact with Hardware via kernels. So it is faster than any other programming language. It is not only used in computers. The Food Processor with Timing, the Tv Remote etc everything has C in it.
===================================================
What is Android?
=> Android can be simpt explained by saying "The mobile version of Linux is known as Android"
This was just a chapter for some extra information that would be usefull in your future when you will start doing some work in android or windows, or even when you will try to make some programs in C while you are learning from this tutorial.
Chapter 1 Theory On C prgramming
​So basically What is C?
=> C is a programming language developed at AT & T's Bell Laboratories of USA in 1972. It was designed and written by only one person "Dennis Ritchie". In the late seventies C began to replace the other programming languages like PL/I,ALGOL,etc. No one pushed C neither was it 'official' Bell Labs language nor was it advertised by any means. Still C's reputation spread and its pool of users grew. Ritchie seems to have been rather surprised that so many programmers preferred C over the older languages, including FORTRAN. Still it is choosen over the newer languages like PASCAL and APL.
Probbaly , why C seems so popular is because it is reliable, simple and easy to use. Moreover, In an industry where newer languages, tools and technologies emerge and vanish day in and day out, a language that has survived for more than three decades has to be really good.
An opinion that is often heard today is -
"C has already superceded by languages like C++, C# and Java, so why bother to learn C today!!". I seriously beg to differ with this opinion. There are several reasons for this(according to the aurthor of the book "Let Us C"-Yashwant Kanetkar, and i agree with him):
I believer that nobody can learn C++ or Java directly. This is because while learning these languages you have things like Classes , Objects, Inheritance , polymorphism , Templates , etc. and also the elements like loop , if-else, nested if-else, switch,etc. These elements like loop etc should be learned in C , then about objects in C++ and then Exception handling in Java , so it is like a proper flow in the boat of Knowledge. Though this Three-Step learning process may take more time, but at the end of it you will definitely find it worth the trouble.
C++,C# or Java make use of principle called Object Oriented Programming(OOP) to organize the program. This organizing principle has lots of advantages to offer . But eve while using this organizing principle you would still need a good hold over the language elements of C and the basic programming Skill
Though many C++ and Java based tools and frameworks have evoleved over the years the importance of C is still unchanged because knowingly or unknowingly while using these frameworks and tools you would be still required to use the core C language elements -another good reason whu one should learn C before C++ , C# or Java.
Major parts of popular operating system like Windows, UNIX, Linux are still written in C (As we talked on it earlier) This is because even today when it comes to performance (speed of execution Nothing beats c) Moreover, if one is to extend the operating system to work with new devices one needs to write device driver programs. This programs are exclusively written in C (this is what you will do when you will build android kernels after learning C)
Mobile devices like Cellular phones and palmtops have become rage of today. Also, common consumer devices like mirowaveovens , washing machines and digital cameras are getting smarter by the day. This smartness comes from a microprocessor, an operating system and program embedded in this devices. These programs not only have to run fast but also have to work in limited amount of memory. No wonder that such programs are written in C. With these costraints on time and space, C is the language of choice while building such operating system and programs.
You must have seen several professional 3F computer games where the user navigates some object, like say a spaceship and fires bullets at the invaders. The essence of all such games is speed. Needless to say, such games wont become popular if they take a long time to move the spaceship or to fire a bullet . To match the expectations of the player the game has to react fast to the user inputs. This is where C language scores over the other languages. Many popular gaming frameworks have been built using C language
At times one is required to very closely interact with the hardware devices. Since C provides several languages elements that make this interaction feasible without compromising the performance, it is the preferred choice of the programmer.
I hope that these are very convincing reasons why you should adopt C as the first and the very important step in your quest for learning programming languages.
================================================================================
Getting Started with C​Communicating with a computer involces speaking the language the computer understands , which immediately rules out English as the language of communication with computer. However, there is a close analogy between learning English language and learning C language. The best method to learn English is to first learn the alphabets used in the language , then learn to combine these alphabets to form words, which , in turn, are combined to form sentences and sentences are combined to form paragraphs. Learning C is similar and easier . Instead of straight-away learning how to write programs , we must first know what alphabets, number and special symbols are used in C , then how using them,constants, variables and keywords are constructed and finally, how are these combined to form an instruction. It is illustrated below:
=========================================================================
C Character Set​A character denotes any alphabet, digit or special symbol used to represent information. The Valid aplphabets, numbers and special symbols allowed in C are :
We would talk about what are variables,constants and keywords and set up the programming environment and also make our first prorgram with its flowchart
CHAPTER 2
​I can bet you will relate most of the things with C programming , from flowcharts.
When you run an application , it first reserves the memory required for it to run . Lets suppose you are playing a game on computer, "pinball", this game will first reserve the memory locations in the RAM or storage. And then only THE PINBALL game can access those memory locations. The image below depicts is properly.
as you can see above , memory is made up of cells, each cell has its address (0x111 to 0x142 are the adresses, dont worry about the numbers like 0x111 n stuff i just wrote it to show you , the real memory locations are like 2031576,2031577,2031578,2031579 and so on. We will see it in real when we go further down with the chapters )
Lets say your computer has a memory from 0x000 to 0x999, and then you open the pinball game , the pinball game needs 32memory cells, and it started getting cells from 0x111 and then reserved till 0x142 so that it can run smoothly , and lets suppose you open another app in backgroud , lets say you opened Calculator, and also suppose Calculator needs 50 cells of memory , then it willl start from 0x143 to 0x193.
These cells are nothing but Bytes.
1Gigabyte = 1000Mega Byte
1MegaByte= 1000 Killobyte
1Kilobyte = 1000 byte
This is what we know right? its wrong
1Gigabyte = 1024 Mega Byte
1MegaByte= 1024 Killobyte
1Kilobyte = 1024 byte
What is 1 byte equal to??
1byte = 8bits
NOTE: Google this "1 byte = how many bits"
You will see this at the start , as you can see it works like a converter, just goof around with it have a lil fun n learn mean while.
This was just off topic things, but keep these things in mind while learning C , this is like the general knowledge required for learning C , so now we are starting with Real C programming.
===================================================================================
So now what is variables?
Various Definitions:
Code:
"A variable is the name for a place in the computer's memory where you store some data."
"A variable is a way of referring to a memory location used in a computer program. "
Lets not go into theory again , lets talk about a program in which you want to add two numbers.
First of all you want to accept 2 numbers from users , add them and then store it to another variable?
Lets say you accept two numbers 'x' and 'y' from the user , you cant just write x + y, right? cuz x + y what? you will have to use one more variable 'z' and then store the value sum of 'x' and 'y' in it. ie z=x+y
so now here the three variable 'x' , 'y' and 'z' are variables, agreed?
so these variables WILL be stored in memory?
Each of them will use their own memory cells? or to be precise each one of the variable will use a BYTE from memory?
lets say the three memory locations used are 0x200,0x201,0x202
So you can conclude that the NICKNAMES of the memory location 0x200,0x201,0x202 , are 'x' , 'y' and 'z' respectively.
which in other words means the variable 'x' is reffering to 0x200 , so what ever you store in variable x is gonna be stored in the memory cell with address 0x200 and the same with 'y' and 'z' . so the above definitions are true, If you may read it again , you will understand better . Still you dont know what is DATA in this right? we will talk about it in a while.
What are constants?
The value of a variable is constant.
lets talk about the above program again , the variable x, y and z.
The user inputs the number 2 and 4,
so x = 2 , y = 4 and as these numbers are supposed to add and the answer is stored in z , so z=6.
now the value of x will change from program to program , if i make another program , i can use variable x and it may have a different value.
But the VALUE of value of variable , (2, is the value of x) this will never change, 2 will remain 2 , it wont ever mean 3, like 2=3 or something.
Hence it is a constant. This constant is stored in memory. The image below depicts is clearly.
============================================================================
Lets get in actoin?
So lets download the compiler now.
So the compiler we gonna use is DJGPP, it it like command line GCC (GNU C Compiler) , we will write program in notepad++, and then save it and then open up command prompt and then compile it from there and then we will get an .exe file .(dont worry if you arent getting it, everything will be taught )
Links:
DJGPP
Notepad++
How to download things?
For DJGPP:
select these fields:
The selection of Operating system may change according to your OS. If on Windows 7/vista select windows XP in that os section.
then click on tell me which files to download .
then download each of the zip file .
NOTE : If you are on linux then you have gcc compilers already, google it how to use it.
For notepad++:
go to the link above , then click on download button on left botom panel:
then:
.
===========================================================
Put the downloaded files from DJGPP in a folder named DJGPP.
now open the note pad plus plus exe and install it ..
then copy the DJGPP folder to C drive:
now open notepad++
and then write the name of the files in that DJGPP folder in the notepad++ (write unzip32 and then the file name):
and then save it as DJGPP.bat (dont forget to write .bat in that DJGPP folder..
if you have done the downlaod the way i have said and you have 8 files in the folder then copy this and paste in notepad :
Code:
unzip32 bnu2211b
unzip32 djdev203
unzip32 faq230b
unzip32 gcc472b
unzip32 mak3791b
unzip32 pakk023b
unzip32 rhid15ab
unzip32 txi412b
now go to DJGPP folder and open this DJGPP.bat file.. it will extract things for you..
now go to start menu , right click on my computer then click on properties:
now follow the instructions in the screen shots below(in some screen shots i have show the PATH in note pad, its jst to show you the path in bigger font. you need not write it on notepad):
click on advanced system properties, for windows xp users, you will have a box opened like the image below , click on advanced tab , for vista users IDK i never used Windows vista goof arround with it you will find what to do..
click on environment variables
click on path and then click on EDIT .
Note that in the path , there should be a ':' semicolon , then write c:/djgpp/bin;%PATH% , then click on ok.
now click on new
write these things in the Variable name and variable value , click on ok , then again ok then again ok. and you will be done..
now we have set up our Compiler .
Now lets write our first C program, just to check whether the compiler is running or not.
copy this and paste it in notepad++ ,
Code:
#include<stdio.h>
void main()
{
printf("Hello XDA!!!");
}
now save it with the name hello.c , dont forget to write ".c" at the end.
now open command prompt ,
write
Code:
cd desktop
then write
Code:
gcc hello.c
then write
Code:
a
if you got something like this then you are done.. if you got a error like Gcc is not an internal comand or something.. you messed it up , try the steps above from setting the environment variables.. and still you fail then you mail me at [email protected]
NOTE: Dont worry , we were just checking if its working or no , m gona teach you to use command prompt soon trust me , the boring part is over now. Its all the fun now :good:
Chapter 5 - Part II
Integer and float conversions​
In last tutorial you learnt about the operators used in C programming. Now we will see about how to use them effectively, i am making this tutorial by writing it because it has some tables which will take time for you to understand, and for that its better to write it than to show it in video.
So in order to effectively develop C programs, it will be necessary to understand the rules that are used for the implicit conversion of floating point(means a float variable) and integer values in C. These are mentioned below : (read them carefully , remember float variable, floating point and real variable , all mean one and the same thing)
An arithmetic operation between an integer and integer will always yield an integer result.
Eg. 2*2=4
An operation between real and real will always yield a real result.
Eg, 2.000000 * 2.000000 = 4.000000
Point to remember: : Float variable has 6 digits after the decimal , so if you write ,
Code:
#include<stdio.h>
main()
{
float a;
a=10;
print("%f",a);
}
then it will print 10.000000 as float value has 6 digits of precision..
An operation between an integer and real will always yield a real result.
eg, 6/2.0 = 3.000000 , you see that 6 is integer , 2.0 is real and they are divided, the 6 gets promoted to real value (6.000000) and then 6.000000 is divided with 2.000000 and the answer is 3.000000
Lets list all the operators we know so far:
+ (Addition operator)
- (Subtracting operator)
* (Multiplying operator)
/ (Dividing operator)
% (Modulus)
= (Assignment operator)
== (Equality operator)
Lets suppose you were to write a expresion like this:
Code:
x=2*3+4;
Now there are two possibilities in this ,
The compiler can first multiply:
Code:
2*3
and then add 4 to it.
OR
The compiler can first add:
Code:
3+4
and then multiply it by 2.
These two possibilities can create confusions while making programs, hence to solve these, C has something known as "Operators Precedence".
See the Image Below :
As you can see, that the */% have more precedence then the + -, hence , When there is a expression like:
Code:
x=2*3+4;
First multiplication is carried out , and then it is added. and then it is assigned(the assignment operator has last precedence) to the variable in left.
NOTE: The =! is NOT EQUAL to operator and is used when you compare it. will be explained in following chapters with examples.
===========================================================================================================
In addition to these operators, there are more operators, which we will see as we need them further, and will be explained as we encounter them.,
Chapter 6 (DECISION!! DECISION!! DECISION!!)
Chapter 6​
If you have a calculator which will just ADD the two numbers, then calculator will be pretty useless , wont it?
Hence,There is something in the calculator that decides whether to add or subtract or multiply the two or more numbers provided by the users. This is when we need decision control.
The C language too must be able to perform different sets of actions depending on the circumstances. Actually, this is what makes C popular and very widely usable.
C has three decision making instruction(Reminder:a line of code is instruction)
If Statement
If-Else Statement
Switch
The if Statement​Like most languages, C uses the keyword(if you forgot what is keywords check out the FAQ) if to implement the decision control instruction. The syntax(look FAQ) of if statement looks like this:
Code:
if(condition)
{
[B][I]code[/I][/B];
}
where the CODE is the instructions that you want to run.
And if the CONDITION is true then the CODE is executed.
The keyword if tells the compiler that what follows the keyword if in the ( ) "parenthesis" is the condition. If this condition is true then the CODE in the pair of { } "braces" is executed. if the condition is not true then the statement is not executed, in fact the program skips it.
How to evaluate if the condition is true or false?
With the help of relational operators.(will be taught in the second part of chapter 5, when it will be updated for now just remember that the operators used for relating is known as relational operators Eg. == , !=, < , > , <= , >=.
== is to compare the right hand side with the left hand side and != means not equal and others are simple. Will be taught in detail in Chapter 5 part 2 i will link you as soon as that chapter is done by my friend.)
Lets try a program now:
Code:
//This is a coment
//A program for demonstration of [B][I]if[/I][/B]
#include<stdio.h>
main()
{
int number;
printf("Please enter a number with less than 100\n");
scanf("%d",&number);
if(number<100)
{
printf("What a good student you are!!");
}
}
NOTE:
Never put semi colon after if statement Like this
Code:
if(a<10);
printf("A is less than 10!");
As the program will think that you terminated the if statement after checking the condition , it will think of it this way
Code:
if(a<10)
{
}
printf("A is less than 10!!");
So no matter what the value of a is , it will always print A is less than 10.
A flowchart for the above program to make things clear:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------​
Another Eg:
If your bill is above 10$ in McDonald's then you get 5% discount, if not then no discount.
(try making a flowchart your self , and then see the C program below)
Code:
#include<stdio.h>
main()
{
float billamount;
[COLOR="Green"]/*float data type because bill can be in decimal. eg 10.40$*/[/COLOR]
int discount;
[COLOR="Green"]/*discount will remain 10% only*/[/COLOR]
float totalamount;
[COLOR="Green"]/*the amount after deducting the discount from the bill we will store the value in the "totalamount" variable*/[/COLOR]
printf("Enter your bill amount in Dollars\n");
scanf("%f",&billamount);
if(billamount>=10)
{
discount=5; //If billamount will be more than or equal to 10$ then we will give discount of 5%
}
totalamount=[COLOR="RoyalBlue"]billamount[/COLOR]-[COLOR="Red"]billamount*discount/100[/COLOR];
[COLOR="Green"]/*here [COLOR="red"]billamount*discount/100[/COLOR] is to calculate the percentage and then subtract it with the real [COLOR="RoyalBlue"]billamount[/COLOR]*/[/COLOR]
printf("The total amount is : %f",totalamount);
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
The If Else Statement
----------------------------------------------------------------------------------------------------------------------------------------------------------------------​
The if -Else statement is the real thing, the if statement was derived from it. Will explain you how and why at the end of the If-Else discussion .
The Syntax(syntax means general form )of the IF-ELSE statement is.
Code:
if(CONDITION)
{
CODE If true;
}
else
{
CODE if the CONDITION is false;
}
Lets go through it Step by step:
The CONDITION is evaluated
The CODE IF TRUE will run if the CONDITION is TRUE
if the condition is false then the CODE IF THE CONDITION IS FALSE will run.
Lets see a example
Code:
/*A program to add or subtract the numbers*/
#include<stdio.h>
main()
{
int a,b,c; /*a and b for accepting number for user and c for storing the addition or subtraction*/
char op;
printf("Hello, Please enter your operation (Addition or Subtraction only)?\n");
scanf("%d%c%d",&a,&op,&b);
if(op=='+')
{
c=a+b;
}
else
{
c=a-b;
}
printf("The answer is : %d",c);
}
Some examples tested in the program.
Found it complicated? The lets simplify:
scanf("%d%c%d",&a,&op,&b);
The %d will accept the first integer and save it in a
The %c will accept the Operator(+ or - ) and save it in op
The %d will accept the second integer and save it in b
Then the If will check if the op=='+', if it is + then it will add and store the answer in the variable c. It will skip the ELSE .
If op is not + then it will skip the if and the codes in the Else will run, meaning it will skip the codes in the if and then subtract the two integers and then store the value in variable c.
After this the printf functions prints the variable c, which is the answer.
---------------------------------------------------------------------------------------------------------------------------------------------------------
Revising Stuffs
---------------------------------------------------------------------------------------------------------------------------------------------------------​
Let me brush up your basics again:
%d is for integers
%c is for characters
%f is for floats
Defining: To tell the computer you want a variable of int/float/char type is called as defining a variable.
Eg.
char a;
int b;
float c;
Initializing: To give a value to a variable is known as initializing a variable.
Eg.
char a;
a='Z';
int b;
b=2;
float c;
c=3.000000; (decimal is not neccesary while initializing, but when you will print a float variable , you will see the decimals)
CAN ALSO BE INITIALIZED THIS WAY:
char a='Z';
int b=2;
float c=3.000000;
Note: To initialize a char type of variable, you use ' ' single inverted commas, Eg. char a = 'Z';. This is what we have used in the if condition in the above example , if(op=='+');
When we write only the variable name like, (supposing int x = 10
printf("%d",x);
We will get 10 as output , that is the value of the varaible.
But when we write a variable name with ampersand(&), (supposing int x is located at 25834 on the memory)
printf("%d",&x);
We will get 25834 as output, as the &(ampersand) is a operator that tells the program to related the variable's address rather than its value.
Now you know why we write
scanf("%d",&a);
Rather than:
scanf("%d",a);
---------------------------------------------------------------------------------------------------------------------------------------------------------​
Switch
---------------------------------------------------------------------------------------------------------------------------------------------------------------​When we have to make only two decisions depending upon only TWO possibilities then we use If-Else.
Eg,
If the numbers are even then add them and if not , then subtract them
If the user is male then he have to pay 25.5% as tax from his income and if not male then 25.0% tax from her income
If a number less than 10 then multiply it by 100, if it is not less than 10 then divide it by 100, Etc.
But what if you want to make various decisions depending on various possibilities
Eg,
If the number is less than 10, then add 10. If the number is greater than 20 then subtract 10, if the number is 0 then add 20.
If the character entered by user is 'a' then print A, if 'b' then B,if 'c' then C, if'd' then D, if 'e' then E , Etc.
This is when you use switch case.
The Syntax of switch case is as follows:
Code:
[COLOR="DarkGreen"]Switch[/COLOR](CASE NUMBER)
[COLOR="DarkGreen"]Case [/COLOR]NUMBER 1:
{
CODES HERE;
}
[COLOR="DarkGreen"]Case [/COLOR]NUMBER 2:
{
CODES HERE;
}
[COLOR="DarkGreen"]Case [/COLOR]NUMBER 3:
{
CODES HERE;
}
[COLOR="DarkGreen"]Case [/COLOR]NUMBER 4:
{
CODES HERE;
}
Default:
{
CODES HERE;
}
Post Under Construction ​

TeamCody Discussion thread!

Team Cody!
Member List (in no particular order):
@thewisenerd
@omerjerk
@#Superuser
@dhrumangajjar
@navinn
@xaak
@Agaphetos
WANTED
- Testers - to beat the hell out of our ROMs
- Graphic Designers - boot logos, wallpapers, banners(one or two people)
- Themers - theme EVERYTHING!!!
- Co-Dev(s) - Do i really know what I'm doing most of the time (the answer to that is "probably not")
- Moral Support - LOL
- Suggestions - anything you got - Lay It On Meh!!
our works:
MiniCM9
CodyROM
CM9 Build #15
Evervolv
AOKP
OmniROM
AOSPA-legacy
note to self: add all the works, links
find a thread tagged [TeamCody], that's ours
Team-
@thewisenerd
@omerjerk
@#Superuser
@dhrumangajjar
@navinn
Source- https://www.github.com/CodyROM/
Blog- http://www.codyrom.wordpress.com/
Yea, we need support and suggestions!
todo list:
generalise this
First, finish the work on "reverse mounter"; as it is *technically speaking* easy (for me, to write scripts, that do things); and is pretty straight forward (no aimless edits or so)
fix gps in omni
fix video recording in omni
udpate twrp
switch to wlan0 in omni
random trolling lol
@thewisenerd
we should fix the date bug in notif bar..
is that xml derps..??
navinn said:
@thewisenerd
we should fix the date bug in notif bar..
is that xml derps..??
Click to expand...
Click to collapse
No, its a java derp
Compiling CM11/Kitkat for pico!
I assume you have knowledge of building with source, even if not, I don't really care (for there are a lot of guides).
First, get *all* the required packages installed. As for what I mean by *all*, is not really a question for me to answer. I used <insert-random-guide-from-xda> here, and the source.android.com's guide on initializing, just to be sure.
As for java, I use openjdk. *most* sources today support openjdk, elseways, either, you could force it to be compatible by removing just ONE line in build/core/main.mk
So, that's the packages part.
As for syncing sources, as most guides say, you DON'T need to use a ~/system folder or anything. You can use a folder, anywhere.
Just open up a shell, wherever you want to get the sources synced, and type in the following commands.
I assume you have the repo tool installed. IMHO, you should really create a "bin" folder in your homefolder (short linked as "~/") using the following commands:
Code:
mkdir -p ~/bin
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
Then, open up your ~/.bashrc file, using Geany (a better alternative to Gedit, perhaps ), using the command:
Code:
geany ~/.bashrc
Just insert this line, randomly (preferrably at the end of the file).
Code:
PATH=$PATH:/home/<insert-your-username>/bin
Now, for syncing sources. Make sure you are a directory above working folder.
Code:
mkdir -p <insert-ROM-name>
cd <insert-ROM-name>
Now, that you are inside the working folder, take your pick about the ROM that you are going to compile. This tutorial is for CM11, so i'd be running the following command.
Code:
repo init -u git://github.com/CyanogenMod/android.git -b cm-11.0
Yes, you can reference this from a cm10.2 source that you've already downloaded, and this will reduce the size required to download. Why, you could even reference this from an ICS source (just saying, not meant to be even tried).
If you aren't really building for mac, I'd suggest that you don't download the darwin repos.
Short way that I use:
Run following command in working folder.
Code:
mkdir -p .repo/local_manifests
grep "darwin" .repo/manifests/default.xml > .repo/local_manifests/local_manifest.xml
Open up local_manifest.xml using
Code:
geany .repo/local_manifests/local_manifest.xml
Add these lines on top:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
and the following line at end.
Code:
</manifest>
Now open up "search and replace" dialog box.
Search for:
Code:
<project
and replace with:
Code:
<remove-project
Voila, you've removed all the unnecessary darwin repos.
Now, for repo syncing.
I'd seriously suggest that if you live in parts of the world where the internet speeds are less than 1 m'b'ps (~128 k'B'ps (worst case, mine's around 60 k'B'ps, and I've known people with speeds ranging 30 k'B'ps), you'd sync just one repo at a time (the -jx).
run:
Code:
repo sync -j1
Else, if you have a super fast internet connection, please don't brag. Use a higher number, preferably 3, or 4.
Now, sync these repos, while I attend my classes. I'd return back and write part 2.
edit: part 2; go here: http://forum.xda-developers.com/showpost.php?p=49349691&postcount=8
Compiling CM11/Kitkat for pico! PART 2
reserved
Also, yes, you could use this localmanifest here: https://github.com/PicoKat/local_manifest/blob/dev/local_manifest.xml
but, you'd miss out the learning process
Anyways, this post would take up part 2 of the tutorial.
This is purely device specific. and, there's already a guide on android development section (of this device), the reason why I didn't make a new thread.
part 2 begins here:
Ok, so, you'd synced the repos?
Now, as opposed to roomservice, I'd prefer manually cloning the device tree, kernel, and vendors.
Clone a device tree (galaxyfreak's, or mine), into /device/htc/pico.
Clone the kernel sources from here: https://github.com/PicoKat/android_kernel_htc_pico
Clone the vendor tree from here: https://github.com/PicoKat/android_vendor_htc_pico
(note: if you are using my device tree, that has ION, you'd have to use my vendor tree, with updated blobs here: https://github.com/vineethraj49/android_vendor_htc_pico)
Ok, so that part's setup.
Now, lets move on to cherry-picking, and/or patching some stuff (from legaCyMod).
Note: you could have just added these to local_manifest too...
android_build:
Hopefully, you should know how to add remotes, and working with them, if not, click on the show content, below (as a sample for android_build):
Code:
git remote add legacymod git://github.com/legaCyMod/android_build.git
git fetch legacymod cm-11.0
git cherry-pick <commit-id>
where commit id's the looong "number" following /commit/ in the URL.
1. always rebuild build.prop
2. bringing back squisher
3. Removing TTS data
4. Revert adding auditd
5. add kitkat sdk versions
6. Revert "add drawables for all densities" (seriously, this saves space.)
7. adding support for our recovery
frameworks/av:
1. enable meta mode for video msm7x27a
2.bring back support for legacy omx
3. support legacy qcom audio variant
vendor/cm:
1. bring back squisher
2. revert adb authentication (yea, screw adb while dev'ving
3. remove ze bloats
Next, clone media-legacy to hardware/qcom/media-legacy, and display-legacy to hardware/qcom/display-legacy.
waait!!!!
You need to do some patches in some files. required to fix up camera.
patch two files, manually, making some sense out of this:
frameworks/base: https://github.com/szezso/vivo_cm11_patches/blob/d819363fe7d181e73841d3fa35c1b8c0c7d7c046/frameworks_base.patch
frameworks/av: https://github.com/szezso/vivo_cm11_patches/blob/2f1c87f4453c1c7c88e3c7d2b011994f894fe669/frameworks_av.patch
The next step:
Get prebuilts, seriously.
Code:
cd vendor/cm
./get-prebuilts
Then, "cd" back to root of source dir.
Run the following commands:
Code:
. build/envsetup.sh
brunch pico -j4
Hopefully, you should see an output package by the end of <insert-time-directly-propotional-to-crappiness-of-computer>
For batch-resizing bootanimation (in linux):
resizing part:
Code:
for file in *.png; do convert $file -resize 320x320! $file; done
you'd know which part to edit
for zip'ing part:
Code:
zip -r -y -q -0 bootanimation.zip *
will edit this later
Using CCahe
Now something very important who gonna compile ROMs, use CCache. It'll spped up the building process.
CCache - Compiler cache
How to use?
> Open a Terminal(Ctrl+Alt+T)
>
Code:
gedit /.bashrc
[You can use any alternative to gedit )
> Add the following lines to it:
Code:
export USE_CCACHE=1
export CCACHE_DIR=/[COLOR="Red"]source[/COLOR]/prebuilts/misc/linux-x86/ccache
Source here is the folder in which you have the code downloaded.
>
Code:
cd source
>
Code:
prebuilts/misc/linux-x86/ccache/ccache -M [COLOR="red"]25G[/COLOR]
25G = 25 GB of space to be used as CCache. You can use any value in this.
How does ccache work ?
Well , in short , what it does is that for C and C++ programs it caches the output. One it detects that the program is getting repeated it directly sends out the output and thus reduces the time of compilation.
After using ccache you will really feel the difference in the compilation speeds of your ROMs and kernels. //Copied.
Credits - Red Devil.
I use CCACHE, but the only difference is that I don't specify the directory. also, I did a "apt-get install ccache" long ago, and set file size according to that. Its still working just as fine.
and oh, yes, adding that USE_CCACHE=1 to .bashrc is required
IRC and you!
In case you came here via my signature, sorry for that. But really, you need to know some stuff about IRC, before going to a channel. The pico channel is #pico :fingers-crossed:
So, you might have heard about IRC, even logged into one (freenode, probably, the webclient of it), (and most probably saw that there was no activity and just closed that browser tab).
Let's take a timeout here to talk about IRC.
Instead of me talking about IRC, (and you being too lazy to Google stuff (not intended to those who solve problems themselves (not noobs (?) :wink: :wink)), here's a nice article by Rey Bango that you might want to read: IRC is Back: Here's Your Starter Guide
So, instead of me talking blah blah, and you skimming through most parts, which I assume, you did in the above article (considering you taking the energy to read it), here's what you need to know about Freenode:
..but in terms of development, from my experience, most developers tend to jump on Freenode - and rightfully so.
Click to expand...
Click to collapse
So, just to let you know, in those channels (where you thought there was no activity), there actually is a lot of discussion going on. You just don't know it yet.
So? What am I supposed to do? Keep a browser tab open? Don't expect me to say "Exactly not!" because that too is a viable option, though not very practically possible.
Here's where bouncers come in. Known as BNCs, here's what they do:
A bouncer (BNC for short) is a piece of software used to relay the communication between an IRC client and the network it is connected to, acting as a Proxy.
So, whats the point you ask? The reasons and benefits of using a bouncer are many and include hiding the real IP you are connecting from, protecting your nickname and channel from being taken on networks that don’t provide channel-/nickname registration and most of the time they’ll also notify you of private messages that came in when you’ve been disconnected – of course only when the bouncer can stay online being connected from a server.
Click to expand...
Click to collapse
Coming as either free or paid (either of them being useful, nonetheless), and cutting all the tech jargon, they allow you to "stay online" allowing you to close that browser tab you feared to keep open.
So, in case you actually read through the above quoted text, software!? Being connected from a server? Nah, just kidding. Here's where online BNC providers come in. They provide you a username, (and of course a password, which you need to select), and they host for you the BNC software (in most cases, ZNC).
Most BNCs allow caching of messages, i.e. buffered playback. Their servers are connected 24x7. You, the user, connect to their server, and through their server join the channels. You then, disconnect from their channel. Poof! But, their server still remains connected to the channels, and logs the messages in the channels, and any PMs sent to you. The next time you connect to their server, it gives you all the logged stuff, and it gets cleared. The next time you disconnect, ... Well, you get the flow.
Questions. That's what you go to IRCs for (mostly. I do it for the conversations ). How exactly do you ask questions? Similar to on XDA, but slightly different. I couldn't have said better than l3dx's answer on stackexchange:
Rule #1: Don't ask to ask
Rule #2: Behave as you would do in a real life conversation
Rule #3: Be patient. If there is no activity, it usually means that no one has read what you wrote yet. If no one responds, they don't know or didn't notice. You can re-try after a while, or ask if anyone has any clue with regards to your question x minutes ago.
Click to expand...
Click to collapse
What does Rule #1 mean?
Something very similar to what zxcdw said in the comments:
"Don't ask to ask. Just ask". Don't ask people "Anybody around?" or let alone highlight others to ask if they are around. It's just easier to drop your question, hang around and wait. Ask again in a few hours or so.
Click to expand...
Click to collapse
Also, use English, in most channels, if possible. Stay safe, don't open any unknown links or links to untested software, scripts and stuff. Stay safe.
IRC clients help you stay connected. A few simple google searches will get you going in the right direction. I personally use XChat IRC on Linux, but there are a lot of other good IRC clients available too.
Free bouncers should do, mostly. I use bnc.im, seen people using EliteBNC, some people installing ZNC in their own private servers that are online 24x7, YMMV.
That's about it for IRCs. Happy chatting!
P.S. Make sure you ask the right questions in the right channels.
sys2cache... something to help with less /system partition size.
note: this would be running at boot, with busybox, so,...
Code:
# algo:
# if read(switch_file=1)
# goto case 2.
# else case 1:
# get /system size
# get /data size
# get /cache size
# check /cache remaining size
# check for files in /system
# check for the following folders
# name generic size priority
# ./etc 3.1M 6
# ./vendor 36K 9
# ./addon.d 12K 8
# ./core 76K 7
# ./xbin 1.6M 5
# ./fonts 18M 1
# ./usr 21M 2
# ./media 4.8M 3
# ./bin 5.5M 4
#
# switch = 0;
# file folder_list;
# for i in list_args
# if (getsize($i) < getfreesize(/cache))
# mv $i /cache/$i
# mount bind /cache/$i /system/$i #fix syntax
# ifexists(/system/$i)
# switch = 1;
# folder_list >> $i
# else
# switch = 0; break;
# else
# echo "fak this, we're out of space!"
# fi
#
# echo $switch > switch_file
#
# sync; exit!
#
#
#
# case 2:
#
# for i in xargs(folder_list)
# do
# mount bind /cache/$i /system/$i #fix syntax
# done
#
# sync; exit!
#
#
#
# todo:
# * actually code this shiz
# * better error checking
# * add logging
Hey!
Make sure y'all check this!
http://team-cody.github.io/ :highfive:
welcome to another member @Agaphetos
Source- https://www.github.com/Team-Cody/
todo: update this post with website link.
lol, nvm this post
shameless bump.
since my board exams are over (sort of; only CS is left); i thought of building something for pico (a looong time since I did so).
Waht do I build?
At first thought; one *pure* CM9 build with *some* cherry-picks;
another; an updated CM11 build (updated sources and stuff)...
fixing up omx and stuff on Omni is on the "to-do" list and going to take some 'time' to do; so don't expect it to be fixed already :silly:
So; which one do I 'invest' time in? :cyclops:
@thewisenerd
MTP and OTG in cm9
Cm11 only if you can make it compressed
Sent from my Xperia S using XDA Free mobile app
mirhl said:
@thewisenerd
MTP and OTG in cm9
Cm11 only if you can make it compressed
Sent from my Xperia S using XDA Free mobile app
Click to expand...
Click to collapse
you mean MTP && USB tethering?
edit: a test build will be up today (if build goes well, that is).
edit: here you go: cm-9-20150315-UNOFFICIAL-pico.zip
thewisenerd said:
you mean MTP && USB tethering?
edit: a test build will be up today (if build goes well, that is).
edit: here you go: cm-9-20150315-UNOFFICIAL-pico.zip
Click to expand...
Click to collapse
This is one sick ROM - good job !!!

[GUIDE] Reversing of insertions for ARM-based mobile phones

Author: Apriorit (Research and Reverse Engineering Team)
Permanent link: www(dot)apriorit(dot)com/dev-blog/76-reversing-of-mobile-phones-insertions
Once we faced the need to investigate how Samsung cellular phones work; we required some information from them, which is not documented (and will never be, for sure). So this article is about interesting points our reverser had met while working with Samsung cellular phones firmware.
Reversing of Insertions for ARM-based Mobile Phones
I have managed to research insertions of all Samsung' generations, including CDMA (except for the smartphones only). In every Samsung phone the ARM-compatible processor with a set of ARM7TDMI commands is used. Insertions are built on the basis of three OS: RTCX, RTK, Nucleus, and compiled on different compilers. I have seen insertions compiled on ADS (SDT) and IAR.
On forums people call Samsung's generations in different way: somebody divides them into Gumi/Suvon (2 cities in Korea), others give code names - "Sysol", "Agere", "VLSI", "Conexant" and "Ancient". I have come to a conclusion that it's more correctly to divide them according to the phone processor.
Processor Models
OM6357 (aka Sysol) E100, E700, E720, E800, E820, S50x, X100, X460, X60x
M46 (aka Conexant) A100, A110, A200, A300, A400, M100, T208
SkyWorks (aka Conexant) C100, C108, C110, P510, P518
ONE-C (aka VLSI) R2XX, Nxxx, Txxx(except for T208)
Trident (aka Agere) Dxxx, Qxxx, Sxxx(except for S50x), Vxxx, C200, E105, E310, E400, E600, E710, E810, X105, X400, X42x, X450 etc.
MSMxxxx all CDMA
Hope, I haven't made any mistakes in this list. )
According to the list, insertions within the same generation are very similar and, to be honest, sometimes they are twins at all (with extremely slight changes). For example, in X100 there are obvious traces of E100/E700/X600 - why then there is a code for working with the second display, camera and IRDA, which it didn't have in a whole life?
Naturally, OS is the same for the whole generation:
OM6357 - RTK
M46 - RTCX OSE
SkyWorks - RTCX OSE
ONE-C - RTK
Trident - Nucleus
MSMxxxx - don't know exactly, it might be any OS from Qualcomm. It's just clear that they are collected to ADS/SDT.
If you are going to investigate the low level, then SDK from corresponding OS will be to the point. Another helpful thing is the symbolical information, which can be met in some insertions archives. Sometimes you can come across the insertions with .lst, .sym, .map, .out files, containing the information, extremely useful in researches. In particular, such files occur in almost all C100, S500 insertions. When talking about the other models, the situation is worse and you have to content yourself with symbols signatures, made for insertion of the same generation. For example, for M46 I have managed to find just one insertion with symbols and it was from A110. But signatures made from it perfectly lie down on A200, A300 etc.
Interpretation of the symbolical information
MAP format
.map files contain the information on modules included in the insertion and look like
Code:
Base Size Type RO? Name
0 20 CODE RO AAA_vectors from object file obj/isr.o
20 38e8 CODE RO C$$code from object file../../src/t9latin.o
3908 30 CODE RO C$$code from object file obj/mmi_date.o
3938 5a4 CODE RO C$$code from object file hw_slow.o
3edc 874 CODE RO C$$code from object file rtkgo.o
etc.
where
Base - displacement in an insertion file.
Size - length.
Type - region type.
RO? - region access type.
Name - original file name, part of which was included in the insertion
How all this can be interpreted? For example, this way: starting with displacement 20, there is a block of the code (CODE) 38e8 length - it's an access to Read Only block. The fact that block has CODE attribute is far from being means that the WHOLE area is filled with a code. Actually, it is a code plus data, just as if the block has DATA type it does not mean that it is necessary to make it all by data in IDA.
Without the names/symbols file this information can be used only for determination of insertion code size (i.e. to not get into the graphics). Therefore, we will better examine SYM format.
SYM Format
.sym files are the mines of information. They look like:
Code:
Symbol Table
AAA_vectors$$Base 000000
AAA_vectors$$Limit 000020
VectorMap$$Base 1006a3c
VectorMap$$Limit 1006a60
isr$$Base 12774c
isr$$Limit 127bb0
gl_MaskIT 1000078
Rtk_RegionCount 100564c
rtk_WorthItSched 10056a0
Rtk11_Schedule 11f5c8
etc.
It is a little bit easier here, because the name-address correspondence exists. But as for the addresses, there are some secrets - a set of names exists, containing $ sign and having the special status. Symbols with $$Base at the end indicate the beginning of virtual address space area, $$Limit indicates the end. I.e. here we have the information on segments. It is possible to make a memory map of these segments and see how the parts of binary code are being thrown to different addresses. Building memory map should be started with such symbols:
Code:
Image$$RO$$Base 000000
Image$$RO$$Limit 1afef4
Image$$RW$$Base 1000000
Image$$RW$$Limit 107dad4
Image$$ZI$$Base 1006a60
Image$$ZI$$Limit 107dad4
RO - Read Only, indicates code addresses.
RW - Read/Write i.e. it is RAM.
ZI - Zero Initialized. RAM, which is being stuffed with zero values when mobile phone is turned on.
Thus segments can be easily created on these addresses. Now we look further:
Code:
AAA_vectors$$Base 000000
AAA_vectors$$Limit 000020
C$$code$$Base 000020
C$$code$$Limit 127310
C$$code$$__call_via$$Base 127310
C$$code$$__call_via$$Limit 127320
Example$$Base 127320
Example$$Limit 127324
HAL_boot$$Base 127324
HAL_boot$$Limit 12735c
RtkCode$$Base 12735c
RtkCode$$Limit 127408
SysSupportCode$$Base 127408
SysSupportCode$$Limit 12744c
boot$$Base 12744c
boot$$Limit 127654
clib$$Base 127654
clib$$Limit 12774c
isr$$Base 12774c
isr$$Limit 127bb0
C$$constdata$$Base 127bb0
C$$constdata$$Limit 1afef4
C$$data$$Base 1000000
C$$data$$Limit 1005a38
Stacks$$Base 1005a38
Stacks$$Limit 1006a3c
VectorMap$$Base 1006a3c
VectorMap$$Limit 1006a60
C$$zidata$$Base 1006a60
C$$zidata$$Limit 107dad4
In this interesting way they go one after another. If you wish, it is possible to divide them into segments to corresponding addresses, but this is merely a logic division. Moreover, in .sym file these lines are scattered badly. And more sooner or later a question appears: why the code size is 1afef4, if length of insertion file is 1b6950? Where to put the rest 6a60 byte? We look again on the initial memory map:
Code:
Image$$RW$$Base 1000000
Image$$RW$$Limit 107dad4
Image$$ZI$$Base 1006a60
Image$$ZI$$Limit 107dad4
RAM ends on 107dad4 address, block 1006a60-107dad4 is zero initialized, hence there is a question: what does initialize the 1000000-1006a60 block, which size is exactly 6a60? Absolutely right, those odd bytes. If analyse the OS start code, then in the RAM initialization procedure you will find the same copying.
In the newer insertions there is a chance to come across the next inscriptions:
Code:
Load$$IRAM$$Base 639a74
Image$$IRAM$$Base 2010000
Image$$IRAM$$Length 0015a4
They should be understood this way: data of 15a4 length are being loaded from 639a74 file displacement to the 2010000 address.
We continue the analysis of symbols with the $ sign:
x$litpool$ - Literal Pool, pieces of the data from functions. At the end of many functions indexes, lines, constants are placed, and x$litpool$ specifies the beginning of such constants.
x$litpool_e$ - Literal Pool end.
$T is merely for debugger. Indicates the addresses where the PC register change take place. So, at these addresses transition commands BL/BEQ/B/BX etc. are placed.
$$- addresses where there is a change of ARM/THUMB state.
There are also C$$code symbols, but I haven't found what it is.
Other names without $ sign are the names for constants and functions. They can be freely used.
If the archive with an insertion contains both MAP and SYM, it is an ideal variant - when you set a name taken from SYM it is possible to check up whether it lays in the code area by using data from MAP. If yes, we may freely indicate it as code not being afraid, that code/data will be determined in IDA incorrectly.
LST Format
It's a real paradise for a reverser, in these files lays all at once. They consist of five parts:
Image Symbol Table - symbols... their meaning I have not understood yet
Local Symbols - everything is clear from the name
Global Symbols - .sym file analogue.
Memory Map of the image - memory map! All at once!
Image component sizes - .map file analogue
The information is so detailed, that even the processor mode for each function is specified.
OUT Format
Have met it only in the Nucleus-based insertions. Here can be tlink.out and tsymb.out files:
tsymb.out - ordinary SYM
think.out - MAP file to which almost useless linker information is added.
Now when we are armed with the symbolical information we can load the insertion in IDA.
What to do if there are no symbols at all
"When there is no toothbrush at hand..." Yes, we take IDA, emulating debuggerand brains in the hands. IDA is "must have". The emulating debugger for ARM, called Trace32, can be taken here.
First of all, we load the insertion in IDA to 0 address. I.e. the whole insertion is being loaded to default addresses. Then look what is on 0 address.
Code:
BOOT:00000000 B ResetHandler
BOOT:00000004 B loc_3B4
BOOT:00000008 B loc_410
BOOT:0000000C B loc_42C
BOOT:00000010 B loc_488
etc.
The code in any case begins with 0 address. In all Samsungs and, as I guess, not only in Samsungs an insertion begins with the interruption vectors. These are eight B commands in ARM state, i.e. 8 vectors. 0 address is a vector of null interruption or insertion start/restart. This zero interruption simply starts the mobile phone and thus handler leads to the system loader:
Code:
BOOT:00000048 ResetHandler; CODE XREF: BOOT:loc_0 _ j
BOOT:00000048 MRS R0,CPSR
BOOT:0000004C BIC R0,R0,#0x1F
BOOT:00000050 ORR R0,R0,#0x13
BOOT:00000054 ORR R0,R0,#0xC0
BOOT:00000058 MSR CPSR_cxsf,R0
BOOT:0000005C LDR R3,=(InitialHWConfig+1)
BOOT:00000060 MOV LR,PC
BOOT:00000064 BX R3
If the jump from zero address goes to the non-existent address it means that the rest part of the code is mapped to some other addresses. It's easy to determine to which exactly. For example, we have such beginning:
Code:
BOOT:00000000 B 0x4003CE
And there is no code on the 4003CE address. We look on 3CE displacement and see an ARM-code. It means the rest part of insertion is displaced on 0x400000. So we have to copy piece of insertion with interruption handlers, load them to zero address and then load an insertion from 400000 address. Now our code is in the right place. We go further. It is necessary to find out where are the RAM and area of input/output ports. The ports are usually either in the end (addresses from about e0000000 and higher) or in the beginning of the memory (up to 0x200000), depending on where the insertion is being loaded. There can be several RAM areas. First of all, we see ports initialization:
Code:
BOOT:00000588 MOV R1,#1
BOOT:0000058A LDR R0,=0xE0006000
BOOT:0000058C LSL R1,R1,#0x1B
BOOT:0000058E STR R1,[R0]
BOOT:00000590 STR R1,[R0,#0x10]
BOOT:00000592 STR R1,[R0,#0x20]
BOOT:00000594 LDR R1,=loc_20102
BOOT:00000596 LDR R0,=0xE0003040
BOOT:00000598 STR R1,[R0, #4]
BOOT:0000059A LDR R1,=0x20003
BOOT:0000059C STR R1,[R0, #8]
BOOT:0000059E LDR R0,=0xE0003000
BOOT:000005A0 MOV R1,#0xC
BOOT:000005A2 STR R1,[R0,#0x24]
I.e. since around E0000000 there is an area of input/output ports. Its size doesn't exceed the size of segment and therefore it's possible to create a segment of 0x10000 size. Now we go further. In any insertion there are RAM area which is initialized by zero values and the area which is filled by initial settings which are taken from an insertion. We are looking for copy cycles, so we need the debugger.
Here we see copying:
Code:
BOOT:000000D4 LDR R0,=0x63B018
BOOT:000000D8 LDR R1,=0x1000000
BOOT:000000DC LDR R3,=0x1045B38
BOOT:000000E0 CMP R1,R3
BOOT:000000E4 BEQ loc_F8
BOOT:000000E8
BOOT:000000E8 loc_E8; CODE XREF: BOOT:000000F4 _ j
BOOT:000000E8 CMP R1,R3
BOOT:000000EC LDRCC R2,[R0],#4
BOOT:000000F0 STRCC R2,[R1],#4
BOOT:000000F4 BCC loc_E8
The block is being copied from 63B018 address to 1000000 address of insertion. The length is 45B38.
This is the first RAM area. Now we look for the second one, whose zero initialization should be nearby:
Code:
BOOT:000000F8 LDR R1,=0x11ED9E4
BOOT:000000FC MOV R2,#0
BOOT:00000100 CMP R3,R1
BOOT:00000104
BOOT:00000104 loc_104; BOOT:00000108 _ j
BOOT:00000104
BOOT:00000104 STRCC R2,[R3],#4
BOOT:00000108 BCC loc_100
Indeed, there is a stuffing with zero values in the area from 1045B38 to 11ED9E4, so here we have the second part. If there are any areas, then there will certainly be zero or copy initialization. Other memory pieces can be found only analytically, but we have got the basis already.
The further research depends on the presence of symbols/signatures. If yes, then everything comes to looking for the necessary function in the names list. What to do if not? First of all, it is necessary to determine approximate code bounds and, if possible, to find functions in the code. The most primitive and effective way is to search for a push command with which 60 % of insertion code begins. Insertion code usually consists of Thumb code on 90 %, so we should look for B5 byte (push) and try to define it as the code in IDA. Insertion code usually takes less than 50 % of the whole size, the rest part is for graphics and language resources. Else I can say that very often at the end of the code there are copyrights lines, a kind of "Samsung corp. 199x-200x ARM ADS 1.2".
Some code has been revealed, around 20% were harmed by IDA itself, because it often can't cope with THUMB/ARM transition. And now we have to take anything left lying around loose, i.e. what had been left by programmers. And what they had left? Trace and Assert. And any trace and assert doesn't go without sprintf/printf. We have to find it. It's easy - we should just look for the "%s" line. We need that which obviously contains a pattern of the error message. With xref we find where this line is used and it will be exactly sprintf, followed by Trace or Assert. Now, with basing on the error messages, we can name the functions. I.e. walking with xref to the Trace/Assert function, we can find output of more than half of mistakes. Further functions naming is possible by searching the following words:
Code:
Bad
Fail
Incorrect
Invalid
Error
Memory
File
Null
No
Critical
Abnormal
etc.
This way we will find some more error output functions. Thus we will gradually gain the information, not being based on anything except for the insertion.

Copy text to clipboard in shell

Interacting with the Clipboard from the shell can be difficult.
It used to be easier and you could use service call clipboard ...
Nowadays Clipboard only takes ClipData.
Ok, you could still do it using the service executable but you'd have a long list of opaque numbers.
I wrote a regular executable (not using any Java itself) to fill the Clipboard with your text.
It works for UTF-8, although I haven't gotten it to work pretty-like on Windows.
(I got the CHCP 65001, but I don't have a font for the console.)
Code:
# /data/local/tmp/copyclip 'I want to go to 中关村科贸电子城.'
This is an ELF64, you have to be rooted, it's a beta and everything is subject to change.
It works on A10. Later Android might need some fixes for attribution tags.
You should rename it to plain "copyclip".
Just park it somewhere (/data/local/tmp is fine) and chmod 755 it.
I've made a few tiny tweaks.
You can do the paste automatically, but there's a rub.
The input keyevent is pretty stupid because it rolls out a whole zygote just to inject a key.
Still, if you don't expect performance you can always:
Code:
# ./copyclip 'The short tedious text' && input keyevent 279
Normally, I do either a USB HID device or a key injector daemon if I want performance.
As noted previously, copyclip itself doesn't roll out a zygote, so it's quick.
Edit: Update again March 7th.
Yet another fine tuning.
I'm thinking about -e processing like echo has.
copyclip can be found in my sig.
Hmm, that's interesting. There were big changes in ClipData from A10 to A11.
This wouldn't work if you are on A11.
There's a two new versions out that works for at least A9, A10 & A11, either 32 bit or 64 bit.
If you're not rooted you'll probably get:
Code:
Error: Package android does not belong to 2000
You'll find it in the sig.
I'd appreciate any feedback on success/failure.
It seems like this would be really useful for entering snippets of Unicode text selected from the desktop.
input text can't handle Unicode.
One of the reasons that I'm having fun with this is the efficiency of not using app_process/Zygote/Java.
Code:
Poke3:/ # time input text Hello
0m00.51s real 0m00.28s user 0m00.20s system
Poke3:/ # time /data/local/tmp/copyclip Hello
0m00.04s real 0m00.01s user 0m00.02s system
Yow! I love talking to myself! I'm 7 posts in and no interruptions from somebody who wants to know something.
I just posted (Win32) adbclip.exe, an amazing accessory that works in concert with (Android) copyclip.
If you're on your desktop you can go to some nice Korean (or Japanese or Arabic or English) website, select some text and then paste it to the Android clipboard!
Amazing, eh?
All the details are in my sig, or more directly: http://www.temblast.com/copyclip.htm.
The Android utility copyclip has been updated:
You can style the text bold with -b and/or italic with -i
You can pipe other shell commands to it: date | /data/local/tmp/copyclip

Categories

Resources