Reading string values from a Cgo DLL struct - reverse-engineering

I am trying to reverse engineer a 64-bit DLL that was written in Go and compiled to a C DLL. I want to log the first parameter of exported DoRequest method.
The DLL is invoked with P/Invoke in a C# application. Using dnSpy, I can see the struct of the data is;
private struct Struct0
{
// Token: 0x04000474 RID: 1140
public string string_0;
// Token: 0x04000475 RID: 1141
public string string_1;
// Token: 0x04000476 RID: 1142
public string string_2;
// Token: 0x04000477 RID: 1143
public string string_3;
// Token: 0x04000478 RID: 1144
public string }{__>_;
// Token: 0x04000479 RID: 1145
[MarshalAs(UnmanagedType.LPUTF8Str)]
public string string_4;
// Token: 0x0400047A RID: 1146
[MarshalAs(UnmanagedType.LPUTF8Str)]
public string string_5;
// Token: 0x0400047B RID: 1147
public string string_6;
// Token: 0x0400047C RID: 1148
public string string_7;
// Token: 0x0400047D RID: 1149
public string string_8;
// Token: 0x0400047E RID: 1150
public string string_9;
// Token: 0x0400047F RID: 1151
public int int_0;
// Token: 0x04000480 RID: 1152
public int int_1;
// Token: 0x04000481 RID: 1153
public string string_10;
// Token: 0x04000482 RID: 1154
[MarshalAs(UnmanagedType.I1)]
public bool bool_0;
// Token: 0x04000483 RID: 1155
[MarshalAs(UnmanagedType.I1)]
public bool bool_1;
// Token: 0x04000484 RID: 1156
public string string_11;
// Token: 0x04000485 RID: 1157
public int int_2;
// Token: 0x04000486 RID: 1158
public uint uint_0;
}
This is a screenshot of the method from IDA:
I have started writing a Frida hook;
var doRequest = Module.getExportByName("client64.dll", "DoRequest");
Interceptor.attach(doRequest, {
onEnter: function(args) {
console.log("Hooked DoRequest");
var structPointer = (args[0]);
console.log("structPointer : " + structPointer);
}
});
However I'm not sure where to go next. How can I read each property of the struct?

Related

