Goal : i want to inject a one line code in smali
My current approach
I am reading smali file with getline() and writing whole content to a new file with some changes.
Here is code
while(getline(&line,&line_size,smaliFile) != -1) {
if (FLAG) {
if (strstr(line,"return-void") != NULL) {
fputs(" invoke-static {}, Lcom/hax/util/MainService;->start()V\n\n",smali_tmp);
fputs(" return-void\n",smali_tmp);
FLAG=0;
continue;
}
}
fputs(line,smali_tmp);
}
if (FLAG) {
fprintf(stderr,"can't find hook point !\n");
exit(1);
}
Where smaliFile is original smali file and smali_tmp is new patched smali file.
And if i am doing same thing manually then it's recompiling as expected
Here is error while recompiling
Smali.smali[1771,7] mismatched input '' expecting END_METHOD_DIRECTIVE
Could not smali file: com/gbwhatsapp/Smali.smali
But when i am looking into corrupted file at location 1771,7 with vim , there is no any unusual thing or character present.
I also used diff command to check changes and diff outputs only one line which was added by me.