@@ -132,51 +132,45 @@ void DartDumper::Dump4Radare2(std::filesystem::path outDir)
132132 std::filesystem::create_directory (outDir);
133133 std::ofstream of ((outDir / " addNames.r2" ).string ());
134134 of << " # create flags for libraries, classes and methods\n " ;
135-
136- // app base & heap base address values changes on every run i.e, setting flag names for them is of no use
137135
138- // of << fmt::format("f app.base = {:#x}\n", app.base());
139- // of << fmt::format("f app.heap_base = {:#x}\n", app.heap_base());
136+ of << " e emu.str=true\n " ;
137+ // app base & heap base address values changes on every run i.e, setting flag names for them is of no use
138+ // but since right now r2 bases it to address 0 let's leave it as it is
139+ // https://github.com/worawit/blutter/pull/104#discussion_r1769637361
140+ of << fmt::format (" f app.base = {:#x}\n " , app.base ());
141+ of << fmt::format (" f app.heap_base = {:#x}\n " , app.heap_base ());
140142
141143 bool show_library = true ;
142144 bool show_class = true ;
143145 for (auto lib : app.libs ) {
144146 std::string lib_prefix = lib->GetName ();
145-
146- std::replace (lib_prefix.begin (), lib_prefix.end (), ' $' , ' _' );
147- std::replace (lib_prefix.begin (), lib_prefix.end (), ' &' , ' _' );
148- std::replace (lib_prefix.begin (), lib_prefix.end (), ' -' , ' _' );
149- std::replace (lib_prefix.begin (), lib_prefix.end (), ' +' , ' _' );
147+ filterString (lib_prefix);
150148 for (auto cls : lib->classes ) {
151149 std::string cls_prefix = cls->Name ();
152- std::replace (cls_prefix.begin (), cls_prefix.end (), ' $' , ' _' );
153- std::replace (cls_prefix.begin (), cls_prefix.end (), ' &' , ' _' );
154- std::replace (cls_prefix.begin (), cls_prefix.end (), ' -' , ' _' );
155- std::replace (cls_prefix.begin (), cls_prefix.end (), ' +' , ' _' );
150+ filterString (cls_prefix);
156151 for (auto dartFn : cls->Functions ()) {
157152 const auto ep = dartFn->Address ();
158- auto name = getFunctionName4Ida (*dartFn, cls_prefix);
159- std::replace (name.begin (), name.end (), ' $' , ' _' );
160- std::replace (name.begin (), name.end (), ' &' , ' _' );
161- std::replace (name.begin (), name.end (), ' -' , ' _' );
162- std::replace (name.begin (), name.end (), ' +' , ' _' );
163- std::replace (name.begin (), name.end (), ' ?' , ' _' );
153+ std::string name = getFunctionName4Ida (*dartFn, cls_prefix);
154+ filterString (name);
164155 if (show_library) {
165- of << fmt::format (" CC Library({:#x}) = {} @ {} \n " , lib->id , lib_prefix, ep );
166- of << fmt::format (" f lib.{}={ :#x} # {:#x }\n " , lib_prefix, ep, lib-> id );
156+ of << fmt::format (" '@{:#x}' CC Library({:#x}) = {}\n " , ep, lib->id , lib-> GetName () );
157+ of << fmt::format (" '@{ :#x}'f lib.{ }\n " , ep, lib_prefix );
167158 show_library = false ;
168159 }
169160 if (show_class) {
170- of << fmt::format (" CC Class({:#x}) = {} @ {} \n " , cls->Id (), cls_prefix, ep );
171- of << fmt::format (" f class.{}.{}={:#x} # {:#x} \n " , lib_prefix, cls_prefix, ep, cls-> Id () );
161+ of << fmt::format (" '@{:#x}' CC Class({:#x}) = {}\n " , ep, cls->Id (), cls-> Name () );
162+ of << fmt::format (" '@{:#x}' f class.{}.{}\n " , ep, lib_prefix, cls_prefix );
172163 show_class = false ;
173164 }
174- of << fmt::format (" f method.{}.{}.{}_{:x}={:#x}\n " , lib_prefix, cls_prefix, name.c_str (), ep, ep);
165+ of << fmt::format (" '@{:#x}'f method.{}.{}.{}\n " , ep, lib_prefix, cls_prefix, name);
166+ of << fmt::format (" '@{:#x}'ic+{}.{}\n " , ep, cls_prefix, name);
175167 if (dartFn->HasMorphicCode ()) {
176- of << fmt::format (" f method.{}.{}.{}.miss={:#x}\n " , lib_prefix, cls_prefix, name.c_str (),
177- dartFn->PayloadAddress ());
178- of << fmt::format (" f method.{}.{}.{}.check={:#x}\n " , lib_prefix, cls_prefix, name.c_str (),
179- dartFn->MonomorphicAddress ());
168+ of << fmt::format (" '@{:#x}'f method.{}.{}.{}.miss\n " ,
169+ dartFn->PayloadAddress (),
170+ lib_prefix, cls_prefix, name);
171+ of << fmt::format (" '@{:#x}'f method.{}.{}.{}.check\n " ,
172+ dartFn->MonomorphicAddress (),
173+ lib_prefix, cls_prefix, name);
180174 }
181175 }
182176 show_class = true ;
@@ -187,28 +181,19 @@ void DartDumper::Dump4Radare2(std::filesystem::path outDir)
187181 auto stub = item.second ;
188182 const auto ep = stub->Address ();
189183 std::string name = stub->FullName ();
190- std::replace (name.begin (), name.end (), ' <' , ' _' );
191- std::replace (name.begin (), name.end (), ' >' , ' _' );
192- std::replace (name.begin (), name.end (), ' ,' , ' _' );
193- std::replace (name.begin (), name.end (), ' ' , ' _' );
194- std::replace (name.begin (), name.end (), ' $' , ' _' );
195- std::replace (name.begin (), name.end (), ' &' , ' _' );
196- std::replace (name.begin (), name.end (), ' -' , ' _' );
197- std::replace (name.begin (), name.end (), ' +' , ' _' );
198- std::replace (name.begin (), name.end (), ' ?' , ' _' );
199- std::replace (name.begin (), name.end (), ' (' , ' _' ); // https://github.com/AbhiTheModder/blutter-termux/issues/6
200- std::replace (name.begin (), name.end (), ' )' , ' _' );
201- of << fmt::format (" f method.stub.{}_{:x}={:#x}\n " , name.c_str (), ep, ep);
184+ std::string flagName = name;
185+ filterString (flagName);
186+ of << fmt::format (" '@{:#x}'f method.stub.{}\n " , ep, flagName);
202187 }
203-
204- of << " f pptr =x27\n " ; // TODO: hardcoded value
188+ of << " dr x27=`e anal.gp` \n " ;
189+ of << " 'f PP =x27\n " ;
205190 auto comments = DumpStructHeaderFile ((outDir / " r2_dart_struct.h" ).string ());
206191 for (const auto & [offset, comment] : comments) {
207192 if (comment.find (" String:" ) != -1 ) {
208193 std::string flagFromComment = comment;
209194 filterString (flagFromComment);
210- of << " f pp." << flagFromComment << " =pptr +" << offset << " \n " ;
211- of << " '@0x0 +" << offset << " 'CC " << comment << " \n " ;
195+ of << " f pp." << flagFromComment << " =PP +" << offset << " \n " ;
196+ of << " '@PP +" << offset << " 'CC " << comment << " \n " ;
212197 }
213198 }
214199}
@@ -219,6 +204,7 @@ void DartDumper::Dump4Ida(std::filesystem::path outDir)
219204 std::ofstream of ((outDir / " addNames.py" ).string ());
220205 of << " import ida_funcs\n " ;
221206 of << " import idaapi\n\n " ;
207+ of << " print(\" [+] Adding Function names...\" )\n\n " ;
222208
223209 for (auto lib : app.libs ) {
224210 std::string lib_prefix = lib->GetName ();
@@ -250,8 +236,9 @@ void DartDumper::Dump4Ida(std::filesystem::path outDir)
250236 continue ;
251237 of << fmt::format (" ida_funcs.add_func({:#x}, {:#x})\n " , ep, ep + stub->Size ());
252238 }
239+ of << " print(\" [+] Done!\" )\n " ;
253240
254-
241+ # ifndef IDA_FCN
255242 // Note: create struct with a lot of member by ida script is very slow
256243 // use header file then adding comment is much faster
257244 auto comments = DumpStructHeaderFile ((outDir / " ida_dart_struct.h" ).string ());
@@ -271,13 +258,27 @@ def create_Dart_structs():
271258 for (const auto & [offset, comment] : comments) {
272259 of << " \t ida_struct.set_member_cmt(ida_struct.get_member(struc, " << offset << " ), '''" << comment << " ''', True)\n " ;
273260 }
261+ #else
262+ auto comments = DumpStructHeaderFile ((outDir / " ida_dart_struct.h" ).string ());
263+ of << R"CBLOCK(
264+ import os
265+ def create_Dart_structs():
266+ sid1 = idc.get_struc_id("DartThread")
267+ if sid1 != idc.BADADDR:
268+ return sid1, idc.get_struc_id("DartObjectPool")
269+ hdr_file = os.path.join(os.path.dirname(__file__), 'ida_dart_struct.h')
270+ idaapi.idc_parse_types(hdr_file, idc.PT_FILE)
271+ sid1 = idc.import_type(-1, "DartThread")
272+ sid2 = idc.import_type(-1, "DartObjectPool")
273+ )CBLOCK" ;
274+ #endif
274275 of << " \t return sid1, sid2\n " ;
275276 of << " thrs, pps = create_Dart_structs()\n " ;
276277
277- of << " print('Applying Thread and Object Pool struct')\n " ;
278+ of << " print('[+] Applying Thread and Object Pool struct')\n " ;
278279 applyStruct4Ida (of);
279280
280- of << " print('Script finished!')\n " ;
281+ of << " print('[+] Script finished!')\n " ;
281282}
282283
283284std::vector<std::pair<intptr_t , std::string>> DartDumper::DumpStructHeaderFile (std::string outFile)
0 commit comments