Error: Unexpected character encountered while parsing value: { using .NET core 3

I don't understand why get an error "Unexpected character encountered while parsing value: {"?
My startup config:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddControllers().AddNewtonsoftJson(opts => {
opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
);
}
My controller:
[HttpPost("{accountId}/top-up")]
public async Task<IActionResult> TopUp([FromBody] decimal amount, [FromRoute] int accountId)
{
//...
}
Parameters do not match the data you passed in
// param [FromBody] decimal amount
Matchs
100
public class Foo {
public decimal Amount { get; set; }
}
//param [FromBody]Foo model
Matchs
{
"amount":100
}

Retrofit error when response is being parsed as list

I'm getting the following error when attempting to get a array of json objects using retrofit.
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 2 path $
The request is declared in the api interface as
interface HttpRequests {
#GET("/api/v1/emergency")
Observable<List<Emergency>> getEmergencies(#Query("lat") Double lat,
#Query("lng") Double lng,
#Query("dist") int dist);
Where Emergency is defined as
public class Emergency {
#SerializedName("emergencyUuid")
#Expose
private String emergencyUuid;
#SerializedName("lat")
#Expose
private Double lat;
#SerializedName("lng")
#Expose
private Double lng;
#SerializedName("phoneNumber")
#Expose
private String phoneNumber;
public Emergency(){};
public Emergency(String emergencyUuid, Double lat, Double lng, String phoneNumber){
this.emergencyUuid = emergencyUuid;
this.lat = lat;
this.lng = lng;
this.phoneNumber = phoneNumber;
}
// getters & setters
}
When I replace the List<Emergency> with String I can print the response which looks somewhat like:
"[{\"emergencyUuid\":\"axkdjfiwokdfj\",\"lat\":22.22,\"lng\":33.33,\"phoneNumber\":\"12345678910\"}]"
This seems to me a perfectly fine json array with a single emergency object. I do not understand why this can't be parsed. What did I do wrong?

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token

Currently I am working on rest service, while consuming the service getting error.
public String userName;
public String refernceNumber;
public String requestType;
public String fullName;
public String dateOfBirth;
public String placeOfBirth;
public String gender;
public String nationlaity;
public String telphoneNo;
public String mobileNo;
public String note;
public String email;
public String processId;
public List<DocumentDTO> attachmentsList;
and my documentdto is like
private String doumentNameEng;
private Integer documentId;
private String fileName;
private MultipartFile attachment;
private String ticketNo;
private String dmsRefId;
enter code here
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token
at [Source: org.apache.catalina.connector.CoyoteInputStream#1171c8a3; line: 1, column: 233] (through reference chain: com.micd.process.dto.applcation["attachmentsList"])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:575)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:569)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.handleNonArray(CollectionDeserializer.java:259)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:217)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:207)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:23)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:98)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:295)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2094)
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readJavaType(MappingJackson2HttpMessageConverter.java:168)
help me to getout from this error, unable to understand this eror.

Unable to get through CXF with JSON

I am trying to build a CXF RESTFul service with JSON as input and output. I am using JAXRSServerFactoryBean to boot my service. When I try to hit the URL from a client program, I am getting the following exception. My program is very simple and attached the same at the bottom.
Please help.
May 19, 2015 11:03:30 PM org.apache.cxf.jaxrs.provider.AbstractJAXBProvider handleExceptionStart
WARNING: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[0,0]
Message: A JSONObject text must begin with '{' at character 0 of
at org.codehaus.jettison.mapped.MappedXMLInputFactory.createXMLStreamReader(MappedXMLInputFactory.java:51)
at org.codehaus.jettison.AbstractXMLInputFactory.createXMLStreamReader(AbstractXMLInputFactory.java:116)
at org.apache.cxf.jaxrs.provider.json.utils.JSONUtils.createStreamReader(JSONUtils.java:162)
at org.apache.cxf.jaxrs.provider.json.JSONProvider.createReader(JSONProvider.java:290)
at org.apache.cxf.jaxrs.provider.json.JSONProvider.createReader(JSONProvider.java:280)
at org.apache.cxf.jaxrs.provider.json.JSONProvider.readFrom(JSONProvider.java:233)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1337)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1288)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:824)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:787)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:212)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:77)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
May 19, 2015 11:03:30 PM org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
WARNING: javax.ws.rs.BadRequestException: HTTP 400 Bad Request
at org.apache.cxf.jaxrs.utils.SpecExceptions.toBadRequestException(SpecExceptions.java:84)
at org.apache.cxf.jaxrs.utils.ExceptionUtils.toBadRequestException(ExceptionUtils.java:114)
at org.apache.cxf.jaxrs.provider.AbstractJAXBProvider.handleExceptionEnd(AbstractJAXBProvider.java:705)
at org.apache.cxf.jaxrs.provider.AbstractJAXBProvider.handleXMLStreamException(AbstractJAXBProvider.java:734)
at org.apache.cxf.jaxrs.provider.json.JSONProvider.readFrom(JSONProvider.java:261)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1337)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1288)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:824)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:787)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:212)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:77)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:234)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:70)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1129)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1065)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[0,0]
Message: A JSONObject text must begin with '{' at character 0 of
at org.codehaus.jettison.mapped.MappedXMLInputFactory.createXMLStreamReader(MappedXMLInputFactory.java:51)
at org.codehaus.jettison.AbstractXMLInputFactory.createXMLStreamReader(AbstractXMLInputFactory.java:116)
at org.apache.cxf.jaxrs.provider.json.utils.JSONUtils.createStreamReader(JSONUtils.java:162)
at org.apache.cxf.jaxrs.provider.json.JSONProvider.createReader(JSONProvider.java:290)
RestFulServiceStarter
public class RestFulServiceStarter {
public static void main(String[] args) {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(ProfileService.class);
sf.setResourceProvider(ProfileService.class,
new SingletonResourceProvider(new ProfileServiceImpl()));
sf.setAddress("http://localhost:9999/");
Server server = sf.create();
}
}
ProfileService
#Path("/profile/")
public interface ProfileService {
#GET
#Path("/static/")
#Consumes({ MediaType.APPLICATION_JSON })
#Produces({ MediaType.APPLICATION_JSON })
public Response getStaticProfiles(ProfileRequest pr);
}
ProfileServiceImpl
public class ProfileServiceImpl implements ProfileService {
public Response getStaticProfiles(ProfileRequest pr) {
return Response.status(200).entity(pr).build();
}
}
ProfileRequest
#XmlRootElement ( name = "profile" )
public class ProfileRequest {
private String name="";
private String country="";
private String region="";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
}
Your interface method is annotated with a #GET method, yet it also has an entity parameter (ProfileRequest). Try #POST.

Unrecognized Property in fetching data from JSONObject in Jersey web service

I need to convert a certain JSON string to a Java object. I am using Jackson for JSON handling.
Here is my Java class:
public class RequestClass {
String email_id;
String password;
public String getEmailId() {
return email_id;
}
public String getPassword() {
return password;
}
#Override
public String toString(){
return email_id+" "+password;
}
}
Here is the web service code:
#POST
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
#Path("/dbconnect3")
public String connectToDbTest3(RequestClass rc) {
System.out.println("connectToDbTest3");
String email_id = rc.getEmailId();
String password = rc.getPassword();
System.out.println(email_id + " " + password);
}
This throws exception UnrecognizedPropertyException with message "Unrecognized field "email_id" (Class jaxrs.RequestClass), not marked as ignorable".
In case i am not using the annotation #JsonIgnoreProperties(ignoreUnknown = true) in my Java class, the output I am getting on line 09 is:
null myPassword
So I don't want to ignore Unrecognized field instead I want to get the value of email_id.
Please tell why It shows email_id as Unrecognized field while password is fetched successfully.
Just add #JsonProperty("email_id") before the getEmailId() like given below:
#JsonProperty("email_id")
public String getEmailId() {
return email_id;
}