read 시스템콜 질문입니다!

enaaan의 이미지

간단한 shell 을 만들고
execve()에게 매개변수를 전달해주기위해서
새로운 my_read() 함수를 만드려고 합니다

void my_read(char *a, char *b)
{
 read(0,a,100);
 read(0,b,100);
}
 
이런식으로 전달하려고했는데... 무엇이 문제인가요ㅠ
처음하는거라서 너무 서투르네요....ㅠ
shint의 이미지

- 함수 인자값을 포인터로 넘기는것은 C 책을 보시면 알 수 있습니다.
- read 함수'라고 네이버와 구글 검색 해보면. 함수 설명을 볼 수 있습니다.
- read 함수에 첫번째 인자값은 파일 디스크립터로 검색하시면 알 수 있습니다.
- read 함수에 두번째 인자값은 데이터 버퍼 입니다.
- read 함수에 세번째 인자값은 데이터 크기 입니다.
- execve 함수에 첫번째 값은 경로이고. 두번째값은 포인터 배열입니다.

이것들을 확인해 보시면 될거 같습니다.

함수와 C. 배열에 대해 알고 싶으시다면.
C 관련 책을 보거나. 학원. 직업교육시설등을 참고해보시면 좋습니다.

어설프게 설명해 드린다면. 이런 겁니다.

#include <stdio.h>
 
void fn_execve(const char* path, char * const argv[])
{
	int i=0;
	printf("경로명 : %s\n", path);
 
	while(1)
	{
		if(argv[i] == NULL)
			break;
 
		printf("argv[] : %s\n", argv[i]);
		i++;
	}
}
 
 
void my_read(char *a, char *b)
{
// read(0,a,100);
// read(0,b,100);
	printf("----------------------------------------------------\n");
	printf("a에 값   : %s     b에 값   : %s\n", a, b);
	printf("a에 주소 : %x     b에 주소 : %x\n", &a, &b);
}
 
int main(int argc, char* argv[])
{
    char data1[10] = {"shint1"};
    char data2[10] = {"shint2"};
 
	//.c 파일에서는 데이터형 선언을 가장 위로 해야 한다.
	//error C2143: 구문 오류 : ';'이(가) '형식' 앞에 없습니다.
	char * argv_test[5] = { "test1", "test2", "test3" };
//-	argv_test	0x0012fe9c	char * [5]
//+	[0x0]	0x0042602c "test1"	char *
//+	[0x1]	0x0042601c "test2"	char *
//+	[0x2]	0x00426024 "test3"	char *
//+	[0x3]	0x00000000 <Ptr>이 잘못되었습니다.	char *
//+	[0x4]	0x00000000 <Ptr>이 잘못되었습니다.	char *
 
	printf("----------------------------------------------------\n");
	printf("data1에 값   : %s     data2에 값   : %s\n", data1, data2);
	printf("data1에 주소 : %x     data2에 주소 : %x\n", &data1, &data2);
 
	my_read(data1, data2);
 
	printf("----------------------------------------------------\n");
	printf("data1에 값   : %s     data2에 값   : %s\n", data1, data2);
	printf("data1에 주소 : %x     data2에 주소 : %x\n", &data1, &data2);
 
 
	//
	//fn_execve(const char* path, char * const argv[])
	fn_execve("c:\\testpath", argv_test);
 
 
	system("pause");
    return 0;
}
 
 
//출력 화면
----------------------------------------------------
data1에 값   : shint1     data2에 값   : shint2
data1에 주소 : 12fecc     data2에 주소 : 12feb8
----------------------------------------------------
a에 값   : shint1     b에 값   : shint2
a에 주소 : 12fdc8     b에 주소 : 12fdcc
----------------------------------------------------
data1에 값   : shint1     data2에 값   : shint2
data1에 주소 : 12fecc     data2에 주소 : 12feb8
경로명 : c:\testpath
argv[] : test122
argv[] : test2
argv[] : test3

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.