2007/10/05
File Control in C
File Open
FILE *fp;
fp = fopen("FileName" , "Mode");
/* 失敗 return NULL */
Mode
w ... 只可寫入,覆寫
r ... 只可讀取
a ... 只可附加資料在此檔之後
b ... 只可讀取 binary 類型 file
r+ ... 可讀取與寫入
w+ ... 可讀取、覆寫
a+ ... 可讀取、附加資料在此檔之後
/* 以下成功 return 0 ,失敗 return EOF 即 -1 */
File Close
fclose(fp);
fgetc、fputc
File *fp2 = fopen("FileName2.txt","w");
int c;
while ( (c = fgetc(fp /* stdin */)) != EOF) /* 讀取一個字元並傳回 */
fputc(c, fp2 /* stdout */); /* 將字元 c 寫入檔案 */
fscanf、fprintf
fscanf(FILE *stream, const char *format, ...);
/* 用法同 scanf(),但讀取的資料改成來自 stream */
fprintf(FILE *stream, const char *format, ...);
/* 用法同 printf(),但寫入的資料改成寫到 stream */
ex:
fscanf(stdin,"%d",fp); /* 讀 stdin 寫 fp */
fprintf(fp,"%d",stdout); /* 讀 stdout 寫 fp */
/* 以下傳回所讀資料的筆數,若失敗傳回值為 0 */
fread、fwrite
char buf[128];
while ( (size = fread(buf, sizeof(char), sizeof(buf), fp_in) ))
fwrite(buf, sizeof(char), size , fp_out) ;
/* 從檔案 fp_in 讀取資料,一次讀取資料大小為 sizeof(char) 的物件
sizeof(buf) 個,並且將讀到的資料存放到 buf 這個暫存區,將 buf
所存的資料大小為 sizeof(char) 的物件 size 個,寫入檔案 fp_out */
fgets、fputs
char s[128]
fgets(s, n, fp);
/* 由 fp 讀入 n-1 個字元, 儲存到 s 的位址,正
確 return *s , 錯誤或檔案結束 return NULL */
fputs(s, fp);
/* fputs() 將字串輸出至 fp 成功 return
最後一個輸出的字元, 否則 return EOF */
FILE *fp;
fp = fopen("FileName" , "Mode");
/* 失敗 return NULL */
Mode
w ... 只可寫入,覆寫
r ... 只可讀取
a ... 只可附加資料在此檔之後
b ... 只可讀取 binary 類型 file
r+ ... 可讀取與寫入
w+ ... 可讀取、覆寫
a+ ... 可讀取、附加資料在此檔之後
/* 以下成功 return 0 ,失敗 return EOF 即 -1 */
File Close
fclose(fp);
fgetc、fputc
File *fp2 = fopen("FileName2.txt","w");
int c;
while ( (c = fgetc(fp /* stdin */)) != EOF) /* 讀取一個字元並傳回 */
fputc(c, fp2 /* stdout */); /* 將字元 c 寫入檔案 */
fscanf、fprintf
fscanf(FILE *stream, const char *format, ...);
/* 用法同 scanf(),但讀取的資料改成來自 stream */
fprintf(FILE *stream, const char *format, ...);
/* 用法同 printf(),但寫入的資料改成寫到 stream */
ex:
fscanf(stdin,"%d",fp); /* 讀 stdin 寫 fp */
fprintf(fp,"%d",stdout); /* 讀 stdout 寫 fp */
/* 以下傳回所讀資料的筆數,若失敗傳回值為 0 */
fread、fwrite
char buf[128];
while ( (size = fread(buf, sizeof(char), sizeof(buf), fp_in) ))
fwrite(buf, sizeof(char), size , fp_out) ;
/* 從檔案 fp_in 讀取資料,一次讀取資料大小為 sizeof(char) 的物件
sizeof(buf) 個,並且將讀到的資料存放到 buf 這個暫存區,將 buf
所存的資料大小為 sizeof(char) 的物件 size 個,寫入檔案 fp_out */
fgets、fputs
char s[128]
fgets(s, n, fp);
/* 由 fp 讀入 n-1 個字元, 儲存到 s 的位址,正
確 return *s , 錯誤或檔案結束 return NULL */
fputs(s, fp);
/* fputs() 將字串輸出至 fp 成功 return
最後一個輸出的字元, 否則 return EOF */
2007/09/21
[TeX/LaTeX] NS2 Documentation's page number problem
Edit "ns-daily-2.31/ns-2/doc/basic.tex" as follows for correct page number
The number 12 is the correct page number for the manual on September 20, 2007
-\chapter{Introduction}
+\chapter{Introduction}\setcounter{page}{12}
The number 12 is the correct page number for the manual on September 20, 2007
2007/09/11
Using Sluice on Tmote Sky
Sluice: Secure Dissemination of Code Updates in Sensor Networks
Source code
Author's research website
0. Install Moteiv’s Tmote Tools from http://www.moteiv.com/
1. Extract file "sluice-tinyos.tgz" and move sub-directory "contrib" to "C:\cygwin\opt\tinyos-1.x\contrib"
2. Change file "/opt/tinyos-1.x/contrib/cmu/tools/java/jars/bcprov-jdk15-130.jar" to latest version if you need from here. (I use "bcprov-jdk16-137.jar" for this note.)
3. Set up environment variables as follows:
[code]export LD_LIBRARY_PATH=".:$LD_LIBRARY_PATH"
export TOSROOT="/opt/tinyos-1.x"
export TOSDIR="$TOSROOT/tos"
export MAKERULES="$TOSROOT/tools/make/Makerules"
export CLASSPATH="`$TOSROOT/tools/java/javapath`;C:\\\\cygwin\\\\opt\\\\tinyos-1.x\\\\contrib\\\\cmu\\\\tools\\\\java;C:\\\\cygwin\\\\opt\\\\tinyos-1.x\\\\contrib\\\\cmu\\\\tools\\\\java\\\\jars\\\\bcprov-jdk16-137.jar"
export SLUICE_PRIV_KEYFILE="c:\\\\cygwin\\\\opt\\\\tinyos-1.x\\\\contrib\\\\cmu\\\\tools\\\\java\\\\eccPrivate.key"[/code]
4. Modify files "/opt/tinyos-1.x/contrib/cmu/tos/lib/Sluice/DelugePageTransferC.nc" and "/opt/tinyos-1.x/contrib/cmu/tos/lib/Sluice/DelugePageTransferM.nc" about token "SharedMsgBufTX" and "SharedMsgBufRX" by refer to files " /opt/moteiv/tos/lib/Deluge/DelugePageTransferC.nc" and "/opt/moteiv/tos/lib/Deluge/DelugePageTransferM.nc"
5. Modify files "/opt/tinyos-1.x/contrib/cmu/tos/lib/Sluice/VerifierM.nc" as follows:
6. Change to directory "/opt/tinyos-1.x/contrib/cmu/apps/Sluice" and make as follows:
[code]make tmote install[/code]
7. Change to directory "/opt/tinyos-1.x/contrib/cmu/tools/java/net/tinyos/sluice" and "/opt/tinyos-1.x/contrib/cmu/tools/java/net/tinyos/tools" and complie all java files
8. Set up environment variables of "MOTECOM" for the Tmote Sky. for example:
[code]export MOTECOM=serial@COM6:tmote[/code]
9. Now, you can run "java net.tinyos.tools.Sluice" for testing.
Note: the source seems only implement function "inject".
for a example:
10. Change to directory "/opt/moteiv/apps/Count/CountLed" and Modify
file "/opt/moteiv/apps/Count/CountLed/Makefile" as follows:
11. And then make as follows:
[code]make tmote[/code]
12. Change to directory "/opt/moteiv/apps/Count/CountLeds/build/tmote" and "inject to image 1" as follows:
[code]java net.tinyos.tools.Sluice -i -in=1 -ti=tos_image.xml[/code]
Source code
Author's research website
0. Install Moteiv’s Tmote Tools from http://www.moteiv.com/
1. Extract file "sluice-tinyos.tgz" and move sub-directory "contrib" to "C:\cygwin\opt\tinyos-1.x\contrib"
2. Change file "/opt/tinyos-1.x/contrib/cmu/tools/java/jars/bcprov-jdk15-130.jar" to latest version if you need from here. (I use "bcprov-jdk16-137.jar" for this note.)
3. Set up environment variables as follows:
[code]export LD_LIBRARY_PATH=".:$LD_LIBRARY_PATH"
export TOSROOT="/opt/tinyos-1.x"
export TOSDIR="$TOSROOT/tos"
export MAKERULES="$TOSROOT/tools/make/Makerules"
export CLASSPATH="`$TOSROOT/tools/java/javapath`;C:\\\\cygwin\\\\opt\\\\tinyos-1.x\\\\contrib\\\\cmu\\\\tools\\\\java;C:\\\\cygwin\\\\opt\\\\tinyos-1.x\\\\contrib\\\\cmu\\\\tools\\\\java\\\\jars\\\\bcprov-jdk16-137.jar"
export SLUICE_PRIV_KEYFILE="c:\\\\cygwin\\\\opt\\\\tinyos-1.x\\\\contrib\\\\cmu\\\\tools\\\\java\\\\eccPrivate.key"[/code]
4. Modify files "/opt/tinyos-1.x/contrib/cmu/tos/lib/Sluice/DelugePageTransferC.nc" and "/opt/tinyos-1.x/contrib/cmu/tos/lib/Sluice/DelugePageTransferM.nc" about token "SharedMsgBufTX" and "SharedMsgBufRX" by refer to files " /opt/moteiv/tos/lib/Deluge/DelugePageTransferC.nc" and "/opt/moteiv/tos/lib/Deluge/DelugePageTransferM.nc"
5. Modify files "/opt/tinyos-1.x/contrib/cmu/tos/lib/Sluice/VerifierM.nc" as follows:
...
command uint8_t Verifier.verify(uint8_t *msg_ptr, uint16_t msg_len, NN_DIGIT *r_ptr, NN_DIGIT *s_ptr) {
...
if (post VerifyTask()) {
-#if 1
+#if PLATFORM_PC
dbg(DBG_USR2, "[Verifier.verify] info: posted VerifyTask\n");
dbg_clear(DBG_USR2, "\tr: 0x");
print_nn(r, DBG_USR2);
dbg_clear(DBG_USR2, "\n\ts: 0x");
print_nn(s, DBG_USR2);
dbg_clear(DBG_USR2, "\n");
#endif
return SUCCESS;
} else {
...
}
}
...
6. Change to directory "/opt/tinyos-1.x/contrib/cmu/apps/Sluice" and make as follows:
[code]make tmote install[/code]
7. Change to directory "/opt/tinyos-1.x/contrib/cmu/tools/java/net/tinyos/sluice" and "/opt/tinyos-1.x/contrib/cmu/tools/java/net/tinyos/tools" and complie all java files
8. Set up environment variables of "MOTECOM" for the Tmote Sky. for example:
[code]export MOTECOM=serial@COM6:tmote[/code]
9. Now, you can run "java net.tinyos.tools.Sluice" for testing.
Note: the source seems only implement function "inject".
for a example:
10. Change to directory "/opt/moteiv/apps/Count/CountLed" and Modify
file "/opt/moteiv/apps/Count/CountLed/Makefile" as follows:
COMPONENT ?= CountLedsC
CFLAGS += -I..
+PFLAGS += -DVERIFY_TIME=25 -I$(TOSROOT)/contrib/cmu/tos/lib/Sluice -I$(TOSROOT)/contrib/cmu/tos/lib/SHA1 -I$(TOSROOT)/contrib/ncsu/tos/lib/TinyECC
+TINYOS_NP ?= BNP
include $(MAKERULES)
11. And then make as follows:
[code]make tmote[/code]
12. Change to directory "/opt/moteiv/apps/Count/CountLeds/build/tmote" and "inject to image 1" as follows:
[code]java net.tinyos.tools.Sluice -i -in=1 -ti=tos_image.xml[/code]
2007/09/10
BackTrack: Penetration Testing
BackTrack is the most Top rated linux live distribution focused on penetration testing. With no installation whatsoever, the analysis platform is started directly from the CD-Rom and is fully accessible within minutes
BackTrack Wiki.
remote-exploit.org
BackTrack Wiki.
remote-exploit.org
2007/09/09
Paper Search
Reference: http://netlab.cse.yzu.edu.tw/
---
# NEC ResearchIndex
# IBM Technical Journals
# Network Bibliography
# The Collection of Computer Science Bibliographies
# IEICE Tran on (可線上申請帳號)
# JIT
# ACM digital library
# IEEE Xplore
# Elsevier SDOS 電子期刊全文資料庫
# 全國博碩士論文資訊網
# Springer - high-quality STM(scientific, technical, and medical) journals, book series, books, reference works and the Online Archives Collection
# Wiley InterScience
# PQDD Thesis in U.S.A (美國碩博論文資料庫)
# JCR資料庫 (SCI, SSCI)
# Google Scholar
# Scirus - for scientific information
---
# NEC ResearchIndex
# IBM Technical Journals
# Network Bibliography
# The Collection of Computer Science Bibliographies
# IEICE Tran on (可線上申請帳號)
# JIT
# ACM digital library
# IEEE Xplore
# Elsevier SDOS 電子期刊全文資料庫
# 全國博碩士論文資訊網
# Springer - high-quality STM(scientific, technical, and medical) journals, book series, books, reference works and the Online Archives Collection
# Wiley InterScience
# PQDD Thesis in U.S.A (美國碩博論文資料庫)
# JCR資料庫 (SCI, SSCI)
# Google Scholar
# Scirus - for scientific information
Subscribe to:
Posts (Atom)