2013年8月14日星期三

DD-WRT Firmware Mod Kit 重新封装gui时提示www目录为空的修复

author荒野无灯2013-05-05 23:29:44 (CST)
committer荒野无灯2013-05-05 23:29:44 (CST)
commit742a7cbe5bb3fc75be03151ffdf267c2eafc1ccb (patch)
tree70881a77b5186d4c11cc0d710944ebf8a8659e73
parent871a75d5ab4b639ea9f25b2d7baaf2e8122eec76 (diff)
downloadfirmware-mod-kit-742a7cbe5bb3fc75be03151ffdf267c2eafc1ccb.zip
firmware-mod-kit-742a7cbe5bb3fc75be03151ffdf267c2eafc1ccb.tar.gz
firmware-mod-kit-742a7cbe5bb3fc75be03151ffdf267c2eafc1ccb.tar.bz2

此bug会导致ddwrt-gui-rebuild.sh 无法重新打包ddwrt的GUI组件. 原因在于,后面的 detect_key(httpd, www); 还要对www文件进行读取。 而原版程序在此之前就已经以二进制写方式打开了www文件: fp = fopen(www, "wb"); 这个操作将导致www文件直接变成0字节的文件。因此,后面的读取操作只会读取到 一个0字节的www文件,从而导致无法顺利打包。

可以直接

1
git clone git://ihacklog.com/firmware-mod-kit.git

使用修正版的fmk.

修正restore函数中一处bug.
此bug会导致ddwrt-gui-rebuild.sh 无法打包ddwrt的GUI组件. 原因在于,后面的 detect_key(httpd, www); 还要对www文件进行读取。 而原版程序在此之前就已经以二进制写方式打开了www文件: fp = fopen(www, "wb"); 这个操作将导致www文件直接变成0字节的文件。因此,后面的读取操作只会读取到 一个0字节的www文件,从而导致无法顺利打包。
-rw-r--r--src/webcomp-tools/webdecomp.c 54
1 files changed, 29 insertions, 25 deletions
diff --git a/src/webcomp-tools/webdecomp.c b/src/webcomp-tools/webdecomp.c
index d2bb8db..b67cfd4 100644
--- a/src/webcomp-tools/webdecomp.c
+++ b/src/webcomp-tools/webdecomp.c
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
};
memset((void *) &globals, 0, sizeof(globals));
-
+
while((c = getopt_long(argc, argv, short_options, long_options, &long_opt_index)) != -1)
{
switch(c)
@@ -63,7 +63,7 @@ int main(int argc, char *argv[])
default:
usage(argv[0]);
goto end;
-
+
}
}
@@ -191,7 +191,7 @@ int extract(char *httpd, char *www, char *outdir, char *key)
/* Read in the httpd and www files */
hdata = (unsigned char *) file_read(httpd, &hsize);
wdata = (unsigned char *) file_read(www, &wsize);
-
+
if(hdata != NULL && wdata != NULL && detect_settings(hdata, hsize))
{
/* Detect the key */
@@ -205,7 +205,7 @@ int extract(char *httpd, char *www, char *outdir, char *key)
{
perror(outdir);
}
- else
+ else
{
/* Get the next entry until we get a blank entry */
while((info = next_entry(hdata, hsize)) != NULL)
@@ -257,13 +257,13 @@ int extract(char *httpd, char *www, char *outdir, char *key)
{
fprintf(stderr, "\nERROR opening keyfile, aborting\n");
n=-1;
- }
+ }
else
{
if(fwrite(&globals.key, 1, sizeof(globals.key), fp) != sizeof(globals.key))
{
fprintf(stderr, "\nERROR writing keyfile, aborting\n");
- n=-1;
+ n=-1;
}
fclose(fp);
}
@@ -289,7 +289,7 @@ int restore(char *httpd, char *www, char *indir, char *key)
struct entry_info *info = NULL;
unsigned char *hdata = NULL, *fdata = NULL;
char origdir[FILENAME_MAX] = { 0 };
- char *path = NULL;
+ char *path = NULL;
if(key)
{
@@ -314,31 +314,35 @@ int restore(char *httpd, char *www, char *indir, char *key)
/* Read in the httpd file */
hdata = (unsigned char *) file_read(httpd, &hsize);
-
+
/* Get the current working directory */
getcwd((char *) &origdir, sizeof(origdir));
- /* Open the www file for writing */
- fp = fopen(www, "wb");
-
- if(hdata != NULL && fp != NULL && detect_settings(hdata, hsize))
+ if(hdata != NULL && detect_settings(hdata, hsize))
{
/* Detect the key */
detect_key(httpd, www);
+ /* Open the www file for writing */
+ fp = fopen(www, "wb");
+ if( fp == NULL )
+ {
+ fprintf(stderr,"failed to open www file for writing \n");
+ }
+
/* Change directories to the target directory */
- if(chdir(indir) == -1)
- {
- perror(indir);
- }
- else
+ if(chdir(indir) == -1)
+ {
+ perror(indir);
+ }
+ else
{
/* Get the next entry until we get a blank entry */
while((info = next_entry(hdata, hsize)) != NULL)
{
/* Count the number of files we process */
n++;
-
+
/* Make sure the full file path is safe (i.e., it won't overwrite something critical on the host system) */
path = make_path_safe(info->name);
if(path)
@@ -348,18 +352,18 @@ int restore(char *httpd, char *www, char *indir, char *key)
/* Read in the file */
fdata = (unsigned char *) file_read(path, &fsize);
-
+
/* Update the entry size and file offset */
if(globals.use_new_format)
{
- info->new_entry->size = fsize + globals.key;
+ info->new_entry->size = fsize + globals.key;
}
else
{
info->entry->size = fsize;
info->entry->offset = total;
}
-
+
/* Byte swap, if necessary */
hton_entries(info);
@@ -375,17 +379,17 @@ int restore(char *httpd, char *www, char *indir, char *key)
/* Update the total size written to the www blob */
total += fsize;
}
-
+
free(fdata);
}
-
+
free(path);
}
else
{
fprintf(stderr, "File path '%s' is not safe! Skipping...\n", info->name);
}
-
+
free(info);
}
@@ -408,7 +412,7 @@ int restore(char *httpd, char *www, char *indir, char *key)
{
perror("restore");
}
-
+
if(fp) fclose(fp);
if(hdata) free(hdata);
return n;