'IDA patching, How to add new code, create new variable?

I have a very basic knowledge about IDA and patching. From my understanding, I can change a line of code by doing Edit -> Patch program -> Assembly. But how to I go about adding new lines of code into program?

The existing variable can also be change by doing Patch program-> Change byte, how can new variable be added?



Solution 1:[1]

add new code: as CherryDT said,Find an unused place to put your code (or create one by adding a section to the file). jump to ...then jump return.

create new variable: no need to do this,"add new code" can do everything.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 omgkaka